1 #LyX 1.5.7 created this file. For more info see http://www.lyx.org/
7 \pdfoptionpdfminorversion=3
9 pdftitle={SDCC Compiler User Guide},
10 pdfauthor={SDCC development team},
11 pdfsubject={installation, user manual},
12 pdfkeywords={68hc08 8032 8051 ansi c compiler assembler CPU DS390 embedded development free Floating Point Arithmetic Freescale GPL HC08 inline Intel ISO/IEC 9899:1990 Linux MAC OS X manual Maxim mcs51 Microchip microcontroller open source PIC Unix Windows Z80 Zilog},
13 pdfpagemode=UseOutlines,
15 linkcolor=blue] {hyperref}
19 \emergencystretch=30pt
24 \inputencoding default
27 \font_typewriter courier
28 \font_default_family default
34 \paperfontsize default
36 \papersize letterpaper
42 \paperorientation portrait
49 \paragraph_separation indent
51 \quotes_language swedish
55 \tracking_changes false
63 \begin_layout Standard
64 \begin_inset Note Note
67 \begin_layout Standard
68 Please note: double dashed longoptions (e.g.
69 --version) are written this way: -
73 \begin_layout Standard
85 \begin_layout Standard
87 three consecutive dashes would otherwise result in a long resp.
91 \begin_layout Standard
92 Architecture specific stuff (like memory models, code examples) should maybe
96 \begin_layout Standard
97 into separate sections/chapters/appendices (it is hard to document PIC or
101 \begin_layout Standard
102 a 8051 centered document) - for now simply add.
111 SDCC Compiler User Guide
126 \begin_layout Standard
127 \begin_inset Note Note
130 \begin_layout Standard
131 The above strings enclosed in $ are automatically updated by Subversion
139 \begin_layout Standard
140 \begin_inset LatexCommand tableofcontents
147 \begin_layout Chapter
151 \begin_layout Section
155 \begin_layout Standard
176 ompiler) is free open source, retargettable, optimizing ANSI-C compiler
181 designed for 8 bit Microprocessors.
182 The current version targets Intel MCS51 based Microprocessors (8031, 8032,
184 \begin_inset LatexCommand index
185 name "8031, 8032, 8051, 8052, mcs51 CPU"
189 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
190 Zilog Z80 based MCUs.
191 It can be retargeted for other microprocessors, support for Microchip PIC,
192 Atmel AVR is under development.
193 The entire source code for the compiler is distributed under GPL.
195 \begin_inset LatexCommand index
196 name "asXXXX (as-gbz80, as-hc08, asx8051, as-z80)"
201 \begin_inset LatexCommand index
206 , an open source retargetable assembler & linker.
207 SDCC has extensive language extensions suitable for utilizing various microcont
208 rollers and underlying hardware effectively.
213 In addition to the MCU specific optimizations SDCC also does a host of
214 standard optimizations like:
217 \begin_layout Itemize
218 global sub expression elimination,
221 \begin_layout Itemize
222 loop optimizations (loop invariant, strength reduction of induction variables
226 \begin_layout Itemize
227 constant folding & propagation,
230 \begin_layout Itemize
234 \begin_layout Itemize
235 dead code elimination
238 \begin_layout Itemize
246 \begin_layout Standard
247 For the back-end SDCC uses a global register allocation scheme which should
248 be well suited for other 8 bit MCUs.
253 The peep hole optimizer uses a rule based substitution mechanism which
259 Supported data-types are:
262 \begin_layout Standard
264 <lyxtabular version="3" rows="8" columns="5">
266 <column alignment="center" valignment="top" leftline="true" width="0">
267 <column alignment="center" valignment="top" leftline="true" width="0">
268 <column alignment="center" valignment="top" leftline="true" width="0">
269 <column alignment="center" valignment="top" leftline="true" width="0">
270 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
271 <row topline="true" bottomline="true">
272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
275 \begin_layout Standard
281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
284 \begin_layout Standard
290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
293 \begin_layout Standard
299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
302 \begin_layout Standard
308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
311 \begin_layout Standard
319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
322 \begin_layout Standard
328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
331 \begin_layout Standard
337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
340 \begin_layout Standard
346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
349 \begin_layout Standard
355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
358 \begin_layout Standard
366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
369 \begin_layout Standard
375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
378 \begin_layout Standard
384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
387 \begin_layout Standard
393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
396 \begin_layout Standard
402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
405 \begin_layout Standard
413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
416 \begin_layout Standard
422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
425 \begin_layout Standard
431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
434 \begin_layout Standard
440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
443 \begin_layout Standard
449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
452 \begin_layout Standard
460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
463 \begin_layout Standard
469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
472 \begin_layout Standard
478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
481 \begin_layout Standard
487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
490 \begin_layout Standard
496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
499 \begin_layout Standard
506 <row topline="true" bottomline="true">
507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
510 \begin_layout Standard
516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
519 \begin_layout Standard
525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
528 \begin_layout Standard
534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
537 \begin_layout Standard
538 -2.147.483.648, +2.147.483.647
543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
546 \begin_layout Standard
553 <row topline="true" bottomline="true">
554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
557 \begin_layout Standard
563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
566 \begin_layout Standard
572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
575 \begin_layout Standard
581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
584 \begin_layout Standard
590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
593 \begin_layout Standard
609 <row topline="true" bottomline="true">
610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
613 \begin_layout Standard
619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
622 \begin_layout Standard
628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
631 \begin_layout Standard
637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
640 \begin_layout Standard
646 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
649 \begin_layout Standard
662 The compiler also allows
664 inline assembler code
666 to be embedded anywhere in a function.
667 In addition, routines developed in assembly can also be called.
672 provides an option (-
676 \begin_layout Standard
685 -cyclomatic) to report the relative complexity of a function.
686 These functions can then be further optimized, or hand coded in assembly
692 SDCC also comes with a companion source level debugger SDCDB.
693 The debugger currently uses ucSim, a free open source simulator for 8051
694 and other micro-controllers.
698 The latest SDCC version can be downloaded from
700 \begin_inset LatexCommand url
701 target "http://sdcc.sourceforge.net/snap.php"
708 Please note: the compiler will probably always be some steps ahead of this
713 \begin_inset LatexCommand index
714 name "Status of documentation"
722 \begin_layout Standard
723 Obviously this has pros and cons
731 \begin_layout Section
735 \begin_layout Standard
736 All packages used in this compiler system are
744 ; source code for all the sub-packages (pre-processor, assemblers, linkers
745 etc.) is distributed with the package.
746 This documentation is maintained using a free open source word processor
749 This program is free software; you can redistribute it and/or modify
750 it under the terms of the GNU General Public License
751 \begin_inset LatexCommand index
752 name "GNU General Public License, GPL"
756 as published by the Free Software Foundation; either version 2, or (at
757 your option) any later version.
758 This program is distributed in the hope that it will be useful, but WITHOUT
759 ANY WARRANTY; without even the implied warranty
760 \begin_inset LatexCommand index
765 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
766 See the GNU General Public License for more details.
767 You should have received a copy of the GNU General Public License along
768 with this program; if not, write to the Free Software Foundation, 59 Temple
769 Place - Suite 330, Boston, MA 02111-1307, USA.
770 In other words, you are welcome to use, share and improve this program.
771 You are forbidden to forbid anyone else to use, share and improve what
773 Help stamp out software-hoarding!
776 \begin_layout Section
777 Typographic conventions
778 \begin_inset LatexCommand index
779 name "Typographic conventions"
786 \begin_layout Standard
787 Throughout this manual, we will use the following convention.
788 Commands you have to type in are printed in
796 Code samples are printed in
801 Interesting items and new terms are printed in
806 \begin_layout Section
808 \begin_inset LatexCommand label
809 name "sec:Compatibility-with-previous"
813 with previous versions
814 \begin_inset LatexCommand index
815 name "Compatibility with previous versions"
822 \begin_layout Standard
823 Newer versions have usually numerous bug fixes compared with the previous
825 But we also sometimes introduce some incompatibilities with older versions.
826 Not just for the fun of it, but to make the compiler more stable, efficient
828 \begin_inset LatexCommand index
829 name "ANSI-compliance"
834 \begin_inset LatexCommand ref
835 reference "sub:ANSI-Compliance"
839 for ANSI-Compliance).
841 \begin_inset Note Note
844 \begin_layout Standard
845 It would be fine to add to each item, in which version was it changed.
855 \begin_layout Itemize
856 short is now equivalent to int (16 bits), it used to be equivalent to char
857 (8 bits) which is not ANSI compliant.
858 To maintain compatibility, old programs may be compiled using the -
862 \begin_layout Standard
871 -short-is-8bits commandline option (see
872 \begin_inset LatexCommand vref
873 reference "lyx:--short-is-8bits"
880 \begin_layout Itemize
881 the default directory for gcc-builds where include, library and documentation
882 files are stored is now in /usr/local/share.
885 \begin_layout Itemize
886 char type parameters to vararg
887 \begin_inset LatexCommand index
888 name "vararg, va\\_arg"
892 functions are casted to int unless explicitly casted and
898 \begin_layout Standard
908 \begin_inset LatexCommand index
921 \begin_layout Standard
931 \begin_inset LatexCommand index
938 command line option are not defined
939 \begin_inset Marginal
942 \begin_layout Standard
967 will push a as an int and as a char resp if
973 \begin_layout Standard
983 \begin_inset LatexCommand index
996 \begin_layout Standard
1006 \begin_inset LatexCommand index
1013 command line options are not defined,
1015 will push a as two ints if
1021 \begin_layout Standard
1031 \begin_inset LatexCommand index
1044 \begin_layout Standard
1054 \begin_inset LatexCommand index
1061 command line option is defined.
1064 \begin_layout Itemize
1069 \begin_layout Standard
1078 -regextend has been removed.
1081 \begin_layout Itemize
1086 \begin_layout Standard
1095 -noregparms has been removed.
1098 \begin_layout Itemize
1103 \begin_layout Standard
1112 -stack-after-data has been removed.
1115 \begin_layout Itemize
1117 \begin_inset LatexCommand index
1123 \begin_inset LatexCommand index
1129 \begin_inset LatexCommand index
1134 types now consistently behave like the C99 _Bool type with respect to type
1136 \begin_inset LatexCommand index
1137 name "type conversion"
1142 \begin_inset LatexCommand index
1143 name "type promotion"
1148 The most common incompatibility resulting from this change is related to
1150 \begin_inset LatexCommand index
1166 \begin_inset LatexCommand index
1167 name "\\~\\/ Operator"
1171 b; /* equivalent to b=1 instead of toggling b */
1172 \begin_inset Marginal
1175 \begin_layout Standard
1188 b = !b; /* toggles b */
1192 In previous versions, both forms would have toggled the bit.
1195 \begin_layout Itemize
1196 in older versions, the preprocessor was always called with
1202 \begin_layout Standard
1212 \begin_inset LatexCommand index
1225 \begin_layout Standard
1237 This is no longer true, and can cause compilation failures on code built
1244 \begin_layout Standard
1254 \begin_inset LatexCommand index
1261 but using c99 preprocessor features, such as one-line (//) comments
1264 \begin_layout Itemize
1265 in versions older then 2.8.4 the pic16 *printf() and printf_tiny() library
1266 functions supported undocumented and not standard compliant 'b' binary
1267 format specifier ("%b", "%hb" and "%lb").
1268 The 'b' specifier is now disabled by default.
1269 It can be enabled by defining BINARY_SPECIFIER macro in files device/lib/pic16/
1270 libc/stdio/vfprintf.c and device/lib/pic16/libc/stdio/printf_tiny.c and recompilin
1274 \begin_layout Itemize
1275 in versions older then 2.8.5 the unnamed bitfield structure members participated
1276 in initialization, which is not conforming with ISO/IEC 9899:1999 standard
1277 (see section Section 6.7.8 Initialization, clause 9)
1281 Old behavior, before
1317 /* s.a = 1, s.b = 3 */
1358 /* s.a = 1, s.b = 2 */
1361 \begin_layout Section
1365 \begin_layout Standard
1366 What do you need before you start installation of SDCC? A computer, and
1367 a desire to compute.
1368 The preferred method of installation is to compile SDCC from source using
1370 For Windows some pre-compiled binary distributions are available for your
1372 You should have some experience with command line tools and compiler use.
1375 \begin_layout Section
1379 \begin_layout Standard
1380 The SDCC home page at
1381 \begin_inset LatexCommand url
1382 target "http://sdcc.sourceforge.net/"
1386 is a great place to find distribution sets.
1387 You can also find links to the user mailing lists that offer help or discuss
1388 SDCC with other SDCC users.
1389 Web links to other SDCC related sites can also be found here.
1390 This document can be found in the DOC directory of the source package as
1391 a text or HTML file.
1392 A pdf version of this document is available at
1393 \begin_inset LatexCommand url
1394 target "http://sdcc.sourceforge.net/doc/sdccman.pdf"
1399 Some of the other tools (simulator and assembler) included with SDCC contain
1400 their own documentation and can be found in the source distribution.
1401 If you want the latest unreleased software, the complete source package
1402 is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1406 \begin_layout Section
1407 Wishes for the future
1410 \begin_layout Standard
1411 There are (and always will be) some things that could be done.
1412 Here are some I can think of:
1417 \begin_layout Standard
1420 char KernelFunction3(char p) at 0x340;
1425 \begin_layout Standard
1429 \begin_inset LatexCommand index
1430 name "code banking (limited support)"
1440 If you can think of some more, please see the section
1441 \begin_inset LatexCommand ref
1442 reference "sub:Requesting-Features"
1446 about filing feature requests
1447 \begin_inset LatexCommand index
1448 name "Requesting features"
1453 \begin_inset LatexCommand index
1454 name "Feature request"
1463 \begin_layout Chapter
1465 \begin_inset LatexCommand index
1473 \begin_layout Standard
1474 For most users it is sufficient to skip to either section
1475 \begin_inset LatexCommand ref
1476 reference "sub:Building-SDCC-on-Linux"
1481 \begin_inset LatexCommand ref
1482 reference "sub:Windows-Install"
1487 More detailed instructions follow below.
1490 \begin_layout Section
1492 \begin_inset LatexCommand index
1493 name "Options SDCC configuration"
1500 \begin_layout Standard
1501 The install paths, search paths and other options are defined when running
1503 The defaults can be overridden by:
1507 \labelwidthstring 00.00.0000
1512 \begin_layout Standard
1521 -prefix see table below
1525 \labelwidthstring 00.00.0000
1530 \begin_layout Standard
1539 -exec_prefix see table below
1543 \labelwidthstring 00.00.0000
1548 \begin_layout Standard
1557 -bindir see table below
1561 \labelwidthstring 00.00.0000
1566 \begin_layout Standard
1575 -datadir see table below
1579 \labelwidthstring 00.00.0000
1584 \begin_layout Standard
1593 -datarootdir see table below
1599 \labelwidthstring 00.00.0000
1602 docdir environment variable, see table below
1606 \labelwidthstring 00.00.0000
1609 include_dir_suffix environment variable, see table below
1613 \labelwidthstring 00.00.0000
1616 lib_dir_suffix environment variable, see table below
1620 \labelwidthstring 00.00.0000
1623 sdccconf_h_dir_separator environment variable, either / or
1628 This character will only be used in sdccconf.h; don't forget it's a C-header,
1629 therefore a double-backslash is needed there.
1635 \labelwidthstring 00.00.0000
1640 \begin_layout Standard
1649 -disable-mcs51-port Excludes the Intel mcs51 port
1653 \labelwidthstring 00.00.0000
1658 \begin_layout Standard
1667 -disable-gbz80-port Excludes the Gameboy gbz80 port
1671 \labelwidthstring 00.00.0000
1676 \begin_layout Standard
1685 -disable-z80-port Excludes the z80 port
1689 \labelwidthstring 00.00.0000
1694 \begin_layout Standard
1703 -disable-avr-port Excludes the AVR port
1707 \labelwidthstring 00.00.0000
1712 \begin_layout Standard
1721 -disable-ds390-port Excludes the DS390 port
1725 \labelwidthstring 00.00.0000
1730 \begin_layout Standard
1739 -disable-hc08-port Excludes the HC08 port
1743 \labelwidthstring 00.00.0000
1748 \begin_layout Standard
1757 -disable-pic-port Excludes the PIC14 port
1761 \labelwidthstring 00.00.0000
1766 \begin_layout Standard
1775 -disable-pic16-port Excludes the PIC16 port
1779 \labelwidthstring 00.00.0000
1784 \begin_layout Standard
1793 -disable-xa51-port Excludes the XA51 port
1797 \labelwidthstring 00.00.0000
1802 \begin_layout Standard
1811 -disable-ucsim Disables configuring and building of ucsim
1815 \labelwidthstring 00.00.0000
1820 \begin_layout Standard
1829 -disable-device-lib Disables automatically building device libraries
1833 \labelwidthstring 00.00.0000
1838 \begin_layout Standard
1847 -disable-packihx Disables building packihx
1853 \labelwidthstring 00.00.0000
1858 \begin_layout Standard
1867 -enable-doc Build pdf, html and txt files from the lyx sources
1871 \labelwidthstring 00.00.0000
1876 \begin_layout Standard
1885 -enable-libgc Use the Bohem memory allocator.
1886 Lower runtime footprint.
1890 \labelwidthstring 00.00.0000
1895 \begin_layout Standard
1904 -without-ccache Do not use ccache even if available
1907 \begin_layout Standard
1908 Furthermore the environment variables CC, CFLAGS, ...
1909 the tools and their arguments can be influenced.
1910 Please see `configure -
1914 \begin_layout Standard
1923 -help' and the man/info pages of `configure' for details.
1928 standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1929 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1930 SDCC_LIB_NAME are defined by `configure' too.
1931 At the moment it's not possible to change the default settings (it was
1932 simply never required).
1936 These configure options are compiled into the binaries,
1937 and can only be changed by rerunning 'configure' and recompiling SDCC.
1938 The configure options are written in
1942 to distinguish them from run time environment variables (see section search
1948 \begin_inset Quotes sld
1952 \begin_inset Quotes srd
1955 are used by the SDCC team to build the official Win32 binaries.
1956 The SDCC team uses Mingw32 to build the official Windows binaries, because
1960 \begin_layout Enumerate
1964 \begin_layout Enumerate
1965 a gcc compiler and last but not least
1968 \begin_layout Enumerate
1969 the binaries can be built by cross compiling on SDCC Distributed Compile
1973 \begin_layout Standard
1974 See the examples, how to pass the Win32 settings to 'configure'.
1975 The other Win32 builds using Borland, VC or whatever don't use 'configure',
1976 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1986 \begin_layout Standard
1988 \begin_inset Tabular
1989 <lyxtabular version="3" rows="9" columns="3">
1991 <column alignment="block" valignment="top" leftline="true" width="0in">
1992 <column alignment="block" valignment="top" leftline="true" width="0in">
1993 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1994 <row topline="true" bottomline="true">
1995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1998 \begin_layout Standard
2004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2007 \begin_layout Standard
2013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2016 \begin_layout Standard
2023 <row topline="true">
2024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2027 \begin_layout Standard
2035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2038 \begin_layout Standard
2044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2047 \begin_layout Standard
2056 <row topline="true">
2057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2060 \begin_layout Standard
2068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2071 \begin_layout Standard
2079 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2082 \begin_layout Standard
2091 <row topline="true">
2092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2095 \begin_layout Standard
2103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2106 \begin_layout Standard
2116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2119 \begin_layout Standard
2132 <row topline="true">
2133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2136 \begin_layout Standard
2144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2147 \begin_layout Standard
2155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2158 \begin_layout Standard
2167 <row topline="true">
2168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2171 \begin_layout Standard
2179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2182 \begin_layout Standard
2192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2195 \begin_layout Standard
2204 <row topline="true">
2205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2208 \begin_layout Standard
2216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2219 \begin_layout Standard
2229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2232 \begin_layout Standard
2245 <row topline="true">
2246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2249 \begin_layout Standard
2257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2260 \begin_layout Standard
2266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2269 \begin_layout Standard
2276 <row topline="true" bottomline="true">
2277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2280 \begin_layout Standard
2288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2291 \begin_layout Standard
2297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2300 \begin_layout Standard
2316 \begin_layout Standard
2318 'configure' also computes relative paths.
2319 This is needed for full relocatability of a binary package and to complete
2320 search paths (see section search paths below):
2325 \begin_layout Standard
2327 \begin_inset Tabular
2328 <lyxtabular version="3" rows="4" columns="3">
2330 <column alignment="block" valignment="top" leftline="true" width="0in">
2331 <column alignment="block" valignment="top" leftline="true" width="0in">
2332 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2333 <row topline="true" bottomline="true">
2334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2337 \begin_layout Standard
2343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2346 \begin_layout Standard
2352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2355 \begin_layout Standard
2362 <row topline="true" bottomline="true">
2363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2366 \begin_layout Standard
2374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2377 \begin_layout Standard
2383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2386 \begin_layout Standard
2393 <row bottomline="true">
2394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2397 \begin_layout Standard
2405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2408 \begin_layout Standard
2414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2417 \begin_layout Standard
2424 <row bottomline="true">
2425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2428 \begin_layout Standard
2436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2439 \begin_layout Standard
2445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2448 \begin_layout Standard
2464 \begin_layout Standard
2469 \begin_layout LyX-Code
2476 \begin_layout Standard
2486 \begin_inset Quotes srd
2490 \begin_inset Quotes srd
2497 \begin_layout Standard
2507 \begin_inset Quotes srd
2511 \begin_inset Quotes srd
2520 \begin_layout Standard
2533 \begin_layout Standard
2545 \begin_layout Standard
2546 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2550 \begin_layout LyX-Code
2556 \begin_inset Quotes srd
2559 i586-mingw32msvc-gcc
2560 \begin_inset Quotes srd
2564 \begin_inset Quotes srd
2567 i586-mingw32msvc-g++
2568 \begin_inset Quotes srd
2576 \begin_inset Quotes srd
2579 i586-mingw32msvc-ranlib
2580 \begin_inset Quotes srd
2588 \begin_inset Quotes srd
2591 i586-mingw32msvc-strip
2592 \begin_inset Quotes srd
2603 \begin_layout Standard
2613 \begin_inset Quotes srd
2617 \begin_inset Quotes srd
2628 \begin_layout Standard
2638 \begin_inset Quotes srd
2642 \begin_inset Quotes srd
2650 \begin_inset Quotes srd
2656 \begin_inset Quotes srd
2664 \begin_inset Quotes srd
2668 \begin_inset Quotes srd
2676 \begin_inset Quotes srd
2680 \begin_inset Quotes srd
2687 sdccconf_h_dir_separator=
2688 \begin_inset Quotes srd
2700 \begin_inset Quotes srd
2711 \begin_layout Standard
2728 \begin_layout Standard
2737 -host=i586-mingw32msvc
2745 \begin_layout Standard
2754 -build=unknown-unknown-linux-gnu
2757 \begin_layout Standard
2759 \begin_inset Quotes sld
2763 \begin_inset Quotes srd
2766 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2770 \begin_layout LyX-Code
2779 \begin_layout Standard
2789 \begin_inset Quotes srd
2793 \begin_inset Quotes srd
2804 \begin_layout Standard
2814 \begin_inset Quotes srd
2818 \begin_inset Quotes srd
2826 \begin_inset Quotes srd
2832 \begin_inset Quotes srd
2840 \begin_inset Quotes srd
2844 \begin_inset Quotes srd
2852 \begin_inset Quotes srd
2856 \begin_inset Quotes srd
2863 sdccconf_h_dir_separator=
2864 \begin_inset Quotes srd
2876 \begin_inset Quotes srd
2884 \begin_inset Quotes srd
2888 \begin_inset Quotes srd
2896 \begin_inset Quotes srd
2900 \begin_inset Quotes srd
2906 \begin_layout Standard
2907 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2912 \begin_layout Standard
2921 -C' turns on caching, which gives a little bit extra speed.
2922 However if options are changed, it can be necessary to delete the config.cache
2926 \begin_layout Section
2928 \begin_inset LatexCommand label
2929 name "sub:Install-paths"
2934 \begin_inset LatexCommand index
2935 name "Install paths"
2942 \begin_layout Standard
2943 \begin_inset VSpace medskip
2949 \begin_layout Standard
2951 \begin_inset Tabular
2952 <lyxtabular version="3" rows="5" columns="4">
2954 <column alignment="left" valignment="top" leftline="true" width="0">
2955 <column alignment="left" valignment="top" leftline="true" width="0">
2956 <column alignment="left" valignment="top" leftline="true" width="0">
2957 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2958 <row topline="true" bottomline="true">
2959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2962 \begin_layout Standard
2970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2973 \begin_layout Standard
2981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2984 \begin_layout Standard
2992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2995 \begin_layout Standard
3004 <row topline="true">
3005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3008 \begin_layout Standard
3014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3017 \begin_layout Standard
3025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3028 \begin_layout Standard
3034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3037 \begin_layout Standard
3048 <row topline="true">
3049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3052 \begin_layout Standard
3058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3061 \begin_layout Standard
3064 $DATADIR/ $INCLUDE_DIR_SUFFIX
3069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3072 \begin_layout Standard
3073 /usr/local/share/sdcc/include
3078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3081 \begin_layout Standard
3092 <row topline="true">
3093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3096 \begin_layout Standard
3102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3105 \begin_layout Standard
3108 $DATADIR/$LIB_DIR_SUFFIX
3113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3116 \begin_layout Standard
3117 /usr/local/share/sdcc/lib
3122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3125 \begin_layout Standard
3136 <row topline="true" bottomline="true">
3137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3140 \begin_layout Standard
3146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3149 \begin_layout Standard
3157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3160 \begin_layout Standard
3161 /usr/local/share/sdcc/doc
3166 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3169 \begin_layout Standard
3190 *compiler, preprocessor, assembler, and linker
3196 is auto-appended by the compiler, e.g.
3197 small, large, z80, ds390 etc
3200 \begin_layout Standard
3202 The install paths can still be changed during `make install' with e.g.:
3205 \begin_layout LyX-Code
3206 make install prefix=$(HOME)/local/sdcc
3209 \begin_layout Standard
3210 Of course this doesn't change the search paths compiled into the binaries.
3215 r the install path can be changed by defining DESTDIR
3216 \begin_inset LatexCommand index
3224 \begin_layout LyX-Code
3225 make install DESTDIR=$(HOME)/sdcc.rpm/
3228 \begin_layout Standard
3229 Please note that DESTDIR must have a trailing slash!
3232 \begin_layout Section
3234 \begin_inset LatexCommand label
3235 name "sub:Search-Paths"
3240 \begin_inset LatexCommand index
3248 \begin_layout Standard
3249 Some search paths or parts of them are determined by configure variables
3254 , see section above).
3255 Further search paths are determined by environment variables during runtime.
3258 The paths searched when running the compiler are as follows (the first
3264 Binary files (preprocessor, assembler and linker)
3269 \begin_layout Standard
3271 \begin_inset Tabular
3272 <lyxtabular version="3" rows="4" columns="3">
3274 <column alignment="block" valignment="top" leftline="true" width="0in">
3275 <column alignment="block" valignment="top" leftline="true" width="0in">
3276 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3277 <row topline="true" bottomline="true">
3278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3281 \begin_layout Standard
3287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3290 \begin_layout Standard
3296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3299 \begin_layout Standard
3306 <row topline="true">
3307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3310 \begin_layout Standard
3318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3321 \begin_layout Standard
3327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3330 \begin_layout Standard
3339 <row topline="true">
3340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3343 \begin_layout Standard
3344 Path of argv[0] (if available)
3349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3352 \begin_layout Standard
3358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3361 \begin_layout Standard
3368 <row topline="true" bottomline="true">
3369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3372 \begin_layout Standard
3378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3381 \begin_layout Standard
3387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3390 \begin_layout Standard
3406 \begin_layout Standard
3414 \begin_layout Standard
3416 \begin_inset Tabular
3417 <lyxtabular version="3" rows="6" columns="3">
3419 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3420 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3421 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3422 <row topline="true" bottomline="true">
3423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3426 \begin_layout Standard
3432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3435 \begin_layout Standard
3441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3444 \begin_layout Standard
3451 <row topline="true">
3452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3455 \begin_layout Standard
3460 \begin_layout Standard
3474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3477 \begin_layout Standard
3482 \begin_layout Standard
3496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3499 \begin_layout Standard
3504 \begin_layout Standard
3519 <row topline="true">
3520 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3523 \begin_layout Standard
3529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3532 \begin_layout Standard
3538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3541 \begin_layout Standard
3548 <row topline="true">
3549 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3552 \begin_layout Standard
3564 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3567 \begin_layout Standard
3577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3580 \begin_layout Standard
3589 <row topline="true">
3590 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3593 \begin_layout Standard
3609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3612 \begin_layout Standard
3660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3663 \begin_layout Standard
3674 <row topline="true" bottomline="true">
3675 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3678 \begin_layout Standard
3692 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3695 \begin_layout Standard
3696 /usr/local/share/sdcc/
3703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3706 \begin_layout Standard
3722 \begin_layout Standard
3728 \begin_layout Standard
3737 -nostdinc disables the last two search paths.
3747 \begin_layout Standard
3748 With the exception of
3749 \begin_inset Quotes sld
3756 \begin_layout Standard
3766 \begin_inset Quotes srd
3773 is auto-appended by the compiler (e.g.
3774 small, large, z80, ds390 etc.).
3780 \begin_layout Standard
3782 \begin_inset Tabular
3783 <lyxtabular version="3" rows="6" columns="3">
3785 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3786 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3787 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3788 <row topline="true" bottomline="true">
3789 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3792 \begin_layout Standard
3798 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3801 \begin_layout Standard
3807 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3810 \begin_layout Standard
3817 <row topline="true">
3818 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3821 \begin_layout Standard
3826 \begin_layout Standard
3840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3843 \begin_layout Standard
3848 \begin_layout Standard
3862 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3865 \begin_layout Standard
3870 \begin_layout Standard
3885 <row topline="true">
3886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3889 \begin_layout Standard
3899 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3902 \begin_layout Standard
3912 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3915 \begin_layout Standard
3928 <row topline="true">
3929 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3932 \begin_layout Standard
3939 $LIB_DIR_SUFFIX/<model>
3944 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3947 \begin_layout Standard
3959 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3962 \begin_layout Standard
3977 <row topline="true">
3978 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3981 \begin_layout Standard
3992 $LIB_DIR_SUFFIX/<model>
3997 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
4000 \begin_layout Standard
4051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4054 \begin_layout Standard
4108 <row topline="true" bottomline="true">
4109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4112 \begin_layout Standard
4117 $LIB_DIR_SUFFIX/<model>
4122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4125 \begin_layout Standard
4126 /usr/local/share/sdcc/
4135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4138 \begin_layout Standard
4154 \begin_layout Standard
4155 \begin_inset Note Note
4158 \begin_layout Standard
4159 Don't delete any of the stray spaces in the table above without checking
4160 the HTML output (last line)!
4168 \begin_layout Standard
4176 \begin_layout Standard
4185 -nostdlib disables the last two search paths.
4188 \begin_layout Section
4190 \begin_inset LatexCommand index
4191 name "Building SDCC"
4198 \begin_layout Subsection
4199 Building SDCC on Linux
4200 \begin_inset LatexCommand label
4201 name "sub:Building-SDCC-on-Linux"
4208 \begin_layout Enumerate
4211 Download the source package
4213 either from the SDCC Subversion repository or from snapshot builds
4215 , it will be named something like sdcc
4226 \begin_inset LatexCommand url
4227 target "http://sdcc.sourceforge.net/snap.php"
4234 \begin_layout Enumerate
4237 Bring up a command line terminal, such as xterm.
4240 \begin_layout Enumerate
4243 Unpack the file using a command like:
4248 "tar -xvjf sdcc-src-yyyymmdd-rrrr.tar.bz2
4249 \begin_inset Quotes srd
4255 , this will create a sub-directory called sdcc with all of the sources.
4258 \begin_layout Enumerate
4259 Change directory into the main SDCC directory, for example type:
4267 \begin_layout Enumerate
4279 This configures the package for compilation on your system.
4282 \begin_layout Enumerate
4298 All of the source packages will compile, this can take a while.
4301 \begin_layout Enumerate
4317 This copies the binary executables, the include files, the libraries and
4318 the documentation to the install directories.
4319 Proceed with section
4320 \begin_inset LatexCommand ref
4321 reference "sec:Testing-the-SDCC"
4328 \begin_layout Subsection
4329 Building SDCC on Mac OS X
4332 \begin_layout Standard
4333 Follow the instruction for Linux.
4337 On Mac OS X 10.2.x it was reported, that the
4338 default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
4339 Fortunately there's also gcc 2.9.x installed, which works fine.
4340 This compiler can be selected by running 'configure' with:
4343 \begin_layout LyX-Code
4344 ./configure CC=gcc2 CXX=g++2
4347 \begin_layout Standard
4348 Universal (ppc and i386) binaries can be produced on Mac OS X 10.4.x with
4350 Run 'configure' with:
4353 \begin_layout LyX-Code
4359 \begin_layout LyX-Code
4360 LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4366 \begin_layout LyX-Code
4367 CXXFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4373 \begin_layout LyX-Code
4374 CFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
4377 \begin_layout Subsection
4378 Cross compiling SDCC on Linux for Windows
4381 \begin_layout Standard
4382 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
4383 See section 'Configure Options'.
4386 \begin_layout Subsection
4387 Building SDCC using Cygwin and Mingw32
4390 \begin_layout Standard
4391 For building and installing a Cygwin executable follow the instructions
4397 \begin_inset Quotes sld
4401 \begin_inset Quotes srd
4404 Win32-binary can be built, which will not need the Cygwin-DLL.
4405 For the necessary 'configure' options see section 'configure options' or
4406 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4411 Cygwin on Windows download setup.exe from
4412 \begin_inset LatexCommand url
4413 name "www.cygwin.com"
4414 target "http://www.cygwin.com/"
4420 \begin_inset Quotes sld
4423 default text file type
4424 \begin_inset Quotes srd
4428 \begin_inset Quotes sld
4432 \begin_inset Quotes srd
4435 and download/install at least the following packages.
4436 Some packages are selected by default, others will be automatically selected
4437 because of dependencies with the manually selected packages.
4438 Never deselect these packages!
4441 \begin_layout Itemize
4445 \begin_layout Itemize
4449 \begin_layout Itemize
4450 gcc ; version 3.x is fine, no need to use the old 2.9x
4453 \begin_layout Itemize
4454 binutils ; selected with gcc
4457 \begin_layout Itemize
4461 \begin_layout Itemize
4462 rxvt ; a nice console, which makes life much easier under windoze (see below)
4465 \begin_layout Itemize
4466 man ; not really needed for building SDCC, but you'll miss it sooner or
4470 \begin_layout Itemize
4471 less ; not really needed for building SDCC, but you'll miss it sooner or
4475 \begin_layout Itemize
4476 svn ; only if you use Subversion access
4479 \begin_layout Standard
4480 If you want to develop something you'll need:
4483 \begin_layout Itemize
4484 python ; for the regression tests
4487 \begin_layout Itemize
4488 gdb ; the gnu debugger, together with the nice GUI
4489 \begin_inset Quotes sld
4493 \begin_inset Quotes srd
4499 \begin_layout Itemize
4500 openssh ; to access the CF or commit changes
4503 \begin_layout Itemize
4504 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4505 use autoconf-stable!
4508 \begin_layout Standard
4509 rxvt is a nice console with history.
4510 Replace in your cygwin.bat the line
4513 \begin_layout LyX-Code
4518 \begin_layout Standard
4530 \begin_layout Standard
4534 \begin_layout LyX-Code
4535 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4538 \begin_layout LyX-Code
4539 -bg black -fg white -geometry 100x65 -e bash -
4543 \begin_layout Standard
4555 \begin_layout Standard
4556 Text selected with the mouse is automatically copied to the clipboard, pasting
4557 works with shift-insert.
4561 The other good tip is to make sure you have no //c/-styl
4562 e paths anywhere, use /cygdrive/c/ instead.
4563 Using // invokes a network lookup which is very slow.
4565 \begin_inset Quotes sld
4569 \begin_inset Quotes srd
4572 is too long, you can change it with e.g.
4575 \begin_layout LyX-Code
4579 \begin_layout Standard
4580 SDCC sources use the unix line ending LF.
4581 Life is much easier, if you store the source tree on a drive which is mounted
4583 And use an editor which can handle LF-only line endings.
4584 Make sure not to commit files with windows line endings.
4585 The tabulator spacing
4586 \begin_inset LatexCommand index
4587 name "tabulator spacing (8 columns)"
4591 used in the project is 8.
4592 Although a tabulator spacing of 8 is a sensible choice for programmers
4593 (it's a power of 2 and allows to display 8/16 bit signed variables without
4594 loosing columns) the plan is to move towards using only spaces in the source.
4597 \begin_layout Subsection
4598 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4601 \begin_layout Standard
4604 Download the source package
4606 either from the SDCC Subversion repository or from the
4607 \begin_inset LatexCommand url
4608 name "snapshot builds"
4609 target "http://sdcc.sourceforge.net/snap.php"
4615 , it will be named something like sdcc
4619 -yyyymmdd-rrrr.tar.bz2.
4622 SDCC is distributed with all the projects, workspaces, and files you need
4623 to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4624 The workspace name is 'sdcc.dsw'.
4625 Please note that as it is now, all the executables are created in a folder
4629 Once built you need to copy the executables from sdcc
4633 bin before running SDCC.
4638 WARNING: Visual studio is very picky with line terminations; it expects
4639 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4640 When using the Subversion repository it's easiest to configure the svn
4641 client to convert automatically for you.
4642 If however you are getting a message such as "This makefile was not generated
4643 by Developer Studio etc.
4645 \begin_inset Quotes srd
4648 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4649 need to convert the Unix style line endings to DOS style line endings.
4650 To do so you can use the
4651 \begin_inset Quotes sld
4655 \begin_inset Quotes srd
4658 utility freely available on the internet.
4659 Doug Hawkins reported in the sdcc-user list that this works:
4667 SDCC> unix2dos sdcc.dsw
4673 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4677 In order to build SDCC with MSVC
4678 you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4679 One good place to get them is
4680 \begin_inset LatexCommand url
4682 target "http://unxutils.sourceforge.net"
4690 Download the file UnxUtils
4691 \begin_inset LatexCommand index
4697 Now you have to install the utilities and setup MSVC so it can locate the
4699 Here there are two alternatives (choose one!):
4702 \begin_layout Enumerate
4707 a) Extract UnxUtils.zip to your C:
4709 hard disk PRESERVING the original paths, otherwise bison won't work.
4710 (If you are using WinZip make certain that 'Use folder names' is selected)
4715 In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4716 'Show directories for:' select 'Executable files', and in the directories
4717 window add a new path: 'C:
4727 (As a side effect, you get a bunch of Unix utilities that
4728 could be useful, such as diff and patch.)
4731 \begin_layout Enumerate
4736 This one avoids extracting a bunch of files you may not
4737 use, but requires some extra work:
4741 a) Create a directory were to put the
4742 tools needed, or use a directory already present.
4749 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4750 gawk.exe to such directory WITHOUT preserving the original paths.
4751 (If you are using WinZip make certain that 'Use folder names' is not selected)
4756 ) Rename bison.exe to '_bison.exe'.
4760 d) Create a batch file 'bison.bat' in 'C:
4764 ' and add these lines:
4784 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4788 Steps 'c' and 'd' are needed
4789 because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4790 reside in some weird Unix directory, '/usr/local/share/' I think.
4791 So it is necessary to tell bison where those files are located if they
4792 are not in such directory.
4793 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4798 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4799 in 'Show directories for:' select 'Executable files', and in the directories
4800 window add a new path: 'c:
4803 Note that you can use any other path instead of 'c:
4805 util', even the path where the Visual C++ tools are, probably: 'C:
4809 Microsoft Visual Studio
4814 So you don't have to execute step 'e' :)
4817 \begin_layout Standard
4819 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4820 the executables from sdcc
4824 bin, and you can compile using SDCC.
4827 \begin_layout Subsection
4828 Building SDCC Using Borland
4831 \begin_layout Enumerate
4832 From the sdcc directory, run the command "make -f Makefile.bcc".
4833 This should regenerate all the .exe files in the bin directory except for
4837 \begin_layout Enumerate
4838 If you modify any source files and need to rebuild, be aware that the dependenci
4839 es may not be correctly calculated.
4840 The safest option is to delete all .obj files and run the build again.
4841 From a Cygwin BASH prompt, this can easily be done with the command (be
4842 sure you are in the sdcc directory):
4852 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
4854 ) -print -exec rm {}
4863 or on Windows NT/2000/XP from the command prompt with the command:
4870 del /s *.obj *.lib *.rul
4873 from the sdcc directory.
4876 \begin_layout Subsection
4877 Windows Install Using a ZIP Package
4880 \begin_layout Enumerate
4881 Download the binary zip package from
4882 \begin_inset LatexCommand url
4883 target "http://sdcc.sf.net/snap.php"
4887 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4888 This should unpack to a group of sub-directories.
4889 An example directory structure after unpacking the mingw32 package is:
4894 bin for the executables, c:
4902 lib for the include and libraries.
4905 \begin_layout Enumerate
4906 Adjust your environment variable PATH to include the location of the bin
4907 directory or start sdcc using the full path.
4910 \begin_layout Subsection
4911 Windows Install Using the Setup Program
4912 \begin_inset LatexCommand label
4913 name "sub:Windows-Install"
4920 \begin_layout Standard
4921 Download the setup program
4923 sdcc-x.y.z-setup.exe
4925 for an official release from
4928 \begin_inset LatexCommand url
4929 target "http://sf.net/project/showfiles.php?group_id=599"
4933 or a setup program for one of the snapshots
4935 sdcc-yyyymmdd-xxxx-setup.exe
4938 \begin_inset LatexCommand url
4939 target "http://sdcc.sf.net/snap.php"
4944 A windows typical installer will guide you through the installation process.
4947 \begin_layout Subsection
4949 \begin_inset LatexCommand index
4957 \begin_layout Standard
4958 SDCC supports the VPATH feature provided by configure and make.
4959 It allows to separate the source and build trees.
4963 \begin_layout Standard
5005 \begin_layout Standard
5008 tar -xjf sdcc-src-yyyymmdd-rrrr.tar.bz2\InsetSpace ~
5009 # extract source to directory sdcc
5012 \begin_layout Standard
5015 mkdir sdcc.build\InsetSpace ~
5039 # put output in sdcc.build
5042 \begin_layout Standard
5048 \begin_layout Standard
5051 ../sdcc/configure\InsetSpace ~
5074 # configure is doing all the magic!
5077 \begin_layout Standard
5083 \begin_layout Standard
5089 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
5090 It automagically computes the variables srcdir, top_srcdir and top_buildir
5096 the generated files will be in ~/sdcc.build, while the source files stay
5099 This is not only usefull for building different binaries, e.g.
5100 when cross compiling.
5101 It also gives you a much better overview in the source tree when all the
5102 generated files are not scattered between the source files.
5103 And the best thing is: if you want to change a file you can leave the original
5104 file untouched in the source directory.
5105 Simply copy it to the build directory, edit it, enter `make clean', `rm
5106 Makefile.dep' and `make'.
5111 will do the rest for you!
5114 \begin_layout Section
5115 Building the Documentation
5118 \begin_layout Standard
5123 \begin_layout Standard
5132 -enable-doc to the configure arguments to build the documentation together
5133 with all the other stuff.
5134 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
5135 dvips and makeindex) to get the job done.
5136 Another possibility is to change to the doc directory and to type
5140 \begin_inset Quotes srd
5144 \begin_inset Quotes srd
5151 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
5154 \begin_inset LatexCommand url
5155 target "http://www.lyx.org"
5159 as editor is straightforward.
5160 Prebuilt documentation in html and pdf format is available from
5161 \begin_inset LatexCommand url
5162 target "http://sdcc.sf.net/snap.php"
5169 \begin_layout Section
5170 Reading the Documentation
5171 \begin_inset LatexCommand index
5172 name "Documentation"
5179 \begin_layout Standard
5180 Currently reading the document in pdf format is recommended, as for unknown
5181 reason the hyperlinks are working there whereas in the html version they
5186 \begin_layout Standard
5187 If you should know why please drop us a note
5195 You'll find the pdf version
5196 \begin_inset LatexCommand index
5197 name "PDF version of this document"
5202 \begin_inset LatexCommand url
5203 target "http://sdcc.sf.net/doc/sdccman.pdf"
5211 \begin_inset LatexCommand index
5212 name "HTML version of this document"
5217 \begin_inset LatexCommand url
5218 target "http://sdcc.sf.net/doc/sdccman.html/index.html"
5224 This documentation is in some aspects different from a commercial documentation:
5228 \begin_layout Itemize
5229 It tries to document SDCC for several processor architectures in one document
5230 (commercially these probably would be separate documents/products).
5232 \begin_inset LatexCommand index
5233 name "Status of documentation"
5237 currently matches SDCC for mcs51 and DS390 best and does give too few informati
5239 Z80, PIC14, PIC16 and HC08.
5242 \begin_layout Itemize
5243 There are many references pointing away from this documentation.
5244 Don't let this distract you.
5246 was a reference like
5247 \begin_inset LatexCommand url
5248 target "http://www.opencores.org"
5252 together with a statement
5253 \begin_inset Quotes sld
5256 some processors which are targetted by SDCC can be implemented in a
5273 \begin_inset LatexCommand index
5274 name "FPGA (field programmable gate array)"
5279 \begin_inset Quotes srd
5283 \begin_inset LatexCommand url
5284 target "http://sf.net/projects/fpgac"
5289 \begin_inset LatexCommand index
5290 name "FpgaC ((subset of) C to FPGA compiler)"
5295 \begin_inset Quotes sld
5298 have you ever heard of an open source compiler that compiles a subset of
5300 \begin_inset Quotes srd
5303 we expect you to have a quick look there and come back.
5304 If you read this you are on the right track.
5307 \begin_layout Itemize
5308 Some sections attribute more space to problems, restrictions and warnings
5309 than to the solution.
5312 \begin_layout Itemize
5313 The installation section and the section about the debugger is intimidating.
5316 \begin_layout Itemize
5317 There are still lots of typos and there are more different writing styles
5321 \begin_layout Section
5322 Testing the SDCC Compiler
5323 \begin_inset LatexCommand label
5324 name "sec:Testing-the-SDCC"
5331 \begin_layout Standard
5332 The first thing you should do after installing your SDCC compiler is to
5341 \begin_layout Standard
5351 \begin_inset LatexCommand index
5359 at the prompt, and the program should run and output its version like:
5364 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
5368 \begin_layout Standard
5369 If it doesn't run, or gives a message about not finding sdcc program, then
5370 you need to check over your installation.
5371 Make sure that the sdcc bin directory is in your executable search path
5372 defined by the PATH environment setting (
5377 \begin_inset LatexCommand ref
5378 reference "sub:Install-Trouble-shooting"
5385 Install trouble-shooting for suggestions
5388 Make sure that the sdcc program is in the bin folder, if not perhaps something
5389 did not install correctly.
5397 is commonly installed as described in section
5398 \begin_inset Quotes sld
5401 Install and search paths
5402 \begin_inset Quotes srd
5411 Make sure the compiler works on a very simple example.
5412 Type in the following test.c program using your favorite
5437 \begin_layout Standard
5440 Compile this using the following command:
5451 If all goes well, the compiler will generate a test.asm and test.rel file.
5452 Congratulations, you've just compiled your first program with SDCC.
5453 We used the -c option to tell SDCC not to link the generated code, just
5454 to keep things simple for this step.
5462 The next step is to try it with the linker.
5474 If all goes well the compiler will link with the libraries and produce
5475 a test.ihx output file.
5480 (no test.ihx, and the linker generates warnings), then the problem is most
5489 usr/local/share/sdcc/lib directory
5496 \begin_inset LatexCommand ref
5497 reference "sub:Install-Trouble-shooting"
5504 Install trouble-shooting for suggestions).
5512 The final test is to ensure
5520 header files and libraries.
5521 Edit test.c and change it to the following:
5539 strcpy(str1, "testing");
5544 \begin_layout Standard
5547 Compile this by typing
5556 This should generate a test.ihx output file, and it should give no warnings
5557 such as not finding the string.h file.
5558 If it cannot find the string.h file, then the problem is that
5562 cannot find the /usr/local/share/sdcc/include directory
5569 \begin_inset LatexCommand ref
5570 reference "sub:Install-Trouble-shooting"
5577 Install trouble-shooting section for suggestions).
5586 \begin_layout Standard
5598 \begin_inset LatexCommand index
5599 name "-\\/-print-search-dirs"
5603 to find exactly where SDCC is looking for the include and lib files.
5606 \begin_layout Section
5607 Install Trouble-shooting
5608 \begin_inset LatexCommand label
5609 name "sub:Install-Trouble-shooting"
5614 \begin_inset LatexCommand index
5615 name "Install trouble-shooting"
5622 \begin_layout Subsection
5623 If SDCC does not build correctly
5626 \begin_layout Standard
5627 A thing to try is starting from scratch by unpacking the .tgz source package
5628 again in an empty directory.
5636 ./configure 2>&1 | tee configure.log
5650 make 2>&1 | tee make.log
5657 If anything goes wrong, you can review the log files to locate the problem.
5658 Or a relevant part of this can be attached to an email that could be helpful
5659 when requesting help from the mailing list.
5662 \begin_layout Subsection
5664 \begin_inset Quotes sld
5668 \begin_inset Quotes srd
5674 \begin_layout Standard
5676 \begin_inset Quotes sld
5680 \begin_inset Quotes srd
5683 command is a script that analyzes your system and performs some configuration
5684 to ensure the source package compiles on your system.
5685 It will take a few minutes to run, and will compile a few tests to determine
5686 what compiler features are installed.
5689 \begin_layout Subsection
5691 \begin_inset Quotes sld
5695 \begin_inset Quotes srd
5701 \begin_layout Standard
5702 This runs the GNU make tool, which automatically compiles all the source
5703 packages into the final installed binary executables.
5706 \begin_layout Subsection
5708 \begin_inset Quotes sld
5712 \begin_inset Quotes erd
5718 \begin_layout Standard
5719 This will install the compiler, other executables libraries and include
5720 files into the appropriate directories.
5722 \begin_inset LatexCommand ref
5723 reference "sub:Install-paths"
5729 \begin_inset LatexCommand ref
5730 reference "sub:Search-Paths"
5735 about install and search paths.
5737 On most systems you will need super-user privilege
5741 \begin_layout Section
5745 \begin_layout Standard
5746 SDCC is not just a compiler, but a collection of tools by various developers.
5747 These include linkers, assemblers, simulators and other components.
5748 Here is a summary of some of the components.
5749 Note that the included simulator and assembler have separate documentation
5750 which you can find in the source package in their respective directories.
5751 As SDCC grows to include support for other processors, other packages from
5752 various developers are included and may have their own sets of documentation.
5757 might want to look at the files which are installed in <installdir>.
5758 At the time of this writing, we find the following programs for gcc-builds:
5763 In <installdir>/bin:
5766 \begin_layout Itemize
5767 sdcc - The compiler.
5770 \begin_layout Itemize
5771 sdcpp - The C preprocessor.
5774 \begin_layout Itemize
5775 asx8051 - The assembler for 8051 type processors.
5778 \begin_layout Itemize
5783 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5786 \begin_layout Itemize
5787 aslink -The linker for 8051 type processors.
5790 \begin_layout Itemize
5795 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5798 \begin_layout Itemize
5799 s51 - The ucSim 8051 simulator.
5802 \begin_layout Itemize
5803 sdcdb - The source debugger.
5806 \begin_layout Itemize
5807 packihx - A tool to pack (compress) Intel hex files.
5810 \begin_layout Standard
5811 In <installdir>/share/sdcc/include
5814 \begin_layout Itemize
5818 \begin_layout Standard
5819 In <installdir>/share/sdcc/lib
5822 \begin_layout Itemize
5823 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5827 \begin_layout Standard
5828 In <installdir>/share/sdcc/doc
5831 \begin_layout Itemize
5835 \begin_layout Standard
5836 As development for other processors proceeds, this list will expand to include
5837 executables to support processors like AVR, PIC, etc.
5840 \begin_layout Subsection
5844 \begin_layout Standard
5845 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5846 the assembler and linkage editor.
5849 \begin_layout Subsection
5850 sdcpp - The C-Preprocessor
5853 \begin_layout Standard
5855 \begin_inset LatexCommand index
5856 name "sdcpp (preprocessor)"
5860 is a modified version of the GNU cpp
5861 \begin_inset LatexCommand index
5862 name "cpp|see{sdcpp}"
5867 \begin_inset LatexCommand url
5868 target "http://gcc.gnu.org/"
5873 The C preprocessor is used to pull in #include sources, process #ifdef
5874 statements, #defines and so on.
5877 \begin_layout Subsection
5886 - The Assemblers and Linkage Editors
5889 \begin_layout Standard
5890 This is retargettable assembler & linkage editor, it was developed by Alan
5892 John Hartman created the version for 8051, and I (Sandeep) have made some
5893 enhancements and bug fixes for it to work properly with SDCC.
5896 \begin_layout Subsection
5900 \begin_layout Standard
5902 \begin_inset LatexCommand index
5907 is a free open source simulator developed by Daniel Drotos.
5908 The simulator is built as part of the build process.
5909 For more information visit Daniel's web site at:
5910 \begin_inset LatexCommand url
5911 target "http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51"
5916 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5920 \begin_layout Subsection
5921 sdcdb - Source Level Debugger
5924 \begin_layout Standard
5926 \begin_inset LatexCommand index
5927 name "SDCDB (debugger)"
5931 is the companion source level debugger.
5932 More about SDCDB in section
5933 \begin_inset LatexCommand ref
5934 reference "cha:Debugging-with-SDCDB"
5939 The current version of the debugger uses Daniel's Simulator S51
5940 \begin_inset LatexCommand index
5945 , but can be easily changed to use other simulators.
5948 \begin_layout Chapter
5952 \begin_layout Section
5956 \begin_layout Subsection
5957 Single Source File Projects
5960 \begin_layout Standard
5961 For single source file 8051 projects the process is very simple.
5962 Compile your programs with the following command
5965 "sdcc sourcefile.c".
5969 This will compile, assemble and link your source file.
5970 Output files are as follows:
5973 \begin_layout Itemize
5975 \begin_inset LatexCommand index
5981 \begin_inset LatexCommand index
5982 name "Assembler source"
5986 file created by the compiler
5989 \begin_layout Itemize
5991 \begin_inset LatexCommand index
5997 \begin_inset LatexCommand index
5998 name "Assembler listing"
6002 file created by the Assembler
6005 \begin_layout Itemize
6007 \begin_inset LatexCommand index
6013 \begin_inset LatexCommand index
6014 name "Assembler listing"
6018 file updated with linkedit information, created by linkage editor
6021 \begin_layout Itemize
6023 \begin_inset LatexCommand index
6029 \begin_inset LatexCommand index
6030 name "Symbol listing"
6034 for the sourcefile, created by the assembler
6037 \begin_layout Itemize
6039 \begin_inset LatexCommand index
6045 \begin_inset LatexCommand index
6051 \begin_inset LatexCommand index
6056 created by the assembler, input to Linkage editor
6059 \begin_layout Itemize
6061 \begin_inset LatexCommand index
6067 \begin_inset LatexCommand index
6072 for the load module, created by the Linker
6075 \begin_layout Itemize
6077 \begin_inset LatexCommand index
6082 - A file with a summary of the memory usage
6085 \begin_layout Itemize
6087 \begin_inset LatexCommand index
6092 - The load module in Intel hex format
6093 \begin_inset LatexCommand index
6094 name "Intel hex format"
6098 (you can select the Motorola S19 format
6099 \begin_inset LatexCommand index
6100 name "Motorola S19 format"
6108 \begin_layout Standard
6118 \begin_inset LatexCommand index
6119 name "-\\/-out-fmt-s19"
6124 If you need another format you might want to use
6131 \begin_inset LatexCommand index
6132 name "objdump (tool)"
6143 \begin_inset LatexCommand index
6144 name "srecord (bin, hex, ... tool)"
6149 \begin_inset Note Note
6152 \begin_layout Standard
6159 \begin_inset LatexCommand vref
6160 reference "sub:Postprocessing-the-Intel"
6165 Both formats are documented in the documentation of srecord
6166 \begin_inset LatexCommand index
6167 name "srecord (bin, hex, ... tool)"
6174 \begin_layout Itemize
6176 \begin_inset LatexCommand index
6181 - An intermediate file containing debug information needed to create the
6186 \begin_layout Standard
6196 \begin_inset LatexCommand index
6204 \begin_layout Itemize
6206 \begin_inset LatexCommand index
6211 - An optional file (with -
6215 \begin_layout Standard
6224 -debug) containing debug information.
6225 The format is documented in cdbfileformat.pdf
6228 \begin_layout Itemize
6231 \begin_inset LatexCommand index
6232 name "<file> (no extension)"
6236 An optional AOMF or AOMF51
6237 \begin_inset LatexCommand index
6243 \begin_inset LatexCommand label
6248 file containing debug information (generated with option -
6252 \begin_layout Standard
6278 ormat is a subformat of the OMF51 format and is commonly used by third party
6280 \begin_inset LatexCommand index
6285 , simulators, emulators).
6288 \begin_layout Itemize
6290 \begin_inset LatexCommand index
6295 - Dump file to debug the compiler it self (generated with option -
6299 \begin_layout Standard
6308 -dumpall) (see section
6309 \begin_inset LatexCommand ref
6310 reference "sub:Intermediate-Dump-Options"
6316 \begin_inset LatexCommand ref
6317 reference "sub:The-anatomy-of"
6323 \begin_inset Quotes sld
6326 Anatomy of the compiler
6327 \begin_inset Quotes srd
6333 \begin_layout Subsection
6334 Postprocessing the Intel Hex
6335 \begin_inset LatexCommand index
6336 name "Intel hex format"
6341 \begin_inset LatexCommand label
6342 name "sub:Postprocessing-the-Intel"
6349 \begin_layout Standard
6350 In most cases this won't be needed but the Intel Hex file
6351 \begin_inset LatexCommand index
6356 which is generated by SDCC might include lines of varying length and the
6357 addresses within the file are not guaranteed to be strictly ascending.
6358 If your toolchain or a bootloader does not like this you can use the tool
6364 \begin_inset LatexCommand index
6365 name "packihx (tool)"
6369 which is part of the SDCC distribution:
6376 packihx sourcefile.ihx >sourcefile.hex
6383 The separately available
6388 \begin_inset LatexCommand index
6389 name "srecord (bin, hex, ... tool)"
6393 package additionally allows to set undefined locations to a predefined
6394 value, to insert checksums
6395 \begin_inset LatexCommand index
6400 of various flavours (crc, add, xor) and to perform other manipulations
6401 (convert, split, crop, offset, ...).
6409 srec_cat\InsetSpace ~
6411 sourcefile.ihx -intel\InsetSpace ~
6413 -o sourcefile.hex -intel
6420 An example for a more complex command line
6424 \begin_layout Standard
6425 the command backfills
6426 \begin_inset LatexCommand index
6427 name "backfill unused memory"
6431 unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
6433 If the program counter on an mcs51 runs wild the backfill pattern 0x12
6434 will be interpreted as an
6442 (where an emergency routine could sit).
6455 srec_cat\InsetSpace ~
6456 sourcefile.ihx -intel\InsetSpace ~
6458 -fill 0x12 0x0000 0xfffe\InsetSpace ~
6459 -little-endian-checksum-nega
6460 tive 0xfffe 0x02 0x02\InsetSpace ~
6462 -o sourcefile.hex -intel
6471 The srecord package is available at
6472 \begin_inset LatexCommand url
6473 target "http://sf.net/projects/srecord"
6480 \begin_layout Subsection
6481 Projects with Multiple Source Files
6484 \begin_layout Standard
6485 SDCC can compile only ONE file at a time.
6486 Let us for example assume that you have a project containing the following
6491 foo1.c (contains some functions)
6493 foo2.c (contains some more functions)
6496 n.c (contains more functions and the function main)
6504 The first two files will need to be compiled separately with the commands:
6536 Then compile the source file containing the
6541 \begin_inset LatexCommand index
6546 the files together with the following command:
6554 foomain.c\InsetSpace ~
6555 foo1.rel\InsetSpace ~
6560 \begin_inset LatexCommand index
6573 can be separately compiled as well:
6584 sdcc foomain.rel foo1.rel foo2.rel
6591 The file containing the
6603 file specified in the command line, since the linkage editor processes
6604 file in the order they are presented to it.
6605 The linker is invoked from SDCC using a script file with extension .lnk
6606 \begin_inset LatexCommand index
6612 You can view this file to troubleshoot linking problems such as those arising
6613 from missing libraries.
6616 \begin_layout Subsection
6617 Projects with Additional Libraries
6618 \begin_inset LatexCommand index
6626 \begin_layout Standard
6627 Some reusable routines may be compiled into a library, see the documentation
6628 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6632 \begin_inset LatexCommand index
6640 Libraries created in this manner can be included in the command line.
6641 Make sure you include the -L <library-path> option to tell the linker where
6642 to look for these files if they are not in the current directory.
6643 Here is an example, assuming you have the source file
6655 (if that is not the same as your current project):
6662 sdcc foomain.c foolib.lib -L mylib
6673 must be an absolute path name.
6677 The most efficient way to use libraries is
6678 to keep separate modules in separate source files.
6679 The lib file now should name all the modules.rel
6680 \begin_inset LatexCommand index
6686 For an example see the standard library file
6690 in the directory <installdir>/share/lib/small.
6693 \begin_layout Subsection
6694 Using sdcclib to Create and Manage Libraries
6695 \begin_inset LatexCommand index
6703 \begin_layout Standard
6704 Alternatively, instead of having a .rel file for each entry on the library
6705 file as described in the preceding section, sdcclib can be used to embed
6706 all the modules belonging to such library in the library file itself.
6707 This results in a larger library file, but it greatly reduces the number
6708 of disk files accessed by the linker.
6709 Additionally, the packed library file contains an index of all include
6710 modules and symbols that significantly speeds up the linking process.
6711 To display a list of options supported by sdcclib type:
6716 \begin_layout Standard
6721 \begin_inset LatexCommand index
6733 To create a new library file, start by compiling all the required modules.
6739 \begin_layout Standard
6746 \begin_layout Standard
6753 \begin_layout Standard
6760 \begin_layout Standard
6767 \begin_layout Standard
6776 \begin_layout Standard
6777 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6779 The next step is to add the .rel files to the library file:
6784 \begin_layout Standard
6788 sdcclib libint.lib _divsint.rel
6791 \begin_inset LatexCommand index
6799 \begin_layout Standard
6803 sdcclib libint.lib _divuint.rel
6806 \begin_layout Standard
6810 sdcclib libint.lib _modsint.rel
6813 \begin_layout Standard
6817 sdcclib libint.lib _moduint.rel
6820 \begin_layout Standard
6824 sdcclib libint.lib _mulint.rel
6832 \begin_layout Standard
6841 \begin_layout Standard
6845 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6853 \begin_layout Standard
6854 If the file already exists in the library, it will be replaced.
6855 If a list of .rel files is available, you can tell sdcclib to add those
6857 For example, if the file 'myliblist.txt' contains
6865 \begin_layout Standard
6872 \begin_layout Standard
6879 \begin_layout Standard
6886 \begin_layout Standard
6893 \begin_layout Standard
6905 \begin_layout Standard
6914 \begin_layout Standard
6918 sdcclib -l libint.lib myliblist.txt
6926 \begin_layout Standard
6927 Additionally, you can instruct sdcclib to compiles the files before adding
6928 them to the library.
6929 This is achieved using the environment variables SDCCLIB_CC and/or SDCCLIB_AS.
6938 \begin_layout Standard
6942 set SDCCLIB_CC=sdcc -c
6945 \begin_layout Standard
6949 sdcclib -l libint.lib myliblist.txt
6957 \begin_layout Standard
6958 To see what modules and symbols are included in the library, options -s
6959 and -m are available.
6967 sdcclib -s libint.lib
6970 \begin_inset LatexCommand index
6983 \begin_layout Standard
6989 \begin_layout Standard
6995 \begin_layout Standard
7003 \begin_layout Standard
7009 \begin_layout Standard
7015 \begin_layout Standard
7021 \begin_layout Standard
7027 \begin_layout Standard
7035 \begin_layout Standard
7041 \begin_layout Standard
7047 \begin_layout Standard
7055 \begin_layout Standard
7061 \begin_layout Standard
7067 \begin_layout Standard
7073 \begin_layout Standard
7081 \begin_layout Standard
7087 \begin_layout Standard
7098 \begin_layout Standard
7099 If the source files are compiled using -
7103 \begin_layout Standard
7113 \begin_inset LatexCommand index
7118 , the corresponding debug information file .adb will be include in the library
7120 The library files created with sdcclib are plain text files, so they can
7121 be viewed with a text editor.
7122 It is not recommended to modify a library file created with sdcclib using
7123 a text editor, as there are file indexes numbers located across the file
7124 used by the linker to quickly locate the required module to link.
7125 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
7126 it can be safely deleted, since all the information required for linking
7127 is embedded in the library file itself.
7128 Library files created using sdcclib are used as described in the preceding
7132 \begin_layout Subsection
7133 Using ar to Create and Manage Libraries
7134 \begin_inset LatexCommand index
7142 \begin_layout Standard
7143 Support for ar format libraries was introduced in sdcc 2.9.0.
7144 Ar is a standard archive managing utility on unices (Linux, Mac OS X, several
7145 unix flavors) so it is not included in the sdcc package.
7153 For Windows platform you can find ar utility in GNU binutils package included
7154 in several projects: Cygwin at
7155 \begin_inset LatexCommand url
7156 target "http://www.cygwin.com/"
7161 \begin_inset LatexCommand url
7162 target "http://www.mingw.org/"
7174 Both the GNU and BSD ar format variants are suppurated by asxxxx linkers.
7175 Ar doesn't understand the asxxxx object file format, so there is a special
7176 version of ranlib distributed with sdcc, called asranlib, which produces
7177 the ar symbol lookup table.
7185 To create a library containing asxxxx object files, you should use the following
7193 \begin_layout Standard
7197 ar -Sq <library name>.lib <list of .rel files>
7200 \begin_layout Standard
7204 asranlib <library name>.lib
7207 \begin_layout Standard
7208 \begin_inset VSpace bigskip
7214 \begin_layout Section
7215 Command Line Options
7216 \begin_inset LatexCommand index
7217 name "Command Line Options"
7222 \begin_inset LatexCommand label
7223 name "sec:Command-Line-Options"
7230 \begin_layout Subsection
7231 Processor Selection Options
7232 \begin_inset LatexCommand index
7233 name "Options processor selection"
7238 \begin_inset LatexCommand index
7239 name "Processor selection options"
7247 \labelwidthstring 00.00.0000
7251 \begin_inset LatexCommand index
7258 Generate code for the Intel MCS51
7259 \begin_inset LatexCommand index
7264 family of processors.
7265 This is the default processor target.
7269 \labelwidthstring 00.00.0000
7273 \begin_inset LatexCommand index
7280 Generate code for the Dallas DS80C390
7281 \begin_inset LatexCommand index
7290 \labelwidthstring 00.00.0000
7294 \begin_inset LatexCommand index
7301 Generate code for the Dallas DS80C400
7302 \begin_inset LatexCommand index
7311 \labelwidthstring 00.00.0000
7315 \begin_inset LatexCommand index
7322 Generate code for the Freescale/Motorola HC08
7323 \begin_inset LatexCommand index
7328 family of processors.
7332 \labelwidthstring 00.00.0000
7336 \begin_inset LatexCommand index
7343 Generate code for the Zilog Z80
7344 \begin_inset LatexCommand index
7349 family of processors.
7353 \labelwidthstring 00.00.0000
7357 \begin_inset LatexCommand index
7364 Generate code for the GameBoy Z80
7365 \begin_inset LatexCommand index
7366 name "gbz80 (GameBoy Z80)"
7370 processor (Not actively maintained).
7374 \labelwidthstring 00.00.0000
7378 \begin_inset LatexCommand index
7385 Generate code for the Atmel AVR
7386 \begin_inset LatexCommand index
7391 processor (Not maintained, not complete).
7392 AVR users should probably have a look at winavr
7393 \begin_inset LatexCommand url
7394 target "http://sourceforge.net/projects/winavr"
7399 \begin_inset LatexCommand url
7400 target "http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index"
7404 , which is based on AVR-port of the gcc compiler.
7407 \begin_layout Standard
7408 \begin_inset Note Note
7411 \begin_layout Standard
7412 I think it is fair to direct users there for now.
7413 Open source is also about avoiding unnecessary work .
7414 But I didn't find the 'official' link.
7423 \labelwidthstring 00.00.0000
7427 \begin_inset LatexCommand index
7434 Generate code for the Microchip PIC 14
7435 \begin_inset LatexCommand index
7440 -bit processors (p16f84 and variants.
7441 In development, not complete).
7444 \begin_layout Standard
7445 \begin_inset Note Note
7448 \begin_layout Standard
7449 p16f627 p16f628 p16f84 p16f873 p16f877?
7458 \labelwidthstring 00.00.0000
7462 \begin_inset LatexCommand index
7469 Generate code for the Microchip PIC 16
7470 \begin_inset LatexCommand index
7475 -bit processors (p18f452 and variants.
7476 In development, not complete).
7480 \labelwidthstring 00.00.0000
7485 Generate code for the Toshiba TLCS-900H
7486 \begin_inset LatexCommand index
7491 processor (Not maintained, not complete).
7495 \labelwidthstring 00.00.0000
7499 \begin_inset LatexCommand index
7506 Generate code for the Phillips XA51
7507 \begin_inset LatexCommand index
7512 processor (Not maintained, not complete).
7515 \begin_layout Standard
7516 \begin_inset VSpace bigskip
7522 \begin_layout Subsection
7523 Preprocessor Options
7524 \begin_inset LatexCommand index
7525 name "Options preprocessor"
7530 \begin_inset LatexCommand index
7531 name "Preprocessor options"
7536 \begin_inset LatexCommand index
7537 name "sdcpp (preprocessor)"
7545 \labelwidthstring 00.00.0000
7549 \begin_inset LatexCommand index
7556 The additional location where the preprocessor will look for <..h> or
7557 \begin_inset Quotes eld
7561 \begin_inset Quotes erd
7568 \labelwidthstring 00.00.0000
7572 \begin_inset LatexCommand index
7573 name "-D<macro[=value]>"
7579 Command line definition of macros.
7580 Passed to the preprocessor.
7584 \labelwidthstring 00.00.0000
7588 \begin_inset LatexCommand index
7595 Tell the preprocessor to output a rule suitable for make describing the
7596 dependencies of each object file.
7597 For each source file, the preprocessor outputs one make-rule whose target
7598 is the object file name for that source file and whose dependencies are
7599 all the files `#include'd in it.
7600 This rule may be a single line or may be continued with `
7602 '-newline if it is long.
7603 The list of rules is printed on standard output instead of the preprocessed
7606 \begin_inset LatexCommand index
7615 \labelwidthstring 00.00.0000
7619 \begin_inset LatexCommand index
7626 Tell the preprocessor not to discard comments.
7627 Used with the `-E' option.
7631 \labelwidthstring 00.00.0000
7635 \begin_inset LatexCommand index
7645 Like `-M' but the output mentions only the user header files included with
7647 \begin_inset Quotes eld
7651 System header files included with `#include <file>' are omitted.
7655 \labelwidthstring 00.00.0000
7659 \begin_inset LatexCommand index
7660 name "-Aquestion(answer)"
7666 Assert the answer answer for question, in case it is tested with a preprocessor
7667 conditional such as `#if #question(answer)'.
7668 `-A-' disables the standard assertions that normally describe the target
7673 \labelwidthstring 00.00.0000
7677 \begin_inset LatexCommand index
7684 Undefine macro macro.
7685 `-U' options are evaluated after all `-D' options, but before any `-include'
7686 and `-imacros' options.
7690 \labelwidthstring 00.00.0000
7694 \begin_inset LatexCommand index
7701 Tell the preprocessor to output only a list of the macro definitions that
7702 are in effect at the end of preprocessing.
7703 Used with the `-E' option.
7707 \labelwidthstring 00.00.0000
7711 \begin_inset LatexCommand index
7718 Tell the preprocessor to pass all macro definitions into the output, in
7719 their proper sequence in the rest of the output.
7723 \labelwidthstring 00.00.0000
7727 \begin_inset LatexCommand index
7737 Like `-dD' except that the macro arguments and contents are omitted.
7738 Only `#define name' is included in the output.
7742 \labelwidthstring 00.00.0000
7745 -pedantic-parse-number
7746 \begin_inset LatexCommand index
7752 \begin_inset LatexCommand index
7753 name "-pedantic-parse-number"
7761 \begin_inset LatexCommand label
7762 name "lyx:-pedantic-parse-number"
7771 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7772 and the macro LO_B(3) gets expanded.
7773 See also #pragma pedantic_parse_number
7774 \begin_inset LatexCommand vpageref
7775 reference "ite:pedantic_parse_number"
7780 \begin_inset LatexCommand ref
7781 reference "sec:Pragmas"
7787 Note: this functionality is not in conformance with C99 standard!
7791 \labelwidthstring 00.00.0000
7795 preprocessorOption[,preprocessorOption]
7798 \begin_inset LatexCommand index
7799 name "-Wp preprocessorOption[,preprocessorOption]"
7804 Pass the preprocessorOption to the preprocessor
7809 \begin_inset LatexCommand index
7810 name "sdcpp (preprocessor)"
7815 SDCC uses an adapted version of the GNU Compiler Collection
7816 \begin_inset LatexCommand index
7817 name "gcc (GNU Compiler Collection)"
7830 \begin_inset LatexCommand url
7831 target "http://gcc.gnu.org/"
7836 If you need more dedicated options please refer to the GCC\InsetSpace ~
7840 \begin_inset LatexCommand htmlurl
7841 target "http://www.gnu.org/software/gcc/onlinedocs/"
7848 \begin_layout Standard
7849 \begin_inset VSpace bigskip
7855 \begin_layout Subsection
7857 \begin_inset LatexCommand index
7858 name "Options linker"
7863 \begin_inset LatexCommand index
7864 name "Linker options"
7872 \labelwidthstring 00.00.0000
7882 \begin_layout Standard
7894 \begin_inset LatexCommand index
7895 name "-\\/-lib-path <path>"
7900 \begin_inset LatexCommand index
7901 name "-L -\\/-lib-path"
7908 <absolute path to additional libraries> This option is passed to the linkage
7909 editor's additional libraries
7910 \begin_inset LatexCommand index
7916 The path name must be absolute.
7917 Additional library files may be specified in the command line.
7918 See section Compiling programs for more details.
7922 \labelwidthstring 00.00.0000
7929 \begin_layout Standard
7941 \begin_inset LatexCommand index
7942 name "-\\/-xram-loc <Value>"
7947 <Value> The start location of the external ram
7948 \begin_inset LatexCommand index
7949 name "xdata (mcs51, ds390 storage class)"
7953 , default value is 0.
7954 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7958 \begin_layout Standard
7967 -xram-loc 0x8000 or -
7971 \begin_layout Standard
7984 \labelwidthstring 00.00.0000
7991 \begin_layout Standard
8003 \begin_inset LatexCommand index
8004 name "-\\/-code-loc <Value>"
8009 <Value> The start location of the code
8010 \begin_inset LatexCommand index
8015 segment, default value 0.
8016 Note when this option is used the interrupt vector table
8017 \begin_inset LatexCommand index
8018 name "interrupt vector table"
8022 is also relocated to the given address.
8023 The value entered can be in Hexadecimal or Decimal format, e.g.: -
8027 \begin_layout Standard
8036 -code-loc 0x8000 or -
8040 \begin_layout Standard
8053 \labelwidthstring 00.00.0000
8060 \begin_layout Standard
8072 \begin_inset LatexCommand index
8073 name "-\\/-stack-loc <Value>"
8078 <Value> By default the stack
8079 \begin_inset LatexCommand index
8084 is placed after the data segment.
8085 Using this option the stack can be placed anywhere in the internal memory
8087 The value entered can be in Hexadecimal or Decimal format, e.g.
8092 \begin_layout Standard
8101 -stack-loc 0x20 or -
8105 \begin_layout Standard
8115 Since the sp register is incremented before a push or call, the initial
8116 sp will be set to one byte prior the provided value.
8117 The provided value should not overlap any other memory areas such as used
8118 register banks or the data segment and with enough space for the current
8126 \begin_layout Standard
8139 \begin_inset LatexCommand index
8140 name "-\\/-pack-iram"
8144 option (which is now a default setting) will override this setting, so
8145 you should also specify the
8151 \begin_layout Standard
8164 \begin_inset LatexCommand index
8165 name "-\\/-no-pack-iram"
8169 option if you need to manually place the stack.
8173 \labelwidthstring 00.00.0000
8180 \begin_layout Standard
8192 \begin_inset LatexCommand index
8193 name "-\\/-xstack-loc <Value>"
8198 <Value> By default the external stack
8199 \begin_inset LatexCommand index
8204 is placed after the pdata
8205 \begin_inset LatexCommand index
8206 name "pdata (mcs51, ds390 storage class)"
8211 Using this option the xstack can be placed anywhere in the external memory
8213 The value entered can be in Hexadecimal or Decimal format, e.g.
8218 \begin_layout Standard
8227 -xstack-loc 0x8000 or -
8231 \begin_layout Standard
8241 The provided value should not overlap any other memory areas such as the
8242 pdata or xdata segment and with enough space for the current application.
8246 \labelwidthstring 00.00.0000
8253 \begin_layout Standard
8265 \begin_inset LatexCommand index
8266 name "-\\/-data-loc <Value>"
8271 <Value> The start location of the internal ram data
8272 \begin_inset LatexCommand index
8273 name "data (mcs51, ds390 storage class)"
8278 The value entered can be in Hexadecimal or Decimal format, eg.
8283 \begin_layout Standard
8296 \begin_layout Standard
8306 (By default, the start location of the internal ram data segment is set
8307 as low as possible in memory, taking into account the used register banks
8308 and the bit segment at address 0x20.
8309 For example if register banks 0 and 1 are used without bit variables, the
8310 data segment will be set, if -
8314 \begin_layout Standard
8323 -data-loc is not used, to location 0x10.)
8327 \labelwidthstring 00.00.0000
8334 \begin_layout Standard
8346 \begin_inset LatexCommand index
8347 name "-\\/-idata-loc <Value>"
8352 <Value> The start location of the indirectly addressable internal ram
8353 \begin_inset LatexCommand index
8354 name "idata (mcs51, ds390 storage class)"
8358 of the 8051, default value is 0x80.
8359 The value entered can be in Hexadecimal or Decimal format, eg.
8364 \begin_layout Standard
8373 -idata-loc 0x88 or -
8377 \begin_layout Standard
8390 \labelwidthstring 00.00.0000
8397 \begin_layout Standard
8409 <Value> The start location of the bit
8410 \begin_inset LatexCommand index
8415 addressable internal ram of the 8051.
8421 Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
8426 \labelwidthstring 00.00.0000
8433 \begin_layout Standard
8443 \begin_inset LatexCommand index
8444 name "-\\/-out-fmt-ihx"
8450 The linker output (final object code) is in Intel Hex format.
8451 \begin_inset LatexCommand index
8452 name "Intel hex format"
8456 This is the default option.
8457 The format itself is documented in the documentation of srecord
8458 \begin_inset LatexCommand index
8459 name "srecord (bin, hex, ... tool)"
8467 \labelwidthstring 00.00.0000
8474 \begin_layout Standard
8484 \begin_inset LatexCommand index
8485 name "-\\/-out-fmt-s19"
8491 The linker output (final object code) is in Motorola S19 format
8492 \begin_inset LatexCommand index
8493 name "Motorola S19 format"
8498 The format itself is documented in the documentation of srecord.
8502 \labelwidthstring 00.00.0000
8509 \begin_layout Standard
8519 \begin_inset LatexCommand index
8520 name "-\\/-out-fmt-s19"
8525 \begin_inset LatexCommand index
8526 name "HC08!Options!-\\/-out-fmt-elf"
8532 The linker output (final object code) is in ELF format
8533 \begin_inset LatexCommand index
8539 (Currently only supported for the HC08
8540 \begin_inset LatexCommand index
8549 \labelwidthstring 00.00.0000
8553 linkOption[,linkOption]
8556 \begin_inset LatexCommand index
8557 name "-Wl linkOption[,linkOption]"
8562 \begin_inset LatexCommand label
8563 name "lyx:-Wl option"
8568 Pass the linkOption to the linker.
8569 If a bootloader is used an option like
8570 \begin_inset Quotes sld
8575 \begin_inset Quotes srd
8578 would be typical to set the start of the code segment.
8579 Either use the double quotes around this option or use no space (e.g.
8581 See also #pragma constseg and #pragma codeseg in section
8582 \begin_inset LatexCommand ref
8583 reference "sec:Pragmas"
8588 File sdcc/as/doc/asxhtm.html has more on linker options.
8591 \begin_layout Standard
8592 \begin_inset VSpace bigskip
8598 \begin_layout Subsection
8600 \begin_inset LatexCommand index
8601 name "Options MCS51"
8606 \begin_inset LatexCommand index
8607 name "MCS51 options"
8615 \labelwidthstring 00.00.0000
8622 \begin_layout Standard
8632 \begin_inset LatexCommand index
8633 name "-\\/-model-small"
8642 Generate code for Small Model programs, see section Memory Models for more
8644 This is the default model.
8648 \labelwidthstring 00.00.0000
8655 \begin_layout Standard
8665 \begin_inset LatexCommand index
8666 name "-\\/-model-medium"
8672 Generate code for Medium model programs, see section Memory Models for
8674 If this option is used all source files in the project have to be compiled
8676 It must also be used when invoking the linker.
8680 \labelwidthstring 00.00.0000
8687 \begin_layout Standard
8697 \begin_inset LatexCommand index
8698 name "-\\/-model-large"
8704 Generate code for Large model programs, see section Memory Models for more
8706 If this option is used all source files in the project have to be compiled
8708 It must also be used when invoking the linker.
8712 \labelwidthstring 00.00.0000
8719 \begin_layout Standard
8729 \begin_inset LatexCommand index
8736 Uses a pseudo stack in the pdata
8737 \begin_inset LatexCommand index
8738 name "pdata (mcs51, ds390 storage class)"
8742 area (usually the first 256 bytes in the external ram) for allocating variables
8743 and passing parameters.
8745 \begin_inset LatexCommand ref
8746 reference "sub:External-Stack"
8751 External Stack for more details.
8755 \labelwidthstring 00.00.0000
8762 \begin_layout Standard
8775 \begin_inset LatexCommand index
8776 name "-\\/-iram-size <Value>"
8780 Causes the linker to check if the internal ram usage is within limits of
8785 \labelwidthstring 00.00.0000
8792 \begin_layout Standard
8805 \begin_inset LatexCommand index
8806 name "-\\/-xram-size <Value>"
8810 Causes the linker to check if the external ram usage is within limits of
8815 \labelwidthstring 00.00.0000
8822 \begin_layout Standard
8835 \begin_inset LatexCommand index
8836 name "-\\/-code-size <Value>"
8840 Causes the linker to check if the code memory usage is within limits of
8845 \labelwidthstring 00.00.0000
8852 \begin_layout Standard
8865 \begin_inset LatexCommand index
8866 name "-\\/-stack-size <Value>"
8870 Causes the linker to check if there is at minimum <Value> bytes for stack.
8874 \labelwidthstring 00.00.0000
8881 \begin_layout Standard
8894 \begin_inset LatexCommand index
8895 name "-\\/-pack-iram"
8899 Causes the linker to use unused register banks for data variables and pack
8900 data, idata and stack together.
8901 This is the default now.
8905 \labelwidthstring 00.00.0000
8912 \begin_layout Standard
8925 \begin_inset LatexCommand index
8926 name "-\\/-no-pack-iram"
8930 Causes the linker to use old style for allocating memory areas.
8934 \labelwidthstring 00.00.0000
8941 \begin_layout Standard
8954 \begin_inset LatexCommand index
8955 name "-\\/-acall-ajmp"
8959 Replaces the three byte instructions lcall/ljmp with the two byte instructions
8961 Only use this option if your code is in the same 2k block of memory.
8962 You may need to use this option for some 8051 derivatives which lack the
8963 lcall/ljmp instructions..
8966 \begin_layout Standard
8967 \begin_inset VSpace bigskip
8973 \begin_layout Subsection
8974 DS390 / DS400 Options
8975 \begin_inset LatexCommand index
8976 name "Options DS390"
8981 \begin_inset LatexCommand index
8990 \labelwidthstring 00.00.0000
8997 \begin_layout Standard
9009 \begin_inset LatexCommand index
9010 name "DS390!Options!-\\/-model-flat24"
9018 Generate 24-bit flat mode code.
9019 This is the one and only that the ds390 code generator supports right now
9020 and is default when using
9025 See section Memory Models for more details.
9029 \labelwidthstring 00.00.0000
9036 \begin_layout Standard
9046 \begin_inset LatexCommand index
9047 name "DS390!Options!-\\/-protect-sp-update"
9053 disable interrupts during ESP:SP updates.
9057 \labelwidthstring 00.00.0000
9064 \begin_layout Standard
9076 \begin_inset LatexCommand index
9077 name "DS390!Options!-\\/-stack-10bit"
9081 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
9082 This is the one and only that the ds390 code generator supports right now
9083 and is default when using
9088 In this mode, the stack is located in the lower 1K of the internal RAM,
9089 which is mapped to 0x400000.
9090 Note that the support is incomplete, since it still uses a single byte
9091 as the stack pointer.
9092 This means that only the lower 256 bytes of the potential 1K stack space
9093 will actually be used.
9094 However, this does allow you to reclaim the precious 256 bytes of low RAM
9095 for use for the DATA and IDATA segments.
9096 The compiler will not generate any code to put the processor into 10 bit
9098 It is important to ensure that the processor is in this mode before calling
9099 any re-entrant functions compiled with this option.
9100 In principle, this should work with the
9106 \begin_layout Standard
9116 \begin_inset LatexCommand index
9117 name "-\\/-stack-auto"
9123 option, but that has not been tested.
9124 It is incompatible with the
9130 \begin_layout Standard
9140 \begin_inset LatexCommand index
9148 It also only makes sense if the processor is in 24 bit contiguous addressing
9155 \begin_layout Standard
9164 -model-flat24 option
9169 \begin_inset Note Note
9173 \labelwidthstring 00.00.0000
9180 \begin_layout Standard
9189 -stack-8-bit - switches off the 10-bit mode
9198 \labelwidthstring 00.00.0000
9205 \begin_layout Standard
9215 \begin_inset LatexCommand index
9216 name "DS390!Options!-\\/-stack-probe"
9222 insert call to function __stack_probe at each function prologue.
9226 \labelwidthstring 00.00.0000
9233 \begin_layout Standard
9243 \begin_inset LatexCommand index
9244 name "DS390!Options!-\\/-tini-libid"
9250 <nnnn> LibraryID used in -mTININative.
9255 \labelwidthstring 00.00.0000
9262 \begin_layout Standard
9272 \begin_inset LatexCommand index
9273 name "DS390!Options!-\\/-use-accelerator"
9279 generate code for DS390 Arithmetic Accelerator.
9283 \begin_layout Standard
9284 \begin_inset VSpace bigskip
9290 \begin_layout Subsection
9292 \begin_inset LatexCommand index
9298 \begin_inset LatexCommand index
9307 \labelwidthstring 00.00.0000
9314 \begin_layout Standard
9326 \begin_inset LatexCommand index
9327 name "Z80!Options!-\\/-callee-saves-bc"
9335 Force a called function to always save BC.
9339 \labelwidthstring 00.00.0000
9346 \begin_layout Standard
9358 \begin_inset LatexCommand index
9359 name "Z80!Options!-\\/-no-std-crt0"
9363 When linking, skip the standard crt0.o object file.
9364 You must provide your own crt0.o for your system when linking.
9368 \labelwidthstring 00.00.0000
9375 \begin_layout Standard
9387 \begin_inset LatexCommand index
9388 name "Z80!Options!-\\/-portmode=<Value>"
9392 Determinate PORT I/O mode (<Value> is z80 or z180).
9396 \labelwidthstring 00.00.0000
9403 \begin_layout Standard
9415 \begin_inset LatexCommand index
9416 name "Z80!Options!-\\/-asm=<Value>"
9420 Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
9424 \labelwidthstring 00.00.0000
9431 \begin_layout Standard
9444 \begin_inset LatexCommand index
9445 name "Z80!Options!-\\/-codeseg <Value>"
9449 Use <Value> for the code segment name.
9453 \labelwidthstring 00.00.0000
9460 \begin_layout Standard
9473 \begin_inset LatexCommand index
9474 name "Z80!Options!-\\/-constseg <Value>"
9478 Use <Value> for the const segment name.
9482 \labelwidthstring 00.00.0000
9483 \begin_inset VSpace bigskip
9489 \begin_layout Subsection
9491 \begin_inset LatexCommand index
9492 name "Options GBZ80"
9497 \begin_inset LatexCommand index
9506 \labelwidthstring 00.00.0000
9513 \begin_layout Standard
9525 \begin_inset LatexCommand index
9526 name "GBZ80!Options!-\\/-callee-saves-bc"
9534 Force a called function to always save BC.
9538 \labelwidthstring 00.00.0000
9545 \begin_layout Standard
9557 \begin_inset LatexCommand index
9558 name "Z80!Options!-\\/-no-std-crt0"
9562 When linking, skip the standard crt0.o object file.
9563 You must provide your own crt0.o for your system when linking.
9567 \labelwidthstring 00.00.0000
9574 \begin_inset LatexCommand index
9575 name "GBZ80!Options!-bo <Num>"
9579 Use code bank <Num>.
9583 \labelwidthstring 00.00.0000
9590 \begin_inset LatexCommand index
9591 name "GBZ80!Options!-ba <Num>"
9595 Use data bank <Num>.
9599 \labelwidthstring 00.00.0000
9606 \begin_layout Standard
9619 \begin_inset LatexCommand index
9620 name "GBZ80!Options!-\\/-codeseg <Value>"
9624 Use <Value> for the code segment name.
9628 \labelwidthstring 00.00.0000
9635 \begin_layout Standard
9648 \begin_inset LatexCommand index
9649 name "GBZ80!Options!-\\/-constseg <Value>"
9653 Use <Value> for the const segment name.
9656 \begin_layout Standard
9657 \begin_inset VSpace bigskip
9663 \begin_layout Subsection
9664 Optimization Options
9665 \begin_inset LatexCommand index
9666 name "Options optimization"
9671 \begin_inset LatexCommand index
9672 name "Optimization options"
9680 \labelwidthstring 00.00.0000
9687 \begin_layout Standard
9697 \begin_inset LatexCommand index
9704 Will not do global subexpression elimination, this option may be used when
9705 the compiler creates undesirably large stack/data spaces to store compiler
9715 \begin_inset LatexCommand index
9716 name "sloc (spill location)"
9721 A warning message will be generated when this happens and the compiler
9722 will indicate the number of extra bytes it allocated.
9723 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9725 \begin_inset LatexCommand index
9726 name "\\#pragma nogcse"
9730 can be used to turn off global subexpression elimination
9731 \begin_inset LatexCommand index
9732 name "Subexpression elimination"
9736 for a given function only.
9740 \labelwidthstring 00.00.0000
9747 \begin_layout Standard
9757 \begin_inset LatexCommand index
9758 name "-\\/-noinvariant"
9764 Will not do loop invariant optimizations, this may be turned off for reasons
9765 explained for the previous option.
9766 For more details of loop optimizations performed see Loop Invariants in
9768 \begin_inset LatexCommand ref
9769 reference "sub:Loop-Optimizations"
9774 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9776 \begin_inset LatexCommand index
9777 name "\\#pragma noinvariant"
9781 can be used to turn off invariant optimizations for a given function only.
9785 \labelwidthstring 00.00.0000
9792 \begin_layout Standard
9802 \begin_inset LatexCommand index
9803 name "-\\/-noinduction"
9809 Will not do loop induction optimizations, see section strength reduction
9811 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9813 \begin_inset LatexCommand index
9814 name "\\#pragma noinduction"
9818 can be used to turn off induction optimizations for a given function only.
9822 \labelwidthstring 00.00.0000
9829 \begin_layout Standard
9839 \begin_inset LatexCommand index
9840 name "-\\/-nojtbound"
9849 Will not generate boundary condition check when switch statements
9850 \begin_inset LatexCommand index
9851 name "switch statement"
9855 are implemented using jump-tables.
9857 \begin_inset LatexCommand ref
9858 reference "sub:'switch'-Statements"
9863 Switch Statements for more details.
9864 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9866 \begin_inset LatexCommand index
9867 name "\\#pragma nojtbound"
9871 can be used to turn off boundary checking for jump tables for a given function
9876 \labelwidthstring 00.00.0000
9883 \begin_layout Standard
9893 \begin_inset LatexCommand index
9894 name "-\\/-noloopreverse"
9903 Will not do loop reversal
9904 \begin_inset LatexCommand index
9905 name "Loop reversing"
9913 \labelwidthstring 00.00.0000
9918 \begin_layout Standard
9932 \begin_inset LatexCommand index
9933 name "-\\/-nolabelopt "
9937 Will not optimize labels (makes the dumpfiles more readable).
9941 \labelwidthstring 00.00.0000
9948 \begin_layout Standard
9958 \begin_inset LatexCommand index
9959 name "-\\/-no-xinit-opt"
9965 Will not memcpy initialized data from code space into xdata space.
9966 This saves a few bytes in code space if you don't have initialized data
9967 \begin_inset LatexCommand index
9968 name "Variable initialization"
9976 \labelwidthstring 00.00.0000
9983 \begin_layout Standard
9993 \begin_inset LatexCommand index
9994 name "-\\/-nooverlay"
10000 The compiler will not overlay parameters and local variables of any function,
10001 see section Parameters and local variables for more details.
10005 \labelwidthstring 00.00.0000
10012 \begin_layout Standard
10022 \begin_inset LatexCommand index
10023 name "-\\/-no-peep"
10029 Disable peep-hole optimization with built-in rules.
10033 \labelwidthstring 00.00.0000
10040 \begin_layout Standard
10052 \begin_inset LatexCommand index
10053 name "-\\/-peep-file"
10058 <filename> This option can be used to use additional rules to be used by
10059 the peep hole optimizer.
10061 \begin_inset LatexCommand ref
10062 reference "sub:Peephole-Optimizer"
10067 Peep Hole optimizations for details on how to write these rules.
10071 \labelwidthstring 00.00.0000
10078 \begin_layout Standard
10088 \begin_inset LatexCommand index
10089 name "-\\/-peep-asm"
10095 Pass the inline assembler code through the peep hole optimizer.
10096 This can cause unexpected changes to inline assembler code, please go through
10097 the peephole optimizer
10098 \begin_inset LatexCommand index
10099 name "Peephole optimizer"
10103 rules defined in the source file tree '<target>/peeph.def' before using
10108 \labelwidthstring 00.00.0000
10115 \begin_layout Standard
10125 \begin_inset LatexCommand index
10126 name "-\\/-opt-code-speed"
10132 The compiler will optimize code generation towards fast code, possibly
10133 at the expense of code size.
10137 \labelwidthstring 00.00.0000
10144 \begin_layout Standard
10154 \begin_inset LatexCommand index
10155 name "-\\/-opt-code-size"
10161 The compiler will optimize code generation towards compact code, possibly
10162 at the expense of code speed.
10165 \begin_layout Standard
10166 \begin_inset VSpace bigskip
10172 \begin_layout Subsection
10174 \begin_inset LatexCommand index
10175 name "Options other"
10183 \labelwidthstring 00.00.0000
10191 \begin_layout Standard
10201 \begin_inset LatexCommand index
10202 name "-\\/-compile-only"
10207 \begin_inset LatexCommand index
10208 name "-c -\\/-compile-only"
10214 will compile and assemble the source, but will not call the linkage editor.
10218 \labelwidthstring 00.00.0000
10227 \begin_layout Standard
10239 \begin_inset LatexCommand index
10246 reads the preprocessed source from standard input and compiles it.
10247 The file name for the assembler output must be specified using the -o option.
10251 \labelwidthstring 00.00.0000
10255 \begin_inset LatexCommand index
10262 Run only the C preprocessor.
10263 Preprocess all the C source files specified and output the results to standard
10268 \labelwidthstring 00.00.0000
10273 \begin_inset LatexCommand index
10274 name "-o <path/file>"
10280 The output path where everything will be placed or the file name used for
10281 all generated output files.
10282 If the parameter is a path, it must have a trailing slash (or backslash
10283 for the Windows binaries) to be recognized as a path.
10284 Note for Windows users: if the path contains spaces, it should be surrounded
10286 The trailing backslash should be doubled in order to prevent escaping the
10287 final quote, for example:
10290 \begin_inset Quotes sld
10304 \begin_inset Quotes srd
10309 or put after the final quote, for example:
10312 \begin_inset Quotes sld
10322 \begin_inset Quotes srd
10330 The path using slashes for directory delimiters can be used too, for example:
10334 \begin_inset Quotes sld
10337 F:/Projects/test3/output 1/
10338 \begin_inset Quotes srd
10347 \labelwidthstring 00.00.0000
10354 \begin_layout Standard
10364 \begin_inset LatexCommand index
10365 name "-\\/-stack-auto"
10374 All functions in the source file will be compiled as
10379 \begin_inset LatexCommand index
10385 the parameters and local variables will be allocated on the stack
10386 \begin_inset LatexCommand index
10393 \begin_inset LatexCommand ref
10394 reference "sec:Parameters-and-Local-Variables"
10398 Parameters and Local Variables for more details.
10399 If this option is used all source files in the project should be compiled
10401 It automatically implies -
10407 \begin_layout Standard
10418 -int-long-reent and -
10424 \begin_layout Standard
10440 \labelwidthstring 00.00.0000
10447 \begin_layout Standard
10457 \begin_inset LatexCommand index
10458 name "-\\/-callee-saves"
10463 \begin_inset LatexCommand label
10464 name "lyx:--callee-saves-function1[,function2][,function3]..."
10468 function1[,function2][,function3]....
10471 The compiler by default uses a caller saves convention for register saving
10472 across function calls, however this can cause unnecessary register pushing
10473 and popping when calling small functions from larger functions.
10474 This option can be used to switch the register saving convention for the
10475 function names specified.
10476 The compiler will not save registers when calling these functions, no extra
10477 code will be generated at the entry and exit (function prologue
10480 \begin_inset LatexCommand index
10481 name "function prologue"
10490 \begin_inset LatexCommand index
10491 name "function epilogue"
10497 ) for these functions to save and restore the registers used by these functions,
10498 this can SUBSTANTIALLY reduce code and improve run time performance of
10499 the generated code.
10500 In the future the compiler (with inter procedural analysis) will be able
10501 to determine the appropriate scheme to use for each function call.
10502 DO NOT use this option for built-in functions such as _mulint..., if this
10503 option is used for a library function the appropriate library function
10504 needs to be recompiled with the same option.
10505 If the project consists of multiple source files then all the source file
10506 should be compiled with the same -
10510 \begin_layout Standard
10519 -callee-saves option string.
10520 Also see #pragma\InsetSpace ~
10522 \begin_inset LatexCommand index
10523 name "\\#pragma callee\\_saves"
10528 \begin_inset LatexCommand vpageref
10529 reference "ite:callee_saves-function1[,function2[,function3...]]--"
10537 \labelwidthstring 00.00.0000
10544 \begin_layout Standard
10554 \begin_inset LatexCommand index
10555 name "-\\/-all-callee-saves"
10565 \begin_layout Standard
10574 -callee-saves will be applied to all functions by default.
10578 \labelwidthstring 00.00.0000
10585 \begin_layout Standard
10595 \begin_inset LatexCommand index
10602 When this option is used the compiler will generate debug information.
10603 The debug information collected in a file with .cdb extension can be used
10605 For more information see documentation for SDCDB.
10606 Another file with no extension contains debug information in AOMF or AOMF51
10607 \begin_inset LatexCommand index
10608 name "AOMF, AOMF51"
10612 format which is commonly used by third party tools.
10616 \labelwidthstring 00.00.0000
10620 \begin_inset LatexCommand index
10630 Stop after the stage of compilation proper; do not assemble.
10631 The output is an assembler code file for the input file specified.
10635 \labelwidthstring 00.00.0000
10642 \begin_layout Standard
10652 \begin_inset LatexCommand index
10653 name "-\\/-int-long-reent"
10659 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
10660 Note by default these libraries are compiled as non-reentrant.
10661 See section Installation for more details.
10665 \labelwidthstring 00.00.0000
10672 \begin_layout Standard
10682 \begin_inset LatexCommand index
10683 name "-\\/-cyclomatic"
10689 This option will cause the compiler to generate an information message for
10690 each function in the source file.
10691 The message contains some
10695 information about the function.
10696 The number of edges and nodes the compiler detected in the control flow
10697 graph of the function, and most importantly the
10699 cyclomatic complexity
10700 \begin_inset LatexCommand index
10701 name "Cyclomatic complexity"
10707 see section on Cyclomatic Complexity for more details.
10711 \labelwidthstring 00.00.0000
10718 \begin_layout Standard
10728 \begin_inset LatexCommand index
10729 name "-\\/-float-reent"
10735 Floating point library is compiled as reentrant
10736 \begin_inset LatexCommand index
10742 See section Installation for more details.
10746 \labelwidthstring 00.00.0000
10753 \begin_layout Standard
10763 \begin_inset LatexCommand index
10764 name "-\\/-funsigned-char"
10770 The default signedness for every type is
10775 In some embedded environments the default signedness of
10784 To set the signess for characters to unsigned, use the option -
10790 \begin_layout Standard
10802 If this option is set and no signedness keyword (unsigned/signed) is given,
10803 a char will be signed.
10804 All other types are unaffected.
10808 \labelwidthstring 00.00.0000
10815 \begin_layout Standard
10825 \begin_inset LatexCommand index
10826 name "-\\/-main-return"
10832 This option can be used if the code generated is called by a monitor program
10833 or if the main routine includes an endless loop.
10834 This option results in slightly smaller code and saves two bytes of stack
10836 The return from the 'main'
10837 \begin_inset LatexCommand index
10842 function will return to the function calling main.
10843 The default setting is to lock up i.e.
10852 \labelwidthstring 00.00.0000
10859 \begin_layout Standard
10869 \begin_inset LatexCommand index
10870 name "-\\/-nostdinc"
10876 This will prevent the compiler from passing on the default include path
10877 to the preprocessor.
10881 \labelwidthstring 00.00.0000
10888 \begin_layout Standard
10898 \begin_inset LatexCommand index
10899 name "-\\/-nostdlib"
10905 This will prevent the compiler from passing on the default library
10906 \begin_inset LatexCommand index
10911 path to the linker.
10915 \labelwidthstring 00.00.0000
10922 \begin_layout Standard
10932 \begin_inset LatexCommand index
10933 name "-\\/-verbose"
10939 Shows the various actions the compiler is performing.
10943 \labelwidthstring 00.00.0000
10947 \begin_inset LatexCommand index
10954 Shows the actual commands the compiler is executing.
10958 \labelwidthstring 00.00.0000
10965 \begin_layout Standard
10975 \begin_inset LatexCommand index
10976 name "-\\/-no-c-code-in-asm"
10982 Hides your ugly and inefficient c-code from the asm file, so you can always
10983 blame the compiler :)
10987 \labelwidthstring 00.00.0000
10994 \begin_layout Standard
11004 \begin_inset LatexCommand index
11005 name "-\\/-no-gen-comments"
11011 Include code generator and peep-hole comments in the generated asm files.
11015 \labelwidthstring 00.00.0000
11022 \begin_layout Standard
11032 \begin_inset LatexCommand index
11033 name "-\\/-no-peep-comments"
11039 Don't include peep-hole comments in the generated asm files even if -
11045 \begin_layout Standard
11056 -fverbose-asm option is specified.
11060 \labelwidthstring 00.00.0000
11067 \begin_layout Standard
11077 \begin_inset LatexCommand index
11078 name "-\\/-i-code-in-asm"
11084 Include i-codes in the asm file.
11085 Sounds like noise but is most helpful for debugging the compiler itself.
11089 \labelwidthstring 00.00.0000
11096 \begin_layout Standard
11106 \begin_inset LatexCommand index
11112 \begin_inset LatexCommand index
11113 name "-\\/-less-pedantic"
11120 \begin_inset LatexCommand label
11121 name "lyx:--less-pedantic"
11125 Disable some of the more pedantic warnings
11126 \begin_inset LatexCommand index
11132 For more details, see the less_pedantic pragma
11133 \begin_inset LatexCommand vpageref
11134 reference "ite:less_pedantic"
11142 \labelwidthstring 00.00.0000
11149 \begin_layout Standard
11158 -disable-warning\InsetSpace ~
11160 \begin_inset LatexCommand index
11161 name "-\\/-disable-warning"
11167 Disable specific warning with number <nnnn>.
11171 \labelwidthstring 00.00.0000
11178 \begin_layout Standard
11188 \begin_inset LatexCommand index
11195 Treat all warnings as errors.
11199 \labelwidthstring 00.00.0000
11206 \begin_layout Standard
11216 \begin_inset LatexCommand index
11217 name "-\\/-print-search-dirs"
11223 Display the directories in the compiler's search path
11227 \labelwidthstring 00.00.0000
11234 \begin_layout Standard
11244 \begin_inset LatexCommand index
11251 Display errors and warnings using MSVC style, so you can use SDCC with
11252 the visual studio IDE
11253 \begin_inset LatexCommand index
11259 With SDCC both offering a GCC-like (the default) and a MSVC-like
11260 \begin_inset LatexCommand index
11261 name "MSVC output style"
11265 output style, integration into most programming editors should be straightforwa
11270 \labelwidthstring 00.00.0000
11277 \begin_layout Standard
11287 \begin_inset LatexCommand index
11288 name "-\\/-use-stdout"
11294 Send errors and warnings to stdout instead of stderr.
11298 \labelwidthstring 00.00.0000
11302 asmOption[,asmOption]
11305 \begin_inset LatexCommand index
11306 name "-Wa asmOption[,asmOption]"
11311 Pass the asmOption to the assembler
11312 \begin_inset LatexCommand index
11313 name "Options assembler"
11318 \begin_inset LatexCommand index
11319 name "Assembler options"
11324 See file sdcc/as/doc/asxhtm.html for assembler options.cd
11328 \labelwidthstring 00.00.0000
11335 \begin_layout Standard
11345 \begin_inset LatexCommand index
11346 name "-\\/-std-sdcc89"
11352 Generally follow the C89 standard, but allow SDCC features that conflict
11353 with the standard (default).
11357 \labelwidthstring 00.00.0000
11364 \begin_layout Standard
11374 \begin_inset LatexCommand index
11375 name "-\\/-std-c89"
11381 Follow the C89 standard and disable SDCC features that conflict with the
11386 \labelwidthstring 00.00.0000
11393 \begin_layout Standard
11403 \begin_inset LatexCommand index
11404 name "-\\/-std-sdcc99"
11410 Generally follow the C99 standard, but allow SDCC features that conflict
11411 with the standard (incomplete support).
11415 \labelwidthstring 00.00.0000
11422 \begin_layout Standard
11432 \begin_inset LatexCommand index
11433 name "-\\/-std-sdcc99"
11439 Follow the C99 standard and disable SDCC features that conflict with the
11440 standard (incomplete support).
11444 \labelwidthstring 00.00.0000
11451 \begin_layout Standard
11463 \begin_inset LatexCommand index
11464 name "-\\/-codeseg <Value>"
11469 \begin_inset LatexCommand label
11470 name "lyx:-codeseg"
11475 <Name> The name to be used for the code
11476 \begin_inset LatexCommand index
11481 segment, default CSEG.
11482 This is useful if you need to tell the compiler to put the code in a special
11483 segment so you can later on tell the linker to put this segment in a special
11485 Can be used for instance when using bank switching to put the code in a
11490 \labelwidthstring 00.00.0000
11497 \begin_layout Standard
11509 \begin_inset LatexCommand index
11510 name "-\\/-constseg <Value>"
11515 <Name> The name to be used for the const
11516 \begin_inset LatexCommand index
11521 segment, default CONST.
11522 This is useful if you need to tell the compiler to put the const data in
11523 a special segment so you can later on tell the linker to put this segment
11524 in a special place in memory.
11525 Can be used for instance when using bank switching to put the const data
11530 \labelwidthstring 00.00.0000
11537 \begin_layout Standard
11546 -fdollars-in-identifiers
11547 \begin_inset LatexCommand index
11548 name "-\\/-fdollars-in-identifiers"
11554 Permit '$' as an identifier character.
11558 \labelwidthstring 00.00.0000
11565 \begin_layout Standard
11577 \begin_inset LatexCommand index
11578 name "-\\/-more-pedantic"
11583 \begin_inset LatexCommand index
11594 a SDCC compiler option but if you want
11598 warnings you can use a separate tool dedicated to syntax checking like
11600 \begin_inset LatexCommand label
11601 name "lyx:more-pedantic-SPLINT"
11606 \begin_inset LatexCommand index
11607 name "lint (syntax checking tool)"
11612 \begin_inset LatexCommand url
11613 target "http://www.splint.org"
11618 To make your source files parseable by splint you will have to include
11624 \begin_inset LatexCommand index
11625 name "splint (syntax checking tool)"
11629 in your source file and add brackets around extended keywords (like
11632 \begin_inset Quotes sld
11645 \begin_inset Quotes srd
11653 \begin_inset Quotes sld
11656 __interrupt\InsetSpace ~
11658 \begin_inset Quotes srd
11666 Splint has an excellent on line manual at
11667 \begin_inset LatexCommand url
11668 target "http://www.splint.org/manual/"
11672 and it's capabilities go beyond pure syntax checking.
11673 You'll need to tell splint the location of SDCC's include files so a typical
11674 command line could look like this:
11678 splint\InsetSpace ~
11680 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
11686 \labelwidthstring 00.00.0000
11693 \begin_layout Standard
11705 \begin_inset LatexCommand index
11706 name "-\\/-short-is-8bits"
11711 \begin_inset LatexCommand label
11712 name "lyx:--short-is-8bits"
11716 Treat short as 8-bit (for backward compatibility with older versions of
11717 compiler - see section
11718 \begin_inset LatexCommand ref
11719 reference "sec:Compatibility-with-previous"
11726 \begin_layout Standard
11727 \begin_inset VSpace bigskip
11733 \begin_layout Subsection
11734 Intermediate Dump Options
11735 \begin_inset LatexCommand label
11736 name "sub:Intermediate-Dump-Options"
11741 \begin_inset LatexCommand index
11742 name "Options intermediate dump"
11747 \begin_inset LatexCommand index
11748 name "Intermediate dump options"
11755 \begin_layout Standard
11756 The following options are provided for the purpose of retargetting and debugging
11758 They provide a means to dump the intermediate code (iCode
11759 \begin_inset LatexCommand index
11764 ) generated by the compiler in human readable form at various stages of
11765 the compilation process.
11766 More on iCodes see chapter
11767 \begin_inset LatexCommand ref
11768 reference "sub:The-anatomy-of"
11773 \begin_inset Quotes srd
11776 The anatomy of the compiler
11777 \begin_inset Quotes srd
11784 \labelwidthstring 00.00.0000
11791 \begin_layout Standard
11801 \begin_inset LatexCommand index
11802 name "-\\/-dumpraw"
11808 This option will cause the compiler to dump the intermediate code into
11811 <source filename>.dumpraw
11813 just after the intermediate code has been generated for a function, i.e.
11814 before any optimizations are done.
11816 \begin_inset LatexCommand index
11817 name "Basic blocks"
11821 at this stage ordered in the depth first number, so they may not be in
11822 sequence of execution.
11826 \labelwidthstring 00.00.0000
11833 \begin_layout Standard
11843 \begin_inset LatexCommand index
11844 name "-\\/-dumpgcse"
11850 Will create a dump of iCodes, after global subexpression elimination
11851 \begin_inset LatexCommand index
11852 name "Global subexpression elimination"
11856 , into a file named
11858 <source filename>.dumpgcse.
11862 \labelwidthstring 00.00.0000
11869 \begin_layout Standard
11879 \begin_inset LatexCommand index
11880 name "-\\/-dumpdeadcode"
11886 Will create a dump of iCodes, after deadcode elimination
11887 \begin_inset LatexCommand index
11888 name "Dead-code elimination"
11892 , into a file named
11894 <source filename>.dumpdeadcode.
11898 \labelwidthstring 00.00.0000
11905 \begin_layout Standard
11915 \begin_inset LatexCommand index
11916 name "-\\/-dumploop"
11925 Will create a dump of iCodes, after loop optimizations
11926 \begin_inset LatexCommand index
11927 name "Loop optimization"
11931 , into a file named
11933 <source filename>.dumploop.
11937 \labelwidthstring 00.00.0000
11944 \begin_layout Standard
11954 \begin_inset LatexCommand index
11955 name "-\\/-dumprange"
11964 Will create a dump of iCodes, after live range analysis
11965 \begin_inset LatexCommand index
11966 name "Live range analysis"
11970 , into a file named
11972 <source filename>.dumprange.
11976 \labelwidthstring 00.00.0000
11983 \begin_layout Standard
11993 \begin_inset LatexCommand index
11994 name "-\\/-dumlrange"
12000 Will dump the life ranges
12001 \begin_inset LatexCommand index
12002 name "Live range analysis"
12010 \labelwidthstring 00.00.0000
12017 \begin_layout Standard
12027 \begin_inset LatexCommand index
12028 name "-\\/-dumpregassign"
12034 Will create a dump of iCodes, after register assignment
12035 \begin_inset LatexCommand index
12036 name "Register assignment"
12040 , into a file named
12042 <source filename>.dumprassgn.
12046 \labelwidthstring 00.00.0000
12053 \begin_layout Standard
12063 \begin_inset LatexCommand index
12064 name "-\\/-dumplrange"
12070 Will create a dump of the live ranges of iTemp's
12074 \labelwidthstring 00.00.0000
12081 \begin_layout Standard
12091 \begin_inset LatexCommand index
12092 name "-\\/-dumpall"
12101 Will cause all the above mentioned dumps to be created.
12104 \begin_layout Standard
12105 \begin_inset VSpace bigskip
12111 \begin_layout Subsection
12112 Redirecting output on Windows Shells
12115 \begin_layout Standard
12116 By default SDCC writes its error messages to
12117 \begin_inset Quotes sld
12121 \begin_inset Quotes srd
12125 To force all messages to
12126 \begin_inset Quotes sld
12130 \begin_inset Quotes srd
12142 \begin_layout Standard
12157 \begin_inset LatexCommand index
12158 name "-\\/-use-stdout"
12163 Additionally, if you happen to have visual studio installed in your windows
12164 machine, you can use it to compile your sources using a custom build and
12171 \begin_layout Standard
12183 \begin_inset LatexCommand index
12189 Something like this should work:
12208 \begin_layout Standard
12227 \begin_layout Standard
12239 -model-large -c $(InputPath)
12242 \begin_inset VSpace bigskip
12248 \begin_layout Section
12249 Environment variables
12250 \begin_inset LatexCommand index
12251 name "Environment variables"
12258 \begin_layout Standard
12259 SDCC recognizes the following environment variables:
12263 \labelwidthstring 00.00.0000
12267 \begin_inset LatexCommand index
12268 name "SDCC\\_LEAVE\\_SIGNALS"
12274 SDCC installs a signal handler
12275 \begin_inset LatexCommand index
12276 name "signal handler"
12280 to be able to delete temporary files after an user break (^C) or an exception.
12281 If this environment variable is set, SDCC won't install the signal handler
12282 in order to be able to debug SDCC.
12286 \labelwidthstring 00.00.0000
12292 \begin_inset LatexCommand index
12293 name "TMP, TEMP, TMPDIR"
12299 Path, where temporary files will be created.
12300 The order of the variables is the search order.
12301 In a standard *nix environment these variables are not set, and there's
12302 no need to set them.
12303 On Windows it's recommended to set one of them.
12307 \labelwidthstring 00.00.0000
12311 \begin_inset LatexCommand index
12319 \begin_inset LatexCommand ref
12320 reference "sub:Install-paths"
12326 \begin_inset Quotes sld
12330 \begin_inset Quotes srd
12337 \labelwidthstring 00.00.0000
12341 \begin_inset LatexCommand index
12342 name "SDCC\\_INCLUDE"
12349 \begin_inset LatexCommand ref
12350 reference "sub:Search-Paths"
12356 \begin_inset Quotes sld
12360 \begin_inset Quotes srd
12367 \labelwidthstring 00.00.0000
12371 \begin_inset LatexCommand index
12379 \begin_inset LatexCommand ref
12380 reference "sub:Search-Paths"
12386 \begin_inset Quotes sld
12390 \begin_inset Quotes srd
12396 \begin_layout Standard
12397 There are some more environment variables recognized by SDCC, but these
12398 are solely used for debugging purposes.
12399 They can change or disappear very quickly, and will never be documented.
12400 \begin_inset VSpace bigskip
12406 \begin_layout Section
12407 Storage Class Language Extensions
12410 \begin_layout Subsection
12411 MCS51/DS390 Storage Class
12412 \begin_inset LatexCommand index
12413 name "Storage class"
12417 Language Extensions
12420 \begin_layout Standard
12421 In addition to the ANSI storage classes SDCC allows the following MCS51
12422 specific storage classes:
12425 \begin_layout Subsubsection
12427 \begin_inset LatexCommand index
12428 name "data (mcs51, ds390 storage class)"
12433 \begin_inset LatexCommand index
12434 name "\\_\\_data (mcs51, ds390 storage class)"
12439 \begin_inset LatexCommand index
12440 name "near (storage class)"
12445 \begin_inset LatexCommand index
12446 name "\\_\\_near (storage class)"
12453 \begin_layout Standard
12458 storage class for the Small Memory model (
12466 or the more ANSI-C compliant forms
12474 can be used synonymously).
12475 Variables declared with this storage class will be allocated in the directly
12476 addressable portion of the internal RAM of a 8051, e.g.:
12479 \begin_layout Verse
12482 __data unsigned char test_data;
12485 \begin_layout Standard
12486 Writing 0x01 to this variable generates the assembly code:
12489 \begin_layout Verse
12492 75*00 01\InsetSpace ~
12500 \begin_layout Subsubsection
12502 \begin_inset LatexCommand index
12503 name "xdata (mcs51, ds390 storage class)"
12508 \begin_inset LatexCommand index
12509 name "\\_\\_xdata (mcs51, ds390 storage class)"
12514 \begin_inset LatexCommand index
12515 name "far (storage class)"
12520 \begin_inset LatexCommand index
12521 name "\\_\\_far (storage class)"
12528 \begin_layout Standard
12529 Variables declared with this storage class will be placed in the external
12535 storage class for the Large Memory model, e.g.:
12538 \begin_layout Verse
12541 __xdata unsigned char test_xdata;
12544 \begin_layout Standard
12545 Writing 0x01 to this variable generates the assembly code:
12548 \begin_layout Verse
12551 90s00r00\InsetSpace ~
12582 \begin_layout Subsubsection
12584 \begin_inset LatexCommand index
12585 name "idata (mcs51, ds390 storage class)"
12590 \begin_inset LatexCommand index
12591 name "\\_\\_idata (mcs51, ds390 storage class)"
12598 \begin_layout Standard
12599 Variables declared with this storage class will be allocated into the indirectly
12600 addressable portion of the internal ram of a 8051, e.g.:
12603 \begin_layout Verse
12606 __idata unsigned char test_idata;
12609 \begin_layout Standard
12610 Writing 0x01 to this variable generates the assembly code:
12613 \begin_layout Verse
12640 \begin_layout Standard
12641 Please note, the first 128 byte of idata physically access the same RAM
12642 as the data memory.
12643 The original 8051 had 128 byte idata memory, nowadays most devices have
12644 256 byte idata memory.
12646 \begin_inset LatexCommand index
12651 is located in idata memory.
12654 \begin_layout Subsubsection
12656 \begin_inset LatexCommand index
12657 name "pdata (mcs51, ds390 storage class)"
12662 \begin_inset LatexCommand index
12663 name "\\_\\_pdata (mcs51, ds390 storage class)"
12670 \begin_layout Standard
12671 Paged xdata access is just as straightforward as using the other addressing
12673 It is typically located at the start of xdata and has a maximum size of
12675 The following example writes 0x01 to the pdata variable.
12676 Please note, pdata access physically accesses xdata memory.
12677 The high byte of the address is determined by port P2
12678 \begin_inset LatexCommand index
12679 name "P2 (mcs51 sfr)"
12683 (or in case of some 8051 variants by a separate Special Function Register,
12685 \begin_inset LatexCommand ref
12686 reference "sub:MCS51-variants"
12695 storage class for the Medium Memory model, e.g.:
12698 \begin_layout Verse
12701 __pdata unsigned char test_pdata;
12704 \begin_layout Standard
12705 Writing 0x01 to this variable generates the assembly code:
12708 \begin_layout Verse
12717 mov r0,#_test_pdata
12739 \begin_layout Standard
12744 \begin_layout Standard
12754 \begin_inset LatexCommand index
12759 option is used the pdata memory area is followed by the xstack memory area
12760 and the sum of their sizes is limited to 256 bytes.
12763 \begin_layout Subsubsection
12765 \begin_inset LatexCommand index
12771 \begin_inset LatexCommand index
12779 \begin_layout Standard
12780 'Variables' declared with this storage class will be placed in the code
12784 \begin_layout Verse
12787 __code unsigned char test_code;
12790 \begin_layout Standard
12791 Read access to this variable generates the assembly code:
12794 \begin_layout Verse
12797 90s00r6F\InsetSpace ~
12800 mov dptr,#_test_code
12825 \begin_layout Standard
12830 indexed arrays of characters in code memory can be accessed efficiently:
12833 \begin_layout Verse
12836 __code char test_array[] = {'c','h','e','a','p'};
12839 \begin_layout Standard
12840 Read access to this array using an 8-bit unsigned index generates the assembly
12844 \begin_layout Verse
12856 \begin_layout Verse
12859 90s00r41\InsetSpace ~
12862 mov dptr,#_test_array
12865 \begin_layout Verse
12880 \begin_layout Subsubsection
12882 \begin_inset LatexCommand index
12888 \begin_inset LatexCommand index
12896 \begin_layout Standard
12897 This is a data-type and a storage class specifier.
12898 When a variable is declared as a bit, it is allocated into the bit addressable
12899 memory of 8051, e.g.:
12902 \begin_layout Verse
12908 \begin_layout Standard
12909 Writing 1 to this variable generates the assembly code:
12912 \begin_layout Verse
12926 \begin_layout Standard
12927 The bit addressable memory consists of 128 bits which are located from 0x20
12928 to 0x2f in data memory.
12931 Apart from this 8051 specific storage class most architectures support
12933 \begin_inset LatexCommand index
12942 \begin_layout Standard
12943 Not really meant as examples, but nevertheless showing what bitfields are
12944 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12950 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12951 signed modifier are implemented as unsigned.
12954 \begin_layout Subsubsection
12956 \begin_inset LatexCommand index
12962 \begin_inset LatexCommand index
12968 \begin_inset LatexCommand index
12974 \begin_inset LatexCommand index
12980 \begin_inset LatexCommand index
12986 \begin_inset LatexCommand index
12992 \begin_inset LatexCommand index
12998 \begin_inset LatexCommand index
13006 \begin_layout Standard
13007 Like the bit keyword,
13009 sfr / sfr16 / sfr32 / sbit
13011 signify both a data-type and storage class, they are used to describe the
13032 variables of a 8051, eg:
13035 \begin_layout Verse
13039 \begin_inset LatexCommand index
13045 \begin_inset LatexCommand index
13050 (0x80) P0;\InsetSpace ~
13051 /* special function register P0 at location 0x80 */
13056 special function register combination for timer 0
13060 with the high byte at
13061 location 0x8C and the low byte at location 0x8A */
13063 __sfr16 __at (0x8C8A)
13069 \begin_inset LatexCommand index
13075 \begin_inset LatexCommand index
13080 (0xd7) CY;\InsetSpace ~
13082 \begin_inset LatexCommand index
13088 \begin_inset LatexCommand index
13096 \begin_layout Standard
13097 Special function registers which are located on an address dividable by
13098 8 are bit-addressable, an
13102 addresses a specific bit within these sfr.
13104 16 Bit and 32 bit special function
13105 register combinations which require a certain access order are better not
13115 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
13116 this is not guaranteed.
13121 \begin_layout Standard
13122 Please note, if you use a header file which was written for another compiler
13123 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
13129 Specifically the syntax
13132 sfr P0 = 0x80;\InsetSpace ~
13139 by SDCC to an assignment of 0x80 to a variable called P0
13142 \begin_inset Marginal
13145 \begin_layout Standard
13159 Nevertheless it is possible to write header files
13160 \begin_inset LatexCommand index
13161 name "Header files"
13166 \begin_inset LatexCommand index
13167 name "Include files"
13171 which can be shared among different compilers (see section
13172 \begin_inset LatexCommand ref
13173 reference "sec:Porting-code-to-other-compilers"
13181 \begin_layout Subsubsection
13183 \begin_inset LatexCommand index
13188 to MCS51/DS390 specific memory spaces
13191 \begin_layout Standard
13192 SDCC allows (via language extensions) pointers to explicitly point to any
13193 of the memory spaces
13194 \begin_inset LatexCommand index
13195 name "Memory model"
13200 In addition to the explicit pointers, the compiler uses (by default) generic
13201 pointers which can be used to point to any of the memory spaces.
13206 declaration examples:
13209 \begin_layout Verse
13212 /* pointer physically in internal ram pointing to object in external ram
13215 __xdata unsigned char * __data p;
13219 /* pointer physically in external ram
13220 pointing to object in internal ram */
13222 __data unsigned char * __xdata p;
13227 pointer physically in code rom pointing to data in xdata space */
13230 unsigned char * __code p;
13234 /* pointer physically in code space pointing to
13235 data in code space */
13237 __code unsigned char * __code p;
13242 physically located in xdata space */
13244 unsigned char * __xdata p;
13249 pointer physically located in default memory space */
13256 the following is a function pointer
13257 \begin_inset LatexCommand index
13258 name "function pointer"
13262 physically located in data space */
13264 char (* __data fp)(void);
13267 \begin_layout Standard
13268 Well you get the idea.
13273 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
13286 The highest order byte of the
13290 pointers contains the data space information.
13291 Assembler support routines are called whenever data is stored or retrieved
13297 These are useful for developing reusable library
13298 \begin_inset LatexCommand index
13304 Explicitly specifying the pointer
13305 \begin_inset LatexCommand index
13310 type will generate the most efficient code.
13313 \begin_layout Subsubsection
13314 Notes on MCS51 memory
13315 \begin_inset LatexCommand index
13316 name "MCS51 memory"
13323 \begin_layout Standard
13324 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
13325 RAM memory which is structured as follows:
13329 - Bytes 00-1F - 32 bytes to hold
13330 up to 4 banks of the registers R0 to R7,
13332 - Bytes 20-2F - 16 bytes to hold
13334 \begin_inset LatexCommand index
13341 - Bytes 30-7F - 80 bytes for general purpose use.
13346 \begin_layout Standard
13347 Additionally some members of the MCS51 family may have up to 128 bytes of
13348 additional, indirectly addressable, internal RAM memory (
13353 \begin_inset LatexCommand index
13354 name "idata (mcs51, ds390 storage class)"
13359 \begin_inset LatexCommand index
13360 name "\\_\\_idata (mcs51, ds390 storage class)"
13365 Furthermore, some chips may have some built in external memory (
13370 \begin_inset LatexCommand index
13371 name "xdata (mcs51, ds390 storage class)"
13376 \begin_inset LatexCommand index
13377 name "\\_\\_xdata (mcs51, ds390 storage class)"
13381 ) which should not be confused with the internal, directly addressable RAM
13387 \begin_inset LatexCommand index
13388 name "data (mcs51, ds390 storage class)"
13393 \begin_inset LatexCommand index
13394 name "\\_\\_data (mcs51, ds390 storage class)"
13399 Sometimes this built in
13403 memory has to be activated before using it (you can probably find this
13404 information on the datasheet of the microcontroller your are using, see
13406 \begin_inset LatexCommand ref
13407 reference "sub:Startup-Code"
13415 \begin_layout Standard
13416 Normally SDCC will only use the first bank
13417 \begin_inset LatexCommand index
13418 name "register bank (mcs51, ds390)"
13422 of registers (register bank 0), but it is possible to specify that other
13423 banks of registers (keyword
13430 \begin_inset LatexCommand index
13431 name "using (mcs51, ds390 register bank)"
13436 \begin_inset LatexCommand index
13437 name "\\_\\_using (mcs51, ds390 register bank)"
13443 ) should be used for example in interrupt
13444 \begin_inset LatexCommand index
13450 \begin_inset LatexCommand index
13451 name "\\_\\_interrupt"
13456 By default, the compiler will place the stack after the last byte of allocated
13457 memory for variables.
13458 For example, if the first 2 banks of registers are used, and only four
13463 variables, it will position the base of the internal stack at address 20
13465 This implies that as the stack
13466 \begin_inset LatexCommand index
13471 grows, it will use up the remaining register banks, and the 16 bytes used
13472 by the 128 bit variables, and 80 bytes for general purpose use.
13473 If any bit variables are used, the data variables will be placed in unused
13474 register banks and after the byte holding the last bit variable.
13475 For example, if register banks 0 and 1 are used, and there are 9 bit variables
13480 variables will be placed starting from address 0x10 to 0x20 and continue
13486 \begin_layout Standard
13496 \begin_inset LatexCommand index
13497 name "-\\/-data-loc <Value>"
13501 to specify the start address of the
13509 \begin_layout Standard
13519 \begin_inset LatexCommand index
13520 name "-\\/-iram-size <Value>"
13524 to specify the size of the total internal RAM (
13538 \begin_layout Standard
13539 By default the 8051 linker will place the stack after the last byte of (i)data
13545 \begin_layout Standard
13555 \begin_inset LatexCommand index
13556 name "-\\/-stack-loc <Value>"
13560 allows you to specify the start of the stack, i.e.
13561 you could start it after any data in the general purpose area.
13562 If your microcontroller has additional indirectly addressable internal
13567 ) you can place the stack on it.
13568 You may also need to use -
13572 \begin_layout Standard
13582 \begin_inset LatexCommand index
13583 name "-\\/-xdata-loc<Value>"
13587 to set the start address of the external RAM (
13595 \begin_layout Standard
13605 \begin_inset LatexCommand index
13606 name "-\\/-xram-size <Value>"
13610 to specify its size.
13611 Same goes for the code memory, using -
13615 \begin_layout Standard
13625 \begin_inset LatexCommand index
13626 name "-\\/-code-loc <Value>"
13634 \begin_layout Standard
13644 \begin_inset LatexCommand index
13645 name "-\\/-code-size <Value>"
13650 If in doubt, don't specify any options and see if the resulting memory
13651 layout is appropriate, then you can adjust it.
13654 \begin_layout Standard
13655 The linker generates two files with memory allocation information.
13656 The first, with extension .map
13657 \begin_inset LatexCommand index
13662 shows all the variables and segments.
13663 The second with extension .mem
13664 \begin_inset LatexCommand index
13669 shows the final memory layout.
13670 The linker will complain either if memory segments overlap, there is not
13671 enough memory, or there is not enough space for stack.
13672 If you get any linking warnings and/or errors related to stack or segments
13673 allocation, take a look at either the .map or .mem files to find out what
13675 The .mem file may even suggest a solution to the problem.
13676 \begin_inset VSpace bigskip
13682 \begin_layout Subsection
13683 Z80/Z180 Storage Class
13684 \begin_inset LatexCommand index
13685 name "Z80!Storage class"
13689 Language Extensions
13692 \begin_layout Subsubsection
13694 \begin_inset LatexCommand index
13700 \begin_inset LatexCommand index
13705 (in/out to 8-bit addresses)
13708 \begin_layout Standard
13710 \begin_inset LatexCommand index
13715 family has separate address spaces for memory and
13725 \begin_inset LatexCommand index
13726 name "I/O memory (Z80, Z180)"
13731 \begin_inset LatexCommand index
13732 name "Z80!I/O memory"
13737 \begin_inset LatexCommand index
13738 name "Z180!I/O memory"
13742 is accessed with special instructions, e.g.:
13745 \begin_layout Verse
13748 sfr at 0x78 IoPort;\InsetSpace ~
13750 /* define a var in I/O space at 78h called IoPort */
13754 \begin_layout Standard
13755 Writing 0x01 to this variable generates the assembly code:
13758 \begin_layout Verse
13778 \begin_layout Subsubsection
13780 \begin_inset LatexCommand index
13786 \begin_inset LatexCommand index
13791 (in/out to 16-bit addresses)
13794 \begin_layout Standard
13799 is used to support 16 bit addresses in I/O memory e.g.:
13802 \begin_layout Verse
13806 \begin_inset LatexCommand index
13812 \begin_inset LatexCommand index
13820 \begin_layout Standard
13821 Writing 0x01 to this variable generates the assembly code:
13824 \begin_layout Verse
13827 01 23 01\InsetSpace ~
13849 \begin_layout Subsubsection
13851 \begin_inset LatexCommand index
13857 \begin_inset LatexCommand index
13862 (in0/out0 to 8 bit addresses on Z180
13863 \begin_inset LatexCommand index
13869 \begin_inset LatexCommand index
13870 name "HD64180 (see Z180)"
13877 \begin_layout Standard
13878 The compiler option -
13882 \begin_layout Standard
13892 \begin_inset LatexCommand index
13893 name "Z180!Options!-\\/-portmode"
13897 =180 (80) and a compiler #pragma\InsetSpace ~
13899 \begin_inset LatexCommand index
13900 name "Z180!Pragmas!\\#pragma portmode"
13904 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
13914 If you include the file z180.h this will be set automatically.
13915 \begin_inset VSpace bigskip
13921 \begin_layout Subsection
13923 \begin_inset LatexCommand index
13924 name "HC08!Storage class"
13928 Language Extensions
13931 \begin_layout Subsubsection
13933 \begin_inset LatexCommand index
13934 name "data (hc08 storage class)"
13939 \begin_inset LatexCommand index
13940 name "\\_\\_data (hc08 storage class)"
13947 \begin_layout Standard
13948 The data storage class declares a variable that resides in the first 256
13949 bytes of memory (the direct page).
13951 \begin_inset LatexCommand index
13956 is most efficient at accessing variables (especially pointers) stored here.
13959 \begin_layout Subsubsection
13961 \begin_inset LatexCommand index
13962 name "xdata (hc08 storage class)"
13967 \begin_inset LatexCommand index
13968 name "\\_\\_xdata (hc08 storage class)"
13975 \begin_layout Standard
13976 The xdata storage class declares a variable that can reside anywhere in
13978 This is the default if no storage class is specified.
13980 \begin_inset VSpace bigskip
13986 \begin_layout Section
13987 Other SDCC language extensions
13988 \begin_inset LatexCommand index
13989 name "Other SDCC language extensions"
13996 \begin_layout Subsection
14000 \begin_layout Standard
14001 SDCC supports the use of binary constants, such as 0b01100010.
14002 This feature is only enabled when the compiler is invoked using --std-sdccxx.
14005 \begin_layout Standard
14006 \begin_inset VSpace bigskip
14012 \begin_layout Section
14013 Absolute Addressing
14014 \begin_inset LatexCommand index
14015 name "Absolute addressing"
14022 \begin_layout Standard
14023 Data items can be assigned an absolute address with the
14026 \begin_inset LatexCommand index
14032 \begin_inset LatexCommand index
14039 keyword, in addition to a storage class, e.g.:
14042 \begin_layout Verse
14046 \begin_inset LatexCommand index
14047 name "xdata (mcs51, ds390 storage class)"
14052 \begin_inset LatexCommand index
14053 name "\\_\\_xdata (mcs51, ds390 storage class)"
14058 \begin_inset LatexCommand index
14064 \begin_inset LatexCommand index
14069 0x7ffe unsigned int chksum;
14072 \begin_layout Standard
14073 or, better conforming to ISO/IEC 9899 C:
14076 \begin_layout Verse
14079 __xdata __at (0x7ffe) unsigned int chksum;
14082 \begin_layout Standard
14083 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
14084 of the external ram.
14089 reserve any space for variables declared in this way
14090 \begin_inset Marginal
14093 \begin_layout Standard
14102 (they are implemented with an equate in the assembler).
14103 Thus it is left to the programmer to make sure there are no overlaps with
14104 other variables that are declared without the absolute address.
14105 The assembler listing file (.lst
14106 \begin_inset LatexCommand index
14111 ) and the linker output files (.rst
14112 \begin_inset LatexCommand index
14118 \begin_inset LatexCommand index
14123 ) are good places to look for such overlaps.
14126 \begin_layout Standard
14127 If however you provide an initializer
14128 \begin_inset LatexCommand index
14129 name "Variable initialization"
14133 actual memory allocation will take place and overlaps will be detected
14138 \begin_layout Verse
14141 __code __at (0x7ff0) char Id[5] =
14142 \begin_inset Quotes sld
14146 \begin_inset Quotes srd
14152 \begin_layout Standard
14153 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
14157 \begin_layout Standard
14158 In case of memory mapped I/O devices the keyword
14162 has to be used to tell the compiler that accesses might not be removed:
14165 \begin_layout Verse
14169 \begin_inset LatexCommand index
14175 \begin_inset LatexCommand index
14176 name "xdata (mcs51, ds390 storage class)"
14181 \begin_inset LatexCommand index
14186 (0x8000) unsigned char PORTA_8255;
14189 \begin_layout Standard
14190 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
14195 \begin_inset LatexCommand index
14196 name "Aligned array"
14203 starts at a block (256 byte) boundary
14204 \begin_inset LatexCommand index
14205 name "block boundary"
14210 \begin_inset LatexCommand ref
14211 reference "sub:A-Step-by Assembler Introduction"
14217 Absolute addresses can be specified for variables in all
14218 storage classes, e.g.:
14221 \begin_layout Verse
14225 \begin_inset LatexCommand index
14231 \begin_inset LatexCommand index
14239 \begin_layout Standard
14240 The above example will allocate the variable at offset 0x02 in the bit-addressab
14242 There is no real advantage to assigning absolute addresses to variables
14243 in this manner, unless you want strict control over all the variables allocated.
14244 One possible use would be to write hardware portable code.
14245 For example, if you have a routine that uses one or more of the microcontroller
14246 I/O pins, and such pins are different for two different hardwares, you
14247 can declare the I/O pins in your routine using:
14250 \begin_layout Verse
14254 \begin_inset LatexCommand index
14259 __bit MOSI;\InsetSpace ~
14263 /* master out, slave in */
14265 extern volatile __bit MISO;\InsetSpace ~
14272 extern volatile __bit MCLK;\InsetSpace ~
14281 Output of a byte on a 3-wire serial bus.
14286 If needed adapt polarity of clock,
14287 polarity of data and bit order
14292 unsigned char spi_io(unsigned char out_byte)
14317 MOSI = out_byte & 0x80;
14348 /* _asm nop _endasm; */\InsetSpace ~
14356 /* for slow peripherals */
14408 \begin_layout Standard
14409 Then, someplace in the code for the first hardware you would use
14412 \begin_layout Verse
14416 \begin_inset LatexCommand index
14422 \begin_inset LatexCommand index
14427 (0x80) MOSI;\InsetSpace ~
14431 /* I/O port 0, bit 0 */
14433 __bit __at (0x81) MISO;\InsetSpace ~
14440 __bit __at (0x82) MCLK;\InsetSpace ~
14444 /* I/O port 0, bit 2 */
14447 \begin_layout Standard
14448 Similarly, for the second hardware you would use
14451 \begin_layout Verse
14454 __bit __at (0x83) MOSI;\InsetSpace ~
14458 /* I/O port 0, bit 3 */
14460 __bit __at (0x91) MISO;\InsetSpace ~
14465 I/O port 1, bit 1 */
14468 \begin_inset LatexCommand index
14473 __at (0x92) MCLK;\InsetSpace ~
14477 /* I/O port 1, bit 2 */
14480 \begin_layout Standard
14481 and you can use the same hardware dependent routine without changes, as
14482 for example in a library.
14483 This is somehow similar to sbit, but only one absolute address has to be
14484 specified in the whole project.
14485 \begin_inset VSpace bigskip
14491 \begin_layout Section
14493 \begin_inset LatexCommand index
14499 \begin_inset LatexCommand index
14500 name "function parameter"
14505 \begin_inset LatexCommand index
14506 name "local variables"
14511 \begin_inset LatexCommand label
14512 name "sec:Parameters-and-Local-Variables"
14519 \begin_layout Standard
14520 Automatic (local) variables and parameters to functions can either be placed
14521 on the stack or in data-space.
14522 The default action of the compiler is to place these variables in the internal
14523 RAM (for small model) or external RAM (for medium or large model).
14524 This in fact makes them similar to
14527 \begin_inset LatexCommand index
14534 so by default functions are non-reentrant
14535 \begin_inset LatexCommand index
14545 They can be placed on the stack
14546 \begin_inset LatexCommand index
14557 \begin_layout Standard
14567 \begin_inset LatexCommand index
14568 name "-\\/-stack-auto"
14576 #pragma\InsetSpace ~
14580 \begin_inset LatexCommand index
14581 name "\\#pragma stackauto"
14588 \begin_inset LatexCommand index
14595 keyword in the function declaration, e.g.:
14598 \begin_layout Verse
14601 unsigned char foo(char i) __reentrant
14615 \begin_layout Standard
14616 Since stack space on 8051 is limited, the
14626 \begin_layout Standard
14637 option should be used sparingly.
14638 Note that the reentrant keyword just means that the parameters & local
14639 variables will be allocated to the stack, it
14643 mean that the function is register bank
14644 \begin_inset LatexCommand index
14645 name "register bank (mcs51, ds390)"
14654 \begin_inset LatexCommand index
14655 name "local variables"
14659 can be assigned storage classes and absolute
14660 \begin_inset LatexCommand index
14661 name "Absolute addressing"
14668 \begin_layout Verse
14671 unsigned char foo()
14679 __xdata unsigned char i;
14692 \begin_inset LatexCommand index
14697 (0x31) unsigned char j;
14709 \begin_layout Standard
14710 In the above example the variable
14714 will be allocated in the external ram,
14718 in bit addressable space and
14729 \begin_layout Standard
14740 or when a function is declared as
14744 this should only be done for static variables.
14747 \begin_layout Standard
14749 \begin_inset LatexCommand index
14750 name "function parameter"
14754 however are not allowed any storage class
14755 \begin_inset LatexCommand index
14756 name "Storage class"
14760 , (storage classes for parameters will be ignored), their allocation is
14761 governed by the memory model in use, and the reentrancy options.
14764 \begin_layout Standard
14765 It is however allowed to use bit parameters in reentrant functions and also
14766 non-static local bit variables are supported.
14767 Efficient use is limited to 8 semi-bitregisters in bit space.
14768 They are pushed and popped to stack
14769 \begin_inset LatexCommand index
14774 as a single byte just like the normal registers.
14777 \begin_layout Section
14779 \begin_inset LatexCommand label
14780 name "sub:Overlaying"
14785 \begin_inset LatexCommand index
14793 \begin_layout Standard
14795 \begin_inset LatexCommand index
14800 functions SDCC will try to reduce internal ram space usage by overlaying
14801 parameters and local variables of a function (if possible).
14802 Parameters and local variables
14803 \begin_inset LatexCommand index
14804 name "local variables"
14808 of a function will be allocated to an overlayable segment if the function
14811 no other function calls and the function is non-reentrant and the memory
14813 \begin_inset LatexCommand index
14814 name "Memory model"
14821 If an explicit storage class
14822 \begin_inset LatexCommand index
14823 name "Storage class"
14827 is specified for a local variable, it will NOT be overlaid.
14830 \begin_layout Standard
14831 Note that the compiler (not the linkage editor) makes the decision for overlayin
14833 Functions that are called from an interrupt service routine
14834 \begin_inset Marginal
14837 \begin_layout Standard
14845 should be preceded by a #pragma\InsetSpace ~
14847 \begin_inset LatexCommand index
14848 name "\\#pragma nooverlay"
14852 if they are not reentrant.
14855 \begin_layout Standard
14856 Also note that the compiler does not do any processing of inline assembler
14857 code, so the compiler might incorrectly assign local variables and parameters
14858 of a function into the overlay segment if the inline assembler code calls
14859 other c-functions that might use the overlay.
14860 In that case the #pragma\InsetSpace ~
14861 nooverlay should be used.
14864 \begin_layout Standard
14865 Parameters and local variables of functions that contain 16 or 32 bit multiplica
14867 \begin_inset LatexCommand index
14868 name "Multiplication"
14873 \begin_inset LatexCommand index
14878 will NOT be overlaid since these are implemented using external functions,
14882 \begin_layout Verse
14888 \begin_inset LatexCommand index
14889 name "\\#pragma nooverlay"
14895 void set_error(unsigned char errcd)
14912 some_isr () __interrupt
14913 \begin_inset LatexCommand index
14944 \begin_layout Standard
14945 In the above example the parameter
14953 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
14955 not present, this could cause unpredictable runtime behavior when called
14956 from an interrupt service routine.
14957 The #pragma\InsetSpace ~
14958 nooverlay ensures that the parameters and local variables for
14959 the function are NOT overlaid.
14960 \begin_inset VSpace bigskip
14966 \begin_layout Section
14967 Interrupt Service Routines
14968 \begin_inset LatexCommand label
14969 name "sub:Interrupt-Service-Routines"
14976 \begin_layout Subsection
14977 General Information
14980 \begin_layout Standard
14993 outines to be coded in C, with some extended keywords.
14996 \begin_layout Verse
14999 void timer_isr (void) __interrupt (1) __using (1)
15013 \begin_layout Standard
15014 The optional number following the
15017 \begin_inset LatexCommand index
15023 \begin_inset LatexCommand index
15024 name "\\_\\_interrupt"
15030 keyword is the interrupt number this routine will service.
15031 When present, the compiler will insert a call to this routine in the interrupt
15033 \begin_inset LatexCommand index
15034 name "interrupt vector table"
15038 for the interrupt number specified.
15039 If you have multiple source files in your project, interrupt service routines
15040 can be present in any of them, but a prototype of the isr MUST be present
15041 or included in the file that contains the function
15046 The optional (8051 specific) keyword
15049 \begin_inset LatexCommand index
15050 name "using (mcs51, ds390 register bank)"
15055 \begin_inset LatexCommand index
15056 name "\\_\\_using (mcs51, ds390 register bank)"
15062 can be used to tell the compiler to use the specified register bank when
15063 generating code for this function.
15066 Interrupt service routines open the door for some very interesting bugs:
15069 \begin_layout Subsubsection
15070 \begin_inset LatexCommand label
15071 name "sub:Common-interrupt-pitfall-volatile"
15075 Common interrupt pitfall: variable not declared
15080 \begin_layout Standard
15081 If an interrupt service routine changes variables which are accessed by
15082 other functions these variables have to be declared
15087 \begin_inset LatexCommand index
15094 \begin_inset LatexCommand url
15095 target "http://en.wikipedia.org/wiki/Volatile_variable"
15102 \begin_layout Subsubsection
15103 \begin_inset LatexCommand label
15104 name "sub:Common-interrupt-pitfall-non-atomic"
15108 Common interrupt pitfall:
15113 \begin_layout Standard
15114 If the access to these variables is not
15117 \begin_inset LatexCommand index
15125 the processor needs more than one instruction for the access and could
15126 be interrupted while accessing the variable) the interrupt must be disabled
15127 during the access to avoid inconsistent data.
15130 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
15131 and should be protected by disabling interrupts.
15132 You're not automatically on the safe side if you use 8 bit variables though.
15133 We need an example here: f.e.
15134 on the 8051 the harmless looking
15135 \begin_inset Quotes srd
15145 \begin_inset Quotes sld
15154 \begin_inset Quotes srd
15164 \begin_inset Quotes sld
15167 from within an interrupt routine might get lost if the interrupt occurs
15170 \begin_inset Quotes sld
15175 counter\InsetSpace ~
15180 \begin_inset Quotes srd
15183 is not atomic on the 8051 even if
15187 is located in data memory.
15189 Bugs like these are hard to reproduce and can
15190 cause a lot of trouble.
15194 \begin_layout Subsubsection
15195 \begin_inset LatexCommand label
15196 name "sub:Common-interrupt-pitfall-stack-overflow"
15200 Common interrupt pitfall:
15205 \begin_layout Standard
15206 The return address and the registers used in the interrupt service routine
15207 are saved on the stack
15208 \begin_inset LatexCommand index
15213 so there must be sufficient stack space.
15214 If there isn't variables or registers (or even the return address itself)
15221 \begin_inset LatexCommand index
15222 name "stack overflow"
15226 is most likely to happen if the interrupt occurs during the
15227 \begin_inset Quotes sld
15231 \begin_inset Quotes srd
15234 subroutine when the stack is already in use for f.e.
15235 many return addresses.
15238 \begin_layout Subsubsection
15239 \begin_inset LatexCommand label
15240 name "sub:Common-interrupt-pitfall-non-reentrant"
15244 Common interrupt pitfall:
15246 use of non-reentrant functions
15249 \begin_layout Standard
15250 A special note here, int (16 bit) and long (32 bit) integer division
15251 \begin_inset LatexCommand index
15257 \begin_inset LatexCommand index
15258 name "Multiplication"
15263 \begin_inset LatexCommand index
15269 \begin_inset LatexCommand index
15270 name "Floating point support"
15274 operations are implemented using external support routines.
15275 If an interrupt service routine needs to do any of these operations then
15276 the support routines (as mentioned in a following section) will have to
15277 be recompiled using the
15283 \begin_layout Standard
15293 \begin_inset LatexCommand index
15294 name "-\\/-stack-auto"
15300 option and the source file will need to be compiled using the
15306 \begin_layout Standard
15318 \begin_inset LatexCommand index
15319 name "-\\/-int-long-reent"
15326 Note, the type promotion
15327 \begin_inset LatexCommand index
15328 name "type promotion"
15332 required by ANSI C can cause 16 bit routines to be used
15333 \begin_inset Marginal
15336 \begin_layout Standard
15345 without the programmer being aware of it.
15350 (unsigned char)(tail-1)
15355 within the if clause in section
15356 \begin_inset LatexCommand ref
15357 reference "sub:A-Step-by Assembler Introduction"
15364 \begin_layout Standard
15365 Calling other functions from an interrupt service routine is not recommended,
15366 avoid it if possible.
15367 Note that when some function is called from an interrupt service routine
15368 it should be preceded by a #pragma\InsetSpace ~
15370 \begin_inset LatexCommand index
15371 name "\\#pragma nooverlay"
15375 if it is not reentrant.
15376 Furthermore nonreentrant functions should not be called from the main program
15377 while the interrupt service routine might be active.
15378 They also must not be called from low priority interrupt service routines
15379 while a high priority interrupt service routine might be active.
15380 You could use semaphores or make the function
15384 if all parameters are passed in registers.
15387 \begin_inset LatexCommand ref
15388 reference "sub:Overlaying"
15393 about Overlaying and section
15394 \begin_inset LatexCommand ref
15395 reference "sub:Functions-using-private-banks"
15400 about Functions using private register banks.
15401 \begin_inset VSpace bigskip
15407 \begin_layout Subsection
15408 MCS51/DS390 Interrupt Service Routines
15411 \begin_layout Standard
15413 \begin_inset LatexCommand index
15418 numbers and the corresponding address & descriptions for the Standard 8051/8052
15420 SDCC will automatically adjust the
15421 \begin_inset LatexCommand index
15422 name "interrupt vector table"
15426 to the maximum interrupt number specified.
15431 \begin_layout Standard
15433 \begin_inset Tabular
15434 <lyxtabular version="3" rows="9" columns="3">
15436 <column alignment="center" valignment="top" leftline="true" width="0in">
15437 <column alignment="left" valignment="top" leftline="true" width="0in">
15438 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
15439 <row topline="true" bottomline="true">
15440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15443 \begin_layout Standard
15449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15452 \begin_layout Standard
15458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15461 \begin_layout Standard
15468 <row topline="true">
15469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15472 \begin_layout Standard
15478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15481 \begin_layout Standard
15487 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15490 \begin_layout Standard
15497 <row topline="true">
15498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15501 \begin_layout Standard
15507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15510 \begin_layout Standard
15516 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15519 \begin_layout Standard
15526 <row topline="true">
15527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15530 \begin_layout Standard
15536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15539 \begin_layout Standard
15545 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15548 \begin_layout Standard
15555 <row topline="true">
15556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15559 \begin_layout Standard
15565 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15568 \begin_layout Standard
15574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15577 \begin_layout Standard
15584 <row topline="true">
15585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15588 \begin_layout Standard
15594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15597 \begin_layout Standard
15603 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15606 \begin_layout Standard
15613 <row topline="true">
15614 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15617 \begin_layout Standard
15623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15626 \begin_layout Standard
15632 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15635 \begin_layout Standard
15642 <row topline="true">
15643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15646 \begin_layout Standard
15652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15655 \begin_layout Standard
15661 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15664 \begin_layout Standard
15671 <row topline="true" bottomline="true">
15672 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15675 \begin_layout Standard
15681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15684 \begin_layout Standard
15690 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15693 \begin_layout Standard
15709 \begin_layout Standard
15710 If the interrupt service routine is defined without
15713 \begin_inset LatexCommand index
15714 name "using (mcs51, ds390 register bank)"
15719 \begin_inset LatexCommand index
15720 name "\\_\\_using (mcs51, ds390 register bank)"
15726 a register bank or with register bank 0 (
15730 0), the compiler will save the registers used by itself on the stack upon
15731 entry and restore them at exit, however if such an interrupt service routine
15732 calls another function then the entire register bank will be saved on the
15734 This scheme may be advantageous for small interrupt service routines which
15735 have low register usage.
15738 \begin_layout Standard
15739 If the interrupt service routine is defined to be using a specific register
15744 & psw are saved and restored, if such an interrupt service routine calls
15745 another function (using another register bank) then the entire register
15746 bank of the called function will be saved on the stack
15747 \begin_inset LatexCommand index
15753 This scheme is recommended for larger interrupt service routines.
15754 \begin_inset VSpace bigskip
15760 \begin_layout Subsection
15762 \begin_inset LatexCommand index
15767 Interrupt Service Routines
15770 \begin_layout Standard
15771 Since the number of interrupts
15772 \begin_inset LatexCommand index
15773 name "HC08!interrupt"
15777 available is chip specific and the interrupt vector table always ends at
15778 the last byte of memory, the interrupt numbers corresponds to the interrupt
15779 vectors in reverse order of address.
15780 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
15781 2 will use the interrupt vector at 0xfffa, and so on.
15782 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
15783 this way; instead see section
15784 \begin_inset LatexCommand ref
15785 reference "sub:Startup-Code"
15789 for details on customizing startup.
15790 \begin_inset VSpace bigskip
15796 \begin_layout Subsection
15797 Z80 Interrupt Service Routines
15800 \begin_layout Standard
15802 \begin_inset LatexCommand index
15807 uses several different methods for determining the correct interrupt
15808 \begin_inset LatexCommand index
15809 name "Z80!interrupt"
15813 vector depending on the hardware implementation.
15814 Therefore, SDCC ignores the optional interrupt number and does not attempt
15815 to generate an interrupt vector table.
15818 \begin_layout Standard
15819 By default, SDCC generates code for a maskable interrupt, which uses a RETI
15820 instruction to return from the interrupt.
15821 To write an interrupt handler for the non-maskable interrupt, which needs
15822 a RETN instruction instead, add the
15829 \begin_layout Verse
15832 void nmi_isr (void) critical interrupt
15846 \begin_layout Standard
15847 However if you need to create a non-interruptable interrupt service routine
15848 you would also require the
15853 To distinguish between this and an nmi_isr you must provide an interrupt
15855 \begin_inset VSpace bigskip
15861 \begin_layout Section
15862 Enabling and Disabling Interrupts
15865 \begin_layout Subsection
15866 Critical Functions and Critical Statements
15869 \begin_layout Standard
15870 A special keyword may be associated with a block or a function declaring
15876 SDCC will generate code to disable all interrupts
15877 \begin_inset LatexCommand index
15882 upon entry to a critical function and restore the interrupt enable to the
15883 previous state before returning.
15884 Nesting critical functions will need one additional byte on the stack
15885 \begin_inset LatexCommand index
15893 \begin_layout Verse
15896 int foo () __critical
15897 \begin_inset LatexCommand index
15903 \begin_inset LatexCommand index
15904 name "\\_\\_critical"
15929 \begin_layout Standard
15930 The critical attribute maybe used with other attributes like
15940 may also be used to disable interrupts more locally:
15943 \begin_layout Verse
15949 \begin_layout Standard
15950 More than one statement could have been included in the block.
15953 \begin_layout Subsection
15954 Enabling and Disabling Interrupts directly
15957 \begin_layout Standard
15959 \begin_inset LatexCommand index
15964 can also be disabled and enabled directly (8051):
15967 \begin_layout Verse
15970 EA = 0;\InsetSpace ~
15996 \begin_layout Verse
16032 \begin_layout Verse
16035 EA = 1;\InsetSpace ~
16064 \begin_layout Verse
16103 \begin_layout Standard
16104 On other architectures which have separate opcodes for enabling and disabling
16105 interrupts you might want to make use of defines with inline assembly
16106 \begin_inset LatexCommand index
16107 name "Assembler routines"
16112 \begin_inset LatexCommand index
16113 name "HC08!interrupt"
16120 \begin_layout Verse
16124 \begin_inset LatexCommand index
16134 \begin_inset LatexCommand index
16142 \begin_layout Verse
16145 #define SEI _asm\InsetSpace ~
16152 \begin_layout Verse
16158 \begin_layout Standard
16159 Note: it is sometimes sufficient to disable only a specific interrupt source
16161 a timer or serial interrupt by manipulating an
16164 \begin_inset LatexCommand index
16165 name "interrupt mask"
16175 \begin_layout Standard
16176 Usually the time during which interrupts are disabled should be kept as
16178 This minimizes both
16183 \begin_inset LatexCommand index
16184 name "interrupt latency"
16188 (the time between the occurrence of the interrupt and the execution of
16189 the first code in the interrupt routine) and
16194 \begin_inset LatexCommand index
16195 name "interrupt jitter"
16199 (the difference between the shortest and the longest interrupt latency).
16200 These really are something different, f.e.
16201 a serial interrupt has to be served before its buffer overruns so it cares
16202 for the maximum interrupt latency, whereas it does not care about jitter.
16203 On a loudspeaker driven via a digital to analog converter which is fed
16204 by an interrupt a latency of a few milliseconds might be tolerable, whereas
16205 a much smaller jitter will be very audible.
16208 \begin_layout Standard
16209 You can reenable interrupts within an interrupt routine and on some architecture
16210 s you can make use of two (or more) levels of
16212 interrupt priorities
16215 \begin_inset LatexCommand index
16216 name "interrupt priority"
16221 On some architectures which don't support interrupt priorities these can
16222 be implemented by manipulating the interrupt mask and reenabling interrupts
16223 within the interrupt routine.
16224 Check there is sufficient space on the stack
16225 \begin_inset LatexCommand index
16230 and don't add complexity unless you have to.
16234 \begin_layout Subsection
16236 \begin_inset LatexCommand index
16241 locking (mcs51/ds390)
16244 \begin_layout Standard
16245 Some architectures (mcs51/ds390) have an atomic
16246 \begin_inset LatexCommand index
16251 bit test and clear instruction.
16252 These type of instructions are typically used in preemptive multitasking
16253 systems, where a routine f.e.
16254 claims the use of a data structure ('acquires a lock
16255 \begin_inset LatexCommand index
16260 on it'), makes some modifications and then releases the lock when the data
16261 structure is consistent again.
16262 The instruction may also be used if interrupt and non-interrupt code have
16263 to compete for a resource.
16264 With the atomic bit test and clear instruction interrupts
16265 \begin_inset LatexCommand index
16270 don't have to be disabled for the locking operation.
16274 \begin_layout Standard
16275 SDCC generates this instruction if the source follows this pattern:
16278 \begin_layout Verse
16282 \begin_inset LatexCommand index
16287 bit resource_is_free;
16291 if (resource_is_free)
16301 resource_is_free=0;
16314 resource_is_free=1;
16321 \begin_layout Standard
16322 Note, mcs51 and ds390 support only an atomic
16323 \begin_inset LatexCommand index
16332 instruction (as opposed to atomic bit test and
16337 \begin_layout Section
16338 Functions using private register banks
16339 \begin_inset LatexCommand label
16340 name "sub:Functions-using-private-banks"
16347 \begin_layout Standard
16348 Some architectures have support for quickly changing register sets.
16349 SDCC supports this feature with the
16352 \begin_inset LatexCommand index
16353 name "using (mcs51, ds390 register bank)"
16358 \begin_inset LatexCommand index
16359 name "\\_\\_using (mcs51, ds390 register bank)"
16365 attribute (which tells the compiler to use a register bank
16366 \begin_inset LatexCommand index
16367 name "register bank (mcs51, ds390)"
16371 other than the default bank zero).
16372 It should only be applied to
16375 \begin_inset LatexCommand index
16382 functions (see footnote below).
16383 This will in most circumstances make the generated ISR code more efficient
16384 since it will not have to save registers on the stack.
16387 \begin_layout Standard
16392 attribute will have no effect on the generated code for a
16396 function (but may occasionally be useful anyway
16400 \begin_layout Standard
16401 possible exception: if a function is called ONLY from 'interrupt' functions
16402 using a particular bank, it can be declared with the same 'using' attribute
16403 as the calling 'interrupt' functions.
16404 For instance, if you have several ISRs using bank one, and all of them
16405 call memcpy(), it might make sense to create a specialized version of memcpy()
16406 'using 1', since this would prevent the ISR from having to save bank zero
16407 to the stack on entry and switch to bank zero before calling the function
16416 (pending: Note, nowadays the
16420 attribute has an effect on
16424 the generated code for a
16435 \begin_layout Standard
16440 function using a non-zero bank will assume that it can trash that register
16441 bank, and will not save it.
16442 Since high-priority interrupts
16443 \begin_inset LatexCommand index
16449 \begin_inset LatexCommand index
16450 name "interrupt priority"
16454 can interrupt low-priority ones on the 8051 and friends, this means that
16455 if a high-priority ISR
16459 a particular bank occurs while processing a low-priority ISR
16463 the same bank, terrible and bad things can happen.
16464 To prevent this, no single register bank should be
16468 by both a high priority and a low priority ISR.
16469 This is probably most easily done by having all high priority ISRs use
16470 one bank and all low priority ISRs use another.
16471 If you have an ISR which can change priority at runtime, you're on your
16472 own: I suggest using the default bank zero and taking the small performance
16476 \begin_layout Standard
16477 It is most efficient if your ISR calls no other functions.
16478 If your ISR must call other functions, it is most efficient if those functions
16479 use the same bank as the ISR (see note 1 below); the next best is if the
16480 called functions use bank zero.
16481 It is very inefficient to call a function using a different, non-zero bank
16484 \begin_inset VSpace bigskip
16490 \begin_layout Section
16492 \begin_inset LatexCommand label
16493 name "sub:Startup-Code"
16498 \begin_inset LatexCommand index
16499 name "Startup code"
16506 \begin_layout Subsection
16507 MCS51/DS390 Startup Code
16510 \begin_layout Standard
16511 The compiler triggers the linker to link certain initialization modules
16512 from the runtime library
16513 \begin_inset LatexCommand index
16514 name "Runtime library"
16518 called crt<something>.
16519 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
16520 GSINIT5) is not linked unless the -
16526 \begin_layout Standard
16537 -xstack option is used.
16538 These modules are highly entangled by the use of special segments/areas,
16539 but a common layout is shown below:
16542 \begin_layout Verse
16550 \begin_layout Verse
16574 ljmp __sdcc_gsinit_startup
16577 \begin_layout Verse
16585 \begin_layout Verse
16597 .area GSINIT0 (CODE)
16599 __sdcc_gsinit_startup::
16609 mov sp,#__start__stack - 1
16612 \begin_layout Verse
16620 \begin_layout Verse
16632 .area GSINIT1 (CODE)
16634 __sdcc_init_xstack::
16636 ; Need to initialize in GSINIT1 in
16637 case the user's __sdcc_external_startup uses the xstack.
16647 mov __XPAGE,#(__start__x
16658 mov _spx,#__start__xstack
16661 \begin_layout Verse
16669 \begin_layout Verse
16681 .area GSINIT2 (CODE)
16691 lcall __sdcc_external_startup
16711 jz __sdcc_init_data
16722 __sdcc_program_startup
16727 \begin_layout Verse
16735 \begin_layout Verse
16747 .area GSINIT3 (CODE)
16800 mov r2,#((l_XINIT+255) >> 8)
16831 __XPAGE,#(s_XISEG >> 8)
16833 00001$:\InsetSpace ~
16897 00002$:\InsetSpace ~
16924 \begin_layout Verse
16932 \begin_layout Verse
16944 .area GSINIT4 (CODE)
16946 __mcs51_genRAMCLEAR::
16968 00004$:\InsetSpace ~
16982 ; _mcs51_genRAMCLEAR() end
16985 \begin_layout Verse
16993 \begin_layout Verse
17005 .area GSINIT4 (CODE)
17007 __mcs51_genXRAMCLEAR::
17068 mov __XPAGE,#(s_PSEG >> 8)
17080 00005$:\InsetSpace ~
17155 mov r1,#((l_XSEG + 255) >> 8)
17177 00007$:\InsetSpace ~
17214 \begin_layout Verse
17222 \begin_layout Verse
17234 .area GSINIT5 (CODE)
17236 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
17239 ; and __mcs51_genRAMCLEAR modifies _spx.
17249 mov __XPAGE,#(__start__x
17260 mov _spx,#__start__xstack
17263 \begin_layout Verse
17268 (application modules)
17271 \begin_layout Verse
17283 .area GSINIT (CODE)
17286 \begin_layout Verse
17294 \begin_layout Verse
17306 .area GSFINAL (CODE)
17316 ljmp __sdcc_program_startup
17318 ;---------------------------------
17319 -----------------------
17323 ;--------------------------------------------------
17346 __sdcc_program_startup:
17359 return from main will lock up
17372 \begin_layout Standard
17373 One of these modules (crtstart.asm) contains a call to the C routine
17375 _sdcc_external_startup()
17376 \begin_inset LatexCommand index
17377 name "\\_sdcc\\_external\\_startup()"
17383 at the start of the CODE area.
17384 This routine is also in the runtime library
17385 \begin_inset LatexCommand index
17386 name "Runtime library"
17390 and returns 0 by default.
17391 If this routine returns a non-zero value, the static & global variable
17392 initialization will be skipped and the function main will be invoked.
17393 Otherwise static & global variables will be initialized before the function
17397 _sdcc_external_startup()
17399 routine to your program to override the default if you need to setup hardware
17400 or perform some other critical operation prior to static & global variable
17402 \begin_inset LatexCommand index
17403 name "Variable initialization"
17408 On some mcs51 variants xdata
17409 \begin_inset LatexCommand index
17410 name "xdata (mcs51, ds390 storage class)"
17414 memory has to be explicitly enabled before it can be accessed or if the
17416 \begin_inset LatexCommand index
17421 needs to be disabled, this is the place to do it.
17422 The startup code clears all internal data memory, 256 bytes by default,
17423 but from 0 to n-1 if
17429 \begin_layout Standard
17439 \begin_inset LatexCommand index
17440 name "-\\/-iram-size <Value>"
17447 (recommended for Chipcon CC1010).
17450 \begin_layout Standard
17451 See also the compiler options
17457 \begin_layout Standard
17473 \begin_inset LatexCommand index
17474 name "-\\/-no-xinit-opt"
17484 \begin_layout Standard
17496 \begin_inset LatexCommand index
17497 name "-\\/-main-return"
17502 \begin_inset LatexCommand ref
17503 reference "sub:MCS51-variants"
17507 about MCS51-variants.
17512 \begin_layout Standard
17513 While these initialization modules are meant as generic startup code there
17514 might be the need for customization.
17515 Let's assume the return value of
17517 _sdcc_external_startup()
17523 should not be checked (or
17525 _sdcc_external_startup()
17527 should not be called at all).
17528 The recommended way would be to copy
17534 \begin_inset LatexCommand url
17535 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm"
17539 ) into the source directory, adapt it there, then assemble it with
17545 \begin_layout Standard
17546 \begin_inset Quotes sld
17550 \begin_inset Quotes srd
17553 are the assembler options used in
17554 \begin_inset LatexCommand url
17555 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup "
17566 and when linking your project explicitly specify
17571 As a bonus a listing of the relocated object file
17578 \begin_layout Standard
17579 \begin_inset VSpace bigskip
17585 \begin_layout Subsection
17589 \begin_layout Standard
17591 \begin_inset LatexCommand index
17596 startup code follows the same scheme as the MCS51 startup code.
17597 \begin_inset VSpace bigskip
17603 \begin_layout Subsection
17607 \begin_layout Standard
17609 \begin_inset LatexCommand index
17614 the startup code is inserted by linking with crt0.o which is generated from
17615 sdcc/device/lib/z80/crt0.s.
17616 If you need a different startup code you can use the compiler option
17625 \begin_layout Standard
17640 \begin_inset LatexCommand index
17641 name "-\\/-no-std-crt0"
17645 and provide your own crt0.o.
17647 \begin_inset VSpace bigskip
17653 \begin_layout Section
17654 Inline Assembler Code
17655 \begin_inset LatexCommand index
17656 name "Assembler routines"
17663 \begin_layout Subsection
17664 A Step by Step Introduction
17665 \begin_inset LatexCommand label
17666 name "sub:A-Step-by Assembler Introduction"
17673 \begin_layout Standard
17674 Starting from a small snippet of c-code this example shows for the MCS51
17675 how to use inline assembly, access variables, a function parameter and
17676 an array in xdata memory.
17677 The example uses an MCS51 here but is easily adapted for other architectures.
17678 This is a buffer routine which should be optimized:
17681 \begin_layout Verse
17685 unsigned char __far
17686 \begin_inset LatexCommand index
17687 name "far (storage class)"
17692 \begin_inset LatexCommand index
17693 name "\\_\\_far (storage class)"
17698 \begin_inset LatexCommand index
17704 \begin_inset LatexCommand index
17709 (0x7f00) buf[0x100];
17710 \begin_inset LatexCommand index
17711 name "Aligned array"
17717 unsigned char head, tail;\InsetSpace ~
17735 \begin_inset LatexCommand index
17788 \begin_inset LatexCommand ref
17789 reference "sub:Common-interrupt-pitfall-volatile"
17807 void to_buffer( unsigned char c )
17815 if( head != (unsigned char)(tail-1)
17828 \begin_inset LatexCommand index
17829 name "promotion to signed int"
17834 \begin_inset LatexCommand index
17835 name "type promotion"
17840 \begin_inset Marginal
17843 \begin_layout Standard
17862 buf[ head++ ] = c;\InsetSpace ~
17878 /* access to a 256 byte aligned array */
17883 \begin_layout Standard
17884 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
17885 then a corresponding buffer.asm file is generated.
17886 We define a new function
17890 in file buffer.c in which we cut and paste the generated code, removing
17891 unwanted comments and some ':'.
17893 \begin_inset Quotes sld
17901 \begin_inset Quotes srd
17905 \begin_inset Quotes sld
17913 \begin_inset Quotes srd
17920 \begin_layout Standard
17921 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
17922 and for C-99 compatibility, the double-underscore form (__asm and __endasm)
17924 The latter is also used in the library functions.
17929 to the beginning and the end of the function body:
17932 \begin_layout Verse
17936 /* With a cut and paste from the .asm file, we have something to start with.
17942 function is not yet OK! (registers aren't saved) */
17944 void to_buffer_asm(
17954 \begin_inset LatexCommand index
17960 \begin_inset LatexCommand index
17975 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
17987 \begin_inset LatexCommand index
17988 name "promotion to signed int"
17993 \begin_inset LatexCommand index
17994 name "type promotion"
18047 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
18048 \begin_inset LatexCommand index
18049 name "Aligned array"
18115 \begin_inset LatexCommand index
18121 \begin_inset LatexCommand index
18122 name "\\_\\_endasm"
18131 \begin_layout Standard
18132 The new file buffer.c should compile with only one warning about the unreferenced
18133 function argument 'c'.
18134 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
18135 (1) and finally have:
18138 \begin_layout Verse
18142 unsigned char __far __at(0x7f00) buf[0x100];
18144 unsigned char head, tail;
18155 void to_buffer( unsigned char c )
18164 head != (unsigned char)(tail-1) )
18193 c; // to avoid warning: unreferenced function argument
18200 \begin_inset LatexCommand index
18206 \begin_inset LatexCommand index
18221 ; save used registers here.
18232 ; If we were still using r2,r3 we would have to push them here.
18235 ; if( head != (unsigned char)(tail-1) )
18279 could do an ANL a,#0x0f here to use a smaller buffer (see below)
18315 a,dpl \InsetSpace ~
18322 ; dpl holds lower byte of function argument
18334 dpl,_head \InsetSpace ~
18337 ; buf is 0x100 byte aligned so head can be used directly
18380 ; we could do an ANL _head,#0x0f here to use a
18381 smaller buffer (see above)
18393 ; restore used registers here
18400 \begin_inset LatexCommand index
18406 \begin_inset LatexCommand index
18407 name "\\_\\_endasm"
18418 \begin_layout Standard
18419 The inline assembler code can contain any valid code understood by the assembler
18420 , this includes any assembler directives and comment lines.
18421 The assembler does not like some characters like ':' or ''' in comments.
18422 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
18423 \begin_inset LatexCommand index
18424 name "asXXXX (as-gbz80, as-hc08, asx8051, as-z80)"
18429 \begin_inset LatexCommand index
18430 name "Assembler documentation"
18435 \begin_inset LatexCommand url
18436 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html"
18444 \begin_layout Standard
18445 The compiler does not do any validation of the code within the
18448 \begin_inset LatexCommand index
18454 \begin_inset LatexCommand index
18463 \begin_inset LatexCommand index
18469 \begin_inset LatexCommand index
18470 name "\\_\\_endasm"
18479 Specifically it will not know which registers are used and thus register
18481 \begin_inset LatexCommand index
18486 has to be done manually.
18490 \begin_layout Standard
18491 It is recommended that each assembly instruction (including labels) be placed
18492 in a separate line (as the example shows).
18497 \begin_layout Standard
18509 \begin_inset LatexCommand index
18510 name "-\\/-peep-asm"
18516 command line option is used, the inline assembler code will be passed through
18517 the peephole optimizer
18518 \begin_inset LatexCommand index
18519 name "Peephole optimizer"
18524 There are only a few (if any) cases where this option makes sense, it might
18525 cause some unexpected changes in the inline assembler code.
18526 Please go through the peephole optimizer rules defined in file
18530 before using this option.
18533 \begin_layout Subsection
18535 \begin_inset LatexCommand label
18536 name "sub:Naked-Functions"
18541 \begin_inset LatexCommand index
18542 name "Naked functions"
18549 \begin_layout Standard
18550 A special keyword may be associated with a function declaring it as
18553 \begin_inset LatexCommand index
18559 \begin_inset LatexCommand index
18571 function modifier attribute prevents the compiler from generating prologue
18572 \begin_inset LatexCommand index
18573 name "function prologue"
18578 \begin_inset LatexCommand index
18579 name "function epilogue"
18583 code for that function.
18584 This means that the user is entirely responsible for such things as saving
18585 any registers that may need to be preserved, selecting the proper register
18586 bank, generating the
18590 instruction at the end, etc.
18591 Practically, this means that the contents of the function must be written
18592 in inline assembler.
18593 This is particularly useful for interrupt functions, which can have a large
18594 (and often unnecessary) prologue/epilogue.
18595 For example, compare the code generated by these two functions:
18598 \begin_layout Verse
18602 \begin_inset LatexCommand index
18607 data unsigned char counter;
18611 void simpleInterrupt(void) __interrupt
18612 \begin_inset LatexCommand index
18618 \begin_inset LatexCommand index
18619 name "\\_\\_interrupt"
18637 void nakedInterrupt(void) __interrupt (2) __naked
18646 \begin_inset LatexCommand index
18652 \begin_inset LatexCommand index
18670 _counter ; does not change flags, no need to save psw
18683 include ret or reti in _naked function.
18690 \begin_inset LatexCommand index
18696 \begin_inset LatexCommand index
18697 name "\\_\\_endasm"
18706 \begin_layout Standard
18707 For an 8051 target, the generated simpleInterrupt looks like:
18710 \begin_layout Verse
18723 example, recent versions of SDCC generate
18735 code for simpleInterrupt() and nakedInterrupt()!
18876 \begin_layout Standard
18877 whereas nakedInterrupt looks like:
18880 \begin_layout Verse
18893 _counter ; does not change flags, no need to save psw
18912 MUST explicitly include ret or reti in _naked function
18915 \begin_layout Standard
18916 The related directive #pragma exclude
18917 \begin_inset LatexCommand index
18918 name "\\#pragma exclude"
18922 allows a more fine grained control over pushing & popping
18923 \begin_inset LatexCommand index
18931 \begin_layout Standard
18932 While there is nothing preventing you from writing C code inside a
18936 function, there are many ways to shoot yourself in the foot doing this,
18937 and it is recommended that you stick to inline assembler.
18940 \begin_layout Subsection
18941 Use of Labels within Inline Assembler
18944 \begin_layout Standard
18945 SDCC allows the use of in-line assembler with a few restrictions regarding
18947 All labels defined within inline assembler code have to be of the form
18952 where nnnnn is a number less than 100 (which implies a limit of utmost
18953 100 inline assembler labels
18964 \begin_layout Standard
18965 This is a slightly more stringent rule than absolutely necessary, but stays
18966 always on the safe side.
18967 Labels in the form of nnnnn$ are local labels in the assembler, locality
18968 of which is confined within two labels of the standard form.
18969 The compiler uses the same form for labels within a function (but starting
18970 from nnnnn=00100); and places always a standard label at the beginning
18971 of a function, thus limiting the locality of labels within the scope of
18973 So, if the inline assembler part would be embedded into C-code, an improperly
18974 placed non-local label in the assembler would break up the reference space
18975 for labels created by the compiler for the C-code, leading to an assembling
18979 \begin_layout Standard
18980 The numeric part of local labels does not need to have 5 digits (although
18981 this is the form of labels output by the compiler), any valid integer will
18983 Please refer to the assemblers documentation for further details.
18991 \begin_layout Verse
18995 \begin_inset LatexCommand index
19001 \begin_inset LatexCommand index
19032 \begin_inset LatexCommand index
19038 \begin_inset LatexCommand index
19039 name "\\_\\_endasm"
19046 \begin_layout Standard
19047 Inline assembler code cannot reference any C-labels, however it can reference
19049 \begin_inset LatexCommand index
19054 defined by the inline assembler, e.g.:
19057 \begin_layout Verse
19080 ; some assembler code
19101 /* some more c code */
19103 clabel:\InsetSpace ~
19105 /* inline assembler cannot reference this
19110 \begin_layout Standard
19115 is translated by the compiler into a local label, so the locality of labels
19116 within the function is not broken.
19133 0003$: ;label (can be referenced by inline assembler only)
19140 \begin_inset LatexCommand index
19146 \begin_inset LatexCommand index
19147 name "\\_\\_endasm"
19157 /* some more c code */
19162 \begin_layout Standard
19163 In other words inline assembly code can access labels defined in inline
19164 assembly within the scope of the function.
19165 The same goes the other way, i.e.
19166 labels defines in inline assembly can not be accessed by C statements.
19169 \begin_layout Section
19170 Interfacing with Assembler Code
19171 \begin_inset LatexCommand index
19172 name "Assembler routines"
19179 \begin_layout Subsection
19180 Global Registers used for Parameter Passing
19181 \begin_inset LatexCommand index
19182 name "Parameter passing"
19189 \begin_layout Standard
19190 The compiler always uses the global registers
19193 \begin_inset LatexCommand index
19194 name "DPTR, DPH, DPL"
19199 \begin_inset LatexCommand index
19205 \begin_inset LatexCommand index
19206 name "B (mcs51, ds390 register)"
19215 \begin_inset LatexCommand index
19216 name "ACC (mcs51, ds390 register)"
19222 to pass the first (non-bit) parameter to a function, and also to pass the
19224 \begin_inset LatexCommand index
19225 name "return value"
19229 of function; according to the following scheme: one byte return value in
19234 , two byte value in
19243 three byte values (generic pointers) in
19255 , and four byte values in
19273 \begin_inset LatexCommand index
19274 name "generic pointer"
19278 contain type of accessed memory in
19299 \begin_inset Note Note
19302 \begin_layout Standard
19303 This might not be the case of certain memory models (medium???)
19311 \begin_layout Standard
19312 The second parameter onwards is either allocated on the stack (for reentrant
19317 \begin_layout Standard
19326 -stack-auto is used) or in data/xdata memory (depending on the memory model).
19329 \begin_layout Standard
19330 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
19331 space for reentrant functions or allocated directly in bit memory otherwise.
19334 \begin_layout Standard
19335 Functions (with two or more parameters or bit parameters) that are called
19336 through function pointers
19337 \begin_inset LatexCommand index
19338 name "function pointers"
19342 must therefor be reentrant so the compiler knows how to pass the parameters.
19345 \begin_layout Subsection
19349 \begin_layout Standard
19350 Unless the called function is declared as
19355 \begin_inset LatexCommand index
19364 \begin_layout Standard
19374 \begin_inset LatexCommand index
19375 name "-\\/-callee-saves"
19383 \begin_layout Standard
19392 -all-callee-saves command line option or the corresponding callee_saves
19393 pragma are used, the caller will save the registers (
19397 ) around the call, so the called function can destroy they content freely.
19400 \begin_layout Standard
19401 If the called function is not declared as
19405 , the caller will swap register banks around the call, if caller and callee
19406 use different register banks (having them defined by the
19414 \begin_layout Standard
19415 The called function can also use
19431 observing that they are used for parameter/return value passing.
19434 \begin_layout Subsection
19435 Assembler Routine (non-reentrant)
19438 \begin_layout Standard
19439 In the following example
19440 \begin_inset LatexCommand index
19446 \begin_inset LatexCommand index
19447 name "Assembler routines (non-reentrant)"
19451 the function c_func calls an assembler routine asm_func, which takes two
19453 \begin_inset LatexCommand index
19454 name "function parameter"
19461 \begin_layout Verse
19464 extern int asm_func(unsigned char, unsigned char);
19468 int c_func (unsigned char
19469 i, unsigned char j)
19477 return asm_func(i,j);
19491 return c_func(10,9);
19496 \begin_layout Standard
19497 The corresponding assembler function is:
19500 \begin_layout Verse
19503 .globl _asm_func_PARM_2
19605 \begin_inset LatexCommand index
19606 name "DPTR, DPH, DPL"
19623 \begin_layout Standard
19624 The parameter naming convention is _<function_name>_PARM_<n>, where n is
19625 the parameter number starting from 1, and counting from the left.
19626 The first parameter is passed in
19642 according to the description above.
19643 The variable name for the second parameter will be _<function_name>_PARM_2.
19648 ble the assembler routine with the following command:
19655 asx8051 -losg asmfunc.asm
19662 Then compile and link the assembler routine to the C source file with the
19670 sdcc cfunc.c asmfunc.rel
19673 \begin_layout Subsection
19674 Assembler Routine (reentrant)
19677 \begin_layout Standard
19679 \begin_inset LatexCommand index
19685 \begin_inset LatexCommand index
19686 name "Assembler routines (reentrant)"
19690 the second parameter
19691 \begin_inset LatexCommand index
19692 name "function parameter"
19696 onwards will be passed on the stack, the parameters are pushed from right
19698 before the call the second leftmost parameter will be on the top of the
19699 stack (the leftmost parameter is passed in registers).
19700 Here is an example:
19703 \begin_layout Verse
19706 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
19711 c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
19720 return asm_func(i,j,k);
19734 return c_func(10,9,8);
19739 \begin_layout Standard
19740 The corresponding (unoptimized) assembler routine is:
19743 \begin_layout Verse
19763 _bp,sp\InsetSpace ~
19769 ;stack contains: _bp, return
19770 address, second parameter, third parameter
19794 a,#0xfd\InsetSpace ~
19800 pointer to the second parameter
19824 a,#0xfc\InsetSpace ~
19830 to the rightmost parameter
19871 result (= sum of all three parameters)
19886 ;return value goes into dptr
19920 \begin_layout Standard
19921 The compiling and linking procedure remains the same, however note the extra
19922 entry & exit linkage required for the assembler code, _bp is the stack
19923 frame pointer and is used to compute the offset into the stack for parameters
19924 and local variables.
19925 \begin_inset VSpace bigskip
19931 \begin_layout Section
19933 \begin_inset LatexCommand index
19934 name "int (16 bit)"
19939 \begin_inset LatexCommand index
19940 name "long (32 bit)"
19947 \begin_layout Standard
19948 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
19949 multiplication and modulus operations are implemented by support routines.
19950 These support routines are all developed in ANSI-C to facilitate porting
19951 to other MCUs, although some model specific assembler optimizations are
19953 The following files contain the described routines, all of them can be
19954 found in <installdir>/share/sdcc/lib.
19959 \begin_layout Standard
19961 \begin_inset Tabular
19962 <lyxtabular version="3" rows="11" columns="2">
19964 <column alignment="left" valignment="top" leftline="true" width="0">
19965 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19966 <row topline="true" bottomline="true">
19967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19970 \begin_layout Standard
19978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19981 \begin_layout Standard
19990 <row topline="true">
19991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19994 \begin_layout Standard
20000 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20003 \begin_layout Standard
20004 16 bit multiplication
20010 <row topline="true">
20011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20014 \begin_layout Standard
20020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20023 \begin_layout Standard
20024 signed 16 bit division (calls _divuint)
20030 <row topline="true">
20031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20034 \begin_layout Standard
20040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20043 \begin_layout Standard
20044 unsigned 16 bit division
20050 <row topline="true">
20051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20054 \begin_layout Standard
20060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20063 \begin_layout Standard
20064 signed 16 bit modulus (calls _moduint)
20070 <row topline="true">
20071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20074 \begin_layout Standard
20080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20083 \begin_layout Standard
20084 unsigned 16 bit modulus
20090 <row topline="true">
20091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20094 \begin_layout Standard
20100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20103 \begin_layout Standard
20104 32 bit multiplication
20110 <row topline="true">
20111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20114 \begin_layout Standard
20120 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20123 \begin_layout Standard
20124 signed 32 division (calls _divulong)
20130 <row topline="true">
20131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20134 \begin_layout Standard
20140 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20143 \begin_layout Standard
20144 unsigned 32 division
20150 <row topline="true">
20151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20154 \begin_layout Standard
20160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20163 \begin_layout Standard
20164 signed 32 bit modulus (calls _modulong)
20170 <row topline="true" bottomline="true">
20171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20174 \begin_layout Standard
20180 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20183 \begin_layout Standard
20184 unsigned 32 bit modulus
20199 \begin_layout Standard
20200 Since they are compiled as
20205 \begin_inset LatexCommand index
20211 \begin_inset LatexCommand index
20216 service routines should not do any of the above operations.
20217 If this is unavoidable then the above routines will need to be compiled
20224 \begin_layout Standard
20234 \begin_inset LatexCommand index
20235 name "-\\/-stack-auto"
20241 option, after which the source program will have to be compiled with
20247 \begin_layout Standard
20257 \begin_inset LatexCommand index
20258 name "-\\/-int-long-reent"
20265 Notice that you don't have to call these routines directly.
20266 The compiler will use them automatically every time an integer operation
20270 \begin_layout Section
20271 Floating Point Support
20272 \begin_inset LatexCommand index
20273 name "Floating point support"
20280 \begin_layout Standard
20281 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
20282 The floating point support routines are derived from gcc's floatlib.c and
20283 consist of the following routines:
20288 \begin_layout Standard
20292 \begin_inset Tabular
20293 <lyxtabular version="3" rows="17" columns="2">
20295 <column alignment="left" valignment="top" leftline="true" width="0">
20296 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
20297 <row topline="true" bottomline="true">
20298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20301 \begin_layout Standard
20316 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20319 \begin_layout Standard
20326 <row topline="true">
20327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20330 \begin_layout Standard
20345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20348 \begin_layout Standard
20358 add floating point numbers
20364 <row topline="true">
20365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20368 \begin_layout Standard
20383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20386 \begin_layout Standard
20396 subtract floating point numbers
20402 <row topline="true">
20403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20406 \begin_layout Standard
20421 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20424 \begin_layout Standard
20434 divide floating point numbers
20440 <row topline="true">
20441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20444 \begin_layout Standard
20459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20462 \begin_layout Standard
20472 multiply floating point numbers
20478 <row topline="true">
20479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20482 \begin_layout Standard
20497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20500 \begin_layout Standard
20510 convert floating point to unsigned char
20516 <row topline="true">
20517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20520 \begin_layout Standard
20535 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20538 \begin_layout Standard
20548 convert floating point to signed char
20554 <row topline="true">
20555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20558 \begin_layout Standard
20573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20576 \begin_layout Standard
20586 convert floating point to unsigned int
20592 <row topline="true">
20593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20596 \begin_layout Standard
20611 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20614 \begin_layout Standard
20624 convert floating point to signed int
20630 <row topline="true">
20631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20634 \begin_layout Standard
20657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20660 \begin_layout Standard
20670 convert floating point to unsigned long
20676 <row topline="true">
20677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20680 \begin_layout Standard
20695 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20698 \begin_layout Standard
20708 convert floating point to signed long
20714 <row topline="true">
20715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20718 \begin_layout Standard
20733 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20736 \begin_layout Standard
20746 convert unsigned char to floating point
20752 <row topline="true">
20753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20756 \begin_layout Standard
20771 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20774 \begin_layout Standard
20784 convert char to floating point number
20790 <row topline="true">
20791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20794 \begin_layout Standard
20809 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20812 \begin_layout Standard
20822 convert unsigned int to floating point
20828 <row topline="true">
20829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20832 \begin_layout Standard
20847 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20850 \begin_layout Standard
20860 convert int to floating point numbers
20866 <row topline="true">
20867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20870 \begin_layout Standard
20885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20888 \begin_layout Standard
20898 convert unsigned long to floating point number
20904 <row topline="true" bottomline="true">
20905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20908 \begin_layout Standard
20923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20926 \begin_layout Standard
20936 convert long to floating point number
20951 \begin_layout Standard
20952 These support routines are developed in ANSI-C so there is room for space
20953 and speed improvement
20957 \begin_layout Standard
20958 These floating point routines (
20962 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
20969 Note if all these routines are used simultaneously the data space might
20971 For serious floating point usage the large model might be needed.
20972 Also notice that you don't have to call this routines directly.
20973 The compiler will use them automatically every time a floating point operation
20975 \begin_inset VSpace bigskip
20981 \begin_layout Section
20983 \begin_inset LatexCommand index
20991 \begin_layout Standard
20994 <pending: this is messy and incomplete - a little more information is in
20995 sdcc/doc/libdoc.txt
21000 \begin_layout Subsection
21001 Compiler support routines (_gptrget, _mulint etc.)
21004 \begin_layout Subsection
21005 Stdclib functions (puts, printf, strcat etc.)
21008 \begin_layout Subsubsection
21012 \begin_layout Paragraph
21013 getchar(), putchar()
21016 \begin_layout Standard
21017 \begin_inset LatexCommand index
21022 As usual on embedded systems you have to provide your own
21025 \begin_inset LatexCommand index
21035 \begin_inset LatexCommand index
21043 SDCC does not know whether the system connects to a serial line with or
21044 without handshake, LCD, keyboard or other device.
21058 You'll find examples for serial routines f.e.
21059 in sdcc/device/lib.
21060 For the mcs51 this minimalistic polling
21064 routine might be a start:
21067 \begin_layout Verse
21070 void putchar (char c) {
21076 while (!TI)\InsetSpace ~
21079 /* assumes UART is initialized */
21107 \begin_layout Paragraph
21111 \begin_layout Standard
21115 \begin_inset LatexCommand index
21126 does not support float
21127 \begin_inset LatexCommand index
21128 name "Floating point support"
21132 (except on ds390), only <NO FLOAT>
21133 \begin_inset LatexCommand index
21139 \begin_inset LatexCommand index
21140 name "printf floating point support"
21144 will be printed instead of the value.
21145 To enable floating point output, recompile it with the option
21151 \begin_layout Standard
21161 \begin_inset LatexCommand index
21162 name "USE\\_FLOATS"
21168 on the command line.
21175 \begin_layout Standard
21185 \begin_inset LatexCommand index
21186 name "-\\/-model-large"
21192 for the mcs51 port, since this uses a lot of memory.
21193 To enable float support for the pic16 targets, see
21194 \begin_inset LatexCommand ref
21195 reference "sub:pic16Libraries"
21202 \begin_layout Standard
21203 If you're short on code memory you might want to use
21206 \begin_inset LatexCommand index
21207 name "printf\\_small()"
21222 For the mcs51 there additionally are assembly versions
21225 \begin_inset LatexCommand index
21226 name "printf\\_tiny() (mcs51)"
21232 (subset of printf using less than 270 bytes) and
21235 \begin_inset LatexCommand index
21236 name "printf\\_fast() (mcs51)"
21245 \begin_inset LatexCommand index
21246 name "printf\\_fast\\_f() (mcs51)"
21252 (floating-point aware version of printf_fast) which should fit the requirements
21253 of many embedded systems (printf_fast() can be customized by unsetting
21258 support long variables and field widths).
21259 Be sure to use only one of these printf options within a project.
21264 \begin_layout Standard
21265 Feature matrix of different
21272 \begin_layout Standard
21273 \begin_inset Tabular
21274 <lyxtabular version="3" rows="14" columns="7">
21275 <features islongtable="true">
21276 <column alignment="left" valignment="middle" leftline="true" width="14col%">
21277 <column alignment="center" valignment="top" leftline="true" width="0">
21278 <column alignment="center" valignment="top" leftline="true" width="12col%">
21279 <column alignment="center" valignment="top" leftline="true" width="10col%">
21280 <column alignment="center" valignment="top" leftline="true" width="0">
21281 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
21282 <column alignment="center" valignment="top" rightline="true" width="0">
21283 <row topline="true" bottomline="true" endhead="true">
21284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21287 \begin_layout Standard
21296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21299 \begin_layout Standard
21301 \begin_inset LatexCommand index
21311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21314 \begin_layout Standard
21322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21325 \begin_layout Standard
21331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21334 \begin_layout Standard
21340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21343 \begin_layout Standard
21349 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21352 \begin_layout Standard
21359 <row topline="true" endhead="true">
21360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21363 \begin_layout Standard
21369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21372 \begin_layout Standard
21380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21383 \begin_layout Standard
21391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21394 \begin_layout Standard
21402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21405 \begin_layout Standard
21413 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21416 \begin_layout Standard
21424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21427 \begin_layout Standard
21436 <row topline="true" endhead="true">
21437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21440 \begin_layout Standard
21441 \begin_inset Quotes sld
21445 \begin_inset Quotes srd
21451 \begin_layout Standard
21457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21460 \begin_layout Standard
21466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21469 \begin_layout Standard
21475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21478 \begin_layout Standard
21484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21487 \begin_layout Standard
21493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21496 \begin_layout Standard
21502 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21505 \begin_layout Standard
21512 <row topline="true" endhead="true">
21513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21516 \begin_layout Standard
21520 \begin_layout Standard
21526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21529 \begin_layout Standard
21535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21538 \begin_layout Standard
21544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21547 \begin_layout Standard
21548 0.45k / 0.47k (+ _ltoa)
21553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21556 \begin_layout Standard
21562 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21565 \begin_layout Standard
21571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21574 \begin_layout Standard
21581 <row topline="true">
21582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21585 \begin_layout Standard
21591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21594 \begin_layout Standard
21604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21607 \begin_layout Standard
21654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21657 \begin_layout Standard
21696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21699 \begin_layout Standard
21705 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21708 \begin_layout Standard
21714 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21717 \begin_layout Standard
21724 <row topline="true">
21725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21728 \begin_layout Standard
21729 long (32 bit) support
21734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21737 \begin_layout Standard
21743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21746 \begin_layout Standard
21752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21755 \begin_layout Standard
21761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21764 \begin_layout Standard
21770 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21773 \begin_layout Standard
21788 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21791 \begin_layout Standard
21798 <row topline="true">
21799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21802 \begin_layout Standard
21803 byte arguments on stack
21808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21811 \begin_layout Standard
21817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21820 \begin_layout Standard
21826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21829 \begin_layout Standard
21835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21838 \begin_layout Standard
21844 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21847 \begin_layout Standard
21853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21856 \begin_layout Standard
21863 <row topline="true">
21864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21867 \begin_layout Standard
21869 \begin_inset LatexCommand index
21870 name "Floating point support"
21879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21882 \begin_layout Standard
21888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21891 \begin_layout Standard
21897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21900 \begin_layout Standard
21906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21909 \begin_layout Standard
21915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21918 \begin_layout Standard
21923 \begin_layout Standard
21924 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
21934 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21937 \begin_layout Standard
21944 <row topline="true">
21945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21948 \begin_layout Standard
21949 float formats %e %g
21954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21957 \begin_layout Standard
21963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21966 \begin_layout Standard
21972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21975 \begin_layout Standard
21981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21984 \begin_layout Standard
21990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21993 \begin_layout Standard
21999 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22002 \begin_layout Standard
22009 <row topline="true" bottomline="true">
22010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22013 \begin_layout Standard
22019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22022 \begin_layout Standard
22028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22031 \begin_layout Standard
22037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22040 \begin_layout Standard
22046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22049 \begin_layout Standard
22055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22058 \begin_layout Standard
22064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22067 \begin_layout Standard
22074 <row bottomline="true">
22075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22078 \begin_layout Standard
22083 \begin_layout Standard
22084 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
22088 n'); standard 8051 @ 22.1184 MHz, empty putchar()
22096 \begin_layout Standard
22102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22105 \begin_layout Standard
22111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22114 \begin_layout Standard
22120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22123 \begin_layout Standard
22129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22132 \begin_layout Standard
22138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22141 \begin_layout Standard
22147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22150 \begin_layout Standard
22157 <row bottomline="true">
22158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22161 \begin_layout Standard
22166 \begin_layout Standard
22167 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
22176 \begin_layout Standard
22182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22185 \begin_layout Standard
22191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22194 \begin_layout Standard
22200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22203 \begin_layout Standard
22209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22212 \begin_layout Standard
22218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22221 \begin_layout Standard
22227 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22230 \begin_layout Standard
22235 \begin_layout Standard
22236 printf_tiny integer speed is data dependent, worst case is 0.33 ms
22247 <row bottomline="true">
22248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22251 \begin_layout Standard
22256 \begin_layout Standard
22257 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
22266 \begin_layout Standard
22272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22275 \begin_layout Standard
22281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22284 \begin_layout Standard
22290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22293 \begin_layout Standard
22299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22302 \begin_layout Standard
22308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22311 \begin_layout Standard
22317 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22320 \begin_layout Standard
22327 <row bottomline="true">
22328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22331 \begin_layout Standard
22336 \begin_layout Standard
22337 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
22346 \begin_layout Standard
22352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22355 \begin_layout Standard
22361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22364 \begin_layout Standard
22370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22373 \begin_layout Standard
22379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22382 \begin_layout Standard
22388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22391 \begin_layout Standard
22397 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22400 \begin_layout Standard
22414 \begin_layout Subsubsection
22416 \begin_inset LatexCommand index
22424 \begin_layout Standard
22425 As of SDCC 2.6.2 you no longer need to call an initialization routine before
22426 using dynamic memory allocation
22427 \begin_inset LatexCommand index
22428 name "dynamic memory allocation (malloc)"
22433 \begin_inset LatexCommand index
22434 name "heap (malloc)"
22438 space of 1024 bytes is provided for malloc to allocate memory from.
22439 If you need a different heap size you need to recompile _heap.c with the
22440 required size defined in HEAP_SIZE.
22441 It is recommended to make a copy of this file into your project directory
22442 and compile it there with:
22445 \begin_layout Verse
22448 sdcc -c _heap.c -D HEAD_SIZE=2048
22451 \begin_layout Standard
22452 And then link it with:
22455 \begin_layout Verse
22458 sdcc main.rel _heap.rel
22461 \begin_layout Subsection
22462 Math functions (sinf, powf, sqrtf etc.)
22465 \begin_layout Subsubsection
22469 \begin_layout Standard
22470 See definitions in file <math.h>.
22473 \begin_layout Subsection
22477 \begin_layout Standard
22479 \begin_inset LatexCommand index
22484 included in SDCC should have a license at least as liberal as the GNU Lesser
22485 General Public License
22486 \begin_inset LatexCommand index
22487 name "GNU Lesser General Public License, LGPL"
22498 \begin_layout Standard
22499 \begin_inset Note Note
22502 \begin_layout Standard
22503 license statements for the libraries are missing.
22504 sdcc/device/lib/ser_ir.c
22507 \begin_layout Standard
22509 come with a GPL (as opposed to LGPL) License - this will not be liberal
22510 enough for many embedded programmers.
22518 \begin_layout Standard
22519 If you have ported some library or want to share experience about some code
22521 falls into any of these categories Busses (I
22522 \begin_inset Formula $^{\textrm{2}}$
22525 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
22526 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
22527 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
22528 \begin_inset LatexCommand url
22529 target "http://sourceforge.net/mail/?group_id=599"
22534 would certainly like to hear about it.
22537 \begin_layout Standard
22538 Programmers coding for embedded systems are not especially famous for being
22539 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
22540 e these references are very valuable.
22541 Let's help to create a climate where information is shared.
22542 \begin_inset VSpace bigskip
22548 \begin_layout Section
22552 \begin_layout Subsection
22553 MCS51 Memory Models
22554 \begin_inset LatexCommand index
22555 name "Memory model"
22560 \begin_inset LatexCommand index
22561 name "MCS51 memory model"
22568 \begin_layout Subsubsection
22569 Small, Medium and Large
22572 \begin_layout Standard
22573 SDCC allows three memory models for MCS51 code,
22582 Modules compiled with different memory models should
22586 be combined together or the results would be unpredictable.
22587 The library routines supplied with the compiler are compiled as small,
22589 The compiled library modules are contained in separate directories as small,
22590 medium and large so that you can link to the appropriate set.
22593 \begin_layout Standard
22594 When the medium or large model is used all variables declared without a
22595 storage class will be allocated into the external ram, this includes all
22596 parameters and local variables (for non-reentrant
22597 \begin_inset LatexCommand index
22603 When the small model is used variables without storage class are allocated
22604 in the internal ram.
22607 \begin_layout Standard
22608 Judicious usage of the processor specific storage classes
22609 \begin_inset LatexCommand index
22610 name "Storage class"
22614 and the 'reentrant' function type will yield much more efficient code,
22615 than using the large model.
22616 Several optimizations are disabled when the program is compiled using the
22617 large model, it is therefore recommended that the small model be used unless
22618 absolutely required.
22621 \begin_layout Subsubsection
22623 \begin_inset LatexCommand label
22624 name "sub:External-Stack"
22629 \begin_inset LatexCommand index
22635 \begin_inset LatexCommand index
22636 name "External stack (mcs51)"
22643 \begin_layout Standard
22644 The external stack (-
22648 \begin_layout Standard
22658 \begin_inset LatexCommand index
22663 ) is located in pdata
22664 \begin_inset LatexCommand index
22665 name "pdata (mcs51, ds390 storage class)"
22669 memory (usually at the start of the external ram segment) and uses all
22670 unused space in pdata (max.
22676 \begin_layout Standard
22685 -xstack option is used to compile the program, the parameters and local
22687 \begin_inset LatexCommand index
22688 name "local variables"
22692 of all reentrant functions are allocated in this area.
22693 This option is provided for programs with large stack space requirements.
22694 When used with the -
22698 \begin_layout Standard
22708 \begin_inset LatexCommand index
22709 name "-\\/-stack-auto"
22713 option, all parameters and local variables are allocated on the external
22714 stack (note: support libraries will need to be recompiled with the same
22716 There is a predefined target in the library makefile).
22719 \begin_layout Standard
22720 The compiler outputs the higher order address byte of the external ram segment
22722 \begin_inset LatexCommand index
22723 name "P2 (mcs51 sfr)"
22728 \begin_inset LatexCommand ref
22729 reference "sub:MCS51-variants"
22733 ), therefore when using the External Stack option, this port
22737 be used by the application program.
22740 \begin_layout Subsection
22742 \begin_inset LatexCommand index
22743 name "Memory model"
22748 \begin_inset LatexCommand index
22749 name "DS390 memory model"
22756 \begin_layout Standard
22757 The only model supported is Flat 24
22758 \begin_inset LatexCommand index
22759 name "Flat 24 (DS390 memory model)"
22764 This generates code for the 24 bit contiguous addressing mode of the Dallas
22766 In this mode, up to four meg of external RAM or code space can be directly
22768 See the data sheets at www.dalsemi.com for further information on this part.
22773 that the compiler does not generate any code to place the processor into
22774 24 bitmode (although
22778 in the ds390 libraries will do that for you).
22784 \begin_inset LatexCommand index
22785 name "Tinibios (DS390)"
22789 , the boot loader or similar code must ensure that the processor is in 24
22790 bit contiguous addressing mode before calling the SDCC startup code.
22801 \begin_layout Standard
22812 option, variables will by default be placed into the XDATA segment.
22817 Segments may be placed anywhere in the 4 meg address space using the usual
22822 \begin_layout Standard
22832 Note that if any segments are located above 64K, the -r flag must be passed
22833 to the linker to generate the proper segment relocations, and the Intel
22834 HEX output format must be used.
22835 The -r flag can be passed to the linker by using the option
22839 on the SDCC command line.
22840 However, currently the linker can not handle code segments > 64k.
22843 \begin_layout Section
22845 \begin_inset LatexCommand label
22851 \begin_inset LatexCommand index
22859 \begin_layout Standard
22860 Pragmas are used to turn on and/or off certain compiler options.
22861 Some of them are closely related to corresponding command-line options
22863 \begin_inset LatexCommand vref
22864 reference "sec:Command-Line-Options"
22870 Pragmas should be placed before and/or after a function, placing pragmas
22871 inside a function body could have unpredictable results.
22876 following #pragma directives:
22879 \begin_layout Itemize
22885 \begin_inset LatexCommand index
22886 name "\\#pragma save"
22890 - this will save most current options to the save/restore stack.
22891 See #pragma\InsetSpace ~
22895 \begin_layout Itemize
22901 \begin_inset LatexCommand index
22902 name "\\#pragma restore"
22906 - will restore saved options from the last save.
22907 saves & restores can be nested.
22908 SDCC uses a save/restore stack: save pushes current options to the stack,
22909 restore pulls current options from the stack.
22910 See #pragma\InsetSpace ~
22916 \begin_layout Itemize
22922 \begin_inset LatexCommand index
22923 name "\\#pragma callee\\_saves"
22928 \begin_inset LatexCommand index
22929 name "function prologue"
22933 function1[,function2[,function3...]]
22934 \begin_inset LatexCommand label
22935 name "ite:callee_saves-function1[,function2[,function3...]]--"
22939 - The compiler by default uses a caller saves convention for register saving
22940 across function calls, however this can cause unnecessary register pushing
22942 \begin_inset LatexCommand index
22947 when calling small functions from larger functions.
22948 This option can be used to switch off the register saving convention for
22949 the function names specified.
22950 The compiler will not save registers when calling these functions, extra
22951 code need to be manually inserted at the entry and exit for these functions
22952 to save and restore the registers used by these functions, this can SUBSTANTIAL
22953 LY reduce code and improve run time performance of the generated code.
22954 In the future the compiler (with inter procedural analysis) may be able
22955 to determine the appropriate scheme to use for each function call.
22960 \begin_layout Standard
22969 -callee-saves command line option is used (see page
22970 \begin_inset LatexCommand vpageref
22971 reference "lyx:--callee-saves-function1[,function2][,function3]..."
22975 ), the function names specified in #pragma\InsetSpace ~
22977 \begin_inset LatexCommand index
22978 name "\\#pragma callee\\_saves"
22982 is appended to the list of functions specified in the command line.
22985 \begin_layout Itemize
22991 \begin_inset LatexCommand index
22992 name "\\#pragma exclude"
22996 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
22997 of pairs of push/pop
22998 \begin_inset LatexCommand index
23008 \begin_inset LatexCommand index
23022 The directive should be placed immediately before the ISR function definition
23023 and it affects ALL ISR functions following it.
23024 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
23025 exclude\InsetSpace ~
23027 \begin_inset LatexCommand index
23028 name "\\#pragma exclude"
23033 See also the related keyword _naked
23034 \begin_inset LatexCommand index
23040 \begin_inset LatexCommand index
23048 \begin_layout Itemize
23054 \begin_inset LatexCommand index
23060 \begin_inset LatexCommand index
23061 name "\\#pragma less\\_pedantic"
23066 \begin_inset LatexCommand label
23067 name "ite:less_pedantic"
23071 - the compiler will not warn you anymore for obvious mistakes, you're on
23073 See also the command line option -
23077 \begin_layout Standard
23087 \begin_inset LatexCommand vpageref
23088 reference "lyx:--less-pedantic"
23095 More specifically, the following warnings will be disabled:
23097 comparison is always [true/false] due to limited range of data type
23101 overflow in implicit constant conversion
23103 (158); [the (in)famous]
23105 conditional flow changed by optimizer: so said EVELYN the modified DOG
23109 function '[function name]' must return value
23114 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
23115 level) are disabled, too, namely:
23118 \begin_inset Note Note
23121 \begin_layout Standard
23122 dunno what comes here - this warning appears to be unused altogether
23131 [left/right] shifting more than size of object changed to zero
23139 integer overflow in expression
23143 unmatched #pragma save and #pragma restore
23147 comparison of 'signed char' with 'unsigned char' requires promotion to int
23151 ISO C90 does not support flexible array members
23155 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
23159 \begin_inset Note Note
23162 \begin_layout Standard
23163 appears to be always blank - what was supposed to be here?
23172 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
23173 complexity [number]
23178 \begin_layout Itemize
23184 \begin_inset LatexCommand index
23185 name "\\#pragma disable\\_warning"
23189 - the compiler will not warn you anymore about warning number <nnnn>.
23192 \begin_layout Itemize
23198 \begin_inset LatexCommand index
23199 name "\\#pragma nogcse"
23203 - will stop global common subexpression elimination.
23206 \begin_layout Itemize
23212 \begin_inset LatexCommand index
23213 name "\\#pragma noinduction"
23217 - will stop loop induction optimizations.
23220 \begin_layout Itemize
23226 \begin_inset LatexCommand index
23227 name "\\#pragma noinvariant"
23231 - will not do loop invariant optimizations.
23232 For more details see Loop Invariants in section
23233 \begin_inset LatexCommand ref
23234 reference "sub:Loop-Optimizations"
23241 \begin_layout Itemize
23247 \begin_inset LatexCommand index
23248 name "\\#pragma noiv"
23252 - Do not generate interrupt
23253 \begin_inset LatexCommand index
23259 \begin_inset LatexCommand index
23260 name "interrupt vector table"
23264 entries for all ISR functions defined after the pragma.
23265 This is useful in cases where the interrupt vector table must be defined
23266 manually, or when there is a secondary, manually defined interrupt vector
23268 for the autovector feature of the Cypress EZ-USB FX2).
23269 More elegantly this can be achieved by omitting the optional interrupt
23270 number after the interrupt keyword, see section
23271 \begin_inset LatexCommand ref
23272 reference "sub:Interrupt-Service-Routines"
23280 \begin_layout Itemize
23286 \begin_inset LatexCommand index
23287 name "\\#pragma nojtbound"
23291 - will not generate code for boundary value checking, when switch statements
23292 are turned into jump-tables (dangerous).
23293 For more details see section
23294 \begin_inset LatexCommand ref
23295 reference "sub:'switch'-Statements"
23302 \begin_layout Itemize
23308 \begin_inset LatexCommand index
23309 name "\\#pragma noloopreverse"
23313 - Will not do loop reversal optimization
23316 \begin_layout Itemize
23322 \begin_inset LatexCommand index
23323 name "\\#pragma nooverlay"
23327 - the compiler will not overlay the parameters and local variables of a
23331 \begin_layout Itemize
23337 \begin_inset LatexCommand index
23338 name "\\#pragma stackauto"
23346 \begin_layout Standard
23356 \begin_inset LatexCommand index
23357 name "-\\/-stack-auto"
23362 \begin_inset LatexCommand ref
23363 reference "sec:Parameters-and-Local-Variables"
23367 Parameters and Local Variables.
23370 \begin_layout Itemize
23376 \begin_inset LatexCommand index
23377 name "\\#pragma opt\\_code\\_speed"
23381 - The compiler will optimize code generation towards fast code, possibly
23382 at the expense of code size.
23383 Currently this has little effect.
23386 \begin_layout Itemize
23392 \begin_inset LatexCommand index
23393 name "\\#pragma opt\\_code\\_size"
23397 - The compiler will optimize code generation towards compact code, possibly
23398 at the expense of code speed.
23399 Currently this has little effect.
23402 \begin_layout Itemize
23408 \begin_inset LatexCommand index
23409 name "\\#pragma opt\\_code\\_balanced"
23413 - The compiler will attempt to generate code that is both compact and fast,
23414 as long as meeting one goal is not a detriment to the other (this is the
23419 \begin_layout Itemize
23425 \begin_inset LatexCommand index
23426 name "\\#pragma std\\_sdcc89"
23430 - Generally follow the C89 standard, but allow SDCC features that conflict
23431 with the standard (default).
23434 \begin_layout Itemize
23440 \begin_inset LatexCommand index
23441 name "\\#pragma std\\_c89"
23445 - Follow the C89 standard and disable SDCC features that conflict with the
23449 \begin_layout Itemize
23455 \begin_inset LatexCommand index
23456 name "\\#pragma std\\_sdcc99"
23460 - Generally follow the C99 standard, but allow SDCC features that conflict
23461 with the standard (incomplete support).
23464 \begin_layout Itemize
23470 \begin_inset LatexCommand index
23471 name "\\#pragma std\\_c99"
23475 - Follow the C99 standard and disable SDCC features that conflict with the
23476 standard (incomplete support).
23479 \begin_layout Itemize
23485 \begin_inset LatexCommand index
23486 name "\\#pragma codeseg"
23490 - Use this name (max.
23491 8 characters) for the code segment.
23496 \begin_layout Standard
23508 \begin_layout Itemize
23514 \begin_inset LatexCommand index
23515 name "\\#pragma constseg"
23519 - Use this name (max.
23520 8 characters) for the const segment.
23525 \begin_layout Standard
23537 \begin_layout Standard
23538 The preprocessor SDCPP
23539 \begin_inset LatexCommand index
23540 name "sdcpp (preprocessor)"
23544 supports the following #pragma directives:
23547 \begin_layout Itemize
23550 pedantic_parse_number
23553 \begin_inset LatexCommand index
23559 \begin_inset LatexCommand index
23560 name "\\#pragma pedantic\\_parse\\_number"
23565 \begin_inset LatexCommand label
23566 name "ite:pedantic_parse_number"
23570 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
23571 properly and the macro LO_B(3) gets expanded.
23577 \begin_layout Standard
23586 -pedantic-parse-number command line option
23587 \begin_inset LatexCommand vpageref
23588 reference "lyx:-pedantic-parse-number"
23595 Below is an example on how to use this pragma.
23598 Note: this functionality is not in conformance with standard!
23601 \begin_layout Verse
23604 #pragma pedantic_parse_number +
23605 \begin_inset LatexCommand index
23606 name "\\#pragma pedantic\\_parse\\_number"
23614 #define LO_B(x) ((x) & 0xff)
23618 unsigned char foo(void)
23625 unsigned char c=0xfe-LO_B(3)
23640 \begin_layout Itemize
23646 \begin_inset LatexCommand index
23647 name "\\#pragma preproc\\_asm"
23651 (+ | -) - switch _asm _endasm block preprocessing on / off.
23653 You use this pragma to define multilines of assembly code.
23654 This will prevent the preprocessor from changing the formatting required
23656 Below is an example on how to use this pragma.
23659 \begin_layout Verse
23662 #pragma preproc_asm -
23663 \begin_inset LatexCommand index
23664 name "\\#pragma preproc\\_asm"
23670 #define MYDELAY _asm
23675 nop ;my assembly comment...
23689 #pragma preproc_asm
23720 \begin_layout Itemize
23726 \begin_inset LatexCommand index
23727 name "\\#pragma sdcc\\_hash"
23731 (+ | -) - Allow "naked" hash in macro definition, for example:
23735 #define DIR_LO(x) #(x & 0xff)
23740 Below is an example on how to use this pragma.
23743 \begin_layout Verse
23746 #pragma preproc_asm +
23748 #pragma sdcc_hash +
23749 \begin_inset LatexCommand index
23750 name "\\#pragma sdcc\\_hash"
23765 mov R6_B3, #(x & 0xff)
23772 mov R7_B3, #((x >> 8) & 0xff)
23796 \begin_layout Standard
23797 Some of the pragmas are intended to be used to turn-on or off certain optimizati
23798 ons which might cause the compiler to generate extra stack and/or data space
23799 to store compiler generated temporary variables.
23800 This usually happens in large functions.
23801 Pragma directives should be used as shown in the following example, they
23802 are used to control options and optimizations for a given function.
23806 \begin_layout Verse
23810 \begin_inset LatexCommand index
23811 name "\\#pragma save"
23822 /* save the current settings */
23825 \begin_inset LatexCommand index
23826 name "\\#pragma nogcse"
23835 /* turnoff global subexpression elimination */
23837 #pragma noinduction
23838 \begin_inset LatexCommand index
23839 name "\\#pragma noinduction"
23843 /* turn off induction optimizations */
23866 \begin_inset LatexCommand index
23867 name "\\#pragma restore"
23871 /* turn the optimizations back on */
23874 \begin_layout Standard
23875 The compiler will generate a warning message when extra space is allocated.
23876 It is strongly recommended that the save and restore pragmas be used when
23877 changing options for a function.
23886 \begin_layout Section
23887 Defines Created by the Compiler
23890 \begin_layout Standard
23891 The compiler creates the following #defines
23892 \begin_inset LatexCommand index
23898 \begin_inset LatexCommand index
23899 name "Defines created by the compiler"
23908 \begin_layout Standard
23909 \begin_inset Tabular
23910 <lyxtabular version="3" rows="15" columns="2">
23912 <column alignment="left" valignment="top" leftline="true" width="3in">
23913 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
23914 <row topline="true" bottomline="true">
23915 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23918 \begin_layout Standard
23926 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23929 \begin_layout Standard
23938 <row topline="true">
23939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23942 \begin_layout Standard
23944 \begin_inset LatexCommand index
23954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23957 \begin_layout Standard
23959 Since version 2.5.6 the version number as an int (ex.
23966 <row topline="true">
23967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23970 \begin_layout Standard
23972 \begin_inset LatexCommand index
23973 name "SDCC\\_mcs51"
23978 \begin_inset LatexCommand index
23979 name "SDCC\\_ds390"
23984 \begin_inset LatexCommand index
23994 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23997 \begin_layout Standard
23998 depending on the model used (e.g.: -mds390)
24004 <row topline="true">
24005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24008 \begin_layout Standard
24010 \begin_inset LatexCommand index
24016 \begin_inset LatexCommand index
24022 \begin_inset LatexCommand index
24028 \begin_inset LatexCommand index
24038 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24041 \begin_layout Standard
24042 depending on the model used (e.g.
24049 <row topline="true">
24050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24053 \begin_layout Standard
24055 \begin_inset LatexCommand index
24056 name "SDCC\\_STACK\\_AUTO"
24065 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24068 \begin_layout Standard
24075 \begin_layout Standard
24092 <row topline="true">
24093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24096 \begin_layout Standard
24098 \begin_inset LatexCommand index
24099 name "SDCC\\_MODEL\\_SMALL"
24108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24111 \begin_layout Standard
24118 \begin_layout Standard
24135 <row topline="true">
24136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24139 \begin_layout Standard
24141 \begin_inset LatexCommand index
24142 name "SDCC\\_MODEL\\_MEDIUM"
24151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24154 \begin_layout Standard
24161 \begin_layout Standard
24178 <row topline="true">
24179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24182 \begin_layout Standard
24184 \begin_inset LatexCommand index
24185 name "SDCC\\_MODEL\\_LARGE"
24194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24197 \begin_layout Standard
24204 \begin_layout Standard
24221 <row topline="true">
24222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24225 \begin_layout Standard
24227 \begin_inset LatexCommand index
24228 name "SDCC\\_USE\\_XSTACK"
24237 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24240 \begin_layout Standard
24247 \begin_layout Standard
24264 <row topline="true">
24265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24268 \begin_layout Standard
24270 \begin_inset LatexCommand index
24271 name "SDCC\\_STACK\\_TENBIT"
24280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24283 \begin_layout Standard
24294 <row topline="true">
24295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24298 \begin_layout Standard
24300 \begin_inset LatexCommand index
24301 name "SDCC\\_MODEL\\_FLAT24"
24310 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24313 \begin_layout Standard
24324 <row topline="true">
24325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24328 \begin_layout Standard
24330 \begin_inset LatexCommand index
24331 name "SDCC\\_REVISION"
24340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24343 \begin_layout Standard
24345 SDCC svn revision number
24351 <row topline="true">
24352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24355 \begin_layout Standard
24356 SDCC_PARMS_IN_BANK1
24357 \begin_inset LatexCommand index
24358 name "SDCC\\_PARMS\\_IN\\_BANK1"
24367 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24370 \begin_layout Standard
24377 \begin_layout Standard
24394 <row topline="true">
24395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24398 \begin_layout Standard
24400 \begin_inset LatexCommand index
24401 name "SDCC\\_MODEL\\_FLAT24"
24410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24413 \begin_layout Standard
24420 \begin_layout Standard
24437 <row topline="true" bottomline="true">
24438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24441 \begin_layout Standard
24442 SDCC_INT_LONG_REENT
24443 \begin_inset LatexCommand index
24444 name "SDCC\\_INT\\_LONG\\_REENT"
24453 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24456 \begin_layout Standard
24463 \begin_layout Standard
24487 \begin_layout Chapter
24488 Notes on supported Processors
24491 \begin_layout Section
24493 \begin_inset LatexCommand label
24494 name "sub:MCS51-variants"
24499 \begin_inset LatexCommand index
24500 name "MCS51 variants"
24507 \begin_layout Standard
24508 MCS51 processors are available from many vendors and come in many different
24510 While they might differ considerably in respect to Special Function Registers
24511 the core MCS51 is usually not modified or is kept compatible.
24515 \begin_layout Subsection
24516 pdata access by SFR
24519 \begin_layout Standard
24520 With the upcome of devices with internal xdata and flash memory devices
24522 \begin_inset LatexCommand index
24523 name "P2 (mcs51 sfr)"
24527 as dedicated I/O port is becoming more popular.
24528 Switching the high byte for pdata
24529 \begin_inset LatexCommand index
24530 name "pdata (mcs51, ds390 storage class)"
24534 access which was formerly done by port P2 is then achieved by a Special
24536 \begin_inset LatexCommand index
24542 In well-established MCS51 tradition the address of this
24546 is where the chip designers decided to put it.
24547 Needless to say that they didn't agree on a common name either.
24548 So that the startup code can correctly initialize xdata variables, you
24549 should define an sfr with the name _XPAGE
24552 \begin_inset LatexCommand index
24553 name "\\_XPAGE (mcs51)"
24559 at the appropriate location if the default, port P2, is not used for this.
24563 \begin_layout Verse
24566 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
24570 \begin_layout Verse
24573 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
24578 \begin_layout Verse
24581 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
24585 \begin_layout Verse
24588 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
24592 \begin_layout Verse
24595 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
24599 \begin_layout Standard
24600 For more exotic implementations further customizations may be needed.
24602 \begin_inset LatexCommand ref
24603 reference "sub:Startup-Code"
24607 for other possibilities.
24610 \begin_layout Subsection
24611 Other Features available by SFR
24614 \begin_layout Standard
24615 Some MCS51 variants offer features like Double DPTR
24616 \begin_inset LatexCommand index
24621 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
24622 These are currently not used for the MCS51 port.
24623 If you absolutely need them you can fall back to inline assembly or submit
24627 \begin_layout Subsection
24631 \begin_layout Standard
24633 \begin_inset LatexCommand index
24634 name "Bankswitching"
24640 \begin_inset LatexCommand index
24641 name "code banking"
24645 ) is a technique to increase the code space above the 64k limit of the 8051.
24648 \begin_layout Subsubsection
24652 \begin_layout Standard
24653 \begin_inset Tabular
24654 <lyxtabular version="3" rows="3" columns="4">
24656 <column alignment="center" valignment="top" width="0">
24657 <column alignment="center" valignment="top" leftline="true" width="0">
24658 <column alignment="center" valignment="top" leftline="true" width="0">
24659 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24660 <row topline="true" bottomline="true">
24661 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24664 \begin_layout Standard
24670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24673 \begin_layout Standard
24679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24682 \begin_layout Standard
24688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24691 \begin_layout Standard
24698 <row topline="true" bottomline="true">
24699 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24702 \begin_layout Standard
24708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24711 \begin_layout Standard
24717 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24720 \begin_layout Standard
24726 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24729 \begin_layout Standard
24737 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24740 \begin_layout Standard
24741 SiLabs C8051F120 example
24746 <cell multicolumn="2" alignment="center" valignment="top" usebox="none">
24749 \begin_layout Standard
24755 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24758 \begin_layout Standard
24764 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24767 \begin_layout Standard
24782 Usually the hardware uses some sfr (an output port or an internal sfr) to
24783 select a bank and put it in the banked area of the memory map.
24784 The selected bank usually becomes active immediately upon assignment to
24785 this sfr and when running inside a bank it will switch out this code it
24786 is currently running.
24787 Therefor you cannot jump or call directly from one bank to another and
24788 need to use a so-called trampoline in the common area.
24789 For SDCC an example trampoline is in crtbank.asm and you may need to change
24790 it to your 8051 derivative or schematic.
24791 The presented code is written for the C8051F120.
24795 When calling a banked function
24796 SDCC will put the LSB of the functions address in register R0, the MSB
24797 in R1 and the bank in R2 and then call this trampoline
24802 The current selected bank is saved on the stack, the new bank is selected
24803 and an indirect jump is made.
24804 When the banked function returns it jumps to
24808 which restores the previous bank and returns to the caller.
24811 \begin_layout Subsubsection
24815 \begin_layout Standard
24816 When writing banked software using SDCC you need to use some special keywords
24818 You also need to take over a bit of work from the linker.
24822 To create a function
24823 that can be called from another bank it requires the keyword
24828 \begin_inset LatexCommand index
24834 The caller must see this in the prototype of the callee and the callee
24835 needs it for a proper return.
24836 Called functions within the same bank as the caller do not need the
24840 keyword nor do functions in the common area.
24841 Beware: SDCC does not know or check if functions are in the same bank.
24842 This is your responsibility!
24846 Normally all functions you write end up in
24848 If you want a function explicitly to reside in the common area put it in
24850 This applies for instance to interrupt service routines as they should
24854 \begin_layout Standard
24855 Functions that need to be in a switched bank must be put in a named segment.
24856 The name can be mostly anything up to eight characters (e.g.
24858 To do this you either use -
24862 \begin_layout Standard
24871 -codeseg BANK1 (See
24872 \begin_inset LatexCommand ref
24873 reference "lyx:-codeseg"
24877 ) on the command line when compiling or #pragma codeseg BANK1 (See
24878 \begin_inset LatexCommand ref
24879 reference "sec:Pragmas"
24883 ) at the top of the C source file.
24884 The segment name always applies to the whole source file and generated
24885 object so functions for different banks need to be defined in different
24890 When linking your objects you need to tell the linker where
24891 to put your segments.
24892 To do this you use the following command line option to SDCC: -Wl-b BANK1=0x180
24894 \begin_inset LatexCommand ref
24895 reference "lyx:-Wl option"
24900 This sets the virtual start address of this segment.
24901 It sets the banknumber to 0x01 and maps the bank to 0x8000 and up.
24902 The linker will not check for overflows, again this is your responsibility.
24905 \begin_layout Standard
24906 \begin_inset VSpace bigskip
24912 \begin_layout Section
24916 \begin_layout Standard
24918 \begin_inset LatexCommand index
24924 \begin_inset LatexCommand index
24929 microcontroller has a rich set of peripherals.
24930 In its built-in ROM library it includes functions to access some of the
24931 features, among them is a TCP stack with IP4 and IP6 support.
24932 Library headers (currently in beta status) and other files are provided
24936 \begin_inset LatexCommand url
24937 target "ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html"
24943 \begin_inset VSpace bigskip
24949 \begin_layout Section
24950 The Z80 and gbz80 port
24953 \begin_layout Standard
24954 SDCC can target both the Zilog Z80
24955 \begin_inset LatexCommand index
24960 and the Nintendo Gameboy's Z80-like gbz80
24961 \begin_inset LatexCommand index
24962 name "gbz80 (GameBoy Z80)"
24967 The Z80 port is passed through the same
24970 \begin_inset LatexCommand index
24971 name "Regression test"
24978 \begin_inset LatexCommand ref
24979 reference "sec:Quality-control"
24983 ) as the MCS51 and DS390 ports, so floating point support, support for long
24984 variables and bitfield support is fine.
24985 See mailing lists and forums about interrupt routines.
24988 \begin_layout Standard
24989 As always, the code is the authoritative reference - see z80/ralloc.c and
24992 \begin_inset LatexCommand index
24997 frame is similar to that generated by the IAR Z80 compiler.
24998 IX is used as the base pointer, HL and IY are used as a temporary registers,
24999 and BC and DE are available for holding variables.
25001 \begin_inset LatexCommand index
25002 name "Z80!return value"
25006 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
25008 The gbz80 port use the same set of registers for the return values, but
25009 in a different order of significance: E (one byte), DE (two bytes), or
25011 \begin_inset VSpace bigskip
25017 \begin_layout Section
25021 \begin_layout Standard
25022 The port to the Freescale/Motorola HC08
25023 \begin_inset LatexCommand index
25028 family has been added in October 2003, and is still undergoing some basic
25030 The code generator is complete, but the register allocation is still quite
25032 Some of the SDCC's standard C library functions have embedded non-HC08
25033 inline assembly and so are not yet usable.
25036 \begin_layout Standard
25037 The HC08 port passes the regression test suite (see section
25038 \begin_inset LatexCommand ref
25039 reference "sec:Quality-control"
25044 \begin_inset VSpace bigskip
25050 \begin_layout Section
25052 \begin_inset LatexCommand index
25060 \begin_layout Standard
25061 The PIC14 port adds support for Microchip
25062 \begin_inset LatexCommand index
25068 \begin_inset Formula $^{\text{TM}}$
25072 \begin_inset LatexCommand index
25078 \begin_inset Formula $^{\text{TM}}$
25081 MCUs with 14 bit wide instructions.
25082 This port is not yet mature and still lacks many features.
25083 However, it can work for simple code.
25086 \begin_layout Standard
25088 Currently supported devices include:
25091 \begin_layout Standard
25092 12F: 629, 635, 675, 683
25095 \begin_layout Standard
25099 \begin_layout Standard
25103 \begin_layout Standard
25104 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
25107 \begin_layout Standard
25108 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
25112 \begin_layout Standard
25116 \begin_layout Standard
25117 16CR: 620a, 73, 74, 76, 77
25120 \begin_layout Standard
25121 16F: 616, 627, 627a, 628, 628a, 630, 636, 639, 648, 648a, 676, 684, 685,
25125 \begin_layout Standard
25126 16F: 716, 72, 73, 737, 74, 747, 76, 767, 77, 777, 785
25129 \begin_layout Standard
25130 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
25131 877, 877a, 88, 886, 887
25134 \begin_layout Standard
25135 16F: 913, 914, 916, 917, 946
25138 \begin_layout Standard
25142 \begin_layout Standard
25144 An up-to-date list of currently supported devices can be obtained via
25146 sdcc -mpic14 -phelp foo.c
25148 (foo.c must exist...).
25151 \begin_layout Subsection
25153 \begin_inset LatexCommand index
25154 name "code page (pic14)"
25159 \begin_inset LatexCommand index
25160 name "Memory bank (pic14)"
25167 \begin_layout Standard
25168 The linker organizes allocation for the code page and RAM banks.
25169 It does not have intimate knowledge of the code flow.
25170 It will put all the code section of a single .asm file into a single code
25172 In order to make use of multiple code pages, separate asm files must be
25174 The compiler assigns all
25178 functions of a single .c file into the same code page.
25182 To get the best results,
25183 follow these guidelines:
25186 \begin_layout Enumerate
25187 Make local functions static, as non static functions require code page selection
25190 Due to the way sdcc handles functions, place called functions prior
25191 to calling functions in the file wherever possible: Otherwise sdcc will
25192 insert unnecessary pagesel directives around the call, believing that the
25193 called function is externally defined.
25196 \begin_layout Enumerate
25197 For devices that have multiple code pages it is more efficient to use the
25198 same number of files as pages: Use up to 4 separate .c files for the 16F877,
25199 but only 2 files for the 16F874.
25200 This way the linker can put the code for each file into different code
25201 pages and there will be less page selection overhead.
25204 \begin_layout Enumerate
25205 And as for any 8 bit micro (especially for PIC14 as they have a very simple
25206 instruction set), use `unsigned char' wherever possible instead of `int'.
25209 \begin_layout Subsection
25210 Adding New Devices to the Port
25213 \begin_layout Standard
25214 Adding support for a new 14
25218 \begin_layout Standard
25227 bit PIC MCU requires the following steps:
25230 \begin_layout Enumerate
25231 Create a new device description.
25233 Each device is described in two files: pic16f*.h
25235 These files primarily define SFRs, structs to access their bits, and symbolic
25236 configuration options.
25237 Both files can be generated from gputils' .inc files using the perl script
25240 support/scripts/inc2h.pl
25243 This file also contains further instructions on how to proceed.
25246 \begin_layout Enumerate
25247 Copy the .h file into SDCC's include path and either add the .c file to your
25248 project or copy it to
25250 device/lib/pic/libdev
25253 Afterwards, rebuild and install the libraries.
25256 \begin_layout Enumerate
25257 Edit pic14devices.txt in SDCC's include path (
25259 device/include/pic/
25261 in the source tree or
25263 /usr/local/share/sdcc/include/pic
25265 after installation).
25267 You need to add a device specification here to make
25268 the memory layout (code banks, RAM, aliased memory regions, ...) known to
25270 Probably you can copy and modify an existing entry.
25271 The file format is documented at the top of the file.
25274 \begin_layout Subsection
25278 \begin_layout Standard
25279 For the interrupt function, use the keyword `__interrupt'
25280 \begin_inset LatexCommand index
25281 name "PIC14!interrupt"
25285 with level number of 0 (PIC14 only has 1 interrupt so this number is only
25286 there to avoid a syntax error - it ought to be fixed).
25290 \begin_layout Verse
25293 void Intr(void) __interrupt 0
25299 T0IF = 0; /* Clear timer interrupt */
25304 \begin_layout Subsection
25305 Linking and Assembling
25308 \begin_layout Standard
25309 For assembling you can use either GPUTILS'
25310 \begin_inset LatexCommand index
25311 name "gputils (pic tools)"
25315 gpasm.exe or MPLAB's mpasmwin.exe.
25316 GPUTILS are available from
25317 \begin_inset LatexCommand url
25318 target "http://sourceforge.net/projects/gputils"
25323 For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
25324 If you use MPLAB and an interrupt function then the linker script file
25325 vectors section will need to be enlarged to link with mplink.
25336 \begin_layout Verse
25349 sdcc -V -mpic14 -p16f877 -c $<
25353 $(PRJ).hex: $(OBJS)
25363 gplink -m -s $(PRJ).lkr
25364 -o $(PRJ).hex $(OBJS) libsdcc.lib
25367 \begin_layout Standard
25375 \begin_layout Verse
25388 sdcc -S -V -mpic14 -p16f877 $<
25398 mpasmwin /q /o $*.asm
25402 $(PRJ).hex: $(OBJS)
25413 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
25416 \begin_layout Standard
25417 Please note that indentations within a
25421 have to be done with a tabulator character.
25424 \begin_layout Subsection
25425 Command-Line Options
25428 \begin_layout Standard
25429 Besides the switches common to all SDCC backends, the PIC14 port accepts
25430 the following options (for an updated list see sdcc -
25434 \begin_layout Standard
25446 \begin_layout Description
25451 \begin_layout Standard
25461 \begin_inset LatexCommand index
25462 name "PIC14!Options!-\\/-debug-extra"
25466 emit debug info in assembly output
25469 \begin_layout Description
25474 \begin_layout Standard
25484 \begin_inset LatexCommand index
25485 name "PIC14!Options!-\\/-no-pcode-opt"
25489 disable (slightly faulty) optimization on pCode
25492 \begin_layout Description
25497 \begin_layout Standard
25507 \begin_inset LatexCommand index
25508 name "PIC14!Options!-\\/-stack-loc"
25512 sets the lowest address of the argument passing stack (defaults to a suitably
25513 large shared databank to reduce BANKSEL overhead)
25516 \begin_layout Description
25521 \begin_layout Standard
25531 \begin_inset LatexCommand index
25532 name "PIC14!Options!-\\/-stack-size"
25536 sets the size if the argument passing stack (default: 16, minimum: 4)
25539 \begin_layout Subsection
25540 Environment Variables
25543 \begin_layout Standard
25544 The PIC14 port recognizes the following environment variables:
25547 \begin_layout Description
25548 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
25549 register (the ones called r0xNNNN) in a section of its own.
25550 By default (if this variable is unset), sdcc tries to cluster registers
25551 in sections in order to reduce the BANKSEL overhead when accessing them.
25554 \begin_layout Subsection
25558 \begin_layout Standard
25559 The PIC14 library currently only contains support routines required by the
25560 compiler to implement multiplication, division, and floating point support.
25561 No libc-like replacement is available at the moment, though many of the
25562 common sdcc library sources (in
25566 ) should also compile with the PIC14 port.
25569 \begin_layout Subsubsection
25570 error: missing definition for symbol ``__gptrget1''
25573 \begin_layout Standard
25574 The PIC14 port uses library routines to provide more complex operations
25575 like multiplication, division/modulus and (generic) pointer dereferencing.
25576 In order to add these routines to your project, you must link with PIC14's
25582 For single source file projects this is done automatically, more complex
25587 to the linker's arguments.
25588 Make sure you also add an include path for the library (using the -I switch
25592 \begin_layout Subsubsection
25593 Processor mismatch in file ``XXX''.
25596 \begin_layout Standard
25597 This warning can usually be ignored due to the very good compatibility amongst
25602 \begin_layout Standard
25612 \begin_inset LatexCommand index
25620 \begin_layout Standard
25621 You might also consider recompiling the library for your specific device
25622 by changing the ARCH=p16f877 (default target) entry in
25624 device/lib/pic/Makefile.in
25628 device/lib/pic/Makefile
25630 to reflect your device.
25631 This might even improve performance for smaller devices as unnecessary
25632 BANKSELs might be removed.
25635 \begin_layout Subsection
25639 \begin_layout Subsubsection
25643 \begin_layout Standard
25644 Functions with variable argument lists (like printf) are not yet supported.
25645 Similarly, taking the address of the first argument passed into a function
25646 does not work: It is currently passed in WREG and has no address...
25649 \begin_layout Subsubsection
25650 Regression tests fail
25653 \begin_layout Standard
25654 Though the small subset of regression tests in src/regression passes, SDCC
25655 regression test suite does not, indicating that there are still major bugs
25657 However, many smaller projects have successfully used SDCC in the past...
25660 \begin_layout Standard
25668 \begin_layout Section
25670 \begin_inset LatexCommand index
25678 \begin_layout Standard
25679 The PIC16 port adds support for Microchip
25680 \begin_inset LatexCommand index
25686 \begin_inset Formula $^{\text{TM}}$
25690 \begin_inset LatexCommand index
25696 \begin_inset Formula $^{\text{TM}}$
25699 MCUs with 16 bit wide instructions.
25700 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
25701 ; devices supported by the port include:
25704 \begin_layout Standard
25705 18F: 242, 248, 252, 258, 442, 448, 452, 458
25708 \begin_layout Standard
25712 \begin_layout Standard
25713 18F: 2220, 2221, 2320, 2321, 2331, 2410, 2420, 2423, 2431, 2450, 2455, 2480,
25717 \begin_layout Standard
25718 18F: (2510,) 2515, 2520, 2523, 2525, 2550, 2580, 2585, 25j10, 2610, 2620,
25722 \begin_layout Standard
25723 18F: 4220, 4221, 4320, 4321, 4331, 4410, 4420, 4423, 4431, 4450, 4455, 4480,
25727 \begin_layout Standard
25728 18F: 4510, 4515, 4520, 4523, 4525, 4550, 4580, 4585, 45j10, 4610, 4620,
25732 \begin_layout Standard
25733 18F: 6520, 6585, 6620, 6680, 66j60, 66j65, 6720, 67j60
25736 \begin_layout Standard
25737 18F: 8520, 8585, 8620, 8680, 86j60, 86j65, 8720, 87j60
25740 \begin_layout Standard
25741 18F: 96j60, 96j65, 97j60
25744 \begin_layout Standard
25746 An up-to-date list of supported devices is also available via '
25748 sdcc -mpic16 -plist
25753 \begin_layout Subsection
25757 \begin_layout Standard
25758 PIC16 port supports the standard command line arguments as supposed, with
25759 the exception of certain cases that will be mentioned in the following
25763 \begin_layout Description
25768 \begin_layout Standard
25778 \begin_inset LatexCommand index
25779 name "PIC16!Options!-\\/-callee-saves"
25787 \begin_layout Standard
25799 \begin_layout Description
25804 \begin_layout Standard
25813 -fommit-frame-pointer
25814 \begin_inset LatexCommand index
25815 name "PIC16!Options!-\\/-fommit-frame-pointer"
25819 Frame pointer will be omitted when the function uses no local variables.
25822 \begin_layout Subsection
25823 Port Specific Options
25824 \begin_inset LatexCommand index
25825 name "Options PIC16"
25832 \begin_layout Standard
25833 The port specific options appear after the global options in the sdcc -
25837 \begin_layout Standard
25849 \begin_layout Subsubsection
25850 Code Generation Options
25853 \begin_layout Standard
25854 These options influence the generated assembler code.
25857 \begin_layout Description
25862 \begin_layout Standard
25871 -pstack-model=[model] Used in conjunction with the command above.
25872 Defines the stack model to be used, valid stack models are:
25877 \labelwidthstring 00.00.0000
25882 Selects small stack model.
25883 8 bit stack and frame pointers.
25884 Supports 256 bytes stack size.
25888 \labelwidthstring 00.00.0000
25893 Selects large stack model.
25894 16 bit stack and frame pointers.
25895 Supports 65536 bytes stack size.
25899 \begin_layout Description
25904 \begin_layout Standard
25913 -pno-banksel Do not generate BANKSEL assembler directives.
25916 \begin_layout Description
25921 \begin_layout Standard
25930 -extended Enable extended instruction set/literal offset addressing mode.
25934 \begin_layout Subsubsection
25935 Optimization Options
25938 \begin_layout Description
25943 \begin_layout Standard
25952 -obanksel=n Set optimization level for inserting BANKSELs.
25959 \labelwidthstring 00.00.0000
25964 \labelwidthstring 00.00.0000
25965 1 checks previous used register and if it is the same then does not emit
25966 BANKSEL, accounts only for labels.
25970 \labelwidthstring 00.00.0000
25971 2 tries to check the location of (even different) symbols and removes BANKSELs
25972 if they are in the same bank.
25977 Important: There might be problems if the linker script has data sections
25978 across bank borders!
25982 \begin_layout Description
25987 \begin_layout Standard
25996 -denable-peeps Force the usage of peepholes.
26000 \begin_layout Description
26005 \begin_layout Standard
26014 -no-optimize-goto Do not use (conditional) BRA instead of GOTO.
26017 \begin_layout Description
26022 \begin_layout Standard
26031 -optimize-cmp Try to optimize some compares.
26034 \begin_layout Description
26039 \begin_layout Standard
26048 -optimize-df Analyze the dataflow of the generated code and improve it.
26051 \begin_layout Subsubsection
26055 \begin_layout Description
26060 \begin_layout Standard
26069 -asm= Sets the full path and name of an external assembler to call.
26072 \begin_layout Description
26077 \begin_layout Standard
26087 \begin_inset LatexCommand index
26092 compatibility option.
26093 Currently only suppresses special gpasm directives.
26096 \begin_layout Subsubsection
26100 \begin_layout Description
26105 \begin_layout Standard
26114 -link= Sets the full path and name of an external linker to call.
26117 \begin_layout Description
26122 \begin_layout Standard
26131 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
26132 unitialized data variables with [kword].
26133 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
26136 \begin_layout Description
26141 \begin_layout Standard
26150 -ivt-loc=n Place the interrupt vector table at address
26155 Useful for bootloaders.
26158 \begin_layout Description
26163 \begin_layout Standard
26172 -nodefaultlibs Do not link default libraries when linking.
26175 \begin_layout Description
26180 \begin_layout Standard
26189 -use-crt= Use a custom run-time module instead of the defaults.
26192 \begin_layout Description
26197 \begin_layout Standard
26206 -no-crt Don't link the default run-time modules
26209 \begin_layout Subsubsection
26213 \begin_layout Standard
26214 Debugging options enable extra debugging information in the output files.
26217 \begin_layout Description
26222 \begin_layout Standard
26231 -debug-xtra Similar to -
26235 \begin_layout Standard
26245 \begin_inset LatexCommand index
26250 , but dumps more information.
26253 \begin_layout Description
26258 \begin_layout Standard
26267 -debug-ralloc Force register allocator to dump <source>.d file with debugging
26269 <source> is the name of the file being compiled.
26272 \begin_layout Description
26277 \begin_layout Standard
26286 -pcode-verbose Enable pcode debugging information in translation.
26289 \begin_layout Description
26294 \begin_layout Standard
26303 -calltree Dump call tree in .calltree file.
26306 \begin_layout Description
26311 \begin_layout Standard
26320 -gstack Trace push/pops for stack pointer overflow.
26323 \begin_layout Subsection
26324 Environment Variables
26327 \begin_layout Standard
26328 There is a number of environmental variables that can be used when running
26329 SDCC to enable certain optimizations or force a specific program behaviour.
26330 these variables are primarily for debugging purposes so they can be enabled/dis
26334 \begin_layout Standard
26335 Currently there is only two such variables available:
26338 \begin_layout Description
26339 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
26340 bitfields is optimized by directly loading FSR0 with the address of the
26341 bitfield structure.
26342 Normally SDCC will cast the bitfield structure to a bitfield pointer and
26344 This step saves data ram and code space for functions that make heavy use
26346 (i.e., 80 bytes of code space are saved when compiling malloc.c with this
26351 \begin_layout Description
26352 NO_REG_OPT Do not perform pCode registers optimization.
26353 This should be used for debugging purposes.
26354 If bugs in the pcode optimizer are found, users can benefit from temporarily
26355 disabling the optimizer until the bug is fixed.
26358 \begin_layout Subsection
26359 Preprocessor Macros
26362 \begin_layout Standard
26364 \begin_inset LatexCommand index
26369 port defines the following preprocessor macros while translating a source.
26372 \begin_layout Standard
26374 \begin_inset Tabular
26375 <lyxtabular version="3" rows="6" columns="2">
26377 <column alignment="center" valignment="top" leftline="true" width="0">
26378 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26379 <row topline="true" bottomline="true">
26380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26383 \begin_layout Standard
26389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26392 \begin_layout Standard
26399 <row topline="true">
26400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26403 \begin_layout Standard
26409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26412 \begin_layout Standard
26413 Port identification
26419 <row topline="true">
26420 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26423 \begin_layout Standard
26428 \begin_layout Standard
26442 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26445 \begin_layout Standard
26446 Port identification (same as above)
26452 <row topline="true">
26453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26456 \begin_layout Standard
26462 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26465 \begin_layout Standard
26466 MCU Identification.
26471 is the microcontrol identification number, i.e.
26478 <row topline="true">
26479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26482 \begin_layout Standard
26487 \begin_layout Standard
26501 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26504 \begin_layout Standard
26505 MCU Identification (same as above)
26511 <row topline="true" bottomline="true">
26512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26515 \begin_layout Standard
26521 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26524 \begin_layout Standard
26525 nnn = SMALL or LARGE respectively according to the stack model used
26538 \begin_layout Standard
26540 In addition the following macros are defined when calling assembler:
26543 \begin_layout Standard
26545 \begin_inset Tabular
26546 <lyxtabular version="3" rows="4" columns="2">
26548 <column alignment="center" valignment="top" leftline="true" width="0">
26549 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26550 <row topline="true" bottomline="true">
26551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26554 \begin_layout Standard
26560 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26563 \begin_layout Standard
26570 <row topline="true">
26571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26574 \begin_layout Standard
26580 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26583 \begin_layout Standard
26584 MCU Identification.
26589 is the microcontrol identification number, i.e.
26596 <row topline="true">
26597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26600 \begin_layout Standard
26606 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26609 \begin_layout Standard
26610 nnn = SMALL or LARGE respectively according to the memory model used for
26617 <row topline="true" bottomline="true">
26618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26621 \begin_layout Standard
26627 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26630 \begin_layout Standard
26631 nnn = SMALL or LARGE respectively according to the stack model used
26644 \begin_layout Subsection
26648 \begin_layout Standard
26650 \begin_inset LatexCommand index
26655 port uses the following directories for searching header files and libraries.
26658 \begin_layout Standard
26660 \begin_inset Tabular
26661 <lyxtabular version="3" rows="3" columns="4">
26663 <column alignment="center" valignment="top" leftline="true" width="0">
26664 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26665 <column alignment="center" valignment="top" width="0">
26666 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26667 <row topline="true" bottomline="true">
26668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26671 \begin_layout Standard
26677 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26680 \begin_layout Standard
26686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26689 \begin_layout Standard
26695 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26698 \begin_layout Standard
26705 <row topline="true">
26706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26709 \begin_layout Standard
26710 PREFIX/sdcc/include/pic16
26715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26718 \begin_layout Standard
26719 PIC16 specific headers
26724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26727 \begin_layout Standard
26733 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26736 \begin_layout Standard
26743 <row topline="true" bottomline="true">
26744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26747 \begin_layout Standard
26748 PREFIX/sdcc/lib/pic16
26753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26756 \begin_layout Standard
26757 PIC16 specific libraries
26762 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26765 \begin_layout Standard
26771 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26774 \begin_layout Standard
26788 \begin_layout Subsection
26790 \begin_inset LatexCommand label
26791 name "sub:PIC16_Pragmas"
26798 \begin_layout Standard
26800 \begin_inset LatexCommand index
26805 port currently supports the following pragmas:
26808 \begin_layout Description
26810 \begin_inset LatexCommand index
26811 name "PIC16!Pragmas!\\#pragma stack"
26815 This forces the code generator to initialize the stack & frame pointers
26816 at a specific address.
26817 This is an ad hoc solution for cases where no STACK directive is available
26818 in the linker script or gplink is not instructed to create a stack section.
26821 stack pragma should be used only once in a project.
26822 Multiple pragmas may result in indeterminate behaviour of the program.
26826 \begin_layout Standard
26827 The old format (ie.
26828 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
26829 cross page boundaries (or even exceed the available data RAM) and crash
26831 Make sure that stack does not cross page boundaries when using the SMALL
26839 The format is as follows:
26844 \begin_layout LyX-Code
26845 #pragma stack bottom_address [stack_size]
26850 \begin_layout Standard
26855 is the lower bound of the stack section.
26856 The stack pointer initially will point at address (bottom_address+stack_size-1).
26859 \begin_layout LyX-Code
26863 \begin_layout LyX-Code
26867 \begin_layout LyX-Code
26868 /* initializes stack of 100 bytes at RAM address 0x200 */
26871 \begin_layout LyX-Code
26872 #pragma stack 0x200 100
26875 \begin_layout Standard
26876 If the stack_size field is omitted then a stack is created with the default
26878 This size might be enough for most programs, but its not enough for operations
26879 with deep function nesting or excessive stack usage.
26882 \begin_layout Description
26884 \begin_inset LatexCommand index
26885 name "PIC16!Pragmas!\\#pragma code"
26889 Force a function to a static FLASH address.
26892 \begin_layout LyX-Code
26896 \begin_layout LyX-Code
26900 \begin_layout LyX-Code
26901 /* place function test_func at 0x4000 */
26904 \begin_layout LyX-Code
26905 #pragma code test_func 0x4000
26908 \begin_layout LyX-Code
26912 \begin_layout Description
26913 library instructs the linker to use a library module.
26918 \begin_layout LyX-Code
26919 #pragma library module_name
26922 \begin_layout Standard
26927 can be any library or object file (including its path).
26928 Note that there are four reserved keywords which have special meaning.
26932 \begin_layout Standard
26934 \begin_inset Tabular
26935 <lyxtabular version="3" rows="6" columns="3">
26937 <column alignment="center" valignment="top" leftline="true" width="0">
26938 <column alignment="block" valignment="top" leftline="true" width="20page%">
26939 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
26940 <row topline="true" bottomline="true">
26941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26944 \begin_layout Standard
26950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26953 \begin_layout Standard
26959 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26962 \begin_layout Standard
26969 <row topline="true">
26970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26973 \begin_layout Standard
26981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26984 \begin_layout Standard
26985 ignore all library pragmas
26990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26993 \begin_layout Standard
27002 <row topline="true">
27003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27006 \begin_layout Standard
27014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27017 \begin_layout Standard
27023 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27026 \begin_layout Standard
27037 <row topline="true">
27038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27041 \begin_layout Standard
27049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27052 \begin_layout Standard
27053 link the Math libarary
27058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27061 \begin_layout Standard
27072 <row topline="true">
27073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27076 \begin_layout Standard
27084 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27087 \begin_layout Standard
27088 link the I/O library
27093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27096 \begin_layout Standard
27107 <row topline="true" bottomline="true">
27108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27111 \begin_layout Standard
27119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27122 \begin_layout Standard
27123 link the debug library
27128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27131 \begin_layout Standard
27148 * is the device number, i.e.
27149 452 for PIC18F452 MCU.
27152 \begin_layout Standard
27154 This feature allows for linking with specific libraries without having to
27155 explicit name them in the command line.
27160 keyword will reject all modules specified by the library pragma.
27163 \begin_layout Description
27164 udata The pragma udata instructs the compiler to emit code so that linker
27165 will place a variable at a specific memory bank.
27168 \begin_layout LyX-Code
27172 \begin_layout LyX-Code
27176 \begin_layout LyX-Code
27177 /* places variable foo at bank2 */
27180 \begin_layout LyX-Code
27181 #pragma udata bank2 foo
27184 \begin_layout LyX-Code
27188 \begin_layout Standard
27189 In order for this pragma to work extra SECTION directives should be added
27190 in the .lkr script.
27191 In the following example a sample .lkr file is shown:
27194 \begin_layout LyX-Code
27198 \begin_layout LyX-Code
27199 // Sample linker script for the PIC18F452 processor
27202 \begin_layout LyX-Code
27206 \begin_layout LyX-Code
27207 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
27210 \begin_layout LyX-Code
27211 CODEPAGE NAME=page START=0x2A END=0x7FFF
27214 \begin_layout LyX-Code
27215 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
27218 \begin_layout LyX-Code
27219 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
27222 \begin_layout LyX-Code
27223 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
27226 \begin_layout LyX-Code
27227 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
27230 \begin_layout LyX-Code
27231 ACCESSBANK NAME=accessram START=0x0 END=0x7F
27234 \begin_layout LyX-Code
27238 \begin_layout LyX-Code
27239 DATABANK NAME=gpr0 START=0x80 END=0xFF
27242 \begin_layout LyX-Code
27243 DATABANK NAME=gpr1 START=0x100 END=0x1FF
27246 \begin_layout LyX-Code
27247 DATABANK NAME=gpr2 START=0x200 END=0x2FF
27250 \begin_layout LyX-Code
27251 DATABANK NAME=gpr3 START=0x300 END=0x3FF
27254 \begin_layout LyX-Code
27255 DATABANK NAME=gpr4 START=0x400 END=0x4FF
27258 \begin_layout LyX-Code
27259 DATABANK NAME=gpr5 START=0x500 END=0x5FF
27262 \begin_layout LyX-Code
27263 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
27266 \begin_layout LyX-Code
27270 \begin_layout LyX-Code
27271 SECTION NAME=CONFIG ROM=config
27274 \begin_layout LyX-Code
27278 \begin_layout LyX-Code
27279 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
27282 \begin_layout LyX-Code
27283 SECTION NAME=bank1 RAM=gpr1 # should be added to link
27286 \begin_layout LyX-Code
27287 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
27290 \begin_layout LyX-Code
27291 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
27294 \begin_layout LyX-Code
27295 SECTION NAME=bank4 RAM=gpr4
27298 \begin_layout LyX-Code
27299 SECTION NAME=bank5 RAM=gpr5
27302 \begin_layout Standard
27303 The linker will recognise the section name set in the pragma statement and
27304 will position the variable at the memory bank set with the RAM field at
27305 the SECTION line in the linker script file.
27308 \begin_layout Subsection
27310 \begin_inset LatexCommand label
27311 name "sub:PIC16_Header-Files"
27318 \begin_layout Standard
27319 There is one main header file
27320 \begin_inset LatexCommand index
27321 name "PIC16!Header files"
27325 that can be included to the source files using the pic16
27326 \begin_inset LatexCommand index
27337 This header file contains the definitions for the processor special registers,
27338 so it is necessary if the source accesses them.
27339 It can be included by adding the following line in the beginning of the
27343 \begin_layout LyX-Code
27344 #include <pic18fregs.h>
27347 \begin_layout Standard
27348 The specific microcontroller is selected within the pic18fregs.h automatically,
27349 so the same source can be used with a variety of devices.
27352 \begin_layout Subsection
27354 \begin_inset LatexCommand label
27355 name "sub:pic16Libraries"
27362 \begin_layout Standard
27364 \begin_inset LatexCommand index
27365 name "PIC16!Libraries"
27370 \begin_inset LatexCommand index
27375 port depends on are the microcontroller device libraries which contain
27376 the symbol definitions for the microcontroller special function registers.
27377 These libraries have the format pic18fxxxx.lib, where
27381 is the microcontroller identification number.
27382 The specific library is selected automatically by the compiler at link
27383 stage according to the selected device.
27386 \begin_layout Standard
27388 Libraries are created with gplib which is part of the gputils package
27389 \begin_inset LatexCommand url
27390 target "http://sourceforge.net/projects/gputils"
27397 \begin_layout Subsubsection*
27398 Building the libraries
27401 \begin_layout Standard
27402 Before using SDCC/pic16 there are some libraries that need to be compiled.
27403 This process is done automatically if gputils are found at SDCC's compile
27405 Should you require to rebuild the pic16 libraries manually (e.g.
27406 in order to enable output of float values
27407 \begin_inset LatexCommand index
27408 name "Floating point support"
27416 , see below), these are the steps required to do so under Linux or Mac OS
27417 X (cygwin might work as well, but is untested):
27420 \begin_layout LyX-Code
27421 cd device/lib/pic16
27424 \begin_layout LyX-Code
27428 \begin_layout LyX-Code
27432 \begin_layout LyX-Code
27436 \begin_layout LyX-Code
27437 su -c 'make install' # install the libraries, you need the root password
27440 \begin_layout LyX-Code
27444 \begin_layout Standard
27445 If you need to install the headers too, do:
27448 \begin_layout LyX-Code
27452 \begin_layout LyX-Code
27453 su -c 'make install' # install the headers, you need the root password
27456 \begin_layout Subsubsection*
27457 Output of float values via printf()
27460 \begin_layout Standard
27461 The library is normally built without support for displaying float values,
27463 \begin_inset LatexCommand index
27469 \begin_inset LatexCommand index
27470 name "printf floating point support"
27474 will appear instead of the value.
27475 To change this, rebuild the library as stated above, but call
27477 ./configure.gnu --enable-floats
27484 Also make sure that at least
27486 libc/stdio/vfprintf.c
27488 is actually recompiled, e.g.
27497 run or deleting its
27504 \begin_layout Standard
27505 The more common appraoch of compiling
27513 should also work, but is untested.
27516 \begin_layout Subsection
27517 Adding New Devices to the Port
27520 \begin_layout Standard
27521 Adding support for a new 16
27525 \begin_layout Standard
27534 bit PIC MCU requires the following steps:
27537 \begin_layout Enumerate
27538 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
27542 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
27546 \begin_layout Enumerate
27549 mv picDEVICE.h /path/to/sdcc/device/include/pic16
27552 \begin_layout Enumerate
27555 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
27558 \begin_layout Enumerate
27561 /path/to/sdcc/device/lib/pic16/pics.all
27565 Note: No 18f prefix here!
27568 \begin_layout Enumerate
27571 /path/to/sdcc/device/include/pic16/adc.h
27575 Add the new devices to the correct ADC style class (depending on the number
27582 if the device does not offer any ADC at all.
27585 \begin_layout Enumerate
27588 /path/to/sdcc/device/include/pic16/pic18fregs.h
27592 The file format is self-explanatory, just add
27596 #elif defined(picDEVICE)
27602 \begin_layout Standard
27613 include <picDEVICE.h>
27617 at the right place (keep the file sorted, please).
27620 \begin_layout Enumerate
27623 /path/to/sdcc/device/include/pic16devices.txt
27627 Copy and modify an existing entry or create a new one and insert it at the
27628 correct place (keep the file sorted, please).
27631 \begin_layout Enumerate
27634 /path/to/sdcc/device/lib/pic16/libdev/Makefile.am
27638 Copy an existing entry and adjust the device name.
27641 \begin_layout Enumerate
27644 /path/to/sdcc/device/lib/pic16/libio/Makefile.am
27648 Copy the record from the 18f2220 and adjust the device name.
27651 does not offer ADC, I
27652 \begin_inset Formula $^{\text{2}}$
27655 C, and/or (E)USART functionality as assumed by the library, remove the lines
27671 \begin_layout Enumerate
27690 /path/to/sdcc/device/lib/pic16
27695 \begin_layout Enumerate
27696 Recompile the pic16 libraries as described in
27697 \begin_inset LatexCommand ref
27698 reference "sub:pic16Libraries"
27705 \begin_layout Subsection
27709 \begin_layout Standard
27710 The following memory models are supported by the PIC16 port:
27713 \begin_layout Itemize
27717 \begin_layout Itemize
27721 \begin_layout Standard
27722 Memory model affects the default size of pointers within the source.
27723 The sizes are shown in the next table:
27726 \begin_layout Standard
27728 \begin_inset Tabular
27729 <lyxtabular version="3" rows="3" columns="3">
27731 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27732 <column alignment="center" valignment="top" leftline="true" width="0">
27733 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27734 <row topline="true" bottomline="true">
27735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27738 \begin_layout Standard
27739 Pointer sizes according to memory model
27744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27747 \begin_layout Standard
27753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27756 \begin_layout Standard
27763 <row topline="true" bottomline="true">
27764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27767 \begin_layout Standard
27773 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27776 \begin_layout Standard
27782 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27785 \begin_layout Standard
27792 <row topline="true" bottomline="true">
27793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27796 \begin_layout Standard
27802 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
27805 \begin_layout Standard
27811 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27814 \begin_layout Standard
27828 \begin_layout Standard
27829 It is advisable that all sources within a project are compiled with the
27831 If one wants to override the default memory model, this can be done by
27832 declaring a pointer as
27841 Far selects large memory model's pointers, while near selects small memory
27845 \begin_layout Standard
27846 The standard device libraries (see
27847 \begin_inset LatexCommand ref
27848 reference "sub:PIC16_Header-Files"
27852 ) contain no reference to pointers, so they can be used with both memory
27856 \begin_layout Subsection
27860 \begin_layout Standard
27862 \begin_inset LatexCommand index
27867 implementation for the PIC16 port uses two indirect registers, FSR1 and
27871 \begin_layout Description
27872 FSR1 is assigned as stack pointer
27875 \begin_layout Description
27876 FSR2 is assigned as frame pointer
27879 \begin_layout Standard
27880 The following stack models are supported by the PIC16 port
27883 \begin_layout Itemize
27891 \begin_layout Itemize
27899 \begin_layout Standard
27904 model means that only the FSRxL byte is used to access stack and frame,
27911 uses both FSRxL and FSRxH registers.
27912 The following table shows the stack/frame pointers sizes according to stack
27913 model and the maximum space they can address:
27916 \begin_layout Standard
27918 \begin_inset Tabular
27919 <lyxtabular version="3" rows="3" columns="3">
27921 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27922 <column alignment="center" valignment="top" leftline="true" width="0">
27923 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27924 <row topline="true" bottomline="true">
27925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27928 \begin_layout Standard
27929 Stack & Frame pointer sizes according to stack model
27934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27937 \begin_layout Standard
27943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27946 \begin_layout Standard
27953 <row topline="true">
27954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27957 \begin_layout Standard
27963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27966 \begin_layout Standard
27972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27975 \begin_layout Standard
27982 <row topline="true" bottomline="true">
27983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27986 \begin_layout Standard
27992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27995 \begin_layout Standard
28001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28004 \begin_layout Standard
28018 \begin_layout Standard
28024 stack model is currently not working properly throughout the code generator.
28025 So its use is not advised.
28026 Also there are some other points that need special care:
28031 \begin_layout Enumerate
28032 Do not create stack sections with size more than one physical bank (that
28036 \begin_layout Enumerate
28037 Stack sections should no cross physical bank limits (i.e.
28038 #pragma stack 0x50 0x100)
28041 \begin_layout Standard
28042 These limitations are caused by the fact that only FSRxL is modified when
28043 using SMALL stack model, so no more than 256 bytes of stack can be used.
28044 This problem will disappear after LARGE model is fully implemented.
28047 \begin_layout Subsection
28051 \begin_layout Standard
28052 In addition to the standard SDCC function keywords, PIC16
28053 \begin_inset LatexCommand index
28058 port makes available two more:
28061 \begin_layout Description
28063 \begin_inset LatexCommand index
28064 name "PIC16!wparam"
28068 Use the WREG to pass one byte of the first function argument.
28069 This improves speed but you may not use this for functions with arguments
28070 that are called via function pointers, otherwise the first byte of the
28071 first parameter will get lost.
28075 \begin_layout LyX-Code
28076 void func_wparam(int a) wparam
28079 \begin_layout LyX-Code
28083 \begin_layout LyX-Code
28084 /* WREG hold the lower part of a */
28087 \begin_layout LyX-Code
28088 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
28092 \begin_layout LyX-Code
28096 \begin_layout LyX-Code
28100 \begin_layout Description
28102 \begin_inset LatexCommand index
28103 name "PIC16!shadowregs"
28107 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
28108 hardware shadow registers which hold the values of WREG, STATUS and BSR
28110 This can be done by adding the keyword
28118 keyword in the function's header.
28121 \begin_layout LyX-Code
28122 void isr_shadow(void) shadowregs interrupt 1
28125 \begin_layout LyX-Code
28129 \begin_layout LyX-Code
28133 \begin_layout LyX-Code
28137 \begin_layout Standard
28142 instructs the code generator not to store/restore WREG, STATUS, BSR when
28143 entering/exiting the ISR.
28146 \begin_layout Subsection
28147 Function return values
28150 \begin_layout Standard
28151 Return values from functions are placed to the appropriate registers following
28152 a modified Microchip policy optimized for SDCC.
28153 The following table shows these registers:
28156 \begin_layout Standard
28158 \begin_inset Tabular
28159 <lyxtabular version="3" rows="6" columns="2">
28161 <column alignment="center" valignment="top" leftline="true" width="0">
28162 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28163 <row topline="true" bottomline="true">
28164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28167 \begin_layout Standard
28173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28176 \begin_layout Standard
28177 destination register
28183 <row topline="true">
28184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28187 \begin_layout Standard
28193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28196 \begin_layout Standard
28203 <row topline="true">
28204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28207 \begin_layout Standard
28213 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28216 \begin_layout Standard
28223 <row topline="true">
28224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28227 \begin_layout Standard
28233 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28236 \begin_layout Standard
28243 <row topline="true">
28244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28247 \begin_layout Standard
28253 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28256 \begin_layout Standard
28257 FSR0L:PRODH:PRODL:WREG
28263 <row topline="true" bottomline="true">
28264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28267 \begin_layout Standard
28273 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28276 \begin_layout Standard
28277 on stack, FSR0 points to the beginning
28290 \begin_layout Subsection
28294 \begin_layout Standard
28296 \begin_inset LatexCommand index
28297 name "PIC16!interrupt"
28301 service routine (ISR) is declared using the
28308 \begin_layout LyX-Code
28309 void isr(void) interrupt
28314 \begin_layout LyX-Code
28318 \begin_layout LyX-Code
28322 \begin_layout LyX-Code
28326 \begin_layout Standard
28331 is the interrupt number, which for PIC18F devices can be:
28334 \begin_layout Standard
28336 \begin_inset Tabular
28337 <lyxtabular version="3" rows="4" columns="3">
28339 <column alignment="center" valignment="top" leftline="true" width="0">
28340 <column alignment="center" valignment="top" leftline="true" width="0">
28341 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28342 <row topline="true" bottomline="true">
28343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28346 \begin_layout Standard
28354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28357 \begin_layout Standard
28363 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28366 \begin_layout Standard
28367 Interrupt Vector Address
28373 <row topline="true">
28374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28377 \begin_layout Standard
28383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28386 \begin_layout Standard
28392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28395 \begin_layout Standard
28402 <row topline="true">
28403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28406 \begin_layout Standard
28421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28424 \begin_layout Standard
28434 HIGH priority interrupts
28439 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28442 \begin_layout Standard
28449 <row topline="true" bottomline="true">
28450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28453 \begin_layout Standard
28459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28462 \begin_layout Standard
28463 LOW priority interrupts
28468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28471 \begin_layout Standard
28485 \begin_layout Standard
28486 When generating assembly code for ISR the code generator places a
28492 Interrupt Vector Address
28494 which points at the generated ISR.
28495 This single GOTO instruction is part of an automatically generated
28497 interrupt entry point
28500 The actuall ISR code is placed as normally would in the code space.
28501 Upon interrupt request, the GOTO instruction is executed which jumps to
28503 When declaring interrupt functions as _naked this GOTO instruction is
28508 The whole interrupt functions is therefore placed at the Interrupt Vector
28509 Address of the specific interrupt.
28510 This is not a problem for the LOW priority interrupts, but it is a problem
28511 for the RESET and the HIGH priority interrupts because code may be written
28512 at the next interrupt's vector address and cause indeterminate program
28513 behaviour if that interrupt is raised.
28517 \begin_layout Standard
28518 This is not a problem when
28521 \begin_layout Enumerate
28522 this is a HIGH interrupt ISR and LOW interrupts are
28529 \begin_layout Enumerate
28530 when the ISR is small enough not to reach the next interrupt's vector address.
28538 \begin_layout Standard
28544 This way a function is generated similar to an ISR, but it is not assigned
28548 \begin_layout Standard
28549 When entering an interrupt, currently the PIC16
28550 \begin_inset LatexCommand index
28555 port automatically saves the following registers:
28558 \begin_layout Itemize
28562 \begin_layout Itemize
28566 \begin_layout Itemize
28570 \begin_layout Itemize
28571 PROD (PRODL and PRODH)
28574 \begin_layout Itemize
28575 FSR0 (FSR0L and FSR0H)
28578 \begin_layout Standard
28579 These registers are restored upon return from the interrupt routine.
28583 \begin_layout Standard
28584 NOTE that when the _naked attribute is specified for an interrupt routine,
28585 then NO registers are stored or restored.
28593 \begin_layout Subsection
28597 \begin_layout Standard
28598 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
28599 There are 3 types of generic pointers currently implemented data, code
28600 and eeprom pointers.
28601 They are differentiated by the value of the 7th and 6th bits of the upper
28605 \begin_layout Standard
28607 \begin_inset Tabular
28608 <lyxtabular version="3" rows="5" columns="5">
28610 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28611 <column alignment="center" valignment="top" width="0">
28612 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28613 <column alignment="center" valignment="top" width="0">
28614 <column alignment="left" valignment="top" rightline="true" width="0">
28615 <row topline="true" bottomline="true">
28616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28619 \begin_layout Standard
28625 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28628 \begin_layout Standard
28634 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28637 \begin_layout Standard
28643 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28646 \begin_layout Standard
28647 rest of the pointer
28652 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28655 \begin_layout Standard
28662 <row topline="true" bottomline="true">
28663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28666 \begin_layout Standard
28672 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28675 \begin_layout Standard
28681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28684 \begin_layout Standard
28690 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28693 \begin_layout Standard
28698 uuuuuu uuuuxxxx xxxxxxxx
28703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28706 \begin_layout Standard
28707 a 12-bit data pointer in data RAM memory
28713 <row bottomline="true">
28714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28717 \begin_layout Standard
28723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28726 \begin_layout Standard
28732 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28735 \begin_layout Standard
28741 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28744 \begin_layout Standard
28749 uxxxxx xxxxxxxx xxxxxxxx
28754 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28757 \begin_layout Standard
28758 a 21-bit code pointer in FLASH memory
28764 <row bottomline="true">
28765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28768 \begin_layout Standard
28774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28777 \begin_layout Standard
28783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28786 \begin_layout Standard
28792 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28795 \begin_layout Standard
28800 uuuuuu uuuuuuxx xxxxxxxx
28805 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28808 \begin_layout Standard
28809 a 10-bit eeprom pointer in EEPROM memory
28815 <row bottomline="true">
28816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28819 \begin_layout Standard
28825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28828 \begin_layout Standard
28834 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28837 \begin_layout Standard
28843 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28846 \begin_layout Standard
28851 xxxxxx xxxxxxxx xxxxxxxx
28856 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28859 \begin_layout Standard
28860 unimplemented pointer type
28873 \begin_layout Standard
28875 Generic pointer are read and written with a set of library functions which
28876 read/write 1, 2, 3, 4 bytes.
28879 \begin_layout Subsection
28883 \begin_layout Subsubsection
28884 Standard I/O Streams
28887 \begin_layout Standard
28892 the type FILE is defined as:
28895 \begin_layout LyX-Code
28896 typedef char * FILE;
28899 \begin_layout Standard
28900 This type is the stream type implemented I/O in the PIC18F devices.
28901 Also the standard input and output streams are declared in stdio.h:
28904 \begin_layout LyX-Code
28905 extern FILE * stdin;
28908 \begin_layout LyX-Code
28909 extern FILE * stdout;
28912 \begin_layout Standard
28913 The FILE type is actually a generic pointer which defines one more type
28914 of generic pointers, the
28919 This new type has the format:
28922 \begin_layout Standard
28925 \begin_inset Tabular
28926 <lyxtabular version="3" rows="2" columns="7">
28928 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28929 <column alignment="center" valignment="top" width="0">
28930 <column alignment="center" valignment="top" leftline="true" width="0">
28931 <column alignment="center" valignment="top" leftline="true" width="0">
28932 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28933 <column alignment="center" valignment="top" width="0">
28934 <column alignment="left" valignment="top" rightline="true" width="0">
28935 <row topline="true" bottomline="true">
28936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28939 \begin_layout Standard
28945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28948 \begin_layout Standard
28954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28957 \begin_layout Standard
28963 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28966 \begin_layout Standard
28972 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28975 \begin_layout Standard
28981 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28984 \begin_layout Standard
28985 rest of the pointer
28990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28993 \begin_layout Standard
29000 <row topline="true" bottomline="true">
29001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29004 \begin_layout Standard
29010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29013 \begin_layout Standard
29019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29022 \begin_layout Standard
29028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29031 \begin_layout Standard
29037 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29040 \begin_layout Standard
29046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29049 \begin_layout Standard
29059 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29062 \begin_layout Standard
29063 upper byte high nubble is 0x2n, the rest are zeroes
29076 \begin_layout Standard
29078 Currently implemented there are 3 types of streams defined:
29081 \begin_layout Standard
29084 \begin_inset Tabular
29085 <lyxtabular version="3" rows="4" columns="4">
29087 <column alignment="center" valignment="top" leftline="true" width="0">
29088 <column alignment="center" valignment="top" leftline="true" width="0">
29089 <column alignment="center" valignment="top" leftline="true" width="0">
29090 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29091 <row topline="true" bottomline="true">
29092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29095 \begin_layout Standard
29101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29104 \begin_layout Standard
29110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29113 \begin_layout Standard
29119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29122 \begin_layout Standard
29129 <row topline="true">
29130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29133 \begin_layout Standard
29139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29142 \begin_layout Standard
29150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29153 \begin_layout Standard
29159 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29162 \begin_layout Standard
29163 Writes/Reads characters via the USART peripheral
29169 <row topline="true">
29170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29173 \begin_layout Standard
29179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29182 \begin_layout Standard
29190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29193 \begin_layout Standard
29199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29202 \begin_layout Standard
29203 Writes/Reads characters via the MSSP peripheral
29209 <row topline="true" bottomline="true">
29210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29213 \begin_layout Standard
29219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29222 \begin_layout Standard
29230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29233 \begin_layout Standard
29239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29242 \begin_layout Standard
29243 Writes/Reads characters via used defined functions
29256 \begin_layout Standard
29258 The stream identifiers are declared as macros in the stdio.h header.
29261 \begin_layout Standard
29263 In the libc library there exist the functions that are used to write to
29264 each of the above streams.
29268 \begin_layout Description
29273 \begin_layout Standard
29282 _stream_usart_putchar writes a character at the USART stream
29285 \begin_layout Description
29290 \begin_layout Standard
29299 _stream_mssp_putchar writes a character at the MSSP stream
29302 \begin_layout Description
29303 putchar dummy function.
29304 This writes a character to a user specified manner.
29307 \begin_layout Standard
29308 In order to increase performance
29312 is declared in stdio.h as having its parameter in WREG (it has the wparam
29314 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
29315 in a user-friendly way.
29320 is the name of the variable that holds the character to print.
29321 An example follows:
29324 \begin_layout LyX-Code
29325 #include <pic18fregs.h>
29334 \begin_layout LyX-Code
29338 \begin_layout LyX-Code
29339 PORTA = c; /* dump character c to PORTA */
29342 \begin_layout LyX-Code
29350 \begin_layout LyX-Code
29354 \begin_layout LyX-Code
29355 stdout = STREAM_USER; /* this is not necessary, since stdout points
29358 \begin_layout LyX-Code
29359 * by default to STREAM_USER */
29362 \begin_layout LyX-Code
29364 \begin_inset Quotes sld
29367 This is a printf test
29370 \begin_inset Quotes srd
29376 \begin_layout LyX-Code
29380 \begin_layout LyX-Code
29384 \begin_layout Subsubsection
29388 \begin_layout Standard
29389 PIC16 contains an implementation of the printf-family of functions.
29390 There exist the following functions:
29393 \begin_layout LyX-Code
29394 extern unsigned int sprintf(char *buf, char *fmt, ...);
29397 \begin_layout LyX-Code
29398 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
29401 \begin_layout LyX-Code
29405 \begin_layout LyX-Code
29406 extern unsigned int printf(char *fmt, ...);
29409 \begin_layout LyX-Code
29410 extern unsigned int vprintf(char *fmt, va_lista ap);
29413 \begin_layout LyX-Code
29417 \begin_layout LyX-Code
29418 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
29421 \begin_layout LyX-Code
29422 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
29425 \begin_layout Standard
29426 For sprintf and vsprintf
29430 should normally be a data pointer where the resulting string will be placed.
29431 No range checking is done so the user should allocate the necessary buffer.
29432 For fprintf and vfprintf
29436 should be a stream pointer (i.e.
29437 stdout, STREAM_MSSP, etc...).
29440 \begin_layout Subsubsection
29444 \begin_layout Standard
29445 The PIC18F family of microcontrollers supports a number of interrupt sources.
29446 A list of these interrupts is shown in the following table:
29449 \begin_layout Standard
29451 \begin_inset Tabular
29452 <lyxtabular version="3" rows="11" columns="4">
29454 <column alignment="left" valignment="top" leftline="true" width="0">
29455 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29456 <column alignment="left" valignment="top" leftline="true" width="0">
29457 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29458 <row topline="true" bottomline="true">
29459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29462 \begin_layout Standard
29468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29471 \begin_layout Standard
29477 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29480 \begin_layout Standard
29486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29489 \begin_layout Standard
29496 <row topline="true">
29497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29500 \begin_layout Standard
29506 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29509 \begin_layout Standard
29510 PORTB change interrupt
29515 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29518 \begin_layout Standard
29524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29527 \begin_layout Standard
29528 EEPROM/FLASH write complete interrupt
29534 <row topline="true">
29535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29538 \begin_layout Standard
29544 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29547 \begin_layout Standard
29548 INT0 external interrupt
29553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29556 \begin_layout Standard
29562 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29565 \begin_layout Standard
29566 Bus collision interrupt
29572 <row topline="true">
29573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29576 \begin_layout Standard
29582 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29585 \begin_layout Standard
29586 INT1 external interrupt
29591 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29594 \begin_layout Standard
29600 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29603 \begin_layout Standard
29604 Low voltage detect interrupt
29610 <row topline="true">
29611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29614 \begin_layout Standard
29620 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29623 \begin_layout Standard
29624 INT2 external interrupt
29629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29632 \begin_layout Standard
29638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29641 \begin_layout Standard
29642 Parallel slave port interrupt
29648 <row topline="true">
29649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29652 \begin_layout Standard
29658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29661 \begin_layout Standard
29662 CCP1 module interrupt
29667 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29670 \begin_layout Standard
29676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29679 \begin_layout Standard
29680 AD convertion complete interrupt
29686 <row topline="true">
29687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29690 \begin_layout Standard
29696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29699 \begin_layout Standard
29700 CCP2 module interrupt
29705 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29708 \begin_layout Standard
29714 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29717 \begin_layout Standard
29718 USART receive interrupt
29724 <row topline="true">
29725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29728 \begin_layout Standard
29734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29737 \begin_layout Standard
29738 TMR0 overflow interrupt
29743 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29746 \begin_layout Standard
29752 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29755 \begin_layout Standard
29756 USART transmit interrupt
29762 <row topline="true">
29763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29766 \begin_layout Standard
29772 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29775 \begin_layout Standard
29776 TMR1 overflow interrupt
29781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29784 \begin_layout Standard
29790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29793 \begin_layout Standard
29794 SSP receive/transmit interrupt
29800 <row topline="true">
29801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29804 \begin_layout Standard
29810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29813 \begin_layout Standard
29814 TMR2 matches PR2 interrupt
29819 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29822 \begin_layout Standard
29828 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29831 \begin_layout Standard
29838 <row topline="true" bottomline="true">
29839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29842 \begin_layout Standard
29848 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29851 \begin_layout Standard
29852 TMR3 overflow interrupt
29857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29860 \begin_layout Standard
29866 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29869 \begin_layout Standard
29883 \begin_layout Standard
29885 The prototypes for these names are defined in the header file
29892 \begin_layout Standard
29894 In order to simplify signal handling, a number of macros is provided:
29898 \labelwidthstring 00.00.0000
29899 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
29900 high priority interrupts.
29905 is the function name to use.
29909 \labelwidthstring 00.00.0000
29910 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
29911 low priority interrupt.
29916 is the function name to use.
29920 \labelwidthstring 00.00.0000
29921 DEF_HANDLER(sig,handler) define a handler for signal
29927 \labelwidthstring 00.00.0000
29928 END_DEF end the declaration of the dispatch table.
29931 \begin_layout Standard
29932 Additionally there are two more macros to simplify the declaration of the
29937 \labelwidthstring 00.00.0000
29940 SIGHANDLER(handler)
29942 this declares the function prototype for the
29950 \labelwidthstring 00.00.0000
29951 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
29954 \begin_layout Standard
29955 An example of using the macros above is shown below:
29958 \begin_layout LyX-Code
29959 #include <pic18fregs.h>
29962 \begin_layout LyX-Code
29963 #include <signal.h>
29967 DEF_INTHIGH(high_int)
29970 \begin_layout LyX-Code
29971 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
29974 \begin_layout LyX-Code
29975 DEF_HANDLER(SIG_BCOL, _bcol_handler)
29978 \begin_layout LyX-Code
29983 SIGHANDLER(_tmr0_handler)
29986 \begin_layout LyX-Code
29990 \begin_layout LyX-Code
29991 /* action to be taken when timer 0 overflows */
29994 \begin_layout LyX-Code
29999 SIGHANDLERNAKED(_bcol_handler)
30002 \begin_layout LyX-Code
30006 \begin_layout LyX-Code
30010 \begin_layout LyX-Code
30011 /* action to be taken when bus collision occurs */
30014 \begin_layout LyX-Code
30018 \begin_layout LyX-Code
30022 \begin_layout LyX-Code
30026 \begin_layout Standard
30031 Special care should be taken when using the above scheme:
30034 \begin_layout Itemize
30035 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
30038 \begin_layout Itemize
30039 when declaring SIGHANDLERNAKED handler never forget to use
30043 for proper returning.
30046 \begin_layout Subsection
30050 \begin_layout Standard
30051 Here you can find some general tips for compiling programs with SDCC/pic16.
30054 \begin_layout Subsubsection
30058 \begin_layout Standard
30060 \begin_inset LatexCommand index
30065 size (that is 64 bytes) probably is enough for many programs.
30066 One must take care that when there are many levels of function nesting,
30067 or there is excessive usage of stack, its size should be extended.
30068 An example of such a case is the printf/sprintf family of functions.
30069 If you encounter problems like not being able to print integers, then you
30070 need to set the stack size around the maximum (256 for small stack model).
30071 The following diagram shows what happens when calling printf to print an
30075 \begin_layout LyX-Code
30076 printf () --> ltoa () --> ultoa () --> divschar ()
30079 \begin_layout Standard
30080 It is should be understood that stack is easily consumed when calling complicate
30082 Using command line arguments like -
30086 \begin_layout Standard
30095 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
30097 Other ways to reduce stack usage may exist.
30100 \begin_layout Subsection
30104 \begin_layout Subsubsection
30105 Extended Instruction Set
30108 \begin_layout Standard
30109 The PIC16 port emits code which is incompatible with the extended instruction
30110 set available with many newer devices.
30111 Make sure to always explicitly disable it, usually using
30114 \begin_layout Standard
30117 static __code char __at(__CONFIG4L) conf4l = /* more flags & */ _XINST_OFF_4L;
30120 \begin_layout Standard
30122 Some devices (namely 18f2455, 18f2550, 18f4455, and 18f4550) use _ENHCPU_OFF_4L
30123 instead of _XINST_OFF_4L.
30126 \begin_layout Subsubsection
30130 \begin_layout Standard
30131 The PIC16 port currently passes most but not all of the tests in SDCC's
30133 \begin_inset LatexCommand index
30134 name "Regression test (PIC16)"
30139 \begin_inset LatexCommand ref
30140 reference "sec:Quality-control"
30144 ), thus no automatic regression tests are currently performed for the PIC16
30148 \begin_layout Chapter
30152 \begin_layout Standard
30153 There are several approaches to debugging your code.
30154 This chapter is meant to show your options and to give detail on some of
30159 When writing your code:
30162 \begin_layout Itemize
30163 write your code with debugging in mind (avoid duplicating code, put conceptually
30164 similar variables into structs, use structured code, have strategic points
30165 within your code where all variables are consistent, ...)
30168 \begin_layout Itemize
30169 run a syntax-checking tool like splint
30170 \begin_inset LatexCommand index
30171 name "splint (syntax checking tool)"
30176 \begin_inset LatexCommand index
30177 name "lint (syntax checking tool)"
30185 \begin_layout Standard
30195 \begin_inset LatexCommand ref
30196 reference "lyx:more-pedantic-SPLINT"
30203 \begin_layout Itemize
30204 for the high level code use a C-compiler (like f.e.
30205 GCC) to compile run and debug the code on your host.
30210 \begin_layout Standard
30220 \begin_inset LatexCommand ref
30221 reference "lyx:more-pedantic-SPLINT"
30225 ) on how to handle syntax extensions like __xdata, __at(), ...
30229 \begin_layout Itemize
30230 use another C-compiler to compile code for your target.
30231 Always an option but not recommended:) And not very likely to help you.
30232 If you seriously consider walking this path you should at least occasionally
30233 check portability of your code.
30234 Most commercial compiler vendors will offer an evaluation version so you
30235 can test compile your code or snippets of your code.
30238 \begin_layout Standard
30239 Debugging on a simulator:
30242 \begin_layout Itemize
30243 there is a separate section about SDCDB (section
30244 \begin_inset LatexCommand ref
30245 reference "cha:Debugging-with-SDCDB"
30252 \begin_layout Itemize
30253 or (8051 specific) use a freeware/commercial simulator which interfaces
30255 \begin_inset LatexCommand index
30256 name "AOMF, AOMF51"
30261 \begin_inset LatexCommand ref
30262 reference "OMF file"
30266 ) optionally generated by SDCC.
30269 \begin_layout Standard
30270 Debugging On-target:
30273 \begin_layout Itemize
30274 use a MCU port pin to serially output debug data to the RS232 port of your
30276 You'll probably want some level shifting device typically involving a MAX232
30278 If the hardware serial port of the MCU is not available search for 'Software
30279 UART' in your favourite search machine.
30282 \begin_layout Itemize
30283 use an on-target monitor.
30284 In this context a monitor is a small program which usually accepts commands
30285 via a serial line and allows to set program counter, to single step through
30286 a program and read/write memory locations.
30287 For the 8051 good examples of monitors are paulmon and cmon51 (see section
30289 \begin_inset LatexCommand ref
30290 reference "sec:Related-open-source-tools"
30297 \begin_layout Itemize
30298 toggle MCU port pins at strategic points within your code and use an oscilloscop
30302 digital oscilloscope
30305 \begin_inset LatexCommand index
30306 name "Oscilloscope"
30310 with deep trace memory is really helpful especially if you have to debug
30311 a realtime application.
30312 If you need to monitor more pins than your oscilloscope provides you can
30313 sometimes get away with a small R-2R network.
30314 On a single channel oscilloscope you could f.e.
30315 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
30317 \begin_inset Formula $\Omega$
30320 resistor and the other one by a 5\InsetSpace ~
30322 \begin_inset Formula $\Omega$
30325 resistor to the oscilloscope probe (check output drive capability of the
30326 pins you want to monitor).
30327 If you need to monitor many more pins a
30334 \begin_layout Itemize
30348 \begin_inset LatexCommand index
30349 name "ICE (in circuit emulator)"
30354 Usually very expensive.
30355 And very nice to have too.
30356 And usually locks you (for years...) to the devices the ICE can emulate.
30360 \begin_layout Itemize
30361 use a remote debugger.
30362 In most 8-bit systems the symbol information is not available on the target,
30363 and a complete debugger is too bulky for the target system.
30364 Therefore usually a debugger on the host system connects to an on-target
30365 debugging stub which accepts only primitive commands.
30368 Terms to enter into your favourite search engine could be 'remote debugging',
30369 'gdb stub' or 'inferior debugger'.
30373 \begin_layout Itemize
30374 use an on target hardware debugger.
30375 Some of the more modern MCUs include hardware support for setting break
30376 points and monitoring/changing variables by using dedicated hardware pins.
30377 This facility doesn't require additional code to run on the target and
30382 doesn't affect runtime behaviour until a breakpoint is hit.
30383 For the mcs51 most hardware debuggers use the AOMF
30384 \begin_inset LatexCommand index
30385 name "AOMF, AOMF51"
30390 \begin_inset LatexCommand ref
30391 reference "OMF file"
30399 \begin_layout Standard
30403 \begin_layout Itemize
30404 if you are not familiar with any of the following terms you're likely to
30405 run into problems rather sooner than later:
30422 As an embedded programmer you
30426 to know them so why not look them up
30430 you have problems?)
30433 \begin_layout Itemize
30434 tell someone else about your problem (actually this is a surprisingly effective
30435 means to hunt down the bug even if the listener is not familiar with your
30437 As 'failure to communicate' is probably one of the job-induced deformations
30438 of an embedded programmer this is highly encouraged.
30441 \begin_layout Section
30442 Debugging with SDCDB
30443 \begin_inset LatexCommand label
30444 name "cha:Debugging-with-SDCDB"
30449 \begin_inset LatexCommand index
30450 name "SDCDB (debugger)"
30457 \begin_layout Standard
30458 SDCC is distributed with a source level debugger
30459 \begin_inset LatexCommand index
30465 The debugger uses a command line interface, the command repertoire of the
30466 debugger has been kept as close to gdb
30467 \begin_inset LatexCommand index
30472 (the GNU debugger) as possible.
30473 The configuration and build process is part of the standard compiler installati
30474 on, which also builds and installs the debugger in the target directory
30475 specified during configuration.
30476 The debugger allows you debug BOTH at the C source and at the ASM source
30480 \begin_layout Subsection
30481 Compiling for Debugging
30484 \begin_layout Standard
30489 \begin_layout Standard
30499 \begin_inset LatexCommand index
30504 option must be specified for all files for which debug information is to
30506 The compiler generates a .adb file for each of these files.
30507 The linker creates the .cdb
30508 \begin_inset LatexCommand index
30514 \begin_inset LatexCommand index
30519 files and the address information.
30520 This .cdb is used by the debugger.
30523 \begin_layout Subsection
30524 How the Debugger Works
30527 \begin_layout Standard
30532 \begin_layout Standard
30541 -debug option is specified the compiler generates extra symbol information
30542 some of which are put into the assembler source and some are put into the
30544 Then the linker creates the .cdb file from the individual .adb files with
30545 the address information for the symbols.
30546 The debugger reads the symbolic information generated by the compiler &
30547 the address information generated by the linker.
30548 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
30549 execution is controlled by the debugger.
30550 When a command is issued for the debugger, it translates it into appropriate
30551 commands for the simulator.
30552 (Currently SDCDM only connects to the simulator but
30557 \begin_inset LatexCommand url
30558 target "http://ec2drv.sf.net/"
30562 is an effort to connect directly to the hardware.)
30565 \begin_layout Subsection
30566 Starting the Debugger SDCDB
30569 \begin_layout Standard
30570 The debugger can be started using the following command line.
30571 (Assume the file you are debugging has the file name foo).
30585 The debugger will look for the following files.
30588 \begin_layout Itemize
30589 foo.c - the source file.
30592 \begin_layout Itemize
30593 foo.cdb - the debugger symbol information file.
30596 \begin_layout Itemize
30597 foo.ihx - the Intel hex format
30598 \begin_inset LatexCommand index
30599 name "Intel hex format"
30606 \begin_layout Subsection
30607 SDCDB Command Line Options
30610 \begin_layout Itemize
30615 \begin_layout Standard
30624 -directory=<source file directory> this option can used to specify the directory
30626 The debugger will look into the directory list specified for source, cdb
30628 The items in the directory list must be separated by ':', e.g.
30629 if the source files can be in the directories /home/src1 and /home/src2,
30634 \begin_layout Standard
30643 -directory option should be -
30647 \begin_layout Standard
30656 -directory=/home/src1:/home/src2.
30657 Note there can be no spaces in the option.
30661 \begin_layout Itemize
30662 -cd <directory> - change to the <directory>.
30665 \begin_layout Itemize
30666 -fullname - used by GUI front ends.
30669 \begin_layout Itemize
30670 -cpu <cpu-type> - this argument is passed to the simulator please see the
30671 simulator docs for details.
30674 \begin_layout Itemize
30675 -X <Clock frequency > this options is passed to the simulator please see
30676 the simulator docs for details.
30679 \begin_layout Itemize
30680 -s <serial port file> passed to simulator see the simulator docs for details.
30683 \begin_layout Itemize
30684 -S <serial in,out> passed to simulator see the simulator docs for details.
30687 \begin_layout Itemize
30688 -k <port number> passed to simulator see the simulator docs for details.
30691 \begin_layout Subsection
30692 SDCDB Debugger Commands
30695 \begin_layout Standard
30696 As mentioned earlier the command interface for the debugger has been deliberatel
30697 y kept as close the GNU debugger gdb, as possible.
30698 This will help the integration with existing graphical user interfaces
30699 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
30700 If you use a graphical user interface for the debugger you can skip this
30704 \begin_layout Subsubsection*
30705 break [line | file:line | function | file:function]
30708 \begin_layout Standard
30709 Set breakpoint at specified line or function:
30718 sdcdb>break foo.c:100
30720 sdcdb>break funcfoo
30722 sdcdb>break foo.c:funcfoo
30725 \begin_layout Subsubsection*
30726 clear [line | file:line | function | file:function ]
30729 \begin_layout Standard
30730 Clear breakpoint at specified line or function:
30739 sdcdb>clear foo.c:100
30741 sdcdb>clear funcfoo
30743 sdcdb>clear foo.c:funcfoo
30746 \begin_layout Subsubsection*
30750 \begin_layout Standard
30751 Continue program being debugged, after breakpoint.
30754 \begin_layout Subsubsection*
30758 \begin_layout Standard
30759 Execute till the end of the current function.
30762 \begin_layout Subsubsection*
30766 \begin_layout Standard
30767 Delete breakpoint number 'n'.
30768 If used without any option clear ALL user defined break points.
30771 \begin_layout Subsubsection*
30772 info [break | stack | frame | registers ]
30775 \begin_layout Itemize
30776 info break - list all breakpoints
30779 \begin_layout Itemize
30780 info stack - show the function call stack.
30783 \begin_layout Itemize
30784 info frame - show information about the current execution frame.
30787 \begin_layout Itemize
30788 info registers - show content of all registers.
30791 \begin_layout Subsubsection*
30795 \begin_layout Standard
30796 Step program until it reaches a different source line.
30797 Note: pressing <return> repeats the last command.
30800 \begin_layout Subsubsection*
30804 \begin_layout Standard
30805 Step program, proceeding through subroutine calls.
30808 \begin_layout Subsubsection*
30812 \begin_layout Standard
30813 Start debugged program.
30816 \begin_layout Subsubsection*
30820 \begin_layout Standard
30821 Print type information of the variable.
30824 \begin_layout Subsubsection*
30828 \begin_layout Standard
30829 print value of variable.
30832 \begin_layout Subsubsection*
30836 \begin_layout Standard
30837 load the given file name.
30838 Note this is an alternate method of loading file for debugging.
30841 \begin_layout Subsubsection*
30845 \begin_layout Standard
30846 print information about current frame.
30849 \begin_layout Subsubsection*
30853 \begin_layout Standard
30854 Toggle between C source & assembly source.
30857 \begin_layout Subsubsection*
30858 ! simulator command
30861 \begin_layout Standard
30862 Send the string following '!' to the simulator, the simulator response is
30864 Note the debugger does not interpret the command being sent to the simulator,
30865 so if a command like 'go' is sent the debugger can loose its execution
30866 context and may display incorrect values.
30869 \begin_layout Subsubsection*
30873 \begin_layout Standard
30876 My name is Bobby Brown"
30879 \begin_layout Subsection
30880 Interfacing SDCDB with DDD
30883 \begin_layout Standard
30884 \begin_inset Note Note
30887 \begin_layout Standard
30888 The screenshot was converted from png to eps with:
30889 \begin_inset Quotes sld
30892 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
30893 \begin_inset Quotes srd
30896 which produces a pretty compact eps file which is free from compression
30900 \begin_layout Standard
30901 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
30902 as this broke the build system on Sourceforge (pdf-file was broken.
30903 pdflatex does not accept eps files).
30911 \begin_layout Standard
30927 \begin_inset LatexCommand url
30928 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png"
30934 shows a screenshot of a debugging session with DDD
30935 \begin_inset LatexCommand index
30936 name "DDD (debugger)"
30940 (Unix only) on a simulated 8032.
30941 The debugging session might not run as smoothly as the screenshot suggests.
30942 The debugger allows setting of breakpoints, displaying and changing variables,
30943 single stepping through C and assembler code.
30946 The source was compiled with
30960 \begin_layout Standard
30972 -debug ddd_example.c
30985 and DDD was invoked with
30992 ddd -debugger "sdcdb -cpu 8032 ddd_example"
30995 \begin_layout Standard
30996 \begin_inset Note Note
30999 \begin_layout Standard
31000 Check that the double quotes or an apostrophe within the command line survive
31001 the LyX tool chain.
31002 Previously the apostrophes got slanted in the PDF output so a cut and paste
31011 \begin_layout Subsection
31012 Interfacing SDCDB with XEmacs
31013 \begin_inset LatexCommand index
31019 \begin_inset LatexCommand index
31027 \begin_layout Standard
31028 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
31029 sdcdb.el and sdcdbsrc.el.
31030 These two files can be found in the $(prefix)/bin directory after the installat
31032 These files need to be loaded into XEmacs for the interface to work.
31033 This can be done at XEmacs startup time by inserting the following into
31034 your '.xemacs' file (which can be found in your HOME directory):
31040 (load-file sdcdbsrc.el)
31046 .xemacs is a lisp file so the () around the command is REQUIRED.
31047 The files can also be loaded dynamically while XEmacs is running, set the
31048 environment variable 'EMACSLOADPATH' to the installation bin directory
31049 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
31050 To start the interface enter the following command:
31064 You will prompted to enter the file name to be debugged.
31069 The command line options that are passed to the simulator directly are
31070 bound to default values in the file sdcdbsrc.el.
31071 The variables are listed below, these values maybe changed as required.
31074 \begin_layout Itemize
31075 sdcdbsrc-cpu-type '51
31078 \begin_layout Itemize
31079 sdcdbsrc-frequency '11059200
31082 \begin_layout Itemize
31083 sdcdbsrc-serial nil
31086 \begin_layout Standard
31087 The following is a list of key mapping for the debugger interface.
31090 \begin_layout Standard
31113 binding\InsetSpace ~
31151 -------\InsetSpace ~
31222 sdcdb-back-from-src\InsetSpace ~
31251 rom-src\InsetSpace ~
31261 SDCDB continue command
31279 sdcdb-step-from-src\InsetSpace ~
31308 hatis-c-sexp\InsetSpace ~
31318 SDCDB ptypecommand for data at
31385 sdcdbsrc-delete\InsetSpace ~
31400 B Delete all breakpoints if no arg
31449 given or delete arg (C-u arg x)
31468 -frame\InsetSpace ~
31483 SDCDB Display current frame if no arg,
31532 given or display frame arg
31600 sdcdbsrc-goto-sdcdb\InsetSpace ~
31610 Goto the SDCDB output buffer
31629 t-c-sexp\InsetSpace ~
31640 SDCDB print command for data at
31707 sdcdbsrc-goto-sdcdb\InsetSpace ~
31718 o the SDCDB output buffer
31736 sdcdbsrc-mode\InsetSpace ~
31752 Toggles Sdcdbsrc mode (turns it
31768 sdcdb-finish-from-src\InsetSpace ~
31776 SDCDB finish command
31810 Set break for line with point
31825 sdcdbsrc-mode\InsetSpace ~
31841 Toggle Sdcdbsrc mode
31857 dbsrc-srcmode\InsetSpace ~
31881 \begin_layout Chapter
31885 \begin_layout Standard
31886 Here are a few guidelines that will help the compiler generate more efficient
31887 code, some of the tips are specific to this compiler others are generally
31888 good programming practice.
31891 \begin_layout Itemize
31892 Use the smallest data type to represent your data-value.
31893 If it is known in advance that the value is going to be less than 256 then
31894 use an 'unsigned char' instead of a 'short' or 'int'.
31895 Please note, that ANSI C requires both signed and unsigned chars to be
31896 promoted to 'signed int'
31897 \begin_inset LatexCommand index
31898 name "promotion to signed int"
31903 \begin_inset Marginal
31906 \begin_layout Standard
31915 before doing any operation.
31917 \begin_inset LatexCommand index
31918 name "type promotion"
31923 \begin_inset LatexCommand label
31924 name "type promotion"
31928 can be omitted, if the result is the same.
31929 The effect of the promotion rules together with the sign-extension is often
31934 \begin_layout Verse
31937 unsigned char uc = 0xfe;
31939 if (uc * uc < 0) /* this is true! */
31952 \begin_layout Standard
31959 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
31967 \begin_layout Verse
31970 (unsigned char) -12 / (signed char) -3 = ...
31973 \begin_layout Standard
31974 No, the result is not 4:
31977 \begin_layout Verse
31980 (int) (unsigned char) -12 / (int) (signed char) -3 =
31982 (int) (unsigned char)
31983 0xf4 / (int) (signed char) 0xfd =
31985 (int) 0x00f4 / (int) 0xfffd =
31990 (int) 244 / (int) -3 =
31992 (int) -81 = (int) 0xffaf;
31995 \begin_layout Standard
31996 Don't complain, that gcc gives you a different result.
31997 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
31998 Therefore the results are different.
32001 \begin_inset Quotes sld
32005 \begin_inset Quotes srd
32011 \begin_layout Quote
32014 If well-defined overflow characteristics are important and negative values
32015 are not, or if you want to steer clear of sign-extension problems when
32016 manipulating bits or bytes, use one of the corresponding unsigned types.
32017 (Beware when mixing signed and unsigned values in expressions, though.)
32020 character types (especially unsigned char) can be used as "tiny" integers,
32021 doing so is sometimes more trouble than it's worth, due to unpredictable
32022 sign extension and increased code size.
32026 \begin_layout Itemize
32027 Use unsigned when it is known in advance that the value is not going to
32029 This helps especially if you are doing division or multiplication, bit-shifting
32030 or are using an array index.
32033 \begin_layout Itemize
32034 NEVER jump into a LOOP.
32037 \begin_layout Itemize
32038 Declare the variables to be local
32039 \begin_inset LatexCommand index
32040 name "local variables"
32044 whenever possible, especially loop control variables (induction).
32047 \begin_layout Itemize
32048 Have a look at the assembly listing to get a
32049 \begin_inset Quotes sld
32053 \begin_inset Quotes srd
32056 for the code generation.
32059 \begin_layout Section
32060 Porting code from or to other compilers
32061 \begin_inset LatexCommand label
32062 name "sec:Porting-code-to-other-compilers"
32069 \begin_layout Itemize
32070 check whether endianness of the compilers differs and adapt where needed.
32073 \begin_layout Itemize
32074 check the device specific header files
32075 \begin_inset LatexCommand index
32076 name "Header files"
32081 \begin_inset LatexCommand index
32082 name "Include files"
32086 for compiler specific syntax.
32087 Eventually include the file <compiler.h
32088 \begin_inset LatexCommand index
32089 name "compiler.h (include file)"
32094 \begin_inset LatexCommand url
32095 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup"
32099 to allow using common header files.
32102 \begin_inset LatexCommand url
32103 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup"
32110 \begin_layout Itemize
32111 check whether the startup code contains the correct initialization (watchdog,
32115 \begin_layout Itemize
32116 check whether the sizes of short, int, long match.
32119 \begin_layout Itemize
32120 check if some 16 or 32 bit hardware registers require a specific addressing
32121 order (least significant or most significant byte first) and adapt if needed
32130 relate to time and not to lower/upper memory location here, so this is
32135 the same as endianness).
32138 \begin_layout Itemize
32139 check whether the keyword
32143 is used where needed.
32144 The compilers might differ in their optimization characteristics (as different
32145 versions of the same compiler might also use more clever optimizations
32146 this is good idea anyway).
32148 \begin_inset LatexCommand ref
32149 reference "sub:Common-interrupt-pitfall-volatile"
32156 \begin_layout Itemize
32157 check that the compilers are not told to suppress warnings.
32160 \begin_layout Itemize
32161 check and convert compiler specific extensions (interrupts, memory areas,
32165 \begin_layout Itemize
32166 check for differences in type promotion.
32167 Especially check for math operations on
32176 For the sake of C99 compatibility SDCC will probably promote these to
32180 more often than other compilers.
32181 Eventually insert explicit casts to
32190 Also check that the ~\InsetSpace ~
32192 \begin_inset LatexCommand index
32193 name "\\~\\/ Operator"
32200 \begin_inset LatexCommand index
32207 variables, use the !\InsetSpace ~
32210 \begin_inset LatexCommand ref
32211 reference "type promotion"
32216 \begin_inset LatexCommand ref
32217 reference "sec:Compatibility-with-previous"
32224 \begin_layout Itemize
32225 check the assembly code generated for interrupt routines (f.e.
32226 for calls to possibly non-reentrant library functions).
32229 \begin_layout Itemize
32230 check whether timing loops result in proper timing (or preferably consider
32231 a rewrite of the code with timer based delays instead).
32234 \begin_layout Itemize
32235 check for differences in printf parameters (some compilers push (va_arg
32236 \begin_inset LatexCommand index
32237 name "vararg, va\\_arg"
32241 ) char variables as
32245 others push them as
32251 \begin_inset LatexCommand ref
32252 reference "sec:Compatibility-with-previous"
32259 \begin_layout Itemize
32260 check the resulting memory map
32261 \begin_inset LatexCommand index
32267 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
32268 ly idata, pdata, xdata).
32269 Eventually check if unexpected library functions are included.
32272 \begin_layout Section
32274 \begin_inset LatexCommand index
32279 included in the distribution
32282 \begin_layout Standard
32284 \begin_inset Tabular
32285 <lyxtabular version="3" rows="12" columns="3">
32287 <column alignment="left" valignment="top" leftline="true" width="0pt">
32288 <column alignment="left" valignment="top" leftline="true" width="0pt">
32289 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32290 <row topline="true" bottomline="true">
32291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32294 \begin_layout Standard
32302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32305 \begin_layout Standard
32313 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32316 \begin_layout Standard
32325 <row topline="true">
32326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32329 \begin_layout Standard
32331 \begin_inset LatexCommand index
32341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32344 \begin_layout Standard
32345 Simulator for various architectures
32350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32353 \begin_layout Standard
32360 <row topline="true">
32361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32364 \begin_layout Standard
32370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32373 \begin_layout Standard
32375 \begin_inset LatexCommand index
32376 name "Header files"
32381 \begin_inset LatexCommand index
32382 name "Include files"
32391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32394 \begin_layout Standard
32395 sdcc/support/scripts
32401 <row topline="true">
32402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32405 \begin_layout Standard
32411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32414 \begin_layout Standard
32415 header file conversion
32420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32423 \begin_layout Standard
32424 sdcc/support/scripts
32430 <row topline="true">
32431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32434 \begin_layout Standard
32440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32443 \begin_layout Standard
32449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32452 \begin_layout Standard
32468 <row topline="true">
32469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32472 \begin_layout Standard
32478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32481 \begin_layout Standard
32487 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32490 \begin_layout Standard
32506 <row topline="true">
32507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32510 \begin_layout Standard
32516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32519 \begin_layout Standard
32525 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32528 \begin_layout Standard
32544 <row topline="true">
32545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32548 \begin_layout Standard
32554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32557 \begin_layout Standard
32563 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32566 \begin_layout Standard
32582 <row topline="true">
32583 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32586 \begin_layout Standard
32592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32595 \begin_layout Standard
32601 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32604 \begin_layout Standard
32620 <row topline="true">
32621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32624 \begin_layout Standard
32630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32633 \begin_layout Standard
32639 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32642 \begin_layout Standard
32658 <row topline="true">
32659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32662 \begin_layout Standard
32668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32671 \begin_layout Standard
32677 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32680 \begin_layout Standard
32696 <row topline="true" bottomline="true">
32697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32700 \begin_layout Standard
32706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32709 \begin_layout Standard
32711 \begin_inset LatexCommand index
32712 name "packihx (tool)"
32721 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32724 \begin_layout Standard
32749 \begin_layout Section
32751 \begin_inset LatexCommand index
32752 name "Documentation"
32756 included in the distribution
32759 \begin_layout Standard
32761 \begin_inset Tabular
32762 <lyxtabular version="3" rows="10" columns="2">
32764 <column alignment="block" valignment="top" leftline="true" width="40col%">
32765 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
32766 <row topline="true" bottomline="true" endhead="true">
32767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32770 \begin_layout Standard
32778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32781 \begin_layout Standard
32784 Filename / Where to get
32790 <row topline="true">
32791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32794 \begin_layout Standard
32795 SDCC Compiler User Guide
32800 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32803 \begin_layout Standard
32804 You're reading it right now
32816 \begin_inset LatexCommand url
32817 target "http://sdcc.sourceforge.net/doc/sdccman.pdf"
32827 <row topline="true">
32828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32831 \begin_layout Standard
32837 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32840 \begin_layout Standard
32853 \begin_inset LatexCommand url
32854 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog"
32864 <row topline="true">
32865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32868 \begin_layout Standard
32870 \begin_inset LatexCommand index
32871 name "asXXXX (as-gbz80, as-hc08, asx8051, as-z80)"
32876 \begin_inset LatexCommand index
32877 name "Assembler documentation"
32884 \begin_inset LatexCommand index
32890 \begin_inset LatexCommand index
32891 name "Linker documentation"
32900 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32903 \begin_layout Standard
32904 sdcc/as/doc/asxhtm.html
32916 \begin_inset LatexCommand url
32917 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html"
32927 <row topline="true">
32928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32931 \begin_layout Standard
32932 SDCC regression test
32933 \begin_inset LatexCommand index
32934 name "Regression test"
32943 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32946 \begin_layout Standard
32947 sdcc/doc/test_suite_spec.pdf
32959 \begin_inset LatexCommand url
32960 target "http://sdcc.sourceforge.net/doc/test_suite_spec.pdf"
32970 <row topline="true">
32971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32974 \begin_layout Standard
32980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32983 \begin_layout Standard
32996 \begin_inset LatexCommand url
32997 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/"
33007 <row topline="true">
33008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33011 \begin_layout Standard
33012 Notes on debugging with SDCDB
33013 \begin_inset LatexCommand index
33014 name "SDCDB (debugger)"
33023 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33026 \begin_layout Standard
33027 sdcc/debugger/README
33039 \begin_inset LatexCommand url
33040 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README"
33050 <row topline="true">
33051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33054 \begin_layout Standard
33056 \begin_inset LatexCommand index
33061 Software simulator for microcontrollers
33066 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33069 \begin_layout Standard
33099 \begin_inset LatexCommand url
33100 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html"
33110 <row topline="true">
33111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33114 \begin_layout Standard
33115 Temporary notes on the pic16
33116 \begin_inset LatexCommand index
33126 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33129 \begin_layout Standard
33130 sdcc/src/pic16/NOTES
33142 \begin_inset LatexCommand url
33143 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES"
33153 <row topline="true" bottomline="true">
33154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33157 \begin_layout Standard
33158 SDCC internal documentation (debugging file format)
33163 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33166 \begin_layout Standard
33196 \begin_inset LatexCommand url
33197 target "http://sdcc.sourceforge.net/doc/cdbfileformat.pdf"
33216 \begin_layout Section
33217 Related open source tools
33218 \begin_inset LatexCommand label
33219 name "sec:Related-open-source-tools"
33224 \begin_inset LatexCommand index
33225 name "Related tools"
33232 \begin_layout Standard
33234 \begin_inset Tabular
33235 <lyxtabular version="3" rows="16" columns="3">
33237 <column alignment="left" valignment="top" leftline="true" width="0pt">
33238 <column alignment="block" valignment="top" leftline="true" width="30line%">
33239 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
33240 <row topline="true" bottomline="true">
33241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33244 \begin_layout Standard
33252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33255 \begin_layout Standard
33263 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33266 \begin_layout Standard
33275 <row topline="true">
33276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33279 \begin_layout Standard
33281 \begin_inset LatexCommand index
33282 name "gpsim (pic simulator)"
33291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33294 \begin_layout Standard
33300 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33303 \begin_layout Standard
33304 \begin_inset LatexCommand url
33305 target "http://www.dattalo.com/gnupic/gpsim.html"
33315 <row topline="true">
33316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33319 \begin_layout Standard
33321 \begin_inset LatexCommand index
33322 name "gputils (pic tools)"
33331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33334 \begin_layout Standard
33340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33343 \begin_layout Standard
33344 \begin_inset LatexCommand url
33345 target "http://sourceforge.net/projects/gputils"
33355 <row topline="true">
33356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33359 \begin_layout Standard
33365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33368 \begin_layout Standard
33374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33377 \begin_layout Standard
33378 \begin_inset LatexCommand url
33379 target "http://freshmeat.net/projects/flp5/"
33389 <row topline="true">
33390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33393 \begin_layout Standard
33399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33402 \begin_layout Standard
33403 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
33409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33412 \begin_layout Standard
33413 \begin_inset LatexCommand url
33414 target "http://sourceforge.net/projects/ec2drv"
33424 <row topline="true">
33425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33428 \begin_layout Standard
33430 \begin_inset LatexCommand index
33431 name "indent (source formatting tool)"
33440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33443 \begin_layout Standard
33444 Formats C source - Master of the white spaces
33449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33452 \begin_layout Standard
33453 \begin_inset LatexCommand url
33454 target "http://directory.fsf.org/GNU/indent.html"
33464 <row topline="true">
33465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33468 \begin_layout Standard
33470 \begin_inset LatexCommand index
33471 name "srecord (bin, hex, ... tool)"
33480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33483 \begin_layout Standard
33484 Object file conversion, checksumming, ...
33489 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33492 \begin_layout Standard
33493 \begin_inset LatexCommand url
33494 target "http://sourceforge.net/projects/srecord"
33504 <row topline="true">
33505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33508 \begin_layout Standard
33510 \begin_inset LatexCommand index
33511 name "objdump (tool)"
33520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33523 \begin_layout Standard
33524 Object file conversion, ...
33529 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33532 \begin_layout Standard
33533 Part of binutils (should be there anyway)
33539 <row topline="true">
33540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33543 \begin_layout Standard
33549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33552 \begin_layout Standard
33553 8051 monitor (hex up-/download, single step, disassemble)
33558 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33561 \begin_layout Standard
33562 \begin_inset LatexCommand url
33563 target "http://sourceforge.net/projects/cmon51"
33573 <row topline="true">
33574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33577 \begin_layout Standard
33579 \begin_inset LatexCommand index
33580 name "doxygen (source documentation tool)"
33589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33592 \begin_layout Standard
33593 Source code documentation system
33598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33601 \begin_layout Standard
33602 \begin_inset LatexCommand url
33603 target "http://www.doxygen.org"
33613 <row topline="true">
33614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33617 \begin_layout Standard
33623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33626 \begin_layout Standard
33627 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
33632 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33635 \begin_layout Standard
33636 \begin_inset LatexCommand url
33637 target "http://www.kdevelop.org"
33647 <row topline="true">
33648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33651 \begin_layout Standard
33657 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33660 \begin_layout Standard
33661 8051 monitor (hex up-/download, single step, disassemble)
33666 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33669 \begin_layout Standard
33670 \begin_inset LatexCommand url
33671 target "http://www.pjrc.com/tech/8051/paulmon2.html"
33681 <row topline="true">
33682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33685 \begin_layout Standard
33687 \begin_inset LatexCommand index
33688 name "splint (syntax checking tool)"
33697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33700 \begin_layout Standard
33701 Statically checks c sources (see
33702 \begin_inset LatexCommand ref
33703 reference "lyx:more-pedantic-SPLINT"
33712 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33715 \begin_layout Standard
33716 \begin_inset LatexCommand url
33717 target "http://www.splint.org"
33727 <row topline="true" bottomline="true">
33728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33731 \begin_layout Standard
33733 \begin_inset LatexCommand index
33734 name "DDD (debugger)"
33743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33746 \begin_layout Standard
33747 Debugger, serves nicely as GUI to SDCDB
33748 \begin_inset LatexCommand index
33749 name "SDCDB (debugger)"
33758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33761 \begin_layout Standard
33762 \begin_inset LatexCommand url
33763 target "http://www.gnu.org/software/ddd/"
33773 <row bottomline="true">
33774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33777 \begin_layout Standard
33779 \begin_inset LatexCommand index
33785 \begin_inset LatexCommand index
33786 name "d52 (disassembler)"
33795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33798 \begin_layout Standard
33799 Disassembler, can count instruction cycles
33800 \begin_inset LatexCommand index
33801 name "instruction cycles (count)"
33805 , use with options -pnd
33810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33813 \begin_layout Standard
33814 \begin_inset LatexCommand url
33815 target "http://www.8052.com/users/disasm/"
33825 <row bottomline="true">
33826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33829 \begin_layout Standard
33831 \begin_inset LatexCommand index
33841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33844 \begin_layout Standard
33845 Cross platform build system, generates Makefiles
33846 \begin_inset LatexCommand index
33851 and project workspaces
33852 \begin_inset LatexCommand index
33853 name "project workspace"
33862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33865 \begin_layout Standard
33866 \begin_inset LatexCommand url
33867 target "http://www.cmake.org"
33875 and a dedicated wiki entry:
33876 \begin_inset LatexCommand url
33877 target "http://www.cmake.org/Wiki/CmakeSdcc"
33896 \begin_layout Section
33897 Related documentation / recommended reading
33900 \begin_layout Standard
33902 \begin_inset Tabular
33903 <lyxtabular version="3" rows="7" columns="3">
33905 <column alignment="left" valignment="top" leftline="true" width="0pt">
33906 <column alignment="left" valignment="top" leftline="true" width="0">
33907 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
33908 <row topline="true" bottomline="true">
33909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33912 \begin_layout Standard
33920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33923 \begin_layout Standard
33931 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33934 \begin_layout Standard
33943 <row topline="true">
33944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33947 \begin_layout Standard
33962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33965 \begin_layout Standard
33967 \begin_inset LatexCommand index
33968 name "C Reference card"
33977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33980 \begin_layout Standard
33981 \begin_inset LatexCommand url
33982 target "http://refcards.com/refcards/c/index.html"
33992 <row topline="true">
33993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33996 \begin_layout Standard
34002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34005 \begin_layout Standard
34007 \begin_inset LatexCommand index
34017 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34020 \begin_layout Standard
34021 \begin_inset LatexCommand url
34022 target "http://www.c-faq.com"
34032 <row topline="true">
34033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34036 \begin_layout Standard
34042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34045 \begin_layout Standard
34046 \begin_inset Quotes sld
34050 \begin_inset Quotes srd
34058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34061 \begin_layout Standard
34064 \begin_inset LatexCommand url
34065 target "http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899"
34075 <row topline="true">
34076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34079 \begin_layout Standard
34085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34088 \begin_layout Standard
34089 \begin_inset Quotes sld
34092 Extensions for Embedded C
34093 \begin_inset Quotes srd
34101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34104 \begin_layout Standard
34107 \begin_inset LatexCommand url
34108 target "http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf"
34118 <row topline="true">
34119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34122 \begin_layout Standard
34128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34131 \begin_layout Standard
34132 Latest datasheet of target CPU
34137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34140 \begin_layout Standard
34147 <row topline="true" bottomline="true">
34148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34151 \begin_layout Standard
34157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34160 \begin_layout Standard
34161 Revision history of datasheet
34166 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34169 \begin_layout Standard
34185 \begin_layout Section
34186 Application notes specifically for SDCC
34189 \begin_layout Standard
34190 SDCC makes no claims about the completeness of this list and about up-to-datenes
34191 s or correctness of the application notes
34192 \begin_inset LatexCommand index
34193 name "Application notes"
34200 \begin_layout Standard
34204 \begin_inset Tabular
34205 <lyxtabular version="3" rows="7" columns="3">
34207 <column alignment="block" valignment="top" leftline="true" width="17col%">
34208 <column alignment="block" valignment="top" leftline="true" width="27col%">
34209 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
34210 <row topline="true" bottomline="true">
34211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34214 \begin_layout Standard
34223 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
34226 \begin_layout Standard
34235 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34238 \begin_layout Standard
34248 <row topline="true">
34249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34252 \begin_layout Standard
34260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34263 \begin_layout Standard
34266 Using the SDCC Compiler for the DS80C400
34267 \begin_inset LatexCommand index
34277 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34280 \begin_layout Standard
34283 \begin_inset LatexCommand url
34284 target "http://pdfserv.maxim-ic.com/en/an/AN3346.pdf"
34294 <row topline="true">
34295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34298 \begin_layout Standard
34306 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
34309 \begin_layout Standard
34312 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
34313 \begin_inset LatexCommand index
34318 Family of Microcontrollers
34323 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34326 \begin_layout Standard
34329 \begin_inset LatexCommand url
34330 target "http://pdfserv.maxim-ic.com/en/an/AN3477.pdf"
34340 <row topline="true">
34341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34344 \begin_layout Standard
34347 Silicon Laboratories / Cygnal
34352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34355 \begin_layout Standard
34358 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
34359 \begin_inset LatexCommand index
34369 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34372 \begin_layout Standard
34375 \begin_inset LatexCommand url
34376 target "http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf"
34386 <row topline="true">
34387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34390 \begin_layout Standard
34393 Ramtron / Goal Semiconductor
34398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34401 \begin_layout Standard
34404 Interfacing SDCC to Syn and Textpad
34409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34412 \begin_layout Standard
34415 \begin_inset LatexCommand url
34416 target "http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp"
34426 <row topline="true">
34427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34430 \begin_layout Standard
34433 Ramtron / Goal Semiconductor
34438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34441 \begin_layout Standard
34444 Installing and Configuring SDCC and Crimson Editor
34449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34452 \begin_layout Standard
34455 \begin_inset LatexCommand url
34456 target "http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp"
34466 <row topline="true" bottomline="true">
34467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34470 \begin_layout Standard
34478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34481 \begin_layout Standard
34484 MSC12xx Programming with SDCC
34489 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34492 \begin_layout Standard
34495 \begin_inset LatexCommand url
34496 target "http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf"
34513 \begin_layout Section
34517 \begin_layout Standard
34518 Some questions answered, some pointers given - it might be time to in turn
34526 \begin_layout Itemize
34527 can you solve your project with the selected microcontroller? Would you
34528 find out early or rather late that your target is too small/slow/whatever?
34529 Can you switch to a slightly better device if it doesn't fit?
34532 \begin_layout Itemize
34533 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
34534 and/or another programming language be more adequate? Would an operating
34535 system on the target device help?
34538 \begin_layout Itemize
34539 if you solved the problem, will the marketing department be happy?
34542 \begin_layout Itemize
34543 if the marketing department is happy, will customers be happy?
34546 \begin_layout Itemize
34547 if you're the project manager, marketing department and maybe even the customer
34548 in one person, have you tried to see the project from the outside?
34551 \begin_layout Itemize
34552 is the project done if you think it is done? Or is just that other interface/pro
34553 tocol/feature/configuration/option missing? How about website, manual(s),
34554 internationali(z|s)ation, packaging, labels, 2nd source for components,
34555 electromagnetic compatability/interference, documentation for production,
34556 production test software, update mechanism, patent issues?
34559 \begin_layout Itemize
34560 is your project adequately positioned in that magic triangle: fame, fortune,
34564 \begin_layout Standard
34565 Maybe not all answers to these questions are known and some answers may
34570 , nevertheless knowing these questions may help you to avoid burnout
34574 \begin_layout Standard
34575 burnout is bad for electronic devices, programmers and motorcycle tyres
34581 Chances are you didn't want to hear some of them...
34584 \begin_layout Chapter
34586 \begin_inset LatexCommand index
34594 \begin_layout Standard
34595 SDCC has grown to be a large project.
34596 The compiler alone (without the preprocessor, assembler and linker) is
34597 well over 150,000 lines of code (blank stripped).
34598 The open source nature of this project is a key to its continued growth
34600 You gain the benefit and support of many active software developers and
34602 Is SDCC perfect? No, that's why we need your help.
34603 The developers take pride in fixing reported bugs.
34604 You can help by reporting the bugs and helping other SDCC users.
34605 There are lots of ways to contribute, and we encourage you to take part
34606 in making SDCC a great software package.
34610 \begin_layout Standard
34611 The SDCC project is hosted on the SDCC sourceforge site at
34612 \begin_inset LatexCommand htmlurl
34613 target "http://sourceforge.net/projects/sdcc"
34618 You'll find the complete set of mailing lists
34619 \begin_inset LatexCommand index
34620 name "Mailing list(s)"
34624 , forums, bug reporting system, patch submission
34625 \begin_inset LatexCommand index
34626 name "Patch submission"
34631 \begin_inset LatexCommand index
34636 area and Subversion code repository
34637 \begin_inset LatexCommand index
34638 name "Subversion code repository"
34645 \begin_layout Section
34647 \begin_inset LatexCommand index
34648 name "Bug reporting"
34653 \begin_inset LatexCommand index
34654 name "Reporting bugs"
34661 \begin_layout Standard
34662 The recommended way of reporting bugs is using the infrastructure of the
34664 You can follow the status of bug reports there and have an overview about
34668 \begin_layout Standard
34669 Bug reports are automatically forwarded to the developer mailing list and
34670 will be fixed ASAP.
34671 When reporting a bug, it is very useful to include a small test program
34672 (the smaller the better) which reproduces the problem.
34673 If you can isolate the problem by looking at the generated assembly code,
34674 this can be very helpful.
34675 Compiling your program with the -
34679 \begin_layout Standard
34689 \begin_inset LatexCommand index
34690 name "-\\/-dumpall"
34694 option can sometimes be useful in locating optimization problems.
34695 When reporting a bug please make sure you:
34698 \begin_layout Enumerate
34699 Attach the code you are compiling with SDCC.
34703 \begin_layout Enumerate
34704 Specify the exact command you use to run SDCC, or attach your Makefile.
34708 \begin_layout Enumerate
34709 Specify the SDCC version (type "
34715 "), your platform, and operating system.
34719 \begin_layout Enumerate
34720 Provide an exact copy of any error message or incorrect output.
34724 \begin_layout Enumerate
34725 Put something meaningful in the subject of your message.
34728 \begin_layout Standard
34729 Please attempt to include these 5 important parts, as applicable, in all
34730 requests for support or when reporting any problems or bugs with SDCC.
34731 Though this will make your message lengthy, it will greatly improve your
34732 chance that SDCC users and developers will be able to help you.
34733 Some SDCC developers are frustrated by bug reports without code provided
34734 that they can use to reproduce and ultimately fix the problem, so please
34735 be sure to provide sample code if you are reporting a bug!
34738 \begin_layout Standard
34739 Please have a short check that you are using a recent version of SDCC and
34740 the bug is not yet known.
34741 This is the link for reporting bugs:
34742 \begin_inset LatexCommand htmlurl
34743 target "http://sourceforge.net/tracker/?group_id=599&atid=100599"
34748 With SDCC on average having more than 200 downloads
34749 \begin_inset LatexCommand index
34754 on sourceforge per day
34758 \begin_layout Standard
34759 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
34760 between 2002 and 2005.
34761 This does not include other methods of distribution.
34766 there must be some users.
34767 So it's not exactly easy to find a new bug.
34768 If you find one we need it:
34770 reporting bugs is good
34775 \begin_layout Section
34776 Requesting Features
34777 \begin_inset LatexCommand label
34778 name "sub:Requesting-Features"
34783 \begin_inset LatexCommand index
34784 name "Feature request"
34789 \begin_inset LatexCommand index
34790 name "Requesting features"
34797 \begin_layout Standard
34798 Like bug reports feature requests are forwarded to the developer mailing
34800 This is the link for requesting features:
34801 \begin_inset LatexCommand htmlurl
34802 target "http://sourceforge.net/tracker/?group_id=599&atid=350599"
34809 \begin_layout Section
34813 \begin_layout Standard
34814 Like bug reports contributed patches are forwarded to the developer mailing
34816 This is the link for submitting patches
34817 \begin_inset LatexCommand index
34818 name "Patch submission"
34823 \begin_inset LatexCommand url
34824 target "http://sourceforge.net/tracker/?group_id=599&atid=300599"
34831 \begin_layout Standard
34832 You need to specify some parameters to the
34836 command for the patches to be useful.
34837 If you modified more than one file a patch created f.e.
34842 \begin_inset Quotes sld
34845 diff -Naur unmodified_directory modified_directory >my_changes.patch
34846 \begin_inset Quotes srd
34852 will be fine, otherwise
34856 \begin_inset Quotes sld
34859 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
34860 \begin_inset Quotes srd
34869 \begin_layout Section
34873 \begin_layout Standard
34874 These links should take you directly to the
34875 \begin_inset LatexCommand url
34876 name "Mailing lists"
34877 target "http://sourceforge.net/mail/?group_id=599"
34885 \begin_layout Standard
34886 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
34887 automated messages (mid 2003)
34893 \begin_inset LatexCommand url
34895 target "http://sourceforge.net/forum/?group_id=599"
34900 \begin_inset LatexCommand index
34901 name "Mailing list(s)"
34905 and forums are archived and searchable so if you are lucky someone already
34906 had a similar problem.
34907 While mails to the lists themselves are delivered promptly their web front
34908 end on sourceforge sometimes shows a severe time lag (up to several weeks),
34909 if you're seriously using SDCC please consider subscribing to the lists.
34912 \begin_layout Section
34916 \begin_layout Standard
34917 You can follow the status of the Subversion version
34918 \begin_inset LatexCommand index
34923 of SDCC by watching the Changelog
34924 \begin_inset LatexCommand index
34929 in the Subversion repository
34932 \begin_inset LatexCommand htmlurl
34933 target "http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog"
34940 \begin_layout Section
34941 Subversion Source Code Repository
34944 \begin_layout Standard
34954 \begin_layout Standard
34968 or the filenames of the snapshot versions of SDCC include date and its
34970 \begin_inset LatexCommand index
34971 name "Subversion code repository"
34976 Subversion allows to download the source of recent or previous versions
34978 \begin_inset LatexCommand url
34979 target "http://sourceforge.net/svn/?group_id=599"
34983 (by number or by date).
34984 An on-line source code browser and detailled instructions are also available
34986 SDCC versions starting from 1999 up to now are available (currently the
34987 versions prior to the conversion from cvs
34988 \begin_inset LatexCommand index
34989 name "cvs|see{Subversion}"
34993 to Subversion (April 2006) are either by accessible by Subversion or by
34997 \begin_layout Section
34999 \begin_inset LatexCommand index
35000 name "Release policy"
35007 \begin_layout Standard
35008 Historically there often were long delays between official releases and
35009 the sourceforge download area tends to get not updated at all.
35010 Excuses in the past might have referred to problems with live range analysis,
35011 but as this was fixed a while ago, the current problem is that another
35012 excuse has to be found.
35013 Kidding aside, we have to get better there! On the other hand there are
35014 daily snapshots available at
35015 \begin_inset LatexCommand htmlurl
35017 target "http://sdcc.sourceforge.net/snap.php"
35021 , and you can always build the very last version (hopefully with many bugs
35022 fixed, and features added) from the source code available at
35023 \begin_inset LatexCommand htmlurl
35025 target "http://sdcc.sourceforge.net/snap.php#Source"
35031 \begin_inset LatexCommand index
35037 \begin_inset LatexCommand index
35043 \begin_inset LatexCommand url
35044 target "http://sdcc.wiki.sourceforge.net/"
35048 also holds some information about past and future releases.
35051 \begin_layout Section
35053 \begin_inset LatexCommand index
35061 \begin_layout Standard
35062 You'll find some small examples in the directory
35064 sdcc/device/examples/.
35067 More examples and libraries are available at
35069 The SDCC Open Knowledge Resource
35070 \begin_inset LatexCommand url
35071 target "http://sdccokr.dl9sec.de/"
35078 \begin_inset LatexCommand url
35079 target "http://www.pjrc.com/tech/8051/"
35086 \begin_layout Standard
35087 \begin_inset Note Note
35090 \begin_layout Standard
35091 I did insert a reference to Paul's web site here although it seems rather
35092 dedicated to a specific 8032 board (I think it's okay because it f.e.
35093 shows LCD/Harddisc interface and has a free 8051 monitor.
35094 Independent 8032 board vendors face hard competition of heavily subsidized
35095 development boards anyway).
35098 \begin_layout Standard
35099 Maybe we should include some links to real world applications.
35100 Preferably pointer to pointers (one for each architecture) so this stays
35109 \begin_layout Section
35111 \begin_inset LatexCommand label
35112 name "sec:Quality-control"
35117 \begin_inset LatexCommand index
35118 name "Quality control"
35125 \begin_layout Standard
35126 The compiler is passed through snaphot build compile and build checks.
35132 \begin_inset LatexCommand index
35133 name "Regression test"
35137 check that SDCC itself compiles flawlessly on several host platforms (i386,
35138 Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
35139 and checks the quality of the code generated by SDCC by running the code
35140 for several target platforms through simulators.
35141 The regression test suite comprises more than 100 files which expand to
35142 more than 500 test cases which include more than 4500 tests.
35143 The results of these tests are published daily on SDCC's snapshot page
35144 (click on the red or green symbols on the right side of
35145 \begin_inset LatexCommand url
35146 target "http://sdcc.sourceforge.net/snap.php"
35153 \begin_layout Standard
35154 There is a separate document
35157 \begin_inset LatexCommand index
35165 \begin_inset LatexCommand url
35166 target "http://sdcc.sourceforge.net/doc/test_suite_spec.pdf"
35170 about the regression test suite.
35173 \begin_layout Standard
35174 You'll find the test code in the directory
35176 sdcc/support/regression
35179 You can run these tests manually by running
35183 in this directory (or f.e.
35188 \begin_inset Quotes sld
35192 \begin_inset Quotes srd
35198 if you don't want to run the complete tests).
35199 The test code might also be interesting if you want to look for examples
35200 \begin_inset LatexCommand index
35205 checking corner cases of SDCC or if you plan to submit patches
35206 \begin_inset LatexCommand index
35207 name "Patch submission"
35214 \begin_layout Standard
35215 The PIC14 port uses a different set of regression tests
35216 \begin_inset LatexCommand index
35217 name "Regression test (PIC14)"
35221 , you'll find them in the directory
35223 sdcc/src/regression
35228 \begin_layout Section
35229 Use of SDCC in Education
35232 \begin_layout Standard
35241 \begin_layout Standard
35242 the phrase "use in education" might evoke the association "
35246 fit for use in education".
35247 This connotation is not intended but nevertheless risked as the licensing
35248 of SDCC makes it difficult to offer educational discounts
35254 If your rationales are to:
35257 \begin_layout Enumerate
35258 give students a chance to understand the
35262 steps of code generation
35265 \begin_layout Enumerate
35266 have a curriculum that can be extended for years.
35267 Then you could use an fpga board as target and your curriculum will seamlessly
35268 extend from logic synthesis (
35269 \begin_inset LatexCommand url
35270 name "http://www.opencores.org"
35271 target "opencores.org"
35276 \begin_inset LatexCommand url
35278 target "http://www.oregano.at/ip/ip01.htm"
35282 ), over assembly programming, to C to FPGA compilers (
35283 \begin_inset LatexCommand url
35285 target "http://sf.net/projects/fpgac"
35292 \begin_layout Enumerate
35293 be able to insert excursions about skills like using a revision control
35294 system, submitting/applying patches, using a type-setting (as opposed to
35295 word-processing) engine LyX/LaTeX, using
35296 \begin_inset LatexCommand url
35298 target "http://www.sf.net"
35303 \begin_inset LatexCommand url
35305 target "http://en.wikipedia.org/wiki/Netiquette"
35309 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
35310 Source Software, CPU simulation, compiler regression tests
35311 \begin_inset LatexCommand index
35312 name "Regression test"
35319 And if there should be a shortage of ideas then you can always point students
35320 to the ever-growing feature request list
35321 \begin_inset LatexCommand htmlurl
35322 target "http://sourceforge.net/tracker/?group_id=599&atid=350599"
35329 \begin_layout Enumerate
35330 not tie students to a specific host platform and instead allow them to use
35335 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
35337 \begin_inset LatexCommand url
35339 target "http://www.laptop.org"
35346 \begin_layout Enumerate
35347 not encourage students to use illegal copies of educational software
35350 \begin_layout Enumerate
35351 be immune to licensing/availability/price changes of the chosen tool chain
35354 \begin_layout Enumerate
35355 be able to change to a new target platform without having to adopt a new
35359 \begin_layout Enumerate
35360 have complete control over and insight into the tool chain
35363 \begin_layout Enumerate
35364 make your students aware about the pros and cons of open source software
35368 \begin_layout Enumerate
35369 give back to the public as you are probably at least partially publicly
35373 \begin_layout Enumerate
35374 give students a chance to publicly prove their skills and to possibly see
35375 a world wide impact
35378 \begin_layout Standard
35379 then SDCC is probably among the first choices.
35380 Well, probably SDCC might be the only choice.
35385 \begin_layout Chapter
35386 SDCC Technical Data
35389 \begin_layout Section
35391 \begin_inset LatexCommand index
35392 name "Optimizations"
35399 \begin_layout Standard
35400 SDCC performs a host of standard optimizations in addition to some MCU specific
35405 \begin_layout Subsection
35406 Sub-expression Elimination
35407 \begin_inset LatexCommand index
35408 name "Subexpression elimination"
35415 \begin_layout Standard
35416 The compiler does local and
35435 \begin_layout Verse
35443 \begin_layout Standard
35444 will be translated to
35447 \begin_layout Verse
35457 \begin_layout Standard
35458 Some subexpressions are not as obvious as the above example, e.g.:
35461 \begin_layout Verse
35469 \begin_layout Standard
35470 In this case the address arithmetic a->b[i] will be computed only once;
35471 the equivalent code in C would be.
35474 \begin_layout Verse
35484 \begin_layout Standard
35485 The compiler will try to keep these temporary variables in registers.
35488 \begin_layout Subsection
35489 Dead-Code Elimination
35490 \begin_inset LatexCommand index
35491 name "Dead-code elimination"
35498 \begin_layout Verse
35513 i = 1; \InsetSpace ~
35522 global = 1;\InsetSpace ~
35536 global = 3;\InsetSpace ~
35542 \begin_layout Standard
35546 \begin_layout Verse
35562 \begin_layout Subsection
35564 \begin_inset LatexCommand index
35565 name "Copy propagation"
35572 \begin_layout Verse
35596 \begin_layout Standard
35600 \begin_layout Verse
35624 \begin_layout Standard
35625 Note: the dead stores created by this copy propagation will be eliminated
35626 by dead-code elimination.
35629 \begin_layout Subsection
35631 \begin_inset LatexCommand index
35632 name "Loop optimization"
35637 \begin_inset LatexCommand label
35638 name "sub:Loop-Optimizations"
35645 \begin_layout Standard
35646 Two types of loop optimizations are done by SDCC
35654 of loop induction variables.
35655 In addition to the strength reduction the optimizer marks the induction
35656 variables and the register allocator tries to keep the induction variables
35657 in registers for the duration of the loop.
35658 Because of this preference of the register allocator
35659 \begin_inset LatexCommand index
35660 name "Register allocation"
35664 , loop induction optimization causes an increase in register pressure, which
35665 may cause unwanted spilling of other temporary variables into the stack
35666 \begin_inset LatexCommand index
35672 The compiler will generate a warning message when it is forced to allocate
35673 extra space either on the stack or data space.
35674 If this extra space allocation is undesirable then induction optimization
35675 can be eliminated either for the entire source file (with -
35679 \begin_layout Standard
35688 -noinduction option) or for a given function only using #pragma\InsetSpace ~
35690 \begin_inset LatexCommand index
35691 name "\\#pragma noinduction"
35702 \begin_layout Verse
35705 for (i = 0 ; i < 100 ; i ++)
35714 \begin_layout Standard
35718 \begin_layout Verse
35723 for (i = 0; i < 100; i++)
35732 \begin_layout Standard
35733 As mentioned previously some loop invariants are not as apparent, all static
35734 address computations are also moved out of the loop.
35739 \begin_inset LatexCommand index
35740 name "Strength reduction"
35744 , this optimization substitutes an expression by a cheaper expression:
35747 \begin_layout Verse
35750 for (i=0;i < 100; i++)
35759 \begin_layout Standard
35763 \begin_layout Verse
35770 for (i=0;i< 100;i++) {
35776 ar[itemp1] = itemp2;
35794 \begin_layout Standard
35795 The more expensive multiplication
35796 \begin_inset LatexCommand index
35797 name "Multiplication"
35801 is changed to a less expensive addition.
35804 \begin_layout Subsection
35806 \begin_inset LatexCommand index
35807 name "Loop reversing"
35814 \begin_layout Standard
35815 This optimization is done to reduce the overhead of checking loop boundaries
35816 for every iteration.
35817 Some simple loops can be reversed and implemented using a
35818 \begin_inset Quotes eld
35821 decrement and jump if not zero
35822 \begin_inset Quotes erd
35826 SDCC checks for the following criterion to determine if a loop is reversible
35827 (note: more sophisticated compilers use data-dependency analysis to make
35828 this determination, SDCC uses a more simple minded analysis).
35831 \begin_layout Itemize
35832 The 'for' loop is of the form
35838 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
35848 \begin_layout Itemize
35849 The <for body> does not contain
35850 \begin_inset Quotes eld
35854 \begin_inset Quotes erd
35858 \begin_inset Quotes erd
35864 \begin_layout Itemize
35865 All goto's are contained within the loop.
35868 \begin_layout Itemize
35869 No function calls within the loop.
35872 \begin_layout Itemize
35873 The loop control variable <sym> is not assigned any value within the loop
35876 \begin_layout Itemize
35877 The loop control variable does NOT participate in any arithmetic operation
35881 \begin_layout Itemize
35882 There are NO switch statements in the loop.
35885 \begin_layout Subsection
35886 Algebraic Simplifications
35889 \begin_layout Standard
35890 SDCC does numerous algebraic simplifications, the following is a small sub-set
35891 of these optimizations.
35894 \begin_layout Verse
35897 i = j + 0;\InsetSpace ~
35901 /* changed to: */\InsetSpace ~
35907 i /= 2;\InsetSpace ~
35914 /* changed to: */\InsetSpace ~
35921 = j - j;\InsetSpace ~
35925 /* changed to: */\InsetSpace ~
35931 i = j / 1;\InsetSpace ~
35935 /* changed to: */\InsetSpace ~
35942 \begin_layout Standard
35943 Note the subexpressions
35944 \begin_inset LatexCommand index
35945 name "Subexpression"
35949 given above are generally introduced by macro expansions or as a result
35950 of copy/constant propagation.
35953 \begin_layout Subsection
35954 'switch' Statements
35955 \begin_inset LatexCommand label
35956 name "sub:'switch'-Statements"
35961 \begin_inset LatexCommand index
35962 name "switch statement"
35969 \begin_layout Standard
35970 SDCC can optimize switch statements to jump tables
35971 \begin_inset LatexCommand index
35977 It makes the decision based on an estimate of the generated code size.
35978 SDCC is quite liberal in the requirements for jump table generation:
35981 \begin_layout Itemize
35982 The labels need not be in order, and the starting number need not be one
35983 or zero, the case labels are in numerical sequence or not too many case
35984 labels are missing.
35988 \begin_layout Verse
35991 switch(i) {\InsetSpace ~
36022 case 4: ...\InsetSpace ~
36054 case 5: ...\InsetSpace ~
36086 case 3: ...\InsetSpace ~
36117 case 6: ...\InsetSpace ~
36149 case 7: ...\InsetSpace ~
36181 case 8: ...\InsetSpace ~
36213 case 9: ...\InsetSpace ~
36245 case 10: ...\InsetSpace ~
36276 case 11: ...\InsetSpace ~
36343 \begin_layout Standard
36344 Both the above switch statements will be implemented using a jump-table.
36345 The example to the right side is slightly more efficient as the check for
36346 the lower boundary of the jump-table is not needed.
36350 \begin_layout Itemize
36351 The number of case labels is not larger than supported by the target architectur
36355 \begin_layout Itemize
36356 If the case labels are not in numerical sequence ('gaps' between cases)
36357 SDCC checks whether a jump table with additionally inserted dummy cases
36358 is still attractive.
36362 \begin_layout Itemize
36363 If the starting number is not zero and a check for the lower boundary of
36364 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
36369 \begin_layout Standard
36370 Switch statements which have large gaps in the numeric sequence or those
36371 that have too many case labels can be split into more than one switch statement
36372 for efficient code generation, e.g.:
36375 \begin_layout Verse
36453 \begin_layout Standard
36454 If the above switch statement is broken down into two switch statements
36457 \begin_layout Verse
36500 \begin_layout Standard
36504 \begin_layout Verse
36547 \begin_layout Standard
36548 then both the switch statements will be implemented using jump-tables whereas
36549 the unmodified switch statement will not be.
36552 \begin_layout Standard
36553 \begin_inset Note Note
36556 \begin_layout Standard
36557 There might be reasons which SDCC cannot know about to either favour or
36558 not favour jump tables.
36559 If the target system has to be as quick for the last switch case as for
36560 the first (pro jump table), or if the switch argument is known to be zero
36561 in the majority of the cases (contra jump table).
36569 \begin_layout Standard
36570 The pragma nojtbound
36571 \begin_inset LatexCommand index
36572 name "\\#pragma nojtbound"
36576 can be used to turn off checking the
36589 It has no effect if a default label is supplied.
36590 Use of this pragma is dangerous: if the switch
36591 \begin_inset LatexCommand index
36592 name "switch statement"
36596 argument is not matched by a case statement the processor will happily
36600 \begin_layout Subsection
36601 Bit-shifting Operations
36602 \begin_inset LatexCommand index
36603 name "Bit shifting"
36610 \begin_layout Standard
36611 Bit shifting is one of the most frequently used operation in embedded programmin
36613 SDCC tries to implement bit-shift operations in the most efficient way
36617 \begin_layout Verse
36630 \begin_layout Standard
36631 generates the following code:
36634 \begin_layout Verse
36649 \begin_layout Standard
36650 In general SDCC will never setup a loop if the shift count is known.
36654 \begin_layout Verse
36667 \begin_layout Standard
36671 \begin_layout Verse
36695 \begin_layout Subsection
36697 \begin_inset LatexCommand index
36698 name "Bit rotation"
36705 \begin_layout Standard
36706 A special case of the bit-shift operation is bit rotation
36707 \begin_inset LatexCommand index
36708 name "rotating bits"
36712 , SDCC recognizes the following expression to be a left bit-rotation:
36715 \begin_layout Verse
36723 char i;\InsetSpace ~
36734 /* unsigned is needed for rotation */
36739 i = ((i << 1) | (i >> 7));
36748 \begin_layout Standard
36749 will generate the following code:
36752 \begin_layout Verse
36769 \begin_layout Standard
36770 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
36771 ns of this case will also be recognized as bit-rotation, i.e.:
36774 \begin_layout Verse
36777 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
36780 \begin_layout Subsection
36781 Nibble and Byte Swapping
36784 \begin_layout Standard
36785 Other special cases of the bit-shift operations are nibble or byte swapping
36786 \begin_inset LatexCommand index
36787 name "swapping nibbles/bytes"
36791 , SDCC recognizes the following expressions:
36794 \begin_layout Verse
36815 i = ((i << 4) | (i >> 4));
36821 j = ((j << 8) | (j >> 8));
36824 \begin_layout Standard
36825 and generates a swap instruction for the nibble swapping
36826 \begin_inset LatexCommand index
36827 name "Nibble swapping"
36831 or move instructions for the byte swapping
36832 \begin_inset LatexCommand index
36833 name "Byte swapping"
36839 \begin_inset Quotes sld
36843 \begin_inset Quotes srd
36846 example can be used to convert from little to big-endian or vice versa.
36847 If you want to change the endianness of a
36851 integer you have to cast to
36858 \begin_layout Standard
36859 Note that SDCC stores numbers in little-endian
36863 \begin_layout Standard
36864 Usually 8-bit processors don't care much about endianness.
36865 This is not the case for the standard 8051 which only has an instruction
36871 \begin_inset LatexCommand index
36876 -datapointer so little-endian is the more efficient byte order.
36882 \begin_inset LatexCommand index
36883 name "little-endian"
36888 \begin_inset LatexCommand index
36894 lowest order first).
36897 \begin_layout Subsection
36899 \begin_inset LatexCommand index
36900 name "Highest Order Bit"
36905 \begin_inset LatexCommand index
36906 name "Any Order Bit"
36913 \begin_layout Standard
36914 It is frequently required to obtain the highest order bit of an integral
36915 type (long, int, short or char types).
36916 Also obtaining any other order bit is not uncommon.
36917 SDCC recognizes the following expressions to yield the highest order bit
36918 and generates optimized code for it, e.g.:
36921 \begin_layout Verse
36932 unsigned char hob1, aob1;
36936 bit hob2, hob3, aob2,
36946 hob1 = (gint >> 15) & 1;
36950 hob2 = (gint >> 15) & 1;
36954 hob3 = gint & 0x8000;
36959 aob1 = (gint >> 9) & 1;
36963 aob2 = (gint >> 8) & 1;
36967 aob3 = gint & 0x0800;
36977 \begin_layout Standard
36978 will generate the following code:
36981 \begin_layout Verse
37012 000A E5*01\InsetSpace ~
37039 000C 23\InsetSpace ~
37070 000D 54 01\InsetSpace ~
37098 000F F5*02\InsetSpace ~
37153 0011 E5*01\InsetSpace ~
37181 0013 33\InsetSpace ~
37211 0014 92*00\InsetSpace ~
37267 0016 E5*01\InsetSpace ~
37294 0018 33\InsetSpace ~
37324 0019 92*01\InsetSpace ~
37380 001B E5*01\InsetSpace ~
37439 001E 54 01\InsetSpace ~
37466 0020 F5*03\InsetSpace ~
37522 0022 E5*01\InsetSpace ~
37549 0024 13\InsetSpace ~
37579 0025 92*02\InsetSpace ~
37635 0027 E5*01\InsetSpace ~
37690 002B 92*03\InsetSpace ~
37718 \begin_layout Standard
37719 Other variations of these cases however will
37724 They are standard C expressions, so I heartily recommend these be the only
37725 way to get the highest order bit, (it is portable).
37726 Of course it will be recognized even if it is embedded in other expressions,
37730 \begin_layout Verse
37733 xyz = gint + ((gint >> 15) & 1);
37736 \begin_layout Standard
37737 will still be recognized.
37740 \begin_layout Subsection
37742 \begin_inset LatexCommand index
37743 name "Higher Order Byte"
37747 / Higher Order Word
37748 \begin_inset LatexCommand index
37749 name "Higher Order Word"
37756 \begin_layout Standard
37757 It is also frequently required to obtain a higher order byte or word of
37758 a larger integral type (long, int or short types).
37759 SDCC recognizes the following expressions to yield the higher order byte
37760 or word and generates optimized code for it, e.g.:
37763 \begin_layout Verse
37768 unsigned long int glong;
37776 unsigned char hob1,
37781 unsigned int how1, how2;
37790 hob1 = (gint >> 8) & 0xFF;
37794 hob2 = glong >> 24;
37798 how1 = (glong >> 16) & 0xFFFF;
37813 \begin_layout Standard
37814 will generate the following code:
37817 \begin_layout Verse
37848 0037 85*01*06\InsetSpace ~
37870 _foo_hob1_1_1,(_gint + 1)
37901 003A 85*05*07\InsetSpace ~
37923 _foo_hob2_1_1,(_glong + 3)
37953 003D 85*04*08\InsetSpace ~
37976 _foo_how1_1_1,(_glong + 2)
37978 0040 85*05*09\InsetSpace ~
38003 0043 85*03*0A\InsetSpace ~
38025 _foo_how2_1_1,(_glong + 1)
38027 0046 85*04*0B\InsetSpace ~
38050 (_foo_how2_1_1 + 1),(_glong + 2)
38053 \begin_layout Standard
38054 Again, variations of these cases may
38059 They are standard C expressions, so I heartily recommend these be the only
38060 way to get the higher order byte/word, (it is portable).
38061 Of course it will be recognized even if it is embedded in other expressions,
38065 \begin_layout Verse
38068 xyz = gint + ((gint >> 8) & 0xFF);
38071 \begin_layout Standard
38072 will still be recognized.
38075 \begin_layout Subsection
38077 \begin_inset LatexCommand label
38078 name "sub:Peephole-Optimizer"
38083 \begin_inset LatexCommand index
38084 name "Peephole optimizer"
38091 \begin_layout Standard
38092 The compiler uses a rule based, pattern matching and re-writing mechanism
38093 for peep-hole optimization.
38098 a peep-hole optimizer by Christopher W.
38099 Fraser (cwfraser\InsetSpace ~
38102 A default set of rules are compiled into the compiler, additional rules
38103 may be added with the
38109 \begin_layout Standard
38119 \begin_inset LatexCommand index
38120 name "-\\/-peep-file"
38127 The rule language is best illustrated with examples.
38130 \begin_layout Verse
38152 \begin_layout Standard
38153 The above rule will change the following assembly
38154 \begin_inset LatexCommand index
38155 name "Assembler routines"
38162 \begin_layout Verse
38170 \begin_layout Standard
38174 \begin_layout Verse
38180 \begin_layout Standard
38181 Note: All occurrences of a
38185 (pattern variable) must denote the same string.
38186 With the above rule, the assembly sequence:
38189 \begin_layout Verse
38197 \begin_layout Standard
38198 will remain unmodified.
38202 Other special case optimizations may be added by the
38209 \begin_layout Standard
38222 some variants of the 8051 MCU
38223 \begin_inset LatexCommand index
38224 name "MCS51 variants"
38237 The following two rules will change all
38254 \begin_layout Verse
38257 replace { lcall %1 } by { acall %1 }
38259 replace { ljmp %1 } by { ajmp %1 }
38262 \begin_layout Standard
38263 (NOTE: from version 2.7.3 on, you can use option -
38269 \begin_layout Standard
38281 \begin_inset LatexCommand index
38282 name "-\\/-acall-ajmp"
38286 , which also takes care of aligning the interrupt vectors properly.)
38291 \begin_layout Standard
38294 inline-assembler code
38296 is also passed through the peep hole optimizer, thus the peephole optimizer
38297 can also be used as an assembly level macro expander.
38298 The rules themselves are MCU dependent whereas the rule language infra-structur
38299 e is MCU independent.
38300 Peephole optimization rules for other MCU can be easily programmed using
38305 The syntax for a rule is as follows:
38308 \begin_layout Verse
38311 rule := replace [ restart ] '{' <assembly sequence> '
38349 <assembly sequence> '
38367 '}' [if <functionName> ] '
38372 \begin_layout Standard
38373 <assembly sequence> := assembly instruction (each instruction including
38374 labels must be on a separate line).
38378 The optimizer will apply to the rules
38379 one by one from the top in the sequence of their appearance, it will terminate
38380 when all rules are exhausted.
38381 If the 'restart' option is specified, then the optimizer will start matching
38382 the rules again from the top, this option for a rule is expensive (performance)
38383 , it is intended to be used in situations where a transformation will trigger
38384 the same rule again.
38385 An example of this (not a good one, it has side effects) is the following
38389 \begin_layout Verse
38409 \begin_layout Standard
38410 Note that the replace pattern cannot be a blank, but can be a comment line.
38411 Without the 'restart' option only the innermost 'pop' 'push' pair would
38412 be eliminated, i.e.:
38415 \begin_layout Verse
38427 \begin_layout Standard
38431 \begin_layout Verse
38441 \begin_layout Standard
38446 the restart option the rule will be applied again to the resulting code
38447 and then all the pop-push pairs will be eliminated to yield:
38450 \begin_layout Verse
38458 \begin_layout Standard
38459 A conditional function can be attached to a rule.
38460 Attaching rules are somewhat more involved, let me illustrate this with
38464 \begin_layout Verse
38488 \begin_layout Standard
38489 The optimizer does a look-up of a function name table defined in function
38494 in the source file SDCCpeeph.c, with the name
38499 If it finds a corresponding entry the function is called.
38500 Note there can be no parameters specified for these functions, in this
38505 is crucial, since the function
38509 expects to find the label in that particular variable (the hash table containin
38510 g the variable bindings is passed as a parameter).
38511 If you want to code more such functions, take a close look at the function
38512 labelInRange and the calling mechanism in source file SDCCpeeph.c.
38513 Currently implemented are
38515 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
38516 24bitMode, portIsDS390, 24bitModeAndPortDS390
38525 \begin_layout Standard
38526 I know this whole thing is a little kludgey, but maybe some day we will
38527 have some better means.
38528 If you are looking at this file, you will see the default rules that are
38529 compiled into the compiler, you can add your own rules in the default set
38530 there if you get tired of specifying the -
38534 \begin_layout Standard
38546 \begin_layout Section
38548 \begin_inset LatexCommand index
38549 name "ANSI-compliance"
38554 \begin_inset LatexCommand label
38555 name "sub:ANSI-Compliance"
38562 \begin_layout Standard
38563 The latest publicly available version of the standard
38565 ISO/IEC 9899 - Programming languages - C
38567 should be available at:
38568 \begin_inset LatexCommand url
38569 target "http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899"
38578 \begin_layout Standard
38579 Deviations from the compliance:
38582 \begin_layout Itemize
38583 functions are not reentrant
38584 \begin_inset LatexCommand index
38589 unless explicitly declared as such or the
38595 \begin_layout Standard
38605 \begin_inset LatexCommand index
38606 name "-\\/-stack-auto"
38612 command line option is specified.
38615 \begin_layout Itemize
38617 \begin_inset LatexCommand index
38623 \begin_inset LatexCommand index
38628 cannot be assigned values directly, cannot be passed as function parameters
38629 or assigned to each other and cannot be a return value
38630 \begin_inset LatexCommand index
38631 name "return value"
38635 from a function, e.g.:
38639 \begin_layout Verse
38662 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
38687 s parms) /* invalid in SDCC although allowed in ANSI */
38709 return rets; /* is invalid in SDCC although allowed in ANSI */
38715 \begin_layout Itemize
38716 initialization of structure arrays must be fully braced.
38720 \begin_layout Verse
38723 struct s { char x } a[] = {1, 2};\InsetSpace ~
38728 /* invalid in SDCC */
38731 } a[] = {{1}, {2}}; /* OK */
38735 \begin_layout Itemize
38737 \begin_inset LatexCommand index
38738 name "long long (not supported)"
38743 \begin_inset LatexCommand index
38744 name "int (64 bit) (not supported)"
38751 \begin_layout Itemize
38753 \begin_inset LatexCommand index
38754 name "double (not supported)"
38758 ' precision floating point
38759 \begin_inset LatexCommand index
38760 name "Floating point support"
38767 \begin_layout Itemize
38769 \begin_inset LatexCommand index
38774 function declarations are NOT allowed.
38778 \begin_layout Verse
38781 foo(i,j) /* this old style of function declarations */
38783 int i,j; /* is valid
38784 in ANSI but not valid in SDCC */
38799 \begin_layout Itemize
38800 Most enhancements in C99 are not supported, e.g.:
38804 \begin_layout Verse
38814 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
38818 \begin_layout Itemize
38819 But some have been added recently in SDCC 2.7.0.
38820 They must be considered alpha quality however.
38824 \begin_layout Verse
38829 \begin_inset LatexCommand index
38830 name "inline (not supported)"
38839 int increment (int a) { return a+1; } /* inlines the increment without function
38848 \begin_inset LatexCommand index
38849 name "inline (not supported)"
38858 p; /* accepted but ignored */
38862 \begin_layout Itemize
38863 Certain words that are valid identifiers in the standard may be reserved
38864 words in SDCC unless the
38870 \begin_layout Standard
38880 \begin_inset LatexCommand index
38881 name "-\\/-std-c89"
38893 \begin_layout Standard
38903 \begin_inset LatexCommand index
38904 name "-\\/-std-c99"
38910 command line options are used.
38911 These may include (depending on the selected processor): 'at', 'banked',
38912 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
38913 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
38914 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
38916 Compliant equivalents of these keywords are always available in a form
38917 that begin with two underscores
38918 \begin_inset LatexCommand index
38919 name "\\_\\_ (prefix for extended keywords)"
38924 '__data' instead of 'data'.
38927 \begin_layout Itemize
38928 Integer promotion of variable arguments is not performed if the argument
38929 is explicitly taypecasted unless the
38935 \begin_layout Standard
38945 \begin_inset LatexCommand index
38946 name "-\\/-std-c89"
38958 \begin_layout Standard
38968 \begin_inset LatexCommand index
38969 name "-\\/-std-c99"
38975 command line options are used.
38979 \begin_layout Verse
38982 void vararg_func (char *str, ...) { str; }
38999 u is promoted to int before
39004 * passing to function */
39008 vararg_func ("%c", c);
39015 argument u is not promoted to int,
39020 * it is passed as char to function
39026 --std-cXX is not defined;
39031 * is promoted to int before passing
39037 if --std-cXX is defined */
39041 vararg_func ("%bc", (char)u);
39047 \begin_layout Section
39048 Cyclomatic Complexity
39049 \begin_inset LatexCommand index
39050 name "Cyclomatic complexity"
39057 \begin_layout Standard
39058 Cyclomatic complexity of a function is defined as the number of independent
39059 paths the program can take during execution of the function.
39060 This is an important number since it defines the number test cases you
39061 have to generate to validate the function.
39062 The accepted industry standard for complexity number is 10, if the cyclomatic
39063 complexity reported by SDCC exceeds 10 you should think about simplification
39064 of the function logic.
39065 Note that the complexity level is not related to the number of lines of
39066 code in a function.
39067 Large functions can have low complexity, and small functions can have large
39073 SDCC uses the following formula to compute the complexity:
39078 \begin_layout Standard
39079 complexity = (number of edges in control flow graph) - (number of nodes
39080 in control flow graph) + 2;
39084 Having said that the industry standard is 10,
39085 you should be aware that in some cases it be may unavoidable to have a
39086 complexity level of less than 10.
39087 For example if you have switch statement with more than 10 case labels,
39088 each case label adds one to the complexity level.
39089 The complexity level is by no means an absolute measure of the algorithmic
39090 complexity of the function, it does however provide a good starting point
39091 for which functions you might look at for further optimization.
39094 \begin_layout Section
39095 Retargetting for other Processors
39098 \begin_layout Standard
39099 The issues for retargetting the compiler are far too numerous to be covered
39101 What follows is a brief description of each of the seven phases of the
39102 compiler and its MCU dependency.
39105 \begin_layout Itemize
39106 Parsing the source and building the annotated parse tree.
39107 This phase is largely MCU independent (except for the language extensions).
39108 Syntax & semantic checks are also done in this phase, along with some initial
39109 optimizations like back patching labels and the pattern matching optimizations
39110 like bit-rotation etc.
39113 \begin_layout Itemize
39114 The second phase involves generating an intermediate code which can be easy
39115 manipulated during the later phases.
39116 This phase is entirely MCU independent.
39117 The intermediate code generation assumes the target machine has unlimited
39118 number of registers, and designates them with the name iTemp.
39119 The compiler can be made to dump a human readable form of the code generated
39124 \begin_layout Standard
39136 \begin_layout Itemize
39137 This phase does the bulk of the standard optimizations and is also MCU independe
39139 This phase can be broken down into several sub-phases:
39143 Break down intermediate
39144 code (iCode) into basic blocks.
39146 Do control flow & data flow analysis on the
39149 Do local common subexpression elimination, then global subexpressio
39152 Dead code elimination
39156 If loop optimizations
39157 caused any changes then do 'global subexpression elimination' and 'dead
39158 code elimination' again.
39161 \begin_layout Itemize
39162 This phase determines the live-ranges; by live range I mean those iTemp
39163 variables defined by the compiler that still survive after all the optimization
39165 Live range analysis
39166 \begin_inset LatexCommand index
39167 name "Live range analysis"
39171 is essential for register allocation, since these computation determines
39172 which of these iTemps will be assigned to registers, and for how long.
39175 \begin_layout Itemize
39176 Phase five is register allocation.
39177 There are two parts to this process.
39181 The first part I call 'register packing'
39182 (for lack of a better term).
39183 In this case several MCU specific expression folding is done to reduce
39188 The second part is more MCU independent and deals with
39189 allocating registers to the remaining live ranges.
39190 A lot of MCU specific code does creep into this phase because of the limited
39191 number of index registers available in the 8051.
39194 \begin_layout Itemize
39195 The Code generation phase is (unhappily), entirely MCU dependent and very
39196 little (if any at all) of this code can be reused for other MCU.
39197 However the scheme for allocating a homogenized assembler operand for each
39198 iCode operand may be reused.
39201 \begin_layout Itemize
39202 As mentioned in the optimization section the peep-hole optimizer is rule
39203 based system, which can reprogrammed for other MCUs.
39206 \begin_layout Standard
39207 More information is available on SDCC Wiki
39208 \begin_inset LatexCommand index
39214 \begin_inset LatexCommand url
39215 target "http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting"
39219 ) and in the thread
39220 \begin_inset LatexCommand url
39221 target "http://sf.net/mailarchive/message.php?msg_id=13954144"
39228 \begin_layout Chapter
39230 \begin_inset LatexCommand index
39231 name "Compiler internals"
39238 \begin_layout Section
39239 The anatomy of the compiler
39240 \begin_inset LatexCommand label
39241 name "sub:The-anatomy-of"
39248 \begin_layout Standard
39251 This is an excerpt from an article published in Circuit Cellar Magazine
39260 It's a little outdated (the compiler is much more efficient now and user/develo
39261 per friendly), but pretty well exposes the guts of it all.
39267 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
39268 It is fairly easy to retarget for other 8-bit MCU.
39269 Here we take a look at some of the internals of the compiler.
39273 \begin_layout Paragraph*
39275 \begin_inset LatexCommand index
39283 \begin_layout Standard
39284 Parsing the input source file and creating an AST (Annotated Syntax Tree
39285 \begin_inset LatexCommand index
39286 name "Annotated syntax tree"
39291 This phase also involves propagating types (annotating each node of the
39292 parse tree with type information) and semantic analysis.
39293 There are some MCU specific parsing rules.
39294 For example the storage classes, the extended storage classes are MCU specific
39295 while there may be a xdata storage class for 8051 there is no such storage
39296 class for z80 or Atmel AVR.
39297 SDCC allows MCU specific storage class extensions, i.e.
39298 xdata will be treated as a storage class specifier when parsing 8051 C
39299 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
39303 \begin_layout Paragraph*
39305 \begin_inset LatexCommand index
39313 \begin_layout Standard
39314 Intermediate code generation.
39315 In this phase the AST is broken down into three-operand form (iCode).
39316 These three operand forms are represented as doubly linked lists.
39317 ICode is the term given to the intermediate form generated by the compiler.
39318 ICode example section shows some examples of iCode generated for some simple
39319 C source functions.
39322 \begin_layout Paragraph*
39324 \begin_inset LatexCommand index
39325 name "Optimizations"
39332 \begin_layout Standard
39333 Bulk of the target independent optimizations is performed in this phase.
39334 The optimizations include constant propagation, common sub-expression eliminati
39335 on, loop invariant code movement, strength reduction of loop induction variables
39336 and dead-code elimination.
39339 \begin_layout Paragraph*
39340 Live range analysis
39341 \begin_inset LatexCommand index
39342 name "Live range analysis"
39349 \begin_layout Standard
39350 During intermediate code generation phase, the compiler assumes the target
39351 machine has infinite number of registers and generates a lot of temporary
39353 The live range computation determines the lifetime of each of these compiler-ge
39354 nerated temporaries.
39355 A picture speaks a thousand words.
39356 ICode example sections show the live range annotations for each of the
39358 It is important to note here, each iCode is assigned a number in the order
39359 of its execution in the function.
39360 The live ranges are computed in terms of these numbers.
39361 The from number is the number of the iCode which first defines the operand
39362 and the to number signifies the iCode which uses this operand last.
39365 \begin_layout Paragraph*
39366 Register Allocation
39367 \begin_inset LatexCommand index
39368 name "Register allocation"
39375 \begin_layout Standard
39376 The register allocation determines the type and number of registers needed
39378 In most MCUs only a few registers can be used for indirect addressing.
39379 In case of 8051 for example the registers R0 & R1 can be used to indirectly
39380 address the internal ram and DPTR to indirectly address the external ram.
39381 The compiler will try to allocate the appropriate register to pointer variables
39383 ICode example section shows the operands annotated with the registers assigned
39385 The compiler will try to keep operands in registers as much as possible;
39386 there are several schemes the compiler uses to do achieve this.
39387 When the compiler runs out of registers the compiler will check to see
39388 if there are any live operands which is not used or defined in the current
39389 basic block being processed, if there are any found then it will push that
39390 operand and use the registers in this block, the operand will then be popped
39391 at the end of the basic block.
39395 \begin_layout Standard
39396 There are other MCU specific considerations in this phase.
39397 Some MCUs have an accumulator; very short-lived operands could be assigned
39398 to the accumulator instead of a general-purpose register.
39401 \begin_layout Paragraph*
39405 \begin_layout Standard
39406 Figure II gives a table of iCode
39407 \begin_inset LatexCommand index
39412 operations supported by the compiler.
39413 The code generation involves translating these operations into corresponding
39414 assembly code for the processor.
39415 This sounds overly simple but that is the essence of code generation.
39416 Some of the iCode operations are generated on a MCU specific manner for
39417 example, the z80 port does not use registers to pass parameters so the
39418 SEND and RECV iCode operations will not be generated, and it also does
39419 not support JUMPTABLES.
39425 \begin_layout Standard
39429 \begin_inset Tabular
39430 <lyxtabular version="3" rows="39" columns="4">
39431 <features islongtable="true" headBottomDL="true">
39432 <column alignment="block" valignment="top" leftline="true" width="13col%">
39433 <column alignment="left" valignment="top" leftline="true" width="13col%">
39434 <column alignment="block" valignment="top" leftline="true" width="22col%">
39435 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
39436 <row topline="true" bottomline="true" endhead="true">
39437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39440 \begin_layout Standard
39446 \begin_inset LatexCommand index
39456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39459 \begin_layout Standard
39467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39470 \begin_layout Standard
39478 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39481 \begin_layout Standard
39490 <row topline="true">
39491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39494 \begin_layout Standard
39502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39505 \begin_layout Standard
39508 IC_LEFT() IC_RESULT()
39513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39516 \begin_layout Standard
39524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39527 \begin_layout Standard
39530 IC_RESULT = ! IC_LEFT;
39536 <row topline="true">
39537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39540 \begin_layout Standard
39548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39551 \begin_layout Standard
39554 IC_LEFT() IC_RESULT()
39559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39562 \begin_layout Standard
39565 Bitwise complement of
39570 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39573 \begin_layout Standard
39576 IC_RESULT = ~IC_LEFT;
39582 <row topline="true">
39583 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39586 \begin_layout Standard
39594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39597 \begin_layout Standard
39600 IC_LEFT() IC_RESULT()
39605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39608 \begin_layout Standard
39611 Rotate right with carry
39616 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39619 \begin_layout Standard
39622 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
39628 <row topline="true">
39629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39632 \begin_layout Standard
39640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39643 \begin_layout Standard
39646 IC_LEFT() IC_RESULT()
39651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39654 \begin_layout Standard
39657 Rotate left with carry
39662 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39665 \begin_layout Standard
39668 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
39674 <row topline="true">
39675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39678 \begin_layout Standard
39686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39689 \begin_layout Standard
39692 IC_LEFT() IC_RESULT()
39697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39700 \begin_layout Standard
39703 Get the highest order bit of IC_LEFT
39708 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39711 \begin_layout Standard
39714 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
39720 <row topline="true">
39721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39724 \begin_layout Standard
39732 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39735 \begin_layout Standard
39738 IC_LEFT() IC_RESULT()
39743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39746 \begin_layout Standard
39754 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39757 \begin_layout Standard
39760 IC_RESULT = - IC_LEFT;
39766 <row topline="true">
39767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39770 \begin_layout Standard
39778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39781 \begin_layout Standard
39789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39792 \begin_layout Standard
39795 Push the operand into stack
39800 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39803 \begin_layout Standard
39812 <row topline="true">
39813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39816 \begin_layout Standard
39824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39827 \begin_layout Standard
39835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39838 \begin_layout Standard
39841 Pop the operand from the stack
39846 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39849 \begin_layout Standard
39858 <row topline="true">
39859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39862 \begin_layout Standard
39870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39873 \begin_layout Standard
39876 IC_LEFT() IC_RESULT()
39881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39884 \begin_layout Standard
39887 Call the function represented by IC_LEFT
39892 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39895 \begin_layout Standard
39898 IC_RESULT = IC_LEFT();
39904 <row topline="true">
39905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39908 \begin_layout Standard
39916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39919 \begin_layout Standard
39922 IC_LEFT() IC_RESULT()
39927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39930 \begin_layout Standard
39933 Call via function pointer
39938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39941 \begin_layout Standard
39944 IC_RESULT = (*IC_LEFT)();
39950 <row topline="true">
39951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39954 \begin_layout Standard
39962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39965 \begin_layout Standard
39973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39976 \begin_layout Standard
39979 Return the value in operand IC_LEFT
39984 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39987 \begin_layout Standard
39996 <row topline="true">
39997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40000 \begin_layout Standard
40008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40011 \begin_layout Standard
40019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40022 \begin_layout Standard
40030 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40033 \begin_layout Standard
40042 <row topline="true">
40043 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40046 \begin_layout Standard
40054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40057 \begin_layout Standard
40065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40068 \begin_layout Standard
40076 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40079 \begin_layout Standard
40088 <row topline="true">
40089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40092 \begin_layout Standard
40100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40103 \begin_layout Standard
40106 IC_LEFT() IC_RIGHT() IC_RESULT()
40111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40114 \begin_layout Standard
40122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40125 \begin_layout Standard
40128 IC_RESULT = IC_LEFT + IC_RIGHT
40134 <row topline="true">
40135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40138 \begin_layout Standard
40146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40149 \begin_layout Standard
40152 IC_LEFT() IC_RIGHT() IC_RESULT()
40157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40160 \begin_layout Standard
40168 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40171 \begin_layout Standard
40174 IC_RESULT = IC_LEFT - IC_RIGHT
40180 <row topline="true">
40181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40184 \begin_layout Standard
40192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40195 \begin_layout Standard
40198 IC_LEFT() IC_RIGHT() IC_RESULT()
40203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40206 \begin_layout Standard
40214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40217 \begin_layout Standard
40220 IC_RESULT = IC_LEFT * IC_RIGHT;
40226 <row topline="true">
40227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40230 \begin_layout Standard
40238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40241 \begin_layout Standard
40244 IC_LEFT() IC_RIGHT() IC_RESULT()
40249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40252 \begin_layout Standard
40260 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40263 \begin_layout Standard
40266 IC_RESULT = IC_LEFT / IC_RIGHT;
40272 <row topline="true">
40273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40276 \begin_layout Standard
40284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40287 \begin_layout Standard
40290 IC_LEFT() IC_RIGHT() IC_RESULT()
40295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40298 \begin_layout Standard
40306 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40309 \begin_layout Standard
40312 IC_RESULT = IC_LEFT % IC_RIGHT;
40318 <row topline="true">
40319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40322 \begin_layout Standard
40330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40333 \begin_layout Standard
40336 IC_LEFT() IC_RIGHT() IC_RESULT()
40341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40344 \begin_layout Standard
40352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40355 \begin_layout Standard
40358 IC_RESULT = IC_LEFT < IC_RIGHT;
40364 <row topline="true">
40365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40368 \begin_layout Standard
40376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40379 \begin_layout Standard
40382 IC_LEFT() IC_RIGHT() IC_RESULT()
40387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40390 \begin_layout Standard
40398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40401 \begin_layout Standard
40404 IC_RESULT = IC_LEFT > IC_RIGHT;
40410 <row topline="true">
40411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40414 \begin_layout Standard
40422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40425 \begin_layout Standard
40428 IC_LEFT() IC_RIGHT() IC_RESULT()
40433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40436 \begin_layout Standard
40444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40447 \begin_layout Standard
40450 IC_RESULT = IC_LEFT == IC_RIGHT;
40456 <row topline="true">
40457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40460 \begin_layout Standard
40468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40471 \begin_layout Standard
40474 IC_LEFT() IC_RIGHT() IC_RESULT()
40479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40482 \begin_layout Standard
40485 Logical and operation
40490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40493 \begin_layout Standard
40496 IC_RESULT = IC_LEFT && IC_RIGHT;
40502 <row topline="true">
40503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40506 \begin_layout Standard
40514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40517 \begin_layout Standard
40520 IC_LEFT() IC_RIGHT() IC_RESULT()
40525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40528 \begin_layout Standard
40531 Logical or operation
40536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40539 \begin_layout Standard
40542 IC_RESULT = IC_LEFT || IC_RIGHT;
40548 <row topline="true">
40549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40552 \begin_layout Standard
40560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40563 \begin_layout Standard
40566 IC_LEFT() IC_RIGHT() IC_RESULT()
40571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40574 \begin_layout Standard
40582 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40585 \begin_layout Standard
40588 IC_RESULT = IC_LEFT ^ IC_RIGHT;
40594 <row topline="true">
40595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40598 \begin_layout Standard
40606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40609 \begin_layout Standard
40612 IC_LEFT() IC_RIGHT() IC_RESULT()
40617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40620 \begin_layout Standard
40628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40631 \begin_layout Standard
40634 IC_RESULT = IC_LEFT | IC_RIGHT;
40640 <row topline="true">
40641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40644 \begin_layout Standard
40652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40655 \begin_layout Standard
40658 IC_LEFT() IC_RIGHT() IC_RESULT()
40663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40666 \begin_layout Standard
40674 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40677 \begin_layout Standard
40680 IC_RESULT = IC_LEFT & IC_RIGHT;
40686 <row topline="true">
40687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40690 \begin_layout Standard
40698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40701 \begin_layout Standard
40704 IC_LEFT() IC_RIGHT() IC_RESULT()
40709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40712 \begin_layout Standard
40720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40723 \begin_layout Standard
40726 IC_RESULT = IC_LEFT << IC_RIGHT
40732 <row topline="true">
40733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40736 \begin_layout Standard
40744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40747 \begin_layout Standard
40750 IC_LEFT() IC_RIGHT() IC_RESULT()
40755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40758 \begin_layout Standard
40766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40769 \begin_layout Standard
40772 IC_RESULT = IC_LEFT >> IC_RIGHT
40778 <row topline="true">
40779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40782 \begin_layout Standard
40792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40795 \begin_layout Standard
40798 IC_LEFT() IC_RESULT()
40803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40806 \begin_layout Standard
40814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40817 \begin_layout Standard
40820 IC_RESULT = (*IC_LEFT);
40826 <row topline="true">
40827 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40830 \begin_layout Standard
40838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40841 \begin_layout Standard
40844 IC_RIGHT() IC_RESULT()
40849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40852 \begin_layout Standard
40860 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40863 \begin_layout Standard
40866 (*IC_RESULT) = IC_RIGHT;
40872 <row topline="true">
40873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40876 \begin_layout Standard
40884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40887 \begin_layout Standard
40890 IC_RIGHT() IC_RESULT()
40895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40898 \begin_layout Standard
40906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40909 \begin_layout Standard
40912 IC_RESULT = IC_RIGHT;
40918 <row topline="true">
40919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40922 \begin_layout Standard
40930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40933 \begin_layout Standard
40936 IC_COND IC_TRUE IC_LABEL
40941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40944 \begin_layout Standard
40948 If true label is present then jump to true label if condition is true else
40949 jump to false label if condition is false
40954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40957 \begin_layout Standard
40960 if (IC_COND) goto IC_TRUE;
40966 If (!IC_COND) goto IC_FALSE;
40972 <row topline="true">
40973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40976 \begin_layout Standard
40984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40987 \begin_layout Standard
40990 IC_LEFT() IC_RESULT()
40995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40998 \begin_layout Standard
41006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41009 \begin_layout Standard
41012 IC_RESULT = &IC_LEFT();
41018 <row topline="true">
41019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41022 \begin_layout Standard
41030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41033 \begin_layout Standard
41036 IC_JTCOND IC_JTLABELS
41041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41044 \begin_layout Standard
41047 Jump to list of labels depending on the value of JTCOND
41052 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41055 \begin_layout Standard
41064 <row topline="true">
41065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41068 \begin_layout Standard
41076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41079 \begin_layout Standard
41082 IC_RIGHT() IC_LEFT() IC_RESULT()
41087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41090 \begin_layout Standard
41098 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41101 \begin_layout Standard
41104 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
41110 <row topline="true">
41111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41114 \begin_layout Standard
41122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41125 \begin_layout Standard
41133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41136 \begin_layout Standard
41139 This is used for passing parameters in registers;
41141 move IC_LEFT to the next
41142 available parameter register.
41147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41150 \begin_layout Standard
41159 <row topline="true">
41160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41163 \begin_layout Standard
41171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41174 \begin_layout Standard
41182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41185 \begin_layout Standard
41188 This is used for receiving parameters passed in registers;
41191 in the next parameter register to IC_RESULT
41196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41199 \begin_layout Standard
41208 <row topline="true" bottomline="true">
41209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41212 \begin_layout Standard
41216 (some more have been added)
41221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41224 \begin_layout Standard
41230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41233 \begin_layout Standard
41239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41242 \begin_layout Standard
41275 \begin_layout Standard
41276 \begin_inset Note Note
41279 \begin_layout Standard
41280 In the original article Figure II was announced to be downloadable on
41285 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
41293 \begin_layout Paragraph*
41295 \begin_inset LatexCommand index
41303 \begin_layout Standard
41304 This section shows some details of iCode.
41305 The example C code does not do anything useful; it is used as an example
41306 to illustrate the intermediate code generated by the compiler.
41309 \begin_layout Verse
41319 /* This function does nothing useful.
41326 for the purpose of explaining iCode */
41329 short function (data
41338 short i=10; \InsetSpace ~
41340 /* dead initialization eliminated */
41346 /* dead initialization eliminated */
41374 /* compiler detects i,j to be induction
41379 for (i = 0, j = 10 ; i < 10 ; i++, j
41385 \begin_layout Standard
41408 mul += i * 3; \InsetSpace ~
41410 /* this multiplication remains */
41417 j * 3;\InsetSpace ~
41419 /* this multiplication changed to addition */
41433 \begin_layout Standard
41434 In addition to the operands each iCode contains information about the filename
41435 and line it corresponds to in the source file.
41436 The first field in the listing should be interpreted as follows:
41441 Filename(linenumber: iCode Execution sequence number : ICode hash table
41442 key : loop depth of the iCode).
41447 Then follows the human readable form of the ICode operation.
41448 Each operand of this triplet form can be of three basic types a) compiler
41449 generated temporary b) user defined variable c) a constant value.
41450 Note that local variables and parameters are replaced by compiler generated
41453 \begin_inset LatexCommand index
41454 name "Live range analysis"
41458 are computed only for temporaries (i.e.
41459 live ranges are not computed for global variables).
41461 \begin_inset LatexCommand index
41462 name "Register allocation"
41466 are allocated for temporaries only.
41467 Operands are formatted in the following manner:
41472 Operand Name [lr live-from : live-to ] { type information } [ registers
41478 As mentioned earlier the live ranges are computed in terms of the execution
41479 sequence number of the iCodes, for example
41481 the iTemp0 is live from (i.e.
41482 first defined in iCode with execution sequence number 3, and is last used
41483 in the iCode with sequence number 5).
41484 For induction variables such as iTemp21 the live range computation extends
41485 the lifetime from the start to the end of the loop.
41487 The register allocator
41488 used the live range information to allocate registers, the same registers
41489 may be used for different temporaries if their live ranges do not overlap,
41490 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
41491 ranges do not overlap.
41492 In addition the allocator also takes into consideration the type and usage
41493 of a temporary, for example itemp6 is a pointer to near space and is used
41494 as to fetch data from (i.e.
41495 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
41496 Some short lived temporaries are allocated to special registers which have
41497 meaning to the code generator e.g.
41498 iTemp13 is allocated to a pseudo register CC which tells the back end that
41499 the temporary is used only for a conditional jump the code generation makes
41500 use of this information to optimize a compare and jump ICode.
41504 \begin_inset LatexCommand index
41505 name "Loop optimization"
41509 performed by the compiler.
41510 It can detect induction variables iTemp21(i) and iTemp23(j).
41511 Also note the compiler does selective strength reduction
41512 \begin_inset LatexCommand index
41513 name "Strength reduction"
41518 the multiplication of an induction variable in line 18 (gint = j * 3) is
41519 changed to addition, a new temporary iTemp17 is allocated and assigned
41520 a initial value, a constant 3 is then added for each iteration of the loop.
41521 The compiler does not change the multiplication
41522 \begin_inset LatexCommand index
41523 name "Multiplication"
41527 in line 17 however since the processor does support an 8 * 8 bit multiplication.
41530 Note the dead code elimination
41531 \begin_inset LatexCommand index
41532 name "Dead-code elimination"
41536 optimization eliminated the dead assignments in line 7 & 8 to I and sum
41542 \begin_layout Standard
41545 Sample.c (5:1:0:0) _entry($9) :
41548 \begin_layout Standard
41551 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
41554 \begin_layout Standard
41557 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
41560 \begin_layout Standard
41563 Sample.c(11:4:53:0) preHeaderLbl0($11) :
41566 \begin_layout Standard
41569 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
41573 \begin_layout Standard
41576 Sample.c(11:6:5:1) _whilecontinue_0($1) :
41579 \begin_layout Standard
41582 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
41586 \begin_layout Standard
41589 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
41592 \begin_layout Standard
41595 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
41599 \begin_layout Standard
41602 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
41606 \begin_layout Standard
41609 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
41613 \begin_layout Standard
41616 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
41620 \begin_layout Standard
41623 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
41624 * int}[r0] + 0x2 {short}
41627 \begin_layout Standard
41630 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
41633 \begin_layout Standard
41636 Sample.c(11:17:21:0)_whilebreak_0($3) :
41639 \begin_layout Standard
41642 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
41645 \begin_layout Standard
41648 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
41651 \begin_layout Standard
41654 Sample.c(15:20:54:0)preHeaderLbl1($13) :
41657 \begin_layout Standard
41660 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
41663 \begin_layout Standard
41666 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
41669 \begin_layout Standard
41672 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
41675 \begin_layout Standard
41678 Sample.c(15:24:26:1)_forcond_0($4) :
41681 \begin_layout Standard
41684 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
41688 \begin_layout Standard
41691 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
41694 \begin_layout Standard
41697 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
41698 + ITemp21 [lr21:38]{short}[r4]
41701 \begin_layout Standard
41704 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
41708 \begin_layout Standard
41711 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
41712 + iTemp15 [lr29:30]{short}[r1]
41715 \begin_layout Standard
41718 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
41722 \begin_layout Standard
41725 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
41729 \begin_layout Standard
41732 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
41736 \begin_layout Standard
41739 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
41743 \begin_layout Standard
41746 Sample.c(19:38:47:1) goto _forcond_0($4)
41749 \begin_layout Standard
41752 Sample.c(19:39:48:0)_forbreak_0($7) :
41755 \begin_layout Standard
41758 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
41759 + ITemp11 [lr19:40]{short}[r3]
41762 \begin_layout Standard
41765 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
41768 \begin_layout Standard
41771 Sample.c(20:42:51:0)_return($8) :
41774 \begin_layout Standard
41777 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
41783 Finally the code generated for this function:
41788 \begin_layout Standard
41794 \begin_layout Standard
41800 \begin_layout Standard
41808 \begin_layout Standard
41814 \begin_layout Standard
41822 \begin_layout Standard
41828 \begin_layout Standard
41831 ; ----------------------------------------------
41834 \begin_layout Standard
41837 ; function function
41840 \begin_layout Standard
41843 ; ----------------------------------------------
41846 \begin_layout Standard
41852 \begin_layout Standard
41855 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
41858 \begin_layout Standard
41866 \begin_layout Standard
41869 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
41872 \begin_layout Standard
41880 \begin_layout Standard
41883 ;_whilecontinue_0($1) :
41886 \begin_layout Standard
41892 \begin_layout Standard
41895 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
41898 \begin_layout Standard
41901 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
41904 \begin_layout Standard
41912 \begin_layout Standard
41920 \begin_layout Standard
41928 \begin_layout Standard
41936 \begin_layout Standard
41944 \begin_layout Standard
41952 \begin_layout Standard
41960 \begin_layout Standard
41966 \begin_layout Standard
41969 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
41972 \begin_layout Standard
41980 \begin_layout Standard
41988 \begin_layout Standard
41991 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
41994 \begin_layout Standard
42002 \begin_layout Standard
42010 \begin_layout Standard
42018 \begin_layout Standard
42026 \begin_layout Standard
42034 \begin_layout Standard
42042 \begin_layout Standard
42045 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
42048 \begin_layout Standard
42056 \begin_layout Standard
42064 \begin_layout Standard
42072 \begin_layout Standard
42080 \begin_layout Standard
42088 \begin_layout Standard
42091 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
42094 \begin_layout Standard
42102 \begin_layout Standard
42110 \begin_layout Standard
42118 \begin_layout Standard
42121 ; iTemp6 [lr5:16]{_near * int}[r0] =
42124 \begin_layout Standard
42127 ; iTemp6 [lr5:16]{_near * int}[r0] +
42130 \begin_layout Standard
42136 \begin_layout Standard
42144 \begin_layout Standard
42147 ; goto _whilecontinue_0($1)
42150 \begin_layout Standard
42158 \begin_layout Standard
42161 ; _whilebreak_0($3) :
42164 \begin_layout Standard
42170 \begin_layout Standard
42173 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
42176 \begin_layout Standard
42184 \begin_layout Standard
42187 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
42190 \begin_layout Standard
42198 \begin_layout Standard
42201 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
42204 \begin_layout Standard
42212 \begin_layout Standard
42215 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
42218 \begin_layout Standard
42226 \begin_layout Standard
42234 \begin_layout Standard
42237 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
42240 \begin_layout Standard
42248 \begin_layout Standard
42256 \begin_layout Standard
42262 \begin_layout Standard
42268 \begin_layout Standard
42271 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
42274 \begin_layout Standard
42277 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
42280 \begin_layout Standard
42288 \begin_layout Standard
42296 \begin_layout Standard
42304 \begin_layout Standard
42312 \begin_layout Standard
42320 \begin_layout Standard
42326 \begin_layout Standard
42329 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
42332 \begin_layout Standard
42335 ; iTemp21 [lr21:38]{short}[r4]
42338 \begin_layout Standard
42346 \begin_layout Standard
42354 \begin_layout Standard
42362 \begin_layout Standard
42365 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
42368 \begin_layout Standard
42376 \begin_layout Standard
42384 \begin_layout Standard
42392 \begin_layout Standard
42400 \begin_layout Standard
42403 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
42406 \begin_layout Standard
42409 ; iTemp15 [lr29:30]{short}[r1]
42412 \begin_layout Standard
42420 \begin_layout Standard
42428 \begin_layout Standard
42431 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
42434 \begin_layout Standard
42442 \begin_layout Standard
42450 \begin_layout Standard
42458 \begin_layout Standard
42466 \begin_layout Standard
42474 \begin_layout Standard
42482 \begin_layout Standard
42485 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
42488 \begin_layout Standard
42496 \begin_layout Standard
42504 \begin_layout Standard
42512 \begin_layout Standard
42520 \begin_layout Standard
42528 \begin_layout Standard
42536 \begin_layout Standard
42539 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
42542 \begin_layout Standard
42550 \begin_layout Standard
42553 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
42556 \begin_layout Standard
42564 \begin_layout Standard
42569 cjne r5,#0xff,00104$
42572 \begin_layout Standard
42580 \begin_layout Standard
42583 ; goto _forcond_0($4)
42586 \begin_layout Standard
42594 \begin_layout Standard
42597 ; _forbreak_0($7) :
42600 \begin_layout Standard
42606 \begin_layout Standard
42609 ; ret iTemp24 [lr40:41]{short}
42612 \begin_layout Standard
42620 \begin_layout Standard
42628 \begin_layout Standard
42636 \begin_layout Standard
42642 \begin_layout Standard
42648 \begin_layout Standard
42658 \begin_layout Section
42659 A few words about basic block successors, predecessors and dominators
42662 \begin_layout Standard
42663 Successors are basic blocks
42664 \begin_inset LatexCommand index
42665 name "Basic blocks"
42669 that might execute after this basic block.
42671 Predecessors are basic blocks
42672 that might execute before reaching this basic block.
42674 Dominators are basic
42675 blocks that WILL execute before reaching this basic block.
42680 \begin_layout Standard
42684 \begin_layout Standard
42688 \begin_layout Standard
42696 \begin_layout Standard
42700 \begin_layout Standard
42708 \begin_layout Standard
42714 \begin_layout Standard
42715 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
42718 \begin_layout Standard
42719 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
42722 \begin_layout Standard
42723 c) domVect of [BB4] = BB1 ...
42724 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
42728 \begin_layout Chapter
42732 \begin_layout Standard
42733 \begin_inset LatexCommand url
42734 target "http://sdcc.sourceforge.net/#Who"
42744 Thanks to all the other volunteer developers who have helped with coding,
42745 testing, web-page creation, distribution sets, etc.
42746 You know who you are :-)
42754 Thanks to Sourceforge
42755 \begin_inset LatexCommand url
42756 target "http://www.sf.net"
42760 which has hosted the project since 1999 and donates significant download
42769 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
42770 cycles and bandwidth for snapshot builds.
42775 \begin_layout Standard
42776 This document was initially written by Sandeep Dutta
42779 \begin_layout Standard
42780 All product names mentioned herein may be trademarks
42781 \begin_inset LatexCommand index
42786 of their respective companies.
42790 \begin_layout Section*
42794 \begin_layout Standard
42795 To avoid confusion, the installation and building options for SDCC itself
42796 (chapter 2) are not part of the index.
42799 \begin_layout Standard
42800 \begin_inset LatexCommand printindex