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
121 $Date:: 2009-03-13 #$
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\\_STACK\\_TENBIT"
24311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24314 \begin_layout Standard
24325 <row topline="true">
24326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24329 \begin_layout Standard
24331 \begin_inset LatexCommand index
24332 name "SDCC\\_MODEL\\_FLAT24"
24341 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24344 \begin_layout Standard
24355 <row topline="true">
24356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24359 \begin_layout Standard
24361 \begin_inset LatexCommand index
24362 name "SDCC\\_REVISION"
24371 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24374 \begin_layout Standard
24376 SDCC svn revision number
24382 <row topline="true">
24383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24386 \begin_layout Standard
24387 SDCC_PARMS_IN_BANK1
24388 \begin_inset LatexCommand index
24389 name "SDCC\\_PARMS\\_IN\\_BANK1"
24398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24401 \begin_layout Standard
24408 \begin_layout Standard
24425 <row topline="true">
24426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24429 \begin_layout Standard
24431 \begin_inset LatexCommand index
24432 name "SDCC\\_MODEL\\_FLAT24"
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" bottomline="true">
24469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24472 \begin_layout Standard
24473 SDCC_INT_LONG_REENT
24474 \begin_inset LatexCommand index
24475 name "SDCC\\_INT\\_LONG\\_REENT"
24484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24487 \begin_layout Standard
24494 \begin_layout Standard
24518 \begin_layout Chapter
24519 Notes on supported Processors
24522 \begin_layout Section
24524 \begin_inset LatexCommand label
24525 name "sub:MCS51-variants"
24530 \begin_inset LatexCommand index
24531 name "MCS51 variants"
24538 \begin_layout Standard
24539 MCS51 processors are available from many vendors and come in many different
24541 While they might differ considerably in respect to Special Function Registers
24542 the core MCS51 is usually not modified or is kept compatible.
24546 \begin_layout Subsection
24547 pdata access by SFR
24550 \begin_layout Standard
24551 With the upcome of devices with internal xdata and flash memory devices
24553 \begin_inset LatexCommand index
24554 name "P2 (mcs51 sfr)"
24558 as dedicated I/O port is becoming more popular.
24559 Switching the high byte for pdata
24560 \begin_inset LatexCommand index
24561 name "pdata (mcs51, ds390 storage class)"
24565 access which was formerly done by port P2 is then achieved by a Special
24567 \begin_inset LatexCommand index
24573 In well-established MCS51 tradition the address of this
24577 is where the chip designers decided to put it.
24578 Needless to say that they didn't agree on a common name either.
24579 So that the startup code can correctly initialize xdata variables, you
24580 should define an sfr with the name _XPAGE
24583 \begin_inset LatexCommand index
24584 name "\\_XPAGE (mcs51)"
24590 at the appropriate location if the default, port P2, is not used for this.
24594 \begin_layout Verse
24597 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
24601 \begin_layout Verse
24604 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
24609 \begin_layout Verse
24612 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
24616 \begin_layout Verse
24619 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
24623 \begin_layout Verse
24626 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
24630 \begin_layout Standard
24631 For more exotic implementations further customizations may be needed.
24633 \begin_inset LatexCommand ref
24634 reference "sub:Startup-Code"
24638 for other possibilities.
24641 \begin_layout Subsection
24642 Other Features available by SFR
24645 \begin_layout Standard
24646 Some MCS51 variants offer features like Double DPTR
24647 \begin_inset LatexCommand index
24652 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
24653 These are currently not used for the MCS51 port.
24654 If you absolutely need them you can fall back to inline assembly or submit
24658 \begin_layout Subsection
24662 \begin_layout Standard
24664 \begin_inset LatexCommand index
24665 name "Bankswitching"
24671 \begin_inset LatexCommand index
24672 name "code banking"
24676 ) is a technique to increase the code space above the 64k limit of the 8051.
24679 \begin_layout Subsubsection
24683 \begin_layout Standard
24684 \begin_inset Tabular
24685 <lyxtabular version="3" rows="3" columns="4">
24687 <column alignment="center" valignment="top" width="0">
24688 <column alignment="center" valignment="top" leftline="true" width="0">
24689 <column alignment="center" valignment="top" leftline="true" width="0">
24690 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24691 <row topline="true" bottomline="true">
24692 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24695 \begin_layout Standard
24701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24704 \begin_layout Standard
24710 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24713 \begin_layout Standard
24719 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24722 \begin_layout Standard
24729 <row topline="true" bottomline="true">
24730 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24733 \begin_layout Standard
24739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24742 \begin_layout Standard
24748 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24751 \begin_layout Standard
24757 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24760 \begin_layout Standard
24768 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24771 \begin_layout Standard
24772 SiLabs C8051F120 example
24777 <cell multicolumn="2" alignment="center" valignment="top" usebox="none">
24780 \begin_layout Standard
24786 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24789 \begin_layout Standard
24795 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24798 \begin_layout Standard
24813 Usually the hardware uses some sfr (an output port or an internal sfr) to
24814 select a bank and put it in the banked area of the memory map.
24815 The selected bank usually becomes active immediately upon assignment to
24816 this sfr and when running inside a bank it will switch out this code it
24817 is currently running.
24818 Therefor you cannot jump or call directly from one bank to another and
24819 need to use a so-called trampoline in the common area.
24820 For SDCC an example trampoline is in crtbank.asm and you may need to change
24821 it to your 8051 derivative or schematic.
24822 The presented code is written for the C8051F120.
24826 When calling a banked function
24827 SDCC will put the LSB of the functions address in register R0, the MSB
24828 in R1 and the bank in R2 and then call this trampoline
24833 The current selected bank is saved on the stack, the new bank is selected
24834 and an indirect jump is made.
24835 When the banked function returns it jumps to
24839 which restores the previous bank and returns to the caller.
24842 \begin_layout Subsubsection
24846 \begin_layout Standard
24847 When writing banked software using SDCC you need to use some special keywords
24849 You also need to take over a bit of work from the linker.
24853 To create a function
24854 that can be called from another bank it requires the keyword
24859 \begin_inset LatexCommand index
24865 The caller must see this in the prototype of the callee and the callee
24866 needs it for a proper return.
24867 Called functions within the same bank as the caller do not need the
24871 keyword nor do functions in the common area.
24872 Beware: SDCC does not know or check if functions are in the same bank.
24873 This is your responsibility!
24877 Normally all functions you write end up in
24879 If you want a function explicitly to reside in the common area put it in
24881 This applies for instance to interrupt service routines as they should
24885 \begin_layout Standard
24886 Functions that need to be in a switched bank must be put in a named segment.
24887 The name can be mostly anything up to eight characters (e.g.
24889 To do this you either use -
24893 \begin_layout Standard
24902 -codeseg BANK1 (See
24903 \begin_inset LatexCommand ref
24904 reference "lyx:-codeseg"
24908 ) on the command line when compiling or #pragma codeseg BANK1 (See
24909 \begin_inset LatexCommand ref
24910 reference "sec:Pragmas"
24914 ) at the top of the C source file.
24915 The segment name always applies to the whole source file and generated
24916 object so functions for different banks need to be defined in different
24921 When linking your objects you need to tell the linker where
24922 to put your segments.
24923 To do this you use the following command line option to SDCC: -Wl-b BANK1=0x180
24925 \begin_inset LatexCommand ref
24926 reference "lyx:-Wl option"
24931 This sets the virtual start address of this segment.
24932 It sets the banknumber to 0x01 and maps the bank to 0x8000 and up.
24933 The linker will not check for overflows, again this is your responsibility.
24936 \begin_layout Standard
24937 \begin_inset VSpace bigskip
24943 \begin_layout Section
24947 \begin_layout Standard
24949 \begin_inset LatexCommand index
24955 \begin_inset LatexCommand index
24960 microcontroller has a rich set of peripherals.
24961 In its built-in ROM library it includes functions to access some of the
24962 features, among them is a TCP stack with IP4 and IP6 support.
24963 Library headers (currently in beta status) and other files are provided
24967 \begin_inset LatexCommand url
24968 target "ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html"
24974 \begin_inset VSpace bigskip
24980 \begin_layout Section
24981 The Z80 and gbz80 port
24984 \begin_layout Standard
24985 SDCC can target both the Zilog Z80
24986 \begin_inset LatexCommand index
24991 and the Nintendo Gameboy's Z80-like gbz80
24992 \begin_inset LatexCommand index
24993 name "gbz80 (GameBoy Z80)"
24998 The Z80 port is passed through the same
25001 \begin_inset LatexCommand index
25002 name "Regression test"
25009 \begin_inset LatexCommand ref
25010 reference "sec:Quality-control"
25014 ) as the MCS51 and DS390 ports, so floating point support, support for long
25015 variables and bitfield support is fine.
25016 See mailing lists and forums about interrupt routines.
25019 \begin_layout Standard
25020 As always, the code is the authoritative reference - see z80/ralloc.c and
25023 \begin_inset LatexCommand index
25028 frame is similar to that generated by the IAR Z80 compiler.
25029 IX is used as the base pointer, HL and IY are used as a temporary registers,
25030 and BC and DE are available for holding variables.
25032 \begin_inset LatexCommand index
25033 name "Z80!return value"
25037 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
25039 The gbz80 port use the same set of registers for the return values, but
25040 in a different order of significance: E (one byte), DE (two bytes), or
25042 \begin_inset VSpace bigskip
25048 \begin_layout Section
25052 \begin_layout Standard
25053 The port to the Freescale/Motorola HC08
25054 \begin_inset LatexCommand index
25059 family has been added in October 2003, and is still undergoing some basic
25061 The code generator is complete, but the register allocation is still quite
25063 Some of the SDCC's standard C library functions have embedded non-HC08
25064 inline assembly and so are not yet usable.
25067 \begin_layout Standard
25068 The HC08 port passes the regression test suite (see section
25069 \begin_inset LatexCommand ref
25070 reference "sec:Quality-control"
25075 \begin_inset VSpace bigskip
25081 \begin_layout Section
25083 \begin_inset LatexCommand index
25091 \begin_layout Standard
25092 The PIC14 port adds support for Microchip
25093 \begin_inset LatexCommand index
25099 \begin_inset Formula $^{\text{TM}}$
25103 \begin_inset LatexCommand index
25109 \begin_inset Formula $^{\text{TM}}$
25112 MCUs with 14 bit wide instructions.
25113 This port is not yet mature and still lacks many features.
25114 However, it can work for simple code.
25117 \begin_layout Standard
25119 Currently supported devices include:
25122 \begin_layout Standard
25123 12F: 629, 635, 675, 683
25126 \begin_layout Standard
25130 \begin_layout Standard
25134 \begin_layout Standard
25135 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
25138 \begin_layout Standard
25139 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
25143 \begin_layout Standard
25147 \begin_layout Standard
25148 16CR: 620a, 73, 74, 76, 77
25151 \begin_layout Standard
25152 16F: 616, 627, 627a, 628, 628a, 630, 636, 639, 648, 648a, 676, 684, 685,
25156 \begin_layout Standard
25157 16F: 716, 72, 73, 737, 74, 747, 76, 767, 77, 777, 785
25160 \begin_layout Standard
25161 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
25162 877, 877a, 88, 886, 887
25165 \begin_layout Standard
25166 16F: 913, 914, 916, 917, 946
25169 \begin_layout Standard
25173 \begin_layout Standard
25175 An up-to-date list of currently supported devices can be obtained via
25177 sdcc -mpic14 -phelp foo.c
25179 (foo.c must exist...).
25182 \begin_layout Subsection
25184 \begin_inset LatexCommand index
25185 name "code page (pic14)"
25190 \begin_inset LatexCommand index
25191 name "Memory bank (pic14)"
25198 \begin_layout Standard
25199 The linker organizes allocation for the code page and RAM banks.
25200 It does not have intimate knowledge of the code flow.
25201 It will put all the code section of a single .asm file into a single code
25203 In order to make use of multiple code pages, separate asm files must be
25205 The compiler assigns all
25209 functions of a single .c file into the same code page.
25213 To get the best results,
25214 follow these guidelines:
25217 \begin_layout Enumerate
25218 Make local functions static, as non static functions require code page selection
25221 Due to the way sdcc handles functions, place called functions prior
25222 to calling functions in the file wherever possible: Otherwise sdcc will
25223 insert unnecessary pagesel directives around the call, believing that the
25224 called function is externally defined.
25227 \begin_layout Enumerate
25228 For devices that have multiple code pages it is more efficient to use the
25229 same number of files as pages: Use up to 4 separate .c files for the 16F877,
25230 but only 2 files for the 16F874.
25231 This way the linker can put the code for each file into different code
25232 pages and there will be less page selection overhead.
25235 \begin_layout Enumerate
25236 And as for any 8 bit micro (especially for PIC14 as they have a very simple
25237 instruction set), use `unsigned char' wherever possible instead of `int'.
25240 \begin_layout Subsection
25241 Adding New Devices to the Port
25244 \begin_layout Standard
25245 Adding support for a new 14
25249 \begin_layout Standard
25258 bit PIC MCU requires the following steps:
25261 \begin_layout Enumerate
25262 Create a new device description.
25264 Each device is described in two files: pic16f*.h
25266 These files primarily define SFRs, structs to access their bits, and symbolic
25267 configuration options.
25268 Both files can be generated from gputils' .inc files using the perl script
25271 support/scripts/inc2h.pl
25274 This file also contains further instructions on how to proceed.
25277 \begin_layout Enumerate
25278 Copy the .h file into SDCC's include path and either add the .c file to your
25279 project or copy it to
25281 device/lib/pic/libdev
25284 Afterwards, rebuild and install the libraries.
25287 \begin_layout Enumerate
25288 Edit pic14devices.txt in SDCC's include path (
25290 device/include/pic/
25292 in the source tree or
25294 /usr/local/share/sdcc/include/pic
25296 after installation).
25298 You need to add a device specification here to make
25299 the memory layout (code banks, RAM, aliased memory regions, ...) known to
25301 Probably you can copy and modify an existing entry.
25302 The file format is documented at the top of the file.
25305 \begin_layout Subsection
25309 \begin_layout Standard
25310 For the interrupt function, use the keyword `__interrupt'
25311 \begin_inset LatexCommand index
25312 name "PIC14!interrupt"
25316 with level number of 0 (PIC14 only has 1 interrupt so this number is only
25317 there to avoid a syntax error - it ought to be fixed).
25321 \begin_layout Verse
25324 void Intr(void) __interrupt 0
25330 T0IF = 0; /* Clear timer interrupt */
25335 \begin_layout Subsection
25336 Linking and Assembling
25339 \begin_layout Standard
25340 For assembling you can use either GPUTILS'
25341 \begin_inset LatexCommand index
25342 name "gputils (pic tools)"
25346 gpasm.exe or MPLAB's mpasmwin.exe.
25347 GPUTILS are available from
25348 \begin_inset LatexCommand url
25349 target "http://sourceforge.net/projects/gputils"
25354 For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
25355 If you use MPLAB and an interrupt function then the linker script file
25356 vectors section will need to be enlarged to link with mplink.
25367 \begin_layout Verse
25380 sdcc -V -mpic14 -p16f877 -c $<
25384 $(PRJ).hex: $(OBJS)
25394 gplink -m -s $(PRJ).lkr
25395 -o $(PRJ).hex $(OBJS) libsdcc.lib
25398 \begin_layout Standard
25406 \begin_layout Verse
25419 sdcc -S -V -mpic14 -p16f877 $<
25429 mpasmwin /q /o $*.asm
25433 $(PRJ).hex: $(OBJS)
25444 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
25447 \begin_layout Standard
25448 Please note that indentations within a
25452 have to be done with a tabulator character.
25455 \begin_layout Subsection
25456 Command-Line Options
25459 \begin_layout Standard
25460 Besides the switches common to all SDCC backends, the PIC14 port accepts
25461 the following options (for an updated list see sdcc -
25465 \begin_layout Standard
25477 \begin_layout Description
25482 \begin_layout Standard
25492 \begin_inset LatexCommand index
25493 name "PIC14!Options!-\\/-debug-extra"
25497 emit debug info in assembly output
25500 \begin_layout Description
25505 \begin_layout Standard
25515 \begin_inset LatexCommand index
25516 name "PIC14!Options!-\\/-no-pcode-opt"
25520 disable (slightly faulty) optimization on pCode
25523 \begin_layout Description
25528 \begin_layout Standard
25538 \begin_inset LatexCommand index
25539 name "PIC14!Options!-\\/-stack-loc"
25543 sets the lowest address of the argument passing stack (defaults to a suitably
25544 large shared databank to reduce BANKSEL overhead)
25547 \begin_layout Description
25552 \begin_layout Standard
25562 \begin_inset LatexCommand index
25563 name "PIC14!Options!-\\/-stack-size"
25567 sets the size if the argument passing stack (default: 16, minimum: 4)
25570 \begin_layout Subsection
25571 Environment Variables
25574 \begin_layout Standard
25575 The PIC14 port recognizes the following environment variables:
25578 \begin_layout Description
25579 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
25580 register (the ones called r0xNNNN) in a section of its own.
25581 By default (if this variable is unset), sdcc tries to cluster registers
25582 in sections in order to reduce the BANKSEL overhead when accessing them.
25585 \begin_layout Subsection
25589 \begin_layout Standard
25590 The PIC14 library currently only contains support routines required by the
25591 compiler to implement multiplication, division, and floating point support.
25592 No libc-like replacement is available at the moment, though many of the
25593 common sdcc library sources (in
25597 ) should also compile with the PIC14 port.
25600 \begin_layout Subsubsection
25601 error: missing definition for symbol ``__gptrget1''
25604 \begin_layout Standard
25605 The PIC14 port uses library routines to provide more complex operations
25606 like multiplication, division/modulus and (generic) pointer dereferencing.
25607 In order to add these routines to your project, you must link with PIC14's
25613 For single source file projects this is done automatically, more complex
25618 to the linker's arguments.
25619 Make sure you also add an include path for the library (using the -I switch
25623 \begin_layout Subsubsection
25624 Processor mismatch in file ``XXX''.
25627 \begin_layout Standard
25628 This warning can usually be ignored due to the very good compatibility amongst
25633 \begin_layout Standard
25643 \begin_inset LatexCommand index
25651 \begin_layout Standard
25652 You might also consider recompiling the library for your specific device
25653 by changing the ARCH=p16f877 (default target) entry in
25655 device/lib/pic/Makefile.in
25659 device/lib/pic/Makefile
25661 to reflect your device.
25662 This might even improve performance for smaller devices as unnecessary
25663 BANKSELs might be removed.
25666 \begin_layout Subsection
25670 \begin_layout Subsubsection
25674 \begin_layout Standard
25675 Functions with variable argument lists (like printf) are not yet supported.
25676 Similarly, taking the address of the first argument passed into a function
25677 does not work: It is currently passed in WREG and has no address...
25680 \begin_layout Subsubsection
25681 Regression tests fail
25684 \begin_layout Standard
25685 Though the small subset of regression tests in src/regression passes, SDCC
25686 regression test suite does not, indicating that there are still major bugs
25688 However, many smaller projects have successfully used SDCC in the past...
25691 \begin_layout Standard
25699 \begin_layout Section
25701 \begin_inset LatexCommand index
25709 \begin_layout Standard
25710 The PIC16 port adds support for Microchip
25711 \begin_inset LatexCommand index
25717 \begin_inset Formula $^{\text{TM}}$
25721 \begin_inset LatexCommand index
25727 \begin_inset Formula $^{\text{TM}}$
25730 MCUs with 16 bit wide instructions.
25731 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
25732 ; devices supported by the port include:
25735 \begin_layout Standard
25736 18F: 242, 248, 252, 258, 442, 448, 452, 458
25739 \begin_layout Standard
25743 \begin_layout Standard
25744 18F: 2220, 2221, 2320, 2321, 2331, 23k20
25747 \begin_layout Standard
25748 18F: 2410, 2420, 2423, 2431, 2450, 2455, 2480, 24j10, 24k20
25751 \begin_layout Standard
25752 18F: 2510, 2515, 2520, 2523, 2525, 2550, 2580, 2585, 25j10, 25k20
25755 \begin_layout Standard
25756 18F: 2610, 2620, 2680, 2682, 2685
25759 \begin_layout Standard
25760 18F: 4220, 4221, 4320, 4321, 4331, 43k20
25763 \begin_layout Standard
25764 18F: 4410, 4420, 4423, 4431, 4450, 4455, 4480, 44j10, 44k20
25767 \begin_layout Standard
25768 18F: 4510, 4515, 4520, 4523, 4525, 4550, 4580, 4585, 45j10, 45k20
25771 \begin_layout Standard
25772 18F: 4610, 4620, 4680, 4682, 4685, 46k20
25775 \begin_layout Standard
25776 18F: 6520, 6585, 65j50, 6620, 6680, 66j50, 66j55, 66j60, 66j65, 6720, 67j50,
25780 \begin_layout Standard
25781 18F: 8520, 8585, 85j50, 8620, 8680, 86j50, 86j55, 86j60, 86j65, 8720, 87j50,
25785 \begin_layout Standard
25786 18F: 96j60, 96j65, 97j60
25789 \begin_layout Standard
25791 An up-to-date list of supported devices is also available via '
25793 sdcc -mpic16 -plist
25798 \begin_layout Subsection
25802 \begin_layout Standard
25803 PIC16 port supports the standard command line arguments as supposed, with
25804 the exception of certain cases that will be mentioned in the following
25808 \begin_layout Description
25813 \begin_layout Standard
25823 \begin_inset LatexCommand index
25824 name "PIC16!Options!-\\/-callee-saves"
25832 \begin_layout Standard
25844 \begin_layout Description
25849 \begin_layout Standard
25858 -fommit-frame-pointer
25859 \begin_inset LatexCommand index
25860 name "PIC16!Options!-\\/-fommit-frame-pointer"
25864 Frame pointer will be omitted when the function uses no local variables.
25867 \begin_layout Subsection
25868 Port Specific Options
25869 \begin_inset LatexCommand index
25870 name "Options PIC16"
25877 \begin_layout Standard
25878 The port specific options appear after the global options in the sdcc -
25882 \begin_layout Standard
25894 \begin_layout Subsubsection
25895 Code Generation Options
25898 \begin_layout Standard
25899 These options influence the generated assembler code.
25902 \begin_layout Description
25907 \begin_layout Standard
25916 -pstack-model=[model] Used in conjunction with the command above.
25917 Defines the stack model to be used, valid stack models are:
25922 \labelwidthstring 00.00.0000
25927 Selects small stack model.
25928 8 bit stack and frame pointers.
25929 Supports 256 bytes stack size.
25933 \labelwidthstring 00.00.0000
25938 Selects large stack model.
25939 16 bit stack and frame pointers.
25940 Supports 65536 bytes stack size.
25944 \begin_layout Description
25949 \begin_layout Standard
25958 -pno-banksel Do not generate BANKSEL assembler directives.
25961 \begin_layout Description
25966 \begin_layout Standard
25975 -extended Enable extended instruction set/literal offset addressing mode.
25979 \begin_layout Subsubsection
25980 Optimization Options
25983 \begin_layout Description
25988 \begin_layout Standard
25997 -obanksel=n Set optimization level for inserting BANKSELs.
26004 \labelwidthstring 00.00.0000
26009 \labelwidthstring 00.00.0000
26010 1 checks previous used register and if it is the same then does not emit
26011 BANKSEL, accounts only for labels.
26015 \labelwidthstring 00.00.0000
26016 2 tries to check the location of (even different) symbols and removes BANKSELs
26017 if they are in the same bank.
26022 Important: There might be problems if the linker script has data sections
26023 across bank borders!
26027 \begin_layout Description
26032 \begin_layout Standard
26041 -denable-peeps Force the usage of peepholes.
26045 \begin_layout Description
26050 \begin_layout Standard
26059 -no-optimize-goto Do not use (conditional) BRA instead of GOTO.
26062 \begin_layout Description
26067 \begin_layout Standard
26076 -optimize-cmp Try to optimize some compares.
26079 \begin_layout Description
26084 \begin_layout Standard
26093 -optimize-df Analyze the dataflow of the generated code and improve it.
26096 \begin_layout Subsubsection
26100 \begin_layout Description
26105 \begin_layout Standard
26114 -asm= Sets the full path and name of an external assembler to call.
26117 \begin_layout Description
26122 \begin_layout Standard
26132 \begin_inset LatexCommand index
26137 compatibility option.
26138 Currently only suppresses special gpasm directives.
26141 \begin_layout Subsubsection
26145 \begin_layout Description
26150 \begin_layout Standard
26159 -link= Sets the full path and name of an external linker to call.
26162 \begin_layout Description
26167 \begin_layout Standard
26176 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
26177 unitialized data variables with [kword].
26178 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
26181 \begin_layout Description
26186 \begin_layout Standard
26195 -ivt-loc=n Place the interrupt vector table at address
26200 Useful for bootloaders.
26203 \begin_layout Description
26208 \begin_layout Standard
26217 -nodefaultlibs Do not link default libraries when linking.
26220 \begin_layout Description
26225 \begin_layout Standard
26234 -use-crt= Use a custom run-time module instead of the defaults.
26237 \begin_layout Description
26242 \begin_layout Standard
26251 -no-crt Don't link the default run-time modules
26254 \begin_layout Subsubsection
26258 \begin_layout Standard
26259 Debugging options enable extra debugging information in the output files.
26262 \begin_layout Description
26267 \begin_layout Standard
26276 -debug-xtra Similar to -
26280 \begin_layout Standard
26290 \begin_inset LatexCommand index
26295 , but dumps more information.
26298 \begin_layout Description
26303 \begin_layout Standard
26312 -debug-ralloc Force register allocator to dump <source>.d file with debugging
26314 <source> is the name of the file being compiled.
26317 \begin_layout Description
26322 \begin_layout Standard
26331 -pcode-verbose Enable pcode debugging information in translation.
26334 \begin_layout Description
26339 \begin_layout Standard
26348 -calltree Dump call tree in .calltree file.
26351 \begin_layout Description
26356 \begin_layout Standard
26365 -gstack Trace push/pops for stack pointer overflow.
26368 \begin_layout Subsection
26369 Environment Variables
26372 \begin_layout Standard
26373 There is a number of environmental variables that can be used when running
26374 SDCC to enable certain optimizations or force a specific program behaviour.
26375 these variables are primarily for debugging purposes so they can be enabled/dis
26379 \begin_layout Standard
26380 Currently there is only two such variables available:
26383 \begin_layout Description
26384 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
26385 bitfields is optimized by directly loading FSR0 with the address of the
26386 bitfield structure.
26387 Normally SDCC will cast the bitfield structure to a bitfield pointer and
26389 This step saves data ram and code space for functions that make heavy use
26391 (i.e., 80 bytes of code space are saved when compiling malloc.c with this
26396 \begin_layout Description
26397 NO_REG_OPT Do not perform pCode registers optimization.
26398 This should be used for debugging purposes.
26399 If bugs in the pcode optimizer are found, users can benefit from temporarily
26400 disabling the optimizer until the bug is fixed.
26403 \begin_layout Subsection
26404 Preprocessor Macros
26407 \begin_layout Standard
26409 \begin_inset LatexCommand index
26414 port defines the following preprocessor macros while translating a source.
26417 \begin_layout Standard
26419 \begin_inset Tabular
26420 <lyxtabular version="3" rows="6" columns="2">
26422 <column alignment="center" valignment="top" leftline="true" width="0">
26423 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26424 <row topline="true" bottomline="true">
26425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26428 \begin_layout Standard
26434 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26437 \begin_layout Standard
26444 <row topline="true">
26445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26448 \begin_layout Standard
26454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26457 \begin_layout Standard
26458 Port identification
26464 <row topline="true">
26465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26468 \begin_layout Standard
26473 \begin_layout Standard
26487 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26490 \begin_layout Standard
26491 Port identification (same as above)
26497 <row topline="true">
26498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26501 \begin_layout Standard
26507 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26510 \begin_layout Standard
26511 MCU Identification.
26516 is the microcontrol identification number, i.e.
26523 <row topline="true">
26524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26527 \begin_layout Standard
26532 \begin_layout Standard
26546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26549 \begin_layout Standard
26550 MCU Identification (same as above)
26556 <row topline="true" bottomline="true">
26557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26560 \begin_layout Standard
26566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26569 \begin_layout Standard
26570 nnn = SMALL or LARGE respectively according to the stack model used
26583 \begin_layout Standard
26585 In addition the following macros are defined when calling assembler:
26588 \begin_layout Standard
26590 \begin_inset Tabular
26591 <lyxtabular version="3" rows="4" columns="2">
26593 <column alignment="center" valignment="top" leftline="true" width="0">
26594 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26595 <row topline="true" bottomline="true">
26596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26599 \begin_layout Standard
26605 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26608 \begin_layout Standard
26615 <row topline="true">
26616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26619 \begin_layout Standard
26625 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26628 \begin_layout Standard
26629 MCU Identification.
26634 is the microcontrol identification number, i.e.
26641 <row topline="true">
26642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26645 \begin_layout Standard
26651 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26654 \begin_layout Standard
26655 nnn = SMALL or LARGE respectively according to the memory model used for
26662 <row topline="true" bottomline="true">
26663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26666 \begin_layout Standard
26672 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26675 \begin_layout Standard
26676 nnn = SMALL or LARGE respectively according to the stack model used
26689 \begin_layout Subsection
26693 \begin_layout Standard
26695 \begin_inset LatexCommand index
26700 port uses the following directories for searching header files and libraries.
26703 \begin_layout Standard
26705 \begin_inset Tabular
26706 <lyxtabular version="3" rows="3" columns="4">
26708 <column alignment="center" valignment="top" leftline="true" width="0">
26709 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26710 <column alignment="center" valignment="top" width="0">
26711 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26712 <row topline="true" bottomline="true">
26713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26716 \begin_layout Standard
26722 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26725 \begin_layout Standard
26731 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26734 \begin_layout Standard
26740 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26743 \begin_layout Standard
26750 <row topline="true">
26751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26754 \begin_layout Standard
26755 PREFIX/sdcc/include/pic16
26760 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26763 \begin_layout Standard
26764 PIC16 specific headers
26769 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26772 \begin_layout Standard
26778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26781 \begin_layout Standard
26788 <row topline="true" bottomline="true">
26789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26792 \begin_layout Standard
26793 PREFIX/sdcc/lib/pic16
26798 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26801 \begin_layout Standard
26802 PIC16 specific libraries
26807 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26810 \begin_layout Standard
26816 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26819 \begin_layout Standard
26833 \begin_layout Subsection
26835 \begin_inset LatexCommand label
26836 name "sub:PIC16_Pragmas"
26843 \begin_layout Standard
26845 \begin_inset LatexCommand index
26850 port currently supports the following pragmas:
26853 \begin_layout Description
26855 \begin_inset LatexCommand index
26856 name "PIC16!Pragmas!\\#pragma stack"
26860 This forces the code generator to initialize the stack & frame pointers
26861 at a specific address.
26862 This is an ad hoc solution for cases where no STACK directive is available
26863 in the linker script or gplink is not instructed to create a stack section.
26866 stack pragma should be used only once in a project.
26867 Multiple pragmas may result in indeterminate behaviour of the program.
26871 \begin_layout Standard
26872 The old format (ie.
26873 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
26874 cross page boundaries (or even exceed the available data RAM) and crash
26876 Make sure that stack does not cross page boundaries when using the SMALL
26884 The format is as follows:
26889 \begin_layout LyX-Code
26890 #pragma stack bottom_address [stack_size]
26895 \begin_layout Standard
26900 is the lower bound of the stack section.
26901 The stack pointer initially will point at address (bottom_address+stack_size-1).
26904 \begin_layout LyX-Code
26908 \begin_layout LyX-Code
26912 \begin_layout LyX-Code
26913 /* initializes stack of 100 bytes at RAM address 0x200 */
26916 \begin_layout LyX-Code
26917 #pragma stack 0x200 100
26920 \begin_layout Standard
26921 If the stack_size field is omitted then a stack is created with the default
26923 This size might be enough for most programs, but its not enough for operations
26924 with deep function nesting or excessive stack usage.
26927 \begin_layout Description
26929 \begin_inset LatexCommand index
26930 name "PIC16!Pragmas!\\#pragma code"
26934 Force a function to a static FLASH address.
26937 \begin_layout LyX-Code
26941 \begin_layout LyX-Code
26945 \begin_layout LyX-Code
26946 /* place function test_func at 0x4000 */
26949 \begin_layout LyX-Code
26950 #pragma code test_func 0x4000
26953 \begin_layout LyX-Code
26957 \begin_layout Description
26958 library instructs the linker to use a library module.
26963 \begin_layout LyX-Code
26964 #pragma library module_name
26967 \begin_layout Standard
26972 can be any library or object file (including its path).
26973 Note that there are four reserved keywords which have special meaning.
26977 \begin_layout Standard
26979 \begin_inset Tabular
26980 <lyxtabular version="3" rows="6" columns="3">
26982 <column alignment="center" valignment="top" leftline="true" width="0">
26983 <column alignment="block" valignment="top" leftline="true" width="20page%">
26984 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
26985 <row topline="true" bottomline="true">
26986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26989 \begin_layout Standard
26995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26998 \begin_layout Standard
27004 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27007 \begin_layout Standard
27014 <row topline="true">
27015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27018 \begin_layout Standard
27026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27029 \begin_layout Standard
27030 ignore all library pragmas
27035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27038 \begin_layout Standard
27047 <row topline="true">
27048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27051 \begin_layout Standard
27059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27062 \begin_layout Standard
27068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27071 \begin_layout Standard
27082 <row topline="true">
27083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27086 \begin_layout Standard
27094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27097 \begin_layout Standard
27098 link the Math libarary
27103 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27106 \begin_layout Standard
27117 <row topline="true">
27118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27121 \begin_layout Standard
27129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27132 \begin_layout Standard
27133 link the I/O library
27138 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27141 \begin_layout Standard
27152 <row topline="true" bottomline="true">
27153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27156 \begin_layout Standard
27164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27167 \begin_layout Standard
27168 link the debug library
27173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27176 \begin_layout Standard
27193 * is the device number, i.e.
27194 452 for PIC18F452 MCU.
27197 \begin_layout Standard
27199 This feature allows for linking with specific libraries without having to
27200 explicit name them in the command line.
27205 keyword will reject all modules specified by the library pragma.
27208 \begin_layout Description
27209 udata The pragma udata instructs the compiler to emit code so that linker
27210 will place a variable at a specific memory bank.
27213 \begin_layout LyX-Code
27217 \begin_layout LyX-Code
27221 \begin_layout LyX-Code
27222 /* places variable foo at bank2 */
27225 \begin_layout LyX-Code
27226 #pragma udata bank2 foo
27229 \begin_layout LyX-Code
27233 \begin_layout Standard
27234 In order for this pragma to work extra SECTION directives should be added
27235 in the .lkr script.
27236 In the following example a sample .lkr file is shown:
27239 \begin_layout LyX-Code
27243 \begin_layout LyX-Code
27244 // Sample linker script for the PIC18F452 processor
27247 \begin_layout LyX-Code
27251 \begin_layout LyX-Code
27252 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
27255 \begin_layout LyX-Code
27256 CODEPAGE NAME=page START=0x2A END=0x7FFF
27259 \begin_layout LyX-Code
27260 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
27263 \begin_layout LyX-Code
27264 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
27267 \begin_layout LyX-Code
27268 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
27271 \begin_layout LyX-Code
27272 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
27275 \begin_layout LyX-Code
27276 ACCESSBANK NAME=accessram START=0x0 END=0x7F
27279 \begin_layout LyX-Code
27283 \begin_layout LyX-Code
27284 DATABANK NAME=gpr0 START=0x80 END=0xFF
27287 \begin_layout LyX-Code
27288 DATABANK NAME=gpr1 START=0x100 END=0x1FF
27291 \begin_layout LyX-Code
27292 DATABANK NAME=gpr2 START=0x200 END=0x2FF
27295 \begin_layout LyX-Code
27296 DATABANK NAME=gpr3 START=0x300 END=0x3FF
27299 \begin_layout LyX-Code
27300 DATABANK NAME=gpr4 START=0x400 END=0x4FF
27303 \begin_layout LyX-Code
27304 DATABANK NAME=gpr5 START=0x500 END=0x5FF
27307 \begin_layout LyX-Code
27308 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
27311 \begin_layout LyX-Code
27315 \begin_layout LyX-Code
27316 SECTION NAME=CONFIG ROM=config
27319 \begin_layout LyX-Code
27323 \begin_layout LyX-Code
27324 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
27327 \begin_layout LyX-Code
27328 SECTION NAME=bank1 RAM=gpr1 # should be added to link
27331 \begin_layout LyX-Code
27332 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
27335 \begin_layout LyX-Code
27336 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
27339 \begin_layout LyX-Code
27340 SECTION NAME=bank4 RAM=gpr4
27343 \begin_layout LyX-Code
27344 SECTION NAME=bank5 RAM=gpr5
27347 \begin_layout Standard
27348 The linker will recognise the section name set in the pragma statement and
27349 will position the variable at the memory bank set with the RAM field at
27350 the SECTION line in the linker script file.
27353 \begin_layout Subsection
27355 \begin_inset LatexCommand label
27356 name "sub:PIC16_Header-Files"
27363 \begin_layout Standard
27364 There is one main header file
27365 \begin_inset LatexCommand index
27366 name "PIC16!Header files"
27370 that can be included to the source files using the pic16
27371 \begin_inset LatexCommand index
27382 This header file contains the definitions for the processor special registers,
27383 so it is necessary if the source accesses them.
27384 It can be included by adding the following line in the beginning of the
27388 \begin_layout LyX-Code
27389 #include <pic18fregs.h>
27392 \begin_layout Standard
27393 The specific microcontroller is selected within the pic18fregs.h automatically,
27394 so the same source can be used with a variety of devices.
27397 \begin_layout Subsection
27399 \begin_inset LatexCommand label
27400 name "sub:pic16Libraries"
27407 \begin_layout Standard
27409 \begin_inset LatexCommand index
27410 name "PIC16!Libraries"
27415 \begin_inset LatexCommand index
27420 port depends on are the microcontroller device libraries which contain
27421 the symbol definitions for the microcontroller special function registers.
27422 These libraries have the format pic18fxxxx.lib, where
27426 is the microcontroller identification number.
27427 The specific library is selected automatically by the compiler at link
27428 stage according to the selected device.
27431 \begin_layout Standard
27433 Libraries are created with gplib which is part of the gputils package
27434 \begin_inset LatexCommand url
27435 target "http://sourceforge.net/projects/gputils"
27442 \begin_layout Subsubsection*
27443 Building the libraries
27446 \begin_layout Standard
27447 Before using SDCC/pic16 there are some libraries that need to be compiled.
27448 This process is done automatically if gputils are found at SDCC's compile
27450 Should you require to rebuild the pic16 libraries manually (e.g.
27451 in order to enable output of float values
27452 \begin_inset LatexCommand index
27453 name "Floating point support"
27461 , see below), these are the steps required to do so under Linux or Mac OS
27462 X (cygwin might work as well, but is untested):
27465 \begin_layout LyX-Code
27466 cd device/lib/pic16
27469 \begin_layout LyX-Code
27473 \begin_layout LyX-Code
27477 \begin_layout LyX-Code
27481 \begin_layout LyX-Code
27482 su -c 'make install' # install the libraries, you need the root password
27485 \begin_layout LyX-Code
27489 \begin_layout Standard
27490 If you need to install the headers too, do:
27493 \begin_layout LyX-Code
27497 \begin_layout LyX-Code
27498 su -c 'make install' # install the headers, you need the root password
27501 \begin_layout Subsubsection*
27502 Output of float values via printf()
27505 \begin_layout Standard
27506 The library is normally built without support for displaying float values,
27508 \begin_inset LatexCommand index
27514 \begin_inset LatexCommand index
27515 name "printf floating point support"
27519 will appear instead of the value.
27520 To change this, rebuild the library as stated above, but call
27522 ./configure.gnu --enable-floats
27529 Also make sure that at least
27531 libc/stdio/vfprintf.c
27533 is actually recompiled, e.g.
27542 run or deleting its
27549 \begin_layout Standard
27550 The more common appraoch of compiling
27558 should also work, but is untested.
27561 \begin_layout Subsection
27562 Adding New Devices to the Port
27565 \begin_layout Standard
27566 Adding support for a new 16
27570 \begin_layout Standard
27579 bit PIC MCU requires the following steps:
27582 \begin_layout Enumerate
27583 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
27587 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
27591 \begin_layout Enumerate
27594 mv picDEVICE.h /path/to/sdcc/device/include/pic16
27597 \begin_layout Enumerate
27600 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
27603 \begin_layout Enumerate
27606 /path/to/sdcc/device/lib/pic16/pics.all
27610 Note: No 18f prefix here!
27613 \begin_layout Enumerate
27616 /path/to/sdcc/device/include/pic16/adc.h
27620 Add the new devices to the correct ADC style class (depending on the number
27627 if the device does not offer any ADC at all.
27630 \begin_layout Enumerate
27633 /path/to/sdcc/device/include/pic16/pic18fregs.h
27637 The file format is self-explanatory, just add
27641 #elif defined(picDEVICE)
27647 \begin_layout Standard
27658 include <picDEVICE.h>
27662 at the right place (keep the file sorted, please).
27665 \begin_layout Enumerate
27668 /path/to/sdcc/device/include/pic16devices.txt
27672 Copy and modify an existing entry or create a new one and insert it at the
27673 correct place (keep the file sorted, please).
27676 \begin_layout Enumerate
27679 /path/to/sdcc/device/lib/pic16/libdev/Makefile.am
27683 Copy an existing entry and adjust the device name.
27686 \begin_layout Enumerate
27689 /path/to/sdcc/device/lib/pic16/libio/Makefile.am
27693 Copy the record from the 18f2220 and adjust the device name.
27696 does not offer ADC, I
27697 \begin_inset Formula $^{\text{2}}$
27700 C, and/or (E)USART functionality as assumed by the library, remove the lines
27716 \begin_layout Enumerate
27735 /path/to/sdcc/device/lib/pic16
27740 \begin_layout Enumerate
27741 Recompile the pic16 libraries as described in
27742 \begin_inset LatexCommand ref
27743 reference "sub:pic16Libraries"
27750 \begin_layout Subsection
27754 \begin_layout Standard
27755 The following memory models are supported by the PIC16 port:
27758 \begin_layout Itemize
27762 \begin_layout Itemize
27766 \begin_layout Standard
27767 Memory model affects the default size of pointers within the source.
27768 The sizes are shown in the next table:
27771 \begin_layout Standard
27773 \begin_inset Tabular
27774 <lyxtabular version="3" rows="3" columns="3">
27776 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27777 <column alignment="center" valignment="top" leftline="true" width="0">
27778 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27779 <row topline="true" bottomline="true">
27780 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27783 \begin_layout Standard
27784 Pointer sizes according to memory model
27789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27792 \begin_layout Standard
27798 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27801 \begin_layout Standard
27808 <row topline="true" bottomline="true">
27809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27812 \begin_layout Standard
27818 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27821 \begin_layout Standard
27827 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27830 \begin_layout Standard
27837 <row topline="true" bottomline="true">
27838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27841 \begin_layout Standard
27847 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
27850 \begin_layout Standard
27856 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27859 \begin_layout Standard
27873 \begin_layout Standard
27874 It is advisable that all sources within a project are compiled with the
27876 If one wants to override the default memory model, this can be done by
27877 declaring a pointer as
27886 Far selects large memory model's pointers, while near selects small memory
27890 \begin_layout Standard
27891 The standard device libraries (see
27892 \begin_inset LatexCommand ref
27893 reference "sub:PIC16_Header-Files"
27897 ) contain no reference to pointers, so they can be used with both memory
27901 \begin_layout Subsection
27905 \begin_layout Standard
27907 \begin_inset LatexCommand index
27912 implementation for the PIC16 port uses two indirect registers, FSR1 and
27916 \begin_layout Description
27917 FSR1 is assigned as stack pointer
27920 \begin_layout Description
27921 FSR2 is assigned as frame pointer
27924 \begin_layout Standard
27925 The following stack models are supported by the PIC16 port
27928 \begin_layout Itemize
27936 \begin_layout Itemize
27944 \begin_layout Standard
27949 model means that only the FSRxL byte is used to access stack and frame,
27956 uses both FSRxL and FSRxH registers.
27957 The following table shows the stack/frame pointers sizes according to stack
27958 model and the maximum space they can address:
27961 \begin_layout Standard
27963 \begin_inset Tabular
27964 <lyxtabular version="3" rows="3" columns="3">
27966 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27967 <column alignment="center" valignment="top" leftline="true" width="0">
27968 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27969 <row topline="true" bottomline="true">
27970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27973 \begin_layout Standard
27974 Stack & Frame pointer sizes according to stack model
27979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27982 \begin_layout Standard
27988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27991 \begin_layout Standard
27998 <row topline="true">
27999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28002 \begin_layout Standard
28008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28011 \begin_layout Standard
28017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28020 \begin_layout Standard
28027 <row topline="true" bottomline="true">
28028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28031 \begin_layout Standard
28037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28040 \begin_layout Standard
28046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28049 \begin_layout Standard
28063 \begin_layout Standard
28069 stack model is currently not working properly throughout the code generator.
28070 So its use is not advised.
28071 Also there are some other points that need special care:
28076 \begin_layout Enumerate
28077 Do not create stack sections with size more than one physical bank (that
28081 \begin_layout Enumerate
28082 Stack sections should no cross physical bank limits (i.e.
28083 #pragma stack 0x50 0x100)
28086 \begin_layout Standard
28087 These limitations are caused by the fact that only FSRxL is modified when
28088 using SMALL stack model, so no more than 256 bytes of stack can be used.
28089 This problem will disappear after LARGE model is fully implemented.
28092 \begin_layout Subsection
28096 \begin_layout Standard
28097 In addition to the standard SDCC function keywords, PIC16
28098 \begin_inset LatexCommand index
28103 port makes available two more:
28106 \begin_layout Description
28108 \begin_inset LatexCommand index
28109 name "PIC16!wparam"
28113 Use the WREG to pass one byte of the first function argument.
28114 This improves speed but you may not use this for functions with arguments
28115 that are called via function pointers, otherwise the first byte of the
28116 first parameter will get lost.
28120 \begin_layout LyX-Code
28121 void func_wparam(int a) wparam
28124 \begin_layout LyX-Code
28128 \begin_layout LyX-Code
28129 /* WREG hold the lower part of a */
28132 \begin_layout LyX-Code
28133 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
28137 \begin_layout LyX-Code
28141 \begin_layout LyX-Code
28145 \begin_layout Description
28147 \begin_inset LatexCommand index
28148 name "PIC16!shadowregs"
28152 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
28153 hardware shadow registers which hold the values of WREG, STATUS and BSR
28155 This can be done by adding the keyword
28163 keyword in the function's header.
28166 \begin_layout LyX-Code
28167 void isr_shadow(void) shadowregs interrupt 1
28170 \begin_layout LyX-Code
28174 \begin_layout LyX-Code
28178 \begin_layout LyX-Code
28182 \begin_layout Standard
28187 instructs the code generator not to store/restore WREG, STATUS, BSR when
28188 entering/exiting the ISR.
28191 \begin_layout Subsection
28192 Function return values
28195 \begin_layout Standard
28196 Return values from functions are placed to the appropriate registers following
28197 a modified Microchip policy optimized for SDCC.
28198 The following table shows these registers:
28201 \begin_layout Standard
28203 \begin_inset Tabular
28204 <lyxtabular version="3" rows="6" columns="2">
28206 <column alignment="center" valignment="top" leftline="true" width="0">
28207 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28208 <row topline="true" bottomline="true">
28209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28212 \begin_layout Standard
28218 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28221 \begin_layout Standard
28222 destination register
28228 <row topline="true">
28229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28232 \begin_layout Standard
28238 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28241 \begin_layout Standard
28248 <row topline="true">
28249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28252 \begin_layout Standard
28258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28261 \begin_layout Standard
28268 <row topline="true">
28269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28272 \begin_layout Standard
28278 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28281 \begin_layout Standard
28288 <row topline="true">
28289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28292 \begin_layout Standard
28298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28301 \begin_layout Standard
28302 FSR0L:PRODH:PRODL:WREG
28308 <row topline="true" bottomline="true">
28309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28312 \begin_layout Standard
28318 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28321 \begin_layout Standard
28322 on stack, FSR0 points to the beginning
28335 \begin_layout Subsection
28339 \begin_layout Standard
28341 \begin_inset LatexCommand index
28342 name "PIC16!interrupt"
28346 service routine (ISR) is declared using the
28353 \begin_layout LyX-Code
28354 void isr(void) interrupt
28359 \begin_layout LyX-Code
28363 \begin_layout LyX-Code
28367 \begin_layout LyX-Code
28371 \begin_layout Standard
28376 is the interrupt number, which for PIC18F devices can be:
28379 \begin_layout Standard
28381 \begin_inset Tabular
28382 <lyxtabular version="3" rows="4" columns="3">
28384 <column alignment="center" valignment="top" leftline="true" width="0">
28385 <column alignment="center" valignment="top" leftline="true" width="0">
28386 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28387 <row topline="true" bottomline="true">
28388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28391 \begin_layout Standard
28399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28402 \begin_layout Standard
28408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28411 \begin_layout Standard
28412 Interrupt Vector Address
28418 <row topline="true">
28419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28422 \begin_layout Standard
28428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28431 \begin_layout Standard
28437 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28440 \begin_layout Standard
28447 <row topline="true">
28448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28451 \begin_layout Standard
28466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28469 \begin_layout Standard
28479 HIGH priority interrupts
28484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28487 \begin_layout Standard
28494 <row topline="true" bottomline="true">
28495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28498 \begin_layout Standard
28504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28507 \begin_layout Standard
28508 LOW priority interrupts
28513 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28516 \begin_layout Standard
28530 \begin_layout Standard
28531 When generating assembly code for ISR the code generator places a
28537 Interrupt Vector Address
28539 which points at the generated ISR.
28540 This single GOTO instruction is part of an automatically generated
28542 interrupt entry point
28545 The actuall ISR code is placed as normally would in the code space.
28546 Upon interrupt request, the GOTO instruction is executed which jumps to
28548 When declaring interrupt functions as _naked this GOTO instruction is
28553 The whole interrupt functions is therefore placed at the Interrupt Vector
28554 Address of the specific interrupt.
28555 This is not a problem for the LOW priority interrupts, but it is a problem
28556 for the RESET and the HIGH priority interrupts because code may be written
28557 at the next interrupt's vector address and cause indeterminate program
28558 behaviour if that interrupt is raised.
28562 \begin_layout Standard
28563 This is not a problem when
28566 \begin_layout Enumerate
28567 this is a HIGH interrupt ISR and LOW interrupts are
28574 \begin_layout Enumerate
28575 when the ISR is small enough not to reach the next interrupt's vector address.
28583 \begin_layout Standard
28589 This way a function is generated similar to an ISR, but it is not assigned
28593 \begin_layout Standard
28594 When entering an interrupt, currently the PIC16
28595 \begin_inset LatexCommand index
28600 port automatically saves the following registers:
28603 \begin_layout Itemize
28607 \begin_layout Itemize
28611 \begin_layout Itemize
28615 \begin_layout Itemize
28616 PROD (PRODL and PRODH)
28619 \begin_layout Itemize
28620 FSR0 (FSR0L and FSR0H)
28623 \begin_layout Standard
28624 These registers are restored upon return from the interrupt routine.
28628 \begin_layout Standard
28629 NOTE that when the _naked attribute is specified for an interrupt routine,
28630 then NO registers are stored or restored.
28638 \begin_layout Subsection
28642 \begin_layout Standard
28643 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
28644 There are 3 types of generic pointers currently implemented data, code
28645 and eeprom pointers.
28646 They are differentiated by the value of the 7th and 6th bits of the upper
28650 \begin_layout Standard
28652 \begin_inset Tabular
28653 <lyxtabular version="3" rows="5" columns="5">
28655 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28656 <column alignment="center" valignment="top" width="0">
28657 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28658 <column alignment="center" valignment="top" width="0">
28659 <column alignment="left" valignment="top" rightline="true" width="0">
28660 <row topline="true" bottomline="true">
28661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28664 \begin_layout Standard
28670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28673 \begin_layout Standard
28679 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28682 \begin_layout Standard
28688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28691 \begin_layout Standard
28692 rest of the pointer
28697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28700 \begin_layout Standard
28707 <row topline="true" bottomline="true">
28708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28711 \begin_layout Standard
28717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28720 \begin_layout Standard
28726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28729 \begin_layout Standard
28735 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28738 \begin_layout Standard
28743 uuuuuu uuuuxxxx xxxxxxxx
28748 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28751 \begin_layout Standard
28752 a 12-bit data pointer in data RAM memory
28758 <row bottomline="true">
28759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28762 \begin_layout Standard
28768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28771 \begin_layout Standard
28777 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28780 \begin_layout Standard
28786 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28789 \begin_layout Standard
28794 uxxxxx xxxxxxxx xxxxxxxx
28799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28802 \begin_layout Standard
28803 a 21-bit code pointer in FLASH memory
28809 <row bottomline="true">
28810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28813 \begin_layout Standard
28819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28822 \begin_layout Standard
28828 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28831 \begin_layout Standard
28837 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28840 \begin_layout Standard
28845 uuuuuu uuuuuuxx xxxxxxxx
28850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28853 \begin_layout Standard
28854 a 10-bit eeprom pointer in EEPROM memory
28860 <row bottomline="true">
28861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28864 \begin_layout Standard
28870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28873 \begin_layout Standard
28879 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28882 \begin_layout Standard
28888 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28891 \begin_layout Standard
28896 xxxxxx xxxxxxxx xxxxxxxx
28901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28904 \begin_layout Standard
28905 unimplemented pointer type
28918 \begin_layout Standard
28920 Generic pointer are read and written with a set of library functions which
28921 read/write 1, 2, 3, 4 bytes.
28924 \begin_layout Subsection
28928 \begin_layout Subsubsection
28929 Standard I/O Streams
28932 \begin_layout Standard
28937 the type FILE is defined as:
28940 \begin_layout LyX-Code
28941 typedef char * FILE;
28944 \begin_layout Standard
28945 This type is the stream type implemented I/O in the PIC18F devices.
28946 Also the standard input and output streams are declared in stdio.h:
28949 \begin_layout LyX-Code
28950 extern FILE * stdin;
28953 \begin_layout LyX-Code
28954 extern FILE * stdout;
28957 \begin_layout Standard
28958 The FILE type is actually a generic pointer which defines one more type
28959 of generic pointers, the
28964 This new type has the format:
28967 \begin_layout Standard
28970 \begin_inset Tabular
28971 <lyxtabular version="3" rows="2" columns="7">
28973 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28974 <column alignment="center" valignment="top" width="0">
28975 <column alignment="center" valignment="top" leftline="true" width="0">
28976 <column alignment="center" valignment="top" leftline="true" width="0">
28977 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28978 <column alignment="center" valignment="top" width="0">
28979 <column alignment="left" valignment="top" rightline="true" width="0">
28980 <row topline="true" bottomline="true">
28981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28984 \begin_layout Standard
28990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28993 \begin_layout Standard
28999 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29002 \begin_layout Standard
29008 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29011 \begin_layout Standard
29017 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29020 \begin_layout Standard
29026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29029 \begin_layout Standard
29030 rest of the pointer
29035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29038 \begin_layout Standard
29045 <row topline="true" bottomline="true">
29046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29049 \begin_layout Standard
29055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29058 \begin_layout Standard
29064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29067 \begin_layout Standard
29073 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29076 \begin_layout Standard
29082 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29085 \begin_layout Standard
29091 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29094 \begin_layout Standard
29104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29107 \begin_layout Standard
29108 upper byte high nubble is 0x2n, the rest are zeroes
29121 \begin_layout Standard
29123 Currently implemented there are 3 types of streams defined:
29126 \begin_layout Standard
29129 \begin_inset Tabular
29130 <lyxtabular version="3" rows="4" columns="4">
29132 <column alignment="center" valignment="top" leftline="true" width="0">
29133 <column alignment="center" valignment="top" leftline="true" width="0">
29134 <column alignment="center" valignment="top" leftline="true" width="0">
29135 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29136 <row topline="true" bottomline="true">
29137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29140 \begin_layout Standard
29146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29149 \begin_layout Standard
29155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29158 \begin_layout Standard
29164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29167 \begin_layout Standard
29174 <row topline="true">
29175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29178 \begin_layout Standard
29184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29187 \begin_layout Standard
29195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29198 \begin_layout Standard
29204 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29207 \begin_layout Standard
29208 Writes/Reads characters via the USART peripheral
29214 <row topline="true">
29215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29218 \begin_layout Standard
29224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29227 \begin_layout Standard
29235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29238 \begin_layout Standard
29244 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29247 \begin_layout Standard
29248 Writes/Reads characters via the MSSP peripheral
29254 <row topline="true" bottomline="true">
29255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29258 \begin_layout Standard
29264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29267 \begin_layout Standard
29275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29278 \begin_layout Standard
29284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29287 \begin_layout Standard
29288 Writes/Reads characters via used defined functions
29301 \begin_layout Standard
29303 The stream identifiers are declared as macros in the stdio.h header.
29306 \begin_layout Standard
29308 In the libc library there exist the functions that are used to write to
29309 each of the above streams.
29313 \begin_layout Description
29318 \begin_layout Standard
29327 _stream_usart_putchar writes a character at the USART stream
29330 \begin_layout Description
29335 \begin_layout Standard
29344 _stream_mssp_putchar writes a character at the MSSP stream
29347 \begin_layout Description
29348 putchar dummy function.
29349 This writes a character to a user specified manner.
29352 \begin_layout Standard
29353 In order to increase performance
29357 is declared in stdio.h as having its parameter in WREG (it has the wparam
29359 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
29360 in a user-friendly way.
29365 is the name of the variable that holds the character to print.
29366 An example follows:
29369 \begin_layout LyX-Code
29370 #include <pic18fregs.h>
29379 \begin_layout LyX-Code
29383 \begin_layout LyX-Code
29384 PORTA = c; /* dump character c to PORTA */
29387 \begin_layout LyX-Code
29395 \begin_layout LyX-Code
29399 \begin_layout LyX-Code
29400 stdout = STREAM_USER; /* this is not necessary, since stdout points
29403 \begin_layout LyX-Code
29404 * by default to STREAM_USER */
29407 \begin_layout LyX-Code
29409 \begin_inset Quotes sld
29412 This is a printf test
29415 \begin_inset Quotes srd
29421 \begin_layout LyX-Code
29425 \begin_layout LyX-Code
29429 \begin_layout Subsubsection
29433 \begin_layout Standard
29434 PIC16 contains an implementation of the printf-family of functions.
29435 There exist the following functions:
29438 \begin_layout LyX-Code
29439 extern unsigned int sprintf(char *buf, char *fmt, ...);
29442 \begin_layout LyX-Code
29443 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
29446 \begin_layout LyX-Code
29450 \begin_layout LyX-Code
29451 extern unsigned int printf(char *fmt, ...);
29454 \begin_layout LyX-Code
29455 extern unsigned int vprintf(char *fmt, va_lista ap);
29458 \begin_layout LyX-Code
29462 \begin_layout LyX-Code
29463 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
29466 \begin_layout LyX-Code
29467 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
29470 \begin_layout Standard
29471 For sprintf and vsprintf
29475 should normally be a data pointer where the resulting string will be placed.
29476 No range checking is done so the user should allocate the necessary buffer.
29477 For fprintf and vfprintf
29481 should be a stream pointer (i.e.
29482 stdout, STREAM_MSSP, etc...).
29485 \begin_layout Subsubsection
29489 \begin_layout Standard
29490 The PIC18F family of microcontrollers supports a number of interrupt sources.
29491 A list of these interrupts is shown in the following table:
29494 \begin_layout Standard
29496 \begin_inset Tabular
29497 <lyxtabular version="3" rows="11" columns="4">
29499 <column alignment="left" valignment="top" leftline="true" width="0">
29500 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29501 <column alignment="left" valignment="top" leftline="true" width="0">
29502 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29503 <row topline="true" bottomline="true">
29504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29507 \begin_layout Standard
29513 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29516 \begin_layout Standard
29522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29525 \begin_layout Standard
29531 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29534 \begin_layout Standard
29541 <row topline="true">
29542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29545 \begin_layout Standard
29551 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29554 \begin_layout Standard
29555 PORTB change interrupt
29560 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29563 \begin_layout Standard
29569 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29572 \begin_layout Standard
29573 EEPROM/FLASH write complete interrupt
29579 <row topline="true">
29580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29583 \begin_layout Standard
29589 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29592 \begin_layout Standard
29593 INT0 external interrupt
29598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29601 \begin_layout Standard
29607 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29610 \begin_layout Standard
29611 Bus collision interrupt
29617 <row topline="true">
29618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29621 \begin_layout Standard
29627 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29630 \begin_layout Standard
29631 INT1 external interrupt
29636 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29639 \begin_layout Standard
29645 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29648 \begin_layout Standard
29649 Low voltage detect interrupt
29655 <row topline="true">
29656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29659 \begin_layout Standard
29665 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29668 \begin_layout Standard
29669 INT2 external interrupt
29674 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29677 \begin_layout Standard
29683 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29686 \begin_layout Standard
29687 Parallel slave port interrupt
29693 <row topline="true">
29694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29697 \begin_layout Standard
29703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29706 \begin_layout Standard
29707 CCP1 module interrupt
29712 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29715 \begin_layout Standard
29721 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29724 \begin_layout Standard
29725 AD convertion complete interrupt
29731 <row topline="true">
29732 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29735 \begin_layout Standard
29741 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29744 \begin_layout Standard
29745 CCP2 module interrupt
29750 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29753 \begin_layout Standard
29759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29762 \begin_layout Standard
29763 USART receive interrupt
29769 <row topline="true">
29770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29773 \begin_layout Standard
29779 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29782 \begin_layout Standard
29783 TMR0 overflow interrupt
29788 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29791 \begin_layout Standard
29797 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29800 \begin_layout Standard
29801 USART transmit interrupt
29807 <row topline="true">
29808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29811 \begin_layout Standard
29817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29820 \begin_layout Standard
29821 TMR1 overflow interrupt
29826 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29829 \begin_layout Standard
29835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29838 \begin_layout Standard
29839 SSP receive/transmit interrupt
29845 <row topline="true">
29846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29849 \begin_layout Standard
29855 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29858 \begin_layout Standard
29859 TMR2 matches PR2 interrupt
29864 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29867 \begin_layout Standard
29873 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29876 \begin_layout Standard
29883 <row topline="true" bottomline="true">
29884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29887 \begin_layout Standard
29893 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29896 \begin_layout Standard
29897 TMR3 overflow interrupt
29902 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29905 \begin_layout Standard
29911 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29914 \begin_layout Standard
29928 \begin_layout Standard
29930 The prototypes for these names are defined in the header file
29937 \begin_layout Standard
29939 In order to simplify signal handling, a number of macros is provided:
29943 \labelwidthstring 00.00.0000
29944 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
29945 high priority interrupts.
29950 is the function name to use.
29954 \labelwidthstring 00.00.0000
29955 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
29956 low priority interrupt.
29961 is the function name to use.
29965 \labelwidthstring 00.00.0000
29966 DEF_HANDLER(sig,handler) define a handler for signal
29972 \labelwidthstring 00.00.0000
29973 END_DEF end the declaration of the dispatch table.
29976 \begin_layout Standard
29977 Additionally there are two more macros to simplify the declaration of the
29982 \labelwidthstring 00.00.0000
29985 SIGHANDLER(handler)
29987 this declares the function prototype for the
29995 \labelwidthstring 00.00.0000
29996 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
29999 \begin_layout Standard
30000 An example of using the macros above is shown below:
30003 \begin_layout LyX-Code
30004 #include <pic18fregs.h>
30007 \begin_layout LyX-Code
30008 #include <signal.h>
30012 DEF_INTHIGH(high_int)
30015 \begin_layout LyX-Code
30016 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
30019 \begin_layout LyX-Code
30020 DEF_HANDLER(SIG_BCOL, _bcol_handler)
30023 \begin_layout LyX-Code
30028 SIGHANDLER(_tmr0_handler)
30031 \begin_layout LyX-Code
30035 \begin_layout LyX-Code
30036 /* action to be taken when timer 0 overflows */
30039 \begin_layout LyX-Code
30044 SIGHANDLERNAKED(_bcol_handler)
30047 \begin_layout LyX-Code
30051 \begin_layout LyX-Code
30055 \begin_layout LyX-Code
30056 /* action to be taken when bus collision occurs */
30059 \begin_layout LyX-Code
30063 \begin_layout LyX-Code
30067 \begin_layout LyX-Code
30071 \begin_layout Standard
30076 Special care should be taken when using the above scheme:
30079 \begin_layout Itemize
30080 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
30083 \begin_layout Itemize
30084 when declaring SIGHANDLERNAKED handler never forget to use
30088 for proper returning.
30091 \begin_layout Subsection
30095 \begin_layout Standard
30096 Here you can find some general tips for compiling programs with SDCC/pic16.
30099 \begin_layout Subsubsection
30103 \begin_layout Standard
30105 \begin_inset LatexCommand index
30110 size (that is 64 bytes) probably is enough for many programs.
30111 One must take care that when there are many levels of function nesting,
30112 or there is excessive usage of stack, its size should be extended.
30113 An example of such a case is the printf/sprintf family of functions.
30114 If you encounter problems like not being able to print integers, then you
30115 need to set the stack size around the maximum (256 for small stack model).
30116 The following diagram shows what happens when calling printf to print an
30120 \begin_layout LyX-Code
30121 printf () --> ltoa () --> ultoa () --> divschar ()
30124 \begin_layout Standard
30125 It is should be understood that stack is easily consumed when calling complicate
30127 Using command line arguments like -
30131 \begin_layout Standard
30140 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
30142 Other ways to reduce stack usage may exist.
30145 \begin_layout Subsection
30149 \begin_layout Subsubsection
30150 Extended Instruction Set
30153 \begin_layout Standard
30154 The PIC16 port emits code which is incompatible with the extended instruction
30155 set available with many newer devices.
30156 Make sure to always explicitly disable it, usually using
30159 \begin_layout Standard
30162 static __code char __at(__CONFIG4L) conf4l = /* more flags & */ _XINST_OFF_4L;
30165 \begin_layout Standard
30167 Some devices (namely 18f2455, 18f2550, 18f4455, and 18f4550) use _ENHCPU_OFF_4L
30168 instead of _XINST_OFF_4L.
30171 \begin_layout Subsubsection
30175 \begin_layout Standard
30176 The PIC16 port currently passes most but not all of the tests in SDCC's
30178 \begin_inset LatexCommand index
30179 name "Regression test (PIC16)"
30184 \begin_inset LatexCommand ref
30185 reference "sec:Quality-control"
30189 ), thus no automatic regression tests are currently performed for the PIC16
30193 \begin_layout Chapter
30197 \begin_layout Standard
30198 There are several approaches to debugging your code.
30199 This chapter is meant to show your options and to give detail on some of
30204 When writing your code:
30207 \begin_layout Itemize
30208 write your code with debugging in mind (avoid duplicating code, put conceptually
30209 similar variables into structs, use structured code, have strategic points
30210 within your code where all variables are consistent, ...)
30213 \begin_layout Itemize
30214 run a syntax-checking tool like splint
30215 \begin_inset LatexCommand index
30216 name "splint (syntax checking tool)"
30221 \begin_inset LatexCommand index
30222 name "lint (syntax checking tool)"
30230 \begin_layout Standard
30240 \begin_inset LatexCommand ref
30241 reference "lyx:more-pedantic-SPLINT"
30248 \begin_layout Itemize
30249 for the high level code use a C-compiler (like f.e.
30250 GCC) to compile run and debug the code on your host.
30255 \begin_layout Standard
30265 \begin_inset LatexCommand ref
30266 reference "lyx:more-pedantic-SPLINT"
30270 ) on how to handle syntax extensions like __xdata, __at(), ...
30274 \begin_layout Itemize
30275 use another C-compiler to compile code for your target.
30276 Always an option but not recommended:) And not very likely to help you.
30277 If you seriously consider walking this path you should at least occasionally
30278 check portability of your code.
30279 Most commercial compiler vendors will offer an evaluation version so you
30280 can test compile your code or snippets of your code.
30283 \begin_layout Standard
30284 Debugging on a simulator:
30287 \begin_layout Itemize
30288 there is a separate section about SDCDB (section
30289 \begin_inset LatexCommand ref
30290 reference "cha:Debugging-with-SDCDB"
30297 \begin_layout Itemize
30298 or (8051 specific) use a free open source/commercial simulator which interfaces
30300 \begin_inset LatexCommand index
30301 name "AOMF, AOMF51"
30306 \begin_inset LatexCommand ref
30307 reference "OMF file"
30311 ) optionally generated by SDCC.
30314 \begin_layout Standard
30315 Debugging On-target:
30318 \begin_layout Itemize
30319 use a MCU port pin to serially output debug data to the RS232 port of your
30321 You'll probably want some level shifting device typically involving a MAX232
30323 If the hardware serial port of the MCU is not available search for 'Software
30324 UART' in your favourite search machine.
30327 \begin_layout Itemize
30328 use an on-target monitor.
30329 In this context a monitor is a small program which usually accepts commands
30330 via a serial line and allows to set program counter, to single step through
30331 a program and read/write memory locations.
30332 For the 8051 good examples of monitors are paulmon and cmon51 (see section
30334 \begin_inset LatexCommand ref
30335 reference "sec:Related-open-source-tools"
30342 \begin_layout Itemize
30343 toggle MCU port pins at strategic points within your code and use an oscilloscop
30347 digital oscilloscope
30350 \begin_inset LatexCommand index
30351 name "Oscilloscope"
30355 with deep trace memory is really helpful especially if you have to debug
30356 a realtime application.
30357 If you need to monitor more pins than your oscilloscope provides you can
30358 sometimes get away with a small R-2R network.
30359 On a single channel oscilloscope you could f.e.
30360 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
30362 \begin_inset Formula $\Omega$
30365 resistor and the other one by a 5\InsetSpace ~
30367 \begin_inset Formula $\Omega$
30370 resistor to the oscilloscope probe (check output drive capability of the
30371 pins you want to monitor).
30372 If you need to monitor many more pins a
30379 \begin_layout Itemize
30393 \begin_inset LatexCommand index
30394 name "ICE (in circuit emulator)"
30399 Usually very expensive.
30400 And very nice to have too.
30401 And usually locks you (for years...) to the devices the ICE can emulate.
30405 \begin_layout Itemize
30406 use a remote debugger.
30407 In most 8-bit systems the symbol information is not available on the target,
30408 and a complete debugger is too bulky for the target system.
30409 Therefore usually a debugger on the host system connects to an on-target
30410 debugging stub which accepts only primitive commands.
30413 Terms to enter into your favourite search engine could be 'remote debugging',
30414 'gdb stub' or 'inferior debugger'.
30418 \begin_layout Itemize
30419 use an on target hardware debugger.
30420 Some of the more modern MCUs include hardware support for setting break
30421 points and monitoring/changing variables by using dedicated hardware pins.
30422 This facility doesn't require additional code to run on the target and
30427 doesn't affect runtime behaviour until a breakpoint is hit.
30428 For the mcs51 most hardware debuggers use the AOMF
30429 \begin_inset LatexCommand index
30430 name "AOMF, AOMF51"
30435 \begin_inset LatexCommand ref
30436 reference "OMF file"
30444 \begin_layout Standard
30448 \begin_layout Itemize
30449 if you are not familiar with any of the following terms you're likely to
30450 run into problems rather sooner than later:
30467 As an embedded programmer you
30471 to know them so why not look them up
30475 you have problems?)
30478 \begin_layout Itemize
30479 tell someone else about your problem (actually this is a surprisingly effective
30480 means to hunt down the bug even if the listener is not familiar with your
30482 As 'failure to communicate' is probably one of the job-induced deformations
30483 of an embedded programmer this is highly encouraged.
30486 \begin_layout Section
30487 Debugging with SDCDB
30488 \begin_inset LatexCommand label
30489 name "cha:Debugging-with-SDCDB"
30494 \begin_inset LatexCommand index
30495 name "SDCDB (debugger)"
30502 \begin_layout Standard
30503 SDCC is distributed with a source level debugger
30504 \begin_inset LatexCommand index
30510 The debugger uses a command line interface, the command repertoire of the
30511 debugger has been kept as close to gdb
30512 \begin_inset LatexCommand index
30517 (the GNU debugger) as possible.
30518 The configuration and build process is part of the standard compiler installati
30519 on, which also builds and installs the debugger in the target directory
30520 specified during configuration.
30521 The debugger allows you debug BOTH at the C source and at the ASM source
30525 \begin_layout Subsection
30526 Compiling for Debugging
30529 \begin_layout Standard
30534 \begin_layout Standard
30544 \begin_inset LatexCommand index
30549 option must be specified for all files for which debug information is to
30551 The compiler generates a .adb file for each of these files.
30552 The linker creates the .cdb
30553 \begin_inset LatexCommand index
30559 \begin_inset LatexCommand index
30564 files and the address information.
30565 This .cdb is used by the debugger.
30568 \begin_layout Subsection
30569 How the Debugger Works
30572 \begin_layout Standard
30577 \begin_layout Standard
30586 -debug option is specified the compiler generates extra symbol information
30587 some of which are put into the assembler source and some are put into the
30589 Then the linker creates the .cdb file from the individual .adb files with
30590 the address information for the symbols.
30591 The debugger reads the symbolic information generated by the compiler &
30592 the address information generated by the linker.
30593 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
30594 execution is controlled by the debugger.
30595 When a command is issued for the debugger, it translates it into appropriate
30596 commands for the simulator.
30597 (Currently SDCDM only connects to the simulator but
30602 \begin_inset LatexCommand url
30603 target "http://ec2drv.sf.net/"
30607 is an effort to connect directly to the hardware.)
30610 \begin_layout Subsection
30611 Starting the Debugger SDCDB
30614 \begin_layout Standard
30615 The debugger can be started using the following command line.
30616 (Assume the file you are debugging has the file name foo).
30630 The debugger will look for the following files.
30633 \begin_layout Itemize
30634 foo.c - the source file.
30637 \begin_layout Itemize
30638 foo.cdb - the debugger symbol information file.
30641 \begin_layout Itemize
30642 foo.ihx - the Intel hex format
30643 \begin_inset LatexCommand index
30644 name "Intel hex format"
30651 \begin_layout Subsection
30652 SDCDB Command Line Options
30655 \begin_layout Itemize
30660 \begin_layout Standard
30669 -directory=<source file directory> this option can used to specify the directory
30671 The debugger will look into the directory list specified for source, cdb
30673 The items in the directory list must be separated by ':', e.g.
30674 if the source files can be in the directories /home/src1 and /home/src2,
30679 \begin_layout Standard
30688 -directory option should be -
30692 \begin_layout Standard
30701 -directory=/home/src1:/home/src2.
30702 Note there can be no spaces in the option.
30706 \begin_layout Itemize
30707 -cd <directory> - change to the <directory>.
30710 \begin_layout Itemize
30711 -fullname - used by GUI front ends.
30714 \begin_layout Itemize
30715 -cpu <cpu-type> - this argument is passed to the simulator please see the
30716 simulator docs for details.
30719 \begin_layout Itemize
30720 -X <Clock frequency > this options is passed to the simulator please see
30721 the simulator docs for details.
30724 \begin_layout Itemize
30725 -s <serial port file> passed to simulator see the simulator docs for details.
30728 \begin_layout Itemize
30729 -S <serial in,out> passed to simulator see the simulator docs for details.
30732 \begin_layout Itemize
30733 -k <port number> passed to simulator see the simulator docs for details.
30736 \begin_layout Subsection
30737 SDCDB Debugger Commands
30740 \begin_layout Standard
30741 As mentioned earlier the command interface for the debugger has been deliberatel
30742 y kept as close the GNU debugger gdb, as possible.
30743 This will help the integration with existing graphical user interfaces
30744 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
30745 If you use a graphical user interface for the debugger you can skip this
30749 \begin_layout Subsubsection*
30750 break [line | file:line | function | file:function]
30753 \begin_layout Standard
30754 Set breakpoint at specified line or function:
30763 sdcdb>break foo.c:100
30765 sdcdb>break funcfoo
30767 sdcdb>break foo.c:funcfoo
30770 \begin_layout Subsubsection*
30771 clear [line | file:line | function | file:function ]
30774 \begin_layout Standard
30775 Clear breakpoint at specified line or function:
30784 sdcdb>clear foo.c:100
30786 sdcdb>clear funcfoo
30788 sdcdb>clear foo.c:funcfoo
30791 \begin_layout Subsubsection*
30795 \begin_layout Standard
30796 Continue program being debugged, after breakpoint.
30799 \begin_layout Subsubsection*
30803 \begin_layout Standard
30804 Execute till the end of the current function.
30807 \begin_layout Subsubsection*
30811 \begin_layout Standard
30812 Delete breakpoint number 'n'.
30813 If used without any option clear ALL user defined break points.
30816 \begin_layout Subsubsection*
30817 info [break | stack | frame | registers ]
30820 \begin_layout Itemize
30821 info break - list all breakpoints
30824 \begin_layout Itemize
30825 info stack - show the function call stack.
30828 \begin_layout Itemize
30829 info frame - show information about the current execution frame.
30832 \begin_layout Itemize
30833 info registers - show content of all registers.
30836 \begin_layout Subsubsection*
30840 \begin_layout Standard
30841 Step program until it reaches a different source line.
30842 Note: pressing <return> repeats the last command.
30845 \begin_layout Subsubsection*
30849 \begin_layout Standard
30850 Step program, proceeding through subroutine calls.
30853 \begin_layout Subsubsection*
30857 \begin_layout Standard
30858 Start debugged program.
30861 \begin_layout Subsubsection*
30865 \begin_layout Standard
30866 Print type information of the variable.
30869 \begin_layout Subsubsection*
30873 \begin_layout Standard
30874 print value of variable.
30877 \begin_layout Subsubsection*
30881 \begin_layout Standard
30882 load the given file name.
30883 Note this is an alternate method of loading file for debugging.
30886 \begin_layout Subsubsection*
30890 \begin_layout Standard
30891 print information about current frame.
30894 \begin_layout Subsubsection*
30898 \begin_layout Standard
30899 Toggle between C source & assembly source.
30902 \begin_layout Subsubsection*
30903 ! simulator command
30906 \begin_layout Standard
30907 Send the string following '!' to the simulator, the simulator response is
30909 Note the debugger does not interpret the command being sent to the simulator,
30910 so if a command like 'go' is sent the debugger can loose its execution
30911 context and may display incorrect values.
30914 \begin_layout Subsubsection*
30918 \begin_layout Standard
30921 My name is Bobby Brown"
30924 \begin_layout Subsection
30925 Interfacing SDCDB with DDD
30928 \begin_layout Standard
30929 \begin_inset Note Note
30932 \begin_layout Standard
30933 The screenshot was converted from png to eps with:
30934 \begin_inset Quotes sld
30937 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
30938 \begin_inset Quotes srd
30941 which produces a pretty compact eps file which is free from compression
30945 \begin_layout Standard
30946 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
30947 as this broke the build system on Sourceforge (pdf-file was broken.
30948 pdflatex does not accept eps files).
30956 \begin_layout Standard
30972 \begin_inset LatexCommand url
30973 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png"
30979 shows a screenshot of a debugging session with DDD
30980 \begin_inset LatexCommand index
30981 name "DDD (debugger)"
30985 (Unix only) on a simulated 8032.
30986 The debugging session might not run as smoothly as the screenshot suggests.
30987 The debugger allows setting of breakpoints, displaying and changing variables,
30988 single stepping through C and assembler code.
30991 The source was compiled with
31005 \begin_layout Standard
31017 -debug ddd_example.c
31030 and DDD was invoked with
31037 ddd -debugger "sdcdb -cpu 8032 ddd_example"
31040 \begin_layout Standard
31041 \begin_inset Note Note
31044 \begin_layout Standard
31045 Check that the double quotes or an apostrophe within the command line survive
31046 the LyX tool chain.
31047 Previously the apostrophes got slanted in the PDF output so a cut and paste
31056 \begin_layout Subsection
31057 Interfacing SDCDB with XEmacs
31058 \begin_inset LatexCommand index
31064 \begin_inset LatexCommand index
31072 \begin_layout Standard
31073 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
31074 sdcdb.el and sdcdbsrc.el.
31075 These two files can be found in the $(prefix)/bin directory after the installat
31077 These files need to be loaded into XEmacs for the interface to work.
31078 This can be done at XEmacs startup time by inserting the following into
31079 your '.xemacs' file (which can be found in your HOME directory):
31085 (load-file sdcdbsrc.el)
31091 .xemacs is a lisp file so the () around the command is REQUIRED.
31092 The files can also be loaded dynamically while XEmacs is running, set the
31093 environment variable 'EMACSLOADPATH' to the installation bin directory
31094 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
31095 To start the interface enter the following command:
31109 You will prompted to enter the file name to be debugged.
31114 The command line options that are passed to the simulator directly are
31115 bound to default values in the file sdcdbsrc.el.
31116 The variables are listed below, these values maybe changed as required.
31119 \begin_layout Itemize
31120 sdcdbsrc-cpu-type '51
31123 \begin_layout Itemize
31124 sdcdbsrc-frequency '11059200
31127 \begin_layout Itemize
31128 sdcdbsrc-serial nil
31131 \begin_layout Standard
31132 The following is a list of key mapping for the debugger interface.
31135 \begin_layout Standard
31158 binding\InsetSpace ~
31196 -------\InsetSpace ~
31267 sdcdb-back-from-src\InsetSpace ~
31296 rom-src\InsetSpace ~
31306 SDCDB continue command
31324 sdcdb-step-from-src\InsetSpace ~
31353 hatis-c-sexp\InsetSpace ~
31363 SDCDB ptypecommand for data at
31430 sdcdbsrc-delete\InsetSpace ~
31445 B Delete all breakpoints if no arg
31494 given or delete arg (C-u arg x)
31513 -frame\InsetSpace ~
31528 SDCDB Display current frame if no arg,
31577 given or display frame arg
31645 sdcdbsrc-goto-sdcdb\InsetSpace ~
31655 Goto the SDCDB output buffer
31674 t-c-sexp\InsetSpace ~
31685 SDCDB print command for data at
31752 sdcdbsrc-goto-sdcdb\InsetSpace ~
31763 o the SDCDB output buffer
31781 sdcdbsrc-mode\InsetSpace ~
31797 Toggles Sdcdbsrc mode (turns it
31813 sdcdb-finish-from-src\InsetSpace ~
31821 SDCDB finish command
31855 Set break for line with point
31870 sdcdbsrc-mode\InsetSpace ~
31886 Toggle Sdcdbsrc mode
31902 dbsrc-srcmode\InsetSpace ~
31926 \begin_layout Chapter
31930 \begin_layout Standard
31931 Here are a few guidelines that will help the compiler generate more efficient
31932 code, some of the tips are specific to this compiler others are generally
31933 good programming practice.
31936 \begin_layout Itemize
31937 Use the smallest data type to represent your data-value.
31938 If it is known in advance that the value is going to be less than 256 then
31939 use an 'unsigned char' instead of a 'short' or 'int'.
31940 Please note, that ANSI C requires both signed and unsigned chars to be
31941 promoted to 'signed int'
31942 \begin_inset LatexCommand index
31943 name "promotion to signed int"
31948 \begin_inset Marginal
31951 \begin_layout Standard
31960 before doing any operation.
31962 \begin_inset LatexCommand index
31963 name "type promotion"
31968 \begin_inset LatexCommand label
31969 name "type promotion"
31973 can be omitted, if the result is the same.
31974 The effect of the promotion rules together with the sign-extension is often
31979 \begin_layout Verse
31982 unsigned char uc = 0xfe;
31984 if (uc * uc < 0) /* this is true! */
31997 \begin_layout Standard
32004 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
32012 \begin_layout Verse
32015 (unsigned char) -12 / (signed char) -3 = ...
32018 \begin_layout Standard
32019 No, the result is not 4:
32022 \begin_layout Verse
32025 (int) (unsigned char) -12 / (int) (signed char) -3 =
32027 (int) (unsigned char)
32028 0xf4 / (int) (signed char) 0xfd =
32030 (int) 0x00f4 / (int) 0xfffd =
32035 (int) 244 / (int) -3 =
32037 (int) -81 = (int) 0xffaf;
32040 \begin_layout Standard
32041 Don't complain, that gcc gives you a different result.
32042 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
32043 Therefore the results are different.
32046 \begin_inset Quotes sld
32050 \begin_inset Quotes srd
32056 \begin_layout Quote
32059 If well-defined overflow characteristics are important and negative values
32060 are not, or if you want to steer clear of sign-extension problems when
32061 manipulating bits or bytes, use one of the corresponding unsigned types.
32062 (Beware when mixing signed and unsigned values in expressions, though.)
32065 character types (especially unsigned char) can be used as "tiny" integers,
32066 doing so is sometimes more trouble than it's worth, due to unpredictable
32067 sign extension and increased code size.
32071 \begin_layout Itemize
32072 Use unsigned when it is known in advance that the value is not going to
32074 This helps especially if you are doing division or multiplication, bit-shifting
32075 or are using an array index.
32078 \begin_layout Itemize
32079 NEVER jump into a LOOP.
32082 \begin_layout Itemize
32083 Declare the variables to be local
32084 \begin_inset LatexCommand index
32085 name "local variables"
32089 whenever possible, especially loop control variables (induction).
32092 \begin_layout Itemize
32093 Have a look at the assembly listing to get a
32094 \begin_inset Quotes sld
32098 \begin_inset Quotes srd
32101 for the code generation.
32104 \begin_layout Section
32105 Porting code from or to other compilers
32106 \begin_inset LatexCommand label
32107 name "sec:Porting-code-to-other-compilers"
32114 \begin_layout Itemize
32115 check whether endianness of the compilers differs and adapt where needed.
32118 \begin_layout Itemize
32119 check the device specific header files
32120 \begin_inset LatexCommand index
32121 name "Header files"
32126 \begin_inset LatexCommand index
32127 name "Include files"
32131 for compiler specific syntax.
32132 Eventually include the file <compiler.h
32133 \begin_inset LatexCommand index
32134 name "compiler.h (include file)"
32139 \begin_inset LatexCommand url
32140 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup"
32144 to allow using common header files.
32147 \begin_inset LatexCommand url
32148 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup"
32155 \begin_layout Itemize
32156 check whether the startup code contains the correct initialization (watchdog,
32160 \begin_layout Itemize
32161 check whether the sizes of short, int, long match.
32164 \begin_layout Itemize
32165 check if some 16 or 32 bit hardware registers require a specific addressing
32166 order (least significant or most significant byte first) and adapt if needed
32175 relate to time and not to lower/upper memory location here, so this is
32180 the same as endianness).
32183 \begin_layout Itemize
32184 check whether the keyword
32188 is used where needed.
32189 The compilers might differ in their optimization characteristics (as different
32190 versions of the same compiler might also use more clever optimizations
32191 this is good idea anyway).
32193 \begin_inset LatexCommand ref
32194 reference "sub:Common-interrupt-pitfall-volatile"
32201 \begin_layout Itemize
32202 check that the compilers are not told to suppress warnings.
32205 \begin_layout Itemize
32206 check and convert compiler specific extensions (interrupts, memory areas,
32210 \begin_layout Itemize
32211 check for differences in type promotion.
32212 Especially check for math operations on
32221 For the sake of C99 compatibility SDCC will probably promote these to
32225 more often than other compilers.
32226 Eventually insert explicit casts to
32235 Also check that the ~\InsetSpace ~
32237 \begin_inset LatexCommand index
32238 name "\\~\\/ Operator"
32245 \begin_inset LatexCommand index
32252 variables, use the !\InsetSpace ~
32255 \begin_inset LatexCommand ref
32256 reference "type promotion"
32261 \begin_inset LatexCommand ref
32262 reference "sec:Compatibility-with-previous"
32269 \begin_layout Itemize
32270 check the assembly code generated for interrupt routines (f.e.
32271 for calls to possibly non-reentrant library functions).
32274 \begin_layout Itemize
32275 check whether timing loops result in proper timing (or preferably consider
32276 a rewrite of the code with timer based delays instead).
32279 \begin_layout Itemize
32280 check for differences in printf parameters (some compilers push (va_arg
32281 \begin_inset LatexCommand index
32282 name "vararg, va\\_arg"
32286 ) char variables as
32290 others push them as
32296 \begin_inset LatexCommand ref
32297 reference "sec:Compatibility-with-previous"
32304 \begin_layout Itemize
32305 check the resulting memory map
32306 \begin_inset LatexCommand index
32312 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
32313 ly idata, pdata, xdata).
32314 Eventually check if unexpected library functions are included.
32317 \begin_layout Section
32319 \begin_inset LatexCommand index
32324 included in the distribution
32327 \begin_layout Standard
32329 \begin_inset Tabular
32330 <lyxtabular version="3" rows="12" columns="3">
32332 <column alignment="left" valignment="top" leftline="true" width="0pt">
32333 <column alignment="left" valignment="top" leftline="true" width="0pt">
32334 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32335 <row topline="true" bottomline="true">
32336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32339 \begin_layout Standard
32347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32350 \begin_layout Standard
32358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32361 \begin_layout Standard
32370 <row topline="true">
32371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32374 \begin_layout Standard
32376 \begin_inset LatexCommand index
32386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32389 \begin_layout Standard
32390 Simulator for various architectures
32395 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32398 \begin_layout Standard
32405 <row topline="true">
32406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32409 \begin_layout Standard
32415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32418 \begin_layout Standard
32420 \begin_inset LatexCommand index
32421 name "Header files"
32426 \begin_inset LatexCommand index
32427 name "Include files"
32436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32439 \begin_layout Standard
32440 sdcc/support/scripts
32446 <row topline="true">
32447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32450 \begin_layout Standard
32456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32459 \begin_layout Standard
32460 header file conversion
32465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32468 \begin_layout Standard
32469 sdcc/support/scripts
32475 <row topline="true">
32476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32479 \begin_layout Standard
32485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32488 \begin_layout Standard
32494 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32497 \begin_layout Standard
32513 <row topline="true">
32514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32517 \begin_layout Standard
32523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32526 \begin_layout Standard
32532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32535 \begin_layout Standard
32551 <row topline="true">
32552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32555 \begin_layout Standard
32561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32564 \begin_layout Standard
32570 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32573 \begin_layout Standard
32589 <row topline="true">
32590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32593 \begin_layout Standard
32599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32602 \begin_layout Standard
32608 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32611 \begin_layout Standard
32627 <row topline="true">
32628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32631 \begin_layout Standard
32637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32640 \begin_layout Standard
32646 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32649 \begin_layout Standard
32665 <row topline="true">
32666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32669 \begin_layout Standard
32675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32678 \begin_layout Standard
32684 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32687 \begin_layout Standard
32703 <row topline="true">
32704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32707 \begin_layout Standard
32713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32716 \begin_layout Standard
32722 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32725 \begin_layout Standard
32741 <row topline="true" bottomline="true">
32742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32745 \begin_layout Standard
32751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32754 \begin_layout Standard
32756 \begin_inset LatexCommand index
32757 name "packihx (tool)"
32766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32769 \begin_layout Standard
32794 \begin_layout Section
32796 \begin_inset LatexCommand index
32797 name "Documentation"
32801 included in the distribution
32804 \begin_layout Standard
32806 \begin_inset Tabular
32807 <lyxtabular version="3" rows="10" columns="2">
32809 <column alignment="block" valignment="top" leftline="true" width="40col%">
32810 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
32811 <row topline="true" bottomline="true" endhead="true">
32812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32815 \begin_layout Standard
32823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32826 \begin_layout Standard
32829 Filename / Where to get
32835 <row topline="true">
32836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32839 \begin_layout Standard
32840 SDCC Compiler User Guide
32845 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32848 \begin_layout Standard
32849 You're reading it right now
32861 \begin_inset LatexCommand url
32862 target "http://sdcc.sourceforge.net/doc/sdccman.pdf"
32872 <row topline="true">
32873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32876 \begin_layout Standard
32882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32885 \begin_layout Standard
32898 \begin_inset LatexCommand url
32899 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog"
32909 <row topline="true">
32910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32913 \begin_layout Standard
32915 \begin_inset LatexCommand index
32916 name "asXXXX (as-gbz80, as-hc08, asx8051, as-z80)"
32921 \begin_inset LatexCommand index
32922 name "Assembler documentation"
32929 \begin_inset LatexCommand index
32935 \begin_inset LatexCommand index
32936 name "Linker documentation"
32945 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32948 \begin_layout Standard
32949 sdcc/as/doc/asxhtm.html
32961 \begin_inset LatexCommand url
32962 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html"
32972 <row topline="true">
32973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32976 \begin_layout Standard
32977 SDCC regression test
32978 \begin_inset LatexCommand index
32979 name "Regression test"
32988 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32991 \begin_layout Standard
32992 sdcc/doc/test_suite_spec.pdf
33004 \begin_inset LatexCommand url
33005 target "http://sdcc.sourceforge.net/doc/test_suite_spec.pdf"
33015 <row topline="true">
33016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33019 \begin_layout Standard
33025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33028 \begin_layout Standard
33041 \begin_inset LatexCommand url
33042 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/"
33052 <row topline="true">
33053 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33056 \begin_layout Standard
33057 Notes on debugging with SDCDB
33058 \begin_inset LatexCommand index
33059 name "SDCDB (debugger)"
33068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33071 \begin_layout Standard
33072 sdcc/debugger/README
33084 \begin_inset LatexCommand url
33085 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README"
33095 <row topline="true">
33096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33099 \begin_layout Standard
33101 \begin_inset LatexCommand index
33106 Software simulator for microcontrollers
33111 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33114 \begin_layout Standard
33144 \begin_inset LatexCommand url
33145 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html"
33155 <row topline="true">
33156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33159 \begin_layout Standard
33160 Temporary notes on the pic16
33161 \begin_inset LatexCommand index
33171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33174 \begin_layout Standard
33175 sdcc/src/pic16/NOTES
33187 \begin_inset LatexCommand url
33188 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES"
33198 <row topline="true" bottomline="true">
33199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33202 \begin_layout Standard
33203 SDCC internal documentation (debugging file format)
33208 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33211 \begin_layout Standard
33241 \begin_inset LatexCommand url
33242 target "http://sdcc.sourceforge.net/doc/cdbfileformat.pdf"
33261 \begin_layout Section
33262 Related open source tools
33263 \begin_inset LatexCommand label
33264 name "sec:Related-open-source-tools"
33269 \begin_inset LatexCommand index
33270 name "Related tools"
33277 \begin_layout Standard
33279 \begin_inset Tabular
33280 <lyxtabular version="3" rows="16" columns="3">
33282 <column alignment="left" valignment="top" leftline="true" width="0pt">
33283 <column alignment="block" valignment="top" leftline="true" width="30line%">
33284 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
33285 <row topline="true" bottomline="true">
33286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33289 \begin_layout Standard
33297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33300 \begin_layout Standard
33308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33311 \begin_layout Standard
33320 <row topline="true">
33321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33324 \begin_layout Standard
33326 \begin_inset LatexCommand index
33327 name "gpsim (pic simulator)"
33336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33339 \begin_layout Standard
33345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33348 \begin_layout Standard
33349 \begin_inset LatexCommand url
33350 target "http://www.dattalo.com/gnupic/gpsim.html"
33360 <row topline="true">
33361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33364 \begin_layout Standard
33366 \begin_inset LatexCommand index
33367 name "gputils (pic tools)"
33376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33379 \begin_layout Standard
33385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33388 \begin_layout Standard
33389 \begin_inset LatexCommand url
33390 target "http://sourceforge.net/projects/gputils"
33400 <row topline="true">
33401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33404 \begin_layout Standard
33410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33413 \begin_layout Standard
33419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33422 \begin_layout Standard
33423 \begin_inset LatexCommand url
33424 target "http://freshmeat.net/projects/flp5/"
33434 <row topline="true">
33435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33438 \begin_layout Standard
33444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33447 \begin_layout Standard
33448 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
33454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33457 \begin_layout Standard
33458 \begin_inset LatexCommand url
33459 target "http://sourceforge.net/projects/ec2drv"
33469 <row topline="true">
33470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33473 \begin_layout Standard
33475 \begin_inset LatexCommand index
33476 name "indent (source formatting tool)"
33485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33488 \begin_layout Standard
33489 Formats C source - Master of the white spaces
33494 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33497 \begin_layout Standard
33498 \begin_inset LatexCommand url
33499 target "http://directory.fsf.org/GNU/indent.html"
33509 <row topline="true">
33510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33513 \begin_layout Standard
33515 \begin_inset LatexCommand index
33516 name "srecord (bin, hex, ... tool)"
33525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33528 \begin_layout Standard
33529 Object file conversion, checksumming, ...
33534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33537 \begin_layout Standard
33538 \begin_inset LatexCommand url
33539 target "http://sourceforge.net/projects/srecord"
33549 <row topline="true">
33550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33553 \begin_layout Standard
33555 \begin_inset LatexCommand index
33556 name "objdump (tool)"
33565 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33568 \begin_layout Standard
33569 Object file conversion, ...
33574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33577 \begin_layout Standard
33578 Part of binutils (should be there anyway)
33584 <row topline="true">
33585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33588 \begin_layout Standard
33594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33597 \begin_layout Standard
33598 8051 monitor (hex up-/download, single step, disassemble)
33603 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33606 \begin_layout Standard
33607 \begin_inset LatexCommand url
33608 target "http://sourceforge.net/projects/cmon51"
33618 <row topline="true">
33619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33622 \begin_layout Standard
33624 \begin_inset LatexCommand index
33625 name "doxygen (source documentation tool)"
33634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33637 \begin_layout Standard
33638 Source code documentation system
33643 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33646 \begin_layout Standard
33647 \begin_inset LatexCommand url
33648 target "http://www.doxygen.org"
33658 <row topline="true">
33659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33662 \begin_layout Standard
33668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33671 \begin_layout Standard
33672 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
33677 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33680 \begin_layout Standard
33681 \begin_inset LatexCommand url
33682 target "http://www.kdevelop.org"
33692 <row topline="true">
33693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33696 \begin_layout Standard
33702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33705 \begin_layout Standard
33706 8051 monitor (hex up-/download, single step, disassemble)
33711 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33714 \begin_layout Standard
33715 \begin_inset LatexCommand url
33716 target "http://www.pjrc.com/tech/8051/paulmon2.html"
33726 <row topline="true">
33727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33730 \begin_layout Standard
33732 \begin_inset LatexCommand index
33733 name "splint (syntax checking tool)"
33742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33745 \begin_layout Standard
33746 Statically checks c sources (see
33747 \begin_inset LatexCommand ref
33748 reference "lyx:more-pedantic-SPLINT"
33757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33760 \begin_layout Standard
33761 \begin_inset LatexCommand url
33762 target "http://www.splint.org"
33772 <row topline="true" bottomline="true">
33773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33776 \begin_layout Standard
33778 \begin_inset LatexCommand index
33779 name "DDD (debugger)"
33788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33791 \begin_layout Standard
33792 Debugger, serves nicely as GUI to SDCDB
33793 \begin_inset LatexCommand index
33794 name "SDCDB (debugger)"
33803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33806 \begin_layout Standard
33807 \begin_inset LatexCommand url
33808 target "http://www.gnu.org/software/ddd/"
33818 <row bottomline="true">
33819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33822 \begin_layout Standard
33824 \begin_inset LatexCommand index
33830 \begin_inset LatexCommand index
33831 name "d52 (disassembler)"
33840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33843 \begin_layout Standard
33844 Disassembler, can count instruction cycles
33845 \begin_inset LatexCommand index
33846 name "instruction cycles (count)"
33850 , use with options -pnd
33855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33858 \begin_layout Standard
33859 \begin_inset LatexCommand url
33860 target "http://www.8052.com/users/disasm/"
33870 <row bottomline="true">
33871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33874 \begin_layout Standard
33876 \begin_inset LatexCommand index
33886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33889 \begin_layout Standard
33890 Cross platform build system, generates Makefiles
33891 \begin_inset LatexCommand index
33896 and project workspaces
33897 \begin_inset LatexCommand index
33898 name "project workspace"
33907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33910 \begin_layout Standard
33911 \begin_inset LatexCommand url
33912 target "http://www.cmake.org"
33920 and a dedicated wiki entry:
33921 \begin_inset LatexCommand url
33922 target "http://www.cmake.org/Wiki/CmakeSdcc"
33941 \begin_layout Section
33942 Related documentation / recommended reading
33945 \begin_layout Standard
33947 \begin_inset Tabular
33948 <lyxtabular version="3" rows="7" columns="3">
33950 <column alignment="left" valignment="top" leftline="true" width="0pt">
33951 <column alignment="left" valignment="top" leftline="true" width="0">
33952 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
33953 <row topline="true" bottomline="true">
33954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33957 \begin_layout Standard
33965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33968 \begin_layout Standard
33976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33979 \begin_layout Standard
33988 <row topline="true">
33989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33992 \begin_layout Standard
34007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34010 \begin_layout Standard
34012 \begin_inset LatexCommand index
34013 name "C Reference card"
34022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34025 \begin_layout Standard
34026 \begin_inset LatexCommand url
34027 target "http://refcards.com/refcards/c/index.html"
34037 <row topline="true">
34038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34041 \begin_layout Standard
34047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34050 \begin_layout Standard
34052 \begin_inset LatexCommand index
34062 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34065 \begin_layout Standard
34066 \begin_inset LatexCommand url
34067 target "http://www.c-faq.com"
34077 <row topline="true">
34078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34081 \begin_layout Standard
34087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34090 \begin_layout Standard
34091 \begin_inset Quotes sld
34095 \begin_inset Quotes srd
34103 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34106 \begin_layout Standard
34109 \begin_inset LatexCommand url
34110 target "http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899"
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
34137 Extensions for Embedded C
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/docs/n1021.pdf"
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 Latest datasheet of target CPU
34182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34185 \begin_layout Standard
34192 <row topline="true" bottomline="true">
34193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34196 \begin_layout Standard
34202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34205 \begin_layout Standard
34206 Revision history of datasheet
34211 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34214 \begin_layout Standard
34230 \begin_layout Section
34231 Application notes specifically for SDCC
34234 \begin_layout Standard
34235 SDCC makes no claims about the completeness of this list and about up-to-datenes
34236 s or correctness of the application notes
34237 \begin_inset LatexCommand index
34238 name "Application notes"
34245 \begin_layout Standard
34249 \begin_inset Tabular
34250 <lyxtabular version="3" rows="7" columns="3">
34252 <column alignment="block" valignment="top" leftline="true" width="17col%">
34253 <column alignment="block" valignment="top" leftline="true" width="27col%">
34254 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
34255 <row topline="true" bottomline="true">
34256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34259 \begin_layout Standard
34268 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
34271 \begin_layout Standard
34280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34283 \begin_layout Standard
34293 <row topline="true">
34294 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34297 \begin_layout Standard
34305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34308 \begin_layout Standard
34311 Using the SDCC Compiler for the DS80C400
34312 \begin_inset LatexCommand index
34322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34325 \begin_layout Standard
34328 \begin_inset LatexCommand url
34329 target "http://pdfserv.maxim-ic.com/en/an/AN3346.pdf"
34339 <row topline="true">
34340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34343 \begin_layout Standard
34351 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
34354 \begin_layout Standard
34357 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
34358 \begin_inset LatexCommand index
34363 Family of Microcontrollers
34368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34371 \begin_layout Standard
34374 \begin_inset LatexCommand url
34375 target "http://pdfserv.maxim-ic.com/en/an/AN3477.pdf"
34385 <row topline="true">
34386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34389 \begin_layout Standard
34392 Silicon Laboratories / Cygnal
34397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34400 \begin_layout Standard
34403 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
34404 \begin_inset LatexCommand index
34414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34417 \begin_layout Standard
34420 \begin_inset LatexCommand url
34421 target "http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf"
34431 <row topline="true">
34432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34435 \begin_layout Standard
34438 Ramtron / Goal Semiconductor
34443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34446 \begin_layout Standard
34449 Interfacing SDCC to Syn and Textpad
34454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34457 \begin_layout Standard
34460 \begin_inset LatexCommand url
34461 target "http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp"
34471 <row topline="true">
34472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34475 \begin_layout Standard
34478 Ramtron / Goal Semiconductor
34483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34486 \begin_layout Standard
34489 Installing and Configuring SDCC and Crimson Editor
34494 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34497 \begin_layout Standard
34500 \begin_inset LatexCommand url
34501 target "http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp"
34511 <row topline="true" bottomline="true">
34512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34515 \begin_layout Standard
34523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34526 \begin_layout Standard
34529 MSC12xx Programming with SDCC
34534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34537 \begin_layout Standard
34540 \begin_inset LatexCommand url
34541 target "http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf"
34558 \begin_layout Section
34562 \begin_layout Standard
34563 Some questions answered, some pointers given - it might be time to in turn
34571 \begin_layout Itemize
34572 can you solve your project with the selected microcontroller? Would you
34573 find out early or rather late that your target is too small/slow/whatever?
34574 Can you switch to a slightly better device if it doesn't fit?
34577 \begin_layout Itemize
34578 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
34579 and/or another programming language be more adequate? Would an operating
34580 system on the target device help?
34583 \begin_layout Itemize
34584 if you solved the problem, will the marketing department be happy?
34587 \begin_layout Itemize
34588 if the marketing department is happy, will customers be happy?
34591 \begin_layout Itemize
34592 if you're the project manager, marketing department and maybe even the customer
34593 in one person, have you tried to see the project from the outside?
34596 \begin_layout Itemize
34597 is the project done if you think it is done? Or is just that other interface/pro
34598 tocol/feature/configuration/option missing? How about website, manual(s),
34599 internationali(z|s)ation, packaging, labels, 2nd source for components,
34600 electromagnetic compatability/interference, documentation for production,
34601 production test software, update mechanism, patent issues?
34604 \begin_layout Itemize
34605 is your project adequately positioned in that magic triangle: fame, fortune,
34609 \begin_layout Standard
34610 Maybe not all answers to these questions are known and some answers may
34615 , nevertheless knowing these questions may help you to avoid burnout
34619 \begin_layout Standard
34620 burnout is bad for electronic devices, programmers and motorcycle tyres
34626 Chances are you didn't want to hear some of them...
34629 \begin_layout Chapter
34631 \begin_inset LatexCommand index
34639 \begin_layout Standard
34640 SDCC has grown to be a large project.
34641 The compiler alone (without the preprocessor, assembler and linker) is
34642 well over 150,000 lines of code (blank stripped).
34643 The open source nature of this project is a key to its continued growth
34645 You gain the benefit and support of many active software developers and
34647 Is SDCC perfect? No, that's why we need your help.
34648 The developers take pride in fixing reported bugs.
34649 You can help by reporting the bugs and helping other SDCC users.
34650 There are lots of ways to contribute, and we encourage you to take part
34651 in making SDCC a great software package.
34655 \begin_layout Standard
34656 The SDCC project is hosted on the SDCC sourceforge site at
34657 \begin_inset LatexCommand htmlurl
34658 target "http://sourceforge.net/projects/sdcc"
34663 You'll find the complete set of mailing lists
34664 \begin_inset LatexCommand index
34665 name "Mailing list(s)"
34669 , forums, bug reporting system, patch submission
34670 \begin_inset LatexCommand index
34671 name "Patch submission"
34676 \begin_inset LatexCommand index
34681 area and Subversion code repository
34682 \begin_inset LatexCommand index
34683 name "Subversion code repository"
34690 \begin_layout Section
34692 \begin_inset LatexCommand index
34693 name "Bug reporting"
34698 \begin_inset LatexCommand index
34699 name "Reporting bugs"
34706 \begin_layout Standard
34707 The recommended way of reporting bugs is using the infrastructure of the
34709 You can follow the status of bug reports there and have an overview about
34713 \begin_layout Standard
34714 Bug reports are automatically forwarded to the developer mailing list and
34715 will be fixed ASAP.
34716 When reporting a bug, it is very useful to include a small test program
34717 (the smaller the better) which reproduces the problem.
34718 If you can isolate the problem by looking at the generated assembly code,
34719 this can be very helpful.
34720 Compiling your program with the -
34724 \begin_layout Standard
34734 \begin_inset LatexCommand index
34735 name "-\\/-dumpall"
34739 option can sometimes be useful in locating optimization problems.
34740 When reporting a bug please make sure you:
34743 \begin_layout Enumerate
34744 Attach the code you are compiling with SDCC.
34748 \begin_layout Enumerate
34749 Specify the exact command you use to run SDCC, or attach your Makefile.
34753 \begin_layout Enumerate
34754 Specify the SDCC version (type "
34760 "), your platform, and operating system.
34764 \begin_layout Enumerate
34765 Provide an exact copy of any error message or incorrect output.
34769 \begin_layout Enumerate
34770 Put something meaningful in the subject of your message.
34773 \begin_layout Standard
34774 Please attempt to include these 5 important parts, as applicable, in all
34775 requests for support or when reporting any problems or bugs with SDCC.
34776 Though this will make your message lengthy, it will greatly improve your
34777 chance that SDCC users and developers will be able to help you.
34778 Some SDCC developers are frustrated by bug reports without code provided
34779 that they can use to reproduce and ultimately fix the problem, so please
34780 be sure to provide sample code if you are reporting a bug!
34783 \begin_layout Standard
34784 Please have a short check that you are using a recent version of SDCC and
34785 the bug is not yet known.
34786 This is the link for reporting bugs:
34787 \begin_inset LatexCommand htmlurl
34788 target "http://sourceforge.net/tracker/?group_id=599&atid=100599"
34793 With SDCC on average having more than 200 downloads
34794 \begin_inset LatexCommand index
34799 on sourceforge per day
34803 \begin_layout Standard
34804 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
34805 between 2002 and 2005.
34806 This does not include other methods of distribution.
34811 there must be some users.
34812 So it's not exactly easy to find a new bug.
34813 If you find one we need it:
34815 reporting bugs is good
34820 \begin_layout Section
34821 Requesting Features
34822 \begin_inset LatexCommand label
34823 name "sub:Requesting-Features"
34828 \begin_inset LatexCommand index
34829 name "Feature request"
34834 \begin_inset LatexCommand index
34835 name "Requesting features"
34842 \begin_layout Standard
34843 Like bug reports feature requests are forwarded to the developer mailing
34845 This is the link for requesting features:
34846 \begin_inset LatexCommand htmlurl
34847 target "http://sourceforge.net/tracker/?group_id=599&atid=350599"
34854 \begin_layout Section
34858 \begin_layout Standard
34859 Like bug reports contributed patches are forwarded to the developer mailing
34861 This is the link for submitting patches
34862 \begin_inset LatexCommand index
34863 name "Patch submission"
34868 \begin_inset LatexCommand url
34869 target "http://sourceforge.net/tracker/?group_id=599&atid=300599"
34876 \begin_layout Standard
34877 You need to specify some parameters to the
34881 command for the patches to be useful.
34882 If you modified more than one file a patch created f.e.
34887 \begin_inset Quotes sld
34890 diff -Naur unmodified_directory modified_directory >my_changes.patch
34891 \begin_inset Quotes srd
34897 will be fine, otherwise
34901 \begin_inset Quotes sld
34904 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
34905 \begin_inset Quotes srd
34914 \begin_layout Section
34918 \begin_layout Standard
34919 These links should take you directly to the
34920 \begin_inset LatexCommand url
34921 name "Mailing lists"
34922 target "http://sourceforge.net/mail/?group_id=599"
34930 \begin_layout Standard
34931 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
34932 automated messages (mid 2003)
34938 \begin_inset LatexCommand url
34940 target "http://sourceforge.net/forum/?group_id=599"
34945 \begin_inset LatexCommand index
34946 name "Mailing list(s)"
34950 and forums are archived and searchable so if you are lucky someone already
34951 had a similar problem.
34952 While mails to the lists themselves are delivered promptly their web front
34953 end on sourceforge sometimes shows a severe time lag (up to several weeks),
34954 if you're seriously using SDCC please consider subscribing to the lists.
34957 \begin_layout Section
34961 \begin_layout Standard
34962 You can follow the status of the Subversion version
34963 \begin_inset LatexCommand index
34968 of SDCC by watching the Changelog
34969 \begin_inset LatexCommand index
34974 in the Subversion repository
34977 \begin_inset LatexCommand htmlurl
34978 target "http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog"
34985 \begin_layout Section
34986 Subversion Source Code Repository
34989 \begin_layout Standard
34999 \begin_layout Standard
35013 or the filenames of the snapshot versions of SDCC include date and its
35015 \begin_inset LatexCommand index
35016 name "Subversion code repository"
35021 Subversion allows to download the source of recent or previous versions
35023 \begin_inset LatexCommand url
35024 target "http://sourceforge.net/svn/?group_id=599"
35028 (by number or by date).
35029 An on-line source code browser and detailled instructions are also available
35031 SDCC versions starting from 1999 up to now are available (currently the
35032 versions prior to the conversion from cvs
35033 \begin_inset LatexCommand index
35034 name "cvs|see{Subversion}"
35038 to Subversion (April 2006) are either by accessible by Subversion or by
35042 \begin_layout Section
35044 \begin_inset LatexCommand index
35045 name "Release policy"
35052 \begin_layout Standard
35053 Historically there often were long delays between official releases and
35054 the sourceforge download area tends to get not updated at all.
35055 Excuses in the past might have referred to problems with live range analysis,
35056 but as this was fixed a while ago, the current problem is that another
35057 excuse has to be found.
35058 Kidding aside, we have to get better there! On the other hand there are
35059 daily snapshots available at
35060 \begin_inset LatexCommand htmlurl
35062 target "http://sdcc.sourceforge.net/snap.php"
35066 , and you can always build the very last version (hopefully with many bugs
35067 fixed, and features added) from the source code available at
35068 \begin_inset LatexCommand htmlurl
35070 target "http://sdcc.sourceforge.net/snap.php#Source"
35076 \begin_inset LatexCommand index
35082 \begin_inset LatexCommand index
35088 \begin_inset LatexCommand url
35089 target "http://sdcc.wiki.sourceforge.net/"
35093 also holds some information about past and future releases.
35096 \begin_layout Section
35098 \begin_inset LatexCommand index
35106 \begin_layout Standard
35107 You'll find some small examples in the directory
35109 sdcc/device/examples/.
35112 More examples and libraries are available at
35114 The SDCC Open Knowledge Resource
35115 \begin_inset LatexCommand url
35116 target "http://sdccokr.dl9sec.de/"
35123 \begin_inset LatexCommand url
35124 target "http://www.pjrc.com/tech/8051/"
35131 \begin_layout Standard
35132 \begin_inset Note Note
35135 \begin_layout Standard
35136 I did insert a reference to Paul's web site here although it seems rather
35137 dedicated to a specific 8032 board (I think it's okay because it f.e.
35138 shows LCD/Harddisc interface and has a free 8051 monitor.
35139 Independent 8032 board vendors face hard competition of heavily subsidized
35140 development boards anyway).
35143 \begin_layout Standard
35144 Maybe we should include some links to real world applications.
35145 Preferably pointer to pointers (one for each architecture) so this stays
35154 \begin_layout Section
35156 \begin_inset LatexCommand label
35157 name "sec:Quality-control"
35162 \begin_inset LatexCommand index
35163 name "Quality control"
35170 \begin_layout Standard
35171 The compiler is passed through snaphot build compile and build checks.
35177 \begin_inset LatexCommand index
35178 name "Regression test"
35182 check that SDCC itself compiles flawlessly on several host platforms (i386,
35183 Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
35184 and checks the quality of the code generated by SDCC by running the code
35185 for several target platforms through simulators.
35186 The regression test suite comprises more than 100 files which expand to
35187 more than 500 test cases which include more than 4500 tests.
35188 The results of these tests are published daily on SDCC's snapshot page
35189 (click on the red or green symbols on the right side of
35190 \begin_inset LatexCommand url
35191 target "http://sdcc.sourceforge.net/snap.php"
35198 \begin_layout Standard
35199 There is a separate document
35202 \begin_inset LatexCommand index
35210 \begin_inset LatexCommand url
35211 target "http://sdcc.sourceforge.net/doc/test_suite_spec.pdf"
35215 about the regression test suite.
35218 \begin_layout Standard
35219 You'll find the test code in the directory
35221 sdcc/support/regression
35224 You can run these tests manually by running
35228 in this directory (or f.e.
35233 \begin_inset Quotes sld
35237 \begin_inset Quotes srd
35243 if you don't want to run the complete tests).
35244 The test code might also be interesting if you want to look for examples
35245 \begin_inset LatexCommand index
35250 checking corner cases of SDCC or if you plan to submit patches
35251 \begin_inset LatexCommand index
35252 name "Patch submission"
35259 \begin_layout Standard
35260 The PIC14 port uses a different set of regression tests
35261 \begin_inset LatexCommand index
35262 name "Regression test (PIC14)"
35266 , you'll find them in the directory
35268 sdcc/src/regression
35273 \begin_layout Section
35274 Use of SDCC in Education
35277 \begin_layout Standard
35286 \begin_layout Standard
35287 the phrase "use in education" might evoke the association "
35291 fit for use in education".
35292 This connotation is not intended but nevertheless risked as the licensing
35293 of SDCC makes it difficult to offer educational discounts
35299 If your rationales are to:
35302 \begin_layout Enumerate
35303 give students a chance to understand the
35307 steps of code generation
35310 \begin_layout Enumerate
35311 have a curriculum that can be extended for years.
35312 Then you could use an fpga board as target and your curriculum will seamlessly
35313 extend from logic synthesis (
35314 \begin_inset LatexCommand url
35315 name "http://www.opencores.org"
35316 target "opencores.org"
35321 \begin_inset LatexCommand url
35323 target "http://www.oregano.at/ip/ip01.htm"
35327 ), over assembly programming, to C to FPGA compilers (
35328 \begin_inset LatexCommand url
35330 target "http://sf.net/projects/fpgac"
35337 \begin_layout Enumerate
35338 be able to insert excursions about skills like using a revision control
35339 system, submitting/applying patches, using a type-setting (as opposed to
35340 word-processing) engine LyX/LaTeX, using
35341 \begin_inset LatexCommand url
35343 target "http://www.sf.net"
35348 \begin_inset LatexCommand url
35350 target "http://en.wikipedia.org/wiki/Netiquette"
35354 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
35355 Source Software, CPU simulation, compiler regression tests
35356 \begin_inset LatexCommand index
35357 name "Regression test"
35364 And if there should be a shortage of ideas then you can always point students
35365 to the ever-growing feature request list
35366 \begin_inset LatexCommand htmlurl
35367 target "http://sourceforge.net/tracker/?group_id=599&atid=350599"
35374 \begin_layout Enumerate
35375 not tie students to a specific host platform and instead allow them to use
35380 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
35382 \begin_inset LatexCommand url
35384 target "http://www.laptop.org"
35391 \begin_layout Enumerate
35392 not encourage students to use illegal copies of educational software
35395 \begin_layout Enumerate
35396 be immune to licensing/availability/price changes of the chosen tool chain
35399 \begin_layout Enumerate
35400 be able to change to a new target platform without having to adopt a new
35404 \begin_layout Enumerate
35405 have complete control over and insight into the tool chain
35408 \begin_layout Enumerate
35409 make your students aware about the pros and cons of open source software
35413 \begin_layout Enumerate
35414 give back to the public as you are probably at least partially publicly
35418 \begin_layout Enumerate
35419 give students a chance to publicly prove their skills and to possibly see
35420 a world wide impact
35423 \begin_layout Standard
35424 then SDCC is probably among the first choices.
35425 Well, probably SDCC might be the only choice.
35430 \begin_layout Chapter
35431 SDCC Technical Data
35434 \begin_layout Section
35436 \begin_inset LatexCommand index
35437 name "Optimizations"
35444 \begin_layout Standard
35445 SDCC performs a host of standard optimizations in addition to some MCU specific
35450 \begin_layout Subsection
35451 Sub-expression Elimination
35452 \begin_inset LatexCommand index
35453 name "Subexpression elimination"
35460 \begin_layout Standard
35461 The compiler does local and
35480 \begin_layout Verse
35488 \begin_layout Standard
35489 will be translated to
35492 \begin_layout Verse
35502 \begin_layout Standard
35503 Some subexpressions are not as obvious as the above example, e.g.:
35506 \begin_layout Verse
35514 \begin_layout Standard
35515 In this case the address arithmetic a->b[i] will be computed only once;
35516 the equivalent code in C would be.
35519 \begin_layout Verse
35529 \begin_layout Standard
35530 The compiler will try to keep these temporary variables in registers.
35533 \begin_layout Subsection
35534 Dead-Code Elimination
35535 \begin_inset LatexCommand index
35536 name "Dead-code elimination"
35543 \begin_layout Verse
35558 i = 1; \InsetSpace ~
35567 global = 1;\InsetSpace ~
35581 global = 3;\InsetSpace ~
35587 \begin_layout Standard
35591 \begin_layout Verse
35607 \begin_layout Subsection
35609 \begin_inset LatexCommand index
35610 name "Copy propagation"
35617 \begin_layout Verse
35641 \begin_layout Standard
35645 \begin_layout Verse
35669 \begin_layout Standard
35670 Note: the dead stores created by this copy propagation will be eliminated
35671 by dead-code elimination.
35674 \begin_layout Subsection
35676 \begin_inset LatexCommand index
35677 name "Loop optimization"
35682 \begin_inset LatexCommand label
35683 name "sub:Loop-Optimizations"
35690 \begin_layout Standard
35691 Two types of loop optimizations are done by SDCC
35699 of loop induction variables.
35700 In addition to the strength reduction the optimizer marks the induction
35701 variables and the register allocator tries to keep the induction variables
35702 in registers for the duration of the loop.
35703 Because of this preference of the register allocator
35704 \begin_inset LatexCommand index
35705 name "Register allocation"
35709 , loop induction optimization causes an increase in register pressure, which
35710 may cause unwanted spilling of other temporary variables into the stack
35711 \begin_inset LatexCommand index
35717 The compiler will generate a warning message when it is forced to allocate
35718 extra space either on the stack or data space.
35719 If this extra space allocation is undesirable then induction optimization
35720 can be eliminated either for the entire source file (with -
35724 \begin_layout Standard
35733 -noinduction option) or for a given function only using #pragma\InsetSpace ~
35735 \begin_inset LatexCommand index
35736 name "\\#pragma noinduction"
35747 \begin_layout Verse
35750 for (i = 0 ; i < 100 ; i ++)
35759 \begin_layout Standard
35763 \begin_layout Verse
35768 for (i = 0; i < 100; i++)
35777 \begin_layout Standard
35778 As mentioned previously some loop invariants are not as apparent, all static
35779 address computations are also moved out of the loop.
35784 \begin_inset LatexCommand index
35785 name "Strength reduction"
35789 , this optimization substitutes an expression by a cheaper expression:
35792 \begin_layout Verse
35795 for (i=0;i < 100; i++)
35804 \begin_layout Standard
35808 \begin_layout Verse
35815 for (i=0;i< 100;i++) {
35821 ar[itemp1] = itemp2;
35839 \begin_layout Standard
35840 The more expensive multiplication
35841 \begin_inset LatexCommand index
35842 name "Multiplication"
35846 is changed to a less expensive addition.
35849 \begin_layout Subsection
35851 \begin_inset LatexCommand index
35852 name "Loop reversing"
35859 \begin_layout Standard
35860 This optimization is done to reduce the overhead of checking loop boundaries
35861 for every iteration.
35862 Some simple loops can be reversed and implemented using a
35863 \begin_inset Quotes eld
35866 decrement and jump if not zero
35867 \begin_inset Quotes erd
35871 SDCC checks for the following criterion to determine if a loop is reversible
35872 (note: more sophisticated compilers use data-dependency analysis to make
35873 this determination, SDCC uses a more simple minded analysis).
35876 \begin_layout Itemize
35877 The 'for' loop is of the form
35883 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
35893 \begin_layout Itemize
35894 The <for body> does not contain
35895 \begin_inset Quotes eld
35899 \begin_inset Quotes erd
35903 \begin_inset Quotes erd
35909 \begin_layout Itemize
35910 All goto's are contained within the loop.
35913 \begin_layout Itemize
35914 No function calls within the loop.
35917 \begin_layout Itemize
35918 The loop control variable <sym> is not assigned any value within the loop
35921 \begin_layout Itemize
35922 The loop control variable does NOT participate in any arithmetic operation
35926 \begin_layout Itemize
35927 There are NO switch statements in the loop.
35930 \begin_layout Subsection
35931 Algebraic Simplifications
35934 \begin_layout Standard
35935 SDCC does numerous algebraic simplifications, the following is a small sub-set
35936 of these optimizations.
35939 \begin_layout Verse
35942 i = j + 0;\InsetSpace ~
35946 /* changed to: */\InsetSpace ~
35952 i /= 2;\InsetSpace ~
35959 /* changed to: */\InsetSpace ~
35966 = j - j;\InsetSpace ~
35970 /* changed to: */\InsetSpace ~
35976 i = j / 1;\InsetSpace ~
35980 /* changed to: */\InsetSpace ~
35987 \begin_layout Standard
35988 Note the subexpressions
35989 \begin_inset LatexCommand index
35990 name "Subexpression"
35994 given above are generally introduced by macro expansions or as a result
35995 of copy/constant propagation.
35998 \begin_layout Subsection
35999 'switch' Statements
36000 \begin_inset LatexCommand label
36001 name "sub:'switch'-Statements"
36006 \begin_inset LatexCommand index
36007 name "switch statement"
36014 \begin_layout Standard
36015 SDCC can optimize switch statements to jump tables
36016 \begin_inset LatexCommand index
36022 It makes the decision based on an estimate of the generated code size.
36023 SDCC is quite liberal in the requirements for jump table generation:
36026 \begin_layout Itemize
36027 The labels need not be in order, and the starting number need not be one
36028 or zero, the case labels are in numerical sequence or not too many case
36029 labels are missing.
36033 \begin_layout Verse
36036 switch(i) {\InsetSpace ~
36067 case 4: ...\InsetSpace ~
36099 case 5: ...\InsetSpace ~
36131 case 3: ...\InsetSpace ~
36162 case 6: ...\InsetSpace ~
36194 case 7: ...\InsetSpace ~
36226 case 8: ...\InsetSpace ~
36258 case 9: ...\InsetSpace ~
36290 case 10: ...\InsetSpace ~
36321 case 11: ...\InsetSpace ~
36388 \begin_layout Standard
36389 Both the above switch statements will be implemented using a jump-table.
36390 The example to the right side is slightly more efficient as the check for
36391 the lower boundary of the jump-table is not needed.
36395 \begin_layout Itemize
36396 The number of case labels is not larger than supported by the target architectur
36400 \begin_layout Itemize
36401 If the case labels are not in numerical sequence ('gaps' between cases)
36402 SDCC checks whether a jump table with additionally inserted dummy cases
36403 is still attractive.
36407 \begin_layout Itemize
36408 If the starting number is not zero and a check for the lower boundary of
36409 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
36414 \begin_layout Standard
36415 Switch statements which have large gaps in the numeric sequence or those
36416 that have too many case labels can be split into more than one switch statement
36417 for efficient code generation, e.g.:
36420 \begin_layout Verse
36498 \begin_layout Standard
36499 If the above switch statement is broken down into two switch statements
36502 \begin_layout Verse
36545 \begin_layout Standard
36549 \begin_layout Verse
36592 \begin_layout Standard
36593 then both the switch statements will be implemented using jump-tables whereas
36594 the unmodified switch statement will not be.
36597 \begin_layout Standard
36598 \begin_inset Note Note
36601 \begin_layout Standard
36602 There might be reasons which SDCC cannot know about to either favour or
36603 not favour jump tables.
36604 If the target system has to be as quick for the last switch case as for
36605 the first (pro jump table), or if the switch argument is known to be zero
36606 in the majority of the cases (contra jump table).
36614 \begin_layout Standard
36615 The pragma nojtbound
36616 \begin_inset LatexCommand index
36617 name "\\#pragma nojtbound"
36621 can be used to turn off checking the
36634 It has no effect if a default label is supplied.
36635 Use of this pragma is dangerous: if the switch
36636 \begin_inset LatexCommand index
36637 name "switch statement"
36641 argument is not matched by a case statement the processor will happily
36645 \begin_layout Subsection
36646 Bit-shifting Operations
36647 \begin_inset LatexCommand index
36648 name "Bit shifting"
36655 \begin_layout Standard
36656 Bit shifting is one of the most frequently used operation in embedded programmin
36658 SDCC tries to implement bit-shift operations in the most efficient way
36662 \begin_layout Verse
36675 \begin_layout Standard
36676 generates the following code:
36679 \begin_layout Verse
36694 \begin_layout Standard
36695 In general SDCC will never setup a loop if the shift count is known.
36699 \begin_layout Verse
36712 \begin_layout Standard
36716 \begin_layout Verse
36740 \begin_layout Subsection
36742 \begin_inset LatexCommand index
36743 name "Bit rotation"
36750 \begin_layout Standard
36751 A special case of the bit-shift operation is bit rotation
36752 \begin_inset LatexCommand index
36753 name "rotating bits"
36757 , SDCC recognizes the following expression to be a left bit-rotation:
36760 \begin_layout Verse
36768 char i;\InsetSpace ~
36779 /* unsigned is needed for rotation */
36784 i = ((i << 1) | (i >> 7));
36793 \begin_layout Standard
36794 will generate the following code:
36797 \begin_layout Verse
36814 \begin_layout Standard
36815 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
36816 ns of this case will also be recognized as bit-rotation, i.e.:
36819 \begin_layout Verse
36822 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
36825 \begin_layout Subsection
36826 Nibble and Byte Swapping
36829 \begin_layout Standard
36830 Other special cases of the bit-shift operations are nibble or byte swapping
36831 \begin_inset LatexCommand index
36832 name "swapping nibbles/bytes"
36836 , SDCC recognizes the following expressions:
36839 \begin_layout Verse
36860 i = ((i << 4) | (i >> 4));
36866 j = ((j << 8) | (j >> 8));
36869 \begin_layout Standard
36870 and generates a swap instruction for the nibble swapping
36871 \begin_inset LatexCommand index
36872 name "Nibble swapping"
36876 or move instructions for the byte swapping
36877 \begin_inset LatexCommand index
36878 name "Byte swapping"
36884 \begin_inset Quotes sld
36888 \begin_inset Quotes srd
36891 example can be used to convert from little to big-endian or vice versa.
36892 If you want to change the endianness of a
36896 integer you have to cast to
36903 \begin_layout Standard
36904 Note that SDCC stores numbers in little-endian
36908 \begin_layout Standard
36909 Usually 8-bit processors don't care much about endianness.
36910 This is not the case for the standard 8051 which only has an instruction
36916 \begin_inset LatexCommand index
36921 -datapointer so little-endian is the more efficient byte order.
36927 \begin_inset LatexCommand index
36928 name "little-endian"
36933 \begin_inset LatexCommand index
36939 lowest order first).
36942 \begin_layout Subsection
36944 \begin_inset LatexCommand index
36945 name "Highest Order Bit"
36950 \begin_inset LatexCommand index
36951 name "Any Order Bit"
36958 \begin_layout Standard
36959 It is frequently required to obtain the highest order bit of an integral
36960 type (long, int, short or char types).
36961 Also obtaining any other order bit is not uncommon.
36962 SDCC recognizes the following expressions to yield the highest order bit
36963 and generates optimized code for it, e.g.:
36966 \begin_layout Verse
36977 unsigned char hob1, aob1;
36981 bit hob2, hob3, aob2,
36991 hob1 = (gint >> 15) & 1;
36995 hob2 = (gint >> 15) & 1;
36999 hob3 = gint & 0x8000;
37004 aob1 = (gint >> 9) & 1;
37008 aob2 = (gint >> 8) & 1;
37012 aob3 = gint & 0x0800;
37022 \begin_layout Standard
37023 will generate the following code:
37026 \begin_layout Verse
37057 000A E5*01\InsetSpace ~
37084 000C 23\InsetSpace ~
37115 000D 54 01\InsetSpace ~
37143 000F F5*02\InsetSpace ~
37198 0011 E5*01\InsetSpace ~
37226 0013 33\InsetSpace ~
37256 0014 92*00\InsetSpace ~
37312 0016 E5*01\InsetSpace ~
37339 0018 33\InsetSpace ~
37369 0019 92*01\InsetSpace ~
37425 001B E5*01\InsetSpace ~
37484 001E 54 01\InsetSpace ~
37511 0020 F5*03\InsetSpace ~
37567 0022 E5*01\InsetSpace ~
37594 0024 13\InsetSpace ~
37624 0025 92*02\InsetSpace ~
37680 0027 E5*01\InsetSpace ~
37735 002B 92*03\InsetSpace ~
37763 \begin_layout Standard
37764 Other variations of these cases however will
37769 They are standard C expressions, so I heartily recommend these be the only
37770 way to get the highest order bit, (it is portable).
37771 Of course it will be recognized even if it is embedded in other expressions,
37775 \begin_layout Verse
37778 xyz = gint + ((gint >> 15) & 1);
37781 \begin_layout Standard
37782 will still be recognized.
37785 \begin_layout Subsection
37787 \begin_inset LatexCommand index
37788 name "Higher Order Byte"
37792 / Higher Order Word
37793 \begin_inset LatexCommand index
37794 name "Higher Order Word"
37801 \begin_layout Standard
37802 It is also frequently required to obtain a higher order byte or word of
37803 a larger integral type (long, int or short types).
37804 SDCC recognizes the following expressions to yield the higher order byte
37805 or word and generates optimized code for it, e.g.:
37808 \begin_layout Verse
37813 unsigned long int glong;
37821 unsigned char hob1,
37826 unsigned int how1, how2;
37835 hob1 = (gint >> 8) & 0xFF;
37839 hob2 = glong >> 24;
37843 how1 = (glong >> 16) & 0xFFFF;
37858 \begin_layout Standard
37859 will generate the following code:
37862 \begin_layout Verse
37893 0037 85*01*06\InsetSpace ~
37915 _foo_hob1_1_1,(_gint + 1)
37946 003A 85*05*07\InsetSpace ~
37968 _foo_hob2_1_1,(_glong + 3)
37998 003D 85*04*08\InsetSpace ~
38021 _foo_how1_1_1,(_glong + 2)
38023 0040 85*05*09\InsetSpace ~
38048 0043 85*03*0A\InsetSpace ~
38070 _foo_how2_1_1,(_glong + 1)
38072 0046 85*04*0B\InsetSpace ~
38095 (_foo_how2_1_1 + 1),(_glong + 2)
38098 \begin_layout Standard
38099 Again, variations of these cases may
38104 They are standard C expressions, so I heartily recommend these be the only
38105 way to get the higher order byte/word, (it is portable).
38106 Of course it will be recognized even if it is embedded in other expressions,
38110 \begin_layout Verse
38113 xyz = gint + ((gint >> 8) & 0xFF);
38116 \begin_layout Standard
38117 will still be recognized.
38120 \begin_layout Subsection
38122 \begin_inset LatexCommand label
38123 name "sub:Peephole-Optimizer"
38128 \begin_inset LatexCommand index
38129 name "Peephole optimizer"
38136 \begin_layout Standard
38137 The compiler uses a rule based, pattern matching and re-writing mechanism
38138 for peep-hole optimization.
38143 a peep-hole optimizer by Christopher W.
38144 Fraser (cwfraser\InsetSpace ~
38147 A default set of rules are compiled into the compiler, additional rules
38148 may be added with the
38154 \begin_layout Standard
38164 \begin_inset LatexCommand index
38165 name "-\\/-peep-file"
38172 The rule language is best illustrated with examples.
38175 \begin_layout Verse
38197 \begin_layout Standard
38198 The above rule will change the following assembly
38199 \begin_inset LatexCommand index
38200 name "Assembler routines"
38207 \begin_layout Verse
38215 \begin_layout Standard
38219 \begin_layout Verse
38225 \begin_layout Standard
38226 Note: All occurrences of a
38230 (pattern variable) must denote the same string.
38231 With the above rule, the assembly sequence:
38234 \begin_layout Verse
38242 \begin_layout Standard
38243 will remain unmodified.
38247 Other special case optimizations may be added by the
38254 \begin_layout Standard
38267 some variants of the 8051 MCU
38268 \begin_inset LatexCommand index
38269 name "MCS51 variants"
38282 The following two rules will change all
38299 \begin_layout Verse
38302 replace { lcall %1 } by { acall %1 }
38304 replace { ljmp %1 } by { ajmp %1 }
38307 \begin_layout Standard
38308 (NOTE: from version 2.7.3 on, you can use option -
38314 \begin_layout Standard
38326 \begin_inset LatexCommand index
38327 name "-\\/-acall-ajmp"
38331 , which also takes care of aligning the interrupt vectors properly.)
38336 \begin_layout Standard
38339 inline-assembler code
38341 is also passed through the peep hole optimizer, thus the peephole optimizer
38342 can also be used as an assembly level macro expander.
38343 The rules themselves are MCU dependent whereas the rule language infra-structur
38344 e is MCU independent.
38345 Peephole optimization rules for other MCU can be easily programmed using
38350 The syntax for a rule is as follows:
38353 \begin_layout Verse
38356 rule := replace [ restart ] '{' <assembly sequence> '
38394 <assembly sequence> '
38412 '}' [if <functionName> ] '
38417 \begin_layout Standard
38418 <assembly sequence> := assembly instruction (each instruction including
38419 labels must be on a separate line).
38423 The optimizer will apply to the rules
38424 one by one from the top in the sequence of their appearance, it will terminate
38425 when all rules are exhausted.
38426 If the 'restart' option is specified, then the optimizer will start matching
38427 the rules again from the top, this option for a rule is expensive (performance)
38428 , it is intended to be used in situations where a transformation will trigger
38429 the same rule again.
38430 An example of this (not a good one, it has side effects) is the following
38434 \begin_layout Verse
38454 \begin_layout Standard
38455 Note that the replace pattern cannot be a blank, but can be a comment line.
38456 Without the 'restart' option only the innermost 'pop' 'push' pair would
38457 be eliminated, i.e.:
38460 \begin_layout Verse
38472 \begin_layout Standard
38476 \begin_layout Verse
38486 \begin_layout Standard
38491 the restart option the rule will be applied again to the resulting code
38492 and then all the pop-push pairs will be eliminated to yield:
38495 \begin_layout Verse
38503 \begin_layout Standard
38504 A conditional function can be attached to a rule.
38505 Attaching rules are somewhat more involved, let me illustrate this with
38509 \begin_layout Verse
38533 \begin_layout Standard
38534 The optimizer does a look-up of a function name table defined in function
38539 in the source file SDCCpeeph.c, with the name
38544 If it finds a corresponding entry the function is called.
38545 Note there can be no parameters specified for these functions, in this
38550 is crucial, since the function
38554 expects to find the label in that particular variable (the hash table containin
38555 g the variable bindings is passed as a parameter).
38556 If you want to code more such functions, take a close look at the function
38557 labelInRange and the calling mechanism in source file SDCCpeeph.c.
38558 Currently implemented are
38560 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
38561 24bitMode, portIsDS390, 24bitModeAndPortDS390
38570 \begin_layout Standard
38571 I know this whole thing is a little kludgey, but maybe some day we will
38572 have some better means.
38573 If you are looking at this file, you will see the default rules that are
38574 compiled into the compiler, you can add your own rules in the default set
38575 there if you get tired of specifying the -
38579 \begin_layout Standard
38591 \begin_layout Section
38593 \begin_inset LatexCommand index
38594 name "ANSI-compliance"
38599 \begin_inset LatexCommand label
38600 name "sub:ANSI-Compliance"
38607 \begin_layout Standard
38608 The latest publicly available version of the standard
38610 ISO/IEC 9899 - Programming languages - C
38612 should be available at:
38613 \begin_inset LatexCommand url
38614 target "http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899"
38623 \begin_layout Standard
38624 Deviations from the compliance:
38627 \begin_layout Itemize
38628 functions are not reentrant
38629 \begin_inset LatexCommand index
38634 unless explicitly declared as such or the
38640 \begin_layout Standard
38650 \begin_inset LatexCommand index
38651 name "-\\/-stack-auto"
38657 command line option is specified.
38660 \begin_layout Itemize
38662 \begin_inset LatexCommand index
38668 \begin_inset LatexCommand index
38673 cannot be assigned values directly, cannot be passed as function parameters
38674 or assigned to each other and cannot be a return value
38675 \begin_inset LatexCommand index
38676 name "return value"
38680 from a function, e.g.:
38684 \begin_layout Verse
38707 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
38732 s parms) /* invalid in SDCC although allowed in ANSI */
38754 return rets; /* is invalid in SDCC although allowed in ANSI */
38760 \begin_layout Itemize
38761 initialization of structure arrays must be fully braced.
38765 \begin_layout Verse
38768 struct s { char x } a[] = {1, 2};\InsetSpace ~
38773 /* invalid in SDCC */
38776 } a[] = {{1}, {2}}; /* OK */
38780 \begin_layout Itemize
38782 \begin_inset LatexCommand index
38783 name "long long (not supported)"
38788 \begin_inset LatexCommand index
38789 name "int (64 bit) (not supported)"
38796 \begin_layout Itemize
38798 \begin_inset LatexCommand index
38799 name "double (not supported)"
38803 ' precision floating point
38804 \begin_inset LatexCommand index
38805 name "Floating point support"
38812 \begin_layout Itemize
38814 \begin_inset LatexCommand index
38819 function declarations are NOT allowed.
38823 \begin_layout Verse
38826 foo(i,j) /* this old style of function declarations */
38828 int i,j; /* is valid
38829 in ANSI but not valid in SDCC */
38844 \begin_layout Itemize
38845 Most enhancements in C99 are not supported, e.g.:
38849 \begin_layout Verse
38859 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
38863 \begin_layout Itemize
38864 But some have been added recently in SDCC 2.7.0.
38865 They must be considered alpha quality however.
38869 \begin_layout Verse
38874 \begin_inset LatexCommand index
38875 name "inline (not supported)"
38884 int increment (int a) { return a+1; } /* inlines the increment without function
38893 \begin_inset LatexCommand index
38894 name "inline (not supported)"
38903 p; /* accepted but ignored */
38907 \begin_layout Itemize
38908 Certain words that are valid identifiers in the standard may be reserved
38909 words in SDCC unless the
38915 \begin_layout Standard
38925 \begin_inset LatexCommand index
38926 name "-\\/-std-c89"
38938 \begin_layout Standard
38948 \begin_inset LatexCommand index
38949 name "-\\/-std-c99"
38955 command line options are used.
38956 These may include (depending on the selected processor): 'at', 'banked',
38957 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
38958 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
38959 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
38961 Compliant equivalents of these keywords are always available in a form
38962 that begin with two underscores
38963 \begin_inset LatexCommand index
38964 name "\\_\\_ (prefix for extended keywords)"
38969 '__data' instead of 'data'.
38972 \begin_layout Itemize
38973 Integer promotion of variable arguments is not performed if the argument
38974 is explicitly taypecasted unless the
38980 \begin_layout Standard
38990 \begin_inset LatexCommand index
38991 name "-\\/-std-c89"
39003 \begin_layout Standard
39013 \begin_inset LatexCommand index
39014 name "-\\/-std-c99"
39020 command line options are used.
39024 \begin_layout Verse
39027 void vararg_func (char *str, ...) { str; }
39044 u is promoted to int before
39049 * passing to function */
39053 vararg_func ("%c", c);
39060 argument u is not promoted to int,
39065 * it is passed as char to function
39071 --std-cXX is not defined;
39076 * is promoted to int before passing
39082 if --std-cXX is defined */
39086 vararg_func ("%bc", (char)u);
39092 \begin_layout Section
39093 Cyclomatic Complexity
39094 \begin_inset LatexCommand index
39095 name "Cyclomatic complexity"
39102 \begin_layout Standard
39103 Cyclomatic complexity of a function is defined as the number of independent
39104 paths the program can take during execution of the function.
39105 This is an important number since it defines the number test cases you
39106 have to generate to validate the function.
39107 The accepted industry standard for complexity number is 10, if the cyclomatic
39108 complexity reported by SDCC exceeds 10 you should think about simplification
39109 of the function logic.
39110 Note that the complexity level is not related to the number of lines of
39111 code in a function.
39112 Large functions can have low complexity, and small functions can have large
39118 SDCC uses the following formula to compute the complexity:
39123 \begin_layout Standard
39124 complexity = (number of edges in control flow graph) - (number of nodes
39125 in control flow graph) + 2;
39129 Having said that the industry standard is 10,
39130 you should be aware that in some cases it be may unavoidable to have a
39131 complexity level of less than 10.
39132 For example if you have switch statement with more than 10 case labels,
39133 each case label adds one to the complexity level.
39134 The complexity level is by no means an absolute measure of the algorithmic
39135 complexity of the function, it does however provide a good starting point
39136 for which functions you might look at for further optimization.
39139 \begin_layout Section
39140 Retargetting for other Processors
39143 \begin_layout Standard
39144 The issues for retargetting the compiler are far too numerous to be covered
39146 What follows is a brief description of each of the seven phases of the
39147 compiler and its MCU dependency.
39150 \begin_layout Itemize
39151 Parsing the source and building the annotated parse tree.
39152 This phase is largely MCU independent (except for the language extensions).
39153 Syntax & semantic checks are also done in this phase, along with some initial
39154 optimizations like back patching labels and the pattern matching optimizations
39155 like bit-rotation etc.
39158 \begin_layout Itemize
39159 The second phase involves generating an intermediate code which can be easy
39160 manipulated during the later phases.
39161 This phase is entirely MCU independent.
39162 The intermediate code generation assumes the target machine has unlimited
39163 number of registers, and designates them with the name iTemp.
39164 The compiler can be made to dump a human readable form of the code generated
39169 \begin_layout Standard
39181 \begin_layout Itemize
39182 This phase does the bulk of the standard optimizations and is also MCU independe
39184 This phase can be broken down into several sub-phases:
39188 Break down intermediate
39189 code (iCode) into basic blocks.
39191 Do control flow & data flow analysis on the
39194 Do local common subexpression elimination, then global subexpressio
39197 Dead code elimination
39201 If loop optimizations
39202 caused any changes then do 'global subexpression elimination' and 'dead
39203 code elimination' again.
39206 \begin_layout Itemize
39207 This phase determines the live-ranges; by live range I mean those iTemp
39208 variables defined by the compiler that still survive after all the optimization
39210 Live range analysis
39211 \begin_inset LatexCommand index
39212 name "Live range analysis"
39216 is essential for register allocation, since these computation determines
39217 which of these iTemps will be assigned to registers, and for how long.
39220 \begin_layout Itemize
39221 Phase five is register allocation.
39222 There are two parts to this process.
39226 The first part I call 'register packing'
39227 (for lack of a better term).
39228 In this case several MCU specific expression folding is done to reduce
39233 The second part is more MCU independent and deals with
39234 allocating registers to the remaining live ranges.
39235 A lot of MCU specific code does creep into this phase because of the limited
39236 number of index registers available in the 8051.
39239 \begin_layout Itemize
39240 The Code generation phase is (unhappily), entirely MCU dependent and very
39241 little (if any at all) of this code can be reused for other MCU.
39242 However the scheme for allocating a homogenized assembler operand for each
39243 iCode operand may be reused.
39246 \begin_layout Itemize
39247 As mentioned in the optimization section the peep-hole optimizer is rule
39248 based system, which can reprogrammed for other MCUs.
39251 \begin_layout Standard
39252 More information is available on SDCC Wiki
39253 \begin_inset LatexCommand index
39259 \begin_inset LatexCommand url
39260 target "http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting"
39264 ) and in the thread
39265 \begin_inset LatexCommand url
39266 target "http://sf.net/mailarchive/message.php?msg_id=13954144"
39273 \begin_layout Chapter
39275 \begin_inset LatexCommand index
39276 name "Compiler internals"
39283 \begin_layout Section
39284 The anatomy of the compiler
39285 \begin_inset LatexCommand label
39286 name "sub:The-anatomy-of"
39293 \begin_layout Standard
39296 This is an excerpt from an article published in Circuit Cellar Magazine
39305 It's a little outdated (the compiler is much more efficient now and user/develo
39306 per friendly), but pretty well exposes the guts of it all.
39312 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
39313 It is fairly easy to retarget for other 8-bit MCU.
39314 Here we take a look at some of the internals of the compiler.
39318 \begin_layout Paragraph*
39320 \begin_inset LatexCommand index
39328 \begin_layout Standard
39329 Parsing the input source file and creating an AST (Annotated Syntax Tree
39330 \begin_inset LatexCommand index
39331 name "Annotated syntax tree"
39336 This phase also involves propagating types (annotating each node of the
39337 parse tree with type information) and semantic analysis.
39338 There are some MCU specific parsing rules.
39339 For example the storage classes, the extended storage classes are MCU specific
39340 while there may be a xdata storage class for 8051 there is no such storage
39341 class for z80 or Atmel AVR.
39342 SDCC allows MCU specific storage class extensions, i.e.
39343 xdata will be treated as a storage class specifier when parsing 8051 C
39344 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
39348 \begin_layout Paragraph*
39350 \begin_inset LatexCommand index
39358 \begin_layout Standard
39359 Intermediate code generation.
39360 In this phase the AST is broken down into three-operand form (iCode).
39361 These three operand forms are represented as doubly linked lists.
39362 ICode is the term given to the intermediate form generated by the compiler.
39363 ICode example section shows some examples of iCode generated for some simple
39364 C source functions.
39367 \begin_layout Paragraph*
39369 \begin_inset LatexCommand index
39370 name "Optimizations"
39377 \begin_layout Standard
39378 Bulk of the target independent optimizations is performed in this phase.
39379 The optimizations include constant propagation, common sub-expression eliminati
39380 on, loop invariant code movement, strength reduction of loop induction variables
39381 and dead-code elimination.
39384 \begin_layout Paragraph*
39385 Live range analysis
39386 \begin_inset LatexCommand index
39387 name "Live range analysis"
39394 \begin_layout Standard
39395 During intermediate code generation phase, the compiler assumes the target
39396 machine has infinite number of registers and generates a lot of temporary
39398 The live range computation determines the lifetime of each of these compiler-ge
39399 nerated temporaries.
39400 A picture speaks a thousand words.
39401 ICode example sections show the live range annotations for each of the
39403 It is important to note here, each iCode is assigned a number in the order
39404 of its execution in the function.
39405 The live ranges are computed in terms of these numbers.
39406 The from number is the number of the iCode which first defines the operand
39407 and the to number signifies the iCode which uses this operand last.
39410 \begin_layout Paragraph*
39411 Register Allocation
39412 \begin_inset LatexCommand index
39413 name "Register allocation"
39420 \begin_layout Standard
39421 The register allocation determines the type and number of registers needed
39423 In most MCUs only a few registers can be used for indirect addressing.
39424 In case of 8051 for example the registers R0 & R1 can be used to indirectly
39425 address the internal ram and DPTR to indirectly address the external ram.
39426 The compiler will try to allocate the appropriate register to pointer variables
39428 ICode example section shows the operands annotated with the registers assigned
39430 The compiler will try to keep operands in registers as much as possible;
39431 there are several schemes the compiler uses to do achieve this.
39432 When the compiler runs out of registers the compiler will check to see
39433 if there are any live operands which is not used or defined in the current
39434 basic block being processed, if there are any found then it will push that
39435 operand and use the registers in this block, the operand will then be popped
39436 at the end of the basic block.
39440 \begin_layout Standard
39441 There are other MCU specific considerations in this phase.
39442 Some MCUs have an accumulator; very short-lived operands could be assigned
39443 to the accumulator instead of a general-purpose register.
39446 \begin_layout Paragraph*
39450 \begin_layout Standard
39451 Figure II gives a table of iCode
39452 \begin_inset LatexCommand index
39457 operations supported by the compiler.
39458 The code generation involves translating these operations into corresponding
39459 assembly code for the processor.
39460 This sounds overly simple but that is the essence of code generation.
39461 Some of the iCode operations are generated on a MCU specific manner for
39462 example, the z80 port does not use registers to pass parameters so the
39463 SEND and RECV iCode operations will not be generated, and it also does
39464 not support JUMPTABLES.
39470 \begin_layout Standard
39474 \begin_inset Tabular
39475 <lyxtabular version="3" rows="39" columns="4">
39476 <features islongtable="true" headBottomDL="true">
39477 <column alignment="block" valignment="top" leftline="true" width="13col%">
39478 <column alignment="left" valignment="top" leftline="true" width="13col%">
39479 <column alignment="block" valignment="top" leftline="true" width="22col%">
39480 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
39481 <row topline="true" bottomline="true" endhead="true">
39482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39485 \begin_layout Standard
39491 \begin_inset LatexCommand index
39501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39504 \begin_layout Standard
39512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39515 \begin_layout Standard
39523 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39526 \begin_layout Standard
39535 <row topline="true">
39536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39539 \begin_layout Standard
39547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39550 \begin_layout Standard
39553 IC_LEFT() IC_RESULT()
39558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39561 \begin_layout Standard
39569 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39572 \begin_layout Standard
39575 IC_RESULT = ! IC_LEFT;
39581 <row topline="true">
39582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39585 \begin_layout Standard
39593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39596 \begin_layout Standard
39599 IC_LEFT() IC_RESULT()
39604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39607 \begin_layout Standard
39610 Bitwise complement of
39615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39618 \begin_layout Standard
39621 IC_RESULT = ~IC_LEFT;
39627 <row topline="true">
39628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39631 \begin_layout Standard
39639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39642 \begin_layout Standard
39645 IC_LEFT() IC_RESULT()
39650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39653 \begin_layout Standard
39656 Rotate right with carry
39661 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39664 \begin_layout Standard
39667 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
39673 <row topline="true">
39674 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39677 \begin_layout Standard
39685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39688 \begin_layout Standard
39691 IC_LEFT() IC_RESULT()
39696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39699 \begin_layout Standard
39702 Rotate left with carry
39707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39710 \begin_layout Standard
39713 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
39719 <row topline="true">
39720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39723 \begin_layout Standard
39731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39734 \begin_layout Standard
39737 IC_LEFT() IC_RESULT()
39742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39745 \begin_layout Standard
39748 Get the highest order bit of IC_LEFT
39753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39756 \begin_layout Standard
39759 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
39765 <row topline="true">
39766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39769 \begin_layout Standard
39777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39780 \begin_layout Standard
39783 IC_LEFT() IC_RESULT()
39788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39791 \begin_layout Standard
39799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39802 \begin_layout Standard
39805 IC_RESULT = - IC_LEFT;
39811 <row topline="true">
39812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39815 \begin_layout Standard
39823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39826 \begin_layout Standard
39834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39837 \begin_layout Standard
39840 Push the operand into stack
39845 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39848 \begin_layout Standard
39857 <row topline="true">
39858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39861 \begin_layout Standard
39869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39872 \begin_layout Standard
39880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39883 \begin_layout Standard
39886 Pop the operand from the stack
39891 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39894 \begin_layout Standard
39903 <row topline="true">
39904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39907 \begin_layout Standard
39915 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39918 \begin_layout Standard
39921 IC_LEFT() IC_RESULT()
39926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39929 \begin_layout Standard
39932 Call the function represented by IC_LEFT
39937 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39940 \begin_layout Standard
39943 IC_RESULT = IC_LEFT();
39949 <row topline="true">
39950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39953 \begin_layout Standard
39961 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39964 \begin_layout Standard
39967 IC_LEFT() IC_RESULT()
39972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39975 \begin_layout Standard
39978 Call via function pointer
39983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39986 \begin_layout Standard
39989 IC_RESULT = (*IC_LEFT)();
39995 <row topline="true">
39996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39999 \begin_layout Standard
40007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40010 \begin_layout Standard
40018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40021 \begin_layout Standard
40024 Return the value in operand IC_LEFT
40029 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40032 \begin_layout Standard
40041 <row topline="true">
40042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40045 \begin_layout Standard
40053 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40056 \begin_layout Standard
40064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40067 \begin_layout Standard
40075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40078 \begin_layout Standard
40087 <row topline="true">
40088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40091 \begin_layout Standard
40099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40102 \begin_layout Standard
40110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40113 \begin_layout Standard
40121 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40124 \begin_layout Standard
40133 <row topline="true">
40134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40137 \begin_layout Standard
40145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40148 \begin_layout Standard
40151 IC_LEFT() IC_RIGHT() IC_RESULT()
40156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40159 \begin_layout Standard
40167 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40170 \begin_layout Standard
40173 IC_RESULT = IC_LEFT + IC_RIGHT
40179 <row topline="true">
40180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40183 \begin_layout Standard
40191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40194 \begin_layout Standard
40197 IC_LEFT() IC_RIGHT() IC_RESULT()
40202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40205 \begin_layout Standard
40213 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40216 \begin_layout Standard
40219 IC_RESULT = IC_LEFT - IC_RIGHT
40225 <row topline="true">
40226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40229 \begin_layout Standard
40237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40240 \begin_layout Standard
40243 IC_LEFT() IC_RIGHT() IC_RESULT()
40248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40251 \begin_layout Standard
40259 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40262 \begin_layout Standard
40265 IC_RESULT = IC_LEFT * IC_RIGHT;
40271 <row topline="true">
40272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40275 \begin_layout Standard
40283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40286 \begin_layout Standard
40289 IC_LEFT() IC_RIGHT() IC_RESULT()
40294 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40297 \begin_layout Standard
40305 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40308 \begin_layout Standard
40311 IC_RESULT = IC_LEFT / IC_RIGHT;
40317 <row topline="true">
40318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40321 \begin_layout Standard
40329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40332 \begin_layout Standard
40335 IC_LEFT() IC_RIGHT() IC_RESULT()
40340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40343 \begin_layout Standard
40351 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40354 \begin_layout Standard
40357 IC_RESULT = IC_LEFT % IC_RIGHT;
40363 <row topline="true">
40364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40367 \begin_layout Standard
40375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40378 \begin_layout Standard
40381 IC_LEFT() IC_RIGHT() IC_RESULT()
40386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40389 \begin_layout Standard
40397 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40400 \begin_layout Standard
40403 IC_RESULT = IC_LEFT < IC_RIGHT;
40409 <row topline="true">
40410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40413 \begin_layout Standard
40421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40424 \begin_layout Standard
40427 IC_LEFT() IC_RIGHT() IC_RESULT()
40432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40435 \begin_layout Standard
40443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40446 \begin_layout Standard
40449 IC_RESULT = IC_LEFT > IC_RIGHT;
40455 <row topline="true">
40456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40459 \begin_layout Standard
40467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40470 \begin_layout Standard
40473 IC_LEFT() IC_RIGHT() IC_RESULT()
40478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40481 \begin_layout Standard
40489 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40492 \begin_layout Standard
40495 IC_RESULT = IC_LEFT == IC_RIGHT;
40501 <row topline="true">
40502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40505 \begin_layout Standard
40513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40516 \begin_layout Standard
40519 IC_LEFT() IC_RIGHT() IC_RESULT()
40524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40527 \begin_layout Standard
40530 Logical and operation
40535 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40538 \begin_layout Standard
40541 IC_RESULT = IC_LEFT && IC_RIGHT;
40547 <row topline="true">
40548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40551 \begin_layout Standard
40559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40562 \begin_layout Standard
40565 IC_LEFT() IC_RIGHT() IC_RESULT()
40570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40573 \begin_layout Standard
40576 Logical or operation
40581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40584 \begin_layout Standard
40587 IC_RESULT = IC_LEFT || IC_RIGHT;
40593 <row topline="true">
40594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40597 \begin_layout Standard
40605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40608 \begin_layout Standard
40611 IC_LEFT() IC_RIGHT() IC_RESULT()
40616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40619 \begin_layout Standard
40627 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40630 \begin_layout Standard
40633 IC_RESULT = IC_LEFT ^ IC_RIGHT;
40639 <row topline="true">
40640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40643 \begin_layout Standard
40651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40654 \begin_layout Standard
40657 IC_LEFT() IC_RIGHT() IC_RESULT()
40662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40665 \begin_layout Standard
40673 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40676 \begin_layout Standard
40679 IC_RESULT = IC_LEFT | IC_RIGHT;
40685 <row topline="true">
40686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40689 \begin_layout Standard
40697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40700 \begin_layout Standard
40703 IC_LEFT() IC_RIGHT() IC_RESULT()
40708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40711 \begin_layout Standard
40719 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40722 \begin_layout Standard
40725 IC_RESULT = IC_LEFT & IC_RIGHT;
40731 <row topline="true">
40732 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40735 \begin_layout Standard
40743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40746 \begin_layout Standard
40749 IC_LEFT() IC_RIGHT() IC_RESULT()
40754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40757 \begin_layout Standard
40765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40768 \begin_layout Standard
40771 IC_RESULT = IC_LEFT << IC_RIGHT
40777 <row topline="true">
40778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40781 \begin_layout Standard
40789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40792 \begin_layout Standard
40795 IC_LEFT() IC_RIGHT() IC_RESULT()
40800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40803 \begin_layout Standard
40811 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40814 \begin_layout Standard
40817 IC_RESULT = IC_LEFT >> IC_RIGHT
40823 <row topline="true">
40824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40827 \begin_layout Standard
40837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40840 \begin_layout Standard
40843 IC_LEFT() IC_RESULT()
40848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40851 \begin_layout Standard
40859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40862 \begin_layout Standard
40865 IC_RESULT = (*IC_LEFT);
40871 <row topline="true">
40872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40875 \begin_layout Standard
40883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40886 \begin_layout Standard
40889 IC_RIGHT() IC_RESULT()
40894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40897 \begin_layout Standard
40905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40908 \begin_layout Standard
40911 (*IC_RESULT) = IC_RIGHT;
40917 <row topline="true">
40918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40921 \begin_layout Standard
40929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40932 \begin_layout Standard
40935 IC_RIGHT() IC_RESULT()
40940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40943 \begin_layout Standard
40951 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40954 \begin_layout Standard
40957 IC_RESULT = IC_RIGHT;
40963 <row topline="true">
40964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40967 \begin_layout Standard
40975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40978 \begin_layout Standard
40981 IC_COND IC_TRUE IC_LABEL
40986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40989 \begin_layout Standard
40993 If true label is present then jump to true label if condition is true else
40994 jump to false label if condition is false
40999 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41002 \begin_layout Standard
41005 if (IC_COND) goto IC_TRUE;
41011 If (!IC_COND) goto IC_FALSE;
41017 <row topline="true">
41018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41021 \begin_layout Standard
41029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41032 \begin_layout Standard
41035 IC_LEFT() IC_RESULT()
41040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41043 \begin_layout Standard
41051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41054 \begin_layout Standard
41057 IC_RESULT = &IC_LEFT();
41063 <row topline="true">
41064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41067 \begin_layout Standard
41075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41078 \begin_layout Standard
41081 IC_JTCOND IC_JTLABELS
41086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41089 \begin_layout Standard
41092 Jump to list of labels depending on the value of JTCOND
41097 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41100 \begin_layout Standard
41109 <row topline="true">
41110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41113 \begin_layout Standard
41121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41124 \begin_layout Standard
41127 IC_RIGHT() IC_LEFT() IC_RESULT()
41132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41135 \begin_layout Standard
41143 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41146 \begin_layout Standard
41149 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
41155 <row topline="true">
41156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41159 \begin_layout Standard
41167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41170 \begin_layout Standard
41178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41181 \begin_layout Standard
41184 This is used for passing parameters in registers;
41186 move IC_LEFT to the next
41187 available parameter register.
41192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41195 \begin_layout Standard
41204 <row topline="true">
41205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41208 \begin_layout Standard
41216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41219 \begin_layout Standard
41227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41230 \begin_layout Standard
41233 This is used for receiving parameters passed in registers;
41236 in the next parameter register to IC_RESULT
41241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41244 \begin_layout Standard
41253 <row topline="true" bottomline="true">
41254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41257 \begin_layout Standard
41261 (some more have been added)
41266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41269 \begin_layout Standard
41275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41278 \begin_layout Standard
41284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41287 \begin_layout Standard
41320 \begin_layout Standard
41321 \begin_inset Note Note
41324 \begin_layout Standard
41325 In the original article Figure II was announced to be downloadable on
41330 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
41338 \begin_layout Paragraph*
41340 \begin_inset LatexCommand index
41348 \begin_layout Standard
41349 This section shows some details of iCode.
41350 The example C code does not do anything useful; it is used as an example
41351 to illustrate the intermediate code generated by the compiler.
41354 \begin_layout Verse
41364 /* This function does nothing useful.
41371 for the purpose of explaining iCode */
41374 short function (data
41383 short i=10; \InsetSpace ~
41385 /* dead initialization eliminated */
41391 /* dead initialization eliminated */
41419 /* compiler detects i,j to be induction
41424 for (i = 0, j = 10 ; i < 10 ; i++, j
41430 \begin_layout Standard
41453 mul += i * 3; \InsetSpace ~
41455 /* this multiplication remains */
41462 j * 3;\InsetSpace ~
41464 /* this multiplication changed to addition */
41478 \begin_layout Standard
41479 In addition to the operands each iCode contains information about the filename
41480 and line it corresponds to in the source file.
41481 The first field in the listing should be interpreted as follows:
41486 Filename(linenumber: iCode Execution sequence number : ICode hash table
41487 key : loop depth of the iCode).
41492 Then follows the human readable form of the ICode operation.
41493 Each operand of this triplet form can be of three basic types a) compiler
41494 generated temporary b) user defined variable c) a constant value.
41495 Note that local variables and parameters are replaced by compiler generated
41498 \begin_inset LatexCommand index
41499 name "Live range analysis"
41503 are computed only for temporaries (i.e.
41504 live ranges are not computed for global variables).
41506 \begin_inset LatexCommand index
41507 name "Register allocation"
41511 are allocated for temporaries only.
41512 Operands are formatted in the following manner:
41517 Operand Name [lr live-from : live-to ] { type information } [ registers
41523 As mentioned earlier the live ranges are computed in terms of the execution
41524 sequence number of the iCodes, for example
41526 the iTemp0 is live from (i.e.
41527 first defined in iCode with execution sequence number 3, and is last used
41528 in the iCode with sequence number 5).
41529 For induction variables such as iTemp21 the live range computation extends
41530 the lifetime from the start to the end of the loop.
41532 The register allocator
41533 used the live range information to allocate registers, the same registers
41534 may be used for different temporaries if their live ranges do not overlap,
41535 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
41536 ranges do not overlap.
41537 In addition the allocator also takes into consideration the type and usage
41538 of a temporary, for example itemp6 is a pointer to near space and is used
41539 as to fetch data from (i.e.
41540 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
41541 Some short lived temporaries are allocated to special registers which have
41542 meaning to the code generator e.g.
41543 iTemp13 is allocated to a pseudo register CC which tells the back end that
41544 the temporary is used only for a conditional jump the code generation makes
41545 use of this information to optimize a compare and jump ICode.
41549 \begin_inset LatexCommand index
41550 name "Loop optimization"
41554 performed by the compiler.
41555 It can detect induction variables iTemp21(i) and iTemp23(j).
41556 Also note the compiler does selective strength reduction
41557 \begin_inset LatexCommand index
41558 name "Strength reduction"
41563 the multiplication of an induction variable in line 18 (gint = j * 3) is
41564 changed to addition, a new temporary iTemp17 is allocated and assigned
41565 a initial value, a constant 3 is then added for each iteration of the loop.
41566 The compiler does not change the multiplication
41567 \begin_inset LatexCommand index
41568 name "Multiplication"
41572 in line 17 however since the processor does support an 8 * 8 bit multiplication.
41575 Note the dead code elimination
41576 \begin_inset LatexCommand index
41577 name "Dead-code elimination"
41581 optimization eliminated the dead assignments in line 7 & 8 to I and sum
41587 \begin_layout Standard
41590 Sample.c (5:1:0:0) _entry($9) :
41593 \begin_layout Standard
41596 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
41599 \begin_layout Standard
41602 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
41605 \begin_layout Standard
41608 Sample.c(11:4:53:0) preHeaderLbl0($11) :
41611 \begin_layout Standard
41614 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
41618 \begin_layout Standard
41621 Sample.c(11:6:5:1) _whilecontinue_0($1) :
41624 \begin_layout Standard
41627 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
41631 \begin_layout Standard
41634 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
41637 \begin_layout Standard
41640 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
41644 \begin_layout Standard
41647 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
41651 \begin_layout Standard
41654 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
41658 \begin_layout Standard
41661 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
41665 \begin_layout Standard
41668 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
41669 * int}[r0] + 0x2 {short}
41672 \begin_layout Standard
41675 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
41678 \begin_layout Standard
41681 Sample.c(11:17:21:0)_whilebreak_0($3) :
41684 \begin_layout Standard
41687 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
41690 \begin_layout Standard
41693 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
41696 \begin_layout Standard
41699 Sample.c(15:20:54:0)preHeaderLbl1($13) :
41702 \begin_layout Standard
41705 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
41708 \begin_layout Standard
41711 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
41714 \begin_layout Standard
41717 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
41720 \begin_layout Standard
41723 Sample.c(15:24:26:1)_forcond_0($4) :
41726 \begin_layout Standard
41729 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
41733 \begin_layout Standard
41736 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
41739 \begin_layout Standard
41742 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
41743 + ITemp21 [lr21:38]{short}[r4]
41746 \begin_layout Standard
41749 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
41753 \begin_layout Standard
41756 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
41757 + iTemp15 [lr29:30]{short}[r1]
41760 \begin_layout Standard
41763 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
41767 \begin_layout Standard
41770 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
41774 \begin_layout Standard
41777 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
41781 \begin_layout Standard
41784 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
41788 \begin_layout Standard
41791 Sample.c(19:38:47:1) goto _forcond_0($4)
41794 \begin_layout Standard
41797 Sample.c(19:39:48:0)_forbreak_0($7) :
41800 \begin_layout Standard
41803 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
41804 + ITemp11 [lr19:40]{short}[r3]
41807 \begin_layout Standard
41810 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
41813 \begin_layout Standard
41816 Sample.c(20:42:51:0)_return($8) :
41819 \begin_layout Standard
41822 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
41828 Finally the code generated for this function:
41833 \begin_layout Standard
41839 \begin_layout Standard
41845 \begin_layout Standard
41853 \begin_layout Standard
41859 \begin_layout Standard
41867 \begin_layout Standard
41873 \begin_layout Standard
41876 ; ----------------------------------------------
41879 \begin_layout Standard
41882 ; function function
41885 \begin_layout Standard
41888 ; ----------------------------------------------
41891 \begin_layout Standard
41897 \begin_layout Standard
41900 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
41903 \begin_layout Standard
41911 \begin_layout Standard
41914 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
41917 \begin_layout Standard
41925 \begin_layout Standard
41928 ;_whilecontinue_0($1) :
41931 \begin_layout Standard
41937 \begin_layout Standard
41940 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
41943 \begin_layout Standard
41946 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
41949 \begin_layout Standard
41957 \begin_layout Standard
41965 \begin_layout Standard
41973 \begin_layout Standard
41981 \begin_layout Standard
41989 \begin_layout Standard
41997 \begin_layout Standard
42005 \begin_layout Standard
42011 \begin_layout Standard
42014 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
42017 \begin_layout Standard
42025 \begin_layout Standard
42033 \begin_layout Standard
42036 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
42039 \begin_layout Standard
42047 \begin_layout Standard
42055 \begin_layout Standard
42063 \begin_layout Standard
42071 \begin_layout Standard
42079 \begin_layout Standard
42087 \begin_layout Standard
42090 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
42093 \begin_layout Standard
42101 \begin_layout Standard
42109 \begin_layout Standard
42117 \begin_layout Standard
42125 \begin_layout Standard
42133 \begin_layout Standard
42136 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
42139 \begin_layout Standard
42147 \begin_layout Standard
42155 \begin_layout Standard
42163 \begin_layout Standard
42166 ; iTemp6 [lr5:16]{_near * int}[r0] =
42169 \begin_layout Standard
42172 ; iTemp6 [lr5:16]{_near * int}[r0] +
42175 \begin_layout Standard
42181 \begin_layout Standard
42189 \begin_layout Standard
42192 ; goto _whilecontinue_0($1)
42195 \begin_layout Standard
42203 \begin_layout Standard
42206 ; _whilebreak_0($3) :
42209 \begin_layout Standard
42215 \begin_layout Standard
42218 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
42221 \begin_layout Standard
42229 \begin_layout Standard
42232 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
42235 \begin_layout Standard
42243 \begin_layout Standard
42246 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
42249 \begin_layout Standard
42257 \begin_layout Standard
42260 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
42263 \begin_layout Standard
42271 \begin_layout Standard
42279 \begin_layout Standard
42282 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
42285 \begin_layout Standard
42293 \begin_layout Standard
42301 \begin_layout Standard
42307 \begin_layout Standard
42313 \begin_layout Standard
42316 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
42319 \begin_layout Standard
42322 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
42325 \begin_layout Standard
42333 \begin_layout Standard
42341 \begin_layout Standard
42349 \begin_layout Standard
42357 \begin_layout Standard
42365 \begin_layout Standard
42371 \begin_layout Standard
42374 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
42377 \begin_layout Standard
42380 ; iTemp21 [lr21:38]{short}[r4]
42383 \begin_layout Standard
42391 \begin_layout Standard
42399 \begin_layout Standard
42407 \begin_layout Standard
42410 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
42413 \begin_layout Standard
42421 \begin_layout Standard
42429 \begin_layout Standard
42437 \begin_layout Standard
42445 \begin_layout Standard
42448 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
42451 \begin_layout Standard
42454 ; iTemp15 [lr29:30]{short}[r1]
42457 \begin_layout Standard
42465 \begin_layout Standard
42473 \begin_layout Standard
42476 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
42479 \begin_layout Standard
42487 \begin_layout Standard
42495 \begin_layout Standard
42503 \begin_layout Standard
42511 \begin_layout Standard
42519 \begin_layout Standard
42527 \begin_layout Standard
42530 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
42533 \begin_layout Standard
42541 \begin_layout Standard
42549 \begin_layout Standard
42557 \begin_layout Standard
42565 \begin_layout Standard
42573 \begin_layout Standard
42581 \begin_layout Standard
42584 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
42587 \begin_layout Standard
42595 \begin_layout Standard
42598 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
42601 \begin_layout Standard
42609 \begin_layout Standard
42614 cjne r5,#0xff,00104$
42617 \begin_layout Standard
42625 \begin_layout Standard
42628 ; goto _forcond_0($4)
42631 \begin_layout Standard
42639 \begin_layout Standard
42642 ; _forbreak_0($7) :
42645 \begin_layout Standard
42651 \begin_layout Standard
42654 ; ret iTemp24 [lr40:41]{short}
42657 \begin_layout Standard
42665 \begin_layout Standard
42673 \begin_layout Standard
42681 \begin_layout Standard
42687 \begin_layout Standard
42693 \begin_layout Standard
42703 \begin_layout Section
42704 A few words about basic block successors, predecessors and dominators
42707 \begin_layout Standard
42708 Successors are basic blocks
42709 \begin_inset LatexCommand index
42710 name "Basic blocks"
42714 that might execute after this basic block.
42716 Predecessors are basic blocks
42717 that might execute before reaching this basic block.
42719 Dominators are basic
42720 blocks that WILL execute before reaching this basic block.
42725 \begin_layout Standard
42729 \begin_layout Standard
42733 \begin_layout Standard
42741 \begin_layout Standard
42745 \begin_layout Standard
42753 \begin_layout Standard
42759 \begin_layout Standard
42760 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
42763 \begin_layout Standard
42764 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
42767 \begin_layout Standard
42768 c) domVect of [BB4] = BB1 ...
42769 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
42773 \begin_layout Chapter
42777 \begin_layout Standard
42778 \begin_inset LatexCommand url
42779 target "http://sdcc.sourceforge.net/#Who"
42789 Thanks to all the other volunteer developers who have helped with coding,
42790 testing, web-page creation, distribution sets, etc.
42791 You know who you are :-)
42799 Thanks to Sourceforge
42800 \begin_inset LatexCommand url
42801 target "http://www.sf.net"
42805 which has hosted the project since 1999 and donates significant download
42814 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
42815 cycles and bandwidth for snapshot builds.
42820 \begin_layout Standard
42821 This document was initially written by Sandeep Dutta
42824 \begin_layout Standard
42825 All product names mentioned herein may be trademarks
42826 \begin_inset LatexCommand index
42831 of their respective companies.
42835 \begin_layout Section*
42839 \begin_layout Standard
42840 To avoid confusion, the installation and building options for SDCC itself
42841 (chapter 2) are not part of the index.
42844 \begin_layout Standard
42845 \begin_inset LatexCommand printindex