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 free 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
740 ; source code for all the sub-packages (pre-processor, assemblers, linkers
741 etc.) is distributed with the package.
742 This documentation is maintained using a free open source word processor
745 This program is free software; you can redistribute it and/or modify
746 it under the terms of the GNU General Public License
747 \begin_inset LatexCommand index
748 name "GNU General Public License, GPL"
752 as published by the Free Software Foundation; either version 2, or (at
753 your option) any later version.
754 This program is distributed in the hope that it will be useful, but WITHOUT
755 ANY WARRANTY; without even the implied warranty
756 \begin_inset LatexCommand index
761 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
762 See the GNU General Public License for more details.
763 You should have received a copy of the GNU General Public License along
764 with this program; if not, write to the Free Software Foundation, 59 Temple
765 Place - Suite 330, Boston, MA 02111-1307, USA.
766 In other words, you are welcome to use, share and improve this program.
767 You are forbidden to forbid anyone else to use, share and improve what
769 Help stamp out software-hoarding!
772 \begin_layout Section
773 Typographic conventions
774 \begin_inset LatexCommand index
775 name "Typographic conventions"
782 \begin_layout Standard
783 Throughout this manual, we will use the following convention.
784 Commands you have to type in are printed in
792 Code samples are printed in
797 Interesting items and new terms are printed in
802 \begin_layout Section
804 \begin_inset LatexCommand label
805 name "sec:Compatibility-with-previous"
809 with previous versions
810 \begin_inset LatexCommand index
811 name "Compatibility with previous versions"
818 \begin_layout Standard
819 Newer versions have usually numerous bug fixes compared with the previous
821 But we also sometimes introduce some incompatibilities with older versions.
822 Not just for the fun of it, but to make the compiler more stable, efficient
824 \begin_inset LatexCommand index
825 name "ANSI-compliance"
830 \begin_inset LatexCommand ref
831 reference "sub:ANSI-Compliance"
835 for ANSI-Compliance).
837 \begin_inset Note Note
840 \begin_layout Standard
841 It would be fine to add to each item, in which version was it changed.
851 \begin_layout Itemize
852 short is now equivalent to int (16 bits), it used to be equivalent to char
853 (8 bits) which is not ANSI compliant.
854 To maintain compatibility, old programs may be compiled using the -
858 \begin_layout Standard
867 -short-is-8bits commandline option (see
868 \begin_inset LatexCommand vref
869 reference "lyx:--short-is-8bits"
876 \begin_layout Itemize
877 the default directory for gcc-builds where include, library and documentation
878 files are stored is now in /usr/local/share.
881 \begin_layout Itemize
882 char type parameters to vararg
883 \begin_inset LatexCommand index
884 name "vararg, va\\_arg"
888 functions are casted to int unless explicitly casted and
894 \begin_layout Standard
904 \begin_inset LatexCommand index
917 \begin_layout Standard
927 \begin_inset LatexCommand index
934 command line option are not defined
935 \begin_inset Marginal
938 \begin_layout Standard
963 will push a as an int and as a char resp if
969 \begin_layout Standard
979 \begin_inset LatexCommand index
992 \begin_layout Standard
1002 \begin_inset LatexCommand index
1009 command line options are not defined,
1011 will push a as two ints if
1017 \begin_layout Standard
1027 \begin_inset LatexCommand index
1040 \begin_layout Standard
1050 \begin_inset LatexCommand index
1057 command line option is defined.
1060 \begin_layout Itemize
1065 \begin_layout Standard
1074 -regextend has been removed.
1077 \begin_layout Itemize
1082 \begin_layout Standard
1091 -noregparms has been removed.
1094 \begin_layout Itemize
1099 \begin_layout Standard
1108 -stack-after-data has been removed.
1111 \begin_layout Itemize
1113 \begin_inset LatexCommand index
1119 \begin_inset LatexCommand index
1125 \begin_inset LatexCommand index
1130 types now consistently behave like the C99 _Bool type with respect to type
1132 \begin_inset LatexCommand index
1133 name "type conversion"
1138 \begin_inset LatexCommand index
1139 name "type promotion"
1144 The most common incompatibility resulting from this change is related to
1146 \begin_inset LatexCommand index
1162 \begin_inset LatexCommand index
1163 name "\\~\\/ Operator"
1167 b; /* equivalent to b=1 instead of toggling b */
1168 \begin_inset Marginal
1171 \begin_layout Standard
1184 b = !b; /* toggles b */
1188 In previous versions, both forms would have toggled the bit.
1191 \begin_layout Itemize
1192 in older versions, the preprocessor was always called with
1198 \begin_layout Standard
1208 \begin_inset LatexCommand index
1221 \begin_layout Standard
1233 This is no longer true, and can cause compilation failures on code built
1240 \begin_layout Standard
1250 \begin_inset LatexCommand index
1257 but using c99 preprocessor features, such as one-line (//) comments
1260 \begin_layout Itemize
1261 in versions older then 2.8.4 the pic16 *printf() and printf_tiny() library
1262 functions supported undocumented and not standard compliant 'b' binary
1263 format specifier ("%b", "%hb" and "%lb").
1264 The 'b' specifier is now disabled by default.
1265 It can be enabled by defining BINARY_SPECIFIER macro in files device/lib/pic16/
1266 libc/stdio/vfprintf.c and device/lib/pic16/libc/stdio/printf_tiny.c and recompilin
1270 \begin_layout Itemize
1271 in versions older then 2.8.5 the unnamed bitfield structure members participated
1272 in initialization, which is not conforming with ISO/IEC 9899:1999 standard
1273 (see section Section 6.7.8 Initialization, clause 9)
1277 Old behavior, before
1313 /* s.a = 1, s.b = 3 */
1354 /* s.a = 1, s.b = 2 */
1357 \begin_layout Section
1361 \begin_layout Standard
1362 What do you need before you start installation of SDCC? A computer, and
1363 a desire to compute.
1364 The preferred method of installation is to compile SDCC from source using
1366 For Windows some pre-compiled binary distributions are available for your
1368 You should have some experience with command line tools and compiler use.
1371 \begin_layout Section
1375 \begin_layout Standard
1376 The SDCC home page at
1377 \begin_inset LatexCommand url
1378 target "http://sdcc.sourceforge.net/"
1382 is a great place to find distribution sets.
1383 You can also find links to the user mailing lists that offer help or discuss
1384 SDCC with other SDCC users.
1385 Web links to other SDCC related sites can also be found here.
1386 This document can be found in the DOC directory of the source package as
1387 a text or HTML file.
1388 A pdf version of this document is available at
1389 \begin_inset LatexCommand url
1390 target "http://sdcc.sourceforge.net/doc/sdccman.pdf"
1395 Some of the other tools (simulator and assembler) included with SDCC contain
1396 their own documentation and can be found in the source distribution.
1397 If you want the latest unreleased software, the complete source package
1398 is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1402 \begin_layout Section
1403 Wishes for the future
1406 \begin_layout Standard
1407 There are (and always will be) some things that could be done.
1408 Here are some I can think of:
1413 \begin_layout Standard
1416 char KernelFunction3(char p) at 0x340;
1421 \begin_layout Standard
1425 \begin_inset LatexCommand index
1426 name "code banking (limited support)"
1436 If you can think of some more, please see the section
1437 \begin_inset LatexCommand ref
1438 reference "sub:Requesting-Features"
1442 about filing feature requests
1443 \begin_inset LatexCommand index
1444 name "Requesting features"
1449 \begin_inset LatexCommand index
1450 name "Feature request"
1459 \begin_layout Chapter
1461 \begin_inset LatexCommand index
1469 \begin_layout Standard
1470 For most users it is sufficient to skip to either section
1471 \begin_inset LatexCommand ref
1472 reference "sub:Building-SDCC-on-Linux"
1477 \begin_inset LatexCommand ref
1478 reference "sub:Windows-Install"
1483 More detailed instructions follow below.
1486 \begin_layout Section
1488 \begin_inset LatexCommand index
1489 name "Options SDCC configuration"
1496 \begin_layout Standard
1497 The install paths, search paths and other options are defined when running
1499 The defaults can be overridden by:
1503 \labelwidthstring 00.00.0000
1508 \begin_layout Standard
1517 -prefix see table below
1521 \labelwidthstring 00.00.0000
1526 \begin_layout Standard
1535 -exec_prefix see table below
1539 \labelwidthstring 00.00.0000
1544 \begin_layout Standard
1553 -bindir see table below
1557 \labelwidthstring 00.00.0000
1562 \begin_layout Standard
1571 -datadir see table below
1575 \labelwidthstring 00.00.0000
1580 \begin_layout Standard
1589 -datarootdir see table below
1595 \labelwidthstring 00.00.0000
1598 docdir environment variable, see table below
1602 \labelwidthstring 00.00.0000
1605 include_dir_suffix environment variable, see table below
1609 \labelwidthstring 00.00.0000
1612 lib_dir_suffix environment variable, see table below
1616 \labelwidthstring 00.00.0000
1619 sdccconf_h_dir_separator environment variable, either / or
1624 This character will only be used in sdccconf.h; don't forget it's a C-header,
1625 therefore a double-backslash is needed there.
1631 \labelwidthstring 00.00.0000
1636 \begin_layout Standard
1645 -disable-mcs51-port Excludes the Intel mcs51 port
1649 \labelwidthstring 00.00.0000
1654 \begin_layout Standard
1663 -disable-gbz80-port Excludes the Gameboy gbz80 port
1667 \labelwidthstring 00.00.0000
1672 \begin_layout Standard
1681 -disable-z80-port Excludes the z80 port
1685 \labelwidthstring 00.00.0000
1690 \begin_layout Standard
1699 -disable-avr-port Excludes the AVR port
1703 \labelwidthstring 00.00.0000
1708 \begin_layout Standard
1717 -disable-ds390-port Excludes the DS390 port
1721 \labelwidthstring 00.00.0000
1726 \begin_layout Standard
1735 -disable-hc08-port Excludes the HC08 port
1739 \labelwidthstring 00.00.0000
1744 \begin_layout Standard
1753 -disable-pic-port Excludes the PIC14 port
1757 \labelwidthstring 00.00.0000
1762 \begin_layout Standard
1771 -disable-pic16-port Excludes the PIC16 port
1775 \labelwidthstring 00.00.0000
1780 \begin_layout Standard
1789 -disable-xa51-port Excludes the XA51 port
1793 \labelwidthstring 00.00.0000
1798 \begin_layout Standard
1807 -disable-ucsim Disables configuring and building of ucsim
1811 \labelwidthstring 00.00.0000
1816 \begin_layout Standard
1825 -disable-device-lib Disables automatically building device libraries
1829 \labelwidthstring 00.00.0000
1834 \begin_layout Standard
1843 -disable-packihx Disables building packihx
1849 \labelwidthstring 00.00.0000
1854 \begin_layout Standard
1863 -enable-doc Build pdf, html and txt files from the lyx sources
1867 \labelwidthstring 00.00.0000
1872 \begin_layout Standard
1881 -enable-libgc Use the Bohem memory allocator.
1882 Lower runtime footprint.
1886 \labelwidthstring 00.00.0000
1891 \begin_layout Standard
1900 -without-ccache Do not use ccache even if available
1903 \begin_layout Standard
1904 Furthermore the environment variables CC, CFLAGS, ...
1905 the tools and their arguments can be influenced.
1906 Please see `configure -
1910 \begin_layout Standard
1919 -help' and the man/info pages of `configure' for details.
1924 standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1925 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1926 SDCC_LIB_NAME are defined by `configure' too.
1927 At the moment it's not possible to change the default settings (it was
1928 simply never required).
1932 These configure options are compiled into the binaries,
1933 and can only be changed by rerunning 'configure' and recompiling SDCC.
1934 The configure options are written in
1938 to distinguish them from run time environment variables (see section search
1944 \begin_inset Quotes sld
1948 \begin_inset Quotes srd
1951 are used by the SDCC team to build the official Win32 binaries.
1952 The SDCC team uses Mingw32 to build the official Windows binaries, because
1956 \begin_layout Enumerate
1960 \begin_layout Enumerate
1961 a gcc compiler and last but not least
1964 \begin_layout Enumerate
1965 the binaries can be built by cross compiling on SDCC Distributed Compile
1969 \begin_layout Standard
1970 See the examples, how to pass the Win32 settings to 'configure'.
1971 The other Win32 builds using Borland, VC or whatever don't use 'configure',
1972 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1982 \begin_layout Standard
1984 \begin_inset Tabular
1985 <lyxtabular version="3" rows="9" columns="3">
1987 <column alignment="block" valignment="top" leftline="true" width="0in">
1988 <column alignment="block" valignment="top" leftline="true" width="0in">
1989 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1990 <row topline="true" bottomline="true">
1991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1994 \begin_layout Standard
2000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2003 \begin_layout Standard
2009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2012 \begin_layout Standard
2019 <row topline="true">
2020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2023 \begin_layout Standard
2031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2034 \begin_layout Standard
2040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2043 \begin_layout Standard
2052 <row topline="true">
2053 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2056 \begin_layout Standard
2064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2067 \begin_layout Standard
2075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2078 \begin_layout Standard
2087 <row topline="true">
2088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2091 \begin_layout Standard
2099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2102 \begin_layout Standard
2112 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2115 \begin_layout Standard
2128 <row topline="true">
2129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2132 \begin_layout Standard
2140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2143 \begin_layout Standard
2151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2154 \begin_layout Standard
2163 <row topline="true">
2164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2167 \begin_layout Standard
2175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2178 \begin_layout Standard
2188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2191 \begin_layout Standard
2200 <row topline="true">
2201 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2204 \begin_layout Standard
2212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2215 \begin_layout Standard
2225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2228 \begin_layout Standard
2241 <row topline="true">
2242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2245 \begin_layout Standard
2253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2256 \begin_layout Standard
2262 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2265 \begin_layout Standard
2272 <row topline="true" bottomline="true">
2273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2276 \begin_layout Standard
2284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2287 \begin_layout Standard
2293 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2296 \begin_layout Standard
2312 \begin_layout Standard
2314 'configure' also computes relative paths.
2315 This is needed for full relocatability of a binary package and to complete
2316 search paths (see section search paths below):
2321 \begin_layout Standard
2323 \begin_inset Tabular
2324 <lyxtabular version="3" rows="4" columns="3">
2326 <column alignment="block" valignment="top" leftline="true" width="0in">
2327 <column alignment="block" valignment="top" leftline="true" width="0in">
2328 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2329 <row topline="true" bottomline="true">
2330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2333 \begin_layout Standard
2339 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2342 \begin_layout Standard
2348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2351 \begin_layout Standard
2358 <row topline="true" bottomline="true">
2359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2362 \begin_layout Standard
2370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2373 \begin_layout Standard
2379 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2382 \begin_layout Standard
2389 <row bottomline="true">
2390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2393 \begin_layout Standard
2401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2404 \begin_layout Standard
2410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2413 \begin_layout Standard
2420 <row bottomline="true">
2421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2424 \begin_layout Standard
2432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2435 \begin_layout Standard
2441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2444 \begin_layout Standard
2460 \begin_layout Standard
2465 \begin_layout LyX-Code
2472 \begin_layout Standard
2482 \begin_inset Quotes srd
2486 \begin_inset Quotes srd
2493 \begin_layout Standard
2503 \begin_inset Quotes srd
2507 \begin_inset Quotes srd
2516 \begin_layout Standard
2529 \begin_layout Standard
2541 \begin_layout Standard
2542 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2546 \begin_layout LyX-Code
2552 \begin_inset Quotes srd
2555 i586-mingw32msvc-gcc
2556 \begin_inset Quotes srd
2560 \begin_inset Quotes srd
2563 i586-mingw32msvc-g++
2564 \begin_inset Quotes srd
2572 \begin_inset Quotes srd
2575 i586-mingw32msvc-ranlib
2576 \begin_inset Quotes srd
2584 \begin_inset Quotes srd
2587 i586-mingw32msvc-strip
2588 \begin_inset Quotes srd
2599 \begin_layout Standard
2609 \begin_inset Quotes srd
2613 \begin_inset Quotes srd
2624 \begin_layout Standard
2634 \begin_inset Quotes srd
2638 \begin_inset Quotes srd
2646 \begin_inset Quotes srd
2652 \begin_inset Quotes srd
2660 \begin_inset Quotes srd
2664 \begin_inset Quotes srd
2672 \begin_inset Quotes srd
2676 \begin_inset Quotes srd
2683 sdccconf_h_dir_separator=
2684 \begin_inset Quotes srd
2696 \begin_inset Quotes srd
2707 \begin_layout Standard
2724 \begin_layout Standard
2733 -host=i586-mingw32msvc
2741 \begin_layout Standard
2750 -build=unknown-unknown-linux-gnu
2753 \begin_layout Standard
2755 \begin_inset Quotes sld
2759 \begin_inset Quotes srd
2762 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2766 \begin_layout LyX-Code
2775 \begin_layout Standard
2785 \begin_inset Quotes srd
2789 \begin_inset Quotes srd
2800 \begin_layout Standard
2810 \begin_inset Quotes srd
2814 \begin_inset Quotes srd
2822 \begin_inset Quotes srd
2828 \begin_inset Quotes srd
2836 \begin_inset Quotes srd
2840 \begin_inset Quotes srd
2848 \begin_inset Quotes srd
2852 \begin_inset Quotes srd
2859 sdccconf_h_dir_separator=
2860 \begin_inset Quotes srd
2872 \begin_inset Quotes srd
2880 \begin_inset Quotes srd
2884 \begin_inset Quotes srd
2892 \begin_inset Quotes srd
2896 \begin_inset Quotes srd
2902 \begin_layout Standard
2903 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2908 \begin_layout Standard
2917 -C' turns on caching, which gives a little bit extra speed.
2918 However if options are changed, it can be necessary to delete the config.cache
2922 \begin_layout Section
2924 \begin_inset LatexCommand label
2925 name "sub:Install-paths"
2930 \begin_inset LatexCommand index
2931 name "Install paths"
2938 \begin_layout Standard
2939 \begin_inset VSpace medskip
2945 \begin_layout Standard
2947 \begin_inset Tabular
2948 <lyxtabular version="3" rows="5" columns="4">
2950 <column alignment="left" valignment="top" leftline="true" width="0">
2951 <column alignment="left" valignment="top" leftline="true" width="0">
2952 <column alignment="left" valignment="top" leftline="true" width="0">
2953 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2954 <row topline="true" bottomline="true">
2955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2958 \begin_layout Standard
2966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2969 \begin_layout Standard
2977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2980 \begin_layout Standard
2988 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2991 \begin_layout Standard
3000 <row topline="true">
3001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3004 \begin_layout Standard
3010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3013 \begin_layout Standard
3021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3024 \begin_layout Standard
3030 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3033 \begin_layout Standard
3044 <row topline="true">
3045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3048 \begin_layout Standard
3054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3057 \begin_layout Standard
3060 $DATADIR/ $INCLUDE_DIR_SUFFIX
3065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3068 \begin_layout Standard
3069 /usr/local/share/sdcc/include
3074 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3077 \begin_layout Standard
3088 <row topline="true">
3089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3092 \begin_layout Standard
3098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3101 \begin_layout Standard
3104 $DATADIR/$LIB_DIR_SUFFIX
3109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3112 \begin_layout Standard
3113 /usr/local/share/sdcc/lib
3118 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3121 \begin_layout Standard
3132 <row topline="true" bottomline="true">
3133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3136 \begin_layout Standard
3142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3145 \begin_layout Standard
3153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3156 \begin_layout Standard
3157 /usr/local/share/sdcc/doc
3162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3165 \begin_layout Standard
3186 *compiler, preprocessor, assembler, and linker
3192 is auto-appended by the compiler, e.g.
3193 small, large, z80, ds390 etc
3196 \begin_layout Standard
3198 The install paths can still be changed during `make install' with e.g.:
3201 \begin_layout LyX-Code
3202 make install prefix=$(HOME)/local/sdcc
3205 \begin_layout Standard
3206 Of course this doesn't change the search paths compiled into the binaries.
3211 r the install path can be changed by defining DESTDIR
3212 \begin_inset LatexCommand index
3220 \begin_layout LyX-Code
3221 make install DESTDIR=$(HOME)/sdcc.rpm/
3224 \begin_layout Standard
3225 Please note that DESTDIR must have a trailing slash!
3228 \begin_layout Section
3230 \begin_inset LatexCommand label
3231 name "sub:Search-Paths"
3236 \begin_inset LatexCommand index
3244 \begin_layout Standard
3245 Some search paths or parts of them are determined by configure variables
3250 , see section above).
3251 Further search paths are determined by environment variables during runtime.
3254 The paths searched when running the compiler are as follows (the first
3260 Binary files (preprocessor, assembler and linker)
3265 \begin_layout Standard
3267 \begin_inset Tabular
3268 <lyxtabular version="3" rows="4" columns="3">
3270 <column alignment="block" valignment="top" leftline="true" width="0in">
3271 <column alignment="block" valignment="top" leftline="true" width="0in">
3272 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3273 <row topline="true" bottomline="true">
3274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3277 \begin_layout Standard
3283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3286 \begin_layout Standard
3292 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3295 \begin_layout Standard
3302 <row topline="true">
3303 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3306 \begin_layout Standard
3314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3317 \begin_layout Standard
3323 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3326 \begin_layout Standard
3335 <row topline="true">
3336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3339 \begin_layout Standard
3340 Path of argv[0] (if available)
3345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3348 \begin_layout Standard
3354 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3357 \begin_layout Standard
3364 <row topline="true" bottomline="true">
3365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3368 \begin_layout Standard
3374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3377 \begin_layout Standard
3383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3386 \begin_layout Standard
3402 \begin_layout Standard
3410 \begin_layout Standard
3412 \begin_inset Tabular
3413 <lyxtabular version="3" rows="6" columns="3">
3415 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3416 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3417 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3418 <row topline="true" bottomline="true">
3419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3422 \begin_layout Standard
3428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3431 \begin_layout Standard
3437 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3440 \begin_layout Standard
3447 <row topline="true">
3448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3451 \begin_layout Standard
3456 \begin_layout Standard
3470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3473 \begin_layout Standard
3478 \begin_layout Standard
3492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3495 \begin_layout Standard
3500 \begin_layout Standard
3515 <row topline="true">
3516 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3519 \begin_layout Standard
3525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3528 \begin_layout Standard
3534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3537 \begin_layout Standard
3544 <row topline="true">
3545 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3548 \begin_layout Standard
3560 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3563 \begin_layout Standard
3573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3576 \begin_layout Standard
3585 <row topline="true">
3586 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3589 \begin_layout Standard
3605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3608 \begin_layout Standard
3656 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3659 \begin_layout Standard
3670 <row topline="true" bottomline="true">
3671 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3674 \begin_layout Standard
3688 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3691 \begin_layout Standard
3692 /usr/local/share/sdcc/
3699 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3702 \begin_layout Standard
3718 \begin_layout Standard
3724 \begin_layout Standard
3733 -nostdinc disables the last two search paths.
3743 \begin_layout Standard
3744 With the exception of
3745 \begin_inset Quotes sld
3752 \begin_layout Standard
3762 \begin_inset Quotes srd
3769 is auto-appended by the compiler (e.g.
3770 small, large, z80, ds390 etc.).
3776 \begin_layout Standard
3778 \begin_inset Tabular
3779 <lyxtabular version="3" rows="6" columns="3">
3781 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3782 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3783 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3784 <row topline="true" bottomline="true">
3785 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3788 \begin_layout Standard
3794 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3797 \begin_layout Standard
3803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3806 \begin_layout Standard
3813 <row topline="true">
3814 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3817 \begin_layout Standard
3822 \begin_layout Standard
3836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3839 \begin_layout Standard
3844 \begin_layout Standard
3858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3861 \begin_layout Standard
3866 \begin_layout Standard
3881 <row topline="true">
3882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3885 \begin_layout Standard
3895 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3898 \begin_layout Standard
3908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3911 \begin_layout Standard
3924 <row topline="true">
3925 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3928 \begin_layout Standard
3935 $LIB_DIR_SUFFIX/<model>
3940 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3943 \begin_layout Standard
3955 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3958 \begin_layout Standard
3973 <row topline="true">
3974 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3977 \begin_layout Standard
3988 $LIB_DIR_SUFFIX/<model>
3993 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3996 \begin_layout Standard
4047 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4050 \begin_layout Standard
4104 <row topline="true" bottomline="true">
4105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4108 \begin_layout Standard
4113 $LIB_DIR_SUFFIX/<model>
4118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4121 \begin_layout Standard
4122 /usr/local/share/sdcc/
4131 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4134 \begin_layout Standard
4150 \begin_layout Standard
4151 \begin_inset Note Note
4154 \begin_layout Standard
4155 Don't delete any of the stray spaces in the table above without checking
4156 the HTML output (last line)!
4164 \begin_layout Standard
4172 \begin_layout Standard
4181 -nostdlib disables the last two search paths.
4184 \begin_layout Section
4186 \begin_inset LatexCommand index
4187 name "Building SDCC"
4194 \begin_layout Subsection
4195 Building SDCC on Linux
4196 \begin_inset LatexCommand label
4197 name "sub:Building-SDCC-on-Linux"
4204 \begin_layout Enumerate
4207 Download the source package
4209 either from the SDCC Subversion repository or from snapshot builds
4211 , it will be named something like sdcc
4222 \begin_inset LatexCommand url
4223 target "http://sdcc.sourceforge.net/snap.php"
4230 \begin_layout Enumerate
4233 Bring up a command line terminal, such as xterm.
4236 \begin_layout Enumerate
4239 Unpack the file using a command like:
4244 "tar -xvjf sdcc-src-yyyymmdd-rrrr.tar.bz2
4245 \begin_inset Quotes srd
4251 , this will create a sub-directory called sdcc with all of the sources.
4254 \begin_layout Enumerate
4255 Change directory into the main SDCC directory, for example type:
4263 \begin_layout Enumerate
4275 This configures the package for compilation on your system.
4278 \begin_layout Enumerate
4294 All of the source packages will compile, this can take a while.
4297 \begin_layout Enumerate
4313 This copies the binary executables, the include files, the libraries and
4314 the documentation to the install directories.
4315 Proceed with section
4316 \begin_inset LatexCommand ref
4317 reference "sec:Testing-the-SDCC"
4324 \begin_layout Subsection
4325 Building SDCC on Mac OS X
4328 \begin_layout Standard
4329 Follow the instruction for Linux.
4333 On Mac OS X 10.2.x it was reported, that the
4334 default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
4335 Fortunately there's also gcc 2.9.x installed, which works fine.
4336 This compiler can be selected by running 'configure' with:
4339 \begin_layout LyX-Code
4340 ./configure CC=gcc2 CXX=g++2
4343 \begin_layout Standard
4344 Universal (ppc and i386) binaries can be produced on Mac OS X 10.4.x with
4346 Run 'configure' with:
4349 \begin_layout LyX-Code
4355 \begin_layout LyX-Code
4356 LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4362 \begin_layout LyX-Code
4363 CXXFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4369 \begin_layout LyX-Code
4370 CFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
4373 \begin_layout Subsection
4374 Cross compiling SDCC on Linux for Windows
4377 \begin_layout Standard
4378 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
4379 See section 'Configure Options'.
4382 \begin_layout Subsection
4383 Building SDCC using Cygwin and Mingw32
4386 \begin_layout Standard
4387 For building and installing a Cygwin executable follow the instructions
4393 \begin_inset Quotes sld
4397 \begin_inset Quotes srd
4400 Win32-binary can be built, which will not need the Cygwin-DLL.
4401 For the necessary 'configure' options see section 'configure options' or
4402 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4407 Cygwin on Windows download setup.exe from
4408 \begin_inset LatexCommand url
4409 name "www.cygwin.com"
4410 target "http://www.cygwin.com/"
4416 \begin_inset Quotes sld
4419 default text file type
4420 \begin_inset Quotes srd
4424 \begin_inset Quotes sld
4428 \begin_inset Quotes srd
4431 and download/install at least the following packages.
4432 Some packages are selected by default, others will be automatically selected
4433 because of dependencies with the manually selected packages.
4434 Never deselect these packages!
4437 \begin_layout Itemize
4441 \begin_layout Itemize
4445 \begin_layout Itemize
4446 gcc ; version 3.x is fine, no need to use the old 2.9x
4449 \begin_layout Itemize
4450 binutils ; selected with gcc
4453 \begin_layout Itemize
4457 \begin_layout Itemize
4458 rxvt ; a nice console, which makes life much easier under windoze (see below)
4461 \begin_layout Itemize
4462 man ; not really needed for building SDCC, but you'll miss it sooner or
4466 \begin_layout Itemize
4467 less ; not really needed for building SDCC, but you'll miss it sooner or
4471 \begin_layout Itemize
4472 svn ; only if you use Subversion access
4475 \begin_layout Standard
4476 If you want to develop something you'll need:
4479 \begin_layout Itemize
4480 python ; for the regression tests
4483 \begin_layout Itemize
4484 gdb ; the gnu debugger, together with the nice GUI
4485 \begin_inset Quotes sld
4489 \begin_inset Quotes srd
4495 \begin_layout Itemize
4496 openssh ; to access the CF or commit changes
4499 \begin_layout Itemize
4500 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4501 use autoconf-stable!
4504 \begin_layout Standard
4505 rxvt is a nice console with history.
4506 Replace in your cygwin.bat the line
4509 \begin_layout LyX-Code
4514 \begin_layout Standard
4526 \begin_layout Standard
4530 \begin_layout LyX-Code
4531 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4534 \begin_layout LyX-Code
4535 -bg black -fg white -geometry 100x65 -e bash -
4539 \begin_layout Standard
4551 \begin_layout Standard
4552 Text selected with the mouse is automatically copied to the clipboard, pasting
4553 works with shift-insert.
4557 The other good tip is to make sure you have no //c/-styl
4558 e paths anywhere, use /cygdrive/c/ instead.
4559 Using // invokes a network lookup which is very slow.
4561 \begin_inset Quotes sld
4565 \begin_inset Quotes srd
4568 is too long, you can change it with e.g.
4571 \begin_layout LyX-Code
4575 \begin_layout Standard
4576 SDCC sources use the unix line ending LF.
4577 Life is much easier, if you store the source tree on a drive which is mounted
4579 And use an editor which can handle LF-only line endings.
4580 Make sure not to commit files with windows line endings.
4581 The tabulator spacing
4582 \begin_inset LatexCommand index
4583 name "tabulator spacing (8 columns)"
4587 used in the project is 8.
4588 Although a tabulator spacing of 8 is a sensible choice for programmers
4589 (it's a power of 2 and allows to display 8/16 bit signed variables without
4590 loosing columns) the plan is to move towards using only spaces in the source.
4593 \begin_layout Subsection
4594 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4597 \begin_layout Standard
4600 Download the source package
4602 either from the SDCC Subversion repository or from the
4603 \begin_inset LatexCommand url
4604 name "snapshot builds"
4605 target "http://sdcc.sourceforge.net/snap.php"
4611 , it will be named something like sdcc
4615 -yyyymmdd-rrrr.tar.bz2.
4618 SDCC is distributed with all the projects, workspaces, and files you need
4619 to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4620 The workspace name is 'sdcc.dsw'.
4621 Please note that as it is now, all the executables are created in a folder
4625 Once built you need to copy the executables from sdcc
4629 bin before running SDCC.
4634 WARNING: Visual studio is very picky with line terminations; it expects
4635 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4636 When using the Subversion repository it's easiest to configure the svn
4637 client to convert automatically for you.
4638 If however you are getting a message such as "This makefile was not generated
4639 by Developer Studio etc.
4641 \begin_inset Quotes srd
4644 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4645 need to convert the Unix style line endings to DOS style line endings.
4646 To do so you can use the
4647 \begin_inset Quotes sld
4651 \begin_inset Quotes srd
4654 utility freely available on the internet.
4655 Doug Hawkins reported in the sdcc-user list that this works:
4663 SDCC> unix2dos sdcc.dsw
4669 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4673 In order to build SDCC with MSVC
4674 you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4675 One good place to get them is
4676 \begin_inset LatexCommand url
4678 target "http://unxutils.sourceforge.net"
4686 Download the file UnxUtils
4687 \begin_inset LatexCommand index
4693 Now you have to install the utilities and setup MSVC so it can locate the
4695 Here there are two alternatives (choose one!):
4698 \begin_layout Enumerate
4703 a) Extract UnxUtils.zip to your C:
4705 hard disk PRESERVING the original paths, otherwise bison won't work.
4706 (If you are using WinZip make certain that 'Use folder names' is selected)
4711 In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4712 'Show directories for:' select 'Executable files', and in the directories
4713 window add a new path: 'C:
4723 (As a side effect, you get a bunch of Unix utilities that
4724 could be useful, such as diff and patch.)
4727 \begin_layout Enumerate
4732 This one avoids extracting a bunch of files you may not
4733 use, but requires some extra work:
4737 a) Create a directory were to put the
4738 tools needed, or use a directory already present.
4745 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4746 gawk.exe to such directory WITHOUT preserving the original paths.
4747 (If you are using WinZip make certain that 'Use folder names' is not selected)
4752 ) Rename bison.exe to '_bison.exe'.
4756 d) Create a batch file 'bison.bat' in 'C:
4760 ' and add these lines:
4780 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4784 Steps 'c' and 'd' are needed
4785 because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4786 reside in some weird Unix directory, '/usr/local/share/' I think.
4787 So it is necessary to tell bison where those files are located if they
4788 are not in such directory.
4789 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4794 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4795 in 'Show directories for:' select 'Executable files', and in the directories
4796 window add a new path: 'c:
4799 Note that you can use any other path instead of 'c:
4801 util', even the path where the Visual C++ tools are, probably: 'C:
4805 Microsoft Visual Studio
4810 So you don't have to execute step 'e' :)
4813 \begin_layout Standard
4815 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4816 the executables from sdcc
4820 bin, and you can compile using SDCC.
4823 \begin_layout Subsection
4824 Building SDCC Using Borland
4827 \begin_layout Enumerate
4828 From the sdcc directory, run the command "make -f Makefile.bcc".
4829 This should regenerate all the .exe files in the bin directory except for
4833 \begin_layout Enumerate
4834 If you modify any source files and need to rebuild, be aware that the dependenci
4835 es may not be correctly calculated.
4836 The safest option is to delete all .obj files and run the build again.
4837 From a Cygwin BASH prompt, this can easily be done with the command (be
4838 sure you are in the sdcc directory):
4848 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
4850 ) -print -exec rm {}
4859 or on Windows NT/2000/XP from the command prompt with the command:
4866 del /s *.obj *.lib *.rul
4869 from the sdcc directory.
4872 \begin_layout Subsection
4873 Windows Install Using a ZIP Package
4876 \begin_layout Enumerate
4877 Download the binary zip package from
4878 \begin_inset LatexCommand url
4879 target "http://sdcc.sf.net/snap.php"
4883 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4884 This should unpack to a group of sub-directories.
4885 An example directory structure after unpacking the mingw32 package is:
4890 bin for the executables, c:
4898 lib for the include and libraries.
4901 \begin_layout Enumerate
4902 Adjust your environment variable PATH to include the location of the bin
4903 directory or start sdcc using the full path.
4906 \begin_layout Subsection
4907 Windows Install Using the Setup Program
4908 \begin_inset LatexCommand label
4909 name "sub:Windows-Install"
4916 \begin_layout Standard
4917 Download the setup program
4919 sdcc-x.y.z-setup.exe
4921 for an official release from
4924 \begin_inset LatexCommand url
4925 target "http://sf.net/project/showfiles.php?group_id=599"
4929 or a setup program for one of the snapshots
4931 sdcc-yyyymmdd-xxxx-setup.exe
4934 \begin_inset LatexCommand url
4935 target "http://sdcc.sf.net/snap.php"
4940 A windows typical installer will guide you through the installation process.
4943 \begin_layout Subsection
4945 \begin_inset LatexCommand index
4953 \begin_layout Standard
4954 SDCC supports the VPATH feature provided by configure and make.
4955 It allows to separate the source and build trees.
4959 \begin_layout Standard
5001 \begin_layout Standard
5004 tar -xjf sdcc-src-yyyymmdd-rrrr.tar.bz2\InsetSpace ~
5005 # extract source to directory sdcc
5008 \begin_layout Standard
5011 mkdir sdcc.build\InsetSpace ~
5035 # put output in sdcc.build
5038 \begin_layout Standard
5044 \begin_layout Standard
5047 ../sdcc/configure\InsetSpace ~
5070 # configure is doing all the magic!
5073 \begin_layout Standard
5079 \begin_layout Standard
5085 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
5086 It automagically computes the variables srcdir, top_srcdir and top_buildir
5092 the generated files will be in ~/sdcc.build, while the source files stay
5095 This is not only usefull for building different binaries, e.g.
5096 when cross compiling.
5097 It also gives you a much better overview in the source tree when all the
5098 generated files are not scattered between the source files.
5099 And the best thing is: if you want to change a file you can leave the original
5100 file untouched in the source directory.
5101 Simply copy it to the build directory, edit it, enter `make clean', `rm
5102 Makefile.dep' and `make'.
5107 will do the rest for you!
5110 \begin_layout Section
5111 Building the Documentation
5114 \begin_layout Standard
5119 \begin_layout Standard
5128 -enable-doc to the configure arguments to build the documentation together
5129 with all the other stuff.
5130 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
5131 dvips and makeindex) to get the job done.
5132 Another possibility is to change to the doc directory and to type
5136 \begin_inset Quotes srd
5140 \begin_inset Quotes srd
5147 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
5150 \begin_inset LatexCommand url
5151 target "http://www.lyx.org"
5155 as editor is straightforward.
5156 Prebuilt documentation in html and pdf format is available from
5157 \begin_inset LatexCommand url
5158 target "http://sdcc.sf.net/snap.php"
5165 \begin_layout Section
5166 Reading the Documentation
5167 \begin_inset LatexCommand index
5168 name "Documentation"
5175 \begin_layout Standard
5176 Currently reading the document in pdf format is recommended, as for unknown
5177 reason the hyperlinks are working there whereas in the html version they
5182 \begin_layout Standard
5183 If you should know why please drop us a note
5191 You'll find the pdf version
5192 \begin_inset LatexCommand index
5193 name "PDF version of this document"
5198 \begin_inset LatexCommand url
5199 target "http://sdcc.sf.net/doc/sdccman.pdf"
5207 \begin_inset LatexCommand index
5208 name "HTML version of this document"
5213 \begin_inset LatexCommand url
5214 target "http://sdcc.sf.net/doc/sdccman.html/index.html"
5220 This documentation is in some aspects different from a commercial documentation:
5224 \begin_layout Itemize
5225 It tries to document SDCC for several processor architectures in one document
5226 (commercially these probably would be separate documents/products).
5228 \begin_inset LatexCommand index
5229 name "Status of documentation"
5233 currently matches SDCC for mcs51 and DS390 best and does give too few informati
5235 Z80, PIC14, PIC16 and HC08.
5238 \begin_layout Itemize
5239 There are many references pointing away from this documentation.
5240 Don't let this distract you.
5242 was a reference like
5243 \begin_inset LatexCommand url
5244 target "http://www.opencores.org"
5248 together with a statement
5249 \begin_inset Quotes sld
5252 some processors which are targetted by SDCC can be implemented in a
5269 \begin_inset LatexCommand index
5270 name "FPGA (field programmable gate array)"
5275 \begin_inset Quotes srd
5279 \begin_inset LatexCommand url
5280 target "http://sf.net/projects/fpgac"
5285 \begin_inset LatexCommand index
5286 name "FpgaC ((subset of) C to FPGA compiler)"
5291 \begin_inset Quotes sld
5294 have you ever heard of an open source compiler that compiles a subset of
5296 \begin_inset Quotes srd
5299 we expect you to have a quick look there and come back.
5300 If you read this you are on the right track.
5303 \begin_layout Itemize
5304 Some sections attribute more space to problems, restrictions and warnings
5305 than to the solution.
5308 \begin_layout Itemize
5309 The installation section and the section about the debugger is intimidating.
5312 \begin_layout Itemize
5313 There are still lots of typos and there are more different writing styles
5317 \begin_layout Section
5318 Testing the SDCC Compiler
5319 \begin_inset LatexCommand label
5320 name "sec:Testing-the-SDCC"
5327 \begin_layout Standard
5328 The first thing you should do after installing your SDCC compiler is to
5337 \begin_layout Standard
5347 \begin_inset LatexCommand index
5355 at the prompt, and the program should run and output its version like:
5360 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
5364 \begin_layout Standard
5365 If it doesn't run, or gives a message about not finding sdcc program, then
5366 you need to check over your installation.
5367 Make sure that the sdcc bin directory is in your executable search path
5368 defined by the PATH environment setting (
5373 \begin_inset LatexCommand ref
5374 reference "sub:Install-Trouble-shooting"
5381 Install trouble-shooting for suggestions
5384 Make sure that the sdcc program is in the bin folder, if not perhaps something
5385 did not install correctly.
5393 is commonly installed as described in section
5394 \begin_inset Quotes sld
5397 Install and search paths
5398 \begin_inset Quotes srd
5407 Make sure the compiler works on a very simple example.
5408 Type in the following test.c program using your favorite
5433 \begin_layout Standard
5436 Compile this using the following command:
5447 If all goes well, the compiler will generate a test.asm and test.rel file.
5448 Congratulations, you've just compiled your first program with SDCC.
5449 We used the -c option to tell SDCC not to link the generated code, just
5450 to keep things simple for this step.
5458 The next step is to try it with the linker.
5470 If all goes well the compiler will link with the libraries and produce
5471 a test.ihx output file.
5476 (no test.ihx, and the linker generates warnings), then the problem is most
5485 usr/local/share/sdcc/lib directory
5492 \begin_inset LatexCommand ref
5493 reference "sub:Install-Trouble-shooting"
5500 Install trouble-shooting for suggestions).
5508 The final test is to ensure
5516 header files and libraries.
5517 Edit test.c and change it to the following:
5535 strcpy(str1, "testing");
5540 \begin_layout Standard
5543 Compile this by typing
5552 This should generate a test.ihx output file, and it should give no warnings
5553 such as not finding the string.h file.
5554 If it cannot find the string.h file, then the problem is that
5558 cannot find the /usr/local/share/sdcc/include directory
5565 \begin_inset LatexCommand ref
5566 reference "sub:Install-Trouble-shooting"
5573 Install trouble-shooting section for suggestions).
5582 \begin_layout Standard
5594 \begin_inset LatexCommand index
5595 name "-\\/-print-search-dirs"
5599 to find exactly where SDCC is looking for the include and lib files.
5602 \begin_layout Section
5603 Install Trouble-shooting
5604 \begin_inset LatexCommand label
5605 name "sub:Install-Trouble-shooting"
5610 \begin_inset LatexCommand index
5611 name "Install trouble-shooting"
5618 \begin_layout Subsection
5619 If SDCC does not build correctly
5622 \begin_layout Standard
5623 A thing to try is starting from scratch by unpacking the .tgz source package
5624 again in an empty directory.
5632 ./configure 2>&1 | tee configure.log
5646 make 2>&1 | tee make.log
5653 If anything goes wrong, you can review the log files to locate the problem.
5654 Or a relevant part of this can be attached to an email that could be helpful
5655 when requesting help from the mailing list.
5658 \begin_layout Subsection
5660 \begin_inset Quotes sld
5664 \begin_inset Quotes srd
5670 \begin_layout Standard
5672 \begin_inset Quotes sld
5676 \begin_inset Quotes srd
5679 command is a script that analyzes your system and performs some configuration
5680 to ensure the source package compiles on your system.
5681 It will take a few minutes to run, and will compile a few tests to determine
5682 what compiler features are installed.
5685 \begin_layout Subsection
5687 \begin_inset Quotes sld
5691 \begin_inset Quotes srd
5697 \begin_layout Standard
5698 This runs the GNU make tool, which automatically compiles all the source
5699 packages into the final installed binary executables.
5702 \begin_layout Subsection
5704 \begin_inset Quotes sld
5708 \begin_inset Quotes erd
5714 \begin_layout Standard
5715 This will install the compiler, other executables libraries and include
5716 files into the appropriate directories.
5718 \begin_inset LatexCommand ref
5719 reference "sub:Install-paths"
5725 \begin_inset LatexCommand ref
5726 reference "sub:Search-Paths"
5731 about install and search paths.
5733 On most systems you will need super-user privilege
5737 \begin_layout Section
5741 \begin_layout Standard
5742 SDCC is not just a compiler, but a collection of tools by various developers.
5743 These include linkers, assemblers, simulators and other components.
5744 Here is a summary of some of the components.
5745 Note that the included simulator and assembler have separate documentation
5746 which you can find in the source package in their respective directories.
5747 As SDCC grows to include support for other processors, other packages from
5748 various developers are included and may have their own sets of documentation.
5753 might want to look at the files which are installed in <installdir>.
5754 At the time of this writing, we find the following programs for gcc-builds:
5759 In <installdir>/bin:
5762 \begin_layout Itemize
5763 sdcc - The compiler.
5766 \begin_layout Itemize
5767 sdcpp - The C preprocessor.
5770 \begin_layout Itemize
5771 asx8051 - The assembler for 8051 type processors.
5774 \begin_layout Itemize
5779 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5782 \begin_layout Itemize
5783 aslink -The linker for 8051 type processors.
5786 \begin_layout Itemize
5791 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5794 \begin_layout Itemize
5795 s51 - The ucSim 8051 simulator.
5798 \begin_layout Itemize
5799 sdcdb - The source debugger.
5802 \begin_layout Itemize
5803 packihx - A tool to pack (compress) Intel hex files.
5806 \begin_layout Standard
5807 In <installdir>/share/sdcc/include
5810 \begin_layout Itemize
5814 \begin_layout Standard
5815 In <installdir>/share/sdcc/lib
5818 \begin_layout Itemize
5819 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5823 \begin_layout Standard
5824 In <installdir>/share/sdcc/doc
5827 \begin_layout Itemize
5831 \begin_layout Standard
5832 As development for other processors proceeds, this list will expand to include
5833 executables to support processors like AVR, PIC, etc.
5836 \begin_layout Subsection
5840 \begin_layout Standard
5841 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5842 the assembler and linkage editor.
5845 \begin_layout Subsection
5846 sdcpp - The C-Preprocessor
5849 \begin_layout Standard
5851 \begin_inset LatexCommand index
5852 name "sdcpp (preprocessor)"
5856 is a modified version of the GNU cpp
5857 \begin_inset LatexCommand index
5858 name "cpp|see{sdcpp}"
5863 \begin_inset LatexCommand url
5864 target "http://gcc.gnu.org/"
5869 The C preprocessor is used to pull in #include sources, process #ifdef
5870 statements, #defines and so on.
5873 \begin_layout Subsection
5882 - The Assemblers and Linkage Editors
5885 \begin_layout Standard
5886 This is retargettable assembler & linkage editor, it was developed by Alan
5888 John Hartman created the version for 8051, and I (Sandeep) have made some
5889 enhancements and bug fixes for it to work properly with SDCC.
5892 \begin_layout Subsection
5896 \begin_layout Standard
5898 \begin_inset LatexCommand index
5903 is a free open source simulator developed by Daniel Drotos.
5904 The simulator is built as part of the build process.
5905 For more information visit Daniel's web site at:
5906 \begin_inset LatexCommand url
5907 target "http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51"
5912 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5916 \begin_layout Subsection
5917 sdcdb - Source Level Debugger
5920 \begin_layout Standard
5922 \begin_inset LatexCommand index
5923 name "SDCDB (debugger)"
5927 is the companion source level debugger.
5928 More about SDCDB in section
5929 \begin_inset LatexCommand ref
5930 reference "cha:Debugging-with-SDCDB"
5935 The current version of the debugger uses Daniel's Simulator S51
5936 \begin_inset LatexCommand index
5941 , but can be easily changed to use other simulators.
5944 \begin_layout Chapter
5948 \begin_layout Section
5952 \begin_layout Subsection
5953 Single Source File Projects
5956 \begin_layout Standard
5957 For single source file 8051 projects the process is very simple.
5958 Compile your programs with the following command
5961 "sdcc sourcefile.c".
5965 This will compile, assemble and link your source file.
5966 Output files are as follows:
5969 \begin_layout Itemize
5971 \begin_inset LatexCommand index
5977 \begin_inset LatexCommand index
5978 name "Assembler source"
5982 file created by the compiler
5985 \begin_layout Itemize
5987 \begin_inset LatexCommand index
5993 \begin_inset LatexCommand index
5994 name "Assembler listing"
5998 file created by the Assembler
6001 \begin_layout Itemize
6003 \begin_inset LatexCommand index
6009 \begin_inset LatexCommand index
6010 name "Assembler listing"
6014 file updated with linkedit information, created by linkage editor
6017 \begin_layout Itemize
6019 \begin_inset LatexCommand index
6025 \begin_inset LatexCommand index
6026 name "Symbol listing"
6030 for the sourcefile, created by the assembler
6033 \begin_layout Itemize
6035 \begin_inset LatexCommand index
6041 \begin_inset LatexCommand index
6047 \begin_inset LatexCommand index
6052 created by the assembler, input to Linkage editor
6055 \begin_layout Itemize
6057 \begin_inset LatexCommand index
6063 \begin_inset LatexCommand index
6068 for the load module, created by the Linker
6071 \begin_layout Itemize
6073 \begin_inset LatexCommand index
6078 - A file with a summary of the memory usage
6081 \begin_layout Itemize
6083 \begin_inset LatexCommand index
6088 - The load module in Intel hex format
6089 \begin_inset LatexCommand index
6090 name "Intel hex format"
6094 (you can select the Motorola S19 format
6095 \begin_inset LatexCommand index
6096 name "Motorola S19 format"
6104 \begin_layout Standard
6114 \begin_inset LatexCommand index
6115 name "-\\/-out-fmt-s19"
6120 If you need another format you might want to use
6127 \begin_inset LatexCommand index
6128 name "objdump (tool)"
6139 \begin_inset LatexCommand index
6140 name "srecord (bin, hex, ... tool)"
6145 \begin_inset Note Note
6148 \begin_layout Standard
6155 \begin_inset LatexCommand vref
6156 reference "sub:Postprocessing-the-Intel"
6161 Both formats are documented in the documentation of srecord
6162 \begin_inset LatexCommand index
6163 name "srecord (bin, hex, ... tool)"
6170 \begin_layout Itemize
6172 \begin_inset LatexCommand index
6177 - An intermediate file containing debug information needed to create the
6182 \begin_layout Standard
6192 \begin_inset LatexCommand index
6200 \begin_layout Itemize
6202 \begin_inset LatexCommand index
6207 - An optional file (with -
6211 \begin_layout Standard
6220 -debug) containing debug information.
6221 The format is documented in cdbfileformat.pdf
6224 \begin_layout Itemize
6227 \begin_inset LatexCommand index
6228 name "<file> (no extension)"
6232 An optional AOMF or AOMF51
6233 \begin_inset LatexCommand index
6239 \begin_inset LatexCommand label
6244 file containing debug information (generated with option -
6248 \begin_layout Standard
6274 ormat is a subformat of the OMF51 format and is commonly used by third party
6276 \begin_inset LatexCommand index
6281 , simulators, emulators).
6284 \begin_layout Itemize
6286 \begin_inset LatexCommand index
6291 - Dump file to debug the compiler it self (generated with option -
6295 \begin_layout Standard
6304 -dumpall) (see section
6305 \begin_inset LatexCommand ref
6306 reference "sub:Intermediate-Dump-Options"
6312 \begin_inset LatexCommand ref
6313 reference "sub:The-anatomy-of"
6319 \begin_inset Quotes sld
6322 Anatomy of the compiler
6323 \begin_inset Quotes srd
6329 \begin_layout Subsection
6330 Postprocessing the Intel Hex
6331 \begin_inset LatexCommand index
6332 name "Intel hex format"
6337 \begin_inset LatexCommand label
6338 name "sub:Postprocessing-the-Intel"
6345 \begin_layout Standard
6346 In most cases this won't be needed but the Intel Hex file
6347 \begin_inset LatexCommand index
6352 which is generated by SDCC might include lines of varying length and the
6353 addresses within the file are not guaranteed to be strictly ascending.
6354 If your toolchain or a bootloader does not like this you can use the tool
6360 \begin_inset LatexCommand index
6361 name "packihx (tool)"
6365 which is part of the SDCC distribution:
6372 packihx sourcefile.ihx >sourcefile.hex
6379 The separately available
6384 \begin_inset LatexCommand index
6385 name "srecord (bin, hex, ... tool)"
6389 package additionally allows to set undefined locations to a predefined
6390 value, to insert checksums
6391 \begin_inset LatexCommand index
6396 of various flavours (crc, add, xor) and to perform other manipulations
6397 (convert, split, crop, offset, ...).
6405 srec_cat\InsetSpace ~
6407 sourcefile.ihx -intel\InsetSpace ~
6409 -o sourcefile.hex -intel
6416 An example for a more complex command line
6420 \begin_layout Standard
6421 the command backfills
6422 \begin_inset LatexCommand index
6423 name "backfill unused memory"
6427 unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
6429 If the program counter on an mcs51 runs wild the backfill pattern 0x12
6430 will be interpreted as an
6438 (where an emergency routine could sit).
6451 srec_cat\InsetSpace ~
6452 sourcefile.ihx -intel\InsetSpace ~
6454 -fill 0x12 0x0000 0xfffe\InsetSpace ~
6455 -little-endian-checksum-nega
6456 tive 0xfffe 0x02 0x02\InsetSpace ~
6458 -o sourcefile.hex -intel
6467 The srecord package is available at
6468 \begin_inset LatexCommand url
6469 target "http://sf.net/projects/srecord"
6476 \begin_layout Subsection
6477 Projects with Multiple Source Files
6480 \begin_layout Standard
6481 SDCC can compile only ONE file at a time.
6482 Let us for example assume that you have a project containing the following
6487 foo1.c (contains some functions)
6489 foo2.c (contains some more functions)
6492 n.c (contains more functions and the function main)
6500 The first two files will need to be compiled separately with the commands:
6532 Then compile the source file containing the
6537 \begin_inset LatexCommand index
6542 the files together with the following command:
6550 foomain.c\InsetSpace ~
6551 foo1.rel\InsetSpace ~
6556 \begin_inset LatexCommand index
6569 can be separately compiled as well:
6580 sdcc foomain.rel foo1.rel foo2.rel
6587 The file containing the
6599 file specified in the command line, since the linkage editor processes
6600 file in the order they are presented to it.
6601 The linker is invoked from SDCC using a script file with extension .lnk
6602 \begin_inset LatexCommand index
6608 You can view this file to troubleshoot linking problems such as those arising
6609 from missing libraries.
6612 \begin_layout Subsection
6613 Projects with Additional Libraries
6614 \begin_inset LatexCommand index
6622 \begin_layout Standard
6623 Some reusable routines may be compiled into a library, see the documentation
6624 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6628 \begin_inset LatexCommand index
6636 Libraries created in this manner can be included in the command line.
6637 Make sure you include the -L <library-path> option to tell the linker where
6638 to look for these files if they are not in the current directory.
6639 Here is an example, assuming you have the source file
6651 (if that is not the same as your current project):
6658 sdcc foomain.c foolib.lib -L mylib
6669 must be an absolute path name.
6673 The most efficient way to use libraries is
6674 to keep separate modules in separate source files.
6675 The lib file now should name all the modules.rel
6676 \begin_inset LatexCommand index
6682 For an example see the standard library file
6686 in the directory <installdir>/share/lib/small.
6689 \begin_layout Subsection
6690 Using sdcclib to Create and Manage Libraries
6691 \begin_inset LatexCommand index
6699 \begin_layout Standard
6700 Alternatively, instead of having a .rel file for each entry on the library
6701 file as described in the preceding section, sdcclib can be used to embed
6702 all the modules belonging to such library in the library file itself.
6703 This results in a larger library file, but it greatly reduces the number
6704 of disk files accessed by the linker.
6705 Additionally, the packed library file contains an index of all include
6706 modules and symbols that significantly speeds up the linking process.
6707 To display a list of options supported by sdcclib type:
6712 \begin_layout Standard
6717 \begin_inset LatexCommand index
6729 To create a new library file, start by compiling all the required modules.
6735 \begin_layout Standard
6742 \begin_layout Standard
6749 \begin_layout Standard
6756 \begin_layout Standard
6763 \begin_layout Standard
6772 \begin_layout Standard
6773 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6775 The next step is to add the .rel files to the library file:
6780 \begin_layout Standard
6784 sdcclib libint.lib _divsint.rel
6787 \begin_inset LatexCommand index
6795 \begin_layout Standard
6799 sdcclib libint.lib _divuint.rel
6802 \begin_layout Standard
6806 sdcclib libint.lib _modsint.rel
6809 \begin_layout Standard
6813 sdcclib libint.lib _moduint.rel
6816 \begin_layout Standard
6820 sdcclib libint.lib _mulint.rel
6828 \begin_layout Standard
6837 \begin_layout Standard
6841 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6849 \begin_layout Standard
6850 If the file already exists in the library, it will be replaced.
6851 If a list of .rel files is available, you can tell sdcclib to add those
6853 For example, if the file 'myliblist.txt' contains
6861 \begin_layout Standard
6868 \begin_layout Standard
6875 \begin_layout Standard
6882 \begin_layout Standard
6889 \begin_layout Standard
6901 \begin_layout Standard
6910 \begin_layout Standard
6914 sdcclib -l libint.lib myliblist.txt
6922 \begin_layout Standard
6923 Additionally, you can instruct sdcclib to compiles the files before adding
6924 them to the library.
6925 This is achieved using the environment variables SDCCLIB_CC and/or SDCCLIB_AS.
6934 \begin_layout Standard
6938 set SDCCLIB_CC=sdcc -c
6941 \begin_layout Standard
6945 sdcclib -l libint.lib myliblist.txt
6953 \begin_layout Standard
6954 To see what modules and symbols are included in the library, options -s
6955 and -m are available.
6963 sdcclib -s libint.lib
6966 \begin_inset LatexCommand index
6979 \begin_layout Standard
6985 \begin_layout Standard
6991 \begin_layout Standard
6999 \begin_layout Standard
7005 \begin_layout Standard
7011 \begin_layout Standard
7017 \begin_layout Standard
7023 \begin_layout Standard
7031 \begin_layout Standard
7037 \begin_layout Standard
7043 \begin_layout Standard
7051 \begin_layout Standard
7057 \begin_layout Standard
7063 \begin_layout Standard
7069 \begin_layout Standard
7077 \begin_layout Standard
7083 \begin_layout Standard
7094 \begin_layout Standard
7095 If the source files are compiled using -
7099 \begin_layout Standard
7109 \begin_inset LatexCommand index
7114 , the corresponding debug information file .adb will be include in the library
7116 The library files created with sdcclib are plain text files, so they can
7117 be viewed with a text editor.
7118 It is not recommended to modify a library file created with sdcclib using
7119 a text editor, as there are file indexes numbers located across the file
7120 used by the linker to quickly locate the required module to link.
7121 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
7122 it can be safely deleted, since all the information required for linking
7123 is embedded in the library file itself.
7124 Library files created using sdcclib are used as described in the preceding
7128 \begin_layout Subsection
7129 Using ar to Create and Manage Libraries
7130 \begin_inset LatexCommand index
7138 \begin_layout Standard
7139 Support for ar format libraries was introduced in sdcc 2.9.0.
7140 Ar is a standard archive managing utility on unices (Linux, Mac OS X, several
7141 unix flavors) so it is not included in the sdcc package.
7149 For Windows platform you can find ar utility in GNU binutils package included
7150 in several projects: Cygwin at
7151 \begin_inset LatexCommand url
7152 target "http://www.cygwin.com/"
7157 \begin_inset LatexCommand url
7158 target "http://www.mingw.org/"
7170 Both the GNU and BSD ar format variants are suppurated by asxxxx linkers.
7171 Ar doesn't understand the asxxxx object file format, so there is a special
7172 version of ranlib distributed with sdcc, called asranlib, which produces
7173 the ar symbol lookup table.
7181 To create a library containing asxxxx object files, you should use the following
7189 \begin_layout Standard
7193 ar -Sq <library name>.lib <list of .rel files>
7196 \begin_layout Standard
7200 asranlib <library name>.lib
7203 \begin_layout Standard
7204 \begin_inset VSpace bigskip
7210 \begin_layout Section
7211 Command Line Options
7212 \begin_inset LatexCommand index
7213 name "Command Line Options"
7218 \begin_inset LatexCommand label
7219 name "sec:Command-Line-Options"
7226 \begin_layout Subsection
7227 Processor Selection Options
7228 \begin_inset LatexCommand index
7229 name "Options processor selection"
7234 \begin_inset LatexCommand index
7235 name "Processor selection options"
7243 \labelwidthstring 00.00.0000
7247 \begin_inset LatexCommand index
7254 Generate code for the Intel MCS51
7255 \begin_inset LatexCommand index
7260 family of processors.
7261 This is the default processor target.
7265 \labelwidthstring 00.00.0000
7269 \begin_inset LatexCommand index
7276 Generate code for the Dallas DS80C390
7277 \begin_inset LatexCommand index
7286 \labelwidthstring 00.00.0000
7290 \begin_inset LatexCommand index
7297 Generate code for the Dallas DS80C400
7298 \begin_inset LatexCommand index
7307 \labelwidthstring 00.00.0000
7311 \begin_inset LatexCommand index
7318 Generate code for the Freescale/Motorola HC08
7319 \begin_inset LatexCommand index
7324 family of processors.
7328 \labelwidthstring 00.00.0000
7332 \begin_inset LatexCommand index
7339 Generate code for the Zilog Z80
7340 \begin_inset LatexCommand index
7345 family of processors.
7349 \labelwidthstring 00.00.0000
7353 \begin_inset LatexCommand index
7360 Generate code for the GameBoy Z80
7361 \begin_inset LatexCommand index
7362 name "gbz80 (GameBoy Z80)"
7366 processor (Not actively maintained).
7370 \labelwidthstring 00.00.0000
7374 \begin_inset LatexCommand index
7381 Generate code for the Atmel AVR
7382 \begin_inset LatexCommand index
7387 processor (Not maintained, not complete).
7388 AVR users should probably have a look at winavr
7389 \begin_inset LatexCommand url
7390 target "http://sourceforge.net/projects/winavr"
7395 \begin_inset LatexCommand url
7396 target "http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index"
7400 , which is based on AVR-port of the gcc compiler.
7403 \begin_layout Standard
7404 \begin_inset Note Note
7407 \begin_layout Standard
7408 I think it is fair to direct users there for now.
7409 Open source is also about avoiding unnecessary work .
7410 But I didn't find the 'official' link.
7419 \labelwidthstring 00.00.0000
7423 \begin_inset LatexCommand index
7430 Generate code for the Microchip PIC 14
7431 \begin_inset LatexCommand index
7436 -bit processors (p16f84 and variants.
7437 In development, not complete).
7440 \begin_layout Standard
7441 \begin_inset Note Note
7444 \begin_layout Standard
7445 p16f627 p16f628 p16f84 p16f873 p16f877?
7454 \labelwidthstring 00.00.0000
7458 \begin_inset LatexCommand index
7465 Generate code for the Microchip PIC 16
7466 \begin_inset LatexCommand index
7471 -bit processors (p18f452 and variants.
7472 In development, not complete).
7476 \labelwidthstring 00.00.0000
7481 Generate code for the Toshiba TLCS-900H
7482 \begin_inset LatexCommand index
7487 processor (Not maintained, not complete).
7491 \labelwidthstring 00.00.0000
7495 \begin_inset LatexCommand index
7502 Generate code for the Phillips XA51
7503 \begin_inset LatexCommand index
7508 processor (Not maintained, not complete).
7511 \begin_layout Standard
7512 \begin_inset VSpace bigskip
7518 \begin_layout Subsection
7519 Preprocessor Options
7520 \begin_inset LatexCommand index
7521 name "Options preprocessor"
7526 \begin_inset LatexCommand index
7527 name "Preprocessor options"
7532 \begin_inset LatexCommand index
7533 name "sdcpp (preprocessor)"
7541 \labelwidthstring 00.00.0000
7545 \begin_inset LatexCommand index
7552 The additional location where the preprocessor will look for <..h> or
7553 \begin_inset Quotes eld
7557 \begin_inset Quotes erd
7564 \labelwidthstring 00.00.0000
7568 \begin_inset LatexCommand index
7569 name "-D<macro[=value]>"
7575 Command line definition of macros.
7576 Passed to the preprocessor.
7580 \labelwidthstring 00.00.0000
7584 \begin_inset LatexCommand index
7591 Tell the preprocessor to output a rule suitable for make describing the
7592 dependencies of each object file.
7593 For each source file, the preprocessor outputs one make-rule whose target
7594 is the object file name for that source file and whose dependencies are
7595 all the files `#include'd in it.
7596 This rule may be a single line or may be continued with `
7598 '-newline if it is long.
7599 The list of rules is printed on standard output instead of the preprocessed
7602 \begin_inset LatexCommand index
7611 \labelwidthstring 00.00.0000
7615 \begin_inset LatexCommand index
7622 Tell the preprocessor not to discard comments.
7623 Used with the `-E' option.
7627 \labelwidthstring 00.00.0000
7631 \begin_inset LatexCommand index
7641 Like `-M' but the output mentions only the user header files included with
7643 \begin_inset Quotes eld
7647 System header files included with `#include <file>' are omitted.
7651 \labelwidthstring 00.00.0000
7655 \begin_inset LatexCommand index
7656 name "-Aquestion(answer)"
7662 Assert the answer answer for question, in case it is tested with a preprocessor
7663 conditional such as `#if #question(answer)'.
7664 `-A-' disables the standard assertions that normally describe the target
7669 \labelwidthstring 00.00.0000
7673 \begin_inset LatexCommand index
7680 Undefine macro macro.
7681 `-U' options are evaluated after all `-D' options, but before any `-include'
7682 and `-imacros' options.
7686 \labelwidthstring 00.00.0000
7690 \begin_inset LatexCommand index
7697 Tell the preprocessor to output only a list of the macro definitions that
7698 are in effect at the end of preprocessing.
7699 Used with the `-E' option.
7703 \labelwidthstring 00.00.0000
7707 \begin_inset LatexCommand index
7714 Tell the preprocessor to pass all macro definitions into the output, in
7715 their proper sequence in the rest of the output.
7719 \labelwidthstring 00.00.0000
7723 \begin_inset LatexCommand index
7733 Like `-dD' except that the macro arguments and contents are omitted.
7734 Only `#define name' is included in the output.
7738 \labelwidthstring 00.00.0000
7741 -pedantic-parse-number
7742 \begin_inset LatexCommand index
7748 \begin_inset LatexCommand index
7749 name "-pedantic-parse-number"
7757 \begin_inset LatexCommand label
7758 name "lyx:-pedantic-parse-number"
7767 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7768 and the macro LO_B(3) gets expanded.
7769 See also #pragma pedantic_parse_number
7770 \begin_inset LatexCommand vpageref
7771 reference "ite:pedantic_parse_number"
7776 \begin_inset LatexCommand ref
7777 reference "sec:Pragmas"
7783 Note: this functionality is not in conformance with C99 standard!
7787 \labelwidthstring 00.00.0000
7791 preprocessorOption[,preprocessorOption]
7794 \begin_inset LatexCommand index
7795 name "-Wp preprocessorOption[,preprocessorOption]"
7800 Pass the preprocessorOption to the preprocessor
7805 \begin_inset LatexCommand index
7806 name "sdcpp (preprocessor)"
7811 SDCC uses an adapted version of the GNU Compiler Collection
7812 \begin_inset LatexCommand index
7813 name "gcc (GNU Compiler Collection)"
7826 \begin_inset LatexCommand url
7827 target "http://gcc.gnu.org/"
7832 If you need more dedicated options please refer to the GCC\InsetSpace ~
7836 \begin_inset LatexCommand htmlurl
7837 target "http://www.gnu.org/software/gcc/onlinedocs/"
7844 \begin_layout Standard
7845 \begin_inset VSpace bigskip
7851 \begin_layout Subsection
7853 \begin_inset LatexCommand index
7854 name "Options linker"
7859 \begin_inset LatexCommand index
7860 name "Linker options"
7868 \labelwidthstring 00.00.0000
7878 \begin_layout Standard
7890 \begin_inset LatexCommand index
7891 name "-\\/-lib-path <path>"
7896 \begin_inset LatexCommand index
7904 <absolute path to additional libraries> This option is passed to the linkage
7905 editor's additional libraries
7906 \begin_inset LatexCommand index
7912 The path name must be absolute.
7913 Additional library files may be specified in the command line.
7914 See section Compiling programs for more details.
7918 \labelwidthstring 00.00.0000
7925 \begin_layout Standard
7937 \begin_inset LatexCommand index
7938 name "-\\/-xram-loc <Value>"
7943 <Value> The start location of the external ram
7944 \begin_inset LatexCommand index
7945 name "xdata (mcs51, ds390 storage class)"
7949 , default value is 0.
7950 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7954 \begin_layout Standard
7963 -xram-loc 0x8000 or -
7967 \begin_layout Standard
7980 \labelwidthstring 00.00.0000
7987 \begin_layout Standard
7999 \begin_inset LatexCommand index
8000 name "-\\/-code-loc <Value>"
8005 <Value> The start location of the code
8006 \begin_inset LatexCommand index
8011 segment, default value 0.
8012 Note when this option is used the interrupt vector table
8013 \begin_inset LatexCommand index
8014 name "interrupt vector table"
8018 is also relocated to the given address.
8019 The value entered can be in Hexadecimal or Decimal format, e.g.: -
8023 \begin_layout Standard
8032 -code-loc 0x8000 or -
8036 \begin_layout Standard
8049 \labelwidthstring 00.00.0000
8056 \begin_layout Standard
8068 \begin_inset LatexCommand index
8069 name "-\\/-stack-loc <Value>"
8074 <Value> By default the stack
8075 \begin_inset LatexCommand index
8080 is placed after the data segment.
8081 Using this option the stack can be placed anywhere in the internal memory
8083 The value entered can be in Hexadecimal or Decimal format, e.g.
8088 \begin_layout Standard
8097 -stack-loc 0x20 or -
8101 \begin_layout Standard
8111 Since the sp register is incremented before a push or call, the initial
8112 sp will be set to one byte prior the provided value.
8113 The provided value should not overlap any other memory areas such as used
8114 register banks or the data segment and with enough space for the current
8122 \begin_layout Standard
8135 \begin_inset LatexCommand index
8136 name "-\\/-pack-iram"
8140 option (which is now a default setting) will override this setting, so
8141 you should also specify the
8147 \begin_layout Standard
8160 \begin_inset LatexCommand index
8161 name "-\\/-no-pack-iram"
8165 option if you need to manually place the stack.
8169 \labelwidthstring 00.00.0000
8176 \begin_layout Standard
8188 \begin_inset LatexCommand index
8189 name "-\\/-xstack-loc <Value>"
8194 <Value> By default the external stack
8195 \begin_inset LatexCommand index
8200 is placed after the pdata
8201 \begin_inset LatexCommand index
8202 name "pdata (mcs51, ds390 storage class)"
8207 Using this option the xstack can be placed anywhere in the external memory
8209 The value entered can be in Hexadecimal or Decimal format, e.g.
8214 \begin_layout Standard
8223 -xstack-loc 0x8000 or -
8227 \begin_layout Standard
8237 The provided value should not overlap any other memory areas such as the
8238 pdata or xdata segment and with enough space for the current application.
8242 \labelwidthstring 00.00.0000
8249 \begin_layout Standard
8261 \begin_inset LatexCommand index
8262 name "-\\/-data-loc <Value>"
8267 <Value> The start location of the internal ram data
8268 \begin_inset LatexCommand index
8269 name "data (mcs51, ds390 storage class)"
8274 The value entered can be in Hexadecimal or Decimal format, eg.
8279 \begin_layout Standard
8292 \begin_layout Standard
8302 (By default, the start location of the internal ram data segment is set
8303 as low as possible in memory, taking into account the used register banks
8304 and the bit segment at address 0x20.
8305 For example if register banks 0 and 1 are used without bit variables, the
8306 data segment will be set, if -
8310 \begin_layout Standard
8319 -data-loc is not used, to location 0x10.)
8323 \labelwidthstring 00.00.0000
8330 \begin_layout Standard
8342 \begin_inset LatexCommand index
8343 name "-\\/-idata-loc <Value>"
8348 <Value> The start location of the indirectly addressable internal ram
8349 \begin_inset LatexCommand index
8350 name "idata (mcs51, ds390 storage class)"
8354 of the 8051, default value is 0x80.
8355 The value entered can be in Hexadecimal or Decimal format, eg.
8360 \begin_layout Standard
8369 -idata-loc 0x88 or -
8373 \begin_layout Standard
8386 \labelwidthstring 00.00.0000
8393 \begin_layout Standard
8405 <Value> The start location of the bit
8406 \begin_inset LatexCommand index
8411 addressable internal ram of the 8051.
8417 Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
8422 \labelwidthstring 00.00.0000
8429 \begin_layout Standard
8439 \begin_inset LatexCommand index
8440 name "-\\/-out-fmt-ihx"
8446 The linker output (final object code) is in Intel Hex format.
8447 \begin_inset LatexCommand index
8448 name "Intel hex format"
8452 This is the default option.
8453 The format itself is documented in the documentation of srecord
8454 \begin_inset LatexCommand index
8455 name "srecord (bin, hex, ... tool)"
8463 \labelwidthstring 00.00.0000
8470 \begin_layout Standard
8480 \begin_inset LatexCommand index
8481 name "-\\/-out-fmt-s19"
8487 The linker output (final object code) is in Motorola S19 format
8488 \begin_inset LatexCommand index
8489 name "Motorola S19 format"
8494 The format itself is documented in the documentation of srecord.
8498 \labelwidthstring 00.00.0000
8505 \begin_layout Standard
8515 \begin_inset LatexCommand index
8516 name "-\\/-out-fmt-s19"
8521 \begin_inset LatexCommand index
8522 name "HC08!Options!-\\/-out-fmt-elf"
8528 The linker output (final object code) is in ELF format
8529 \begin_inset LatexCommand index
8535 (Currently only supported for the HC08
8536 \begin_inset LatexCommand index
8545 \labelwidthstring 00.00.0000
8549 linkOption[,linkOption]
8552 \begin_inset LatexCommand index
8553 name "-Wl linkOption[,linkOption]"
8558 \begin_inset LatexCommand label
8559 name "lyx:-Wl option"
8564 Pass the linkOption to the linker.
8565 If a bootloader is used an option like
8566 \begin_inset Quotes sld
8571 \begin_inset Quotes srd
8574 would be typical to set the start of the code segment.
8575 Either use the double quotes around this option or use no space (e.g.
8577 See also #pragma constseg and #pragma codeseg in section
8578 \begin_inset LatexCommand ref
8579 reference "sec:Pragmas"
8584 File sdcc/as/doc/asxhtm.html has more on linker options.
8587 \begin_layout Standard
8588 \begin_inset VSpace bigskip
8594 \begin_layout Subsection
8596 \begin_inset LatexCommand index
8597 name "Options MCS51"
8602 \begin_inset LatexCommand index
8603 name "MCS51 options"
8611 \labelwidthstring 00.00.0000
8618 \begin_layout Standard
8628 \begin_inset LatexCommand index
8629 name "-\\/-model-small"
8638 Generate code for Small Model programs, see section Memory Models for more
8640 This is the default model.
8644 \labelwidthstring 00.00.0000
8651 \begin_layout Standard
8661 \begin_inset LatexCommand index
8662 name "-\\/-model-medium"
8668 Generate code for Medium model programs, see section Memory Models for
8670 If this option is used all source files in the project have to be compiled
8672 It must also be used when invoking the linker.
8676 \labelwidthstring 00.00.0000
8683 \begin_layout Standard
8693 \begin_inset LatexCommand index
8694 name "-\\/-model-large"
8700 Generate code for Large model programs, see section Memory Models for more
8702 If this option is used all source files in the project have to be compiled
8704 It must also be used when invoking the linker.
8708 \labelwidthstring 00.00.0000
8715 \begin_layout Standard
8725 \begin_inset LatexCommand index
8732 Uses a pseudo stack in the pdata
8733 \begin_inset LatexCommand index
8734 name "pdata (mcs51, ds390 storage class)"
8738 area (usually the first 256 bytes in the external ram) for allocating variables
8739 and passing parameters.
8741 \begin_inset LatexCommand ref
8742 reference "sub:External-Stack"
8747 External Stack for more details.
8751 \labelwidthstring 00.00.0000
8758 \begin_layout Standard
8771 \begin_inset LatexCommand index
8772 name "-\\/-iram-size <Value>"
8776 Causes the linker to check if the internal ram usage is within limits of
8781 \labelwidthstring 00.00.0000
8788 \begin_layout Standard
8801 \begin_inset LatexCommand index
8802 name "-\\/-xram-size <Value>"
8806 Causes the linker to check if the external ram usage is within limits of
8811 \labelwidthstring 00.00.0000
8818 \begin_layout Standard
8831 \begin_inset LatexCommand index
8832 name "-\\/-code-size <Value>"
8836 Causes the linker to check if the code memory usage is within limits of
8841 \labelwidthstring 00.00.0000
8848 \begin_layout Standard
8861 \begin_inset LatexCommand index
8862 name "-\\/-stack-size <Value>"
8866 Causes the linker to check if there is at minimum <Value> bytes for stack.
8870 \labelwidthstring 00.00.0000
8877 \begin_layout Standard
8890 \begin_inset LatexCommand index
8891 name "-\\/-pack-iram"
8895 Causes the linker to use unused register banks for data variables and pack
8896 data, idata and stack together.
8897 This is the default now.
8901 \labelwidthstring 00.00.0000
8908 \begin_layout Standard
8921 \begin_inset LatexCommand index
8922 name "-\\/-no-pack-iram"
8926 Causes the linker to use old style for allocating memory areas.
8930 \labelwidthstring 00.00.0000
8937 \begin_layout Standard
8950 \begin_inset LatexCommand index
8951 name "-\\/-acall-ajmp"
8955 Replaces the three byte instructions lcall/ljmp with the two byte instructions
8957 Only use this option if your code is in the same 2k block of memory.
8958 You may need to use this option for some 8051 derivatives which lack the
8959 lcall/ljmp instructions..
8962 \begin_layout Standard
8963 \begin_inset VSpace bigskip
8969 \begin_layout Subsection
8970 DS390 / DS400 Options
8971 \begin_inset LatexCommand index
8972 name "Options DS390"
8977 \begin_inset LatexCommand index
8986 \labelwidthstring 00.00.0000
8993 \begin_layout Standard
9005 \begin_inset LatexCommand index
9006 name "DS390!Options!-\\/-model-flat24"
9014 Generate 24-bit flat mode code.
9015 This is the one and only that the ds390 code generator supports right now
9016 and is default when using
9021 See section Memory Models for more details.
9025 \labelwidthstring 00.00.0000
9032 \begin_layout Standard
9042 \begin_inset LatexCommand index
9043 name "DS390!Options!-\\/-protect-sp-update"
9049 disable interrupts during ESP:SP updates.
9053 \labelwidthstring 00.00.0000
9060 \begin_layout Standard
9072 \begin_inset LatexCommand index
9073 name "DS390!Options!-\\/-stack-10bit"
9077 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
9078 This is the one and only that the ds390 code generator supports right now
9079 and is default when using
9084 In this mode, the stack is located in the lower 1K of the internal RAM,
9085 which is mapped to 0x400000.
9086 Note that the support is incomplete, since it still uses a single byte
9087 as the stack pointer.
9088 This means that only the lower 256 bytes of the potential 1K stack space
9089 will actually be used.
9090 However, this does allow you to reclaim the precious 256 bytes of low RAM
9091 for use for the DATA and IDATA segments.
9092 The compiler will not generate any code to put the processor into 10 bit
9094 It is important to ensure that the processor is in this mode before calling
9095 any re-entrant functions compiled with this option.
9096 In principle, this should work with the
9102 \begin_layout Standard
9112 \begin_inset LatexCommand index
9113 name "-\\/-stack-auto"
9119 option, but that has not been tested.
9120 It is incompatible with the
9126 \begin_layout Standard
9136 \begin_inset LatexCommand index
9144 It also only makes sense if the processor is in 24 bit contiguous addressing
9151 \begin_layout Standard
9160 -model-flat24 option
9165 \begin_inset Note Note
9169 \labelwidthstring 00.00.0000
9176 \begin_layout Standard
9185 -stack-8-bit - switches off the 10-bit mode
9194 \labelwidthstring 00.00.0000
9201 \begin_layout Standard
9211 \begin_inset LatexCommand index
9212 name "DS390!Options!-\\/-stack-probe"
9218 insert call to function __stack_probe at each function prologue.
9222 \labelwidthstring 00.00.0000
9229 \begin_layout Standard
9239 \begin_inset LatexCommand index
9240 name "DS390!Options!-\\/-tini-libid"
9246 <nnnn> LibraryID used in -mTININative.
9251 \labelwidthstring 00.00.0000
9258 \begin_layout Standard
9268 \begin_inset LatexCommand index
9269 name "DS390!Options!-\\/-use-accelerator"
9275 generate code for DS390 Arithmetic Accelerator.
9279 \begin_layout Standard
9280 \begin_inset VSpace bigskip
9286 \begin_layout Subsection
9288 \begin_inset LatexCommand index
9294 \begin_inset LatexCommand index
9303 \labelwidthstring 00.00.0000
9310 \begin_layout Standard
9322 \begin_inset LatexCommand index
9323 name "Z80!Options!-\\/-callee-saves-bc"
9331 Force a called function to always save BC.
9335 \labelwidthstring 00.00.0000
9342 \begin_layout Standard
9354 \begin_inset LatexCommand index
9355 name "Z80!Options!-\\/-no-std-crt0"
9359 When linking, skip the standard crt0.o object file.
9360 You must provide your own crt0.o for your system when linking.
9364 \labelwidthstring 00.00.0000
9371 \begin_layout Standard
9383 \begin_inset LatexCommand index
9384 name "Z80!Options!-\\/-portmode=<Value>"
9388 Determinate PORT I/O mode (<Value> is z80 or z180).
9392 \labelwidthstring 00.00.0000
9399 \begin_layout Standard
9411 \begin_inset LatexCommand index
9412 name "Z80!Options!-\\/-asm=<Value>"
9416 Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
9420 \labelwidthstring 00.00.0000
9427 \begin_layout Standard
9440 \begin_inset LatexCommand index
9441 name "Z80!Options!-\\/-codeseg <Value>"
9445 Use <Value> for the code segment name.
9449 \labelwidthstring 00.00.0000
9456 \begin_layout Standard
9469 \begin_inset LatexCommand index
9470 name "Z80!Options!-\\/-constseg <Value>"
9474 Use <Value> for the const segment name.
9478 \labelwidthstring 00.00.0000
9479 \begin_inset VSpace bigskip
9485 \begin_layout Subsection
9487 \begin_inset LatexCommand index
9488 name "Options GBZ80"
9493 \begin_inset LatexCommand index
9502 \labelwidthstring 00.00.0000
9509 \begin_layout Standard
9521 \begin_inset LatexCommand index
9522 name "GBZ80!Options!-\\/-callee-saves-bc"
9530 Force a called function to always save BC.
9534 \labelwidthstring 00.00.0000
9541 \begin_layout Standard
9553 \begin_inset LatexCommand index
9554 name "Z80!Options!-\\/-no-std-crt0"
9558 When linking, skip the standard crt0.o object file.
9559 You must provide your own crt0.o for your system when linking.
9563 \labelwidthstring 00.00.0000
9570 \begin_inset LatexCommand index
9571 name "GBZ80!Options!-bo <Num>"
9575 Use code bank <Num>.
9579 \labelwidthstring 00.00.0000
9586 \begin_inset LatexCommand index
9587 name "GBZ80!Options!-ba <Num>"
9591 Use data bank <Num>.
9595 \labelwidthstring 00.00.0000
9602 \begin_layout Standard
9615 \begin_inset LatexCommand index
9616 name "GBZ80!Options!-\\/-codeseg <Value>"
9620 Use <Value> for the code segment name.
9624 \labelwidthstring 00.00.0000
9631 \begin_layout Standard
9644 \begin_inset LatexCommand index
9645 name "GBZ80!Options!-\\/-constseg <Value>"
9649 Use <Value> for the const segment name.
9652 \begin_layout Standard
9653 \begin_inset VSpace bigskip
9659 \begin_layout Subsection
9660 Optimization Options
9661 \begin_inset LatexCommand index
9662 name "Options optimization"
9667 \begin_inset LatexCommand index
9668 name "Optimization options"
9676 \labelwidthstring 00.00.0000
9683 \begin_layout Standard
9693 \begin_inset LatexCommand index
9700 Will not do global subexpression elimination, this option may be used when
9701 the compiler creates undesirably large stack/data spaces to store compiler
9711 \begin_inset LatexCommand index
9712 name "sloc (spill location)"
9717 A warning message will be generated when this happens and the compiler
9718 will indicate the number of extra bytes it allocated.
9719 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9721 \begin_inset LatexCommand index
9722 name "\\#pragma nogcse"
9726 can be used to turn off global subexpression elimination
9727 \begin_inset LatexCommand index
9728 name "Subexpression elimination"
9732 for a given function only.
9736 \labelwidthstring 00.00.0000
9743 \begin_layout Standard
9753 \begin_inset LatexCommand index
9754 name "-\\/-noinvariant"
9760 Will not do loop invariant optimizations, this may be turned off for reasons
9761 explained for the previous option.
9762 For more details of loop optimizations performed see Loop Invariants in
9764 \begin_inset LatexCommand ref
9765 reference "sub:Loop-Optimizations"
9770 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9772 \begin_inset LatexCommand index
9773 name "\\#pragma noinvariant"
9777 can be used to turn off invariant optimizations for a given function only.
9781 \labelwidthstring 00.00.0000
9788 \begin_layout Standard
9798 \begin_inset LatexCommand index
9799 name "-\\/-noinduction"
9805 Will not do loop induction optimizations, see section strength reduction
9807 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9809 \begin_inset LatexCommand index
9810 name "\\#pragma noinduction"
9814 can be used to turn off induction optimizations for a given function only.
9818 \labelwidthstring 00.00.0000
9825 \begin_layout Standard
9835 \begin_inset LatexCommand index
9836 name "-\\/-nojtbound"
9845 Will not generate boundary condition check when switch statements
9846 \begin_inset LatexCommand index
9847 name "switch statement"
9851 are implemented using jump-tables.
9853 \begin_inset LatexCommand ref
9854 reference "sub:'switch'-Statements"
9859 Switch Statements for more details.
9860 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9862 \begin_inset LatexCommand index
9863 name "\\#pragma nojtbound"
9867 can be used to turn off boundary checking for jump tables for a given function
9872 \labelwidthstring 00.00.0000
9879 \begin_layout Standard
9889 \begin_inset LatexCommand index
9890 name "-\\/-noloopreverse"
9899 Will not do loop reversal
9900 \begin_inset LatexCommand index
9901 name "Loop reversing"
9909 \labelwidthstring 00.00.0000
9914 \begin_layout Standard
9928 \begin_inset LatexCommand index
9929 name "-\\/-nolabelopt "
9933 Will not optimize labels (makes the dumpfiles more readable).
9937 \labelwidthstring 00.00.0000
9944 \begin_layout Standard
9954 \begin_inset LatexCommand index
9955 name "-\\/-no-xinit-opt"
9961 Will not memcpy initialized data from code space into xdata space.
9962 This saves a few bytes in code space if you don't have initialized data
9963 \begin_inset LatexCommand index
9964 name "Variable initialization"
9972 \labelwidthstring 00.00.0000
9979 \begin_layout Standard
9989 \begin_inset LatexCommand index
9990 name "-\\/-nooverlay"
9996 The compiler will not overlay parameters and local variables of any function,
9997 see section Parameters and local variables for more details.
10001 \labelwidthstring 00.00.0000
10008 \begin_layout Standard
10018 \begin_inset LatexCommand index
10019 name "-\\/-no-peep"
10025 Disable peep-hole optimization with built-in rules.
10029 \labelwidthstring 00.00.0000
10036 \begin_layout Standard
10048 \begin_inset LatexCommand index
10049 name "-\\/-peep-file"
10054 <filename> This option can be used to use additional rules to be used by
10055 the peep hole optimizer.
10057 \begin_inset LatexCommand ref
10058 reference "sub:Peephole-Optimizer"
10063 Peep Hole optimizations for details on how to write these rules.
10067 \labelwidthstring 00.00.0000
10074 \begin_layout Standard
10084 \begin_inset LatexCommand index
10085 name "-\\/-peep-asm"
10091 Pass the inline assembler code through the peep hole optimizer.
10092 This can cause unexpected changes to inline assembler code, please go through
10093 the peephole optimizer
10094 \begin_inset LatexCommand index
10095 name "Peephole optimizer"
10099 rules defined in the source file tree '<target>/peeph.def' before using
10104 \labelwidthstring 00.00.0000
10111 \begin_layout Standard
10121 \begin_inset LatexCommand index
10122 name "-\\/-opt-code-speed"
10128 The compiler will optimize code generation towards fast code, possibly
10129 at the expense of code size.
10133 \labelwidthstring 00.00.0000
10140 \begin_layout Standard
10150 \begin_inset LatexCommand index
10151 name "-\\/-opt-code-size"
10157 The compiler will optimize code generation towards compact code, possibly
10158 at the expense of code speed.
10161 \begin_layout Standard
10162 \begin_inset VSpace bigskip
10168 \begin_layout Subsection
10170 \begin_inset LatexCommand index
10171 name "Options other"
10179 \labelwidthstring 00.00.0000
10187 \begin_layout Standard
10197 \begin_inset LatexCommand index
10198 name "-\\/-version"
10203 \begin_inset LatexCommand index
10210 displays the sdcc version.
10214 \labelwidthstring 00.00.0000
10222 \begin_layout Standard
10232 \begin_inset LatexCommand index
10233 name "-\\/-compile-only"
10238 \begin_inset LatexCommand index
10245 will compile and assemble the source, but will not call the linkage editor.
10249 \labelwidthstring 00.00.0000
10258 \begin_layout Standard
10270 \begin_inset LatexCommand index
10277 reads the preprocessed source from standard input and compiles it.
10278 The file name for the assembler output must be specified using the -o option.
10282 \labelwidthstring 00.00.0000
10286 \begin_inset LatexCommand index
10293 Run only the C preprocessor.
10294 Preprocess all the C source files specified and output the results to standard
10299 \labelwidthstring 00.00.0000
10304 \begin_inset LatexCommand index
10305 name "-o <path/file>"
10311 The output path where everything will be placed or the file name used for
10312 all generated output files.
10313 If the parameter is a path, it must have a trailing slash (or backslash
10314 for the Windows binaries) to be recognized as a path.
10315 Note for Windows users: if the path contains spaces, it should be surrounded
10317 The trailing backslash should be doubled in order to prevent escaping the
10318 final quote, for example:
10321 \begin_inset Quotes sld
10335 \begin_inset Quotes srd
10340 or put after the final quote, for example:
10343 \begin_inset Quotes sld
10353 \begin_inset Quotes srd
10361 The path using slashes for directory delimiters can be used too, for example:
10365 \begin_inset Quotes sld
10368 F:/Projects/test3/output 1/
10369 \begin_inset Quotes srd
10378 \labelwidthstring 00.00.0000
10385 \begin_layout Standard
10395 \begin_inset LatexCommand index
10396 name "-\\/-stack-auto"
10405 All functions in the source file will be compiled as
10410 \begin_inset LatexCommand index
10416 the parameters and local variables will be allocated on the stack
10417 \begin_inset LatexCommand index
10424 \begin_inset LatexCommand ref
10425 reference "sec:Parameters-and-Local-Variables"
10429 Parameters and Local Variables for more details.
10430 If this option is used all source files in the project should be compiled
10432 It automatically implies -
10438 \begin_layout Standard
10449 -int-long-reent and -
10455 \begin_layout Standard
10471 \labelwidthstring 00.00.0000
10478 \begin_layout Standard
10488 \begin_inset LatexCommand index
10489 name "-\\/-callee-saves"
10494 \begin_inset LatexCommand label
10495 name "lyx:--callee-saves-function1[,function2][,function3]..."
10499 function1[,function2][,function3]....
10502 The compiler by default uses a caller saves convention for register saving
10503 across function calls, however this can cause unnecessary register pushing
10504 and popping when calling small functions from larger functions.
10505 This option can be used to switch the register saving convention for the
10506 function names specified.
10507 The compiler will not save registers when calling these functions, no extra
10508 code will be generated at the entry and exit (function prologue
10511 \begin_inset LatexCommand index
10512 name "function prologue"
10521 \begin_inset LatexCommand index
10522 name "function epilogue"
10528 ) for these functions to save and restore the registers used by these functions,
10529 this can SUBSTANTIALLY reduce code and improve run time performance of
10530 the generated code.
10531 In the future the compiler (with inter procedural analysis) will be able
10532 to determine the appropriate scheme to use for each function call.
10533 DO NOT use this option for built-in functions such as _mulint..., if this
10534 option is used for a library function the appropriate library function
10535 needs to be recompiled with the same option.
10536 If the project consists of multiple source files then all the source file
10537 should be compiled with the same -
10541 \begin_layout Standard
10550 -callee-saves option string.
10551 Also see #pragma\InsetSpace ~
10553 \begin_inset LatexCommand index
10554 name "\\#pragma callee\\_saves"
10559 \begin_inset LatexCommand vpageref
10560 reference "ite:callee_saves-function1[,function2[,function3...]]--"
10568 \labelwidthstring 00.00.0000
10575 \begin_layout Standard
10585 \begin_inset LatexCommand index
10586 name "-\\/-all-callee-saves"
10596 \begin_layout Standard
10605 -callee-saves will be applied to all functions by default.
10609 \labelwidthstring 00.00.0000
10616 \begin_layout Standard
10626 \begin_inset LatexCommand index
10633 When this option is used the compiler will generate debug information.
10634 The debug information collected in a file with .cdb extension can be used
10636 For more information see documentation for SDCDB.
10637 Another file with no extension contains debug information in AOMF or AOMF51
10638 \begin_inset LatexCommand index
10639 name "AOMF, AOMF51"
10643 format which is commonly used by third party tools.
10647 \labelwidthstring 00.00.0000
10651 \begin_inset LatexCommand index
10661 Stop after the stage of compilation proper; do not assemble.
10662 The output is an assembler code file for the input file specified.
10666 \labelwidthstring 00.00.0000
10673 \begin_layout Standard
10683 \begin_inset LatexCommand index
10684 name "-\\/-int-long-reent"
10690 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
10691 Note by default these libraries are compiled as non-reentrant.
10692 See section Installation for more details.
10696 \labelwidthstring 00.00.0000
10703 \begin_layout Standard
10713 \begin_inset LatexCommand index
10714 name "-\\/-cyclomatic"
10720 This option will cause the compiler to generate an information message for
10721 each function in the source file.
10722 The message contains some
10726 information about the function.
10727 The number of edges and nodes the compiler detected in the control flow
10728 graph of the function, and most importantly the
10730 cyclomatic complexity
10731 \begin_inset LatexCommand index
10732 name "Cyclomatic complexity"
10738 see section on Cyclomatic Complexity for more details.
10742 \labelwidthstring 00.00.0000
10749 \begin_layout Standard
10759 \begin_inset LatexCommand index
10760 name "-\\/-float-reent"
10766 Floating point library is compiled as reentrant
10767 \begin_inset LatexCommand index
10773 See section Installation for more details.
10777 \labelwidthstring 00.00.0000
10784 \begin_layout Standard
10794 \begin_inset LatexCommand index
10795 name "-\\/-funsigned-char"
10801 The default signedness for every type is
10806 In some embedded environments the default signedness of
10815 To set the signess for characters to unsigned, use the option -
10821 \begin_layout Standard
10833 If this option is set and no signedness keyword (unsigned/signed) is given,
10834 a char will be signed.
10835 All other types are unaffected.
10839 \labelwidthstring 00.00.0000
10846 \begin_layout Standard
10856 \begin_inset LatexCommand index
10857 name "-\\/-main-return"
10863 This option can be used if the code generated is called by a monitor program
10864 or if the main routine includes an endless loop.
10865 This option results in slightly smaller code and saves two bytes of stack
10867 The return from the 'main'
10868 \begin_inset LatexCommand index
10873 function will return to the function calling main.
10874 The default setting is to lock up i.e.
10883 \labelwidthstring 00.00.0000
10890 \begin_layout Standard
10900 \begin_inset LatexCommand index
10901 name "-\\/-nostdinc"
10907 This will prevent the compiler from passing on the default include path
10908 to the preprocessor.
10912 \labelwidthstring 00.00.0000
10919 \begin_layout Standard
10929 \begin_inset LatexCommand index
10930 name "-\\/-nostdlib"
10936 This will prevent the compiler from passing on the default library
10937 \begin_inset LatexCommand index
10942 path to the linker.
10946 \labelwidthstring 00.00.0000
10953 \begin_layout Standard
10963 \begin_inset LatexCommand index
10964 name "-\\/-verbose"
10970 Shows the various actions the compiler is performing.
10974 \labelwidthstring 00.00.0000
10978 \begin_inset LatexCommand index
10985 Shows the actual commands the compiler is executing.
10989 \labelwidthstring 00.00.0000
10996 \begin_layout Standard
11006 \begin_inset LatexCommand index
11007 name "-\\/-no-c-code-in-asm"
11013 Hides your ugly and inefficient c-code from the asm file, so you can always
11014 blame the compiler :)
11018 \labelwidthstring 00.00.0000
11025 \begin_layout Standard
11035 \begin_inset LatexCommand index
11036 name "-\\/-no-gen-comments"
11042 Include code generator and peep-hole comments in the generated asm files.
11046 \labelwidthstring 00.00.0000
11053 \begin_layout Standard
11063 \begin_inset LatexCommand index
11064 name "-\\/-no-peep-comments"
11070 Don't include peep-hole comments in the generated asm files even if -
11076 \begin_layout Standard
11087 -fverbose-asm option is specified.
11091 \labelwidthstring 00.00.0000
11098 \begin_layout Standard
11108 \begin_inset LatexCommand index
11109 name "-\\/-i-code-in-asm"
11115 Include i-codes in the asm file.
11116 Sounds like noise but is most helpful for debugging the compiler itself.
11120 \labelwidthstring 00.00.0000
11127 \begin_layout Standard
11137 \begin_inset LatexCommand index
11143 \begin_inset LatexCommand index
11144 name "-\\/-less-pedantic"
11151 \begin_inset LatexCommand label
11152 name "lyx:--less-pedantic"
11156 Disable some of the more pedantic warnings
11157 \begin_inset LatexCommand index
11163 For more details, see the less_pedantic pragma
11164 \begin_inset LatexCommand vpageref
11165 reference "ite:less_pedantic"
11173 \labelwidthstring 00.00.0000
11180 \begin_layout Standard
11189 -disable-warning\InsetSpace ~
11191 \begin_inset LatexCommand index
11192 name "-\\/-disable-warning"
11198 Disable specific warning with number <nnnn>.
11202 \labelwidthstring 00.00.0000
11209 \begin_layout Standard
11219 \begin_inset LatexCommand index
11226 Treat all warnings as errors.
11230 \labelwidthstring 00.00.0000
11237 \begin_layout Standard
11247 \begin_inset LatexCommand index
11248 name "-\\/-print-search-dirs"
11254 Display the directories in the compiler's search path
11258 \labelwidthstring 00.00.0000
11265 \begin_layout Standard
11275 \begin_inset LatexCommand index
11282 Display errors and warnings using MSVC style, so you can use SDCC with
11283 the visual studio IDE
11284 \begin_inset LatexCommand index
11290 With SDCC both offering a GCC-like (the default) and a MSVC-like
11291 \begin_inset LatexCommand index
11292 name "MSVC output style"
11296 output style, integration into most programming editors should be straightforwa
11301 \labelwidthstring 00.00.0000
11308 \begin_layout Standard
11318 \begin_inset LatexCommand index
11319 name "-\\/-use-stdout"
11325 Send errors and warnings to stdout instead of stderr.
11329 \labelwidthstring 00.00.0000
11333 asmOption[,asmOption]
11336 \begin_inset LatexCommand index
11337 name "-Wa asmOption[,asmOption]"
11342 Pass the asmOption to the assembler
11343 \begin_inset LatexCommand index
11344 name "Options assembler"
11349 \begin_inset LatexCommand index
11350 name "Assembler options"
11355 See file sdcc/as/doc/asxhtm.html for assembler options.cd
11359 \labelwidthstring 00.00.0000
11366 \begin_layout Standard
11376 \begin_inset LatexCommand index
11377 name "-\\/-std-sdcc89"
11383 Generally follow the C89 standard, but allow SDCC features that conflict
11384 with the standard (default).
11388 \labelwidthstring 00.00.0000
11395 \begin_layout Standard
11405 \begin_inset LatexCommand index
11406 name "-\\/-std-c89"
11412 Follow the C89 standard and disable SDCC features that conflict with the
11417 \labelwidthstring 00.00.0000
11424 \begin_layout Standard
11434 \begin_inset LatexCommand index
11435 name "-\\/-std-sdcc99"
11441 Generally follow the C99 standard, but allow SDCC features that conflict
11442 with the standard (incomplete support).
11446 \labelwidthstring 00.00.0000
11453 \begin_layout Standard
11463 \begin_inset LatexCommand index
11464 name "-\\/-std-sdcc99"
11470 Follow the C99 standard and disable SDCC features that conflict with the
11471 standard (incomplete support).
11475 \labelwidthstring 00.00.0000
11482 \begin_layout Standard
11494 \begin_inset LatexCommand index
11495 name "-\\/-codeseg <Value>"
11500 \begin_inset LatexCommand label
11501 name "lyx:-codeseg"
11506 <Name> The name to be used for the code
11507 \begin_inset LatexCommand index
11512 segment, default CSEG.
11513 This is useful if you need to tell the compiler to put the code in a special
11514 segment so you can later on tell the linker to put this segment in a special
11516 Can be used for instance when using bank switching to put the code in a
11521 \labelwidthstring 00.00.0000
11528 \begin_layout Standard
11540 \begin_inset LatexCommand index
11541 name "-\\/-constseg <Value>"
11546 <Name> The name to be used for the const
11547 \begin_inset LatexCommand index
11552 segment, default CONST.
11553 This is useful if you need to tell the compiler to put the const data in
11554 a special segment so you can later on tell the linker to put this segment
11555 in a special place in memory.
11556 Can be used for instance when using bank switching to put the const data
11561 \labelwidthstring 00.00.0000
11568 \begin_layout Standard
11577 -fdollars-in-identifiers
11578 \begin_inset LatexCommand index
11579 name "-\\/-fdollars-in-identifiers"
11585 Permit '$' as an identifier character.
11589 \labelwidthstring 00.00.0000
11596 \begin_layout Standard
11608 \begin_inset LatexCommand index
11609 name "-\\/-more-pedantic"
11614 \begin_inset LatexCommand index
11625 a SDCC compiler option but if you want
11629 warnings you can use a separate tool dedicated to syntax checking like
11631 \begin_inset LatexCommand label
11632 name "lyx:more-pedantic-SPLINT"
11637 \begin_inset LatexCommand index
11638 name "lint (syntax checking tool)"
11643 \begin_inset LatexCommand url
11644 target "http://www.splint.org"
11649 To make your source files parseable by splint you will have to include
11655 \begin_inset LatexCommand index
11656 name "splint (syntax checking tool)"
11660 in your source file and add brackets around extended keywords (like
11663 \begin_inset Quotes sld
11676 \begin_inset Quotes srd
11684 \begin_inset Quotes sld
11687 __interrupt\InsetSpace ~
11689 \begin_inset Quotes srd
11697 Splint has an excellent on line manual at
11698 \begin_inset LatexCommand url
11699 target "http://www.splint.org/manual/"
11703 and it's capabilities go beyond pure syntax checking.
11704 You'll need to tell splint the location of SDCC's include files so a typical
11705 command line could look like this:
11709 splint\InsetSpace ~
11711 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
11717 \labelwidthstring 00.00.0000
11724 \begin_layout Standard
11736 \begin_inset LatexCommand index
11737 name "-\\/-short-is-8bits"
11742 \begin_inset LatexCommand label
11743 name "lyx:--short-is-8bits"
11747 Treat short as 8-bit (for backward compatibility with older versions of
11748 compiler - see section
11749 \begin_inset LatexCommand ref
11750 reference "sec:Compatibility-with-previous"
11757 \begin_layout Standard
11758 \begin_inset VSpace bigskip
11764 \begin_layout Subsection
11765 Intermediate Dump Options
11766 \begin_inset LatexCommand label
11767 name "sub:Intermediate-Dump-Options"
11772 \begin_inset LatexCommand index
11773 name "Options intermediate dump"
11778 \begin_inset LatexCommand index
11779 name "Intermediate dump options"
11786 \begin_layout Standard
11787 The following options are provided for the purpose of retargetting and debugging
11789 They provide a means to dump the intermediate code (iCode
11790 \begin_inset LatexCommand index
11795 ) generated by the compiler in human readable form at various stages of
11796 the compilation process.
11797 More on iCodes see chapter
11798 \begin_inset LatexCommand ref
11799 reference "sub:The-anatomy-of"
11804 \begin_inset Quotes srd
11807 The anatomy of the compiler
11808 \begin_inset Quotes srd
11815 \labelwidthstring 00.00.0000
11822 \begin_layout Standard
11832 \begin_inset LatexCommand index
11833 name "-\\/-dumpraw"
11839 This option will cause the compiler to dump the intermediate code into
11842 <source filename>.dumpraw
11844 just after the intermediate code has been generated for a function, i.e.
11845 before any optimizations are done.
11847 \begin_inset LatexCommand index
11848 name "Basic blocks"
11852 at this stage ordered in the depth first number, so they may not be in
11853 sequence of execution.
11857 \labelwidthstring 00.00.0000
11864 \begin_layout Standard
11874 \begin_inset LatexCommand index
11875 name "-\\/-dumpgcse"
11881 Will create a dump of iCodes, after global subexpression elimination
11882 \begin_inset LatexCommand index
11883 name "Global subexpression elimination"
11887 , into a file named
11889 <source filename>.dumpgcse.
11893 \labelwidthstring 00.00.0000
11900 \begin_layout Standard
11910 \begin_inset LatexCommand index
11911 name "-\\/-dumpdeadcode"
11917 Will create a dump of iCodes, after deadcode elimination
11918 \begin_inset LatexCommand index
11919 name "Dead-code elimination"
11923 , into a file named
11925 <source filename>.dumpdeadcode.
11929 \labelwidthstring 00.00.0000
11936 \begin_layout Standard
11946 \begin_inset LatexCommand index
11947 name "-\\/-dumploop"
11956 Will create a dump of iCodes, after loop optimizations
11957 \begin_inset LatexCommand index
11958 name "Loop optimization"
11962 , into a file named
11964 <source filename>.dumploop.
11968 \labelwidthstring 00.00.0000
11975 \begin_layout Standard
11985 \begin_inset LatexCommand index
11986 name "-\\/-dumprange"
11995 Will create a dump of iCodes, after live range analysis
11996 \begin_inset LatexCommand index
11997 name "Live range analysis"
12001 , into a file named
12003 <source filename>.dumprange.
12007 \labelwidthstring 00.00.0000
12014 \begin_layout Standard
12024 \begin_inset LatexCommand index
12025 name "-\\/-dumlrange"
12031 Will dump the life ranges
12032 \begin_inset LatexCommand index
12033 name "Live range analysis"
12041 \labelwidthstring 00.00.0000
12048 \begin_layout Standard
12058 \begin_inset LatexCommand index
12059 name "-\\/-dumpregassign"
12065 Will create a dump of iCodes, after register assignment
12066 \begin_inset LatexCommand index
12067 name "Register assignment"
12071 , into a file named
12073 <source filename>.dumprassgn.
12077 \labelwidthstring 00.00.0000
12084 \begin_layout Standard
12094 \begin_inset LatexCommand index
12095 name "-\\/-dumplrange"
12101 Will create a dump of the live ranges of iTemp's
12105 \labelwidthstring 00.00.0000
12112 \begin_layout Standard
12122 \begin_inset LatexCommand index
12123 name "-\\/-dumpall"
12132 Will cause all the above mentioned dumps to be created.
12135 \begin_layout Standard
12136 \begin_inset VSpace bigskip
12142 \begin_layout Subsection
12143 Redirecting output on Windows Shells
12146 \begin_layout Standard
12147 By default SDCC writes its error messages to
12148 \begin_inset Quotes sld
12152 \begin_inset Quotes srd
12156 To force all messages to
12157 \begin_inset Quotes sld
12161 \begin_inset Quotes srd
12173 \begin_layout Standard
12188 \begin_inset LatexCommand index
12189 name "-\\/-use-stdout"
12194 Additionally, if you happen to have visual studio installed in your windows
12195 machine, you can use it to compile your sources using a custom build and
12202 \begin_layout Standard
12214 \begin_inset LatexCommand index
12220 Something like this should work:
12239 \begin_layout Standard
12258 \begin_layout Standard
12270 -model-large -c $(InputPath)
12273 \begin_inset VSpace bigskip
12279 \begin_layout Section
12280 Environment variables
12281 \begin_inset LatexCommand index
12282 name "Environment variables"
12289 \begin_layout Standard
12290 SDCC recognizes the following environment variables:
12294 \labelwidthstring 00.00.0000
12298 \begin_inset LatexCommand index
12299 name "SDCC\\_LEAVE\\_SIGNALS"
12305 SDCC installs a signal handler
12306 \begin_inset LatexCommand index
12307 name "signal handler"
12311 to be able to delete temporary files after an user break (^C) or an exception.
12312 If this environment variable is set, SDCC won't install the signal handler
12313 in order to be able to debug SDCC.
12317 \labelwidthstring 00.00.0000
12323 \begin_inset LatexCommand index
12324 name "TMP, TEMP, TMPDIR"
12330 Path, where temporary files will be created.
12331 The order of the variables is the search order.
12332 In a standard *nix environment these variables are not set, and there's
12333 no need to set them.
12334 On Windows it's recommended to set one of them.
12338 \labelwidthstring 00.00.0000
12342 \begin_inset LatexCommand index
12350 \begin_inset LatexCommand ref
12351 reference "sub:Install-paths"
12357 \begin_inset Quotes sld
12361 \begin_inset Quotes srd
12368 \labelwidthstring 00.00.0000
12372 \begin_inset LatexCommand index
12373 name "SDCC\\_INCLUDE"
12380 \begin_inset LatexCommand ref
12381 reference "sub:Search-Paths"
12387 \begin_inset Quotes sld
12391 \begin_inset Quotes srd
12398 \labelwidthstring 00.00.0000
12402 \begin_inset LatexCommand index
12410 \begin_inset LatexCommand ref
12411 reference "sub:Search-Paths"
12417 \begin_inset Quotes sld
12421 \begin_inset Quotes srd
12427 \begin_layout Standard
12428 There are some more environment variables recognized by SDCC, but these
12429 are solely used for debugging purposes.
12430 They can change or disappear very quickly, and will never be documented.
12431 \begin_inset VSpace bigskip
12437 \begin_layout Section
12438 Storage Class Language Extensions
12441 \begin_layout Subsection
12442 MCS51/DS390 Storage Class
12443 \begin_inset LatexCommand index
12444 name "Storage class"
12448 Language Extensions
12451 \begin_layout Standard
12452 In addition to the ANSI storage classes SDCC allows the following MCS51
12453 specific storage classes:
12456 \begin_layout Subsubsection
12458 \begin_inset LatexCommand index
12459 name "data (mcs51, ds390 storage class)"
12464 \begin_inset LatexCommand index
12465 name "\\_\\_data (mcs51, ds390 storage class)"
12470 \begin_inset LatexCommand index
12471 name "near (storage class)"
12476 \begin_inset LatexCommand index
12477 name "\\_\\_near (storage class)"
12484 \begin_layout Standard
12489 storage class for the Small Memory model (
12497 or the more ANSI-C compliant forms
12505 can be used synonymously).
12506 Variables declared with this storage class will be allocated in the directly
12507 addressable portion of the internal RAM of a 8051, e.g.:
12510 \begin_layout Verse
12513 __data unsigned char test_data;
12516 \begin_layout Standard
12517 Writing 0x01 to this variable generates the assembly code:
12520 \begin_layout Verse
12523 75*00 01\InsetSpace ~
12531 \begin_layout Subsubsection
12533 \begin_inset LatexCommand index
12534 name "xdata (mcs51, ds390 storage class)"
12539 \begin_inset LatexCommand index
12540 name "\\_\\_xdata (mcs51, ds390 storage class)"
12545 \begin_inset LatexCommand index
12546 name "far (storage class)"
12551 \begin_inset LatexCommand index
12552 name "\\_\\_far (storage class)"
12559 \begin_layout Standard
12560 Variables declared with this storage class will be placed in the external
12566 storage class for the Large Memory model, e.g.:
12569 \begin_layout Verse
12572 __xdata unsigned char test_xdata;
12575 \begin_layout Standard
12576 Writing 0x01 to this variable generates the assembly code:
12579 \begin_layout Verse
12582 90s00r00\InsetSpace ~
12613 \begin_layout Subsubsection
12615 \begin_inset LatexCommand index
12616 name "idata (mcs51, ds390 storage class)"
12621 \begin_inset LatexCommand index
12622 name "\\_\\_idata (mcs51, ds390 storage class)"
12629 \begin_layout Standard
12630 Variables declared with this storage class will be allocated into the indirectly
12631 addressable portion of the internal ram of a 8051, e.g.:
12634 \begin_layout Verse
12637 __idata unsigned char test_idata;
12640 \begin_layout Standard
12641 Writing 0x01 to this variable generates the assembly code:
12644 \begin_layout Verse
12671 \begin_layout Standard
12672 Please note, the first 128 byte of idata physically access the same RAM
12673 as the data memory.
12674 The original 8051 had 128 byte idata memory, nowadays most devices have
12675 256 byte idata memory.
12677 \begin_inset LatexCommand index
12682 is located in idata memory.
12685 \begin_layout Subsubsection
12687 \begin_inset LatexCommand index
12688 name "pdata (mcs51, ds390 storage class)"
12693 \begin_inset LatexCommand index
12694 name "\\_\\_pdata (mcs51, ds390 storage class)"
12701 \begin_layout Standard
12702 Paged xdata access is just as straightforward as using the other addressing
12704 It is typically located at the start of xdata and has a maximum size of
12706 The following example writes 0x01 to the pdata variable.
12707 Please note, pdata access physically accesses xdata memory.
12708 The high byte of the address is determined by port P2
12709 \begin_inset LatexCommand index
12710 name "P2 (mcs51 sfr)"
12714 (or in case of some 8051 variants by a separate Special Function Register,
12716 \begin_inset LatexCommand ref
12717 reference "sub:MCS51-variants"
12726 storage class for the Medium Memory model, e.g.:
12729 \begin_layout Verse
12732 __pdata unsigned char test_pdata;
12735 \begin_layout Standard
12736 Writing 0x01 to this variable generates the assembly code:
12739 \begin_layout Verse
12748 mov r0,#_test_pdata
12770 \begin_layout Standard
12775 \begin_layout Standard
12785 \begin_inset LatexCommand index
12790 option is used the pdata memory area is followed by the xstack memory area
12791 and the sum of their sizes is limited to 256 bytes.
12794 \begin_layout Subsubsection
12796 \begin_inset LatexCommand index
12802 \begin_inset LatexCommand index
12810 \begin_layout Standard
12811 'Variables' declared with this storage class will be placed in the code
12815 \begin_layout Verse
12818 __code unsigned char test_code;
12821 \begin_layout Standard
12822 Read access to this variable generates the assembly code:
12825 \begin_layout Verse
12828 90s00r6F\InsetSpace ~
12831 mov dptr,#_test_code
12856 \begin_layout Standard
12861 indexed arrays of characters in code memory can be accessed efficiently:
12864 \begin_layout Verse
12867 __code char test_array[] = {'c','h','e','a','p'};
12870 \begin_layout Standard
12871 Read access to this array using an 8-bit unsigned index generates the assembly
12875 \begin_layout Verse
12887 \begin_layout Verse
12890 90s00r41\InsetSpace ~
12893 mov dptr,#_test_array
12896 \begin_layout Verse
12911 \begin_layout Subsubsection
12913 \begin_inset LatexCommand index
12919 \begin_inset LatexCommand index
12927 \begin_layout Standard
12928 This is a data-type and a storage class specifier.
12929 When a variable is declared as a bit, it is allocated into the bit addressable
12930 memory of 8051, e.g.:
12933 \begin_layout Verse
12939 \begin_layout Standard
12940 Writing 1 to this variable generates the assembly code:
12943 \begin_layout Verse
12957 \begin_layout Standard
12958 The bit addressable memory consists of 128 bits which are located from 0x20
12959 to 0x2f in data memory.
12962 Apart from this 8051 specific storage class most architectures support
12964 \begin_inset LatexCommand index
12973 \begin_layout Standard
12974 Not really meant as examples, but nevertheless showing what bitfields are
12975 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12981 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12982 signed modifier are implemented as unsigned.
12985 \begin_layout Subsubsection
12987 \begin_inset LatexCommand index
12993 \begin_inset LatexCommand index
12999 \begin_inset LatexCommand index
13005 \begin_inset LatexCommand index
13011 \begin_inset LatexCommand index
13017 \begin_inset LatexCommand index
13023 \begin_inset LatexCommand index
13029 \begin_inset LatexCommand index
13037 \begin_layout Standard
13038 Like the bit keyword,
13040 sfr / sfr16 / sfr32 / sbit
13042 signify both a data-type and storage class, they are used to describe the
13063 variables of a 8051, eg:
13066 \begin_layout Verse
13070 \begin_inset LatexCommand index
13076 \begin_inset LatexCommand index
13081 (0x80) P0;\InsetSpace ~
13082 /* special function register P0 at location 0x80 */
13087 special function register combination for timer 0
13091 with the high byte at
13092 location 0x8C and the low byte at location 0x8A */
13094 __sfr16 __at (0x8C8A)
13100 \begin_inset LatexCommand index
13106 \begin_inset LatexCommand index
13111 (0xd7) CY;\InsetSpace ~
13113 \begin_inset LatexCommand index
13119 \begin_inset LatexCommand index
13127 \begin_layout Standard
13128 Special function registers which are located on an address dividable by
13129 8 are bit-addressable, an
13133 addresses a specific bit within these sfr.
13135 16 Bit and 32 bit special function
13136 register combinations which require a certain access order are better not
13146 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
13147 this is not guaranteed.
13152 \begin_layout Standard
13153 Please note, if you use a header file which was written for another compiler
13154 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
13160 Specifically the syntax
13163 sfr P0 = 0x80;\InsetSpace ~
13170 by SDCC to an assignment of 0x80 to a variable called P0
13173 \begin_inset Marginal
13176 \begin_layout Standard
13190 Nevertheless it is possible to write header files
13191 \begin_inset LatexCommand index
13192 name "Header files"
13197 \begin_inset LatexCommand index
13198 name "Include files"
13202 which can be shared among different compilers (see section
13203 \begin_inset LatexCommand ref
13204 reference "sec:Porting-code-to-other-compilers"
13212 \begin_layout Subsubsection
13214 \begin_inset LatexCommand index
13219 to MCS51/DS390 specific memory spaces
13222 \begin_layout Standard
13223 SDCC allows (via language extensions) pointers to explicitly point to any
13224 of the memory spaces
13225 \begin_inset LatexCommand index
13226 name "Memory model"
13231 In addition to the explicit pointers, the compiler uses (by default) generic
13232 pointers which can be used to point to any of the memory spaces.
13237 declaration examples:
13240 \begin_layout Verse
13243 /* pointer physically in internal ram pointing to object in external ram
13246 __xdata unsigned char * __data p;
13250 /* pointer physically in external ram
13251 pointing to object in internal ram */
13253 __data unsigned char * __xdata p;
13258 pointer physically in code rom pointing to data in xdata space */
13261 unsigned char * __code p;
13265 /* pointer physically in code space pointing to
13266 data in code space */
13268 __code unsigned char * __code p;
13273 physically located in xdata space */
13275 unsigned char * __xdata p;
13280 pointer physically located in default memory space */
13287 the following is a function pointer
13288 \begin_inset LatexCommand index
13289 name "function pointer"
13293 physically located in data space */
13295 char (* __data fp)(void);
13298 \begin_layout Standard
13299 Well you get the idea.
13304 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
13317 The highest order byte of the
13321 pointers contains the data space information.
13322 Assembler support routines are called whenever data is stored or retrieved
13328 These are useful for developing reusable library
13329 \begin_inset LatexCommand index
13335 Explicitly specifying the pointer
13336 \begin_inset LatexCommand index
13341 type will generate the most efficient code.
13344 \begin_layout Subsubsection
13345 Notes on MCS51 memory
13346 \begin_inset LatexCommand index
13347 name "MCS51 memory"
13354 \begin_layout Standard
13355 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
13356 RAM memory which is structured as follows:
13360 - Bytes 00-1F - 32 bytes to hold
13361 up to 4 banks of the registers R0 to R7,
13363 - Bytes 20-2F - 16 bytes to hold
13365 \begin_inset LatexCommand index
13372 - Bytes 30-7F - 80 bytes for general purpose use.
13377 \begin_layout Standard
13378 Additionally some members of the MCS51 family may have up to 128 bytes of
13379 additional, indirectly addressable, internal RAM memory (
13384 \begin_inset LatexCommand index
13385 name "idata (mcs51, ds390 storage class)"
13390 \begin_inset LatexCommand index
13391 name "\\_\\_idata (mcs51, ds390 storage class)"
13396 Furthermore, some chips may have some built in external memory (
13401 \begin_inset LatexCommand index
13402 name "xdata (mcs51, ds390 storage class)"
13407 \begin_inset LatexCommand index
13408 name "\\_\\_xdata (mcs51, ds390 storage class)"
13412 ) which should not be confused with the internal, directly addressable RAM
13418 \begin_inset LatexCommand index
13419 name "data (mcs51, ds390 storage class)"
13424 \begin_inset LatexCommand index
13425 name "\\_\\_data (mcs51, ds390 storage class)"
13430 Sometimes this built in
13434 memory has to be activated before using it (you can probably find this
13435 information on the datasheet of the microcontroller your are using, see
13437 \begin_inset LatexCommand ref
13438 reference "sub:Startup-Code"
13446 \begin_layout Standard
13447 Normally SDCC will only use the first bank
13448 \begin_inset LatexCommand index
13449 name "register bank (mcs51, ds390)"
13453 of registers (register bank 0), but it is possible to specify that other
13454 banks of registers (keyword
13461 \begin_inset LatexCommand index
13462 name "using (mcs51, ds390 register bank)"
13467 \begin_inset LatexCommand index
13468 name "\\_\\_using (mcs51, ds390 register bank)"
13474 ) should be used for example in interrupt
13475 \begin_inset LatexCommand index
13481 \begin_inset LatexCommand index
13482 name "\\_\\_interrupt"
13487 By default, the compiler will place the stack after the last byte of allocated
13488 memory for variables.
13489 For example, if the first 2 banks of registers are used, and only four
13494 variables, it will position the base of the internal stack at address 20
13496 This implies that as the stack
13497 \begin_inset LatexCommand index
13502 grows, it will use up the remaining register banks, and the 16 bytes used
13503 by the 128 bit variables, and 80 bytes for general purpose use.
13504 If any bit variables are used, the data variables will be placed in unused
13505 register banks and after the byte holding the last bit variable.
13506 For example, if register banks 0 and 1 are used, and there are 9 bit variables
13511 variables will be placed starting from address 0x10 to 0x20 and continue
13517 \begin_layout Standard
13527 \begin_inset LatexCommand index
13528 name "-\\/-data-loc <Value>"
13532 to specify the start address of the
13540 \begin_layout Standard
13550 \begin_inset LatexCommand index
13551 name "-\\/-iram-size <Value>"
13555 to specify the size of the total internal RAM (
13569 \begin_layout Standard
13570 By default the 8051 linker will place the stack after the last byte of (i)data
13576 \begin_layout Standard
13586 \begin_inset LatexCommand index
13587 name "-\\/-stack-loc <Value>"
13591 allows you to specify the start of the stack, i.e.
13592 you could start it after any data in the general purpose area.
13593 If your microcontroller has additional indirectly addressable internal
13598 ) you can place the stack on it.
13599 You may also need to use -
13603 \begin_layout Standard
13613 \begin_inset LatexCommand index
13614 name "-\\/-xdata-loc<Value>"
13618 to set the start address of the external RAM (
13626 \begin_layout Standard
13636 \begin_inset LatexCommand index
13637 name "-\\/-xram-size <Value>"
13641 to specify its size.
13642 Same goes for the code memory, using -
13646 \begin_layout Standard
13656 \begin_inset LatexCommand index
13657 name "-\\/-code-loc <Value>"
13665 \begin_layout Standard
13675 \begin_inset LatexCommand index
13676 name "-\\/-code-size <Value>"
13681 If in doubt, don't specify any options and see if the resulting memory
13682 layout is appropriate, then you can adjust it.
13685 \begin_layout Standard
13686 The linker generates two files with memory allocation information.
13687 The first, with extension .map
13688 \begin_inset LatexCommand index
13693 shows all the variables and segments.
13694 The second with extension .mem
13695 \begin_inset LatexCommand index
13700 shows the final memory layout.
13701 The linker will complain either if memory segments overlap, there is not
13702 enough memory, or there is not enough space for stack.
13703 If you get any linking warnings and/or errors related to stack or segments
13704 allocation, take a look at either the .map or .mem files to find out what
13706 The .mem file may even suggest a solution to the problem.
13707 \begin_inset VSpace bigskip
13713 \begin_layout Subsection
13714 Z80/Z180 Storage Class
13715 \begin_inset LatexCommand index
13716 name "Z80!Storage class"
13720 Language Extensions
13723 \begin_layout Subsubsection
13725 \begin_inset LatexCommand index
13731 \begin_inset LatexCommand index
13736 (in/out to 8-bit addresses)
13739 \begin_layout Standard
13741 \begin_inset LatexCommand index
13746 family has separate address spaces for memory and
13756 \begin_inset LatexCommand index
13757 name "I/O memory (Z80, Z180)"
13762 \begin_inset LatexCommand index
13763 name "Z80!I/O memory"
13768 \begin_inset LatexCommand index
13769 name "Z180!I/O memory"
13773 is accessed with special instructions, e.g.:
13776 \begin_layout Verse
13779 sfr at 0x78 IoPort;\InsetSpace ~
13781 /* define a var in I/O space at 78h called IoPort */
13785 \begin_layout Standard
13786 Writing 0x01 to this variable generates the assembly code:
13789 \begin_layout Verse
13809 \begin_layout Subsubsection
13811 \begin_inset LatexCommand index
13817 \begin_inset LatexCommand index
13822 (in/out to 16-bit addresses)
13825 \begin_layout Standard
13830 is used to support 16 bit addresses in I/O memory e.g.:
13833 \begin_layout Verse
13837 \begin_inset LatexCommand index
13843 \begin_inset LatexCommand index
13851 \begin_layout Standard
13852 Writing 0x01 to this variable generates the assembly code:
13855 \begin_layout Verse
13858 01 23 01\InsetSpace ~
13880 \begin_layout Subsubsection
13882 \begin_inset LatexCommand index
13888 \begin_inset LatexCommand index
13893 (in0/out0 to 8 bit addresses on Z180
13894 \begin_inset LatexCommand index
13900 \begin_inset LatexCommand index
13901 name "HD64180 (see Z180)"
13908 \begin_layout Standard
13909 The compiler option -
13913 \begin_layout Standard
13923 \begin_inset LatexCommand index
13924 name "Z180!Options!-\\/-portmode"
13928 =180 (80) and a compiler #pragma\InsetSpace ~
13930 \begin_inset LatexCommand index
13931 name "Z180!Pragmas!\\#pragma portmode"
13935 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
13945 If you include the file z180.h this will be set automatically.
13946 \begin_inset VSpace bigskip
13952 \begin_layout Subsection
13954 \begin_inset LatexCommand index
13955 name "HC08!Storage class"
13959 Language Extensions
13962 \begin_layout Subsubsection
13964 \begin_inset LatexCommand index
13965 name "data (hc08 storage class)"
13970 \begin_inset LatexCommand index
13971 name "\\_\\_data (hc08 storage class)"
13978 \begin_layout Standard
13979 The data storage class declares a variable that resides in the first 256
13980 bytes of memory (the direct page).
13982 \begin_inset LatexCommand index
13987 is most efficient at accessing variables (especially pointers) stored here.
13990 \begin_layout Subsubsection
13992 \begin_inset LatexCommand index
13993 name "xdata (hc08 storage class)"
13998 \begin_inset LatexCommand index
13999 name "\\_\\_xdata (hc08 storage class)"
14006 \begin_layout Standard
14007 The xdata storage class declares a variable that can reside anywhere in
14009 This is the default if no storage class is specified.
14011 \begin_inset VSpace bigskip
14017 \begin_layout Section
14018 Other SDCC language extensions
14019 \begin_inset LatexCommand index
14020 name "Other SDCC language extensions"
14027 \begin_layout Subsection
14031 \begin_layout Standard
14032 SDCC supports the use of binary constants, such as 0b01100010.
14033 This feature is only enabled when the compiler is invoked using --std-sdccxx.
14036 \begin_layout Standard
14037 \begin_inset VSpace bigskip
14043 \begin_layout Section
14044 Absolute Addressing
14045 \begin_inset LatexCommand index
14046 name "Absolute addressing"
14053 \begin_layout Standard
14054 Data items can be assigned an absolute address with the
14057 \begin_inset LatexCommand index
14063 \begin_inset LatexCommand index
14070 keyword, in addition to a storage class, e.g.:
14073 \begin_layout Verse
14077 \begin_inset LatexCommand index
14078 name "xdata (mcs51, ds390 storage class)"
14083 \begin_inset LatexCommand index
14084 name "\\_\\_xdata (mcs51, ds390 storage class)"
14089 \begin_inset LatexCommand index
14095 \begin_inset LatexCommand index
14100 0x7ffe unsigned int chksum;
14103 \begin_layout Standard
14104 or, better conforming to ISO/IEC 9899 C:
14107 \begin_layout Verse
14110 __xdata __at (0x7ffe) unsigned int chksum;
14113 \begin_layout Standard
14114 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
14115 of the external ram.
14120 reserve any space for variables declared in this way
14121 \begin_inset Marginal
14124 \begin_layout Standard
14133 (they are implemented with an equate in the assembler).
14134 Thus it is left to the programmer to make sure there are no overlaps with
14135 other variables that are declared without the absolute address.
14136 The assembler listing file (.lst
14137 \begin_inset LatexCommand index
14142 ) and the linker output files (.rst
14143 \begin_inset LatexCommand index
14149 \begin_inset LatexCommand index
14154 ) are good places to look for such overlaps.
14157 \begin_layout Standard
14158 If however you provide an initializer
14159 \begin_inset LatexCommand index
14160 name "Variable initialization"
14164 actual memory allocation will take place and overlaps will be detected
14169 \begin_layout Verse
14172 __code __at (0x7ff0) char Id[5] =
14173 \begin_inset Quotes sld
14177 \begin_inset Quotes srd
14183 \begin_layout Standard
14184 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
14188 \begin_layout Standard
14189 In case of memory mapped I/O devices the keyword
14193 has to be used to tell the compiler that accesses might not be removed:
14196 \begin_layout Verse
14200 \begin_inset LatexCommand index
14206 \begin_inset LatexCommand index
14207 name "xdata (mcs51, ds390 storage class)"
14212 \begin_inset LatexCommand index
14217 (0x8000) unsigned char PORTA_8255;
14220 \begin_layout Standard
14221 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
14226 \begin_inset LatexCommand index
14227 name "Aligned array"
14234 starts at a block (256 byte) boundary
14235 \begin_inset LatexCommand index
14236 name "block boundary"
14241 \begin_inset LatexCommand ref
14242 reference "sub:A-Step-by Assembler Introduction"
14248 Absolute addresses can be specified for variables in all
14249 storage classes, e.g.:
14252 \begin_layout Verse
14256 \begin_inset LatexCommand index
14262 \begin_inset LatexCommand index
14270 \begin_layout Standard
14271 The above example will allocate the variable at offset 0x02 in the bit-addressab
14273 There is no real advantage to assigning absolute addresses to variables
14274 in this manner, unless you want strict control over all the variables allocated.
14275 One possible use would be to write hardware portable code.
14276 For example, if you have a routine that uses one or more of the microcontroller
14277 I/O pins, and such pins are different for two different hardwares, you
14278 can declare the I/O pins in your routine using:
14281 \begin_layout Verse
14285 \begin_inset LatexCommand index
14290 __bit MOSI;\InsetSpace ~
14294 /* master out, slave in */
14296 extern volatile __bit MISO;\InsetSpace ~
14303 extern volatile __bit MCLK;\InsetSpace ~
14312 Output of a byte on a 3-wire serial bus.
14317 If needed adapt polarity of clock,
14318 polarity of data and bit order
14323 unsigned char spi_io(unsigned char out_byte)
14348 MOSI = out_byte & 0x80;
14379 /* _asm nop _endasm; */\InsetSpace ~
14387 /* for slow peripherals */
14439 \begin_layout Standard
14440 Then, someplace in the code for the first hardware you would use
14443 \begin_layout Verse
14447 \begin_inset LatexCommand index
14453 \begin_inset LatexCommand index
14458 (0x80) MOSI;\InsetSpace ~
14462 /* I/O port 0, bit 0 */
14464 __bit __at (0x81) MISO;\InsetSpace ~
14471 __bit __at (0x82) MCLK;\InsetSpace ~
14475 /* I/O port 0, bit 2 */
14478 \begin_layout Standard
14479 Similarly, for the second hardware you would use
14482 \begin_layout Verse
14485 __bit __at (0x83) MOSI;\InsetSpace ~
14489 /* I/O port 0, bit 3 */
14491 __bit __at (0x91) MISO;\InsetSpace ~
14496 I/O port 1, bit 1 */
14499 \begin_inset LatexCommand index
14504 __at (0x92) MCLK;\InsetSpace ~
14508 /* I/O port 1, bit 2 */
14511 \begin_layout Standard
14512 and you can use the same hardware dependent routine without changes, as
14513 for example in a library.
14514 This is somehow similar to sbit, but only one absolute address has to be
14515 specified in the whole project.
14516 \begin_inset VSpace bigskip
14522 \begin_layout Section
14524 \begin_inset LatexCommand index
14530 \begin_inset LatexCommand index
14531 name "function parameter"
14536 \begin_inset LatexCommand index
14537 name "local variables"
14542 \begin_inset LatexCommand label
14543 name "sec:Parameters-and-Local-Variables"
14550 \begin_layout Standard
14551 Automatic (local) variables and parameters to functions can either be placed
14552 on the stack or in data-space.
14553 The default action of the compiler is to place these variables in the internal
14554 RAM (for small model) or external RAM (for medium or large model).
14555 This in fact makes them similar to
14558 \begin_inset LatexCommand index
14565 so by default functions are non-reentrant
14566 \begin_inset LatexCommand index
14576 They can be placed on the stack
14577 \begin_inset LatexCommand index
14588 \begin_layout Standard
14598 \begin_inset LatexCommand index
14599 name "-\\/-stack-auto"
14607 #pragma\InsetSpace ~
14611 \begin_inset LatexCommand index
14612 name "\\#pragma stackauto"
14619 \begin_inset LatexCommand index
14626 keyword in the function declaration, e.g.:
14629 \begin_layout Verse
14632 unsigned char foo(char i) __reentrant
14646 \begin_layout Standard
14647 Since stack space on 8051 is limited, the
14657 \begin_layout Standard
14668 option should be used sparingly.
14669 Note that the reentrant keyword just means that the parameters & local
14670 variables will be allocated to the stack, it
14674 mean that the function is register bank
14675 \begin_inset LatexCommand index
14676 name "register bank (mcs51, ds390)"
14685 \begin_inset LatexCommand index
14686 name "local variables"
14690 can be assigned storage classes and absolute
14691 \begin_inset LatexCommand index
14692 name "Absolute addressing"
14699 \begin_layout Verse
14702 unsigned char foo()
14710 __xdata unsigned char i;
14723 \begin_inset LatexCommand index
14728 (0x31) unsigned char j;
14740 \begin_layout Standard
14741 In the above example the variable
14745 will be allocated in the external ram,
14749 in bit addressable space and
14760 \begin_layout Standard
14771 or when a function is declared as
14775 this should only be done for static variables.
14778 \begin_layout Standard
14780 \begin_inset LatexCommand index
14781 name "function parameter"
14785 however are not allowed any storage class
14786 \begin_inset LatexCommand index
14787 name "Storage class"
14791 , (storage classes for parameters will be ignored), their allocation is
14792 governed by the memory model in use, and the reentrancy options.
14795 \begin_layout Standard
14796 It is however allowed to use bit parameters in reentrant functions and also
14797 non-static local bit variables are supported.
14798 Efficient use is limited to 8 semi-bitregisters in bit space.
14799 They are pushed and popped to stack
14800 \begin_inset LatexCommand index
14805 as a single byte just like the normal registers.
14808 \begin_layout Section
14810 \begin_inset LatexCommand label
14811 name "sub:Overlaying"
14816 \begin_inset LatexCommand index
14824 \begin_layout Standard
14826 \begin_inset LatexCommand index
14831 functions SDCC will try to reduce internal ram space usage by overlaying
14832 parameters and local variables of a function (if possible).
14833 Parameters and local variables
14834 \begin_inset LatexCommand index
14835 name "local variables"
14839 of a function will be allocated to an overlayable segment if the function
14842 no other function calls and the function is non-reentrant and the memory
14844 \begin_inset LatexCommand index
14845 name "Memory model"
14852 If an explicit storage class
14853 \begin_inset LatexCommand index
14854 name "Storage class"
14858 is specified for a local variable, it will NOT be overlaid.
14861 \begin_layout Standard
14862 Note that the compiler (not the linkage editor) makes the decision for overlayin
14864 Functions that are called from an interrupt service routine
14865 \begin_inset Marginal
14868 \begin_layout Standard
14876 should be preceded by a #pragma\InsetSpace ~
14878 \begin_inset LatexCommand index
14879 name "\\#pragma nooverlay"
14883 if they are not reentrant.
14886 \begin_layout Standard
14887 Also note that the compiler does not do any processing of inline assembler
14888 code, so the compiler might incorrectly assign local variables and parameters
14889 of a function into the overlay segment if the inline assembler code calls
14890 other c-functions that might use the overlay.
14891 In that case the #pragma\InsetSpace ~
14892 nooverlay should be used.
14895 \begin_layout Standard
14896 Parameters and local variables of functions that contain 16 or 32 bit multiplica
14898 \begin_inset LatexCommand index
14899 name "Multiplication"
14904 \begin_inset LatexCommand index
14909 will NOT be overlaid since these are implemented using external functions,
14913 \begin_layout Verse
14919 \begin_inset LatexCommand index
14920 name "\\#pragma nooverlay"
14926 void set_error(unsigned char errcd)
14943 some_isr () __interrupt
14944 \begin_inset LatexCommand index
14975 \begin_layout Standard
14976 In the above example the parameter
14984 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
14986 not present, this could cause unpredictable runtime behavior when called
14987 from an interrupt service routine.
14988 The #pragma\InsetSpace ~
14989 nooverlay ensures that the parameters and local variables for
14990 the function are NOT overlaid.
14991 \begin_inset VSpace bigskip
14997 \begin_layout Section
14998 Interrupt Service Routines
14999 \begin_inset LatexCommand label
15000 name "sub:Interrupt-Service-Routines"
15007 \begin_layout Subsection
15008 General Information
15011 \begin_layout Standard
15024 outines to be coded in C, with some extended keywords.
15027 \begin_layout Verse
15030 void timer_isr (void) __interrupt (1) __using (1)
15044 \begin_layout Standard
15045 The optional number following the
15048 \begin_inset LatexCommand index
15054 \begin_inset LatexCommand index
15055 name "\\_\\_interrupt"
15061 keyword is the interrupt number this routine will service.
15062 When present, the compiler will insert a call to this routine in the interrupt
15064 \begin_inset LatexCommand index
15065 name "interrupt vector table"
15069 for the interrupt number specified.
15070 If you have multiple source files in your project, interrupt service routines
15071 can be present in any of them, but a prototype of the isr MUST be present
15072 or included in the file that contains the function
15077 The optional (8051 specific) keyword
15080 \begin_inset LatexCommand index
15081 name "using (mcs51, ds390 register bank)"
15086 \begin_inset LatexCommand index
15087 name "\\_\\_using (mcs51, ds390 register bank)"
15093 can be used to tell the compiler to use the specified register bank when
15094 generating code for this function.
15097 Interrupt service routines open the door for some very interesting bugs:
15100 \begin_layout Subsubsection
15101 \begin_inset LatexCommand label
15102 name "sub:Common-interrupt-pitfall-volatile"
15106 Common interrupt pitfall: variable not declared
15111 \begin_layout Standard
15112 If an interrupt service routine changes variables which are accessed by
15113 other functions these variables have to be declared
15118 \begin_inset LatexCommand index
15125 \begin_inset LatexCommand url
15126 target "http://en.wikipedia.org/wiki/Volatile_variable"
15133 \begin_layout Subsubsection
15134 \begin_inset LatexCommand label
15135 name "sub:Common-interrupt-pitfall-non-atomic"
15139 Common interrupt pitfall:
15144 \begin_layout Standard
15145 If the access to these variables is not
15148 \begin_inset LatexCommand index
15156 the processor needs more than one instruction for the access and could
15157 be interrupted while accessing the variable) the interrupt must be disabled
15158 during the access to avoid inconsistent data.
15161 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
15162 and should be protected by disabling interrupts.
15163 You're not automatically on the safe side if you use 8 bit variables though.
15164 We need an example here: f.e.
15165 on the 8051 the harmless looking
15166 \begin_inset Quotes srd
15176 \begin_inset Quotes sld
15185 \begin_inset Quotes srd
15195 \begin_inset Quotes sld
15198 from within an interrupt routine might get lost if the interrupt occurs
15201 \begin_inset Quotes sld
15206 counter\InsetSpace ~
15211 \begin_inset Quotes srd
15214 is not atomic on the 8051 even if
15218 is located in data memory.
15220 Bugs like these are hard to reproduce and can
15221 cause a lot of trouble.
15225 \begin_layout Subsubsection
15226 \begin_inset LatexCommand label
15227 name "sub:Common-interrupt-pitfall-stack-overflow"
15231 Common interrupt pitfall:
15236 \begin_layout Standard
15237 The return address and the registers used in the interrupt service routine
15238 are saved on the stack
15239 \begin_inset LatexCommand index
15244 so there must be sufficient stack space.
15245 If there isn't variables or registers (or even the return address itself)
15252 \begin_inset LatexCommand index
15253 name "stack overflow"
15257 is most likely to happen if the interrupt occurs during the
15258 \begin_inset Quotes sld
15262 \begin_inset Quotes srd
15265 subroutine when the stack is already in use for f.e.
15266 many return addresses.
15269 \begin_layout Subsubsection
15270 \begin_inset LatexCommand label
15271 name "sub:Common-interrupt-pitfall-non-reentrant"
15275 Common interrupt pitfall:
15277 use of non-reentrant functions
15280 \begin_layout Standard
15281 A special note here, int (16 bit) and long (32 bit) integer division
15282 \begin_inset LatexCommand index
15288 \begin_inset LatexCommand index
15289 name "Multiplication"
15294 \begin_inset LatexCommand index
15300 \begin_inset LatexCommand index
15301 name "Floating point support"
15305 operations are implemented using external support routines.
15306 If an interrupt service routine needs to do any of these operations then
15307 the support routines (as mentioned in a following section) will have to
15308 be recompiled using the
15314 \begin_layout Standard
15324 \begin_inset LatexCommand index
15325 name "-\\/-stack-auto"
15331 option and the source file will need to be compiled using the
15337 \begin_layout Standard
15349 \begin_inset LatexCommand index
15350 name "-\\/-int-long-reent"
15357 Note, the type promotion
15358 \begin_inset LatexCommand index
15359 name "type promotion"
15363 required by ANSI C can cause 16 bit routines to be used
15364 \begin_inset Marginal
15367 \begin_layout Standard
15376 without the programmer being aware of it.
15381 (unsigned char)(tail-1)
15386 within the if clause in section
15387 \begin_inset LatexCommand ref
15388 reference "sub:A-Step-by Assembler Introduction"
15395 \begin_layout Standard
15396 Calling other functions from an interrupt service routine is not recommended,
15397 avoid it if possible.
15398 Note that when some function is called from an interrupt service routine
15399 it should be preceded by a #pragma\InsetSpace ~
15401 \begin_inset LatexCommand index
15402 name "\\#pragma nooverlay"
15406 if it is not reentrant.
15407 Furthermore nonreentrant functions should not be called from the main program
15408 while the interrupt service routine might be active.
15409 They also must not be called from low priority interrupt service routines
15410 while a high priority interrupt service routine might be active.
15411 You could use semaphores or make the function
15415 if all parameters are passed in registers.
15418 \begin_inset LatexCommand ref
15419 reference "sub:Overlaying"
15424 about Overlaying and section
15425 \begin_inset LatexCommand ref
15426 reference "sub:Functions-using-private-banks"
15431 about Functions using private register banks.
15432 \begin_inset VSpace bigskip
15438 \begin_layout Subsection
15439 MCS51/DS390 Interrupt Service Routines
15442 \begin_layout Standard
15444 \begin_inset LatexCommand index
15449 numbers and the corresponding address & descriptions for the Standard 8051/8052
15451 SDCC will automatically adjust the
15452 \begin_inset LatexCommand index
15453 name "interrupt vector table"
15457 to the maximum interrupt number specified.
15462 \begin_layout Standard
15464 \begin_inset Tabular
15465 <lyxtabular version="3" rows="9" columns="3">
15467 <column alignment="center" valignment="top" leftline="true" width="0in">
15468 <column alignment="left" valignment="top" leftline="true" width="0in">
15469 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
15470 <row topline="true" bottomline="true">
15471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15474 \begin_layout Standard
15480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15483 \begin_layout Standard
15489 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15492 \begin_layout Standard
15499 <row topline="true">
15500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15503 \begin_layout Standard
15509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15512 \begin_layout Standard
15518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15521 \begin_layout Standard
15528 <row topline="true">
15529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15532 \begin_layout Standard
15538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15541 \begin_layout Standard
15547 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15550 \begin_layout Standard
15557 <row topline="true">
15558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15561 \begin_layout Standard
15567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15570 \begin_layout Standard
15576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15579 \begin_layout Standard
15586 <row topline="true">
15587 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15590 \begin_layout Standard
15596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15599 \begin_layout Standard
15605 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15608 \begin_layout Standard
15615 <row topline="true">
15616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15619 \begin_layout Standard
15625 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15628 \begin_layout Standard
15634 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15637 \begin_layout Standard
15644 <row topline="true">
15645 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15648 \begin_layout Standard
15654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15657 \begin_layout Standard
15663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15666 \begin_layout Standard
15673 <row topline="true">
15674 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15677 \begin_layout Standard
15683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15686 \begin_layout Standard
15692 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15695 \begin_layout Standard
15702 <row topline="true" bottomline="true">
15703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15706 \begin_layout Standard
15712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15715 \begin_layout Standard
15721 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15724 \begin_layout Standard
15740 \begin_layout Standard
15741 If the interrupt service routine is defined without
15744 \begin_inset LatexCommand index
15745 name "using (mcs51, ds390 register bank)"
15750 \begin_inset LatexCommand index
15751 name "\\_\\_using (mcs51, ds390 register bank)"
15757 a register bank or with register bank 0 (
15761 0), the compiler will save the registers used by itself on the stack upon
15762 entry and restore them at exit, however if such an interrupt service routine
15763 calls another function then the entire register bank will be saved on the
15765 This scheme may be advantageous for small interrupt service routines which
15766 have low register usage.
15769 \begin_layout Standard
15770 If the interrupt service routine is defined to be using a specific register
15775 & psw are saved and restored, if such an interrupt service routine calls
15776 another function (using another register bank) then the entire register
15777 bank of the called function will be saved on the stack
15778 \begin_inset LatexCommand index
15784 This scheme is recommended for larger interrupt service routines.
15785 \begin_inset VSpace bigskip
15791 \begin_layout Subsection
15793 \begin_inset LatexCommand index
15798 Interrupt Service Routines
15801 \begin_layout Standard
15802 Since the number of interrupts
15803 \begin_inset LatexCommand index
15804 name "HC08!interrupt"
15808 available is chip specific and the interrupt vector table always ends at
15809 the last byte of memory, the interrupt numbers corresponds to the interrupt
15810 vectors in reverse order of address.
15811 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
15812 2 will use the interrupt vector at 0xfffa, and so on.
15813 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
15814 this way; instead see section
15815 \begin_inset LatexCommand ref
15816 reference "sub:Startup-Code"
15820 for details on customizing startup.
15821 \begin_inset VSpace bigskip
15827 \begin_layout Subsection
15828 Z80 Interrupt Service Routines
15831 \begin_layout Standard
15833 \begin_inset LatexCommand index
15838 uses several different methods for determining the correct interrupt
15839 \begin_inset LatexCommand index
15840 name "Z80!interrupt"
15844 vector depending on the hardware implementation.
15845 Therefore, SDCC ignores the optional interrupt number and does not attempt
15846 to generate an interrupt vector table.
15849 \begin_layout Standard
15850 By default, SDCC generates code for a maskable interrupt, which uses a RETI
15851 instruction to return from the interrupt.
15852 To write an interrupt handler for the non-maskable interrupt, which needs
15853 a RETN instruction instead, add the
15860 \begin_layout Verse
15863 void nmi_isr (void) critical interrupt
15877 \begin_layout Standard
15878 However if you need to create a non-interruptable interrupt service routine
15879 you would also require the
15884 To distinguish between this and an nmi_isr you must provide an interrupt
15886 \begin_inset VSpace bigskip
15892 \begin_layout Section
15893 Enabling and Disabling Interrupts
15896 \begin_layout Subsection
15897 Critical Functions and Critical Statements
15900 \begin_layout Standard
15901 A special keyword may be associated with a block or a function declaring
15907 SDCC will generate code to disable all interrupts
15908 \begin_inset LatexCommand index
15913 upon entry to a critical function and restore the interrupt enable to the
15914 previous state before returning.
15915 Nesting critical functions will need one additional byte on the stack
15916 \begin_inset LatexCommand index
15924 \begin_layout Verse
15927 int foo () __critical
15928 \begin_inset LatexCommand index
15934 \begin_inset LatexCommand index
15935 name "\\_\\_critical"
15960 \begin_layout Standard
15961 The critical attribute maybe used with other attributes like
15971 may also be used to disable interrupts more locally:
15974 \begin_layout Verse
15980 \begin_layout Standard
15981 More than one statement could have been included in the block.
15984 \begin_layout Subsection
15985 Enabling and Disabling Interrupts directly
15988 \begin_layout Standard
15990 \begin_inset LatexCommand index
15995 can also be disabled and enabled directly (8051):
15998 \begin_layout Verse
16001 EA = 0;\InsetSpace ~
16027 \begin_layout Verse
16063 \begin_layout Verse
16066 EA = 1;\InsetSpace ~
16095 \begin_layout Verse
16134 \begin_layout Standard
16135 On other architectures which have separate opcodes for enabling and disabling
16136 interrupts you might want to make use of defines with inline assembly
16137 \begin_inset LatexCommand index
16138 name "Assembler routines"
16143 \begin_inset LatexCommand index
16144 name "HC08!interrupt"
16151 \begin_layout Verse
16155 \begin_inset LatexCommand index
16165 \begin_inset LatexCommand index
16173 \begin_layout Verse
16176 #define SEI _asm\InsetSpace ~
16183 \begin_layout Verse
16189 \begin_layout Standard
16190 Note: it is sometimes sufficient to disable only a specific interrupt source
16192 a timer or serial interrupt by manipulating an
16195 \begin_inset LatexCommand index
16196 name "interrupt mask"
16206 \begin_layout Standard
16207 Usually the time during which interrupts are disabled should be kept as
16209 This minimizes both
16214 \begin_inset LatexCommand index
16215 name "interrupt latency"
16219 (the time between the occurrence of the interrupt and the execution of
16220 the first code in the interrupt routine) and
16225 \begin_inset LatexCommand index
16226 name "interrupt jitter"
16230 (the difference between the shortest and the longest interrupt latency).
16231 These really are something different, f.e.
16232 a serial interrupt has to be served before its buffer overruns so it cares
16233 for the maximum interrupt latency, whereas it does not care about jitter.
16234 On a loudspeaker driven via a digital to analog converter which is fed
16235 by an interrupt a latency of a few milliseconds might be tolerable, whereas
16236 a much smaller jitter will be very audible.
16239 \begin_layout Standard
16240 You can reenable interrupts within an interrupt routine and on some architecture
16241 s you can make use of two (or more) levels of
16243 interrupt priorities
16246 \begin_inset LatexCommand index
16247 name "interrupt priority"
16252 On some architectures which don't support interrupt priorities these can
16253 be implemented by manipulating the interrupt mask and reenabling interrupts
16254 within the interrupt routine.
16255 Check there is sufficient space on the stack
16256 \begin_inset LatexCommand index
16261 and don't add complexity unless you have to.
16265 \begin_layout Subsection
16267 \begin_inset LatexCommand index
16272 locking (mcs51/ds390)
16275 \begin_layout Standard
16276 Some architectures (mcs51/ds390) have an atomic
16277 \begin_inset LatexCommand index
16282 bit test and clear instruction.
16283 These type of instructions are typically used in preemptive multitasking
16284 systems, where a routine f.e.
16285 claims the use of a data structure ('acquires a lock
16286 \begin_inset LatexCommand index
16291 on it'), makes some modifications and then releases the lock when the data
16292 structure is consistent again.
16293 The instruction may also be used if interrupt and non-interrupt code have
16294 to compete for a resource.
16295 With the atomic bit test and clear instruction interrupts
16296 \begin_inset LatexCommand index
16301 don't have to be disabled for the locking operation.
16305 \begin_layout Standard
16306 SDCC generates this instruction if the source follows this pattern:
16309 \begin_layout Verse
16313 \begin_inset LatexCommand index
16318 bit resource_is_free;
16322 if (resource_is_free)
16332 resource_is_free=0;
16345 resource_is_free=1;
16352 \begin_layout Standard
16353 Note, mcs51 and ds390 support only an atomic
16354 \begin_inset LatexCommand index
16363 instruction (as opposed to atomic bit test and
16368 \begin_layout Section
16369 Functions using private register banks
16370 \begin_inset LatexCommand label
16371 name "sub:Functions-using-private-banks"
16378 \begin_layout Standard
16379 Some architectures have support for quickly changing register sets.
16380 SDCC supports this feature with the
16383 \begin_inset LatexCommand index
16384 name "using (mcs51, ds390 register bank)"
16389 \begin_inset LatexCommand index
16390 name "\\_\\_using (mcs51, ds390 register bank)"
16396 attribute (which tells the compiler to use a register bank
16397 \begin_inset LatexCommand index
16398 name "register bank (mcs51, ds390)"
16402 other than the default bank zero).
16403 It should only be applied to
16406 \begin_inset LatexCommand index
16413 functions (see footnote below).
16414 This will in most circumstances make the generated ISR code more efficient
16415 since it will not have to save registers on the stack.
16418 \begin_layout Standard
16423 attribute will have no effect on the generated code for a
16427 function (but may occasionally be useful anyway
16431 \begin_layout Standard
16432 possible exception: if a function is called ONLY from 'interrupt' functions
16433 using a particular bank, it can be declared with the same 'using' attribute
16434 as the calling 'interrupt' functions.
16435 For instance, if you have several ISRs using bank one, and all of them
16436 call memcpy(), it might make sense to create a specialized version of memcpy()
16437 'using 1', since this would prevent the ISR from having to save bank zero
16438 to the stack on entry and switch to bank zero before calling the function
16447 (pending: Note, nowadays the
16451 attribute has an effect on
16455 the generated code for a
16466 \begin_layout Standard
16471 function using a non-zero bank will assume that it can trash that register
16472 bank, and will not save it.
16473 Since high-priority interrupts
16474 \begin_inset LatexCommand index
16480 \begin_inset LatexCommand index
16481 name "interrupt priority"
16485 can interrupt low-priority ones on the 8051 and friends, this means that
16486 if a high-priority ISR
16490 a particular bank occurs while processing a low-priority ISR
16494 the same bank, terrible and bad things can happen.
16495 To prevent this, no single register bank should be
16499 by both a high priority and a low priority ISR.
16500 This is probably most easily done by having all high priority ISRs use
16501 one bank and all low priority ISRs use another.
16502 If you have an ISR which can change priority at runtime, you're on your
16503 own: I suggest using the default bank zero and taking the small performance
16507 \begin_layout Standard
16508 It is most efficient if your ISR calls no other functions.
16509 If your ISR must call other functions, it is most efficient if those functions
16510 use the same bank as the ISR (see note 1 below); the next best is if the
16511 called functions use bank zero.
16512 It is very inefficient to call a function using a different, non-zero bank
16515 \begin_inset VSpace bigskip
16521 \begin_layout Section
16523 \begin_inset LatexCommand label
16524 name "sub:Startup-Code"
16529 \begin_inset LatexCommand index
16530 name "Startup code"
16537 \begin_layout Subsection
16538 MCS51/DS390 Startup Code
16541 \begin_layout Standard
16542 The compiler triggers the linker to link certain initialization modules
16543 from the runtime library
16544 \begin_inset LatexCommand index
16545 name "Runtime library"
16549 called crt<something>.
16550 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
16551 GSINIT5) is not linked unless the -
16557 \begin_layout Standard
16568 -xstack option is used.
16569 These modules are highly entangled by the use of special segments/areas,
16570 but a common layout is shown below:
16573 \begin_layout Verse
16581 \begin_layout Verse
16605 ljmp __sdcc_gsinit_startup
16608 \begin_layout Verse
16616 \begin_layout Verse
16628 .area GSINIT0 (CODE)
16630 __sdcc_gsinit_startup::
16640 mov sp,#__start__stack - 1
16643 \begin_layout Verse
16651 \begin_layout Verse
16663 .area GSINIT1 (CODE)
16665 __sdcc_init_xstack::
16667 ; Need to initialize in GSINIT1 in
16668 case the user's __sdcc_external_startup uses the xstack.
16678 mov __XPAGE,#(__start__x
16689 mov _spx,#__start__xstack
16692 \begin_layout Verse
16700 \begin_layout Verse
16712 .area GSINIT2 (CODE)
16722 lcall __sdcc_external_startup
16742 jz __sdcc_init_data
16753 __sdcc_program_startup
16758 \begin_layout Verse
16766 \begin_layout Verse
16778 .area GSINIT3 (CODE)
16831 mov r2,#((l_XINIT+255) >> 8)
16862 __XPAGE,#(s_XISEG >> 8)
16864 00001$:\InsetSpace ~
16928 00002$:\InsetSpace ~
16955 \begin_layout Verse
16963 \begin_layout Verse
16975 .area GSINIT4 (CODE)
16977 __mcs51_genRAMCLEAR::
16999 00004$:\InsetSpace ~
17013 ; _mcs51_genRAMCLEAR() end
17016 \begin_layout Verse
17024 \begin_layout Verse
17036 .area GSINIT4 (CODE)
17038 __mcs51_genXRAMCLEAR::
17099 mov __XPAGE,#(s_PSEG >> 8)
17111 00005$:\InsetSpace ~
17186 mov r1,#((l_XSEG + 255) >> 8)
17208 00007$:\InsetSpace ~
17245 \begin_layout Verse
17253 \begin_layout Verse
17265 .area GSINIT5 (CODE)
17267 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
17270 ; and __mcs51_genRAMCLEAR modifies _spx.
17280 mov __XPAGE,#(__start__x
17291 mov _spx,#__start__xstack
17294 \begin_layout Verse
17299 (application modules)
17302 \begin_layout Verse
17314 .area GSINIT (CODE)
17317 \begin_layout Verse
17325 \begin_layout Verse
17337 .area GSFINAL (CODE)
17347 ljmp __sdcc_program_startup
17349 ;---------------------------------
17350 -----------------------
17354 ;--------------------------------------------------
17377 __sdcc_program_startup:
17390 return from main will lock up
17403 \begin_layout Standard
17404 One of these modules (crtstart.asm) contains a call to the C routine
17406 _sdcc_external_startup()
17407 \begin_inset LatexCommand index
17408 name "\\_sdcc\\_external\\_startup()"
17414 at the start of the CODE area.
17415 This routine is also in the runtime library
17416 \begin_inset LatexCommand index
17417 name "Runtime library"
17421 and returns 0 by default.
17422 If this routine returns a non-zero value, the static & global variable
17423 initialization will be skipped and the function main will be invoked.
17424 Otherwise static & global variables will be initialized before the function
17428 _sdcc_external_startup()
17430 routine to your program to override the default if you need to setup hardware
17431 or perform some other critical operation prior to static & global variable
17433 \begin_inset LatexCommand index
17434 name "Variable initialization"
17439 On some mcs51 variants xdata
17440 \begin_inset LatexCommand index
17441 name "xdata (mcs51, ds390 storage class)"
17445 memory has to be explicitly enabled before it can be accessed or if the
17447 \begin_inset LatexCommand index
17452 needs to be disabled, this is the place to do it.
17453 The startup code clears all internal data memory, 256 bytes by default,
17454 but from 0 to n-1 if
17460 \begin_layout Standard
17470 \begin_inset LatexCommand index
17471 name "-\\/-iram-size <Value>"
17478 (recommended for Chipcon CC1010).
17481 \begin_layout Standard
17482 See also the compiler options
17488 \begin_layout Standard
17504 \begin_inset LatexCommand index
17505 name "-\\/-no-xinit-opt"
17515 \begin_layout Standard
17527 \begin_inset LatexCommand index
17528 name "-\\/-main-return"
17533 \begin_inset LatexCommand ref
17534 reference "sub:MCS51-variants"
17538 about MCS51-variants.
17543 \begin_layout Standard
17544 While these initialization modules are meant as generic startup code there
17545 might be the need for customization.
17546 Let's assume the return value of
17548 _sdcc_external_startup()
17554 should not be checked (or
17556 _sdcc_external_startup()
17558 should not be called at all).
17559 The recommended way would be to copy
17565 \begin_inset LatexCommand url
17566 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm"
17570 ) into the source directory, adapt it there, then assemble it with
17576 \begin_layout Standard
17577 \begin_inset Quotes sld
17581 \begin_inset Quotes srd
17584 are the assembler options used in
17585 \begin_inset LatexCommand url
17586 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup "
17597 and when linking your project explicitly specify
17602 As a bonus a listing of the relocated object file
17609 \begin_layout Standard
17610 \begin_inset VSpace bigskip
17616 \begin_layout Subsection
17620 \begin_layout Standard
17622 \begin_inset LatexCommand index
17627 startup code follows the same scheme as the MCS51 startup code.
17628 \begin_inset VSpace bigskip
17634 \begin_layout Subsection
17638 \begin_layout Standard
17640 \begin_inset LatexCommand index
17645 the startup code is inserted by linking with crt0.o which is generated from
17646 sdcc/device/lib/z80/crt0.s.
17647 If you need a different startup code you can use the compiler option
17656 \begin_layout Standard
17671 \begin_inset LatexCommand index
17672 name "-\\/-no-std-crt0"
17676 and provide your own crt0.o.
17678 \begin_inset VSpace bigskip
17684 \begin_layout Section
17685 Inline Assembler Code
17686 \begin_inset LatexCommand index
17687 name "Assembler routines"
17694 \begin_layout Subsection
17695 A Step by Step Introduction
17696 \begin_inset LatexCommand label
17697 name "sub:A-Step-by Assembler Introduction"
17704 \begin_layout Standard
17705 Starting from a small snippet of c-code this example shows for the MCS51
17706 how to use inline assembly, access variables, a function parameter and
17707 an array in xdata memory.
17708 The example uses an MCS51 here but is easily adapted for other architectures.
17709 This is a buffer routine which should be optimized:
17712 \begin_layout Verse
17716 unsigned char __far
17717 \begin_inset LatexCommand index
17718 name "far (storage class)"
17723 \begin_inset LatexCommand index
17724 name "\\_\\_far (storage class)"
17729 \begin_inset LatexCommand index
17735 \begin_inset LatexCommand index
17740 (0x7f00) buf[0x100];
17741 \begin_inset LatexCommand index
17742 name "Aligned array"
17748 unsigned char head, tail;\InsetSpace ~
17766 \begin_inset LatexCommand index
17819 \begin_inset LatexCommand ref
17820 reference "sub:Common-interrupt-pitfall-volatile"
17838 void to_buffer( unsigned char c )
17846 if( head != (unsigned char)(tail-1)
17859 \begin_inset LatexCommand index
17860 name "promotion to signed int"
17865 \begin_inset LatexCommand index
17866 name "type promotion"
17871 \begin_inset Marginal
17874 \begin_layout Standard
17893 buf[ head++ ] = c;\InsetSpace ~
17909 /* access to a 256 byte aligned array */
17914 \begin_layout Standard
17915 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
17916 then a corresponding buffer.asm file is generated.
17917 We define a new function
17921 in file buffer.c in which we cut and paste the generated code, removing
17922 unwanted comments and some ':'.
17924 \begin_inset Quotes sld
17932 \begin_inset Quotes srd
17936 \begin_inset Quotes sld
17944 \begin_inset Quotes srd
17951 \begin_layout Standard
17952 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
17953 and for C-99 compatibility, the double-underscore form (__asm and __endasm)
17955 The latter is also used in the library functions.
17960 to the beginning and the end of the function body:
17963 \begin_layout Verse
17967 /* With a cut and paste from the .asm file, we have something to start with.
17973 function is not yet OK! (registers aren't saved) */
17975 void to_buffer_asm(
17985 \begin_inset LatexCommand index
17991 \begin_inset LatexCommand index
18006 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
18018 \begin_inset LatexCommand index
18019 name "promotion to signed int"
18024 \begin_inset LatexCommand index
18025 name "type promotion"
18078 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
18079 \begin_inset LatexCommand index
18080 name "Aligned array"
18146 \begin_inset LatexCommand index
18152 \begin_inset LatexCommand index
18153 name "\\_\\_endasm"
18162 \begin_layout Standard
18163 The new file buffer.c should compile with only one warning about the unreferenced
18164 function argument 'c'.
18165 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
18166 (1) and finally have:
18169 \begin_layout Verse
18173 unsigned char __far __at(0x7f00) buf[0x100];
18175 unsigned char head, tail;
18186 void to_buffer( unsigned char c )
18195 head != (unsigned char)(tail-1) )
18224 c; // to avoid warning: unreferenced function argument
18231 \begin_inset LatexCommand index
18237 \begin_inset LatexCommand index
18252 ; save used registers here.
18263 ; If we were still using r2,r3 we would have to push them here.
18266 ; if( head != (unsigned char)(tail-1) )
18310 could do an ANL a,#0x0f here to use a smaller buffer (see below)
18346 a,dpl \InsetSpace ~
18353 ; dpl holds lower byte of function argument
18365 dpl,_head \InsetSpace ~
18368 ; buf is 0x100 byte aligned so head can be used directly
18411 ; we could do an ANL _head,#0x0f here to use a
18412 smaller buffer (see above)
18424 ; restore used registers here
18431 \begin_inset LatexCommand index
18437 \begin_inset LatexCommand index
18438 name "\\_\\_endasm"
18449 \begin_layout Standard
18450 The inline assembler code can contain any valid code understood by the assembler
18451 , this includes any assembler directives and comment lines.
18452 The assembler does not like some characters like ':' or ''' in comments.
18453 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
18454 \begin_inset LatexCommand index
18455 name "asXXXX (as-gbz80, as-hc08, asx8051, as-z80)"
18460 \begin_inset LatexCommand index
18461 name "Assembler documentation"
18466 \begin_inset LatexCommand url
18467 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html"
18475 \begin_layout Standard
18476 The compiler does not do any validation of the code within the
18479 \begin_inset LatexCommand index
18485 \begin_inset LatexCommand index
18494 \begin_inset LatexCommand index
18500 \begin_inset LatexCommand index
18501 name "\\_\\_endasm"
18510 Specifically it will not know which registers are used and thus register
18512 \begin_inset LatexCommand index
18517 has to be done manually.
18521 \begin_layout Standard
18522 It is recommended that each assembly instruction (including labels) be placed
18523 in a separate line (as the example shows).
18528 \begin_layout Standard
18540 \begin_inset LatexCommand index
18541 name "-\\/-peep-asm"
18547 command line option is used, the inline assembler code will be passed through
18548 the peephole optimizer
18549 \begin_inset LatexCommand index
18550 name "Peephole optimizer"
18555 There are only a few (if any) cases where this option makes sense, it might
18556 cause some unexpected changes in the inline assembler code.
18557 Please go through the peephole optimizer rules defined in file
18561 before using this option.
18564 \begin_layout Subsection
18566 \begin_inset LatexCommand label
18567 name "sub:Naked-Functions"
18572 \begin_inset LatexCommand index
18573 name "Naked functions"
18580 \begin_layout Standard
18581 A special keyword may be associated with a function declaring it as
18584 \begin_inset LatexCommand index
18590 \begin_inset LatexCommand index
18602 function modifier attribute prevents the compiler from generating prologue
18603 \begin_inset LatexCommand index
18604 name "function prologue"
18609 \begin_inset LatexCommand index
18610 name "function epilogue"
18614 code for that function.
18615 This means that the user is entirely responsible for such things as saving
18616 any registers that may need to be preserved, selecting the proper register
18617 bank, generating the
18621 instruction at the end, etc.
18622 Practically, this means that the contents of the function must be written
18623 in inline assembler.
18624 This is particularly useful for interrupt functions, which can have a large
18625 (and often unnecessary) prologue/epilogue.
18626 For example, compare the code generated by these two functions:
18629 \begin_layout Verse
18633 \begin_inset LatexCommand index
18638 data unsigned char counter;
18642 void simpleInterrupt(void) __interrupt
18643 \begin_inset LatexCommand index
18649 \begin_inset LatexCommand index
18650 name "\\_\\_interrupt"
18668 void nakedInterrupt(void) __interrupt (2) __naked
18677 \begin_inset LatexCommand index
18683 \begin_inset LatexCommand index
18701 _counter ; does not change flags, no need to save psw
18714 include ret or reti in _naked function.
18721 \begin_inset LatexCommand index
18727 \begin_inset LatexCommand index
18728 name "\\_\\_endasm"
18737 \begin_layout Standard
18738 For an 8051 target, the generated simpleInterrupt looks like:
18741 \begin_layout Verse
18754 example, recent versions of SDCC generate
18766 code for simpleInterrupt() and nakedInterrupt()!
18907 \begin_layout Standard
18908 whereas nakedInterrupt looks like:
18911 \begin_layout Verse
18924 _counter ; does not change flags, no need to save psw
18943 MUST explicitly include ret or reti in _naked function
18946 \begin_layout Standard
18947 The related directive #pragma exclude
18948 \begin_inset LatexCommand index
18949 name "\\#pragma exclude"
18953 allows a more fine grained control over pushing & popping
18954 \begin_inset LatexCommand index
18962 \begin_layout Standard
18963 While there is nothing preventing you from writing C code inside a
18967 function, there are many ways to shoot yourself in the foot doing this,
18968 and it is recommended that you stick to inline assembler.
18971 \begin_layout Subsection
18972 Use of Labels within Inline Assembler
18975 \begin_layout Standard
18976 SDCC allows the use of in-line assembler with a few restrictions regarding
18978 All labels defined within inline assembler code have to be of the form
18983 where nnnnn is a number less than 100 (which implies a limit of utmost
18984 100 inline assembler labels
18995 \begin_layout Standard
18996 This is a slightly more stringent rule than absolutely necessary, but stays
18997 always on the safe side.
18998 Labels in the form of nnnnn$ are local labels in the assembler, locality
18999 of which is confined within two labels of the standard form.
19000 The compiler uses the same form for labels within a function (but starting
19001 from nnnnn=00100); and places always a standard label at the beginning
19002 of a function, thus limiting the locality of labels within the scope of
19004 So, if the inline assembler part would be embedded into C-code, an improperly
19005 placed non-local label in the assembler would break up the reference space
19006 for labels created by the compiler for the C-code, leading to an assembling
19010 \begin_layout Standard
19011 The numeric part of local labels does not need to have 5 digits (although
19012 this is the form of labels output by the compiler), any valid integer will
19014 Please refer to the assemblers documentation for further details.
19022 \begin_layout Verse
19026 \begin_inset LatexCommand index
19032 \begin_inset LatexCommand index
19063 \begin_inset LatexCommand index
19069 \begin_inset LatexCommand index
19070 name "\\_\\_endasm"
19077 \begin_layout Standard
19078 Inline assembler code cannot reference any C-labels, however it can reference
19080 \begin_inset LatexCommand index
19085 defined by the inline assembler, e.g.:
19088 \begin_layout Verse
19111 ; some assembler code
19132 /* some more c code */
19134 clabel:\InsetSpace ~
19136 /* inline assembler cannot reference this
19141 \begin_layout Standard
19146 is translated by the compiler into a local label, so the locality of labels
19147 within the function is not broken.
19164 0003$: ;label (can be referenced by inline assembler only)
19171 \begin_inset LatexCommand index
19177 \begin_inset LatexCommand index
19178 name "\\_\\_endasm"
19188 /* some more c code */
19193 \begin_layout Standard
19194 In other words inline assembly code can access labels defined in inline
19195 assembly within the scope of the function.
19196 The same goes the other way, i.e.
19197 labels defines in inline assembly can not be accessed by C statements.
19200 \begin_layout Section
19201 Interfacing with Assembler Code
19202 \begin_inset LatexCommand index
19203 name "Assembler routines"
19210 \begin_layout Subsection
19211 Global Registers used for Parameter Passing
19212 \begin_inset LatexCommand index
19213 name "Parameter passing"
19220 \begin_layout Standard
19221 The compiler always uses the global registers
19224 \begin_inset LatexCommand index
19225 name "DPTR, DPH, DPL"
19230 \begin_inset LatexCommand index
19236 \begin_inset LatexCommand index
19237 name "B (mcs51, ds390 register)"
19246 \begin_inset LatexCommand index
19247 name "ACC (mcs51, ds390 register)"
19253 to pass the first (non-bit) parameter to a function, and also to pass the
19255 \begin_inset LatexCommand index
19256 name "return value"
19260 of function; according to the following scheme: one byte return value in
19265 , two byte value in
19274 three byte values (generic pointers) in
19286 , and four byte values in
19304 \begin_inset LatexCommand index
19305 name "generic pointer"
19309 contain type of accessed memory in
19330 \begin_inset Note Note
19333 \begin_layout Standard
19334 This might not be the case of certain memory models (medium???)
19342 \begin_layout Standard
19343 The second parameter onwards is either allocated on the stack (for reentrant
19348 \begin_layout Standard
19357 -stack-auto is used) or in data/xdata memory (depending on the memory model).
19360 \begin_layout Standard
19361 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
19362 space for reentrant functions or allocated directly in bit memory otherwise.
19365 \begin_layout Standard
19366 Functions (with two or more parameters or bit parameters) that are called
19367 through function pointers
19368 \begin_inset LatexCommand index
19369 name "function pointers"
19373 must therefor be reentrant so the compiler knows how to pass the parameters.
19376 \begin_layout Subsection
19380 \begin_layout Standard
19381 Unless the called function is declared as
19386 \begin_inset LatexCommand index
19395 \begin_layout Standard
19405 \begin_inset LatexCommand index
19406 name "-\\/-callee-saves"
19414 \begin_layout Standard
19423 -all-callee-saves command line option or the corresponding callee_saves
19424 pragma are used, the caller will save the registers (
19428 ) around the call, so the called function can destroy they content freely.
19431 \begin_layout Standard
19432 If the called function is not declared as
19436 , the caller will swap register banks around the call, if caller and callee
19437 use different register banks (having them defined by the
19445 \begin_layout Standard
19446 The called function can also use
19462 observing that they are used for parameter/return value passing.
19465 \begin_layout Subsection
19466 Assembler Routine (non-reentrant)
19469 \begin_layout Standard
19470 In the following example
19471 \begin_inset LatexCommand index
19477 \begin_inset LatexCommand index
19478 name "Assembler routines (non-reentrant)"
19482 the function c_func calls an assembler routine asm_func, which takes two
19484 \begin_inset LatexCommand index
19485 name "function parameter"
19492 \begin_layout Verse
19495 extern int asm_func(unsigned char, unsigned char);
19499 int c_func (unsigned char
19500 i, unsigned char j)
19508 return asm_func(i,j);
19522 return c_func(10,9);
19527 \begin_layout Standard
19528 The corresponding assembler function is:
19531 \begin_layout Verse
19534 .globl _asm_func_PARM_2
19636 \begin_inset LatexCommand index
19637 name "DPTR, DPH, DPL"
19654 \begin_layout Standard
19655 The parameter naming convention is _<function_name>_PARM_<n>, where n is
19656 the parameter number starting from 1, and counting from the left.
19657 The first parameter is passed in
19673 according to the description above.
19674 The variable name for the second parameter will be _<function_name>_PARM_2.
19679 ble the assembler routine with the following command:
19686 asx8051 -losg asmfunc.asm
19693 Then compile and link the assembler routine to the C source file with the
19701 sdcc cfunc.c asmfunc.rel
19704 \begin_layout Subsection
19705 Assembler Routine (reentrant)
19708 \begin_layout Standard
19710 \begin_inset LatexCommand index
19716 \begin_inset LatexCommand index
19717 name "Assembler routines (reentrant)"
19721 the second parameter
19722 \begin_inset LatexCommand index
19723 name "function parameter"
19727 onwards will be passed on the stack, the parameters are pushed from right
19729 before the call the second leftmost parameter will be on the top of the
19730 stack (the leftmost parameter is passed in registers).
19731 Here is an example:
19734 \begin_layout Verse
19737 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
19742 c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
19751 return asm_func(i,j,k);
19765 return c_func(10,9,8);
19770 \begin_layout Standard
19771 The corresponding (unoptimized) assembler routine is:
19774 \begin_layout Verse
19794 _bp,sp\InsetSpace ~
19800 ;stack contains: _bp, return
19801 address, second parameter, third parameter
19825 a,#0xfd\InsetSpace ~
19831 pointer to the second parameter
19855 a,#0xfc\InsetSpace ~
19861 to the rightmost parameter
19902 result (= sum of all three parameters)
19917 ;return value goes into dptr
19951 \begin_layout Standard
19952 The compiling and linking procedure remains the same, however note the extra
19953 entry & exit linkage required for the assembler code, _bp is the stack
19954 frame pointer and is used to compute the offset into the stack for parameters
19955 and local variables.
19956 \begin_inset VSpace bigskip
19962 \begin_layout Section
19964 \begin_inset LatexCommand index
19965 name "int (16 bit)"
19970 \begin_inset LatexCommand index
19971 name "long (32 bit)"
19978 \begin_layout Standard
19979 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
19980 multiplication and modulus operations are implemented by support routines.
19981 These support routines are all developed in ANSI-C to facilitate porting
19982 to other MCUs, although some model specific assembler optimizations are
19984 The following files contain the described routines, all of them can be
19985 found in <installdir>/share/sdcc/lib.
19990 \begin_layout Standard
19992 \begin_inset Tabular
19993 <lyxtabular version="3" rows="11" columns="2">
19995 <column alignment="left" valignment="top" leftline="true" width="0">
19996 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19997 <row topline="true" bottomline="true">
19998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20001 \begin_layout Standard
20009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20012 \begin_layout Standard
20021 <row topline="true">
20022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20025 \begin_layout Standard
20031 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20034 \begin_layout Standard
20035 16 bit multiplication
20041 <row topline="true">
20042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20045 \begin_layout Standard
20051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20054 \begin_layout Standard
20055 signed 16 bit division (calls _divuint)
20061 <row topline="true">
20062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20065 \begin_layout Standard
20071 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20074 \begin_layout Standard
20075 unsigned 16 bit division
20081 <row topline="true">
20082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20085 \begin_layout Standard
20091 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20094 \begin_layout Standard
20095 signed 16 bit modulus (calls _moduint)
20101 <row topline="true">
20102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20105 \begin_layout Standard
20111 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20114 \begin_layout Standard
20115 unsigned 16 bit modulus
20121 <row topline="true">
20122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20125 \begin_layout Standard
20131 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20134 \begin_layout Standard
20135 32 bit multiplication
20141 <row topline="true">
20142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20145 \begin_layout Standard
20151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20154 \begin_layout Standard
20155 signed 32 division (calls _divulong)
20161 <row topline="true">
20162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20165 \begin_layout Standard
20171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20174 \begin_layout Standard
20175 unsigned 32 division
20181 <row topline="true">
20182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20185 \begin_layout Standard
20191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20194 \begin_layout Standard
20195 signed 32 bit modulus (calls _modulong)
20201 <row topline="true" bottomline="true">
20202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20205 \begin_layout Standard
20211 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20214 \begin_layout Standard
20215 unsigned 32 bit modulus
20230 \begin_layout Standard
20231 Since they are compiled as
20236 \begin_inset LatexCommand index
20242 \begin_inset LatexCommand index
20247 service routines should not do any of the above operations.
20248 If this is unavoidable then the above routines will need to be compiled
20255 \begin_layout Standard
20265 \begin_inset LatexCommand index
20266 name "-\\/-stack-auto"
20272 option, after which the source program will have to be compiled with
20278 \begin_layout Standard
20288 \begin_inset LatexCommand index
20289 name "-\\/-int-long-reent"
20296 Notice that you don't have to call these routines directly.
20297 The compiler will use them automatically every time an integer operation
20301 \begin_layout Section
20302 Floating Point Support
20303 \begin_inset LatexCommand index
20304 name "Floating point support"
20311 \begin_layout Standard
20312 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
20313 The floating point support routines are derived from gcc's floatlib.c and
20314 consist of the following routines:
20319 \begin_layout Standard
20323 \begin_inset Tabular
20324 <lyxtabular version="3" rows="17" columns="2">
20326 <column alignment="left" valignment="top" leftline="true" width="0">
20327 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
20328 <row topline="true" bottomline="true">
20329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20332 \begin_layout Standard
20347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20350 \begin_layout Standard
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 add 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 subtract 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 divide floating point numbers
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 multiply floating point numbers
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 char
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 char
20585 <row topline="true">
20586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20589 \begin_layout Standard
20604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20607 \begin_layout Standard
20617 convert floating point to unsigned int
20623 <row topline="true">
20624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20627 \begin_layout Standard
20642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20645 \begin_layout Standard
20655 convert floating point to signed int
20661 <row topline="true">
20662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20665 \begin_layout Standard
20688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20691 \begin_layout Standard
20701 convert floating point to unsigned long
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 floating point to signed long
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 char 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 char to floating point number
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 int to floating point
20859 <row topline="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 int to floating point numbers
20897 <row topline="true">
20898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20901 \begin_layout Standard
20916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20919 \begin_layout Standard
20929 convert unsigned long to floating point number
20935 <row topline="true" bottomline="true">
20936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20939 \begin_layout Standard
20954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20957 \begin_layout Standard
20967 convert long to floating point number
20982 \begin_layout Standard
20983 These support routines are developed in ANSI-C so there is room for space
20984 and speed improvement
20988 \begin_layout Standard
20989 These floating point routines (
20993 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
21000 Note if all these routines are used simultaneously the data space might
21002 For serious floating point usage the large model might be needed.
21003 Also notice that you don't have to call this routines directly.
21004 The compiler will use them automatically every time a floating point operation
21006 \begin_inset VSpace bigskip
21012 \begin_layout Section
21014 \begin_inset LatexCommand index
21022 \begin_layout Standard
21025 <pending: this is messy and incomplete - a little more information is in
21026 sdcc/doc/libdoc.txt
21031 \begin_layout Subsection
21032 Compiler support routines (_gptrget, _mulint etc.)
21035 \begin_layout Subsection
21036 Stdclib functions (puts, printf, strcat etc.)
21039 \begin_layout Subsubsection
21043 \begin_layout Paragraph
21044 getchar(), putchar()
21047 \begin_layout Standard
21048 \begin_inset LatexCommand index
21053 As usual on embedded systems you have to provide your own
21056 \begin_inset LatexCommand index
21066 \begin_inset LatexCommand index
21074 SDCC does not know whether the system connects to a serial line with or
21075 without handshake, LCD, keyboard or other device.
21089 You'll find examples for serial routines f.e.
21090 in sdcc/device/lib.
21091 For the mcs51 this minimalistic polling
21095 routine might be a start:
21098 \begin_layout Verse
21101 void putchar (char c) {
21107 while (!TI)\InsetSpace ~
21110 /* assumes UART is initialized */
21138 \begin_layout Paragraph
21142 \begin_layout Standard
21146 \begin_inset LatexCommand index
21157 does not support float
21158 \begin_inset LatexCommand index
21159 name "Floating point support"
21163 (except on ds390), only <NO FLOAT>
21164 \begin_inset LatexCommand index
21170 \begin_inset LatexCommand index
21171 name "printf floating point support"
21175 will be printed instead of the value.
21176 To enable floating point output, recompile it with the option
21182 \begin_layout Standard
21192 \begin_inset LatexCommand index
21193 name "USE\\_FLOATS"
21199 on the command line.
21206 \begin_layout Standard
21216 \begin_inset LatexCommand index
21217 name "-\\/-model-large"
21223 for the mcs51 port, since this uses a lot of memory.
21224 To enable float support for the pic16 targets, see
21225 \begin_inset LatexCommand ref
21226 reference "sub:pic16Libraries"
21233 \begin_layout Standard
21234 If you're short on code memory you might want to use
21237 \begin_inset LatexCommand index
21238 name "printf\\_small()"
21253 For the mcs51 there additionally are assembly versions
21256 \begin_inset LatexCommand index
21257 name "printf\\_tiny() (mcs51)"
21263 (subset of printf using less than 270 bytes) and
21266 \begin_inset LatexCommand index
21267 name "printf\\_fast() (mcs51)"
21276 \begin_inset LatexCommand index
21277 name "printf\\_fast\\_f() (mcs51)"
21283 (floating-point aware version of printf_fast) which should fit the requirements
21284 of many embedded systems (printf_fast() can be customized by unsetting
21289 support long variables and field widths).
21290 Be sure to use only one of these printf options within a project.
21295 \begin_layout Standard
21296 Feature matrix of different
21303 \begin_layout Standard
21304 \begin_inset Tabular
21305 <lyxtabular version="3" rows="14" columns="7">
21306 <features islongtable="true">
21307 <column alignment="left" valignment="middle" leftline="true" width="14col%">
21308 <column alignment="center" valignment="top" leftline="true" width="0">
21309 <column alignment="center" valignment="top" leftline="true" width="12col%">
21310 <column alignment="center" valignment="top" leftline="true" width="10col%">
21311 <column alignment="center" valignment="top" leftline="true" width="0">
21312 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
21313 <column alignment="center" valignment="top" rightline="true" width="0">
21314 <row topline="true" bottomline="true" endhead="true">
21315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21318 \begin_layout Standard
21327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21330 \begin_layout Standard
21332 \begin_inset LatexCommand index
21342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21345 \begin_layout Standard
21353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21356 \begin_layout Standard
21362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21365 \begin_layout Standard
21371 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21374 \begin_layout Standard
21380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21383 \begin_layout Standard
21390 <row topline="true" endhead="true">
21391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21394 \begin_layout Standard
21400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21403 \begin_layout Standard
21411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21414 \begin_layout Standard
21422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21425 \begin_layout Standard
21433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21436 \begin_layout Standard
21444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21447 \begin_layout Standard
21455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21458 \begin_layout Standard
21467 <row topline="true" endhead="true">
21468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21471 \begin_layout Standard
21472 \begin_inset Quotes sld
21476 \begin_inset Quotes srd
21482 \begin_layout Standard
21488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21491 \begin_layout Standard
21497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21500 \begin_layout Standard
21506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21509 \begin_layout Standard
21515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21518 \begin_layout Standard
21524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21527 \begin_layout Standard
21533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21536 \begin_layout Standard
21543 <row topline="true" endhead="true">
21544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21547 \begin_layout Standard
21551 \begin_layout Standard
21557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21560 \begin_layout Standard
21566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21569 \begin_layout Standard
21575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21578 \begin_layout Standard
21579 0.45k / 0.47k (+ _ltoa)
21584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21587 \begin_layout Standard
21593 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21596 \begin_layout Standard
21602 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21605 \begin_layout Standard
21612 <row topline="true">
21613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21616 \begin_layout Standard
21622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21625 \begin_layout Standard
21635 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21638 \begin_layout Standard
21685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21688 \begin_layout Standard
21727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21730 \begin_layout Standard
21736 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21739 \begin_layout Standard
21745 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21748 \begin_layout Standard
21755 <row topline="true">
21756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21759 \begin_layout Standard
21760 long (32 bit) support
21765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21768 \begin_layout Standard
21774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21777 \begin_layout Standard
21783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21786 \begin_layout Standard
21792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21795 \begin_layout Standard
21801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21804 \begin_layout Standard
21819 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21822 \begin_layout Standard
21829 <row topline="true">
21830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21833 \begin_layout Standard
21834 byte arguments on stack
21839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21842 \begin_layout Standard
21848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21851 \begin_layout Standard
21857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21860 \begin_layout Standard
21866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21869 \begin_layout Standard
21875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21878 \begin_layout Standard
21884 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21887 \begin_layout Standard
21894 <row topline="true">
21895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21898 \begin_layout Standard
21900 \begin_inset LatexCommand index
21901 name "Floating point support"
21910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21913 \begin_layout Standard
21919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21922 \begin_layout Standard
21928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21931 \begin_layout Standard
21937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21940 \begin_layout Standard
21946 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21949 \begin_layout Standard
21954 \begin_layout Standard
21955 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
21965 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21968 \begin_layout Standard
21975 <row topline="true">
21976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21979 \begin_layout Standard
21980 float formats %e %g
21985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21988 \begin_layout Standard
21994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21997 \begin_layout Standard
22003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22006 \begin_layout Standard
22012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22015 \begin_layout Standard
22021 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22024 \begin_layout Standard
22030 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22033 \begin_layout Standard
22040 <row topline="true" bottomline="true">
22041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22044 \begin_layout Standard
22050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22053 \begin_layout Standard
22059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22062 \begin_layout Standard
22068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22071 \begin_layout Standard
22077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22080 \begin_layout Standard
22086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22089 \begin_layout Standard
22095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22098 \begin_layout Standard
22105 <row bottomline="true">
22106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22109 \begin_layout Standard
22114 \begin_layout Standard
22115 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
22119 n'); standard 8051 @ 22.1184 MHz, empty putchar()
22127 \begin_layout Standard
22133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22136 \begin_layout Standard
22142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22145 \begin_layout Standard
22151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22154 \begin_layout Standard
22160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22163 \begin_layout Standard
22169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22172 \begin_layout Standard
22178 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22181 \begin_layout Standard
22188 <row bottomline="true">
22189 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22192 \begin_layout Standard
22197 \begin_layout Standard
22198 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
22207 \begin_layout Standard
22213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22216 \begin_layout Standard
22222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22225 \begin_layout Standard
22231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22234 \begin_layout Standard
22240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22243 \begin_layout Standard
22249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22252 \begin_layout Standard
22258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22261 \begin_layout Standard
22266 \begin_layout Standard
22267 printf_tiny integer speed is data dependent, worst case is 0.33 ms
22278 <row bottomline="true">
22279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22282 \begin_layout Standard
22287 \begin_layout Standard
22288 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
22297 \begin_layout Standard
22303 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22306 \begin_layout Standard
22312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22315 \begin_layout Standard
22321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22324 \begin_layout Standard
22330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22333 \begin_layout Standard
22339 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22342 \begin_layout Standard
22348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22351 \begin_layout Standard
22358 <row bottomline="true">
22359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22362 \begin_layout Standard
22367 \begin_layout Standard
22368 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
22377 \begin_layout Standard
22383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22386 \begin_layout Standard
22392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22395 \begin_layout Standard
22401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22404 \begin_layout Standard
22410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22413 \begin_layout Standard
22419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22422 \begin_layout Standard
22428 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22431 \begin_layout Standard
22445 \begin_layout Subsubsection
22447 \begin_inset LatexCommand index
22455 \begin_layout Standard
22456 As of SDCC 2.6.2 you no longer need to call an initialization routine before
22457 using dynamic memory allocation
22458 \begin_inset LatexCommand index
22459 name "dynamic memory allocation (malloc)"
22464 \begin_inset LatexCommand index
22465 name "heap (malloc)"
22469 space of 1024 bytes is provided for malloc to allocate memory from.
22470 If you need a different heap size you need to recompile _heap.c with the
22471 required size defined in HEAP_SIZE.
22472 It is recommended to make a copy of this file into your project directory
22473 and compile it there with:
22476 \begin_layout Verse
22479 sdcc -c _heap.c -D HEAP_SIZE=2048
22482 \begin_layout Standard
22483 And then link it with:
22486 \begin_layout Verse
22489 sdcc main.rel _heap.rel
22492 \begin_layout Subsection
22493 Math functions (sinf, powf, sqrtf etc.)
22496 \begin_layout Subsubsection
22500 \begin_layout Standard
22501 See definitions in file <math.h>.
22504 \begin_layout Subsection
22508 \begin_layout Standard
22510 \begin_inset LatexCommand index
22515 included in SDCC should have a license at least as liberal as the GNU Lesser
22516 General Public License
22517 \begin_inset LatexCommand index
22518 name "GNU Lesser General Public License, LGPL"
22529 \begin_layout Standard
22530 \begin_inset Note Note
22533 \begin_layout Standard
22534 license statements for the libraries are missing.
22535 sdcc/device/lib/ser_ir.c
22538 \begin_layout Standard
22540 come with a GPL (as opposed to LGPL) License - this will not be liberal
22541 enough for many embedded programmers.
22549 \begin_layout Standard
22550 If you have ported some library or want to share experience about some code
22552 falls into any of these categories Busses (I
22553 \begin_inset Formula $^{\textrm{2}}$
22556 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
22557 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
22558 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
22559 \begin_inset LatexCommand url
22560 target "http://sourceforge.net/mail/?group_id=599"
22565 would certainly like to hear about it.
22568 \begin_layout Standard
22569 Programmers coding for embedded systems are not especially famous for being
22570 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
22571 e these references are very valuable.
22572 Let's help to create a climate where information is shared.
22573 \begin_inset VSpace bigskip
22579 \begin_layout Section
22583 \begin_layout Subsection
22584 MCS51 Memory Models
22585 \begin_inset LatexCommand index
22586 name "Memory model"
22591 \begin_inset LatexCommand index
22592 name "MCS51 memory model"
22599 \begin_layout Subsubsection
22600 Small, Medium and Large
22603 \begin_layout Standard
22604 SDCC allows three memory models for MCS51 code,
22613 Modules compiled with different memory models should
22617 be combined together or the results would be unpredictable.
22618 The library routines supplied with the compiler are compiled as small,
22620 The compiled library modules are contained in separate directories as small,
22621 medium and large so that you can link to the appropriate set.
22624 \begin_layout Standard
22625 When the medium or large model is used all variables declared without a
22626 storage class will be allocated into the external ram, this includes all
22627 parameters and local variables (for non-reentrant
22628 \begin_inset LatexCommand index
22634 When the small model is used variables without storage class are allocated
22635 in the internal ram.
22638 \begin_layout Standard
22639 Judicious usage of the processor specific storage classes
22640 \begin_inset LatexCommand index
22641 name "Storage class"
22645 and the 'reentrant' function type will yield much more efficient code,
22646 than using the large model.
22647 Several optimizations are disabled when the program is compiled using the
22648 large model, it is therefore recommended that the small model be used unless
22649 absolutely required.
22652 \begin_layout Subsubsection
22654 \begin_inset LatexCommand label
22655 name "sub:External-Stack"
22660 \begin_inset LatexCommand index
22666 \begin_inset LatexCommand index
22667 name "External stack (mcs51)"
22674 \begin_layout Standard
22675 The external stack (-
22679 \begin_layout Standard
22689 \begin_inset LatexCommand index
22694 ) is located in pdata
22695 \begin_inset LatexCommand index
22696 name "pdata (mcs51, ds390 storage class)"
22700 memory (usually at the start of the external ram segment) and uses all
22701 unused space in pdata (max.
22707 \begin_layout Standard
22716 -xstack option is used to compile the program, the parameters and local
22718 \begin_inset LatexCommand index
22719 name "local variables"
22723 of all reentrant functions are allocated in this area.
22724 This option is provided for programs with large stack space requirements.
22725 When used with the -
22729 \begin_layout Standard
22739 \begin_inset LatexCommand index
22740 name "-\\/-stack-auto"
22744 option, all parameters and local variables are allocated on the external
22745 stack (note: support libraries will need to be recompiled with the same
22747 There is a predefined target in the library makefile).
22750 \begin_layout Standard
22751 The compiler outputs the higher order address byte of the external ram segment
22753 \begin_inset LatexCommand index
22754 name "P2 (mcs51 sfr)"
22759 \begin_inset LatexCommand ref
22760 reference "sub:MCS51-variants"
22764 ), therefore when using the External Stack option, this port
22768 be used by the application program.
22771 \begin_layout Subsection
22773 \begin_inset LatexCommand index
22774 name "Memory model"
22779 \begin_inset LatexCommand index
22780 name "DS390 memory model"
22787 \begin_layout Standard
22788 The only model supported is Flat 24
22789 \begin_inset LatexCommand index
22790 name "Flat 24 (DS390 memory model)"
22795 This generates code for the 24 bit contiguous addressing mode of the Dallas
22797 In this mode, up to four meg of external RAM or code space can be directly
22799 See the data sheets at www.dalsemi.com for further information on this part.
22804 that the compiler does not generate any code to place the processor into
22805 24 bitmode (although
22809 in the ds390 libraries will do that for you).
22815 \begin_inset LatexCommand index
22816 name "Tinibios (DS390)"
22820 , the boot loader or similar code must ensure that the processor is in 24
22821 bit contiguous addressing mode before calling the SDCC startup code.
22832 \begin_layout Standard
22843 option, variables will by default be placed into the XDATA segment.
22848 Segments may be placed anywhere in the 4 meg address space using the usual
22853 \begin_layout Standard
22863 Note that if any segments are located above 64K, the -r flag must be passed
22864 to the linker to generate the proper segment relocations, and the Intel
22865 HEX output format must be used.
22866 The -r flag can be passed to the linker by using the option
22870 on the SDCC command line.
22871 However, currently the linker can not handle code segments > 64k.
22874 \begin_layout Section
22876 \begin_inset LatexCommand label
22882 \begin_inset LatexCommand index
22890 \begin_layout Standard
22891 Pragmas are used to turn on and/or off certain compiler options.
22892 Some of them are closely related to corresponding command-line options
22894 \begin_inset LatexCommand vref
22895 reference "sec:Command-Line-Options"
22901 Pragmas should be placed before and/or after a function, placing pragmas
22902 inside a function body could have unpredictable results.
22907 following #pragma directives:
22910 \begin_layout Itemize
22916 \begin_inset LatexCommand index
22917 name "\\#pragma save"
22921 - this will save most current options to the save/restore stack.
22922 See #pragma\InsetSpace ~
22926 \begin_layout Itemize
22932 \begin_inset LatexCommand index
22933 name "\\#pragma restore"
22937 - will restore saved options from the last save.
22938 saves & restores can be nested.
22939 SDCC uses a save/restore stack: save pushes current options to the stack,
22940 restore pulls current options from the stack.
22941 See #pragma\InsetSpace ~
22947 \begin_layout Itemize
22953 \begin_inset LatexCommand index
22954 name "\\#pragma callee\\_saves"
22959 \begin_inset LatexCommand index
22960 name "function prologue"
22964 function1[,function2[,function3...]]
22965 \begin_inset LatexCommand label
22966 name "ite:callee_saves-function1[,function2[,function3...]]--"
22970 - The compiler by default uses a caller saves convention for register saving
22971 across function calls, however this can cause unnecessary register pushing
22973 \begin_inset LatexCommand index
22978 when calling small functions from larger functions.
22979 This option can be used to switch off the register saving convention for
22980 the function names specified.
22981 The compiler will not save registers when calling these functions, extra
22982 code need to be manually inserted at the entry and exit for these functions
22983 to save and restore the registers used by these functions, this can SUBSTANTIAL
22984 LY reduce code and improve run time performance of the generated code.
22985 In the future the compiler (with inter procedural analysis) may be able
22986 to determine the appropriate scheme to use for each function call.
22991 \begin_layout Standard
23000 -callee-saves command line option is used (see page
23001 \begin_inset LatexCommand vpageref
23002 reference "lyx:--callee-saves-function1[,function2][,function3]..."
23006 ), the function names specified in #pragma\InsetSpace ~
23008 \begin_inset LatexCommand index
23009 name "\\#pragma callee\\_saves"
23013 is appended to the list of functions specified in the command line.
23016 \begin_layout Itemize
23022 \begin_inset LatexCommand index
23023 name "\\#pragma exclude"
23027 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
23028 of pairs of push/pop
23029 \begin_inset LatexCommand index
23039 \begin_inset LatexCommand index
23053 The directive should be placed immediately before the ISR function definition
23054 and it affects ALL ISR functions following it.
23055 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
23056 exclude\InsetSpace ~
23058 \begin_inset LatexCommand index
23059 name "\\#pragma exclude"
23064 See also the related keyword _naked
23065 \begin_inset LatexCommand index
23071 \begin_inset LatexCommand index
23079 \begin_layout Itemize
23085 \begin_inset LatexCommand index
23091 \begin_inset LatexCommand index
23092 name "\\#pragma less\\_pedantic"
23097 \begin_inset LatexCommand label
23098 name "ite:less_pedantic"
23102 - the compiler will not warn you anymore for obvious mistakes, you're on
23104 See also the command line option -
23108 \begin_layout Standard
23118 \begin_inset LatexCommand vpageref
23119 reference "lyx:--less-pedantic"
23126 More specifically, the following warnings will be disabled:
23128 comparison is always [true/false] due to limited range of data type
23132 overflow in implicit constant conversion
23134 (158); [the (in)famous]
23136 conditional flow changed by optimizer: so said EVELYN the modified DOG
23140 function '[function name]' must return value
23145 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
23146 level) are disabled, too, namely:
23149 \begin_inset Note Note
23152 \begin_layout Standard
23153 dunno what comes here - this warning appears to be unused altogether
23162 [left/right] shifting more than size of object changed to zero
23170 integer overflow in expression
23174 unmatched #pragma save and #pragma restore
23178 comparison of 'signed char' with 'unsigned char' requires promotion to int
23182 ISO C90 does not support flexible array members
23186 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
23190 \begin_inset Note Note
23193 \begin_layout Standard
23194 appears to be always blank - what was supposed to be here?
23203 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
23204 complexity [number]
23209 \begin_layout Itemize
23215 \begin_inset LatexCommand index
23216 name "\\#pragma disable\\_warning"
23220 - the compiler will not warn you anymore about warning number <nnnn>.
23223 \begin_layout Itemize
23229 \begin_inset LatexCommand index
23230 name "\\#pragma nogcse"
23234 - will stop global common subexpression elimination.
23237 \begin_layout Itemize
23243 \begin_inset LatexCommand index
23244 name "\\#pragma noinduction"
23248 - will stop loop induction optimizations.
23251 \begin_layout Itemize
23257 \begin_inset LatexCommand index
23258 name "\\#pragma noinvariant"
23262 - will not do loop invariant optimizations.
23263 For more details see Loop Invariants in section
23264 \begin_inset LatexCommand ref
23265 reference "sub:Loop-Optimizations"
23272 \begin_layout Itemize
23278 \begin_inset LatexCommand index
23279 name "\\#pragma noiv"
23283 - Do not generate interrupt
23284 \begin_inset LatexCommand index
23290 \begin_inset LatexCommand index
23291 name "interrupt vector table"
23295 entries for all ISR functions defined after the pragma.
23296 This is useful in cases where the interrupt vector table must be defined
23297 manually, or when there is a secondary, manually defined interrupt vector
23299 for the autovector feature of the Cypress EZ-USB FX2).
23300 More elegantly this can be achieved by omitting the optional interrupt
23301 number after the interrupt keyword, see section
23302 \begin_inset LatexCommand ref
23303 reference "sub:Interrupt-Service-Routines"
23311 \begin_layout Itemize
23317 \begin_inset LatexCommand index
23318 name "\\#pragma nojtbound"
23322 - will not generate code for boundary value checking, when switch statements
23323 are turned into jump-tables (dangerous).
23324 For more details see section
23325 \begin_inset LatexCommand ref
23326 reference "sub:'switch'-Statements"
23333 \begin_layout Itemize
23339 \begin_inset LatexCommand index
23340 name "\\#pragma noloopreverse"
23344 - Will not do loop reversal optimization
23347 \begin_layout Itemize
23353 \begin_inset LatexCommand index
23354 name "\\#pragma nooverlay"
23358 - the compiler will not overlay the parameters and local variables of a
23362 \begin_layout Itemize
23368 \begin_inset LatexCommand index
23369 name "\\#pragma stackauto"
23377 \begin_layout Standard
23387 \begin_inset LatexCommand index
23388 name "-\\/-stack-auto"
23393 \begin_inset LatexCommand ref
23394 reference "sec:Parameters-and-Local-Variables"
23398 Parameters and Local Variables.
23401 \begin_layout Itemize
23407 \begin_inset LatexCommand index
23408 name "\\#pragma opt\\_code\\_speed"
23412 - The compiler will optimize code generation towards fast code, possibly
23413 at the expense of code size.
23414 Currently this has little effect.
23417 \begin_layout Itemize
23423 \begin_inset LatexCommand index
23424 name "\\#pragma opt\\_code\\_size"
23428 - The compiler will optimize code generation towards compact code, possibly
23429 at the expense of code speed.
23430 Currently this has little effect.
23433 \begin_layout Itemize
23439 \begin_inset LatexCommand index
23440 name "\\#pragma opt\\_code\\_balanced"
23444 - The compiler will attempt to generate code that is both compact and fast,
23445 as long as meeting one goal is not a detriment to the other (this is the
23450 \begin_layout Itemize
23456 \begin_inset LatexCommand index
23457 name "\\#pragma std\\_sdcc89"
23461 - Generally follow the C89 standard, but allow SDCC features that conflict
23462 with the standard (default).
23465 \begin_layout Itemize
23471 \begin_inset LatexCommand index
23472 name "\\#pragma std\\_c89"
23476 - Follow the C89 standard and disable SDCC features that conflict with the
23480 \begin_layout Itemize
23486 \begin_inset LatexCommand index
23487 name "\\#pragma std\\_sdcc99"
23491 - Generally follow the C99 standard, but allow SDCC features that conflict
23492 with the standard (incomplete support).
23495 \begin_layout Itemize
23501 \begin_inset LatexCommand index
23502 name "\\#pragma std\\_c99"
23506 - Follow the C99 standard and disable SDCC features that conflict with the
23507 standard (incomplete support).
23510 \begin_layout Itemize
23516 \begin_inset LatexCommand index
23517 name "\\#pragma codeseg"
23521 - Use this name (max.
23522 8 characters) for the code segment.
23527 \begin_layout Standard
23539 \begin_layout Itemize
23545 \begin_inset LatexCommand index
23546 name "\\#pragma constseg"
23550 - Use this name (max.
23551 8 characters) for the const segment.
23556 \begin_layout Standard
23568 \begin_layout Standard
23569 The preprocessor SDCPP
23570 \begin_inset LatexCommand index
23571 name "sdcpp (preprocessor)"
23575 supports the following #pragma directives:
23578 \begin_layout Itemize
23581 pedantic_parse_number
23584 \begin_inset LatexCommand index
23590 \begin_inset LatexCommand index
23591 name "\\#pragma pedantic\\_parse\\_number"
23596 \begin_inset LatexCommand label
23597 name "ite:pedantic_parse_number"
23601 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
23602 properly and the macro LO_B(3) gets expanded.
23608 \begin_layout Standard
23617 -pedantic-parse-number command line option
23618 \begin_inset LatexCommand vpageref
23619 reference "lyx:-pedantic-parse-number"
23626 Below is an example on how to use this pragma.
23629 Note: this functionality is not in conformance with standard!
23632 \begin_layout Verse
23635 #pragma pedantic_parse_number +
23636 \begin_inset LatexCommand index
23637 name "\\#pragma pedantic\\_parse\\_number"
23645 #define LO_B(x) ((x) & 0xff)
23649 unsigned char foo(void)
23656 unsigned char c=0xfe-LO_B(3)
23671 \begin_layout Itemize
23677 \begin_inset LatexCommand index
23678 name "\\#pragma preproc\\_asm"
23682 (+ | -) - switch _asm _endasm block preprocessing on / off.
23684 You use this pragma to define multilines of assembly code.
23685 This will prevent the preprocessor from changing the formatting required
23687 Below is an example on how to use this pragma.
23690 \begin_layout Verse
23693 #pragma preproc_asm -
23694 \begin_inset LatexCommand index
23695 name "\\#pragma preproc\\_asm"
23701 #define MYDELAY _asm
23706 nop ;my assembly comment...
23720 #pragma preproc_asm
23751 \begin_layout Itemize
23757 \begin_inset LatexCommand index
23758 name "\\#pragma sdcc\\_hash"
23762 (+ | -) - Allow "naked" hash in macro definition, for example:
23766 #define DIR_LO(x) #(x & 0xff)
23771 Below is an example on how to use this pragma.
23774 \begin_layout Verse
23777 #pragma preproc_asm +
23779 #pragma sdcc_hash +
23780 \begin_inset LatexCommand index
23781 name "\\#pragma sdcc\\_hash"
23796 mov R6_B3, #(x & 0xff)
23803 mov R7_B3, #((x >> 8) & 0xff)
23827 \begin_layout Standard
23828 Some of the pragmas are intended to be used to turn-on or off certain optimizati
23829 ons which might cause the compiler to generate extra stack and/or data space
23830 to store compiler generated temporary variables.
23831 This usually happens in large functions.
23832 Pragma directives should be used as shown in the following example, they
23833 are used to control options and optimizations for a given function.
23837 \begin_layout Verse
23841 \begin_inset LatexCommand index
23842 name "\\#pragma save"
23853 /* save the current settings */
23856 \begin_inset LatexCommand index
23857 name "\\#pragma nogcse"
23866 /* turnoff global subexpression elimination */
23868 #pragma noinduction
23869 \begin_inset LatexCommand index
23870 name "\\#pragma noinduction"
23874 /* turn off induction optimizations */
23897 \begin_inset LatexCommand index
23898 name "\\#pragma restore"
23902 /* turn the optimizations back on */
23905 \begin_layout Standard
23906 The compiler will generate a warning message when extra space is allocated.
23907 It is strongly recommended that the save and restore pragmas be used when
23908 changing options for a function.
23917 \begin_layout Section
23918 Defines Created by the Compiler
23921 \begin_layout Standard
23922 The compiler creates the following #defines
23923 \begin_inset LatexCommand index
23929 \begin_inset LatexCommand index
23930 name "Defines created by the compiler"
23939 \begin_layout Standard
23940 \begin_inset Tabular
23941 <lyxtabular version="3" rows="15" columns="2">
23943 <column alignment="left" valignment="top" leftline="true" width="3in">
23944 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
23945 <row topline="true" bottomline="true">
23946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23949 \begin_layout Standard
23957 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23960 \begin_layout Standard
23969 <row topline="true">
23970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23973 \begin_layout Standard
23975 \begin_inset LatexCommand index
23985 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23988 \begin_layout Standard
23990 Since version 2.5.6 the version number as an int (ex.
23997 <row topline="true">
23998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24001 \begin_layout Standard
24003 \begin_inset LatexCommand index
24004 name "SDCC\\_mcs51"
24009 \begin_inset LatexCommand index
24010 name "SDCC\\_ds390"
24015 \begin_inset LatexCommand index
24025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24028 \begin_layout Standard
24029 depending on the model used (e.g.: -mds390)
24035 <row topline="true">
24036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24039 \begin_layout Standard
24041 \begin_inset LatexCommand index
24047 \begin_inset LatexCommand index
24053 \begin_inset LatexCommand index
24059 \begin_inset LatexCommand index
24069 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24072 \begin_layout Standard
24073 depending on the model used (e.g.
24080 <row topline="true">
24081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24084 \begin_layout Standard
24086 \begin_inset LatexCommand index
24087 name "SDCC\\_STACK\\_AUTO"
24096 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24099 \begin_layout Standard
24106 \begin_layout Standard
24123 <row topline="true">
24124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24127 \begin_layout Standard
24129 \begin_inset LatexCommand index
24130 name "SDCC\\_MODEL\\_SMALL"
24139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24142 \begin_layout Standard
24149 \begin_layout Standard
24166 <row topline="true">
24167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24170 \begin_layout Standard
24172 \begin_inset LatexCommand index
24173 name "SDCC\\_MODEL\\_MEDIUM"
24182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24185 \begin_layout Standard
24192 \begin_layout Standard
24209 <row topline="true">
24210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24213 \begin_layout Standard
24215 \begin_inset LatexCommand index
24216 name "SDCC\\_MODEL\\_LARGE"
24225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24228 \begin_layout Standard
24235 \begin_layout Standard
24252 <row topline="true">
24253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24256 \begin_layout Standard
24258 \begin_inset LatexCommand index
24259 name "SDCC\\_USE\\_XSTACK"
24268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24271 \begin_layout Standard
24278 \begin_layout Standard
24295 <row topline="true">
24296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24299 \begin_layout Standard
24301 \begin_inset LatexCommand index
24302 name "SDCC\\_CHAR\\_UNSIGNED"
24311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24314 \begin_layout Standard
24321 \begin_layout Standard
24338 <row topline="true">
24339 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24342 \begin_layout Standard
24344 \begin_inset LatexCommand index
24345 name "SDCC\\_STACK\\_TENBIT"
24354 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24357 \begin_layout Standard
24368 <row topline="true">
24369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24372 \begin_layout Standard
24374 \begin_inset LatexCommand index
24375 name "SDCC\\_MODEL\\_FLAT24"
24384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24387 \begin_layout Standard
24398 <row topline="true">
24399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24402 \begin_layout Standard
24404 \begin_inset LatexCommand index
24405 name "SDCC\\_REVISION"
24414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24417 \begin_layout Standard
24419 SDCC svn revision number
24425 <row topline="true">
24426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24429 \begin_layout Standard
24430 SDCC_PARMS_IN_BANK1
24431 \begin_inset LatexCommand index
24432 name "SDCC\\_PARMS\\_IN\\_BANK1"
24441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24444 \begin_layout Standard
24451 \begin_layout Standard
24468 <row topline="true">
24469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24472 \begin_layout Standard
24474 \begin_inset LatexCommand index
24475 name "SDCC\\_MODEL\\_FLAT24"
24484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24487 \begin_layout Standard
24494 \begin_layout Standard
24511 <row topline="true" bottomline="true">
24512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24515 \begin_layout Standard
24516 SDCC_INT_LONG_REENT
24517 \begin_inset LatexCommand index
24518 name "SDCC\\_INT\\_LONG\\_REENT"
24527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24530 \begin_layout Standard
24537 \begin_layout Standard
24561 \begin_layout Chapter
24562 Notes on supported Processors
24565 \begin_layout Section
24567 \begin_inset LatexCommand label
24568 name "sub:MCS51-variants"
24573 \begin_inset LatexCommand index
24574 name "MCS51 variants"
24581 \begin_layout Standard
24582 MCS51 processors are available from many vendors and come in many different
24584 While they might differ considerably in respect to Special Function Registers
24585 the core MCS51 is usually not modified or is kept compatible.
24589 \begin_layout Subsection
24590 pdata access by SFR
24593 \begin_layout Standard
24594 With the upcome of devices with internal xdata and flash memory devices
24596 \begin_inset LatexCommand index
24597 name "P2 (mcs51 sfr)"
24601 as dedicated I/O port is becoming more popular.
24602 Switching the high byte for pdata
24603 \begin_inset LatexCommand index
24604 name "pdata (mcs51, ds390 storage class)"
24608 access which was formerly done by port P2 is then achieved by a Special
24610 \begin_inset LatexCommand index
24616 In well-established MCS51 tradition the address of this
24620 is where the chip designers decided to put it.
24621 Needless to say that they didn't agree on a common name either.
24622 So that the startup code can correctly initialize xdata variables, you
24623 should define an sfr with the name _XPAGE
24626 \begin_inset LatexCommand index
24627 name "\\_XPAGE (mcs51)"
24633 at the appropriate location if the default, port P2, is not used for this.
24637 \begin_layout Verse
24640 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
24644 \begin_layout Verse
24647 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
24652 \begin_layout Verse
24655 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
24659 \begin_layout Verse
24662 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
24666 \begin_layout Verse
24669 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
24673 \begin_layout Standard
24674 For more exotic implementations further customizations may be needed.
24676 \begin_inset LatexCommand ref
24677 reference "sub:Startup-Code"
24681 for other possibilities.
24684 \begin_layout Subsection
24685 Other Features available by SFR
24688 \begin_layout Standard
24689 Some MCS51 variants offer features like Double DPTR
24690 \begin_inset LatexCommand index
24695 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
24696 These are currently not used for the MCS51 port.
24697 If you absolutely need them you can fall back to inline assembly or submit
24701 \begin_layout Subsection
24705 \begin_layout Standard
24707 \begin_inset LatexCommand index
24708 name "Bankswitching"
24714 \begin_inset LatexCommand index
24715 name "code banking"
24719 ) is a technique to increase the code space above the 64k limit of the 8051.
24722 \begin_layout Subsubsection
24726 \begin_layout Standard
24727 \begin_inset Tabular
24728 <lyxtabular version="3" rows="3" columns="4">
24730 <column alignment="center" valignment="top" width="0">
24731 <column alignment="center" valignment="top" leftline="true" width="0">
24732 <column alignment="center" valignment="top" leftline="true" width="0">
24733 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24734 <row topline="true" bottomline="true">
24735 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24738 \begin_layout Standard
24744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24747 \begin_layout Standard
24753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24756 \begin_layout Standard
24762 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24765 \begin_layout Standard
24772 <row topline="true" bottomline="true">
24773 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24776 \begin_layout Standard
24782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24785 \begin_layout Standard
24791 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24794 \begin_layout Standard
24800 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24803 \begin_layout Standard
24811 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24814 \begin_layout Standard
24815 SiLabs C8051F120 example
24820 <cell multicolumn="2" alignment="center" valignment="top" usebox="none">
24823 \begin_layout Standard
24829 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24832 \begin_layout Standard
24838 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24841 \begin_layout Standard
24856 Usually the hardware uses some sfr (an output port or an internal sfr) to
24857 select a bank and put it in the banked area of the memory map.
24858 The selected bank usually becomes active immediately upon assignment to
24859 this sfr and when running inside a bank it will switch out this code it
24860 is currently running.
24861 Therefor you cannot jump or call directly from one bank to another and
24862 need to use a so-called trampoline in the common area.
24863 For SDCC an example trampoline is in crtbank.asm and you may need to change
24864 it to your 8051 derivative or schematic.
24865 The presented code is written for the C8051F120.
24869 When calling a banked function
24870 SDCC will put the LSB of the functions address in register R0, the MSB
24871 in R1 and the bank in R2 and then call this trampoline
24876 The current selected bank is saved on the stack, the new bank is selected
24877 and an indirect jump is made.
24878 When the banked function returns it jumps to
24882 which restores the previous bank and returns to the caller.
24885 \begin_layout Subsubsection
24889 \begin_layout Standard
24890 When writing banked software using SDCC you need to use some special keywords
24892 You also need to take over a bit of work from the linker.
24896 To create a function
24897 that can be called from another bank it requires the keyword
24902 \begin_inset LatexCommand index
24908 The caller must see this in the prototype of the callee and the callee
24909 needs it for a proper return.
24910 Called functions within the same bank as the caller do not need the
24914 keyword nor do functions in the common area.
24915 Beware: SDCC does not know or check if functions are in the same bank.
24916 This is your responsibility!
24920 Normally all functions you write end up in
24922 If you want a function explicitly to reside in the common area put it in
24924 This applies for instance to interrupt service routines as they should
24928 \begin_layout Standard
24929 Functions that need to be in a switched bank must be put in a named segment.
24930 The name can be mostly anything up to eight characters (e.g.
24932 To do this you either use -
24936 \begin_layout Standard
24945 -codeseg BANK1 (See
24946 \begin_inset LatexCommand ref
24947 reference "lyx:-codeseg"
24951 ) on the command line when compiling or #pragma codeseg BANK1 (See
24952 \begin_inset LatexCommand ref
24953 reference "sec:Pragmas"
24957 ) at the top of the C source file.
24958 The segment name always applies to the whole source file and generated
24959 object so functions for different banks need to be defined in different
24964 When linking your objects you need to tell the linker where
24965 to put your segments.
24966 To do this you use the following command line option to SDCC: -Wl-b BANK1=0x180
24968 \begin_inset LatexCommand ref
24969 reference "lyx:-Wl option"
24974 This sets the virtual start address of this segment.
24975 It sets the banknumber to 0x01 and maps the bank to 0x8000 and up.
24976 The linker will not check for overflows, again this is your responsibility.
24979 \begin_layout Standard
24980 \begin_inset VSpace bigskip
24986 \begin_layout Section
24990 \begin_layout Standard
24992 \begin_inset LatexCommand index
24998 \begin_inset LatexCommand index
25003 microcontroller has a rich set of peripherals.
25004 In its built-in ROM library it includes functions to access some of the
25005 features, among them is a TCP stack with IP4 and IP6 support.
25006 Library headers (currently in beta status) and other files are provided
25010 \begin_inset LatexCommand url
25011 target "ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html"
25017 \begin_inset VSpace bigskip
25023 \begin_layout Section
25024 The Z80 and gbz80 port
25027 \begin_layout Standard
25028 SDCC can target both the Zilog Z80
25029 \begin_inset LatexCommand index
25034 and the Nintendo Gameboy's Z80-like gbz80
25035 \begin_inset LatexCommand index
25036 name "gbz80 (GameBoy Z80)"
25041 The Z80 port is passed through the same
25044 \begin_inset LatexCommand index
25045 name "Regression test"
25052 \begin_inset LatexCommand ref
25053 reference "sec:Quality-control"
25057 ) as the MCS51 and DS390 ports, so floating point support, support for long
25058 variables and bitfield support is fine.
25059 See mailing lists and forums about interrupt routines.
25062 \begin_layout Standard
25063 As always, the code is the authoritative reference - see z80/ralloc.c and
25066 \begin_inset LatexCommand index
25071 frame is similar to that generated by the IAR Z80 compiler.
25072 IX is used as the base pointer, HL and IY are used as a temporary registers,
25073 and BC and DE are available for holding variables.
25075 \begin_inset LatexCommand index
25076 name "Z80!return value"
25080 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
25082 The gbz80 port use the same set of registers for the return values, but
25083 in a different order of significance: E (one byte), DE (two bytes), or
25085 \begin_inset VSpace bigskip
25091 \begin_layout Section
25095 \begin_layout Standard
25096 The port to the Freescale/Motorola HC08
25097 \begin_inset LatexCommand index
25102 family has been added in October 2003, and is still undergoing some basic
25104 The code generator is complete, but the register allocation is still quite
25106 Some of the SDCC's standard C library functions have embedded non-HC08
25107 inline assembly and so are not yet usable.
25110 \begin_layout Standard
25111 The HC08 port passes the regression test suite (see section
25112 \begin_inset LatexCommand ref
25113 reference "sec:Quality-control"
25118 \begin_inset VSpace bigskip
25124 \begin_layout Section
25126 \begin_inset LatexCommand index
25134 \begin_layout Standard
25135 The PIC14 port adds support for Microchip
25136 \begin_inset LatexCommand index
25142 \begin_inset Formula $^{\text{TM}}$
25146 \begin_inset LatexCommand index
25152 \begin_inset Formula $^{\text{TM}}$
25155 MCUs with 14 bit wide instructions.
25156 This port is not yet mature and still lacks many features.
25157 However, it can work for simple code.
25160 \begin_layout Standard
25162 Currently supported devices include:
25165 \begin_layout Standard
25166 12F: 629, 635, 675, 683
25169 \begin_layout Standard
25173 \begin_layout Standard
25177 \begin_layout Standard
25178 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
25181 \begin_layout Standard
25182 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
25186 \begin_layout Standard
25190 \begin_layout Standard
25191 16CR: 620a, 73, 74, 76, 77
25194 \begin_layout Standard
25195 16F: 616, 627, 627a, 628, 628a, 630, 636, 639, 648, 648a, 676, 684, 685,
25199 \begin_layout Standard
25200 16F: 716, 72, 73, 737, 74, 747, 76, 767, 77, 777, 785
25203 \begin_layout Standard
25204 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
25205 877, 877a, 88, 886, 887
25208 \begin_layout Standard
25209 16F: 913, 914, 916, 917, 946
25212 \begin_layout Standard
25216 \begin_layout Standard
25218 An up-to-date list of currently supported devices can be obtained via
25220 sdcc -mpic14 -phelp foo.c
25222 (foo.c must exist...).
25225 \begin_layout Subsection
25227 \begin_inset LatexCommand index
25228 name "code page (pic14)"
25233 \begin_inset LatexCommand index
25234 name "Memory bank (pic14)"
25241 \begin_layout Standard
25242 The linker organizes allocation for the code page and RAM banks.
25243 It does not have intimate knowledge of the code flow.
25244 It will put all the code section of a single .asm file into a single code
25246 In order to make use of multiple code pages, separate asm files must be
25248 The compiler assigns all
25252 functions of a single .c file into the same code page.
25256 To get the best results,
25257 follow these guidelines:
25260 \begin_layout Enumerate
25261 Make local functions static, as non static functions require code page selection
25264 Due to the way sdcc handles functions, place called functions prior
25265 to calling functions in the file wherever possible: Otherwise sdcc will
25266 insert unnecessary pagesel directives around the call, believing that the
25267 called function is externally defined.
25270 \begin_layout Enumerate
25271 For devices that have multiple code pages it is more efficient to use the
25272 same number of files as pages: Use up to 4 separate .c files for the 16F877,
25273 but only 2 files for the 16F874.
25274 This way the linker can put the code for each file into different code
25275 pages and there will be less page selection overhead.
25278 \begin_layout Enumerate
25279 And as for any 8 bit micro (especially for PIC14 as they have a very simple
25280 instruction set), use `unsigned char' wherever possible instead of `int'.
25283 \begin_layout Subsection
25284 Adding New Devices to the Port
25287 \begin_layout Standard
25288 Adding support for a new 14
25292 \begin_layout Standard
25301 bit PIC MCU requires the following steps:
25304 \begin_layout Enumerate
25305 Create a new device description.
25307 Each device is described in two files: pic16f*.h
25309 These files primarily define SFRs, structs to access their bits, and symbolic
25310 configuration options.
25311 Both files can be generated from gputils' .inc files using the perl script
25314 support/scripts/inc2h.pl
25317 This file also contains further instructions on how to proceed.
25320 \begin_layout Enumerate
25321 Copy the .h file into SDCC's include path and either add the .c file to your
25322 project or copy it to
25324 device/lib/pic/libdev
25327 Afterwards, rebuild and install the libraries.
25330 \begin_layout Enumerate
25331 Edit pic14devices.txt in SDCC's include path (
25333 device/include/pic/
25335 in the source tree or
25337 /usr/local/share/sdcc/include/pic
25339 after installation).
25341 You need to add a device specification here to make
25342 the memory layout (code banks, RAM, aliased memory regions, ...) known to
25344 Probably you can copy and modify an existing entry.
25345 The file format is documented at the top of the file.
25348 \begin_layout Subsection
25352 \begin_layout Standard
25353 For the interrupt function, use the keyword `__interrupt'
25354 \begin_inset LatexCommand index
25355 name "PIC14!interrupt"
25359 with level number of 0 (PIC14 only has 1 interrupt so this number is only
25360 there to avoid a syntax error - it ought to be fixed).
25364 \begin_layout Verse
25367 void Intr(void) __interrupt 0
25373 T0IF = 0; /* Clear timer interrupt */
25378 \begin_layout Subsection
25379 Linking and Assembling
25382 \begin_layout Standard
25383 For assembling you can use either GPUTILS'
25384 \begin_inset LatexCommand index
25385 name "gputils (pic tools)"
25389 gpasm.exe or MPLAB's mpasmwin.exe.
25390 GPUTILS are available from
25391 \begin_inset LatexCommand url
25392 target "http://sourceforge.net/projects/gputils"
25397 For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
25398 If you use MPLAB and an interrupt function then the linker script file
25399 vectors section will need to be enlarged to link with mplink.
25410 \begin_layout Verse
25423 sdcc -V -mpic14 -p16f877 -c $<
25427 $(PRJ).hex: $(OBJS)
25437 gplink -m -s $(PRJ).lkr
25438 -o $(PRJ).hex $(OBJS) libsdcc.lib
25441 \begin_layout Standard
25449 \begin_layout Verse
25462 sdcc -S -V -mpic14 -p16f877 $<
25472 mpasmwin /q /o $*.asm
25476 $(PRJ).hex: $(OBJS)
25487 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
25490 \begin_layout Standard
25491 Please note that indentations within a
25495 have to be done with a tabulator character.
25498 \begin_layout Subsection
25499 Command-Line Options
25502 \begin_layout Standard
25503 Besides the switches common to all SDCC backends, the PIC14 port accepts
25504 the following options (for an updated list see sdcc -
25508 \begin_layout Standard
25520 \begin_layout Description
25525 \begin_layout Standard
25535 \begin_inset LatexCommand index
25536 name "PIC14!Options!-\\/-debug-extra"
25540 emit debug info in assembly output
25543 \begin_layout Description
25548 \begin_layout Standard
25558 \begin_inset LatexCommand index
25559 name "PIC14!Options!-\\/-no-pcode-opt"
25563 disable (slightly faulty) optimization on pCode
25566 \begin_layout Description
25571 \begin_layout Standard
25581 \begin_inset LatexCommand index
25582 name "PIC14!Options!-\\/-stack-loc"
25586 sets the lowest address of the argument passing stack (defaults to a suitably
25587 large shared databank to reduce BANKSEL overhead)
25590 \begin_layout Description
25595 \begin_layout Standard
25605 \begin_inset LatexCommand index
25606 name "PIC14!Options!-\\/-stack-size"
25610 sets the size if the argument passing stack (default: 16, minimum: 4)
25613 \begin_layout Subsection
25614 Environment Variables
25617 \begin_layout Standard
25618 The PIC14 port recognizes the following environment variables:
25621 \begin_layout Description
25622 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
25623 register (the ones called r0xNNNN) in a section of its own.
25624 By default (if this variable is unset), sdcc tries to cluster registers
25625 in sections in order to reduce the BANKSEL overhead when accessing them.
25628 \begin_layout Subsection
25632 \begin_layout Standard
25633 The PIC14 library currently only contains support routines required by the
25634 compiler to implement multiplication, division, and floating point support.
25635 No libc-like replacement is available at the moment, though many of the
25636 common sdcc library sources (in
25640 ) should also compile with the PIC14 port.
25643 \begin_layout Subsubsection
25644 error: missing definition for symbol ``__gptrget1''
25647 \begin_layout Standard
25648 The PIC14 port uses library routines to provide more complex operations
25649 like multiplication, division/modulus and (generic) pointer dereferencing.
25650 In order to add these routines to your project, you must link with PIC14's
25656 For single source file projects this is done automatically, more complex
25661 to the linker's arguments.
25662 Make sure you also add an include path for the library (using the -I switch
25666 \begin_layout Subsubsection
25667 Processor mismatch in file ``XXX''.
25670 \begin_layout Standard
25671 This warning can usually be ignored due to the very good compatibility amongst
25676 \begin_layout Standard
25686 \begin_inset LatexCommand index
25694 \begin_layout Standard
25695 You might also consider recompiling the library for your specific device
25696 by changing the ARCH=p16f877 (default target) entry in
25698 device/lib/pic/Makefile.in
25702 device/lib/pic/Makefile
25704 to reflect your device.
25705 This might even improve performance for smaller devices as unnecessary
25706 BANKSELs might be removed.
25709 \begin_layout Subsection
25713 \begin_layout Subsubsection
25717 \begin_layout Standard
25718 Functions with variable argument lists (like printf) are not yet supported.
25719 Similarly, taking the address of the first argument passed into a function
25720 does not work: It is currently passed in WREG and has no address...
25723 \begin_layout Subsubsection
25724 Regression tests fail
25727 \begin_layout Standard
25728 Though the small subset of regression tests in src/regression passes, SDCC
25729 regression test suite does not, indicating that there are still major bugs
25731 However, many smaller projects have successfully used SDCC in the past...
25734 \begin_layout Standard
25742 \begin_layout Section
25744 \begin_inset LatexCommand index
25752 \begin_layout Standard
25753 The PIC16 port adds support for Microchip
25754 \begin_inset LatexCommand index
25760 \begin_inset Formula $^{\text{TM}}$
25764 \begin_inset LatexCommand index
25770 \begin_inset Formula $^{\text{TM}}$
25773 MCUs with 16 bit wide instructions.
25774 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
25775 ; devices supported by the port include:
25778 \begin_layout Standard
25779 18F: 242, 248, 252, 258, 442, 448, 452, 458
25782 \begin_layout Standard
25786 \begin_layout Standard
25787 18F: 2220, 2221, 2320, 2321, 2331, 23k20
25790 \begin_layout Standard
25791 18F: 2410, 2420, 2423, 2431, 2450, 2455, 2480, 24j10, 24k20
25794 \begin_layout Standard
25795 18F: 2510, 2515, 2520, 2523, 2525, 2550, 2580, 2585, 25j10, 25k20
25798 \begin_layout Standard
25799 18F: 2610, 2620, 2680, 2682, 2685
25802 \begin_layout Standard
25803 18F: 4220, 4221, 4320, 4321, 4331, 43k20
25806 \begin_layout Standard
25807 18F: 4410, 4420, 4423, 4431, 4450, 4455, 4480, 44j10, 44k20
25810 \begin_layout Standard
25811 18F: 4510, 4515, 4520, 4523, 4525, 4550, 4580, 4585, 45j10, 45k20
25814 \begin_layout Standard
25815 18F: 4610, 4620, 4680, 4682, 4685, 46k20
25818 \begin_layout Standard
25819 18F: 6520, 6585, 65j50, 6620, 6680, 66j50, 66j55, 66j60, 66j65, 6720, 67j50,
25823 \begin_layout Standard
25824 18F: 8520, 8585, 85j50, 8620, 8680, 86j50, 86j55, 86j60, 86j65, 8720, 87j50,
25828 \begin_layout Standard
25829 18F: 96j60, 96j65, 97j60
25832 \begin_layout Standard
25834 An up-to-date list of supported devices is also available via '
25836 sdcc -mpic16 -plist
25841 \begin_layout Subsection
25845 \begin_layout Standard
25846 PIC16 port supports the standard command line arguments as supposed, with
25847 the exception of certain cases that will be mentioned in the following
25851 \begin_layout Description
25856 \begin_layout Standard
25866 \begin_inset LatexCommand index
25867 name "PIC16!Options!-\\/-callee-saves"
25875 \begin_layout Standard
25887 \begin_layout Description
25892 \begin_layout Standard
25901 -fommit-frame-pointer
25902 \begin_inset LatexCommand index
25903 name "PIC16!Options!-\\/-fommit-frame-pointer"
25907 Frame pointer will be omitted when the function uses no local variables.
25910 \begin_layout Subsection
25911 Port Specific Options
25912 \begin_inset LatexCommand index
25913 name "Options PIC16"
25920 \begin_layout Standard
25921 The port specific options appear after the global options in the sdcc -
25925 \begin_layout Standard
25937 \begin_layout Subsubsection
25938 Code Generation Options
25941 \begin_layout Standard
25942 These options influence the generated assembler code.
25945 \begin_layout Description
25950 \begin_layout Standard
25959 -pstack-model=[model] Used in conjunction with the command above.
25960 Defines the stack model to be used, valid stack models are:
25965 \labelwidthstring 00.00.0000
25970 Selects small stack model.
25971 8 bit stack and frame pointers.
25972 Supports 256 bytes stack size.
25976 \labelwidthstring 00.00.0000
25981 Selects large stack model.
25982 16 bit stack and frame pointers.
25983 Supports 65536 bytes stack size.
25987 \begin_layout Description
25992 \begin_layout Standard
26001 -pno-banksel Do not generate BANKSEL assembler directives.
26004 \begin_layout Description
26009 \begin_layout Standard
26018 -extended Enable extended instruction set/literal offset addressing mode.
26022 \begin_layout Subsubsection
26023 Optimization Options
26026 \begin_layout Description
26031 \begin_layout Standard
26040 -obanksel=n Set optimization level for inserting BANKSELs.
26047 \labelwidthstring 00.00.0000
26052 \labelwidthstring 00.00.0000
26053 1 checks previous used register and if it is the same then does not emit
26054 BANKSEL, accounts only for labels.
26058 \labelwidthstring 00.00.0000
26059 2 tries to check the location of (even different) symbols and removes BANKSELs
26060 if they are in the same bank.
26065 Important: There might be problems if the linker script has data sections
26066 across bank borders!
26070 \begin_layout Description
26075 \begin_layout Standard
26084 -denable-peeps Force the usage of peepholes.
26088 \begin_layout Description
26093 \begin_layout Standard
26102 -no-optimize-goto Do not use (conditional) BRA instead of GOTO.
26105 \begin_layout Description
26110 \begin_layout Standard
26119 -optimize-cmp Try to optimize some compares.
26122 \begin_layout Description
26127 \begin_layout Standard
26136 -optimize-df Analyze the dataflow of the generated code and improve it.
26139 \begin_layout Subsubsection
26143 \begin_layout Description
26148 \begin_layout Standard
26157 -asm= Sets the full path and name of an external assembler to call.
26160 \begin_layout Description
26165 \begin_layout Standard
26175 \begin_inset LatexCommand index
26180 compatibility option.
26181 Currently only suppresses special gpasm directives.
26184 \begin_layout Subsubsection
26188 \begin_layout Description
26193 \begin_layout Standard
26202 -link= Sets the full path and name of an external linker to call.
26205 \begin_layout Description
26210 \begin_layout Standard
26219 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
26220 unitialized data variables with [kword].
26221 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
26224 \begin_layout Description
26229 \begin_layout Standard
26238 -ivt-loc=n Place the interrupt vector table at address
26243 Useful for bootloaders.
26246 \begin_layout Description
26251 \begin_layout Standard
26260 -nodefaultlibs Do not link default libraries when linking.
26263 \begin_layout Description
26268 \begin_layout Standard
26277 -use-crt= Use a custom run-time module instead of the defaults.
26280 \begin_layout Description
26285 \begin_layout Standard
26294 -no-crt Don't link the default run-time modules
26297 \begin_layout Subsubsection
26301 \begin_layout Standard
26302 Debugging options enable extra debugging information in the output files.
26305 \begin_layout Description
26310 \begin_layout Standard
26319 -debug-xtra Similar to -
26323 \begin_layout Standard
26333 \begin_inset LatexCommand index
26338 , but dumps more information.
26341 \begin_layout Description
26346 \begin_layout Standard
26355 -debug-ralloc Force register allocator to dump <source>.d file with debugging
26357 <source> is the name of the file being compiled.
26360 \begin_layout Description
26365 \begin_layout Standard
26374 -pcode-verbose Enable pcode debugging information in translation.
26377 \begin_layout Description
26382 \begin_layout Standard
26391 -calltree Dump call tree in .calltree file.
26394 \begin_layout Description
26399 \begin_layout Standard
26408 -gstack Trace push/pops for stack pointer overflow.
26411 \begin_layout Subsection
26412 Environment Variables
26415 \begin_layout Standard
26416 There is a number of environmental variables that can be used when running
26417 SDCC to enable certain optimizations or force a specific program behaviour.
26418 these variables are primarily for debugging purposes so they can be enabled/dis
26422 \begin_layout Standard
26423 Currently there is only two such variables available:
26426 \begin_layout Description
26427 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
26428 bitfields is optimized by directly loading FSR0 with the address of the
26429 bitfield structure.
26430 Normally SDCC will cast the bitfield structure to a bitfield pointer and
26432 This step saves data ram and code space for functions that make heavy use
26434 (i.e., 80 bytes of code space are saved when compiling malloc.c with this
26439 \begin_layout Description
26440 NO_REG_OPT Do not perform pCode registers optimization.
26441 This should be used for debugging purposes.
26442 If bugs in the pcode optimizer are found, users can benefit from temporarily
26443 disabling the optimizer until the bug is fixed.
26446 \begin_layout Subsection
26447 Preprocessor Macros
26450 \begin_layout Standard
26452 \begin_inset LatexCommand index
26457 port defines the following preprocessor macros while translating a source.
26460 \begin_layout Standard
26462 \begin_inset Tabular
26463 <lyxtabular version="3" rows="6" columns="2">
26465 <column alignment="center" valignment="top" leftline="true" width="0">
26466 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26467 <row topline="true" bottomline="true">
26468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26471 \begin_layout Standard
26477 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26480 \begin_layout Standard
26487 <row topline="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
26501 Port identification
26507 <row topline="true">
26508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26511 \begin_layout Standard
26516 \begin_layout Standard
26530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26533 \begin_layout Standard
26534 Port identification (same as above)
26540 <row topline="true">
26541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26544 \begin_layout Standard
26550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26553 \begin_layout Standard
26554 MCU Identification.
26559 is the microcontrol identification number, i.e.
26566 <row topline="true">
26567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26570 \begin_layout Standard
26575 \begin_layout Standard
26589 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26592 \begin_layout Standard
26593 MCU Identification (same as above)
26599 <row topline="true" bottomline="true">
26600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26603 \begin_layout Standard
26609 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26612 \begin_layout Standard
26613 nnn = SMALL or LARGE respectively according to the stack model used
26626 \begin_layout Standard
26628 In addition the following macros are defined when calling assembler:
26631 \begin_layout Standard
26633 \begin_inset Tabular
26634 <lyxtabular version="3" rows="4" columns="2">
26636 <column alignment="center" valignment="top" leftline="true" width="0">
26637 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26638 <row topline="true" bottomline="true">
26639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26642 \begin_layout Standard
26648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26651 \begin_layout Standard
26658 <row topline="true">
26659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26662 \begin_layout Standard
26668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26671 \begin_layout Standard
26672 MCU Identification.
26677 is the microcontrol identification number, i.e.
26684 <row topline="true">
26685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26688 \begin_layout Standard
26694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26697 \begin_layout Standard
26698 nnn = SMALL or LARGE respectively according to the memory model used for
26705 <row topline="true" bottomline="true">
26706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26709 \begin_layout Standard
26715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26718 \begin_layout Standard
26719 nnn = SMALL or LARGE respectively according to the stack model used
26732 \begin_layout Subsection
26736 \begin_layout Standard
26738 \begin_inset LatexCommand index
26743 port uses the following directories for searching header files and libraries.
26746 \begin_layout Standard
26748 \begin_inset Tabular
26749 <lyxtabular version="3" rows="3" columns="4">
26751 <column alignment="center" valignment="top" leftline="true" width="0">
26752 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26753 <column alignment="center" valignment="top" width="0">
26754 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26755 <row topline="true" bottomline="true">
26756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26759 \begin_layout Standard
26765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26768 \begin_layout Standard
26774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26777 \begin_layout Standard
26783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26786 \begin_layout Standard
26793 <row topline="true">
26794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26797 \begin_layout Standard
26798 PREFIX/sdcc/include/pic16
26803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26806 \begin_layout Standard
26807 PIC16 specific headers
26812 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26815 \begin_layout Standard
26821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26824 \begin_layout Standard
26831 <row topline="true" bottomline="true">
26832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26835 \begin_layout Standard
26836 PREFIX/sdcc/lib/pic16
26841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26844 \begin_layout Standard
26845 PIC16 specific libraries
26850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26853 \begin_layout Standard
26859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26862 \begin_layout Standard
26876 \begin_layout Subsection
26878 \begin_inset LatexCommand label
26879 name "sub:PIC16_Pragmas"
26886 \begin_layout Standard
26888 \begin_inset LatexCommand index
26893 port currently supports the following pragmas:
26896 \begin_layout Description
26898 \begin_inset LatexCommand index
26899 name "PIC16!Pragmas!\\#pragma stack"
26903 This forces the code generator to initialize the stack & frame pointers
26904 at a specific address.
26905 This is an ad hoc solution for cases where no STACK directive is available
26906 in the linker script or gplink is not instructed to create a stack section.
26909 stack pragma should be used only once in a project.
26910 Multiple pragmas may result in indeterminate behaviour of the program.
26914 \begin_layout Standard
26915 The old format (ie.
26916 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
26917 cross page boundaries (or even exceed the available data RAM) and crash
26919 Make sure that stack does not cross page boundaries when using the SMALL
26927 The format is as follows:
26932 \begin_layout LyX-Code
26933 #pragma stack bottom_address [stack_size]
26938 \begin_layout Standard
26943 is the lower bound of the stack section.
26944 The stack pointer initially will point at address (bottom_address+stack_size-1).
26947 \begin_layout LyX-Code
26951 \begin_layout LyX-Code
26955 \begin_layout LyX-Code
26956 /* initializes stack of 100 bytes at RAM address 0x200 */
26959 \begin_layout LyX-Code
26960 #pragma stack 0x200 100
26963 \begin_layout Standard
26964 If the stack_size field is omitted then a stack is created with the default
26966 This size might be enough for most programs, but its not enough for operations
26967 with deep function nesting or excessive stack usage.
26970 \begin_layout Description
26972 \begin_inset LatexCommand index
26973 name "PIC16!Pragmas!\\#pragma code"
26977 Force a function to a static FLASH address.
26980 \begin_layout LyX-Code
26984 \begin_layout LyX-Code
26988 \begin_layout LyX-Code
26989 /* place function test_func at 0x4000 */
26992 \begin_layout LyX-Code
26993 #pragma code test_func 0x4000
26996 \begin_layout LyX-Code
27000 \begin_layout Description
27001 library instructs the linker to use a library module.
27006 \begin_layout LyX-Code
27007 #pragma library module_name
27010 \begin_layout Standard
27015 can be any library or object file (including its path).
27016 Note that there are four reserved keywords which have special meaning.
27020 \begin_layout Standard
27022 \begin_inset Tabular
27023 <lyxtabular version="3" rows="6" columns="3">
27025 <column alignment="center" valignment="top" leftline="true" width="0">
27026 <column alignment="block" valignment="top" leftline="true" width="20page%">
27027 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
27028 <row topline="true" bottomline="true">
27029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27032 \begin_layout Standard
27038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27041 \begin_layout Standard
27047 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27050 \begin_layout Standard
27057 <row topline="true">
27058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27061 \begin_layout Standard
27069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27072 \begin_layout Standard
27073 ignore all library pragmas
27078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27081 \begin_layout Standard
27090 <row topline="true">
27091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27094 \begin_layout Standard
27102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27105 \begin_layout Standard
27111 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27114 \begin_layout Standard
27125 <row topline="true">
27126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27129 \begin_layout Standard
27137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27140 \begin_layout Standard
27141 link the Math libarary
27146 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27149 \begin_layout Standard
27160 <row topline="true">
27161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27164 \begin_layout Standard
27172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27175 \begin_layout Standard
27176 link the I/O library
27181 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27184 \begin_layout Standard
27195 <row topline="true" bottomline="true">
27196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27199 \begin_layout Standard
27207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27210 \begin_layout Standard
27211 link the debug library
27216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27219 \begin_layout Standard
27236 * is the device number, i.e.
27237 452 for PIC18F452 MCU.
27240 \begin_layout Standard
27242 This feature allows for linking with specific libraries without having to
27243 explicit name them in the command line.
27248 keyword will reject all modules specified by the library pragma.
27251 \begin_layout Description
27252 udata The pragma udata instructs the compiler to emit code so that linker
27253 will place a variable at a specific memory bank.
27256 \begin_layout LyX-Code
27260 \begin_layout LyX-Code
27264 \begin_layout LyX-Code
27265 /* places variable foo at bank2 */
27268 \begin_layout LyX-Code
27269 #pragma udata bank2 foo
27272 \begin_layout LyX-Code
27276 \begin_layout Standard
27277 In order for this pragma to work extra SECTION directives should be added
27278 in the .lkr script.
27279 In the following example a sample .lkr file is shown:
27282 \begin_layout LyX-Code
27286 \begin_layout LyX-Code
27287 // Sample linker script for the PIC18F452 processor
27290 \begin_layout LyX-Code
27294 \begin_layout LyX-Code
27295 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
27298 \begin_layout LyX-Code
27299 CODEPAGE NAME=page START=0x2A END=0x7FFF
27302 \begin_layout LyX-Code
27303 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
27306 \begin_layout LyX-Code
27307 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
27310 \begin_layout LyX-Code
27311 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
27314 \begin_layout LyX-Code
27315 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
27318 \begin_layout LyX-Code
27319 ACCESSBANK NAME=accessram START=0x0 END=0x7F
27322 \begin_layout LyX-Code
27326 \begin_layout LyX-Code
27327 DATABANK NAME=gpr0 START=0x80 END=0xFF
27330 \begin_layout LyX-Code
27331 DATABANK NAME=gpr1 START=0x100 END=0x1FF
27334 \begin_layout LyX-Code
27335 DATABANK NAME=gpr2 START=0x200 END=0x2FF
27338 \begin_layout LyX-Code
27339 DATABANK NAME=gpr3 START=0x300 END=0x3FF
27342 \begin_layout LyX-Code
27343 DATABANK NAME=gpr4 START=0x400 END=0x4FF
27346 \begin_layout LyX-Code
27347 DATABANK NAME=gpr5 START=0x500 END=0x5FF
27350 \begin_layout LyX-Code
27351 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
27354 \begin_layout LyX-Code
27358 \begin_layout LyX-Code
27359 SECTION NAME=CONFIG ROM=config
27362 \begin_layout LyX-Code
27366 \begin_layout LyX-Code
27367 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
27370 \begin_layout LyX-Code
27371 SECTION NAME=bank1 RAM=gpr1 # should be added to link
27374 \begin_layout LyX-Code
27375 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
27378 \begin_layout LyX-Code
27379 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
27382 \begin_layout LyX-Code
27383 SECTION NAME=bank4 RAM=gpr4
27386 \begin_layout LyX-Code
27387 SECTION NAME=bank5 RAM=gpr5
27390 \begin_layout Standard
27391 The linker will recognise the section name set in the pragma statement and
27392 will position the variable at the memory bank set with the RAM field at
27393 the SECTION line in the linker script file.
27396 \begin_layout Subsection
27398 \begin_inset LatexCommand label
27399 name "sub:PIC16_Header-Files"
27406 \begin_layout Standard
27407 There is one main header file
27408 \begin_inset LatexCommand index
27409 name "PIC16!Header files"
27413 that can be included to the source files using the pic16
27414 \begin_inset LatexCommand index
27425 This header file contains the definitions for the processor special registers,
27426 so it is necessary if the source accesses them.
27427 It can be included by adding the following line in the beginning of the
27431 \begin_layout LyX-Code
27432 #include <pic18fregs.h>
27435 \begin_layout Standard
27436 The specific microcontroller is selected within the pic18fregs.h automatically,
27437 so the same source can be used with a variety of devices.
27440 \begin_layout Subsection
27442 \begin_inset LatexCommand label
27443 name "sub:pic16Libraries"
27450 \begin_layout Standard
27452 \begin_inset LatexCommand index
27453 name "PIC16!Libraries"
27458 \begin_inset LatexCommand index
27463 port depends on are the microcontroller device libraries which contain
27464 the symbol definitions for the microcontroller special function registers.
27465 These libraries have the format pic18fxxxx.lib, where
27469 is the microcontroller identification number.
27470 The specific library is selected automatically by the compiler at link
27471 stage according to the selected device.
27474 \begin_layout Standard
27476 Libraries are created with gplib which is part of the gputils package
27477 \begin_inset LatexCommand url
27478 target "http://sourceforge.net/projects/gputils"
27485 \begin_layout Subsubsection*
27486 Building the libraries
27489 \begin_layout Standard
27490 Before using SDCC/pic16 there are some libraries that need to be compiled.
27491 This process is done automatically if gputils are found at SDCC's compile
27493 Should you require to rebuild the pic16 libraries manually (e.g.
27494 in order to enable output of float values
27495 \begin_inset LatexCommand index
27496 name "Floating point support"
27504 , see below), these are the steps required to do so under Linux or Mac OS
27505 X (cygwin might work as well, but is untested):
27508 \begin_layout LyX-Code
27509 cd device/lib/pic16
27512 \begin_layout LyX-Code
27516 \begin_layout LyX-Code
27520 \begin_layout LyX-Code
27524 \begin_layout LyX-Code
27525 su -c 'make install' # install the libraries, you need the root password
27528 \begin_layout LyX-Code
27532 \begin_layout Standard
27533 If you need to install the headers too, do:
27536 \begin_layout LyX-Code
27540 \begin_layout LyX-Code
27541 su -c 'make install' # install the headers, you need the root password
27544 \begin_layout Subsubsection*
27545 Output of float values via printf()
27548 \begin_layout Standard
27549 The library is normally built without support for displaying float values,
27551 \begin_inset LatexCommand index
27557 \begin_inset LatexCommand index
27558 name "printf floating point support"
27562 will appear instead of the value.
27563 To change this, rebuild the library as stated above, but call
27565 ./configure.gnu --enable-floats
27572 Also make sure that at least
27574 libc/stdio/vfprintf.c
27576 is actually recompiled, e.g.
27585 run or deleting its
27592 \begin_layout Standard
27593 The more common appraoch of compiling
27601 should also work, but is untested.
27604 \begin_layout Subsection
27605 Adding New Devices to the Port
27608 \begin_layout Standard
27609 Adding support for a new 16
27613 \begin_layout Standard
27622 bit PIC MCU requires the following steps:
27625 \begin_layout Enumerate
27626 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
27630 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
27634 \begin_layout Enumerate
27637 mv picDEVICE.h /path/to/sdcc/device/include/pic16
27640 \begin_layout Enumerate
27643 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
27646 \begin_layout Enumerate
27649 /path/to/sdcc/device/lib/pic16/pics.all
27653 Note: No 18f prefix here!
27656 \begin_layout Enumerate
27659 /path/to/sdcc/device/include/pic16/adc.h
27663 Add the new devices to the correct ADC style class (depending on the number
27670 if the device does not offer any ADC at all.
27673 \begin_layout Enumerate
27676 /path/to/sdcc/device/include/pic16/pic18fregs.h
27680 The file format is self-explanatory, just add
27684 #elif defined(picDEVICE)
27690 \begin_layout Standard
27701 include <picDEVICE.h>
27705 at the right place (keep the file sorted, please).
27708 \begin_layout Enumerate
27711 /path/to/sdcc/device/include/pic16devices.txt
27715 Copy and modify an existing entry or create a new one and insert it at the
27716 correct place (keep the file sorted, please).
27719 \begin_layout Enumerate
27722 /path/to/sdcc/device/lib/pic16/libdev/Makefile.am
27726 Copy an existing entry and adjust the device name.
27729 \begin_layout Enumerate
27732 /path/to/sdcc/device/lib/pic16/libio/Makefile.am
27736 Copy the record from the 18f2220 and adjust the device name.
27739 does not offer ADC, I
27740 \begin_inset Formula $^{\text{2}}$
27743 C, and/or (E)USART functionality as assumed by the library, remove the lines
27759 \begin_layout Enumerate
27778 /path/to/sdcc/device/lib/pic16
27783 \begin_layout Enumerate
27784 Recompile the pic16 libraries as described in
27785 \begin_inset LatexCommand ref
27786 reference "sub:pic16Libraries"
27793 \begin_layout Subsection
27797 \begin_layout Standard
27798 The following memory models are supported by the PIC16 port:
27801 \begin_layout Itemize
27805 \begin_layout Itemize
27809 \begin_layout Standard
27810 Memory model affects the default size of pointers within the source.
27811 The sizes are shown in the next table:
27814 \begin_layout Standard
27816 \begin_inset Tabular
27817 <lyxtabular version="3" rows="3" columns="3">
27819 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27820 <column alignment="center" valignment="top" leftline="true" width="0">
27821 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27822 <row topline="true" bottomline="true">
27823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27826 \begin_layout Standard
27827 Pointer sizes according to memory model
27832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27835 \begin_layout Standard
27841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27844 \begin_layout Standard
27851 <row topline="true" bottomline="true">
27852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27855 \begin_layout Standard
27861 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27864 \begin_layout Standard
27870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27873 \begin_layout Standard
27880 <row topline="true" bottomline="true">
27881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27884 \begin_layout Standard
27890 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
27893 \begin_layout Standard
27899 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27902 \begin_layout Standard
27916 \begin_layout Standard
27917 It is advisable that all sources within a project are compiled with the
27919 If one wants to override the default memory model, this can be done by
27920 declaring a pointer as
27929 Far selects large memory model's pointers, while near selects small memory
27933 \begin_layout Standard
27934 The standard device libraries (see
27935 \begin_inset LatexCommand ref
27936 reference "sub:PIC16_Header-Files"
27940 ) contain no reference to pointers, so they can be used with both memory
27944 \begin_layout Subsection
27948 \begin_layout Standard
27950 \begin_inset LatexCommand index
27955 implementation for the PIC16 port uses two indirect registers, FSR1 and
27959 \begin_layout Description
27960 FSR1 is assigned as stack pointer
27963 \begin_layout Description
27964 FSR2 is assigned as frame pointer
27967 \begin_layout Standard
27968 The following stack models are supported by the PIC16 port
27971 \begin_layout Itemize
27979 \begin_layout Itemize
27987 \begin_layout Standard
27992 model means that only the FSRxL byte is used to access stack and frame,
27999 uses both FSRxL and FSRxH registers.
28000 The following table shows the stack/frame pointers sizes according to stack
28001 model and the maximum space they can address:
28004 \begin_layout Standard
28006 \begin_inset Tabular
28007 <lyxtabular version="3" rows="3" columns="3">
28009 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28010 <column alignment="center" valignment="top" leftline="true" width="0">
28011 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28012 <row topline="true" bottomline="true">
28013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28016 \begin_layout Standard
28017 Stack & Frame pointer sizes according to stack model
28022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28025 \begin_layout Standard
28031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28034 \begin_layout Standard
28041 <row topline="true">
28042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28045 \begin_layout Standard
28051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28054 \begin_layout Standard
28060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28063 \begin_layout Standard
28070 <row topline="true" bottomline="true">
28071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28074 \begin_layout Standard
28080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28083 \begin_layout Standard
28089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28092 \begin_layout Standard
28106 \begin_layout Standard
28112 stack model is currently not working properly throughout the code generator.
28113 So its use is not advised.
28114 Also there are some other points that need special care:
28119 \begin_layout Enumerate
28120 Do not create stack sections with size more than one physical bank (that
28124 \begin_layout Enumerate
28125 Stack sections should no cross physical bank limits (i.e.
28126 #pragma stack 0x50 0x100)
28129 \begin_layout Standard
28130 These limitations are caused by the fact that only FSRxL is modified when
28131 using SMALL stack model, so no more than 256 bytes of stack can be used.
28132 This problem will disappear after LARGE model is fully implemented.
28135 \begin_layout Subsection
28139 \begin_layout Standard
28140 In addition to the standard SDCC function keywords, PIC16
28141 \begin_inset LatexCommand index
28146 port makes available two more:
28149 \begin_layout Description
28151 \begin_inset LatexCommand index
28152 name "PIC16!wparam"
28156 Use the WREG to pass one byte of the first function argument.
28157 This improves speed but you may not use this for functions with arguments
28158 that are called via function pointers, otherwise the first byte of the
28159 first parameter will get lost.
28163 \begin_layout LyX-Code
28164 void func_wparam(int a) wparam
28167 \begin_layout LyX-Code
28171 \begin_layout LyX-Code
28172 /* WREG hold the lower part of a */
28175 \begin_layout LyX-Code
28176 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
28180 \begin_layout LyX-Code
28184 \begin_layout LyX-Code
28188 \begin_layout Description
28190 \begin_inset LatexCommand index
28191 name "PIC16!shadowregs"
28195 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
28196 hardware shadow registers which hold the values of WREG, STATUS and BSR
28198 This can be done by adding the keyword
28206 keyword in the function's header.
28209 \begin_layout LyX-Code
28210 void isr_shadow(void) shadowregs interrupt 1
28213 \begin_layout LyX-Code
28217 \begin_layout LyX-Code
28221 \begin_layout LyX-Code
28225 \begin_layout Standard
28230 instructs the code generator not to store/restore WREG, STATUS, BSR when
28231 entering/exiting the ISR.
28234 \begin_layout Subsection
28235 Function return values
28238 \begin_layout Standard
28239 Return values from functions are placed to the appropriate registers following
28240 a modified Microchip policy optimized for SDCC.
28241 The following table shows these registers:
28244 \begin_layout Standard
28246 \begin_inset Tabular
28247 <lyxtabular version="3" rows="6" columns="2">
28249 <column alignment="center" valignment="top" leftline="true" width="0">
28250 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28251 <row topline="true" bottomline="true">
28252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28255 \begin_layout Standard
28261 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28264 \begin_layout Standard
28265 destination register
28271 <row topline="true">
28272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28275 \begin_layout Standard
28281 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28284 \begin_layout Standard
28291 <row topline="true">
28292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28295 \begin_layout Standard
28301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28304 \begin_layout Standard
28311 <row topline="true">
28312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28315 \begin_layout Standard
28321 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28324 \begin_layout Standard
28331 <row topline="true">
28332 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28335 \begin_layout Standard
28341 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28344 \begin_layout Standard
28345 FSR0L:PRODH:PRODL:WREG
28351 <row topline="true" bottomline="true">
28352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28355 \begin_layout Standard
28361 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28364 \begin_layout Standard
28365 on stack, FSR0 points to the beginning
28378 \begin_layout Subsection
28382 \begin_layout Standard
28384 \begin_inset LatexCommand index
28385 name "PIC16!interrupt"
28389 service routine (ISR) is declared using the
28396 \begin_layout LyX-Code
28397 void isr(void) interrupt
28402 \begin_layout LyX-Code
28406 \begin_layout LyX-Code
28410 \begin_layout LyX-Code
28414 \begin_layout Standard
28419 is the interrupt number, which for PIC18F devices can be:
28422 \begin_layout Standard
28424 \begin_inset Tabular
28425 <lyxtabular version="3" rows="4" columns="3">
28427 <column alignment="center" valignment="top" leftline="true" width="0">
28428 <column alignment="center" valignment="top" leftline="true" width="0">
28429 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28430 <row topline="true" bottomline="true">
28431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28434 \begin_layout Standard
28442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28445 \begin_layout Standard
28451 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28454 \begin_layout Standard
28455 Interrupt Vector Address
28461 <row topline="true">
28462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28465 \begin_layout Standard
28471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28474 \begin_layout Standard
28480 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28483 \begin_layout Standard
28490 <row topline="true">
28491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28494 \begin_layout Standard
28509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28512 \begin_layout Standard
28522 HIGH priority interrupts
28527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28530 \begin_layout Standard
28537 <row topline="true" bottomline="true">
28538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28541 \begin_layout Standard
28547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28550 \begin_layout Standard
28551 LOW priority interrupts
28556 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28559 \begin_layout Standard
28573 \begin_layout Standard
28574 When generating assembly code for ISR the code generator places a
28580 Interrupt Vector Address
28582 which points at the generated ISR.
28583 This single GOTO instruction is part of an automatically generated
28585 interrupt entry point
28588 The actuall ISR code is placed as normally would in the code space.
28589 Upon interrupt request, the GOTO instruction is executed which jumps to
28591 When declaring interrupt functions as _naked this GOTO instruction is
28596 The whole interrupt functions is therefore placed at the Interrupt Vector
28597 Address of the specific interrupt.
28598 This is not a problem for the LOW priority interrupts, but it is a problem
28599 for the RESET and the HIGH priority interrupts because code may be written
28600 at the next interrupt's vector address and cause indeterminate program
28601 behaviour if that interrupt is raised.
28605 \begin_layout Standard
28606 This is not a problem when
28609 \begin_layout Enumerate
28610 this is a HIGH interrupt ISR and LOW interrupts are
28617 \begin_layout Enumerate
28618 when the ISR is small enough not to reach the next interrupt's vector address.
28626 \begin_layout Standard
28632 This way a function is generated similar to an ISR, but it is not assigned
28636 \begin_layout Standard
28637 When entering an interrupt, currently the PIC16
28638 \begin_inset LatexCommand index
28643 port automatically saves the following registers:
28646 \begin_layout Itemize
28650 \begin_layout Itemize
28654 \begin_layout Itemize
28658 \begin_layout Itemize
28659 PROD (PRODL and PRODH)
28662 \begin_layout Itemize
28663 FSR0 (FSR0L and FSR0H)
28666 \begin_layout Standard
28667 These registers are restored upon return from the interrupt routine.
28671 \begin_layout Standard
28672 NOTE that when the _naked attribute is specified for an interrupt routine,
28673 then NO registers are stored or restored.
28681 \begin_layout Subsection
28685 \begin_layout Standard
28686 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
28687 There are 3 types of generic pointers currently implemented data, code
28688 and eeprom pointers.
28689 They are differentiated by the value of the 7th and 6th bits of the upper
28693 \begin_layout Standard
28695 \begin_inset Tabular
28696 <lyxtabular version="3" rows="5" columns="5">
28698 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28699 <column alignment="center" valignment="top" width="0">
28700 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28701 <column alignment="center" valignment="top" width="0">
28702 <column alignment="left" valignment="top" rightline="true" width="0">
28703 <row topline="true" bottomline="true">
28704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28707 \begin_layout Standard
28713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28716 \begin_layout Standard
28722 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28725 \begin_layout Standard
28731 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28734 \begin_layout Standard
28735 rest of the pointer
28740 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28743 \begin_layout Standard
28750 <row topline="true" bottomline="true">
28751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28754 \begin_layout Standard
28760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28763 \begin_layout Standard
28769 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28772 \begin_layout Standard
28778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28781 \begin_layout Standard
28786 uuuuuu uuuuxxxx xxxxxxxx
28791 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28794 \begin_layout Standard
28795 a 12-bit data pointer in data RAM memory
28801 <row bottomline="true">
28802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28805 \begin_layout Standard
28811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28814 \begin_layout Standard
28820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28823 \begin_layout Standard
28829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28832 \begin_layout Standard
28837 uxxxxx xxxxxxxx xxxxxxxx
28842 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28845 \begin_layout Standard
28846 a 21-bit code pointer in FLASH memory
28852 <row bottomline="true">
28853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28856 \begin_layout Standard
28862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28865 \begin_layout Standard
28871 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28874 \begin_layout Standard
28880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28883 \begin_layout Standard
28888 uuuuuu uuuuuuxx xxxxxxxx
28893 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28896 \begin_layout Standard
28897 a 10-bit eeprom pointer in EEPROM memory
28903 <row bottomline="true">
28904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28907 \begin_layout Standard
28913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28916 \begin_layout Standard
28922 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28925 \begin_layout Standard
28931 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28934 \begin_layout Standard
28939 xxxxxx xxxxxxxx xxxxxxxx
28944 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28947 \begin_layout Standard
28948 unimplemented pointer type
28961 \begin_layout Standard
28963 Generic pointer are read and written with a set of library functions which
28964 read/write 1, 2, 3, 4 bytes.
28967 \begin_layout Subsection
28971 \begin_layout Subsubsection
28972 Standard I/O Streams
28975 \begin_layout Standard
28980 the type FILE is defined as:
28983 \begin_layout LyX-Code
28984 typedef char * FILE;
28987 \begin_layout Standard
28988 This type is the stream type implemented I/O in the PIC18F devices.
28989 Also the standard input and output streams are declared in stdio.h:
28992 \begin_layout LyX-Code
28993 extern FILE * stdin;
28996 \begin_layout LyX-Code
28997 extern FILE * stdout;
29000 \begin_layout Standard
29001 The FILE type is actually a generic pointer which defines one more type
29002 of generic pointers, the
29007 This new type has the format:
29010 \begin_layout Standard
29013 \begin_inset Tabular
29014 <lyxtabular version="3" rows="2" columns="7">
29016 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29017 <column alignment="center" valignment="top" width="0">
29018 <column alignment="center" valignment="top" leftline="true" width="0">
29019 <column alignment="center" valignment="top" leftline="true" width="0">
29020 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29021 <column alignment="center" valignment="top" width="0">
29022 <column alignment="left" valignment="top" rightline="true" width="0">
29023 <row topline="true" bottomline="true">
29024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29027 \begin_layout Standard
29033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29036 \begin_layout Standard
29042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29045 \begin_layout Standard
29051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29054 \begin_layout Standard
29060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29063 \begin_layout Standard
29069 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29072 \begin_layout Standard
29073 rest of the pointer
29078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29081 \begin_layout Standard
29088 <row topline="true" bottomline="true">
29089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29092 \begin_layout Standard
29098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29101 \begin_layout Standard
29107 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29110 \begin_layout Standard
29116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29119 \begin_layout Standard
29125 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29128 \begin_layout Standard
29134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29137 \begin_layout Standard
29147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29150 \begin_layout Standard
29151 upper byte high nubble is 0x2n, the rest are zeroes
29164 \begin_layout Standard
29166 Currently implemented there are 3 types of streams defined:
29169 \begin_layout Standard
29172 \begin_inset Tabular
29173 <lyxtabular version="3" rows="4" columns="4">
29175 <column alignment="center" valignment="top" leftline="true" width="0">
29176 <column alignment="center" valignment="top" leftline="true" width="0">
29177 <column alignment="center" valignment="top" leftline="true" width="0">
29178 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29179 <row topline="true" bottomline="true">
29180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29183 \begin_layout Standard
29189 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29192 \begin_layout Standard
29198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29201 \begin_layout Standard
29207 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29210 \begin_layout Standard
29217 <row topline="true">
29218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29221 \begin_layout Standard
29227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29230 \begin_layout Standard
29238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29241 \begin_layout Standard
29247 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29250 \begin_layout Standard
29251 Writes/Reads characters via the USART peripheral
29257 <row topline="true">
29258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29261 \begin_layout Standard
29267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29270 \begin_layout Standard
29278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29281 \begin_layout Standard
29287 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29290 \begin_layout Standard
29291 Writes/Reads characters via the MSSP peripheral
29297 <row topline="true" bottomline="true">
29298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29301 \begin_layout Standard
29307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29310 \begin_layout Standard
29318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29321 \begin_layout Standard
29327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29330 \begin_layout Standard
29331 Writes/Reads characters via used defined functions
29344 \begin_layout Standard
29346 The stream identifiers are declared as macros in the stdio.h header.
29349 \begin_layout Standard
29351 In the libc library there exist the functions that are used to write to
29352 each of the above streams.
29356 \begin_layout Description
29361 \begin_layout Standard
29370 _stream_usart_putchar writes a character at the USART stream
29373 \begin_layout Description
29378 \begin_layout Standard
29387 _stream_mssp_putchar writes a character at the MSSP stream
29390 \begin_layout Description
29391 putchar dummy function.
29392 This writes a character to a user specified manner.
29395 \begin_layout Standard
29396 In order to increase performance
29400 is declared in stdio.h as having its parameter in WREG (it has the wparam
29402 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
29403 in a user-friendly way.
29408 is the name of the variable that holds the character to print.
29409 An example follows:
29412 \begin_layout LyX-Code
29413 #include <pic18fregs.h>
29422 \begin_layout LyX-Code
29426 \begin_layout LyX-Code
29427 PORTA = c; /* dump character c to PORTA */
29430 \begin_layout LyX-Code
29438 \begin_layout LyX-Code
29442 \begin_layout LyX-Code
29443 stdout = STREAM_USER; /* this is not necessary, since stdout points
29446 \begin_layout LyX-Code
29447 * by default to STREAM_USER */
29450 \begin_layout LyX-Code
29452 \begin_inset Quotes sld
29455 This is a printf test
29458 \begin_inset Quotes srd
29464 \begin_layout LyX-Code
29468 \begin_layout LyX-Code
29472 \begin_layout Subsubsection
29476 \begin_layout Standard
29477 PIC16 contains an implementation of the printf-family of functions.
29478 There exist the following functions:
29481 \begin_layout LyX-Code
29482 extern unsigned int sprintf(char *buf, char *fmt, ...);
29485 \begin_layout LyX-Code
29486 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
29489 \begin_layout LyX-Code
29493 \begin_layout LyX-Code
29494 extern unsigned int printf(char *fmt, ...);
29497 \begin_layout LyX-Code
29498 extern unsigned int vprintf(char *fmt, va_lista ap);
29501 \begin_layout LyX-Code
29505 \begin_layout LyX-Code
29506 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
29509 \begin_layout LyX-Code
29510 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
29513 \begin_layout Standard
29514 For sprintf and vsprintf
29518 should normally be a data pointer where the resulting string will be placed.
29519 No range checking is done so the user should allocate the necessary buffer.
29520 For fprintf and vfprintf
29524 should be a stream pointer (i.e.
29525 stdout, STREAM_MSSP, etc...).
29528 \begin_layout Subsubsection
29532 \begin_layout Standard
29533 The PIC18F family of microcontrollers supports a number of interrupt sources.
29534 A list of these interrupts is shown in the following table:
29537 \begin_layout Standard
29539 \begin_inset Tabular
29540 <lyxtabular version="3" rows="11" columns="4">
29542 <column alignment="left" valignment="top" leftline="true" width="0">
29543 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29544 <column alignment="left" valignment="top" leftline="true" width="0">
29545 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29546 <row topline="true" bottomline="true">
29547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29550 \begin_layout Standard
29556 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29559 \begin_layout Standard
29565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29568 \begin_layout Standard
29574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29577 \begin_layout Standard
29584 <row topline="true">
29585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29588 \begin_layout Standard
29594 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29597 \begin_layout Standard
29598 PORTB change interrupt
29603 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29606 \begin_layout Standard
29612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29615 \begin_layout Standard
29616 EEPROM/FLASH write complete interrupt
29622 <row topline="true">
29623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29626 \begin_layout Standard
29632 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29635 \begin_layout Standard
29636 INT0 external interrupt
29641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29644 \begin_layout Standard
29650 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29653 \begin_layout Standard
29654 Bus collision interrupt
29660 <row topline="true">
29661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29664 \begin_layout Standard
29670 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29673 \begin_layout Standard
29674 INT1 external interrupt
29679 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29682 \begin_layout Standard
29688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29691 \begin_layout Standard
29692 Low voltage detect interrupt
29698 <row topline="true">
29699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29702 \begin_layout Standard
29708 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29711 \begin_layout Standard
29712 INT2 external interrupt
29717 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29720 \begin_layout Standard
29726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29729 \begin_layout Standard
29730 Parallel slave port interrupt
29736 <row topline="true">
29737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29740 \begin_layout Standard
29746 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29749 \begin_layout Standard
29750 CCP1 module interrupt
29755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29758 \begin_layout Standard
29764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29767 \begin_layout Standard
29768 AD convertion complete interrupt
29774 <row topline="true">
29775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29778 \begin_layout Standard
29784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29787 \begin_layout Standard
29788 CCP2 module interrupt
29793 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29796 \begin_layout Standard
29802 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29805 \begin_layout Standard
29806 USART receive interrupt
29812 <row topline="true">
29813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29816 \begin_layout Standard
29822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29825 \begin_layout Standard
29826 TMR0 overflow interrupt
29831 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29834 \begin_layout Standard
29840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29843 \begin_layout Standard
29844 USART transmit interrupt
29850 <row topline="true">
29851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29854 \begin_layout Standard
29860 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29863 \begin_layout Standard
29864 TMR1 overflow interrupt
29869 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29872 \begin_layout Standard
29878 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29881 \begin_layout Standard
29882 SSP receive/transmit interrupt
29888 <row topline="true">
29889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29892 \begin_layout Standard
29898 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29901 \begin_layout Standard
29902 TMR2 matches PR2 interrupt
29907 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29910 \begin_layout Standard
29916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29919 \begin_layout Standard
29926 <row topline="true" bottomline="true">
29927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29930 \begin_layout Standard
29936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29939 \begin_layout Standard
29940 TMR3 overflow interrupt
29945 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29948 \begin_layout Standard
29954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29957 \begin_layout Standard
29971 \begin_layout Standard
29973 The prototypes for these names are defined in the header file
29980 \begin_layout Standard
29982 In order to simplify signal handling, a number of macros is provided:
29986 \labelwidthstring 00.00.0000
29987 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
29988 high priority interrupts.
29993 is the function name to use.
29997 \labelwidthstring 00.00.0000
29998 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
29999 low priority interrupt.
30004 is the function name to use.
30008 \labelwidthstring 00.00.0000
30009 DEF_HANDLER(sig,handler) define a handler for signal
30015 \labelwidthstring 00.00.0000
30016 END_DEF end the declaration of the dispatch table.
30019 \begin_layout Standard
30020 Additionally there are two more macros to simplify the declaration of the
30025 \labelwidthstring 00.00.0000
30028 SIGHANDLER(handler)
30030 this declares the function prototype for the
30038 \labelwidthstring 00.00.0000
30039 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
30042 \begin_layout Standard
30043 An example of using the macros above is shown below:
30046 \begin_layout LyX-Code
30047 #include <pic18fregs.h>
30050 \begin_layout LyX-Code
30051 #include <signal.h>
30055 DEF_INTHIGH(high_int)
30058 \begin_layout LyX-Code
30059 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
30062 \begin_layout LyX-Code
30063 DEF_HANDLER(SIG_BCOL, _bcol_handler)
30066 \begin_layout LyX-Code
30071 SIGHANDLER(_tmr0_handler)
30074 \begin_layout LyX-Code
30078 \begin_layout LyX-Code
30079 /* action to be taken when timer 0 overflows */
30082 \begin_layout LyX-Code
30087 SIGHANDLERNAKED(_bcol_handler)
30090 \begin_layout LyX-Code
30094 \begin_layout LyX-Code
30098 \begin_layout LyX-Code
30099 /* action to be taken when bus collision occurs */
30102 \begin_layout LyX-Code
30106 \begin_layout LyX-Code
30110 \begin_layout LyX-Code
30114 \begin_layout Standard
30119 Special care should be taken when using the above scheme:
30122 \begin_layout Itemize
30123 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
30126 \begin_layout Itemize
30127 when declaring SIGHANDLERNAKED handler never forget to use
30131 for proper returning.
30134 \begin_layout Subsection
30138 \begin_layout Standard
30139 Here you can find some general tips for compiling programs with SDCC/pic16.
30142 \begin_layout Subsubsection
30146 \begin_layout Standard
30148 \begin_inset LatexCommand index
30153 size (that is 64 bytes) probably is enough for many programs.
30154 One must take care that when there are many levels of function nesting,
30155 or there is excessive usage of stack, its size should be extended.
30156 An example of such a case is the printf/sprintf family of functions.
30157 If you encounter problems like not being able to print integers, then you
30158 need to set the stack size around the maximum (256 for small stack model).
30159 The following diagram shows what happens when calling printf to print an
30163 \begin_layout LyX-Code
30164 printf () --> ltoa () --> ultoa () --> divschar ()
30167 \begin_layout Standard
30168 It is should be understood that stack is easily consumed when calling complicate
30170 Using command line arguments like -
30174 \begin_layout Standard
30183 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
30185 Other ways to reduce stack usage may exist.
30188 \begin_layout Subsection
30192 \begin_layout Subsubsection
30193 Extended Instruction Set
30196 \begin_layout Standard
30197 The PIC16 port emits code which is incompatible with the extended instruction
30198 set available with many newer devices.
30199 Make sure to always explicitly disable it, usually using
30202 \begin_layout Standard
30205 static __code char __at(__CONFIG4L) conf4l = /* more flags & */ _XINST_OFF_4L;
30208 \begin_layout Standard
30210 Some devices (namely 18f2455, 18f2550, 18f4455, and 18f4550) use _ENHCPU_OFF_4L
30211 instead of _XINST_OFF_4L.
30214 \begin_layout Subsubsection
30218 \begin_layout Standard
30219 The PIC16 port currently passes most but not all of the tests in SDCC's
30221 \begin_inset LatexCommand index
30222 name "Regression test (PIC16)"
30227 \begin_inset LatexCommand ref
30228 reference "sec:Quality-control"
30232 ), thus no automatic regression tests are currently performed for the PIC16
30236 \begin_layout Chapter
30240 \begin_layout Standard
30241 There are several approaches to debugging your code.
30242 This chapter is meant to show your options and to give detail on some of
30247 When writing your code:
30250 \begin_layout Itemize
30251 write your code with debugging in mind (avoid duplicating code, put conceptually
30252 similar variables into structs, use structured code, have strategic points
30253 within your code where all variables are consistent, ...)
30256 \begin_layout Itemize
30257 run a syntax-checking tool like splint
30258 \begin_inset LatexCommand index
30259 name "splint (syntax checking tool)"
30264 \begin_inset LatexCommand index
30265 name "lint (syntax checking tool)"
30273 \begin_layout Standard
30283 \begin_inset LatexCommand ref
30284 reference "lyx:more-pedantic-SPLINT"
30291 \begin_layout Itemize
30292 for the high level code use a C-compiler (like f.e.
30293 GCC) to compile run and debug the code on your host.
30298 \begin_layout Standard
30308 \begin_inset LatexCommand ref
30309 reference "lyx:more-pedantic-SPLINT"
30313 ) on how to handle syntax extensions like __xdata, __at(), ...
30317 \begin_layout Itemize
30318 use another C-compiler to compile code for your target.
30319 Always an option but not recommended:) And not very likely to help you.
30320 If you seriously consider walking this path you should at least occasionally
30321 check portability of your code.
30322 Most commercial compiler vendors will offer an evaluation version so you
30323 can test compile your code or snippets of your code.
30326 \begin_layout Standard
30327 Debugging on a simulator:
30330 \begin_layout Itemize
30331 there is a separate section about SDCDB (section
30332 \begin_inset LatexCommand ref
30333 reference "cha:Debugging-with-SDCDB"
30340 \begin_layout Itemize
30341 or (8051 specific) use a free open source/commercial simulator which interfaces
30343 \begin_inset LatexCommand index
30344 name "AOMF, AOMF51"
30349 \begin_inset LatexCommand ref
30350 reference "OMF file"
30354 ) optionally generated by SDCC.
30357 \begin_layout Standard
30358 Debugging On-target:
30361 \begin_layout Itemize
30362 use a MCU port pin to serially output debug data to the RS232 port of your
30364 You'll probably want some level shifting device typically involving a MAX232
30366 If the hardware serial port of the MCU is not available search for 'Software
30367 UART' in your favourite search machine.
30370 \begin_layout Itemize
30371 use an on-target monitor.
30372 In this context a monitor is a small program which usually accepts commands
30373 via a serial line and allows to set program counter, to single step through
30374 a program and read/write memory locations.
30375 For the 8051 good examples of monitors are paulmon and cmon51 (see section
30377 \begin_inset LatexCommand ref
30378 reference "sec:Related-open-source-tools"
30385 \begin_layout Itemize
30386 toggle MCU port pins at strategic points within your code and use an oscilloscop
30390 digital oscilloscope
30393 \begin_inset LatexCommand index
30394 name "Oscilloscope"
30398 with deep trace memory is really helpful especially if you have to debug
30399 a realtime application.
30400 If you need to monitor more pins than your oscilloscope provides you can
30401 sometimes get away with a small R-2R network.
30402 On a single channel oscilloscope you could f.e.
30403 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
30405 \begin_inset Formula $\Omega$
30408 resistor and the other one by a 5\InsetSpace ~
30410 \begin_inset Formula $\Omega$
30413 resistor to the oscilloscope probe (check output drive capability of the
30414 pins you want to monitor).
30415 If you need to monitor many more pins a
30422 \begin_layout Itemize
30436 \begin_inset LatexCommand index
30437 name "ICE (in circuit emulator)"
30442 Usually very expensive.
30443 And very nice to have too.
30444 And usually locks you (for years...) to the devices the ICE can emulate.
30448 \begin_layout Itemize
30449 use a remote debugger.
30450 In most 8-bit systems the symbol information is not available on the target,
30451 and a complete debugger is too bulky for the target system.
30452 Therefore usually a debugger on the host system connects to an on-target
30453 debugging stub which accepts only primitive commands.
30456 Terms to enter into your favourite search engine could be 'remote debugging',
30457 'gdb stub' or 'inferior debugger'.
30461 \begin_layout Itemize
30462 use an on target hardware debugger.
30463 Some of the more modern MCUs include hardware support for setting break
30464 points and monitoring/changing variables by using dedicated hardware pins.
30465 This facility doesn't require additional code to run on the target and
30470 doesn't affect runtime behaviour until a breakpoint is hit.
30471 For the mcs51 most hardware debuggers use the AOMF
30472 \begin_inset LatexCommand index
30473 name "AOMF, AOMF51"
30478 \begin_inset LatexCommand ref
30479 reference "OMF file"
30487 \begin_layout Standard
30491 \begin_layout Itemize
30492 if you are not familiar with any of the following terms you're likely to
30493 run into problems rather sooner than later:
30510 As an embedded programmer you
30514 to know them so why not look them up
30518 you have problems?)
30521 \begin_layout Itemize
30522 tell someone else about your problem (actually this is a surprisingly effective
30523 means to hunt down the bug even if the listener is not familiar with your
30525 As 'failure to communicate' is probably one of the job-induced deformations
30526 of an embedded programmer this is highly encouraged.
30529 \begin_layout Section
30530 Debugging with SDCDB
30531 \begin_inset LatexCommand label
30532 name "cha:Debugging-with-SDCDB"
30537 \begin_inset LatexCommand index
30538 name "SDCDB (debugger)"
30545 \begin_layout Standard
30546 SDCC is distributed with a source level debugger
30547 \begin_inset LatexCommand index
30553 The debugger uses a command line interface, the command repertoire of the
30554 debugger has been kept as close to gdb
30555 \begin_inset LatexCommand index
30560 (the GNU debugger) as possible.
30561 The configuration and build process is part of the standard compiler installati
30562 on, which also builds and installs the debugger in the target directory
30563 specified during configuration.
30564 The debugger allows you debug BOTH at the C source and at the ASM source
30568 \begin_layout Subsection
30569 Compiling for Debugging
30572 \begin_layout Standard
30577 \begin_layout Standard
30587 \begin_inset LatexCommand index
30592 option must be specified for all files for which debug information is to
30594 The compiler generates a .adb file for each of these files.
30595 The linker creates the .cdb
30596 \begin_inset LatexCommand index
30602 \begin_inset LatexCommand index
30607 files and the address information.
30608 This .cdb is used by the debugger.
30611 \begin_layout Subsection
30612 How the Debugger Works
30615 \begin_layout Standard
30620 \begin_layout Standard
30629 -debug option is specified the compiler generates extra symbol information
30630 some of which are put into the assembler source and some are put into the
30632 Then the linker creates the .cdb file from the individual .adb files with
30633 the address information for the symbols.
30634 The debugger reads the symbolic information generated by the compiler &
30635 the address information generated by the linker.
30636 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
30637 execution is controlled by the debugger.
30638 When a command is issued for the debugger, it translates it into appropriate
30639 commands for the simulator.
30640 (Currently SDCDM only connects to the simulator but
30645 \begin_inset LatexCommand url
30646 target "http://ec2drv.sf.net/"
30650 is an effort to connect directly to the hardware.)
30653 \begin_layout Subsection
30654 Starting the Debugger SDCDB
30657 \begin_layout Standard
30658 The debugger can be started using the following command line.
30659 (Assume the file you are debugging has the file name foo).
30673 The debugger will look for the following files.
30676 \begin_layout Itemize
30677 foo.c - the source file.
30680 \begin_layout Itemize
30681 foo.cdb - the debugger symbol information file.
30684 \begin_layout Itemize
30685 foo.ihx - the Intel hex format
30686 \begin_inset LatexCommand index
30687 name "Intel hex format"
30694 \begin_layout Subsection
30695 SDCDB Command Line Options
30698 \begin_layout Itemize
30703 \begin_layout Standard
30712 -directory=<source file directory> this option can used to specify the directory
30714 The debugger will look into the directory list specified for source, cdb
30716 The items in the directory list must be separated by ':', e.g.
30717 if the source files can be in the directories /home/src1 and /home/src2,
30722 \begin_layout Standard
30731 -directory option should be -
30735 \begin_layout Standard
30744 -directory=/home/src1:/home/src2.
30745 Note there can be no spaces in the option.
30749 \begin_layout Itemize
30750 -cd <directory> - change to the <directory>.
30753 \begin_layout Itemize
30754 -fullname - used by GUI front ends.
30757 \begin_layout Itemize
30758 -cpu <cpu-type> - this argument is passed to the simulator please see the
30759 simulator docs for details.
30762 \begin_layout Itemize
30763 -X <Clock frequency > this options is passed to the simulator please see
30764 the simulator docs for details.
30767 \begin_layout Itemize
30768 -s <serial port file> passed to simulator see the simulator docs for details.
30771 \begin_layout Itemize
30772 -S <serial in,out> passed to simulator see the simulator docs for details.
30775 \begin_layout Itemize
30776 -k <port number> passed to simulator see the simulator docs for details.
30779 \begin_layout Subsection
30780 SDCDB Debugger Commands
30783 \begin_layout Standard
30784 As mentioned earlier the command interface for the debugger has been deliberatel
30785 y kept as close the GNU debugger gdb, as possible.
30786 This will help the integration with existing graphical user interfaces
30787 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
30788 If you use a graphical user interface for the debugger you can skip this
30792 \begin_layout Subsubsection*
30793 break [line | file:line | function | file:function]
30796 \begin_layout Standard
30797 Set breakpoint at specified line or function:
30806 sdcdb>break foo.c:100
30808 sdcdb>break funcfoo
30810 sdcdb>break foo.c:funcfoo
30813 \begin_layout Subsubsection*
30814 clear [line | file:line | function | file:function ]
30817 \begin_layout Standard
30818 Clear breakpoint at specified line or function:
30827 sdcdb>clear foo.c:100
30829 sdcdb>clear funcfoo
30831 sdcdb>clear foo.c:funcfoo
30834 \begin_layout Subsubsection*
30838 \begin_layout Standard
30839 Continue program being debugged, after breakpoint.
30842 \begin_layout Subsubsection*
30846 \begin_layout Standard
30847 Execute till the end of the current function.
30850 \begin_layout Subsubsection*
30854 \begin_layout Standard
30855 Delete breakpoint number 'n'.
30856 If used without any option clear ALL user defined break points.
30859 \begin_layout Subsubsection*
30860 info [break | stack | frame | registers ]
30863 \begin_layout Itemize
30864 info break - list all breakpoints
30867 \begin_layout Itemize
30868 info stack - show the function call stack.
30871 \begin_layout Itemize
30872 info frame - show information about the current execution frame.
30875 \begin_layout Itemize
30876 info registers - show content of all registers.
30879 \begin_layout Subsubsection*
30883 \begin_layout Standard
30884 Step program until it reaches a different source line.
30885 Note: pressing <return> repeats the last command.
30888 \begin_layout Subsubsection*
30892 \begin_layout Standard
30893 Step program, proceeding through subroutine calls.
30896 \begin_layout Subsubsection*
30900 \begin_layout Standard
30901 Start debugged program.
30904 \begin_layout Subsubsection*
30908 \begin_layout Standard
30909 Print type information of the variable.
30912 \begin_layout Subsubsection*
30916 \begin_layout Standard
30917 print value of variable.
30920 \begin_layout Subsubsection*
30924 \begin_layout Standard
30925 load the given file name.
30926 Note this is an alternate method of loading file for debugging.
30929 \begin_layout Subsubsection*
30933 \begin_layout Standard
30934 print information about current frame.
30937 \begin_layout Subsubsection*
30941 \begin_layout Standard
30942 Toggle between C source & assembly source.
30945 \begin_layout Subsubsection*
30946 ! simulator command
30949 \begin_layout Standard
30950 Send the string following '!' to the simulator, the simulator response is
30952 Note the debugger does not interpret the command being sent to the simulator,
30953 so if a command like 'go' is sent the debugger can loose its execution
30954 context and may display incorrect values.
30957 \begin_layout Subsubsection*
30961 \begin_layout Standard
30964 My name is Bobby Brown"
30967 \begin_layout Subsection
30968 Interfacing SDCDB with DDD
30971 \begin_layout Standard
30972 \begin_inset Note Note
30975 \begin_layout Standard
30976 The screenshot was converted from png to eps with:
30977 \begin_inset Quotes sld
30980 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
30981 \begin_inset Quotes srd
30984 which produces a pretty compact eps file which is free from compression
30988 \begin_layout Standard
30989 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
30990 as this broke the build system on Sourceforge (pdf-file was broken.
30991 pdflatex does not accept eps files).
30999 \begin_layout Standard
31015 \begin_inset LatexCommand url
31016 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png"
31022 shows a screenshot of a debugging session with DDD
31023 \begin_inset LatexCommand index
31024 name "DDD (debugger)"
31028 (Unix only) on a simulated 8032.
31029 The debugging session might not run as smoothly as the screenshot suggests.
31030 The debugger allows setting of breakpoints, displaying and changing variables,
31031 single stepping through C and assembler code.
31034 The source was compiled with
31048 \begin_layout Standard
31060 -debug ddd_example.c
31073 and DDD was invoked with
31080 ddd -debugger "sdcdb -cpu 8032 ddd_example"
31083 \begin_layout Standard
31084 \begin_inset Note Note
31087 \begin_layout Standard
31088 Check that the double quotes or an apostrophe within the command line survive
31089 the LyX tool chain.
31090 Previously the apostrophes got slanted in the PDF output so a cut and paste
31099 \begin_layout Subsection
31100 Interfacing SDCDB with XEmacs
31101 \begin_inset LatexCommand index
31107 \begin_inset LatexCommand index
31115 \begin_layout Standard
31116 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
31117 sdcdb.el and sdcdbsrc.el.
31118 These two files can be found in the $(prefix)/bin directory after the installat
31120 These files need to be loaded into XEmacs for the interface to work.
31121 This can be done at XEmacs startup time by inserting the following into
31122 your '.xemacs' file (which can be found in your HOME directory):
31128 (load-file sdcdbsrc.el)
31134 .xemacs is a lisp file so the () around the command is REQUIRED.
31135 The files can also be loaded dynamically while XEmacs is running, set the
31136 environment variable 'EMACSLOADPATH' to the installation bin directory
31137 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
31138 To start the interface enter the following command:
31152 You will prompted to enter the file name to be debugged.
31157 The command line options that are passed to the simulator directly are
31158 bound to default values in the file sdcdbsrc.el.
31159 The variables are listed below, these values maybe changed as required.
31162 \begin_layout Itemize
31163 sdcdbsrc-cpu-type '51
31166 \begin_layout Itemize
31167 sdcdbsrc-frequency '11059200
31170 \begin_layout Itemize
31171 sdcdbsrc-serial nil
31174 \begin_layout Standard
31175 The following is a list of key mapping for the debugger interface.
31178 \begin_layout Standard
31201 binding\InsetSpace ~
31239 -------\InsetSpace ~
31310 sdcdb-back-from-src\InsetSpace ~
31339 rom-src\InsetSpace ~
31349 SDCDB continue command
31367 sdcdb-step-from-src\InsetSpace ~
31396 hatis-c-sexp\InsetSpace ~
31406 SDCDB ptypecommand for data at
31473 sdcdbsrc-delete\InsetSpace ~
31488 B Delete all breakpoints if no arg
31537 given or delete arg (C-u arg x)
31556 -frame\InsetSpace ~
31571 SDCDB Display current frame if no arg,
31620 given or display frame arg
31688 sdcdbsrc-goto-sdcdb\InsetSpace ~
31698 Goto the SDCDB output buffer
31717 t-c-sexp\InsetSpace ~
31728 SDCDB print command for data at
31795 sdcdbsrc-goto-sdcdb\InsetSpace ~
31806 o the SDCDB output buffer
31824 sdcdbsrc-mode\InsetSpace ~
31840 Toggles Sdcdbsrc mode (turns it
31856 sdcdb-finish-from-src\InsetSpace ~
31864 SDCDB finish command
31898 Set break for line with point
31913 sdcdbsrc-mode\InsetSpace ~
31929 Toggle Sdcdbsrc mode
31945 dbsrc-srcmode\InsetSpace ~
31969 \begin_layout Chapter
31973 \begin_layout Standard
31974 Here are a few guidelines that will help the compiler generate more efficient
31975 code, some of the tips are specific to this compiler others are generally
31976 good programming practice.
31979 \begin_layout Itemize
31980 Use the smallest data type to represent your data-value.
31981 If it is known in advance that the value is going to be less than 256 then
31982 use an 'unsigned char' instead of a 'short' or 'int'.
31983 Please note, that ANSI C requires both signed and unsigned chars to be
31984 promoted to 'signed int'
31985 \begin_inset LatexCommand index
31986 name "promotion to signed int"
31991 \begin_inset Marginal
31994 \begin_layout Standard
32003 before doing any operation.
32005 \begin_inset LatexCommand index
32006 name "type promotion"
32011 \begin_inset LatexCommand label
32012 name "type promotion"
32016 can be omitted, if the result is the same.
32017 The effect of the promotion rules together with the sign-extension is often
32022 \begin_layout Verse
32025 unsigned char uc = 0xfe;
32027 if (uc * uc < 0) /* this is true! */
32040 \begin_layout Standard
32047 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
32055 \begin_layout Verse
32058 (unsigned char) -12 / (signed char) -3 = ...
32061 \begin_layout Standard
32062 No, the result is not 4:
32065 \begin_layout Verse
32068 (int) (unsigned char) -12 / (int) (signed char) -3 =
32070 (int) (unsigned char)
32071 0xf4 / (int) (signed char) 0xfd =
32073 (int) 0x00f4 / (int) 0xfffd =
32078 (int) 244 / (int) -3 =
32080 (int) -81 = (int) 0xffaf;
32083 \begin_layout Standard
32084 Don't complain, that gcc gives you a different result.
32085 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
32086 Therefore the results are different.
32089 \begin_inset Quotes sld
32093 \begin_inset Quotes srd
32099 \begin_layout Quote
32102 If well-defined overflow characteristics are important and negative values
32103 are not, or if you want to steer clear of sign-extension problems when
32104 manipulating bits or bytes, use one of the corresponding unsigned types.
32105 (Beware when mixing signed and unsigned values in expressions, though.)
32108 character types (especially unsigned char) can be used as "tiny" integers,
32109 doing so is sometimes more trouble than it's worth, due to unpredictable
32110 sign extension and increased code size.
32114 \begin_layout Itemize
32115 Use unsigned when it is known in advance that the value is not going to
32117 This helps especially if you are doing division or multiplication, bit-shifting
32118 or are using an array index.
32121 \begin_layout Itemize
32122 NEVER jump into a LOOP.
32125 \begin_layout Itemize
32126 Declare the variables to be local
32127 \begin_inset LatexCommand index
32128 name "local variables"
32132 whenever possible, especially loop control variables (induction).
32135 \begin_layout Itemize
32136 Have a look at the assembly listing to get a
32137 \begin_inset Quotes sld
32141 \begin_inset Quotes srd
32144 for the code generation.
32147 \begin_layout Section
32148 Porting code from or to other compilers
32149 \begin_inset LatexCommand label
32150 name "sec:Porting-code-to-other-compilers"
32157 \begin_layout Itemize
32158 check whether endianness of the compilers differs and adapt where needed.
32161 \begin_layout Itemize
32162 check the device specific header files
32163 \begin_inset LatexCommand index
32164 name "Header files"
32169 \begin_inset LatexCommand index
32170 name "Include files"
32174 for compiler specific syntax.
32175 Eventually include the file <compiler.h
32176 \begin_inset LatexCommand index
32177 name "compiler.h (include file)"
32182 \begin_inset LatexCommand url
32183 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup"
32187 to allow using common header files.
32190 \begin_inset LatexCommand url
32191 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup"
32198 \begin_layout Itemize
32199 check whether the startup code contains the correct initialization (watchdog,
32203 \begin_layout Itemize
32204 check whether the sizes of short, int, long match.
32207 \begin_layout Itemize
32208 check if some 16 or 32 bit hardware registers require a specific addressing
32209 order (least significant or most significant byte first) and adapt if needed
32218 relate to time and not to lower/upper memory location here, so this is
32223 the same as endianness).
32226 \begin_layout Itemize
32227 check whether the keyword
32231 is used where needed.
32232 The compilers might differ in their optimization characteristics (as different
32233 versions of the same compiler might also use more clever optimizations
32234 this is good idea anyway).
32236 \begin_inset LatexCommand ref
32237 reference "sub:Common-interrupt-pitfall-volatile"
32244 \begin_layout Itemize
32245 check that the compilers are not told to suppress warnings.
32248 \begin_layout Itemize
32249 check and convert compiler specific extensions (interrupts, memory areas,
32253 \begin_layout Itemize
32254 check for differences in type promotion.
32255 Especially check for math operations on
32264 For the sake of C99 compatibility SDCC will probably promote these to
32268 more often than other compilers.
32269 Eventually insert explicit casts to
32278 Also check that the ~\InsetSpace ~
32280 \begin_inset LatexCommand index
32281 name "\\~\\/ Operator"
32288 \begin_inset LatexCommand index
32295 variables, use the !\InsetSpace ~
32298 \begin_inset LatexCommand ref
32299 reference "type promotion"
32304 \begin_inset LatexCommand ref
32305 reference "sec:Compatibility-with-previous"
32312 \begin_layout Itemize
32313 check the assembly code generated for interrupt routines (f.e.
32314 for calls to possibly non-reentrant library functions).
32317 \begin_layout Itemize
32318 check whether timing loops result in proper timing (or preferably consider
32319 a rewrite of the code with timer based delays instead).
32322 \begin_layout Itemize
32323 check for differences in printf parameters (some compilers push (va_arg
32324 \begin_inset LatexCommand index
32325 name "vararg, va\\_arg"
32329 ) char variables as
32333 others push them as
32339 \begin_inset LatexCommand ref
32340 reference "sec:Compatibility-with-previous"
32347 \begin_layout Itemize
32348 check the resulting memory map
32349 \begin_inset LatexCommand index
32355 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
32356 ly idata, pdata, xdata).
32357 Eventually check if unexpected library functions are included.
32360 \begin_layout Section
32362 \begin_inset LatexCommand index
32367 included in the distribution
32370 \begin_layout Standard
32372 \begin_inset Tabular
32373 <lyxtabular version="3" rows="12" columns="3">
32375 <column alignment="left" valignment="top" leftline="true" width="0pt">
32376 <column alignment="left" valignment="top" leftline="true" width="0pt">
32377 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32378 <row topline="true" bottomline="true">
32379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32382 \begin_layout Standard
32390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32393 \begin_layout Standard
32401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32404 \begin_layout Standard
32413 <row topline="true">
32414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32417 \begin_layout Standard
32419 \begin_inset LatexCommand index
32429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32432 \begin_layout Standard
32433 Simulator for various architectures
32438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32441 \begin_layout Standard
32448 <row topline="true">
32449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32452 \begin_layout Standard
32458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32461 \begin_layout Standard
32463 \begin_inset LatexCommand index
32464 name "Header files"
32469 \begin_inset LatexCommand index
32470 name "Include files"
32479 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32482 \begin_layout Standard
32483 sdcc/support/scripts
32489 <row topline="true">
32490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32493 \begin_layout Standard
32499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32502 \begin_layout Standard
32503 header file conversion
32508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32511 \begin_layout Standard
32512 sdcc/support/scripts
32518 <row topline="true">
32519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32522 \begin_layout Standard
32528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32531 \begin_layout Standard
32537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32540 \begin_layout Standard
32556 <row topline="true">
32557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32560 \begin_layout Standard
32566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32569 \begin_layout Standard
32575 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32578 \begin_layout Standard
32594 <row topline="true">
32595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32598 \begin_layout Standard
32604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32607 \begin_layout Standard
32613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32616 \begin_layout Standard
32632 <row topline="true">
32633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32636 \begin_layout Standard
32642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32645 \begin_layout Standard
32651 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32654 \begin_layout Standard
32670 <row topline="true">
32671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32674 \begin_layout Standard
32680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32683 \begin_layout Standard
32689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32692 \begin_layout Standard
32708 <row topline="true">
32709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32712 \begin_layout Standard
32718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32721 \begin_layout Standard
32727 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32730 \begin_layout Standard
32746 <row topline="true">
32747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32750 \begin_layout Standard
32756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32759 \begin_layout Standard
32765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32768 \begin_layout Standard
32784 <row topline="true" bottomline="true">
32785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32788 \begin_layout Standard
32794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32797 \begin_layout Standard
32799 \begin_inset LatexCommand index
32800 name "packihx (tool)"
32809 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32812 \begin_layout Standard
32837 \begin_layout Section
32839 \begin_inset LatexCommand index
32840 name "Documentation"
32844 included in the distribution
32847 \begin_layout Standard
32849 \begin_inset Tabular
32850 <lyxtabular version="3" rows="10" columns="2">
32852 <column alignment="block" valignment="top" leftline="true" width="40col%">
32853 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
32854 <row topline="true" bottomline="true" endhead="true">
32855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32858 \begin_layout Standard
32866 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32869 \begin_layout Standard
32872 Filename / Where to get
32878 <row topline="true">
32879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32882 \begin_layout Standard
32883 SDCC Compiler User Guide
32888 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32891 \begin_layout Standard
32892 You're reading it right now
32904 \begin_inset LatexCommand url
32905 target "http://sdcc.sourceforge.net/doc/sdccman.pdf"
32915 <row topline="true">
32916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32919 \begin_layout Standard
32925 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32928 \begin_layout Standard
32941 \begin_inset LatexCommand url
32942 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog"
32952 <row topline="true">
32953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32956 \begin_layout Standard
32958 \begin_inset LatexCommand index
32959 name "asXXXX (as-gbz80, as-hc08, asx8051, as-z80)"
32964 \begin_inset LatexCommand index
32965 name "Assembler documentation"
32972 \begin_inset LatexCommand index
32978 \begin_inset LatexCommand index
32979 name "Linker documentation"
32988 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32991 \begin_layout Standard
32992 sdcc/as/doc/asxhtm.html
33004 \begin_inset LatexCommand url
33005 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html"
33015 <row topline="true">
33016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33019 \begin_layout Standard
33020 SDCC regression test
33021 \begin_inset LatexCommand index
33022 name "Regression test"
33031 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33034 \begin_layout Standard
33035 sdcc/doc/test_suite_spec.pdf
33047 \begin_inset LatexCommand url
33048 target "http://sdcc.sourceforge.net/doc/test_suite_spec.pdf"
33058 <row topline="true">
33059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33062 \begin_layout Standard
33068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33071 \begin_layout Standard
33084 \begin_inset LatexCommand url
33085 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/"
33095 <row topline="true">
33096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33099 \begin_layout Standard
33100 Notes on debugging with SDCDB
33101 \begin_inset LatexCommand index
33102 name "SDCDB (debugger)"
33111 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33114 \begin_layout Standard
33115 sdcc/debugger/README
33127 \begin_inset LatexCommand url
33128 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README"
33138 <row topline="true">
33139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33142 \begin_layout Standard
33144 \begin_inset LatexCommand index
33149 Software simulator for microcontrollers
33154 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33157 \begin_layout Standard
33187 \begin_inset LatexCommand url
33188 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html"
33198 <row topline="true">
33199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33202 \begin_layout Standard
33203 Temporary notes on the pic16
33204 \begin_inset LatexCommand index
33214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33217 \begin_layout Standard
33218 sdcc/src/pic16/NOTES
33230 \begin_inset LatexCommand url
33231 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES"
33241 <row topline="true" bottomline="true">
33242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33245 \begin_layout Standard
33246 SDCC internal documentation (debugging file format)
33251 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33254 \begin_layout Standard
33284 \begin_inset LatexCommand url
33285 target "http://sdcc.sourceforge.net/doc/cdbfileformat.pdf"
33304 \begin_layout Section
33305 Related open source tools
33306 \begin_inset LatexCommand label
33307 name "sec:Related-open-source-tools"
33312 \begin_inset LatexCommand index
33313 name "Related tools"
33320 \begin_layout Standard
33322 \begin_inset Tabular
33323 <lyxtabular version="3" rows="16" columns="3">
33325 <column alignment="left" valignment="top" leftline="true" width="0pt">
33326 <column alignment="block" valignment="top" leftline="true" width="30line%">
33327 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
33328 <row topline="true" bottomline="true">
33329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33332 \begin_layout Standard
33340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33343 \begin_layout Standard
33351 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33354 \begin_layout Standard
33363 <row topline="true">
33364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33367 \begin_layout Standard
33369 \begin_inset LatexCommand index
33370 name "gpsim (pic simulator)"
33379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33382 \begin_layout Standard
33388 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33391 \begin_layout Standard
33392 \begin_inset LatexCommand url
33393 target "http://www.dattalo.com/gnupic/gpsim.html"
33403 <row topline="true">
33404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33407 \begin_layout Standard
33409 \begin_inset LatexCommand index
33410 name "gputils (pic tools)"
33419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33422 \begin_layout Standard
33428 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33431 \begin_layout Standard
33432 \begin_inset LatexCommand url
33433 target "http://sourceforge.net/projects/gputils"
33443 <row topline="true">
33444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33447 \begin_layout Standard
33453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33456 \begin_layout Standard
33462 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33465 \begin_layout Standard
33466 \begin_inset LatexCommand url
33467 target "http://freshmeat.net/projects/flp5/"
33477 <row topline="true">
33478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33481 \begin_layout Standard
33487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33490 \begin_layout Standard
33491 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
33497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33500 \begin_layout Standard
33501 \begin_inset LatexCommand url
33502 target "http://sourceforge.net/projects/ec2drv"
33512 <row topline="true">
33513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33516 \begin_layout Standard
33518 \begin_inset LatexCommand index
33519 name "indent (source formatting tool)"
33528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33531 \begin_layout Standard
33532 Formats C source - Master of the white spaces
33537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33540 \begin_layout Standard
33541 \begin_inset LatexCommand url
33542 target "http://directory.fsf.org/GNU/indent.html"
33552 <row topline="true">
33553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33556 \begin_layout Standard
33558 \begin_inset LatexCommand index
33559 name "srecord (bin, hex, ... tool)"
33568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33571 \begin_layout Standard
33572 Object file conversion, checksumming, ...
33577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33580 \begin_layout Standard
33581 \begin_inset LatexCommand url
33582 target "http://sourceforge.net/projects/srecord"
33592 <row topline="true">
33593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33596 \begin_layout Standard
33598 \begin_inset LatexCommand index
33599 name "objdump (tool)"
33608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33611 \begin_layout Standard
33612 Object file conversion, ...
33617 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33620 \begin_layout Standard
33621 Part of binutils (should be there anyway)
33627 <row topline="true">
33628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33631 \begin_layout Standard
33637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33640 \begin_layout Standard
33641 8051 monitor (hex up-/download, single step, disassemble)
33646 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33649 \begin_layout Standard
33650 \begin_inset LatexCommand url
33651 target "http://sourceforge.net/projects/cmon51"
33661 <row topline="true">
33662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33665 \begin_layout Standard
33667 \begin_inset LatexCommand index
33668 name "doxygen (source documentation tool)"
33677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33680 \begin_layout Standard
33681 Source code documentation system
33686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33689 \begin_layout Standard
33690 \begin_inset LatexCommand url
33691 target "http://www.doxygen.org"
33701 <row topline="true">
33702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33705 \begin_layout Standard
33711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33714 \begin_layout Standard
33715 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
33720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33723 \begin_layout Standard
33724 \begin_inset LatexCommand url
33725 target "http://www.kdevelop.org"
33735 <row topline="true">
33736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33739 \begin_layout Standard
33745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33748 \begin_layout Standard
33749 8051 monitor (hex up-/download, single step, disassemble)
33754 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33757 \begin_layout Standard
33758 \begin_inset LatexCommand url
33759 target "http://www.pjrc.com/tech/8051/paulmon2.html"
33769 <row topline="true">
33770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33773 \begin_layout Standard
33775 \begin_inset LatexCommand index
33776 name "splint (syntax checking tool)"
33785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33788 \begin_layout Standard
33789 Statically checks c sources (see
33790 \begin_inset LatexCommand ref
33791 reference "lyx:more-pedantic-SPLINT"
33800 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33803 \begin_layout Standard
33804 \begin_inset LatexCommand url
33805 target "http://www.splint.org"
33815 <row topline="true" bottomline="true">
33816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33819 \begin_layout Standard
33821 \begin_inset LatexCommand index
33822 name "DDD (debugger)"
33831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33834 \begin_layout Standard
33835 Debugger, serves nicely as GUI to SDCDB
33836 \begin_inset LatexCommand index
33837 name "SDCDB (debugger)"
33846 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33849 \begin_layout Standard
33850 \begin_inset LatexCommand url
33851 target "http://www.gnu.org/software/ddd/"
33861 <row bottomline="true">
33862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33865 \begin_layout Standard
33867 \begin_inset LatexCommand index
33873 \begin_inset LatexCommand index
33874 name "d52 (disassembler)"
33883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33886 \begin_layout Standard
33887 Disassembler, can count instruction cycles
33888 \begin_inset LatexCommand index
33889 name "instruction cycles (count)"
33893 , use with options -pnd
33898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33901 \begin_layout Standard
33902 \begin_inset LatexCommand url
33903 target "http://www.8052.com/users/disasm/"
33913 <row bottomline="true">
33914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33917 \begin_layout Standard
33919 \begin_inset LatexCommand index
33929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33932 \begin_layout Standard
33933 Cross platform build system, generates Makefiles
33934 \begin_inset LatexCommand index
33939 and project workspaces
33940 \begin_inset LatexCommand index
33941 name "project workspace"
33950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33953 \begin_layout Standard
33954 \begin_inset LatexCommand url
33955 target "http://www.cmake.org"
33963 and a dedicated wiki entry:
33964 \begin_inset LatexCommand url
33965 target "http://www.cmake.org/Wiki/CmakeSdcc"
33984 \begin_layout Section
33985 Related documentation / recommended reading
33988 \begin_layout Standard
33990 \begin_inset Tabular
33991 <lyxtabular version="3" rows="7" columns="3">
33993 <column alignment="left" valignment="top" leftline="true" width="0pt">
33994 <column alignment="left" valignment="top" leftline="true" width="0">
33995 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
33996 <row topline="true" bottomline="true">
33997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34000 \begin_layout Standard
34008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34011 \begin_layout Standard
34019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34022 \begin_layout Standard
34031 <row topline="true">
34032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34035 \begin_layout Standard
34050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34053 \begin_layout Standard
34055 \begin_inset LatexCommand index
34056 name "C Reference card"
34065 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34068 \begin_layout Standard
34069 \begin_inset LatexCommand url
34070 target "http://refcards.com/refcards/c/index.html"
34080 <row topline="true">
34081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34084 \begin_layout Standard
34090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34093 \begin_layout Standard
34095 \begin_inset LatexCommand index
34105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34108 \begin_layout Standard
34109 \begin_inset LatexCommand url
34110 target "http://www.c-faq.com"
34120 <row topline="true">
34121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34124 \begin_layout Standard
34130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34133 \begin_layout Standard
34134 \begin_inset Quotes sld
34138 \begin_inset Quotes srd
34146 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34149 \begin_layout Standard
34152 \begin_inset LatexCommand url
34153 target "http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899"
34163 <row topline="true">
34164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34167 \begin_layout Standard
34173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34176 \begin_layout Standard
34177 \begin_inset Quotes sld
34180 Extensions for Embedded C
34181 \begin_inset Quotes srd
34189 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34192 \begin_layout Standard
34195 \begin_inset LatexCommand url
34196 target "http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf"
34206 <row topline="true">
34207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34210 \begin_layout Standard
34216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34219 \begin_layout Standard
34220 Latest datasheet of target CPU
34225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34228 \begin_layout Standard
34235 <row topline="true" bottomline="true">
34236 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34239 \begin_layout Standard
34245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34248 \begin_layout Standard
34249 Revision history of datasheet
34254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34257 \begin_layout Standard
34273 \begin_layout Section
34274 Application notes specifically for SDCC
34277 \begin_layout Standard
34278 SDCC makes no claims about the completeness of this list and about up-to-datenes
34279 s or correctness of the application notes
34280 \begin_inset LatexCommand index
34281 name "Application notes"
34288 \begin_layout Standard
34292 \begin_inset Tabular
34293 <lyxtabular version="3" rows="7" columns="3">
34295 <column alignment="block" valignment="top" leftline="true" width="17col%">
34296 <column alignment="block" valignment="top" leftline="true" width="27col%">
34297 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
34298 <row topline="true" bottomline="true">
34299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34302 \begin_layout Standard
34311 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
34314 \begin_layout Standard
34323 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34326 \begin_layout Standard
34336 <row topline="true">
34337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34340 \begin_layout Standard
34348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34351 \begin_layout Standard
34354 Using the SDCC Compiler for the DS80C400
34355 \begin_inset LatexCommand index
34365 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34368 \begin_layout Standard
34371 \begin_inset LatexCommand url
34372 target "http://pdfserv.maxim-ic.com/en/an/AN3346.pdf"
34382 <row topline="true">
34383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34386 \begin_layout Standard
34394 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
34397 \begin_layout Standard
34400 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
34401 \begin_inset LatexCommand index
34406 Family of Microcontrollers
34411 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34414 \begin_layout Standard
34417 \begin_inset LatexCommand url
34418 target "http://pdfserv.maxim-ic.com/en/an/AN3477.pdf"
34428 <row topline="true">
34429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34432 \begin_layout Standard
34435 Silicon Laboratories / Cygnal
34440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34443 \begin_layout Standard
34446 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
34447 \begin_inset LatexCommand index
34457 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34460 \begin_layout Standard
34463 \begin_inset LatexCommand url
34464 target "http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf"
34474 <row topline="true">
34475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34478 \begin_layout Standard
34481 Ramtron / Goal Semiconductor
34486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34489 \begin_layout Standard
34492 Interfacing SDCC to Syn and Textpad
34497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34500 \begin_layout Standard
34503 \begin_inset LatexCommand url
34504 target "http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp"
34514 <row topline="true">
34515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34518 \begin_layout Standard
34521 Ramtron / Goal Semiconductor
34526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34529 \begin_layout Standard
34532 Installing and Configuring SDCC and Crimson Editor
34537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34540 \begin_layout Standard
34543 \begin_inset LatexCommand url
34544 target "http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp"
34554 <row topline="true" bottomline="true">
34555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34558 \begin_layout Standard
34566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34569 \begin_layout Standard
34572 MSC12xx Programming with SDCC
34577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34580 \begin_layout Standard
34583 \begin_inset LatexCommand url
34584 target "http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf"
34601 \begin_layout Section
34605 \begin_layout Standard
34606 Some questions answered, some pointers given - it might be time to in turn
34614 \begin_layout Itemize
34615 can you solve your project with the selected microcontroller? Would you
34616 find out early or rather late that your target is too small/slow/whatever?
34617 Can you switch to a slightly better device if it doesn't fit?
34620 \begin_layout Itemize
34621 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
34622 and/or another programming language be more adequate? Would an operating
34623 system on the target device help?
34626 \begin_layout Itemize
34627 if you solved the problem, will the marketing department be happy?
34630 \begin_layout Itemize
34631 if the marketing department is happy, will customers be happy?
34634 \begin_layout Itemize
34635 if you're the project manager, marketing department and maybe even the customer
34636 in one person, have you tried to see the project from the outside?
34639 \begin_layout Itemize
34640 is the project done if you think it is done? Or is just that other interface/pro
34641 tocol/feature/configuration/option missing? How about website, manual(s),
34642 internationali(z|s)ation, packaging, labels, 2nd source for components,
34643 electromagnetic compatability/interference, documentation for production,
34644 production test software, update mechanism, patent issues?
34647 \begin_layout Itemize
34648 is your project adequately positioned in that magic triangle: fame, fortune,
34652 \begin_layout Standard
34653 Maybe not all answers to these questions are known and some answers may
34658 , nevertheless knowing these questions may help you to avoid burnout
34662 \begin_layout Standard
34663 burnout is bad for electronic devices, programmers and motorcycle tyres
34669 Chances are you didn't want to hear some of them...
34672 \begin_layout Chapter
34674 \begin_inset LatexCommand index
34682 \begin_layout Standard
34683 SDCC has grown to be a large project.
34684 The compiler alone (without the preprocessor, assembler and linker) is
34685 well over 150,000 lines of code (blank stripped).
34686 The open source nature of this project is a key to its continued growth
34688 You gain the benefit and support of many active software developers and
34690 Is SDCC perfect? No, that's why we need your help.
34691 The developers take pride in fixing reported bugs.
34692 You can help by reporting the bugs and helping other SDCC users.
34693 There are lots of ways to contribute, and we encourage you to take part
34694 in making SDCC a great software package.
34698 \begin_layout Standard
34699 The SDCC project is hosted on the SDCC sourceforge site at
34700 \begin_inset LatexCommand htmlurl
34701 target "http://sourceforge.net/projects/sdcc"
34706 You'll find the complete set of mailing lists
34707 \begin_inset LatexCommand index
34708 name "Mailing list(s)"
34712 , forums, bug reporting system, patch submission
34713 \begin_inset LatexCommand index
34714 name "Patch submission"
34719 \begin_inset LatexCommand index
34724 area and Subversion code repository
34725 \begin_inset LatexCommand index
34726 name "Subversion code repository"
34733 \begin_layout Section
34735 \begin_inset LatexCommand index
34736 name "Bug reporting"
34741 \begin_inset LatexCommand index
34742 name "Reporting bugs"
34749 \begin_layout Standard
34750 The recommended way of reporting bugs is using the infrastructure of the
34752 You can follow the status of bug reports there and have an overview about
34756 \begin_layout Standard
34757 Bug reports are automatically forwarded to the developer mailing list and
34758 will be fixed ASAP.
34759 When reporting a bug, it is very useful to include a small test program
34760 (the smaller the better) which reproduces the problem.
34761 If you can isolate the problem by looking at the generated assembly code,
34762 this can be very helpful.
34763 Compiling your program with the -
34767 \begin_layout Standard
34777 \begin_inset LatexCommand index
34778 name "-\\/-dumpall"
34782 option can sometimes be useful in locating optimization problems.
34783 When reporting a bug please make sure you:
34786 \begin_layout Enumerate
34787 Attach the code you are compiling with SDCC.
34791 \begin_layout Enumerate
34792 Specify the exact command you use to run SDCC, or attach your Makefile.
34796 \begin_layout Enumerate
34797 Specify the SDCC version (type "
34803 "), your platform, and operating system.
34807 \begin_layout Enumerate
34808 Provide an exact copy of any error message or incorrect output.
34812 \begin_layout Enumerate
34813 Put something meaningful in the subject of your message.
34816 \begin_layout Standard
34817 Please attempt to include these 5 important parts, as applicable, in all
34818 requests for support or when reporting any problems or bugs with SDCC.
34819 Though this will make your message lengthy, it will greatly improve your
34820 chance that SDCC users and developers will be able to help you.
34821 Some SDCC developers are frustrated by bug reports without code provided
34822 that they can use to reproduce and ultimately fix the problem, so please
34823 be sure to provide sample code if you are reporting a bug!
34826 \begin_layout Standard
34827 Please have a short check that you are using a recent version of SDCC and
34828 the bug is not yet known.
34829 This is the link for reporting bugs:
34830 \begin_inset LatexCommand htmlurl
34831 target "http://sourceforge.net/tracker/?group_id=599&atid=100599"
34836 With SDCC on average having more than 200 downloads
34837 \begin_inset LatexCommand index
34842 on sourceforge per day
34846 \begin_layout Standard
34847 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
34848 between 2002 and 2005.
34849 This does not include other methods of distribution.
34854 there must be some users.
34855 So it's not exactly easy to find a new bug.
34856 If you find one we need it:
34858 reporting bugs is good
34863 \begin_layout Section
34864 Requesting Features
34865 \begin_inset LatexCommand label
34866 name "sub:Requesting-Features"
34871 \begin_inset LatexCommand index
34872 name "Feature request"
34877 \begin_inset LatexCommand index
34878 name "Requesting features"
34885 \begin_layout Standard
34886 Like bug reports feature requests are forwarded to the developer mailing
34888 This is the link for requesting features:
34889 \begin_inset LatexCommand htmlurl
34890 target "http://sourceforge.net/tracker/?group_id=599&atid=350599"
34897 \begin_layout Section
34901 \begin_layout Standard
34902 Like bug reports contributed patches are forwarded to the developer mailing
34904 This is the link for submitting patches
34905 \begin_inset LatexCommand index
34906 name "Patch submission"
34911 \begin_inset LatexCommand url
34912 target "http://sourceforge.net/tracker/?group_id=599&atid=300599"
34919 \begin_layout Standard
34920 You need to specify some parameters to the
34924 command for the patches to be useful.
34925 If you modified more than one file a patch created f.e.
34930 \begin_inset Quotes sld
34933 diff -Naur unmodified_directory modified_directory >my_changes.patch
34934 \begin_inset Quotes srd
34940 will be fine, otherwise
34944 \begin_inset Quotes sld
34947 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
34948 \begin_inset Quotes srd
34957 \begin_layout Section
34961 \begin_layout Standard
34962 These links should take you directly to the
34963 \begin_inset LatexCommand url
34964 name "Mailing lists"
34965 target "http://sourceforge.net/mail/?group_id=599"
34973 \begin_layout Standard
34974 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
34975 automated messages (mid 2003)
34981 \begin_inset LatexCommand url
34983 target "http://sourceforge.net/forum/?group_id=599"
34988 \begin_inset LatexCommand index
34989 name "Mailing list(s)"
34993 and forums are archived and searchable so if you are lucky someone already
34994 had a similar problem.
34995 While mails to the lists themselves are delivered promptly their web front
34996 end on sourceforge sometimes shows a severe time lag (up to several weeks),
34997 if you're seriously using SDCC please consider subscribing to the lists.
35000 \begin_layout Section
35004 \begin_layout Standard
35005 You can follow the status of the Subversion version
35006 \begin_inset LatexCommand index
35011 of SDCC by watching the Changelog
35012 \begin_inset LatexCommand index
35017 in the Subversion repository
35020 \begin_inset LatexCommand htmlurl
35021 target "http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog"
35028 \begin_layout Section
35029 Subversion Source Code Repository
35032 \begin_layout Standard
35042 \begin_layout Standard
35056 or the filenames of the snapshot versions of SDCC include date and its
35058 \begin_inset LatexCommand index
35059 name "Subversion code repository"
35064 Subversion allows to download the source of recent or previous versions
35066 \begin_inset LatexCommand url
35067 target "http://sourceforge.net/svn/?group_id=599"
35071 (by number or by date).
35072 An on-line source code browser and detailled instructions are also available
35074 SDCC versions starting from 1999 up to now are available (currently the
35075 versions prior to the conversion from cvs
35076 \begin_inset LatexCommand index
35077 name "cvs|see{Subversion}"
35081 to Subversion (April 2006) are either by accessible by Subversion or by
35085 \begin_layout Section
35087 \begin_inset LatexCommand index
35088 name "Release policy"
35095 \begin_layout Standard
35096 Historically there often were long delays between official releases and
35097 the sourceforge download area tends to get not updated at all.
35098 Excuses in the past might have referred to problems with live range analysis,
35099 but as this was fixed a while ago, the current problem is that another
35100 excuse has to be found.
35101 Kidding aside, we have to get better there! On the other hand there are
35102 daily snapshots available at
35103 \begin_inset LatexCommand htmlurl
35105 target "http://sdcc.sourceforge.net/snap.php"
35109 , and you can always build the very last version (hopefully with many bugs
35110 fixed, and features added) from the source code available at
35111 \begin_inset LatexCommand htmlurl
35113 target "http://sdcc.sourceforge.net/snap.php#Source"
35119 \begin_inset LatexCommand index
35125 \begin_inset LatexCommand index
35131 \begin_inset LatexCommand url
35132 target "http://sdcc.wiki.sourceforge.net/"
35136 also holds some information about past and future releases.
35139 \begin_layout Section
35141 \begin_inset LatexCommand index
35149 \begin_layout Standard
35150 You'll find some small examples in the directory
35152 sdcc/device/examples/.
35155 More examples and libraries are available at
35157 The SDCC Open Knowledge Resource
35158 \begin_inset LatexCommand url
35159 target "http://sdccokr.dl9sec.de/"
35166 \begin_inset LatexCommand url
35167 target "http://www.pjrc.com/tech/8051/"
35174 \begin_layout Standard
35175 \begin_inset Note Note
35178 \begin_layout Standard
35179 I did insert a reference to Paul's web site here although it seems rather
35180 dedicated to a specific 8032 board (I think it's okay because it f.e.
35181 shows LCD/Harddisc interface and has a free 8051 monitor.
35182 Independent 8032 board vendors face hard competition of heavily subsidized
35183 development boards anyway).
35186 \begin_layout Standard
35187 Maybe we should include some links to real world applications.
35188 Preferably pointer to pointers (one for each architecture) so this stays
35197 \begin_layout Section
35199 \begin_inset LatexCommand label
35200 name "sec:Quality-control"
35205 \begin_inset LatexCommand index
35206 name "Quality control"
35213 \begin_layout Standard
35214 The compiler is passed through snaphot build compile and build checks.
35220 \begin_inset LatexCommand index
35221 name "Regression test"
35225 check that SDCC itself compiles flawlessly on several host platforms (i386,
35226 Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
35227 and checks the quality of the code generated by SDCC by running the code
35228 for several target platforms through simulators.
35229 The regression test suite comprises more than 100 files which expand to
35230 more than 500 test cases which include more than 4500 tests.
35231 The results of these tests are published daily on SDCC's snapshot page
35232 (click on the red or green symbols on the right side of
35233 \begin_inset LatexCommand url
35234 target "http://sdcc.sourceforge.net/snap.php"
35241 \begin_layout Standard
35242 There is a separate document
35245 \begin_inset LatexCommand index
35253 \begin_inset LatexCommand url
35254 target "http://sdcc.sourceforge.net/doc/test_suite_spec.pdf"
35258 about the regression test suite.
35261 \begin_layout Standard
35262 You'll find the test code in the directory
35264 sdcc/support/regression
35267 You can run these tests manually by running
35271 in this directory (or f.e.
35276 \begin_inset Quotes sld
35280 \begin_inset Quotes srd
35286 if you don't want to run the complete tests).
35287 The test code might also be interesting if you want to look for examples
35288 \begin_inset LatexCommand index
35293 checking corner cases of SDCC or if you plan to submit patches
35294 \begin_inset LatexCommand index
35295 name "Patch submission"
35302 \begin_layout Standard
35303 The PIC14 port uses a different set of regression tests
35304 \begin_inset LatexCommand index
35305 name "Regression test (PIC14)"
35309 , you'll find them in the directory
35311 sdcc/src/regression
35316 \begin_layout Section
35317 Use of SDCC in Education
35320 \begin_layout Standard
35329 \begin_layout Standard
35330 the phrase "use in education" might evoke the association "
35334 fit for use in education".
35335 This connotation is not intended but nevertheless risked as the licensing
35336 of SDCC makes it difficult to offer educational discounts
35342 If your rationales are to:
35345 \begin_layout Enumerate
35346 give students a chance to understand the
35350 steps of code generation
35353 \begin_layout Enumerate
35354 have a curriculum that can be extended for years.
35355 Then you could use an fpga board as target and your curriculum will seamlessly
35356 extend from logic synthesis (
35357 \begin_inset LatexCommand url
35358 name "http://www.opencores.org"
35359 target "opencores.org"
35364 \begin_inset LatexCommand url
35366 target "http://www.oregano.at/ip/ip01.htm"
35370 ), over assembly programming, to C to FPGA compilers (
35371 \begin_inset LatexCommand url
35373 target "http://sf.net/projects/fpgac"
35380 \begin_layout Enumerate
35381 be able to insert excursions about skills like using a revision control
35382 system, submitting/applying patches, using a type-setting (as opposed to
35383 word-processing) engine LyX/LaTeX, using
35384 \begin_inset LatexCommand url
35386 target "http://www.sf.net"
35391 \begin_inset LatexCommand url
35393 target "http://en.wikipedia.org/wiki/Netiquette"
35397 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
35398 Source Software, CPU simulation, compiler regression tests
35399 \begin_inset LatexCommand index
35400 name "Regression test"
35407 And if there should be a shortage of ideas then you can always point students
35408 to the ever-growing feature request list
35409 \begin_inset LatexCommand htmlurl
35410 target "http://sourceforge.net/tracker/?group_id=599&atid=350599"
35417 \begin_layout Enumerate
35418 not tie students to a specific host platform and instead allow them to use
35423 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
35425 \begin_inset LatexCommand url
35427 target "http://www.laptop.org"
35434 \begin_layout Enumerate
35435 not encourage students to use illegal copies of educational software
35438 \begin_layout Enumerate
35439 be immune to licensing/availability/price changes of the chosen tool chain
35442 \begin_layout Enumerate
35443 be able to change to a new target platform without having to adopt a new
35447 \begin_layout Enumerate
35448 have complete control over and insight into the tool chain
35451 \begin_layout Enumerate
35452 make your students aware about the pros and cons of open source software
35456 \begin_layout Enumerate
35457 give back to the public as you are probably at least partially publicly
35461 \begin_layout Enumerate
35462 give students a chance to publicly prove their skills and to possibly see
35463 a world wide impact
35466 \begin_layout Standard
35467 then SDCC is probably among the first choices.
35468 Well, probably SDCC might be the only choice.
35473 \begin_layout Chapter
35474 SDCC Technical Data
35477 \begin_layout Section
35479 \begin_inset LatexCommand index
35480 name "Optimizations"
35487 \begin_layout Standard
35488 SDCC performs a host of standard optimizations in addition to some MCU specific
35493 \begin_layout Subsection
35494 Sub-expression Elimination
35495 \begin_inset LatexCommand index
35496 name "Subexpression elimination"
35503 \begin_layout Standard
35504 The compiler does local and
35523 \begin_layout Verse
35531 \begin_layout Standard
35532 will be translated to
35535 \begin_layout Verse
35545 \begin_layout Standard
35546 Some subexpressions are not as obvious as the above example, e.g.:
35549 \begin_layout Verse
35557 \begin_layout Standard
35558 In this case the address arithmetic a->b[i] will be computed only once;
35559 the equivalent code in C would be.
35562 \begin_layout Verse
35572 \begin_layout Standard
35573 The compiler will try to keep these temporary variables in registers.
35576 \begin_layout Subsection
35577 Dead-Code Elimination
35578 \begin_inset LatexCommand index
35579 name "Dead-code elimination"
35586 \begin_layout Verse
35601 i = 1; \InsetSpace ~
35610 global = 1;\InsetSpace ~
35624 global = 3;\InsetSpace ~
35630 \begin_layout Standard
35634 \begin_layout Verse
35650 \begin_layout Subsection
35652 \begin_inset LatexCommand index
35653 name "Copy propagation"
35660 \begin_layout Verse
35684 \begin_layout Standard
35688 \begin_layout Verse
35712 \begin_layout Standard
35713 Note: the dead stores created by this copy propagation will be eliminated
35714 by dead-code elimination.
35717 \begin_layout Subsection
35719 \begin_inset LatexCommand index
35720 name "Loop optimization"
35725 \begin_inset LatexCommand label
35726 name "sub:Loop-Optimizations"
35733 \begin_layout Standard
35734 Two types of loop optimizations are done by SDCC
35742 of loop induction variables.
35743 In addition to the strength reduction the optimizer marks the induction
35744 variables and the register allocator tries to keep the induction variables
35745 in registers for the duration of the loop.
35746 Because of this preference of the register allocator
35747 \begin_inset LatexCommand index
35748 name "Register allocation"
35752 , loop induction optimization causes an increase in register pressure, which
35753 may cause unwanted spilling of other temporary variables into the stack
35754 \begin_inset LatexCommand index
35760 The compiler will generate a warning message when it is forced to allocate
35761 extra space either on the stack or data space.
35762 If this extra space allocation is undesirable then induction optimization
35763 can be eliminated either for the entire source file (with -
35767 \begin_layout Standard
35776 -noinduction option) or for a given function only using #pragma\InsetSpace ~
35778 \begin_inset LatexCommand index
35779 name "\\#pragma noinduction"
35790 \begin_layout Verse
35793 for (i = 0 ; i < 100 ; i ++)
35802 \begin_layout Standard
35806 \begin_layout Verse
35811 for (i = 0; i < 100; i++)
35820 \begin_layout Standard
35821 As mentioned previously some loop invariants are not as apparent, all static
35822 address computations are also moved out of the loop.
35827 \begin_inset LatexCommand index
35828 name "Strength reduction"
35832 , this optimization substitutes an expression by a cheaper expression:
35835 \begin_layout Verse
35838 for (i=0;i < 100; i++)
35847 \begin_layout Standard
35851 \begin_layout Verse
35858 for (i=0;i< 100;i++) {
35864 ar[itemp1] = itemp2;
35882 \begin_layout Standard
35883 The more expensive multiplication
35884 \begin_inset LatexCommand index
35885 name "Multiplication"
35889 is changed to a less expensive addition.
35892 \begin_layout Subsection
35894 \begin_inset LatexCommand index
35895 name "Loop reversing"
35902 \begin_layout Standard
35903 This optimization is done to reduce the overhead of checking loop boundaries
35904 for every iteration.
35905 Some simple loops can be reversed and implemented using a
35906 \begin_inset Quotes eld
35909 decrement and jump if not zero
35910 \begin_inset Quotes erd
35914 SDCC checks for the following criterion to determine if a loop is reversible
35915 (note: more sophisticated compilers use data-dependency analysis to make
35916 this determination, SDCC uses a more simple minded analysis).
35919 \begin_layout Itemize
35920 The 'for' loop is of the form
35926 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
35936 \begin_layout Itemize
35937 The <for body> does not contain
35938 \begin_inset Quotes eld
35942 \begin_inset Quotes erd
35946 \begin_inset Quotes erd
35952 \begin_layout Itemize
35953 All goto's are contained within the loop.
35956 \begin_layout Itemize
35957 No function calls within the loop.
35960 \begin_layout Itemize
35961 The loop control variable <sym> is not assigned any value within the loop
35964 \begin_layout Itemize
35965 The loop control variable does NOT participate in any arithmetic operation
35969 \begin_layout Itemize
35970 There are NO switch statements in the loop.
35973 \begin_layout Subsection
35974 Algebraic Simplifications
35977 \begin_layout Standard
35978 SDCC does numerous algebraic simplifications, the following is a small sub-set
35979 of these optimizations.
35982 \begin_layout Verse
35985 i = j + 0;\InsetSpace ~
35989 /* changed to: */\InsetSpace ~
35995 i /= 2;\InsetSpace ~
36002 /* changed to: */\InsetSpace ~
36009 = j - j;\InsetSpace ~
36013 /* changed to: */\InsetSpace ~
36019 i = j / 1;\InsetSpace ~
36023 /* changed to: */\InsetSpace ~
36030 \begin_layout Standard
36031 Note the subexpressions
36032 \begin_inset LatexCommand index
36033 name "Subexpression"
36037 given above are generally introduced by macro expansions or as a result
36038 of copy/constant propagation.
36041 \begin_layout Subsection
36042 'switch' Statements
36043 \begin_inset LatexCommand label
36044 name "sub:'switch'-Statements"
36049 \begin_inset LatexCommand index
36050 name "switch statement"
36057 \begin_layout Standard
36058 SDCC can optimize switch statements to jump tables
36059 \begin_inset LatexCommand index
36065 It makes the decision based on an estimate of the generated code size.
36066 SDCC is quite liberal in the requirements for jump table generation:
36069 \begin_layout Itemize
36070 The labels need not be in order, and the starting number need not be one
36071 or zero, the case labels are in numerical sequence or not too many case
36072 labels are missing.
36076 \begin_layout Verse
36079 switch(i) {\InsetSpace ~
36110 case 4: ...\InsetSpace ~
36142 case 5: ...\InsetSpace ~
36174 case 3: ...\InsetSpace ~
36205 case 6: ...\InsetSpace ~
36237 case 7: ...\InsetSpace ~
36269 case 8: ...\InsetSpace ~
36301 case 9: ...\InsetSpace ~
36333 case 10: ...\InsetSpace ~
36364 case 11: ...\InsetSpace ~
36431 \begin_layout Standard
36432 Both the above switch statements will be implemented using a jump-table.
36433 The example to the right side is slightly more efficient as the check for
36434 the lower boundary of the jump-table is not needed.
36438 \begin_layout Itemize
36439 The number of case labels is not larger than supported by the target architectur
36443 \begin_layout Itemize
36444 If the case labels are not in numerical sequence ('gaps' between cases)
36445 SDCC checks whether a jump table with additionally inserted dummy cases
36446 is still attractive.
36450 \begin_layout Itemize
36451 If the starting number is not zero and a check for the lower boundary of
36452 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
36457 \begin_layout Standard
36458 Switch statements which have large gaps in the numeric sequence or those
36459 that have too many case labels can be split into more than one switch statement
36460 for efficient code generation, e.g.:
36463 \begin_layout Verse
36541 \begin_layout Standard
36542 If the above switch statement is broken down into two switch statements
36545 \begin_layout Verse
36588 \begin_layout Standard
36592 \begin_layout Verse
36635 \begin_layout Standard
36636 then both the switch statements will be implemented using jump-tables whereas
36637 the unmodified switch statement will not be.
36640 \begin_layout Standard
36641 \begin_inset Note Note
36644 \begin_layout Standard
36645 There might be reasons which SDCC cannot know about to either favour or
36646 not favour jump tables.
36647 If the target system has to be as quick for the last switch case as for
36648 the first (pro jump table), or if the switch argument is known to be zero
36649 in the majority of the cases (contra jump table).
36657 \begin_layout Standard
36658 The pragma nojtbound
36659 \begin_inset LatexCommand index
36660 name "\\#pragma nojtbound"
36664 can be used to turn off checking the
36677 It has no effect if a default label is supplied.
36678 Use of this pragma is dangerous: if the switch
36679 \begin_inset LatexCommand index
36680 name "switch statement"
36684 argument is not matched by a case statement the processor will happily
36688 \begin_layout Subsection
36689 Bit-shifting Operations
36690 \begin_inset LatexCommand index
36691 name "Bit shifting"
36698 \begin_layout Standard
36699 Bit shifting is one of the most frequently used operation in embedded programmin
36701 SDCC tries to implement bit-shift operations in the most efficient way
36705 \begin_layout Verse
36718 \begin_layout Standard
36719 generates the following code:
36722 \begin_layout Verse
36737 \begin_layout Standard
36738 In general SDCC will never setup a loop if the shift count is known.
36742 \begin_layout Verse
36755 \begin_layout Standard
36759 \begin_layout Verse
36783 \begin_layout Subsection
36785 \begin_inset LatexCommand index
36786 name "Bit rotation"
36793 \begin_layout Standard
36794 A special case of the bit-shift operation is bit rotation
36795 \begin_inset LatexCommand index
36796 name "rotating bits"
36800 , SDCC recognizes the following expression to be a left bit-rotation:
36803 \begin_layout Verse
36811 char i;\InsetSpace ~
36822 /* unsigned is needed for rotation */
36827 i = ((i << 1) | (i >> 7));
36836 \begin_layout Standard
36837 will generate the following code:
36840 \begin_layout Verse
36857 \begin_layout Standard
36858 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
36859 ns of this case will also be recognized as bit-rotation, i.e.:
36862 \begin_layout Verse
36865 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
36868 \begin_layout Subsection
36869 Nibble and Byte Swapping
36872 \begin_layout Standard
36873 Other special cases of the bit-shift operations are nibble or byte swapping
36874 \begin_inset LatexCommand index
36875 name "swapping nibbles/bytes"
36879 , SDCC recognizes the following expressions:
36882 \begin_layout Verse
36903 i = ((i << 4) | (i >> 4));
36909 j = ((j << 8) | (j >> 8));
36912 \begin_layout Standard
36913 and generates a swap instruction for the nibble swapping
36914 \begin_inset LatexCommand index
36915 name "Nibble swapping"
36919 or move instructions for the byte swapping
36920 \begin_inset LatexCommand index
36921 name "Byte swapping"
36927 \begin_inset Quotes sld
36931 \begin_inset Quotes srd
36934 example can be used to convert from little to big-endian or vice versa.
36935 If you want to change the endianness of a
36939 integer you have to cast to
36946 \begin_layout Standard
36947 Note that SDCC stores numbers in little-endian
36951 \begin_layout Standard
36952 Usually 8-bit processors don't care much about endianness.
36953 This is not the case for the standard 8051 which only has an instruction
36959 \begin_inset LatexCommand index
36964 -datapointer so little-endian is the more efficient byte order.
36970 \begin_inset LatexCommand index
36971 name "little-endian"
36976 \begin_inset LatexCommand index
36982 lowest order first).
36985 \begin_layout Subsection
36987 \begin_inset LatexCommand index
36988 name "Highest Order Bit"
36993 \begin_inset LatexCommand index
36994 name "Any Order Bit"
37001 \begin_layout Standard
37002 It is frequently required to obtain the highest order bit of an integral
37003 type (long, int, short or char types).
37004 Also obtaining any other order bit is not uncommon.
37005 SDCC recognizes the following expressions to yield the highest order bit
37006 and generates optimized code for it, e.g.:
37009 \begin_layout Verse
37020 unsigned char hob1, aob1;
37024 bit hob2, hob3, aob2,
37034 hob1 = (gint >> 15) & 1;
37038 hob2 = (gint >> 15) & 1;
37042 hob3 = gint & 0x8000;
37047 aob1 = (gint >> 9) & 1;
37051 aob2 = (gint >> 8) & 1;
37055 aob3 = gint & 0x0800;
37065 \begin_layout Standard
37066 will generate the following code:
37069 \begin_layout Verse
37100 000A E5*01\InsetSpace ~
37127 000C 23\InsetSpace ~
37158 000D 54 01\InsetSpace ~
37186 000F F5*02\InsetSpace ~
37241 0011 E5*01\InsetSpace ~
37269 0013 33\InsetSpace ~
37299 0014 92*00\InsetSpace ~
37355 0016 E5*01\InsetSpace ~
37382 0018 33\InsetSpace ~
37412 0019 92*01\InsetSpace ~
37468 001B E5*01\InsetSpace ~
37527 001E 54 01\InsetSpace ~
37554 0020 F5*03\InsetSpace ~
37610 0022 E5*01\InsetSpace ~
37637 0024 13\InsetSpace ~
37667 0025 92*02\InsetSpace ~
37723 0027 E5*01\InsetSpace ~
37778 002B 92*03\InsetSpace ~
37806 \begin_layout Standard
37807 Other variations of these cases however will
37812 They are standard C expressions, so I heartily recommend these be the only
37813 way to get the highest order bit, (it is portable).
37814 Of course it will be recognized even if it is embedded in other expressions,
37818 \begin_layout Verse
37821 xyz = gint + ((gint >> 15) & 1);
37824 \begin_layout Standard
37825 will still be recognized.
37828 \begin_layout Subsection
37830 \begin_inset LatexCommand index
37831 name "Higher Order Byte"
37835 / Higher Order Word
37836 \begin_inset LatexCommand index
37837 name "Higher Order Word"
37844 \begin_layout Standard
37845 It is also frequently required to obtain a higher order byte or word of
37846 a larger integral type (long, int or short types).
37847 SDCC recognizes the following expressions to yield the higher order byte
37848 or word and generates optimized code for it, e.g.:
37851 \begin_layout Verse
37856 unsigned long int glong;
37864 unsigned char hob1,
37869 unsigned int how1, how2;
37878 hob1 = (gint >> 8) & 0xFF;
37882 hob2 = glong >> 24;
37886 how1 = (glong >> 16) & 0xFFFF;
37901 \begin_layout Standard
37902 will generate the following code:
37905 \begin_layout Verse
37936 0037 85*01*06\InsetSpace ~
37958 _foo_hob1_1_1,(_gint + 1)
37989 003A 85*05*07\InsetSpace ~
38011 _foo_hob2_1_1,(_glong + 3)
38041 003D 85*04*08\InsetSpace ~
38064 _foo_how1_1_1,(_glong + 2)
38066 0040 85*05*09\InsetSpace ~
38091 0043 85*03*0A\InsetSpace ~
38113 _foo_how2_1_1,(_glong + 1)
38115 0046 85*04*0B\InsetSpace ~
38138 (_foo_how2_1_1 + 1),(_glong + 2)
38141 \begin_layout Standard
38142 Again, variations of these cases may
38147 They are standard C expressions, so I heartily recommend these be the only
38148 way to get the higher order byte/word, (it is portable).
38149 Of course it will be recognized even if it is embedded in other expressions,
38153 \begin_layout Verse
38156 xyz = gint + ((gint >> 8) & 0xFF);
38159 \begin_layout Standard
38160 will still be recognized.
38163 \begin_layout Subsection
38165 \begin_inset LatexCommand label
38166 name "sub:Peephole-Optimizer"
38171 \begin_inset LatexCommand index
38172 name "Peephole optimizer"
38179 \begin_layout Standard
38180 The compiler uses a rule based, pattern matching and re-writing mechanism
38181 for peep-hole optimization.
38186 a peep-hole optimizer by Christopher W.
38187 Fraser (cwfraser\InsetSpace ~
38190 A default set of rules are compiled into the compiler, additional rules
38191 may be added with the
38197 \begin_layout Standard
38207 \begin_inset LatexCommand index
38208 name "-\\/-peep-file"
38215 The rule language is best illustrated with examples.
38218 \begin_layout Verse
38240 \begin_layout Standard
38241 The above rule will change the following assembly
38242 \begin_inset LatexCommand index
38243 name "Assembler routines"
38250 \begin_layout Verse
38258 \begin_layout Standard
38262 \begin_layout Verse
38268 \begin_layout Standard
38269 Note: All occurrences of a
38273 (pattern variable) must denote the same string.
38274 With the above rule, the assembly sequence:
38277 \begin_layout Verse
38285 \begin_layout Standard
38286 will remain unmodified.
38290 Other special case optimizations may be added by the
38297 \begin_layout Standard
38310 some variants of the 8051 MCU
38311 \begin_inset LatexCommand index
38312 name "MCS51 variants"
38325 The following two rules will change all
38342 \begin_layout Verse
38345 replace { lcall %1 } by { acall %1 }
38347 replace { ljmp %1 } by { ajmp %1 }
38350 \begin_layout Standard
38351 (NOTE: from version 2.7.3 on, you can use option -
38357 \begin_layout Standard
38369 \begin_inset LatexCommand index
38370 name "-\\/-acall-ajmp"
38374 , which also takes care of aligning the interrupt vectors properly.)
38379 \begin_layout Standard
38382 inline-assembler code
38384 is also passed through the peep hole optimizer, thus the peephole optimizer
38385 can also be used as an assembly level macro expander.
38386 The rules themselves are MCU dependent whereas the rule language infra-structur
38387 e is MCU independent.
38388 Peephole optimization rules for other MCU can be easily programmed using
38393 The syntax for a rule is as follows:
38396 \begin_layout Verse
38399 rule := replace [ restart ] '{' <assembly sequence> '
38437 <assembly sequence> '
38455 '}' [if <functionName> ] '
38460 \begin_layout Standard
38461 <assembly sequence> := assembly instruction (each instruction including
38462 labels must be on a separate line).
38466 The optimizer will apply to the rules
38467 one by one from the top in the sequence of their appearance, it will terminate
38468 when all rules are exhausted.
38469 If the 'restart' option is specified, then the optimizer will start matching
38470 the rules again from the top, this option for a rule is expensive (performance)
38471 , it is intended to be used in situations where a transformation will trigger
38472 the same rule again.
38473 An example of this (not a good one, it has side effects) is the following
38477 \begin_layout Verse
38497 \begin_layout Standard
38498 Note that the replace pattern cannot be a blank, but can be a comment line.
38499 Without the 'restart' option only the innermost 'pop' 'push' pair would
38500 be eliminated, i.e.:
38503 \begin_layout Verse
38515 \begin_layout Standard
38519 \begin_layout Verse
38529 \begin_layout Standard
38534 the restart option the rule will be applied again to the resulting code
38535 and then all the pop-push pairs will be eliminated to yield:
38538 \begin_layout Verse
38546 \begin_layout Standard
38547 A conditional function can be attached to a rule.
38548 Attaching rules are somewhat more involved, let me illustrate this with
38552 \begin_layout Verse
38576 \begin_layout Standard
38577 The optimizer does a look-up of a function name table defined in function
38582 in the source file SDCCpeeph.c, with the name
38587 If it finds a corresponding entry the function is called.
38588 Note there can be no parameters specified for these functions, in this
38593 is crucial, since the function
38597 expects to find the label in that particular variable (the hash table containin
38598 g the variable bindings is passed as a parameter).
38599 If you want to code more such functions, take a close look at the function
38600 labelInRange and the calling mechanism in source file SDCCpeeph.c.
38601 Currently implemented are
38603 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
38604 24bitMode, portIsDS390, 24bitModeAndPortDS390
38613 \begin_layout Standard
38614 I know this whole thing is a little kludgey, but maybe some day we will
38615 have some better means.
38616 If you are looking at this file, you will see the default rules that are
38617 compiled into the compiler, you can add your own rules in the default set
38618 there if you get tired of specifying the -
38622 \begin_layout Standard
38634 \begin_layout Section
38636 \begin_inset LatexCommand index
38637 name "ANSI-compliance"
38642 \begin_inset LatexCommand label
38643 name "sub:ANSI-Compliance"
38650 \begin_layout Standard
38651 The latest publicly available version of the standard
38653 ISO/IEC 9899 - Programming languages - C
38655 should be available at:
38656 \begin_inset LatexCommand url
38657 target "http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899"
38666 \begin_layout Standard
38667 Deviations from the compliance:
38670 \begin_layout Itemize
38671 functions are not reentrant
38672 \begin_inset LatexCommand index
38677 unless explicitly declared as such or the
38683 \begin_layout Standard
38693 \begin_inset LatexCommand index
38694 name "-\\/-stack-auto"
38700 command line option is specified.
38703 \begin_layout Itemize
38705 \begin_inset LatexCommand index
38711 \begin_inset LatexCommand index
38716 cannot be assigned values directly, cannot be passed as function parameters
38717 or assigned to each other and cannot be a return value
38718 \begin_inset LatexCommand index
38719 name "return value"
38723 from a function, e.g.:
38727 \begin_layout Verse
38750 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
38775 s parms) /* invalid in SDCC although allowed in ANSI */
38797 return rets; /* is invalid in SDCC although allowed in ANSI */
38803 \begin_layout Itemize
38804 initialization of structure arrays must be fully braced.
38808 \begin_layout Verse
38811 struct s { char x } a[] = {1, 2};\InsetSpace ~
38816 /* invalid in SDCC */
38819 } a[] = {{1}, {2}}; /* OK */
38823 \begin_layout Itemize
38825 \begin_inset LatexCommand index
38826 name "long long (not supported)"
38831 \begin_inset LatexCommand index
38832 name "int (64 bit) (not supported)"
38839 \begin_layout Itemize
38841 \begin_inset LatexCommand index
38842 name "double (not supported)"
38846 ' precision floating point
38847 \begin_inset LatexCommand index
38848 name "Floating point support"
38855 \begin_layout Itemize
38857 \begin_inset LatexCommand index
38862 function declarations are NOT allowed.
38866 \begin_layout Verse
38869 foo(i,j) /* this old style of function declarations */
38871 int i,j; /* is valid
38872 in ANSI but not valid in SDCC */
38887 \begin_layout Itemize
38888 Most enhancements in C99 are not supported, e.g.:
38892 \begin_layout Verse
38902 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
38906 \begin_layout Itemize
38907 But some have been added recently in SDCC 2.7.0.
38908 They must be considered alpha quality however.
38912 \begin_layout Verse
38917 \begin_inset LatexCommand index
38918 name "inline (not supported)"
38927 int increment (int a) { return a+1; } /* inlines the increment without function
38936 \begin_inset LatexCommand index
38937 name "inline (not supported)"
38946 p; /* accepted but ignored */
38950 \begin_layout Itemize
38951 Certain words that are valid identifiers in the standard may be reserved
38952 words in SDCC unless the
38958 \begin_layout Standard
38968 \begin_inset LatexCommand index
38969 name "-\\/-std-c89"
38981 \begin_layout Standard
38991 \begin_inset LatexCommand index
38992 name "-\\/-std-c99"
38998 command line options are used.
38999 These may include (depending on the selected processor): 'at', 'banked',
39000 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
39001 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
39002 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
39004 Compliant equivalents of these keywords are always available in a form
39005 that begin with two underscores
39006 \begin_inset LatexCommand index
39007 name "\\_\\_ (prefix for extended keywords)"
39012 '__data' instead of 'data'.
39015 \begin_layout Itemize
39016 Integer promotion of variable arguments is not performed if the argument
39017 is explicitly taypecasted unless the
39023 \begin_layout Standard
39033 \begin_inset LatexCommand index
39034 name "-\\/-std-c89"
39046 \begin_layout Standard
39056 \begin_inset LatexCommand index
39057 name "-\\/-std-c99"
39063 command line options are used.
39067 \begin_layout Verse
39070 void vararg_func (char *str, ...) { str; }
39087 u is promoted to int before
39092 * passing to function */
39096 vararg_func ("%c", c);
39103 argument u is not promoted to int,
39108 * it is passed as char to function
39114 --std-cXX is not defined;
39119 * is promoted to int before passing
39125 if --std-cXX is defined */
39129 vararg_func ("%bc", (char)u);
39135 \begin_layout Section
39136 Cyclomatic Complexity
39137 \begin_inset LatexCommand index
39138 name "Cyclomatic complexity"
39145 \begin_layout Standard
39146 Cyclomatic complexity of a function is defined as the number of independent
39147 paths the program can take during execution of the function.
39148 This is an important number since it defines the number test cases you
39149 have to generate to validate the function.
39150 The accepted industry standard for complexity number is 10, if the cyclomatic
39151 complexity reported by SDCC exceeds 10 you should think about simplification
39152 of the function logic.
39153 Note that the complexity level is not related to the number of lines of
39154 code in a function.
39155 Large functions can have low complexity, and small functions can have large
39161 SDCC uses the following formula to compute the complexity:
39166 \begin_layout Standard
39167 complexity = (number of edges in control flow graph) - (number of nodes
39168 in control flow graph) + 2;
39172 Having said that the industry standard is 10,
39173 you should be aware that in some cases it be may unavoidable to have a
39174 complexity level of less than 10.
39175 For example if you have switch statement with more than 10 case labels,
39176 each case label adds one to the complexity level.
39177 The complexity level is by no means an absolute measure of the algorithmic
39178 complexity of the function, it does however provide a good starting point
39179 for which functions you might look at for further optimization.
39182 \begin_layout Section
39183 Retargetting for other Processors
39186 \begin_layout Standard
39187 The issues for retargetting the compiler are far too numerous to be covered
39189 What follows is a brief description of each of the seven phases of the
39190 compiler and its MCU dependency.
39193 \begin_layout Itemize
39194 Parsing the source and building the annotated parse tree.
39195 This phase is largely MCU independent (except for the language extensions).
39196 Syntax & semantic checks are also done in this phase, along with some initial
39197 optimizations like back patching labels and the pattern matching optimizations
39198 like bit-rotation etc.
39201 \begin_layout Itemize
39202 The second phase involves generating an intermediate code which can be easy
39203 manipulated during the later phases.
39204 This phase is entirely MCU independent.
39205 The intermediate code generation assumes the target machine has unlimited
39206 number of registers, and designates them with the name iTemp.
39207 The compiler can be made to dump a human readable form of the code generated
39212 \begin_layout Standard
39224 \begin_layout Itemize
39225 This phase does the bulk of the standard optimizations and is also MCU independe
39227 This phase can be broken down into several sub-phases:
39231 Break down intermediate
39232 code (iCode) into basic blocks.
39234 Do control flow & data flow analysis on the
39237 Do local common subexpression elimination, then global subexpressio
39240 Dead code elimination
39244 If loop optimizations
39245 caused any changes then do 'global subexpression elimination' and 'dead
39246 code elimination' again.
39249 \begin_layout Itemize
39250 This phase determines the live-ranges; by live range I mean those iTemp
39251 variables defined by the compiler that still survive after all the optimization
39253 Live range analysis
39254 \begin_inset LatexCommand index
39255 name "Live range analysis"
39259 is essential for register allocation, since these computation determines
39260 which of these iTemps will be assigned to registers, and for how long.
39263 \begin_layout Itemize
39264 Phase five is register allocation.
39265 There are two parts to this process.
39269 The first part I call 'register packing'
39270 (for lack of a better term).
39271 In this case several MCU specific expression folding is done to reduce
39276 The second part is more MCU independent and deals with
39277 allocating registers to the remaining live ranges.
39278 A lot of MCU specific code does creep into this phase because of the limited
39279 number of index registers available in the 8051.
39282 \begin_layout Itemize
39283 The Code generation phase is (unhappily), entirely MCU dependent and very
39284 little (if any at all) of this code can be reused for other MCU.
39285 However the scheme for allocating a homogenized assembler operand for each
39286 iCode operand may be reused.
39289 \begin_layout Itemize
39290 As mentioned in the optimization section the peep-hole optimizer is rule
39291 based system, which can reprogrammed for other MCUs.
39294 \begin_layout Standard
39295 More information is available on SDCC Wiki
39296 \begin_inset LatexCommand index
39302 \begin_inset LatexCommand url
39303 target "http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting"
39307 ) and in the thread
39308 \begin_inset LatexCommand url
39309 target "http://sf.net/mailarchive/message.php?msg_id=13954144"
39316 \begin_layout Chapter
39318 \begin_inset LatexCommand index
39319 name "Compiler internals"
39326 \begin_layout Section
39327 The anatomy of the compiler
39328 \begin_inset LatexCommand label
39329 name "sub:The-anatomy-of"
39336 \begin_layout Standard
39339 This is an excerpt from an article published in Circuit Cellar Magazine
39348 It's a little outdated (the compiler is much more efficient now and user/develo
39349 per friendly), but pretty well exposes the guts of it all.
39355 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
39356 It is fairly easy to retarget for other 8-bit MCU.
39357 Here we take a look at some of the internals of the compiler.
39361 \begin_layout Paragraph*
39363 \begin_inset LatexCommand index
39371 \begin_layout Standard
39372 Parsing the input source file and creating an AST (Annotated Syntax Tree
39373 \begin_inset LatexCommand index
39374 name "Annotated syntax tree"
39379 This phase also involves propagating types (annotating each node of the
39380 parse tree with type information) and semantic analysis.
39381 There are some MCU specific parsing rules.
39382 For example the storage classes, the extended storage classes are MCU specific
39383 while there may be a xdata storage class for 8051 there is no such storage
39384 class for z80 or Atmel AVR.
39385 SDCC allows MCU specific storage class extensions, i.e.
39386 xdata will be treated as a storage class specifier when parsing 8051 C
39387 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
39391 \begin_layout Paragraph*
39393 \begin_inset LatexCommand index
39401 \begin_layout Standard
39402 Intermediate code generation.
39403 In this phase the AST is broken down into three-operand form (iCode).
39404 These three operand forms are represented as doubly linked lists.
39405 ICode is the term given to the intermediate form generated by the compiler.
39406 ICode example section shows some examples of iCode generated for some simple
39407 C source functions.
39410 \begin_layout Paragraph*
39412 \begin_inset LatexCommand index
39413 name "Optimizations"
39420 \begin_layout Standard
39421 Bulk of the target independent optimizations is performed in this phase.
39422 The optimizations include constant propagation, common sub-expression eliminati
39423 on, loop invariant code movement, strength reduction of loop induction variables
39424 and dead-code elimination.
39427 \begin_layout Paragraph*
39428 Live range analysis
39429 \begin_inset LatexCommand index
39430 name "Live range analysis"
39437 \begin_layout Standard
39438 During intermediate code generation phase, the compiler assumes the target
39439 machine has infinite number of registers and generates a lot of temporary
39441 The live range computation determines the lifetime of each of these compiler-ge
39442 nerated temporaries.
39443 A picture speaks a thousand words.
39444 ICode example sections show the live range annotations for each of the
39446 It is important to note here, each iCode is assigned a number in the order
39447 of its execution in the function.
39448 The live ranges are computed in terms of these numbers.
39449 The from number is the number of the iCode which first defines the operand
39450 and the to number signifies the iCode which uses this operand last.
39453 \begin_layout Paragraph*
39454 Register Allocation
39455 \begin_inset LatexCommand index
39456 name "Register allocation"
39463 \begin_layout Standard
39464 The register allocation determines the type and number of registers needed
39466 In most MCUs only a few registers can be used for indirect addressing.
39467 In case of 8051 for example the registers R0 & R1 can be used to indirectly
39468 address the internal ram and DPTR to indirectly address the external ram.
39469 The compiler will try to allocate the appropriate register to pointer variables
39471 ICode example section shows the operands annotated with the registers assigned
39473 The compiler will try to keep operands in registers as much as possible;
39474 there are several schemes the compiler uses to do achieve this.
39475 When the compiler runs out of registers the compiler will check to see
39476 if there are any live operands which is not used or defined in the current
39477 basic block being processed, if there are any found then it will push that
39478 operand and use the registers in this block, the operand will then be popped
39479 at the end of the basic block.
39483 \begin_layout Standard
39484 There are other MCU specific considerations in this phase.
39485 Some MCUs have an accumulator; very short-lived operands could be assigned
39486 to the accumulator instead of a general-purpose register.
39489 \begin_layout Paragraph*
39493 \begin_layout Standard
39494 Figure II gives a table of iCode
39495 \begin_inset LatexCommand index
39500 operations supported by the compiler.
39501 The code generation involves translating these operations into corresponding
39502 assembly code for the processor.
39503 This sounds overly simple but that is the essence of code generation.
39504 Some of the iCode operations are generated on a MCU specific manner for
39505 example, the z80 port does not use registers to pass parameters so the
39506 SEND and RECV iCode operations will not be generated, and it also does
39507 not support JUMPTABLES.
39513 \begin_layout Standard
39517 \begin_inset Tabular
39518 <lyxtabular version="3" rows="39" columns="4">
39519 <features islongtable="true" headBottomDL="true">
39520 <column alignment="block" valignment="top" leftline="true" width="13col%">
39521 <column alignment="left" valignment="top" leftline="true" width="13col%">
39522 <column alignment="block" valignment="top" leftline="true" width="22col%">
39523 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
39524 <row topline="true" bottomline="true" endhead="true">
39525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39528 \begin_layout Standard
39534 \begin_inset LatexCommand index
39544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39547 \begin_layout Standard
39555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39558 \begin_layout Standard
39566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39569 \begin_layout Standard
39578 <row topline="true">
39579 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39582 \begin_layout Standard
39590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39593 \begin_layout Standard
39596 IC_LEFT() IC_RESULT()
39601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39604 \begin_layout Standard
39612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39615 \begin_layout Standard
39618 IC_RESULT = ! IC_LEFT;
39624 <row topline="true">
39625 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39628 \begin_layout Standard
39636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39639 \begin_layout Standard
39642 IC_LEFT() IC_RESULT()
39647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39650 \begin_layout Standard
39653 Bitwise complement of
39658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39661 \begin_layout Standard
39664 IC_RESULT = ~IC_LEFT;
39670 <row topline="true">
39671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39674 \begin_layout Standard
39682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39685 \begin_layout Standard
39688 IC_LEFT() IC_RESULT()
39693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39696 \begin_layout Standard
39699 Rotate right with carry
39704 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39707 \begin_layout Standard
39710 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
39716 <row topline="true">
39717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39720 \begin_layout Standard
39728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39731 \begin_layout Standard
39734 IC_LEFT() IC_RESULT()
39739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39742 \begin_layout Standard
39745 Rotate left with carry
39750 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39753 \begin_layout Standard
39756 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
39762 <row topline="true">
39763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39766 \begin_layout Standard
39774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39777 \begin_layout Standard
39780 IC_LEFT() IC_RESULT()
39785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39788 \begin_layout Standard
39791 Get the highest order bit of IC_LEFT
39796 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39799 \begin_layout Standard
39802 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
39808 <row topline="true">
39809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39812 \begin_layout Standard
39820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39823 \begin_layout Standard
39826 IC_LEFT() IC_RESULT()
39831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39834 \begin_layout Standard
39842 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39845 \begin_layout Standard
39848 IC_RESULT = - IC_LEFT;
39854 <row topline="true">
39855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39858 \begin_layout Standard
39866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39869 \begin_layout Standard
39877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39880 \begin_layout Standard
39883 Push the operand into stack
39888 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39891 \begin_layout Standard
39900 <row topline="true">
39901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39904 \begin_layout Standard
39912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39915 \begin_layout Standard
39923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39926 \begin_layout Standard
39929 Pop the operand from the stack
39934 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39937 \begin_layout Standard
39946 <row topline="true">
39947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39950 \begin_layout Standard
39958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39961 \begin_layout Standard
39964 IC_LEFT() IC_RESULT()
39969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39972 \begin_layout Standard
39975 Call the function represented by IC_LEFT
39980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39983 \begin_layout Standard
39986 IC_RESULT = IC_LEFT();
39992 <row topline="true">
39993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39996 \begin_layout Standard
40004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40007 \begin_layout Standard
40010 IC_LEFT() IC_RESULT()
40015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40018 \begin_layout Standard
40021 Call via function pointer
40026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40029 \begin_layout Standard
40032 IC_RESULT = (*IC_LEFT)();
40038 <row topline="true">
40039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40042 \begin_layout Standard
40050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40053 \begin_layout Standard
40061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40064 \begin_layout Standard
40067 Return the value in operand IC_LEFT
40072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40075 \begin_layout Standard
40084 <row topline="true">
40085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40088 \begin_layout Standard
40096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40099 \begin_layout Standard
40107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40110 \begin_layout Standard
40118 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40121 \begin_layout Standard
40130 <row topline="true">
40131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40134 \begin_layout Standard
40142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40145 \begin_layout Standard
40153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40156 \begin_layout Standard
40164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40167 \begin_layout Standard
40176 <row topline="true">
40177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40180 \begin_layout Standard
40188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40191 \begin_layout Standard
40194 IC_LEFT() IC_RIGHT() IC_RESULT()
40199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40202 \begin_layout Standard
40210 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40213 \begin_layout Standard
40216 IC_RESULT = IC_LEFT + IC_RIGHT
40222 <row topline="true">
40223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40226 \begin_layout Standard
40234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40237 \begin_layout Standard
40240 IC_LEFT() IC_RIGHT() IC_RESULT()
40245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40248 \begin_layout Standard
40256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40259 \begin_layout Standard
40262 IC_RESULT = IC_LEFT - IC_RIGHT
40268 <row topline="true">
40269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40272 \begin_layout Standard
40280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40283 \begin_layout Standard
40286 IC_LEFT() IC_RIGHT() IC_RESULT()
40291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40294 \begin_layout Standard
40302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40305 \begin_layout Standard
40308 IC_RESULT = IC_LEFT * IC_RIGHT;
40314 <row topline="true">
40315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40318 \begin_layout Standard
40326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40329 \begin_layout Standard
40332 IC_LEFT() IC_RIGHT() IC_RESULT()
40337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40340 \begin_layout Standard
40348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40351 \begin_layout Standard
40354 IC_RESULT = IC_LEFT / IC_RIGHT;
40360 <row topline="true">
40361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40364 \begin_layout Standard
40372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40375 \begin_layout Standard
40378 IC_LEFT() IC_RIGHT() IC_RESULT()
40383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40386 \begin_layout Standard
40394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40397 \begin_layout Standard
40400 IC_RESULT = IC_LEFT % IC_RIGHT;
40406 <row topline="true">
40407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40410 \begin_layout Standard
40418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40421 \begin_layout Standard
40424 IC_LEFT() IC_RIGHT() IC_RESULT()
40429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40432 \begin_layout Standard
40440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40443 \begin_layout Standard
40446 IC_RESULT = IC_LEFT < IC_RIGHT;
40452 <row topline="true">
40453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40456 \begin_layout Standard
40464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40467 \begin_layout Standard
40470 IC_LEFT() IC_RIGHT() IC_RESULT()
40475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40478 \begin_layout Standard
40486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40489 \begin_layout Standard
40492 IC_RESULT = IC_LEFT > IC_RIGHT;
40498 <row topline="true">
40499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40502 \begin_layout Standard
40510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40513 \begin_layout Standard
40516 IC_LEFT() IC_RIGHT() IC_RESULT()
40521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40524 \begin_layout Standard
40532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40535 \begin_layout Standard
40538 IC_RESULT = IC_LEFT == IC_RIGHT;
40544 <row topline="true">
40545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40548 \begin_layout Standard
40556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40559 \begin_layout Standard
40562 IC_LEFT() IC_RIGHT() IC_RESULT()
40567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40570 \begin_layout Standard
40573 Logical and operation
40578 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40581 \begin_layout Standard
40584 IC_RESULT = IC_LEFT && IC_RIGHT;
40590 <row topline="true">
40591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40594 \begin_layout Standard
40602 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40605 \begin_layout Standard
40608 IC_LEFT() IC_RIGHT() IC_RESULT()
40613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40616 \begin_layout Standard
40619 Logical or operation
40624 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40627 \begin_layout Standard
40630 IC_RESULT = IC_LEFT || IC_RIGHT;
40636 <row topline="true">
40637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40640 \begin_layout Standard
40648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40651 \begin_layout Standard
40654 IC_LEFT() IC_RIGHT() IC_RESULT()
40659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40662 \begin_layout Standard
40670 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40673 \begin_layout Standard
40676 IC_RESULT = IC_LEFT ^ IC_RIGHT;
40682 <row topline="true">
40683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40686 \begin_layout Standard
40694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40697 \begin_layout Standard
40700 IC_LEFT() IC_RIGHT() IC_RESULT()
40705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40708 \begin_layout Standard
40716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40719 \begin_layout Standard
40722 IC_RESULT = IC_LEFT | IC_RIGHT;
40728 <row topline="true">
40729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40732 \begin_layout Standard
40740 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40743 \begin_layout Standard
40746 IC_LEFT() IC_RIGHT() IC_RESULT()
40751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40754 \begin_layout Standard
40762 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40765 \begin_layout Standard
40768 IC_RESULT = IC_LEFT & IC_RIGHT;
40774 <row topline="true">
40775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40778 \begin_layout Standard
40786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40789 \begin_layout Standard
40792 IC_LEFT() IC_RIGHT() IC_RESULT()
40797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40800 \begin_layout Standard
40808 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40811 \begin_layout Standard
40814 IC_RESULT = IC_LEFT << IC_RIGHT
40820 <row topline="true">
40821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40824 \begin_layout Standard
40832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40835 \begin_layout Standard
40838 IC_LEFT() IC_RIGHT() IC_RESULT()
40843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40846 \begin_layout Standard
40854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40857 \begin_layout Standard
40860 IC_RESULT = IC_LEFT >> IC_RIGHT
40866 <row topline="true">
40867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40870 \begin_layout Standard
40880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40883 \begin_layout Standard
40886 IC_LEFT() IC_RESULT()
40891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40894 \begin_layout Standard
40902 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40905 \begin_layout Standard
40908 IC_RESULT = (*IC_LEFT);
40914 <row topline="true">
40915 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40918 \begin_layout Standard
40926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40929 \begin_layout Standard
40932 IC_RIGHT() IC_RESULT()
40937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40940 \begin_layout Standard
40948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40951 \begin_layout Standard
40954 (*IC_RESULT) = IC_RIGHT;
40960 <row topline="true">
40961 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40964 \begin_layout Standard
40972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40975 \begin_layout Standard
40978 IC_RIGHT() IC_RESULT()
40983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40986 \begin_layout Standard
40994 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40997 \begin_layout Standard
41000 IC_RESULT = IC_RIGHT;
41006 <row topline="true">
41007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41010 \begin_layout Standard
41018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41021 \begin_layout Standard
41024 IC_COND IC_TRUE IC_LABEL
41029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41032 \begin_layout Standard
41036 If true label is present then jump to true label if condition is true else
41037 jump to false label if condition is false
41042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41045 \begin_layout Standard
41048 if (IC_COND) goto IC_TRUE;
41054 If (!IC_COND) goto IC_FALSE;
41060 <row topline="true">
41061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41064 \begin_layout Standard
41072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41075 \begin_layout Standard
41078 IC_LEFT() IC_RESULT()
41083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41086 \begin_layout Standard
41094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41097 \begin_layout Standard
41100 IC_RESULT = &IC_LEFT();
41106 <row topline="true">
41107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41110 \begin_layout Standard
41118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41121 \begin_layout Standard
41124 IC_JTCOND IC_JTLABELS
41129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41132 \begin_layout Standard
41135 Jump to list of labels depending on the value of JTCOND
41140 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41143 \begin_layout Standard
41152 <row topline="true">
41153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41156 \begin_layout Standard
41164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41167 \begin_layout Standard
41170 IC_RIGHT() IC_LEFT() IC_RESULT()
41175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41178 \begin_layout Standard
41186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41189 \begin_layout Standard
41192 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
41198 <row topline="true">
41199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41202 \begin_layout Standard
41210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41213 \begin_layout Standard
41221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41224 \begin_layout Standard
41227 This is used for passing parameters in registers;
41229 move IC_LEFT to the next
41230 available parameter register.
41235 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41238 \begin_layout Standard
41247 <row topline="true">
41248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41251 \begin_layout Standard
41259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41262 \begin_layout Standard
41270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41273 \begin_layout Standard
41276 This is used for receiving parameters passed in registers;
41279 in the next parameter register to IC_RESULT
41284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41287 \begin_layout Standard
41296 <row topline="true" bottomline="true">
41297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41300 \begin_layout Standard
41304 (some more have been added)
41309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41312 \begin_layout Standard
41318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41321 \begin_layout Standard
41327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41330 \begin_layout Standard
41363 \begin_layout Standard
41364 \begin_inset Note Note
41367 \begin_layout Standard
41368 In the original article Figure II was announced to be downloadable on
41373 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
41381 \begin_layout Paragraph*
41383 \begin_inset LatexCommand index
41391 \begin_layout Standard
41392 This section shows some details of iCode.
41393 The example C code does not do anything useful; it is used as an example
41394 to illustrate the intermediate code generated by the compiler.
41397 \begin_layout Verse
41407 /* This function does nothing useful.
41414 for the purpose of explaining iCode */
41417 short function (data
41426 short i=10; \InsetSpace ~
41428 /* dead initialization eliminated */
41434 /* dead initialization eliminated */
41462 /* compiler detects i,j to be induction
41467 for (i = 0, j = 10 ; i < 10 ; i++, j
41473 \begin_layout Standard
41496 mul += i * 3; \InsetSpace ~
41498 /* this multiplication remains */
41505 j * 3;\InsetSpace ~
41507 /* this multiplication changed to addition */
41521 \begin_layout Standard
41522 In addition to the operands each iCode contains information about the filename
41523 and line it corresponds to in the source file.
41524 The first field in the listing should be interpreted as follows:
41529 Filename(linenumber: iCode Execution sequence number : ICode hash table
41530 key : loop depth of the iCode).
41535 Then follows the human readable form of the ICode operation.
41536 Each operand of this triplet form can be of three basic types a) compiler
41537 generated temporary b) user defined variable c) a constant value.
41538 Note that local variables and parameters are replaced by compiler generated
41541 \begin_inset LatexCommand index
41542 name "Live range analysis"
41546 are computed only for temporaries (i.e.
41547 live ranges are not computed for global variables).
41549 \begin_inset LatexCommand index
41550 name "Register allocation"
41554 are allocated for temporaries only.
41555 Operands are formatted in the following manner:
41560 Operand Name [lr live-from : live-to ] { type information } [ registers
41566 As mentioned earlier the live ranges are computed in terms of the execution
41567 sequence number of the iCodes, for example
41569 the iTemp0 is live from (i.e.
41570 first defined in iCode with execution sequence number 3, and is last used
41571 in the iCode with sequence number 5).
41572 For induction variables such as iTemp21 the live range computation extends
41573 the lifetime from the start to the end of the loop.
41575 The register allocator
41576 used the live range information to allocate registers, the same registers
41577 may be used for different temporaries if their live ranges do not overlap,
41578 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
41579 ranges do not overlap.
41580 In addition the allocator also takes into consideration the type and usage
41581 of a temporary, for example itemp6 is a pointer to near space and is used
41582 as to fetch data from (i.e.
41583 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
41584 Some short lived temporaries are allocated to special registers which have
41585 meaning to the code generator e.g.
41586 iTemp13 is allocated to a pseudo register CC which tells the back end that
41587 the temporary is used only for a conditional jump the code generation makes
41588 use of this information to optimize a compare and jump ICode.
41592 \begin_inset LatexCommand index
41593 name "Loop optimization"
41597 performed by the compiler.
41598 It can detect induction variables iTemp21(i) and iTemp23(j).
41599 Also note the compiler does selective strength reduction
41600 \begin_inset LatexCommand index
41601 name "Strength reduction"
41606 the multiplication of an induction variable in line 18 (gint = j * 3) is
41607 changed to addition, a new temporary iTemp17 is allocated and assigned
41608 a initial value, a constant 3 is then added for each iteration of the loop.
41609 The compiler does not change the multiplication
41610 \begin_inset LatexCommand index
41611 name "Multiplication"
41615 in line 17 however since the processor does support an 8 * 8 bit multiplication.
41618 Note the dead code elimination
41619 \begin_inset LatexCommand index
41620 name "Dead-code elimination"
41624 optimization eliminated the dead assignments in line 7 & 8 to I and sum
41630 \begin_layout Standard
41633 Sample.c (5:1:0:0) _entry($9) :
41636 \begin_layout Standard
41639 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
41642 \begin_layout Standard
41645 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
41648 \begin_layout Standard
41651 Sample.c(11:4:53:0) preHeaderLbl0($11) :
41654 \begin_layout Standard
41657 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
41661 \begin_layout Standard
41664 Sample.c(11:6:5:1) _whilecontinue_0($1) :
41667 \begin_layout Standard
41670 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
41674 \begin_layout Standard
41677 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
41680 \begin_layout Standard
41683 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
41687 \begin_layout Standard
41690 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
41694 \begin_layout Standard
41697 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
41701 \begin_layout Standard
41704 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
41708 \begin_layout Standard
41711 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
41712 * int}[r0] + 0x2 {short}
41715 \begin_layout Standard
41718 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
41721 \begin_layout Standard
41724 Sample.c(11:17:21:0)_whilebreak_0($3) :
41727 \begin_layout Standard
41730 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
41733 \begin_layout Standard
41736 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
41739 \begin_layout Standard
41742 Sample.c(15:20:54:0)preHeaderLbl1($13) :
41745 \begin_layout Standard
41748 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
41751 \begin_layout Standard
41754 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
41757 \begin_layout Standard
41760 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
41763 \begin_layout Standard
41766 Sample.c(15:24:26:1)_forcond_0($4) :
41769 \begin_layout Standard
41772 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
41776 \begin_layout Standard
41779 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
41782 \begin_layout Standard
41785 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
41786 + ITemp21 [lr21:38]{short}[r4]
41789 \begin_layout Standard
41792 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
41796 \begin_layout Standard
41799 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
41800 + iTemp15 [lr29:30]{short}[r1]
41803 \begin_layout Standard
41806 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
41810 \begin_layout Standard
41813 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
41817 \begin_layout Standard
41820 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
41824 \begin_layout Standard
41827 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
41831 \begin_layout Standard
41834 Sample.c(19:38:47:1) goto _forcond_0($4)
41837 \begin_layout Standard
41840 Sample.c(19:39:48:0)_forbreak_0($7) :
41843 \begin_layout Standard
41846 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
41847 + ITemp11 [lr19:40]{short}[r3]
41850 \begin_layout Standard
41853 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
41856 \begin_layout Standard
41859 Sample.c(20:42:51:0)_return($8) :
41862 \begin_layout Standard
41865 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
41871 Finally the code generated for this function:
41876 \begin_layout Standard
41882 \begin_layout Standard
41888 \begin_layout Standard
41896 \begin_layout Standard
41902 \begin_layout Standard
41910 \begin_layout Standard
41916 \begin_layout Standard
41919 ; ----------------------------------------------
41922 \begin_layout Standard
41925 ; function function
41928 \begin_layout Standard
41931 ; ----------------------------------------------
41934 \begin_layout Standard
41940 \begin_layout Standard
41943 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
41946 \begin_layout Standard
41954 \begin_layout Standard
41957 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
41960 \begin_layout Standard
41968 \begin_layout Standard
41971 ;_whilecontinue_0($1) :
41974 \begin_layout Standard
41980 \begin_layout Standard
41983 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
41986 \begin_layout Standard
41989 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
41992 \begin_layout Standard
42000 \begin_layout Standard
42008 \begin_layout Standard
42016 \begin_layout Standard
42024 \begin_layout Standard
42032 \begin_layout Standard
42040 \begin_layout Standard
42048 \begin_layout Standard
42054 \begin_layout Standard
42057 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
42060 \begin_layout Standard
42068 \begin_layout Standard
42076 \begin_layout Standard
42079 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
42082 \begin_layout Standard
42090 \begin_layout Standard
42098 \begin_layout Standard
42106 \begin_layout Standard
42114 \begin_layout Standard
42122 \begin_layout Standard
42130 \begin_layout Standard
42133 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
42136 \begin_layout Standard
42144 \begin_layout Standard
42152 \begin_layout Standard
42160 \begin_layout Standard
42168 \begin_layout Standard
42176 \begin_layout Standard
42179 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
42182 \begin_layout Standard
42190 \begin_layout Standard
42198 \begin_layout Standard
42206 \begin_layout Standard
42209 ; iTemp6 [lr5:16]{_near * int}[r0] =
42212 \begin_layout Standard
42215 ; iTemp6 [lr5:16]{_near * int}[r0] +
42218 \begin_layout Standard
42224 \begin_layout Standard
42232 \begin_layout Standard
42235 ; goto _whilecontinue_0($1)
42238 \begin_layout Standard
42246 \begin_layout Standard
42249 ; _whilebreak_0($3) :
42252 \begin_layout Standard
42258 \begin_layout Standard
42261 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
42264 \begin_layout Standard
42272 \begin_layout Standard
42275 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
42278 \begin_layout Standard
42286 \begin_layout Standard
42289 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
42292 \begin_layout Standard
42300 \begin_layout Standard
42303 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
42306 \begin_layout Standard
42314 \begin_layout Standard
42322 \begin_layout Standard
42325 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
42328 \begin_layout Standard
42336 \begin_layout Standard
42344 \begin_layout Standard
42350 \begin_layout Standard
42356 \begin_layout Standard
42359 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
42362 \begin_layout Standard
42365 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
42368 \begin_layout Standard
42376 \begin_layout Standard
42384 \begin_layout Standard
42392 \begin_layout Standard
42400 \begin_layout Standard
42408 \begin_layout Standard
42414 \begin_layout Standard
42417 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
42420 \begin_layout Standard
42423 ; iTemp21 [lr21:38]{short}[r4]
42426 \begin_layout Standard
42434 \begin_layout Standard
42442 \begin_layout Standard
42450 \begin_layout Standard
42453 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
42456 \begin_layout Standard
42464 \begin_layout Standard
42472 \begin_layout Standard
42480 \begin_layout Standard
42488 \begin_layout Standard
42491 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
42494 \begin_layout Standard
42497 ; iTemp15 [lr29:30]{short}[r1]
42500 \begin_layout Standard
42508 \begin_layout Standard
42516 \begin_layout Standard
42519 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
42522 \begin_layout Standard
42530 \begin_layout Standard
42538 \begin_layout Standard
42546 \begin_layout Standard
42554 \begin_layout Standard
42562 \begin_layout Standard
42570 \begin_layout Standard
42573 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
42576 \begin_layout Standard
42584 \begin_layout Standard
42592 \begin_layout Standard
42600 \begin_layout Standard
42608 \begin_layout Standard
42616 \begin_layout Standard
42624 \begin_layout Standard
42627 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
42630 \begin_layout Standard
42638 \begin_layout Standard
42641 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
42644 \begin_layout Standard
42652 \begin_layout Standard
42657 cjne r5,#0xff,00104$
42660 \begin_layout Standard
42668 \begin_layout Standard
42671 ; goto _forcond_0($4)
42674 \begin_layout Standard
42682 \begin_layout Standard
42685 ; _forbreak_0($7) :
42688 \begin_layout Standard
42694 \begin_layout Standard
42697 ; ret iTemp24 [lr40:41]{short}
42700 \begin_layout Standard
42708 \begin_layout Standard
42716 \begin_layout Standard
42724 \begin_layout Standard
42730 \begin_layout Standard
42736 \begin_layout Standard
42746 \begin_layout Section
42747 A few words about basic block successors, predecessors and dominators
42750 \begin_layout Standard
42751 Successors are basic blocks
42752 \begin_inset LatexCommand index
42753 name "Basic blocks"
42757 that might execute after this basic block.
42759 Predecessors are basic blocks
42760 that might execute before reaching this basic block.
42762 Dominators are basic
42763 blocks that WILL execute before reaching this basic block.
42768 \begin_layout Standard
42772 \begin_layout Standard
42776 \begin_layout Standard
42784 \begin_layout Standard
42788 \begin_layout Standard
42796 \begin_layout Standard
42802 \begin_layout Standard
42803 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
42806 \begin_layout Standard
42807 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
42810 \begin_layout Standard
42811 c) domVect of [BB4] = BB1 ...
42812 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
42816 \begin_layout Chapter
42820 \begin_layout Standard
42821 \begin_inset LatexCommand url
42822 target "http://sdcc.sourceforge.net/#Who"
42832 Thanks to all the other volunteer developers who have helped with coding,
42833 testing, web-page creation, distribution sets, etc.
42834 You know who you are :-)
42842 Thanks to Sourceforge
42843 \begin_inset LatexCommand url
42844 target "http://www.sf.net"
42848 which has hosted the project since 1999 and donates significant download
42857 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
42858 cycles and bandwidth for snapshot builds.
42863 \begin_layout Standard
42864 This document was initially written by Sandeep Dutta
42867 \begin_layout Standard
42868 All product names mentioned herein may be trademarks
42869 \begin_inset LatexCommand index
42874 of their respective companies.
42878 \begin_layout Section*
42882 \begin_layout Standard
42883 To avoid confusion, the installation and building options for SDCC itself
42884 (chapter 2) are not part of the index.
42887 \begin_layout Standard
42888 \begin_inset LatexCommand printindex