1 #LyX 1.5.7 created this file. For more info see http://www.lyx.org/
7 \pdfoptionpdfminorversion=3
9 pdftitle={SDCC Compiler User Guide},
10 pdfauthor={SDCC development team},
11 pdfsubject={installation, user manual},
12 pdfkeywords={68hc08 8032 8051 ansi c compiler assembler CPU DS390 embedded development free Floating Point Arithmetic Freescale GPL HC08 inline Intel ISO/IEC 9899:1990 Linux MAC OS X manual Maxim mcs51 Microchip microcontroller open source PIC Unix Windows Z80 Zilog},
13 pdfpagemode=UseOutlines,
15 linkcolor=blue] {hyperref}
19 \emergencystretch=30pt
24 \inputencoding default
27 \font_typewriter courier
28 \font_default_family default
34 \paperfontsize default
36 \papersize letterpaper
42 \paperorientation portrait
49 \paragraph_separation indent
51 \quotes_language swedish
55 \tracking_changes false
63 \begin_layout Standard
64 \begin_inset Note Note
67 \begin_layout Standard
68 Please note: double dashed longoptions (e.g.
69 --version) are written this way: -
73 \begin_layout Standard
85 \begin_layout Standard
87 three consecutive dashes would otherwise result in a long resp.
91 \begin_layout Standard
92 Architecture specific stuff (like memory models, code examples) should maybe
96 \begin_layout Standard
97 into separate sections/chapters/appendices (it is hard to document PIC or
101 \begin_layout Standard
102 a 8051 centered document) - for now simply add.
111 SDCC Compiler User Guide
126 \begin_layout Standard
127 \begin_inset Note Note
130 \begin_layout Standard
131 The above strings enclosed in $ are automatically updated by Subversion
139 \begin_layout Standard
140 \begin_inset LatexCommand tableofcontents
147 \begin_layout Chapter
151 \begin_layout Section
155 \begin_layout Standard
176 ompiler) is free open source, retargettable, optimizing ANSI-C compiler
181 designed for 8 bit Microprocessors.
182 The current version targets Intel MCS51 based Microprocessors (8031, 8032,
184 \begin_inset LatexCommand index
185 name "8031, 8032, 8051, 8052, mcs51 CPU"
189 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
190 Zilog Z80 based MCUs.
191 It can be retargeted for other microprocessors, support for Microchip PIC,
192 Atmel AVR is under development.
193 The entire source code for the compiler is distributed under GPL.
195 \begin_inset LatexCommand index
196 name "asXXXX (as-gbz80, as-hc08, asx8051, as-z80)"
201 \begin_inset LatexCommand index
206 , an open source retargetable assembler & linker.
207 SDCC has extensive language extensions suitable for utilizing various microcont
208 rollers and underlying hardware effectively.
213 In addition to the MCU specific optimizations SDCC also does a host of
214 standard optimizations like:
217 \begin_layout Itemize
218 global sub expression elimination,
221 \begin_layout Itemize
222 loop optimizations (loop invariant, strength reduction of induction variables
226 \begin_layout Itemize
227 constant folding & propagation,
230 \begin_layout Itemize
234 \begin_layout Itemize
235 dead code elimination
238 \begin_layout Itemize
246 \begin_layout Standard
247 For the back-end SDCC uses a global register allocation scheme which should
248 be well suited for other 8 bit MCUs.
253 The peep hole optimizer uses a rule based substitution mechanism which
259 Supported data-types are:
262 \begin_layout Standard
264 <lyxtabular version="3" rows="8" columns="5">
266 <column alignment="center" valignment="top" leftline="true" width="0">
267 <column alignment="center" valignment="top" leftline="true" width="0">
268 <column alignment="center" valignment="top" leftline="true" width="0">
269 <column alignment="center" valignment="top" leftline="true" width="0">
270 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
271 <row topline="true" bottomline="true">
272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
275 \begin_layout Standard
281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
284 \begin_layout Standard
290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
293 \begin_layout Standard
299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
302 \begin_layout Standard
308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
311 \begin_layout Standard
319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
322 \begin_layout Standard
328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
331 \begin_layout Standard
337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
340 \begin_layout Standard
346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
349 \begin_layout Standard
355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
358 \begin_layout Standard
366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
369 \begin_layout Standard
375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
378 \begin_layout Standard
384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
387 \begin_layout Standard
393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
396 \begin_layout Standard
402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
405 \begin_layout Standard
413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
416 \begin_layout Standard
422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
425 \begin_layout Standard
431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
434 \begin_layout Standard
440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
443 \begin_layout Standard
449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
452 \begin_layout Standard
460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
463 \begin_layout Standard
469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
472 \begin_layout Standard
478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
481 \begin_layout Standard
487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
490 \begin_layout Standard
496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
499 \begin_layout Standard
506 <row topline="true" bottomline="true">
507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
510 \begin_layout Standard
516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
519 \begin_layout Standard
525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
528 \begin_layout Standard
534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
537 \begin_layout Standard
538 -2.147.483.648, +2.147.483.647
543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
546 \begin_layout Standard
553 <row topline="true" bottomline="true">
554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
557 \begin_layout Standard
563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
566 \begin_layout Standard
572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
575 \begin_layout Standard
581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
584 \begin_layout Standard
590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
593 \begin_layout Standard
609 <row topline="true" bottomline="true">
610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
613 \begin_layout Standard
619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
622 \begin_layout Standard
628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
631 \begin_layout Standard
637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
640 \begin_layout Standard
646 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
649 \begin_layout Standard
662 The compiler also allows
664 inline assembler code
666 to be embedded anywhere in a function.
667 In addition, routines developed in assembly can also be called.
672 provides an option (-
676 \begin_layout Standard
685 -cyclomatic) to report the relative complexity of a function.
686 These functions can then be further optimized, or hand coded in assembly
692 SDCC also comes with a companion source level debugger SDCDB.
693 The debugger currently uses ucSim, a free open source simulator for 8051
694 and other micro-controllers.
698 The latest SDCC version can be downloaded from
700 \begin_inset LatexCommand url
701 target "http://sdcc.sourceforge.net/snap.php"
708 Please note: the compiler will probably always be some steps ahead of this
713 \begin_inset LatexCommand index
714 name "Status of documentation"
722 \begin_layout Standard
723 Obviously this has pros and cons
731 \begin_layout Section
735 \begin_layout Standard
736 All packages used in this compiler system are
744 ; source code for all the sub-packages (pre-processor, assemblers, linkers
745 etc.) is distributed with the package.
746 This documentation is maintained using a free open source word processor
749 This program is free software; you can redistribute it and/or modify
750 it under the terms of the GNU General Public License
751 \begin_inset LatexCommand index
752 name "GNU General Public License, GPL"
756 as published by the Free Software Foundation; either version 2, or (at
757 your option) any later version.
758 This program is distributed in the hope that it will be useful, but WITHOUT
759 ANY WARRANTY; without even the implied warranty
760 \begin_inset LatexCommand index
765 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
766 See the GNU General Public License for more details.
767 You should have received a copy of the GNU General Public License along
768 with this program; if not, write to the Free Software Foundation, 59 Temple
769 Place - Suite 330, Boston, MA 02111-1307, USA.
770 In other words, you are welcome to use, share and improve this program.
771 You are forbidden to forbid anyone else to use, share and improve what
773 Help stamp out software-hoarding!
776 \begin_layout Section
777 Typographic conventions
778 \begin_inset LatexCommand index
779 name "Typographic conventions"
786 \begin_layout Standard
787 Throughout this manual, we will use the following convention.
788 Commands you have to type in are printed in
796 Code samples are printed in
801 Interesting items and new terms are printed in
806 \begin_layout Section
808 \begin_inset LatexCommand label
809 name "sec:Compatibility-with-previous"
813 with previous versions
814 \begin_inset LatexCommand index
815 name "Compatibility with previous versions"
822 \begin_layout Standard
823 Newer versions have usually numerous bug fixes compared with the previous
825 But we also sometimes introduce some incompatibilities with older versions.
826 Not just for the fun of it, but to make the compiler more stable, efficient
828 \begin_inset LatexCommand index
829 name "ANSI-compliance"
834 \begin_inset LatexCommand ref
835 reference "sub:ANSI-Compliance"
839 for ANSI-Compliance).
841 \begin_inset Note Note
844 \begin_layout Standard
845 It would be fine to add to each item, in which version was it changed.
855 \begin_layout Itemize
856 short is now equivalent to int (16 bits), it used to be equivalent to char
857 (8 bits) which is not ANSI compliant.
858 To maintain compatibility, old programs may be compiled using the -
862 \begin_layout Standard
871 -short-is-8bits commandline option (see
872 \begin_inset LatexCommand vref
873 reference "lyx:--short-is-8bits"
880 \begin_layout Itemize
881 the default directory for gcc-builds where include, library and documentation
882 files are stored is now in /usr/local/share.
885 \begin_layout Itemize
886 char type parameters to vararg
887 \begin_inset LatexCommand index
888 name "vararg, va\\_arg"
892 functions are casted to int unless explicitly casted and
898 \begin_layout Standard
908 \begin_inset LatexCommand index
921 \begin_layout Standard
931 \begin_inset LatexCommand index
938 command line option are not defined
939 \begin_inset Marginal
942 \begin_layout Standard
967 will push a as an int and as a char resp if
973 \begin_layout Standard
983 \begin_inset LatexCommand index
996 \begin_layout Standard
1006 \begin_inset LatexCommand index
1013 command line options are not defined,
1015 will push a as two ints if
1021 \begin_layout Standard
1031 \begin_inset LatexCommand index
1044 \begin_layout Standard
1054 \begin_inset LatexCommand index
1061 command line option is defined.
1064 \begin_layout Itemize
1069 \begin_layout Standard
1078 -regextend has been removed.
1081 \begin_layout Itemize
1086 \begin_layout Standard
1095 -noregparms has been removed.
1098 \begin_layout Itemize
1103 \begin_layout Standard
1112 -stack-after-data has been removed.
1115 \begin_layout Itemize
1117 \begin_inset LatexCommand index
1123 \begin_inset LatexCommand index
1129 \begin_inset LatexCommand index
1134 types now consistently behave like the C99 _Bool type with respect to type
1136 \begin_inset LatexCommand index
1137 name "type conversion"
1142 \begin_inset LatexCommand index
1143 name "type promotion"
1148 The most common incompatibility resulting from this change is related to
1150 \begin_inset LatexCommand index
1166 \begin_inset LatexCommand index
1167 name "\\~\\/ Operator"
1171 b; /* equivalent to b=1 instead of toggling b */
1172 \begin_inset Marginal
1175 \begin_layout Standard
1188 b = !b; /* toggles b */
1192 In previous versions, both forms would have toggled the bit.
1195 \begin_layout Itemize
1196 in older versions, the preprocessor was always called with
1202 \begin_layout Standard
1212 \begin_inset LatexCommand index
1225 \begin_layout Standard
1237 This is no longer true, and can cause compilation failures on code built
1244 \begin_layout Standard
1254 \begin_inset LatexCommand index
1261 but using c99 preprocessor features, such as one-line (//) comments
1264 \begin_layout Itemize
1265 in versions older then 2.8.4 the pic16 *printf() and printf_tiny() library
1266 functions supported undocumented and not standard compliant 'b' binary
1267 format specifier ("%b", "%hb" and "%lb").
1268 The 'b' specifier is now disabled by default.
1269 It can be enabled by defining BINARY_SPECIFIER macro in files device/lib/pic16/
1270 libc/stdio/vfprintf.c and device/lib/pic16/libc/stdio/printf_tiny.c and recompilin
1274 \begin_layout Itemize
1275 in versions older then 2.8.5 the unnamed bitfield structure members participated
1276 in initialization, which is not conforming with ISO/IEC 9899:1999 standard
1277 (see section Section 6.7.8 Initialization, clause 9)
1281 Old behavior, before
1317 /* s.a = 1, s.b = 3 */
1358 /* s.a = 1, s.b = 2 */
1361 \begin_layout Section
1365 \begin_layout Standard
1366 What do you need before you start installation of SDCC? A computer, and
1367 a desire to compute.
1368 The preferred method of installation is to compile SDCC from source using
1370 For Windows some pre-compiled binary distributions are available for your
1372 You should have some experience with command line tools and compiler use.
1375 \begin_layout Section
1379 \begin_layout Standard
1380 The SDCC home page at
1381 \begin_inset LatexCommand url
1382 target "http://sdcc.sourceforge.net/"
1386 is a great place to find distribution sets.
1387 You can also find links to the user mailing lists that offer help or discuss
1388 SDCC with other SDCC users.
1389 Web links to other SDCC related sites can also be found here.
1390 This document can be found in the DOC directory of the source package as
1391 a text or HTML file.
1392 A pdf version of this document is available at
1393 \begin_inset LatexCommand url
1394 target "http://sdcc.sourceforge.net/doc/sdccman.pdf"
1399 Some of the other tools (simulator and assembler) included with SDCC contain
1400 their own documentation and can be found in the source distribution.
1401 If you want the latest unreleased software, the complete source package
1402 is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1406 \begin_layout Section
1407 Wishes for the future
1410 \begin_layout Standard
1411 There are (and always will be) some things that could be done.
1412 Here are some I can think of:
1417 \begin_layout Standard
1420 char KernelFunction3(char p) at 0x340;
1425 \begin_layout Standard
1429 \begin_inset LatexCommand index
1430 name "code banking (limited support)"
1440 If you can think of some more, please see the section
1441 \begin_inset LatexCommand ref
1442 reference "sub:Requesting-Features"
1446 about filing feature requests
1447 \begin_inset LatexCommand index
1448 name "Requesting features"
1453 \begin_inset LatexCommand index
1454 name "Feature request"
1463 \begin_layout Chapter
1465 \begin_inset LatexCommand index
1473 \begin_layout Standard
1474 For most users it is sufficient to skip to either section
1475 \begin_inset LatexCommand ref
1476 reference "sub:Building-SDCC-on-Linux"
1481 \begin_inset LatexCommand ref
1482 reference "sub:Windows-Install"
1487 More detailed instructions follow below.
1490 \begin_layout Section
1492 \begin_inset LatexCommand index
1493 name "Options SDCC configuration"
1500 \begin_layout Standard
1501 The install paths, search paths and other options are defined when running
1503 The defaults can be overridden by:
1507 \labelwidthstring 00.00.0000
1512 \begin_layout Standard
1521 -prefix see table below
1525 \labelwidthstring 00.00.0000
1530 \begin_layout Standard
1539 -exec_prefix see table below
1543 \labelwidthstring 00.00.0000
1548 \begin_layout Standard
1557 -bindir see table below
1561 \labelwidthstring 00.00.0000
1566 \begin_layout Standard
1575 -datadir see table below
1579 \labelwidthstring 00.00.0000
1584 \begin_layout Standard
1593 -datarootdir see table below
1599 \labelwidthstring 00.00.0000
1602 docdir environment variable, see table below
1606 \labelwidthstring 00.00.0000
1609 include_dir_suffix environment variable, see table below
1613 \labelwidthstring 00.00.0000
1616 lib_dir_suffix environment variable, see table below
1620 \labelwidthstring 00.00.0000
1623 sdccconf_h_dir_separator environment variable, either / or
1628 This character will only be used in sdccconf.h; don't forget it's a C-header,
1629 therefore a double-backslash is needed there.
1635 \labelwidthstring 00.00.0000
1640 \begin_layout Standard
1649 -disable-mcs51-port Excludes the Intel mcs51 port
1653 \labelwidthstring 00.00.0000
1658 \begin_layout Standard
1667 -disable-gbz80-port Excludes the Gameboy gbz80 port
1671 \labelwidthstring 00.00.0000
1676 \begin_layout Standard
1685 -disable-z80-port Excludes the z80 port
1689 \labelwidthstring 00.00.0000
1694 \begin_layout Standard
1703 -disable-avr-port Excludes the AVR port
1707 \labelwidthstring 00.00.0000
1712 \begin_layout Standard
1721 -disable-ds390-port Excludes the DS390 port
1725 \labelwidthstring 00.00.0000
1730 \begin_layout Standard
1739 -disable-hc08-port Excludes the HC08 port
1743 \labelwidthstring 00.00.0000
1748 \begin_layout Standard
1757 -disable-pic-port Excludes the PIC14 port
1761 \labelwidthstring 00.00.0000
1766 \begin_layout Standard
1775 -disable-pic16-port Excludes the PIC16 port
1779 \labelwidthstring 00.00.0000
1784 \begin_layout Standard
1793 -disable-xa51-port Excludes the XA51 port
1797 \labelwidthstring 00.00.0000
1802 \begin_layout Standard
1811 -disable-ucsim Disables configuring and building of ucsim
1815 \labelwidthstring 00.00.0000
1820 \begin_layout Standard
1829 -disable-device-lib Disables automatically building device libraries
1833 \labelwidthstring 00.00.0000
1838 \begin_layout Standard
1847 -disable-packihx Disables building packihx
1853 \labelwidthstring 00.00.0000
1858 \begin_layout Standard
1867 -enable-doc Build pdf, html and txt files from the lyx sources
1871 \labelwidthstring 00.00.0000
1876 \begin_layout Standard
1885 -enable-libgc Use the Bohem memory allocator.
1886 Lower runtime footprint.
1890 \labelwidthstring 00.00.0000
1895 \begin_layout Standard
1904 -without-ccache Do not use ccache even if available
1907 \begin_layout Standard
1908 Furthermore the environment variables CC, CFLAGS, ...
1909 the tools and their arguments can be influenced.
1910 Please see `configure -
1914 \begin_layout Standard
1923 -help' and the man/info pages of `configure' for details.
1928 standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1929 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1930 SDCC_LIB_NAME are defined by `configure' too.
1931 At the moment it's not possible to change the default settings (it was
1932 simply never required).
1936 These configure options are compiled into the binaries,
1937 and can only be changed by rerunning 'configure' and recompiling SDCC.
1938 The configure options are written in
1942 to distinguish them from run time environment variables (see section search
1948 \begin_inset Quotes sld
1952 \begin_inset Quotes srd
1955 are used by the SDCC team to build the official Win32 binaries.
1956 The SDCC team uses Mingw32 to build the official Windows binaries, because
1960 \begin_layout Enumerate
1964 \begin_layout Enumerate
1965 a gcc compiler and last but not least
1968 \begin_layout Enumerate
1969 the binaries can be built by cross compiling on SDCC Distributed Compile
1973 \begin_layout Standard
1974 See the examples, how to pass the Win32 settings to 'configure'.
1975 The other Win32 builds using Borland, VC or whatever don't use 'configure',
1976 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1986 \begin_layout Standard
1988 \begin_inset Tabular
1989 <lyxtabular version="3" rows="9" columns="3">
1991 <column alignment="block" valignment="top" leftline="true" width="0in">
1992 <column alignment="block" valignment="top" leftline="true" width="0in">
1993 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1994 <row topline="true" bottomline="true">
1995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1998 \begin_layout Standard
2004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2007 \begin_layout Standard
2013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2016 \begin_layout Standard
2023 <row topline="true">
2024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2027 \begin_layout Standard
2035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2038 \begin_layout Standard
2044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2047 \begin_layout Standard
2056 <row topline="true">
2057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2060 \begin_layout Standard
2068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2071 \begin_layout Standard
2079 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2082 \begin_layout Standard
2091 <row topline="true">
2092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2095 \begin_layout Standard
2103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2106 \begin_layout Standard
2116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2119 \begin_layout Standard
2132 <row topline="true">
2133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2136 \begin_layout Standard
2144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2147 \begin_layout Standard
2155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2158 \begin_layout Standard
2167 <row topline="true">
2168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2171 \begin_layout Standard
2179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2182 \begin_layout Standard
2192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2195 \begin_layout Standard
2204 <row topline="true">
2205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2208 \begin_layout Standard
2216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2219 \begin_layout Standard
2229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2232 \begin_layout Standard
2245 <row topline="true">
2246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2249 \begin_layout Standard
2257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2260 \begin_layout Standard
2266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2269 \begin_layout Standard
2276 <row topline="true" bottomline="true">
2277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2280 \begin_layout Standard
2288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2291 \begin_layout Standard
2297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2300 \begin_layout Standard
2316 \begin_layout Standard
2318 'configure' also computes relative paths.
2319 This is needed for full relocatability of a binary package and to complete
2320 search paths (see section search paths below):
2325 \begin_layout Standard
2327 \begin_inset Tabular
2328 <lyxtabular version="3" rows="4" columns="3">
2330 <column alignment="block" valignment="top" leftline="true" width="0in">
2331 <column alignment="block" valignment="top" leftline="true" width="0in">
2332 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2333 <row topline="true" bottomline="true">
2334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2337 \begin_layout Standard
2343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2346 \begin_layout Standard
2352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2355 \begin_layout Standard
2362 <row topline="true" bottomline="true">
2363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2366 \begin_layout Standard
2374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2377 \begin_layout Standard
2383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2386 \begin_layout Standard
2393 <row bottomline="true">
2394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2397 \begin_layout Standard
2405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2408 \begin_layout Standard
2414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2417 \begin_layout Standard
2424 <row bottomline="true">
2425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2428 \begin_layout Standard
2436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2439 \begin_layout Standard
2445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2448 \begin_layout Standard
2464 \begin_layout Standard
2469 \begin_layout LyX-Code
2476 \begin_layout Standard
2486 \begin_inset Quotes srd
2490 \begin_inset Quotes srd
2497 \begin_layout Standard
2507 \begin_inset Quotes srd
2511 \begin_inset Quotes srd
2520 \begin_layout Standard
2533 \begin_layout Standard
2545 \begin_layout Standard
2546 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2550 \begin_layout LyX-Code
2556 \begin_inset Quotes srd
2559 i586-mingw32msvc-gcc
2560 \begin_inset Quotes srd
2564 \begin_inset Quotes srd
2567 i586-mingw32msvc-g++
2568 \begin_inset Quotes srd
2576 \begin_inset Quotes srd
2579 i586-mingw32msvc-ranlib
2580 \begin_inset Quotes srd
2588 \begin_inset Quotes srd
2591 i586-mingw32msvc-strip
2592 \begin_inset Quotes srd
2603 \begin_layout Standard
2613 \begin_inset Quotes srd
2617 \begin_inset Quotes srd
2628 \begin_layout Standard
2638 \begin_inset Quotes srd
2642 \begin_inset Quotes srd
2650 \begin_inset Quotes srd
2656 \begin_inset Quotes srd
2664 \begin_inset Quotes srd
2668 \begin_inset Quotes srd
2676 \begin_inset Quotes srd
2680 \begin_inset Quotes srd
2687 sdccconf_h_dir_separator=
2688 \begin_inset Quotes srd
2700 \begin_inset Quotes srd
2711 \begin_layout Standard
2728 \begin_layout Standard
2737 -host=i586-mingw32msvc
2745 \begin_layout Standard
2754 -build=unknown-unknown-linux-gnu
2757 \begin_layout Standard
2759 \begin_inset Quotes sld
2763 \begin_inset Quotes srd
2766 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2770 \begin_layout LyX-Code
2779 \begin_layout Standard
2789 \begin_inset Quotes srd
2793 \begin_inset Quotes srd
2804 \begin_layout Standard
2814 \begin_inset Quotes srd
2818 \begin_inset Quotes srd
2826 \begin_inset Quotes srd
2832 \begin_inset Quotes srd
2840 \begin_inset Quotes srd
2844 \begin_inset Quotes srd
2852 \begin_inset Quotes srd
2856 \begin_inset Quotes srd
2863 sdccconf_h_dir_separator=
2864 \begin_inset Quotes srd
2876 \begin_inset Quotes srd
2884 \begin_inset Quotes srd
2888 \begin_inset Quotes srd
2896 \begin_inset Quotes srd
2900 \begin_inset Quotes srd
2906 \begin_layout Standard
2907 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2912 \begin_layout Standard
2921 -C' turns on caching, which gives a little bit extra speed.
2922 However if options are changed, it can be necessary to delete the config.cache
2926 \begin_layout Section
2928 \begin_inset LatexCommand label
2929 name "sub:Install-paths"
2934 \begin_inset LatexCommand index
2935 name "Install paths"
2942 \begin_layout Standard
2943 \begin_inset VSpace medskip
2949 \begin_layout Standard
2951 \begin_inset Tabular
2952 <lyxtabular version="3" rows="5" columns="4">
2954 <column alignment="left" valignment="top" leftline="true" width="0">
2955 <column alignment="left" valignment="top" leftline="true" width="0">
2956 <column alignment="left" valignment="top" leftline="true" width="0">
2957 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2958 <row topline="true" bottomline="true">
2959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2962 \begin_layout Standard
2970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2973 \begin_layout Standard
2981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2984 \begin_layout Standard
2992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2995 \begin_layout Standard
3004 <row topline="true">
3005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3008 \begin_layout Standard
3014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3017 \begin_layout Standard
3025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3028 \begin_layout Standard
3034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3037 \begin_layout Standard
3048 <row topline="true">
3049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3052 \begin_layout Standard
3058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3061 \begin_layout Standard
3064 $DATADIR/ $INCLUDE_DIR_SUFFIX
3069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3072 \begin_layout Standard
3073 /usr/local/share/sdcc/include
3078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3081 \begin_layout Standard
3092 <row topline="true">
3093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3096 \begin_layout Standard
3102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3105 \begin_layout Standard
3108 $DATADIR/$LIB_DIR_SUFFIX
3113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3116 \begin_layout Standard
3117 /usr/local/share/sdcc/lib
3122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3125 \begin_layout Standard
3136 <row topline="true" bottomline="true">
3137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3140 \begin_layout Standard
3146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3149 \begin_layout Standard
3157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3160 \begin_layout Standard
3161 /usr/local/share/sdcc/doc
3166 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3169 \begin_layout Standard
3190 *compiler, preprocessor, assembler, and linker
3196 is auto-appended by the compiler, e.g.
3197 small, large, z80, ds390 etc
3200 \begin_layout Standard
3202 The install paths can still be changed during `make install' with e.g.:
3205 \begin_layout LyX-Code
3206 make install prefix=$(HOME)/local/sdcc
3209 \begin_layout Standard
3210 Of course this doesn't change the search paths compiled into the binaries.
3215 r the install path can be changed by defining DESTDIR
3216 \begin_inset LatexCommand index
3224 \begin_layout LyX-Code
3225 make install DESTDIR=$(HOME)/sdcc.rpm/
3228 \begin_layout Standard
3229 Please note that DESTDIR must have a trailing slash!
3232 \begin_layout Section
3234 \begin_inset LatexCommand label
3235 name "sub:Search-Paths"
3240 \begin_inset LatexCommand index
3248 \begin_layout Standard
3249 Some search paths or parts of them are determined by configure variables
3254 , see section above).
3255 Further search paths are determined by environment variables during runtime.
3258 The paths searched when running the compiler are as follows (the first
3264 Binary files (preprocessor, assembler and linker)
3269 \begin_layout Standard
3271 \begin_inset Tabular
3272 <lyxtabular version="3" rows="4" columns="3">
3274 <column alignment="block" valignment="top" leftline="true" width="0in">
3275 <column alignment="block" valignment="top" leftline="true" width="0in">
3276 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3277 <row topline="true" bottomline="true">
3278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3281 \begin_layout Standard
3287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3290 \begin_layout Standard
3296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3299 \begin_layout Standard
3306 <row topline="true">
3307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3310 \begin_layout Standard
3318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3321 \begin_layout Standard
3327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3330 \begin_layout Standard
3339 <row topline="true">
3340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3343 \begin_layout Standard
3344 Path of argv[0] (if available)
3349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3352 \begin_layout Standard
3358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3361 \begin_layout Standard
3368 <row topline="true" bottomline="true">
3369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3372 \begin_layout Standard
3378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3381 \begin_layout Standard
3387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3390 \begin_layout Standard
3406 \begin_layout Standard
3414 \begin_layout Standard
3416 \begin_inset Tabular
3417 <lyxtabular version="3" rows="6" columns="3">
3419 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3420 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3421 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3422 <row topline="true" bottomline="true">
3423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3426 \begin_layout Standard
3432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3435 \begin_layout Standard
3441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3444 \begin_layout Standard
3451 <row topline="true">
3452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3455 \begin_layout Standard
3460 \begin_layout Standard
3474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3477 \begin_layout Standard
3482 \begin_layout Standard
3496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3499 \begin_layout Standard
3504 \begin_layout Standard
3519 <row topline="true">
3520 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3523 \begin_layout Standard
3529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3532 \begin_layout Standard
3538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3541 \begin_layout Standard
3548 <row topline="true">
3549 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3552 \begin_layout Standard
3564 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3567 \begin_layout Standard
3577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3580 \begin_layout Standard
3589 <row topline="true">
3590 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3593 \begin_layout Standard
3609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3612 \begin_layout Standard
3660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3663 \begin_layout Standard
3674 <row topline="true" bottomline="true">
3675 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3678 \begin_layout Standard
3692 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3695 \begin_layout Standard
3696 /usr/local/share/sdcc/
3703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3706 \begin_layout Standard
3722 \begin_layout Standard
3728 \begin_layout Standard
3737 -nostdinc disables the last two search paths.
3747 \begin_layout Standard
3748 With the exception of
3749 \begin_inset Quotes sld
3756 \begin_layout Standard
3766 \begin_inset Quotes srd
3773 is auto-appended by the compiler (e.g.
3774 small, large, z80, ds390 etc.).
3780 \begin_layout Standard
3782 \begin_inset Tabular
3783 <lyxtabular version="3" rows="6" columns="3">
3785 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3786 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3787 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3788 <row topline="true" bottomline="true">
3789 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3792 \begin_layout Standard
3798 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3801 \begin_layout Standard
3807 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3810 \begin_layout Standard
3817 <row topline="true">
3818 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3821 \begin_layout Standard
3826 \begin_layout Standard
3840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3843 \begin_layout Standard
3848 \begin_layout Standard
3862 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3865 \begin_layout Standard
3870 \begin_layout Standard
3885 <row topline="true">
3886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3889 \begin_layout Standard
3899 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3902 \begin_layout Standard
3912 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3915 \begin_layout Standard
3928 <row topline="true">
3929 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3932 \begin_layout Standard
3939 $LIB_DIR_SUFFIX/<model>
3944 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3947 \begin_layout Standard
3959 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3962 \begin_layout Standard
3977 <row topline="true">
3978 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3981 \begin_layout Standard
3992 $LIB_DIR_SUFFIX/<model>
3997 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
4000 \begin_layout Standard
4051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4054 \begin_layout Standard
4108 <row topline="true" bottomline="true">
4109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4112 \begin_layout Standard
4117 $LIB_DIR_SUFFIX/<model>
4122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4125 \begin_layout Standard
4126 /usr/local/share/sdcc/
4135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4138 \begin_layout Standard
4154 \begin_layout Standard
4155 \begin_inset Note Note
4158 \begin_layout Standard
4159 Don't delete any of the stray spaces in the table above without checking
4160 the HTML output (last line)!
4168 \begin_layout Standard
4176 \begin_layout Standard
4185 -nostdlib disables the last two search paths.
4188 \begin_layout Section
4190 \begin_inset LatexCommand index
4191 name "Building SDCC"
4198 \begin_layout Subsection
4199 Building SDCC on Linux
4200 \begin_inset LatexCommand label
4201 name "sub:Building-SDCC-on-Linux"
4208 \begin_layout Enumerate
4211 Download the source package
4213 either from the SDCC Subversion repository or from snapshot builds
4215 , it will be named something like sdcc
4226 \begin_inset LatexCommand url
4227 target "http://sdcc.sourceforge.net/snap.php"
4234 \begin_layout Enumerate
4237 Bring up a command line terminal, such as xterm.
4240 \begin_layout Enumerate
4243 Unpack the file using a command like:
4248 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
4249 \begin_inset Quotes srd
4255 , this will create a sub-directory called sdcc with all of the sources.
4258 \begin_layout Enumerate
4259 Change directory into the main SDCC directory, for example type:
4267 \begin_layout Enumerate
4279 This configures the package for compilation on your system.
4282 \begin_layout Enumerate
4298 All of the source packages will compile, this can take a while.
4301 \begin_layout Enumerate
4317 This copies the binary executables, the include files, the libraries and
4318 the documentation to the install directories.
4319 Proceed with section
4320 \begin_inset LatexCommand ref
4321 reference "sec:Testing-the-SDCC"
4328 \begin_layout Subsection
4329 Building SDCC on Mac OS X
4332 \begin_layout Standard
4333 Follow the instruction for Linux.
4337 On Mac OS X 10.2.x it was reported, that the
4338 default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
4339 Fortunately there's also gcc 2.9.x installed, which works fine.
4340 This compiler can be selected by running 'configure' with:
4343 \begin_layout LyX-Code
4344 ./configure CC=gcc2 CXX=g++2
4347 \begin_layout Standard
4348 Universal (ppc and i386) binaries can be produced on Mac OS X 10.4.x with
4350 Run 'configure' with:
4353 \begin_layout LyX-Code
4359 \begin_layout LyX-Code
4360 LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4366 \begin_layout LyX-Code
4367 CXXFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4373 \begin_layout LyX-Code
4374 CFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
4377 \begin_layout Subsection
4378 Cross compiling SDCC on Linux for Windows
4381 \begin_layout Standard
4382 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
4383 See section 'Configure Options'.
4386 \begin_layout Subsection
4387 Building SDCC using Cygwin and Mingw32
4390 \begin_layout Standard
4391 For building and installing a Cygwin executable follow the instructions
4397 \begin_inset Quotes sld
4401 \begin_inset Quotes srd
4404 Win32-binary can be built, which will not need the Cygwin-DLL.
4405 For the necessary 'configure' options see section 'configure options' or
4406 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4411 Cygwin on Windows download setup.exe from
4412 \begin_inset LatexCommand url
4413 name "www.cygwin.com"
4414 target "http://www.cygwin.com/"
4420 \begin_inset Quotes sld
4423 default text file type
4424 \begin_inset Quotes srd
4428 \begin_inset Quotes sld
4432 \begin_inset Quotes srd
4435 and download/install at least the following packages.
4436 Some packages are selected by default, others will be automatically selected
4437 because of dependencies with the manually selected packages.
4438 Never deselect these packages!
4441 \begin_layout Itemize
4445 \begin_layout Itemize
4449 \begin_layout Itemize
4450 gcc ; version 3.x is fine, no need to use the old 2.9x
4453 \begin_layout Itemize
4454 binutils ; selected with gcc
4457 \begin_layout Itemize
4461 \begin_layout Itemize
4462 rxvt ; a nice console, which makes life much easier under windoze (see below)
4465 \begin_layout Itemize
4466 man ; not really needed for building SDCC, but you'll miss it sooner or
4470 \begin_layout Itemize
4471 less ; not really needed for building SDCC, but you'll miss it sooner or
4475 \begin_layout Itemize
4476 svn ; only if you use Subversion access
4479 \begin_layout Standard
4480 If you want to develop something you'll need:
4483 \begin_layout Itemize
4484 python ; for the regression tests
4487 \begin_layout Itemize
4488 gdb ; the gnu debugger, together with the nice GUI
4489 \begin_inset Quotes sld
4493 \begin_inset Quotes srd
4499 \begin_layout Itemize
4500 openssh ; to access the CF or commit changes
4503 \begin_layout Itemize
4504 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4505 use autoconf-stable!
4508 \begin_layout Standard
4509 rxvt is a nice console with history.
4510 Replace in your cygwin.bat the line
4513 \begin_layout LyX-Code
4518 \begin_layout Standard
4530 \begin_layout Standard
4534 \begin_layout LyX-Code
4535 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4538 \begin_layout LyX-Code
4539 -bg black -fg white -geometry 100x65 -e bash -
4543 \begin_layout Standard
4555 \begin_layout Standard
4556 Text selected with the mouse is automatically copied to the clipboard, pasting
4557 works with shift-insert.
4561 The other good tip is to make sure you have no //c/-styl
4562 e paths anywhere, use /cygdrive/c/ instead.
4563 Using // invokes a network lookup which is very slow.
4565 \begin_inset Quotes sld
4569 \begin_inset Quotes srd
4572 is too long, you can change it with e.g.
4575 \begin_layout LyX-Code
4579 \begin_layout Standard
4580 SDCC sources use the unix line ending LF.
4581 Life is much easier, if you store the source tree on a drive which is mounted
4583 And use an editor which can handle LF-only line endings.
4584 Make sure not to commit files with windows line endings.
4585 The tabulator spacing
4586 \begin_inset LatexCommand index
4587 name "tabulator spacing (8 columns)"
4591 used in the project is 8.
4592 Although a tabulator spacing of 8 is a sensible choice for programmers
4593 (it's a power of 2 and allows to display 8/16 bit signed variables without
4594 loosing columns) the plan is to move towards using only spaces in the source.
4597 \begin_layout Subsection
4598 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4601 \begin_layout Standard
4604 Download the source package
4606 either from the SDCC Subversion repository or from the
4607 \begin_inset LatexCommand url
4608 name "snapshot builds"
4609 target "http://sdcc.sourceforge.net/snap.php"
4615 , it will be named something like sdcc
4619 -yyyymmdd-rrrr.tar.bz2.
4622 SDCC is distributed with all the projects, workspaces, and files you need
4623 to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4624 The workspace name is 'sdcc.dsw'.
4625 Please note that as it is now, all the executables are created in a folder
4629 Once built you need to copy the executables from sdcc
4633 bin before running SDCC.
4638 WARNING: Visual studio is very picky with line terminations; it expects
4639 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4640 When using the Subversion repository it's easiest to configure the svn
4641 client to convert automatically for you.
4642 If however you are getting a message such as "This makefile was not generated
4643 by Developer Studio etc.
4645 \begin_inset Quotes srd
4648 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4649 need to convert the Unix style line endings to DOS style line endings.
4650 To do so you can use the
4651 \begin_inset Quotes sld
4655 \begin_inset Quotes srd
4658 utility freely available on the internet.
4659 Doug Hawkins reported in the sdcc-user list that this works:
4667 SDCC> unix2dos sdcc.dsw
4673 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4677 In order to build SDCC with MSVC
4678 you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4679 One good place to get them is
4680 \begin_inset LatexCommand url
4682 target "http://unxutils.sourceforge.net"
4690 Download the file UnxUtils
4691 \begin_inset LatexCommand index
4697 Now you have to install the utilities and setup MSVC so it can locate the
4699 Here there are two alternatives (choose one!):
4702 \begin_layout Enumerate
4707 a) Extract UnxUtils.zip to your C:
4709 hard disk PRESERVING the original paths, otherwise bison won't work.
4710 (If you are using WinZip make certain that 'Use folder names' is selected)
4715 In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4716 'Show directories for:' select 'Executable files', and in the directories
4717 window add a new path: 'C:
4727 (As a side effect, you get a bunch of Unix utilities that
4728 could be useful, such as diff and patch.)
4731 \begin_layout Enumerate
4736 This one avoids extracting a bunch of files you may not
4737 use, but requires some extra work:
4741 a) Create a directory were to put the
4742 tools needed, or use a directory already present.
4749 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4750 gawk.exe to such directory WITHOUT preserving the original paths.
4751 (If you are using WinZip make certain that 'Use folder names' is not selected)
4756 ) Rename bison.exe to '_bison.exe'.
4760 d) Create a batch file 'bison.bat' in 'C:
4764 ' and add these lines:
4784 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4788 Steps 'c' and 'd' are needed
4789 because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4790 reside in some weird Unix directory, '/usr/local/share/' I think.
4791 So it is necessary to tell bison where those files are located if they
4792 are not in such directory.
4793 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4798 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4799 in 'Show directories for:' select 'Executable files', and in the directories
4800 window add a new path: 'c:
4803 Note that you can use any other path instead of 'c:
4805 util', even the path where the Visual C++ tools are, probably: 'C:
4809 Microsoft Visual Studio
4814 So you don't have to execute step 'e' :)
4817 \begin_layout Standard
4819 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4820 the executables from sdcc
4824 bin, and you can compile using SDCC.
4827 \begin_layout Subsection
4828 Building SDCC Using Borland
4831 \begin_layout Enumerate
4832 From the sdcc directory, run the command "make -f Makefile.bcc".
4833 This should regenerate all the .exe files in the bin directory except for
4837 \begin_layout Enumerate
4838 If you modify any source files and need to rebuild, be aware that the dependenci
4839 es may not be correctly calculated.
4840 The safest option is to delete all .obj files and run the build again.
4841 From a Cygwin BASH prompt, this can easily be done with the command (be
4842 sure you are in the sdcc directory):
4852 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
4854 ) -print -exec rm {}
4863 or on Windows NT/2000/XP from the command prompt with the command:
4870 del /s *.obj *.lib *.rul
4873 from the sdcc directory.
4876 \begin_layout Subsection
4877 Windows Install Using a ZIP Package
4880 \begin_layout Enumerate
4881 Download the binary zip package from
4882 \begin_inset LatexCommand url
4883 target "http://sdcc.sf.net/snap.php"
4887 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4888 This should unpack to a group of sub-directories.
4889 An example directory structure after unpacking the mingw32 package is:
4894 bin for the executables, c:
4902 lib for the include and libraries.
4905 \begin_layout Enumerate
4906 Adjust your environment variable PATH to include the location of the bin
4907 directory or start sdcc using the full path.
4910 \begin_layout Subsection
4911 Windows Install Using the Setup Program
4912 \begin_inset LatexCommand label
4913 name "sub:Windows-Install"
4920 \begin_layout Standard
4921 Download the setup program
4923 sdcc-x.y.z-setup.exe
4925 for an official release from
4928 \begin_inset LatexCommand url
4929 target "http://sf.net/project/showfiles.php?group_id=599"
4933 or a setup program for one of the snapshots
4935 sdcc-yyyymmdd-xxxx-setup.exe
4938 \begin_inset LatexCommand url
4939 target "http://sdcc.sf.net/snap.php"
4944 A windows typical installer will guide you through the installation process.
4947 \begin_layout Subsection
4949 \begin_inset LatexCommand index
4957 \begin_layout Standard
4958 SDCC supports the VPATH feature provided by configure and make.
4959 It allows to separate the source and build trees.
4963 \begin_layout Standard
4990 \begin_layout Standard
4993 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4994 # extract source to directory sdcc
4997 \begin_layout Standard
5000 mkdir sdcc.build\InsetSpace ~
5009 # put output in sdcc.build
5012 \begin_layout Standard
5018 \begin_layout Standard
5021 ../sdcc/configure\InsetSpace ~
5029 # configure is doing all the magic!
5032 \begin_layout Standard
5038 \begin_layout Standard
5044 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
5045 It automagically computes the variables srcdir, top_srcdir and top_buildir
5051 the generated files will be in ~/sdcc.build, while the source files stay
5054 This is not only usefull for building different binaries, e.g.
5055 when cross compiling.
5056 It also gives you a much better overview in the source tree when all the
5057 generated files are not scattered between the source files.
5058 And the best thing is: if you want to change a file you can leave the original
5059 file untouched in the source directory.
5060 Simply copy it to the build directory, edit it, enter `make clean', `rm
5061 Makefile.dep' and `make'.
5066 will do the rest for you!
5069 \begin_layout Section
5070 Building the Documentation
5073 \begin_layout Standard
5078 \begin_layout Standard
5087 -enable-doc to the configure arguments to build the documentation together
5088 with all the other stuff.
5089 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
5090 dvips and makeindex) to get the job done.
5091 Another possibility is to change to the doc directory and to type
5095 \begin_inset Quotes srd
5099 \begin_inset Quotes srd
5106 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
5109 \begin_inset LatexCommand url
5110 target "http://www.lyx.org"
5114 as editor is straightforward.
5115 Prebuilt documentation in html and pdf format is available from
5116 \begin_inset LatexCommand url
5117 target "http://sdcc.sf.net/snap.php"
5124 \begin_layout Section
5125 Reading the Documentation
5126 \begin_inset LatexCommand index
5127 name "Documentation"
5134 \begin_layout Standard
5135 Currently reading the document in pdf format is recommended, as for unknown
5136 reason the hyperlinks are working there whereas in the html version they
5141 \begin_layout Standard
5142 If you should know why please drop us a note
5150 You'll find the pdf version
5151 \begin_inset LatexCommand index
5152 name "PDF version of this document"
5157 \begin_inset LatexCommand url
5158 target "http://sdcc.sf.net/doc/sdccman.pdf"
5166 \begin_inset LatexCommand index
5167 name "HTML version of this document"
5172 \begin_inset LatexCommand url
5173 target "http://sdcc.sf.net/doc/sdccman.html/index.html"
5179 This documentation is in some aspects different from a commercial documentation:
5183 \begin_layout Itemize
5184 It tries to document SDCC for several processor architectures in one document
5185 (commercially these probably would be separate documents/products).
5187 \begin_inset LatexCommand index
5188 name "Status of documentation"
5192 currently matches SDCC for mcs51 and DS390 best and does give too few informati
5194 Z80, PIC14, PIC16 and HC08.
5197 \begin_layout Itemize
5198 There are many references pointing away from this documentation.
5199 Don't let this distract you.
5201 was a reference like
5202 \begin_inset LatexCommand url
5203 target "http://www.opencores.org"
5207 together with a statement
5208 \begin_inset Quotes sld
5211 some processors which are targetted by SDCC can be implemented in a
5228 \begin_inset LatexCommand index
5229 name "FPGA (field programmable gate array)"
5234 \begin_inset Quotes srd
5238 \begin_inset LatexCommand url
5239 target "http://sf.net/projects/fpgac"
5244 \begin_inset LatexCommand index
5245 name "FpgaC ((subset of) C to FPGA compiler)"
5250 \begin_inset Quotes sld
5253 have you ever heard of an open source compiler that compiles a subset of
5255 \begin_inset Quotes srd
5258 we expect you to have a quick look there and come back.
5259 If you read this you are on the right track.
5262 \begin_layout Itemize
5263 Some sections attribute more space to problems, restrictions and warnings
5264 than to the solution.
5267 \begin_layout Itemize
5268 The installation section and the section about the debugger is intimidating.
5271 \begin_layout Itemize
5272 There are still lots of typos and there are more different writing styles
5276 \begin_layout Section
5277 Testing the SDCC Compiler
5278 \begin_inset LatexCommand label
5279 name "sec:Testing-the-SDCC"
5286 \begin_layout Standard
5287 The first thing you should do after installing your SDCC compiler is to
5296 \begin_layout Standard
5306 \begin_inset LatexCommand index
5314 at the prompt, and the program should run and output its version like:
5319 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
5323 \begin_layout Standard
5324 If it doesn't run, or gives a message about not finding sdcc program, then
5325 you need to check over your installation.
5326 Make sure that the sdcc bin directory is in your executable search path
5327 defined by the PATH environment setting (
5332 \begin_inset LatexCommand ref
5333 reference "sub:Install-Trouble-shooting"
5340 Install trouble-shooting for suggestions
5343 Make sure that the sdcc program is in the bin folder, if not perhaps something
5344 did not install correctly.
5352 is commonly installed as described in section
5353 \begin_inset Quotes sld
5356 Install and search paths
5357 \begin_inset Quotes srd
5366 Make sure the compiler works on a very simple example.
5367 Type in the following test.c program using your favorite
5392 \begin_layout Standard
5395 Compile this using the following command:
5406 If all goes well, the compiler will generate a test.asm and test.rel file.
5407 Congratulations, you've just compiled your first program with SDCC.
5408 We used the -c option to tell SDCC not to link the generated code, just
5409 to keep things simple for this step.
5417 The next step is to try it with the linker.
5429 If all goes well the compiler will link with the libraries and produce
5430 a test.ihx output file.
5435 (no test.ihx, and the linker generates warnings), then the problem is most
5444 usr/local/share/sdcc/lib directory
5451 \begin_inset LatexCommand ref
5452 reference "sub:Install-Trouble-shooting"
5459 Install trouble-shooting for suggestions).
5467 The final test is to ensure
5475 header files and libraries.
5476 Edit test.c and change it to the following:
5494 strcpy(str1, "testing");
5499 \begin_layout Standard
5502 Compile this by typing
5511 This should generate a test.ihx output file, and it should give no warnings
5512 such as not finding the string.h file.
5513 If it cannot find the string.h file, then the problem is that
5517 cannot find the /usr/local/share/sdcc/include directory
5524 \begin_inset LatexCommand ref
5525 reference "sub:Install-Trouble-shooting"
5532 Install trouble-shooting section for suggestions).
5541 \begin_layout Standard
5553 \begin_inset LatexCommand index
5554 name "-\\/-print-search-dirs"
5558 to find exactly where SDCC is looking for the include and lib files.
5561 \begin_layout Section
5562 Install Trouble-shooting
5563 \begin_inset LatexCommand label
5564 name "sub:Install-Trouble-shooting"
5569 \begin_inset LatexCommand index
5570 name "Install trouble-shooting"
5577 \begin_layout Subsection
5578 If SDCC does not build correctly
5581 \begin_layout Standard
5582 A thing to try is starting from scratch by unpacking the .tgz source package
5583 again in an empty directory.
5591 ./configure 2>&1 | tee configure.log
5605 make 2>&1 | tee make.log
5612 If anything goes wrong, you can review the log files to locate the problem.
5613 Or a relevant part of this can be attached to an email that could be helpful
5614 when requesting help from the mailing list.
5617 \begin_layout Subsection
5619 \begin_inset Quotes sld
5623 \begin_inset Quotes srd
5629 \begin_layout Standard
5631 \begin_inset Quotes sld
5635 \begin_inset Quotes srd
5638 command is a script that analyzes your system and performs some configuration
5639 to ensure the source package compiles on your system.
5640 It will take a few minutes to run, and will compile a few tests to determine
5641 what compiler features are installed.
5644 \begin_layout Subsection
5646 \begin_inset Quotes sld
5650 \begin_inset Quotes srd
5656 \begin_layout Standard
5657 This runs the GNU make tool, which automatically compiles all the source
5658 packages into the final installed binary executables.
5661 \begin_layout Subsection
5663 \begin_inset Quotes sld
5667 \begin_inset Quotes erd
5673 \begin_layout Standard
5674 This will install the compiler, other executables libraries and include
5675 files into the appropriate directories.
5677 \begin_inset LatexCommand ref
5678 reference "sub:Install-paths"
5684 \begin_inset LatexCommand ref
5685 reference "sub:Search-Paths"
5690 about install and search paths.
5692 On most systems you will need super-user privilege
5696 \begin_layout Section
5700 \begin_layout Standard
5701 SDCC is not just a compiler, but a collection of tools by various developers.
5702 These include linkers, assemblers, simulators and other components.
5703 Here is a summary of some of the components.
5704 Note that the included simulator and assembler have separate documentation
5705 which you can find in the source package in their respective directories.
5706 As SDCC grows to include support for other processors, other packages from
5707 various developers are included and may have their own sets of documentation.
5712 might want to look at the files which are installed in <installdir>.
5713 At the time of this writing, we find the following programs for gcc-builds:
5718 In <installdir>/bin:
5721 \begin_layout Itemize
5722 sdcc - The compiler.
5725 \begin_layout Itemize
5726 sdcpp - The C preprocessor.
5729 \begin_layout Itemize
5730 asx8051 - The assembler for 8051 type processors.
5733 \begin_layout Itemize
5738 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5741 \begin_layout Itemize
5742 aslink -The linker for 8051 type processors.
5745 \begin_layout Itemize
5750 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5753 \begin_layout Itemize
5754 s51 - The ucSim 8051 simulator.
5757 \begin_layout Itemize
5758 sdcdb - The source debugger.
5761 \begin_layout Itemize
5762 packihx - A tool to pack (compress) Intel hex files.
5765 \begin_layout Standard
5766 In <installdir>/share/sdcc/include
5769 \begin_layout Itemize
5773 \begin_layout Standard
5774 In <installdir>/share/sdcc/lib
5777 \begin_layout Itemize
5778 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5782 \begin_layout Standard
5783 In <installdir>/share/sdcc/doc
5786 \begin_layout Itemize
5790 \begin_layout Standard
5791 As development for other processors proceeds, this list will expand to include
5792 executables to support processors like AVR, PIC, etc.
5795 \begin_layout Subsection
5799 \begin_layout Standard
5800 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5801 the assembler and linkage editor.
5804 \begin_layout Subsection
5805 sdcpp - The C-Preprocessor
5808 \begin_layout Standard
5810 \begin_inset LatexCommand index
5811 name "sdcpp (preprocessor)"
5815 is a modified version of the GNU cpp
5816 \begin_inset LatexCommand index
5817 name "cpp|see{sdcpp}"
5822 \begin_inset LatexCommand url
5823 target "http://gcc.gnu.org/"
5828 The C preprocessor is used to pull in #include sources, process #ifdef
5829 statements, #defines and so on.
5832 \begin_layout Subsection
5841 - The Assemblers and Linkage Editors
5844 \begin_layout Standard
5845 This is retargettable assembler & linkage editor, it was developed by Alan
5847 John Hartman created the version for 8051, and I (Sandeep) have made some
5848 enhancements and bug fixes for it to work properly with SDCC.
5851 \begin_layout Subsection
5855 \begin_layout Standard
5857 \begin_inset LatexCommand index
5862 is a free open source simulator developed by Daniel Drotos.
5863 The simulator is built as part of the build process.
5864 For more information visit Daniel's web site at:
5865 \begin_inset LatexCommand url
5866 target "http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51"
5871 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5875 \begin_layout Subsection
5876 sdcdb - Source Level Debugger
5879 \begin_layout Standard
5881 \begin_inset LatexCommand index
5882 name "SDCDB (debugger)"
5886 is the companion source level debugger.
5887 More about SDCDB in section
5888 \begin_inset LatexCommand ref
5889 reference "cha:Debugging-with-SDCDB"
5894 The current version of the debugger uses Daniel's Simulator S51
5895 \begin_inset LatexCommand index
5900 , but can be easily changed to use other simulators.
5903 \begin_layout Chapter
5907 \begin_layout Section
5911 \begin_layout Subsection
5912 Single Source File Projects
5915 \begin_layout Standard
5916 For single source file 8051 projects the process is very simple.
5917 Compile your programs with the following command
5920 "sdcc sourcefile.c".
5924 This will compile, assemble and link your source file.
5925 Output files are as follows:
5928 \begin_layout Itemize
5930 \begin_inset LatexCommand index
5936 \begin_inset LatexCommand index
5937 name "Assembler source"
5941 file created by the compiler
5944 \begin_layout Itemize
5946 \begin_inset LatexCommand index
5952 \begin_inset LatexCommand index
5953 name "Assembler listing"
5957 file created by the Assembler
5960 \begin_layout Itemize
5962 \begin_inset LatexCommand index
5968 \begin_inset LatexCommand index
5969 name "Assembler listing"
5973 file updated with linkedit information, created by linkage editor
5976 \begin_layout Itemize
5978 \begin_inset LatexCommand index
5984 \begin_inset LatexCommand index
5985 name "Symbol listing"
5989 for the sourcefile, created by the assembler
5992 \begin_layout Itemize
5994 \begin_inset LatexCommand index
6000 \begin_inset LatexCommand index
6006 \begin_inset LatexCommand index
6011 created by the assembler, input to Linkage editor
6014 \begin_layout Itemize
6016 \begin_inset LatexCommand index
6022 \begin_inset LatexCommand index
6027 for the load module, created by the Linker
6030 \begin_layout Itemize
6032 \begin_inset LatexCommand index
6037 - A file with a summary of the memory usage
6040 \begin_layout Itemize
6042 \begin_inset LatexCommand index
6047 - The load module in Intel hex format
6048 \begin_inset LatexCommand index
6049 name "Intel hex format"
6053 (you can select the Motorola S19 format
6054 \begin_inset LatexCommand index
6055 name "Motorola S19 format"
6063 \begin_layout Standard
6073 \begin_inset LatexCommand index
6074 name "-\\/-out-fmt-s19"
6079 If you need another format you might want to use
6086 \begin_inset LatexCommand index
6087 name "objdump (tool)"
6098 \begin_inset LatexCommand index
6099 name "srecord (bin, hex, ... tool)"
6104 \begin_inset Note Note
6107 \begin_layout Standard
6114 \begin_inset LatexCommand vref
6115 reference "sub:Postprocessing-the-Intel"
6120 Both formats are documented in the documentation of srecord
6121 \begin_inset LatexCommand index
6122 name "srecord (bin, hex, ... tool)"
6129 \begin_layout Itemize
6131 \begin_inset LatexCommand index
6136 - An intermediate file containing debug information needed to create the
6141 \begin_layout Standard
6151 \begin_inset LatexCommand index
6159 \begin_layout Itemize
6161 \begin_inset LatexCommand index
6166 - An optional file (with -
6170 \begin_layout Standard
6179 -debug) containing debug information.
6180 The format is documented in cdbfileformat.pdf
6183 \begin_layout Itemize
6186 \begin_inset LatexCommand index
6187 name "<file> (no extension)"
6191 An optional AOMF or AOMF51
6192 \begin_inset LatexCommand index
6198 \begin_inset LatexCommand label
6203 file containing debug information (generated with option -
6207 \begin_layout Standard
6233 ormat is a subformat of the OMF51 format and is commonly used by third party
6235 \begin_inset LatexCommand index
6240 , simulators, emulators).
6243 \begin_layout Itemize
6245 \begin_inset LatexCommand index
6250 - Dump file to debug the compiler it self (generated with option -
6254 \begin_layout Standard
6263 -dumpall) (see section
6264 \begin_inset LatexCommand ref
6265 reference "sub:Intermediate-Dump-Options"
6271 \begin_inset LatexCommand ref
6272 reference "sub:The-anatomy-of"
6278 \begin_inset Quotes sld
6281 Anatomy of the compiler
6282 \begin_inset Quotes srd
6288 \begin_layout Subsection
6289 Postprocessing the Intel Hex
6290 \begin_inset LatexCommand index
6291 name "Intel hex format"
6296 \begin_inset LatexCommand label
6297 name "sub:Postprocessing-the-Intel"
6304 \begin_layout Standard
6305 In most cases this won't be needed but the Intel Hex file
6306 \begin_inset LatexCommand index
6311 which is generated by SDCC might include lines of varying length and the
6312 addresses within the file are not guaranteed to be strictly ascending.
6313 If your toolchain or a bootloader does not like this you can use the tool
6319 \begin_inset LatexCommand index
6320 name "packihx (tool)"
6324 which is part of the SDCC distribution:
6331 packihx sourcefile.ihx >sourcefile.hex
6338 The separately available
6343 \begin_inset LatexCommand index
6344 name "srecord (bin, hex, ... tool)"
6348 package additionally allows to set undefined locations to a predefined
6349 value, to insert checksums
6350 \begin_inset LatexCommand index
6355 of various flavours (crc, add, xor) and to perform other manipulations
6356 (convert, split, crop, offset, ...).
6364 srec_cat\InsetSpace ~
6366 sourcefile.ihx -intel\InsetSpace ~
6368 -o sourcefile.hex -intel
6375 An example for a more complex command line
6379 \begin_layout Standard
6380 the command backfills
6381 \begin_inset LatexCommand index
6382 name "backfill unused memory"
6386 unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
6388 If the program counter on an mcs51 runs wild the backfill pattern 0x12
6389 will be interpreted as an
6397 (where an emergency routine could sit).
6410 srec_cat\InsetSpace ~
6411 sourcefile.ihx -intel\InsetSpace ~
6413 -fill 0x12 0x0000 0xfffe\InsetSpace ~
6414 -little-endian-checksum-nega
6415 tive 0xfffe 0x02 0x02\InsetSpace ~
6417 -o sourcefile.hex -intel
6426 The srecord package is available at
6427 \begin_inset LatexCommand url
6428 target "http://sf.net/projects/srecord"
6435 \begin_layout Subsection
6436 Projects with Multiple Source Files
6439 \begin_layout Standard
6440 SDCC can compile only ONE file at a time.
6441 Let us for example assume that you have a project containing the following
6446 foo1.c (contains some functions)
6448 foo2.c (contains some more functions)
6451 n.c (contains more functions and the function main)
6459 The first two files will need to be compiled separately with the commands:
6491 Then compile the source file containing the
6496 \begin_inset LatexCommand index
6501 the files together with the following command:
6509 foomain.c\InsetSpace ~
6510 foo1.rel\InsetSpace ~
6515 \begin_inset LatexCommand index
6528 can be separately compiled as well:
6539 sdcc foomain.rel foo1.rel foo2.rel
6546 The file containing the
6558 file specified in the command line, since the linkage editor processes
6559 file in the order they are presented to it.
6560 The linker is invoked from SDCC using a script file with extension .lnk
6561 \begin_inset LatexCommand index
6567 You can view this file to troubleshoot linking problems such as those arising
6568 from missing libraries.
6571 \begin_layout Subsection
6572 Projects with Additional Libraries
6573 \begin_inset LatexCommand index
6581 \begin_layout Standard
6582 Some reusable routines may be compiled into a library, see the documentation
6583 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6587 \begin_inset LatexCommand index
6595 Libraries created in this manner can be included in the command line.
6596 Make sure you include the -L <library-path> option to tell the linker where
6597 to look for these files if they are not in the current directory.
6598 Here is an example, assuming you have the source file
6610 (if that is not the same as your current project):
6617 sdcc foomain.c foolib.lib -L mylib
6628 must be an absolute path name.
6632 The most efficient way to use libraries is
6633 to keep separate modules in separate source files.
6634 The lib file now should name all the modules.rel
6635 \begin_inset LatexCommand index
6641 For an example see the standard library file
6645 in the directory <installdir>/share/lib/small.
6648 \begin_layout Subsection
6649 Using sdcclib to Create and Manage Libraries
6650 \begin_inset LatexCommand index
6658 \begin_layout Standard
6659 Alternatively, instead of having a .rel file for each entry on the library
6660 file as described in the preceding section, sdcclib can be used to embed
6661 all the modules belonging to such library in the library file itself.
6662 This results in a larger library file, but it greatly reduces the number
6663 of disk files accessed by the linker.
6664 Additionally, the packed library file contains an index of all include
6665 modules and symbols that significantly speeds up the linking process.
6666 To display a list of options supported by sdcclib type:
6671 \begin_layout Standard
6676 \begin_inset LatexCommand index
6688 To create a new library file, start by compiling all the required modules.
6694 \begin_layout Standard
6701 \begin_layout Standard
6708 \begin_layout Standard
6715 \begin_layout Standard
6722 \begin_layout Standard
6731 \begin_layout Standard
6732 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6734 The next step is to add the .rel files to the library file:
6739 \begin_layout Standard
6743 sdcclib libint.lib _divsint.rel
6746 \begin_inset LatexCommand index
6754 \begin_layout Standard
6758 sdcclib libint.lib _divuint.rel
6761 \begin_layout Standard
6765 sdcclib libint.lib _modsint.rel
6768 \begin_layout Standard
6772 sdcclib libint.lib _moduint.rel
6775 \begin_layout Standard
6779 sdcclib libint.lib _mulint.rel
6787 \begin_layout Standard
6796 \begin_layout Standard
6800 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6808 \begin_layout Standard
6809 If the file already exists in the library, it will be replaced.
6810 If a list of .rel files is available, you can tell sdcclib to add those
6812 For example, if the file 'myliblist.txt' contains
6820 \begin_layout Standard
6827 \begin_layout Standard
6834 \begin_layout Standard
6841 \begin_layout Standard
6848 \begin_layout Standard
6860 \begin_layout Standard
6869 \begin_layout Standard
6873 sdcclib -l libint.lib myliblist.txt
6881 \begin_layout Standard
6882 Additionally, you can instruct sdcclib to compiles the files before adding
6883 them to the library.
6884 This is achieved using the environment variables SDCCLIB_CC and/or SDCCLIB_AS.
6893 \begin_layout Standard
6897 set SDCCLIB_CC=sdcc -c
6900 \begin_layout Standard
6904 sdcclib -l libint.lib myliblist.txt
6912 \begin_layout Standard
6913 To see what modules and symbols are included in the library, options -s
6914 and -m are available.
6922 sdcclib -s libint.lib
6925 \begin_inset LatexCommand index
6938 \begin_layout Standard
6944 \begin_layout Standard
6950 \begin_layout Standard
6958 \begin_layout Standard
6964 \begin_layout Standard
6970 \begin_layout Standard
6976 \begin_layout Standard
6982 \begin_layout Standard
6990 \begin_layout Standard
6996 \begin_layout Standard
7002 \begin_layout Standard
7010 \begin_layout Standard
7016 \begin_layout Standard
7022 \begin_layout Standard
7028 \begin_layout Standard
7036 \begin_layout Standard
7042 \begin_layout Standard
7053 \begin_layout Standard
7054 If the source files are compiled using -
7058 \begin_layout Standard
7068 \begin_inset LatexCommand index
7073 , the corresponding debug information file .adb will be include in the library
7075 The library files created with sdcclib are plain text files, so they can
7076 be viewed with a text editor.
7077 It is not recommended to modify a library file created with sdcclib using
7078 a text editor, as there are file indexes numbers located across the file
7079 used by the linker to quickly locate the required module to link.
7080 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
7081 it can be safely deleted, since all the information required for linking
7082 is embedded in the library file itself.
7083 Library files created using sdcclib are used as described in the preceding
7087 \begin_layout Subsection
7088 Using ar to Create and Manage Libraries
7089 \begin_inset LatexCommand index
7097 \begin_layout Standard
7098 Support for ar format libraries was introduced in sdcc 2.9.0.
7099 Ar is a standard archive managing utility on unices (Linux, Mac OS X, several
7100 unix flavors) so it is not included in the sdcc package.
7108 For Windows platform you can find ar utility in GNU binutils package included
7109 in several projects: Cygwin at
7110 \begin_inset LatexCommand url
7111 target "http://www.cygwin.com/"
7116 \begin_inset LatexCommand url
7117 target "http://www.mingw.org/"
7129 Both the GNU and BSD ar format variants are suppurated by asxxxx linkers.
7130 Ar doesn't understand the asxxxx object file format, so there is a special
7131 version of ranlib distributed with sdcc, called asranlib, which produces
7132 the ar symbol lookup table.
7140 To create a library containing asxxxx object files, you should use the following
7148 \begin_layout Standard
7152 ar -Sq <library name>.lib <list of .rel files>
7155 \begin_layout Standard
7159 asranlib <library name>.lib
7162 \begin_layout Standard
7163 \begin_inset VSpace bigskip
7169 \begin_layout Section
7170 Command Line Options
7171 \begin_inset LatexCommand index
7172 name "Command Line Options"
7177 \begin_inset LatexCommand label
7178 name "sec:Command-Line-Options"
7185 \begin_layout Subsection
7186 Processor Selection Options
7187 \begin_inset LatexCommand index
7188 name "Options processor selection"
7193 \begin_inset LatexCommand index
7194 name "Processor selection options"
7202 \labelwidthstring 00.00.0000
7206 \begin_inset LatexCommand index
7213 Generate code for the Intel MCS51
7214 \begin_inset LatexCommand index
7219 family of processors.
7220 This is the default processor target.
7224 \labelwidthstring 00.00.0000
7228 \begin_inset LatexCommand index
7235 Generate code for the Dallas DS80C390
7236 \begin_inset LatexCommand index
7245 \labelwidthstring 00.00.0000
7249 \begin_inset LatexCommand index
7256 Generate code for the Dallas DS80C400
7257 \begin_inset LatexCommand index
7266 \labelwidthstring 00.00.0000
7270 \begin_inset LatexCommand index
7277 Generate code for the Freescale/Motorola HC08
7278 \begin_inset LatexCommand index
7283 family of processors.
7287 \labelwidthstring 00.00.0000
7291 \begin_inset LatexCommand index
7298 Generate code for the Zilog Z80
7299 \begin_inset LatexCommand index
7304 family of processors.
7308 \labelwidthstring 00.00.0000
7312 \begin_inset LatexCommand index
7319 Generate code for the GameBoy Z80
7320 \begin_inset LatexCommand index
7321 name "gbz80 (GameBoy Z80)"
7325 processor (Not actively maintained).
7329 \labelwidthstring 00.00.0000
7333 \begin_inset LatexCommand index
7340 Generate code for the Atmel AVR
7341 \begin_inset LatexCommand index
7346 processor (Not maintained, not complete).
7347 AVR users should probably have a look at winavr
7348 \begin_inset LatexCommand url
7349 target "http://sourceforge.net/projects/winavr"
7354 \begin_inset LatexCommand url
7355 target "http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index"
7359 , which is based on AVR-port of the gcc compiler.
7362 \begin_layout Standard
7363 \begin_inset Note Note
7366 \begin_layout Standard
7367 I think it is fair to direct users there for now.
7368 Open source is also about avoiding unnecessary work .
7369 But I didn't find the 'official' link.
7378 \labelwidthstring 00.00.0000
7382 \begin_inset LatexCommand index
7389 Generate code for the Microchip PIC 14
7390 \begin_inset LatexCommand index
7395 -bit processors (p16f84 and variants.
7396 In development, not complete).
7399 \begin_layout Standard
7400 \begin_inset Note Note
7403 \begin_layout Standard
7404 p16f627 p16f628 p16f84 p16f873 p16f877?
7413 \labelwidthstring 00.00.0000
7417 \begin_inset LatexCommand index
7424 Generate code for the Microchip PIC 16
7425 \begin_inset LatexCommand index
7430 -bit processors (p18f452 and variants.
7431 In development, not complete).
7435 \labelwidthstring 00.00.0000
7440 Generate code for the Toshiba TLCS-900H
7441 \begin_inset LatexCommand index
7446 processor (Not maintained, not complete).
7450 \labelwidthstring 00.00.0000
7454 \begin_inset LatexCommand index
7461 Generate code for the Phillips XA51
7462 \begin_inset LatexCommand index
7467 processor (Not maintained, not complete).
7470 \begin_layout Standard
7471 \begin_inset VSpace bigskip
7477 \begin_layout Subsection
7478 Preprocessor Options
7479 \begin_inset LatexCommand index
7480 name "Options preprocessor"
7485 \begin_inset LatexCommand index
7486 name "Preprocessor options"
7491 \begin_inset LatexCommand index
7492 name "sdcpp (preprocessor)"
7500 \labelwidthstring 00.00.0000
7504 \begin_inset LatexCommand index
7511 The additional location where the preprocessor will look for <..h> or
7512 \begin_inset Quotes eld
7516 \begin_inset Quotes erd
7523 \labelwidthstring 00.00.0000
7527 \begin_inset LatexCommand index
7528 name "-D<macro[=value]>"
7534 Command line definition of macros.
7535 Passed to the preprocessor.
7539 \labelwidthstring 00.00.0000
7543 \begin_inset LatexCommand index
7550 Tell the preprocessor to output a rule suitable for make describing the
7551 dependencies of each object file.
7552 For each source file, the preprocessor outputs one make-rule whose target
7553 is the object file name for that source file and whose dependencies are
7554 all the files `#include'd in it.
7555 This rule may be a single line or may be continued with `
7557 '-newline if it is long.
7558 The list of rules is printed on standard output instead of the preprocessed
7561 \begin_inset LatexCommand index
7570 \labelwidthstring 00.00.0000
7574 \begin_inset LatexCommand index
7581 Tell the preprocessor not to discard comments.
7582 Used with the `-E' option.
7586 \labelwidthstring 00.00.0000
7590 \begin_inset LatexCommand index
7600 Like `-M' but the output mentions only the user header files included with
7602 \begin_inset Quotes eld
7606 System header files included with `#include <file>' are omitted.
7610 \labelwidthstring 00.00.0000
7614 \begin_inset LatexCommand index
7615 name "-Aquestion(answer)"
7621 Assert the answer answer for question, in case it is tested with a preprocessor
7622 conditional such as `#if #question(answer)'.
7623 `-A-' disables the standard assertions that normally describe the target
7628 \labelwidthstring 00.00.0000
7632 \begin_inset LatexCommand index
7639 Undefine macro macro.
7640 `-U' options are evaluated after all `-D' options, but before any `-include'
7641 and `-imacros' options.
7645 \labelwidthstring 00.00.0000
7649 \begin_inset LatexCommand index
7656 Tell the preprocessor to output only a list of the macro definitions that
7657 are in effect at the end of preprocessing.
7658 Used with the `-E' option.
7662 \labelwidthstring 00.00.0000
7666 \begin_inset LatexCommand index
7673 Tell the preprocessor to pass all macro definitions into the output, in
7674 their proper sequence in the rest of the output.
7678 \labelwidthstring 00.00.0000
7682 \begin_inset LatexCommand index
7692 Like `-dD' except that the macro arguments and contents are omitted.
7693 Only `#define name' is included in the output.
7697 \labelwidthstring 00.00.0000
7700 -pedantic-parse-number
7701 \begin_inset LatexCommand index
7707 \begin_inset LatexCommand index
7708 name "-pedantic-parse-number"
7716 \begin_inset LatexCommand label
7717 name "lyx:-pedantic-parse-number"
7726 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7727 and the macro LO_B(3) gets expanded.
7728 See also #pragma pedantic_parse_number
7729 \begin_inset LatexCommand vpageref
7730 reference "ite:pedantic_parse_number"
7735 \begin_inset LatexCommand ref
7736 reference "sec:Pragmas"
7742 Note: this functionality is not in conformance with C99 standard!
7746 \labelwidthstring 00.00.0000
7750 preprocessorOption[,preprocessorOption]
7753 \begin_inset LatexCommand index
7754 name "-Wp preprocessorOption[,preprocessorOption]"
7759 Pass the preprocessorOption to the preprocessor
7764 \begin_inset LatexCommand index
7765 name "sdcpp (preprocessor)"
7770 SDCC uses an adapted version of the GNU Compiler Collection
7771 \begin_inset LatexCommand index
7772 name "gcc (GNU Compiler Collection)"
7785 \begin_inset LatexCommand url
7786 target "http://gcc.gnu.org/"
7791 If you need more dedicated options please refer to the GCC\InsetSpace ~
7795 \begin_inset LatexCommand htmlurl
7796 target "http://www.gnu.org/software/gcc/onlinedocs/"
7803 \begin_layout Standard
7804 \begin_inset VSpace bigskip
7810 \begin_layout Subsection
7812 \begin_inset LatexCommand index
7813 name "Options linker"
7818 \begin_inset LatexCommand index
7819 name "Linker options"
7827 \labelwidthstring 00.00.0000
7837 \begin_layout Standard
7849 \begin_inset LatexCommand index
7850 name "-\\/-lib-path <path>"
7855 \begin_inset LatexCommand index
7856 name "-L -\\/-lib-path"
7863 <absolute path to additional libraries> This option is passed to the linkage
7864 editor's additional libraries
7865 \begin_inset LatexCommand index
7871 The path name must be absolute.
7872 Additional library files may be specified in the command line.
7873 See section Compiling programs for more details.
7877 \labelwidthstring 00.00.0000
7884 \begin_layout Standard
7896 \begin_inset LatexCommand index
7897 name "-\\/-xram-loc <Value>"
7902 <Value> The start location of the external ram
7903 \begin_inset LatexCommand index
7904 name "xdata (mcs51, ds390 storage class)"
7908 , default value is 0.
7909 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7913 \begin_layout Standard
7922 -xram-loc 0x8000 or -
7926 \begin_layout Standard
7939 \labelwidthstring 00.00.0000
7946 \begin_layout Standard
7958 \begin_inset LatexCommand index
7959 name "-\\/-code-loc <Value>"
7964 <Value> The start location of the code
7965 \begin_inset LatexCommand index
7970 segment, default value 0.
7971 Note when this option is used the interrupt vector table
7972 \begin_inset LatexCommand index
7973 name "interrupt vector table"
7977 is also relocated to the given address.
7978 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7982 \begin_layout Standard
7991 -code-loc 0x8000 or -
7995 \begin_layout Standard
8008 \labelwidthstring 00.00.0000
8015 \begin_layout Standard
8027 \begin_inset LatexCommand index
8028 name "-\\/-stack-loc <Value>"
8033 <Value> By default the stack
8034 \begin_inset LatexCommand index
8039 is placed after the data segment.
8040 Using this option the stack can be placed anywhere in the internal memory
8042 The value entered can be in Hexadecimal or Decimal format, e.g.
8047 \begin_layout Standard
8056 -stack-loc 0x20 or -
8060 \begin_layout Standard
8070 Since the sp register is incremented before a push or call, the initial
8071 sp will be set to one byte prior the provided value.
8072 The provided value should not overlap any other memory areas such as used
8073 register banks or the data segment and with enough space for the current
8081 \begin_layout Standard
8094 \begin_inset LatexCommand index
8095 name "-\\/-pack-iram"
8099 option (which is now a default setting) will override this setting, so
8100 you should also specify the
8106 \begin_layout Standard
8119 \begin_inset LatexCommand index
8120 name "-\\/-no-pack-iram"
8124 option if you need to manually place the stack.
8128 \labelwidthstring 00.00.0000
8135 \begin_layout Standard
8147 \begin_inset LatexCommand index
8148 name "-\\/-xstack-loc <Value>"
8153 <Value> By default the external stack
8154 \begin_inset LatexCommand index
8159 is placed after the pdata
8160 \begin_inset LatexCommand index
8161 name "pdata (mcs51, ds390 storage class)"
8166 Using this option the xstack can be placed anywhere in the external memory
8168 The value entered can be in Hexadecimal or Decimal format, e.g.
8173 \begin_layout Standard
8182 -xstack-loc 0x8000 or -
8186 \begin_layout Standard
8196 The provided value should not overlap any other memory areas such as the
8197 pdata or xdata segment and with enough space for the current application.
8201 \labelwidthstring 00.00.0000
8208 \begin_layout Standard
8220 \begin_inset LatexCommand index
8221 name "-\\/-data-loc <Value>"
8226 <Value> The start location of the internal ram data
8227 \begin_inset LatexCommand index
8228 name "data (mcs51, ds390 storage class)"
8233 The value entered can be in Hexadecimal or Decimal format, eg.
8238 \begin_layout Standard
8251 \begin_layout Standard
8261 (By default, the start location of the internal ram data segment is set
8262 as low as possible in memory, taking into account the used register banks
8263 and the bit segment at address 0x20.
8264 For example if register banks 0 and 1 are used without bit variables, the
8265 data segment will be set, if -
8269 \begin_layout Standard
8278 -data-loc is not used, to location 0x10.)
8282 \labelwidthstring 00.00.0000
8289 \begin_layout Standard
8301 \begin_inset LatexCommand index
8302 name "-\\/-idata-loc <Value>"
8307 <Value> The start location of the indirectly addressable internal ram
8308 \begin_inset LatexCommand index
8309 name "idata (mcs51, ds390 storage class)"
8313 of the 8051, default value is 0x80.
8314 The value entered can be in Hexadecimal or Decimal format, eg.
8319 \begin_layout Standard
8328 -idata-loc 0x88 or -
8332 \begin_layout Standard
8345 \labelwidthstring 00.00.0000
8352 \begin_layout Standard
8364 <Value> The start location of the bit
8365 \begin_inset LatexCommand index
8370 addressable internal ram of the 8051.
8376 Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
8381 \labelwidthstring 00.00.0000
8388 \begin_layout Standard
8398 \begin_inset LatexCommand index
8399 name "-\\/-out-fmt-ihx"
8405 The linker output (final object code) is in Intel Hex format.
8406 \begin_inset LatexCommand index
8407 name "Intel hex format"
8411 This is the default option.
8412 The format itself is documented in the documentation of srecord
8413 \begin_inset LatexCommand index
8414 name "srecord (bin, hex, ... tool)"
8422 \labelwidthstring 00.00.0000
8429 \begin_layout Standard
8439 \begin_inset LatexCommand index
8440 name "-\\/-out-fmt-s19"
8446 The linker output (final object code) is in Motorola S19 format
8447 \begin_inset LatexCommand index
8448 name "Motorola S19 format"
8453 The format itself is documented in the documentation of srecord.
8457 \labelwidthstring 00.00.0000
8464 \begin_layout Standard
8474 \begin_inset LatexCommand index
8475 name "-\\/-out-fmt-s19"
8480 \begin_inset LatexCommand index
8481 name "HC08!Options!-\\/-out-fmt-elf"
8487 The linker output (final object code) is in ELF format
8488 \begin_inset LatexCommand index
8494 (Currently only supported for the HC08
8495 \begin_inset LatexCommand index
8504 \labelwidthstring 00.00.0000
8508 linkOption[,linkOption]
8511 \begin_inset LatexCommand index
8512 name "-Wl linkOption[,linkOption]"
8517 \begin_inset LatexCommand label
8518 name "lyx:-Wl option"
8523 Pass the linkOption to the linker.
8524 If a bootloader is used an option like
8525 \begin_inset Quotes sld
8530 \begin_inset Quotes srd
8533 would be typical to set the start of the code segment.
8534 Either use the double quotes around this option or use no space (e.g.
8536 See also #pragma constseg and #pragma codeseg in section
8537 \begin_inset LatexCommand ref
8538 reference "sec:Pragmas"
8543 File sdcc/as/doc/asxhtm.html has more on linker options.
8546 \begin_layout Standard
8547 \begin_inset VSpace bigskip
8553 \begin_layout Subsection
8555 \begin_inset LatexCommand index
8556 name "Options MCS51"
8561 \begin_inset LatexCommand index
8562 name "MCS51 options"
8570 \labelwidthstring 00.00.0000
8577 \begin_layout Standard
8587 \begin_inset LatexCommand index
8588 name "-\\/-model-small"
8597 Generate code for Small Model programs, see section Memory Models for more
8599 This is the default model.
8603 \labelwidthstring 00.00.0000
8610 \begin_layout Standard
8620 \begin_inset LatexCommand index
8621 name "-\\/-model-medium"
8627 Generate code for Medium model programs, see section Memory Models for
8629 If this option is used all source files in the project have to be compiled
8631 It must also be used when invoking the linker.
8635 \labelwidthstring 00.00.0000
8642 \begin_layout Standard
8652 \begin_inset LatexCommand index
8653 name "-\\/-model-large"
8659 Generate code for Large model programs, see section Memory Models for more
8661 If this option is used all source files in the project have to be compiled
8663 It must also be used when invoking the linker.
8667 \labelwidthstring 00.00.0000
8674 \begin_layout Standard
8684 \begin_inset LatexCommand index
8691 Uses a pseudo stack in the pdata
8692 \begin_inset LatexCommand index
8693 name "pdata (mcs51, ds390 storage class)"
8697 area (usually the first 256 bytes in the external ram) for allocating variables
8698 and passing parameters.
8700 \begin_inset LatexCommand ref
8701 reference "sub:External-Stack"
8706 External Stack for more details.
8710 \labelwidthstring 00.00.0000
8717 \begin_layout Standard
8730 \begin_inset LatexCommand index
8731 name "-\\/-iram-size <Value>"
8735 Causes the linker to check if the internal ram usage is within limits of
8740 \labelwidthstring 00.00.0000
8747 \begin_layout Standard
8760 \begin_inset LatexCommand index
8761 name "-\\/-xram-size <Value>"
8765 Causes the linker to check if the external ram usage is within limits of
8770 \labelwidthstring 00.00.0000
8777 \begin_layout Standard
8790 \begin_inset LatexCommand index
8791 name "-\\/-code-size <Value>"
8795 Causes the linker to check if the code memory usage is within limits of
8800 \labelwidthstring 00.00.0000
8807 \begin_layout Standard
8820 \begin_inset LatexCommand index
8821 name "-\\/-stack-size <Value>"
8825 Causes the linker to check if there is at minimum <Value> bytes for stack.
8829 \labelwidthstring 00.00.0000
8836 \begin_layout Standard
8849 \begin_inset LatexCommand index
8850 name "-\\/-pack-iram"
8854 Causes the linker to use unused register banks for data variables and pack
8855 data, idata and stack together.
8856 This is the default now.
8860 \labelwidthstring 00.00.0000
8867 \begin_layout Standard
8880 \begin_inset LatexCommand index
8881 name "-\\/-no-pack-iram"
8885 Causes the linker to use old style for allocating memory areas.
8889 \labelwidthstring 00.00.0000
8896 \begin_layout Standard
8909 \begin_inset LatexCommand index
8910 name "-\\/-acall-ajmp"
8914 Replaces the three byte instructions lcall/ljmp with the two byte instructions
8916 Only use this option if your code is in the same 2k block of memory.
8917 You may need to use this option for some 8051 derivatives which lack the
8918 lcall/ljmp instructions..
8921 \begin_layout Standard
8922 \begin_inset VSpace bigskip
8928 \begin_layout Subsection
8929 DS390 / DS400 Options
8930 \begin_inset LatexCommand index
8931 name "Options DS390"
8936 \begin_inset LatexCommand index
8945 \labelwidthstring 00.00.0000
8952 \begin_layout Standard
8964 \begin_inset LatexCommand index
8965 name "DS390!Options!-\\/-model-flat24"
8973 Generate 24-bit flat mode code.
8974 This is the one and only that the ds390 code generator supports right now
8975 and is default when using
8980 See section Memory Models for more details.
8984 \labelwidthstring 00.00.0000
8991 \begin_layout Standard
9001 \begin_inset LatexCommand index
9002 name "DS390!Options!-\\/-protect-sp-update"
9008 disable interrupts during ESP:SP updates.
9012 \labelwidthstring 00.00.0000
9019 \begin_layout Standard
9031 \begin_inset LatexCommand index
9032 name "DS390!Options!-\\/-stack-10bit"
9036 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
9037 This is the one and only that the ds390 code generator supports right now
9038 and is default when using
9043 In this mode, the stack is located in the lower 1K of the internal RAM,
9044 which is mapped to 0x400000.
9045 Note that the support is incomplete, since it still uses a single byte
9046 as the stack pointer.
9047 This means that only the lower 256 bytes of the potential 1K stack space
9048 will actually be used.
9049 However, this does allow you to reclaim the precious 256 bytes of low RAM
9050 for use for the DATA and IDATA segments.
9051 The compiler will not generate any code to put the processor into 10 bit
9053 It is important to ensure that the processor is in this mode before calling
9054 any re-entrant functions compiled with this option.
9055 In principle, this should work with the
9061 \begin_layout Standard
9071 \begin_inset LatexCommand index
9072 name "-\\/-stack-auto"
9078 option, but that has not been tested.
9079 It is incompatible with the
9085 \begin_layout Standard
9095 \begin_inset LatexCommand index
9103 It also only makes sense if the processor is in 24 bit contiguous addressing
9110 \begin_layout Standard
9119 -model-flat24 option
9124 \begin_inset Note Note
9128 \labelwidthstring 00.00.0000
9135 \begin_layout Standard
9144 -stack-8-bit - switches off the 10-bit mode
9153 \labelwidthstring 00.00.0000
9160 \begin_layout Standard
9170 \begin_inset LatexCommand index
9171 name "DS390!Options!-\\/-stack-probe"
9177 insert call to function __stack_probe at each function prologue.
9181 \labelwidthstring 00.00.0000
9188 \begin_layout Standard
9198 \begin_inset LatexCommand index
9199 name "DS390!Options!-\\/-tini-libid"
9205 <nnnn> LibraryID used in -mTININative.
9210 \labelwidthstring 00.00.0000
9217 \begin_layout Standard
9227 \begin_inset LatexCommand index
9228 name "DS390!Options!-\\/-use-accelerator"
9234 generate code for DS390 Arithmetic Accelerator.
9238 \begin_layout Standard
9239 \begin_inset VSpace bigskip
9245 \begin_layout Subsection
9247 \begin_inset LatexCommand index
9253 \begin_inset LatexCommand index
9262 \labelwidthstring 00.00.0000
9269 \begin_layout Standard
9281 \begin_inset LatexCommand index
9282 name "Z80!Options!-\\/-callee-saves-bc"
9290 Force a called function to always save BC.
9294 \labelwidthstring 00.00.0000
9301 \begin_layout Standard
9313 \begin_inset LatexCommand index
9314 name "Z80!Options!-\\/-no-std-crt0"
9318 When linking, skip the standard crt0.o object file.
9319 You must provide your own crt0.o for your system when linking.
9323 \labelwidthstring 00.00.0000
9330 \begin_layout Standard
9342 \begin_inset LatexCommand index
9343 name "Z80!Options!-\\/-portmode=<Value>"
9347 Determinate PORT I/O mode (<Value> is z80 or z180).
9351 \labelwidthstring 00.00.0000
9358 \begin_layout Standard
9370 \begin_inset LatexCommand index
9371 name "Z80!Options!-\\/-asm=<Value>"
9375 Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
9379 \labelwidthstring 00.00.0000
9386 \begin_layout Standard
9399 \begin_inset LatexCommand index
9400 name "Z80!Options!-\\/-codeseg <Value>"
9404 Use <Value> for the code segment name.
9408 \labelwidthstring 00.00.0000
9415 \begin_layout Standard
9428 \begin_inset LatexCommand index
9429 name "Z80!Options!-\\/-constseg <Value>"
9433 Use <Value> for the const segment name.
9437 \labelwidthstring 00.00.0000
9438 \begin_inset VSpace bigskip
9444 \begin_layout Subsection
9446 \begin_inset LatexCommand index
9447 name "Options GBZ80"
9452 \begin_inset LatexCommand index
9461 \labelwidthstring 00.00.0000
9468 \begin_layout Standard
9480 \begin_inset LatexCommand index
9481 name "GBZ80!Options!-\\/-callee-saves-bc"
9489 Force a called function to always save BC.
9493 \labelwidthstring 00.00.0000
9500 \begin_layout Standard
9512 \begin_inset LatexCommand index
9513 name "Z80!Options!-\\/-no-std-crt0"
9517 When linking, skip the standard crt0.o object file.
9518 You must provide your own crt0.o for your system when linking.
9522 \labelwidthstring 00.00.0000
9529 \begin_inset LatexCommand index
9530 name "GBZ80!Options!-bo <Num>"
9534 Use code bank <Num>.
9538 \labelwidthstring 00.00.0000
9545 \begin_inset LatexCommand index
9546 name "GBZ80!Options!-ba <Num>"
9550 Use data bank <Num>.
9554 \labelwidthstring 00.00.0000
9561 \begin_layout Standard
9574 \begin_inset LatexCommand index
9575 name "GBZ80!Options!-\\/-codeseg <Value>"
9579 Use <Value> for the code segment name.
9583 \labelwidthstring 00.00.0000
9590 \begin_layout Standard
9603 \begin_inset LatexCommand index
9604 name "GBZ80!Options!-\\/-constseg <Value>"
9608 Use <Value> for the const segment name.
9611 \begin_layout Standard
9612 \begin_inset VSpace bigskip
9618 \begin_layout Subsection
9619 Optimization Options
9620 \begin_inset LatexCommand index
9621 name "Options optimization"
9626 \begin_inset LatexCommand index
9627 name "Optimization options"
9635 \labelwidthstring 00.00.0000
9642 \begin_layout Standard
9652 \begin_inset LatexCommand index
9659 Will not do global subexpression elimination, this option may be used when
9660 the compiler creates undesirably large stack/data spaces to store compiler
9670 \begin_inset LatexCommand index
9671 name "sloc (spill location)"
9676 A warning message will be generated when this happens and the compiler
9677 will indicate the number of extra bytes it allocated.
9678 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9680 \begin_inset LatexCommand index
9681 name "\\#pragma nogcse"
9685 can be used to turn off global subexpression elimination
9686 \begin_inset LatexCommand index
9687 name "Subexpression elimination"
9691 for a given function only.
9695 \labelwidthstring 00.00.0000
9702 \begin_layout Standard
9712 \begin_inset LatexCommand index
9713 name "-\\/-noinvariant"
9719 Will not do loop invariant optimizations, this may be turned off for reasons
9720 explained for the previous option.
9721 For more details of loop optimizations performed see Loop Invariants in
9723 \begin_inset LatexCommand ref
9724 reference "sub:Loop-Optimizations"
9729 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9731 \begin_inset LatexCommand index
9732 name "\\#pragma noinvariant"
9736 can be used to turn off invariant optimizations for a given function only.
9740 \labelwidthstring 00.00.0000
9747 \begin_layout Standard
9757 \begin_inset LatexCommand index
9758 name "-\\/-noinduction"
9764 Will not do loop induction optimizations, see section strength reduction
9766 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9768 \begin_inset LatexCommand index
9769 name "\\#pragma noinduction"
9773 can be used to turn off induction optimizations for a given function only.
9777 \labelwidthstring 00.00.0000
9784 \begin_layout Standard
9794 \begin_inset LatexCommand index
9795 name "-\\/-nojtbound"
9804 Will not generate boundary condition check when switch statements
9805 \begin_inset LatexCommand index
9806 name "switch statement"
9810 are implemented using jump-tables.
9812 \begin_inset LatexCommand ref
9813 reference "sub:'switch'-Statements"
9818 Switch Statements for more details.
9819 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9821 \begin_inset LatexCommand index
9822 name "\\#pragma nojtbound"
9826 can be used to turn off boundary checking for jump tables for a given function
9831 \labelwidthstring 00.00.0000
9838 \begin_layout Standard
9848 \begin_inset LatexCommand index
9849 name "-\\/-noloopreverse"
9858 Will not do loop reversal
9859 \begin_inset LatexCommand index
9860 name "Loop reversing"
9868 \labelwidthstring 00.00.0000
9873 \begin_layout Standard
9887 \begin_inset LatexCommand index
9888 name "-\\/-nolabelopt "
9892 Will not optimize labels (makes the dumpfiles more readable).
9896 \labelwidthstring 00.00.0000
9903 \begin_layout Standard
9913 \begin_inset LatexCommand index
9914 name "-\\/-no-xinit-opt"
9920 Will not memcpy initialized data from code space into xdata space.
9921 This saves a few bytes in code space if you don't have initialized data
9922 \begin_inset LatexCommand index
9923 name "Variable initialization"
9931 \labelwidthstring 00.00.0000
9938 \begin_layout Standard
9948 \begin_inset LatexCommand index
9949 name "-\\/-nooverlay"
9955 The compiler will not overlay parameters and local variables of any function,
9956 see section Parameters and local variables for more details.
9960 \labelwidthstring 00.00.0000
9967 \begin_layout Standard
9977 \begin_inset LatexCommand index
9984 Disable peep-hole optimization with built-in rules.
9988 \labelwidthstring 00.00.0000
9995 \begin_layout Standard
10007 \begin_inset LatexCommand index
10008 name "-\\/-peep-file"
10013 <filename> This option can be used to use additional rules to be used by
10014 the peep hole optimizer.
10016 \begin_inset LatexCommand ref
10017 reference "sub:Peephole-Optimizer"
10022 Peep Hole optimizations for details on how to write these rules.
10026 \labelwidthstring 00.00.0000
10033 \begin_layout Standard
10043 \begin_inset LatexCommand index
10044 name "-\\/-peep-asm"
10050 Pass the inline assembler code through the peep hole optimizer.
10051 This can cause unexpected changes to inline assembler code, please go through
10052 the peephole optimizer
10053 \begin_inset LatexCommand index
10054 name "Peephole optimizer"
10058 rules defined in the source file tree '<target>/peeph.def' before using
10063 \labelwidthstring 00.00.0000
10070 \begin_layout Standard
10080 \begin_inset LatexCommand index
10081 name "-\\/-opt-code-speed"
10087 The compiler will optimize code generation towards fast code, possibly
10088 at the expense of code size.
10092 \labelwidthstring 00.00.0000
10099 \begin_layout Standard
10109 \begin_inset LatexCommand index
10110 name "-\\/-opt-code-size"
10116 The compiler will optimize code generation towards compact code, possibly
10117 at the expense of code speed.
10120 \begin_layout Standard
10121 \begin_inset VSpace bigskip
10127 \begin_layout Subsection
10129 \begin_inset LatexCommand index
10130 name "Options other"
10138 \labelwidthstring 00.00.0000
10146 \begin_layout Standard
10156 \begin_inset LatexCommand index
10157 name "-\\/-compile-only"
10162 \begin_inset LatexCommand index
10163 name "-c -\\/-compile-only"
10169 will compile and assemble the source, but will not call the linkage editor.
10173 \labelwidthstring 00.00.0000
10182 \begin_layout Standard
10194 \begin_inset LatexCommand index
10201 reads the preprocessed source from standard input and compiles it.
10202 The file name for the assembler output must be specified using the -o option.
10206 \labelwidthstring 00.00.0000
10210 \begin_inset LatexCommand index
10217 Run only the C preprocessor.
10218 Preprocess all the C source files specified and output the results to standard
10223 \labelwidthstring 00.00.0000
10228 \begin_inset LatexCommand index
10229 name "-o <path/file>"
10235 The output path where everything will be placed or the file name used for
10236 all generated output files.
10237 If the parameter is a path, it must have a trailing slash (or backslash
10238 for the Windows binaries) to be recognized as a path.
10239 Note for Windows users: if the path contains spaces, it should be surrounded
10241 The trailing backslash should be doubled in order to prevent escaping the
10242 final quote, for example:
10245 \begin_inset Quotes sld
10259 \begin_inset Quotes srd
10264 or put after the final quote, for example:
10267 \begin_inset Quotes sld
10277 \begin_inset Quotes srd
10285 The path using slashes for directory delimiters can be used too, for example:
10289 \begin_inset Quotes sld
10292 F:/Projects/test3/output 1/
10293 \begin_inset Quotes srd
10302 \labelwidthstring 00.00.0000
10309 \begin_layout Standard
10319 \begin_inset LatexCommand index
10320 name "-\\/-stack-auto"
10329 All functions in the source file will be compiled as
10334 \begin_inset LatexCommand index
10340 the parameters and local variables will be allocated on the stack
10341 \begin_inset LatexCommand index
10348 \begin_inset LatexCommand ref
10349 reference "sec:Parameters-and-Local-Variables"
10353 Parameters and Local Variables for more details.
10354 If this option is used all source files in the project should be compiled
10356 It automatically implies -
10362 \begin_layout Standard
10373 -int-long-reent and -
10379 \begin_layout Standard
10395 \labelwidthstring 00.00.0000
10402 \begin_layout Standard
10412 \begin_inset LatexCommand index
10413 name "-\\/-callee-saves"
10418 \begin_inset LatexCommand label
10419 name "lyx:--callee-saves-function1[,function2][,function3]..."
10423 function1[,function2][,function3]....
10426 The compiler by default uses a caller saves convention for register saving
10427 across function calls, however this can cause unnecessary register pushing
10428 and popping when calling small functions from larger functions.
10429 This option can be used to switch the register saving convention for the
10430 function names specified.
10431 The compiler will not save registers when calling these functions, no extra
10432 code will be generated at the entry and exit (function prologue
10435 \begin_inset LatexCommand index
10436 name "function prologue"
10445 \begin_inset LatexCommand index
10446 name "function epilogue"
10452 ) for these functions to save and restore the registers used by these functions,
10453 this can SUBSTANTIALLY reduce code and improve run time performance of
10454 the generated code.
10455 In the future the compiler (with inter procedural analysis) will be able
10456 to determine the appropriate scheme to use for each function call.
10457 DO NOT use this option for built-in functions such as _mulint..., if this
10458 option is used for a library function the appropriate library function
10459 needs to be recompiled with the same option.
10460 If the project consists of multiple source files then all the source file
10461 should be compiled with the same -
10465 \begin_layout Standard
10474 -callee-saves option string.
10475 Also see #pragma\InsetSpace ~
10477 \begin_inset LatexCommand index
10478 name "\\#pragma callee\\_saves"
10483 \begin_inset LatexCommand vpageref
10484 reference "ite:callee_saves-function1[,function2[,function3...]]--"
10492 \labelwidthstring 00.00.0000
10499 \begin_layout Standard
10509 \begin_inset LatexCommand index
10510 name "-\\/-all-callee-saves"
10520 \begin_layout Standard
10529 -callee-saves will be applied to all functions by default.
10533 \labelwidthstring 00.00.0000
10540 \begin_layout Standard
10550 \begin_inset LatexCommand index
10557 When this option is used the compiler will generate debug information.
10558 The debug information collected in a file with .cdb extension can be used
10560 For more information see documentation for SDCDB.
10561 Another file with no extension contains debug information in AOMF or AOMF51
10562 \begin_inset LatexCommand index
10563 name "AOMF, AOMF51"
10567 format which is commonly used by third party tools.
10571 \labelwidthstring 00.00.0000
10575 \begin_inset LatexCommand index
10585 Stop after the stage of compilation proper; do not assemble.
10586 The output is an assembler code file for the input file specified.
10590 \labelwidthstring 00.00.0000
10597 \begin_layout Standard
10607 \begin_inset LatexCommand index
10608 name "-\\/-int-long-reent"
10614 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
10615 Note by default these libraries are compiled as non-reentrant.
10616 See section Installation for more details.
10620 \labelwidthstring 00.00.0000
10627 \begin_layout Standard
10637 \begin_inset LatexCommand index
10638 name "-\\/-cyclomatic"
10644 This option will cause the compiler to generate an information message for
10645 each function in the source file.
10646 The message contains some
10650 information about the function.
10651 The number of edges and nodes the compiler detected in the control flow
10652 graph of the function, and most importantly the
10654 cyclomatic complexity
10655 \begin_inset LatexCommand index
10656 name "Cyclomatic complexity"
10662 see section on Cyclomatic Complexity for more details.
10666 \labelwidthstring 00.00.0000
10673 \begin_layout Standard
10683 \begin_inset LatexCommand index
10684 name "-\\/-float-reent"
10690 Floating point library is compiled as reentrant
10691 \begin_inset LatexCommand index
10697 See section Installation for more details.
10701 \labelwidthstring 00.00.0000
10708 \begin_layout Standard
10718 \begin_inset LatexCommand index
10719 name "-\\/-funsigned-char"
10725 The default signedness for every type is
10730 In some embedded environments the default signedness of
10739 To set the signess for characters to unsigned, use the option -
10745 \begin_layout Standard
10757 If this option is set and no signedness keyword (unsigned/signed) is given,
10758 a char will be signed.
10759 All other types are unaffected.
10763 \labelwidthstring 00.00.0000
10770 \begin_layout Standard
10780 \begin_inset LatexCommand index
10781 name "-\\/-main-return"
10787 This option can be used if the code generated is called by a monitor program
10788 or if the main routine includes an endless loop.
10789 This option results in slightly smaller code and saves two bytes of stack
10791 The return from the 'main'
10792 \begin_inset LatexCommand index
10797 function will return to the function calling main.
10798 The default setting is to lock up i.e.
10807 \labelwidthstring 00.00.0000
10814 \begin_layout Standard
10824 \begin_inset LatexCommand index
10825 name "-\\/-nostdinc"
10831 This will prevent the compiler from passing on the default include path
10832 to the preprocessor.
10836 \labelwidthstring 00.00.0000
10843 \begin_layout Standard
10853 \begin_inset LatexCommand index
10854 name "-\\/-nostdlib"
10860 This will prevent the compiler from passing on the default library
10861 \begin_inset LatexCommand index
10866 path to the linker.
10870 \labelwidthstring 00.00.0000
10877 \begin_layout Standard
10887 \begin_inset LatexCommand index
10888 name "-\\/-verbose"
10894 Shows the various actions the compiler is performing.
10898 \labelwidthstring 00.00.0000
10902 \begin_inset LatexCommand index
10909 Shows the actual commands the compiler is executing.
10913 \labelwidthstring 00.00.0000
10920 \begin_layout Standard
10930 \begin_inset LatexCommand index
10931 name "-\\/-no-c-code-in-asm"
10937 Hides your ugly and inefficient c-code from the asm file, so you can always
10938 blame the compiler :)
10942 \labelwidthstring 00.00.0000
10949 \begin_layout Standard
10959 \begin_inset LatexCommand index
10960 name "-\\/-no-gen-comments"
10966 Include code generator and peep-hole comments in the generated asm files.
10970 \labelwidthstring 00.00.0000
10977 \begin_layout Standard
10987 \begin_inset LatexCommand index
10988 name "-\\/-no-peep-comments"
10994 Don't include peep-hole comments in the generated asm files even if -
11000 \begin_layout Standard
11011 -fverbose-asm option is specified.
11015 \labelwidthstring 00.00.0000
11022 \begin_layout Standard
11032 \begin_inset LatexCommand index
11033 name "-\\/-i-code-in-asm"
11039 Include i-codes in the asm file.
11040 Sounds like noise but is most helpful for debugging the compiler itself.
11044 \labelwidthstring 00.00.0000
11051 \begin_layout Standard
11061 \begin_inset LatexCommand index
11067 \begin_inset LatexCommand index
11068 name "-\\/-less-pedantic"
11075 \begin_inset LatexCommand label
11076 name "lyx:--less-pedantic"
11080 Disable some of the more pedantic warnings
11081 \begin_inset LatexCommand index
11087 For more details, see the less_pedantic pragma
11088 \begin_inset LatexCommand vpageref
11089 reference "ite:less_pedantic"
11097 \labelwidthstring 00.00.0000
11104 \begin_layout Standard
11113 -disable-warning\InsetSpace ~
11115 \begin_inset LatexCommand index
11116 name "-\\/-disable-warning"
11122 Disable specific warning with number <nnnn>.
11126 \labelwidthstring 00.00.0000
11133 \begin_layout Standard
11143 \begin_inset LatexCommand index
11150 Treat all warnings as errors.
11154 \labelwidthstring 00.00.0000
11161 \begin_layout Standard
11171 \begin_inset LatexCommand index
11172 name "-\\/-print-search-dirs"
11178 Display the directories in the compiler's search path
11182 \labelwidthstring 00.00.0000
11189 \begin_layout Standard
11199 \begin_inset LatexCommand index
11206 Display errors and warnings using MSVC style, so you can use SDCC with
11207 the visual studio IDE
11208 \begin_inset LatexCommand index
11214 With SDCC both offering a GCC-like (the default) and a MSVC-like
11215 \begin_inset LatexCommand index
11216 name "MSVC output style"
11220 output style, integration into most programming editors should be straightforwa
11225 \labelwidthstring 00.00.0000
11232 \begin_layout Standard
11242 \begin_inset LatexCommand index
11243 name "-\\/-use-stdout"
11249 Send errors and warnings to stdout instead of stderr.
11253 \labelwidthstring 00.00.0000
11257 asmOption[,asmOption]
11260 \begin_inset LatexCommand index
11261 name "-Wa asmOption[,asmOption]"
11266 Pass the asmOption to the assembler
11267 \begin_inset LatexCommand index
11268 name "Options assembler"
11273 \begin_inset LatexCommand index
11274 name "Assembler options"
11279 See file sdcc/as/doc/asxhtm.html for assembler options.cd
11283 \labelwidthstring 00.00.0000
11290 \begin_layout Standard
11300 \begin_inset LatexCommand index
11301 name "-\\/-std-sdcc89"
11307 Generally follow the C89 standard, but allow SDCC features that conflict
11308 with the standard (default).
11312 \labelwidthstring 00.00.0000
11319 \begin_layout Standard
11329 \begin_inset LatexCommand index
11330 name "-\\/-std-c89"
11336 Follow the C89 standard and disable SDCC features that conflict with the
11341 \labelwidthstring 00.00.0000
11348 \begin_layout Standard
11358 \begin_inset LatexCommand index
11359 name "-\\/-std-sdcc99"
11365 Generally follow the C99 standard, but allow SDCC features that conflict
11366 with the standard (incomplete support).
11370 \labelwidthstring 00.00.0000
11377 \begin_layout Standard
11387 \begin_inset LatexCommand index
11388 name "-\\/-std-sdcc99"
11394 Follow the C99 standard and disable SDCC features that conflict with the
11395 standard (incomplete support).
11399 \labelwidthstring 00.00.0000
11406 \begin_layout Standard
11418 \begin_inset LatexCommand index
11419 name "-\\/-codeseg <Value>"
11424 \begin_inset LatexCommand label
11425 name "lyx:-codeseg"
11430 <Name> The name to be used for the code
11431 \begin_inset LatexCommand index
11436 segment, default CSEG.
11437 This is useful if you need to tell the compiler to put the code in a special
11438 segment so you can later on tell the linker to put this segment in a special
11440 Can be used for instance when using bank switching to put the code in a
11445 \labelwidthstring 00.00.0000
11452 \begin_layout Standard
11464 \begin_inset LatexCommand index
11465 name "-\\/-constseg <Value>"
11470 <Name> The name to be used for the const
11471 \begin_inset LatexCommand index
11476 segment, default CONST.
11477 This is useful if you need to tell the compiler to put the const data in
11478 a special segment so you can later on tell the linker to put this segment
11479 in a special place in memory.
11480 Can be used for instance when using bank switching to put the const data
11485 \labelwidthstring 00.00.0000
11492 \begin_layout Standard
11501 -fdollars-in-identifiers
11502 \begin_inset LatexCommand index
11503 name "-\\/-fdollars-in-identifiers"
11509 Permit '$' as an identifier character.
11513 \labelwidthstring 00.00.0000
11520 \begin_layout Standard
11532 \begin_inset LatexCommand index
11533 name "-\\/-more-pedantic"
11538 \begin_inset LatexCommand index
11549 a SDCC compiler option but if you want
11553 warnings you can use a separate tool dedicated to syntax checking like
11555 \begin_inset LatexCommand label
11556 name "lyx:more-pedantic-SPLINT"
11561 \begin_inset LatexCommand index
11562 name "lint (syntax checking tool)"
11567 \begin_inset LatexCommand url
11568 target "http://www.splint.org"
11573 To make your source files parseable by splint you will have to include
11579 \begin_inset LatexCommand index
11580 name "splint (syntax checking tool)"
11584 in your source file and add brackets around extended keywords (like
11587 \begin_inset Quotes sld
11600 \begin_inset Quotes srd
11608 \begin_inset Quotes sld
11611 __interrupt\InsetSpace ~
11613 \begin_inset Quotes srd
11621 Splint has an excellent on line manual at
11622 \begin_inset LatexCommand url
11623 target "http://www.splint.org/manual/"
11627 and it's capabilities go beyond pure syntax checking.
11628 You'll need to tell splint the location of SDCC's include files so a typical
11629 command line could look like this:
11633 splint\InsetSpace ~
11635 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
11641 \labelwidthstring 00.00.0000
11648 \begin_layout Standard
11660 \begin_inset LatexCommand index
11661 name "-\\/-short-is-8bits"
11666 \begin_inset LatexCommand label
11667 name "lyx:--short-is-8bits"
11671 Treat short as 8-bit (for backward compatibility with older versions of
11672 compiler - see section
11673 \begin_inset LatexCommand ref
11674 reference "sec:Compatibility-with-previous"
11681 \begin_layout Standard
11682 \begin_inset VSpace bigskip
11688 \begin_layout Subsection
11689 Intermediate Dump Options
11690 \begin_inset LatexCommand label
11691 name "sub:Intermediate-Dump-Options"
11696 \begin_inset LatexCommand index
11697 name "Options intermediate dump"
11702 \begin_inset LatexCommand index
11703 name "Intermediate dump options"
11710 \begin_layout Standard
11711 The following options are provided for the purpose of retargetting and debugging
11713 They provide a means to dump the intermediate code (iCode
11714 \begin_inset LatexCommand index
11719 ) generated by the compiler in human readable form at various stages of
11720 the compilation process.
11721 More on iCodes see chapter
11722 \begin_inset LatexCommand ref
11723 reference "sub:The-anatomy-of"
11728 \begin_inset Quotes srd
11731 The anatomy of the compiler
11732 \begin_inset Quotes srd
11739 \labelwidthstring 00.00.0000
11746 \begin_layout Standard
11756 \begin_inset LatexCommand index
11757 name "-\\/-dumpraw"
11763 This option will cause the compiler to dump the intermediate code into
11766 <source filename>.dumpraw
11768 just after the intermediate code has been generated for a function, i.e.
11769 before any optimizations are done.
11771 \begin_inset LatexCommand index
11772 name "Basic blocks"
11776 at this stage ordered in the depth first number, so they may not be in
11777 sequence of execution.
11781 \labelwidthstring 00.00.0000
11788 \begin_layout Standard
11798 \begin_inset LatexCommand index
11799 name "-\\/-dumpgcse"
11805 Will create a dump of iCodes, after global subexpression elimination
11806 \begin_inset LatexCommand index
11807 name "Global subexpression elimination"
11811 , into a file named
11813 <source filename>.dumpgcse.
11817 \labelwidthstring 00.00.0000
11824 \begin_layout Standard
11834 \begin_inset LatexCommand index
11835 name "-\\/-dumpdeadcode"
11841 Will create a dump of iCodes, after deadcode elimination
11842 \begin_inset LatexCommand index
11843 name "Dead-code elimination"
11847 , into a file named
11849 <source filename>.dumpdeadcode.
11853 \labelwidthstring 00.00.0000
11860 \begin_layout Standard
11870 \begin_inset LatexCommand index
11871 name "-\\/-dumploop"
11880 Will create a dump of iCodes, after loop optimizations
11881 \begin_inset LatexCommand index
11882 name "Loop optimization"
11886 , into a file named
11888 <source filename>.dumploop.
11892 \labelwidthstring 00.00.0000
11899 \begin_layout Standard
11909 \begin_inset LatexCommand index
11910 name "-\\/-dumprange"
11919 Will create a dump of iCodes, after live range analysis
11920 \begin_inset LatexCommand index
11921 name "Live range analysis"
11925 , into a file named
11927 <source filename>.dumprange.
11931 \labelwidthstring 00.00.0000
11938 \begin_layout Standard
11948 \begin_inset LatexCommand index
11949 name "-\\/-dumlrange"
11955 Will dump the life ranges
11956 \begin_inset LatexCommand index
11957 name "Live range analysis"
11965 \labelwidthstring 00.00.0000
11972 \begin_layout Standard
11982 \begin_inset LatexCommand index
11983 name "-\\/-dumpregassign"
11989 Will create a dump of iCodes, after register assignment
11990 \begin_inset LatexCommand index
11991 name "Register assignment"
11995 , into a file named
11997 <source filename>.dumprassgn.
12001 \labelwidthstring 00.00.0000
12008 \begin_layout Standard
12018 \begin_inset LatexCommand index
12019 name "-\\/-dumplrange"
12025 Will create a dump of the live ranges of iTemp's
12029 \labelwidthstring 00.00.0000
12036 \begin_layout Standard
12046 \begin_inset LatexCommand index
12047 name "-\\/-dumpall"
12056 Will cause all the above mentioned dumps to be created.
12059 \begin_layout Standard
12060 \begin_inset VSpace bigskip
12066 \begin_layout Subsection
12067 Redirecting output on Windows Shells
12070 \begin_layout Standard
12071 By default SDCC writes its error messages to
12072 \begin_inset Quotes sld
12076 \begin_inset Quotes srd
12080 To force all messages to
12081 \begin_inset Quotes sld
12085 \begin_inset Quotes srd
12097 \begin_layout Standard
12112 \begin_inset LatexCommand index
12113 name "-\\/-use-stdout"
12118 Additionally, if you happen to have visual studio installed in your windows
12119 machine, you can use it to compile your sources using a custom build and
12126 \begin_layout Standard
12138 \begin_inset LatexCommand index
12144 Something like this should work:
12163 \begin_layout Standard
12182 \begin_layout Standard
12194 -model-large -c $(InputPath)
12197 \begin_inset VSpace bigskip
12203 \begin_layout Section
12204 Environment variables
12205 \begin_inset LatexCommand index
12206 name "Environment variables"
12213 \begin_layout Standard
12214 SDCC recognizes the following environment variables:
12218 \labelwidthstring 00.00.0000
12222 \begin_inset LatexCommand index
12223 name "SDCC\\_LEAVE\\_SIGNALS"
12229 SDCC installs a signal handler
12230 \begin_inset LatexCommand index
12231 name "signal handler"
12235 to be able to delete temporary files after an user break (^C) or an exception.
12236 If this environment variable is set, SDCC won't install the signal handler
12237 in order to be able to debug SDCC.
12241 \labelwidthstring 00.00.0000
12247 \begin_inset LatexCommand index
12248 name "TMP, TEMP, TMPDIR"
12254 Path, where temporary files will be created.
12255 The order of the variables is the search order.
12256 In a standard *nix environment these variables are not set, and there's
12257 no need to set them.
12258 On Windows it's recommended to set one of them.
12262 \labelwidthstring 00.00.0000
12266 \begin_inset LatexCommand index
12274 \begin_inset LatexCommand ref
12275 reference "sub:Install-paths"
12281 \begin_inset Quotes sld
12285 \begin_inset Quotes srd
12292 \labelwidthstring 00.00.0000
12296 \begin_inset LatexCommand index
12297 name "SDCC\\_INCLUDE"
12304 \begin_inset LatexCommand ref
12305 reference "sub:Search-Paths"
12311 \begin_inset Quotes sld
12315 \begin_inset Quotes srd
12322 \labelwidthstring 00.00.0000
12326 \begin_inset LatexCommand index
12334 \begin_inset LatexCommand ref
12335 reference "sub:Search-Paths"
12341 \begin_inset Quotes sld
12345 \begin_inset Quotes srd
12351 \begin_layout Standard
12352 There are some more environment variables recognized by SDCC, but these
12353 are solely used for debugging purposes.
12354 They can change or disappear very quickly, and will never be documented.
12355 \begin_inset VSpace bigskip
12361 \begin_layout Section
12362 Storage Class Language Extensions
12365 \begin_layout Subsection
12366 MCS51/DS390 Storage Class
12367 \begin_inset LatexCommand index
12368 name "Storage class"
12372 Language Extensions
12375 \begin_layout Standard
12376 In addition to the ANSI storage classes SDCC allows the following MCS51
12377 specific storage classes:
12380 \begin_layout Subsubsection
12382 \begin_inset LatexCommand index
12383 name "data (mcs51, ds390 storage class)"
12388 \begin_inset LatexCommand index
12389 name "\\_\\_data (mcs51, ds390 storage class)"
12394 \begin_inset LatexCommand index
12395 name "near (storage class)"
12400 \begin_inset LatexCommand index
12401 name "\\_\\_near (storage class)"
12408 \begin_layout Standard
12413 storage class for the Small Memory model (
12421 or the more ANSI-C compliant forms
12429 can be used synonymously).
12430 Variables declared with this storage class will be allocated in the directly
12431 addressable portion of the internal RAM of a 8051, e.g.:
12434 \begin_layout Verse
12437 __data unsigned char test_data;
12440 \begin_layout Standard
12441 Writing 0x01 to this variable generates the assembly code:
12444 \begin_layout Verse
12447 75*00 01\InsetSpace ~
12455 \begin_layout Subsubsection
12457 \begin_inset LatexCommand index
12458 name "xdata (mcs51, ds390 storage class)"
12463 \begin_inset LatexCommand index
12464 name "\\_\\_xdata (mcs51, ds390 storage class)"
12469 \begin_inset LatexCommand index
12470 name "far (storage class)"
12475 \begin_inset LatexCommand index
12476 name "\\_\\_far (storage class)"
12483 \begin_layout Standard
12484 Variables declared with this storage class will be placed in the external
12490 storage class for the Large Memory model, e.g.:
12493 \begin_layout Verse
12496 __xdata unsigned char test_xdata;
12499 \begin_layout Standard
12500 Writing 0x01 to this variable generates the assembly code:
12503 \begin_layout Verse
12506 90s00r00\InsetSpace ~
12537 \begin_layout Subsubsection
12539 \begin_inset LatexCommand index
12540 name "idata (mcs51, ds390 storage class)"
12545 \begin_inset LatexCommand index
12546 name "\\_\\_idata (mcs51, ds390 storage class)"
12553 \begin_layout Standard
12554 Variables declared with this storage class will be allocated into the indirectly
12555 addressable portion of the internal ram of a 8051, e.g.:
12558 \begin_layout Verse
12561 __idata unsigned char test_idata;
12564 \begin_layout Standard
12565 Writing 0x01 to this variable generates the assembly code:
12568 \begin_layout Verse
12595 \begin_layout Standard
12596 Please note, the first 128 byte of idata physically access the same RAM
12597 as the data memory.
12598 The original 8051 had 128 byte idata memory, nowadays most devices have
12599 256 byte idata memory.
12601 \begin_inset LatexCommand index
12606 is located in idata memory.
12609 \begin_layout Subsubsection
12611 \begin_inset LatexCommand index
12612 name "pdata (mcs51, ds390 storage class)"
12617 \begin_inset LatexCommand index
12618 name "\\_\\_pdata (mcs51, ds390 storage class)"
12625 \begin_layout Standard
12626 Paged xdata access is just as straightforward as using the other addressing
12628 It is typically located at the start of xdata and has a maximum size of
12630 The following example writes 0x01 to the pdata variable.
12631 Please note, pdata access physically accesses xdata memory.
12632 The high byte of the address is determined by port P2
12633 \begin_inset LatexCommand index
12634 name "P2 (mcs51 sfr)"
12638 (or in case of some 8051 variants by a separate Special Function Register,
12640 \begin_inset LatexCommand ref
12641 reference "sub:MCS51-variants"
12650 storage class for the Medium Memory model, e.g.:
12653 \begin_layout Verse
12656 __pdata unsigned char test_pdata;
12659 \begin_layout Standard
12660 Writing 0x01 to this variable generates the assembly code:
12663 \begin_layout Verse
12672 mov r0,#_test_pdata
12694 \begin_layout Standard
12699 \begin_layout Standard
12709 \begin_inset LatexCommand index
12714 option is used the pdata memory area is followed by the xstack memory area
12715 and the sum of their sizes is limited to 256 bytes.
12718 \begin_layout Subsubsection
12720 \begin_inset LatexCommand index
12726 \begin_inset LatexCommand index
12734 \begin_layout Standard
12735 'Variables' declared with this storage class will be placed in the code
12739 \begin_layout Verse
12742 __code unsigned char test_code;
12745 \begin_layout Standard
12746 Read access to this variable generates the assembly code:
12749 \begin_layout Verse
12752 90s00r6F\InsetSpace ~
12755 mov dptr,#_test_code
12780 \begin_layout Standard
12785 indexed arrays of characters in code memory can be accessed efficiently:
12788 \begin_layout Verse
12791 __code char test_array[] = {'c','h','e','a','p'};
12794 \begin_layout Standard
12795 Read access to this array using an 8-bit unsigned index generates the assembly
12799 \begin_layout Verse
12811 \begin_layout Verse
12814 90s00r41\InsetSpace ~
12817 mov dptr,#_test_array
12820 \begin_layout Verse
12835 \begin_layout Subsubsection
12837 \begin_inset LatexCommand index
12843 \begin_inset LatexCommand index
12851 \begin_layout Standard
12852 This is a data-type and a storage class specifier.
12853 When a variable is declared as a bit, it is allocated into the bit addressable
12854 memory of 8051, e.g.:
12857 \begin_layout Verse
12863 \begin_layout Standard
12864 Writing 1 to this variable generates the assembly code:
12867 \begin_layout Verse
12881 \begin_layout Standard
12882 The bit addressable memory consists of 128 bits which are located from 0x20
12883 to 0x2f in data memory.
12886 Apart from this 8051 specific storage class most architectures support
12888 \begin_inset LatexCommand index
12897 \begin_layout Standard
12898 Not really meant as examples, but nevertheless showing what bitfields are
12899 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12905 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12906 signed modifier are implemented as unsigned.
12909 \begin_layout Subsubsection
12911 \begin_inset LatexCommand index
12917 \begin_inset LatexCommand index
12923 \begin_inset LatexCommand index
12929 \begin_inset LatexCommand index
12935 \begin_inset LatexCommand index
12941 \begin_inset LatexCommand index
12947 \begin_inset LatexCommand index
12953 \begin_inset LatexCommand index
12961 \begin_layout Standard
12962 Like the bit keyword,
12964 sfr / sfr16 / sfr32 / sbit
12966 signify both a data-type and storage class, they are used to describe the
12987 variables of a 8051, eg:
12990 \begin_layout Verse
12994 \begin_inset LatexCommand index
13000 \begin_inset LatexCommand index
13005 (0x80) P0;\InsetSpace ~
13006 /* special function register P0 at location 0x80 */
13011 special function register combination for timer 0
13015 with the high byte at
13016 location 0x8C and the low byte at location 0x8A */
13018 __sfr16 __at (0x8C8A)
13024 \begin_inset LatexCommand index
13030 \begin_inset LatexCommand index
13035 (0xd7) CY;\InsetSpace ~
13037 \begin_inset LatexCommand index
13043 \begin_inset LatexCommand index
13051 \begin_layout Standard
13052 Special function registers which are located on an address dividable by
13053 8 are bit-addressable, an
13057 addresses a specific bit within these sfr.
13059 16 Bit and 32 bit special function
13060 register combinations which require a certain access order are better not
13070 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
13071 this is not guaranteed.
13076 \begin_layout Standard
13077 Please note, if you use a header file which was written for another compiler
13078 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
13084 Specifically the syntax
13087 sfr P0 = 0x80;\InsetSpace ~
13094 by SDCC to an assignment of 0x80 to a variable called P0
13097 \begin_inset Marginal
13100 \begin_layout Standard
13114 Nevertheless it is possible to write header files
13115 \begin_inset LatexCommand index
13116 name "Header files"
13121 \begin_inset LatexCommand index
13122 name "Include files"
13126 which can be shared among different compilers (see section
13127 \begin_inset LatexCommand ref
13128 reference "sec:Porting-code-to-other-compilers"
13136 \begin_layout Subsubsection
13138 \begin_inset LatexCommand index
13143 to MCS51/DS390 specific memory spaces
13146 \begin_layout Standard
13147 SDCC allows (via language extensions) pointers to explicitly point to any
13148 of the memory spaces
13149 \begin_inset LatexCommand index
13150 name "Memory model"
13155 In addition to the explicit pointers, the compiler uses (by default) generic
13156 pointers which can be used to point to any of the memory spaces.
13161 declaration examples:
13164 \begin_layout Verse
13167 /* pointer physically in internal ram pointing to object in external ram
13170 __xdata unsigned char * __data p;
13174 /* pointer physically in external ram
13175 pointing to object in internal ram */
13177 __data unsigned char * __xdata p;
13182 pointer physically in code rom pointing to data in xdata space */
13185 unsigned char * __code p;
13189 /* pointer physically in code space pointing to
13190 data in code space */
13192 __code unsigned char * __code p;
13197 physically located in xdata space */
13199 unsigned char * __xdata p;
13204 pointer physically located in default memory space */
13211 the following is a function pointer
13212 \begin_inset LatexCommand index
13213 name "function pointer"
13217 physically located in data space */
13219 char (* __data fp)(void);
13222 \begin_layout Standard
13223 Well you get the idea.
13228 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
13241 The highest order byte of the
13245 pointers contains the data space information.
13246 Assembler support routines are called whenever data is stored or retrieved
13252 These are useful for developing reusable library
13253 \begin_inset LatexCommand index
13259 Explicitly specifying the pointer
13260 \begin_inset LatexCommand index
13265 type will generate the most efficient code.
13268 \begin_layout Subsubsection
13269 Notes on MCS51 memory
13270 \begin_inset LatexCommand index
13271 name "MCS51 memory"
13278 \begin_layout Standard
13279 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
13280 RAM memory which is structured as follows:
13284 - Bytes 00-1F - 32 bytes to hold
13285 up to 4 banks of the registers R0 to R7,
13287 - Bytes 20-2F - 16 bytes to hold
13289 \begin_inset LatexCommand index
13296 - Bytes 30-7F - 80 bytes for general purpose use.
13301 \begin_layout Standard
13302 Additionally some members of the MCS51 family may have up to 128 bytes of
13303 additional, indirectly addressable, internal RAM memory (
13308 \begin_inset LatexCommand index
13309 name "idata (mcs51, ds390 storage class)"
13314 \begin_inset LatexCommand index
13315 name "\\_\\_idata (mcs51, ds390 storage class)"
13320 Furthermore, some chips may have some built in external memory (
13325 \begin_inset LatexCommand index
13326 name "xdata (mcs51, ds390 storage class)"
13331 \begin_inset LatexCommand index
13332 name "\\_\\_xdata (mcs51, ds390 storage class)"
13336 ) which should not be confused with the internal, directly addressable RAM
13342 \begin_inset LatexCommand index
13343 name "data (mcs51, ds390 storage class)"
13348 \begin_inset LatexCommand index
13349 name "\\_\\_data (mcs51, ds390 storage class)"
13354 Sometimes this built in
13358 memory has to be activated before using it (you can probably find this
13359 information on the datasheet of the microcontroller your are using, see
13361 \begin_inset LatexCommand ref
13362 reference "sub:Startup-Code"
13370 \begin_layout Standard
13371 Normally SDCC will only use the first bank
13372 \begin_inset LatexCommand index
13373 name "register bank (mcs51, ds390)"
13377 of registers (register bank 0), but it is possible to specify that other
13378 banks of registers (keyword
13385 \begin_inset LatexCommand index
13386 name "using (mcs51, ds390 register bank)"
13391 \begin_inset LatexCommand index
13392 name "\\_\\_using (mcs51, ds390 register bank)"
13398 ) should be used for example in interrupt
13399 \begin_inset LatexCommand index
13405 \begin_inset LatexCommand index
13406 name "\\_\\_interrupt"
13411 By default, the compiler will place the stack after the last byte of allocated
13412 memory for variables.
13413 For example, if the first 2 banks of registers are used, and only four
13418 variables, it will position the base of the internal stack at address 20
13420 This implies that as the stack
13421 \begin_inset LatexCommand index
13426 grows, it will use up the remaining register banks, and the 16 bytes used
13427 by the 128 bit variables, and 80 bytes for general purpose use.
13428 If any bit variables are used, the data variables will be placed in unused
13429 register banks and after the byte holding the last bit variable.
13430 For example, if register banks 0 and 1 are used, and there are 9 bit variables
13435 variables will be placed starting from address 0x10 to 0x20 and continue
13441 \begin_layout Standard
13451 \begin_inset LatexCommand index
13452 name "-\\/-data-loc <Value>"
13456 to specify the start address of the
13464 \begin_layout Standard
13474 \begin_inset LatexCommand index
13475 name "-\\/-iram-size <Value>"
13479 to specify the size of the total internal RAM (
13493 \begin_layout Standard
13494 By default the 8051 linker will place the stack after the last byte of (i)data
13500 \begin_layout Standard
13510 \begin_inset LatexCommand index
13511 name "-\\/-stack-loc <Value>"
13515 allows you to specify the start of the stack, i.e.
13516 you could start it after any data in the general purpose area.
13517 If your microcontroller has additional indirectly addressable internal
13522 ) you can place the stack on it.
13523 You may also need to use -
13527 \begin_layout Standard
13537 \begin_inset LatexCommand index
13538 name "-\\/-xdata-loc<Value>"
13542 to set the start address of the external RAM (
13550 \begin_layout Standard
13560 \begin_inset LatexCommand index
13561 name "-\\/-xram-size <Value>"
13565 to specify its size.
13566 Same goes for the code memory, using -
13570 \begin_layout Standard
13580 \begin_inset LatexCommand index
13581 name "-\\/-code-loc <Value>"
13589 \begin_layout Standard
13599 \begin_inset LatexCommand index
13600 name "-\\/-code-size <Value>"
13605 If in doubt, don't specify any options and see if the resulting memory
13606 layout is appropriate, then you can adjust it.
13609 \begin_layout Standard
13610 The linker generates two files with memory allocation information.
13611 The first, with extension .map
13612 \begin_inset LatexCommand index
13617 shows all the variables and segments.
13618 The second with extension .mem
13619 \begin_inset LatexCommand index
13624 shows the final memory layout.
13625 The linker will complain either if memory segments overlap, there is not
13626 enough memory, or there is not enough space for stack.
13627 If you get any linking warnings and/or errors related to stack or segments
13628 allocation, take a look at either the .map or .mem files to find out what
13630 The .mem file may even suggest a solution to the problem.
13631 \begin_inset VSpace bigskip
13637 \begin_layout Subsection
13638 Z80/Z180 Storage Class
13639 \begin_inset LatexCommand index
13640 name "Z80!Storage class"
13644 Language Extensions
13647 \begin_layout Subsubsection
13649 \begin_inset LatexCommand index
13655 \begin_inset LatexCommand index
13660 (in/out to 8-bit addresses)
13663 \begin_layout Standard
13665 \begin_inset LatexCommand index
13670 family has separate address spaces for memory and
13680 \begin_inset LatexCommand index
13681 name "I/O memory (Z80, Z180)"
13686 \begin_inset LatexCommand index
13687 name "Z80!I/O memory"
13692 \begin_inset LatexCommand index
13693 name "Z180!I/O memory"
13697 is accessed with special instructions, e.g.:
13700 \begin_layout Verse
13703 sfr at 0x78 IoPort;\InsetSpace ~
13705 /* define a var in I/O space at 78h called IoPort */
13709 \begin_layout Standard
13710 Writing 0x01 to this variable generates the assembly code:
13713 \begin_layout Verse
13733 \begin_layout Subsubsection
13735 \begin_inset LatexCommand index
13741 \begin_inset LatexCommand index
13746 (in/out to 16-bit addresses)
13749 \begin_layout Standard
13754 is used to support 16 bit addresses in I/O memory e.g.:
13757 \begin_layout Verse
13761 \begin_inset LatexCommand index
13767 \begin_inset LatexCommand index
13775 \begin_layout Standard
13776 Writing 0x01 to this variable generates the assembly code:
13779 \begin_layout Verse
13782 01 23 01\InsetSpace ~
13804 \begin_layout Subsubsection
13806 \begin_inset LatexCommand index
13812 \begin_inset LatexCommand index
13817 (in0/out0 to 8 bit addresses on Z180
13818 \begin_inset LatexCommand index
13824 \begin_inset LatexCommand index
13825 name "HD64180 (see Z180)"
13832 \begin_layout Standard
13833 The compiler option -
13837 \begin_layout Standard
13847 \begin_inset LatexCommand index
13848 name "Z180!Options!-\\/-portmode"
13852 =180 (80) and a compiler #pragma\InsetSpace ~
13854 \begin_inset LatexCommand index
13855 name "Z180!Pragmas!\\#pragma portmode"
13859 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
13869 If you include the file z180.h this will be set automatically.
13870 \begin_inset VSpace bigskip
13876 \begin_layout Subsection
13878 \begin_inset LatexCommand index
13879 name "HC08!Storage class"
13883 Language Extensions
13886 \begin_layout Subsubsection
13888 \begin_inset LatexCommand index
13889 name "data (hc08 storage class)"
13894 \begin_inset LatexCommand index
13895 name "\\_\\_data (hc08 storage class)"
13902 \begin_layout Standard
13903 The data storage class declares a variable that resides in the first 256
13904 bytes of memory (the direct page).
13906 \begin_inset LatexCommand index
13911 is most efficient at accessing variables (especially pointers) stored here.
13914 \begin_layout Subsubsection
13916 \begin_inset LatexCommand index
13917 name "xdata (hc08 storage class)"
13922 \begin_inset LatexCommand index
13923 name "\\_\\_xdata (hc08 storage class)"
13930 \begin_layout Standard
13931 The xdata storage class declares a variable that can reside anywhere in
13933 This is the default if no storage class is specified.
13935 \begin_inset VSpace bigskip
13941 \begin_layout Section
13942 Other SDCC language extensions
13943 \begin_inset LatexCommand index
13944 name "Other SDCC language extensions"
13951 \begin_layout Subsection
13955 \begin_layout Standard
13956 SDCC supports the use of binary constants, such as 0b01100010.
13957 This feature is only enabled when the compiler is invoked using --std-sdccxx.
13960 \begin_layout Standard
13961 \begin_inset VSpace bigskip
13967 \begin_layout Section
13968 Absolute Addressing
13969 \begin_inset LatexCommand index
13970 name "Absolute addressing"
13977 \begin_layout Standard
13978 Data items can be assigned an absolute address with the
13981 \begin_inset LatexCommand index
13987 \begin_inset LatexCommand index
13994 keyword, in addition to a storage class, e.g.:
13997 \begin_layout Verse
14001 \begin_inset LatexCommand index
14002 name "xdata (mcs51, ds390 storage class)"
14007 \begin_inset LatexCommand index
14008 name "\\_\\_xdata (mcs51, ds390 storage class)"
14013 \begin_inset LatexCommand index
14019 \begin_inset LatexCommand index
14024 0x7ffe unsigned int chksum;
14027 \begin_layout Standard
14028 or, better conforming to ISO/IEC 9899 C:
14031 \begin_layout Verse
14034 __xdata __at (0x7ffe) unsigned int chksum;
14037 \begin_layout Standard
14038 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
14039 of the external ram.
14044 reserve any space for variables declared in this way
14045 \begin_inset Marginal
14048 \begin_layout Standard
14057 (they are implemented with an equate in the assembler).
14058 Thus it is left to the programmer to make sure there are no overlaps with
14059 other variables that are declared without the absolute address.
14060 The assembler listing file (.lst
14061 \begin_inset LatexCommand index
14066 ) and the linker output files (.rst
14067 \begin_inset LatexCommand index
14073 \begin_inset LatexCommand index
14078 ) are good places to look for such overlaps.
14081 \begin_layout Standard
14082 If however you provide an initializer
14083 \begin_inset LatexCommand index
14084 name "Variable initialization"
14088 actual memory allocation will take place and overlaps will be detected
14093 \begin_layout Verse
14096 __code __at (0x7ff0) char Id[5] =
14097 \begin_inset Quotes sld
14101 \begin_inset Quotes srd
14107 \begin_layout Standard
14108 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
14112 \begin_layout Standard
14113 In case of memory mapped I/O devices the keyword
14117 has to be used to tell the compiler that accesses might not be removed:
14120 \begin_layout Verse
14124 \begin_inset LatexCommand index
14130 \begin_inset LatexCommand index
14131 name "xdata (mcs51, ds390 storage class)"
14136 \begin_inset LatexCommand index
14141 (0x8000) unsigned char PORTA_8255;
14144 \begin_layout Standard
14145 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
14150 \begin_inset LatexCommand index
14151 name "Aligned array"
14158 starts at a block (256 byte) boundary
14159 \begin_inset LatexCommand index
14160 name "block boundary"
14165 \begin_inset LatexCommand ref
14166 reference "sub:A-Step-by Assembler Introduction"
14172 Absolute addresses can be specified for variables in all
14173 storage classes, e.g.:
14176 \begin_layout Verse
14180 \begin_inset LatexCommand index
14186 \begin_inset LatexCommand index
14194 \begin_layout Standard
14195 The above example will allocate the variable at offset 0x02 in the bit-addressab
14197 There is no real advantage to assigning absolute addresses to variables
14198 in this manner, unless you want strict control over all the variables allocated.
14199 One possible use would be to write hardware portable code.
14200 For example, if you have a routine that uses one or more of the microcontroller
14201 I/O pins, and such pins are different for two different hardwares, you
14202 can declare the I/O pins in your routine using:
14205 \begin_layout Verse
14209 \begin_inset LatexCommand index
14214 __bit MOSI;\InsetSpace ~
14218 /* master out, slave in */
14220 extern volatile __bit MISO;\InsetSpace ~
14227 extern volatile __bit MCLK;\InsetSpace ~
14236 Output of a byte on a 3-wire serial bus.
14241 If needed adapt polarity of clock,
14242 polarity of data and bit order
14247 unsigned char spi_io(unsigned char out_byte)
14272 MOSI = out_byte & 0x80;
14303 /* _asm nop _endasm; */\InsetSpace ~
14311 /* for slow peripherals */
14363 \begin_layout Standard
14364 Then, someplace in the code for the first hardware you would use
14367 \begin_layout Verse
14371 \begin_inset LatexCommand index
14377 \begin_inset LatexCommand index
14382 (0x80) MOSI;\InsetSpace ~
14386 /* I/O port 0, bit 0 */
14388 __bit __at (0x81) MISO;\InsetSpace ~
14395 __bit __at (0x82) MCLK;\InsetSpace ~
14399 /* I/O port 0, bit 2 */
14402 \begin_layout Standard
14403 Similarly, for the second hardware you would use
14406 \begin_layout Verse
14409 __bit __at (0x83) MOSI;\InsetSpace ~
14413 /* I/O port 0, bit 3 */
14415 __bit __at (0x91) MISO;\InsetSpace ~
14420 I/O port 1, bit 1 */
14423 \begin_inset LatexCommand index
14428 __at (0x92) MCLK;\InsetSpace ~
14432 /* I/O port 1, bit 2 */
14435 \begin_layout Standard
14436 and you can use the same hardware dependent routine without changes, as
14437 for example in a library.
14438 This is somehow similar to sbit, but only one absolute address has to be
14439 specified in the whole project.
14440 \begin_inset VSpace bigskip
14446 \begin_layout Section
14448 \begin_inset LatexCommand index
14454 \begin_inset LatexCommand index
14455 name "function parameter"
14460 \begin_inset LatexCommand index
14461 name "local variables"
14466 \begin_inset LatexCommand label
14467 name "sec:Parameters-and-Local-Variables"
14474 \begin_layout Standard
14475 Automatic (local) variables and parameters to functions can either be placed
14476 on the stack or in data-space.
14477 The default action of the compiler is to place these variables in the internal
14478 RAM (for small model) or external RAM (for medium or large model).
14479 This in fact makes them similar to
14482 \begin_inset LatexCommand index
14489 so by default functions are non-reentrant
14490 \begin_inset LatexCommand index
14500 They can be placed on the stack
14501 \begin_inset LatexCommand index
14512 \begin_layout Standard
14522 \begin_inset LatexCommand index
14523 name "-\\/-stack-auto"
14531 #pragma\InsetSpace ~
14535 \begin_inset LatexCommand index
14536 name "\\#pragma stackauto"
14543 \begin_inset LatexCommand index
14550 keyword in the function declaration, e.g.:
14553 \begin_layout Verse
14556 unsigned char foo(char i) __reentrant
14570 \begin_layout Standard
14571 Since stack space on 8051 is limited, the
14581 \begin_layout Standard
14592 option should be used sparingly.
14593 Note that the reentrant keyword just means that the parameters & local
14594 variables will be allocated to the stack, it
14598 mean that the function is register bank
14599 \begin_inset LatexCommand index
14600 name "register bank (mcs51, ds390)"
14609 \begin_inset LatexCommand index
14610 name "local variables"
14614 can be assigned storage classes and absolute
14615 \begin_inset LatexCommand index
14616 name "Absolute addressing"
14623 \begin_layout Verse
14626 unsigned char foo()
14634 __xdata unsigned char i;
14647 \begin_inset LatexCommand index
14652 (0x31) unsigned char j;
14664 \begin_layout Standard
14665 In the above example the variable
14669 will be allocated in the external ram,
14673 in bit addressable space and
14684 \begin_layout Standard
14695 or when a function is declared as
14699 this should only be done for static variables.
14702 \begin_layout Standard
14704 \begin_inset LatexCommand index
14705 name "function parameter"
14709 however are not allowed any storage class
14710 \begin_inset LatexCommand index
14711 name "Storage class"
14715 , (storage classes for parameters will be ignored), their allocation is
14716 governed by the memory model in use, and the reentrancy options.
14719 \begin_layout Standard
14720 It is however allowed to use bit parameters in reentrant functions and also
14721 non-static local bit variables are supported.
14722 Efficient use is limited to 8 semi-bitregisters in bit space.
14723 They are pushed and popped to stack
14724 \begin_inset LatexCommand index
14729 as a single byte just like the normal registers.
14732 \begin_layout Section
14734 \begin_inset LatexCommand label
14735 name "sub:Overlaying"
14740 \begin_inset LatexCommand index
14748 \begin_layout Standard
14750 \begin_inset LatexCommand index
14755 functions SDCC will try to reduce internal ram space usage by overlaying
14756 parameters and local variables of a function (if possible).
14757 Parameters and local variables
14758 \begin_inset LatexCommand index
14759 name "local variables"
14763 of a function will be allocated to an overlayable segment if the function
14766 no other function calls and the function is non-reentrant and the memory
14768 \begin_inset LatexCommand index
14769 name "Memory model"
14776 If an explicit storage class
14777 \begin_inset LatexCommand index
14778 name "Storage class"
14782 is specified for a local variable, it will NOT be overlaid.
14785 \begin_layout Standard
14786 Note that the compiler (not the linkage editor) makes the decision for overlayin
14788 Functions that are called from an interrupt service routine
14789 \begin_inset Marginal
14792 \begin_layout Standard
14800 should be preceded by a #pragma\InsetSpace ~
14802 \begin_inset LatexCommand index
14803 name "\\#pragma nooverlay"
14807 if they are not reentrant.
14810 \begin_layout Standard
14811 Also note that the compiler does not do any processing of inline assembler
14812 code, so the compiler might incorrectly assign local variables and parameters
14813 of a function into the overlay segment if the inline assembler code calls
14814 other c-functions that might use the overlay.
14815 In that case the #pragma\InsetSpace ~
14816 nooverlay should be used.
14819 \begin_layout Standard
14820 Parameters and local variables of functions that contain 16 or 32 bit multiplica
14822 \begin_inset LatexCommand index
14823 name "Multiplication"
14828 \begin_inset LatexCommand index
14833 will NOT be overlaid since these are implemented using external functions,
14837 \begin_layout Verse
14843 \begin_inset LatexCommand index
14844 name "\\#pragma nooverlay"
14850 void set_error(unsigned char errcd)
14867 some_isr () __interrupt
14868 \begin_inset LatexCommand index
14899 \begin_layout Standard
14900 In the above example the parameter
14908 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
14910 not present, this could cause unpredictable runtime behavior when called
14911 from an interrupt service routine.
14912 The #pragma\InsetSpace ~
14913 nooverlay ensures that the parameters and local variables for
14914 the function are NOT overlaid.
14915 \begin_inset VSpace bigskip
14921 \begin_layout Section
14922 Interrupt Service Routines
14923 \begin_inset LatexCommand label
14924 name "sub:Interrupt-Service-Routines"
14931 \begin_layout Subsection
14932 General Information
14935 \begin_layout Standard
14948 outines to be coded in C, with some extended keywords.
14951 \begin_layout Verse
14954 void timer_isr (void) __interrupt (1) __using (1)
14968 \begin_layout Standard
14969 The optional number following the
14972 \begin_inset LatexCommand index
14978 \begin_inset LatexCommand index
14979 name "\\_\\_interrupt"
14985 keyword is the interrupt number this routine will service.
14986 When present, the compiler will insert a call to this routine in the interrupt
14988 \begin_inset LatexCommand index
14989 name "interrupt vector table"
14993 for the interrupt number specified.
14994 If you have multiple source files in your project, interrupt service routines
14995 can be present in any of them, but a prototype of the isr MUST be present
14996 or included in the file that contains the function
15001 The optional (8051 specific) keyword
15004 \begin_inset LatexCommand index
15005 name "using (mcs51, ds390 register bank)"
15010 \begin_inset LatexCommand index
15011 name "\\_\\_using (mcs51, ds390 register bank)"
15017 can be used to tell the compiler to use the specified register bank when
15018 generating code for this function.
15021 Interrupt service routines open the door for some very interesting bugs:
15024 \begin_layout Subsubsection
15025 \begin_inset LatexCommand label
15026 name "sub:Common-interrupt-pitfall-volatile"
15030 Common interrupt pitfall: variable not declared
15035 \begin_layout Standard
15036 If an interrupt service routine changes variables which are accessed by
15037 other functions these variables have to be declared
15042 \begin_inset LatexCommand index
15049 \begin_inset LatexCommand url
15050 target "http://en.wikipedia.org/wiki/Volatile_variable"
15057 \begin_layout Subsubsection
15058 \begin_inset LatexCommand label
15059 name "sub:Common-interrupt-pitfall-non-atomic"
15063 Common interrupt pitfall:
15068 \begin_layout Standard
15069 If the access to these variables is not
15072 \begin_inset LatexCommand index
15080 the processor needs more than one instruction for the access and could
15081 be interrupted while accessing the variable) the interrupt must be disabled
15082 during the access to avoid inconsistent data.
15085 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
15086 and should be protected by disabling interrupts.
15087 You're not automatically on the safe side if you use 8 bit variables though.
15088 We need an example here: f.e.
15089 on the 8051 the harmless looking
15090 \begin_inset Quotes srd
15100 \begin_inset Quotes sld
15109 \begin_inset Quotes srd
15119 \begin_inset Quotes sld
15122 from within an interrupt routine might get lost if the interrupt occurs
15125 \begin_inset Quotes sld
15130 counter\InsetSpace ~
15135 \begin_inset Quotes srd
15138 is not atomic on the 8051 even if
15142 is located in data memory.
15144 Bugs like these are hard to reproduce and can
15145 cause a lot of trouble.
15149 \begin_layout Subsubsection
15150 \begin_inset LatexCommand label
15151 name "sub:Common-interrupt-pitfall-stack-overflow"
15155 Common interrupt pitfall:
15160 \begin_layout Standard
15161 The return address and the registers used in the interrupt service routine
15162 are saved on the stack
15163 \begin_inset LatexCommand index
15168 so there must be sufficient stack space.
15169 If there isn't variables or registers (or even the return address itself)
15176 \begin_inset LatexCommand index
15177 name "stack overflow"
15181 is most likely to happen if the interrupt occurs during the
15182 \begin_inset Quotes sld
15186 \begin_inset Quotes srd
15189 subroutine when the stack is already in use for f.e.
15190 many return addresses.
15193 \begin_layout Subsubsection
15194 \begin_inset LatexCommand label
15195 name "sub:Common-interrupt-pitfall-non-reentrant"
15199 Common interrupt pitfall:
15201 use of non-reentrant functions
15204 \begin_layout Standard
15205 A special note here, int (16 bit) and long (32 bit) integer division
15206 \begin_inset LatexCommand index
15212 \begin_inset LatexCommand index
15213 name "Multiplication"
15218 \begin_inset LatexCommand index
15224 \begin_inset LatexCommand index
15225 name "Floating point support"
15229 operations are implemented using external support routines.
15230 If an interrupt service routine needs to do any of these operations then
15231 the support routines (as mentioned in a following section) will have to
15232 be recompiled using the
15238 \begin_layout Standard
15248 \begin_inset LatexCommand index
15249 name "-\\/-stack-auto"
15255 option and the source file will need to be compiled using the
15261 \begin_layout Standard
15273 \begin_inset LatexCommand index
15274 name "-\\/-int-long-reent"
15281 Note, the type promotion
15282 \begin_inset LatexCommand index
15283 name "type promotion"
15287 required by ANSI C can cause 16 bit routines to be used
15288 \begin_inset Marginal
15291 \begin_layout Standard
15300 without the programmer being aware of it.
15305 (unsigned char)(tail-1)
15310 within the if clause in section
15311 \begin_inset LatexCommand ref
15312 reference "sub:A-Step-by Assembler Introduction"
15319 \begin_layout Standard
15320 Calling other functions from an interrupt service routine is not recommended,
15321 avoid it if possible.
15322 Note that when some function is called from an interrupt service routine
15323 it should be preceded by a #pragma\InsetSpace ~
15325 \begin_inset LatexCommand index
15326 name "\\#pragma nooverlay"
15330 if it is not reentrant.
15331 Furthermore nonreentrant functions should not be called from the main program
15332 while the interrupt service routine might be active.
15333 They also must not be called from low priority interrupt service routines
15334 while a high priority interrupt service routine might be active.
15335 You could use semaphores or make the function
15339 if all parameters are passed in registers.
15342 \begin_inset LatexCommand ref
15343 reference "sub:Overlaying"
15348 about Overlaying and section
15349 \begin_inset LatexCommand ref
15350 reference "sub:Functions-using-private-banks"
15355 about Functions using private register banks.
15356 \begin_inset VSpace bigskip
15362 \begin_layout Subsection
15363 MCS51/DS390 Interrupt Service Routines
15366 \begin_layout Standard
15368 \begin_inset LatexCommand index
15373 numbers and the corresponding address & descriptions for the Standard 8051/8052
15375 SDCC will automatically adjust the
15376 \begin_inset LatexCommand index
15377 name "interrupt vector table"
15381 to the maximum interrupt number specified.
15386 \begin_layout Standard
15388 \begin_inset Tabular
15389 <lyxtabular version="3" rows="9" columns="3">
15391 <column alignment="center" valignment="top" leftline="true" width="0in">
15392 <column alignment="left" valignment="top" leftline="true" width="0in">
15393 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
15394 <row topline="true" bottomline="true">
15395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15398 \begin_layout Standard
15404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15407 \begin_layout Standard
15413 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15416 \begin_layout Standard
15423 <row topline="true">
15424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15427 \begin_layout Standard
15433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15436 \begin_layout Standard
15442 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15445 \begin_layout Standard
15452 <row topline="true">
15453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15456 \begin_layout Standard
15462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15465 \begin_layout Standard
15471 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15474 \begin_layout Standard
15481 <row topline="true">
15482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15485 \begin_layout Standard
15491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15494 \begin_layout Standard
15500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15503 \begin_layout Standard
15510 <row topline="true">
15511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15514 \begin_layout Standard
15520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15523 \begin_layout Standard
15529 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15532 \begin_layout Standard
15539 <row topline="true">
15540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15543 \begin_layout Standard
15549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15552 \begin_layout Standard
15558 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15561 \begin_layout Standard
15568 <row topline="true">
15569 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15572 \begin_layout Standard
15578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15581 \begin_layout Standard
15587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15590 \begin_layout Standard
15597 <row topline="true">
15598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15601 \begin_layout Standard
15607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15610 \begin_layout Standard
15616 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15619 \begin_layout Standard
15626 <row topline="true" bottomline="true">
15627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15630 \begin_layout Standard
15636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15639 \begin_layout Standard
15645 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15648 \begin_layout Standard
15664 \begin_layout Standard
15665 If the interrupt service routine is defined without
15668 \begin_inset LatexCommand index
15669 name "using (mcs51, ds390 register bank)"
15674 \begin_inset LatexCommand index
15675 name "\\_\\_using (mcs51, ds390 register bank)"
15681 a register bank or with register bank 0 (
15685 0), the compiler will save the registers used by itself on the stack upon
15686 entry and restore them at exit, however if such an interrupt service routine
15687 calls another function then the entire register bank will be saved on the
15689 This scheme may be advantageous for small interrupt service routines which
15690 have low register usage.
15693 \begin_layout Standard
15694 If the interrupt service routine is defined to be using a specific register
15699 & psw are saved and restored, if such an interrupt service routine calls
15700 another function (using another register bank) then the entire register
15701 bank of the called function will be saved on the stack
15702 \begin_inset LatexCommand index
15708 This scheme is recommended for larger interrupt service routines.
15709 \begin_inset VSpace bigskip
15715 \begin_layout Subsection
15717 \begin_inset LatexCommand index
15722 Interrupt Service Routines
15725 \begin_layout Standard
15726 Since the number of interrupts
15727 \begin_inset LatexCommand index
15728 name "HC08!interrupt"
15732 available is chip specific and the interrupt vector table always ends at
15733 the last byte of memory, the interrupt numbers corresponds to the interrupt
15734 vectors in reverse order of address.
15735 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
15736 2 will use the interrupt vector at 0xfffa, and so on.
15737 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
15738 this way; instead see section
15739 \begin_inset LatexCommand ref
15740 reference "sub:Startup-Code"
15744 for details on customizing startup.
15745 \begin_inset VSpace bigskip
15751 \begin_layout Subsection
15752 Z80 Interrupt Service Routines
15755 \begin_layout Standard
15757 \begin_inset LatexCommand index
15762 uses several different methods for determining the correct interrupt
15763 \begin_inset LatexCommand index
15764 name "Z80!interrupt"
15768 vector depending on the hardware implementation.
15769 Therefore, SDCC ignores the optional interrupt number and does not attempt
15770 to generate an interrupt vector table.
15773 \begin_layout Standard
15774 By default, SDCC generates code for a maskable interrupt, which uses a RETI
15775 instruction to return from the interrupt.
15776 To write an interrupt handler for the non-maskable interrupt, which needs
15777 a RETN instruction instead, add the
15784 \begin_layout Verse
15787 void nmi_isr (void) critical interrupt
15801 \begin_layout Standard
15802 However if you need to create a non-interruptable interrupt service routine
15803 you would also require the
15808 To distinguish between this and an nmi_isr you must provide an interrupt
15810 \begin_inset VSpace bigskip
15816 \begin_layout Section
15817 Enabling and Disabling Interrupts
15820 \begin_layout Subsection
15821 Critical Functions and Critical Statements
15824 \begin_layout Standard
15825 A special keyword may be associated with a block or a function declaring
15831 SDCC will generate code to disable all interrupts
15832 \begin_inset LatexCommand index
15837 upon entry to a critical function and restore the interrupt enable to the
15838 previous state before returning.
15839 Nesting critical functions will need one additional byte on the stack
15840 \begin_inset LatexCommand index
15848 \begin_layout Verse
15851 int foo () __critical
15852 \begin_inset LatexCommand index
15858 \begin_inset LatexCommand index
15859 name "\\_\\_critical"
15884 \begin_layout Standard
15885 The critical attribute maybe used with other attributes like
15895 may also be used to disable interrupts more locally:
15898 \begin_layout Verse
15904 \begin_layout Standard
15905 More than one statement could have been included in the block.
15908 \begin_layout Subsection
15909 Enabling and Disabling Interrupts directly
15912 \begin_layout Standard
15914 \begin_inset LatexCommand index
15919 can also be disabled and enabled directly (8051):
15922 \begin_layout Verse
15925 EA = 0;\InsetSpace ~
15951 \begin_layout Verse
15987 \begin_layout Verse
15990 EA = 1;\InsetSpace ~
16019 \begin_layout Verse
16058 \begin_layout Standard
16059 On other architectures which have separate opcodes for enabling and disabling
16060 interrupts you might want to make use of defines with inline assembly
16061 \begin_inset LatexCommand index
16062 name "Assembler routines"
16067 \begin_inset LatexCommand index
16068 name "HC08!interrupt"
16075 \begin_layout Verse
16079 \begin_inset LatexCommand index
16089 \begin_inset LatexCommand index
16097 \begin_layout Verse
16100 #define SEI _asm\InsetSpace ~
16107 \begin_layout Verse
16113 \begin_layout Standard
16114 Note: it is sometimes sufficient to disable only a specific interrupt source
16116 a timer or serial interrupt by manipulating an
16119 \begin_inset LatexCommand index
16120 name "interrupt mask"
16130 \begin_layout Standard
16131 Usually the time during which interrupts are disabled should be kept as
16133 This minimizes both
16138 \begin_inset LatexCommand index
16139 name "interrupt latency"
16143 (the time between the occurrence of the interrupt and the execution of
16144 the first code in the interrupt routine) and
16149 \begin_inset LatexCommand index
16150 name "interrupt jitter"
16154 (the difference between the shortest and the longest interrupt latency).
16155 These really are something different, f.e.
16156 a serial interrupt has to be served before its buffer overruns so it cares
16157 for the maximum interrupt latency, whereas it does not care about jitter.
16158 On a loudspeaker driven via a digital to analog converter which is fed
16159 by an interrupt a latency of a few milliseconds might be tolerable, whereas
16160 a much smaller jitter will be very audible.
16163 \begin_layout Standard
16164 You can reenable interrupts within an interrupt routine and on some architecture
16165 s you can make use of two (or more) levels of
16167 interrupt priorities
16170 \begin_inset LatexCommand index
16171 name "interrupt priority"
16176 On some architectures which don't support interrupt priorities these can
16177 be implemented by manipulating the interrupt mask and reenabling interrupts
16178 within the interrupt routine.
16179 Check there is sufficient space on the stack
16180 \begin_inset LatexCommand index
16185 and don't add complexity unless you have to.
16189 \begin_layout Subsection
16191 \begin_inset LatexCommand index
16196 locking (mcs51/ds390)
16199 \begin_layout Standard
16200 Some architectures (mcs51/ds390) have an atomic
16201 \begin_inset LatexCommand index
16206 bit test and clear instruction.
16207 These type of instructions are typically used in preemptive multitasking
16208 systems, where a routine f.e.
16209 claims the use of a data structure ('acquires a lock
16210 \begin_inset LatexCommand index
16215 on it'), makes some modifications and then releases the lock when the data
16216 structure is consistent again.
16217 The instruction may also be used if interrupt and non-interrupt code have
16218 to compete for a resource.
16219 With the atomic bit test and clear instruction interrupts
16220 \begin_inset LatexCommand index
16225 don't have to be disabled for the locking operation.
16229 \begin_layout Standard
16230 SDCC generates this instruction if the source follows this pattern:
16233 \begin_layout Verse
16237 \begin_inset LatexCommand index
16242 bit resource_is_free;
16246 if (resource_is_free)
16256 resource_is_free=0;
16269 resource_is_free=1;
16276 \begin_layout Standard
16277 Note, mcs51 and ds390 support only an atomic
16278 \begin_inset LatexCommand index
16287 instruction (as opposed to atomic bit test and
16292 \begin_layout Section
16293 Functions using private register banks
16294 \begin_inset LatexCommand label
16295 name "sub:Functions-using-private-banks"
16302 \begin_layout Standard
16303 Some architectures have support for quickly changing register sets.
16304 SDCC supports this feature with the
16307 \begin_inset LatexCommand index
16308 name "using (mcs51, ds390 register bank)"
16313 \begin_inset LatexCommand index
16314 name "\\_\\_using (mcs51, ds390 register bank)"
16320 attribute (which tells the compiler to use a register bank
16321 \begin_inset LatexCommand index
16322 name "register bank (mcs51, ds390)"
16326 other than the default bank zero).
16327 It should only be applied to
16330 \begin_inset LatexCommand index
16337 functions (see footnote below).
16338 This will in most circumstances make the generated ISR code more efficient
16339 since it will not have to save registers on the stack.
16342 \begin_layout Standard
16347 attribute will have no effect on the generated code for a
16351 function (but may occasionally be useful anyway
16355 \begin_layout Standard
16356 possible exception: if a function is called ONLY from 'interrupt' functions
16357 using a particular bank, it can be declared with the same 'using' attribute
16358 as the calling 'interrupt' functions.
16359 For instance, if you have several ISRs using bank one, and all of them
16360 call memcpy(), it might make sense to create a specialized version of memcpy()
16361 'using 1', since this would prevent the ISR from having to save bank zero
16362 to the stack on entry and switch to bank zero before calling the function
16371 (pending: Note, nowadays the
16375 attribute has an effect on
16379 the generated code for a
16390 \begin_layout Standard
16395 function using a non-zero bank will assume that it can trash that register
16396 bank, and will not save it.
16397 Since high-priority interrupts
16398 \begin_inset LatexCommand index
16404 \begin_inset LatexCommand index
16405 name "interrupt priority"
16409 can interrupt low-priority ones on the 8051 and friends, this means that
16410 if a high-priority ISR
16414 a particular bank occurs while processing a low-priority ISR
16418 the same bank, terrible and bad things can happen.
16419 To prevent this, no single register bank should be
16423 by both a high priority and a low priority ISR.
16424 This is probably most easily done by having all high priority ISRs use
16425 one bank and all low priority ISRs use another.
16426 If you have an ISR which can change priority at runtime, you're on your
16427 own: I suggest using the default bank zero and taking the small performance
16431 \begin_layout Standard
16432 It is most efficient if your ISR calls no other functions.
16433 If your ISR must call other functions, it is most efficient if those functions
16434 use the same bank as the ISR (see note 1 below); the next best is if the
16435 called functions use bank zero.
16436 It is very inefficient to call a function using a different, non-zero bank
16439 \begin_inset VSpace bigskip
16445 \begin_layout Section
16447 \begin_inset LatexCommand label
16448 name "sub:Startup-Code"
16453 \begin_inset LatexCommand index
16454 name "Startup code"
16461 \begin_layout Subsection
16462 MCS51/DS390 Startup Code
16465 \begin_layout Standard
16466 The compiler triggers the linker to link certain initialization modules
16467 from the runtime library
16468 \begin_inset LatexCommand index
16469 name "Runtime library"
16473 called crt<something>.
16474 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
16475 GSINIT5) is not linked unless the -
16481 \begin_layout Standard
16492 -xstack option is used.
16493 These modules are highly entangled by the use of special segments/areas,
16494 but a common layout is shown below:
16497 \begin_layout Verse
16505 \begin_layout Verse
16529 ljmp __sdcc_gsinit_startup
16532 \begin_layout Verse
16540 \begin_layout Verse
16552 .area GSINIT0 (CODE)
16554 __sdcc_gsinit_startup::
16564 mov sp,#__start__stack - 1
16567 \begin_layout Verse
16575 \begin_layout Verse
16587 .area GSINIT1 (CODE)
16589 __sdcc_init_xstack::
16591 ; Need to initialize in GSINIT1 in
16592 case the user's __sdcc_external_startup uses the xstack.
16602 mov __XPAGE,#(__start__x
16613 mov _spx,#__start__xstack
16616 \begin_layout Verse
16624 \begin_layout Verse
16636 .area GSINIT2 (CODE)
16646 lcall __sdcc_external_startup
16666 jz __sdcc_init_data
16677 __sdcc_program_startup
16682 \begin_layout Verse
16690 \begin_layout Verse
16702 .area GSINIT3 (CODE)
16755 mov r2,#((l_XINIT+255) >> 8)
16786 __XPAGE,#(s_XISEG >> 8)
16788 00001$:\InsetSpace ~
16852 00002$:\InsetSpace ~
16879 \begin_layout Verse
16887 \begin_layout Verse
16899 .area GSINIT4 (CODE)
16901 __mcs51_genRAMCLEAR::
16923 00004$:\InsetSpace ~
16937 ; _mcs51_genRAMCLEAR() end
16940 \begin_layout Verse
16948 \begin_layout Verse
16960 .area GSINIT4 (CODE)
16962 __mcs51_genXRAMCLEAR::
17023 mov __XPAGE,#(s_PSEG >> 8)
17035 00005$:\InsetSpace ~
17110 mov r1,#((l_XSEG + 255) >> 8)
17132 00007$:\InsetSpace ~
17169 \begin_layout Verse
17177 \begin_layout Verse
17189 .area GSINIT5 (CODE)
17191 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
17194 ; and __mcs51_genRAMCLEAR modifies _spx.
17204 mov __XPAGE,#(__start__x
17215 mov _spx,#__start__xstack
17218 \begin_layout Verse
17223 (application modules)
17226 \begin_layout Verse
17238 .area GSINIT (CODE)
17241 \begin_layout Verse
17249 \begin_layout Verse
17261 .area GSFINAL (CODE)
17271 ljmp __sdcc_program_startup
17273 ;---------------------------------
17274 -----------------------
17278 ;--------------------------------------------------
17301 __sdcc_program_startup:
17314 return from main will lock up
17327 \begin_layout Standard
17328 One of these modules (crtstart.asm) contains a call to the C routine
17330 _sdcc_external_startup()
17331 \begin_inset LatexCommand index
17332 name "\\_sdcc\\_external\\_startup()"
17338 at the start of the CODE area.
17339 This routine is also in the runtime library
17340 \begin_inset LatexCommand index
17341 name "Runtime library"
17345 and returns 0 by default.
17346 If this routine returns a non-zero value, the static & global variable
17347 initialization will be skipped and the function main will be invoked.
17348 Otherwise static & global variables will be initialized before the function
17352 _sdcc_external_startup()
17354 routine to your program to override the default if you need to setup hardware
17355 or perform some other critical operation prior to static & global variable
17357 \begin_inset LatexCommand index
17358 name "Variable initialization"
17363 On some mcs51 variants xdata
17364 \begin_inset LatexCommand index
17365 name "xdata (mcs51, ds390 storage class)"
17369 memory has to be explicitly enabled before it can be accessed or if the
17371 \begin_inset LatexCommand index
17376 needs to be disabled, this is the place to do it.
17377 The startup code clears all internal data memory, 256 bytes by default,
17378 but from 0 to n-1 if
17384 \begin_layout Standard
17394 \begin_inset LatexCommand index
17395 name "-\\/-iram-size <Value>"
17402 (recommended for Chipcon CC1010).
17405 \begin_layout Standard
17406 See also the compiler options
17412 \begin_layout Standard
17428 \begin_inset LatexCommand index
17429 name "-\\/-no-xinit-opt"
17439 \begin_layout Standard
17451 \begin_inset LatexCommand index
17452 name "-\\/-main-return"
17457 \begin_inset LatexCommand ref
17458 reference "sub:MCS51-variants"
17462 about MCS51-variants.
17467 \begin_layout Standard
17468 While these initialization modules are meant as generic startup code there
17469 might be the need for customization.
17470 Let's assume the return value of
17472 _sdcc_external_startup()
17478 should not be checked (or
17480 _sdcc_external_startup()
17482 should not be called at all).
17483 The recommended way would be to copy
17489 \begin_inset LatexCommand url
17490 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm"
17494 ) into the source directory, adapt it there, then assemble it with
17500 \begin_layout Standard
17501 \begin_inset Quotes sld
17505 \begin_inset Quotes srd
17508 are the assembler options used in
17509 \begin_inset LatexCommand url
17510 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup "
17521 and when linking your project explicitly specify
17526 As a bonus a listing of the relocated object file
17533 \begin_layout Standard
17534 \begin_inset VSpace bigskip
17540 \begin_layout Subsection
17544 \begin_layout Standard
17546 \begin_inset LatexCommand index
17551 startup code follows the same scheme as the MCS51 startup code.
17552 \begin_inset VSpace bigskip
17558 \begin_layout Subsection
17562 \begin_layout Standard
17564 \begin_inset LatexCommand index
17569 the startup code is inserted by linking with crt0.o which is generated from
17570 sdcc/device/lib/z80/crt0.s.
17571 If you need a different startup code you can use the compiler option
17580 \begin_layout Standard
17595 \begin_inset LatexCommand index
17596 name "-\\/-no-std-crt0"
17600 and provide your own crt0.o.
17602 \begin_inset VSpace bigskip
17608 \begin_layout Section
17609 Inline Assembler Code
17610 \begin_inset LatexCommand index
17611 name "Assembler routines"
17618 \begin_layout Subsection
17619 A Step by Step Introduction
17620 \begin_inset LatexCommand label
17621 name "sub:A-Step-by Assembler Introduction"
17628 \begin_layout Standard
17629 Starting from a small snippet of c-code this example shows for the MCS51
17630 how to use inline assembly, access variables, a function parameter and
17631 an array in xdata memory.
17632 The example uses an MCS51 here but is easily adapted for other architectures.
17633 This is a buffer routine which should be optimized:
17636 \begin_layout Verse
17640 unsigned char __far
17641 \begin_inset LatexCommand index
17642 name "far (storage class)"
17647 \begin_inset LatexCommand index
17648 name "\\_\\_far (storage class)"
17653 \begin_inset LatexCommand index
17659 \begin_inset LatexCommand index
17664 (0x7f00) buf[0x100];
17665 \begin_inset LatexCommand index
17666 name "Aligned array"
17672 unsigned char head, tail;\InsetSpace ~
17690 \begin_inset LatexCommand index
17743 \begin_inset LatexCommand ref
17744 reference "sub:Common-interrupt-pitfall-volatile"
17762 void to_buffer( unsigned char c )
17770 if( head != (unsigned char)(tail-1)
17783 \begin_inset LatexCommand index
17784 name "promotion to signed int"
17789 \begin_inset LatexCommand index
17790 name "type promotion"
17795 \begin_inset Marginal
17798 \begin_layout Standard
17817 buf[ head++ ] = c;\InsetSpace ~
17833 /* access to a 256 byte aligned array */
17838 \begin_layout Standard
17839 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
17840 then a corresponding buffer.asm file is generated.
17841 We define a new function
17845 in file buffer.c in which we cut and paste the generated code, removing
17846 unwanted comments and some ':'.
17848 \begin_inset Quotes sld
17856 \begin_inset Quotes srd
17860 \begin_inset Quotes sld
17868 \begin_inset Quotes srd
17875 \begin_layout Standard
17876 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
17877 and for C-99 compatibility, the double-underscore form (__asm and __endasm)
17879 The latter is also used in the library functions.
17884 to the beginning and the end of the function body:
17887 \begin_layout Verse
17891 /* With a cut and paste from the .asm file, we have something to start with.
17897 function is not yet OK! (registers aren't saved) */
17899 void to_buffer_asm(
17909 \begin_inset LatexCommand index
17915 \begin_inset LatexCommand index
17930 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
17942 \begin_inset LatexCommand index
17943 name "promotion to signed int"
17948 \begin_inset LatexCommand index
17949 name "type promotion"
18002 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
18003 \begin_inset LatexCommand index
18004 name "Aligned array"
18070 \begin_inset LatexCommand index
18076 \begin_inset LatexCommand index
18077 name "\\_\\_endasm"
18086 \begin_layout Standard
18087 The new file buffer.c should compile with only one warning about the unreferenced
18088 function argument 'c'.
18089 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
18090 (1) and finally have:
18093 \begin_layout Verse
18097 unsigned char __far __at(0x7f00) buf[0x100];
18099 unsigned char head, tail;
18110 void to_buffer( unsigned char c )
18119 head != (unsigned char)(tail-1) )
18148 c; // to avoid warning: unreferenced function argument
18155 \begin_inset LatexCommand index
18161 \begin_inset LatexCommand index
18176 ; save used registers here.
18187 ; If we were still using r2,r3 we would have to push them here.
18190 ; if( head != (unsigned char)(tail-1) )
18234 could do an ANL a,#0x0f here to use a smaller buffer (see below)
18270 a,dpl \InsetSpace ~
18277 ; dpl holds lower byte of function argument
18289 dpl,_head \InsetSpace ~
18292 ; buf is 0x100 byte aligned so head can be used directly
18335 ; we could do an ANL _head,#0x0f here to use a
18336 smaller buffer (see above)
18348 ; restore used registers here
18355 \begin_inset LatexCommand index
18361 \begin_inset LatexCommand index
18362 name "\\_\\_endasm"
18373 \begin_layout Standard
18374 The inline assembler code can contain any valid code understood by the assembler
18375 , this includes any assembler directives and comment lines.
18376 The assembler does not like some characters like ':' or ''' in comments.
18377 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
18378 \begin_inset LatexCommand index
18379 name "asXXXX (as-gbz80, as-hc08, asx8051, as-z80)"
18384 \begin_inset LatexCommand index
18385 name "Assembler documentation"
18390 \begin_inset LatexCommand url
18391 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html"
18399 \begin_layout Standard
18400 The compiler does not do any validation of the code within the
18403 \begin_inset LatexCommand index
18409 \begin_inset LatexCommand index
18418 \begin_inset LatexCommand index
18424 \begin_inset LatexCommand index
18425 name "\\_\\_endasm"
18434 Specifically it will not know which registers are used and thus register
18436 \begin_inset LatexCommand index
18441 has to be done manually.
18445 \begin_layout Standard
18446 It is recommended that each assembly instruction (including labels) be placed
18447 in a separate line (as the example shows).
18452 \begin_layout Standard
18464 \begin_inset LatexCommand index
18465 name "-\\/-peep-asm"
18471 command line option is used, the inline assembler code will be passed through
18472 the peephole optimizer
18473 \begin_inset LatexCommand index
18474 name "Peephole optimizer"
18479 There are only a few (if any) cases where this option makes sense, it might
18480 cause some unexpected changes in the inline assembler code.
18481 Please go through the peephole optimizer rules defined in file
18485 before using this option.
18488 \begin_layout Subsection
18490 \begin_inset LatexCommand label
18491 name "sub:Naked-Functions"
18496 \begin_inset LatexCommand index
18497 name "Naked functions"
18504 \begin_layout Standard
18505 A special keyword may be associated with a function declaring it as
18508 \begin_inset LatexCommand index
18514 \begin_inset LatexCommand index
18526 function modifier attribute prevents the compiler from generating prologue
18527 \begin_inset LatexCommand index
18528 name "function prologue"
18533 \begin_inset LatexCommand index
18534 name "function epilogue"
18538 code for that function.
18539 This means that the user is entirely responsible for such things as saving
18540 any registers that may need to be preserved, selecting the proper register
18541 bank, generating the
18545 instruction at the end, etc.
18546 Practically, this means that the contents of the function must be written
18547 in inline assembler.
18548 This is particularly useful for interrupt functions, which can have a large
18549 (and often unnecessary) prologue/epilogue.
18550 For example, compare the code generated by these two functions:
18553 \begin_layout Verse
18557 \begin_inset LatexCommand index
18562 data unsigned char counter;
18566 void simpleInterrupt(void) __interrupt
18567 \begin_inset LatexCommand index
18573 \begin_inset LatexCommand index
18574 name "\\_\\_interrupt"
18592 void nakedInterrupt(void) __interrupt (2) __naked
18601 \begin_inset LatexCommand index
18607 \begin_inset LatexCommand index
18625 _counter ; does not change flags, no need to save psw
18638 include ret or reti in _naked function.
18645 \begin_inset LatexCommand index
18651 \begin_inset LatexCommand index
18652 name "\\_\\_endasm"
18661 \begin_layout Standard
18662 For an 8051 target, the generated simpleInterrupt looks like:
18665 \begin_layout Verse
18678 example, recent versions of SDCC generate
18690 code for simpleInterrupt() and nakedInterrupt()!
18831 \begin_layout Standard
18832 whereas nakedInterrupt looks like:
18835 \begin_layout Verse
18848 _counter ; does not change flags, no need to save psw
18867 MUST explicitly include ret or reti in _naked function
18870 \begin_layout Standard
18871 The related directive #pragma exclude
18872 \begin_inset LatexCommand index
18873 name "\\#pragma exclude"
18877 allows a more fine grained control over pushing & popping
18878 \begin_inset LatexCommand index
18886 \begin_layout Standard
18887 While there is nothing preventing you from writing C code inside a
18891 function, there are many ways to shoot yourself in the foot doing this,
18892 and it is recommended that you stick to inline assembler.
18895 \begin_layout Subsection
18896 Use of Labels within Inline Assembler
18899 \begin_layout Standard
18900 SDCC allows the use of in-line assembler with a few restrictions regarding
18902 All labels defined within inline assembler code have to be of the form
18907 where nnnnn is a number less than 100 (which implies a limit of utmost
18908 100 inline assembler labels
18919 \begin_layout Standard
18920 This is a slightly more stringent rule than absolutely necessary, but stays
18921 always on the safe side.
18922 Labels in the form of nnnnn$ are local labels in the assembler, locality
18923 of which is confined within two labels of the standard form.
18924 The compiler uses the same form for labels within a function (but starting
18925 from nnnnn=00100); and places always a standard label at the beginning
18926 of a function, thus limiting the locality of labels within the scope of
18928 So, if the inline assembler part would be embedded into C-code, an improperly
18929 placed non-local label in the assembler would break up the reference space
18930 for labels created by the compiler for the C-code, leading to an assembling
18934 \begin_layout Standard
18935 The numeric part of local labels does not need to have 5 digits (although
18936 this is the form of labels output by the compiler), any valid integer will
18938 Please refer to the assemblers documentation for further details.
18946 \begin_layout Verse
18950 \begin_inset LatexCommand index
18956 \begin_inset LatexCommand index
18987 \begin_inset LatexCommand index
18993 \begin_inset LatexCommand index
18994 name "\\_\\_endasm"
19001 \begin_layout Standard
19002 Inline assembler code cannot reference any C-labels, however it can reference
19004 \begin_inset LatexCommand index
19009 defined by the inline assembler, e.g.:
19012 \begin_layout Verse
19035 ; some assembler code
19056 /* some more c code */
19058 clabel:\InsetSpace ~
19060 /* inline assembler cannot reference this
19065 \begin_layout Standard
19070 is translated by the compiler into a local label, so the locality of labels
19071 within the function is not broken.
19088 0003$: ;label (can be referenced by inline assembler only)
19095 \begin_inset LatexCommand index
19101 \begin_inset LatexCommand index
19102 name "\\_\\_endasm"
19112 /* some more c code */
19117 \begin_layout Standard
19118 In other words inline assembly code can access labels defined in inline
19119 assembly within the scope of the function.
19120 The same goes the other way, i.e.
19121 labels defines in inline assembly can not be accessed by C statements.
19124 \begin_layout Section
19125 Interfacing with Assembler Code
19126 \begin_inset LatexCommand index
19127 name "Assembler routines"
19134 \begin_layout Subsection
19135 Global Registers used for Parameter Passing
19136 \begin_inset LatexCommand index
19137 name "Parameter passing"
19144 \begin_layout Standard
19145 The compiler always uses the global registers
19148 \begin_inset LatexCommand index
19149 name "DPTR, DPH, DPL"
19154 \begin_inset LatexCommand index
19160 \begin_inset LatexCommand index
19161 name "B (mcs51, ds390 register)"
19170 \begin_inset LatexCommand index
19171 name "ACC (mcs51, ds390 register)"
19177 to pass the first (non-bit) parameter to a function, and also to pass the
19179 \begin_inset LatexCommand index
19180 name "return value"
19184 of function; according to the following scheme: one byte return value in
19189 , two byte value in
19198 three byte values (generic pointers) in
19210 , and four byte values in
19228 \begin_inset LatexCommand index
19229 name "generic pointer"
19233 contain type of accessed memory in
19254 \begin_inset Note Note
19257 \begin_layout Standard
19258 This might not be the case of certain memory models (medium???)
19266 \begin_layout Standard
19267 The second parameter onwards is either allocated on the stack (for reentrant
19272 \begin_layout Standard
19281 -stack-auto is used) or in data/xdata memory (depending on the memory model).
19284 \begin_layout Standard
19285 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
19286 space for reentrant functions or allocated directly in bit memory otherwise.
19289 \begin_layout Standard
19290 Functions (with two or more parameters or bit parameters) that are called
19291 through function pointers
19292 \begin_inset LatexCommand index
19293 name "function pointers"
19297 must therefor be reentrant so the compiler knows how to pass the parameters.
19300 \begin_layout Subsection
19304 \begin_layout Standard
19305 Unless the called function is declared as
19310 \begin_inset LatexCommand index
19319 \begin_layout Standard
19329 \begin_inset LatexCommand index
19330 name "-\\/-callee-saves"
19338 \begin_layout Standard
19347 -all-callee-saves command line option or the corresponding callee_saves
19348 pragma are used, the caller will save the registers (
19352 ) around the call, so the called function can destroy they content freely.
19355 \begin_layout Standard
19356 If the called function is not declared as
19360 , the caller will swap register banks around the call, if caller and callee
19361 use different register banks (having them defined by the
19369 \begin_layout Standard
19370 The called function can also use
19386 observing that they are used for parameter/return value passing.
19389 \begin_layout Subsection
19390 Assembler Routine (non-reentrant)
19393 \begin_layout Standard
19394 In the following example
19395 \begin_inset LatexCommand index
19401 \begin_inset LatexCommand index
19402 name "Assembler routines (non-reentrant)"
19406 the function c_func calls an assembler routine asm_func, which takes two
19408 \begin_inset LatexCommand index
19409 name "function parameter"
19416 \begin_layout Verse
19419 extern int asm_func(unsigned char, unsigned char);
19423 int c_func (unsigned char
19424 i, unsigned char j)
19432 return asm_func(i,j);
19446 return c_func(10,9);
19451 \begin_layout Standard
19452 The corresponding assembler function is:
19455 \begin_layout Verse
19458 .globl _asm_func_PARM_2
19560 \begin_inset LatexCommand index
19561 name "DPTR, DPH, DPL"
19578 \begin_layout Standard
19579 The parameter naming convention is _<function_name>_PARM_<n>, where n is
19580 the parameter number starting from 1, and counting from the left.
19581 The first parameter is passed in
19597 according to the description above.
19598 The variable name for the second parameter will be _<function_name>_PARM_2.
19603 ble the assembler routine with the following command:
19610 asx8051 -losg asmfunc.asm
19617 Then compile and link the assembler routine to the C source file with the
19625 sdcc cfunc.c asmfunc.rel
19628 \begin_layout Subsection
19629 Assembler Routine (reentrant)
19632 \begin_layout Standard
19634 \begin_inset LatexCommand index
19640 \begin_inset LatexCommand index
19641 name "Assembler routines (reentrant)"
19645 the second parameter
19646 \begin_inset LatexCommand index
19647 name "function parameter"
19651 onwards will be passed on the stack, the parameters are pushed from right
19653 before the call the second leftmost parameter will be on the top of the
19654 stack (the leftmost parameter is passed in registers).
19655 Here is an example:
19658 \begin_layout Verse
19661 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
19666 c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
19675 return asm_func(i,j,k);
19689 return c_func(10,9,8);
19694 \begin_layout Standard
19695 The corresponding (unoptimized) assembler routine is:
19698 \begin_layout Verse
19718 _bp,sp\InsetSpace ~
19724 ;stack contains: _bp, return
19725 address, second parameter, third parameter
19749 a,#0xfd\InsetSpace ~
19755 pointer to the second parameter
19779 a,#0xfc\InsetSpace ~
19785 to the rightmost parameter
19826 result (= sum of all three parameters)
19841 ;return value goes into dptr
19875 \begin_layout Standard
19876 The compiling and linking procedure remains the same, however note the extra
19877 entry & exit linkage required for the assembler code, _bp is the stack
19878 frame pointer and is used to compute the offset into the stack for parameters
19879 and local variables.
19880 \begin_inset VSpace bigskip
19886 \begin_layout Section
19888 \begin_inset LatexCommand index
19889 name "int (16 bit)"
19894 \begin_inset LatexCommand index
19895 name "long (32 bit)"
19902 \begin_layout Standard
19903 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
19904 multiplication and modulus operations are implemented by support routines.
19905 These support routines are all developed in ANSI-C to facilitate porting
19906 to other MCUs, although some model specific assembler optimizations are
19908 The following files contain the described routines, all of them can be
19909 found in <installdir>/share/sdcc/lib.
19914 \begin_layout Standard
19916 \begin_inset Tabular
19917 <lyxtabular version="3" rows="11" columns="2">
19919 <column alignment="left" valignment="top" leftline="true" width="0">
19920 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19921 <row topline="true" bottomline="true">
19922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19925 \begin_layout Standard
19933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19936 \begin_layout Standard
19945 <row topline="true">
19946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19949 \begin_layout Standard
19955 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19958 \begin_layout Standard
19959 16 bit multiplication
19965 <row topline="true">
19966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19969 \begin_layout Standard
19975 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19978 \begin_layout Standard
19979 signed 16 bit division (calls _divuint)
19985 <row topline="true">
19986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19989 \begin_layout Standard
19995 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19998 \begin_layout Standard
19999 unsigned 16 bit division
20005 <row topline="true">
20006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20009 \begin_layout Standard
20015 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20018 \begin_layout Standard
20019 signed 16 bit modulus (calls _moduint)
20025 <row topline="true">
20026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20029 \begin_layout Standard
20035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20038 \begin_layout Standard
20039 unsigned 16 bit modulus
20045 <row topline="true">
20046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20049 \begin_layout Standard
20055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20058 \begin_layout Standard
20059 32 bit multiplication
20065 <row topline="true">
20066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20069 \begin_layout Standard
20075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20078 \begin_layout Standard
20079 signed 32 division (calls _divulong)
20085 <row topline="true">
20086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20089 \begin_layout Standard
20095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20098 \begin_layout Standard
20099 unsigned 32 division
20105 <row topline="true">
20106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20109 \begin_layout Standard
20115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20118 \begin_layout Standard
20119 signed 32 bit modulus (calls _modulong)
20125 <row topline="true" bottomline="true">
20126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20129 \begin_layout Standard
20135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20138 \begin_layout Standard
20139 unsigned 32 bit modulus
20154 \begin_layout Standard
20155 Since they are compiled as
20160 \begin_inset LatexCommand index
20166 \begin_inset LatexCommand index
20171 service routines should not do any of the above operations.
20172 If this is unavoidable then the above routines will need to be compiled
20179 \begin_layout Standard
20189 \begin_inset LatexCommand index
20190 name "-\\/-stack-auto"
20196 option, after which the source program will have to be compiled with
20202 \begin_layout Standard
20212 \begin_inset LatexCommand index
20213 name "-\\/-int-long-reent"
20220 Notice that you don't have to call these routines directly.
20221 The compiler will use them automatically every time an integer operation
20225 \begin_layout Section
20226 Floating Point Support
20227 \begin_inset LatexCommand index
20228 name "Floating point support"
20235 \begin_layout Standard
20236 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
20237 The floating point support routines are derived from gcc's floatlib.c and
20238 consist of the following routines:
20243 \begin_layout Standard
20247 \begin_inset Tabular
20248 <lyxtabular version="3" rows="17" columns="2">
20250 <column alignment="left" valignment="top" leftline="true" width="0">
20251 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
20252 <row topline="true" bottomline="true">
20253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20256 \begin_layout Standard
20271 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20274 \begin_layout Standard
20281 <row topline="true">
20282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20285 \begin_layout Standard
20300 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20303 \begin_layout Standard
20313 add floating point numbers
20319 <row topline="true">
20320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20323 \begin_layout Standard
20338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20341 \begin_layout Standard
20351 subtract floating point numbers
20357 <row topline="true">
20358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20361 \begin_layout Standard
20376 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20379 \begin_layout Standard
20389 divide floating point numbers
20395 <row topline="true">
20396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20399 \begin_layout Standard
20414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20417 \begin_layout Standard
20427 multiply floating point numbers
20433 <row topline="true">
20434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20437 \begin_layout Standard
20452 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20455 \begin_layout Standard
20465 convert floating point to unsigned char
20471 <row topline="true">
20472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20475 \begin_layout Standard
20490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20493 \begin_layout Standard
20503 convert floating point to signed char
20509 <row topline="true">
20510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20513 \begin_layout Standard
20528 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20531 \begin_layout Standard
20541 convert floating point to unsigned int
20547 <row topline="true">
20548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20551 \begin_layout Standard
20566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20569 \begin_layout Standard
20579 convert floating point to signed int
20585 <row topline="true">
20586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20589 \begin_layout Standard
20612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20615 \begin_layout Standard
20625 convert floating point to unsigned long
20631 <row topline="true">
20632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20635 \begin_layout Standard
20650 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20653 \begin_layout Standard
20663 convert floating point to signed long
20669 <row topline="true">
20670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20673 \begin_layout Standard
20688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20691 \begin_layout Standard
20701 convert unsigned char to floating point
20707 <row topline="true">
20708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20711 \begin_layout Standard
20726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20729 \begin_layout Standard
20739 convert char to floating point number
20745 <row topline="true">
20746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20749 \begin_layout Standard
20764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20767 \begin_layout Standard
20777 convert unsigned int to floating point
20783 <row topline="true">
20784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20787 \begin_layout Standard
20802 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20805 \begin_layout Standard
20815 convert int to floating point numbers
20821 <row topline="true">
20822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20825 \begin_layout Standard
20840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20843 \begin_layout Standard
20853 convert unsigned long to floating point number
20859 <row topline="true" bottomline="true">
20860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20863 \begin_layout Standard
20878 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20881 \begin_layout Standard
20891 convert long to floating point number
20906 \begin_layout Standard
20907 These support routines are developed in ANSI-C so there is room for space
20908 and speed improvement
20912 \begin_layout Standard
20913 These floating point routines (
20917 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
20924 Note if all these routines are used simultaneously the data space might
20926 For serious floating point usage the large model might be needed.
20927 Also notice that you don't have to call this routines directly.
20928 The compiler will use them automatically every time a floating point operation
20930 \begin_inset VSpace bigskip
20936 \begin_layout Section
20938 \begin_inset LatexCommand index
20946 \begin_layout Standard
20949 <pending: this is messy and incomplete - a little more information is in
20950 sdcc/doc/libdoc.txt
20955 \begin_layout Subsection
20956 Compiler support routines (_gptrget, _mulint etc.)
20959 \begin_layout Subsection
20960 Stdclib functions (puts, printf, strcat etc.)
20963 \begin_layout Subsubsection
20967 \begin_layout Paragraph
20968 getchar(), putchar()
20971 \begin_layout Standard
20972 \begin_inset LatexCommand index
20977 As usual on embedded systems you have to provide your own
20980 \begin_inset LatexCommand index
20990 \begin_inset LatexCommand index
20998 SDCC does not know whether the system connects to a serial line with or
20999 without handshake, LCD, keyboard or other device.
21013 You'll find examples for serial routines f.e.
21014 in sdcc/device/lib.
21015 For the mcs51 this minimalistic polling
21019 routine might be a start:
21022 \begin_layout Verse
21025 void putchar (char c) {
21031 while (!TI)\InsetSpace ~
21034 /* assumes UART is initialized */
21062 \begin_layout Paragraph
21066 \begin_layout Standard
21070 \begin_inset LatexCommand index
21081 does not support float
21082 \begin_inset LatexCommand index
21083 name "Floating point support"
21087 (except on ds390), only <NO FLOAT>
21088 \begin_inset LatexCommand index
21094 \begin_inset LatexCommand index
21095 name "printf floating point support"
21099 will be printed instead of the value.
21100 To enable floating point output, recompile it with the option
21106 \begin_layout Standard
21116 \begin_inset LatexCommand index
21117 name "USE\\_FLOATS"
21123 on the command line.
21130 \begin_layout Standard
21140 \begin_inset LatexCommand index
21141 name "-\\/-model-large"
21147 for the mcs51 port, since this uses a lot of memory.
21148 To enable float support for the pic16 targets, see
21149 \begin_inset LatexCommand ref
21150 reference "sub:pic16Libraries"
21157 \begin_layout Standard
21158 If you're short on code memory you might want to use
21161 \begin_inset LatexCommand index
21162 name "printf\\_small()"
21177 For the mcs51 there additionally are assembly versions
21180 \begin_inset LatexCommand index
21181 name "printf\\_tiny() (mcs51)"
21187 (subset of printf using less than 270 bytes) and
21190 \begin_inset LatexCommand index
21191 name "printf\\_fast() (mcs51)"
21200 \begin_inset LatexCommand index
21201 name "printf\\_fast\\_f() (mcs51)"
21207 (floating-point aware version of printf_fast) which should fit the requirements
21208 of many embedded systems (printf_fast() can be customized by unsetting
21213 support long variables and field widths).
21214 Be sure to use only one of these printf options within a project.
21219 \begin_layout Standard
21220 Feature matrix of different
21227 \begin_layout Standard
21228 \begin_inset Tabular
21229 <lyxtabular version="3" rows="14" columns="7">
21230 <features islongtable="true">
21231 <column alignment="left" valignment="middle" leftline="true" width="14col%">
21232 <column alignment="center" valignment="top" leftline="true" width="0">
21233 <column alignment="center" valignment="top" leftline="true" width="12col%">
21234 <column alignment="center" valignment="top" leftline="true" width="10col%">
21235 <column alignment="center" valignment="top" leftline="true" width="0">
21236 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
21237 <column alignment="center" valignment="top" rightline="true" width="0">
21238 <row topline="true" bottomline="true" endhead="true">
21239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21242 \begin_layout Standard
21251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21254 \begin_layout Standard
21256 \begin_inset LatexCommand index
21266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21269 \begin_layout Standard
21277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21280 \begin_layout Standard
21286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21289 \begin_layout Standard
21295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21298 \begin_layout Standard
21304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21307 \begin_layout Standard
21314 <row topline="true" endhead="true">
21315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21318 \begin_layout Standard
21324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21327 \begin_layout Standard
21335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21338 \begin_layout Standard
21346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21349 \begin_layout Standard
21357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21360 \begin_layout Standard
21368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21371 \begin_layout Standard
21379 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21382 \begin_layout Standard
21391 <row topline="true" endhead="true">
21392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21395 \begin_layout Standard
21396 \begin_inset Quotes sld
21400 \begin_inset Quotes srd
21406 \begin_layout Standard
21412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21415 \begin_layout Standard
21421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21424 \begin_layout Standard
21430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21433 \begin_layout Standard
21439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21442 \begin_layout Standard
21448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21451 \begin_layout Standard
21457 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21460 \begin_layout Standard
21467 <row topline="true" endhead="true">
21468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21471 \begin_layout Standard
21475 \begin_layout Standard
21481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21484 \begin_layout Standard
21490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21493 \begin_layout Standard
21499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21502 \begin_layout Standard
21503 0.45k / 0.47k (+ _ltoa)
21508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21511 \begin_layout Standard
21517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21520 \begin_layout Standard
21526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21529 \begin_layout Standard
21536 <row topline="true">
21537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21540 \begin_layout Standard
21546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21549 \begin_layout Standard
21559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21562 \begin_layout Standard
21609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21612 \begin_layout Standard
21651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21654 \begin_layout Standard
21660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21663 \begin_layout Standard
21669 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21672 \begin_layout Standard
21679 <row topline="true">
21680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21683 \begin_layout Standard
21684 long (32 bit) support
21689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21692 \begin_layout Standard
21698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21701 \begin_layout Standard
21707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21710 \begin_layout Standard
21716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21719 \begin_layout Standard
21725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21728 \begin_layout Standard
21743 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21746 \begin_layout Standard
21753 <row topline="true">
21754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21757 \begin_layout Standard
21758 byte arguments on stack
21763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21766 \begin_layout Standard
21772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21775 \begin_layout Standard
21781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21784 \begin_layout Standard
21790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21793 \begin_layout Standard
21799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21802 \begin_layout Standard
21808 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21811 \begin_layout Standard
21818 <row topline="true">
21819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21822 \begin_layout Standard
21824 \begin_inset LatexCommand index
21825 name "Floating point support"
21834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21837 \begin_layout Standard
21843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21846 \begin_layout Standard
21852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21855 \begin_layout Standard
21861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21864 \begin_layout Standard
21870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21873 \begin_layout Standard
21878 \begin_layout Standard
21879 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
21889 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21892 \begin_layout Standard
21899 <row topline="true">
21900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21903 \begin_layout Standard
21904 float formats %e %g
21909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21912 \begin_layout Standard
21918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21921 \begin_layout Standard
21927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21930 \begin_layout Standard
21936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21939 \begin_layout Standard
21945 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21948 \begin_layout Standard
21954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21957 \begin_layout Standard
21964 <row topline="true" bottomline="true">
21965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21968 \begin_layout Standard
21974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21977 \begin_layout Standard
21983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21986 \begin_layout Standard
21992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21995 \begin_layout Standard
22001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22004 \begin_layout Standard
22010 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22013 \begin_layout Standard
22019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22022 \begin_layout Standard
22029 <row bottomline="true">
22030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22033 \begin_layout Standard
22038 \begin_layout Standard
22039 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
22043 n'); standard 8051 @ 22.1184 MHz, empty putchar()
22051 \begin_layout Standard
22057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22060 \begin_layout Standard
22066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22069 \begin_layout Standard
22075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22078 \begin_layout Standard
22084 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22087 \begin_layout Standard
22093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22096 \begin_layout Standard
22102 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22105 \begin_layout Standard
22112 <row bottomline="true">
22113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22116 \begin_layout Standard
22121 \begin_layout Standard
22122 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
22131 \begin_layout Standard
22137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22140 \begin_layout Standard
22146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22149 \begin_layout Standard
22155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22158 \begin_layout Standard
22164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22167 \begin_layout Standard
22173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22176 \begin_layout Standard
22182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22185 \begin_layout Standard
22190 \begin_layout Standard
22191 printf_tiny integer speed is data dependent, worst case is 0.33 ms
22202 <row bottomline="true">
22203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22206 \begin_layout Standard
22211 \begin_layout Standard
22212 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
22221 \begin_layout Standard
22227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22230 \begin_layout Standard
22236 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22239 \begin_layout Standard
22245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22248 \begin_layout Standard
22254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22257 \begin_layout Standard
22263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22266 \begin_layout Standard
22272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22275 \begin_layout Standard
22282 <row bottomline="true">
22283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22286 \begin_layout Standard
22291 \begin_layout Standard
22292 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
22301 \begin_layout Standard
22307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22310 \begin_layout Standard
22316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22319 \begin_layout Standard
22325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22328 \begin_layout Standard
22334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22337 \begin_layout Standard
22343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22346 \begin_layout Standard
22352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22355 \begin_layout Standard
22369 \begin_layout Subsubsection
22371 \begin_inset LatexCommand index
22379 \begin_layout Standard
22380 As of SDCC 2.6.2 you no longer need to call an initialization routine before
22381 using dynamic memory allocation
22382 \begin_inset LatexCommand index
22383 name "dynamic memory allocation (malloc)"
22388 \begin_inset LatexCommand index
22389 name "heap (malloc)"
22393 space of 1024 bytes is provided for malloc to allocate memory from.
22394 If you need a different heap size you need to recompile _heap.c with the
22395 required size defined in HEAP_SIZE.
22396 It is recommended to make a copy of this file into your project directory
22397 and compile it there with:
22400 \begin_layout Verse
22403 sdcc -c _heap.c -D HEAD_SIZE=2048
22406 \begin_layout Standard
22407 And then link it with:
22410 \begin_layout Verse
22413 sdcc main.rel _heap.rel
22416 \begin_layout Subsection
22417 Math functions (sinf, powf, sqrtf etc.)
22420 \begin_layout Subsubsection
22424 \begin_layout Standard
22425 See definitions in file <math.h>.
22428 \begin_layout Subsection
22432 \begin_layout Standard
22434 \begin_inset LatexCommand index
22439 included in SDCC should have a license at least as liberal as the GNU Lesser
22440 General Public License
22441 \begin_inset LatexCommand index
22442 name "GNU Lesser General Public License, LGPL"
22453 \begin_layout Standard
22454 \begin_inset Note Note
22457 \begin_layout Standard
22458 license statements for the libraries are missing.
22459 sdcc/device/lib/ser_ir.c
22462 \begin_layout Standard
22464 come with a GPL (as opposed to LGPL) License - this will not be liberal
22465 enough for many embedded programmers.
22473 \begin_layout Standard
22474 If you have ported some library or want to share experience about some code
22476 falls into any of these categories Busses (I
22477 \begin_inset Formula $^{\textrm{2}}$
22480 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
22481 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
22482 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
22483 \begin_inset LatexCommand url
22484 target "http://sourceforge.net/mail/?group_id=599"
22489 would certainly like to hear about it.
22492 \begin_layout Standard
22493 Programmers coding for embedded systems are not especially famous for being
22494 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
22495 e these references are very valuable.
22496 Let's help to create a climate where information is shared.
22497 \begin_inset VSpace bigskip
22503 \begin_layout Section
22507 \begin_layout Subsection
22508 MCS51 Memory Models
22509 \begin_inset LatexCommand index
22510 name "Memory model"
22515 \begin_inset LatexCommand index
22516 name "MCS51 memory model"
22523 \begin_layout Subsubsection
22524 Small, Medium and Large
22527 \begin_layout Standard
22528 SDCC allows three memory models for MCS51 code,
22537 Modules compiled with different memory models should
22541 be combined together or the results would be unpredictable.
22542 The library routines supplied with the compiler are compiled as small,
22544 The compiled library modules are contained in separate directories as small,
22545 medium and large so that you can link to the appropriate set.
22548 \begin_layout Standard
22549 When the medium or large model is used all variables declared without a
22550 storage class will be allocated into the external ram, this includes all
22551 parameters and local variables (for non-reentrant
22552 \begin_inset LatexCommand index
22558 When the small model is used variables without storage class are allocated
22559 in the internal ram.
22562 \begin_layout Standard
22563 Judicious usage of the processor specific storage classes
22564 \begin_inset LatexCommand index
22565 name "Storage class"
22569 and the 'reentrant' function type will yield much more efficient code,
22570 than using the large model.
22571 Several optimizations are disabled when the program is compiled using the
22572 large model, it is therefore recommended that the small model be used unless
22573 absolutely required.
22576 \begin_layout Subsubsection
22578 \begin_inset LatexCommand label
22579 name "sub:External-Stack"
22584 \begin_inset LatexCommand index
22590 \begin_inset LatexCommand index
22591 name "External stack (mcs51)"
22598 \begin_layout Standard
22599 The external stack (-
22603 \begin_layout Standard
22613 \begin_inset LatexCommand index
22618 ) is located in pdata
22619 \begin_inset LatexCommand index
22620 name "pdata (mcs51, ds390 storage class)"
22624 memory (usually at the start of the external ram segment) and uses all
22625 unused space in pdata (max.
22631 \begin_layout Standard
22640 -xstack option is used to compile the program, the parameters and local
22642 \begin_inset LatexCommand index
22643 name "local variables"
22647 of all reentrant functions are allocated in this area.
22648 This option is provided for programs with large stack space requirements.
22649 When used with the -
22653 \begin_layout Standard
22663 \begin_inset LatexCommand index
22664 name "-\\/-stack-auto"
22668 option, all parameters and local variables are allocated on the external
22669 stack (note: support libraries will need to be recompiled with the same
22671 There is a predefined target in the library makefile).
22674 \begin_layout Standard
22675 The compiler outputs the higher order address byte of the external ram segment
22677 \begin_inset LatexCommand index
22678 name "P2 (mcs51 sfr)"
22683 \begin_inset LatexCommand ref
22684 reference "sub:MCS51-variants"
22688 ), therefore when using the External Stack option, this port
22692 be used by the application program.
22695 \begin_layout Subsection
22697 \begin_inset LatexCommand index
22698 name "Memory model"
22703 \begin_inset LatexCommand index
22704 name "DS390 memory model"
22711 \begin_layout Standard
22712 The only model supported is Flat 24
22713 \begin_inset LatexCommand index
22714 name "Flat 24 (DS390 memory model)"
22719 This generates code for the 24 bit contiguous addressing mode of the Dallas
22721 In this mode, up to four meg of external RAM or code space can be directly
22723 See the data sheets at www.dalsemi.com for further information on this part.
22728 that the compiler does not generate any code to place the processor into
22729 24 bitmode (although
22733 in the ds390 libraries will do that for you).
22739 \begin_inset LatexCommand index
22740 name "Tinibios (DS390)"
22744 , the boot loader or similar code must ensure that the processor is in 24
22745 bit contiguous addressing mode before calling the SDCC startup code.
22756 \begin_layout Standard
22767 option, variables will by default be placed into the XDATA segment.
22772 Segments may be placed anywhere in the 4 meg address space using the usual
22777 \begin_layout Standard
22787 Note that if any segments are located above 64K, the -r flag must be passed
22788 to the linker to generate the proper segment relocations, and the Intel
22789 HEX output format must be used.
22790 The -r flag can be passed to the linker by using the option
22794 on the SDCC command line.
22795 However, currently the linker can not handle code segments > 64k.
22798 \begin_layout Section
22800 \begin_inset LatexCommand label
22806 \begin_inset LatexCommand index
22814 \begin_layout Standard
22815 Pragmas are used to turn on and/or off certain compiler options.
22816 Some of them are closely related to corresponding command-line options
22818 \begin_inset LatexCommand vref
22819 reference "sec:Command-Line-Options"
22825 Pragmas should be placed before and/or after a function, placing pragmas
22826 inside a function body could have unpredictable results.
22831 following #pragma directives:
22834 \begin_layout Itemize
22840 \begin_inset LatexCommand index
22841 name "\\#pragma save"
22845 - this will save most current options to the save/restore stack.
22846 See #pragma\InsetSpace ~
22850 \begin_layout Itemize
22856 \begin_inset LatexCommand index
22857 name "\\#pragma restore"
22861 - will restore saved options from the last save.
22862 saves & restores can be nested.
22863 SDCC uses a save/restore stack: save pushes current options to the stack,
22864 restore pulls current options from the stack.
22865 See #pragma\InsetSpace ~
22871 \begin_layout Itemize
22877 \begin_inset LatexCommand index
22878 name "\\#pragma callee\\_saves"
22883 \begin_inset LatexCommand index
22884 name "function prologue"
22888 function1[,function2[,function3...]]
22889 \begin_inset LatexCommand label
22890 name "ite:callee_saves-function1[,function2[,function3...]]--"
22894 - The compiler by default uses a caller saves convention for register saving
22895 across function calls, however this can cause unnecessary register pushing
22897 \begin_inset LatexCommand index
22902 when calling small functions from larger functions.
22903 This option can be used to switch off the register saving convention for
22904 the function names specified.
22905 The compiler will not save registers when calling these functions, extra
22906 code need to be manually inserted at the entry and exit for these functions
22907 to save and restore the registers used by these functions, this can SUBSTANTIAL
22908 LY reduce code and improve run time performance of the generated code.
22909 In the future the compiler (with inter procedural analysis) may be able
22910 to determine the appropriate scheme to use for each function call.
22915 \begin_layout Standard
22924 -callee-saves command line option is used (see page
22925 \begin_inset LatexCommand vpageref
22926 reference "lyx:--callee-saves-function1[,function2][,function3]..."
22930 ), the function names specified in #pragma\InsetSpace ~
22932 \begin_inset LatexCommand index
22933 name "\\#pragma callee\\_saves"
22937 is appended to the list of functions specified in the command line.
22940 \begin_layout Itemize
22946 \begin_inset LatexCommand index
22947 name "\\#pragma exclude"
22951 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
22952 of pairs of push/pop
22953 \begin_inset LatexCommand index
22963 \begin_inset LatexCommand index
22977 The directive should be placed immediately before the ISR function definition
22978 and it affects ALL ISR functions following it.
22979 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
22980 exclude\InsetSpace ~
22982 \begin_inset LatexCommand index
22983 name "\\#pragma exclude"
22988 See also the related keyword _naked
22989 \begin_inset LatexCommand index
22995 \begin_inset LatexCommand index
23003 \begin_layout Itemize
23009 \begin_inset LatexCommand index
23015 \begin_inset LatexCommand index
23016 name "\\#pragma less\\_pedantic"
23021 \begin_inset LatexCommand label
23022 name "ite:less_pedantic"
23026 - the compiler will not warn you anymore for obvious mistakes, you're on
23028 See also the command line option -
23032 \begin_layout Standard
23042 \begin_inset LatexCommand vpageref
23043 reference "lyx:--less-pedantic"
23050 More specifically, the following warnings will be disabled:
23052 comparison is always [true/false] due to limited range of data type
23056 overflow in implicit constant conversion
23058 (158); [the (in)famous]
23060 conditional flow changed by optimizer: so said EVELYN the modified DOG
23064 function '[function name]' must return value
23069 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
23070 level) are disabled, too, namely:
23073 \begin_inset Note Note
23076 \begin_layout Standard
23077 dunno what comes here - this warning appears to be unused altogether
23086 [left/right] shifting more than size of object changed to zero
23094 integer overflow in expression
23098 unmatched #pragma save and #pragma restore
23102 comparison of 'signed char' with 'unsigned char' requires promotion to int
23106 ISO C90 does not support flexible array members
23110 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
23114 \begin_inset Note Note
23117 \begin_layout Standard
23118 appears to be always blank - what was supposed to be here?
23127 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
23128 complexity [number]
23133 \begin_layout Itemize
23139 \begin_inset LatexCommand index
23140 name "\\#pragma disable\\_warning"
23144 - the compiler will not warn you anymore about warning number <nnnn>.
23147 \begin_layout Itemize
23153 \begin_inset LatexCommand index
23154 name "\\#pragma nogcse"
23158 - will stop global common subexpression elimination.
23161 \begin_layout Itemize
23167 \begin_inset LatexCommand index
23168 name "\\#pragma noinduction"
23172 - will stop loop induction optimizations.
23175 \begin_layout Itemize
23181 \begin_inset LatexCommand index
23182 name "\\#pragma noinvariant"
23186 - will not do loop invariant optimizations.
23187 For more details see Loop Invariants in section
23188 \begin_inset LatexCommand ref
23189 reference "sub:Loop-Optimizations"
23196 \begin_layout Itemize
23202 \begin_inset LatexCommand index
23203 name "\\#pragma noiv"
23207 - Do not generate interrupt
23208 \begin_inset LatexCommand index
23214 \begin_inset LatexCommand index
23215 name "interrupt vector table"
23219 entries for all ISR functions defined after the pragma.
23220 This is useful in cases where the interrupt vector table must be defined
23221 manually, or when there is a secondary, manually defined interrupt vector
23223 for the autovector feature of the Cypress EZ-USB FX2).
23224 More elegantly this can be achieved by omitting the optional interrupt
23225 number after the interrupt keyword, see section
23226 \begin_inset LatexCommand ref
23227 reference "sub:Interrupt-Service-Routines"
23235 \begin_layout Itemize
23241 \begin_inset LatexCommand index
23242 name "\\#pragma nojtbound"
23246 - will not generate code for boundary value checking, when switch statements
23247 are turned into jump-tables (dangerous).
23248 For more details see section
23249 \begin_inset LatexCommand ref
23250 reference "sub:'switch'-Statements"
23257 \begin_layout Itemize
23263 \begin_inset LatexCommand index
23264 name "\\#pragma noloopreverse"
23268 - Will not do loop reversal optimization
23271 \begin_layout Itemize
23277 \begin_inset LatexCommand index
23278 name "\\#pragma nooverlay"
23282 - the compiler will not overlay the parameters and local variables of a
23286 \begin_layout Itemize
23292 \begin_inset LatexCommand index
23293 name "\\#pragma stackauto"
23301 \begin_layout Standard
23311 \begin_inset LatexCommand index
23312 name "-\\/-stack-auto"
23317 \begin_inset LatexCommand ref
23318 reference "sec:Parameters-and-Local-Variables"
23322 Parameters and Local Variables.
23325 \begin_layout Itemize
23331 \begin_inset LatexCommand index
23332 name "\\#pragma opt\\_code\\_speed"
23336 - The compiler will optimize code generation towards fast code, possibly
23337 at the expense of code size.
23338 Currently this has little effect.
23341 \begin_layout Itemize
23347 \begin_inset LatexCommand index
23348 name "\\#pragma opt\\_code\\_size"
23352 - The compiler will optimize code generation towards compact code, possibly
23353 at the expense of code speed.
23354 Currently this has little effect.
23357 \begin_layout Itemize
23363 \begin_inset LatexCommand index
23364 name "\\#pragma opt\\_code\\_balanced"
23368 - The compiler will attempt to generate code that is both compact and fast,
23369 as long as meeting one goal is not a detriment to the other (this is the
23374 \begin_layout Itemize
23380 \begin_inset LatexCommand index
23381 name "\\#pragma std\\_sdcc89"
23385 - Generally follow the C89 standard, but allow SDCC features that conflict
23386 with the standard (default).
23389 \begin_layout Itemize
23395 \begin_inset LatexCommand index
23396 name "\\#pragma std\\_c89"
23400 - Follow the C89 standard and disable SDCC features that conflict with the
23404 \begin_layout Itemize
23410 \begin_inset LatexCommand index
23411 name "\\#pragma std\\_sdcc99"
23415 - Generally follow the C99 standard, but allow SDCC features that conflict
23416 with the standard (incomplete support).
23419 \begin_layout Itemize
23425 \begin_inset LatexCommand index
23426 name "\\#pragma std\\_c99"
23430 - Follow the C99 standard and disable SDCC features that conflict with the
23431 standard (incomplete support).
23434 \begin_layout Itemize
23440 \begin_inset LatexCommand index
23441 name "\\#pragma codeseg"
23445 - Use this name (max.
23446 8 characters) for the code segment.
23451 \begin_layout Standard
23463 \begin_layout Itemize
23469 \begin_inset LatexCommand index
23470 name "\\#pragma constseg"
23474 - Use this name (max.
23475 8 characters) for the const segment.
23480 \begin_layout Standard
23492 \begin_layout Standard
23493 The preprocessor SDCPP
23494 \begin_inset LatexCommand index
23495 name "sdcpp (preprocessor)"
23499 supports the following #pragma directives:
23502 \begin_layout Itemize
23505 pedantic_parse_number
23508 \begin_inset LatexCommand index
23514 \begin_inset LatexCommand index
23515 name "\\#pragma pedantic\\_parse\\_number"
23520 \begin_inset LatexCommand label
23521 name "ite:pedantic_parse_number"
23525 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
23526 properly and the macro LO_B(3) gets expanded.
23532 \begin_layout Standard
23541 -pedantic-parse-number command line option
23542 \begin_inset LatexCommand vpageref
23543 reference "lyx:-pedantic-parse-number"
23550 Below is an example on how to use this pragma.
23553 Note: this functionality is not in conformance with standard!
23556 \begin_layout Verse
23559 #pragma pedantic_parse_number +
23560 \begin_inset LatexCommand index
23561 name "\\#pragma pedantic\\_parse\\_number"
23569 #define LO_B(x) ((x) & 0xff)
23573 unsigned char foo(void)
23580 unsigned char c=0xfe-LO_B(3)
23595 \begin_layout Itemize
23601 \begin_inset LatexCommand index
23602 name "\\#pragma preproc\\_asm"
23606 (+ | -) - switch _asm _endasm block preprocessing on / off.
23608 You use this pragma to define multilines of assembly code.
23609 This will prevent the preprocessor from changing the formatting required
23611 Below is an example on how to use this pragma.
23614 \begin_layout Verse
23617 #pragma preproc_asm -
23618 \begin_inset LatexCommand index
23619 name "\\#pragma preproc\\_asm"
23625 #define MYDELAY _asm
23630 nop ;my assembly comment...
23644 #pragma preproc_asm
23675 \begin_layout Itemize
23681 \begin_inset LatexCommand index
23682 name "\\#pragma sdcc\\_hash"
23686 (+ | -) - Allow "naked" hash in macro definition, for example:
23690 #define DIR_LO(x) #(x & 0xff)
23695 Below is an example on how to use this pragma.
23698 \begin_layout Verse
23701 #pragma preproc_asm +
23703 #pragma sdcc_hash +
23704 \begin_inset LatexCommand index
23705 name "\\#pragma sdcc\\_hash"
23720 mov R6_B3, #(x & 0xff)
23727 mov R7_B3, #((x >> 8) & 0xff)
23751 \begin_layout Standard
23752 Some of the pragmas are intended to be used to turn-on or off certain optimizati
23753 ons which might cause the compiler to generate extra stack and/or data space
23754 to store compiler generated temporary variables.
23755 This usually happens in large functions.
23756 Pragma directives should be used as shown in the following example, they
23757 are used to control options and optimizations for a given function.
23761 \begin_layout Verse
23765 \begin_inset LatexCommand index
23766 name "\\#pragma save"
23777 /* save the current settings */
23780 \begin_inset LatexCommand index
23781 name "\\#pragma nogcse"
23790 /* turnoff global subexpression elimination */
23792 #pragma noinduction
23793 \begin_inset LatexCommand index
23794 name "\\#pragma noinduction"
23798 /* turn off induction optimizations */
23821 \begin_inset LatexCommand index
23822 name "\\#pragma restore"
23826 /* turn the optimizations back on */
23829 \begin_layout Standard
23830 The compiler will generate a warning message when extra space is allocated.
23831 It is strongly recommended that the save and restore pragmas be used when
23832 changing options for a function.
23841 \begin_layout Section
23842 Defines Created by the Compiler
23845 \begin_layout Standard
23846 The compiler creates the following #defines
23847 \begin_inset LatexCommand index
23853 \begin_inset LatexCommand index
23854 name "Defines created by the compiler"
23863 \begin_layout Standard
23864 \begin_inset Tabular
23865 <lyxtabular version="3" rows="15" columns="2">
23867 <column alignment="left" valignment="top" leftline="true" width="3in">
23868 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
23869 <row topline="true" bottomline="true">
23870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23873 \begin_layout Standard
23881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23884 \begin_layout Standard
23893 <row topline="true">
23894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23897 \begin_layout Standard
23899 \begin_inset LatexCommand index
23909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23912 \begin_layout Standard
23914 Since version 2.5.6 the version number as an int (ex.
23921 <row topline="true">
23922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23925 \begin_layout Standard
23927 \begin_inset LatexCommand index
23928 name "SDCC\\_mcs51"
23933 \begin_inset LatexCommand index
23934 name "SDCC\\_ds390"
23939 \begin_inset LatexCommand index
23949 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23952 \begin_layout Standard
23953 depending on the model used (e.g.: -mds390)
23959 <row topline="true">
23960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23963 \begin_layout Standard
23965 \begin_inset LatexCommand index
23971 \begin_inset LatexCommand index
23977 \begin_inset LatexCommand index
23983 \begin_inset LatexCommand index
23993 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23996 \begin_layout Standard
23997 depending on the model used (e.g.
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
24011 name "SDCC\\_STACK\\_AUTO"
24020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24023 \begin_layout Standard
24030 \begin_layout Standard
24047 <row topline="true">
24048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24051 \begin_layout Standard
24053 \begin_inset LatexCommand index
24054 name "SDCC\\_MODEL\\_SMALL"
24063 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24066 \begin_layout Standard
24073 \begin_layout Standard
24090 <row topline="true">
24091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24094 \begin_layout Standard
24096 \begin_inset LatexCommand index
24097 name "SDCC\\_MODEL\\_MEDIUM"
24106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24109 \begin_layout Standard
24116 \begin_layout Standard
24133 <row topline="true">
24134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24137 \begin_layout Standard
24139 \begin_inset LatexCommand index
24140 name "SDCC\\_MODEL\\_LARGE"
24149 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24152 \begin_layout Standard
24159 \begin_layout Standard
24176 <row topline="true">
24177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24180 \begin_layout Standard
24182 \begin_inset LatexCommand index
24183 name "SDCC\\_USE\\_XSTACK"
24192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24195 \begin_layout Standard
24202 \begin_layout Standard
24219 <row topline="true">
24220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24223 \begin_layout Standard
24225 \begin_inset LatexCommand index
24226 name "SDCC\\_STACK\\_TENBIT"
24235 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24238 \begin_layout Standard
24249 <row topline="true">
24250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24253 \begin_layout Standard
24255 \begin_inset LatexCommand index
24256 name "SDCC\\_MODEL\\_FLAT24"
24265 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24268 \begin_layout Standard
24279 <row topline="true">
24280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24283 \begin_layout Standard
24285 \begin_inset LatexCommand index
24286 name "SDCC\\_REVISION"
24295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24298 \begin_layout Standard
24300 SDCC svn revision number
24306 <row topline="true">
24307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24310 \begin_layout Standard
24311 SDCC_PARMS_IN_BANK1
24312 \begin_inset LatexCommand index
24313 name "SDCC\\_PARMS\\_IN\\_BANK1"
24322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24325 \begin_layout Standard
24332 \begin_layout Standard
24349 <row topline="true">
24350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24353 \begin_layout Standard
24355 \begin_inset LatexCommand index
24356 name "SDCC\\_MODEL\\_FLAT24"
24365 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24368 \begin_layout Standard
24375 \begin_layout Standard
24392 <row topline="true" bottomline="true">
24393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24396 \begin_layout Standard
24397 SDCC_INT_LONG_REENT
24398 \begin_inset LatexCommand index
24399 name "SDCC\\_INT\\_LONG\\_REENT"
24408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24411 \begin_layout Standard
24418 \begin_layout Standard
24442 \begin_layout Chapter
24443 Notes on supported Processors
24446 \begin_layout Section
24448 \begin_inset LatexCommand label
24449 name "sub:MCS51-variants"
24454 \begin_inset LatexCommand index
24455 name "MCS51 variants"
24462 \begin_layout Standard
24463 MCS51 processors are available from many vendors and come in many different
24465 While they might differ considerably in respect to Special Function Registers
24466 the core MCS51 is usually not modified or is kept compatible.
24470 \begin_layout Subsection
24471 pdata access by SFR
24474 \begin_layout Standard
24475 With the upcome of devices with internal xdata and flash memory devices
24477 \begin_inset LatexCommand index
24478 name "P2 (mcs51 sfr)"
24482 as dedicated I/O port is becoming more popular.
24483 Switching the high byte for pdata
24484 \begin_inset LatexCommand index
24485 name "pdata (mcs51, ds390 storage class)"
24489 access which was formerly done by port P2 is then achieved by a Special
24491 \begin_inset LatexCommand index
24497 In well-established MCS51 tradition the address of this
24501 is where the chip designers decided to put it.
24502 Needless to say that they didn't agree on a common name either.
24503 So that the startup code can correctly initialize xdata variables, you
24504 should define an sfr with the name _XPAGE
24507 \begin_inset LatexCommand index
24508 name "\\_XPAGE (mcs51)"
24514 at the appropriate location if the default, port P2, is not used for this.
24518 \begin_layout Verse
24521 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
24525 \begin_layout Verse
24528 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
24533 \begin_layout Verse
24536 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
24540 \begin_layout Verse
24543 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
24547 \begin_layout Verse
24550 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
24554 \begin_layout Standard
24555 For more exotic implementations further customizations may be needed.
24557 \begin_inset LatexCommand ref
24558 reference "sub:Startup-Code"
24562 for other possibilities.
24565 \begin_layout Subsection
24566 Other Features available by SFR
24569 \begin_layout Standard
24570 Some MCS51 variants offer features like Double DPTR
24571 \begin_inset LatexCommand index
24576 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
24577 These are currently not used for the MCS51 port.
24578 If you absolutely need them you can fall back to inline assembly or submit
24582 \begin_layout Subsection
24586 \begin_layout Standard
24588 \begin_inset LatexCommand index
24589 name "Bankswitching"
24595 \begin_inset LatexCommand index
24596 name "code banking"
24600 ) is a technique to increase the code space above the 64k limit of the 8051.
24603 \begin_layout Subsubsection
24607 \begin_layout Standard
24608 \begin_inset Tabular
24609 <lyxtabular version="3" rows="3" columns="4">
24611 <column alignment="center" valignment="top" width="0">
24612 <column alignment="center" valignment="top" leftline="true" width="0">
24613 <column alignment="center" valignment="top" leftline="true" width="0">
24614 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24615 <row topline="true" bottomline="true">
24616 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24619 \begin_layout Standard
24625 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24628 \begin_layout Standard
24634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24637 \begin_layout Standard
24643 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24646 \begin_layout Standard
24653 <row topline="true" bottomline="true">
24654 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24657 \begin_layout Standard
24663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24666 \begin_layout Standard
24672 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24675 \begin_layout Standard
24681 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24684 \begin_layout Standard
24692 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24695 \begin_layout Standard
24696 SiLabs C8051F120 example
24701 <cell multicolumn="2" alignment="center" valignment="top" usebox="none">
24704 \begin_layout Standard
24710 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24713 \begin_layout Standard
24719 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24722 \begin_layout Standard
24737 Usually the hardware uses some sfr (an output port or an internal sfr) to
24738 select a bank and put it in the banked area of the memory map.
24739 The selected bank usually becomes active immediately upon assignment to
24740 this sfr and when running inside a bank it will switch out this code it
24741 is currently running.
24742 Therefor you cannot jump or call directly from one bank to another and
24743 need to use a so-called trampoline in the common area.
24744 For SDCC an example trampoline is in crtbank.asm and you may need to change
24745 it to your 8051 derivative or schematic.
24746 The presented code is written for the C8051F120.
24750 When calling a banked function
24751 SDCC will put the LSB of the functions address in register R0, the MSB
24752 in R1 and the bank in R2 and then call this trampoline
24757 The current selected bank is saved on the stack, the new bank is selected
24758 and an indirect jump is made.
24759 When the banked function returns it jumps to
24763 which restores the previous bank and returns to the caller.
24766 \begin_layout Subsubsection
24770 \begin_layout Standard
24771 When writing banked software using SDCC you need to use some special keywords
24773 You also need to take over a bit of work from the linker.
24777 To create a function
24778 that can be called from another bank it requires the keyword
24783 \begin_inset LatexCommand index
24789 The caller must see this in the prototype of the callee and the callee
24790 needs it for a proper return.
24791 Called functions within the same bank as the caller do not need the
24795 keyword nor do functions in the common area.
24796 Beware: SDCC does not know or check if functions are in the same bank.
24797 This is your responsibility!
24801 Normally all functions you write end up in
24803 If you want a function explicitly to reside in the common area put it in
24805 This applies for instance to interrupt service routines as they should
24809 \begin_layout Standard
24810 Functions that need to be in a switched bank must be put in a named segment.
24811 The name can be mostly anything up to eight characters (e.g.
24813 To do this you either use -
24817 \begin_layout Standard
24826 -codeseg BANK1 (See
24827 \begin_inset LatexCommand ref
24828 reference "lyx:-codeseg"
24832 ) on the command line when compiling or #pragma codeseg BANK1 (See
24833 \begin_inset LatexCommand ref
24834 reference "sec:Pragmas"
24838 ) at the top of the C source file.
24839 The segment name always applies to the whole source file and generated
24840 object so functions for different banks need to be defined in different
24845 When linking your objects you need to tell the linker where
24846 to put your segments.
24847 To do this you use the following command line option to SDCC: -Wl-b BANK1=0x180
24849 \begin_inset LatexCommand ref
24850 reference "lyx:-Wl option"
24855 This sets the virtual start address of this segment.
24856 It sets the banknumber to 0x01 and maps the bank to 0x8000 and up.
24857 The linker will not check for overflows, again this is your responsibility.
24860 \begin_layout Standard
24861 \begin_inset VSpace bigskip
24867 \begin_layout Section
24871 \begin_layout Standard
24873 \begin_inset LatexCommand index
24879 \begin_inset LatexCommand index
24884 microcontroller has a rich set of peripherals.
24885 In its built-in ROM library it includes functions to access some of the
24886 features, among them is a TCP stack with IP4 and IP6 support.
24887 Library headers (currently in beta status) and other files are provided
24891 \begin_inset LatexCommand url
24892 target "ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html"
24898 \begin_inset VSpace bigskip
24904 \begin_layout Section
24905 The Z80 and gbz80 port
24908 \begin_layout Standard
24909 SDCC can target both the Zilog Z80
24910 \begin_inset LatexCommand index
24915 and the Nintendo Gameboy's Z80-like gbz80
24916 \begin_inset LatexCommand index
24917 name "gbz80 (GameBoy Z80)"
24922 The Z80 port is passed through the same
24925 \begin_inset LatexCommand index
24926 name "Regression test"
24933 \begin_inset LatexCommand ref
24934 reference "sec:Quality-control"
24938 ) as the MCS51 and DS390 ports, so floating point support, support for long
24939 variables and bitfield support is fine.
24940 See mailing lists and forums about interrupt routines.
24943 \begin_layout Standard
24944 As always, the code is the authoritative reference - see z80/ralloc.c and
24947 \begin_inset LatexCommand index
24952 frame is similar to that generated by the IAR Z80 compiler.
24953 IX is used as the base pointer, HL and IY are used as a temporary registers,
24954 and BC and DE are available for holding variables.
24956 \begin_inset LatexCommand index
24957 name "Z80!return value"
24961 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
24963 The gbz80 port use the same set of registers for the return values, but
24964 in a different order of significance: E (one byte), DE (two bytes), or
24966 \begin_inset VSpace bigskip
24972 \begin_layout Section
24976 \begin_layout Standard
24977 The port to the Freescale/Motorola HC08
24978 \begin_inset LatexCommand index
24983 family has been added in October 2003, and is still undergoing some basic
24985 The code generator is complete, but the register allocation is still quite
24987 Some of the SDCC's standard C library functions have embedded non-HC08
24988 inline assembly and so are not yet usable.
24991 \begin_layout Standard
24992 The HC08 port passes the regression test suite (see section
24993 \begin_inset LatexCommand ref
24994 reference "sec:Quality-control"
24999 \begin_inset VSpace bigskip
25005 \begin_layout Section
25007 \begin_inset LatexCommand index
25015 \begin_layout Standard
25016 The PIC14 port adds support for Microchip
25017 \begin_inset LatexCommand index
25023 \begin_inset Formula $^{\text{TM}}$
25027 \begin_inset LatexCommand index
25033 \begin_inset Formula $^{\text{TM}}$
25036 MCUs with 14 bit wide instructions.
25037 This port is not yet mature and still lacks many features.
25038 However, it can work for simple code.
25041 \begin_layout Standard
25043 Currently supported devices include:
25046 \begin_layout Standard
25047 12F: 629, 635, 675, 683
25050 \begin_layout Standard
25054 \begin_layout Standard
25058 \begin_layout Standard
25059 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
25062 \begin_layout Standard
25063 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
25067 \begin_layout Standard
25071 \begin_layout Standard
25072 16CR: 620a, 73, 74, 76, 77
25075 \begin_layout Standard
25076 16F: 616, 627, 627a, 628, 628a, 630, 636, 639, 648, 648a, 676, 684, 685,
25080 \begin_layout Standard
25081 16F: 716, 72, 73, 737, 74, 747, 76, 767, 77, 777, 785
25084 \begin_layout Standard
25085 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
25086 877, 877a, 88, 886, 887
25089 \begin_layout Standard
25090 16F: 913, 914, 916, 917, 946
25093 \begin_layout Standard
25097 \begin_layout Standard
25099 An up-to-date list of currently supported devices can be obtained via
25101 sdcc -mpic14 -phelp foo.c
25103 (foo.c must exist...).
25106 \begin_layout Subsection
25108 \begin_inset LatexCommand index
25109 name "code page (pic14)"
25114 \begin_inset LatexCommand index
25115 name "Memory bank (pic14)"
25122 \begin_layout Standard
25123 The linker organizes allocation for the code page and RAM banks.
25124 It does not have intimate knowledge of the code flow.
25125 It will put all the code section of a single .asm file into a single code
25127 In order to make use of multiple code pages, separate asm files must be
25129 The compiler assigns all
25133 functions of a single .c file into the same code page.
25137 To get the best results,
25138 follow these guidelines:
25141 \begin_layout Enumerate
25142 Make local functions static, as non static functions require code page selection
25145 Due to the way sdcc handles functions, place called functions prior
25146 to calling functions in the file wherever possible: Otherwise sdcc will
25147 insert unnecessary pagesel directives around the call, believing that the
25148 called function is externally defined.
25151 \begin_layout Enumerate
25152 For devices that have multiple code pages it is more efficient to use the
25153 same number of files as pages: Use up to 4 separate .c files for the 16F877,
25154 but only 2 files for the 16F874.
25155 This way the linker can put the code for each file into different code
25156 pages and there will be less page selection overhead.
25159 \begin_layout Enumerate
25160 And as for any 8 bit micro (especially for PIC14 as they have a very simple
25161 instruction set), use `unsigned char' wherever possible instead of `int'.
25164 \begin_layout Subsection
25165 Adding New Devices to the Port
25168 \begin_layout Standard
25169 Adding support for a new 14
25173 \begin_layout Standard
25182 bit PIC MCU requires the following steps:
25185 \begin_layout Enumerate
25186 Create a new device description.
25188 Each device is described in two files: pic16f*.h
25190 These files primarily define SFRs, structs to access their bits, and symbolic
25191 configuration options.
25192 Both files can be generated from gputils' .inc files using the perl script
25195 support/scripts/inc2h.pl
25198 This file also contains further instructions on how to proceed.
25201 \begin_layout Enumerate
25202 Copy the .h file into SDCC's include path and either add the .c file to your
25203 project or copy it to
25205 device/lib/pic/libdev
25208 Afterwards, rebuild and install the libraries.
25211 \begin_layout Enumerate
25212 Edit pic14devices.txt in SDCC's include path (
25214 device/include/pic/
25216 in the source tree or
25218 /usr/local/share/sdcc/include/pic
25220 after installation).
25222 You need to add a device specification here to make
25223 the memory layout (code banks, RAM, aliased memory regions, ...) known to
25225 Probably you can copy and modify an existing entry.
25226 The file format is documented at the top of the file.
25229 \begin_layout Subsection
25233 \begin_layout Standard
25234 For the interrupt function, use the keyword `__interrupt'
25235 \begin_inset LatexCommand index
25236 name "PIC14!interrupt"
25240 with level number of 0 (PIC14 only has 1 interrupt so this number is only
25241 there to avoid a syntax error - it ought to be fixed).
25245 \begin_layout Verse
25248 void Intr(void) __interrupt 0
25254 T0IF = 0; /* Clear timer interrupt */
25259 \begin_layout Subsection
25260 Linking and Assembling
25263 \begin_layout Standard
25264 For assembling you can use either GPUTILS'
25265 \begin_inset LatexCommand index
25266 name "gputils (pic tools)"
25270 gpasm.exe or MPLAB's mpasmwin.exe.
25271 GPUTILS are available from
25272 \begin_inset LatexCommand url
25273 target "http://sourceforge.net/projects/gputils"
25278 For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
25279 If you use MPLAB and an interrupt function then the linker script file
25280 vectors section will need to be enlarged to link with mplink.
25291 \begin_layout Verse
25304 sdcc -V -mpic14 -p16f877 -c $<
25308 $(PRJ).hex: $(OBJS)
25318 gplink -m -s $(PRJ).lkr
25319 -o $(PRJ).hex $(OBJS) libsdcc.lib
25322 \begin_layout Standard
25330 \begin_layout Verse
25343 sdcc -S -V -mpic14 -p16f877 $<
25353 mpasmwin /q /o $*.asm
25357 $(PRJ).hex: $(OBJS)
25368 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
25371 \begin_layout Standard
25372 Please note that indentations within a
25376 have to be done with a tabulator character.
25379 \begin_layout Subsection
25380 Command-Line Options
25383 \begin_layout Standard
25384 Besides the switches common to all SDCC backends, the PIC14 port accepts
25385 the following options (for an updated list see sdcc -
25389 \begin_layout Standard
25401 \begin_layout Description
25406 \begin_layout Standard
25416 \begin_inset LatexCommand index
25417 name "PIC14!Options!-\\/-debug-extra"
25421 emit debug info in assembly output
25424 \begin_layout Description
25429 \begin_layout Standard
25439 \begin_inset LatexCommand index
25440 name "PIC14!Options!-\\/-no-pcode-opt"
25444 disable (slightly faulty) optimization on pCode
25447 \begin_layout Description
25452 \begin_layout Standard
25462 \begin_inset LatexCommand index
25463 name "PIC14!Options!-\\/-stack-loc"
25467 sets the lowest address of the argument passing stack (defaults to a suitably
25468 large shared databank to reduce BANKSEL overhead)
25471 \begin_layout Description
25476 \begin_layout Standard
25486 \begin_inset LatexCommand index
25487 name "PIC14!Options!-\\/-stack-size"
25491 sets the size if the argument passing stack (default: 16, minimum: 4)
25494 \begin_layout Subsection
25495 Environment Variables
25498 \begin_layout Standard
25499 The PIC14 port recognizes the following environment variables:
25502 \begin_layout Description
25503 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
25504 register (the ones called r0xNNNN) in a section of its own.
25505 By default (if this variable is unset), sdcc tries to cluster registers
25506 in sections in order to reduce the BANKSEL overhead when accessing them.
25509 \begin_layout Subsection
25513 \begin_layout Standard
25514 The PIC14 library currently only contains support routines required by the
25515 compiler to implement multiplication, division, and floating point support.
25516 No libc-like replacement is available at the moment, though many of the
25517 common sdcc library sources (in
25521 ) should also compile with the PIC14 port.
25524 \begin_layout Subsubsection
25525 error: missing definition for symbol ``__gptrget1''
25528 \begin_layout Standard
25529 The PIC14 port uses library routines to provide more complex operations
25530 like multiplication, division/modulus and (generic) pointer dereferencing.
25531 In order to add these routines to your project, you must link with PIC14's
25537 For single source file projects this is done automatically, more complex
25542 to the linker's arguments.
25543 Make sure you also add an include path for the library (using the -I switch
25547 \begin_layout Subsubsection
25548 Processor mismatch in file ``XXX''.
25551 \begin_layout Standard
25552 This warning can usually be ignored due to the very good compatibility amongst
25557 \begin_layout Standard
25567 \begin_inset LatexCommand index
25575 \begin_layout Standard
25576 You might also consider recompiling the library for your specific device
25577 by changing the ARCH=p16f877 (default target) entry in
25579 device/lib/pic/Makefile.in
25583 device/lib/pic/Makefile
25585 to reflect your device.
25586 This might even improve performance for smaller devices as unnecessary
25587 BANKSELs might be removed.
25590 \begin_layout Subsection
25594 \begin_layout Subsubsection
25598 \begin_layout Standard
25599 Functions with variable argument lists (like printf) are not yet supported.
25600 Similarly, taking the address of the first argument passed into a function
25601 does not work: It is currently passed in WREG and has no address...
25604 \begin_layout Subsubsection
25605 Regression tests fail
25608 \begin_layout Standard
25609 Though the small subset of regression tests in src/regression passes, SDCC
25610 regression test suite does not, indicating that there are still major bugs
25612 However, many smaller projects have successfully used SDCC in the past...
25615 \begin_layout Standard
25623 \begin_layout Section
25625 \begin_inset LatexCommand index
25633 \begin_layout Standard
25634 The PIC16 port adds support for Microchip
25635 \begin_inset LatexCommand index
25641 \begin_inset Formula $^{\text{TM}}$
25645 \begin_inset LatexCommand index
25651 \begin_inset Formula $^{\text{TM}}$
25654 MCUs with 16 bit wide instructions.
25655 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
25656 ; devices supported by the port include:
25659 \begin_layout Standard
25660 18F: 242, 248, 252, 258, 442, 448, 452, 458
25663 \begin_layout Standard
25667 \begin_layout Standard
25668 18F: 2220, 2221, 2320, 2321, 2331, 2410, 2420, 2423, 2431, 2450, 2455, 2480,
25672 \begin_layout Standard
25673 18F: (2510,) 2515, 2520, 2523, 2525, 2550, 2580, 2585, 25j10, 2610, 2620,
25677 \begin_layout Standard
25678 18F: 4220, 4221, 4320, 4321, 4331, 4410, 4420, 4423, 4431, 4450, 4455, 4480,
25682 \begin_layout Standard
25683 18F: 4510, 4515, 4520, 4523, 4525, 4550, 4580, 4585, 45j10, 4610, 4620,
25687 \begin_layout Standard
25688 18F: 6520, 6585, 6620, 6680, 66j60, 66j65, 6720, 67j60
25691 \begin_layout Standard
25692 18F: 8520, 8585, 8620, 8680, 86j60, 86j65, 8720, 87j60
25695 \begin_layout Standard
25696 18F: 96j60, 96j65, 97j60
25699 \begin_layout Standard
25701 An up-to-date list of supported devices is also available via '
25703 sdcc -mpic16 -plist
25708 \begin_layout Subsection
25712 \begin_layout Standard
25713 PIC16 port supports the standard command line arguments as supposed, with
25714 the exception of certain cases that will be mentioned in the following
25718 \begin_layout Description
25723 \begin_layout Standard
25733 \begin_inset LatexCommand index
25734 name "PIC16!Options!-\\/-callee-saves"
25742 \begin_layout Standard
25754 \begin_layout Description
25759 \begin_layout Standard
25768 -fommit-frame-pointer
25769 \begin_inset LatexCommand index
25770 name "PIC16!Options!-\\/-fommit-frame-pointer"
25774 Frame pointer will be omitted when the function uses no local variables.
25777 \begin_layout Subsection
25778 Port Specific Options
25779 \begin_inset LatexCommand index
25780 name "Options PIC16"
25787 \begin_layout Standard
25788 The port specific options appear after the global options in the sdcc -
25792 \begin_layout Standard
25804 \begin_layout Subsubsection
25805 Code Generation Options
25808 \begin_layout Standard
25809 These options influence the generated assembler code.
25812 \begin_layout Description
25817 \begin_layout Standard
25826 -pstack-model=[model] Used in conjunction with the command above.
25827 Defines the stack model to be used, valid stack models are:
25832 \labelwidthstring 00.00.0000
25837 Selects small stack model.
25838 8 bit stack and frame pointers.
25839 Supports 256 bytes stack size.
25843 \labelwidthstring 00.00.0000
25848 Selects large stack model.
25849 16 bit stack and frame pointers.
25850 Supports 65536 bytes stack size.
25854 \begin_layout Description
25859 \begin_layout Standard
25868 -pno-banksel Do not generate BANKSEL assembler directives.
25871 \begin_layout Description
25876 \begin_layout Standard
25885 -extended Enable extended instruction set/literal offset addressing mode.
25889 \begin_layout Subsubsection
25890 Optimization Options
25893 \begin_layout Description
25898 \begin_layout Standard
25907 -obanksel=n Set optimization level for inserting BANKSELs.
25914 \labelwidthstring 00.00.0000
25919 \labelwidthstring 00.00.0000
25920 1 checks previous used register and if it is the same then does not emit
25921 BANKSEL, accounts only for labels.
25925 \labelwidthstring 00.00.0000
25926 2 tries to check the location of (even different) symbols and removes BANKSELs
25927 if they are in the same bank.
25932 Important: There might be problems if the linker script has data sections
25933 across bank borders!
25937 \begin_layout Description
25942 \begin_layout Standard
25951 -denable-peeps Force the usage of peepholes.
25955 \begin_layout Description
25960 \begin_layout Standard
25969 -no-optimize-goto Do not use (conditional) BRA instead of GOTO.
25972 \begin_layout Description
25977 \begin_layout Standard
25986 -optimize-cmp Try to optimize some compares.
25989 \begin_layout Description
25994 \begin_layout Standard
26003 -optimize-df Analyze the dataflow of the generated code and improve it.
26006 \begin_layout Subsubsection
26010 \begin_layout Description
26015 \begin_layout Standard
26024 -asm= Sets the full path and name of an external assembler to call.
26027 \begin_layout Description
26032 \begin_layout Standard
26042 \begin_inset LatexCommand index
26047 compatibility option.
26048 Currently only suppresses special gpasm directives.
26051 \begin_layout Subsubsection
26055 \begin_layout Description
26060 \begin_layout Standard
26069 -link= Sets the full path and name of an external linker to call.
26072 \begin_layout Description
26077 \begin_layout Standard
26086 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
26087 unitialized data variables with [kword].
26088 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
26091 \begin_layout Description
26096 \begin_layout Standard
26105 -ivt-loc=n Place the interrupt vector table at address
26110 Useful for bootloaders.
26113 \begin_layout Description
26118 \begin_layout Standard
26127 -nodefaultlibs Do not link default libraries when linking.
26130 \begin_layout Description
26135 \begin_layout Standard
26144 -use-crt= Use a custom run-time module instead of the defaults.
26147 \begin_layout Description
26152 \begin_layout Standard
26161 -no-crt Don't link the default run-time modules
26164 \begin_layout Subsubsection
26168 \begin_layout Standard
26169 Debugging options enable extra debugging information in the output files.
26172 \begin_layout Description
26177 \begin_layout Standard
26186 -debug-xtra Similar to -
26190 \begin_layout Standard
26200 \begin_inset LatexCommand index
26205 , but dumps more information.
26208 \begin_layout Description
26213 \begin_layout Standard
26222 -debug-ralloc Force register allocator to dump <source>.d file with debugging
26224 <source> is the name of the file being compiled.
26227 \begin_layout Description
26232 \begin_layout Standard
26241 -pcode-verbose Enable pcode debugging information in translation.
26244 \begin_layout Description
26249 \begin_layout Standard
26258 -calltree Dump call tree in .calltree file.
26261 \begin_layout Description
26266 \begin_layout Standard
26275 -gstack Trace push/pops for stack pointer overflow.
26278 \begin_layout Subsection
26279 Environment Variables
26282 \begin_layout Standard
26283 There is a number of environmental variables that can be used when running
26284 SDCC to enable certain optimizations or force a specific program behaviour.
26285 these variables are primarily for debugging purposes so they can be enabled/dis
26289 \begin_layout Standard
26290 Currently there is only two such variables available:
26293 \begin_layout Description
26294 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
26295 bitfields is optimized by directly loading FSR0 with the address of the
26296 bitfield structure.
26297 Normally SDCC will cast the bitfield structure to a bitfield pointer and
26299 This step saves data ram and code space for functions that make heavy use
26301 (i.e., 80 bytes of code space are saved when compiling malloc.c with this
26306 \begin_layout Description
26307 NO_REG_OPT Do not perform pCode registers optimization.
26308 This should be used for debugging purposes.
26309 If bugs in the pcode optimizer are found, users can benefit from temporarily
26310 disabling the optimizer until the bug is fixed.
26313 \begin_layout Subsection
26314 Preprocessor Macros
26317 \begin_layout Standard
26319 \begin_inset LatexCommand index
26324 port defines the following preprocessor macros while translating a source.
26327 \begin_layout Standard
26329 \begin_inset Tabular
26330 <lyxtabular version="3" rows="6" columns="2">
26332 <column alignment="center" valignment="top" leftline="true" width="0">
26333 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26334 <row topline="true" bottomline="true">
26335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26338 \begin_layout Standard
26344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26347 \begin_layout Standard
26354 <row topline="true">
26355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26358 \begin_layout Standard
26364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26367 \begin_layout Standard
26368 Port identification
26374 <row topline="true">
26375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26378 \begin_layout Standard
26383 \begin_layout Standard
26397 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26400 \begin_layout Standard
26401 Port identification (same as above)
26407 <row topline="true">
26408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26411 \begin_layout Standard
26417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26420 \begin_layout Standard
26421 MCU Identification.
26426 is the microcontrol identification number, i.e.
26433 <row topline="true">
26434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26437 \begin_layout Standard
26442 \begin_layout Standard
26456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26459 \begin_layout Standard
26460 MCU Identification (same as above)
26466 <row topline="true" bottomline="true">
26467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26470 \begin_layout Standard
26476 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26479 \begin_layout Standard
26480 nnn = SMALL or LARGE respectively according to the stack model used
26493 \begin_layout Standard
26495 In addition the following macros are defined when calling assembler:
26498 \begin_layout Standard
26500 \begin_inset Tabular
26501 <lyxtabular version="3" rows="4" columns="2">
26503 <column alignment="center" valignment="top" leftline="true" width="0">
26504 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26505 <row topline="true" bottomline="true">
26506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26509 \begin_layout Standard
26515 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26518 \begin_layout Standard
26525 <row topline="true">
26526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26529 \begin_layout Standard
26535 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26538 \begin_layout Standard
26539 MCU Identification.
26544 is the microcontrol identification number, i.e.
26551 <row topline="true">
26552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26555 \begin_layout Standard
26561 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26564 \begin_layout Standard
26565 nnn = SMALL or LARGE respectively according to the memory model used for
26572 <row topline="true" bottomline="true">
26573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26576 \begin_layout Standard
26582 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26585 \begin_layout Standard
26586 nnn = SMALL or LARGE respectively according to the stack model used
26599 \begin_layout Subsection
26603 \begin_layout Standard
26605 \begin_inset LatexCommand index
26610 port uses the following directories for searching header files and libraries.
26613 \begin_layout Standard
26615 \begin_inset Tabular
26616 <lyxtabular version="3" rows="3" columns="4">
26618 <column alignment="center" valignment="top" leftline="true" width="0">
26619 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26620 <column alignment="center" valignment="top" width="0">
26621 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26622 <row topline="true" bottomline="true">
26623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26626 \begin_layout Standard
26632 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26635 \begin_layout Standard
26641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26644 \begin_layout Standard
26650 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26653 \begin_layout Standard
26660 <row topline="true">
26661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26664 \begin_layout Standard
26665 PREFIX/sdcc/include/pic16
26670 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26673 \begin_layout Standard
26674 PIC16 specific headers
26679 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26682 \begin_layout Standard
26688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26691 \begin_layout Standard
26698 <row topline="true" bottomline="true">
26699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26702 \begin_layout Standard
26703 PREFIX/sdcc/lib/pic16
26708 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26711 \begin_layout Standard
26712 PIC16 specific libraries
26717 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26720 \begin_layout Standard
26726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26729 \begin_layout Standard
26743 \begin_layout Subsection
26745 \begin_inset LatexCommand label
26746 name "sub:PIC16_Pragmas"
26753 \begin_layout Standard
26755 \begin_inset LatexCommand index
26760 port currently supports the following pragmas:
26763 \begin_layout Description
26765 \begin_inset LatexCommand index
26766 name "PIC16!Pragmas!\\#pragma stack"
26770 This forces the code generator to initialize the stack & frame pointers
26771 at a specific address.
26772 This is an ad hoc solution for cases where no STACK directive is available
26773 in the linker script or gplink is not instructed to create a stack section.
26776 stack pragma should be used only once in a project.
26777 Multiple pragmas may result in indeterminate behaviour of the program.
26781 \begin_layout Standard
26782 The old format (ie.
26783 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
26784 cross page boundaries (or even exceed the available data RAM) and crash
26786 Make sure that stack does not cross page boundaries when using the SMALL
26794 The format is as follows:
26799 \begin_layout LyX-Code
26800 #pragma stack bottom_address [stack_size]
26805 \begin_layout Standard
26810 is the lower bound of the stack section.
26811 The stack pointer initially will point at address (bottom_address+stack_size-1).
26814 \begin_layout LyX-Code
26818 \begin_layout LyX-Code
26822 \begin_layout LyX-Code
26823 /* initializes stack of 100 bytes at RAM address 0x200 */
26826 \begin_layout LyX-Code
26827 #pragma stack 0x200 100
26830 \begin_layout Standard
26831 If the stack_size field is omitted then a stack is created with the default
26833 This size might be enough for most programs, but its not enough for operations
26834 with deep function nesting or excessive stack usage.
26837 \begin_layout Description
26839 \begin_inset LatexCommand index
26840 name "PIC16!Pragmas!\\#pragma code"
26844 Force a function to a static FLASH address.
26847 \begin_layout LyX-Code
26851 \begin_layout LyX-Code
26855 \begin_layout LyX-Code
26856 /* place function test_func at 0x4000 */
26859 \begin_layout LyX-Code
26860 #pragma code test_func 0x4000
26863 \begin_layout LyX-Code
26867 \begin_layout Description
26868 library instructs the linker to use a library module.
26873 \begin_layout LyX-Code
26874 #pragma library module_name
26877 \begin_layout Standard
26882 can be any library or object file (including its path).
26883 Note that there are four reserved keywords which have special meaning.
26887 \begin_layout Standard
26889 \begin_inset Tabular
26890 <lyxtabular version="3" rows="6" columns="3">
26892 <column alignment="center" valignment="top" leftline="true" width="0">
26893 <column alignment="block" valignment="top" leftline="true" width="20page%">
26894 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
26895 <row topline="true" bottomline="true">
26896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26899 \begin_layout Standard
26905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26908 \begin_layout Standard
26914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26917 \begin_layout Standard
26924 <row topline="true">
26925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26928 \begin_layout Standard
26936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26939 \begin_layout Standard
26940 ignore all library pragmas
26945 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26948 \begin_layout Standard
26957 <row topline="true">
26958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26961 \begin_layout Standard
26969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26972 \begin_layout Standard
26978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26981 \begin_layout Standard
26992 <row topline="true">
26993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26996 \begin_layout Standard
27004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27007 \begin_layout Standard
27008 link the Math libarary
27013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27016 \begin_layout Standard
27027 <row topline="true">
27028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27031 \begin_layout Standard
27039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27042 \begin_layout Standard
27043 link the I/O library
27048 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27051 \begin_layout Standard
27062 <row topline="true" bottomline="true">
27063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27066 \begin_layout Standard
27074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27077 \begin_layout Standard
27078 link the debug library
27083 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27086 \begin_layout Standard
27103 * is the device number, i.e.
27104 452 for PIC18F452 MCU.
27107 \begin_layout Standard
27109 This feature allows for linking with specific libraries without having to
27110 explicit name them in the command line.
27115 keyword will reject all modules specified by the library pragma.
27118 \begin_layout Description
27119 udata The pragma udata instructs the compiler to emit code so that linker
27120 will place a variable at a specific memory bank.
27123 \begin_layout LyX-Code
27127 \begin_layout LyX-Code
27131 \begin_layout LyX-Code
27132 /* places variable foo at bank2 */
27135 \begin_layout LyX-Code
27136 #pragma udata bank2 foo
27139 \begin_layout LyX-Code
27143 \begin_layout Standard
27144 In order for this pragma to work extra SECTION directives should be added
27145 in the .lkr script.
27146 In the following example a sample .lkr file is shown:
27149 \begin_layout LyX-Code
27153 \begin_layout LyX-Code
27154 // Sample linker script for the PIC18F452 processor
27157 \begin_layout LyX-Code
27161 \begin_layout LyX-Code
27162 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
27165 \begin_layout LyX-Code
27166 CODEPAGE NAME=page START=0x2A END=0x7FFF
27169 \begin_layout LyX-Code
27170 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
27173 \begin_layout LyX-Code
27174 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
27177 \begin_layout LyX-Code
27178 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
27181 \begin_layout LyX-Code
27182 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
27185 \begin_layout LyX-Code
27186 ACCESSBANK NAME=accessram START=0x0 END=0x7F
27189 \begin_layout LyX-Code
27193 \begin_layout LyX-Code
27194 DATABANK NAME=gpr0 START=0x80 END=0xFF
27197 \begin_layout LyX-Code
27198 DATABANK NAME=gpr1 START=0x100 END=0x1FF
27201 \begin_layout LyX-Code
27202 DATABANK NAME=gpr2 START=0x200 END=0x2FF
27205 \begin_layout LyX-Code
27206 DATABANK NAME=gpr3 START=0x300 END=0x3FF
27209 \begin_layout LyX-Code
27210 DATABANK NAME=gpr4 START=0x400 END=0x4FF
27213 \begin_layout LyX-Code
27214 DATABANK NAME=gpr5 START=0x500 END=0x5FF
27217 \begin_layout LyX-Code
27218 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
27221 \begin_layout LyX-Code
27225 \begin_layout LyX-Code
27226 SECTION NAME=CONFIG ROM=config
27229 \begin_layout LyX-Code
27233 \begin_layout LyX-Code
27234 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
27237 \begin_layout LyX-Code
27238 SECTION NAME=bank1 RAM=gpr1 # should be added to link
27241 \begin_layout LyX-Code
27242 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
27245 \begin_layout LyX-Code
27246 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
27249 \begin_layout LyX-Code
27250 SECTION NAME=bank4 RAM=gpr4
27253 \begin_layout LyX-Code
27254 SECTION NAME=bank5 RAM=gpr5
27257 \begin_layout Standard
27258 The linker will recognise the section name set in the pragma statement and
27259 will position the variable at the memory bank set with the RAM field at
27260 the SECTION line in the linker script file.
27263 \begin_layout Subsection
27265 \begin_inset LatexCommand label
27266 name "sub:PIC16_Header-Files"
27273 \begin_layout Standard
27274 There is one main header file
27275 \begin_inset LatexCommand index
27276 name "PIC16!Header files"
27280 that can be included to the source files using the pic16
27281 \begin_inset LatexCommand index
27292 This header file contains the definitions for the processor special registers,
27293 so it is necessary if the source accesses them.
27294 It can be included by adding the following line in the beginning of the
27298 \begin_layout LyX-Code
27299 #include <pic18fregs.h>
27302 \begin_layout Standard
27303 The specific microcontroller is selected within the pic18fregs.h automatically,
27304 so the same source can be used with a variety of devices.
27307 \begin_layout Subsection
27309 \begin_inset LatexCommand label
27310 name "sub:pic16Libraries"
27317 \begin_layout Standard
27319 \begin_inset LatexCommand index
27320 name "PIC16!Libraries"
27325 \begin_inset LatexCommand index
27330 port depends on are the microcontroller device libraries which contain
27331 the symbol definitions for the microcontroller special function registers.
27332 These libraries have the format pic18fxxxx.lib, where
27336 is the microcontroller identification number.
27337 The specific library is selected automatically by the compiler at link
27338 stage according to the selected device.
27341 \begin_layout Standard
27343 Libraries are created with gplib which is part of the gputils package
27344 \begin_inset LatexCommand url
27345 target "http://sourceforge.net/projects/gputils"
27352 \begin_layout Subsubsection*
27353 Building the libraries
27356 \begin_layout Standard
27357 Before using SDCC/pic16 there are some libraries that need to be compiled.
27358 This process is done automatically if gputils are found at SDCC's compile
27360 Should you require to rebuild the pic16 libraries manually (e.g.
27361 in order to enable output of float values
27362 \begin_inset LatexCommand index
27363 name "Floating point support"
27371 , see below), these are the steps required to do so under Linux or Mac OS
27372 X (cygwin might work as well, but is untested):
27375 \begin_layout LyX-Code
27376 cd device/lib/pic16
27379 \begin_layout LyX-Code
27383 \begin_layout LyX-Code
27387 \begin_layout LyX-Code
27391 \begin_layout LyX-Code
27392 su -c 'make install' # install the libraries, you need the root password
27395 \begin_layout LyX-Code
27399 \begin_layout Standard
27400 If you need to install the headers too, do:
27403 \begin_layout LyX-Code
27407 \begin_layout LyX-Code
27408 su -c 'make install' # install the headers, you need the root password
27411 \begin_layout Subsubsection*
27412 Output of float values via printf()
27415 \begin_layout Standard
27416 The library is normally built without support for displaying float values,
27418 \begin_inset LatexCommand index
27424 \begin_inset LatexCommand index
27425 name "printf floating point support"
27429 will appear instead of the value.
27430 To change this, rebuild the library as stated above, but call
27432 ./configure.gnu --enable-floats
27439 Also make sure that at least
27441 libc/stdio/vfprintf.c
27443 is actually recompiled, e.g.
27452 run or deleting its
27459 \begin_layout Standard
27460 The more common appraoch of compiling
27468 should also work, but is untested.
27471 \begin_layout Subsection
27472 Adding New Devices to the Port
27475 \begin_layout Standard
27476 Adding support for a new 16
27480 \begin_layout Standard
27489 bit PIC MCU requires the following steps:
27492 \begin_layout Enumerate
27493 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
27497 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
27501 \begin_layout Enumerate
27504 mv picDEVICE.h /path/to/sdcc/device/include/pic16
27507 \begin_layout Enumerate
27510 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
27513 \begin_layout Enumerate
27516 /path/to/sdcc/device/lib/pic16/pics.all
27520 Note: No 18f prefix here!
27523 \begin_layout Enumerate
27526 /path/to/sdcc/device/include/pic16/adc.h
27530 Add the new devices to the correct ADC style class (depending on the number
27537 if the device does not offer any ADC at all.
27540 \begin_layout Enumerate
27543 /path/to/sdcc/device/include/pic16/pic18fregs.h
27547 The file format is self-explanatory, just add
27551 #elif defined(picDEVICE)
27557 \begin_layout Standard
27568 include <picDEVICE.h>
27572 at the right place (keep the file sorted, please).
27575 \begin_layout Enumerate
27578 /path/to/sdcc/device/include/pic16devices.txt
27582 Copy and modify an existing entry or create a new one and insert it at the
27583 correct place (keep the file sorted, please).
27586 \begin_layout Enumerate
27589 /path/to/sdcc/device/lib/pic16/libdev/Makefile.am
27593 Copy an existing entry and adjust the device name.
27596 \begin_layout Enumerate
27599 /path/to/sdcc/device/lib/pic16/libio/Makefile.am
27603 Copy the record from the 18f2220 and adjust the device name.
27606 does not offer ADC, I
27607 \begin_inset Formula $^{\text{2}}$
27610 C, and/or (E)USART functionality as assumed by the library, remove the lines
27626 \begin_layout Enumerate
27645 /path/to/sdcc/device/lib/pic16
27650 \begin_layout Enumerate
27651 Recompile the pic16 libraries as described in
27652 \begin_inset LatexCommand ref
27653 reference "sub:pic16Libraries"
27660 \begin_layout Subsection
27664 \begin_layout Standard
27665 The following memory models are supported by the PIC16 port:
27668 \begin_layout Itemize
27672 \begin_layout Itemize
27676 \begin_layout Standard
27677 Memory model affects the default size of pointers within the source.
27678 The sizes are shown in the next table:
27681 \begin_layout Standard
27683 \begin_inset Tabular
27684 <lyxtabular version="3" rows="3" columns="3">
27686 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27687 <column alignment="center" valignment="top" leftline="true" width="0">
27688 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27689 <row topline="true" bottomline="true">
27690 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27693 \begin_layout Standard
27694 Pointer sizes according to memory model
27699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27702 \begin_layout Standard
27708 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27711 \begin_layout Standard
27718 <row topline="true" bottomline="true">
27719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27722 \begin_layout Standard
27728 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27731 \begin_layout Standard
27737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27740 \begin_layout Standard
27747 <row topline="true" bottomline="true">
27748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27751 \begin_layout Standard
27757 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
27760 \begin_layout Standard
27766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27769 \begin_layout Standard
27783 \begin_layout Standard
27784 It is advisable that all sources within a project are compiled with the
27786 If one wants to override the default memory model, this can be done by
27787 declaring a pointer as
27796 Far selects large memory model's pointers, while near selects small memory
27800 \begin_layout Standard
27801 The standard device libraries (see
27802 \begin_inset LatexCommand ref
27803 reference "sub:PIC16_Header-Files"
27807 ) contain no reference to pointers, so they can be used with both memory
27811 \begin_layout Subsection
27815 \begin_layout Standard
27817 \begin_inset LatexCommand index
27822 implementation for the PIC16 port uses two indirect registers, FSR1 and
27826 \begin_layout Description
27827 FSR1 is assigned as stack pointer
27830 \begin_layout Description
27831 FSR2 is assigned as frame pointer
27834 \begin_layout Standard
27835 The following stack models are supported by the PIC16 port
27838 \begin_layout Itemize
27846 \begin_layout Itemize
27854 \begin_layout Standard
27859 model means that only the FSRxL byte is used to access stack and frame,
27866 uses both FSRxL and FSRxH registers.
27867 The following table shows the stack/frame pointers sizes according to stack
27868 model and the maximum space they can address:
27871 \begin_layout Standard
27873 \begin_inset Tabular
27874 <lyxtabular version="3" rows="3" columns="3">
27876 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27877 <column alignment="center" valignment="top" leftline="true" width="0">
27878 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27879 <row topline="true" bottomline="true">
27880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27883 \begin_layout Standard
27884 Stack & Frame pointer sizes according to stack model
27889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27892 \begin_layout Standard
27898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27901 \begin_layout Standard
27908 <row topline="true">
27909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27912 \begin_layout Standard
27918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27921 \begin_layout Standard
27927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27930 \begin_layout Standard
27937 <row topline="true" bottomline="true">
27938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27941 \begin_layout Standard
27947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27950 \begin_layout Standard
27956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27959 \begin_layout Standard
27973 \begin_layout Standard
27979 stack model is currently not working properly throughout the code generator.
27980 So its use is not advised.
27981 Also there are some other points that need special care:
27986 \begin_layout Enumerate
27987 Do not create stack sections with size more than one physical bank (that
27991 \begin_layout Enumerate
27992 Stack sections should no cross physical bank limits (i.e.
27993 #pragma stack 0x50 0x100)
27996 \begin_layout Standard
27997 These limitations are caused by the fact that only FSRxL is modified when
27998 using SMALL stack model, so no more than 256 bytes of stack can be used.
27999 This problem will disappear after LARGE model is fully implemented.
28002 \begin_layout Subsection
28006 \begin_layout Standard
28007 In addition to the standard SDCC function keywords, PIC16
28008 \begin_inset LatexCommand index
28013 port makes available two more:
28016 \begin_layout Description
28018 \begin_inset LatexCommand index
28019 name "PIC16!wparam"
28023 Use the WREG to pass one byte of the first function argument.
28024 This improves speed but you may not use this for functions with arguments
28025 that are called via function pointers, otherwise the first byte of the
28026 first parameter will get lost.
28030 \begin_layout LyX-Code
28031 void func_wparam(int a) wparam
28034 \begin_layout LyX-Code
28038 \begin_layout LyX-Code
28039 /* WREG hold the lower part of a */
28042 \begin_layout LyX-Code
28043 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
28047 \begin_layout LyX-Code
28051 \begin_layout LyX-Code
28055 \begin_layout Description
28057 \begin_inset LatexCommand index
28058 name "PIC16!shadowregs"
28062 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
28063 hardware shadow registers which hold the values of WREG, STATUS and BSR
28065 This can be done by adding the keyword
28073 keyword in the function's header.
28076 \begin_layout LyX-Code
28077 void isr_shadow(void) shadowregs interrupt 1
28080 \begin_layout LyX-Code
28084 \begin_layout LyX-Code
28088 \begin_layout LyX-Code
28092 \begin_layout Standard
28097 instructs the code generator not to store/restore WREG, STATUS, BSR when
28098 entering/exiting the ISR.
28101 \begin_layout Subsection
28102 Function return values
28105 \begin_layout Standard
28106 Return values from functions are placed to the appropriate registers following
28107 a modified Microchip policy optimized for SDCC.
28108 The following table shows these registers:
28111 \begin_layout Standard
28113 \begin_inset Tabular
28114 <lyxtabular version="3" rows="6" columns="2">
28116 <column alignment="center" valignment="top" leftline="true" width="0">
28117 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28118 <row topline="true" bottomline="true">
28119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28122 \begin_layout Standard
28128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28131 \begin_layout Standard
28132 destination register
28138 <row topline="true">
28139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28142 \begin_layout Standard
28148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28151 \begin_layout Standard
28158 <row topline="true">
28159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28162 \begin_layout Standard
28168 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28171 \begin_layout Standard
28178 <row topline="true">
28179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28182 \begin_layout Standard
28188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28191 \begin_layout Standard
28198 <row topline="true">
28199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28202 \begin_layout Standard
28208 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28211 \begin_layout Standard
28212 FSR0L:PRODH:PRODL:WREG
28218 <row topline="true" bottomline="true">
28219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28222 \begin_layout Standard
28228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28231 \begin_layout Standard
28232 on stack, FSR0 points to the beginning
28245 \begin_layout Subsection
28249 \begin_layout Standard
28251 \begin_inset LatexCommand index
28252 name "PIC16!interrupt"
28256 service routine (ISR) is declared using the
28263 \begin_layout LyX-Code
28264 void isr(void) interrupt
28269 \begin_layout LyX-Code
28273 \begin_layout LyX-Code
28277 \begin_layout LyX-Code
28281 \begin_layout Standard
28286 is the interrupt number, which for PIC18F devices can be:
28289 \begin_layout Standard
28291 \begin_inset Tabular
28292 <lyxtabular version="3" rows="4" columns="3">
28294 <column alignment="center" valignment="top" leftline="true" width="0">
28295 <column alignment="center" valignment="top" leftline="true" width="0">
28296 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28297 <row topline="true" bottomline="true">
28298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28301 \begin_layout Standard
28309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28312 \begin_layout Standard
28318 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28321 \begin_layout Standard
28322 Interrupt Vector Address
28328 <row topline="true">
28329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28332 \begin_layout Standard
28338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28341 \begin_layout Standard
28347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28350 \begin_layout Standard
28357 <row topline="true">
28358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28361 \begin_layout Standard
28376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28379 \begin_layout Standard
28389 HIGH priority interrupts
28394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28397 \begin_layout Standard
28404 <row topline="true" bottomline="true">
28405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28408 \begin_layout Standard
28414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28417 \begin_layout Standard
28418 LOW priority interrupts
28423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28426 \begin_layout Standard
28440 \begin_layout Standard
28441 When generating assembly code for ISR the code generator places a
28447 Interrupt Vector Address
28449 which points at the generated ISR.
28450 This single GOTO instruction is part of an automatically generated
28452 interrupt entry point
28455 The actuall ISR code is placed as normally would in the code space.
28456 Upon interrupt request, the GOTO instruction is executed which jumps to
28458 When declaring interrupt functions as _naked this GOTO instruction is
28463 The whole interrupt functions is therefore placed at the Interrupt Vector
28464 Address of the specific interrupt.
28465 This is not a problem for the LOW priority interrupts, but it is a problem
28466 for the RESET and the HIGH priority interrupts because code may be written
28467 at the next interrupt's vector address and cause indeterminate program
28468 behaviour if that interrupt is raised.
28472 \begin_layout Standard
28473 This is not a problem when
28476 \begin_layout Enumerate
28477 this is a HIGH interrupt ISR and LOW interrupts are
28484 \begin_layout Enumerate
28485 when the ISR is small enough not to reach the next interrupt's vector address.
28493 \begin_layout Standard
28499 This way a function is generated similar to an ISR, but it is not assigned
28503 \begin_layout Standard
28504 When entering an interrupt, currently the PIC16
28505 \begin_inset LatexCommand index
28510 port automatically saves the following registers:
28513 \begin_layout Itemize
28517 \begin_layout Itemize
28521 \begin_layout Itemize
28525 \begin_layout Itemize
28526 PROD (PRODL and PRODH)
28529 \begin_layout Itemize
28530 FSR0 (FSR0L and FSR0H)
28533 \begin_layout Standard
28534 These registers are restored upon return from the interrupt routine.
28538 \begin_layout Standard
28539 NOTE that when the _naked attribute is specified for an interrupt routine,
28540 then NO registers are stored or restored.
28548 \begin_layout Subsection
28552 \begin_layout Standard
28553 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
28554 There are 3 types of generic pointers currently implemented data, code
28555 and eeprom pointers.
28556 They are differentiated by the value of the 7th and 6th bits of the upper
28560 \begin_layout Standard
28562 \begin_inset Tabular
28563 <lyxtabular version="3" rows="5" columns="5">
28565 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28566 <column alignment="center" valignment="top" width="0">
28567 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28568 <column alignment="center" valignment="top" width="0">
28569 <column alignment="left" valignment="top" rightline="true" width="0">
28570 <row topline="true" bottomline="true">
28571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28574 \begin_layout Standard
28580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28583 \begin_layout Standard
28589 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28592 \begin_layout Standard
28598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28601 \begin_layout Standard
28602 rest of the pointer
28607 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28610 \begin_layout Standard
28617 <row topline="true" bottomline="true">
28618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28621 \begin_layout Standard
28627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28630 \begin_layout Standard
28636 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28639 \begin_layout Standard
28645 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28648 \begin_layout Standard
28653 uuuuuu uuuuxxxx xxxxxxxx
28658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28661 \begin_layout Standard
28662 a 12-bit data pointer in data RAM memory
28668 <row bottomline="true">
28669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28672 \begin_layout Standard
28678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28681 \begin_layout Standard
28687 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28690 \begin_layout Standard
28696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28699 \begin_layout Standard
28704 uxxxxx xxxxxxxx xxxxxxxx
28709 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28712 \begin_layout Standard
28713 a 21-bit code pointer in FLASH memory
28719 <row bottomline="true">
28720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28723 \begin_layout Standard
28729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28732 \begin_layout Standard
28738 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28741 \begin_layout Standard
28747 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28750 \begin_layout Standard
28755 uuuuuu uuuuuuxx xxxxxxxx
28760 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28763 \begin_layout Standard
28764 a 10-bit eeprom pointer in EEPROM memory
28770 <row bottomline="true">
28771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28774 \begin_layout Standard
28780 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28783 \begin_layout Standard
28789 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28792 \begin_layout Standard
28798 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28801 \begin_layout Standard
28806 xxxxxx xxxxxxxx xxxxxxxx
28811 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28814 \begin_layout Standard
28815 unimplemented pointer type
28828 \begin_layout Standard
28830 Generic pointer are read and written with a set of library functions which
28831 read/write 1, 2, 3, 4 bytes.
28834 \begin_layout Subsection
28838 \begin_layout Subsubsection
28839 Standard I/O Streams
28842 \begin_layout Standard
28847 the type FILE is defined as:
28850 \begin_layout LyX-Code
28851 typedef char * FILE;
28854 \begin_layout Standard
28855 This type is the stream type implemented I/O in the PIC18F devices.
28856 Also the standard input and output streams are declared in stdio.h:
28859 \begin_layout LyX-Code
28860 extern FILE * stdin;
28863 \begin_layout LyX-Code
28864 extern FILE * stdout;
28867 \begin_layout Standard
28868 The FILE type is actually a generic pointer which defines one more type
28869 of generic pointers, the
28874 This new type has the format:
28877 \begin_layout Standard
28880 \begin_inset Tabular
28881 <lyxtabular version="3" rows="2" columns="7">
28883 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28884 <column alignment="center" valignment="top" width="0">
28885 <column alignment="center" valignment="top" leftline="true" width="0">
28886 <column alignment="center" valignment="top" leftline="true" width="0">
28887 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28888 <column alignment="center" valignment="top" width="0">
28889 <column alignment="left" valignment="top" rightline="true" width="0">
28890 <row topline="true" bottomline="true">
28891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28894 \begin_layout Standard
28900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28903 \begin_layout Standard
28909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28912 \begin_layout Standard
28918 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28921 \begin_layout Standard
28927 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28930 \begin_layout Standard
28936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28939 \begin_layout Standard
28940 rest of the pointer
28945 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28948 \begin_layout Standard
28955 <row topline="true" bottomline="true">
28956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28959 \begin_layout Standard
28965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28968 \begin_layout Standard
28974 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28977 \begin_layout Standard
28983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28986 \begin_layout Standard
28992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28995 \begin_layout Standard
29001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29004 \begin_layout Standard
29014 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29017 \begin_layout Standard
29018 upper byte high nubble is 0x2n, the rest are zeroes
29031 \begin_layout Standard
29033 Currently implemented there are 3 types of streams defined:
29036 \begin_layout Standard
29039 \begin_inset Tabular
29040 <lyxtabular version="3" rows="4" columns="4">
29042 <column alignment="center" valignment="top" leftline="true" width="0">
29043 <column alignment="center" valignment="top" leftline="true" width="0">
29044 <column alignment="center" valignment="top" leftline="true" width="0">
29045 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29046 <row topline="true" bottomline="true">
29047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29050 \begin_layout Standard
29056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29059 \begin_layout Standard
29065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29068 \begin_layout Standard
29074 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29077 \begin_layout Standard
29084 <row topline="true">
29085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29088 \begin_layout Standard
29094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29097 \begin_layout Standard
29105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29108 \begin_layout Standard
29114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29117 \begin_layout Standard
29118 Writes/Reads characters via the USART peripheral
29124 <row topline="true">
29125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29128 \begin_layout Standard
29134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29137 \begin_layout Standard
29145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29148 \begin_layout Standard
29154 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29157 \begin_layout Standard
29158 Writes/Reads characters via the MSSP peripheral
29164 <row topline="true" bottomline="true">
29165 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29168 \begin_layout Standard
29174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29177 \begin_layout Standard
29185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29188 \begin_layout Standard
29194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29197 \begin_layout Standard
29198 Writes/Reads characters via used defined functions
29211 \begin_layout Standard
29213 The stream identifiers are declared as macros in the stdio.h header.
29216 \begin_layout Standard
29218 In the libc library there exist the functions that are used to write to
29219 each of the above streams.
29223 \begin_layout Description
29228 \begin_layout Standard
29237 _stream_usart_putchar writes a character at the USART stream
29240 \begin_layout Description
29245 \begin_layout Standard
29254 _stream_mssp_putchar writes a character at the MSSP stream
29257 \begin_layout Description
29258 putchar dummy function.
29259 This writes a character to a user specified manner.
29262 \begin_layout Standard
29263 In order to increase performance
29267 is declared in stdio.h as having its parameter in WREG (it has the wparam
29269 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
29270 in a user-friendly way.
29275 is the name of the variable that holds the character to print.
29276 An example follows:
29279 \begin_layout LyX-Code
29280 #include <pic18fregs.h>
29289 \begin_layout LyX-Code
29293 \begin_layout LyX-Code
29294 PORTA = c; /* dump character c to PORTA */
29297 \begin_layout LyX-Code
29305 \begin_layout LyX-Code
29309 \begin_layout LyX-Code
29310 stdout = STREAM_USER; /* this is not necessary, since stdout points
29313 \begin_layout LyX-Code
29314 * by default to STREAM_USER */
29317 \begin_layout LyX-Code
29319 \begin_inset Quotes sld
29322 This is a printf test
29325 \begin_inset Quotes srd
29331 \begin_layout LyX-Code
29335 \begin_layout LyX-Code
29339 \begin_layout Subsubsection
29343 \begin_layout Standard
29344 PIC16 contains an implementation of the printf-family of functions.
29345 There exist the following functions:
29348 \begin_layout LyX-Code
29349 extern unsigned int sprintf(char *buf, char *fmt, ...);
29352 \begin_layout LyX-Code
29353 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
29356 \begin_layout LyX-Code
29360 \begin_layout LyX-Code
29361 extern unsigned int printf(char *fmt, ...);
29364 \begin_layout LyX-Code
29365 extern unsigned int vprintf(char *fmt, va_lista ap);
29368 \begin_layout LyX-Code
29372 \begin_layout LyX-Code
29373 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
29376 \begin_layout LyX-Code
29377 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
29380 \begin_layout Standard
29381 For sprintf and vsprintf
29385 should normally be a data pointer where the resulting string will be placed.
29386 No range checking is done so the user should allocate the necessary buffer.
29387 For fprintf and vfprintf
29391 should be a stream pointer (i.e.
29392 stdout, STREAM_MSSP, etc...).
29395 \begin_layout Subsubsection
29399 \begin_layout Standard
29400 The PIC18F family of microcontrollers supports a number of interrupt sources.
29401 A list of these interrupts is shown in the following table:
29404 \begin_layout Standard
29406 \begin_inset Tabular
29407 <lyxtabular version="3" rows="11" columns="4">
29409 <column alignment="left" valignment="top" leftline="true" width="0">
29410 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29411 <column alignment="left" valignment="top" leftline="true" width="0">
29412 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29413 <row topline="true" bottomline="true">
29414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29417 \begin_layout Standard
29423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29426 \begin_layout Standard
29432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29435 \begin_layout Standard
29441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29444 \begin_layout Standard
29451 <row topline="true">
29452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29455 \begin_layout Standard
29461 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29464 \begin_layout Standard
29465 PORTB change interrupt
29470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29473 \begin_layout Standard
29479 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29482 \begin_layout Standard
29483 EEPROM/FLASH write complete interrupt
29489 <row topline="true">
29490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29493 \begin_layout Standard
29499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29502 \begin_layout Standard
29503 INT0 external interrupt
29508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29511 \begin_layout Standard
29517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29520 \begin_layout Standard
29521 Bus collision interrupt
29527 <row topline="true">
29528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29531 \begin_layout Standard
29537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29540 \begin_layout Standard
29541 INT1 external interrupt
29546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29549 \begin_layout Standard
29555 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29558 \begin_layout Standard
29559 Low voltage detect interrupt
29565 <row topline="true">
29566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29569 \begin_layout Standard
29575 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29578 \begin_layout Standard
29579 INT2 external interrupt
29584 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29587 \begin_layout Standard
29593 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29596 \begin_layout Standard
29597 Parallel slave port interrupt
29603 <row topline="true">
29604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29607 \begin_layout Standard
29613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29616 \begin_layout Standard
29617 CCP1 module interrupt
29622 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29625 \begin_layout Standard
29631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29634 \begin_layout Standard
29635 AD convertion complete interrupt
29641 <row topline="true">
29642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29645 \begin_layout Standard
29651 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29654 \begin_layout Standard
29655 CCP2 module interrupt
29660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29663 \begin_layout Standard
29669 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29672 \begin_layout Standard
29673 USART receive interrupt
29679 <row topline="true">
29680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29683 \begin_layout Standard
29689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29692 \begin_layout Standard
29693 TMR0 overflow interrupt
29698 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29701 \begin_layout Standard
29707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29710 \begin_layout Standard
29711 USART transmit interrupt
29717 <row topline="true">
29718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29721 \begin_layout Standard
29727 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29730 \begin_layout Standard
29731 TMR1 overflow interrupt
29736 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29739 \begin_layout Standard
29745 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29748 \begin_layout Standard
29749 SSP receive/transmit interrupt
29755 <row topline="true">
29756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29759 \begin_layout Standard
29765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29768 \begin_layout Standard
29769 TMR2 matches PR2 interrupt
29774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29777 \begin_layout Standard
29783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29786 \begin_layout Standard
29793 <row topline="true" bottomline="true">
29794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29797 \begin_layout Standard
29803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29806 \begin_layout Standard
29807 TMR3 overflow interrupt
29812 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29815 \begin_layout Standard
29821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29824 \begin_layout Standard
29838 \begin_layout Standard
29840 The prototypes for these names are defined in the header file
29847 \begin_layout Standard
29849 In order to simplify signal handling, a number of macros is provided:
29853 \labelwidthstring 00.00.0000
29854 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
29855 high priority interrupts.
29860 is the function name to use.
29864 \labelwidthstring 00.00.0000
29865 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
29866 low priority interrupt.
29871 is the function name to use.
29875 \labelwidthstring 00.00.0000
29876 DEF_HANDLER(sig,handler) define a handler for signal
29882 \labelwidthstring 00.00.0000
29883 END_DEF end the declaration of the dispatch table.
29886 \begin_layout Standard
29887 Additionally there are two more macros to simplify the declaration of the
29892 \labelwidthstring 00.00.0000
29895 SIGHANDLER(handler)
29897 this declares the function prototype for the
29905 \labelwidthstring 00.00.0000
29906 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
29909 \begin_layout Standard
29910 An example of using the macros above is shown below:
29913 \begin_layout LyX-Code
29914 #include <pic18fregs.h>
29917 \begin_layout LyX-Code
29918 #include <signal.h>
29922 DEF_INTHIGH(high_int)
29925 \begin_layout LyX-Code
29926 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
29929 \begin_layout LyX-Code
29930 DEF_HANDLER(SIG_BCOL, _bcol_handler)
29933 \begin_layout LyX-Code
29938 SIGHANDLER(_tmr0_handler)
29941 \begin_layout LyX-Code
29945 \begin_layout LyX-Code
29946 /* action to be taken when timer 0 overflows */
29949 \begin_layout LyX-Code
29954 SIGHANDLERNAKED(_bcol_handler)
29957 \begin_layout LyX-Code
29961 \begin_layout LyX-Code
29965 \begin_layout LyX-Code
29966 /* action to be taken when bus collision occurs */
29969 \begin_layout LyX-Code
29973 \begin_layout LyX-Code
29977 \begin_layout LyX-Code
29981 \begin_layout Standard
29986 Special care should be taken when using the above scheme:
29989 \begin_layout Itemize
29990 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
29993 \begin_layout Itemize
29994 when declaring SIGHANDLERNAKED handler never forget to use
29998 for proper returning.
30001 \begin_layout Subsection
30005 \begin_layout Standard
30006 Here you can find some general tips for compiling programs with SDCC/pic16.
30009 \begin_layout Subsubsection
30013 \begin_layout Standard
30015 \begin_inset LatexCommand index
30020 size (that is 64 bytes) probably is enough for many programs.
30021 One must take care that when there are many levels of function nesting,
30022 or there is excessive usage of stack, its size should be extended.
30023 An example of such a case is the printf/sprintf family of functions.
30024 If you encounter problems like not being able to print integers, then you
30025 need to set the stack size around the maximum (256 for small stack model).
30026 The following diagram shows what happens when calling printf to print an
30030 \begin_layout LyX-Code
30031 printf () --> ltoa () --> ultoa () --> divschar ()
30034 \begin_layout Standard
30035 It is should be understood that stack is easily consumed when calling complicate
30037 Using command line arguments like -
30041 \begin_layout Standard
30050 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
30052 Other ways to reduce stack usage may exist.
30055 \begin_layout Subsection
30059 \begin_layout Subsubsection
30060 Extended Instruction Set
30063 \begin_layout Standard
30064 The PIC16 port emits code which is incompatible with the extended instruction
30065 set available with many newer devices.
30066 Make sure to always explicitly disable it, usually using
30069 \begin_layout Standard
30072 static __code char __at(__CONFIG4L) conf4l = /* more flags & */ _XINST_OFF_4L;
30075 \begin_layout Standard
30077 Some devices (namely 18f2455, 18f2550, 18f4455, and 18f4550) use _ENHCPU_OFF_4L
30078 instead of _XINST_OFF_4L.
30081 \begin_layout Subsubsection
30085 \begin_layout Standard
30086 The PIC16 port currently passes most but not all of the tests in SDCC's
30088 \begin_inset LatexCommand index
30089 name "Regression test (PIC16)"
30094 \begin_inset LatexCommand ref
30095 reference "sec:Quality-control"
30099 ), thus no automatic regression tests are currently performed for the PIC16
30103 \begin_layout Chapter
30107 \begin_layout Standard
30108 There are several approaches to debugging your code.
30109 This chapter is meant to show your options and to give detail on some of
30114 When writing your code:
30117 \begin_layout Itemize
30118 write your code with debugging in mind (avoid duplicating code, put conceptually
30119 similar variables into structs, use structured code, have strategic points
30120 within your code where all variables are consistent, ...)
30123 \begin_layout Itemize
30124 run a syntax-checking tool like splint
30125 \begin_inset LatexCommand index
30126 name "splint (syntax checking tool)"
30131 \begin_inset LatexCommand index
30132 name "lint (syntax checking tool)"
30140 \begin_layout Standard
30150 \begin_inset LatexCommand ref
30151 reference "lyx:more-pedantic-SPLINT"
30158 \begin_layout Itemize
30159 for the high level code use a C-compiler (like f.e.
30160 GCC) to compile run and debug the code on your host.
30165 \begin_layout Standard
30175 \begin_inset LatexCommand ref
30176 reference "lyx:more-pedantic-SPLINT"
30180 ) on how to handle syntax extensions like __xdata, __at(), ...
30184 \begin_layout Itemize
30185 use another C-compiler to compile code for your target.
30186 Always an option but not recommended:) And not very likely to help you.
30187 If you seriously consider walking this path you should at least occasionally
30188 check portability of your code.
30189 Most commercial compiler vendors will offer an evaluation version so you
30190 can test compile your code or snippets of your code.
30193 \begin_layout Standard
30194 Debugging on a simulator:
30197 \begin_layout Itemize
30198 there is a separate section about SDCDB (section
30199 \begin_inset LatexCommand ref
30200 reference "cha:Debugging-with-SDCDB"
30207 \begin_layout Itemize
30208 or (8051 specific) use a freeware/commercial simulator which interfaces
30210 \begin_inset LatexCommand index
30211 name "AOMF, AOMF51"
30216 \begin_inset LatexCommand ref
30217 reference "OMF file"
30221 ) optionally generated by SDCC.
30224 \begin_layout Standard
30225 Debugging On-target:
30228 \begin_layout Itemize
30229 use a MCU port pin to serially output debug data to the RS232 port of your
30231 You'll probably want some level shifting device typically involving a MAX232
30233 If the hardware serial port of the MCU is not available search for 'Software
30234 UART' in your favourite search machine.
30237 \begin_layout Itemize
30238 use an on-target monitor.
30239 In this context a monitor is a small program which usually accepts commands
30240 via a serial line and allows to set program counter, to single step through
30241 a program and read/write memory locations.
30242 For the 8051 good examples of monitors are paulmon and cmon51 (see section
30244 \begin_inset LatexCommand ref
30245 reference "sec:Related-open-source-tools"
30252 \begin_layout Itemize
30253 toggle MCU port pins at strategic points within your code and use an oscilloscop
30257 digital oscilloscope
30260 \begin_inset LatexCommand index
30261 name "Oscilloscope"
30265 with deep trace memory is really helpful especially if you have to debug
30266 a realtime application.
30267 If you need to monitor more pins than your oscilloscope provides you can
30268 sometimes get away with a small R-2R network.
30269 On a single channel oscilloscope you could f.e.
30270 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
30272 \begin_inset Formula $\Omega$
30275 resistor and the other one by a 5\InsetSpace ~
30277 \begin_inset Formula $\Omega$
30280 resistor to the oscilloscope probe (check output drive capability of the
30281 pins you want to monitor).
30282 If you need to monitor many more pins a
30289 \begin_layout Itemize
30303 \begin_inset LatexCommand index
30304 name "ICE (in circuit emulator)"
30309 Usually very expensive.
30310 And very nice to have too.
30311 And usually locks you (for years...) to the devices the ICE can emulate.
30315 \begin_layout Itemize
30316 use a remote debugger.
30317 In most 8-bit systems the symbol information is not available on the target,
30318 and a complete debugger is too bulky for the target system.
30319 Therefore usually a debugger on the host system connects to an on-target
30320 debugging stub which accepts only primitive commands.
30323 Terms to enter into your favourite search engine could be 'remote debugging',
30324 'gdb stub' or 'inferior debugger'.
30328 \begin_layout Itemize
30329 use an on target hardware debugger.
30330 Some of the more modern MCUs include hardware support for setting break
30331 points and monitoring/changing variables by using dedicated hardware pins.
30332 This facility doesn't require additional code to run on the target and
30337 doesn't affect runtime behaviour until a breakpoint is hit.
30338 For the mcs51 most hardware debuggers use the AOMF
30339 \begin_inset LatexCommand index
30340 name "AOMF, AOMF51"
30345 \begin_inset LatexCommand ref
30346 reference "OMF file"
30354 \begin_layout Standard
30358 \begin_layout Itemize
30359 if you are not familiar with any of the following terms you're likely to
30360 run into problems rather sooner than later:
30377 As an embedded programmer you
30381 to know them so why not look them up
30385 you have problems?)
30388 \begin_layout Itemize
30389 tell someone else about your problem (actually this is a surprisingly effective
30390 means to hunt down the bug even if the listener is not familiar with your
30392 As 'failure to communicate' is probably one of the job-induced deformations
30393 of an embedded programmer this is highly encouraged.
30396 \begin_layout Section
30397 Debugging with SDCDB
30398 \begin_inset LatexCommand label
30399 name "cha:Debugging-with-SDCDB"
30404 \begin_inset LatexCommand index
30405 name "SDCDB (debugger)"
30412 \begin_layout Standard
30413 SDCC is distributed with a source level debugger
30414 \begin_inset LatexCommand index
30420 The debugger uses a command line interface, the command repertoire of the
30421 debugger has been kept as close to gdb
30422 \begin_inset LatexCommand index
30427 (the GNU debugger) as possible.
30428 The configuration and build process is part of the standard compiler installati
30429 on, which also builds and installs the debugger in the target directory
30430 specified during configuration.
30431 The debugger allows you debug BOTH at the C source and at the ASM source
30435 \begin_layout Subsection
30436 Compiling for Debugging
30439 \begin_layout Standard
30444 \begin_layout Standard
30454 \begin_inset LatexCommand index
30459 option must be specified for all files for which debug information is to
30461 The compiler generates a .adb file for each of these files.
30462 The linker creates the .cdb
30463 \begin_inset LatexCommand index
30469 \begin_inset LatexCommand index
30474 files and the address information.
30475 This .cdb is used by the debugger.
30478 \begin_layout Subsection
30479 How the Debugger Works
30482 \begin_layout Standard
30487 \begin_layout Standard
30496 -debug option is specified the compiler generates extra symbol information
30497 some of which are put into the assembler source and some are put into the
30499 Then the linker creates the .cdb file from the individual .adb files with
30500 the address information for the symbols.
30501 The debugger reads the symbolic information generated by the compiler &
30502 the address information generated by the linker.
30503 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
30504 execution is controlled by the debugger.
30505 When a command is issued for the debugger, it translates it into appropriate
30506 commands for the simulator.
30507 (Currently SDCDM only connects to the simulator but
30512 \begin_inset LatexCommand url
30513 target "http://ec2drv.sf.net/"
30517 is an effort to connect directly to the hardware.)
30520 \begin_layout Subsection
30521 Starting the Debugger SDCDB
30524 \begin_layout Standard
30525 The debugger can be started using the following command line.
30526 (Assume the file you are debugging has the file name foo).
30540 The debugger will look for the following files.
30543 \begin_layout Itemize
30544 foo.c - the source file.
30547 \begin_layout Itemize
30548 foo.cdb - the debugger symbol information file.
30551 \begin_layout Itemize
30552 foo.ihx - the Intel hex format
30553 \begin_inset LatexCommand index
30554 name "Intel hex format"
30561 \begin_layout Subsection
30562 SDCDB Command Line Options
30565 \begin_layout Itemize
30570 \begin_layout Standard
30579 -directory=<source file directory> this option can used to specify the directory
30581 The debugger will look into the directory list specified for source, cdb
30583 The items in the directory list must be separated by ':', e.g.
30584 if the source files can be in the directories /home/src1 and /home/src2,
30589 \begin_layout Standard
30598 -directory option should be -
30602 \begin_layout Standard
30611 -directory=/home/src1:/home/src2.
30612 Note there can be no spaces in the option.
30616 \begin_layout Itemize
30617 -cd <directory> - change to the <directory>.
30620 \begin_layout Itemize
30621 -fullname - used by GUI front ends.
30624 \begin_layout Itemize
30625 -cpu <cpu-type> - this argument is passed to the simulator please see the
30626 simulator docs for details.
30629 \begin_layout Itemize
30630 -X <Clock frequency > this options is passed to the simulator please see
30631 the simulator docs for details.
30634 \begin_layout Itemize
30635 -s <serial port file> passed to simulator see the simulator docs for details.
30638 \begin_layout Itemize
30639 -S <serial in,out> passed to simulator see the simulator docs for details.
30642 \begin_layout Itemize
30643 -k <port number> passed to simulator see the simulator docs for details.
30646 \begin_layout Subsection
30647 SDCDB Debugger Commands
30650 \begin_layout Standard
30651 As mentioned earlier the command interface for the debugger has been deliberatel
30652 y kept as close the GNU debugger gdb, as possible.
30653 This will help the integration with existing graphical user interfaces
30654 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
30655 If you use a graphical user interface for the debugger you can skip this
30659 \begin_layout Subsubsection*
30660 break [line | file:line | function | file:function]
30663 \begin_layout Standard
30664 Set breakpoint at specified line or function:
30673 sdcdb>break foo.c:100
30675 sdcdb>break funcfoo
30677 sdcdb>break foo.c:funcfoo
30680 \begin_layout Subsubsection*
30681 clear [line | file:line | function | file:function ]
30684 \begin_layout Standard
30685 Clear breakpoint at specified line or function:
30694 sdcdb>clear foo.c:100
30696 sdcdb>clear funcfoo
30698 sdcdb>clear foo.c:funcfoo
30701 \begin_layout Subsubsection*
30705 \begin_layout Standard
30706 Continue program being debugged, after breakpoint.
30709 \begin_layout Subsubsection*
30713 \begin_layout Standard
30714 Execute till the end of the current function.
30717 \begin_layout Subsubsection*
30721 \begin_layout Standard
30722 Delete breakpoint number 'n'.
30723 If used without any option clear ALL user defined break points.
30726 \begin_layout Subsubsection*
30727 info [break | stack | frame | registers ]
30730 \begin_layout Itemize
30731 info break - list all breakpoints
30734 \begin_layout Itemize
30735 info stack - show the function call stack.
30738 \begin_layout Itemize
30739 info frame - show information about the current execution frame.
30742 \begin_layout Itemize
30743 info registers - show content of all registers.
30746 \begin_layout Subsubsection*
30750 \begin_layout Standard
30751 Step program until it reaches a different source line.
30752 Note: pressing <return> repeats the last command.
30755 \begin_layout Subsubsection*
30759 \begin_layout Standard
30760 Step program, proceeding through subroutine calls.
30763 \begin_layout Subsubsection*
30767 \begin_layout Standard
30768 Start debugged program.
30771 \begin_layout Subsubsection*
30775 \begin_layout Standard
30776 Print type information of the variable.
30779 \begin_layout Subsubsection*
30783 \begin_layout Standard
30784 print value of variable.
30787 \begin_layout Subsubsection*
30791 \begin_layout Standard
30792 load the given file name.
30793 Note this is an alternate method of loading file for debugging.
30796 \begin_layout Subsubsection*
30800 \begin_layout Standard
30801 print information about current frame.
30804 \begin_layout Subsubsection*
30808 \begin_layout Standard
30809 Toggle between C source & assembly source.
30812 \begin_layout Subsubsection*
30813 ! simulator command
30816 \begin_layout Standard
30817 Send the string following '!' to the simulator, the simulator response is
30819 Note the debugger does not interpret the command being sent to the simulator,
30820 so if a command like 'go' is sent the debugger can loose its execution
30821 context and may display incorrect values.
30824 \begin_layout Subsubsection*
30828 \begin_layout Standard
30831 My name is Bobby Brown"
30834 \begin_layout Subsection
30835 Interfacing SDCDB with DDD
30838 \begin_layout Standard
30839 \begin_inset Note Note
30842 \begin_layout Standard
30843 The screenshot was converted from png to eps with:
30844 \begin_inset Quotes sld
30847 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
30848 \begin_inset Quotes srd
30851 which produces a pretty compact eps file which is free from compression
30855 \begin_layout Standard
30856 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
30857 as this broke the build system on Sourceforge (pdf-file was broken.
30858 pdflatex does not accept eps files).
30866 \begin_layout Standard
30882 \begin_inset LatexCommand url
30883 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png"
30889 shows a screenshot of a debugging session with DDD
30890 \begin_inset LatexCommand index
30891 name "DDD (debugger)"
30895 (Unix only) on a simulated 8032.
30896 The debugging session might not run as smoothly as the screenshot suggests.
30897 The debugger allows setting of breakpoints, displaying and changing variables,
30898 single stepping through C and assembler code.
30901 The source was compiled with
30915 \begin_layout Standard
30927 -debug ddd_example.c
30940 and DDD was invoked with
30947 ddd -debugger "sdcdb -cpu 8032 ddd_example"
30950 \begin_layout Standard
30951 \begin_inset Note Note
30954 \begin_layout Standard
30955 Check that the double quotes or an apostrophe within the command line survive
30956 the LyX tool chain.
30957 Previously the apostrophes got slanted in the PDF output so a cut and paste
30966 \begin_layout Subsection
30967 Interfacing SDCDB with XEmacs
30968 \begin_inset LatexCommand index
30974 \begin_inset LatexCommand index
30982 \begin_layout Standard
30983 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
30984 sdcdb.el and sdcdbsrc.el.
30985 These two files can be found in the $(prefix)/bin directory after the installat
30987 These files need to be loaded into XEmacs for the interface to work.
30988 This can be done at XEmacs startup time by inserting the following into
30989 your '.xemacs' file (which can be found in your HOME directory):
30995 (load-file sdcdbsrc.el)
31001 .xemacs is a lisp file so the () around the command is REQUIRED.
31002 The files can also be loaded dynamically while XEmacs is running, set the
31003 environment variable 'EMACSLOADPATH' to the installation bin directory
31004 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
31005 To start the interface enter the following command:
31019 You will prompted to enter the file name to be debugged.
31024 The command line options that are passed to the simulator directly are
31025 bound to default values in the file sdcdbsrc.el.
31026 The variables are listed below, these values maybe changed as required.
31029 \begin_layout Itemize
31030 sdcdbsrc-cpu-type '51
31033 \begin_layout Itemize
31034 sdcdbsrc-frequency '11059200
31037 \begin_layout Itemize
31038 sdcdbsrc-serial nil
31041 \begin_layout Standard
31042 The following is a list of key mapping for the debugger interface.
31045 \begin_layout Standard
31068 binding\InsetSpace ~
31106 -------\InsetSpace ~
31177 sdcdb-back-from-src\InsetSpace ~
31206 rom-src\InsetSpace ~
31216 SDCDB continue command
31234 sdcdb-step-from-src\InsetSpace ~
31263 hatis-c-sexp\InsetSpace ~
31273 SDCDB ptypecommand for data at
31340 sdcdbsrc-delete\InsetSpace ~
31355 B Delete all breakpoints if no arg
31404 given or delete arg (C-u arg x)
31423 -frame\InsetSpace ~
31438 SDCDB Display current frame if no arg,
31487 given or display frame arg
31555 sdcdbsrc-goto-sdcdb\InsetSpace ~
31565 Goto the SDCDB output buffer
31584 t-c-sexp\InsetSpace ~
31595 SDCDB print command for data at
31662 sdcdbsrc-goto-sdcdb\InsetSpace ~
31673 o the SDCDB output buffer
31691 sdcdbsrc-mode\InsetSpace ~
31707 Toggles Sdcdbsrc mode (turns it
31723 sdcdb-finish-from-src\InsetSpace ~
31731 SDCDB finish command
31765 Set break for line with point
31780 sdcdbsrc-mode\InsetSpace ~
31796 Toggle Sdcdbsrc mode
31812 dbsrc-srcmode\InsetSpace ~
31836 \begin_layout Chapter
31840 \begin_layout Standard
31841 Here are a few guidelines that will help the compiler generate more efficient
31842 code, some of the tips are specific to this compiler others are generally
31843 good programming practice.
31846 \begin_layout Itemize
31847 Use the smallest data type to represent your data-value.
31848 If it is known in advance that the value is going to be less than 256 then
31849 use an 'unsigned char' instead of a 'short' or 'int'.
31850 Please note, that ANSI C requires both signed and unsigned chars to be
31851 promoted to 'signed int'
31852 \begin_inset LatexCommand index
31853 name "promotion to signed int"
31858 \begin_inset Marginal
31861 \begin_layout Standard
31870 before doing any operation.
31872 \begin_inset LatexCommand index
31873 name "type promotion"
31878 \begin_inset LatexCommand label
31879 name "type promotion"
31883 can be omitted, if the result is the same.
31884 The effect of the promotion rules together with the sign-extension is often
31889 \begin_layout Verse
31892 unsigned char uc = 0xfe;
31894 if (uc * uc < 0) /* this is true! */
31907 \begin_layout Standard
31914 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
31922 \begin_layout Verse
31925 (unsigned char) -12 / (signed char) -3 = ...
31928 \begin_layout Standard
31929 No, the result is not 4:
31932 \begin_layout Verse
31935 (int) (unsigned char) -12 / (int) (signed char) -3 =
31937 (int) (unsigned char)
31938 0xf4 / (int) (signed char) 0xfd =
31940 (int) 0x00f4 / (int) 0xfffd =
31945 (int) 244 / (int) -3 =
31947 (int) -81 = (int) 0xffaf;
31950 \begin_layout Standard
31951 Don't complain, that gcc gives you a different result.
31952 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
31953 Therefore the results are different.
31956 \begin_inset Quotes sld
31960 \begin_inset Quotes srd
31966 \begin_layout Quote
31969 If well-defined overflow characteristics are important and negative values
31970 are not, or if you want to steer clear of sign-extension problems when
31971 manipulating bits or bytes, use one of the corresponding unsigned types.
31972 (Beware when mixing signed and unsigned values in expressions, though.)
31975 character types (especially unsigned char) can be used as "tiny" integers,
31976 doing so is sometimes more trouble than it's worth, due to unpredictable
31977 sign extension and increased code size.
31981 \begin_layout Itemize
31982 Use unsigned when it is known in advance that the value is not going to
31984 This helps especially if you are doing division or multiplication, bit-shifting
31985 or are using an array index.
31988 \begin_layout Itemize
31989 NEVER jump into a LOOP.
31992 \begin_layout Itemize
31993 Declare the variables to be local
31994 \begin_inset LatexCommand index
31995 name "local variables"
31999 whenever possible, especially loop control variables (induction).
32002 \begin_layout Itemize
32003 Have a look at the assembly listing to get a
32004 \begin_inset Quotes sld
32008 \begin_inset Quotes srd
32011 for the code generation.
32014 \begin_layout Section
32015 Porting code from or to other compilers
32016 \begin_inset LatexCommand label
32017 name "sec:Porting-code-to-other-compilers"
32024 \begin_layout Itemize
32025 check whether endianness of the compilers differs and adapt where needed.
32028 \begin_layout Itemize
32029 check the device specific header files
32030 \begin_inset LatexCommand index
32031 name "Header files"
32036 \begin_inset LatexCommand index
32037 name "Include files"
32041 for compiler specific syntax.
32042 Eventually include the file <compiler.h
32043 \begin_inset LatexCommand index
32044 name "compiler.h (include file)"
32049 \begin_inset LatexCommand url
32050 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup"
32054 to allow using common header files.
32057 \begin_inset LatexCommand url
32058 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup"
32065 \begin_layout Itemize
32066 check whether the startup code contains the correct initialization (watchdog,
32070 \begin_layout Itemize
32071 check whether the sizes of short, int, long match.
32074 \begin_layout Itemize
32075 check if some 16 or 32 bit hardware registers require a specific addressing
32076 order (least significant or most significant byte first) and adapt if needed
32085 relate to time and not to lower/upper memory location here, so this is
32090 the same as endianness).
32093 \begin_layout Itemize
32094 check whether the keyword
32098 is used where needed.
32099 The compilers might differ in their optimization characteristics (as different
32100 versions of the same compiler might also use more clever optimizations
32101 this is good idea anyway).
32103 \begin_inset LatexCommand ref
32104 reference "sub:Common-interrupt-pitfall-volatile"
32111 \begin_layout Itemize
32112 check that the compilers are not told to suppress warnings.
32115 \begin_layout Itemize
32116 check and convert compiler specific extensions (interrupts, memory areas,
32120 \begin_layout Itemize
32121 check for differences in type promotion.
32122 Especially check for math operations on
32131 For the sake of C99 compatibility SDCC will probably promote these to
32135 more often than other compilers.
32136 Eventually insert explicit casts to
32145 Also check that the ~\InsetSpace ~
32147 \begin_inset LatexCommand index
32148 name "\\~\\/ Operator"
32155 \begin_inset LatexCommand index
32162 variables, use the !\InsetSpace ~
32165 \begin_inset LatexCommand ref
32166 reference "type promotion"
32171 \begin_inset LatexCommand ref
32172 reference "sec:Compatibility-with-previous"
32179 \begin_layout Itemize
32180 check the assembly code generated for interrupt routines (f.e.
32181 for calls to possibly non-reentrant library functions).
32184 \begin_layout Itemize
32185 check whether timing loops result in proper timing (or preferably consider
32186 a rewrite of the code with timer based delays instead).
32189 \begin_layout Itemize
32190 check for differences in printf parameters (some compilers push (va_arg
32191 \begin_inset LatexCommand index
32192 name "vararg, va\\_arg"
32196 ) char variables as
32200 others push them as
32206 \begin_inset LatexCommand ref
32207 reference "sec:Compatibility-with-previous"
32214 \begin_layout Itemize
32215 check the resulting memory map
32216 \begin_inset LatexCommand index
32222 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
32223 ly idata, pdata, xdata).
32224 Eventually check if unexpected library functions are included.
32227 \begin_layout Section
32229 \begin_inset LatexCommand index
32234 included in the distribution
32237 \begin_layout Standard
32239 \begin_inset Tabular
32240 <lyxtabular version="3" rows="12" columns="3">
32242 <column alignment="left" valignment="top" leftline="true" width="0pt">
32243 <column alignment="left" valignment="top" leftline="true" width="0pt">
32244 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32245 <row topline="true" bottomline="true">
32246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32249 \begin_layout Standard
32257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32260 \begin_layout Standard
32268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32271 \begin_layout Standard
32280 <row topline="true">
32281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32284 \begin_layout Standard
32286 \begin_inset LatexCommand index
32296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32299 \begin_layout Standard
32300 Simulator for various architectures
32305 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32308 \begin_layout Standard
32315 <row topline="true">
32316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32319 \begin_layout Standard
32325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32328 \begin_layout Standard
32330 \begin_inset LatexCommand index
32331 name "Header files"
32336 \begin_inset LatexCommand index
32337 name "Include files"
32346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32349 \begin_layout Standard
32350 sdcc/support/scripts
32356 <row topline="true">
32357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32360 \begin_layout Standard
32366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32369 \begin_layout Standard
32370 header file conversion
32375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32378 \begin_layout Standard
32379 sdcc/support/scripts
32385 <row topline="true">
32386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32389 \begin_layout Standard
32395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32398 \begin_layout Standard
32404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32407 \begin_layout Standard
32423 <row topline="true">
32424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32427 \begin_layout Standard
32433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32436 \begin_layout Standard
32442 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32445 \begin_layout Standard
32461 <row topline="true">
32462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32465 \begin_layout Standard
32471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32474 \begin_layout Standard
32480 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32483 \begin_layout Standard
32499 <row topline="true">
32500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32503 \begin_layout Standard
32509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32512 \begin_layout Standard
32518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32521 \begin_layout Standard
32537 <row topline="true">
32538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32541 \begin_layout Standard
32547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32550 \begin_layout Standard
32556 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32559 \begin_layout Standard
32575 <row topline="true">
32576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32579 \begin_layout Standard
32585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32588 \begin_layout Standard
32594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32597 \begin_layout Standard
32613 <row topline="true">
32614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32617 \begin_layout Standard
32623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32626 \begin_layout Standard
32632 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32635 \begin_layout Standard
32651 <row topline="true" bottomline="true">
32652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32655 \begin_layout Standard
32661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32664 \begin_layout Standard
32666 \begin_inset LatexCommand index
32667 name "packihx (tool)"
32676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32679 \begin_layout Standard
32704 \begin_layout Section
32706 \begin_inset LatexCommand index
32707 name "Documentation"
32711 included in the distribution
32714 \begin_layout Standard
32716 \begin_inset Tabular
32717 <lyxtabular version="3" rows="10" columns="2">
32719 <column alignment="block" valignment="top" leftline="true" width="40col%">
32720 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
32721 <row topline="true" bottomline="true" endhead="true">
32722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32725 \begin_layout Standard
32733 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32736 \begin_layout Standard
32739 Filename / Where to get
32745 <row topline="true">
32746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32749 \begin_layout Standard
32750 SDCC Compiler User Guide
32755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32758 \begin_layout Standard
32759 You're reading it right now
32771 \begin_inset LatexCommand url
32772 target "http://sdcc.sourceforge.net/doc/sdccman.pdf"
32782 <row topline="true">
32783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32786 \begin_layout Standard
32792 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32795 \begin_layout Standard
32808 \begin_inset LatexCommand url
32809 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog"
32819 <row topline="true">
32820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32823 \begin_layout Standard
32825 \begin_inset LatexCommand index
32826 name "asXXXX (as-gbz80, as-hc08, asx8051, as-z80)"
32831 \begin_inset LatexCommand index
32832 name "Assembler documentation"
32839 \begin_inset LatexCommand index
32845 \begin_inset LatexCommand index
32846 name "Linker documentation"
32855 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32858 \begin_layout Standard
32859 sdcc/as/doc/asxhtm.html
32871 \begin_inset LatexCommand url
32872 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html"
32882 <row topline="true">
32883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32886 \begin_layout Standard
32887 SDCC regression test
32888 \begin_inset LatexCommand index
32889 name "Regression test"
32898 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32901 \begin_layout Standard
32902 sdcc/doc/test_suite_spec.pdf
32914 \begin_inset LatexCommand url
32915 target "http://sdcc.sourceforge.net/doc/test_suite_spec.pdf"
32925 <row topline="true">
32926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32929 \begin_layout Standard
32935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32938 \begin_layout Standard
32951 \begin_inset LatexCommand url
32952 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/"
32962 <row topline="true">
32963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32966 \begin_layout Standard
32967 Notes on debugging with SDCDB
32968 \begin_inset LatexCommand index
32969 name "SDCDB (debugger)"
32978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32981 \begin_layout Standard
32982 sdcc/debugger/README
32994 \begin_inset LatexCommand url
32995 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README"
33005 <row topline="true">
33006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33009 \begin_layout Standard
33011 \begin_inset LatexCommand index
33016 Software simulator for microcontrollers
33021 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33024 \begin_layout Standard
33054 \begin_inset LatexCommand url
33055 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html"
33065 <row topline="true">
33066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33069 \begin_layout Standard
33070 Temporary notes on the pic16
33071 \begin_inset LatexCommand index
33081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33084 \begin_layout Standard
33085 sdcc/src/pic16/NOTES
33097 \begin_inset LatexCommand url
33098 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES"
33108 <row topline="true" bottomline="true">
33109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33112 \begin_layout Standard
33113 SDCC internal documentation (debugging file format)
33118 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33121 \begin_layout Standard
33151 \begin_inset LatexCommand url
33152 target "http://sdcc.sourceforge.net/doc/cdbfileformat.pdf"
33171 \begin_layout Section
33172 Related open source tools
33173 \begin_inset LatexCommand label
33174 name "sec:Related-open-source-tools"
33179 \begin_inset LatexCommand index
33180 name "Related tools"
33187 \begin_layout Standard
33189 \begin_inset Tabular
33190 <lyxtabular version="3" rows="16" columns="3">
33192 <column alignment="left" valignment="top" leftline="true" width="0pt">
33193 <column alignment="block" valignment="top" leftline="true" width="30line%">
33194 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
33195 <row topline="true" bottomline="true">
33196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33199 \begin_layout Standard
33207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33210 \begin_layout Standard
33218 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33221 \begin_layout Standard
33230 <row topline="true">
33231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33234 \begin_layout Standard
33236 \begin_inset LatexCommand index
33237 name "gpsim (pic simulator)"
33246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33249 \begin_layout Standard
33255 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33258 \begin_layout Standard
33259 \begin_inset LatexCommand url
33260 target "http://www.dattalo.com/gnupic/gpsim.html"
33270 <row topline="true">
33271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33274 \begin_layout Standard
33276 \begin_inset LatexCommand index
33277 name "gputils (pic tools)"
33286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33289 \begin_layout Standard
33295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33298 \begin_layout Standard
33299 \begin_inset LatexCommand url
33300 target "http://sourceforge.net/projects/gputils"
33310 <row topline="true">
33311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33314 \begin_layout Standard
33320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33323 \begin_layout Standard
33329 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33332 \begin_layout Standard
33333 \begin_inset LatexCommand url
33334 target "http://freshmeat.net/projects/flp5/"
33344 <row topline="true">
33345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33348 \begin_layout Standard
33354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33357 \begin_layout Standard
33358 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
33364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33367 \begin_layout Standard
33368 \begin_inset LatexCommand url
33369 target "http://sourceforge.net/projects/ec2drv"
33379 <row topline="true">
33380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33383 \begin_layout Standard
33385 \begin_inset LatexCommand index
33386 name "indent (source formatting tool)"
33395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33398 \begin_layout Standard
33399 Formats C source - Master of the white spaces
33404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33407 \begin_layout Standard
33408 \begin_inset LatexCommand url
33409 target "http://directory.fsf.org/GNU/indent.html"
33419 <row topline="true">
33420 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33423 \begin_layout Standard
33425 \begin_inset LatexCommand index
33426 name "srecord (bin, hex, ... tool)"
33435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33438 \begin_layout Standard
33439 Object file conversion, checksumming, ...
33444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33447 \begin_layout Standard
33448 \begin_inset LatexCommand url
33449 target "http://sourceforge.net/projects/srecord"
33459 <row topline="true">
33460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33463 \begin_layout Standard
33465 \begin_inset LatexCommand index
33466 name "objdump (tool)"
33475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33478 \begin_layout Standard
33479 Object file conversion, ...
33484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33487 \begin_layout Standard
33488 Part of binutils (should be there anyway)
33494 <row topline="true">
33495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33498 \begin_layout Standard
33504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33507 \begin_layout Standard
33508 8051 monitor (hex up-/download, single step, disassemble)
33513 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33516 \begin_layout Standard
33517 \begin_inset LatexCommand url
33518 target "http://sourceforge.net/projects/cmon51"
33528 <row topline="true">
33529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33532 \begin_layout Standard
33534 \begin_inset LatexCommand index
33535 name "doxygen (source documentation tool)"
33544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33547 \begin_layout Standard
33548 Source code documentation system
33553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33556 \begin_layout Standard
33557 \begin_inset LatexCommand url
33558 target "http://www.doxygen.org"
33568 <row topline="true">
33569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33572 \begin_layout Standard
33578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33581 \begin_layout Standard
33582 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
33587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33590 \begin_layout Standard
33591 \begin_inset LatexCommand url
33592 target "http://www.kdevelop.org"
33602 <row topline="true">
33603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33606 \begin_layout Standard
33612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33615 \begin_layout Standard
33616 8051 monitor (hex up-/download, single step, disassemble)
33621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33624 \begin_layout Standard
33625 \begin_inset LatexCommand url
33626 target "http://www.pjrc.com/tech/8051/paulmon2.html"
33636 <row topline="true">
33637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33640 \begin_layout Standard
33642 \begin_inset LatexCommand index
33643 name "splint (syntax checking tool)"
33652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33655 \begin_layout Standard
33656 Statically checks c sources (see
33657 \begin_inset LatexCommand ref
33658 reference "lyx:more-pedantic-SPLINT"
33667 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33670 \begin_layout Standard
33671 \begin_inset LatexCommand url
33672 target "http://www.splint.org"
33682 <row topline="true" bottomline="true">
33683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33686 \begin_layout Standard
33688 \begin_inset LatexCommand index
33689 name "DDD (debugger)"
33698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33701 \begin_layout Standard
33702 Debugger, serves nicely as GUI to SDCDB
33703 \begin_inset LatexCommand index
33704 name "SDCDB (debugger)"
33713 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33716 \begin_layout Standard
33717 \begin_inset LatexCommand url
33718 target "http://www.gnu.org/software/ddd/"
33728 <row bottomline="true">
33729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33732 \begin_layout Standard
33734 \begin_inset LatexCommand index
33740 \begin_inset LatexCommand index
33741 name "d52 (disassembler)"
33750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33753 \begin_layout Standard
33754 Disassembler, can count instruction cycles
33755 \begin_inset LatexCommand index
33756 name "instruction cycles (count)"
33760 , use with options -pnd
33765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33768 \begin_layout Standard
33769 \begin_inset LatexCommand url
33770 target "http://www.8052.com/users/disasm/"
33780 <row bottomline="true">
33781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33784 \begin_layout Standard
33786 \begin_inset LatexCommand index
33796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33799 \begin_layout Standard
33800 Cross platform build system, generates Makefiles
33801 \begin_inset LatexCommand index
33806 and project workspaces
33807 \begin_inset LatexCommand index
33808 name "project workspace"
33817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33820 \begin_layout Standard
33821 \begin_inset LatexCommand url
33822 target "http://www.cmake.org"
33830 and a dedicated wiki entry:
33831 \begin_inset LatexCommand url
33832 target "http://www.cmake.org/Wiki/CmakeSdcc"
33851 \begin_layout Section
33852 Related documentation / recommended reading
33855 \begin_layout Standard
33857 \begin_inset Tabular
33858 <lyxtabular version="3" rows="7" columns="3">
33860 <column alignment="left" valignment="top" leftline="true" width="0pt">
33861 <column alignment="left" valignment="top" leftline="true" width="0">
33862 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
33863 <row topline="true" bottomline="true">
33864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33867 \begin_layout Standard
33875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33878 \begin_layout Standard
33886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33889 \begin_layout Standard
33898 <row topline="true">
33899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33902 \begin_layout Standard
33917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33920 \begin_layout Standard
33922 \begin_inset LatexCommand index
33923 name "C Reference card"
33932 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33935 \begin_layout Standard
33936 \begin_inset LatexCommand url
33937 target "http://refcards.com/refcards/c/index.html"
33947 <row topline="true">
33948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33951 \begin_layout Standard
33957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33960 \begin_layout Standard
33962 \begin_inset LatexCommand index
33972 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33975 \begin_layout Standard
33976 \begin_inset LatexCommand url
33977 target "http://www.c-faq.com"
33987 <row topline="true">
33988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33991 \begin_layout Standard
33997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34000 \begin_layout Standard
34001 \begin_inset Quotes sld
34005 \begin_inset Quotes srd
34013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34016 \begin_layout Standard
34019 \begin_inset LatexCommand url
34020 target "http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899"
34030 <row topline="true">
34031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34034 \begin_layout Standard
34040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34043 \begin_layout Standard
34044 \begin_inset Quotes sld
34047 Extensions for Embedded C
34048 \begin_inset Quotes srd
34056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34059 \begin_layout Standard
34062 \begin_inset LatexCommand url
34063 target "http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf"
34073 <row topline="true">
34074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34077 \begin_layout Standard
34083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34086 \begin_layout Standard
34087 Latest datasheet of target CPU
34092 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34095 \begin_layout Standard
34102 <row topline="true" bottomline="true">
34103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34106 \begin_layout Standard
34112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34115 \begin_layout Standard
34116 Revision history of datasheet
34121 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34124 \begin_layout Standard
34140 \begin_layout Section
34141 Application notes specifically for SDCC
34144 \begin_layout Standard
34145 SDCC makes no claims about the completeness of this list and about up-to-datenes
34146 s or correctness of the application notes
34147 \begin_inset LatexCommand index
34148 name "Application notes"
34155 \begin_layout Standard
34159 \begin_inset Tabular
34160 <lyxtabular version="3" rows="7" columns="3">
34162 <column alignment="block" valignment="top" leftline="true" width="17col%">
34163 <column alignment="block" valignment="top" leftline="true" width="27col%">
34164 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
34165 <row topline="true" bottomline="true">
34166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34169 \begin_layout Standard
34178 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
34181 \begin_layout Standard
34190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34193 \begin_layout Standard
34203 <row topline="true">
34204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34207 \begin_layout Standard
34215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34218 \begin_layout Standard
34221 Using the SDCC Compiler for the DS80C400
34222 \begin_inset LatexCommand index
34232 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34235 \begin_layout Standard
34238 \begin_inset LatexCommand url
34239 target "http://pdfserv.maxim-ic.com/en/an/AN3346.pdf"
34249 <row topline="true">
34250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34253 \begin_layout Standard
34261 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
34264 \begin_layout Standard
34267 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
34268 \begin_inset LatexCommand index
34273 Family of Microcontrollers
34278 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34281 \begin_layout Standard
34284 \begin_inset LatexCommand url
34285 target "http://pdfserv.maxim-ic.com/en/an/AN3477.pdf"
34295 <row topline="true">
34296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34299 \begin_layout Standard
34302 Silicon Laboratories / Cygnal
34307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34310 \begin_layout Standard
34313 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
34314 \begin_inset LatexCommand index
34324 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34327 \begin_layout Standard
34330 \begin_inset LatexCommand url
34331 target "http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf"
34341 <row topline="true">
34342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34345 \begin_layout Standard
34348 Ramtron / Goal Semiconductor
34353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34356 \begin_layout Standard
34359 Interfacing SDCC to Syn and Textpad
34364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34367 \begin_layout Standard
34370 \begin_inset LatexCommand url
34371 target "http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp"
34381 <row topline="true">
34382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34385 \begin_layout Standard
34388 Ramtron / Goal Semiconductor
34393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34396 \begin_layout Standard
34399 Installing and Configuring SDCC and Crimson Editor
34404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34407 \begin_layout Standard
34410 \begin_inset LatexCommand url
34411 target "http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp"
34421 <row topline="true" bottomline="true">
34422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34425 \begin_layout Standard
34433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34436 \begin_layout Standard
34439 MSC12xx Programming with SDCC
34444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34447 \begin_layout Standard
34450 \begin_inset LatexCommand url
34451 target "http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf"
34468 \begin_layout Section
34472 \begin_layout Standard
34473 Some questions answered, some pointers given - it might be time to in turn
34481 \begin_layout Itemize
34482 can you solve your project with the selected microcontroller? Would you
34483 find out early or rather late that your target is too small/slow/whatever?
34484 Can you switch to a slightly better device if it doesn't fit?
34487 \begin_layout Itemize
34488 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
34489 and/or another programming language be more adequate? Would an operating
34490 system on the target device help?
34493 \begin_layout Itemize
34494 if you solved the problem, will the marketing department be happy?
34497 \begin_layout Itemize
34498 if the marketing department is happy, will customers be happy?
34501 \begin_layout Itemize
34502 if you're the project manager, marketing department and maybe even the customer
34503 in one person, have you tried to see the project from the outside?
34506 \begin_layout Itemize
34507 is the project done if you think it is done? Or is just that other interface/pro
34508 tocol/feature/configuration/option missing? How about website, manual(s),
34509 internationali(z|s)ation, packaging, labels, 2nd source for components,
34510 electromagnetic compatability/interference, documentation for production,
34511 production test software, update mechanism, patent issues?
34514 \begin_layout Itemize
34515 is your project adequately positioned in that magic triangle: fame, fortune,
34519 \begin_layout Standard
34520 Maybe not all answers to these questions are known and some answers may
34525 , nevertheless knowing these questions may help you to avoid burnout
34529 \begin_layout Standard
34530 burnout is bad for electronic devices, programmers and motorcycle tyres
34536 Chances are you didn't want to hear some of them...
34539 \begin_layout Chapter
34541 \begin_inset LatexCommand index
34549 \begin_layout Standard
34550 SDCC has grown to be a large project.
34551 The compiler alone (without the preprocessor, assembler and linker) is
34552 well over 150,000 lines of code (blank stripped).
34553 The open source nature of this project is a key to its continued growth
34555 You gain the benefit and support of many active software developers and
34557 Is SDCC perfect? No, that's why we need your help.
34558 The developers take pride in fixing reported bugs.
34559 You can help by reporting the bugs and helping other SDCC users.
34560 There are lots of ways to contribute, and we encourage you to take part
34561 in making SDCC a great software package.
34565 \begin_layout Standard
34566 The SDCC project is hosted on the SDCC sourceforge site at
34567 \begin_inset LatexCommand htmlurl
34568 target "http://sourceforge.net/projects/sdcc"
34573 You'll find the complete set of mailing lists
34574 \begin_inset LatexCommand index
34575 name "Mailing list(s)"
34579 , forums, bug reporting system, patch submission
34580 \begin_inset LatexCommand index
34581 name "Patch submission"
34586 \begin_inset LatexCommand index
34591 area and Subversion code repository
34592 \begin_inset LatexCommand index
34593 name "Subversion code repository"
34600 \begin_layout Section
34602 \begin_inset LatexCommand index
34603 name "Bug reporting"
34608 \begin_inset LatexCommand index
34609 name "Reporting bugs"
34616 \begin_layout Standard
34617 The recommended way of reporting bugs is using the infrastructure of the
34619 You can follow the status of bug reports there and have an overview about
34623 \begin_layout Standard
34624 Bug reports are automatically forwarded to the developer mailing list and
34625 will be fixed ASAP.
34626 When reporting a bug, it is very useful to include a small test program
34627 (the smaller the better) which reproduces the problem.
34628 If you can isolate the problem by looking at the generated assembly code,
34629 this can be very helpful.
34630 Compiling your program with the -
34634 \begin_layout Standard
34644 \begin_inset LatexCommand index
34645 name "-\\/-dumpall"
34649 option can sometimes be useful in locating optimization problems.
34650 When reporting a bug please make sure you:
34653 \begin_layout Enumerate
34654 Attach the code you are compiling with SDCC.
34658 \begin_layout Enumerate
34659 Specify the exact command you use to run SDCC, or attach your Makefile.
34663 \begin_layout Enumerate
34664 Specify the SDCC version (type "
34670 "), your platform, and operating system.
34674 \begin_layout Enumerate
34675 Provide an exact copy of any error message or incorrect output.
34679 \begin_layout Enumerate
34680 Put something meaningful in the subject of your message.
34683 \begin_layout Standard
34684 Please attempt to include these 5 important parts, as applicable, in all
34685 requests for support or when reporting any problems or bugs with SDCC.
34686 Though this will make your message lengthy, it will greatly improve your
34687 chance that SDCC users and developers will be able to help you.
34688 Some SDCC developers are frustrated by bug reports without code provided
34689 that they can use to reproduce and ultimately fix the problem, so please
34690 be sure to provide sample code if you are reporting a bug!
34693 \begin_layout Standard
34694 Please have a short check that you are using a recent version of SDCC and
34695 the bug is not yet known.
34696 This is the link for reporting bugs:
34697 \begin_inset LatexCommand htmlurl
34698 target "http://sourceforge.net/tracker/?group_id=599&atid=100599"
34703 With SDCC on average having more than 200 downloads
34704 \begin_inset LatexCommand index
34709 on sourceforge per day
34713 \begin_layout Standard
34714 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
34715 between 2002 and 2005.
34716 This does not include other methods of distribution.
34721 there must be some users.
34722 So it's not exactly easy to find a new bug.
34723 If you find one we need it:
34725 reporting bugs is good
34730 \begin_layout Section
34731 Requesting Features
34732 \begin_inset LatexCommand label
34733 name "sub:Requesting-Features"
34738 \begin_inset LatexCommand index
34739 name "Feature request"
34744 \begin_inset LatexCommand index
34745 name "Requesting features"
34752 \begin_layout Standard
34753 Like bug reports feature requests are forwarded to the developer mailing
34755 This is the link for requesting features:
34756 \begin_inset LatexCommand htmlurl
34757 target "http://sourceforge.net/tracker/?group_id=599&atid=350599"
34764 \begin_layout Section
34768 \begin_layout Standard
34769 Like bug reports contributed patches are forwarded to the developer mailing
34771 This is the link for submitting patches
34772 \begin_inset LatexCommand index
34773 name "Patch submission"
34778 \begin_inset LatexCommand url
34779 target "http://sourceforge.net/tracker/?group_id=599&atid=300599"
34786 \begin_layout Standard
34787 You need to specify some parameters to the
34791 command for the patches to be useful.
34792 If you modified more than one file a patch created f.e.
34797 \begin_inset Quotes sld
34800 diff -Naur unmodified_directory modified_directory >my_changes.patch
34801 \begin_inset Quotes srd
34807 will be fine, otherwise
34811 \begin_inset Quotes sld
34814 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
34815 \begin_inset Quotes srd
34824 \begin_layout Section
34828 \begin_layout Standard
34829 These links should take you directly to the
34830 \begin_inset LatexCommand url
34831 name "Mailing lists"
34832 target "http://sourceforge.net/mail/?group_id=599"
34840 \begin_layout Standard
34841 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
34842 automated messages (mid 2003)
34848 \begin_inset LatexCommand url
34850 target "http://sourceforge.net/forum/?group_id=599"
34855 \begin_inset LatexCommand index
34856 name "Mailing list(s)"
34860 and forums are archived and searchable so if you are lucky someone already
34861 had a similar problem.
34862 While mails to the lists themselves are delivered promptly their web front
34863 end on sourceforge sometimes shows a severe time lag (up to several weeks),
34864 if you're seriously using SDCC please consider subscribing to the lists.
34867 \begin_layout Section
34871 \begin_layout Standard
34872 You can follow the status of the Subversion version
34873 \begin_inset LatexCommand index
34878 of SDCC by watching the Changelog
34879 \begin_inset LatexCommand index
34884 in the Subversion repository
34887 \begin_inset LatexCommand htmlurl
34888 target "http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog"
34895 \begin_layout Section
34896 Subversion Source Code Repository
34899 \begin_layout Standard
34909 \begin_layout Standard
34923 or the filenames of the snapshot versions of SDCC include date and its
34925 \begin_inset LatexCommand index
34926 name "Subversion code repository"
34931 Subversion allows to download the source of recent or previous versions
34933 \begin_inset LatexCommand url
34934 target "http://sourceforge.net/svn/?group_id=599"
34938 (by number or by date).
34939 An on-line source code browser and detailled instructions are also available
34941 SDCC versions starting from 1999 up to now are available (currently the
34942 versions prior to the conversion from cvs
34943 \begin_inset LatexCommand index
34944 name "cvs|see{Subversion}"
34948 to Subversion (April 2006) are either by accessible by Subversion or by
34952 \begin_layout Section
34954 \begin_inset LatexCommand index
34955 name "Release policy"
34962 \begin_layout Standard
34963 Historically there often were long delays between official releases and
34964 the sourceforge download area tends to get not updated at all.
34965 Excuses in the past might have referred to problems with live range analysis,
34966 but as this was fixed a while ago, the current problem is that another
34967 excuse has to be found.
34968 Kidding aside, we have to get better there! On the other hand there are
34969 daily snapshots available at
34970 \begin_inset LatexCommand htmlurl
34972 target "http://sdcc.sourceforge.net/snap.php"
34976 , and you can always build the very last version (hopefully with many bugs
34977 fixed, and features added) from the source code available at
34978 \begin_inset LatexCommand htmlurl
34980 target "http://sdcc.sourceforge.net/snap.php#Source"
34986 \begin_inset LatexCommand index
34992 \begin_inset LatexCommand index
34998 \begin_inset LatexCommand url
34999 target "http://sdcc.wiki.sourceforge.net/"
35003 also holds some information about past and future releases.
35006 \begin_layout Section
35008 \begin_inset LatexCommand index
35016 \begin_layout Standard
35017 You'll find some small examples in the directory
35019 sdcc/device/examples/.
35022 More examples and libraries are available at
35024 The SDCC Open Knowledge Resource
35025 \begin_inset LatexCommand url
35026 target "http://sdccokr.dl9sec.de/"
35033 \begin_inset LatexCommand url
35034 target "http://www.pjrc.com/tech/8051/"
35041 \begin_layout Standard
35042 \begin_inset Note Note
35045 \begin_layout Standard
35046 I did insert a reference to Paul's web site here although it seems rather
35047 dedicated to a specific 8032 board (I think it's okay because it f.e.
35048 shows LCD/Harddisc interface and has a free 8051 monitor.
35049 Independent 8032 board vendors face hard competition of heavily subsidized
35050 development boards anyway).
35053 \begin_layout Standard
35054 Maybe we should include some links to real world applications.
35055 Preferably pointer to pointers (one for each architecture) so this stays
35064 \begin_layout Section
35066 \begin_inset LatexCommand label
35067 name "sec:Quality-control"
35072 \begin_inset LatexCommand index
35073 name "Quality control"
35080 \begin_layout Standard
35081 The compiler is passed through snaphot build compile and build checks.
35087 \begin_inset LatexCommand index
35088 name "Regression test"
35092 check that SDCC itself compiles flawlessly on several host platforms (i386,
35093 Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
35094 and checks the quality of the code generated by SDCC by running the code
35095 for several target platforms through simulators.
35096 The regression test suite comprises more than 100 files which expand to
35097 more than 500 test cases which include more than 4500 tests.
35098 The results of these tests are published daily on SDCC's snapshot page
35099 (click on the red or green symbols on the right side of
35100 \begin_inset LatexCommand url
35101 target "http://sdcc.sourceforge.net/snap.php"
35108 \begin_layout Standard
35109 There is a separate document
35112 \begin_inset LatexCommand index
35120 \begin_inset LatexCommand url
35121 target "http://sdcc.sourceforge.net/doc/test_suite_spec.pdf"
35125 about the regression test suite.
35128 \begin_layout Standard
35129 You'll find the test code in the directory
35131 sdcc/support/regression
35134 You can run these tests manually by running
35138 in this directory (or f.e.
35143 \begin_inset Quotes sld
35147 \begin_inset Quotes srd
35153 if you don't want to run the complete tests).
35154 The test code might also be interesting if you want to look for examples
35155 \begin_inset LatexCommand index
35160 checking corner cases of SDCC or if you plan to submit patches
35161 \begin_inset LatexCommand index
35162 name "Patch submission"
35169 \begin_layout Standard
35170 The PIC14 port uses a different set of regression tests
35171 \begin_inset LatexCommand index
35172 name "Regression test (PIC14)"
35176 , you'll find them in the directory
35178 sdcc/src/regression
35183 \begin_layout Section
35184 Use of SDCC in Education
35187 \begin_layout Standard
35196 \begin_layout Standard
35197 the phrase "use in education" might evoke the association "
35201 fit for use in education".
35202 This connotation is not intended but nevertheless risked as the licensing
35203 of SDCC makes it difficult to offer educational discounts
35209 If your rationales are to:
35212 \begin_layout Enumerate
35213 give students a chance to understand the
35217 steps of code generation
35220 \begin_layout Enumerate
35221 have a curriculum that can be extended for years.
35222 Then you could use an fpga board as target and your curriculum will seamlessly
35223 extend from logic synthesis (
35224 \begin_inset LatexCommand url
35225 name "http://www.opencores.org"
35226 target "opencores.org"
35231 \begin_inset LatexCommand url
35233 target "http://www.oregano.at/ip/ip01.htm"
35237 ), over assembly programming, to C to FPGA compilers (
35238 \begin_inset LatexCommand url
35240 target "http://sf.net/projects/fpgac"
35247 \begin_layout Enumerate
35248 be able to insert excursions about skills like using a revision control
35249 system, submitting/applying patches, using a type-setting (as opposed to
35250 word-processing) engine LyX/LaTeX, using
35251 \begin_inset LatexCommand url
35253 target "http://www.sf.net"
35258 \begin_inset LatexCommand url
35260 target "http://en.wikipedia.org/wiki/Netiquette"
35264 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
35265 Source Software, CPU simulation, compiler regression tests
35266 \begin_inset LatexCommand index
35267 name "Regression test"
35274 And if there should be a shortage of ideas then you can always point students
35275 to the ever-growing feature request list
35276 \begin_inset LatexCommand htmlurl
35277 target "http://sourceforge.net/tracker/?group_id=599&atid=350599"
35284 \begin_layout Enumerate
35285 not tie students to a specific host platform and instead allow them to use
35290 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
35292 \begin_inset LatexCommand url
35294 target "http://www.laptop.org"
35301 \begin_layout Enumerate
35302 not encourage students to use illegal copies of educational software
35305 \begin_layout Enumerate
35306 be immune to licensing/availability/price changes of the chosen tool chain
35309 \begin_layout Enumerate
35310 be able to change to a new target platform without having to adopt a new
35314 \begin_layout Enumerate
35315 have complete control over and insight into the tool chain
35318 \begin_layout Enumerate
35319 make your students aware about the pros and cons of open source software
35323 \begin_layout Enumerate
35324 give back to the public as you are probably at least partially publicly
35328 \begin_layout Enumerate
35329 give students a chance to publicly prove their skills and to possibly see
35330 a world wide impact
35333 \begin_layout Standard
35334 then SDCC is probably among the first choices.
35335 Well, probably SDCC might be the only choice.
35340 \begin_layout Chapter
35341 SDCC Technical Data
35344 \begin_layout Section
35346 \begin_inset LatexCommand index
35347 name "Optimizations"
35354 \begin_layout Standard
35355 SDCC performs a host of standard optimizations in addition to some MCU specific
35360 \begin_layout Subsection
35361 Sub-expression Elimination
35362 \begin_inset LatexCommand index
35363 name "Subexpression elimination"
35370 \begin_layout Standard
35371 The compiler does local and
35390 \begin_layout Verse
35398 \begin_layout Standard
35399 will be translated to
35402 \begin_layout Verse
35412 \begin_layout Standard
35413 Some subexpressions are not as obvious as the above example, e.g.:
35416 \begin_layout Verse
35424 \begin_layout Standard
35425 In this case the address arithmetic a->b[i] will be computed only once;
35426 the equivalent code in C would be.
35429 \begin_layout Verse
35439 \begin_layout Standard
35440 The compiler will try to keep these temporary variables in registers.
35443 \begin_layout Subsection
35444 Dead-Code Elimination
35445 \begin_inset LatexCommand index
35446 name "Dead-code elimination"
35453 \begin_layout Verse
35468 i = 1; \InsetSpace ~
35477 global = 1;\InsetSpace ~
35491 global = 3;\InsetSpace ~
35497 \begin_layout Standard
35501 \begin_layout Verse
35517 \begin_layout Subsection
35519 \begin_inset LatexCommand index
35520 name "Copy propagation"
35527 \begin_layout Verse
35551 \begin_layout Standard
35555 \begin_layout Verse
35579 \begin_layout Standard
35580 Note: the dead stores created by this copy propagation will be eliminated
35581 by dead-code elimination.
35584 \begin_layout Subsection
35586 \begin_inset LatexCommand index
35587 name "Loop optimization"
35592 \begin_inset LatexCommand label
35593 name "sub:Loop-Optimizations"
35600 \begin_layout Standard
35601 Two types of loop optimizations are done by SDCC
35609 of loop induction variables.
35610 In addition to the strength reduction the optimizer marks the induction
35611 variables and the register allocator tries to keep the induction variables
35612 in registers for the duration of the loop.
35613 Because of this preference of the register allocator
35614 \begin_inset LatexCommand index
35615 name "Register allocation"
35619 , loop induction optimization causes an increase in register pressure, which
35620 may cause unwanted spilling of other temporary variables into the stack
35621 \begin_inset LatexCommand index
35627 The compiler will generate a warning message when it is forced to allocate
35628 extra space either on the stack or data space.
35629 If this extra space allocation is undesirable then induction optimization
35630 can be eliminated either for the entire source file (with -
35634 \begin_layout Standard
35643 -noinduction option) or for a given function only using #pragma\InsetSpace ~
35645 \begin_inset LatexCommand index
35646 name "\\#pragma noinduction"
35657 \begin_layout Verse
35660 for (i = 0 ; i < 100 ; i ++)
35669 \begin_layout Standard
35673 \begin_layout Verse
35678 for (i = 0; i < 100; i++)
35687 \begin_layout Standard
35688 As mentioned previously some loop invariants are not as apparent, all static
35689 address computations are also moved out of the loop.
35694 \begin_inset LatexCommand index
35695 name "Strength reduction"
35699 , this optimization substitutes an expression by a cheaper expression:
35702 \begin_layout Verse
35705 for (i=0;i < 100; i++)
35714 \begin_layout Standard
35718 \begin_layout Verse
35725 for (i=0;i< 100;i++) {
35731 ar[itemp1] = itemp2;
35749 \begin_layout Standard
35750 The more expensive multiplication
35751 \begin_inset LatexCommand index
35752 name "Multiplication"
35756 is changed to a less expensive addition.
35759 \begin_layout Subsection
35761 \begin_inset LatexCommand index
35762 name "Loop reversing"
35769 \begin_layout Standard
35770 This optimization is done to reduce the overhead of checking loop boundaries
35771 for every iteration.
35772 Some simple loops can be reversed and implemented using a
35773 \begin_inset Quotes eld
35776 decrement and jump if not zero
35777 \begin_inset Quotes erd
35781 SDCC checks for the following criterion to determine if a loop is reversible
35782 (note: more sophisticated compilers use data-dependency analysis to make
35783 this determination, SDCC uses a more simple minded analysis).
35786 \begin_layout Itemize
35787 The 'for' loop is of the form
35793 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
35803 \begin_layout Itemize
35804 The <for body> does not contain
35805 \begin_inset Quotes eld
35809 \begin_inset Quotes erd
35813 \begin_inset Quotes erd
35819 \begin_layout Itemize
35820 All goto's are contained within the loop.
35823 \begin_layout Itemize
35824 No function calls within the loop.
35827 \begin_layout Itemize
35828 The loop control variable <sym> is not assigned any value within the loop
35831 \begin_layout Itemize
35832 The loop control variable does NOT participate in any arithmetic operation
35836 \begin_layout Itemize
35837 There are NO switch statements in the loop.
35840 \begin_layout Subsection
35841 Algebraic Simplifications
35844 \begin_layout Standard
35845 SDCC does numerous algebraic simplifications, the following is a small sub-set
35846 of these optimizations.
35849 \begin_layout Verse
35852 i = j + 0;\InsetSpace ~
35856 /* changed to: */\InsetSpace ~
35862 i /= 2;\InsetSpace ~
35869 /* changed to: */\InsetSpace ~
35876 = j - j;\InsetSpace ~
35880 /* changed to: */\InsetSpace ~
35886 i = j / 1;\InsetSpace ~
35890 /* changed to: */\InsetSpace ~
35897 \begin_layout Standard
35898 Note the subexpressions
35899 \begin_inset LatexCommand index
35900 name "Subexpression"
35904 given above are generally introduced by macro expansions or as a result
35905 of copy/constant propagation.
35908 \begin_layout Subsection
35909 'switch' Statements
35910 \begin_inset LatexCommand label
35911 name "sub:'switch'-Statements"
35916 \begin_inset LatexCommand index
35917 name "switch statement"
35924 \begin_layout Standard
35925 SDCC can optimize switch statements to jump tables
35926 \begin_inset LatexCommand index
35932 It makes the decision based on an estimate of the generated code size.
35933 SDCC is quite liberal in the requirements for jump table generation:
35936 \begin_layout Itemize
35937 The labels need not be in order, and the starting number need not be one
35938 or zero, the case labels are in numerical sequence or not too many case
35939 labels are missing.
35943 \begin_layout Verse
35946 switch(i) {\InsetSpace ~
35977 case 4: ...\InsetSpace ~
36009 case 5: ...\InsetSpace ~
36041 case 3: ...\InsetSpace ~
36072 case 6: ...\InsetSpace ~
36104 case 7: ...\InsetSpace ~
36136 case 8: ...\InsetSpace ~
36168 case 9: ...\InsetSpace ~
36200 case 10: ...\InsetSpace ~
36231 case 11: ...\InsetSpace ~
36298 \begin_layout Standard
36299 Both the above switch statements will be implemented using a jump-table.
36300 The example to the right side is slightly more efficient as the check for
36301 the lower boundary of the jump-table is not needed.
36305 \begin_layout Itemize
36306 The number of case labels is not larger than supported by the target architectur
36310 \begin_layout Itemize
36311 If the case labels are not in numerical sequence ('gaps' between cases)
36312 SDCC checks whether a jump table with additionally inserted dummy cases
36313 is still attractive.
36317 \begin_layout Itemize
36318 If the starting number is not zero and a check for the lower boundary of
36319 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
36324 \begin_layout Standard
36325 Switch statements which have large gaps in the numeric sequence or those
36326 that have too many case labels can be split into more than one switch statement
36327 for efficient code generation, e.g.:
36330 \begin_layout Verse
36408 \begin_layout Standard
36409 If the above switch statement is broken down into two switch statements
36412 \begin_layout Verse
36455 \begin_layout Standard
36459 \begin_layout Verse
36502 \begin_layout Standard
36503 then both the switch statements will be implemented using jump-tables whereas
36504 the unmodified switch statement will not be.
36507 \begin_layout Standard
36508 \begin_inset Note Note
36511 \begin_layout Standard
36512 There might be reasons which SDCC cannot know about to either favour or
36513 not favour jump tables.
36514 If the target system has to be as quick for the last switch case as for
36515 the first (pro jump table), or if the switch argument is known to be zero
36516 in the majority of the cases (contra jump table).
36524 \begin_layout Standard
36525 The pragma nojtbound
36526 \begin_inset LatexCommand index
36527 name "\\#pragma nojtbound"
36531 can be used to turn off checking the
36544 It has no effect if a default label is supplied.
36545 Use of this pragma is dangerous: if the switch
36546 \begin_inset LatexCommand index
36547 name "switch statement"
36551 argument is not matched by a case statement the processor will happily
36555 \begin_layout Subsection
36556 Bit-shifting Operations
36557 \begin_inset LatexCommand index
36558 name "Bit shifting"
36565 \begin_layout Standard
36566 Bit shifting is one of the most frequently used operation in embedded programmin
36568 SDCC tries to implement bit-shift operations in the most efficient way
36572 \begin_layout Verse
36585 \begin_layout Standard
36586 generates the following code:
36589 \begin_layout Verse
36604 \begin_layout Standard
36605 In general SDCC will never setup a loop if the shift count is known.
36609 \begin_layout Verse
36622 \begin_layout Standard
36626 \begin_layout Verse
36650 \begin_layout Subsection
36652 \begin_inset LatexCommand index
36653 name "Bit rotation"
36660 \begin_layout Standard
36661 A special case of the bit-shift operation is bit rotation
36662 \begin_inset LatexCommand index
36663 name "rotating bits"
36667 , SDCC recognizes the following expression to be a left bit-rotation:
36670 \begin_layout Verse
36678 char i;\InsetSpace ~
36689 /* unsigned is needed for rotation */
36694 i = ((i << 1) | (i >> 7));
36703 \begin_layout Standard
36704 will generate the following code:
36707 \begin_layout Verse
36724 \begin_layout Standard
36725 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
36726 ns of this case will also be recognized as bit-rotation, i.e.:
36729 \begin_layout Verse
36732 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
36735 \begin_layout Subsection
36736 Nibble and Byte Swapping
36739 \begin_layout Standard
36740 Other special cases of the bit-shift operations are nibble or byte swapping
36741 \begin_inset LatexCommand index
36742 name "swapping nibbles/bytes"
36746 , SDCC recognizes the following expressions:
36749 \begin_layout Verse
36770 i = ((i << 4) | (i >> 4));
36776 j = ((j << 8) | (j >> 8));
36779 \begin_layout Standard
36780 and generates a swap instruction for the nibble swapping
36781 \begin_inset LatexCommand index
36782 name "Nibble swapping"
36786 or move instructions for the byte swapping
36787 \begin_inset LatexCommand index
36788 name "Byte swapping"
36794 \begin_inset Quotes sld
36798 \begin_inset Quotes srd
36801 example can be used to convert from little to big-endian or vice versa.
36802 If you want to change the endianness of a
36806 integer you have to cast to
36813 \begin_layout Standard
36814 Note that SDCC stores numbers in little-endian
36818 \begin_layout Standard
36819 Usually 8-bit processors don't care much about endianness.
36820 This is not the case for the standard 8051 which only has an instruction
36826 \begin_inset LatexCommand index
36831 -datapointer so little-endian is the more efficient byte order.
36837 \begin_inset LatexCommand index
36838 name "little-endian"
36843 \begin_inset LatexCommand index
36849 lowest order first).
36852 \begin_layout Subsection
36854 \begin_inset LatexCommand index
36855 name "Highest Order Bit"
36860 \begin_inset LatexCommand index
36861 name "Any Order Bit"
36868 \begin_layout Standard
36869 It is frequently required to obtain the highest order bit of an integral
36870 type (long, int, short or char types).
36871 Also obtaining any other order bit is not uncommon.
36872 SDCC recognizes the following expressions to yield the highest order bit
36873 and generates optimized code for it, e.g.:
36876 \begin_layout Verse
36887 unsigned char hob1, aob1;
36891 bit hob2, hob3, aob2,
36901 hob1 = (gint >> 15) & 1;
36905 hob2 = (gint >> 15) & 1;
36909 hob3 = gint & 0x8000;
36914 aob1 = (gint >> 9) & 1;
36918 aob2 = (gint >> 8) & 1;
36922 aob3 = gint & 0x0800;
36932 \begin_layout Standard
36933 will generate the following code:
36936 \begin_layout Verse
36967 000A E5*01\InsetSpace ~
36994 000C 23\InsetSpace ~
37025 000D 54 01\InsetSpace ~
37053 000F F5*02\InsetSpace ~
37108 0011 E5*01\InsetSpace ~
37136 0013 33\InsetSpace ~
37166 0014 92*00\InsetSpace ~
37222 0016 E5*01\InsetSpace ~
37249 0018 33\InsetSpace ~
37279 0019 92*01\InsetSpace ~
37335 001B E5*01\InsetSpace ~
37394 001E 54 01\InsetSpace ~
37421 0020 F5*03\InsetSpace ~
37477 0022 E5*01\InsetSpace ~
37504 0024 13\InsetSpace ~
37534 0025 92*02\InsetSpace ~
37590 0027 E5*01\InsetSpace ~
37645 002B 92*03\InsetSpace ~
37673 \begin_layout Standard
37674 Other variations of these cases however will
37679 They are standard C expressions, so I heartily recommend these be the only
37680 way to get the highest order bit, (it is portable).
37681 Of course it will be recognized even if it is embedded in other expressions,
37685 \begin_layout Verse
37688 xyz = gint + ((gint >> 15) & 1);
37691 \begin_layout Standard
37692 will still be recognized.
37695 \begin_layout Subsection
37697 \begin_inset LatexCommand index
37698 name "Higher Order Byte"
37702 / Higher Order Word
37703 \begin_inset LatexCommand index
37704 name "Higher Order Word"
37711 \begin_layout Standard
37712 It is also frequently required to obtain a higher order byte or word of
37713 a larger integral type (long, int or short types).
37714 SDCC recognizes the following expressions to yield the higher order byte
37715 or word and generates optimized code for it, e.g.:
37718 \begin_layout Verse
37723 unsigned long int glong;
37731 unsigned char hob1,
37736 unsigned int how1, how2;
37745 hob1 = (gint >> 8) & 0xFF;
37749 hob2 = glong >> 24;
37753 how1 = (glong >> 16) & 0xFFFF;
37768 \begin_layout Standard
37769 will generate the following code:
37772 \begin_layout Verse
37803 0037 85*01*06\InsetSpace ~
37825 _foo_hob1_1_1,(_gint + 1)
37856 003A 85*05*07\InsetSpace ~
37878 _foo_hob2_1_1,(_glong + 3)
37908 003D 85*04*08\InsetSpace ~
37931 _foo_how1_1_1,(_glong + 2)
37933 0040 85*05*09\InsetSpace ~
37958 0043 85*03*0A\InsetSpace ~
37980 _foo_how2_1_1,(_glong + 1)
37982 0046 85*04*0B\InsetSpace ~
38005 (_foo_how2_1_1 + 1),(_glong + 2)
38008 \begin_layout Standard
38009 Again, variations of these cases may
38014 They are standard C expressions, so I heartily recommend these be the only
38015 way to get the higher order byte/word, (it is portable).
38016 Of course it will be recognized even if it is embedded in other expressions,
38020 \begin_layout Verse
38023 xyz = gint + ((gint >> 8) & 0xFF);
38026 \begin_layout Standard
38027 will still be recognized.
38030 \begin_layout Subsection
38032 \begin_inset LatexCommand label
38033 name "sub:Peephole-Optimizer"
38038 \begin_inset LatexCommand index
38039 name "Peephole optimizer"
38046 \begin_layout Standard
38047 The compiler uses a rule based, pattern matching and re-writing mechanism
38048 for peep-hole optimization.
38053 a peep-hole optimizer by Christopher W.
38054 Fraser (cwfraser\InsetSpace ~
38057 A default set of rules are compiled into the compiler, additional rules
38058 may be added with the
38064 \begin_layout Standard
38074 \begin_inset LatexCommand index
38075 name "-\\/-peep-file"
38082 The rule language is best illustrated with examples.
38085 \begin_layout Verse
38107 \begin_layout Standard
38108 The above rule will change the following assembly
38109 \begin_inset LatexCommand index
38110 name "Assembler routines"
38117 \begin_layout Verse
38125 \begin_layout Standard
38129 \begin_layout Verse
38135 \begin_layout Standard
38136 Note: All occurrences of a
38140 (pattern variable) must denote the same string.
38141 With the above rule, the assembly sequence:
38144 \begin_layout Verse
38152 \begin_layout Standard
38153 will remain unmodified.
38157 Other special case optimizations may be added by the
38164 \begin_layout Standard
38177 some variants of the 8051 MCU
38178 \begin_inset LatexCommand index
38179 name "MCS51 variants"
38192 The following two rules will change all
38209 \begin_layout Verse
38212 replace { lcall %1 } by { acall %1 }
38214 replace { ljmp %1 } by { ajmp %1 }
38217 \begin_layout Standard
38218 (NOTE: from version 2.7.3 on, you can use option -
38224 \begin_layout Standard
38236 \begin_inset LatexCommand index
38237 name "-\\/-acall-ajmp"
38241 , which also takes care of aligning the interrupt vectors properly.)
38246 \begin_layout Standard
38249 inline-assembler code
38251 is also passed through the peep hole optimizer, thus the peephole optimizer
38252 can also be used as an assembly level macro expander.
38253 The rules themselves are MCU dependent whereas the rule language infra-structur
38254 e is MCU independent.
38255 Peephole optimization rules for other MCU can be easily programmed using
38260 The syntax for a rule is as follows:
38263 \begin_layout Verse
38266 rule := replace [ restart ] '{' <assembly sequence> '
38304 <assembly sequence> '
38322 '}' [if <functionName> ] '
38327 \begin_layout Standard
38328 <assembly sequence> := assembly instruction (each instruction including
38329 labels must be on a separate line).
38333 The optimizer will apply to the rules
38334 one by one from the top in the sequence of their appearance, it will terminate
38335 when all rules are exhausted.
38336 If the 'restart' option is specified, then the optimizer will start matching
38337 the rules again from the top, this option for a rule is expensive (performance)
38338 , it is intended to be used in situations where a transformation will trigger
38339 the same rule again.
38340 An example of this (not a good one, it has side effects) is the following
38344 \begin_layout Verse
38364 \begin_layout Standard
38365 Note that the replace pattern cannot be a blank, but can be a comment line.
38366 Without the 'restart' option only the innermost 'pop' 'push' pair would
38367 be eliminated, i.e.:
38370 \begin_layout Verse
38382 \begin_layout Standard
38386 \begin_layout Verse
38396 \begin_layout Standard
38401 the restart option the rule will be applied again to the resulting code
38402 and then all the pop-push pairs will be eliminated to yield:
38405 \begin_layout Verse
38413 \begin_layout Standard
38414 A conditional function can be attached to a rule.
38415 Attaching rules are somewhat more involved, let me illustrate this with
38419 \begin_layout Verse
38443 \begin_layout Standard
38444 The optimizer does a look-up of a function name table defined in function
38449 in the source file SDCCpeeph.c, with the name
38454 If it finds a corresponding entry the function is called.
38455 Note there can be no parameters specified for these functions, in this
38460 is crucial, since the function
38464 expects to find the label in that particular variable (the hash table containin
38465 g the variable bindings is passed as a parameter).
38466 If you want to code more such functions, take a close look at the function
38467 labelInRange and the calling mechanism in source file SDCCpeeph.c.
38468 Currently implemented are
38470 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
38471 24bitMode, portIsDS390, 24bitModeAndPortDS390
38480 \begin_layout Standard
38481 I know this whole thing is a little kludgey, but maybe some day we will
38482 have some better means.
38483 If you are looking at this file, you will see the default rules that are
38484 compiled into the compiler, you can add your own rules in the default set
38485 there if you get tired of specifying the -
38489 \begin_layout Standard
38501 \begin_layout Section
38503 \begin_inset LatexCommand index
38504 name "ANSI-compliance"
38509 \begin_inset LatexCommand label
38510 name "sub:ANSI-Compliance"
38517 \begin_layout Standard
38518 The latest publicly available version of the standard
38520 ISO/IEC 9899 - Programming languages - C
38522 should be available at:
38523 \begin_inset LatexCommand url
38524 target "http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899"
38533 \begin_layout Standard
38534 Deviations from the compliance:
38537 \begin_layout Itemize
38538 functions are not reentrant
38539 \begin_inset LatexCommand index
38544 unless explicitly declared as such or the
38550 \begin_layout Standard
38560 \begin_inset LatexCommand index
38561 name "-\\/-stack-auto"
38567 command line option is specified.
38570 \begin_layout Itemize
38572 \begin_inset LatexCommand index
38578 \begin_inset LatexCommand index
38583 cannot be assigned values directly, cannot be passed as function parameters
38584 or assigned to each other and cannot be a return value
38585 \begin_inset LatexCommand index
38586 name "return value"
38590 from a function, e.g.:
38594 \begin_layout Verse
38617 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
38642 s parms) /* invalid in SDCC although allowed in ANSI */
38664 return rets; /* is invalid in SDCC although allowed in ANSI */
38670 \begin_layout Itemize
38671 initialization of structure arrays must be fully braced.
38675 \begin_layout Verse
38678 struct s { char x } a[] = {1, 2};\InsetSpace ~
38683 /* invalid in SDCC */
38686 } a[] = {{1}, {2}}; /* OK */
38690 \begin_layout Itemize
38692 \begin_inset LatexCommand index
38693 name "long long (not supported)"
38698 \begin_inset LatexCommand index
38699 name "int (64 bit) (not supported)"
38706 \begin_layout Itemize
38708 \begin_inset LatexCommand index
38709 name "double (not supported)"
38713 ' precision floating point
38714 \begin_inset LatexCommand index
38715 name "Floating point support"
38722 \begin_layout Itemize
38724 \begin_inset LatexCommand index
38729 function declarations are NOT allowed.
38733 \begin_layout Verse
38736 foo(i,j) /* this old style of function declarations */
38738 int i,j; /* is valid
38739 in ANSI but not valid in SDCC */
38754 \begin_layout Itemize
38755 Most enhancements in C99 are not supported, e.g.:
38759 \begin_layout Verse
38769 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
38773 \begin_layout Itemize
38774 But some have been added recently in SDCC 2.7.0.
38775 They must be considered alpha quality however.
38779 \begin_layout Verse
38784 \begin_inset LatexCommand index
38785 name "inline (not supported)"
38794 int increment (int a) { return a+1; } /* inlines the increment without function
38803 \begin_inset LatexCommand index
38804 name "inline (not supported)"
38813 p; /* accepted but ignored */
38817 \begin_layout Itemize
38818 Certain words that are valid identifiers in the standard may be reserved
38819 words in SDCC unless the
38825 \begin_layout Standard
38835 \begin_inset LatexCommand index
38836 name "-\\/-std-c89"
38848 \begin_layout Standard
38858 \begin_inset LatexCommand index
38859 name "-\\/-std-c99"
38865 command line options are used.
38866 These may include (depending on the selected processor): 'at', 'banked',
38867 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
38868 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
38869 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
38871 Compliant equivalents of these keywords are always available in a form
38872 that begin with two underscores
38873 \begin_inset LatexCommand index
38874 name "\\_\\_ (prefix for extended keywords)"
38879 '__data' instead of 'data'.
38882 \begin_layout Itemize
38883 Integer promotion of variable arguments is not performed if the argument
38884 is explicitly taypecasted unless the
38890 \begin_layout Standard
38900 \begin_inset LatexCommand index
38901 name "-\\/-std-c89"
38913 \begin_layout Standard
38923 \begin_inset LatexCommand index
38924 name "-\\/-std-c99"
38930 command line options are used.
38934 \begin_layout Verse
38937 void vararg_func (char *str, ...) { str; }
38954 u is promoted to int before
38959 * passing to function */
38963 vararg_func ("%c", c);
38970 argument u is not promoted to int,
38975 * it is passed as char to function
38981 --std-cXX is not defined;
38986 * is promoted to int before passing
38992 if --std-cXX is defined */
38996 vararg_func ("%bc", (char)u);
39002 \begin_layout Section
39003 Cyclomatic Complexity
39004 \begin_inset LatexCommand index
39005 name "Cyclomatic complexity"
39012 \begin_layout Standard
39013 Cyclomatic complexity of a function is defined as the number of independent
39014 paths the program can take during execution of the function.
39015 This is an important number since it defines the number test cases you
39016 have to generate to validate the function.
39017 The accepted industry standard for complexity number is 10, if the cyclomatic
39018 complexity reported by SDCC exceeds 10 you should think about simplification
39019 of the function logic.
39020 Note that the complexity level is not related to the number of lines of
39021 code in a function.
39022 Large functions can have low complexity, and small functions can have large
39028 SDCC uses the following formula to compute the complexity:
39033 \begin_layout Standard
39034 complexity = (number of edges in control flow graph) - (number of nodes
39035 in control flow graph) + 2;
39039 Having said that the industry standard is 10,
39040 you should be aware that in some cases it be may unavoidable to have a
39041 complexity level of less than 10.
39042 For example if you have switch statement with more than 10 case labels,
39043 each case label adds one to the complexity level.
39044 The complexity level is by no means an absolute measure of the algorithmic
39045 complexity of the function, it does however provide a good starting point
39046 for which functions you might look at for further optimization.
39049 \begin_layout Section
39050 Retargetting for other Processors
39053 \begin_layout Standard
39054 The issues for retargetting the compiler are far too numerous to be covered
39056 What follows is a brief description of each of the seven phases of the
39057 compiler and its MCU dependency.
39060 \begin_layout Itemize
39061 Parsing the source and building the annotated parse tree.
39062 This phase is largely MCU independent (except for the language extensions).
39063 Syntax & semantic checks are also done in this phase, along with some initial
39064 optimizations like back patching labels and the pattern matching optimizations
39065 like bit-rotation etc.
39068 \begin_layout Itemize
39069 The second phase involves generating an intermediate code which can be easy
39070 manipulated during the later phases.
39071 This phase is entirely MCU independent.
39072 The intermediate code generation assumes the target machine has unlimited
39073 number of registers, and designates them with the name iTemp.
39074 The compiler can be made to dump a human readable form of the code generated
39079 \begin_layout Standard
39091 \begin_layout Itemize
39092 This phase does the bulk of the standard optimizations and is also MCU independe
39094 This phase can be broken down into several sub-phases:
39098 Break down intermediate
39099 code (iCode) into basic blocks.
39101 Do control flow & data flow analysis on the
39104 Do local common subexpression elimination, then global subexpressio
39107 Dead code elimination
39111 If loop optimizations
39112 caused any changes then do 'global subexpression elimination' and 'dead
39113 code elimination' again.
39116 \begin_layout Itemize
39117 This phase determines the live-ranges; by live range I mean those iTemp
39118 variables defined by the compiler that still survive after all the optimization
39120 Live range analysis
39121 \begin_inset LatexCommand index
39122 name "Live range analysis"
39126 is essential for register allocation, since these computation determines
39127 which of these iTemps will be assigned to registers, and for how long.
39130 \begin_layout Itemize
39131 Phase five is register allocation.
39132 There are two parts to this process.
39136 The first part I call 'register packing'
39137 (for lack of a better term).
39138 In this case several MCU specific expression folding is done to reduce
39143 The second part is more MCU independent and deals with
39144 allocating registers to the remaining live ranges.
39145 A lot of MCU specific code does creep into this phase because of the limited
39146 number of index registers available in the 8051.
39149 \begin_layout Itemize
39150 The Code generation phase is (unhappily), entirely MCU dependent and very
39151 little (if any at all) of this code can be reused for other MCU.
39152 However the scheme for allocating a homogenized assembler operand for each
39153 iCode operand may be reused.
39156 \begin_layout Itemize
39157 As mentioned in the optimization section the peep-hole optimizer is rule
39158 based system, which can reprogrammed for other MCUs.
39161 \begin_layout Standard
39162 More information is available on SDCC Wiki
39163 \begin_inset LatexCommand index
39169 \begin_inset LatexCommand url
39170 target "http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting"
39174 ) and in the thread
39175 \begin_inset LatexCommand url
39176 target "http://sf.net/mailarchive/message.php?msg_id=13954144"
39183 \begin_layout Chapter
39185 \begin_inset LatexCommand index
39186 name "Compiler internals"
39193 \begin_layout Section
39194 The anatomy of the compiler
39195 \begin_inset LatexCommand label
39196 name "sub:The-anatomy-of"
39203 \begin_layout Standard
39206 This is an excerpt from an article published in Circuit Cellar Magazine
39215 It's a little outdated (the compiler is much more efficient now and user/develo
39216 per friendly), but pretty well exposes the guts of it all.
39222 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
39223 It is fairly easy to retarget for other 8-bit MCU.
39224 Here we take a look at some of the internals of the compiler.
39228 \begin_layout Paragraph*
39230 \begin_inset LatexCommand index
39238 \begin_layout Standard
39239 Parsing the input source file and creating an AST (Annotated Syntax Tree
39240 \begin_inset LatexCommand index
39241 name "Annotated syntax tree"
39246 This phase also involves propagating types (annotating each node of the
39247 parse tree with type information) and semantic analysis.
39248 There are some MCU specific parsing rules.
39249 For example the storage classes, the extended storage classes are MCU specific
39250 while there may be a xdata storage class for 8051 there is no such storage
39251 class for z80 or Atmel AVR.
39252 SDCC allows MCU specific storage class extensions, i.e.
39253 xdata will be treated as a storage class specifier when parsing 8051 C
39254 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
39258 \begin_layout Paragraph*
39260 \begin_inset LatexCommand index
39268 \begin_layout Standard
39269 Intermediate code generation.
39270 In this phase the AST is broken down into three-operand form (iCode).
39271 These three operand forms are represented as doubly linked lists.
39272 ICode is the term given to the intermediate form generated by the compiler.
39273 ICode example section shows some examples of iCode generated for some simple
39274 C source functions.
39277 \begin_layout Paragraph*
39279 \begin_inset LatexCommand index
39280 name "Optimizations"
39287 \begin_layout Standard
39288 Bulk of the target independent optimizations is performed in this phase.
39289 The optimizations include constant propagation, common sub-expression eliminati
39290 on, loop invariant code movement, strength reduction of loop induction variables
39291 and dead-code elimination.
39294 \begin_layout Paragraph*
39295 Live range analysis
39296 \begin_inset LatexCommand index
39297 name "Live range analysis"
39304 \begin_layout Standard
39305 During intermediate code generation phase, the compiler assumes the target
39306 machine has infinite number of registers and generates a lot of temporary
39308 The live range computation determines the lifetime of each of these compiler-ge
39309 nerated temporaries.
39310 A picture speaks a thousand words.
39311 ICode example sections show the live range annotations for each of the
39313 It is important to note here, each iCode is assigned a number in the order
39314 of its execution in the function.
39315 The live ranges are computed in terms of these numbers.
39316 The from number is the number of the iCode which first defines the operand
39317 and the to number signifies the iCode which uses this operand last.
39320 \begin_layout Paragraph*
39321 Register Allocation
39322 \begin_inset LatexCommand index
39323 name "Register allocation"
39330 \begin_layout Standard
39331 The register allocation determines the type and number of registers needed
39333 In most MCUs only a few registers can be used for indirect addressing.
39334 In case of 8051 for example the registers R0 & R1 can be used to indirectly
39335 address the internal ram and DPTR to indirectly address the external ram.
39336 The compiler will try to allocate the appropriate register to pointer variables
39338 ICode example section shows the operands annotated with the registers assigned
39340 The compiler will try to keep operands in registers as much as possible;
39341 there are several schemes the compiler uses to do achieve this.
39342 When the compiler runs out of registers the compiler will check to see
39343 if there are any live operands which is not used or defined in the current
39344 basic block being processed, if there are any found then it will push that
39345 operand and use the registers in this block, the operand will then be popped
39346 at the end of the basic block.
39350 \begin_layout Standard
39351 There are other MCU specific considerations in this phase.
39352 Some MCUs have an accumulator; very short-lived operands could be assigned
39353 to the accumulator instead of a general-purpose register.
39356 \begin_layout Paragraph*
39360 \begin_layout Standard
39361 Figure II gives a table of iCode
39362 \begin_inset LatexCommand index
39367 operations supported by the compiler.
39368 The code generation involves translating these operations into corresponding
39369 assembly code for the processor.
39370 This sounds overly simple but that is the essence of code generation.
39371 Some of the iCode operations are generated on a MCU specific manner for
39372 example, the z80 port does not use registers to pass parameters so the
39373 SEND and RECV iCode operations will not be generated, and it also does
39374 not support JUMPTABLES.
39380 \begin_layout Standard
39384 \begin_inset Tabular
39385 <lyxtabular version="3" rows="39" columns="4">
39386 <features islongtable="true" headBottomDL="true">
39387 <column alignment="block" valignment="top" leftline="true" width="13col%">
39388 <column alignment="left" valignment="top" leftline="true" width="13col%">
39389 <column alignment="block" valignment="top" leftline="true" width="22col%">
39390 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
39391 <row topline="true" bottomline="true" endhead="true">
39392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39395 \begin_layout Standard
39401 \begin_inset LatexCommand index
39411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39414 \begin_layout Standard
39422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39425 \begin_layout Standard
39433 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39436 \begin_layout Standard
39445 <row topline="true">
39446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39449 \begin_layout Standard
39457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39460 \begin_layout Standard
39463 IC_LEFT() IC_RESULT()
39468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39471 \begin_layout Standard
39479 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39482 \begin_layout Standard
39485 IC_RESULT = ! IC_LEFT;
39491 <row topline="true">
39492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39495 \begin_layout Standard
39503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39506 \begin_layout Standard
39509 IC_LEFT() IC_RESULT()
39514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39517 \begin_layout Standard
39520 Bitwise complement of
39525 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39528 \begin_layout Standard
39531 IC_RESULT = ~IC_LEFT;
39537 <row topline="true">
39538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39541 \begin_layout Standard
39549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39552 \begin_layout Standard
39555 IC_LEFT() IC_RESULT()
39560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39563 \begin_layout Standard
39566 Rotate right with carry
39571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39574 \begin_layout Standard
39577 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
39583 <row topline="true">
39584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39587 \begin_layout Standard
39595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39598 \begin_layout Standard
39601 IC_LEFT() IC_RESULT()
39606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39609 \begin_layout Standard
39612 Rotate left with carry
39617 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39620 \begin_layout Standard
39623 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
39629 <row topline="true">
39630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39633 \begin_layout Standard
39641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39644 \begin_layout Standard
39647 IC_LEFT() IC_RESULT()
39652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39655 \begin_layout Standard
39658 Get the highest order bit of IC_LEFT
39663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39666 \begin_layout Standard
39669 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
39675 <row topline="true">
39676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39679 \begin_layout Standard
39687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39690 \begin_layout Standard
39693 IC_LEFT() IC_RESULT()
39698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39701 \begin_layout Standard
39709 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39712 \begin_layout Standard
39715 IC_RESULT = - IC_LEFT;
39721 <row topline="true">
39722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39725 \begin_layout Standard
39733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39736 \begin_layout Standard
39744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39747 \begin_layout Standard
39750 Push the operand into stack
39755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39758 \begin_layout Standard
39767 <row topline="true">
39768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39771 \begin_layout Standard
39779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39782 \begin_layout Standard
39790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39793 \begin_layout Standard
39796 Pop the operand from the stack
39801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39804 \begin_layout Standard
39813 <row topline="true">
39814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39817 \begin_layout Standard
39825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39828 \begin_layout Standard
39831 IC_LEFT() IC_RESULT()
39836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39839 \begin_layout Standard
39842 Call the function represented by IC_LEFT
39847 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39850 \begin_layout Standard
39853 IC_RESULT = IC_LEFT();
39859 <row topline="true">
39860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39863 \begin_layout Standard
39871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39874 \begin_layout Standard
39877 IC_LEFT() IC_RESULT()
39882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39885 \begin_layout Standard
39888 Call via function pointer
39893 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39896 \begin_layout Standard
39899 IC_RESULT = (*IC_LEFT)();
39905 <row topline="true">
39906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39909 \begin_layout Standard
39917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39920 \begin_layout Standard
39928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39931 \begin_layout Standard
39934 Return the value in operand IC_LEFT
39939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39942 \begin_layout Standard
39951 <row topline="true">
39952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39955 \begin_layout Standard
39963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39966 \begin_layout Standard
39974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39977 \begin_layout Standard
39985 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39988 \begin_layout Standard
39997 <row topline="true">
39998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40001 \begin_layout Standard
40009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40012 \begin_layout Standard
40020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40023 \begin_layout Standard
40031 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40034 \begin_layout Standard
40043 <row topline="true">
40044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40047 \begin_layout Standard
40055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40058 \begin_layout Standard
40061 IC_LEFT() IC_RIGHT() IC_RESULT()
40066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40069 \begin_layout Standard
40077 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40080 \begin_layout Standard
40083 IC_RESULT = IC_LEFT + IC_RIGHT
40089 <row topline="true">
40090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40093 \begin_layout Standard
40101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40104 \begin_layout Standard
40107 IC_LEFT() IC_RIGHT() IC_RESULT()
40112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40115 \begin_layout Standard
40123 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40126 \begin_layout Standard
40129 IC_RESULT = IC_LEFT - IC_RIGHT
40135 <row topline="true">
40136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40139 \begin_layout Standard
40147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40150 \begin_layout Standard
40153 IC_LEFT() IC_RIGHT() IC_RESULT()
40158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40161 \begin_layout Standard
40169 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40172 \begin_layout Standard
40175 IC_RESULT = IC_LEFT * IC_RIGHT;
40181 <row topline="true">
40182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40185 \begin_layout Standard
40193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40196 \begin_layout Standard
40199 IC_LEFT() IC_RIGHT() IC_RESULT()
40204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40207 \begin_layout Standard
40215 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40218 \begin_layout Standard
40221 IC_RESULT = IC_LEFT / IC_RIGHT;
40227 <row topline="true">
40228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40231 \begin_layout Standard
40239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40242 \begin_layout Standard
40245 IC_LEFT() IC_RIGHT() IC_RESULT()
40250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40253 \begin_layout Standard
40261 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40264 \begin_layout Standard
40267 IC_RESULT = IC_LEFT % IC_RIGHT;
40273 <row topline="true">
40274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40277 \begin_layout Standard
40285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40288 \begin_layout Standard
40291 IC_LEFT() IC_RIGHT() IC_RESULT()
40296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40299 \begin_layout Standard
40307 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40310 \begin_layout Standard
40313 IC_RESULT = IC_LEFT < IC_RIGHT;
40319 <row topline="true">
40320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40323 \begin_layout Standard
40331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40334 \begin_layout Standard
40337 IC_LEFT() IC_RIGHT() IC_RESULT()
40342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40345 \begin_layout Standard
40353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40356 \begin_layout Standard
40359 IC_RESULT = IC_LEFT > IC_RIGHT;
40365 <row topline="true">
40366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40369 \begin_layout Standard
40377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40380 \begin_layout Standard
40383 IC_LEFT() IC_RIGHT() IC_RESULT()
40388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40391 \begin_layout Standard
40399 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40402 \begin_layout Standard
40405 IC_RESULT = IC_LEFT == IC_RIGHT;
40411 <row topline="true">
40412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40415 \begin_layout Standard
40423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40426 \begin_layout Standard
40429 IC_LEFT() IC_RIGHT() IC_RESULT()
40434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40437 \begin_layout Standard
40440 Logical and operation
40445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40448 \begin_layout Standard
40451 IC_RESULT = IC_LEFT && IC_RIGHT;
40457 <row topline="true">
40458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40461 \begin_layout Standard
40469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40472 \begin_layout Standard
40475 IC_LEFT() IC_RIGHT() IC_RESULT()
40480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40483 \begin_layout Standard
40486 Logical or operation
40491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40494 \begin_layout Standard
40497 IC_RESULT = IC_LEFT || IC_RIGHT;
40503 <row topline="true">
40504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40507 \begin_layout Standard
40515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40518 \begin_layout Standard
40521 IC_LEFT() IC_RIGHT() IC_RESULT()
40526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40529 \begin_layout Standard
40537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40540 \begin_layout Standard
40543 IC_RESULT = IC_LEFT ^ IC_RIGHT;
40549 <row topline="true">
40550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40553 \begin_layout Standard
40561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40564 \begin_layout Standard
40567 IC_LEFT() IC_RIGHT() IC_RESULT()
40572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40575 \begin_layout Standard
40583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40586 \begin_layout Standard
40589 IC_RESULT = IC_LEFT | IC_RIGHT;
40595 <row topline="true">
40596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40599 \begin_layout Standard
40607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40610 \begin_layout Standard
40613 IC_LEFT() IC_RIGHT() IC_RESULT()
40618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40621 \begin_layout Standard
40629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40632 \begin_layout Standard
40635 IC_RESULT = IC_LEFT & IC_RIGHT;
40641 <row topline="true">
40642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40645 \begin_layout Standard
40653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40656 \begin_layout Standard
40659 IC_LEFT() IC_RIGHT() IC_RESULT()
40664 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40667 \begin_layout Standard
40675 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40678 \begin_layout Standard
40681 IC_RESULT = IC_LEFT << IC_RIGHT
40687 <row topline="true">
40688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40691 \begin_layout Standard
40699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40702 \begin_layout Standard
40705 IC_LEFT() IC_RIGHT() IC_RESULT()
40710 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40713 \begin_layout Standard
40721 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40724 \begin_layout Standard
40727 IC_RESULT = IC_LEFT >> IC_RIGHT
40733 <row topline="true">
40734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40737 \begin_layout Standard
40747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40750 \begin_layout Standard
40753 IC_LEFT() IC_RESULT()
40758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40761 \begin_layout Standard
40769 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40772 \begin_layout Standard
40775 IC_RESULT = (*IC_LEFT);
40781 <row topline="true">
40782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40785 \begin_layout Standard
40793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40796 \begin_layout Standard
40799 IC_RIGHT() IC_RESULT()
40804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40807 \begin_layout Standard
40815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40818 \begin_layout Standard
40821 (*IC_RESULT) = IC_RIGHT;
40827 <row topline="true">
40828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40831 \begin_layout Standard
40839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40842 \begin_layout Standard
40845 IC_RIGHT() IC_RESULT()
40850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40853 \begin_layout Standard
40861 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40864 \begin_layout Standard
40867 IC_RESULT = IC_RIGHT;
40873 <row topline="true">
40874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40877 \begin_layout Standard
40885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40888 \begin_layout Standard
40891 IC_COND IC_TRUE IC_LABEL
40896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40899 \begin_layout Standard
40903 If true label is present then jump to true label if condition is true else
40904 jump to false label if condition is false
40909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40912 \begin_layout Standard
40915 if (IC_COND) goto IC_TRUE;
40921 If (!IC_COND) goto IC_FALSE;
40927 <row topline="true">
40928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40931 \begin_layout Standard
40939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40942 \begin_layout Standard
40945 IC_LEFT() IC_RESULT()
40950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40953 \begin_layout Standard
40961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40964 \begin_layout Standard
40967 IC_RESULT = &IC_LEFT();
40973 <row topline="true">
40974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40977 \begin_layout Standard
40985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40988 \begin_layout Standard
40991 IC_JTCOND IC_JTLABELS
40996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40999 \begin_layout Standard
41002 Jump to list of labels depending on the value of JTCOND
41007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41010 \begin_layout Standard
41019 <row topline="true">
41020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41023 \begin_layout Standard
41031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41034 \begin_layout Standard
41037 IC_RIGHT() IC_LEFT() IC_RESULT()
41042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41045 \begin_layout Standard
41053 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41056 \begin_layout Standard
41059 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
41065 <row topline="true">
41066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41069 \begin_layout Standard
41077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41080 \begin_layout Standard
41088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41091 \begin_layout Standard
41094 This is used for passing parameters in registers;
41096 move IC_LEFT to the next
41097 available parameter register.
41102 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41105 \begin_layout Standard
41114 <row topline="true">
41115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41118 \begin_layout Standard
41126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41129 \begin_layout Standard
41137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41140 \begin_layout Standard
41143 This is used for receiving parameters passed in registers;
41146 in the next parameter register to IC_RESULT
41151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41154 \begin_layout Standard
41163 <row topline="true" bottomline="true">
41164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41167 \begin_layout Standard
41171 (some more have been added)
41176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41179 \begin_layout Standard
41185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41188 \begin_layout Standard
41194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41197 \begin_layout Standard
41230 \begin_layout Standard
41231 \begin_inset Note Note
41234 \begin_layout Standard
41235 In the original article Figure II was announced to be downloadable on
41240 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
41248 \begin_layout Paragraph*
41250 \begin_inset LatexCommand index
41258 \begin_layout Standard
41259 This section shows some details of iCode.
41260 The example C code does not do anything useful; it is used as an example
41261 to illustrate the intermediate code generated by the compiler.
41264 \begin_layout Verse
41274 /* This function does nothing useful.
41281 for the purpose of explaining iCode */
41284 short function (data
41293 short i=10; \InsetSpace ~
41295 /* dead initialization eliminated */
41301 /* dead initialization eliminated */
41329 /* compiler detects i,j to be induction
41334 for (i = 0, j = 10 ; i < 10 ; i++, j
41340 \begin_layout Standard
41363 mul += i * 3; \InsetSpace ~
41365 /* this multiplication remains */
41372 j * 3;\InsetSpace ~
41374 /* this multiplication changed to addition */
41388 \begin_layout Standard
41389 In addition to the operands each iCode contains information about the filename
41390 and line it corresponds to in the source file.
41391 The first field in the listing should be interpreted as follows:
41396 Filename(linenumber: iCode Execution sequence number : ICode hash table
41397 key : loop depth of the iCode).
41402 Then follows the human readable form of the ICode operation.
41403 Each operand of this triplet form can be of three basic types a) compiler
41404 generated temporary b) user defined variable c) a constant value.
41405 Note that local variables and parameters are replaced by compiler generated
41408 \begin_inset LatexCommand index
41409 name "Live range analysis"
41413 are computed only for temporaries (i.e.
41414 live ranges are not computed for global variables).
41416 \begin_inset LatexCommand index
41417 name "Register allocation"
41421 are allocated for temporaries only.
41422 Operands are formatted in the following manner:
41427 Operand Name [lr live-from : live-to ] { type information } [ registers
41433 As mentioned earlier the live ranges are computed in terms of the execution
41434 sequence number of the iCodes, for example
41436 the iTemp0 is live from (i.e.
41437 first defined in iCode with execution sequence number 3, and is last used
41438 in the iCode with sequence number 5).
41439 For induction variables such as iTemp21 the live range computation extends
41440 the lifetime from the start to the end of the loop.
41442 The register allocator
41443 used the live range information to allocate registers, the same registers
41444 may be used for different temporaries if their live ranges do not overlap,
41445 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
41446 ranges do not overlap.
41447 In addition the allocator also takes into consideration the type and usage
41448 of a temporary, for example itemp6 is a pointer to near space and is used
41449 as to fetch data from (i.e.
41450 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
41451 Some short lived temporaries are allocated to special registers which have
41452 meaning to the code generator e.g.
41453 iTemp13 is allocated to a pseudo register CC which tells the back end that
41454 the temporary is used only for a conditional jump the code generation makes
41455 use of this information to optimize a compare and jump ICode.
41459 \begin_inset LatexCommand index
41460 name "Loop optimization"
41464 performed by the compiler.
41465 It can detect induction variables iTemp21(i) and iTemp23(j).
41466 Also note the compiler does selective strength reduction
41467 \begin_inset LatexCommand index
41468 name "Strength reduction"
41473 the multiplication of an induction variable in line 18 (gint = j * 3) is
41474 changed to addition, a new temporary iTemp17 is allocated and assigned
41475 a initial value, a constant 3 is then added for each iteration of the loop.
41476 The compiler does not change the multiplication
41477 \begin_inset LatexCommand index
41478 name "Multiplication"
41482 in line 17 however since the processor does support an 8 * 8 bit multiplication.
41485 Note the dead code elimination
41486 \begin_inset LatexCommand index
41487 name "Dead-code elimination"
41491 optimization eliminated the dead assignments in line 7 & 8 to I and sum
41497 \begin_layout Standard
41500 Sample.c (5:1:0:0) _entry($9) :
41503 \begin_layout Standard
41506 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
41509 \begin_layout Standard
41512 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
41515 \begin_layout Standard
41518 Sample.c(11:4:53:0) preHeaderLbl0($11) :
41521 \begin_layout Standard
41524 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
41528 \begin_layout Standard
41531 Sample.c(11:6:5:1) _whilecontinue_0($1) :
41534 \begin_layout Standard
41537 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
41541 \begin_layout Standard
41544 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
41547 \begin_layout Standard
41550 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
41554 \begin_layout Standard
41557 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
41561 \begin_layout Standard
41564 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
41568 \begin_layout Standard
41571 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
41575 \begin_layout Standard
41578 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
41579 * int}[r0] + 0x2 {short}
41582 \begin_layout Standard
41585 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
41588 \begin_layout Standard
41591 Sample.c(11:17:21:0)_whilebreak_0($3) :
41594 \begin_layout Standard
41597 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
41600 \begin_layout Standard
41603 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
41606 \begin_layout Standard
41609 Sample.c(15:20:54:0)preHeaderLbl1($13) :
41612 \begin_layout Standard
41615 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
41618 \begin_layout Standard
41621 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
41624 \begin_layout Standard
41627 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
41630 \begin_layout Standard
41633 Sample.c(15:24:26:1)_forcond_0($4) :
41636 \begin_layout Standard
41639 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
41643 \begin_layout Standard
41646 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
41649 \begin_layout Standard
41652 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
41653 + ITemp21 [lr21:38]{short}[r4]
41656 \begin_layout Standard
41659 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
41663 \begin_layout Standard
41666 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
41667 + iTemp15 [lr29:30]{short}[r1]
41670 \begin_layout Standard
41673 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
41677 \begin_layout Standard
41680 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
41684 \begin_layout Standard
41687 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
41691 \begin_layout Standard
41694 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
41698 \begin_layout Standard
41701 Sample.c(19:38:47:1) goto _forcond_0($4)
41704 \begin_layout Standard
41707 Sample.c(19:39:48:0)_forbreak_0($7) :
41710 \begin_layout Standard
41713 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
41714 + ITemp11 [lr19:40]{short}[r3]
41717 \begin_layout Standard
41720 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
41723 \begin_layout Standard
41726 Sample.c(20:42:51:0)_return($8) :
41729 \begin_layout Standard
41732 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
41738 Finally the code generated for this function:
41743 \begin_layout Standard
41749 \begin_layout Standard
41755 \begin_layout Standard
41763 \begin_layout Standard
41769 \begin_layout Standard
41777 \begin_layout Standard
41783 \begin_layout Standard
41786 ; ----------------------------------------------
41789 \begin_layout Standard
41792 ; function function
41795 \begin_layout Standard
41798 ; ----------------------------------------------
41801 \begin_layout Standard
41807 \begin_layout Standard
41810 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
41813 \begin_layout Standard
41821 \begin_layout Standard
41824 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
41827 \begin_layout Standard
41835 \begin_layout Standard
41838 ;_whilecontinue_0($1) :
41841 \begin_layout Standard
41847 \begin_layout Standard
41850 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
41853 \begin_layout Standard
41856 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
41859 \begin_layout Standard
41867 \begin_layout Standard
41875 \begin_layout Standard
41883 \begin_layout Standard
41891 \begin_layout Standard
41899 \begin_layout Standard
41907 \begin_layout Standard
41915 \begin_layout Standard
41921 \begin_layout Standard
41924 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
41927 \begin_layout Standard
41935 \begin_layout Standard
41943 \begin_layout Standard
41946 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
41949 \begin_layout Standard
41957 \begin_layout Standard
41965 \begin_layout Standard
41973 \begin_layout Standard
41981 \begin_layout Standard
41989 \begin_layout Standard
41997 \begin_layout Standard
42000 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
42003 \begin_layout Standard
42011 \begin_layout Standard
42019 \begin_layout Standard
42027 \begin_layout Standard
42035 \begin_layout Standard
42043 \begin_layout Standard
42046 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
42049 \begin_layout Standard
42057 \begin_layout Standard
42065 \begin_layout Standard
42073 \begin_layout Standard
42076 ; iTemp6 [lr5:16]{_near * int}[r0] =
42079 \begin_layout Standard
42082 ; iTemp6 [lr5:16]{_near * int}[r0] +
42085 \begin_layout Standard
42091 \begin_layout Standard
42099 \begin_layout Standard
42102 ; goto _whilecontinue_0($1)
42105 \begin_layout Standard
42113 \begin_layout Standard
42116 ; _whilebreak_0($3) :
42119 \begin_layout Standard
42125 \begin_layout Standard
42128 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
42131 \begin_layout Standard
42139 \begin_layout Standard
42142 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
42145 \begin_layout Standard
42153 \begin_layout Standard
42156 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
42159 \begin_layout Standard
42167 \begin_layout Standard
42170 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
42173 \begin_layout Standard
42181 \begin_layout Standard
42189 \begin_layout Standard
42192 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
42195 \begin_layout Standard
42203 \begin_layout Standard
42211 \begin_layout Standard
42217 \begin_layout Standard
42223 \begin_layout Standard
42226 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
42229 \begin_layout Standard
42232 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
42235 \begin_layout Standard
42243 \begin_layout Standard
42251 \begin_layout Standard
42259 \begin_layout Standard
42267 \begin_layout Standard
42275 \begin_layout Standard
42281 \begin_layout Standard
42284 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
42287 \begin_layout Standard
42290 ; iTemp21 [lr21:38]{short}[r4]
42293 \begin_layout Standard
42301 \begin_layout Standard
42309 \begin_layout Standard
42317 \begin_layout Standard
42320 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
42323 \begin_layout Standard
42331 \begin_layout Standard
42339 \begin_layout Standard
42347 \begin_layout Standard
42355 \begin_layout Standard
42358 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
42361 \begin_layout Standard
42364 ; iTemp15 [lr29:30]{short}[r1]
42367 \begin_layout Standard
42375 \begin_layout Standard
42383 \begin_layout Standard
42386 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
42389 \begin_layout Standard
42397 \begin_layout Standard
42405 \begin_layout Standard
42413 \begin_layout Standard
42421 \begin_layout Standard
42429 \begin_layout Standard
42437 \begin_layout Standard
42440 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
42443 \begin_layout Standard
42451 \begin_layout Standard
42459 \begin_layout Standard
42467 \begin_layout Standard
42475 \begin_layout Standard
42483 \begin_layout Standard
42491 \begin_layout Standard
42494 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
42497 \begin_layout Standard
42505 \begin_layout Standard
42508 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
42511 \begin_layout Standard
42519 \begin_layout Standard
42524 cjne r5,#0xff,00104$
42527 \begin_layout Standard
42535 \begin_layout Standard
42538 ; goto _forcond_0($4)
42541 \begin_layout Standard
42549 \begin_layout Standard
42552 ; _forbreak_0($7) :
42555 \begin_layout Standard
42561 \begin_layout Standard
42564 ; ret iTemp24 [lr40:41]{short}
42567 \begin_layout Standard
42575 \begin_layout Standard
42583 \begin_layout Standard
42591 \begin_layout Standard
42597 \begin_layout Standard
42603 \begin_layout Standard
42613 \begin_layout Section
42614 A few words about basic block successors, predecessors and dominators
42617 \begin_layout Standard
42618 Successors are basic blocks
42619 \begin_inset LatexCommand index
42620 name "Basic blocks"
42624 that might execute after this basic block.
42626 Predecessors are basic blocks
42627 that might execute before reaching this basic block.
42629 Dominators are basic
42630 blocks that WILL execute before reaching this basic block.
42635 \begin_layout Standard
42639 \begin_layout Standard
42643 \begin_layout Standard
42651 \begin_layout Standard
42655 \begin_layout Standard
42663 \begin_layout Standard
42669 \begin_layout Standard
42670 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
42673 \begin_layout Standard
42674 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
42677 \begin_layout Standard
42678 c) domVect of [BB4] = BB1 ...
42679 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
42683 \begin_layout Chapter
42687 \begin_layout Standard
42688 \begin_inset LatexCommand url
42689 target "http://sdcc.sourceforge.net/#Who"
42699 Thanks to all the other volunteer developers who have helped with coding,
42700 testing, web-page creation, distribution sets, etc.
42701 You know who you are :-)
42709 Thanks to Sourceforge
42710 \begin_inset LatexCommand url
42711 target "http://www.sf.net"
42715 which has hosted the project since 1999 and donates significant download
42724 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
42725 cycles and bandwidth for snapshot builds.
42730 \begin_layout Standard
42731 This document was initially written by Sandeep Dutta
42734 \begin_layout Standard
42735 All product names mentioned herein may be trademarks
42736 \begin_inset LatexCommand index
42741 of their respective companies.
42745 \begin_layout Section*
42749 \begin_layout Standard
42750 To avoid confusion, the installation and building options for SDCC itself
42751 (chapter 2) are not part of the index.
42754 \begin_layout Standard
42755 \begin_inset LatexCommand printindex