1 #LyX 1.5.7 created this file. For more info see http://www.lyx.org/
7 \pdfoptionpdfminorversion=3
9 pdftitle={SDCC Compiler User Guide},
10 pdfauthor={SDCC development team},
11 pdfsubject={installation, user manual},
12 pdfkeywords={68hc08 8032 8051 ansi c compiler assembler CPU DS390 embedded development free Floating Point Arithmetic Freescale GPL HC08 inline Intel ISO/IEC 9899:1990 Linux MAC OS X manual Maxim mcs51 Microchip microcontroller open source PIC Unix Windows Z80 Zilog},
13 pdfpagemode=UseOutlines,
15 linkcolor=blue] {hyperref}
19 \emergencystretch=30pt
24 \inputencoding default
27 \font_typewriter courier
28 \font_default_family default
34 \paperfontsize default
36 \papersize letterpaper
42 \paperorientation portrait
49 \paragraph_separation indent
51 \quotes_language swedish
55 \tracking_changes false
63 \begin_layout Standard
64 \begin_inset Note Note
67 \begin_layout Standard
68 Please note: double dashed longoptions (e.g.
69 --version) are written this way: -
73 \begin_layout Standard
85 \begin_layout Standard
87 three consecutive dashes would otherwise result in a long resp.
91 \begin_layout Standard
92 Architecture specific stuff (like memory models, code examples) should maybe
96 \begin_layout Standard
97 into separate sections/chapters/appendices (it is hard to document PIC or
101 \begin_layout Standard
102 a 8051 centered document) - for now simply add.
111 SDCC Compiler User Guide
126 \begin_layout Standard
127 \begin_inset Note Note
130 \begin_layout Standard
131 The above strings enclosed in $ are automatically updated by Subversion
139 \begin_layout Standard
140 \begin_inset LatexCommand tableofcontents
147 \begin_layout Chapter
151 \begin_layout Section
155 \begin_layout Standard
176 ompiler) is free open source, retargettable, optimizing ANSI-C compiler
181 designed for 8 bit Microprocessors.
182 The current version targets Intel MCS51 based Microprocessors (8031, 8032,
184 \begin_inset LatexCommand index
185 name "8031, 8032, 8051, 8052, mcs51 CPU"
189 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
190 Zilog Z80 based MCUs.
191 It can be retargeted for other microprocessors, support for Microchip PIC,
192 Atmel AVR is under development.
193 The entire source code for the compiler is distributed under GPL.
195 \begin_inset LatexCommand index
196 name "asXXXX (as-gbz80, as-hc08, asx8051, as-z80)"
201 \begin_inset LatexCommand index
206 , an open source retargetable assembler & linker.
207 SDCC has extensive language extensions suitable for utilizing various microcont
208 rollers and underlying hardware effectively.
213 In addition to the MCU specific optimizations SDCC also does a host of
214 standard optimizations like:
217 \begin_layout Itemize
218 global sub expression elimination,
221 \begin_layout Itemize
222 loop optimizations (loop invariant, strength reduction of induction variables
226 \begin_layout Itemize
227 constant folding & propagation,
230 \begin_layout Itemize
234 \begin_layout Itemize
235 dead code elimination
238 \begin_layout Itemize
246 \begin_layout Standard
247 For the back-end SDCC uses a global register allocation scheme which should
248 be well suited for other 8 bit MCUs.
253 The peep hole optimizer uses a rule based substitution mechanism which
259 Supported data-types are:
262 \begin_layout Standard
264 <lyxtabular version="3" rows="8" columns="5">
266 <column alignment="center" valignment="top" leftline="true" width="0">
267 <column alignment="center" valignment="top" leftline="true" width="0">
268 <column alignment="center" valignment="top" leftline="true" width="0">
269 <column alignment="center" valignment="top" leftline="true" width="0">
270 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
271 <row topline="true" bottomline="true">
272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
275 \begin_layout Standard
281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
284 \begin_layout Standard
290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
293 \begin_layout Standard
299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
302 \begin_layout Standard
308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
311 \begin_layout Standard
319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
322 \begin_layout Standard
328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
331 \begin_layout Standard
337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
340 \begin_layout Standard
346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
349 \begin_layout Standard
355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
358 \begin_layout Standard
366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
369 \begin_layout Standard
375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
378 \begin_layout Standard
384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
387 \begin_layout Standard
393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
396 \begin_layout Standard
402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
405 \begin_layout Standard
413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
416 \begin_layout Standard
422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
425 \begin_layout Standard
431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
434 \begin_layout Standard
440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
443 \begin_layout Standard
449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
452 \begin_layout Standard
460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
463 \begin_layout Standard
469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
472 \begin_layout Standard
478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
481 \begin_layout Standard
487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
490 \begin_layout Standard
496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
499 \begin_layout Standard
506 <row topline="true" bottomline="true">
507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
510 \begin_layout Standard
516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
519 \begin_layout Standard
525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
528 \begin_layout Standard
534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
537 \begin_layout Standard
538 -2.147.483.648, +2.147.483.647
543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
546 \begin_layout Standard
553 <row topline="true" bottomline="true">
554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
557 \begin_layout Standard
563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
566 \begin_layout Standard
572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
575 \begin_layout Standard
581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
584 \begin_layout Standard
590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
593 \begin_layout Standard
609 <row topline="true" bottomline="true">
610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
613 \begin_layout Standard
619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
622 \begin_layout Standard
628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
631 \begin_layout Standard
637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
640 \begin_layout Standard
646 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
649 \begin_layout Standard
662 The compiler also allows
664 inline assembler code
666 to be embedded anywhere in a function.
667 In addition, routines developed in assembly can also be called.
672 provides an option (-
676 \begin_layout Standard
685 -cyclomatic) to report the relative complexity of a function.
686 These functions can then be further optimized, or hand coded in assembly
692 SDCC also comes with a companion source level debugger SDCDB.
693 The debugger currently uses ucSim, a free open source simulator for 8051
694 and other micro-controllers.
698 The latest SDCC version can be downloaded from
700 \begin_inset LatexCommand url
701 target "http://sdcc.sourceforge.net/snap.php"
708 Please note: the compiler will probably always be some steps ahead of this
713 \begin_inset LatexCommand index
714 name "Status of documentation"
722 \begin_layout Standard
723 Obviously this has pros and cons
731 \begin_layout Section
735 \begin_layout Standard
736 All packages used in this compiler system are
744 ; source code for all the sub-packages (pre-processor, assemblers, linkers
745 etc.) is distributed with the package.
746 This documentation is maintained using a free open source word processor
749 This program is free software; you can redistribute it and/or modify
750 it under the terms of the GNU General Public License
751 \begin_inset LatexCommand index
752 name "GNU General Public License, GPL"
756 as published by the Free Software Foundation; either version 2, or (at
757 your option) any later version.
758 This program is distributed in the hope that it will be useful, but WITHOUT
759 ANY WARRANTY; without even the implied warranty
760 \begin_inset LatexCommand index
765 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
766 See the GNU General Public License for more details.
767 You should have received a copy of the GNU General Public License along
768 with this program; if not, write to the Free Software Foundation, 59 Temple
769 Place - Suite 330, Boston, MA 02111-1307, USA.
770 In other words, you are welcome to use, share and improve this program.
771 You are forbidden to forbid anyone else to use, share and improve what
773 Help stamp out software-hoarding!
776 \begin_layout Section
777 Typographic conventions
778 \begin_inset LatexCommand index
779 name "Typographic conventions"
786 \begin_layout Standard
787 Throughout this manual, we will use the following convention.
788 Commands you have to type in are printed in
796 Code samples are printed in
801 Interesting items and new terms are printed in
806 \begin_layout Section
808 \begin_inset LatexCommand label
809 name "sec:Compatibility-with-previous"
813 with previous versions
814 \begin_inset LatexCommand index
815 name "Compatibility with previous versions"
822 \begin_layout Standard
823 Newer versions have usually numerous bug fixes compared with the previous
825 But we also sometimes introduce some incompatibilities with older versions.
826 Not just for the fun of it, but to make the compiler more stable, efficient
828 \begin_inset LatexCommand index
829 name "ANSI-compliance"
834 \begin_inset LatexCommand ref
835 reference "sub:ANSI-Compliance"
839 for ANSI-Compliance).
841 \begin_inset Note Note
844 \begin_layout Standard
845 It would be fine to add to each item, in which version was it changed.
855 \begin_layout Itemize
856 short is now equivalent to int (16 bits), it used to be equivalent to char
857 (8 bits) which is not ANSI compliant.
858 To maintain compatibility, old programs may be compiled using the -
862 \begin_layout Standard
871 -short-is-8bits commandline option (see
872 \begin_inset LatexCommand vref
873 reference "lyx:--short-is-8bits"
880 \begin_layout Itemize
881 the default directory for gcc-builds where include, library and documentation
882 files are stored is now in /usr/local/share.
885 \begin_layout Itemize
886 char type parameters to vararg
887 \begin_inset LatexCommand index
888 name "vararg, va\\_arg"
892 functions are casted to int unless explicitly casted and
898 \begin_layout Standard
908 \begin_inset LatexCommand index
921 \begin_layout Standard
931 \begin_inset LatexCommand index
938 command line option are not defined
939 \begin_inset Marginal
942 \begin_layout Standard
967 will push a as an int and as a char resp if
973 \begin_layout Standard
983 \begin_inset LatexCommand index
996 \begin_layout Standard
1006 \begin_inset LatexCommand index
1013 command line options are not defined,
1015 will push a as two ints if
1021 \begin_layout Standard
1031 \begin_inset LatexCommand index
1044 \begin_layout Standard
1054 \begin_inset LatexCommand index
1061 command line option is defined.
1064 \begin_layout Itemize
1069 \begin_layout Standard
1078 -regextend has been removed.
1081 \begin_layout Itemize
1086 \begin_layout Standard
1095 -noregparms has been removed.
1098 \begin_layout Itemize
1103 \begin_layout Standard
1112 -stack-after-data has been removed.
1115 \begin_layout Itemize
1117 \begin_inset LatexCommand index
1123 \begin_inset LatexCommand index
1129 \begin_inset LatexCommand index
1134 types now consistently behave like the C99 _Bool type with respect to type
1136 \begin_inset LatexCommand index
1137 name "type conversion"
1142 \begin_inset LatexCommand index
1143 name "type promotion"
1148 The most common incompatibility resulting from this change is related to
1150 \begin_inset LatexCommand index
1166 \begin_inset LatexCommand index
1167 name "\\~\\/ Operator"
1171 b; /* equivalent to b=1 instead of toggling b */
1172 \begin_inset Marginal
1175 \begin_layout Standard
1188 b = !b; /* toggles b */
1192 In previous versions, both forms would have toggled the bit.
1195 \begin_layout Itemize
1196 in older versions, the preprocessor was always called with
1202 \begin_layout Standard
1212 \begin_inset LatexCommand index
1225 \begin_layout Standard
1237 This is no longer true, and can cause compilation failures on code built
1244 \begin_layout Standard
1254 \begin_inset LatexCommand index
1261 but using c99 preprocessor features, such as one-line (//) comments
1264 \begin_layout Itemize
1265 in versions older then 2.8.4 the pic16 *printf() and printf_tiny() library
1266 functions supported undocumented and not standard compliant 'b' binary
1267 format specifier ("%b", "%hb" and "%lb").
1268 The 'b' specifier is now disabled by default.
1269 It can be enabled by defining BINARY_SPECIFIER macro in files device/lib/pic16/
1270 libc/stdio/vfprintf.c and device/lib/pic16/libc/stdio/printf_tiny.c and recompilin
1274 \begin_layout Itemize
1275 in versions older then 2.8.5 the unnamed bitfield structure members participated
1276 in initialization, which is not conforming with ISO/IEC 9899:1999 standard
1277 (see section Section 6.7.8 Initialization, clause 9)
1281 Old behavior, before
1317 /* s.a = 1, s.b = 3 */
1358 /* s.a = 1, s.b = 2 */
1361 \begin_layout Section
1365 \begin_layout Standard
1366 What do you need before you start installation of SDCC? A computer, and
1367 a desire to compute.
1368 The preferred method of installation is to compile SDCC from source using
1370 For Windows some pre-compiled binary distributions are available for your
1372 You should have some experience with command line tools and compiler use.
1375 \begin_layout Section
1379 \begin_layout Standard
1380 The SDCC home page at
1381 \begin_inset LatexCommand url
1382 target "http://sdcc.sourceforge.net/"
1386 is a great place to find distribution sets.
1387 You can also find links to the user mailing lists that offer help or discuss
1388 SDCC with other SDCC users.
1389 Web links to other SDCC related sites can also be found here.
1390 This document can be found in the DOC directory of the source package as
1391 a text or HTML file.
1392 A pdf version of this document is available at
1393 \begin_inset LatexCommand url
1394 target "http://sdcc.sourceforge.net/doc/sdccman.pdf"
1399 Some of the other tools (simulator and assembler) included with SDCC contain
1400 their own documentation and can be found in the source distribution.
1401 If you want the latest unreleased software, the complete source package
1402 is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1406 \begin_layout Section
1407 Wishes for the future
1410 \begin_layout Standard
1411 There are (and always will be) some things that could be done.
1412 Here are some I can think of:
1417 \begin_layout Standard
1420 char KernelFunction3(char p) at 0x340;
1425 \begin_layout Standard
1429 \begin_inset LatexCommand index
1430 name "code banking (limited support)"
1440 If you can think of some more, please see the section
1441 \begin_inset LatexCommand ref
1442 reference "sub:Requesting-Features"
1446 about filing feature requests
1447 \begin_inset LatexCommand index
1448 name "Requesting features"
1453 \begin_inset LatexCommand index
1454 name "Feature request"
1463 \begin_layout Chapter
1465 \begin_inset LatexCommand index
1473 \begin_layout Standard
1474 For most users it is sufficient to skip to either section
1475 \begin_inset LatexCommand ref
1476 reference "sub:Building-SDCC-on-Linux"
1481 \begin_inset LatexCommand ref
1482 reference "sub:Windows-Install"
1487 More detailed instructions follow below.
1490 \begin_layout Section
1492 \begin_inset LatexCommand index
1493 name "Options SDCC configuration"
1500 \begin_layout Standard
1501 The install paths, search paths and other options are defined when running
1503 The defaults can be overridden by:
1507 \labelwidthstring 00.00.0000
1512 \begin_layout Standard
1521 -prefix see table below
1525 \labelwidthstring 00.00.0000
1530 \begin_layout Standard
1539 -exec_prefix see table below
1543 \labelwidthstring 00.00.0000
1548 \begin_layout Standard
1557 -bindir see table below
1561 \labelwidthstring 00.00.0000
1566 \begin_layout Standard
1575 -datadir see table below
1579 \labelwidthstring 00.00.0000
1584 \begin_layout Standard
1593 -datarootdir see table below
1599 \labelwidthstring 00.00.0000
1602 docdir environment variable, see table below
1606 \labelwidthstring 00.00.0000
1609 include_dir_suffix environment variable, see table below
1613 \labelwidthstring 00.00.0000
1616 lib_dir_suffix environment variable, see table below
1620 \labelwidthstring 00.00.0000
1623 sdccconf_h_dir_separator environment variable, either / or
1628 This character will only be used in sdccconf.h; don't forget it's a C-header,
1629 therefore a double-backslash is needed there.
1635 \labelwidthstring 00.00.0000
1640 \begin_layout Standard
1649 -disable-mcs51-port Excludes the Intel mcs51 port
1653 \labelwidthstring 00.00.0000
1658 \begin_layout Standard
1667 -disable-gbz80-port Excludes the Gameboy gbz80 port
1671 \labelwidthstring 00.00.0000
1676 \begin_layout Standard
1685 -disable-z80-port Excludes the z80 port
1689 \labelwidthstring 00.00.0000
1694 \begin_layout Standard
1703 -disable-avr-port Excludes the AVR port
1707 \labelwidthstring 00.00.0000
1712 \begin_layout Standard
1721 -disable-ds390-port Excludes the DS390 port
1725 \labelwidthstring 00.00.0000
1730 \begin_layout Standard
1739 -disable-hc08-port Excludes the HC08 port
1743 \labelwidthstring 00.00.0000
1748 \begin_layout Standard
1757 -disable-pic-port Excludes the PIC14 port
1761 \labelwidthstring 00.00.0000
1766 \begin_layout Standard
1775 -disable-pic16-port Excludes the PIC16 port
1779 \labelwidthstring 00.00.0000
1784 \begin_layout Standard
1793 -disable-xa51-port Excludes the XA51 port
1797 \labelwidthstring 00.00.0000
1802 \begin_layout Standard
1811 -disable-ucsim Disables configuring and building of ucsim
1815 \labelwidthstring 00.00.0000
1820 \begin_layout Standard
1829 -disable-device-lib Disables automatically building device libraries
1833 \labelwidthstring 00.00.0000
1838 \begin_layout Standard
1847 -disable-packihx Disables building packihx
1853 \labelwidthstring 00.00.0000
1858 \begin_layout Standard
1867 -enable-doc Build pdf, html and txt files from the lyx sources
1871 \labelwidthstring 00.00.0000
1876 \begin_layout Standard
1885 -enable-libgc Use the Bohem memory allocator.
1886 Lower runtime footprint.
1890 \labelwidthstring 00.00.0000
1895 \begin_layout Standard
1904 -without-ccache Do not use ccache even if available
1907 \begin_layout Standard
1908 Furthermore the environment variables CC, CFLAGS, ...
1909 the tools and their arguments can be influenced.
1910 Please see `configure -
1914 \begin_layout Standard
1923 -help' and the man/info pages of `configure' for details.
1928 standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1929 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1930 SDCC_LIB_NAME are defined by `configure' too.
1931 At the moment it's not possible to change the default settings (it was
1932 simply never required).
1936 These configure options are compiled into the binaries,
1937 and can only be changed by rerunning 'configure' and recompiling SDCC.
1938 The configure options are written in
1942 to distinguish them from run time environment variables (see section search
1948 \begin_inset Quotes sld
1952 \begin_inset Quotes srd
1955 are used by the SDCC team to build the official Win32 binaries.
1956 The SDCC team uses Mingw32 to build the official Windows binaries, because
1960 \begin_layout Enumerate
1964 \begin_layout Enumerate
1965 a gcc compiler and last but not least
1968 \begin_layout Enumerate
1969 the binaries can be built by cross compiling on SDCC Distributed Compile
1973 \begin_layout Standard
1974 See the examples, how to pass the Win32 settings to 'configure'.
1975 The other Win32 builds using Borland, VC or whatever don't use 'configure',
1976 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1986 \begin_layout Standard
1988 \begin_inset Tabular
1989 <lyxtabular version="3" rows="9" columns="3">
1991 <column alignment="block" valignment="top" leftline="true" width="0in">
1992 <column alignment="block" valignment="top" leftline="true" width="0in">
1993 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1994 <row topline="true" bottomline="true">
1995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1998 \begin_layout Standard
2004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2007 \begin_layout Standard
2013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2016 \begin_layout Standard
2023 <row topline="true">
2024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2027 \begin_layout Standard
2035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2038 \begin_layout Standard
2044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2047 \begin_layout Standard
2056 <row topline="true">
2057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2060 \begin_layout Standard
2068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2071 \begin_layout Standard
2079 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2082 \begin_layout Standard
2091 <row topline="true">
2092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2095 \begin_layout Standard
2103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2106 \begin_layout Standard
2116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2119 \begin_layout Standard
2132 <row topline="true">
2133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2136 \begin_layout Standard
2144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2147 \begin_layout Standard
2155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2158 \begin_layout Standard
2167 <row topline="true">
2168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2171 \begin_layout Standard
2179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2182 \begin_layout Standard
2192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2195 \begin_layout Standard
2204 <row topline="true">
2205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2208 \begin_layout Standard
2216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2219 \begin_layout Standard
2229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2232 \begin_layout Standard
2245 <row topline="true">
2246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2249 \begin_layout Standard
2257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2260 \begin_layout Standard
2266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2269 \begin_layout Standard
2276 <row topline="true" bottomline="true">
2277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2280 \begin_layout Standard
2288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2291 \begin_layout Standard
2297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2300 \begin_layout Standard
2316 \begin_layout Standard
2318 'configure' also computes relative paths.
2319 This is needed for full relocatability of a binary package and to complete
2320 search paths (see section search paths below):
2325 \begin_layout Standard
2327 \begin_inset Tabular
2328 <lyxtabular version="3" rows="4" columns="3">
2330 <column alignment="block" valignment="top" leftline="true" width="0in">
2331 <column alignment="block" valignment="top" leftline="true" width="0in">
2332 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2333 <row topline="true" bottomline="true">
2334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2337 \begin_layout Standard
2343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2346 \begin_layout Standard
2352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2355 \begin_layout Standard
2362 <row topline="true" bottomline="true">
2363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2366 \begin_layout Standard
2374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2377 \begin_layout Standard
2383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2386 \begin_layout Standard
2393 <row bottomline="true">
2394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2397 \begin_layout Standard
2405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2408 \begin_layout Standard
2414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2417 \begin_layout Standard
2424 <row bottomline="true">
2425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2428 \begin_layout Standard
2436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2439 \begin_layout Standard
2445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2448 \begin_layout Standard
2464 \begin_layout Standard
2469 \begin_layout LyX-Code
2476 \begin_layout Standard
2486 \begin_inset Quotes srd
2490 \begin_inset Quotes srd
2497 \begin_layout Standard
2507 \begin_inset Quotes srd
2511 \begin_inset Quotes srd
2520 \begin_layout Standard
2533 \begin_layout Standard
2545 \begin_layout Standard
2546 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2550 \begin_layout LyX-Code
2556 \begin_inset Quotes srd
2559 i586-mingw32msvc-gcc
2560 \begin_inset Quotes srd
2564 \begin_inset Quotes srd
2567 i586-mingw32msvc-g++
2568 \begin_inset Quotes srd
2576 \begin_inset Quotes srd
2579 i586-mingw32msvc-ranlib
2580 \begin_inset Quotes srd
2588 \begin_inset Quotes srd
2591 i586-mingw32msvc-strip
2592 \begin_inset Quotes srd
2603 \begin_layout Standard
2613 \begin_inset Quotes srd
2617 \begin_inset Quotes srd
2628 \begin_layout Standard
2638 \begin_inset Quotes srd
2642 \begin_inset Quotes srd
2650 \begin_inset Quotes srd
2656 \begin_inset Quotes srd
2664 \begin_inset Quotes srd
2668 \begin_inset Quotes srd
2676 \begin_inset Quotes srd
2680 \begin_inset Quotes srd
2687 sdccconf_h_dir_separator=
2688 \begin_inset Quotes srd
2700 \begin_inset Quotes srd
2711 \begin_layout Standard
2728 \begin_layout Standard
2737 -host=i586-mingw32msvc
2745 \begin_layout Standard
2754 -build=unknown-unknown-linux-gnu
2757 \begin_layout Standard
2759 \begin_inset Quotes sld
2763 \begin_inset Quotes srd
2766 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2770 \begin_layout LyX-Code
2779 \begin_layout Standard
2789 \begin_inset Quotes srd
2793 \begin_inset Quotes srd
2804 \begin_layout Standard
2814 \begin_inset Quotes srd
2818 \begin_inset Quotes srd
2826 \begin_inset Quotes srd
2832 \begin_inset Quotes srd
2840 \begin_inset Quotes srd
2844 \begin_inset Quotes srd
2852 \begin_inset Quotes srd
2856 \begin_inset Quotes srd
2863 sdccconf_h_dir_separator=
2864 \begin_inset Quotes srd
2876 \begin_inset Quotes srd
2884 \begin_inset Quotes srd
2888 \begin_inset Quotes srd
2896 \begin_inset Quotes srd
2900 \begin_inset Quotes srd
2906 \begin_layout Standard
2907 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2912 \begin_layout Standard
2921 -C' turns on caching, which gives a little bit extra speed.
2922 However if options are changed, it can be necessary to delete the config.cache
2926 \begin_layout Section
2928 \begin_inset LatexCommand label
2929 name "sub:Install-paths"
2934 \begin_inset LatexCommand index
2935 name "Install paths"
2942 \begin_layout Standard
2943 \begin_inset VSpace medskip
2949 \begin_layout Standard
2951 \begin_inset Tabular
2952 <lyxtabular version="3" rows="5" columns="4">
2954 <column alignment="left" valignment="top" leftline="true" width="0">
2955 <column alignment="left" valignment="top" leftline="true" width="0">
2956 <column alignment="left" valignment="top" leftline="true" width="0">
2957 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2958 <row topline="true" bottomline="true">
2959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2962 \begin_layout Standard
2970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2973 \begin_layout Standard
2981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2984 \begin_layout Standard
2992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2995 \begin_layout Standard
3004 <row topline="true">
3005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3008 \begin_layout Standard
3014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3017 \begin_layout Standard
3025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3028 \begin_layout Standard
3034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3037 \begin_layout Standard
3048 <row topline="true">
3049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3052 \begin_layout Standard
3058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3061 \begin_layout Standard
3064 $DATADIR/ $INCLUDE_DIR_SUFFIX
3069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3072 \begin_layout Standard
3073 /usr/local/share/sdcc/include
3078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3081 \begin_layout Standard
3092 <row topline="true">
3093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3096 \begin_layout Standard
3102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3105 \begin_layout Standard
3108 $DATADIR/$LIB_DIR_SUFFIX
3113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3116 \begin_layout Standard
3117 /usr/local/share/sdcc/lib
3122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3125 \begin_layout Standard
3136 <row topline="true" bottomline="true">
3137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3140 \begin_layout Standard
3146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3149 \begin_layout Standard
3157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3160 \begin_layout Standard
3161 /usr/local/share/sdcc/doc
3166 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3169 \begin_layout Standard
3190 *compiler, preprocessor, assembler, and linker
3196 is auto-appended by the compiler, e.g.
3197 small, large, z80, ds390 etc
3200 \begin_layout Standard
3202 The install paths can still be changed during `make install' with e.g.:
3205 \begin_layout LyX-Code
3206 make install prefix=$(HOME)/local/sdcc
3209 \begin_layout Standard
3210 Of course this doesn't change the search paths compiled into the binaries.
3215 r the install path can be changed by defining DESTDIR
3216 \begin_inset LatexCommand index
3224 \begin_layout LyX-Code
3225 make install DESTDIR=$(HOME)/sdcc.rpm/
3228 \begin_layout Standard
3229 Please note that DESTDIR must have a trailing slash!
3232 \begin_layout Section
3234 \begin_inset LatexCommand label
3235 name "sub:Search-Paths"
3240 \begin_inset LatexCommand index
3248 \begin_layout Standard
3249 Some search paths or parts of them are determined by configure variables
3254 , see section above).
3255 Further search paths are determined by environment variables during runtime.
3258 The paths searched when running the compiler are as follows (the first
3264 Binary files (preprocessor, assembler and linker)
3269 \begin_layout Standard
3271 \begin_inset Tabular
3272 <lyxtabular version="3" rows="4" columns="3">
3274 <column alignment="block" valignment="top" leftline="true" width="0in">
3275 <column alignment="block" valignment="top" leftline="true" width="0in">
3276 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3277 <row topline="true" bottomline="true">
3278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3281 \begin_layout Standard
3287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3290 \begin_layout Standard
3296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3299 \begin_layout Standard
3306 <row topline="true">
3307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3310 \begin_layout Standard
3318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3321 \begin_layout Standard
3327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3330 \begin_layout Standard
3339 <row topline="true">
3340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3343 \begin_layout Standard
3344 Path of argv[0] (if available)
3349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3352 \begin_layout Standard
3358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3361 \begin_layout Standard
3368 <row topline="true" bottomline="true">
3369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3372 \begin_layout Standard
3378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3381 \begin_layout Standard
3387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3390 \begin_layout Standard
3406 \begin_layout Standard
3414 \begin_layout Standard
3416 \begin_inset Tabular
3417 <lyxtabular version="3" rows="6" columns="3">
3419 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3420 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3421 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3422 <row topline="true" bottomline="true">
3423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3426 \begin_layout Standard
3432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3435 \begin_layout Standard
3441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3444 \begin_layout Standard
3451 <row topline="true">
3452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3455 \begin_layout Standard
3460 \begin_layout Standard
3474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3477 \begin_layout Standard
3482 \begin_layout Standard
3496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3499 \begin_layout Standard
3504 \begin_layout Standard
3519 <row topline="true">
3520 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3523 \begin_layout Standard
3529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3532 \begin_layout Standard
3538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3541 \begin_layout Standard
3548 <row topline="true">
3549 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3552 \begin_layout Standard
3564 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3567 \begin_layout Standard
3577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3580 \begin_layout Standard
3589 <row topline="true">
3590 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3593 \begin_layout Standard
3609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3612 \begin_layout Standard
3660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3663 \begin_layout Standard
3674 <row topline="true" bottomline="true">
3675 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3678 \begin_layout Standard
3692 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3695 \begin_layout Standard
3696 /usr/local/share/sdcc/
3703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3706 \begin_layout Standard
3722 \begin_layout Standard
3728 \begin_layout Standard
3737 -nostdinc disables the last two search paths.
3747 \begin_layout Standard
3748 With the exception of
3749 \begin_inset Quotes sld
3756 \begin_layout Standard
3766 \begin_inset Quotes srd
3773 is auto-appended by the compiler (e.g.
3774 small, large, z80, ds390 etc.).
3780 \begin_layout Standard
3782 \begin_inset Tabular
3783 <lyxtabular version="3" rows="6" columns="3">
3785 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3786 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3787 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3788 <row topline="true" bottomline="true">
3789 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3792 \begin_layout Standard
3798 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3801 \begin_layout Standard
3807 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3810 \begin_layout Standard
3817 <row topline="true">
3818 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3821 \begin_layout Standard
3826 \begin_layout Standard
3840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3843 \begin_layout Standard
3848 \begin_layout Standard
3862 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3865 \begin_layout Standard
3870 \begin_layout Standard
3885 <row topline="true">
3886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3889 \begin_layout Standard
3899 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3902 \begin_layout Standard
3912 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3915 \begin_layout Standard
3928 <row topline="true">
3929 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3932 \begin_layout Standard
3939 $LIB_DIR_SUFFIX/<model>
3944 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3947 \begin_layout Standard
3959 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3962 \begin_layout Standard
3977 <row topline="true">
3978 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3981 \begin_layout Standard
3992 $LIB_DIR_SUFFIX/<model>
3997 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
4000 \begin_layout Standard
4051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4054 \begin_layout Standard
4108 <row topline="true" bottomline="true">
4109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4112 \begin_layout Standard
4117 $LIB_DIR_SUFFIX/<model>
4122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4125 \begin_layout Standard
4126 /usr/local/share/sdcc/
4135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4138 \begin_layout Standard
4154 \begin_layout Standard
4155 \begin_inset Note Note
4158 \begin_layout Standard
4159 Don't delete any of the stray spaces in the table above without checking
4160 the HTML output (last line)!
4168 \begin_layout Standard
4176 \begin_layout Standard
4185 -nostdlib disables the last two search paths.
4188 \begin_layout Section
4190 \begin_inset LatexCommand index
4191 name "Building SDCC"
4198 \begin_layout Subsection
4199 Building SDCC on Linux
4200 \begin_inset LatexCommand label
4201 name "sub:Building-SDCC-on-Linux"
4208 \begin_layout Enumerate
4211 Download the source package
4213 either from the SDCC Subversion repository or from snapshot builds
4215 , it will be named something like sdcc
4226 \begin_inset LatexCommand url
4227 target "http://sdcc.sourceforge.net/snap.php"
4234 \begin_layout Enumerate
4237 Bring up a command line terminal, such as xterm.
4240 \begin_layout Enumerate
4243 Unpack the file using a command like:
4248 "tar -xvjf sdcc-src-yyyymmdd-rrrr.tar.bz2
4249 \begin_inset Quotes srd
4255 , this will create a sub-directory called sdcc with all of the sources.
4258 \begin_layout Enumerate
4259 Change directory into the main SDCC directory, for example type:
4267 \begin_layout Enumerate
4279 This configures the package for compilation on your system.
4282 \begin_layout Enumerate
4298 All of the source packages will compile, this can take a while.
4301 \begin_layout Enumerate
4317 This copies the binary executables, the include files, the libraries and
4318 the documentation to the install directories.
4319 Proceed with section
4320 \begin_inset LatexCommand ref
4321 reference "sec:Testing-the-SDCC"
4328 \begin_layout Subsection
4329 Building SDCC on Mac OS X
4332 \begin_layout Standard
4333 Follow the instruction for Linux.
4337 On Mac OS X 10.2.x it was reported, that the
4338 default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
4339 Fortunately there's also gcc 2.9.x installed, which works fine.
4340 This compiler can be selected by running 'configure' with:
4343 \begin_layout LyX-Code
4344 ./configure CC=gcc2 CXX=g++2
4347 \begin_layout Standard
4348 Universal (ppc and i386) binaries can be produced on Mac OS X 10.4.x with
4350 Run 'configure' with:
4353 \begin_layout LyX-Code
4359 \begin_layout LyX-Code
4360 LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4366 \begin_layout LyX-Code
4367 CXXFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4373 \begin_layout LyX-Code
4374 CFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
4377 \begin_layout Subsection
4378 Cross compiling SDCC on Linux for Windows
4381 \begin_layout Standard
4382 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
4383 See section 'Configure Options'.
4386 \begin_layout Subsection
4387 Building SDCC using Cygwin and Mingw32
4390 \begin_layout Standard
4391 For building and installing a Cygwin executable follow the instructions
4397 \begin_inset Quotes sld
4401 \begin_inset Quotes srd
4404 Win32-binary can be built, which will not need the Cygwin-DLL.
4405 For the necessary 'configure' options see section 'configure options' or
4406 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4411 Cygwin on Windows download setup.exe from
4412 \begin_inset LatexCommand url
4413 name "www.cygwin.com"
4414 target "http://www.cygwin.com/"
4420 \begin_inset Quotes sld
4423 default text file type
4424 \begin_inset Quotes srd
4428 \begin_inset Quotes sld
4432 \begin_inset Quotes srd
4435 and download/install at least the following packages.
4436 Some packages are selected by default, others will be automatically selected
4437 because of dependencies with the manually selected packages.
4438 Never deselect these packages!
4441 \begin_layout Itemize
4445 \begin_layout Itemize
4449 \begin_layout Itemize
4450 gcc ; version 3.x is fine, no need to use the old 2.9x
4453 \begin_layout Itemize
4454 binutils ; selected with gcc
4457 \begin_layout Itemize
4461 \begin_layout Itemize
4462 rxvt ; a nice console, which makes life much easier under windoze (see below)
4465 \begin_layout Itemize
4466 man ; not really needed for building SDCC, but you'll miss it sooner or
4470 \begin_layout Itemize
4471 less ; not really needed for building SDCC, but you'll miss it sooner or
4475 \begin_layout Itemize
4476 svn ; only if you use Subversion access
4479 \begin_layout Standard
4480 If you want to develop something you'll need:
4483 \begin_layout Itemize
4484 python ; for the regression tests
4487 \begin_layout Itemize
4488 gdb ; the gnu debugger, together with the nice GUI
4489 \begin_inset Quotes sld
4493 \begin_inset Quotes srd
4499 \begin_layout Itemize
4500 openssh ; to access the CF or commit changes
4503 \begin_layout Itemize
4504 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4505 use autoconf-stable!
4508 \begin_layout Standard
4509 rxvt is a nice console with history.
4510 Replace in your cygwin.bat the line
4513 \begin_layout LyX-Code
4518 \begin_layout Standard
4530 \begin_layout Standard
4534 \begin_layout LyX-Code
4535 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4538 \begin_layout LyX-Code
4539 -bg black -fg white -geometry 100x65 -e bash -
4543 \begin_layout Standard
4555 \begin_layout Standard
4556 Text selected with the mouse is automatically copied to the clipboard, pasting
4557 works with shift-insert.
4561 The other good tip is to make sure you have no //c/-styl
4562 e paths anywhere, use /cygdrive/c/ instead.
4563 Using // invokes a network lookup which is very slow.
4565 \begin_inset Quotes sld
4569 \begin_inset Quotes srd
4572 is too long, you can change it with e.g.
4575 \begin_layout LyX-Code
4579 \begin_layout Standard
4580 SDCC sources use the unix line ending LF.
4581 Life is much easier, if you store the source tree on a drive which is mounted
4583 And use an editor which can handle LF-only line endings.
4584 Make sure not to commit files with windows line endings.
4585 The tabulator spacing
4586 \begin_inset LatexCommand index
4587 name "tabulator spacing (8 columns)"
4591 used in the project is 8.
4592 Although a tabulator spacing of 8 is a sensible choice for programmers
4593 (it's a power of 2 and allows to display 8/16 bit signed variables without
4594 loosing columns) the plan is to move towards using only spaces in the source.
4597 \begin_layout Subsection
4598 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4601 \begin_layout Standard
4604 Download the source package
4606 either from the SDCC Subversion repository or from the
4607 \begin_inset LatexCommand url
4608 name "snapshot builds"
4609 target "http://sdcc.sourceforge.net/snap.php"
4615 , it will be named something like sdcc
4619 -yyyymmdd-rrrr.tar.bz2.
4622 SDCC is distributed with all the projects, workspaces, and files you need
4623 to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4624 The workspace name is 'sdcc.dsw'.
4625 Please note that as it is now, all the executables are created in a folder
4629 Once built you need to copy the executables from sdcc
4633 bin before running SDCC.
4638 WARNING: Visual studio is very picky with line terminations; it expects
4639 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4640 When using the Subversion repository it's easiest to configure the svn
4641 client to convert automatically for you.
4642 If however you are getting a message such as "This makefile was not generated
4643 by Developer Studio etc.
4645 \begin_inset Quotes srd
4648 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4649 need to convert the Unix style line endings to DOS style line endings.
4650 To do so you can use the
4651 \begin_inset Quotes sld
4655 \begin_inset Quotes srd
4658 utility freely available on the internet.
4659 Doug Hawkins reported in the sdcc-user list that this works:
4667 SDCC> unix2dos sdcc.dsw
4673 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4677 In order to build SDCC with MSVC
4678 you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4679 One good place to get them is
4680 \begin_inset LatexCommand url
4682 target "http://unxutils.sourceforge.net"
4690 Download the file UnxUtils
4691 \begin_inset LatexCommand index
4697 Now you have to install the utilities and setup MSVC so it can locate the
4699 Here there are two alternatives (choose one!):
4702 \begin_layout Enumerate
4707 a) Extract UnxUtils.zip to your C:
4709 hard disk PRESERVING the original paths, otherwise bison won't work.
4710 (If you are using WinZip make certain that 'Use folder names' is selected)
4715 In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4716 'Show directories for:' select 'Executable files', and in the directories
4717 window add a new path: 'C:
4727 (As a side effect, you get a bunch of Unix utilities that
4728 could be useful, such as diff and patch.)
4731 \begin_layout Enumerate
4736 This one avoids extracting a bunch of files you may not
4737 use, but requires some extra work:
4741 a) Create a directory were to put the
4742 tools needed, or use a directory already present.
4749 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4750 gawk.exe to such directory WITHOUT preserving the original paths.
4751 (If you are using WinZip make certain that 'Use folder names' is not selected)
4756 ) Rename bison.exe to '_bison.exe'.
4760 d) Create a batch file 'bison.bat' in 'C:
4764 ' and add these lines:
4784 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4788 Steps 'c' and 'd' are needed
4789 because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4790 reside in some weird Unix directory, '/usr/local/share/' I think.
4791 So it is necessary to tell bison where those files are located if they
4792 are not in such directory.
4793 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4798 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4799 in 'Show directories for:' select 'Executable files', and in the directories
4800 window add a new path: 'c:
4803 Note that you can use any other path instead of 'c:
4805 util', even the path where the Visual C++ tools are, probably: 'C:
4809 Microsoft Visual Studio
4814 So you don't have to execute step 'e' :)
4817 \begin_layout Standard
4819 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4820 the executables from sdcc
4824 bin, and you can compile using SDCC.
4827 \begin_layout Subsection
4828 Building SDCC Using Borland
4831 \begin_layout Enumerate
4832 From the sdcc directory, run the command "make -f Makefile.bcc".
4833 This should regenerate all the .exe files in the bin directory except for
4837 \begin_layout Enumerate
4838 If you modify any source files and need to rebuild, be aware that the dependenci
4839 es may not be correctly calculated.
4840 The safest option is to delete all .obj files and run the build again.
4841 From a Cygwin BASH prompt, this can easily be done with the command (be
4842 sure you are in the sdcc directory):
4852 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
4854 ) -print -exec rm {}
4863 or on Windows NT/2000/XP from the command prompt with the command:
4870 del /s *.obj *.lib *.rul
4873 from the sdcc directory.
4876 \begin_layout Subsection
4877 Windows Install Using a ZIP Package
4880 \begin_layout Enumerate
4881 Download the binary zip package from
4882 \begin_inset LatexCommand url
4883 target "http://sdcc.sf.net/snap.php"
4887 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4888 This should unpack to a group of sub-directories.
4889 An example directory structure after unpacking the mingw32 package is:
4894 bin for the executables, c:
4902 lib for the include and libraries.
4905 \begin_layout Enumerate
4906 Adjust your environment variable PATH to include the location of the bin
4907 directory or start sdcc using the full path.
4910 \begin_layout Subsection
4911 Windows Install Using the Setup Program
4912 \begin_inset LatexCommand label
4913 name "sub:Windows-Install"
4920 \begin_layout Standard
4921 Download the setup program
4923 sdcc-x.y.z-setup.exe
4925 for an official release from
4928 \begin_inset LatexCommand url
4929 target "http://sf.net/project/showfiles.php?group_id=599"
4933 or a setup program for one of the snapshots
4935 sdcc-yyyymmdd-xxxx-setup.exe
4938 \begin_inset LatexCommand url
4939 target "http://sdcc.sf.net/snap.php"
4944 A windows typical installer will guide you through the installation process.
4947 \begin_layout Subsection
4949 \begin_inset LatexCommand index
4957 \begin_layout Standard
4958 SDCC supports the VPATH feature provided by configure and make.
4959 It allows to separate the source and build trees.
4963 \begin_layout Standard
5005 \begin_layout Standard
5008 tar -xjf sdcc-src-yyyymmdd-rrrr.tar.bz2\InsetSpace ~
5009 # extract source to directory sdcc
5012 \begin_layout Standard
5015 mkdir sdcc.build\InsetSpace ~
5039 # put output in sdcc.build
5042 \begin_layout Standard
5048 \begin_layout Standard
5051 ../sdcc/configure\InsetSpace ~
5074 # configure is doing all the magic!
5077 \begin_layout Standard
5083 \begin_layout Standard
5089 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
5090 It automagically computes the variables srcdir, top_srcdir and top_buildir
5096 the generated files will be in ~/sdcc.build, while the source files stay
5099 This is not only usefull for building different binaries, e.g.
5100 when cross compiling.
5101 It also gives you a much better overview in the source tree when all the
5102 generated files are not scattered between the source files.
5103 And the best thing is: if you want to change a file you can leave the original
5104 file untouched in the source directory.
5105 Simply copy it to the build directory, edit it, enter `make clean', `rm
5106 Makefile.dep' and `make'.
5111 will do the rest for you!
5114 \begin_layout Section
5115 Building the Documentation
5118 \begin_layout Standard
5123 \begin_layout Standard
5132 -enable-doc to the configure arguments to build the documentation together
5133 with all the other stuff.
5134 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
5135 dvips and makeindex) to get the job done.
5136 Another possibility is to change to the doc directory and to type
5140 \begin_inset Quotes srd
5144 \begin_inset Quotes srd
5151 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
5154 \begin_inset LatexCommand url
5155 target "http://www.lyx.org"
5159 as editor is straightforward.
5160 Prebuilt documentation in html and pdf format is available from
5161 \begin_inset LatexCommand url
5162 target "http://sdcc.sf.net/snap.php"
5169 \begin_layout Section
5170 Reading the Documentation
5171 \begin_inset LatexCommand index
5172 name "Documentation"
5179 \begin_layout Standard
5180 Currently reading the document in pdf format is recommended, as for unknown
5181 reason the hyperlinks are working there whereas in the html version they
5186 \begin_layout Standard
5187 If you should know why please drop us a note
5195 You'll find the pdf version
5196 \begin_inset LatexCommand index
5197 name "PDF version of this document"
5202 \begin_inset LatexCommand url
5203 target "http://sdcc.sf.net/doc/sdccman.pdf"
5211 \begin_inset LatexCommand index
5212 name "HTML version of this document"
5217 \begin_inset LatexCommand url
5218 target "http://sdcc.sf.net/doc/sdccman.html/index.html"
5224 This documentation is in some aspects different from a commercial documentation:
5228 \begin_layout Itemize
5229 It tries to document SDCC for several processor architectures in one document
5230 (commercially these probably would be separate documents/products).
5232 \begin_inset LatexCommand index
5233 name "Status of documentation"
5237 currently matches SDCC for mcs51 and DS390 best and does give too few informati
5239 Z80, PIC14, PIC16 and HC08.
5242 \begin_layout Itemize
5243 There are many references pointing away from this documentation.
5244 Don't let this distract you.
5246 was a reference like
5247 \begin_inset LatexCommand url
5248 target "http://www.opencores.org"
5252 together with a statement
5253 \begin_inset Quotes sld
5256 some processors which are targetted by SDCC can be implemented in a
5273 \begin_inset LatexCommand index
5274 name "FPGA (field programmable gate array)"
5279 \begin_inset Quotes srd
5283 \begin_inset LatexCommand url
5284 target "http://sf.net/projects/fpgac"
5289 \begin_inset LatexCommand index
5290 name "FpgaC ((subset of) C to FPGA compiler)"
5295 \begin_inset Quotes sld
5298 have you ever heard of an open source compiler that compiles a subset of
5300 \begin_inset Quotes srd
5303 we expect you to have a quick look there and come back.
5304 If you read this you are on the right track.
5307 \begin_layout Itemize
5308 Some sections attribute more space to problems, restrictions and warnings
5309 than to the solution.
5312 \begin_layout Itemize
5313 The installation section and the section about the debugger is intimidating.
5316 \begin_layout Itemize
5317 There are still lots of typos and there are more different writing styles
5321 \begin_layout Section
5322 Testing the SDCC Compiler
5323 \begin_inset LatexCommand label
5324 name "sec:Testing-the-SDCC"
5331 \begin_layout Standard
5332 The first thing you should do after installing your SDCC compiler is to
5341 \begin_layout Standard
5351 \begin_inset LatexCommand index
5359 at the prompt, and the program should run and output its version like:
5364 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
5368 \begin_layout Standard
5369 If it doesn't run, or gives a message about not finding sdcc program, then
5370 you need to check over your installation.
5371 Make sure that the sdcc bin directory is in your executable search path
5372 defined by the PATH environment setting (
5377 \begin_inset LatexCommand ref
5378 reference "sub:Install-Trouble-shooting"
5385 Install trouble-shooting for suggestions
5388 Make sure that the sdcc program is in the bin folder, if not perhaps something
5389 did not install correctly.
5397 is commonly installed as described in section
5398 \begin_inset Quotes sld
5401 Install and search paths
5402 \begin_inset Quotes srd
5411 Make sure the compiler works on a very simple example.
5412 Type in the following test.c program using your favorite
5437 \begin_layout Standard
5440 Compile this using the following command:
5451 If all goes well, the compiler will generate a test.asm and test.rel file.
5452 Congratulations, you've just compiled your first program with SDCC.
5453 We used the -c option to tell SDCC not to link the generated code, just
5454 to keep things simple for this step.
5462 The next step is to try it with the linker.
5474 If all goes well the compiler will link with the libraries and produce
5475 a test.ihx output file.
5480 (no test.ihx, and the linker generates warnings), then the problem is most
5489 usr/local/share/sdcc/lib directory
5496 \begin_inset LatexCommand ref
5497 reference "sub:Install-Trouble-shooting"
5504 Install trouble-shooting for suggestions).
5512 The final test is to ensure
5520 header files and libraries.
5521 Edit test.c and change it to the following:
5539 strcpy(str1, "testing");
5544 \begin_layout Standard
5547 Compile this by typing
5556 This should generate a test.ihx output file, and it should give no warnings
5557 such as not finding the string.h file.
5558 If it cannot find the string.h file, then the problem is that
5562 cannot find the /usr/local/share/sdcc/include directory
5569 \begin_inset LatexCommand ref
5570 reference "sub:Install-Trouble-shooting"
5577 Install trouble-shooting section for suggestions).
5586 \begin_layout Standard
5598 \begin_inset LatexCommand index
5599 name "-\\/-print-search-dirs"
5603 to find exactly where SDCC is looking for the include and lib files.
5606 \begin_layout Section
5607 Install Trouble-shooting
5608 \begin_inset LatexCommand label
5609 name "sub:Install-Trouble-shooting"
5614 \begin_inset LatexCommand index
5615 name "Install trouble-shooting"
5622 \begin_layout Subsection
5623 If SDCC does not build correctly
5626 \begin_layout Standard
5627 A thing to try is starting from scratch by unpacking the .tgz source package
5628 again in an empty directory.
5636 ./configure 2>&1 | tee configure.log
5650 make 2>&1 | tee make.log
5657 If anything goes wrong, you can review the log files to locate the problem.
5658 Or a relevant part of this can be attached to an email that could be helpful
5659 when requesting help from the mailing list.
5662 \begin_layout Subsection
5664 \begin_inset Quotes sld
5668 \begin_inset Quotes srd
5674 \begin_layout Standard
5676 \begin_inset Quotes sld
5680 \begin_inset Quotes srd
5683 command is a script that analyzes your system and performs some configuration
5684 to ensure the source package compiles on your system.
5685 It will take a few minutes to run, and will compile a few tests to determine
5686 what compiler features are installed.
5689 \begin_layout Subsection
5691 \begin_inset Quotes sld
5695 \begin_inset Quotes srd
5701 \begin_layout Standard
5702 This runs the GNU make tool, which automatically compiles all the source
5703 packages into the final installed binary executables.
5706 \begin_layout Subsection
5708 \begin_inset Quotes sld
5712 \begin_inset Quotes erd
5718 \begin_layout Standard
5719 This will install the compiler, other executables libraries and include
5720 files into the appropriate directories.
5722 \begin_inset LatexCommand ref
5723 reference "sub:Install-paths"
5729 \begin_inset LatexCommand ref
5730 reference "sub:Search-Paths"
5735 about install and search paths.
5737 On most systems you will need super-user privilege
5741 \begin_layout Section
5745 \begin_layout Standard
5746 SDCC is not just a compiler, but a collection of tools by various developers.
5747 These include linkers, assemblers, simulators and other components.
5748 Here is a summary of some of the components.
5749 Note that the included simulator and assembler have separate documentation
5750 which you can find in the source package in their respective directories.
5751 As SDCC grows to include support for other processors, other packages from
5752 various developers are included and may have their own sets of documentation.
5757 might want to look at the files which are installed in <installdir>.
5758 At the time of this writing, we find the following programs for gcc-builds:
5763 In <installdir>/bin:
5766 \begin_layout Itemize
5767 sdcc - The compiler.
5770 \begin_layout Itemize
5771 sdcpp - The C preprocessor.
5774 \begin_layout Itemize
5775 asx8051 - The assembler for 8051 type processors.
5778 \begin_layout Itemize
5783 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5786 \begin_layout Itemize
5787 aslink -The linker for 8051 type processors.
5790 \begin_layout Itemize
5795 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5798 \begin_layout Itemize
5799 s51 - The ucSim 8051 simulator.
5802 \begin_layout Itemize
5803 sdcdb - The source debugger.
5806 \begin_layout Itemize
5807 packihx - A tool to pack (compress) Intel hex files.
5810 \begin_layout Standard
5811 In <installdir>/share/sdcc/include
5814 \begin_layout Itemize
5818 \begin_layout Standard
5819 In <installdir>/share/sdcc/lib
5822 \begin_layout Itemize
5823 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5827 \begin_layout Standard
5828 In <installdir>/share/sdcc/doc
5831 \begin_layout Itemize
5835 \begin_layout Standard
5836 As development for other processors proceeds, this list will expand to include
5837 executables to support processors like AVR, PIC, etc.
5840 \begin_layout Subsection
5844 \begin_layout Standard
5845 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5846 the assembler and linkage editor.
5849 \begin_layout Subsection
5850 sdcpp - The C-Preprocessor
5853 \begin_layout Standard
5855 \begin_inset LatexCommand index
5856 name "sdcpp (preprocessor)"
5860 is a modified version of the GNU cpp
5861 \begin_inset LatexCommand index
5862 name "cpp|see{sdcpp}"
5867 \begin_inset LatexCommand url
5868 target "http://gcc.gnu.org/"
5873 The C preprocessor is used to pull in #include sources, process #ifdef
5874 statements, #defines and so on.
5877 \begin_layout Subsection
5886 - The Assemblers and Linkage Editors
5889 \begin_layout Standard
5890 This is retargettable assembler & linkage editor, it was developed by Alan
5892 John Hartman created the version for 8051, and I (Sandeep) have made some
5893 enhancements and bug fixes for it to work properly with SDCC.
5896 \begin_layout Subsection
5900 \begin_layout Standard
5902 \begin_inset LatexCommand index
5907 is a free open source simulator developed by Daniel Drotos.
5908 The simulator is built as part of the build process.
5909 For more information visit Daniel's web site at:
5910 \begin_inset LatexCommand url
5911 target "http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51"
5916 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5920 \begin_layout Subsection
5921 sdcdb - Source Level Debugger
5924 \begin_layout Standard
5926 \begin_inset LatexCommand index
5927 name "SDCDB (debugger)"
5931 is the companion source level debugger.
5932 More about SDCDB in section
5933 \begin_inset LatexCommand ref
5934 reference "cha:Debugging-with-SDCDB"
5939 The current version of the debugger uses Daniel's Simulator S51
5940 \begin_inset LatexCommand index
5945 , but can be easily changed to use other simulators.
5948 \begin_layout Chapter
5952 \begin_layout Section
5956 \begin_layout Subsection
5957 Single Source File Projects
5960 \begin_layout Standard
5961 For single source file 8051 projects the process is very simple.
5962 Compile your programs with the following command
5965 "sdcc sourcefile.c".
5969 This will compile, assemble and link your source file.
5970 Output files are as follows:
5973 \begin_layout Itemize
5975 \begin_inset LatexCommand index
5981 \begin_inset LatexCommand index
5982 name "Assembler source"
5986 file created by the compiler
5989 \begin_layout Itemize
5991 \begin_inset LatexCommand index
5997 \begin_inset LatexCommand index
5998 name "Assembler listing"
6002 file created by the Assembler
6005 \begin_layout Itemize
6007 \begin_inset LatexCommand index
6013 \begin_inset LatexCommand index
6014 name "Assembler listing"
6018 file updated with linkedit information, created by linkage editor
6021 \begin_layout Itemize
6023 \begin_inset LatexCommand index
6029 \begin_inset LatexCommand index
6030 name "Symbol listing"
6034 for the sourcefile, created by the assembler
6037 \begin_layout Itemize
6039 \begin_inset LatexCommand index
6045 \begin_inset LatexCommand index
6051 \begin_inset LatexCommand index
6056 created by the assembler, input to Linkage editor
6059 \begin_layout Itemize
6061 \begin_inset LatexCommand index
6067 \begin_inset LatexCommand index
6072 for the load module, created by the Linker
6075 \begin_layout Itemize
6077 \begin_inset LatexCommand index
6082 - A file with a summary of the memory usage
6085 \begin_layout Itemize
6087 \begin_inset LatexCommand index
6092 - The load module in Intel hex format
6093 \begin_inset LatexCommand index
6094 name "Intel hex format"
6098 (you can select the Motorola S19 format
6099 \begin_inset LatexCommand index
6100 name "Motorola S19 format"
6108 \begin_layout Standard
6118 \begin_inset LatexCommand index
6119 name "-\\/-out-fmt-s19"
6124 If you need another format you might want to use
6131 \begin_inset LatexCommand index
6132 name "objdump (tool)"
6143 \begin_inset LatexCommand index
6144 name "srecord (bin, hex, ... tool)"
6149 \begin_inset Note Note
6152 \begin_layout Standard
6159 \begin_inset LatexCommand vref
6160 reference "sub:Postprocessing-the-Intel"
6165 Both formats are documented in the documentation of srecord
6166 \begin_inset LatexCommand index
6167 name "srecord (bin, hex, ... tool)"
6174 \begin_layout Itemize
6176 \begin_inset LatexCommand index
6181 - An intermediate file containing debug information needed to create the
6186 \begin_layout Standard
6196 \begin_inset LatexCommand index
6204 \begin_layout Itemize
6206 \begin_inset LatexCommand index
6211 - An optional file (with -
6215 \begin_layout Standard
6224 -debug) containing debug information.
6225 The format is documented in cdbfileformat.pdf
6228 \begin_layout Itemize
6231 \begin_inset LatexCommand index
6232 name "<file> (no extension)"
6236 An optional AOMF or AOMF51
6237 \begin_inset LatexCommand index
6243 \begin_inset LatexCommand label
6248 file containing debug information (generated with option -
6252 \begin_layout Standard
6278 ormat is a subformat of the OMF51 format and is commonly used by third party
6280 \begin_inset LatexCommand index
6285 , simulators, emulators).
6288 \begin_layout Itemize
6290 \begin_inset LatexCommand index
6295 - Dump file to debug the compiler it self (generated with option -
6299 \begin_layout Standard
6308 -dumpall) (see section
6309 \begin_inset LatexCommand ref
6310 reference "sub:Intermediate-Dump-Options"
6316 \begin_inset LatexCommand ref
6317 reference "sub:The-anatomy-of"
6323 \begin_inset Quotes sld
6326 Anatomy of the compiler
6327 \begin_inset Quotes srd
6333 \begin_layout Subsection
6334 Postprocessing the Intel Hex
6335 \begin_inset LatexCommand index
6336 name "Intel hex format"
6341 \begin_inset LatexCommand label
6342 name "sub:Postprocessing-the-Intel"
6349 \begin_layout Standard
6350 In most cases this won't be needed but the Intel Hex file
6351 \begin_inset LatexCommand index
6356 which is generated by SDCC might include lines of varying length and the
6357 addresses within the file are not guaranteed to be strictly ascending.
6358 If your toolchain or a bootloader does not like this you can use the tool
6364 \begin_inset LatexCommand index
6365 name "packihx (tool)"
6369 which is part of the SDCC distribution:
6376 packihx sourcefile.ihx >sourcefile.hex
6383 The separately available
6388 \begin_inset LatexCommand index
6389 name "srecord (bin, hex, ... tool)"
6393 package additionally allows to set undefined locations to a predefined
6394 value, to insert checksums
6395 \begin_inset LatexCommand index
6400 of various flavours (crc, add, xor) and to perform other manipulations
6401 (convert, split, crop, offset, ...).
6409 srec_cat\InsetSpace ~
6411 sourcefile.ihx -intel\InsetSpace ~
6413 -o sourcefile.hex -intel
6420 An example for a more complex command line
6424 \begin_layout Standard
6425 the command backfills
6426 \begin_inset LatexCommand index
6427 name "backfill unused memory"
6431 unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
6433 If the program counter on an mcs51 runs wild the backfill pattern 0x12
6434 will be interpreted as an
6442 (where an emergency routine could sit).
6455 srec_cat\InsetSpace ~
6456 sourcefile.ihx -intel\InsetSpace ~
6458 -fill 0x12 0x0000 0xfffe\InsetSpace ~
6459 -little-endian-checksum-nega
6460 tive 0xfffe 0x02 0x02\InsetSpace ~
6462 -o sourcefile.hex -intel
6471 The srecord package is available at
6472 \begin_inset LatexCommand url
6473 target "http://sf.net/projects/srecord"
6480 \begin_layout Subsection
6481 Projects with Multiple Source Files
6484 \begin_layout Standard
6485 SDCC can compile only ONE file at a time.
6486 Let us for example assume that you have a project containing the following
6491 foo1.c (contains some functions)
6493 foo2.c (contains some more functions)
6496 n.c (contains more functions and the function main)
6504 The first two files will need to be compiled separately with the commands:
6536 Then compile the source file containing the
6541 \begin_inset LatexCommand index
6546 the files together with the following command:
6554 foomain.c\InsetSpace ~
6555 foo1.rel\InsetSpace ~
6560 \begin_inset LatexCommand index
6573 can be separately compiled as well:
6584 sdcc foomain.rel foo1.rel foo2.rel
6591 The file containing the
6603 file specified in the command line, since the linkage editor processes
6604 file in the order they are presented to it.
6605 The linker is invoked from SDCC using a script file with extension .lnk
6606 \begin_inset LatexCommand index
6612 You can view this file to troubleshoot linking problems such as those arising
6613 from missing libraries.
6616 \begin_layout Subsection
6617 Projects with Additional Libraries
6618 \begin_inset LatexCommand index
6626 \begin_layout Standard
6627 Some reusable routines may be compiled into a library, see the documentation
6628 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6632 \begin_inset LatexCommand index
6640 Libraries created in this manner can be included in the command line.
6641 Make sure you include the -L <library-path> option to tell the linker where
6642 to look for these files if they are not in the current directory.
6643 Here is an example, assuming you have the source file
6655 (if that is not the same as your current project):
6662 sdcc foomain.c foolib.lib -L mylib
6673 must be an absolute path name.
6677 The most efficient way to use libraries is
6678 to keep separate modules in separate source files.
6679 The lib file now should name all the modules.rel
6680 \begin_inset LatexCommand index
6686 For an example see the standard library file
6690 in the directory <installdir>/share/lib/small.
6693 \begin_layout Subsection
6694 Using sdcclib to Create and Manage Libraries
6695 \begin_inset LatexCommand index
6703 \begin_layout Standard
6704 Alternatively, instead of having a .rel file for each entry on the library
6705 file as described in the preceding section, sdcclib can be used to embed
6706 all the modules belonging to such library in the library file itself.
6707 This results in a larger library file, but it greatly reduces the number
6708 of disk files accessed by the linker.
6709 Additionally, the packed library file contains an index of all include
6710 modules and symbols that significantly speeds up the linking process.
6711 To display a list of options supported by sdcclib type:
6716 \begin_layout Standard
6721 \begin_inset LatexCommand index
6733 To create a new library file, start by compiling all the required modules.
6739 \begin_layout Standard
6746 \begin_layout Standard
6753 \begin_layout Standard
6760 \begin_layout Standard
6767 \begin_layout Standard
6776 \begin_layout Standard
6777 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6779 The next step is to add the .rel files to the library file:
6784 \begin_layout Standard
6788 sdcclib libint.lib _divsint.rel
6791 \begin_inset LatexCommand index
6799 \begin_layout Standard
6803 sdcclib libint.lib _divuint.rel
6806 \begin_layout Standard
6810 sdcclib libint.lib _modsint.rel
6813 \begin_layout Standard
6817 sdcclib libint.lib _moduint.rel
6820 \begin_layout Standard
6824 sdcclib libint.lib _mulint.rel
6832 \begin_layout Standard
6841 \begin_layout Standard
6845 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6853 \begin_layout Standard
6854 If the file already exists in the library, it will be replaced.
6855 If a list of .rel files is available, you can tell sdcclib to add those
6857 For example, if the file 'myliblist.txt' contains
6865 \begin_layout Standard
6872 \begin_layout Standard
6879 \begin_layout Standard
6886 \begin_layout Standard
6893 \begin_layout Standard
6905 \begin_layout Standard
6914 \begin_layout Standard
6918 sdcclib -l libint.lib myliblist.txt
6926 \begin_layout Standard
6927 Additionally, you can instruct sdcclib to compiles the files before adding
6928 them to the library.
6929 This is achieved using the environment variables SDCCLIB_CC and/or SDCCLIB_AS.
6938 \begin_layout Standard
6942 set SDCCLIB_CC=sdcc -c
6945 \begin_layout Standard
6949 sdcclib -l libint.lib myliblist.txt
6957 \begin_layout Standard
6958 To see what modules and symbols are included in the library, options -s
6959 and -m are available.
6967 sdcclib -s libint.lib
6970 \begin_inset LatexCommand index
6983 \begin_layout Standard
6989 \begin_layout Standard
6995 \begin_layout Standard
7003 \begin_layout Standard
7009 \begin_layout Standard
7015 \begin_layout Standard
7021 \begin_layout Standard
7027 \begin_layout Standard
7035 \begin_layout Standard
7041 \begin_layout Standard
7047 \begin_layout Standard
7055 \begin_layout Standard
7061 \begin_layout Standard
7067 \begin_layout Standard
7073 \begin_layout Standard
7081 \begin_layout Standard
7087 \begin_layout Standard
7098 \begin_layout Standard
7099 If the source files are compiled using -
7103 \begin_layout Standard
7113 \begin_inset LatexCommand index
7118 , the corresponding debug information file .adb will be include in the library
7120 The library files created with sdcclib are plain text files, so they can
7121 be viewed with a text editor.
7122 It is not recommended to modify a library file created with sdcclib using
7123 a text editor, as there are file indexes numbers located across the file
7124 used by the linker to quickly locate the required module to link.
7125 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
7126 it can be safely deleted, since all the information required for linking
7127 is embedded in the library file itself.
7128 Library files created using sdcclib are used as described in the preceding
7132 \begin_layout Subsection
7133 Using ar to Create and Manage Libraries
7134 \begin_inset LatexCommand index
7142 \begin_layout Standard
7143 Support for ar format libraries was introduced in sdcc 2.9.0.
7144 Ar is a standard archive managing utility on unices (Linux, Mac OS X, several
7145 unix flavors) so it is not included in the sdcc package.
7153 For Windows platform you can find ar utility in GNU binutils package included
7154 in several projects: Cygwin at
7155 \begin_inset LatexCommand url
7156 target "http://www.cygwin.com/"
7161 \begin_inset LatexCommand url
7162 target "http://www.mingw.org/"
7174 Both the GNU and BSD ar format variants are suppurated by asxxxx linkers.
7175 Ar doesn't understand the asxxxx object file format, so there is a special
7176 version of ranlib distributed with sdcc, called asranlib, which produces
7177 the ar symbol lookup table.
7185 To create a library containing asxxxx object files, you should use the following
7193 \begin_layout Standard
7197 ar -Sq <library name>.lib <list of .rel files>
7200 \begin_layout Standard
7204 asranlib <library name>.lib
7207 \begin_layout Standard
7208 \begin_inset VSpace bigskip
7214 \begin_layout Section
7215 Command Line Options
7216 \begin_inset LatexCommand index
7217 name "Command Line Options"
7222 \begin_inset LatexCommand label
7223 name "sec:Command-Line-Options"
7230 \begin_layout Subsection
7231 Processor Selection Options
7232 \begin_inset LatexCommand index
7233 name "Options processor selection"
7238 \begin_inset LatexCommand index
7239 name "Processor selection options"
7247 \labelwidthstring 00.00.0000
7251 \begin_inset LatexCommand index
7258 Generate code for the Intel MCS51
7259 \begin_inset LatexCommand index
7264 family of processors.
7265 This is the default processor target.
7269 \labelwidthstring 00.00.0000
7273 \begin_inset LatexCommand index
7280 Generate code for the Dallas DS80C390
7281 \begin_inset LatexCommand index
7290 \labelwidthstring 00.00.0000
7294 \begin_inset LatexCommand index
7301 Generate code for the Dallas DS80C400
7302 \begin_inset LatexCommand index
7311 \labelwidthstring 00.00.0000
7315 \begin_inset LatexCommand index
7322 Generate code for the Freescale/Motorola HC08
7323 \begin_inset LatexCommand index
7328 family of processors.
7332 \labelwidthstring 00.00.0000
7336 \begin_inset LatexCommand index
7343 Generate code for the Zilog Z80
7344 \begin_inset LatexCommand index
7349 family of processors.
7353 \labelwidthstring 00.00.0000
7357 \begin_inset LatexCommand index
7364 Generate code for the GameBoy Z80
7365 \begin_inset LatexCommand index
7366 name "gbz80 (GameBoy Z80)"
7370 processor (Not actively maintained).
7374 \labelwidthstring 00.00.0000
7378 \begin_inset LatexCommand index
7385 Generate code for the Atmel AVR
7386 \begin_inset LatexCommand index
7391 processor (Not maintained, not complete).
7392 AVR users should probably have a look at winavr
7393 \begin_inset LatexCommand url
7394 target "http://sourceforge.net/projects/winavr"
7399 \begin_inset LatexCommand url
7400 target "http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index"
7404 , which is based on AVR-port of the gcc compiler.
7407 \begin_layout Standard
7408 \begin_inset Note Note
7411 \begin_layout Standard
7412 I think it is fair to direct users there for now.
7413 Open source is also about avoiding unnecessary work .
7414 But I didn't find the 'official' link.
7423 \labelwidthstring 00.00.0000
7427 \begin_inset LatexCommand index
7434 Generate code for the Microchip PIC 14
7435 \begin_inset LatexCommand index
7440 -bit processors (p16f84 and variants.
7441 In development, not complete).
7444 \begin_layout Standard
7445 \begin_inset Note Note
7448 \begin_layout Standard
7449 p16f627 p16f628 p16f84 p16f873 p16f877?
7458 \labelwidthstring 00.00.0000
7462 \begin_inset LatexCommand index
7469 Generate code for the Microchip PIC 16
7470 \begin_inset LatexCommand index
7475 -bit processors (p18f452 and variants.
7476 In development, not complete).
7480 \labelwidthstring 00.00.0000
7485 Generate code for the Toshiba TLCS-900H
7486 \begin_inset LatexCommand index
7491 processor (Not maintained, not complete).
7495 \labelwidthstring 00.00.0000
7499 \begin_inset LatexCommand index
7506 Generate code for the Phillips XA51
7507 \begin_inset LatexCommand index
7512 processor (Not maintained, not complete).
7515 \begin_layout Standard
7516 \begin_inset VSpace bigskip
7522 \begin_layout Subsection
7523 Preprocessor Options
7524 \begin_inset LatexCommand index
7525 name "Options preprocessor"
7530 \begin_inset LatexCommand index
7531 name "Preprocessor options"
7536 \begin_inset LatexCommand index
7537 name "sdcpp (preprocessor)"
7545 \labelwidthstring 00.00.0000
7549 \begin_inset LatexCommand index
7556 The additional location where the preprocessor will look for <..h> or
7557 \begin_inset Quotes eld
7561 \begin_inset Quotes erd
7568 \labelwidthstring 00.00.0000
7572 \begin_inset LatexCommand index
7573 name "-D<macro[=value]>"
7579 Command line definition of macros.
7580 Passed to the preprocessor.
7584 \labelwidthstring 00.00.0000
7588 \begin_inset LatexCommand index
7595 Tell the preprocessor to output a rule suitable for make describing the
7596 dependencies of each object file.
7597 For each source file, the preprocessor outputs one make-rule whose target
7598 is the object file name for that source file and whose dependencies are
7599 all the files `#include'd in it.
7600 This rule may be a single line or may be continued with `
7602 '-newline if it is long.
7603 The list of rules is printed on standard output instead of the preprocessed
7606 \begin_inset LatexCommand index
7615 \labelwidthstring 00.00.0000
7619 \begin_inset LatexCommand index
7626 Tell the preprocessor not to discard comments.
7627 Used with the `-E' option.
7631 \labelwidthstring 00.00.0000
7635 \begin_inset LatexCommand index
7645 Like `-M' but the output mentions only the user header files included with
7647 \begin_inset Quotes eld
7651 System header files included with `#include <file>' are omitted.
7655 \labelwidthstring 00.00.0000
7659 \begin_inset LatexCommand index
7660 name "-Aquestion(answer)"
7666 Assert the answer answer for question, in case it is tested with a preprocessor
7667 conditional such as `#if #question(answer)'.
7668 `-A-' disables the standard assertions that normally describe the target
7673 \labelwidthstring 00.00.0000
7677 \begin_inset LatexCommand index
7684 Undefine macro macro.
7685 `-U' options are evaluated after all `-D' options, but before any `-include'
7686 and `-imacros' options.
7690 \labelwidthstring 00.00.0000
7694 \begin_inset LatexCommand index
7701 Tell the preprocessor to output only a list of the macro definitions that
7702 are in effect at the end of preprocessing.
7703 Used with the `-E' option.
7707 \labelwidthstring 00.00.0000
7711 \begin_inset LatexCommand index
7718 Tell the preprocessor to pass all macro definitions into the output, in
7719 their proper sequence in the rest of the output.
7723 \labelwidthstring 00.00.0000
7727 \begin_inset LatexCommand index
7737 Like `-dD' except that the macro arguments and contents are omitted.
7738 Only `#define name' is included in the output.
7742 \labelwidthstring 00.00.0000
7745 -pedantic-parse-number
7746 \begin_inset LatexCommand index
7752 \begin_inset LatexCommand index
7753 name "-pedantic-parse-number"
7761 \begin_inset LatexCommand label
7762 name "lyx:-pedantic-parse-number"
7771 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7772 and the macro LO_B(3) gets expanded.
7773 See also #pragma pedantic_parse_number
7774 \begin_inset LatexCommand vpageref
7775 reference "ite:pedantic_parse_number"
7780 \begin_inset LatexCommand ref
7781 reference "sec:Pragmas"
7787 Note: this functionality is not in conformance with C99 standard!
7791 \labelwidthstring 00.00.0000
7795 preprocessorOption[,preprocessorOption]
7798 \begin_inset LatexCommand index
7799 name "-Wp preprocessorOption[,preprocessorOption]"
7804 Pass the preprocessorOption to the preprocessor
7809 \begin_inset LatexCommand index
7810 name "sdcpp (preprocessor)"
7815 SDCC uses an adapted version of the GNU Compiler Collection
7816 \begin_inset LatexCommand index
7817 name "gcc (GNU Compiler Collection)"
7830 \begin_inset LatexCommand url
7831 target "http://gcc.gnu.org/"
7836 If you need more dedicated options please refer to the GCC\InsetSpace ~
7840 \begin_inset LatexCommand htmlurl
7841 target "http://www.gnu.org/software/gcc/onlinedocs/"
7848 \begin_layout Standard
7849 \begin_inset VSpace bigskip
7855 \begin_layout Subsection
7857 \begin_inset LatexCommand index
7858 name "Options linker"
7863 \begin_inset LatexCommand index
7864 name "Linker options"
7872 \labelwidthstring 00.00.0000
7882 \begin_layout Standard
7894 \begin_inset LatexCommand index
7895 name "-\\/-lib-path <path>"
7900 \begin_inset LatexCommand index
7908 <absolute path to additional libraries> This option is passed to the linkage
7909 editor's additional libraries
7910 \begin_inset LatexCommand index
7916 The path name must be absolute.
7917 Additional library files may be specified in the command line.
7918 See section Compiling programs for more details.
7922 \labelwidthstring 00.00.0000
7929 \begin_layout Standard
7941 \begin_inset LatexCommand index
7942 name "-\\/-xram-loc <Value>"
7947 <Value> The start location of the external ram
7948 \begin_inset LatexCommand index
7949 name "xdata (mcs51, ds390 storage class)"
7953 , default value is 0.
7954 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7958 \begin_layout Standard
7967 -xram-loc 0x8000 or -
7971 \begin_layout Standard
7984 \labelwidthstring 00.00.0000
7991 \begin_layout Standard
8003 \begin_inset LatexCommand index
8004 name "-\\/-code-loc <Value>"
8009 <Value> The start location of the code
8010 \begin_inset LatexCommand index
8015 segment, default value 0.
8016 Note when this option is used the interrupt vector table
8017 \begin_inset LatexCommand index
8018 name "interrupt vector table"
8022 is also relocated to the given address.
8023 The value entered can be in Hexadecimal or Decimal format, e.g.: -
8027 \begin_layout Standard
8036 -code-loc 0x8000 or -
8040 \begin_layout Standard
8053 \labelwidthstring 00.00.0000
8060 \begin_layout Standard
8072 \begin_inset LatexCommand index
8073 name "-\\/-stack-loc <Value>"
8078 <Value> By default the stack
8079 \begin_inset LatexCommand index
8084 is placed after the data segment.
8085 Using this option the stack can be placed anywhere in the internal memory
8087 The value entered can be in Hexadecimal or Decimal format, e.g.
8092 \begin_layout Standard
8101 -stack-loc 0x20 or -
8105 \begin_layout Standard
8115 Since the sp register is incremented before a push or call, the initial
8116 sp will be set to one byte prior the provided value.
8117 The provided value should not overlap any other memory areas such as used
8118 register banks or the data segment and with enough space for the current
8126 \begin_layout Standard
8139 \begin_inset LatexCommand index
8140 name "-\\/-pack-iram"
8144 option (which is now a default setting) will override this setting, so
8145 you should also specify the
8151 \begin_layout Standard
8164 \begin_inset LatexCommand index
8165 name "-\\/-no-pack-iram"
8169 option if you need to manually place the stack.
8173 \labelwidthstring 00.00.0000
8180 \begin_layout Standard
8192 \begin_inset LatexCommand index
8193 name "-\\/-xstack-loc <Value>"
8198 <Value> By default the external stack
8199 \begin_inset LatexCommand index
8204 is placed after the pdata
8205 \begin_inset LatexCommand index
8206 name "pdata (mcs51, ds390 storage class)"
8211 Using this option the xstack can be placed anywhere in the external memory
8213 The value entered can be in Hexadecimal or Decimal format, e.g.
8218 \begin_layout Standard
8227 -xstack-loc 0x8000 or -
8231 \begin_layout Standard
8241 The provided value should not overlap any other memory areas such as the
8242 pdata or xdata segment and with enough space for the current application.
8246 \labelwidthstring 00.00.0000
8253 \begin_layout Standard
8265 \begin_inset LatexCommand index
8266 name "-\\/-data-loc <Value>"
8271 <Value> The start location of the internal ram data
8272 \begin_inset LatexCommand index
8273 name "data (mcs51, ds390 storage class)"
8278 The value entered can be in Hexadecimal or Decimal format, eg.
8283 \begin_layout Standard
8296 \begin_layout Standard
8306 (By default, the start location of the internal ram data segment is set
8307 as low as possible in memory, taking into account the used register banks
8308 and the bit segment at address 0x20.
8309 For example if register banks 0 and 1 are used without bit variables, the
8310 data segment will be set, if -
8314 \begin_layout Standard
8323 -data-loc is not used, to location 0x10.)
8327 \labelwidthstring 00.00.0000
8334 \begin_layout Standard
8346 \begin_inset LatexCommand index
8347 name "-\\/-idata-loc <Value>"
8352 <Value> The start location of the indirectly addressable internal ram
8353 \begin_inset LatexCommand index
8354 name "idata (mcs51, ds390 storage class)"
8358 of the 8051, default value is 0x80.
8359 The value entered can be in Hexadecimal or Decimal format, eg.
8364 \begin_layout Standard
8373 -idata-loc 0x88 or -
8377 \begin_layout Standard
8390 \labelwidthstring 00.00.0000
8397 \begin_layout Standard
8409 <Value> The start location of the bit
8410 \begin_inset LatexCommand index
8415 addressable internal ram of the 8051.
8421 Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
8426 \labelwidthstring 00.00.0000
8433 \begin_layout Standard
8443 \begin_inset LatexCommand index
8444 name "-\\/-out-fmt-ihx"
8450 The linker output (final object code) is in Intel Hex format.
8451 \begin_inset LatexCommand index
8452 name "Intel hex format"
8456 This is the default option.
8457 The format itself is documented in the documentation of srecord
8458 \begin_inset LatexCommand index
8459 name "srecord (bin, hex, ... tool)"
8467 \labelwidthstring 00.00.0000
8474 \begin_layout Standard
8484 \begin_inset LatexCommand index
8485 name "-\\/-out-fmt-s19"
8491 The linker output (final object code) is in Motorola S19 format
8492 \begin_inset LatexCommand index
8493 name "Motorola S19 format"
8498 The format itself is documented in the documentation of srecord.
8502 \labelwidthstring 00.00.0000
8509 \begin_layout Standard
8519 \begin_inset LatexCommand index
8520 name "-\\/-out-fmt-s19"
8525 \begin_inset LatexCommand index
8526 name "HC08!Options!-\\/-out-fmt-elf"
8532 The linker output (final object code) is in ELF format
8533 \begin_inset LatexCommand index
8539 (Currently only supported for the HC08
8540 \begin_inset LatexCommand index
8549 \labelwidthstring 00.00.0000
8553 linkOption[,linkOption]
8556 \begin_inset LatexCommand index
8557 name "-Wl linkOption[,linkOption]"
8562 \begin_inset LatexCommand label
8563 name "lyx:-Wl option"
8568 Pass the linkOption to the linker.
8569 If a bootloader is used an option like
8570 \begin_inset Quotes sld
8575 \begin_inset Quotes srd
8578 would be typical to set the start of the code segment.
8579 Either use the double quotes around this option or use no space (e.g.
8581 See also #pragma constseg and #pragma codeseg in section
8582 \begin_inset LatexCommand ref
8583 reference "sec:Pragmas"
8588 File sdcc/as/doc/asxhtm.html has more on linker options.
8591 \begin_layout Standard
8592 \begin_inset VSpace bigskip
8598 \begin_layout Subsection
8600 \begin_inset LatexCommand index
8601 name "Options MCS51"
8606 \begin_inset LatexCommand index
8607 name "MCS51 options"
8615 \labelwidthstring 00.00.0000
8622 \begin_layout Standard
8632 \begin_inset LatexCommand index
8633 name "-\\/-model-small"
8642 Generate code for Small Model programs, see section Memory Models for more
8644 This is the default model.
8648 \labelwidthstring 00.00.0000
8655 \begin_layout Standard
8665 \begin_inset LatexCommand index
8666 name "-\\/-model-medium"
8672 Generate code for Medium model programs, see section Memory Models for
8674 If this option is used all source files in the project have to be compiled
8676 It must also be used when invoking the linker.
8680 \labelwidthstring 00.00.0000
8687 \begin_layout Standard
8697 \begin_inset LatexCommand index
8698 name "-\\/-model-large"
8704 Generate code for Large model programs, see section Memory Models for more
8706 If this option is used all source files in the project have to be compiled
8708 It must also be used when invoking the linker.
8712 \labelwidthstring 00.00.0000
8719 \begin_layout Standard
8729 \begin_inset LatexCommand index
8736 Uses a pseudo stack in the pdata
8737 \begin_inset LatexCommand index
8738 name "pdata (mcs51, ds390 storage class)"
8742 area (usually the first 256 bytes in the external ram) for allocating variables
8743 and passing parameters.
8745 \begin_inset LatexCommand ref
8746 reference "sub:External-Stack"
8751 External Stack for more details.
8755 \labelwidthstring 00.00.0000
8762 \begin_layout Standard
8775 \begin_inset LatexCommand index
8776 name "-\\/-iram-size <Value>"
8780 Causes the linker to check if the internal ram usage is within limits of
8785 \labelwidthstring 00.00.0000
8792 \begin_layout Standard
8805 \begin_inset LatexCommand index
8806 name "-\\/-xram-size <Value>"
8810 Causes the linker to check if the external ram usage is within limits of
8815 \labelwidthstring 00.00.0000
8822 \begin_layout Standard
8835 \begin_inset LatexCommand index
8836 name "-\\/-code-size <Value>"
8840 Causes the linker to check if the code memory usage is within limits of
8845 \labelwidthstring 00.00.0000
8852 \begin_layout Standard
8865 \begin_inset LatexCommand index
8866 name "-\\/-stack-size <Value>"
8870 Causes the linker to check if there is at minimum <Value> bytes for stack.
8874 \labelwidthstring 00.00.0000
8881 \begin_layout Standard
8894 \begin_inset LatexCommand index
8895 name "-\\/-pack-iram"
8899 Causes the linker to use unused register banks for data variables and pack
8900 data, idata and stack together.
8901 This is the default now.
8905 \labelwidthstring 00.00.0000
8912 \begin_layout Standard
8925 \begin_inset LatexCommand index
8926 name "-\\/-no-pack-iram"
8930 Causes the linker to use old style for allocating memory areas.
8934 \labelwidthstring 00.00.0000
8941 \begin_layout Standard
8954 \begin_inset LatexCommand index
8955 name "-\\/-acall-ajmp"
8959 Replaces the three byte instructions lcall/ljmp with the two byte instructions
8961 Only use this option if your code is in the same 2k block of memory.
8962 You may need to use this option for some 8051 derivatives which lack the
8963 lcall/ljmp instructions..
8966 \begin_layout Standard
8967 \begin_inset VSpace bigskip
8973 \begin_layout Subsection
8974 DS390 / DS400 Options
8975 \begin_inset LatexCommand index
8976 name "Options DS390"
8981 \begin_inset LatexCommand index
8990 \labelwidthstring 00.00.0000
8997 \begin_layout Standard
9009 \begin_inset LatexCommand index
9010 name "DS390!Options!-\\/-model-flat24"
9018 Generate 24-bit flat mode code.
9019 This is the one and only that the ds390 code generator supports right now
9020 and is default when using
9025 See section Memory Models for more details.
9029 \labelwidthstring 00.00.0000
9036 \begin_layout Standard
9046 \begin_inset LatexCommand index
9047 name "DS390!Options!-\\/-protect-sp-update"
9053 disable interrupts during ESP:SP updates.
9057 \labelwidthstring 00.00.0000
9064 \begin_layout Standard
9076 \begin_inset LatexCommand index
9077 name "DS390!Options!-\\/-stack-10bit"
9081 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
9082 This is the one and only that the ds390 code generator supports right now
9083 and is default when using
9088 In this mode, the stack is located in the lower 1K of the internal RAM,
9089 which is mapped to 0x400000.
9090 Note that the support is incomplete, since it still uses a single byte
9091 as the stack pointer.
9092 This means that only the lower 256 bytes of the potential 1K stack space
9093 will actually be used.
9094 However, this does allow you to reclaim the precious 256 bytes of low RAM
9095 for use for the DATA and IDATA segments.
9096 The compiler will not generate any code to put the processor into 10 bit
9098 It is important to ensure that the processor is in this mode before calling
9099 any re-entrant functions compiled with this option.
9100 In principle, this should work with the
9106 \begin_layout Standard
9116 \begin_inset LatexCommand index
9117 name "-\\/-stack-auto"
9123 option, but that has not been tested.
9124 It is incompatible with the
9130 \begin_layout Standard
9140 \begin_inset LatexCommand index
9148 It also only makes sense if the processor is in 24 bit contiguous addressing
9155 \begin_layout Standard
9164 -model-flat24 option
9169 \begin_inset Note Note
9173 \labelwidthstring 00.00.0000
9180 \begin_layout Standard
9189 -stack-8-bit - switches off the 10-bit mode
9198 \labelwidthstring 00.00.0000
9205 \begin_layout Standard
9215 \begin_inset LatexCommand index
9216 name "DS390!Options!-\\/-stack-probe"
9222 insert call to function __stack_probe at each function prologue.
9226 \labelwidthstring 00.00.0000
9233 \begin_layout Standard
9243 \begin_inset LatexCommand index
9244 name "DS390!Options!-\\/-tini-libid"
9250 <nnnn> LibraryID used in -mTININative.
9255 \labelwidthstring 00.00.0000
9262 \begin_layout Standard
9272 \begin_inset LatexCommand index
9273 name "DS390!Options!-\\/-use-accelerator"
9279 generate code for DS390 Arithmetic Accelerator.
9283 \begin_layout Standard
9284 \begin_inset VSpace bigskip
9290 \begin_layout Subsection
9292 \begin_inset LatexCommand index
9298 \begin_inset LatexCommand index
9307 \labelwidthstring 00.00.0000
9314 \begin_layout Standard
9326 \begin_inset LatexCommand index
9327 name "Z80!Options!-\\/-callee-saves-bc"
9335 Force a called function to always save BC.
9339 \labelwidthstring 00.00.0000
9346 \begin_layout Standard
9358 \begin_inset LatexCommand index
9359 name "Z80!Options!-\\/-no-std-crt0"
9363 When linking, skip the standard crt0.o object file.
9364 You must provide your own crt0.o for your system when linking.
9368 \labelwidthstring 00.00.0000
9375 \begin_layout Standard
9387 \begin_inset LatexCommand index
9388 name "Z80!Options!-\\/-portmode=<Value>"
9392 Determinate PORT I/O mode (<Value> is z80 or z180).
9396 \labelwidthstring 00.00.0000
9403 \begin_layout Standard
9415 \begin_inset LatexCommand index
9416 name "Z80!Options!-\\/-asm=<Value>"
9420 Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
9424 \labelwidthstring 00.00.0000
9431 \begin_layout Standard
9444 \begin_inset LatexCommand index
9445 name "Z80!Options!-\\/-codeseg <Value>"
9449 Use <Value> for the code segment name.
9453 \labelwidthstring 00.00.0000
9460 \begin_layout Standard
9473 \begin_inset LatexCommand index
9474 name "Z80!Options!-\\/-constseg <Value>"
9478 Use <Value> for the const segment name.
9482 \labelwidthstring 00.00.0000
9483 \begin_inset VSpace bigskip
9489 \begin_layout Subsection
9491 \begin_inset LatexCommand index
9492 name "Options GBZ80"
9497 \begin_inset LatexCommand index
9506 \labelwidthstring 00.00.0000
9513 \begin_layout Standard
9525 \begin_inset LatexCommand index
9526 name "GBZ80!Options!-\\/-callee-saves-bc"
9534 Force a called function to always save BC.
9538 \labelwidthstring 00.00.0000
9545 \begin_layout Standard
9557 \begin_inset LatexCommand index
9558 name "Z80!Options!-\\/-no-std-crt0"
9562 When linking, skip the standard crt0.o object file.
9563 You must provide your own crt0.o for your system when linking.
9567 \labelwidthstring 00.00.0000
9574 \begin_inset LatexCommand index
9575 name "GBZ80!Options!-bo <Num>"
9579 Use code bank <Num>.
9583 \labelwidthstring 00.00.0000
9590 \begin_inset LatexCommand index
9591 name "GBZ80!Options!-ba <Num>"
9595 Use data bank <Num>.
9599 \labelwidthstring 00.00.0000
9606 \begin_layout Standard
9619 \begin_inset LatexCommand index
9620 name "GBZ80!Options!-\\/-codeseg <Value>"
9624 Use <Value> for the code segment name.
9628 \labelwidthstring 00.00.0000
9635 \begin_layout Standard
9648 \begin_inset LatexCommand index
9649 name "GBZ80!Options!-\\/-constseg <Value>"
9653 Use <Value> for the const segment name.
9656 \begin_layout Standard
9657 \begin_inset VSpace bigskip
9663 \begin_layout Subsection
9664 Optimization Options
9665 \begin_inset LatexCommand index
9666 name "Options optimization"
9671 \begin_inset LatexCommand index
9672 name "Optimization options"
9680 \labelwidthstring 00.00.0000
9687 \begin_layout Standard
9697 \begin_inset LatexCommand index
9704 Will not do global subexpression elimination, this option may be used when
9705 the compiler creates undesirably large stack/data spaces to store compiler
9715 \begin_inset LatexCommand index
9716 name "sloc (spill location)"
9721 A warning message will be generated when this happens and the compiler
9722 will indicate the number of extra bytes it allocated.
9723 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9725 \begin_inset LatexCommand index
9726 name "\\#pragma nogcse"
9730 can be used to turn off global subexpression elimination
9731 \begin_inset LatexCommand index
9732 name "Subexpression elimination"
9736 for a given function only.
9740 \labelwidthstring 00.00.0000
9747 \begin_layout Standard
9757 \begin_inset LatexCommand index
9758 name "-\\/-noinvariant"
9764 Will not do loop invariant optimizations, this may be turned off for reasons
9765 explained for the previous option.
9766 For more details of loop optimizations performed see Loop Invariants in
9768 \begin_inset LatexCommand ref
9769 reference "sub:Loop-Optimizations"
9774 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9776 \begin_inset LatexCommand index
9777 name "\\#pragma noinvariant"
9781 can be used to turn off invariant optimizations for a given function only.
9785 \labelwidthstring 00.00.0000
9792 \begin_layout Standard
9802 \begin_inset LatexCommand index
9803 name "-\\/-noinduction"
9809 Will not do loop induction optimizations, see section strength reduction
9811 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9813 \begin_inset LatexCommand index
9814 name "\\#pragma noinduction"
9818 can be used to turn off induction optimizations for a given function only.
9822 \labelwidthstring 00.00.0000
9829 \begin_layout Standard
9839 \begin_inset LatexCommand index
9840 name "-\\/-nojtbound"
9849 Will not generate boundary condition check when switch statements
9850 \begin_inset LatexCommand index
9851 name "switch statement"
9855 are implemented using jump-tables.
9857 \begin_inset LatexCommand ref
9858 reference "sub:'switch'-Statements"
9863 Switch Statements for more details.
9864 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9866 \begin_inset LatexCommand index
9867 name "\\#pragma nojtbound"
9871 can be used to turn off boundary checking for jump tables for a given function
9876 \labelwidthstring 00.00.0000
9883 \begin_layout Standard
9893 \begin_inset LatexCommand index
9894 name "-\\/-noloopreverse"
9903 Will not do loop reversal
9904 \begin_inset LatexCommand index
9905 name "Loop reversing"
9913 \labelwidthstring 00.00.0000
9918 \begin_layout Standard
9932 \begin_inset LatexCommand index
9933 name "-\\/-nolabelopt "
9937 Will not optimize labels (makes the dumpfiles more readable).
9941 \labelwidthstring 00.00.0000
9948 \begin_layout Standard
9958 \begin_inset LatexCommand index
9959 name "-\\/-no-xinit-opt"
9965 Will not memcpy initialized data from code space into xdata space.
9966 This saves a few bytes in code space if you don't have initialized data
9967 \begin_inset LatexCommand index
9968 name "Variable initialization"
9976 \labelwidthstring 00.00.0000
9983 \begin_layout Standard
9993 \begin_inset LatexCommand index
9994 name "-\\/-nooverlay"
10000 The compiler will not overlay parameters and local variables of any function,
10001 see section Parameters and local variables for more details.
10005 \labelwidthstring 00.00.0000
10012 \begin_layout Standard
10022 \begin_inset LatexCommand index
10023 name "-\\/-no-peep"
10029 Disable peep-hole optimization with built-in rules.
10033 \labelwidthstring 00.00.0000
10040 \begin_layout Standard
10052 \begin_inset LatexCommand index
10053 name "-\\/-peep-file"
10058 <filename> This option can be used to use additional rules to be used by
10059 the peep hole optimizer.
10061 \begin_inset LatexCommand ref
10062 reference "sub:Peephole-Optimizer"
10067 Peep Hole optimizations for details on how to write these rules.
10071 \labelwidthstring 00.00.0000
10078 \begin_layout Standard
10088 \begin_inset LatexCommand index
10089 name "-\\/-peep-asm"
10095 Pass the inline assembler code through the peep hole optimizer.
10096 This can cause unexpected changes to inline assembler code, please go through
10097 the peephole optimizer
10098 \begin_inset LatexCommand index
10099 name "Peephole optimizer"
10103 rules defined in the source file tree '<target>/peeph.def' before using
10108 \labelwidthstring 00.00.0000
10115 \begin_layout Standard
10125 \begin_inset LatexCommand index
10126 name "-\\/-opt-code-speed"
10132 The compiler will optimize code generation towards fast code, possibly
10133 at the expense of code size.
10137 \labelwidthstring 00.00.0000
10144 \begin_layout Standard
10154 \begin_inset LatexCommand index
10155 name "-\\/-opt-code-size"
10161 The compiler will optimize code generation towards compact code, possibly
10162 at the expense of code speed.
10165 \begin_layout Standard
10166 \begin_inset VSpace bigskip
10172 \begin_layout Subsection
10174 \begin_inset LatexCommand index
10175 name "Options other"
10183 \labelwidthstring 00.00.0000
10191 \begin_layout Standard
10201 \begin_inset LatexCommand index
10202 name "-\\/-version"
10207 \begin_inset LatexCommand index
10214 displays the sdcc version.
10218 \labelwidthstring 00.00.0000
10226 \begin_layout Standard
10236 \begin_inset LatexCommand index
10237 name "-\\/-compile-only"
10242 \begin_inset LatexCommand index
10249 will compile and assemble the source, but will not call the linkage editor.
10253 \labelwidthstring 00.00.0000
10262 \begin_layout Standard
10274 \begin_inset LatexCommand index
10281 reads the preprocessed source from standard input and compiles it.
10282 The file name for the assembler output must be specified using the -o option.
10286 \labelwidthstring 00.00.0000
10290 \begin_inset LatexCommand index
10297 Run only the C preprocessor.
10298 Preprocess all the C source files specified and output the results to standard
10303 \labelwidthstring 00.00.0000
10308 \begin_inset LatexCommand index
10309 name "-o <path/file>"
10315 The output path where everything will be placed or the file name used for
10316 all generated output files.
10317 If the parameter is a path, it must have a trailing slash (or backslash
10318 for the Windows binaries) to be recognized as a path.
10319 Note for Windows users: if the path contains spaces, it should be surrounded
10321 The trailing backslash should be doubled in order to prevent escaping the
10322 final quote, for example:
10325 \begin_inset Quotes sld
10339 \begin_inset Quotes srd
10344 or put after the final quote, for example:
10347 \begin_inset Quotes sld
10357 \begin_inset Quotes srd
10365 The path using slashes for directory delimiters can be used too, for example:
10369 \begin_inset Quotes sld
10372 F:/Projects/test3/output 1/
10373 \begin_inset Quotes srd
10382 \labelwidthstring 00.00.0000
10389 \begin_layout Standard
10399 \begin_inset LatexCommand index
10400 name "-\\/-stack-auto"
10409 All functions in the source file will be compiled as
10414 \begin_inset LatexCommand index
10420 the parameters and local variables will be allocated on the stack
10421 \begin_inset LatexCommand index
10428 \begin_inset LatexCommand ref
10429 reference "sec:Parameters-and-Local-Variables"
10433 Parameters and Local Variables for more details.
10434 If this option is used all source files in the project should be compiled
10436 It automatically implies -
10442 \begin_layout Standard
10453 -int-long-reent and -
10459 \begin_layout Standard
10475 \labelwidthstring 00.00.0000
10482 \begin_layout Standard
10492 \begin_inset LatexCommand index
10493 name "-\\/-callee-saves"
10498 \begin_inset LatexCommand label
10499 name "lyx:--callee-saves-function1[,function2][,function3]..."
10503 function1[,function2][,function3]....
10506 The compiler by default uses a caller saves convention for register saving
10507 across function calls, however this can cause unnecessary register pushing
10508 and popping when calling small functions from larger functions.
10509 This option can be used to switch the register saving convention for the
10510 function names specified.
10511 The compiler will not save registers when calling these functions, no extra
10512 code will be generated at the entry and exit (function prologue
10515 \begin_inset LatexCommand index
10516 name "function prologue"
10525 \begin_inset LatexCommand index
10526 name "function epilogue"
10532 ) for these functions to save and restore the registers used by these functions,
10533 this can SUBSTANTIALLY reduce code and improve run time performance of
10534 the generated code.
10535 In the future the compiler (with inter procedural analysis) will be able
10536 to determine the appropriate scheme to use for each function call.
10537 DO NOT use this option for built-in functions such as _mulint..., if this
10538 option is used for a library function the appropriate library function
10539 needs to be recompiled with the same option.
10540 If the project consists of multiple source files then all the source file
10541 should be compiled with the same -
10545 \begin_layout Standard
10554 -callee-saves option string.
10555 Also see #pragma\InsetSpace ~
10557 \begin_inset LatexCommand index
10558 name "\\#pragma callee\\_saves"
10563 \begin_inset LatexCommand vpageref
10564 reference "ite:callee_saves-function1[,function2[,function3...]]--"
10572 \labelwidthstring 00.00.0000
10579 \begin_layout Standard
10589 \begin_inset LatexCommand index
10590 name "-\\/-all-callee-saves"
10600 \begin_layout Standard
10609 -callee-saves will be applied to all functions by default.
10613 \labelwidthstring 00.00.0000
10620 \begin_layout Standard
10630 \begin_inset LatexCommand index
10637 When this option is used the compiler will generate debug information.
10638 The debug information collected in a file with .cdb extension can be used
10640 For more information see documentation for SDCDB.
10641 Another file with no extension contains debug information in AOMF or AOMF51
10642 \begin_inset LatexCommand index
10643 name "AOMF, AOMF51"
10647 format which is commonly used by third party tools.
10651 \labelwidthstring 00.00.0000
10655 \begin_inset LatexCommand index
10665 Stop after the stage of compilation proper; do not assemble.
10666 The output is an assembler code file for the input file specified.
10670 \labelwidthstring 00.00.0000
10677 \begin_layout Standard
10687 \begin_inset LatexCommand index
10688 name "-\\/-int-long-reent"
10694 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
10695 Note by default these libraries are compiled as non-reentrant.
10696 See section Installation for more details.
10700 \labelwidthstring 00.00.0000
10707 \begin_layout Standard
10717 \begin_inset LatexCommand index
10718 name "-\\/-cyclomatic"
10724 This option will cause the compiler to generate an information message for
10725 each function in the source file.
10726 The message contains some
10730 information about the function.
10731 The number of edges and nodes the compiler detected in the control flow
10732 graph of the function, and most importantly the
10734 cyclomatic complexity
10735 \begin_inset LatexCommand index
10736 name "Cyclomatic complexity"
10742 see section on Cyclomatic Complexity for more details.
10746 \labelwidthstring 00.00.0000
10753 \begin_layout Standard
10763 \begin_inset LatexCommand index
10764 name "-\\/-float-reent"
10770 Floating point library is compiled as reentrant
10771 \begin_inset LatexCommand index
10777 See section Installation for more details.
10781 \labelwidthstring 00.00.0000
10788 \begin_layout Standard
10798 \begin_inset LatexCommand index
10799 name "-\\/-funsigned-char"
10805 The default signedness for every type is
10810 In some embedded environments the default signedness of
10819 To set the signess for characters to unsigned, use the option -
10825 \begin_layout Standard
10837 If this option is set and no signedness keyword (unsigned/signed) is given,
10838 a char will be signed.
10839 All other types are unaffected.
10843 \labelwidthstring 00.00.0000
10850 \begin_layout Standard
10860 \begin_inset LatexCommand index
10861 name "-\\/-main-return"
10867 This option can be used if the code generated is called by a monitor program
10868 or if the main routine includes an endless loop.
10869 This option results in slightly smaller code and saves two bytes of stack
10871 The return from the 'main'
10872 \begin_inset LatexCommand index
10877 function will return to the function calling main.
10878 The default setting is to lock up i.e.
10887 \labelwidthstring 00.00.0000
10894 \begin_layout Standard
10904 \begin_inset LatexCommand index
10905 name "-\\/-nostdinc"
10911 This will prevent the compiler from passing on the default include path
10912 to the preprocessor.
10916 \labelwidthstring 00.00.0000
10923 \begin_layout Standard
10933 \begin_inset LatexCommand index
10934 name "-\\/-nostdlib"
10940 This will prevent the compiler from passing on the default library
10941 \begin_inset LatexCommand index
10946 path to the linker.
10950 \labelwidthstring 00.00.0000
10957 \begin_layout Standard
10967 \begin_inset LatexCommand index
10968 name "-\\/-verbose"
10974 Shows the various actions the compiler is performing.
10978 \labelwidthstring 00.00.0000
10982 \begin_inset LatexCommand index
10989 Shows the actual commands the compiler is executing.
10993 \labelwidthstring 00.00.0000
11000 \begin_layout Standard
11010 \begin_inset LatexCommand index
11011 name "-\\/-no-c-code-in-asm"
11017 Hides your ugly and inefficient c-code from the asm file, so you can always
11018 blame the compiler :)
11022 \labelwidthstring 00.00.0000
11029 \begin_layout Standard
11039 \begin_inset LatexCommand index
11040 name "-\\/-no-gen-comments"
11046 Include code generator and peep-hole comments in the generated asm files.
11050 \labelwidthstring 00.00.0000
11057 \begin_layout Standard
11067 \begin_inset LatexCommand index
11068 name "-\\/-no-peep-comments"
11074 Don't include peep-hole comments in the generated asm files even if -
11080 \begin_layout Standard
11091 -fverbose-asm option is specified.
11095 \labelwidthstring 00.00.0000
11102 \begin_layout Standard
11112 \begin_inset LatexCommand index
11113 name "-\\/-i-code-in-asm"
11119 Include i-codes in the asm file.
11120 Sounds like noise but is most helpful for debugging the compiler itself.
11124 \labelwidthstring 00.00.0000
11131 \begin_layout Standard
11141 \begin_inset LatexCommand index
11147 \begin_inset LatexCommand index
11148 name "-\\/-less-pedantic"
11155 \begin_inset LatexCommand label
11156 name "lyx:--less-pedantic"
11160 Disable some of the more pedantic warnings
11161 \begin_inset LatexCommand index
11167 For more details, see the less_pedantic pragma
11168 \begin_inset LatexCommand vpageref
11169 reference "ite:less_pedantic"
11177 \labelwidthstring 00.00.0000
11184 \begin_layout Standard
11193 -disable-warning\InsetSpace ~
11195 \begin_inset LatexCommand index
11196 name "-\\/-disable-warning"
11202 Disable specific warning with number <nnnn>.
11206 \labelwidthstring 00.00.0000
11213 \begin_layout Standard
11223 \begin_inset LatexCommand index
11230 Treat all warnings as errors.
11234 \labelwidthstring 00.00.0000
11241 \begin_layout Standard
11251 \begin_inset LatexCommand index
11252 name "-\\/-print-search-dirs"
11258 Display the directories in the compiler's search path
11262 \labelwidthstring 00.00.0000
11269 \begin_layout Standard
11279 \begin_inset LatexCommand index
11286 Display errors and warnings using MSVC style, so you can use SDCC with
11287 the visual studio IDE
11288 \begin_inset LatexCommand index
11294 With SDCC both offering a GCC-like (the default) and a MSVC-like
11295 \begin_inset LatexCommand index
11296 name "MSVC output style"
11300 output style, integration into most programming editors should be straightforwa
11305 \labelwidthstring 00.00.0000
11312 \begin_layout Standard
11322 \begin_inset LatexCommand index
11323 name "-\\/-use-stdout"
11329 Send errors and warnings to stdout instead of stderr.
11333 \labelwidthstring 00.00.0000
11337 asmOption[,asmOption]
11340 \begin_inset LatexCommand index
11341 name "-Wa asmOption[,asmOption]"
11346 Pass the asmOption to the assembler
11347 \begin_inset LatexCommand index
11348 name "Options assembler"
11353 \begin_inset LatexCommand index
11354 name "Assembler options"
11359 See file sdcc/as/doc/asxhtm.html for assembler options.cd
11363 \labelwidthstring 00.00.0000
11370 \begin_layout Standard
11380 \begin_inset LatexCommand index
11381 name "-\\/-std-sdcc89"
11387 Generally follow the C89 standard, but allow SDCC features that conflict
11388 with the standard (default).
11392 \labelwidthstring 00.00.0000
11399 \begin_layout Standard
11409 \begin_inset LatexCommand index
11410 name "-\\/-std-c89"
11416 Follow the C89 standard and disable SDCC features that conflict with the
11421 \labelwidthstring 00.00.0000
11428 \begin_layout Standard
11438 \begin_inset LatexCommand index
11439 name "-\\/-std-sdcc99"
11445 Generally follow the C99 standard, but allow SDCC features that conflict
11446 with the standard (incomplete support).
11450 \labelwidthstring 00.00.0000
11457 \begin_layout Standard
11467 \begin_inset LatexCommand index
11468 name "-\\/-std-sdcc99"
11474 Follow the C99 standard and disable SDCC features that conflict with the
11475 standard (incomplete support).
11479 \labelwidthstring 00.00.0000
11486 \begin_layout Standard
11498 \begin_inset LatexCommand index
11499 name "-\\/-codeseg <Value>"
11504 \begin_inset LatexCommand label
11505 name "lyx:-codeseg"
11510 <Name> The name to be used for the code
11511 \begin_inset LatexCommand index
11516 segment, default CSEG.
11517 This is useful if you need to tell the compiler to put the code in a special
11518 segment so you can later on tell the linker to put this segment in a special
11520 Can be used for instance when using bank switching to put the code in a
11525 \labelwidthstring 00.00.0000
11532 \begin_layout Standard
11544 \begin_inset LatexCommand index
11545 name "-\\/-constseg <Value>"
11550 <Name> The name to be used for the const
11551 \begin_inset LatexCommand index
11556 segment, default CONST.
11557 This is useful if you need to tell the compiler to put the const data in
11558 a special segment so you can later on tell the linker to put this segment
11559 in a special place in memory.
11560 Can be used for instance when using bank switching to put the const data
11565 \labelwidthstring 00.00.0000
11572 \begin_layout Standard
11581 -fdollars-in-identifiers
11582 \begin_inset LatexCommand index
11583 name "-\\/-fdollars-in-identifiers"
11589 Permit '$' as an identifier character.
11593 \labelwidthstring 00.00.0000
11600 \begin_layout Standard
11612 \begin_inset LatexCommand index
11613 name "-\\/-more-pedantic"
11618 \begin_inset LatexCommand index
11629 a SDCC compiler option but if you want
11633 warnings you can use a separate tool dedicated to syntax checking like
11635 \begin_inset LatexCommand label
11636 name "lyx:more-pedantic-SPLINT"
11641 \begin_inset LatexCommand index
11642 name "lint (syntax checking tool)"
11647 \begin_inset LatexCommand url
11648 target "http://www.splint.org"
11653 To make your source files parseable by splint you will have to include
11659 \begin_inset LatexCommand index
11660 name "splint (syntax checking tool)"
11664 in your source file and add brackets around extended keywords (like
11667 \begin_inset Quotes sld
11680 \begin_inset Quotes srd
11688 \begin_inset Quotes sld
11691 __interrupt\InsetSpace ~
11693 \begin_inset Quotes srd
11701 Splint has an excellent on line manual at
11702 \begin_inset LatexCommand url
11703 target "http://www.splint.org/manual/"
11707 and it's capabilities go beyond pure syntax checking.
11708 You'll need to tell splint the location of SDCC's include files so a typical
11709 command line could look like this:
11713 splint\InsetSpace ~
11715 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
11721 \labelwidthstring 00.00.0000
11728 \begin_layout Standard
11740 \begin_inset LatexCommand index
11741 name "-\\/-short-is-8bits"
11746 \begin_inset LatexCommand label
11747 name "lyx:--short-is-8bits"
11751 Treat short as 8-bit (for backward compatibility with older versions of
11752 compiler - see section
11753 \begin_inset LatexCommand ref
11754 reference "sec:Compatibility-with-previous"
11761 \begin_layout Standard
11762 \begin_inset VSpace bigskip
11768 \begin_layout Subsection
11769 Intermediate Dump Options
11770 \begin_inset LatexCommand label
11771 name "sub:Intermediate-Dump-Options"
11776 \begin_inset LatexCommand index
11777 name "Options intermediate dump"
11782 \begin_inset LatexCommand index
11783 name "Intermediate dump options"
11790 \begin_layout Standard
11791 The following options are provided for the purpose of retargetting and debugging
11793 They provide a means to dump the intermediate code (iCode
11794 \begin_inset LatexCommand index
11799 ) generated by the compiler in human readable form at various stages of
11800 the compilation process.
11801 More on iCodes see chapter
11802 \begin_inset LatexCommand ref
11803 reference "sub:The-anatomy-of"
11808 \begin_inset Quotes srd
11811 The anatomy of the compiler
11812 \begin_inset Quotes srd
11819 \labelwidthstring 00.00.0000
11826 \begin_layout Standard
11836 \begin_inset LatexCommand index
11837 name "-\\/-dumpraw"
11843 This option will cause the compiler to dump the intermediate code into
11846 <source filename>.dumpraw
11848 just after the intermediate code has been generated for a function, i.e.
11849 before any optimizations are done.
11851 \begin_inset LatexCommand index
11852 name "Basic blocks"
11856 at this stage ordered in the depth first number, so they may not be in
11857 sequence of execution.
11861 \labelwidthstring 00.00.0000
11868 \begin_layout Standard
11878 \begin_inset LatexCommand index
11879 name "-\\/-dumpgcse"
11885 Will create a dump of iCodes, after global subexpression elimination
11886 \begin_inset LatexCommand index
11887 name "Global subexpression elimination"
11891 , into a file named
11893 <source filename>.dumpgcse.
11897 \labelwidthstring 00.00.0000
11904 \begin_layout Standard
11914 \begin_inset LatexCommand index
11915 name "-\\/-dumpdeadcode"
11921 Will create a dump of iCodes, after deadcode elimination
11922 \begin_inset LatexCommand index
11923 name "Dead-code elimination"
11927 , into a file named
11929 <source filename>.dumpdeadcode.
11933 \labelwidthstring 00.00.0000
11940 \begin_layout Standard
11950 \begin_inset LatexCommand index
11951 name "-\\/-dumploop"
11960 Will create a dump of iCodes, after loop optimizations
11961 \begin_inset LatexCommand index
11962 name "Loop optimization"
11966 , into a file named
11968 <source filename>.dumploop.
11972 \labelwidthstring 00.00.0000
11979 \begin_layout Standard
11989 \begin_inset LatexCommand index
11990 name "-\\/-dumprange"
11999 Will create a dump of iCodes, after live range analysis
12000 \begin_inset LatexCommand index
12001 name "Live range analysis"
12005 , into a file named
12007 <source filename>.dumprange.
12011 \labelwidthstring 00.00.0000
12018 \begin_layout Standard
12028 \begin_inset LatexCommand index
12029 name "-\\/-dumlrange"
12035 Will dump the life ranges
12036 \begin_inset LatexCommand index
12037 name "Live range analysis"
12045 \labelwidthstring 00.00.0000
12052 \begin_layout Standard
12062 \begin_inset LatexCommand index
12063 name "-\\/-dumpregassign"
12069 Will create a dump of iCodes, after register assignment
12070 \begin_inset LatexCommand index
12071 name "Register assignment"
12075 , into a file named
12077 <source filename>.dumprassgn.
12081 \labelwidthstring 00.00.0000
12088 \begin_layout Standard
12098 \begin_inset LatexCommand index
12099 name "-\\/-dumplrange"
12105 Will create a dump of the live ranges of iTemp's
12109 \labelwidthstring 00.00.0000
12116 \begin_layout Standard
12126 \begin_inset LatexCommand index
12127 name "-\\/-dumpall"
12136 Will cause all the above mentioned dumps to be created.
12139 \begin_layout Standard
12140 \begin_inset VSpace bigskip
12146 \begin_layout Subsection
12147 Redirecting output on Windows Shells
12150 \begin_layout Standard
12151 By default SDCC writes its error messages to
12152 \begin_inset Quotes sld
12156 \begin_inset Quotes srd
12160 To force all messages to
12161 \begin_inset Quotes sld
12165 \begin_inset Quotes srd
12177 \begin_layout Standard
12192 \begin_inset LatexCommand index
12193 name "-\\/-use-stdout"
12198 Additionally, if you happen to have visual studio installed in your windows
12199 machine, you can use it to compile your sources using a custom build and
12206 \begin_layout Standard
12218 \begin_inset LatexCommand index
12224 Something like this should work:
12243 \begin_layout Standard
12262 \begin_layout Standard
12274 -model-large -c $(InputPath)
12277 \begin_inset VSpace bigskip
12283 \begin_layout Section
12284 Environment variables
12285 \begin_inset LatexCommand index
12286 name "Environment variables"
12293 \begin_layout Standard
12294 SDCC recognizes the following environment variables:
12298 \labelwidthstring 00.00.0000
12302 \begin_inset LatexCommand index
12303 name "SDCC\\_LEAVE\\_SIGNALS"
12309 SDCC installs a signal handler
12310 \begin_inset LatexCommand index
12311 name "signal handler"
12315 to be able to delete temporary files after an user break (^C) or an exception.
12316 If this environment variable is set, SDCC won't install the signal handler
12317 in order to be able to debug SDCC.
12321 \labelwidthstring 00.00.0000
12327 \begin_inset LatexCommand index
12328 name "TMP, TEMP, TMPDIR"
12334 Path, where temporary files will be created.
12335 The order of the variables is the search order.
12336 In a standard *nix environment these variables are not set, and there's
12337 no need to set them.
12338 On Windows it's recommended to set one of them.
12342 \labelwidthstring 00.00.0000
12346 \begin_inset LatexCommand index
12354 \begin_inset LatexCommand ref
12355 reference "sub:Install-paths"
12361 \begin_inset Quotes sld
12365 \begin_inset Quotes srd
12372 \labelwidthstring 00.00.0000
12376 \begin_inset LatexCommand index
12377 name "SDCC\\_INCLUDE"
12384 \begin_inset LatexCommand ref
12385 reference "sub:Search-Paths"
12391 \begin_inset Quotes sld
12395 \begin_inset Quotes srd
12402 \labelwidthstring 00.00.0000
12406 \begin_inset LatexCommand index
12414 \begin_inset LatexCommand ref
12415 reference "sub:Search-Paths"
12421 \begin_inset Quotes sld
12425 \begin_inset Quotes srd
12431 \begin_layout Standard
12432 There are some more environment variables recognized by SDCC, but these
12433 are solely used for debugging purposes.
12434 They can change or disappear very quickly, and will never be documented.
12435 \begin_inset VSpace bigskip
12441 \begin_layout Section
12442 Storage Class Language Extensions
12445 \begin_layout Subsection
12446 MCS51/DS390 Storage Class
12447 \begin_inset LatexCommand index
12448 name "Storage class"
12452 Language Extensions
12455 \begin_layout Standard
12456 In addition to the ANSI storage classes SDCC allows the following MCS51
12457 specific storage classes:
12460 \begin_layout Subsubsection
12462 \begin_inset LatexCommand index
12463 name "data (mcs51, ds390 storage class)"
12468 \begin_inset LatexCommand index
12469 name "\\_\\_data (mcs51, ds390 storage class)"
12474 \begin_inset LatexCommand index
12475 name "near (storage class)"
12480 \begin_inset LatexCommand index
12481 name "\\_\\_near (storage class)"
12488 \begin_layout Standard
12493 storage class for the Small Memory model (
12501 or the more ANSI-C compliant forms
12509 can be used synonymously).
12510 Variables declared with this storage class will be allocated in the directly
12511 addressable portion of the internal RAM of a 8051, e.g.:
12514 \begin_layout Verse
12517 __data unsigned char test_data;
12520 \begin_layout Standard
12521 Writing 0x01 to this variable generates the assembly code:
12524 \begin_layout Verse
12527 75*00 01\InsetSpace ~
12535 \begin_layout Subsubsection
12537 \begin_inset LatexCommand index
12538 name "xdata (mcs51, ds390 storage class)"
12543 \begin_inset LatexCommand index
12544 name "\\_\\_xdata (mcs51, ds390 storage class)"
12549 \begin_inset LatexCommand index
12550 name "far (storage class)"
12555 \begin_inset LatexCommand index
12556 name "\\_\\_far (storage class)"
12563 \begin_layout Standard
12564 Variables declared with this storage class will be placed in the external
12570 storage class for the Large Memory model, e.g.:
12573 \begin_layout Verse
12576 __xdata unsigned char test_xdata;
12579 \begin_layout Standard
12580 Writing 0x01 to this variable generates the assembly code:
12583 \begin_layout Verse
12586 90s00r00\InsetSpace ~
12617 \begin_layout Subsubsection
12619 \begin_inset LatexCommand index
12620 name "idata (mcs51, ds390 storage class)"
12625 \begin_inset LatexCommand index
12626 name "\\_\\_idata (mcs51, ds390 storage class)"
12633 \begin_layout Standard
12634 Variables declared with this storage class will be allocated into the indirectly
12635 addressable portion of the internal ram of a 8051, e.g.:
12638 \begin_layout Verse
12641 __idata unsigned char test_idata;
12644 \begin_layout Standard
12645 Writing 0x01 to this variable generates the assembly code:
12648 \begin_layout Verse
12675 \begin_layout Standard
12676 Please note, the first 128 byte of idata physically access the same RAM
12677 as the data memory.
12678 The original 8051 had 128 byte idata memory, nowadays most devices have
12679 256 byte idata memory.
12681 \begin_inset LatexCommand index
12686 is located in idata memory.
12689 \begin_layout Subsubsection
12691 \begin_inset LatexCommand index
12692 name "pdata (mcs51, ds390 storage class)"
12697 \begin_inset LatexCommand index
12698 name "\\_\\_pdata (mcs51, ds390 storage class)"
12705 \begin_layout Standard
12706 Paged xdata access is just as straightforward as using the other addressing
12708 It is typically located at the start of xdata and has a maximum size of
12710 The following example writes 0x01 to the pdata variable.
12711 Please note, pdata access physically accesses xdata memory.
12712 The high byte of the address is determined by port P2
12713 \begin_inset LatexCommand index
12714 name "P2 (mcs51 sfr)"
12718 (or in case of some 8051 variants by a separate Special Function Register,
12720 \begin_inset LatexCommand ref
12721 reference "sub:MCS51-variants"
12730 storage class for the Medium Memory model, e.g.:
12733 \begin_layout Verse
12736 __pdata unsigned char test_pdata;
12739 \begin_layout Standard
12740 Writing 0x01 to this variable generates the assembly code:
12743 \begin_layout Verse
12752 mov r0,#_test_pdata
12774 \begin_layout Standard
12779 \begin_layout Standard
12789 \begin_inset LatexCommand index
12794 option is used the pdata memory area is followed by the xstack memory area
12795 and the sum of their sizes is limited to 256 bytes.
12798 \begin_layout Subsubsection
12800 \begin_inset LatexCommand index
12806 \begin_inset LatexCommand index
12814 \begin_layout Standard
12815 'Variables' declared with this storage class will be placed in the code
12819 \begin_layout Verse
12822 __code unsigned char test_code;
12825 \begin_layout Standard
12826 Read access to this variable generates the assembly code:
12829 \begin_layout Verse
12832 90s00r6F\InsetSpace ~
12835 mov dptr,#_test_code
12860 \begin_layout Standard
12865 indexed arrays of characters in code memory can be accessed efficiently:
12868 \begin_layout Verse
12871 __code char test_array[] = {'c','h','e','a','p'};
12874 \begin_layout Standard
12875 Read access to this array using an 8-bit unsigned index generates the assembly
12879 \begin_layout Verse
12891 \begin_layout Verse
12894 90s00r41\InsetSpace ~
12897 mov dptr,#_test_array
12900 \begin_layout Verse
12915 \begin_layout Subsubsection
12917 \begin_inset LatexCommand index
12923 \begin_inset LatexCommand index
12931 \begin_layout Standard
12932 This is a data-type and a storage class specifier.
12933 When a variable is declared as a bit, it is allocated into the bit addressable
12934 memory of 8051, e.g.:
12937 \begin_layout Verse
12943 \begin_layout Standard
12944 Writing 1 to this variable generates the assembly code:
12947 \begin_layout Verse
12961 \begin_layout Standard
12962 The bit addressable memory consists of 128 bits which are located from 0x20
12963 to 0x2f in data memory.
12966 Apart from this 8051 specific storage class most architectures support
12968 \begin_inset LatexCommand index
12977 \begin_layout Standard
12978 Not really meant as examples, but nevertheless showing what bitfields are
12979 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12985 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12986 signed modifier are implemented as unsigned.
12989 \begin_layout Subsubsection
12991 \begin_inset LatexCommand index
12997 \begin_inset LatexCommand index
13003 \begin_inset LatexCommand index
13009 \begin_inset LatexCommand index
13015 \begin_inset LatexCommand index
13021 \begin_inset LatexCommand index
13027 \begin_inset LatexCommand index
13033 \begin_inset LatexCommand index
13041 \begin_layout Standard
13042 Like the bit keyword,
13044 sfr / sfr16 / sfr32 / sbit
13046 signify both a data-type and storage class, they are used to describe the
13067 variables of a 8051, eg:
13070 \begin_layout Verse
13074 \begin_inset LatexCommand index
13080 \begin_inset LatexCommand index
13085 (0x80) P0;\InsetSpace ~
13086 /* special function register P0 at location 0x80 */
13091 special function register combination for timer 0
13095 with the high byte at
13096 location 0x8C and the low byte at location 0x8A */
13098 __sfr16 __at (0x8C8A)
13104 \begin_inset LatexCommand index
13110 \begin_inset LatexCommand index
13115 (0xd7) CY;\InsetSpace ~
13117 \begin_inset LatexCommand index
13123 \begin_inset LatexCommand index
13131 \begin_layout Standard
13132 Special function registers which are located on an address dividable by
13133 8 are bit-addressable, an
13137 addresses a specific bit within these sfr.
13139 16 Bit and 32 bit special function
13140 register combinations which require a certain access order are better not
13150 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
13151 this is not guaranteed.
13156 \begin_layout Standard
13157 Please note, if you use a header file which was written for another compiler
13158 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
13164 Specifically the syntax
13167 sfr P0 = 0x80;\InsetSpace ~
13174 by SDCC to an assignment of 0x80 to a variable called P0
13177 \begin_inset Marginal
13180 \begin_layout Standard
13194 Nevertheless it is possible to write header files
13195 \begin_inset LatexCommand index
13196 name "Header files"
13201 \begin_inset LatexCommand index
13202 name "Include files"
13206 which can be shared among different compilers (see section
13207 \begin_inset LatexCommand ref
13208 reference "sec:Porting-code-to-other-compilers"
13216 \begin_layout Subsubsection
13218 \begin_inset LatexCommand index
13223 to MCS51/DS390 specific memory spaces
13226 \begin_layout Standard
13227 SDCC allows (via language extensions) pointers to explicitly point to any
13228 of the memory spaces
13229 \begin_inset LatexCommand index
13230 name "Memory model"
13235 In addition to the explicit pointers, the compiler uses (by default) generic
13236 pointers which can be used to point to any of the memory spaces.
13241 declaration examples:
13244 \begin_layout Verse
13247 /* pointer physically in internal ram pointing to object in external ram
13250 __xdata unsigned char * __data p;
13254 /* pointer physically in external ram
13255 pointing to object in internal ram */
13257 __data unsigned char * __xdata p;
13262 pointer physically in code rom pointing to data in xdata space */
13265 unsigned char * __code p;
13269 /* pointer physically in code space pointing to
13270 data in code space */
13272 __code unsigned char * __code p;
13277 physically located in xdata space */
13279 unsigned char * __xdata p;
13284 pointer physically located in default memory space */
13291 the following is a function pointer
13292 \begin_inset LatexCommand index
13293 name "function pointer"
13297 physically located in data space */
13299 char (* __data fp)(void);
13302 \begin_layout Standard
13303 Well you get the idea.
13308 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
13321 The highest order byte of the
13325 pointers contains the data space information.
13326 Assembler support routines are called whenever data is stored or retrieved
13332 These are useful for developing reusable library
13333 \begin_inset LatexCommand index
13339 Explicitly specifying the pointer
13340 \begin_inset LatexCommand index
13345 type will generate the most efficient code.
13348 \begin_layout Subsubsection
13349 Notes on MCS51 memory
13350 \begin_inset LatexCommand index
13351 name "MCS51 memory"
13358 \begin_layout Standard
13359 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
13360 RAM memory which is structured as follows:
13364 - Bytes 00-1F - 32 bytes to hold
13365 up to 4 banks of the registers R0 to R7,
13367 - Bytes 20-2F - 16 bytes to hold
13369 \begin_inset LatexCommand index
13376 - Bytes 30-7F - 80 bytes for general purpose use.
13381 \begin_layout Standard
13382 Additionally some members of the MCS51 family may have up to 128 bytes of
13383 additional, indirectly addressable, internal RAM memory (
13388 \begin_inset LatexCommand index
13389 name "idata (mcs51, ds390 storage class)"
13394 \begin_inset LatexCommand index
13395 name "\\_\\_idata (mcs51, ds390 storage class)"
13400 Furthermore, some chips may have some built in external memory (
13405 \begin_inset LatexCommand index
13406 name "xdata (mcs51, ds390 storage class)"
13411 \begin_inset LatexCommand index
13412 name "\\_\\_xdata (mcs51, ds390 storage class)"
13416 ) which should not be confused with the internal, directly addressable RAM
13422 \begin_inset LatexCommand index
13423 name "data (mcs51, ds390 storage class)"
13428 \begin_inset LatexCommand index
13429 name "\\_\\_data (mcs51, ds390 storage class)"
13434 Sometimes this built in
13438 memory has to be activated before using it (you can probably find this
13439 information on the datasheet of the microcontroller your are using, see
13441 \begin_inset LatexCommand ref
13442 reference "sub:Startup-Code"
13450 \begin_layout Standard
13451 Normally SDCC will only use the first bank
13452 \begin_inset LatexCommand index
13453 name "register bank (mcs51, ds390)"
13457 of registers (register bank 0), but it is possible to specify that other
13458 banks of registers (keyword
13465 \begin_inset LatexCommand index
13466 name "using (mcs51, ds390 register bank)"
13471 \begin_inset LatexCommand index
13472 name "\\_\\_using (mcs51, ds390 register bank)"
13478 ) should be used for example in interrupt
13479 \begin_inset LatexCommand index
13485 \begin_inset LatexCommand index
13486 name "\\_\\_interrupt"
13491 By default, the compiler will place the stack after the last byte of allocated
13492 memory for variables.
13493 For example, if the first 2 banks of registers are used, and only four
13498 variables, it will position the base of the internal stack at address 20
13500 This implies that as the stack
13501 \begin_inset LatexCommand index
13506 grows, it will use up the remaining register banks, and the 16 bytes used
13507 by the 128 bit variables, and 80 bytes for general purpose use.
13508 If any bit variables are used, the data variables will be placed in unused
13509 register banks and after the byte holding the last bit variable.
13510 For example, if register banks 0 and 1 are used, and there are 9 bit variables
13515 variables will be placed starting from address 0x10 to 0x20 and continue
13521 \begin_layout Standard
13531 \begin_inset LatexCommand index
13532 name "-\\/-data-loc <Value>"
13536 to specify the start address of the
13544 \begin_layout Standard
13554 \begin_inset LatexCommand index
13555 name "-\\/-iram-size <Value>"
13559 to specify the size of the total internal RAM (
13573 \begin_layout Standard
13574 By default the 8051 linker will place the stack after the last byte of (i)data
13580 \begin_layout Standard
13590 \begin_inset LatexCommand index
13591 name "-\\/-stack-loc <Value>"
13595 allows you to specify the start of the stack, i.e.
13596 you could start it after any data in the general purpose area.
13597 If your microcontroller has additional indirectly addressable internal
13602 ) you can place the stack on it.
13603 You may also need to use -
13607 \begin_layout Standard
13617 \begin_inset LatexCommand index
13618 name "-\\/-xdata-loc<Value>"
13622 to set the start address of the external RAM (
13630 \begin_layout Standard
13640 \begin_inset LatexCommand index
13641 name "-\\/-xram-size <Value>"
13645 to specify its size.
13646 Same goes for the code memory, using -
13650 \begin_layout Standard
13660 \begin_inset LatexCommand index
13661 name "-\\/-code-loc <Value>"
13669 \begin_layout Standard
13679 \begin_inset LatexCommand index
13680 name "-\\/-code-size <Value>"
13685 If in doubt, don't specify any options and see if the resulting memory
13686 layout is appropriate, then you can adjust it.
13689 \begin_layout Standard
13690 The linker generates two files with memory allocation information.
13691 The first, with extension .map
13692 \begin_inset LatexCommand index
13697 shows all the variables and segments.
13698 The second with extension .mem
13699 \begin_inset LatexCommand index
13704 shows the final memory layout.
13705 The linker will complain either if memory segments overlap, there is not
13706 enough memory, or there is not enough space for stack.
13707 If you get any linking warnings and/or errors related to stack or segments
13708 allocation, take a look at either the .map or .mem files to find out what
13710 The .mem file may even suggest a solution to the problem.
13711 \begin_inset VSpace bigskip
13717 \begin_layout Subsection
13718 Z80/Z180 Storage Class
13719 \begin_inset LatexCommand index
13720 name "Z80!Storage class"
13724 Language Extensions
13727 \begin_layout Subsubsection
13729 \begin_inset LatexCommand index
13735 \begin_inset LatexCommand index
13740 (in/out to 8-bit addresses)
13743 \begin_layout Standard
13745 \begin_inset LatexCommand index
13750 family has separate address spaces for memory and
13760 \begin_inset LatexCommand index
13761 name "I/O memory (Z80, Z180)"
13766 \begin_inset LatexCommand index
13767 name "Z80!I/O memory"
13772 \begin_inset LatexCommand index
13773 name "Z180!I/O memory"
13777 is accessed with special instructions, e.g.:
13780 \begin_layout Verse
13783 sfr at 0x78 IoPort;\InsetSpace ~
13785 /* define a var in I/O space at 78h called IoPort */
13789 \begin_layout Standard
13790 Writing 0x01 to this variable generates the assembly code:
13793 \begin_layout Verse
13813 \begin_layout Subsubsection
13815 \begin_inset LatexCommand index
13821 \begin_inset LatexCommand index
13826 (in/out to 16-bit addresses)
13829 \begin_layout Standard
13834 is used to support 16 bit addresses in I/O memory e.g.:
13837 \begin_layout Verse
13841 \begin_inset LatexCommand index
13847 \begin_inset LatexCommand index
13855 \begin_layout Standard
13856 Writing 0x01 to this variable generates the assembly code:
13859 \begin_layout Verse
13862 01 23 01\InsetSpace ~
13884 \begin_layout Subsubsection
13886 \begin_inset LatexCommand index
13892 \begin_inset LatexCommand index
13897 (in0/out0 to 8 bit addresses on Z180
13898 \begin_inset LatexCommand index
13904 \begin_inset LatexCommand index
13905 name "HD64180 (see Z180)"
13912 \begin_layout Standard
13913 The compiler option -
13917 \begin_layout Standard
13927 \begin_inset LatexCommand index
13928 name "Z180!Options!-\\/-portmode"
13932 =180 (80) and a compiler #pragma\InsetSpace ~
13934 \begin_inset LatexCommand index
13935 name "Z180!Pragmas!\\#pragma portmode"
13939 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
13949 If you include the file z180.h this will be set automatically.
13950 \begin_inset VSpace bigskip
13956 \begin_layout Subsection
13958 \begin_inset LatexCommand index
13959 name "HC08!Storage class"
13963 Language Extensions
13966 \begin_layout Subsubsection
13968 \begin_inset LatexCommand index
13969 name "data (hc08 storage class)"
13974 \begin_inset LatexCommand index
13975 name "\\_\\_data (hc08 storage class)"
13982 \begin_layout Standard
13983 The data storage class declares a variable that resides in the first 256
13984 bytes of memory (the direct page).
13986 \begin_inset LatexCommand index
13991 is most efficient at accessing variables (especially pointers) stored here.
13994 \begin_layout Subsubsection
13996 \begin_inset LatexCommand index
13997 name "xdata (hc08 storage class)"
14002 \begin_inset LatexCommand index
14003 name "\\_\\_xdata (hc08 storage class)"
14010 \begin_layout Standard
14011 The xdata storage class declares a variable that can reside anywhere in
14013 This is the default if no storage class is specified.
14015 \begin_inset VSpace bigskip
14021 \begin_layout Section
14022 Other SDCC language extensions
14023 \begin_inset LatexCommand index
14024 name "Other SDCC language extensions"
14031 \begin_layout Subsection
14035 \begin_layout Standard
14036 SDCC supports the use of binary constants, such as 0b01100010.
14037 This feature is only enabled when the compiler is invoked using --std-sdccxx.
14040 \begin_layout Standard
14041 \begin_inset VSpace bigskip
14047 \begin_layout Section
14048 Absolute Addressing
14049 \begin_inset LatexCommand index
14050 name "Absolute addressing"
14057 \begin_layout Standard
14058 Data items can be assigned an absolute address with the
14061 \begin_inset LatexCommand index
14067 \begin_inset LatexCommand index
14074 keyword, in addition to a storage class, e.g.:
14077 \begin_layout Verse
14081 \begin_inset LatexCommand index
14082 name "xdata (mcs51, ds390 storage class)"
14087 \begin_inset LatexCommand index
14088 name "\\_\\_xdata (mcs51, ds390 storage class)"
14093 \begin_inset LatexCommand index
14099 \begin_inset LatexCommand index
14104 0x7ffe unsigned int chksum;
14107 \begin_layout Standard
14108 or, better conforming to ISO/IEC 9899 C:
14111 \begin_layout Verse
14114 __xdata __at (0x7ffe) unsigned int chksum;
14117 \begin_layout Standard
14118 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
14119 of the external ram.
14124 reserve any space for variables declared in this way
14125 \begin_inset Marginal
14128 \begin_layout Standard
14137 (they are implemented with an equate in the assembler).
14138 Thus it is left to the programmer to make sure there are no overlaps with
14139 other variables that are declared without the absolute address.
14140 The assembler listing file (.lst
14141 \begin_inset LatexCommand index
14146 ) and the linker output files (.rst
14147 \begin_inset LatexCommand index
14153 \begin_inset LatexCommand index
14158 ) are good places to look for such overlaps.
14161 \begin_layout Standard
14162 If however you provide an initializer
14163 \begin_inset LatexCommand index
14164 name "Variable initialization"
14168 actual memory allocation will take place and overlaps will be detected
14173 \begin_layout Verse
14176 __code __at (0x7ff0) char Id[5] =
14177 \begin_inset Quotes sld
14181 \begin_inset Quotes srd
14187 \begin_layout Standard
14188 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
14192 \begin_layout Standard
14193 In case of memory mapped I/O devices the keyword
14197 has to be used to tell the compiler that accesses might not be removed:
14200 \begin_layout Verse
14204 \begin_inset LatexCommand index
14210 \begin_inset LatexCommand index
14211 name "xdata (mcs51, ds390 storage class)"
14216 \begin_inset LatexCommand index
14221 (0x8000) unsigned char PORTA_8255;
14224 \begin_layout Standard
14225 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
14230 \begin_inset LatexCommand index
14231 name "Aligned array"
14238 starts at a block (256 byte) boundary
14239 \begin_inset LatexCommand index
14240 name "block boundary"
14245 \begin_inset LatexCommand ref
14246 reference "sub:A-Step-by Assembler Introduction"
14252 Absolute addresses can be specified for variables in all
14253 storage classes, e.g.:
14256 \begin_layout Verse
14260 \begin_inset LatexCommand index
14266 \begin_inset LatexCommand index
14274 \begin_layout Standard
14275 The above example will allocate the variable at offset 0x02 in the bit-addressab
14277 There is no real advantage to assigning absolute addresses to variables
14278 in this manner, unless you want strict control over all the variables allocated.
14279 One possible use would be to write hardware portable code.
14280 For example, if you have a routine that uses one or more of the microcontroller
14281 I/O pins, and such pins are different for two different hardwares, you
14282 can declare the I/O pins in your routine using:
14285 \begin_layout Verse
14289 \begin_inset LatexCommand index
14294 __bit MOSI;\InsetSpace ~
14298 /* master out, slave in */
14300 extern volatile __bit MISO;\InsetSpace ~
14307 extern volatile __bit MCLK;\InsetSpace ~
14316 Output of a byte on a 3-wire serial bus.
14321 If needed adapt polarity of clock,
14322 polarity of data and bit order
14327 unsigned char spi_io(unsigned char out_byte)
14352 MOSI = out_byte & 0x80;
14383 /* _asm nop _endasm; */\InsetSpace ~
14391 /* for slow peripherals */
14443 \begin_layout Standard
14444 Then, someplace in the code for the first hardware you would use
14447 \begin_layout Verse
14451 \begin_inset LatexCommand index
14457 \begin_inset LatexCommand index
14462 (0x80) MOSI;\InsetSpace ~
14466 /* I/O port 0, bit 0 */
14468 __bit __at (0x81) MISO;\InsetSpace ~
14475 __bit __at (0x82) MCLK;\InsetSpace ~
14479 /* I/O port 0, bit 2 */
14482 \begin_layout Standard
14483 Similarly, for the second hardware you would use
14486 \begin_layout Verse
14489 __bit __at (0x83) MOSI;\InsetSpace ~
14493 /* I/O port 0, bit 3 */
14495 __bit __at (0x91) MISO;\InsetSpace ~
14500 I/O port 1, bit 1 */
14503 \begin_inset LatexCommand index
14508 __at (0x92) MCLK;\InsetSpace ~
14512 /* I/O port 1, bit 2 */
14515 \begin_layout Standard
14516 and you can use the same hardware dependent routine without changes, as
14517 for example in a library.
14518 This is somehow similar to sbit, but only one absolute address has to be
14519 specified in the whole project.
14520 \begin_inset VSpace bigskip
14526 \begin_layout Section
14528 \begin_inset LatexCommand index
14534 \begin_inset LatexCommand index
14535 name "function parameter"
14540 \begin_inset LatexCommand index
14541 name "local variables"
14546 \begin_inset LatexCommand label
14547 name "sec:Parameters-and-Local-Variables"
14554 \begin_layout Standard
14555 Automatic (local) variables and parameters to functions can either be placed
14556 on the stack or in data-space.
14557 The default action of the compiler is to place these variables in the internal
14558 RAM (for small model) or external RAM (for medium or large model).
14559 This in fact makes them similar to
14562 \begin_inset LatexCommand index
14569 so by default functions are non-reentrant
14570 \begin_inset LatexCommand index
14580 They can be placed on the stack
14581 \begin_inset LatexCommand index
14592 \begin_layout Standard
14602 \begin_inset LatexCommand index
14603 name "-\\/-stack-auto"
14611 #pragma\InsetSpace ~
14615 \begin_inset LatexCommand index
14616 name "\\#pragma stackauto"
14623 \begin_inset LatexCommand index
14630 keyword in the function declaration, e.g.:
14633 \begin_layout Verse
14636 unsigned char foo(char i) __reentrant
14650 \begin_layout Standard
14651 Since stack space on 8051 is limited, the
14661 \begin_layout Standard
14672 option should be used sparingly.
14673 Note that the reentrant keyword just means that the parameters & local
14674 variables will be allocated to the stack, it
14678 mean that the function is register bank
14679 \begin_inset LatexCommand index
14680 name "register bank (mcs51, ds390)"
14689 \begin_inset LatexCommand index
14690 name "local variables"
14694 can be assigned storage classes and absolute
14695 \begin_inset LatexCommand index
14696 name "Absolute addressing"
14703 \begin_layout Verse
14706 unsigned char foo()
14714 __xdata unsigned char i;
14727 \begin_inset LatexCommand index
14732 (0x31) unsigned char j;
14744 \begin_layout Standard
14745 In the above example the variable
14749 will be allocated in the external ram,
14753 in bit addressable space and
14764 \begin_layout Standard
14775 or when a function is declared as
14779 this should only be done for static variables.
14782 \begin_layout Standard
14784 \begin_inset LatexCommand index
14785 name "function parameter"
14789 however are not allowed any storage class
14790 \begin_inset LatexCommand index
14791 name "Storage class"
14795 , (storage classes for parameters will be ignored), their allocation is
14796 governed by the memory model in use, and the reentrancy options.
14799 \begin_layout Standard
14800 It is however allowed to use bit parameters in reentrant functions and also
14801 non-static local bit variables are supported.
14802 Efficient use is limited to 8 semi-bitregisters in bit space.
14803 They are pushed and popped to stack
14804 \begin_inset LatexCommand index
14809 as a single byte just like the normal registers.
14812 \begin_layout Section
14814 \begin_inset LatexCommand label
14815 name "sub:Overlaying"
14820 \begin_inset LatexCommand index
14828 \begin_layout Standard
14830 \begin_inset LatexCommand index
14835 functions SDCC will try to reduce internal ram space usage by overlaying
14836 parameters and local variables of a function (if possible).
14837 Parameters and local variables
14838 \begin_inset LatexCommand index
14839 name "local variables"
14843 of a function will be allocated to an overlayable segment if the function
14846 no other function calls and the function is non-reentrant and the memory
14848 \begin_inset LatexCommand index
14849 name "Memory model"
14856 If an explicit storage class
14857 \begin_inset LatexCommand index
14858 name "Storage class"
14862 is specified for a local variable, it will NOT be overlaid.
14865 \begin_layout Standard
14866 Note that the compiler (not the linkage editor) makes the decision for overlayin
14868 Functions that are called from an interrupt service routine
14869 \begin_inset Marginal
14872 \begin_layout Standard
14880 should be preceded by a #pragma\InsetSpace ~
14882 \begin_inset LatexCommand index
14883 name "\\#pragma nooverlay"
14887 if they are not reentrant.
14890 \begin_layout Standard
14891 Also note that the compiler does not do any processing of inline assembler
14892 code, so the compiler might incorrectly assign local variables and parameters
14893 of a function into the overlay segment if the inline assembler code calls
14894 other c-functions that might use the overlay.
14895 In that case the #pragma\InsetSpace ~
14896 nooverlay should be used.
14899 \begin_layout Standard
14900 Parameters and local variables of functions that contain 16 or 32 bit multiplica
14902 \begin_inset LatexCommand index
14903 name "Multiplication"
14908 \begin_inset LatexCommand index
14913 will NOT be overlaid since these are implemented using external functions,
14917 \begin_layout Verse
14923 \begin_inset LatexCommand index
14924 name "\\#pragma nooverlay"
14930 void set_error(unsigned char errcd)
14947 some_isr () __interrupt
14948 \begin_inset LatexCommand index
14979 \begin_layout Standard
14980 In the above example the parameter
14988 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
14990 not present, this could cause unpredictable runtime behavior when called
14991 from an interrupt service routine.
14992 The #pragma\InsetSpace ~
14993 nooverlay ensures that the parameters and local variables for
14994 the function are NOT overlaid.
14995 \begin_inset VSpace bigskip
15001 \begin_layout Section
15002 Interrupt Service Routines
15003 \begin_inset LatexCommand label
15004 name "sub:Interrupt-Service-Routines"
15011 \begin_layout Subsection
15012 General Information
15015 \begin_layout Standard
15028 outines to be coded in C, with some extended keywords.
15031 \begin_layout Verse
15034 void timer_isr (void) __interrupt (1) __using (1)
15048 \begin_layout Standard
15049 The optional number following the
15052 \begin_inset LatexCommand index
15058 \begin_inset LatexCommand index
15059 name "\\_\\_interrupt"
15065 keyword is the interrupt number this routine will service.
15066 When present, the compiler will insert a call to this routine in the interrupt
15068 \begin_inset LatexCommand index
15069 name "interrupt vector table"
15073 for the interrupt number specified.
15074 If you have multiple source files in your project, interrupt service routines
15075 can be present in any of them, but a prototype of the isr MUST be present
15076 or included in the file that contains the function
15081 The optional (8051 specific) keyword
15084 \begin_inset LatexCommand index
15085 name "using (mcs51, ds390 register bank)"
15090 \begin_inset LatexCommand index
15091 name "\\_\\_using (mcs51, ds390 register bank)"
15097 can be used to tell the compiler to use the specified register bank when
15098 generating code for this function.
15101 Interrupt service routines open the door for some very interesting bugs:
15104 \begin_layout Subsubsection
15105 \begin_inset LatexCommand label
15106 name "sub:Common-interrupt-pitfall-volatile"
15110 Common interrupt pitfall: variable not declared
15115 \begin_layout Standard
15116 If an interrupt service routine changes variables which are accessed by
15117 other functions these variables have to be declared
15122 \begin_inset LatexCommand index
15129 \begin_inset LatexCommand url
15130 target "http://en.wikipedia.org/wiki/Volatile_variable"
15137 \begin_layout Subsubsection
15138 \begin_inset LatexCommand label
15139 name "sub:Common-interrupt-pitfall-non-atomic"
15143 Common interrupt pitfall:
15148 \begin_layout Standard
15149 If the access to these variables is not
15152 \begin_inset LatexCommand index
15160 the processor needs more than one instruction for the access and could
15161 be interrupted while accessing the variable) the interrupt must be disabled
15162 during the access to avoid inconsistent data.
15165 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
15166 and should be protected by disabling interrupts.
15167 You're not automatically on the safe side if you use 8 bit variables though.
15168 We need an example here: f.e.
15169 on the 8051 the harmless looking
15170 \begin_inset Quotes srd
15180 \begin_inset Quotes sld
15189 \begin_inset Quotes srd
15199 \begin_inset Quotes sld
15202 from within an interrupt routine might get lost if the interrupt occurs
15205 \begin_inset Quotes sld
15210 counter\InsetSpace ~
15215 \begin_inset Quotes srd
15218 is not atomic on the 8051 even if
15222 is located in data memory.
15224 Bugs like these are hard to reproduce and can
15225 cause a lot of trouble.
15229 \begin_layout Subsubsection
15230 \begin_inset LatexCommand label
15231 name "sub:Common-interrupt-pitfall-stack-overflow"
15235 Common interrupt pitfall:
15240 \begin_layout Standard
15241 The return address and the registers used in the interrupt service routine
15242 are saved on the stack
15243 \begin_inset LatexCommand index
15248 so there must be sufficient stack space.
15249 If there isn't variables or registers (or even the return address itself)
15256 \begin_inset LatexCommand index
15257 name "stack overflow"
15261 is most likely to happen if the interrupt occurs during the
15262 \begin_inset Quotes sld
15266 \begin_inset Quotes srd
15269 subroutine when the stack is already in use for f.e.
15270 many return addresses.
15273 \begin_layout Subsubsection
15274 \begin_inset LatexCommand label
15275 name "sub:Common-interrupt-pitfall-non-reentrant"
15279 Common interrupt pitfall:
15281 use of non-reentrant functions
15284 \begin_layout Standard
15285 A special note here, int (16 bit) and long (32 bit) integer division
15286 \begin_inset LatexCommand index
15292 \begin_inset LatexCommand index
15293 name "Multiplication"
15298 \begin_inset LatexCommand index
15304 \begin_inset LatexCommand index
15305 name "Floating point support"
15309 operations are implemented using external support routines.
15310 If an interrupt service routine needs to do any of these operations then
15311 the support routines (as mentioned in a following section) will have to
15312 be recompiled using the
15318 \begin_layout Standard
15328 \begin_inset LatexCommand index
15329 name "-\\/-stack-auto"
15335 option and the source file will need to be compiled using the
15341 \begin_layout Standard
15353 \begin_inset LatexCommand index
15354 name "-\\/-int-long-reent"
15361 Note, the type promotion
15362 \begin_inset LatexCommand index
15363 name "type promotion"
15367 required by ANSI C can cause 16 bit routines to be used
15368 \begin_inset Marginal
15371 \begin_layout Standard
15380 without the programmer being aware of it.
15385 (unsigned char)(tail-1)
15390 within the if clause in section
15391 \begin_inset LatexCommand ref
15392 reference "sub:A-Step-by Assembler Introduction"
15399 \begin_layout Standard
15400 Calling other functions from an interrupt service routine is not recommended,
15401 avoid it if possible.
15402 Note that when some function is called from an interrupt service routine
15403 it should be preceded by a #pragma\InsetSpace ~
15405 \begin_inset LatexCommand index
15406 name "\\#pragma nooverlay"
15410 if it is not reentrant.
15411 Furthermore nonreentrant functions should not be called from the main program
15412 while the interrupt service routine might be active.
15413 They also must not be called from low priority interrupt service routines
15414 while a high priority interrupt service routine might be active.
15415 You could use semaphores or make the function
15419 if all parameters are passed in registers.
15422 \begin_inset LatexCommand ref
15423 reference "sub:Overlaying"
15428 about Overlaying and section
15429 \begin_inset LatexCommand ref
15430 reference "sub:Functions-using-private-banks"
15435 about Functions using private register banks.
15436 \begin_inset VSpace bigskip
15442 \begin_layout Subsection
15443 MCS51/DS390 Interrupt Service Routines
15446 \begin_layout Standard
15448 \begin_inset LatexCommand index
15453 numbers and the corresponding address & descriptions for the Standard 8051/8052
15455 SDCC will automatically adjust the
15456 \begin_inset LatexCommand index
15457 name "interrupt vector table"
15461 to the maximum interrupt number specified.
15466 \begin_layout Standard
15468 \begin_inset Tabular
15469 <lyxtabular version="3" rows="9" columns="3">
15471 <column alignment="center" valignment="top" leftline="true" width="0in">
15472 <column alignment="left" valignment="top" leftline="true" width="0in">
15473 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
15474 <row topline="true" bottomline="true">
15475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15478 \begin_layout Standard
15484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15487 \begin_layout Standard
15493 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15496 \begin_layout Standard
15503 <row topline="true">
15504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15507 \begin_layout Standard
15513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15516 \begin_layout Standard
15522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15525 \begin_layout Standard
15532 <row topline="true">
15533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15536 \begin_layout Standard
15542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15545 \begin_layout Standard
15551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15554 \begin_layout Standard
15561 <row topline="true">
15562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15565 \begin_layout Standard
15571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15574 \begin_layout Standard
15580 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15583 \begin_layout Standard
15590 <row topline="true">
15591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15594 \begin_layout Standard
15600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15603 \begin_layout Standard
15609 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15612 \begin_layout Standard
15619 <row topline="true">
15620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15623 \begin_layout Standard
15629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15632 \begin_layout Standard
15638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15641 \begin_layout Standard
15648 <row topline="true">
15649 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15652 \begin_layout Standard
15658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15661 \begin_layout Standard
15667 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15670 \begin_layout Standard
15677 <row topline="true">
15678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15681 \begin_layout Standard
15687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15690 \begin_layout Standard
15696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15699 \begin_layout Standard
15706 <row topline="true" bottomline="true">
15707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15710 \begin_layout Standard
15716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15719 \begin_layout Standard
15725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15728 \begin_layout Standard
15744 \begin_layout Standard
15745 If the interrupt service routine is defined without
15748 \begin_inset LatexCommand index
15749 name "using (mcs51, ds390 register bank)"
15754 \begin_inset LatexCommand index
15755 name "\\_\\_using (mcs51, ds390 register bank)"
15761 a register bank or with register bank 0 (
15765 0), the compiler will save the registers used by itself on the stack upon
15766 entry and restore them at exit, however if such an interrupt service routine
15767 calls another function then the entire register bank will be saved on the
15769 This scheme may be advantageous for small interrupt service routines which
15770 have low register usage.
15773 \begin_layout Standard
15774 If the interrupt service routine is defined to be using a specific register
15779 & psw are saved and restored, if such an interrupt service routine calls
15780 another function (using another register bank) then the entire register
15781 bank of the called function will be saved on the stack
15782 \begin_inset LatexCommand index
15788 This scheme is recommended for larger interrupt service routines.
15789 \begin_inset VSpace bigskip
15795 \begin_layout Subsection
15797 \begin_inset LatexCommand index
15802 Interrupt Service Routines
15805 \begin_layout Standard
15806 Since the number of interrupts
15807 \begin_inset LatexCommand index
15808 name "HC08!interrupt"
15812 available is chip specific and the interrupt vector table always ends at
15813 the last byte of memory, the interrupt numbers corresponds to the interrupt
15814 vectors in reverse order of address.
15815 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
15816 2 will use the interrupt vector at 0xfffa, and so on.
15817 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
15818 this way; instead see section
15819 \begin_inset LatexCommand ref
15820 reference "sub:Startup-Code"
15824 for details on customizing startup.
15825 \begin_inset VSpace bigskip
15831 \begin_layout Subsection
15832 Z80 Interrupt Service Routines
15835 \begin_layout Standard
15837 \begin_inset LatexCommand index
15842 uses several different methods for determining the correct interrupt
15843 \begin_inset LatexCommand index
15844 name "Z80!interrupt"
15848 vector depending on the hardware implementation.
15849 Therefore, SDCC ignores the optional interrupt number and does not attempt
15850 to generate an interrupt vector table.
15853 \begin_layout Standard
15854 By default, SDCC generates code for a maskable interrupt, which uses a RETI
15855 instruction to return from the interrupt.
15856 To write an interrupt handler for the non-maskable interrupt, which needs
15857 a RETN instruction instead, add the
15864 \begin_layout Verse
15867 void nmi_isr (void) critical interrupt
15881 \begin_layout Standard
15882 However if you need to create a non-interruptable interrupt service routine
15883 you would also require the
15888 To distinguish between this and an nmi_isr you must provide an interrupt
15890 \begin_inset VSpace bigskip
15896 \begin_layout Section
15897 Enabling and Disabling Interrupts
15900 \begin_layout Subsection
15901 Critical Functions and Critical Statements
15904 \begin_layout Standard
15905 A special keyword may be associated with a block or a function declaring
15911 SDCC will generate code to disable all interrupts
15912 \begin_inset LatexCommand index
15917 upon entry to a critical function and restore the interrupt enable to the
15918 previous state before returning.
15919 Nesting critical functions will need one additional byte on the stack
15920 \begin_inset LatexCommand index
15928 \begin_layout Verse
15931 int foo () __critical
15932 \begin_inset LatexCommand index
15938 \begin_inset LatexCommand index
15939 name "\\_\\_critical"
15964 \begin_layout Standard
15965 The critical attribute maybe used with other attributes like
15975 may also be used to disable interrupts more locally:
15978 \begin_layout Verse
15984 \begin_layout Standard
15985 More than one statement could have been included in the block.
15988 \begin_layout Subsection
15989 Enabling and Disabling Interrupts directly
15992 \begin_layout Standard
15994 \begin_inset LatexCommand index
15999 can also be disabled and enabled directly (8051):
16002 \begin_layout Verse
16005 EA = 0;\InsetSpace ~
16031 \begin_layout Verse
16067 \begin_layout Verse
16070 EA = 1;\InsetSpace ~
16099 \begin_layout Verse
16138 \begin_layout Standard
16139 On other architectures which have separate opcodes for enabling and disabling
16140 interrupts you might want to make use of defines with inline assembly
16141 \begin_inset LatexCommand index
16142 name "Assembler routines"
16147 \begin_inset LatexCommand index
16148 name "HC08!interrupt"
16155 \begin_layout Verse
16159 \begin_inset LatexCommand index
16169 \begin_inset LatexCommand index
16177 \begin_layout Verse
16180 #define SEI _asm\InsetSpace ~
16187 \begin_layout Verse
16193 \begin_layout Standard
16194 Note: it is sometimes sufficient to disable only a specific interrupt source
16196 a timer or serial interrupt by manipulating an
16199 \begin_inset LatexCommand index
16200 name "interrupt mask"
16210 \begin_layout Standard
16211 Usually the time during which interrupts are disabled should be kept as
16213 This minimizes both
16218 \begin_inset LatexCommand index
16219 name "interrupt latency"
16223 (the time between the occurrence of the interrupt and the execution of
16224 the first code in the interrupt routine) and
16229 \begin_inset LatexCommand index
16230 name "interrupt jitter"
16234 (the difference between the shortest and the longest interrupt latency).
16235 These really are something different, f.e.
16236 a serial interrupt has to be served before its buffer overruns so it cares
16237 for the maximum interrupt latency, whereas it does not care about jitter.
16238 On a loudspeaker driven via a digital to analog converter which is fed
16239 by an interrupt a latency of a few milliseconds might be tolerable, whereas
16240 a much smaller jitter will be very audible.
16243 \begin_layout Standard
16244 You can reenable interrupts within an interrupt routine and on some architecture
16245 s you can make use of two (or more) levels of
16247 interrupt priorities
16250 \begin_inset LatexCommand index
16251 name "interrupt priority"
16256 On some architectures which don't support interrupt priorities these can
16257 be implemented by manipulating the interrupt mask and reenabling interrupts
16258 within the interrupt routine.
16259 Check there is sufficient space on the stack
16260 \begin_inset LatexCommand index
16265 and don't add complexity unless you have to.
16269 \begin_layout Subsection
16271 \begin_inset LatexCommand index
16276 locking (mcs51/ds390)
16279 \begin_layout Standard
16280 Some architectures (mcs51/ds390) have an atomic
16281 \begin_inset LatexCommand index
16286 bit test and clear instruction.
16287 These type of instructions are typically used in preemptive multitasking
16288 systems, where a routine f.e.
16289 claims the use of a data structure ('acquires a lock
16290 \begin_inset LatexCommand index
16295 on it'), makes some modifications and then releases the lock when the data
16296 structure is consistent again.
16297 The instruction may also be used if interrupt and non-interrupt code have
16298 to compete for a resource.
16299 With the atomic bit test and clear instruction interrupts
16300 \begin_inset LatexCommand index
16305 don't have to be disabled for the locking operation.
16309 \begin_layout Standard
16310 SDCC generates this instruction if the source follows this pattern:
16313 \begin_layout Verse
16317 \begin_inset LatexCommand index
16322 bit resource_is_free;
16326 if (resource_is_free)
16336 resource_is_free=0;
16349 resource_is_free=1;
16356 \begin_layout Standard
16357 Note, mcs51 and ds390 support only an atomic
16358 \begin_inset LatexCommand index
16367 instruction (as opposed to atomic bit test and
16372 \begin_layout Section
16373 Functions using private register banks
16374 \begin_inset LatexCommand label
16375 name "sub:Functions-using-private-banks"
16382 \begin_layout Standard
16383 Some architectures have support for quickly changing register sets.
16384 SDCC supports this feature with the
16387 \begin_inset LatexCommand index
16388 name "using (mcs51, ds390 register bank)"
16393 \begin_inset LatexCommand index
16394 name "\\_\\_using (mcs51, ds390 register bank)"
16400 attribute (which tells the compiler to use a register bank
16401 \begin_inset LatexCommand index
16402 name "register bank (mcs51, ds390)"
16406 other than the default bank zero).
16407 It should only be applied to
16410 \begin_inset LatexCommand index
16417 functions (see footnote below).
16418 This will in most circumstances make the generated ISR code more efficient
16419 since it will not have to save registers on the stack.
16422 \begin_layout Standard
16427 attribute will have no effect on the generated code for a
16431 function (but may occasionally be useful anyway
16435 \begin_layout Standard
16436 possible exception: if a function is called ONLY from 'interrupt' functions
16437 using a particular bank, it can be declared with the same 'using' attribute
16438 as the calling 'interrupt' functions.
16439 For instance, if you have several ISRs using bank one, and all of them
16440 call memcpy(), it might make sense to create a specialized version of memcpy()
16441 'using 1', since this would prevent the ISR from having to save bank zero
16442 to the stack on entry and switch to bank zero before calling the function
16451 (pending: Note, nowadays the
16455 attribute has an effect on
16459 the generated code for a
16470 \begin_layout Standard
16475 function using a non-zero bank will assume that it can trash that register
16476 bank, and will not save it.
16477 Since high-priority interrupts
16478 \begin_inset LatexCommand index
16484 \begin_inset LatexCommand index
16485 name "interrupt priority"
16489 can interrupt low-priority ones on the 8051 and friends, this means that
16490 if a high-priority ISR
16494 a particular bank occurs while processing a low-priority ISR
16498 the same bank, terrible and bad things can happen.
16499 To prevent this, no single register bank should be
16503 by both a high priority and a low priority ISR.
16504 This is probably most easily done by having all high priority ISRs use
16505 one bank and all low priority ISRs use another.
16506 If you have an ISR which can change priority at runtime, you're on your
16507 own: I suggest using the default bank zero and taking the small performance
16511 \begin_layout Standard
16512 It is most efficient if your ISR calls no other functions.
16513 If your ISR must call other functions, it is most efficient if those functions
16514 use the same bank as the ISR (see note 1 below); the next best is if the
16515 called functions use bank zero.
16516 It is very inefficient to call a function using a different, non-zero bank
16519 \begin_inset VSpace bigskip
16525 \begin_layout Section
16527 \begin_inset LatexCommand label
16528 name "sub:Startup-Code"
16533 \begin_inset LatexCommand index
16534 name "Startup code"
16541 \begin_layout Subsection
16542 MCS51/DS390 Startup Code
16545 \begin_layout Standard
16546 The compiler triggers the linker to link certain initialization modules
16547 from the runtime library
16548 \begin_inset LatexCommand index
16549 name "Runtime library"
16553 called crt<something>.
16554 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
16555 GSINIT5) is not linked unless the -
16561 \begin_layout Standard
16572 -xstack option is used.
16573 These modules are highly entangled by the use of special segments/areas,
16574 but a common layout is shown below:
16577 \begin_layout Verse
16585 \begin_layout Verse
16609 ljmp __sdcc_gsinit_startup
16612 \begin_layout Verse
16620 \begin_layout Verse
16632 .area GSINIT0 (CODE)
16634 __sdcc_gsinit_startup::
16644 mov sp,#__start__stack - 1
16647 \begin_layout Verse
16655 \begin_layout Verse
16667 .area GSINIT1 (CODE)
16669 __sdcc_init_xstack::
16671 ; Need to initialize in GSINIT1 in
16672 case the user's __sdcc_external_startup uses the xstack.
16682 mov __XPAGE,#(__start__x
16693 mov _spx,#__start__xstack
16696 \begin_layout Verse
16704 \begin_layout Verse
16716 .area GSINIT2 (CODE)
16726 lcall __sdcc_external_startup
16746 jz __sdcc_init_data
16757 __sdcc_program_startup
16762 \begin_layout Verse
16770 \begin_layout Verse
16782 .area GSINIT3 (CODE)
16835 mov r2,#((l_XINIT+255) >> 8)
16866 __XPAGE,#(s_XISEG >> 8)
16868 00001$:\InsetSpace ~
16932 00002$:\InsetSpace ~
16959 \begin_layout Verse
16967 \begin_layout Verse
16979 .area GSINIT4 (CODE)
16981 __mcs51_genRAMCLEAR::
17003 00004$:\InsetSpace ~
17017 ; _mcs51_genRAMCLEAR() end
17020 \begin_layout Verse
17028 \begin_layout Verse
17040 .area GSINIT4 (CODE)
17042 __mcs51_genXRAMCLEAR::
17103 mov __XPAGE,#(s_PSEG >> 8)
17115 00005$:\InsetSpace ~
17190 mov r1,#((l_XSEG + 255) >> 8)
17212 00007$:\InsetSpace ~
17249 \begin_layout Verse
17257 \begin_layout Verse
17269 .area GSINIT5 (CODE)
17271 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
17274 ; and __mcs51_genRAMCLEAR modifies _spx.
17284 mov __XPAGE,#(__start__x
17295 mov _spx,#__start__xstack
17298 \begin_layout Verse
17303 (application modules)
17306 \begin_layout Verse
17318 .area GSINIT (CODE)
17321 \begin_layout Verse
17329 \begin_layout Verse
17341 .area GSFINAL (CODE)
17351 ljmp __sdcc_program_startup
17353 ;---------------------------------
17354 -----------------------
17358 ;--------------------------------------------------
17381 __sdcc_program_startup:
17394 return from main will lock up
17407 \begin_layout Standard
17408 One of these modules (crtstart.asm) contains a call to the C routine
17410 _sdcc_external_startup()
17411 \begin_inset LatexCommand index
17412 name "\\_sdcc\\_external\\_startup()"
17418 at the start of the CODE area.
17419 This routine is also in the runtime library
17420 \begin_inset LatexCommand index
17421 name "Runtime library"
17425 and returns 0 by default.
17426 If this routine returns a non-zero value, the static & global variable
17427 initialization will be skipped and the function main will be invoked.
17428 Otherwise static & global variables will be initialized before the function
17432 _sdcc_external_startup()
17434 routine to your program to override the default if you need to setup hardware
17435 or perform some other critical operation prior to static & global variable
17437 \begin_inset LatexCommand index
17438 name "Variable initialization"
17443 On some mcs51 variants xdata
17444 \begin_inset LatexCommand index
17445 name "xdata (mcs51, ds390 storage class)"
17449 memory has to be explicitly enabled before it can be accessed or if the
17451 \begin_inset LatexCommand index
17456 needs to be disabled, this is the place to do it.
17457 The startup code clears all internal data memory, 256 bytes by default,
17458 but from 0 to n-1 if
17464 \begin_layout Standard
17474 \begin_inset LatexCommand index
17475 name "-\\/-iram-size <Value>"
17482 (recommended for Chipcon CC1010).
17485 \begin_layout Standard
17486 See also the compiler options
17492 \begin_layout Standard
17508 \begin_inset LatexCommand index
17509 name "-\\/-no-xinit-opt"
17519 \begin_layout Standard
17531 \begin_inset LatexCommand index
17532 name "-\\/-main-return"
17537 \begin_inset LatexCommand ref
17538 reference "sub:MCS51-variants"
17542 about MCS51-variants.
17547 \begin_layout Standard
17548 While these initialization modules are meant as generic startup code there
17549 might be the need for customization.
17550 Let's assume the return value of
17552 _sdcc_external_startup()
17558 should not be checked (or
17560 _sdcc_external_startup()
17562 should not be called at all).
17563 The recommended way would be to copy
17569 \begin_inset LatexCommand url
17570 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm"
17574 ) into the source directory, adapt it there, then assemble it with
17580 \begin_layout Standard
17581 \begin_inset Quotes sld
17585 \begin_inset Quotes srd
17588 are the assembler options used in
17589 \begin_inset LatexCommand url
17590 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup "
17601 and when linking your project explicitly specify
17606 As a bonus a listing of the relocated object file
17613 \begin_layout Standard
17614 \begin_inset VSpace bigskip
17620 \begin_layout Subsection
17624 \begin_layout Standard
17626 \begin_inset LatexCommand index
17631 startup code follows the same scheme as the MCS51 startup code.
17632 \begin_inset VSpace bigskip
17638 \begin_layout Subsection
17642 \begin_layout Standard
17644 \begin_inset LatexCommand index
17649 the startup code is inserted by linking with crt0.o which is generated from
17650 sdcc/device/lib/z80/crt0.s.
17651 If you need a different startup code you can use the compiler option
17660 \begin_layout Standard
17675 \begin_inset LatexCommand index
17676 name "-\\/-no-std-crt0"
17680 and provide your own crt0.o.
17682 \begin_inset VSpace bigskip
17688 \begin_layout Section
17689 Inline Assembler Code
17690 \begin_inset LatexCommand index
17691 name "Assembler routines"
17698 \begin_layout Subsection
17699 A Step by Step Introduction
17700 \begin_inset LatexCommand label
17701 name "sub:A-Step-by Assembler Introduction"
17708 \begin_layout Standard
17709 Starting from a small snippet of c-code this example shows for the MCS51
17710 how to use inline assembly, access variables, a function parameter and
17711 an array in xdata memory.
17712 The example uses an MCS51 here but is easily adapted for other architectures.
17713 This is a buffer routine which should be optimized:
17716 \begin_layout Verse
17720 unsigned char __far
17721 \begin_inset LatexCommand index
17722 name "far (storage class)"
17727 \begin_inset LatexCommand index
17728 name "\\_\\_far (storage class)"
17733 \begin_inset LatexCommand index
17739 \begin_inset LatexCommand index
17744 (0x7f00) buf[0x100];
17745 \begin_inset LatexCommand index
17746 name "Aligned array"
17752 unsigned char head, tail;\InsetSpace ~
17770 \begin_inset LatexCommand index
17823 \begin_inset LatexCommand ref
17824 reference "sub:Common-interrupt-pitfall-volatile"
17842 void to_buffer( unsigned char c )
17850 if( head != (unsigned char)(tail-1)
17863 \begin_inset LatexCommand index
17864 name "promotion to signed int"
17869 \begin_inset LatexCommand index
17870 name "type promotion"
17875 \begin_inset Marginal
17878 \begin_layout Standard
17897 buf[ head++ ] = c;\InsetSpace ~
17913 /* access to a 256 byte aligned array */
17918 \begin_layout Standard
17919 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
17920 then a corresponding buffer.asm file is generated.
17921 We define a new function
17925 in file buffer.c in which we cut and paste the generated code, removing
17926 unwanted comments and some ':'.
17928 \begin_inset Quotes sld
17936 \begin_inset Quotes srd
17940 \begin_inset Quotes sld
17948 \begin_inset Quotes srd
17955 \begin_layout Standard
17956 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
17957 and for C-99 compatibility, the double-underscore form (__asm and __endasm)
17959 The latter is also used in the library functions.
17964 to the beginning and the end of the function body:
17967 \begin_layout Verse
17971 /* With a cut and paste from the .asm file, we have something to start with.
17977 function is not yet OK! (registers aren't saved) */
17979 void to_buffer_asm(
17989 \begin_inset LatexCommand index
17995 \begin_inset LatexCommand index
18010 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
18022 \begin_inset LatexCommand index
18023 name "promotion to signed int"
18028 \begin_inset LatexCommand index
18029 name "type promotion"
18082 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
18083 \begin_inset LatexCommand index
18084 name "Aligned array"
18150 \begin_inset LatexCommand index
18156 \begin_inset LatexCommand index
18157 name "\\_\\_endasm"
18166 \begin_layout Standard
18167 The new file buffer.c should compile with only one warning about the unreferenced
18168 function argument 'c'.
18169 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
18170 (1) and finally have:
18173 \begin_layout Verse
18177 unsigned char __far __at(0x7f00) buf[0x100];
18179 unsigned char head, tail;
18190 void to_buffer( unsigned char c )
18199 head != (unsigned char)(tail-1) )
18228 c; // to avoid warning: unreferenced function argument
18235 \begin_inset LatexCommand index
18241 \begin_inset LatexCommand index
18256 ; save used registers here.
18267 ; If we were still using r2,r3 we would have to push them here.
18270 ; if( head != (unsigned char)(tail-1) )
18314 could do an ANL a,#0x0f here to use a smaller buffer (see below)
18350 a,dpl \InsetSpace ~
18357 ; dpl holds lower byte of function argument
18369 dpl,_head \InsetSpace ~
18372 ; buf is 0x100 byte aligned so head can be used directly
18415 ; we could do an ANL _head,#0x0f here to use a
18416 smaller buffer (see above)
18428 ; restore used registers here
18435 \begin_inset LatexCommand index
18441 \begin_inset LatexCommand index
18442 name "\\_\\_endasm"
18453 \begin_layout Standard
18454 The inline assembler code can contain any valid code understood by the assembler
18455 , this includes any assembler directives and comment lines.
18456 The assembler does not like some characters like ':' or ''' in comments.
18457 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
18458 \begin_inset LatexCommand index
18459 name "asXXXX (as-gbz80, as-hc08, asx8051, as-z80)"
18464 \begin_inset LatexCommand index
18465 name "Assembler documentation"
18470 \begin_inset LatexCommand url
18471 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html"
18479 \begin_layout Standard
18480 The compiler does not do any validation of the code within the
18483 \begin_inset LatexCommand index
18489 \begin_inset LatexCommand index
18498 \begin_inset LatexCommand index
18504 \begin_inset LatexCommand index
18505 name "\\_\\_endasm"
18514 Specifically it will not know which registers are used and thus register
18516 \begin_inset LatexCommand index
18521 has to be done manually.
18525 \begin_layout Standard
18526 It is recommended that each assembly instruction (including labels) be placed
18527 in a separate line (as the example shows).
18532 \begin_layout Standard
18544 \begin_inset LatexCommand index
18545 name "-\\/-peep-asm"
18551 command line option is used, the inline assembler code will be passed through
18552 the peephole optimizer
18553 \begin_inset LatexCommand index
18554 name "Peephole optimizer"
18559 There are only a few (if any) cases where this option makes sense, it might
18560 cause some unexpected changes in the inline assembler code.
18561 Please go through the peephole optimizer rules defined in file
18565 before using this option.
18568 \begin_layout Subsection
18570 \begin_inset LatexCommand label
18571 name "sub:Naked-Functions"
18576 \begin_inset LatexCommand index
18577 name "Naked functions"
18584 \begin_layout Standard
18585 A special keyword may be associated with a function declaring it as
18588 \begin_inset LatexCommand index
18594 \begin_inset LatexCommand index
18606 function modifier attribute prevents the compiler from generating prologue
18607 \begin_inset LatexCommand index
18608 name "function prologue"
18613 \begin_inset LatexCommand index
18614 name "function epilogue"
18618 code for that function.
18619 This means that the user is entirely responsible for such things as saving
18620 any registers that may need to be preserved, selecting the proper register
18621 bank, generating the
18625 instruction at the end, etc.
18626 Practically, this means that the contents of the function must be written
18627 in inline assembler.
18628 This is particularly useful for interrupt functions, which can have a large
18629 (and often unnecessary) prologue/epilogue.
18630 For example, compare the code generated by these two functions:
18633 \begin_layout Verse
18637 \begin_inset LatexCommand index
18642 data unsigned char counter;
18646 void simpleInterrupt(void) __interrupt
18647 \begin_inset LatexCommand index
18653 \begin_inset LatexCommand index
18654 name "\\_\\_interrupt"
18672 void nakedInterrupt(void) __interrupt (2) __naked
18681 \begin_inset LatexCommand index
18687 \begin_inset LatexCommand index
18705 _counter ; does not change flags, no need to save psw
18718 include ret or reti in _naked function.
18725 \begin_inset LatexCommand index
18731 \begin_inset LatexCommand index
18732 name "\\_\\_endasm"
18741 \begin_layout Standard
18742 For an 8051 target, the generated simpleInterrupt looks like:
18745 \begin_layout Verse
18758 example, recent versions of SDCC generate
18770 code for simpleInterrupt() and nakedInterrupt()!
18911 \begin_layout Standard
18912 whereas nakedInterrupt looks like:
18915 \begin_layout Verse
18928 _counter ; does not change flags, no need to save psw
18947 MUST explicitly include ret or reti in _naked function
18950 \begin_layout Standard
18951 The related directive #pragma exclude
18952 \begin_inset LatexCommand index
18953 name "\\#pragma exclude"
18957 allows a more fine grained control over pushing & popping
18958 \begin_inset LatexCommand index
18966 \begin_layout Standard
18967 While there is nothing preventing you from writing C code inside a
18971 function, there are many ways to shoot yourself in the foot doing this,
18972 and it is recommended that you stick to inline assembler.
18975 \begin_layout Subsection
18976 Use of Labels within Inline Assembler
18979 \begin_layout Standard
18980 SDCC allows the use of in-line assembler with a few restrictions regarding
18982 All labels defined within inline assembler code have to be of the form
18987 where nnnnn is a number less than 100 (which implies a limit of utmost
18988 100 inline assembler labels
18999 \begin_layout Standard
19000 This is a slightly more stringent rule than absolutely necessary, but stays
19001 always on the safe side.
19002 Labels in the form of nnnnn$ are local labels in the assembler, locality
19003 of which is confined within two labels of the standard form.
19004 The compiler uses the same form for labels within a function (but starting
19005 from nnnnn=00100); and places always a standard label at the beginning
19006 of a function, thus limiting the locality of labels within the scope of
19008 So, if the inline assembler part would be embedded into C-code, an improperly
19009 placed non-local label in the assembler would break up the reference space
19010 for labels created by the compiler for the C-code, leading to an assembling
19014 \begin_layout Standard
19015 The numeric part of local labels does not need to have 5 digits (although
19016 this is the form of labels output by the compiler), any valid integer will
19018 Please refer to the assemblers documentation for further details.
19026 \begin_layout Verse
19030 \begin_inset LatexCommand index
19036 \begin_inset LatexCommand index
19067 \begin_inset LatexCommand index
19073 \begin_inset LatexCommand index
19074 name "\\_\\_endasm"
19081 \begin_layout Standard
19082 Inline assembler code cannot reference any C-labels, however it can reference
19084 \begin_inset LatexCommand index
19089 defined by the inline assembler, e.g.:
19092 \begin_layout Verse
19115 ; some assembler code
19136 /* some more c code */
19138 clabel:\InsetSpace ~
19140 /* inline assembler cannot reference this
19145 \begin_layout Standard
19150 is translated by the compiler into a local label, so the locality of labels
19151 within the function is not broken.
19168 0003$: ;label (can be referenced by inline assembler only)
19175 \begin_inset LatexCommand index
19181 \begin_inset LatexCommand index
19182 name "\\_\\_endasm"
19192 /* some more c code */
19197 \begin_layout Standard
19198 In other words inline assembly code can access labels defined in inline
19199 assembly within the scope of the function.
19200 The same goes the other way, i.e.
19201 labels defines in inline assembly can not be accessed by C statements.
19204 \begin_layout Section
19205 Interfacing with Assembler Code
19206 \begin_inset LatexCommand index
19207 name "Assembler routines"
19214 \begin_layout Subsection
19215 Global Registers used for Parameter Passing
19216 \begin_inset LatexCommand index
19217 name "Parameter passing"
19224 \begin_layout Standard
19225 The compiler always uses the global registers
19228 \begin_inset LatexCommand index
19229 name "DPTR, DPH, DPL"
19234 \begin_inset LatexCommand index
19240 \begin_inset LatexCommand index
19241 name "B (mcs51, ds390 register)"
19250 \begin_inset LatexCommand index
19251 name "ACC (mcs51, ds390 register)"
19257 to pass the first (non-bit) parameter to a function, and also to pass the
19259 \begin_inset LatexCommand index
19260 name "return value"
19264 of function; according to the following scheme: one byte return value in
19269 , two byte value in
19278 three byte values (generic pointers) in
19290 , and four byte values in
19308 \begin_inset LatexCommand index
19309 name "generic pointer"
19313 contain type of accessed memory in
19334 \begin_inset Note Note
19337 \begin_layout Standard
19338 This might not be the case of certain memory models (medium???)
19346 \begin_layout Standard
19347 The second parameter onwards is either allocated on the stack (for reentrant
19352 \begin_layout Standard
19361 -stack-auto is used) or in data/xdata memory (depending on the memory model).
19364 \begin_layout Standard
19365 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
19366 space for reentrant functions or allocated directly in bit memory otherwise.
19369 \begin_layout Standard
19370 Functions (with two or more parameters or bit parameters) that are called
19371 through function pointers
19372 \begin_inset LatexCommand index
19373 name "function pointers"
19377 must therefor be reentrant so the compiler knows how to pass the parameters.
19380 \begin_layout Subsection
19384 \begin_layout Standard
19385 Unless the called function is declared as
19390 \begin_inset LatexCommand index
19399 \begin_layout Standard
19409 \begin_inset LatexCommand index
19410 name "-\\/-callee-saves"
19418 \begin_layout Standard
19427 -all-callee-saves command line option or the corresponding callee_saves
19428 pragma are used, the caller will save the registers (
19432 ) around the call, so the called function can destroy they content freely.
19435 \begin_layout Standard
19436 If the called function is not declared as
19440 , the caller will swap register banks around the call, if caller and callee
19441 use different register banks (having them defined by the
19449 \begin_layout Standard
19450 The called function can also use
19466 observing that they are used for parameter/return value passing.
19469 \begin_layout Subsection
19470 Assembler Routine (non-reentrant)
19473 \begin_layout Standard
19474 In the following example
19475 \begin_inset LatexCommand index
19481 \begin_inset LatexCommand index
19482 name "Assembler routines (non-reentrant)"
19486 the function c_func calls an assembler routine asm_func, which takes two
19488 \begin_inset LatexCommand index
19489 name "function parameter"
19496 \begin_layout Verse
19499 extern int asm_func(unsigned char, unsigned char);
19503 int c_func (unsigned char
19504 i, unsigned char j)
19512 return asm_func(i,j);
19526 return c_func(10,9);
19531 \begin_layout Standard
19532 The corresponding assembler function is:
19535 \begin_layout Verse
19538 .globl _asm_func_PARM_2
19640 \begin_inset LatexCommand index
19641 name "DPTR, DPH, DPL"
19658 \begin_layout Standard
19659 The parameter naming convention is _<function_name>_PARM_<n>, where n is
19660 the parameter number starting from 1, and counting from the left.
19661 The first parameter is passed in
19677 according to the description above.
19678 The variable name for the second parameter will be _<function_name>_PARM_2.
19683 ble the assembler routine with the following command:
19690 asx8051 -losg asmfunc.asm
19697 Then compile and link the assembler routine to the C source file with the
19705 sdcc cfunc.c asmfunc.rel
19708 \begin_layout Subsection
19709 Assembler Routine (reentrant)
19712 \begin_layout Standard
19714 \begin_inset LatexCommand index
19720 \begin_inset LatexCommand index
19721 name "Assembler routines (reentrant)"
19725 the second parameter
19726 \begin_inset LatexCommand index
19727 name "function parameter"
19731 onwards will be passed on the stack, the parameters are pushed from right
19733 before the call the second leftmost parameter will be on the top of the
19734 stack (the leftmost parameter is passed in registers).
19735 Here is an example:
19738 \begin_layout Verse
19741 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
19746 c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
19755 return asm_func(i,j,k);
19769 return c_func(10,9,8);
19774 \begin_layout Standard
19775 The corresponding (unoptimized) assembler routine is:
19778 \begin_layout Verse
19798 _bp,sp\InsetSpace ~
19804 ;stack contains: _bp, return
19805 address, second parameter, third parameter
19829 a,#0xfd\InsetSpace ~
19835 pointer to the second parameter
19859 a,#0xfc\InsetSpace ~
19865 to the rightmost parameter
19906 result (= sum of all three parameters)
19921 ;return value goes into dptr
19955 \begin_layout Standard
19956 The compiling and linking procedure remains the same, however note the extra
19957 entry & exit linkage required for the assembler code, _bp is the stack
19958 frame pointer and is used to compute the offset into the stack for parameters
19959 and local variables.
19960 \begin_inset VSpace bigskip
19966 \begin_layout Section
19968 \begin_inset LatexCommand index
19969 name "int (16 bit)"
19974 \begin_inset LatexCommand index
19975 name "long (32 bit)"
19982 \begin_layout Standard
19983 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
19984 multiplication and modulus operations are implemented by support routines.
19985 These support routines are all developed in ANSI-C to facilitate porting
19986 to other MCUs, although some model specific assembler optimizations are
19988 The following files contain the described routines, all of them can be
19989 found in <installdir>/share/sdcc/lib.
19994 \begin_layout Standard
19996 \begin_inset Tabular
19997 <lyxtabular version="3" rows="11" columns="2">
19999 <column alignment="left" valignment="top" leftline="true" width="0">
20000 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
20001 <row topline="true" bottomline="true">
20002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20005 \begin_layout Standard
20013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20016 \begin_layout Standard
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 16 bit multiplication
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 signed 16 bit division (calls _divuint)
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 unsigned 16 bit division
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 signed 16 bit modulus (calls _moduint)
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 unsigned 16 bit modulus
20125 <row topline="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 32 bit multiplication
20145 <row topline="true">
20146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20149 \begin_layout Standard
20155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20158 \begin_layout Standard
20159 signed 32 division (calls _divulong)
20165 <row topline="true">
20166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20169 \begin_layout Standard
20175 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20178 \begin_layout Standard
20179 unsigned 32 division
20185 <row topline="true">
20186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20189 \begin_layout Standard
20195 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20198 \begin_layout Standard
20199 signed 32 bit modulus (calls _modulong)
20205 <row topline="true" bottomline="true">
20206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20209 \begin_layout Standard
20215 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20218 \begin_layout Standard
20219 unsigned 32 bit modulus
20234 \begin_layout Standard
20235 Since they are compiled as
20240 \begin_inset LatexCommand index
20246 \begin_inset LatexCommand index
20251 service routines should not do any of the above operations.
20252 If this is unavoidable then the above routines will need to be compiled
20259 \begin_layout Standard
20269 \begin_inset LatexCommand index
20270 name "-\\/-stack-auto"
20276 option, after which the source program will have to be compiled with
20282 \begin_layout Standard
20292 \begin_inset LatexCommand index
20293 name "-\\/-int-long-reent"
20300 Notice that you don't have to call these routines directly.
20301 The compiler will use them automatically every time an integer operation
20305 \begin_layout Section
20306 Floating Point Support
20307 \begin_inset LatexCommand index
20308 name "Floating point support"
20315 \begin_layout Standard
20316 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
20317 The floating point support routines are derived from gcc's floatlib.c and
20318 consist of the following routines:
20323 \begin_layout Standard
20327 \begin_inset Tabular
20328 <lyxtabular version="3" rows="17" columns="2">
20330 <column alignment="left" valignment="top" leftline="true" width="0">
20331 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
20332 <row topline="true" bottomline="true">
20333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20336 \begin_layout Standard
20351 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20354 \begin_layout Standard
20361 <row topline="true">
20362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20365 \begin_layout Standard
20380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20383 \begin_layout Standard
20393 add floating point numbers
20399 <row topline="true">
20400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20403 \begin_layout Standard
20418 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20421 \begin_layout Standard
20431 subtract floating point numbers
20437 <row topline="true">
20438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20441 \begin_layout Standard
20456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20459 \begin_layout Standard
20469 divide floating point numbers
20475 <row topline="true">
20476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20479 \begin_layout Standard
20494 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20497 \begin_layout Standard
20507 multiply floating point numbers
20513 <row topline="true">
20514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20517 \begin_layout Standard
20532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20535 \begin_layout Standard
20545 convert floating point to unsigned char
20551 <row topline="true">
20552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20555 \begin_layout Standard
20570 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20573 \begin_layout Standard
20583 convert floating point to signed char
20589 <row topline="true">
20590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20593 \begin_layout Standard
20608 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20611 \begin_layout Standard
20621 convert floating point to unsigned int
20627 <row topline="true">
20628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20631 \begin_layout Standard
20646 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20649 \begin_layout Standard
20659 convert floating point to signed int
20665 <row topline="true">
20666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20669 \begin_layout Standard
20692 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20695 \begin_layout Standard
20705 convert floating point to unsigned long
20711 <row topline="true">
20712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20715 \begin_layout Standard
20730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20733 \begin_layout Standard
20743 convert floating point to signed long
20749 <row topline="true">
20750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20753 \begin_layout Standard
20768 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20771 \begin_layout Standard
20781 convert unsigned char to floating point
20787 <row topline="true">
20788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20791 \begin_layout Standard
20806 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20809 \begin_layout Standard
20819 convert char to floating point number
20825 <row topline="true">
20826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20829 \begin_layout Standard
20844 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20847 \begin_layout Standard
20857 convert unsigned int to floating point
20863 <row topline="true">
20864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20867 \begin_layout Standard
20882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20885 \begin_layout Standard
20895 convert int to floating point numbers
20901 <row topline="true">
20902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20905 \begin_layout Standard
20920 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20923 \begin_layout Standard
20933 convert unsigned long to floating point number
20939 <row topline="true" bottomline="true">
20940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20943 \begin_layout Standard
20958 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20961 \begin_layout Standard
20971 convert long to floating point number
20986 \begin_layout Standard
20987 These support routines are developed in ANSI-C so there is room for space
20988 and speed improvement
20992 \begin_layout Standard
20993 These floating point routines (
20997 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
21004 Note if all these routines are used simultaneously the data space might
21006 For serious floating point usage the large model might be needed.
21007 Also notice that you don't have to call this routines directly.
21008 The compiler will use them automatically every time a floating point operation
21010 \begin_inset VSpace bigskip
21016 \begin_layout Section
21018 \begin_inset LatexCommand index
21026 \begin_layout Standard
21029 <pending: this is messy and incomplete - a little more information is in
21030 sdcc/doc/libdoc.txt
21035 \begin_layout Subsection
21036 Compiler support routines (_gptrget, _mulint etc.)
21039 \begin_layout Subsection
21040 Stdclib functions (puts, printf, strcat etc.)
21043 \begin_layout Subsubsection
21047 \begin_layout Paragraph
21048 getchar(), putchar()
21051 \begin_layout Standard
21052 \begin_inset LatexCommand index
21057 As usual on embedded systems you have to provide your own
21060 \begin_inset LatexCommand index
21070 \begin_inset LatexCommand index
21078 SDCC does not know whether the system connects to a serial line with or
21079 without handshake, LCD, keyboard or other device.
21093 You'll find examples for serial routines f.e.
21094 in sdcc/device/lib.
21095 For the mcs51 this minimalistic polling
21099 routine might be a start:
21102 \begin_layout Verse
21105 void putchar (char c) {
21111 while (!TI)\InsetSpace ~
21114 /* assumes UART is initialized */
21142 \begin_layout Paragraph
21146 \begin_layout Standard
21150 \begin_inset LatexCommand index
21161 does not support float
21162 \begin_inset LatexCommand index
21163 name "Floating point support"
21167 (except on ds390), only <NO FLOAT>
21168 \begin_inset LatexCommand index
21174 \begin_inset LatexCommand index
21175 name "printf floating point support"
21179 will be printed instead of the value.
21180 To enable floating point output, recompile it with the option
21186 \begin_layout Standard
21196 \begin_inset LatexCommand index
21197 name "USE\\_FLOATS"
21203 on the command line.
21210 \begin_layout Standard
21220 \begin_inset LatexCommand index
21221 name "-\\/-model-large"
21227 for the mcs51 port, since this uses a lot of memory.
21228 To enable float support for the pic16 targets, see
21229 \begin_inset LatexCommand ref
21230 reference "sub:pic16Libraries"
21237 \begin_layout Standard
21238 If you're short on code memory you might want to use
21241 \begin_inset LatexCommand index
21242 name "printf\\_small()"
21257 For the mcs51 there additionally are assembly versions
21260 \begin_inset LatexCommand index
21261 name "printf\\_tiny() (mcs51)"
21267 (subset of printf using less than 270 bytes) and
21270 \begin_inset LatexCommand index
21271 name "printf\\_fast() (mcs51)"
21280 \begin_inset LatexCommand index
21281 name "printf\\_fast\\_f() (mcs51)"
21287 (floating-point aware version of printf_fast) which should fit the requirements
21288 of many embedded systems (printf_fast() can be customized by unsetting
21293 support long variables and field widths).
21294 Be sure to use only one of these printf options within a project.
21299 \begin_layout Standard
21300 Feature matrix of different
21307 \begin_layout Standard
21308 \begin_inset Tabular
21309 <lyxtabular version="3" rows="14" columns="7">
21310 <features islongtable="true">
21311 <column alignment="left" valignment="middle" leftline="true" width="14col%">
21312 <column alignment="center" valignment="top" leftline="true" width="0">
21313 <column alignment="center" valignment="top" leftline="true" width="12col%">
21314 <column alignment="center" valignment="top" leftline="true" width="10col%">
21315 <column alignment="center" valignment="top" leftline="true" width="0">
21316 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
21317 <column alignment="center" valignment="top" rightline="true" width="0">
21318 <row topline="true" bottomline="true" endhead="true">
21319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21322 \begin_layout Standard
21331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21334 \begin_layout Standard
21336 \begin_inset LatexCommand index
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
21366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21369 \begin_layout Standard
21375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21378 \begin_layout Standard
21384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21387 \begin_layout Standard
21394 <row topline="true" endhead="true">
21395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21398 \begin_layout Standard
21404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21407 \begin_layout Standard
21415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21418 \begin_layout Standard
21426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21429 \begin_layout Standard
21437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21440 \begin_layout Standard
21448 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21451 \begin_layout Standard
21459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21462 \begin_layout Standard
21471 <row topline="true" endhead="true">
21472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21475 \begin_layout Standard
21476 \begin_inset Quotes sld
21480 \begin_inset Quotes srd
21486 \begin_layout Standard
21492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21495 \begin_layout Standard
21501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21504 \begin_layout Standard
21510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21513 \begin_layout Standard
21519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21522 \begin_layout Standard
21528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21531 \begin_layout Standard
21537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21540 \begin_layout Standard
21547 <row topline="true" endhead="true">
21548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21551 \begin_layout Standard
21555 \begin_layout Standard
21561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21564 \begin_layout Standard
21570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21573 \begin_layout Standard
21579 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21582 \begin_layout Standard
21583 0.45k / 0.47k (+ _ltoa)
21588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21591 \begin_layout Standard
21597 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21600 \begin_layout Standard
21606 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21609 \begin_layout Standard
21616 <row topline="true">
21617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21620 \begin_layout Standard
21626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21629 \begin_layout Standard
21639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21642 \begin_layout Standard
21689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21692 \begin_layout Standard
21731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21734 \begin_layout Standard
21740 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21743 \begin_layout Standard
21749 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21752 \begin_layout Standard
21759 <row topline="true">
21760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21763 \begin_layout Standard
21764 long (32 bit) support
21769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21772 \begin_layout Standard
21778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21781 \begin_layout Standard
21787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21790 \begin_layout Standard
21796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21799 \begin_layout Standard
21805 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21808 \begin_layout Standard
21823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21826 \begin_layout Standard
21833 <row topline="true">
21834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21837 \begin_layout Standard
21838 byte arguments on stack
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" usebox="none">
21873 \begin_layout Standard
21879 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21882 \begin_layout Standard
21888 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21891 \begin_layout Standard
21898 <row topline="true">
21899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21902 \begin_layout Standard
21904 \begin_inset LatexCommand index
21905 name "Floating point support"
21914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21917 \begin_layout Standard
21923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21926 \begin_layout Standard
21932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21935 \begin_layout Standard
21941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21944 \begin_layout Standard
21950 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21953 \begin_layout Standard
21958 \begin_layout Standard
21959 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
21969 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21972 \begin_layout Standard
21979 <row topline="true">
21980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21983 \begin_layout Standard
21984 float formats %e %g
21989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21992 \begin_layout Standard
21998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22001 \begin_layout Standard
22007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22010 \begin_layout Standard
22016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22019 \begin_layout Standard
22025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22028 \begin_layout Standard
22034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22037 \begin_layout Standard
22044 <row topline="true" bottomline="true">
22045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22048 \begin_layout Standard
22054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22057 \begin_layout Standard
22063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22066 \begin_layout Standard
22072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22075 \begin_layout Standard
22081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22084 \begin_layout Standard
22090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22093 \begin_layout Standard
22099 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22102 \begin_layout Standard
22109 <row bottomline="true">
22110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22113 \begin_layout Standard
22118 \begin_layout Standard
22119 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
22123 n'); standard 8051 @ 22.1184 MHz, empty putchar()
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
22192 <row bottomline="true">
22193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22196 \begin_layout Standard
22201 \begin_layout Standard
22202 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
22211 \begin_layout Standard
22217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22220 \begin_layout Standard
22226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22229 \begin_layout Standard
22235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22238 \begin_layout Standard
22244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22247 \begin_layout Standard
22253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22256 \begin_layout Standard
22262 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22265 \begin_layout Standard
22270 \begin_layout Standard
22271 printf_tiny integer speed is data dependent, worst case is 0.33 ms
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("%ld", -123456789); 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
22362 <row bottomline="true">
22363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22366 \begin_layout Standard
22371 \begin_layout Standard
22372 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
22381 \begin_layout Standard
22387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22390 \begin_layout Standard
22396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22399 \begin_layout Standard
22405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22408 \begin_layout Standard
22414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22417 \begin_layout Standard
22423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22426 \begin_layout Standard
22432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22435 \begin_layout Standard
22449 \begin_layout Subsubsection
22451 \begin_inset LatexCommand index
22459 \begin_layout Standard
22460 As of SDCC 2.6.2 you no longer need to call an initialization routine before
22461 using dynamic memory allocation
22462 \begin_inset LatexCommand index
22463 name "dynamic memory allocation (malloc)"
22468 \begin_inset LatexCommand index
22469 name "heap (malloc)"
22473 space of 1024 bytes is provided for malloc to allocate memory from.
22474 If you need a different heap size you need to recompile _heap.c with the
22475 required size defined in HEAP_SIZE.
22476 It is recommended to make a copy of this file into your project directory
22477 and compile it there with:
22480 \begin_layout Verse
22483 sdcc -c _heap.c -D HEAD_SIZE=2048
22486 \begin_layout Standard
22487 And then link it with:
22490 \begin_layout Verse
22493 sdcc main.rel _heap.rel
22496 \begin_layout Subsection
22497 Math functions (sinf, powf, sqrtf etc.)
22500 \begin_layout Subsubsection
22504 \begin_layout Standard
22505 See definitions in file <math.h>.
22508 \begin_layout Subsection
22512 \begin_layout Standard
22514 \begin_inset LatexCommand index
22519 included in SDCC should have a license at least as liberal as the GNU Lesser
22520 General Public License
22521 \begin_inset LatexCommand index
22522 name "GNU Lesser General Public License, LGPL"
22533 \begin_layout Standard
22534 \begin_inset Note Note
22537 \begin_layout Standard
22538 license statements for the libraries are missing.
22539 sdcc/device/lib/ser_ir.c
22542 \begin_layout Standard
22544 come with a GPL (as opposed to LGPL) License - this will not be liberal
22545 enough for many embedded programmers.
22553 \begin_layout Standard
22554 If you have ported some library or want to share experience about some code
22556 falls into any of these categories Busses (I
22557 \begin_inset Formula $^{\textrm{2}}$
22560 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
22561 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
22562 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
22563 \begin_inset LatexCommand url
22564 target "http://sourceforge.net/mail/?group_id=599"
22569 would certainly like to hear about it.
22572 \begin_layout Standard
22573 Programmers coding for embedded systems are not especially famous for being
22574 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
22575 e these references are very valuable.
22576 Let's help to create a climate where information is shared.
22577 \begin_inset VSpace bigskip
22583 \begin_layout Section
22587 \begin_layout Subsection
22588 MCS51 Memory Models
22589 \begin_inset LatexCommand index
22590 name "Memory model"
22595 \begin_inset LatexCommand index
22596 name "MCS51 memory model"
22603 \begin_layout Subsubsection
22604 Small, Medium and Large
22607 \begin_layout Standard
22608 SDCC allows three memory models for MCS51 code,
22617 Modules compiled with different memory models should
22621 be combined together or the results would be unpredictable.
22622 The library routines supplied with the compiler are compiled as small,
22624 The compiled library modules are contained in separate directories as small,
22625 medium and large so that you can link to the appropriate set.
22628 \begin_layout Standard
22629 When the medium or large model is used all variables declared without a
22630 storage class will be allocated into the external ram, this includes all
22631 parameters and local variables (for non-reentrant
22632 \begin_inset LatexCommand index
22638 When the small model is used variables without storage class are allocated
22639 in the internal ram.
22642 \begin_layout Standard
22643 Judicious usage of the processor specific storage classes
22644 \begin_inset LatexCommand index
22645 name "Storage class"
22649 and the 'reentrant' function type will yield much more efficient code,
22650 than using the large model.
22651 Several optimizations are disabled when the program is compiled using the
22652 large model, it is therefore recommended that the small model be used unless
22653 absolutely required.
22656 \begin_layout Subsubsection
22658 \begin_inset LatexCommand label
22659 name "sub:External-Stack"
22664 \begin_inset LatexCommand index
22670 \begin_inset LatexCommand index
22671 name "External stack (mcs51)"
22678 \begin_layout Standard
22679 The external stack (-
22683 \begin_layout Standard
22693 \begin_inset LatexCommand index
22698 ) is located in pdata
22699 \begin_inset LatexCommand index
22700 name "pdata (mcs51, ds390 storage class)"
22704 memory (usually at the start of the external ram segment) and uses all
22705 unused space in pdata (max.
22711 \begin_layout Standard
22720 -xstack option is used to compile the program, the parameters and local
22722 \begin_inset LatexCommand index
22723 name "local variables"
22727 of all reentrant functions are allocated in this area.
22728 This option is provided for programs with large stack space requirements.
22729 When used with the -
22733 \begin_layout Standard
22743 \begin_inset LatexCommand index
22744 name "-\\/-stack-auto"
22748 option, all parameters and local variables are allocated on the external
22749 stack (note: support libraries will need to be recompiled with the same
22751 There is a predefined target in the library makefile).
22754 \begin_layout Standard
22755 The compiler outputs the higher order address byte of the external ram segment
22757 \begin_inset LatexCommand index
22758 name "P2 (mcs51 sfr)"
22763 \begin_inset LatexCommand ref
22764 reference "sub:MCS51-variants"
22768 ), therefore when using the External Stack option, this port
22772 be used by the application program.
22775 \begin_layout Subsection
22777 \begin_inset LatexCommand index
22778 name "Memory model"
22783 \begin_inset LatexCommand index
22784 name "DS390 memory model"
22791 \begin_layout Standard
22792 The only model supported is Flat 24
22793 \begin_inset LatexCommand index
22794 name "Flat 24 (DS390 memory model)"
22799 This generates code for the 24 bit contiguous addressing mode of the Dallas
22801 In this mode, up to four meg of external RAM or code space can be directly
22803 See the data sheets at www.dalsemi.com for further information on this part.
22808 that the compiler does not generate any code to place the processor into
22809 24 bitmode (although
22813 in the ds390 libraries will do that for you).
22819 \begin_inset LatexCommand index
22820 name "Tinibios (DS390)"
22824 , the boot loader or similar code must ensure that the processor is in 24
22825 bit contiguous addressing mode before calling the SDCC startup code.
22836 \begin_layout Standard
22847 option, variables will by default be placed into the XDATA segment.
22852 Segments may be placed anywhere in the 4 meg address space using the usual
22857 \begin_layout Standard
22867 Note that if any segments are located above 64K, the -r flag must be passed
22868 to the linker to generate the proper segment relocations, and the Intel
22869 HEX output format must be used.
22870 The -r flag can be passed to the linker by using the option
22874 on the SDCC command line.
22875 However, currently the linker can not handle code segments > 64k.
22878 \begin_layout Section
22880 \begin_inset LatexCommand label
22886 \begin_inset LatexCommand index
22894 \begin_layout Standard
22895 Pragmas are used to turn on and/or off certain compiler options.
22896 Some of them are closely related to corresponding command-line options
22898 \begin_inset LatexCommand vref
22899 reference "sec:Command-Line-Options"
22905 Pragmas should be placed before and/or after a function, placing pragmas
22906 inside a function body could have unpredictable results.
22911 following #pragma directives:
22914 \begin_layout Itemize
22920 \begin_inset LatexCommand index
22921 name "\\#pragma save"
22925 - this will save most current options to the save/restore stack.
22926 See #pragma\InsetSpace ~
22930 \begin_layout Itemize
22936 \begin_inset LatexCommand index
22937 name "\\#pragma restore"
22941 - will restore saved options from the last save.
22942 saves & restores can be nested.
22943 SDCC uses a save/restore stack: save pushes current options to the stack,
22944 restore pulls current options from the stack.
22945 See #pragma\InsetSpace ~
22951 \begin_layout Itemize
22957 \begin_inset LatexCommand index
22958 name "\\#pragma callee\\_saves"
22963 \begin_inset LatexCommand index
22964 name "function prologue"
22968 function1[,function2[,function3...]]
22969 \begin_inset LatexCommand label
22970 name "ite:callee_saves-function1[,function2[,function3...]]--"
22974 - The compiler by default uses a caller saves convention for register saving
22975 across function calls, however this can cause unnecessary register pushing
22977 \begin_inset LatexCommand index
22982 when calling small functions from larger functions.
22983 This option can be used to switch off the register saving convention for
22984 the function names specified.
22985 The compiler will not save registers when calling these functions, extra
22986 code need to be manually inserted at the entry and exit for these functions
22987 to save and restore the registers used by these functions, this can SUBSTANTIAL
22988 LY reduce code and improve run time performance of the generated code.
22989 In the future the compiler (with inter procedural analysis) may be able
22990 to determine the appropriate scheme to use for each function call.
22995 \begin_layout Standard
23004 -callee-saves command line option is used (see page
23005 \begin_inset LatexCommand vpageref
23006 reference "lyx:--callee-saves-function1[,function2][,function3]..."
23010 ), the function names specified in #pragma\InsetSpace ~
23012 \begin_inset LatexCommand index
23013 name "\\#pragma callee\\_saves"
23017 is appended to the list of functions specified in the command line.
23020 \begin_layout Itemize
23026 \begin_inset LatexCommand index
23027 name "\\#pragma exclude"
23031 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
23032 of pairs of push/pop
23033 \begin_inset LatexCommand index
23043 \begin_inset LatexCommand index
23057 The directive should be placed immediately before the ISR function definition
23058 and it affects ALL ISR functions following it.
23059 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
23060 exclude\InsetSpace ~
23062 \begin_inset LatexCommand index
23063 name "\\#pragma exclude"
23068 See also the related keyword _naked
23069 \begin_inset LatexCommand index
23075 \begin_inset LatexCommand index
23083 \begin_layout Itemize
23089 \begin_inset LatexCommand index
23095 \begin_inset LatexCommand index
23096 name "\\#pragma less\\_pedantic"
23101 \begin_inset LatexCommand label
23102 name "ite:less_pedantic"
23106 - the compiler will not warn you anymore for obvious mistakes, you're on
23108 See also the command line option -
23112 \begin_layout Standard
23122 \begin_inset LatexCommand vpageref
23123 reference "lyx:--less-pedantic"
23130 More specifically, the following warnings will be disabled:
23132 comparison is always [true/false] due to limited range of data type
23136 overflow in implicit constant conversion
23138 (158); [the (in)famous]
23140 conditional flow changed by optimizer: so said EVELYN the modified DOG
23144 function '[function name]' must return value
23149 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
23150 level) are disabled, too, namely:
23153 \begin_inset Note Note
23156 \begin_layout Standard
23157 dunno what comes here - this warning appears to be unused altogether
23166 [left/right] shifting more than size of object changed to zero
23174 integer overflow in expression
23178 unmatched #pragma save and #pragma restore
23182 comparison of 'signed char' with 'unsigned char' requires promotion to int
23186 ISO C90 does not support flexible array members
23190 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
23194 \begin_inset Note Note
23197 \begin_layout Standard
23198 appears to be always blank - what was supposed to be here?
23207 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
23208 complexity [number]
23213 \begin_layout Itemize
23219 \begin_inset LatexCommand index
23220 name "\\#pragma disable\\_warning"
23224 - the compiler will not warn you anymore about warning number <nnnn>.
23227 \begin_layout Itemize
23233 \begin_inset LatexCommand index
23234 name "\\#pragma nogcse"
23238 - will stop global common subexpression elimination.
23241 \begin_layout Itemize
23247 \begin_inset LatexCommand index
23248 name "\\#pragma noinduction"
23252 - will stop loop induction optimizations.
23255 \begin_layout Itemize
23261 \begin_inset LatexCommand index
23262 name "\\#pragma noinvariant"
23266 - will not do loop invariant optimizations.
23267 For more details see Loop Invariants in section
23268 \begin_inset LatexCommand ref
23269 reference "sub:Loop-Optimizations"
23276 \begin_layout Itemize
23282 \begin_inset LatexCommand index
23283 name "\\#pragma noiv"
23287 - Do not generate interrupt
23288 \begin_inset LatexCommand index
23294 \begin_inset LatexCommand index
23295 name "interrupt vector table"
23299 entries for all ISR functions defined after the pragma.
23300 This is useful in cases where the interrupt vector table must be defined
23301 manually, or when there is a secondary, manually defined interrupt vector
23303 for the autovector feature of the Cypress EZ-USB FX2).
23304 More elegantly this can be achieved by omitting the optional interrupt
23305 number after the interrupt keyword, see section
23306 \begin_inset LatexCommand ref
23307 reference "sub:Interrupt-Service-Routines"
23315 \begin_layout Itemize
23321 \begin_inset LatexCommand index
23322 name "\\#pragma nojtbound"
23326 - will not generate code for boundary value checking, when switch statements
23327 are turned into jump-tables (dangerous).
23328 For more details see section
23329 \begin_inset LatexCommand ref
23330 reference "sub:'switch'-Statements"
23337 \begin_layout Itemize
23343 \begin_inset LatexCommand index
23344 name "\\#pragma noloopreverse"
23348 - Will not do loop reversal optimization
23351 \begin_layout Itemize
23357 \begin_inset LatexCommand index
23358 name "\\#pragma nooverlay"
23362 - the compiler will not overlay the parameters and local variables of a
23366 \begin_layout Itemize
23372 \begin_inset LatexCommand index
23373 name "\\#pragma stackauto"
23381 \begin_layout Standard
23391 \begin_inset LatexCommand index
23392 name "-\\/-stack-auto"
23397 \begin_inset LatexCommand ref
23398 reference "sec:Parameters-and-Local-Variables"
23402 Parameters and Local Variables.
23405 \begin_layout Itemize
23411 \begin_inset LatexCommand index
23412 name "\\#pragma opt\\_code\\_speed"
23416 - The compiler will optimize code generation towards fast code, possibly
23417 at the expense of code size.
23418 Currently this has little effect.
23421 \begin_layout Itemize
23427 \begin_inset LatexCommand index
23428 name "\\#pragma opt\\_code\\_size"
23432 - The compiler will optimize code generation towards compact code, possibly
23433 at the expense of code speed.
23434 Currently this has little effect.
23437 \begin_layout Itemize
23443 \begin_inset LatexCommand index
23444 name "\\#pragma opt\\_code\\_balanced"
23448 - The compiler will attempt to generate code that is both compact and fast,
23449 as long as meeting one goal is not a detriment to the other (this is the
23454 \begin_layout Itemize
23460 \begin_inset LatexCommand index
23461 name "\\#pragma std\\_sdcc89"
23465 - Generally follow the C89 standard, but allow SDCC features that conflict
23466 with the standard (default).
23469 \begin_layout Itemize
23475 \begin_inset LatexCommand index
23476 name "\\#pragma std\\_c89"
23480 - Follow the C89 standard and disable SDCC features that conflict with the
23484 \begin_layout Itemize
23490 \begin_inset LatexCommand index
23491 name "\\#pragma std\\_sdcc99"
23495 - Generally follow the C99 standard, but allow SDCC features that conflict
23496 with the standard (incomplete support).
23499 \begin_layout Itemize
23505 \begin_inset LatexCommand index
23506 name "\\#pragma std\\_c99"
23510 - Follow the C99 standard and disable SDCC features that conflict with the
23511 standard (incomplete support).
23514 \begin_layout Itemize
23520 \begin_inset LatexCommand index
23521 name "\\#pragma codeseg"
23525 - Use this name (max.
23526 8 characters) for the code segment.
23531 \begin_layout Standard
23543 \begin_layout Itemize
23549 \begin_inset LatexCommand index
23550 name "\\#pragma constseg"
23554 - Use this name (max.
23555 8 characters) for the const segment.
23560 \begin_layout Standard
23572 \begin_layout Standard
23573 The preprocessor SDCPP
23574 \begin_inset LatexCommand index
23575 name "sdcpp (preprocessor)"
23579 supports the following #pragma directives:
23582 \begin_layout Itemize
23585 pedantic_parse_number
23588 \begin_inset LatexCommand index
23594 \begin_inset LatexCommand index
23595 name "\\#pragma pedantic\\_parse\\_number"
23600 \begin_inset LatexCommand label
23601 name "ite:pedantic_parse_number"
23605 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
23606 properly and the macro LO_B(3) gets expanded.
23612 \begin_layout Standard
23621 -pedantic-parse-number command line option
23622 \begin_inset LatexCommand vpageref
23623 reference "lyx:-pedantic-parse-number"
23630 Below is an example on how to use this pragma.
23633 Note: this functionality is not in conformance with standard!
23636 \begin_layout Verse
23639 #pragma pedantic_parse_number +
23640 \begin_inset LatexCommand index
23641 name "\\#pragma pedantic\\_parse\\_number"
23649 #define LO_B(x) ((x) & 0xff)
23653 unsigned char foo(void)
23660 unsigned char c=0xfe-LO_B(3)
23675 \begin_layout Itemize
23681 \begin_inset LatexCommand index
23682 name "\\#pragma preproc\\_asm"
23686 (+ | -) - switch _asm _endasm block preprocessing on / off.
23688 You use this pragma to define multilines of assembly code.
23689 This will prevent the preprocessor from changing the formatting required
23691 Below is an example on how to use this pragma.
23694 \begin_layout Verse
23697 #pragma preproc_asm -
23698 \begin_inset LatexCommand index
23699 name "\\#pragma preproc\\_asm"
23705 #define MYDELAY _asm
23710 nop ;my assembly comment...
23724 #pragma preproc_asm
23755 \begin_layout Itemize
23761 \begin_inset LatexCommand index
23762 name "\\#pragma sdcc\\_hash"
23766 (+ | -) - Allow "naked" hash in macro definition, for example:
23770 #define DIR_LO(x) #(x & 0xff)
23775 Below is an example on how to use this pragma.
23778 \begin_layout Verse
23781 #pragma preproc_asm +
23783 #pragma sdcc_hash +
23784 \begin_inset LatexCommand index
23785 name "\\#pragma sdcc\\_hash"
23800 mov R6_B3, #(x & 0xff)
23807 mov R7_B3, #((x >> 8) & 0xff)
23831 \begin_layout Standard
23832 Some of the pragmas are intended to be used to turn-on or off certain optimizati
23833 ons which might cause the compiler to generate extra stack and/or data space
23834 to store compiler generated temporary variables.
23835 This usually happens in large functions.
23836 Pragma directives should be used as shown in the following example, they
23837 are used to control options and optimizations for a given function.
23841 \begin_layout Verse
23845 \begin_inset LatexCommand index
23846 name "\\#pragma save"
23857 /* save the current settings */
23860 \begin_inset LatexCommand index
23861 name "\\#pragma nogcse"
23870 /* turnoff global subexpression elimination */
23872 #pragma noinduction
23873 \begin_inset LatexCommand index
23874 name "\\#pragma noinduction"
23878 /* turn off induction optimizations */
23901 \begin_inset LatexCommand index
23902 name "\\#pragma restore"
23906 /* turn the optimizations back on */
23909 \begin_layout Standard
23910 The compiler will generate a warning message when extra space is allocated.
23911 It is strongly recommended that the save and restore pragmas be used when
23912 changing options for a function.
23921 \begin_layout Section
23922 Defines Created by the Compiler
23925 \begin_layout Standard
23926 The compiler creates the following #defines
23927 \begin_inset LatexCommand index
23933 \begin_inset LatexCommand index
23934 name "Defines created by the compiler"
23943 \begin_layout Standard
23944 \begin_inset Tabular
23945 <lyxtabular version="3" rows="15" columns="2">
23947 <column alignment="left" valignment="top" leftline="true" width="3in">
23948 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
23949 <row topline="true" bottomline="true">
23950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23953 \begin_layout Standard
23961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23964 \begin_layout Standard
23973 <row topline="true">
23974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23977 \begin_layout Standard
23979 \begin_inset LatexCommand index
23989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23992 \begin_layout Standard
23994 Since version 2.5.6 the version number as an int (ex.
24001 <row topline="true">
24002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24005 \begin_layout Standard
24007 \begin_inset LatexCommand index
24008 name "SDCC\\_mcs51"
24013 \begin_inset LatexCommand index
24014 name "SDCC\\_ds390"
24019 \begin_inset LatexCommand index
24029 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24032 \begin_layout Standard
24033 depending on the model used (e.g.: -mds390)
24039 <row topline="true">
24040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24043 \begin_layout Standard
24045 \begin_inset LatexCommand index
24051 \begin_inset LatexCommand index
24057 \begin_inset LatexCommand index
24063 \begin_inset LatexCommand index
24073 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24076 \begin_layout Standard
24077 depending on the model used (e.g.
24084 <row topline="true">
24085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24088 \begin_layout Standard
24090 \begin_inset LatexCommand index
24091 name "SDCC\\_STACK\\_AUTO"
24100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24103 \begin_layout Standard
24110 \begin_layout Standard
24127 <row topline="true">
24128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24131 \begin_layout Standard
24133 \begin_inset LatexCommand index
24134 name "SDCC\\_MODEL\\_SMALL"
24143 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24146 \begin_layout Standard
24153 \begin_layout Standard
24170 <row topline="true">
24171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24174 \begin_layout Standard
24176 \begin_inset LatexCommand index
24177 name "SDCC\\_MODEL\\_MEDIUM"
24186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24189 \begin_layout Standard
24196 \begin_layout Standard
24213 <row topline="true">
24214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24217 \begin_layout Standard
24219 \begin_inset LatexCommand index
24220 name "SDCC\\_MODEL\\_LARGE"
24229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24232 \begin_layout Standard
24239 \begin_layout Standard
24256 <row topline="true">
24257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24260 \begin_layout Standard
24262 \begin_inset LatexCommand index
24263 name "SDCC\\_USE\\_XSTACK"
24272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24275 \begin_layout Standard
24282 \begin_layout Standard
24299 <row topline="true">
24300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24303 \begin_layout Standard
24305 \begin_inset LatexCommand index
24306 name "SDCC\\_STACK\\_TENBIT"
24315 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24318 \begin_layout Standard
24329 <row topline="true">
24330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24333 \begin_layout Standard
24335 \begin_inset LatexCommand index
24336 name "SDCC\\_MODEL\\_FLAT24"
24345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24348 \begin_layout Standard
24359 <row topline="true">
24360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24363 \begin_layout Standard
24365 \begin_inset LatexCommand index
24366 name "SDCC\\_REVISION"
24375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24378 \begin_layout Standard
24380 SDCC svn revision number
24386 <row topline="true">
24387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24390 \begin_layout Standard
24391 SDCC_PARMS_IN_BANK1
24392 \begin_inset LatexCommand index
24393 name "SDCC\\_PARMS\\_IN\\_BANK1"
24402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24405 \begin_layout Standard
24412 \begin_layout Standard
24429 <row topline="true">
24430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24433 \begin_layout Standard
24435 \begin_inset LatexCommand index
24436 name "SDCC\\_MODEL\\_FLAT24"
24445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24448 \begin_layout Standard
24455 \begin_layout Standard
24472 <row topline="true" bottomline="true">
24473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24476 \begin_layout Standard
24477 SDCC_INT_LONG_REENT
24478 \begin_inset LatexCommand index
24479 name "SDCC\\_INT\\_LONG\\_REENT"
24488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24491 \begin_layout Standard
24498 \begin_layout Standard
24522 \begin_layout Chapter
24523 Notes on supported Processors
24526 \begin_layout Section
24528 \begin_inset LatexCommand label
24529 name "sub:MCS51-variants"
24534 \begin_inset LatexCommand index
24535 name "MCS51 variants"
24542 \begin_layout Standard
24543 MCS51 processors are available from many vendors and come in many different
24545 While they might differ considerably in respect to Special Function Registers
24546 the core MCS51 is usually not modified or is kept compatible.
24550 \begin_layout Subsection
24551 pdata access by SFR
24554 \begin_layout Standard
24555 With the upcome of devices with internal xdata and flash memory devices
24557 \begin_inset LatexCommand index
24558 name "P2 (mcs51 sfr)"
24562 as dedicated I/O port is becoming more popular.
24563 Switching the high byte for pdata
24564 \begin_inset LatexCommand index
24565 name "pdata (mcs51, ds390 storage class)"
24569 access which was formerly done by port P2 is then achieved by a Special
24571 \begin_inset LatexCommand index
24577 In well-established MCS51 tradition the address of this
24581 is where the chip designers decided to put it.
24582 Needless to say that they didn't agree on a common name either.
24583 So that the startup code can correctly initialize xdata variables, you
24584 should define an sfr with the name _XPAGE
24587 \begin_inset LatexCommand index
24588 name "\\_XPAGE (mcs51)"
24594 at the appropriate location if the default, port P2, is not used for this.
24598 \begin_layout Verse
24601 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
24605 \begin_layout Verse
24608 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
24613 \begin_layout Verse
24616 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
24620 \begin_layout Verse
24623 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
24627 \begin_layout Verse
24630 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
24634 \begin_layout Standard
24635 For more exotic implementations further customizations may be needed.
24637 \begin_inset LatexCommand ref
24638 reference "sub:Startup-Code"
24642 for other possibilities.
24645 \begin_layout Subsection
24646 Other Features available by SFR
24649 \begin_layout Standard
24650 Some MCS51 variants offer features like Double DPTR
24651 \begin_inset LatexCommand index
24656 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
24657 These are currently not used for the MCS51 port.
24658 If you absolutely need them you can fall back to inline assembly or submit
24662 \begin_layout Subsection
24666 \begin_layout Standard
24668 \begin_inset LatexCommand index
24669 name "Bankswitching"
24675 \begin_inset LatexCommand index
24676 name "code banking"
24680 ) is a technique to increase the code space above the 64k limit of the 8051.
24683 \begin_layout Subsubsection
24687 \begin_layout Standard
24688 \begin_inset Tabular
24689 <lyxtabular version="3" rows="3" columns="4">
24691 <column alignment="center" valignment="top" width="0">
24692 <column alignment="center" valignment="top" leftline="true" width="0">
24693 <column alignment="center" valignment="top" leftline="true" width="0">
24694 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24695 <row topline="true" bottomline="true">
24696 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24699 \begin_layout Standard
24705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24708 \begin_layout Standard
24714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24717 \begin_layout Standard
24723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24726 \begin_layout Standard
24733 <row topline="true" bottomline="true">
24734 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24737 \begin_layout Standard
24743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24746 \begin_layout Standard
24752 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24755 \begin_layout Standard
24761 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24764 \begin_layout Standard
24772 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24775 \begin_layout Standard
24776 SiLabs C8051F120 example
24781 <cell multicolumn="2" alignment="center" valignment="top" usebox="none">
24784 \begin_layout Standard
24790 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24793 \begin_layout Standard
24799 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24802 \begin_layout Standard
24817 Usually the hardware uses some sfr (an output port or an internal sfr) to
24818 select a bank and put it in the banked area of the memory map.
24819 The selected bank usually becomes active immediately upon assignment to
24820 this sfr and when running inside a bank it will switch out this code it
24821 is currently running.
24822 Therefor you cannot jump or call directly from one bank to another and
24823 need to use a so-called trampoline in the common area.
24824 For SDCC an example trampoline is in crtbank.asm and you may need to change
24825 it to your 8051 derivative or schematic.
24826 The presented code is written for the C8051F120.
24830 When calling a banked function
24831 SDCC will put the LSB of the functions address in register R0, the MSB
24832 in R1 and the bank in R2 and then call this trampoline
24837 The current selected bank is saved on the stack, the new bank is selected
24838 and an indirect jump is made.
24839 When the banked function returns it jumps to
24843 which restores the previous bank and returns to the caller.
24846 \begin_layout Subsubsection
24850 \begin_layout Standard
24851 When writing banked software using SDCC you need to use some special keywords
24853 You also need to take over a bit of work from the linker.
24857 To create a function
24858 that can be called from another bank it requires the keyword
24863 \begin_inset LatexCommand index
24869 The caller must see this in the prototype of the callee and the callee
24870 needs it for a proper return.
24871 Called functions within the same bank as the caller do not need the
24875 keyword nor do functions in the common area.
24876 Beware: SDCC does not know or check if functions are in the same bank.
24877 This is your responsibility!
24881 Normally all functions you write end up in
24883 If you want a function explicitly to reside in the common area put it in
24885 This applies for instance to interrupt service routines as they should
24889 \begin_layout Standard
24890 Functions that need to be in a switched bank must be put in a named segment.
24891 The name can be mostly anything up to eight characters (e.g.
24893 To do this you either use -
24897 \begin_layout Standard
24906 -codeseg BANK1 (See
24907 \begin_inset LatexCommand ref
24908 reference "lyx:-codeseg"
24912 ) on the command line when compiling or #pragma codeseg BANK1 (See
24913 \begin_inset LatexCommand ref
24914 reference "sec:Pragmas"
24918 ) at the top of the C source file.
24919 The segment name always applies to the whole source file and generated
24920 object so functions for different banks need to be defined in different
24925 When linking your objects you need to tell the linker where
24926 to put your segments.
24927 To do this you use the following command line option to SDCC: -Wl-b BANK1=0x180
24929 \begin_inset LatexCommand ref
24930 reference "lyx:-Wl option"
24935 This sets the virtual start address of this segment.
24936 It sets the banknumber to 0x01 and maps the bank to 0x8000 and up.
24937 The linker will not check for overflows, again this is your responsibility.
24940 \begin_layout Standard
24941 \begin_inset VSpace bigskip
24947 \begin_layout Section
24951 \begin_layout Standard
24953 \begin_inset LatexCommand index
24959 \begin_inset LatexCommand index
24964 microcontroller has a rich set of peripherals.
24965 In its built-in ROM library it includes functions to access some of the
24966 features, among them is a TCP stack with IP4 and IP6 support.
24967 Library headers (currently in beta status) and other files are provided
24971 \begin_inset LatexCommand url
24972 target "ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html"
24978 \begin_inset VSpace bigskip
24984 \begin_layout Section
24985 The Z80 and gbz80 port
24988 \begin_layout Standard
24989 SDCC can target both the Zilog Z80
24990 \begin_inset LatexCommand index
24995 and the Nintendo Gameboy's Z80-like gbz80
24996 \begin_inset LatexCommand index
24997 name "gbz80 (GameBoy Z80)"
25002 The Z80 port is passed through the same
25005 \begin_inset LatexCommand index
25006 name "Regression test"
25013 \begin_inset LatexCommand ref
25014 reference "sec:Quality-control"
25018 ) as the MCS51 and DS390 ports, so floating point support, support for long
25019 variables and bitfield support is fine.
25020 See mailing lists and forums about interrupt routines.
25023 \begin_layout Standard
25024 As always, the code is the authoritative reference - see z80/ralloc.c and
25027 \begin_inset LatexCommand index
25032 frame is similar to that generated by the IAR Z80 compiler.
25033 IX is used as the base pointer, HL and IY are used as a temporary registers,
25034 and BC and DE are available for holding variables.
25036 \begin_inset LatexCommand index
25037 name "Z80!return value"
25041 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
25043 The gbz80 port use the same set of registers for the return values, but
25044 in a different order of significance: E (one byte), DE (two bytes), or
25046 \begin_inset VSpace bigskip
25052 \begin_layout Section
25056 \begin_layout Standard
25057 The port to the Freescale/Motorola HC08
25058 \begin_inset LatexCommand index
25063 family has been added in October 2003, and is still undergoing some basic
25065 The code generator is complete, but the register allocation is still quite
25067 Some of the SDCC's standard C library functions have embedded non-HC08
25068 inline assembly and so are not yet usable.
25071 \begin_layout Standard
25072 The HC08 port passes the regression test suite (see section
25073 \begin_inset LatexCommand ref
25074 reference "sec:Quality-control"
25079 \begin_inset VSpace bigskip
25085 \begin_layout Section
25087 \begin_inset LatexCommand index
25095 \begin_layout Standard
25096 The PIC14 port adds support for Microchip
25097 \begin_inset LatexCommand index
25103 \begin_inset Formula $^{\text{TM}}$
25107 \begin_inset LatexCommand index
25113 \begin_inset Formula $^{\text{TM}}$
25116 MCUs with 14 bit wide instructions.
25117 This port is not yet mature and still lacks many features.
25118 However, it can work for simple code.
25121 \begin_layout Standard
25123 Currently supported devices include:
25126 \begin_layout Standard
25127 12F: 629, 635, 675, 683
25130 \begin_layout Standard
25134 \begin_layout Standard
25138 \begin_layout Standard
25139 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
25142 \begin_layout Standard
25143 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
25147 \begin_layout Standard
25151 \begin_layout Standard
25152 16CR: 620a, 73, 74, 76, 77
25155 \begin_layout Standard
25156 16F: 616, 627, 627a, 628, 628a, 630, 636, 639, 648, 648a, 676, 684, 685,
25160 \begin_layout Standard
25161 16F: 716, 72, 73, 737, 74, 747, 76, 767, 77, 777, 785
25164 \begin_layout Standard
25165 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
25166 877, 877a, 88, 886, 887
25169 \begin_layout Standard
25170 16F: 913, 914, 916, 917, 946
25173 \begin_layout Standard
25177 \begin_layout Standard
25179 An up-to-date list of currently supported devices can be obtained via
25181 sdcc -mpic14 -phelp foo.c
25183 (foo.c must exist...).
25186 \begin_layout Subsection
25188 \begin_inset LatexCommand index
25189 name "code page (pic14)"
25194 \begin_inset LatexCommand index
25195 name "Memory bank (pic14)"
25202 \begin_layout Standard
25203 The linker organizes allocation for the code page and RAM banks.
25204 It does not have intimate knowledge of the code flow.
25205 It will put all the code section of a single .asm file into a single code
25207 In order to make use of multiple code pages, separate asm files must be
25209 The compiler assigns all
25213 functions of a single .c file into the same code page.
25217 To get the best results,
25218 follow these guidelines:
25221 \begin_layout Enumerate
25222 Make local functions static, as non static functions require code page selection
25225 Due to the way sdcc handles functions, place called functions prior
25226 to calling functions in the file wherever possible: Otherwise sdcc will
25227 insert unnecessary pagesel directives around the call, believing that the
25228 called function is externally defined.
25231 \begin_layout Enumerate
25232 For devices that have multiple code pages it is more efficient to use the
25233 same number of files as pages: Use up to 4 separate .c files for the 16F877,
25234 but only 2 files for the 16F874.
25235 This way the linker can put the code for each file into different code
25236 pages and there will be less page selection overhead.
25239 \begin_layout Enumerate
25240 And as for any 8 bit micro (especially for PIC14 as they have a very simple
25241 instruction set), use `unsigned char' wherever possible instead of `int'.
25244 \begin_layout Subsection
25245 Adding New Devices to the Port
25248 \begin_layout Standard
25249 Adding support for a new 14
25253 \begin_layout Standard
25262 bit PIC MCU requires the following steps:
25265 \begin_layout Enumerate
25266 Create a new device description.
25268 Each device is described in two files: pic16f*.h
25270 These files primarily define SFRs, structs to access their bits, and symbolic
25271 configuration options.
25272 Both files can be generated from gputils' .inc files using the perl script
25275 support/scripts/inc2h.pl
25278 This file also contains further instructions on how to proceed.
25281 \begin_layout Enumerate
25282 Copy the .h file into SDCC's include path and either add the .c file to your
25283 project or copy it to
25285 device/lib/pic/libdev
25288 Afterwards, rebuild and install the libraries.
25291 \begin_layout Enumerate
25292 Edit pic14devices.txt in SDCC's include path (
25294 device/include/pic/
25296 in the source tree or
25298 /usr/local/share/sdcc/include/pic
25300 after installation).
25302 You need to add a device specification here to make
25303 the memory layout (code banks, RAM, aliased memory regions, ...) known to
25305 Probably you can copy and modify an existing entry.
25306 The file format is documented at the top of the file.
25309 \begin_layout Subsection
25313 \begin_layout Standard
25314 For the interrupt function, use the keyword `__interrupt'
25315 \begin_inset LatexCommand index
25316 name "PIC14!interrupt"
25320 with level number of 0 (PIC14 only has 1 interrupt so this number is only
25321 there to avoid a syntax error - it ought to be fixed).
25325 \begin_layout Verse
25328 void Intr(void) __interrupt 0
25334 T0IF = 0; /* Clear timer interrupt */
25339 \begin_layout Subsection
25340 Linking and Assembling
25343 \begin_layout Standard
25344 For assembling you can use either GPUTILS'
25345 \begin_inset LatexCommand index
25346 name "gputils (pic tools)"
25350 gpasm.exe or MPLAB's mpasmwin.exe.
25351 GPUTILS are available from
25352 \begin_inset LatexCommand url
25353 target "http://sourceforge.net/projects/gputils"
25358 For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
25359 If you use MPLAB and an interrupt function then the linker script file
25360 vectors section will need to be enlarged to link with mplink.
25371 \begin_layout Verse
25384 sdcc -V -mpic14 -p16f877 -c $<
25388 $(PRJ).hex: $(OBJS)
25398 gplink -m -s $(PRJ).lkr
25399 -o $(PRJ).hex $(OBJS) libsdcc.lib
25402 \begin_layout Standard
25410 \begin_layout Verse
25423 sdcc -S -V -mpic14 -p16f877 $<
25433 mpasmwin /q /o $*.asm
25437 $(PRJ).hex: $(OBJS)
25448 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
25451 \begin_layout Standard
25452 Please note that indentations within a
25456 have to be done with a tabulator character.
25459 \begin_layout Subsection
25460 Command-Line Options
25463 \begin_layout Standard
25464 Besides the switches common to all SDCC backends, the PIC14 port accepts
25465 the following options (for an updated list see sdcc -
25469 \begin_layout Standard
25481 \begin_layout Description
25486 \begin_layout Standard
25496 \begin_inset LatexCommand index
25497 name "PIC14!Options!-\\/-debug-extra"
25501 emit debug info in assembly output
25504 \begin_layout Description
25509 \begin_layout Standard
25519 \begin_inset LatexCommand index
25520 name "PIC14!Options!-\\/-no-pcode-opt"
25524 disable (slightly faulty) optimization on pCode
25527 \begin_layout Description
25532 \begin_layout Standard
25542 \begin_inset LatexCommand index
25543 name "PIC14!Options!-\\/-stack-loc"
25547 sets the lowest address of the argument passing stack (defaults to a suitably
25548 large shared databank to reduce BANKSEL overhead)
25551 \begin_layout Description
25556 \begin_layout Standard
25566 \begin_inset LatexCommand index
25567 name "PIC14!Options!-\\/-stack-size"
25571 sets the size if the argument passing stack (default: 16, minimum: 4)
25574 \begin_layout Subsection
25575 Environment Variables
25578 \begin_layout Standard
25579 The PIC14 port recognizes the following environment variables:
25582 \begin_layout Description
25583 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
25584 register (the ones called r0xNNNN) in a section of its own.
25585 By default (if this variable is unset), sdcc tries to cluster registers
25586 in sections in order to reduce the BANKSEL overhead when accessing them.
25589 \begin_layout Subsection
25593 \begin_layout Standard
25594 The PIC14 library currently only contains support routines required by the
25595 compiler to implement multiplication, division, and floating point support.
25596 No libc-like replacement is available at the moment, though many of the
25597 common sdcc library sources (in
25601 ) should also compile with the PIC14 port.
25604 \begin_layout Subsubsection
25605 error: missing definition for symbol ``__gptrget1''
25608 \begin_layout Standard
25609 The PIC14 port uses library routines to provide more complex operations
25610 like multiplication, division/modulus and (generic) pointer dereferencing.
25611 In order to add these routines to your project, you must link with PIC14's
25617 For single source file projects this is done automatically, more complex
25622 to the linker's arguments.
25623 Make sure you also add an include path for the library (using the -I switch
25627 \begin_layout Subsubsection
25628 Processor mismatch in file ``XXX''.
25631 \begin_layout Standard
25632 This warning can usually be ignored due to the very good compatibility amongst
25637 \begin_layout Standard
25647 \begin_inset LatexCommand index
25655 \begin_layout Standard
25656 You might also consider recompiling the library for your specific device
25657 by changing the ARCH=p16f877 (default target) entry in
25659 device/lib/pic/Makefile.in
25663 device/lib/pic/Makefile
25665 to reflect your device.
25666 This might even improve performance for smaller devices as unnecessary
25667 BANKSELs might be removed.
25670 \begin_layout Subsection
25674 \begin_layout Subsubsection
25678 \begin_layout Standard
25679 Functions with variable argument lists (like printf) are not yet supported.
25680 Similarly, taking the address of the first argument passed into a function
25681 does not work: It is currently passed in WREG and has no address...
25684 \begin_layout Subsubsection
25685 Regression tests fail
25688 \begin_layout Standard
25689 Though the small subset of regression tests in src/regression passes, SDCC
25690 regression test suite does not, indicating that there are still major bugs
25692 However, many smaller projects have successfully used SDCC in the past...
25695 \begin_layout Standard
25703 \begin_layout Section
25705 \begin_inset LatexCommand index
25713 \begin_layout Standard
25714 The PIC16 port adds support for Microchip
25715 \begin_inset LatexCommand index
25721 \begin_inset Formula $^{\text{TM}}$
25725 \begin_inset LatexCommand index
25731 \begin_inset Formula $^{\text{TM}}$
25734 MCUs with 16 bit wide instructions.
25735 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
25736 ; devices supported by the port include:
25739 \begin_layout Standard
25740 18F: 242, 248, 252, 258, 442, 448, 452, 458
25743 \begin_layout Standard
25747 \begin_layout Standard
25748 18F: 2220, 2221, 2320, 2321, 2331, 2410, 2420, 2423, 2431, 2450, 2455, 2480,
25752 \begin_layout Standard
25753 18F: (2510,) 2515, 2520, 2523, 2525, 2550, 2580, 2585, 25j10, 2610, 2620,
25757 \begin_layout Standard
25758 18F: 4220, 4221, 4320, 4321, 4331, 4410, 4420, 4423, 4431, 4450, 4455, 4480,
25762 \begin_layout Standard
25763 18F: 4510, 4515, 4520, 4523, 4525, 4550, 4580, 4585, 45j10, 4610, 4620,
25767 \begin_layout Standard
25768 18F: 6520, 6585, 6620, 6680, 66j60, 66j65, 6720, 67j60
25771 \begin_layout Standard
25772 18F: 8520, 8585, 8620, 8680, 86j60, 86j65, 8720, 87j60
25775 \begin_layout Standard
25776 18F: 96j60, 96j65, 97j60
25779 \begin_layout Standard
25781 An up-to-date list of supported devices is also available via '
25783 sdcc -mpic16 -plist
25788 \begin_layout Subsection
25792 \begin_layout Standard
25793 PIC16 port supports the standard command line arguments as supposed, with
25794 the exception of certain cases that will be mentioned in the following
25798 \begin_layout Description
25803 \begin_layout Standard
25813 \begin_inset LatexCommand index
25814 name "PIC16!Options!-\\/-callee-saves"
25822 \begin_layout Standard
25834 \begin_layout Description
25839 \begin_layout Standard
25848 -fommit-frame-pointer
25849 \begin_inset LatexCommand index
25850 name "PIC16!Options!-\\/-fommit-frame-pointer"
25854 Frame pointer will be omitted when the function uses no local variables.
25857 \begin_layout Subsection
25858 Port Specific Options
25859 \begin_inset LatexCommand index
25860 name "Options PIC16"
25867 \begin_layout Standard
25868 The port specific options appear after the global options in the sdcc -
25872 \begin_layout Standard
25884 \begin_layout Subsubsection
25885 Code Generation Options
25888 \begin_layout Standard
25889 These options influence the generated assembler code.
25892 \begin_layout Description
25897 \begin_layout Standard
25906 -pstack-model=[model] Used in conjunction with the command above.
25907 Defines the stack model to be used, valid stack models are:
25912 \labelwidthstring 00.00.0000
25917 Selects small stack model.
25918 8 bit stack and frame pointers.
25919 Supports 256 bytes stack size.
25923 \labelwidthstring 00.00.0000
25928 Selects large stack model.
25929 16 bit stack and frame pointers.
25930 Supports 65536 bytes stack size.
25934 \begin_layout Description
25939 \begin_layout Standard
25948 -pno-banksel Do not generate BANKSEL assembler directives.
25951 \begin_layout Description
25956 \begin_layout Standard
25965 -extended Enable extended instruction set/literal offset addressing mode.
25969 \begin_layout Subsubsection
25970 Optimization Options
25973 \begin_layout Description
25978 \begin_layout Standard
25987 -obanksel=n Set optimization level for inserting BANKSELs.
25994 \labelwidthstring 00.00.0000
25999 \labelwidthstring 00.00.0000
26000 1 checks previous used register and if it is the same then does not emit
26001 BANKSEL, accounts only for labels.
26005 \labelwidthstring 00.00.0000
26006 2 tries to check the location of (even different) symbols and removes BANKSELs
26007 if they are in the same bank.
26012 Important: There might be problems if the linker script has data sections
26013 across bank borders!
26017 \begin_layout Description
26022 \begin_layout Standard
26031 -denable-peeps Force the usage of peepholes.
26035 \begin_layout Description
26040 \begin_layout Standard
26049 -no-optimize-goto Do not use (conditional) BRA instead of GOTO.
26052 \begin_layout Description
26057 \begin_layout Standard
26066 -optimize-cmp Try to optimize some compares.
26069 \begin_layout Description
26074 \begin_layout Standard
26083 -optimize-df Analyze the dataflow of the generated code and improve it.
26086 \begin_layout Subsubsection
26090 \begin_layout Description
26095 \begin_layout Standard
26104 -asm= Sets the full path and name of an external assembler to call.
26107 \begin_layout Description
26112 \begin_layout Standard
26122 \begin_inset LatexCommand index
26127 compatibility option.
26128 Currently only suppresses special gpasm directives.
26131 \begin_layout Subsubsection
26135 \begin_layout Description
26140 \begin_layout Standard
26149 -link= Sets the full path and name of an external linker to call.
26152 \begin_layout Description
26157 \begin_layout Standard
26166 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
26167 unitialized data variables with [kword].
26168 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
26171 \begin_layout Description
26176 \begin_layout Standard
26185 -ivt-loc=n Place the interrupt vector table at address
26190 Useful for bootloaders.
26193 \begin_layout Description
26198 \begin_layout Standard
26207 -nodefaultlibs Do not link default libraries when linking.
26210 \begin_layout Description
26215 \begin_layout Standard
26224 -use-crt= Use a custom run-time module instead of the defaults.
26227 \begin_layout Description
26232 \begin_layout Standard
26241 -no-crt Don't link the default run-time modules
26244 \begin_layout Subsubsection
26248 \begin_layout Standard
26249 Debugging options enable extra debugging information in the output files.
26252 \begin_layout Description
26257 \begin_layout Standard
26266 -debug-xtra Similar to -
26270 \begin_layout Standard
26280 \begin_inset LatexCommand index
26285 , but dumps more information.
26288 \begin_layout Description
26293 \begin_layout Standard
26302 -debug-ralloc Force register allocator to dump <source>.d file with debugging
26304 <source> is the name of the file being compiled.
26307 \begin_layout Description
26312 \begin_layout Standard
26321 -pcode-verbose Enable pcode debugging information in translation.
26324 \begin_layout Description
26329 \begin_layout Standard
26338 -calltree Dump call tree in .calltree file.
26341 \begin_layout Description
26346 \begin_layout Standard
26355 -gstack Trace push/pops for stack pointer overflow.
26358 \begin_layout Subsection
26359 Environment Variables
26362 \begin_layout Standard
26363 There is a number of environmental variables that can be used when running
26364 SDCC to enable certain optimizations or force a specific program behaviour.
26365 these variables are primarily for debugging purposes so they can be enabled/dis
26369 \begin_layout Standard
26370 Currently there is only two such variables available:
26373 \begin_layout Description
26374 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
26375 bitfields is optimized by directly loading FSR0 with the address of the
26376 bitfield structure.
26377 Normally SDCC will cast the bitfield structure to a bitfield pointer and
26379 This step saves data ram and code space for functions that make heavy use
26381 (i.e., 80 bytes of code space are saved when compiling malloc.c with this
26386 \begin_layout Description
26387 NO_REG_OPT Do not perform pCode registers optimization.
26388 This should be used for debugging purposes.
26389 If bugs in the pcode optimizer are found, users can benefit from temporarily
26390 disabling the optimizer until the bug is fixed.
26393 \begin_layout Subsection
26394 Preprocessor Macros
26397 \begin_layout Standard
26399 \begin_inset LatexCommand index
26404 port defines the following preprocessor macros while translating a source.
26407 \begin_layout Standard
26409 \begin_inset Tabular
26410 <lyxtabular version="3" rows="6" columns="2">
26412 <column alignment="center" valignment="top" leftline="true" width="0">
26413 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26414 <row topline="true" bottomline="true">
26415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26418 \begin_layout Standard
26424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26427 \begin_layout Standard
26434 <row topline="true">
26435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26438 \begin_layout Standard
26444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26447 \begin_layout Standard
26448 Port identification
26454 <row topline="true">
26455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26458 \begin_layout Standard
26463 \begin_layout Standard
26477 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26480 \begin_layout Standard
26481 Port identification (same as above)
26487 <row topline="true">
26488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26491 \begin_layout Standard
26497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26500 \begin_layout Standard
26501 MCU Identification.
26506 is the microcontrol identification number, i.e.
26513 <row topline="true">
26514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26517 \begin_layout Standard
26522 \begin_layout Standard
26536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26539 \begin_layout Standard
26540 MCU Identification (same as above)
26546 <row topline="true" bottomline="true">
26547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26550 \begin_layout Standard
26556 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26559 \begin_layout Standard
26560 nnn = SMALL or LARGE respectively according to the stack model used
26573 \begin_layout Standard
26575 In addition the following macros are defined when calling assembler:
26578 \begin_layout Standard
26580 \begin_inset Tabular
26581 <lyxtabular version="3" rows="4" columns="2">
26583 <column alignment="center" valignment="top" leftline="true" width="0">
26584 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26585 <row topline="true" bottomline="true">
26586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26589 \begin_layout Standard
26595 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26598 \begin_layout Standard
26605 <row topline="true">
26606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26609 \begin_layout Standard
26615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26618 \begin_layout Standard
26619 MCU Identification.
26624 is the microcontrol identification number, i.e.
26631 <row topline="true">
26632 <cell alignment="center" valignment="top" topline="true" leftline="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
26645 nnn = SMALL or LARGE respectively according to the memory model used for
26652 <row topline="true" bottomline="true">
26653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26656 \begin_layout Standard
26662 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26665 \begin_layout Standard
26666 nnn = SMALL or LARGE respectively according to the stack model used
26679 \begin_layout Subsection
26683 \begin_layout Standard
26685 \begin_inset LatexCommand index
26690 port uses the following directories for searching header files and libraries.
26693 \begin_layout Standard
26695 \begin_inset Tabular
26696 <lyxtabular version="3" rows="3" columns="4">
26698 <column alignment="center" valignment="top" leftline="true" width="0">
26699 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26700 <column alignment="center" valignment="top" width="0">
26701 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26702 <row topline="true" bottomline="true">
26703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26706 \begin_layout Standard
26712 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26715 \begin_layout Standard
26721 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26724 \begin_layout Standard
26730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26733 \begin_layout Standard
26740 <row topline="true">
26741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26744 \begin_layout Standard
26745 PREFIX/sdcc/include/pic16
26750 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26753 \begin_layout Standard
26754 PIC16 specific headers
26759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26762 \begin_layout Standard
26768 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26771 \begin_layout Standard
26778 <row topline="true" bottomline="true">
26779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26782 \begin_layout Standard
26783 PREFIX/sdcc/lib/pic16
26788 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26791 \begin_layout Standard
26792 PIC16 specific libraries
26797 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26800 \begin_layout Standard
26806 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26809 \begin_layout Standard
26823 \begin_layout Subsection
26825 \begin_inset LatexCommand label
26826 name "sub:PIC16_Pragmas"
26833 \begin_layout Standard
26835 \begin_inset LatexCommand index
26840 port currently supports the following pragmas:
26843 \begin_layout Description
26845 \begin_inset LatexCommand index
26846 name "PIC16!Pragmas!\\#pragma stack"
26850 This forces the code generator to initialize the stack & frame pointers
26851 at a specific address.
26852 This is an ad hoc solution for cases where no STACK directive is available
26853 in the linker script or gplink is not instructed to create a stack section.
26856 stack pragma should be used only once in a project.
26857 Multiple pragmas may result in indeterminate behaviour of the program.
26861 \begin_layout Standard
26862 The old format (ie.
26863 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
26864 cross page boundaries (or even exceed the available data RAM) and crash
26866 Make sure that stack does not cross page boundaries when using the SMALL
26874 The format is as follows:
26879 \begin_layout LyX-Code
26880 #pragma stack bottom_address [stack_size]
26885 \begin_layout Standard
26890 is the lower bound of the stack section.
26891 The stack pointer initially will point at address (bottom_address+stack_size-1).
26894 \begin_layout LyX-Code
26898 \begin_layout LyX-Code
26902 \begin_layout LyX-Code
26903 /* initializes stack of 100 bytes at RAM address 0x200 */
26906 \begin_layout LyX-Code
26907 #pragma stack 0x200 100
26910 \begin_layout Standard
26911 If the stack_size field is omitted then a stack is created with the default
26913 This size might be enough for most programs, but its not enough for operations
26914 with deep function nesting or excessive stack usage.
26917 \begin_layout Description
26919 \begin_inset LatexCommand index
26920 name "PIC16!Pragmas!\\#pragma code"
26924 Force a function to a static FLASH address.
26927 \begin_layout LyX-Code
26931 \begin_layout LyX-Code
26935 \begin_layout LyX-Code
26936 /* place function test_func at 0x4000 */
26939 \begin_layout LyX-Code
26940 #pragma code test_func 0x4000
26943 \begin_layout LyX-Code
26947 \begin_layout Description
26948 library instructs the linker to use a library module.
26953 \begin_layout LyX-Code
26954 #pragma library module_name
26957 \begin_layout Standard
26962 can be any library or object file (including its path).
26963 Note that there are four reserved keywords which have special meaning.
26967 \begin_layout Standard
26969 \begin_inset Tabular
26970 <lyxtabular version="3" rows="6" columns="3">
26972 <column alignment="center" valignment="top" leftline="true" width="0">
26973 <column alignment="block" valignment="top" leftline="true" width="20page%">
26974 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
26975 <row topline="true" bottomline="true">
26976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26979 \begin_layout Standard
26985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26988 \begin_layout Standard
26994 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26997 \begin_layout Standard
27004 <row topline="true">
27005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27008 \begin_layout Standard
27016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27019 \begin_layout Standard
27020 ignore all library pragmas
27025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27028 \begin_layout Standard
27037 <row topline="true">
27038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27041 \begin_layout Standard
27049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27052 \begin_layout Standard
27058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27061 \begin_layout Standard
27072 <row topline="true">
27073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27076 \begin_layout Standard
27084 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27087 \begin_layout Standard
27088 link the Math libarary
27093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27096 \begin_layout Standard
27107 <row topline="true">
27108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27111 \begin_layout Standard
27119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27122 \begin_layout Standard
27123 link the I/O library
27128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27131 \begin_layout Standard
27142 <row topline="true" bottomline="true">
27143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27146 \begin_layout Standard
27154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27157 \begin_layout Standard
27158 link the debug library
27163 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27166 \begin_layout Standard
27183 * is the device number, i.e.
27184 452 for PIC18F452 MCU.
27187 \begin_layout Standard
27189 This feature allows for linking with specific libraries without having to
27190 explicit name them in the command line.
27195 keyword will reject all modules specified by the library pragma.
27198 \begin_layout Description
27199 udata The pragma udata instructs the compiler to emit code so that linker
27200 will place a variable at a specific memory bank.
27203 \begin_layout LyX-Code
27207 \begin_layout LyX-Code
27211 \begin_layout LyX-Code
27212 /* places variable foo at bank2 */
27215 \begin_layout LyX-Code
27216 #pragma udata bank2 foo
27219 \begin_layout LyX-Code
27223 \begin_layout Standard
27224 In order for this pragma to work extra SECTION directives should be added
27225 in the .lkr script.
27226 In the following example a sample .lkr file is shown:
27229 \begin_layout LyX-Code
27233 \begin_layout LyX-Code
27234 // Sample linker script for the PIC18F452 processor
27237 \begin_layout LyX-Code
27241 \begin_layout LyX-Code
27242 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
27245 \begin_layout LyX-Code
27246 CODEPAGE NAME=page START=0x2A END=0x7FFF
27249 \begin_layout LyX-Code
27250 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
27253 \begin_layout LyX-Code
27254 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
27257 \begin_layout LyX-Code
27258 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
27261 \begin_layout LyX-Code
27262 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
27265 \begin_layout LyX-Code
27266 ACCESSBANK NAME=accessram START=0x0 END=0x7F
27269 \begin_layout LyX-Code
27273 \begin_layout LyX-Code
27274 DATABANK NAME=gpr0 START=0x80 END=0xFF
27277 \begin_layout LyX-Code
27278 DATABANK NAME=gpr1 START=0x100 END=0x1FF
27281 \begin_layout LyX-Code
27282 DATABANK NAME=gpr2 START=0x200 END=0x2FF
27285 \begin_layout LyX-Code
27286 DATABANK NAME=gpr3 START=0x300 END=0x3FF
27289 \begin_layout LyX-Code
27290 DATABANK NAME=gpr4 START=0x400 END=0x4FF
27293 \begin_layout LyX-Code
27294 DATABANK NAME=gpr5 START=0x500 END=0x5FF
27297 \begin_layout LyX-Code
27298 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
27301 \begin_layout LyX-Code
27305 \begin_layout LyX-Code
27306 SECTION NAME=CONFIG ROM=config
27309 \begin_layout LyX-Code
27313 \begin_layout LyX-Code
27314 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
27317 \begin_layout LyX-Code
27318 SECTION NAME=bank1 RAM=gpr1 # should be added to link
27321 \begin_layout LyX-Code
27322 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
27325 \begin_layout LyX-Code
27326 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
27329 \begin_layout LyX-Code
27330 SECTION NAME=bank4 RAM=gpr4
27333 \begin_layout LyX-Code
27334 SECTION NAME=bank5 RAM=gpr5
27337 \begin_layout Standard
27338 The linker will recognise the section name set in the pragma statement and
27339 will position the variable at the memory bank set with the RAM field at
27340 the SECTION line in the linker script file.
27343 \begin_layout Subsection
27345 \begin_inset LatexCommand label
27346 name "sub:PIC16_Header-Files"
27353 \begin_layout Standard
27354 There is one main header file
27355 \begin_inset LatexCommand index
27356 name "PIC16!Header files"
27360 that can be included to the source files using the pic16
27361 \begin_inset LatexCommand index
27372 This header file contains the definitions for the processor special registers,
27373 so it is necessary if the source accesses them.
27374 It can be included by adding the following line in the beginning of the
27378 \begin_layout LyX-Code
27379 #include <pic18fregs.h>
27382 \begin_layout Standard
27383 The specific microcontroller is selected within the pic18fregs.h automatically,
27384 so the same source can be used with a variety of devices.
27387 \begin_layout Subsection
27389 \begin_inset LatexCommand label
27390 name "sub:pic16Libraries"
27397 \begin_layout Standard
27399 \begin_inset LatexCommand index
27400 name "PIC16!Libraries"
27405 \begin_inset LatexCommand index
27410 port depends on are the microcontroller device libraries which contain
27411 the symbol definitions for the microcontroller special function registers.
27412 These libraries have the format pic18fxxxx.lib, where
27416 is the microcontroller identification number.
27417 The specific library is selected automatically by the compiler at link
27418 stage according to the selected device.
27421 \begin_layout Standard
27423 Libraries are created with gplib which is part of the gputils package
27424 \begin_inset LatexCommand url
27425 target "http://sourceforge.net/projects/gputils"
27432 \begin_layout Subsubsection*
27433 Building the libraries
27436 \begin_layout Standard
27437 Before using SDCC/pic16 there are some libraries that need to be compiled.
27438 This process is done automatically if gputils are found at SDCC's compile
27440 Should you require to rebuild the pic16 libraries manually (e.g.
27441 in order to enable output of float values
27442 \begin_inset LatexCommand index
27443 name "Floating point support"
27451 , see below), these are the steps required to do so under Linux or Mac OS
27452 X (cygwin might work as well, but is untested):
27455 \begin_layout LyX-Code
27456 cd device/lib/pic16
27459 \begin_layout LyX-Code
27463 \begin_layout LyX-Code
27467 \begin_layout LyX-Code
27471 \begin_layout LyX-Code
27472 su -c 'make install' # install the libraries, you need the root password
27475 \begin_layout LyX-Code
27479 \begin_layout Standard
27480 If you need to install the headers too, do:
27483 \begin_layout LyX-Code
27487 \begin_layout LyX-Code
27488 su -c 'make install' # install the headers, you need the root password
27491 \begin_layout Subsubsection*
27492 Output of float values via printf()
27495 \begin_layout Standard
27496 The library is normally built without support for displaying float values,
27498 \begin_inset LatexCommand index
27504 \begin_inset LatexCommand index
27505 name "printf floating point support"
27509 will appear instead of the value.
27510 To change this, rebuild the library as stated above, but call
27512 ./configure.gnu --enable-floats
27519 Also make sure that at least
27521 libc/stdio/vfprintf.c
27523 is actually recompiled, e.g.
27532 run or deleting its
27539 \begin_layout Standard
27540 The more common appraoch of compiling
27548 should also work, but is untested.
27551 \begin_layout Subsection
27552 Adding New Devices to the Port
27555 \begin_layout Standard
27556 Adding support for a new 16
27560 \begin_layout Standard
27569 bit PIC MCU requires the following steps:
27572 \begin_layout Enumerate
27573 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
27577 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
27581 \begin_layout Enumerate
27584 mv picDEVICE.h /path/to/sdcc/device/include/pic16
27587 \begin_layout Enumerate
27590 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
27593 \begin_layout Enumerate
27596 /path/to/sdcc/device/lib/pic16/pics.all
27600 Note: No 18f prefix here!
27603 \begin_layout Enumerate
27606 /path/to/sdcc/device/include/pic16/adc.h
27610 Add the new devices to the correct ADC style class (depending on the number
27617 if the device does not offer any ADC at all.
27620 \begin_layout Enumerate
27623 /path/to/sdcc/device/include/pic16/pic18fregs.h
27627 The file format is self-explanatory, just add
27631 #elif defined(picDEVICE)
27637 \begin_layout Standard
27648 include <picDEVICE.h>
27652 at the right place (keep the file sorted, please).
27655 \begin_layout Enumerate
27658 /path/to/sdcc/device/include/pic16devices.txt
27662 Copy and modify an existing entry or create a new one and insert it at the
27663 correct place (keep the file sorted, please).
27666 \begin_layout Enumerate
27669 /path/to/sdcc/device/lib/pic16/libdev/Makefile.am
27673 Copy an existing entry and adjust the device name.
27676 \begin_layout Enumerate
27679 /path/to/sdcc/device/lib/pic16/libio/Makefile.am
27683 Copy the record from the 18f2220 and adjust the device name.
27686 does not offer ADC, I
27687 \begin_inset Formula $^{\text{2}}$
27690 C, and/or (E)USART functionality as assumed by the library, remove the lines
27706 \begin_layout Enumerate
27725 /path/to/sdcc/device/lib/pic16
27730 \begin_layout Enumerate
27731 Recompile the pic16 libraries as described in
27732 \begin_inset LatexCommand ref
27733 reference "sub:pic16Libraries"
27740 \begin_layout Subsection
27744 \begin_layout Standard
27745 The following memory models are supported by the PIC16 port:
27748 \begin_layout Itemize
27752 \begin_layout Itemize
27756 \begin_layout Standard
27757 Memory model affects the default size of pointers within the source.
27758 The sizes are shown in the next table:
27761 \begin_layout Standard
27763 \begin_inset Tabular
27764 <lyxtabular version="3" rows="3" columns="3">
27766 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27767 <column alignment="center" valignment="top" leftline="true" width="0">
27768 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27769 <row topline="true" bottomline="true">
27770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27773 \begin_layout Standard
27774 Pointer sizes according to memory model
27779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27782 \begin_layout Standard
27788 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27791 \begin_layout Standard
27798 <row topline="true" bottomline="true">
27799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27802 \begin_layout Standard
27808 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27811 \begin_layout Standard
27817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27820 \begin_layout Standard
27827 <row topline="true" bottomline="true">
27828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27831 \begin_layout Standard
27837 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
27840 \begin_layout Standard
27846 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27849 \begin_layout Standard
27863 \begin_layout Standard
27864 It is advisable that all sources within a project are compiled with the
27866 If one wants to override the default memory model, this can be done by
27867 declaring a pointer as
27876 Far selects large memory model's pointers, while near selects small memory
27880 \begin_layout Standard
27881 The standard device libraries (see
27882 \begin_inset LatexCommand ref
27883 reference "sub:PIC16_Header-Files"
27887 ) contain no reference to pointers, so they can be used with both memory
27891 \begin_layout Subsection
27895 \begin_layout Standard
27897 \begin_inset LatexCommand index
27902 implementation for the PIC16 port uses two indirect registers, FSR1 and
27906 \begin_layout Description
27907 FSR1 is assigned as stack pointer
27910 \begin_layout Description
27911 FSR2 is assigned as frame pointer
27914 \begin_layout Standard
27915 The following stack models are supported by the PIC16 port
27918 \begin_layout Itemize
27926 \begin_layout Itemize
27934 \begin_layout Standard
27939 model means that only the FSRxL byte is used to access stack and frame,
27946 uses both FSRxL and FSRxH registers.
27947 The following table shows the stack/frame pointers sizes according to stack
27948 model and the maximum space they can address:
27951 \begin_layout Standard
27953 \begin_inset Tabular
27954 <lyxtabular version="3" rows="3" columns="3">
27956 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27957 <column alignment="center" valignment="top" leftline="true" width="0">
27958 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27959 <row topline="true" bottomline="true">
27960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27963 \begin_layout Standard
27964 Stack & Frame pointer sizes according to stack model
27969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27972 \begin_layout Standard
27978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27981 \begin_layout Standard
27988 <row topline="true">
27989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27992 \begin_layout Standard
27998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28001 \begin_layout Standard
28007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28010 \begin_layout Standard
28017 <row topline="true" bottomline="true">
28018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28021 \begin_layout Standard
28027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28030 \begin_layout Standard
28036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28039 \begin_layout Standard
28053 \begin_layout Standard
28059 stack model is currently not working properly throughout the code generator.
28060 So its use is not advised.
28061 Also there are some other points that need special care:
28066 \begin_layout Enumerate
28067 Do not create stack sections with size more than one physical bank (that
28071 \begin_layout Enumerate
28072 Stack sections should no cross physical bank limits (i.e.
28073 #pragma stack 0x50 0x100)
28076 \begin_layout Standard
28077 These limitations are caused by the fact that only FSRxL is modified when
28078 using SMALL stack model, so no more than 256 bytes of stack can be used.
28079 This problem will disappear after LARGE model is fully implemented.
28082 \begin_layout Subsection
28086 \begin_layout Standard
28087 In addition to the standard SDCC function keywords, PIC16
28088 \begin_inset LatexCommand index
28093 port makes available two more:
28096 \begin_layout Description
28098 \begin_inset LatexCommand index
28099 name "PIC16!wparam"
28103 Use the WREG to pass one byte of the first function argument.
28104 This improves speed but you may not use this for functions with arguments
28105 that are called via function pointers, otherwise the first byte of the
28106 first parameter will get lost.
28110 \begin_layout LyX-Code
28111 void func_wparam(int a) wparam
28114 \begin_layout LyX-Code
28118 \begin_layout LyX-Code
28119 /* WREG hold the lower part of a */
28122 \begin_layout LyX-Code
28123 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
28127 \begin_layout LyX-Code
28131 \begin_layout LyX-Code
28135 \begin_layout Description
28137 \begin_inset LatexCommand index
28138 name "PIC16!shadowregs"
28142 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
28143 hardware shadow registers which hold the values of WREG, STATUS and BSR
28145 This can be done by adding the keyword
28153 keyword in the function's header.
28156 \begin_layout LyX-Code
28157 void isr_shadow(void) shadowregs interrupt 1
28160 \begin_layout LyX-Code
28164 \begin_layout LyX-Code
28168 \begin_layout LyX-Code
28172 \begin_layout Standard
28177 instructs the code generator not to store/restore WREG, STATUS, BSR when
28178 entering/exiting the ISR.
28181 \begin_layout Subsection
28182 Function return values
28185 \begin_layout Standard
28186 Return values from functions are placed to the appropriate registers following
28187 a modified Microchip policy optimized for SDCC.
28188 The following table shows these registers:
28191 \begin_layout Standard
28193 \begin_inset Tabular
28194 <lyxtabular version="3" rows="6" columns="2">
28196 <column alignment="center" valignment="top" leftline="true" width="0">
28197 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28198 <row topline="true" bottomline="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 destination register
28218 <row topline="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
28238 <row topline="true">
28239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28242 \begin_layout Standard
28248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28251 \begin_layout Standard
28258 <row topline="true">
28259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28262 \begin_layout Standard
28268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28271 \begin_layout Standard
28278 <row topline="true">
28279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28282 \begin_layout Standard
28288 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28291 \begin_layout Standard
28292 FSR0L:PRODH:PRODL:WREG
28298 <row topline="true" bottomline="true">
28299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28302 \begin_layout Standard
28308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28311 \begin_layout Standard
28312 on stack, FSR0 points to the beginning
28325 \begin_layout Subsection
28329 \begin_layout Standard
28331 \begin_inset LatexCommand index
28332 name "PIC16!interrupt"
28336 service routine (ISR) is declared using the
28343 \begin_layout LyX-Code
28344 void isr(void) interrupt
28349 \begin_layout LyX-Code
28353 \begin_layout LyX-Code
28357 \begin_layout LyX-Code
28361 \begin_layout Standard
28366 is the interrupt number, which for PIC18F devices can be:
28369 \begin_layout Standard
28371 \begin_inset Tabular
28372 <lyxtabular version="3" rows="4" columns="3">
28374 <column alignment="center" valignment="top" leftline="true" width="0">
28375 <column alignment="center" valignment="top" leftline="true" width="0">
28376 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28377 <row topline="true" bottomline="true">
28378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28381 \begin_layout Standard
28389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28392 \begin_layout Standard
28398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28401 \begin_layout Standard
28402 Interrupt Vector Address
28408 <row topline="true">
28409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28412 \begin_layout Standard
28418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28421 \begin_layout Standard
28427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28430 \begin_layout Standard
28437 <row topline="true">
28438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28441 \begin_layout Standard
28456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28459 \begin_layout Standard
28469 HIGH priority interrupts
28474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28477 \begin_layout Standard
28484 <row topline="true" bottomline="true">
28485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28488 \begin_layout Standard
28494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28497 \begin_layout Standard
28498 LOW priority interrupts
28503 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28506 \begin_layout Standard
28520 \begin_layout Standard
28521 When generating assembly code for ISR the code generator places a
28527 Interrupt Vector Address
28529 which points at the generated ISR.
28530 This single GOTO instruction is part of an automatically generated
28532 interrupt entry point
28535 The actuall ISR code is placed as normally would in the code space.
28536 Upon interrupt request, the GOTO instruction is executed which jumps to
28538 When declaring interrupt functions as _naked this GOTO instruction is
28543 The whole interrupt functions is therefore placed at the Interrupt Vector
28544 Address of the specific interrupt.
28545 This is not a problem for the LOW priority interrupts, but it is a problem
28546 for the RESET and the HIGH priority interrupts because code may be written
28547 at the next interrupt's vector address and cause indeterminate program
28548 behaviour if that interrupt is raised.
28552 \begin_layout Standard
28553 This is not a problem when
28556 \begin_layout Enumerate
28557 this is a HIGH interrupt ISR and LOW interrupts are
28564 \begin_layout Enumerate
28565 when the ISR is small enough not to reach the next interrupt's vector address.
28573 \begin_layout Standard
28579 This way a function is generated similar to an ISR, but it is not assigned
28583 \begin_layout Standard
28584 When entering an interrupt, currently the PIC16
28585 \begin_inset LatexCommand index
28590 port automatically saves the following registers:
28593 \begin_layout Itemize
28597 \begin_layout Itemize
28601 \begin_layout Itemize
28605 \begin_layout Itemize
28606 PROD (PRODL and PRODH)
28609 \begin_layout Itemize
28610 FSR0 (FSR0L and FSR0H)
28613 \begin_layout Standard
28614 These registers are restored upon return from the interrupt routine.
28618 \begin_layout Standard
28619 NOTE that when the _naked attribute is specified for an interrupt routine,
28620 then NO registers are stored or restored.
28628 \begin_layout Subsection
28632 \begin_layout Standard
28633 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
28634 There are 3 types of generic pointers currently implemented data, code
28635 and eeprom pointers.
28636 They are differentiated by the value of the 7th and 6th bits of the upper
28640 \begin_layout Standard
28642 \begin_inset Tabular
28643 <lyxtabular version="3" rows="5" columns="5">
28645 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28646 <column alignment="center" valignment="top" width="0">
28647 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28648 <column alignment="center" valignment="top" width="0">
28649 <column alignment="left" valignment="top" rightline="true" width="0">
28650 <row topline="true" bottomline="true">
28651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28654 \begin_layout Standard
28660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28663 \begin_layout Standard
28669 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28672 \begin_layout Standard
28678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28681 \begin_layout Standard
28682 rest of the pointer
28687 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28690 \begin_layout Standard
28697 <row topline="true" bottomline="true">
28698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28701 \begin_layout Standard
28707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28710 \begin_layout Standard
28716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28719 \begin_layout Standard
28725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28728 \begin_layout Standard
28733 uuuuuu uuuuxxxx xxxxxxxx
28738 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28741 \begin_layout Standard
28742 a 12-bit data pointer in data RAM memory
28748 <row bottomline="true">
28749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28752 \begin_layout Standard
28758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28761 \begin_layout Standard
28767 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28770 \begin_layout Standard
28776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28779 \begin_layout Standard
28784 uxxxxx xxxxxxxx xxxxxxxx
28789 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28792 \begin_layout Standard
28793 a 21-bit code pointer in FLASH memory
28799 <row bottomline="true">
28800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28803 \begin_layout Standard
28809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28812 \begin_layout Standard
28818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28821 \begin_layout Standard
28827 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28830 \begin_layout Standard
28835 uuuuuu uuuuuuxx xxxxxxxx
28840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28843 \begin_layout Standard
28844 a 10-bit eeprom pointer in EEPROM memory
28850 <row bottomline="true">
28851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28854 \begin_layout Standard
28860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28863 \begin_layout Standard
28869 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28872 \begin_layout Standard
28878 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28881 \begin_layout Standard
28886 xxxxxx xxxxxxxx xxxxxxxx
28891 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28894 \begin_layout Standard
28895 unimplemented pointer type
28908 \begin_layout Standard
28910 Generic pointer are read and written with a set of library functions which
28911 read/write 1, 2, 3, 4 bytes.
28914 \begin_layout Subsection
28918 \begin_layout Subsubsection
28919 Standard I/O Streams
28922 \begin_layout Standard
28927 the type FILE is defined as:
28930 \begin_layout LyX-Code
28931 typedef char * FILE;
28934 \begin_layout Standard
28935 This type is the stream type implemented I/O in the PIC18F devices.
28936 Also the standard input and output streams are declared in stdio.h:
28939 \begin_layout LyX-Code
28940 extern FILE * stdin;
28943 \begin_layout LyX-Code
28944 extern FILE * stdout;
28947 \begin_layout Standard
28948 The FILE type is actually a generic pointer which defines one more type
28949 of generic pointers, the
28954 This new type has the format:
28957 \begin_layout Standard
28960 \begin_inset Tabular
28961 <lyxtabular version="3" rows="2" columns="7">
28963 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28964 <column alignment="center" valignment="top" width="0">
28965 <column alignment="center" valignment="top" leftline="true" width="0">
28966 <column alignment="center" valignment="top" leftline="true" width="0">
28967 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28968 <column alignment="center" valignment="top" width="0">
28969 <column alignment="left" valignment="top" rightline="true" width="0">
28970 <row topline="true" bottomline="true">
28971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28974 \begin_layout Standard
28980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28983 \begin_layout Standard
28989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28992 \begin_layout Standard
28998 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29001 \begin_layout Standard
29007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29010 \begin_layout Standard
29016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29019 \begin_layout Standard
29020 rest of the pointer
29025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29028 \begin_layout Standard
29035 <row topline="true" bottomline="true">
29036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29039 \begin_layout Standard
29045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29048 \begin_layout Standard
29054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29057 \begin_layout Standard
29063 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29066 \begin_layout Standard
29072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29075 \begin_layout Standard
29081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29084 \begin_layout Standard
29094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29097 \begin_layout Standard
29098 upper byte high nubble is 0x2n, the rest are zeroes
29111 \begin_layout Standard
29113 Currently implemented there are 3 types of streams defined:
29116 \begin_layout Standard
29119 \begin_inset Tabular
29120 <lyxtabular version="3" rows="4" columns="4">
29122 <column alignment="center" valignment="top" leftline="true" width="0">
29123 <column alignment="center" valignment="top" leftline="true" width="0">
29124 <column alignment="center" valignment="top" leftline="true" width="0">
29125 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29126 <row topline="true" bottomline="true">
29127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29130 \begin_layout Standard
29136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29139 \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
29164 <row topline="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 the USART peripheral
29204 <row topline="true">
29205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29208 \begin_layout Standard
29214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29217 \begin_layout Standard
29225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29228 \begin_layout Standard
29234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29237 \begin_layout Standard
29238 Writes/Reads characters via the MSSP peripheral
29244 <row topline="true" bottomline="true">
29245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29248 \begin_layout Standard
29254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29257 \begin_layout Standard
29265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29268 \begin_layout Standard
29274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29277 \begin_layout Standard
29278 Writes/Reads characters via used defined functions
29291 \begin_layout Standard
29293 The stream identifiers are declared as macros in the stdio.h header.
29296 \begin_layout Standard
29298 In the libc library there exist the functions that are used to write to
29299 each of the above streams.
29303 \begin_layout Description
29308 \begin_layout Standard
29317 _stream_usart_putchar writes a character at the USART stream
29320 \begin_layout Description
29325 \begin_layout Standard
29334 _stream_mssp_putchar writes a character at the MSSP stream
29337 \begin_layout Description
29338 putchar dummy function.
29339 This writes a character to a user specified manner.
29342 \begin_layout Standard
29343 In order to increase performance
29347 is declared in stdio.h as having its parameter in WREG (it has the wparam
29349 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
29350 in a user-friendly way.
29355 is the name of the variable that holds the character to print.
29356 An example follows:
29359 \begin_layout LyX-Code
29360 #include <pic18fregs.h>
29369 \begin_layout LyX-Code
29373 \begin_layout LyX-Code
29374 PORTA = c; /* dump character c to PORTA */
29377 \begin_layout LyX-Code
29385 \begin_layout LyX-Code
29389 \begin_layout LyX-Code
29390 stdout = STREAM_USER; /* this is not necessary, since stdout points
29393 \begin_layout LyX-Code
29394 * by default to STREAM_USER */
29397 \begin_layout LyX-Code
29399 \begin_inset Quotes sld
29402 This is a printf test
29405 \begin_inset Quotes srd
29411 \begin_layout LyX-Code
29415 \begin_layout LyX-Code
29419 \begin_layout Subsubsection
29423 \begin_layout Standard
29424 PIC16 contains an implementation of the printf-family of functions.
29425 There exist the following functions:
29428 \begin_layout LyX-Code
29429 extern unsigned int sprintf(char *buf, char *fmt, ...);
29432 \begin_layout LyX-Code
29433 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
29436 \begin_layout LyX-Code
29440 \begin_layout LyX-Code
29441 extern unsigned int printf(char *fmt, ...);
29444 \begin_layout LyX-Code
29445 extern unsigned int vprintf(char *fmt, va_lista ap);
29448 \begin_layout LyX-Code
29452 \begin_layout LyX-Code
29453 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
29456 \begin_layout LyX-Code
29457 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
29460 \begin_layout Standard
29461 For sprintf and vsprintf
29465 should normally be a data pointer where the resulting string will be placed.
29466 No range checking is done so the user should allocate the necessary buffer.
29467 For fprintf and vfprintf
29471 should be a stream pointer (i.e.
29472 stdout, STREAM_MSSP, etc...).
29475 \begin_layout Subsubsection
29479 \begin_layout Standard
29480 The PIC18F family of microcontrollers supports a number of interrupt sources.
29481 A list of these interrupts is shown in the following table:
29484 \begin_layout Standard
29486 \begin_inset Tabular
29487 <lyxtabular version="3" rows="11" columns="4">
29489 <column alignment="left" valignment="top" leftline="true" width="0">
29490 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29491 <column alignment="left" valignment="top" leftline="true" width="0">
29492 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29493 <row topline="true" bottomline="true">
29494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29497 \begin_layout Standard
29503 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29506 \begin_layout Standard
29512 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29515 \begin_layout Standard
29521 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29524 \begin_layout Standard
29531 <row topline="true">
29532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29535 \begin_layout Standard
29541 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29544 \begin_layout Standard
29545 PORTB change interrupt
29550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29553 \begin_layout Standard
29559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29562 \begin_layout Standard
29563 EEPROM/FLASH write complete interrupt
29569 <row topline="true">
29570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29573 \begin_layout Standard
29579 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29582 \begin_layout Standard
29583 INT0 external interrupt
29588 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29591 \begin_layout Standard
29597 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29600 \begin_layout Standard
29601 Bus collision interrupt
29607 <row topline="true">
29608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29611 \begin_layout Standard
29617 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29620 \begin_layout Standard
29621 INT1 external interrupt
29626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29629 \begin_layout Standard
29635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29638 \begin_layout Standard
29639 Low voltage detect interrupt
29645 <row topline="true">
29646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29649 \begin_layout Standard
29655 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29658 \begin_layout Standard
29659 INT2 external interrupt
29664 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29667 \begin_layout Standard
29673 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29676 \begin_layout Standard
29677 Parallel slave port interrupt
29683 <row topline="true">
29684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29687 \begin_layout Standard
29693 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29696 \begin_layout Standard
29697 CCP1 module interrupt
29702 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29705 \begin_layout Standard
29711 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29714 \begin_layout Standard
29715 AD convertion complete interrupt
29721 <row topline="true">
29722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29725 \begin_layout Standard
29731 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29734 \begin_layout Standard
29735 CCP2 module interrupt
29740 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29743 \begin_layout Standard
29749 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29752 \begin_layout Standard
29753 USART receive interrupt
29759 <row topline="true">
29760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29763 \begin_layout Standard
29769 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29772 \begin_layout Standard
29773 TMR0 overflow interrupt
29778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29781 \begin_layout Standard
29787 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29790 \begin_layout Standard
29791 USART transmit interrupt
29797 <row topline="true">
29798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29801 \begin_layout Standard
29807 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29810 \begin_layout Standard
29811 TMR1 overflow interrupt
29816 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29819 \begin_layout Standard
29825 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29828 \begin_layout Standard
29829 SSP receive/transmit interrupt
29835 <row topline="true">
29836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29839 \begin_layout Standard
29845 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29848 \begin_layout Standard
29849 TMR2 matches PR2 interrupt
29854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29857 \begin_layout Standard
29863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29866 \begin_layout Standard
29873 <row topline="true" bottomline="true">
29874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29877 \begin_layout Standard
29883 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29886 \begin_layout Standard
29887 TMR3 overflow interrupt
29892 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29895 \begin_layout Standard
29901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29904 \begin_layout Standard
29918 \begin_layout Standard
29920 The prototypes for these names are defined in the header file
29927 \begin_layout Standard
29929 In order to simplify signal handling, a number of macros is provided:
29933 \labelwidthstring 00.00.0000
29934 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
29935 high priority interrupts.
29940 is the function name to use.
29944 \labelwidthstring 00.00.0000
29945 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
29946 low priority interrupt.
29951 is the function name to use.
29955 \labelwidthstring 00.00.0000
29956 DEF_HANDLER(sig,handler) define a handler for signal
29962 \labelwidthstring 00.00.0000
29963 END_DEF end the declaration of the dispatch table.
29966 \begin_layout Standard
29967 Additionally there are two more macros to simplify the declaration of the
29972 \labelwidthstring 00.00.0000
29975 SIGHANDLER(handler)
29977 this declares the function prototype for the
29985 \labelwidthstring 00.00.0000
29986 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
29989 \begin_layout Standard
29990 An example of using the macros above is shown below:
29993 \begin_layout LyX-Code
29994 #include <pic18fregs.h>
29997 \begin_layout LyX-Code
29998 #include <signal.h>
30002 DEF_INTHIGH(high_int)
30005 \begin_layout LyX-Code
30006 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
30009 \begin_layout LyX-Code
30010 DEF_HANDLER(SIG_BCOL, _bcol_handler)
30013 \begin_layout LyX-Code
30018 SIGHANDLER(_tmr0_handler)
30021 \begin_layout LyX-Code
30025 \begin_layout LyX-Code
30026 /* action to be taken when timer 0 overflows */
30029 \begin_layout LyX-Code
30034 SIGHANDLERNAKED(_bcol_handler)
30037 \begin_layout LyX-Code
30041 \begin_layout LyX-Code
30045 \begin_layout LyX-Code
30046 /* action to be taken when bus collision occurs */
30049 \begin_layout LyX-Code
30053 \begin_layout LyX-Code
30057 \begin_layout LyX-Code
30061 \begin_layout Standard
30066 Special care should be taken when using the above scheme:
30069 \begin_layout Itemize
30070 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
30073 \begin_layout Itemize
30074 when declaring SIGHANDLERNAKED handler never forget to use
30078 for proper returning.
30081 \begin_layout Subsection
30085 \begin_layout Standard
30086 Here you can find some general tips for compiling programs with SDCC/pic16.
30089 \begin_layout Subsubsection
30093 \begin_layout Standard
30095 \begin_inset LatexCommand index
30100 size (that is 64 bytes) probably is enough for many programs.
30101 One must take care that when there are many levels of function nesting,
30102 or there is excessive usage of stack, its size should be extended.
30103 An example of such a case is the printf/sprintf family of functions.
30104 If you encounter problems like not being able to print integers, then you
30105 need to set the stack size around the maximum (256 for small stack model).
30106 The following diagram shows what happens when calling printf to print an
30110 \begin_layout LyX-Code
30111 printf () --> ltoa () --> ultoa () --> divschar ()
30114 \begin_layout Standard
30115 It is should be understood that stack is easily consumed when calling complicate
30117 Using command line arguments like -
30121 \begin_layout Standard
30130 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
30132 Other ways to reduce stack usage may exist.
30135 \begin_layout Subsection
30139 \begin_layout Subsubsection
30140 Extended Instruction Set
30143 \begin_layout Standard
30144 The PIC16 port emits code which is incompatible with the extended instruction
30145 set available with many newer devices.
30146 Make sure to always explicitly disable it, usually using
30149 \begin_layout Standard
30152 static __code char __at(__CONFIG4L) conf4l = /* more flags & */ _XINST_OFF_4L;
30155 \begin_layout Standard
30157 Some devices (namely 18f2455, 18f2550, 18f4455, and 18f4550) use _ENHCPU_OFF_4L
30158 instead of _XINST_OFF_4L.
30161 \begin_layout Subsubsection
30165 \begin_layout Standard
30166 The PIC16 port currently passes most but not all of the tests in SDCC's
30168 \begin_inset LatexCommand index
30169 name "Regression test (PIC16)"
30174 \begin_inset LatexCommand ref
30175 reference "sec:Quality-control"
30179 ), thus no automatic regression tests are currently performed for the PIC16
30183 \begin_layout Chapter
30187 \begin_layout Standard
30188 There are several approaches to debugging your code.
30189 This chapter is meant to show your options and to give detail on some of
30194 When writing your code:
30197 \begin_layout Itemize
30198 write your code with debugging in mind (avoid duplicating code, put conceptually
30199 similar variables into structs, use structured code, have strategic points
30200 within your code where all variables are consistent, ...)
30203 \begin_layout Itemize
30204 run a syntax-checking tool like splint
30205 \begin_inset LatexCommand index
30206 name "splint (syntax checking tool)"
30211 \begin_inset LatexCommand index
30212 name "lint (syntax checking tool)"
30220 \begin_layout Standard
30230 \begin_inset LatexCommand ref
30231 reference "lyx:more-pedantic-SPLINT"
30238 \begin_layout Itemize
30239 for the high level code use a C-compiler (like f.e.
30240 GCC) to compile run and debug the code on your host.
30245 \begin_layout Standard
30255 \begin_inset LatexCommand ref
30256 reference "lyx:more-pedantic-SPLINT"
30260 ) on how to handle syntax extensions like __xdata, __at(), ...
30264 \begin_layout Itemize
30265 use another C-compiler to compile code for your target.
30266 Always an option but not recommended:) And not very likely to help you.
30267 If you seriously consider walking this path you should at least occasionally
30268 check portability of your code.
30269 Most commercial compiler vendors will offer an evaluation version so you
30270 can test compile your code or snippets of your code.
30273 \begin_layout Standard
30274 Debugging on a simulator:
30277 \begin_layout Itemize
30278 there is a separate section about SDCDB (section
30279 \begin_inset LatexCommand ref
30280 reference "cha:Debugging-with-SDCDB"
30287 \begin_layout Itemize
30288 or (8051 specific) use a freeware/commercial simulator which interfaces
30290 \begin_inset LatexCommand index
30291 name "AOMF, AOMF51"
30296 \begin_inset LatexCommand ref
30297 reference "OMF file"
30301 ) optionally generated by SDCC.
30304 \begin_layout Standard
30305 Debugging On-target:
30308 \begin_layout Itemize
30309 use a MCU port pin to serially output debug data to the RS232 port of your
30311 You'll probably want some level shifting device typically involving a MAX232
30313 If the hardware serial port of the MCU is not available search for 'Software
30314 UART' in your favourite search machine.
30317 \begin_layout Itemize
30318 use an on-target monitor.
30319 In this context a monitor is a small program which usually accepts commands
30320 via a serial line and allows to set program counter, to single step through
30321 a program and read/write memory locations.
30322 For the 8051 good examples of monitors are paulmon and cmon51 (see section
30324 \begin_inset LatexCommand ref
30325 reference "sec:Related-open-source-tools"
30332 \begin_layout Itemize
30333 toggle MCU port pins at strategic points within your code and use an oscilloscop
30337 digital oscilloscope
30340 \begin_inset LatexCommand index
30341 name "Oscilloscope"
30345 with deep trace memory is really helpful especially if you have to debug
30346 a realtime application.
30347 If you need to monitor more pins than your oscilloscope provides you can
30348 sometimes get away with a small R-2R network.
30349 On a single channel oscilloscope you could f.e.
30350 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
30352 \begin_inset Formula $\Omega$
30355 resistor and the other one by a 5\InsetSpace ~
30357 \begin_inset Formula $\Omega$
30360 resistor to the oscilloscope probe (check output drive capability of the
30361 pins you want to monitor).
30362 If you need to monitor many more pins a
30369 \begin_layout Itemize
30383 \begin_inset LatexCommand index
30384 name "ICE (in circuit emulator)"
30389 Usually very expensive.
30390 And very nice to have too.
30391 And usually locks you (for years...) to the devices the ICE can emulate.
30395 \begin_layout Itemize
30396 use a remote debugger.
30397 In most 8-bit systems the symbol information is not available on the target,
30398 and a complete debugger is too bulky for the target system.
30399 Therefore usually a debugger on the host system connects to an on-target
30400 debugging stub which accepts only primitive commands.
30403 Terms to enter into your favourite search engine could be 'remote debugging',
30404 'gdb stub' or 'inferior debugger'.
30408 \begin_layout Itemize
30409 use an on target hardware debugger.
30410 Some of the more modern MCUs include hardware support for setting break
30411 points and monitoring/changing variables by using dedicated hardware pins.
30412 This facility doesn't require additional code to run on the target and
30417 doesn't affect runtime behaviour until a breakpoint is hit.
30418 For the mcs51 most hardware debuggers use the AOMF
30419 \begin_inset LatexCommand index
30420 name "AOMF, AOMF51"
30425 \begin_inset LatexCommand ref
30426 reference "OMF file"
30434 \begin_layout Standard
30438 \begin_layout Itemize
30439 if you are not familiar with any of the following terms you're likely to
30440 run into problems rather sooner than later:
30457 As an embedded programmer you
30461 to know them so why not look them up
30465 you have problems?)
30468 \begin_layout Itemize
30469 tell someone else about your problem (actually this is a surprisingly effective
30470 means to hunt down the bug even if the listener is not familiar with your
30472 As 'failure to communicate' is probably one of the job-induced deformations
30473 of an embedded programmer this is highly encouraged.
30476 \begin_layout Section
30477 Debugging with SDCDB
30478 \begin_inset LatexCommand label
30479 name "cha:Debugging-with-SDCDB"
30484 \begin_inset LatexCommand index
30485 name "SDCDB (debugger)"
30492 \begin_layout Standard
30493 SDCC is distributed with a source level debugger
30494 \begin_inset LatexCommand index
30500 The debugger uses a command line interface, the command repertoire of the
30501 debugger has been kept as close to gdb
30502 \begin_inset LatexCommand index
30507 (the GNU debugger) as possible.
30508 The configuration and build process is part of the standard compiler installati
30509 on, which also builds and installs the debugger in the target directory
30510 specified during configuration.
30511 The debugger allows you debug BOTH at the C source and at the ASM source
30515 \begin_layout Subsection
30516 Compiling for Debugging
30519 \begin_layout Standard
30524 \begin_layout Standard
30534 \begin_inset LatexCommand index
30539 option must be specified for all files for which debug information is to
30541 The compiler generates a .adb file for each of these files.
30542 The linker creates the .cdb
30543 \begin_inset LatexCommand index
30549 \begin_inset LatexCommand index
30554 files and the address information.
30555 This .cdb is used by the debugger.
30558 \begin_layout Subsection
30559 How the Debugger Works
30562 \begin_layout Standard
30567 \begin_layout Standard
30576 -debug option is specified the compiler generates extra symbol information
30577 some of which are put into the assembler source and some are put into the
30579 Then the linker creates the .cdb file from the individual .adb files with
30580 the address information for the symbols.
30581 The debugger reads the symbolic information generated by the compiler &
30582 the address information generated by the linker.
30583 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
30584 execution is controlled by the debugger.
30585 When a command is issued for the debugger, it translates it into appropriate
30586 commands for the simulator.
30587 (Currently SDCDM only connects to the simulator but
30592 \begin_inset LatexCommand url
30593 target "http://ec2drv.sf.net/"
30597 is an effort to connect directly to the hardware.)
30600 \begin_layout Subsection
30601 Starting the Debugger SDCDB
30604 \begin_layout Standard
30605 The debugger can be started using the following command line.
30606 (Assume the file you are debugging has the file name foo).
30620 The debugger will look for the following files.
30623 \begin_layout Itemize
30624 foo.c - the source file.
30627 \begin_layout Itemize
30628 foo.cdb - the debugger symbol information file.
30631 \begin_layout Itemize
30632 foo.ihx - the Intel hex format
30633 \begin_inset LatexCommand index
30634 name "Intel hex format"
30641 \begin_layout Subsection
30642 SDCDB Command Line Options
30645 \begin_layout Itemize
30650 \begin_layout Standard
30659 -directory=<source file directory> this option can used to specify the directory
30661 The debugger will look into the directory list specified for source, cdb
30663 The items in the directory list must be separated by ':', e.g.
30664 if the source files can be in the directories /home/src1 and /home/src2,
30669 \begin_layout Standard
30678 -directory option should be -
30682 \begin_layout Standard
30691 -directory=/home/src1:/home/src2.
30692 Note there can be no spaces in the option.
30696 \begin_layout Itemize
30697 -cd <directory> - change to the <directory>.
30700 \begin_layout Itemize
30701 -fullname - used by GUI front ends.
30704 \begin_layout Itemize
30705 -cpu <cpu-type> - this argument is passed to the simulator please see the
30706 simulator docs for details.
30709 \begin_layout Itemize
30710 -X <Clock frequency > this options is passed to the simulator please see
30711 the simulator docs for details.
30714 \begin_layout Itemize
30715 -s <serial port file> passed to simulator see the simulator docs for details.
30718 \begin_layout Itemize
30719 -S <serial in,out> passed to simulator see the simulator docs for details.
30722 \begin_layout Itemize
30723 -k <port number> passed to simulator see the simulator docs for details.
30726 \begin_layout Subsection
30727 SDCDB Debugger Commands
30730 \begin_layout Standard
30731 As mentioned earlier the command interface for the debugger has been deliberatel
30732 y kept as close the GNU debugger gdb, as possible.
30733 This will help the integration with existing graphical user interfaces
30734 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
30735 If you use a graphical user interface for the debugger you can skip this
30739 \begin_layout Subsubsection*
30740 break [line | file:line | function | file:function]
30743 \begin_layout Standard
30744 Set breakpoint at specified line or function:
30753 sdcdb>break foo.c:100
30755 sdcdb>break funcfoo
30757 sdcdb>break foo.c:funcfoo
30760 \begin_layout Subsubsection*
30761 clear [line | file:line | function | file:function ]
30764 \begin_layout Standard
30765 Clear breakpoint at specified line or function:
30774 sdcdb>clear foo.c:100
30776 sdcdb>clear funcfoo
30778 sdcdb>clear foo.c:funcfoo
30781 \begin_layout Subsubsection*
30785 \begin_layout Standard
30786 Continue program being debugged, after breakpoint.
30789 \begin_layout Subsubsection*
30793 \begin_layout Standard
30794 Execute till the end of the current function.
30797 \begin_layout Subsubsection*
30801 \begin_layout Standard
30802 Delete breakpoint number 'n'.
30803 If used without any option clear ALL user defined break points.
30806 \begin_layout Subsubsection*
30807 info [break | stack | frame | registers ]
30810 \begin_layout Itemize
30811 info break - list all breakpoints
30814 \begin_layout Itemize
30815 info stack - show the function call stack.
30818 \begin_layout Itemize
30819 info frame - show information about the current execution frame.
30822 \begin_layout Itemize
30823 info registers - show content of all registers.
30826 \begin_layout Subsubsection*
30830 \begin_layout Standard
30831 Step program until it reaches a different source line.
30832 Note: pressing <return> repeats the last command.
30835 \begin_layout Subsubsection*
30839 \begin_layout Standard
30840 Step program, proceeding through subroutine calls.
30843 \begin_layout Subsubsection*
30847 \begin_layout Standard
30848 Start debugged program.
30851 \begin_layout Subsubsection*
30855 \begin_layout Standard
30856 Print type information of the variable.
30859 \begin_layout Subsubsection*
30863 \begin_layout Standard
30864 print value of variable.
30867 \begin_layout Subsubsection*
30871 \begin_layout Standard
30872 load the given file name.
30873 Note this is an alternate method of loading file for debugging.
30876 \begin_layout Subsubsection*
30880 \begin_layout Standard
30881 print information about current frame.
30884 \begin_layout Subsubsection*
30888 \begin_layout Standard
30889 Toggle between C source & assembly source.
30892 \begin_layout Subsubsection*
30893 ! simulator command
30896 \begin_layout Standard
30897 Send the string following '!' to the simulator, the simulator response is
30899 Note the debugger does not interpret the command being sent to the simulator,
30900 so if a command like 'go' is sent the debugger can loose its execution
30901 context and may display incorrect values.
30904 \begin_layout Subsubsection*
30908 \begin_layout Standard
30911 My name is Bobby Brown"
30914 \begin_layout Subsection
30915 Interfacing SDCDB with DDD
30918 \begin_layout Standard
30919 \begin_inset Note Note
30922 \begin_layout Standard
30923 The screenshot was converted from png to eps with:
30924 \begin_inset Quotes sld
30927 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
30928 \begin_inset Quotes srd
30931 which produces a pretty compact eps file which is free from compression
30935 \begin_layout Standard
30936 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
30937 as this broke the build system on Sourceforge (pdf-file was broken.
30938 pdflatex does not accept eps files).
30946 \begin_layout Standard
30962 \begin_inset LatexCommand url
30963 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png"
30969 shows a screenshot of a debugging session with DDD
30970 \begin_inset LatexCommand index
30971 name "DDD (debugger)"
30975 (Unix only) on a simulated 8032.
30976 The debugging session might not run as smoothly as the screenshot suggests.
30977 The debugger allows setting of breakpoints, displaying and changing variables,
30978 single stepping through C and assembler code.
30981 The source was compiled with
30995 \begin_layout Standard
31007 -debug ddd_example.c
31020 and DDD was invoked with
31027 ddd -debugger "sdcdb -cpu 8032 ddd_example"
31030 \begin_layout Standard
31031 \begin_inset Note Note
31034 \begin_layout Standard
31035 Check that the double quotes or an apostrophe within the command line survive
31036 the LyX tool chain.
31037 Previously the apostrophes got slanted in the PDF output so a cut and paste
31046 \begin_layout Subsection
31047 Interfacing SDCDB with XEmacs
31048 \begin_inset LatexCommand index
31054 \begin_inset LatexCommand index
31062 \begin_layout Standard
31063 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
31064 sdcdb.el and sdcdbsrc.el.
31065 These two files can be found in the $(prefix)/bin directory after the installat
31067 These files need to be loaded into XEmacs for the interface to work.
31068 This can be done at XEmacs startup time by inserting the following into
31069 your '.xemacs' file (which can be found in your HOME directory):
31075 (load-file sdcdbsrc.el)
31081 .xemacs is a lisp file so the () around the command is REQUIRED.
31082 The files can also be loaded dynamically while XEmacs is running, set the
31083 environment variable 'EMACSLOADPATH' to the installation bin directory
31084 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
31085 To start the interface enter the following command:
31099 You will prompted to enter the file name to be debugged.
31104 The command line options that are passed to the simulator directly are
31105 bound to default values in the file sdcdbsrc.el.
31106 The variables are listed below, these values maybe changed as required.
31109 \begin_layout Itemize
31110 sdcdbsrc-cpu-type '51
31113 \begin_layout Itemize
31114 sdcdbsrc-frequency '11059200
31117 \begin_layout Itemize
31118 sdcdbsrc-serial nil
31121 \begin_layout Standard
31122 The following is a list of key mapping for the debugger interface.
31125 \begin_layout Standard
31148 binding\InsetSpace ~
31186 -------\InsetSpace ~
31257 sdcdb-back-from-src\InsetSpace ~
31286 rom-src\InsetSpace ~
31296 SDCDB continue command
31314 sdcdb-step-from-src\InsetSpace ~
31343 hatis-c-sexp\InsetSpace ~
31353 SDCDB ptypecommand for data at
31420 sdcdbsrc-delete\InsetSpace ~
31435 B Delete all breakpoints if no arg
31484 given or delete arg (C-u arg x)
31503 -frame\InsetSpace ~
31518 SDCDB Display current frame if no arg,
31567 given or display frame arg
31635 sdcdbsrc-goto-sdcdb\InsetSpace ~
31645 Goto the SDCDB output buffer
31664 t-c-sexp\InsetSpace ~
31675 SDCDB print command for data at
31742 sdcdbsrc-goto-sdcdb\InsetSpace ~
31753 o the SDCDB output buffer
31771 sdcdbsrc-mode\InsetSpace ~
31787 Toggles Sdcdbsrc mode (turns it
31803 sdcdb-finish-from-src\InsetSpace ~
31811 SDCDB finish command
31845 Set break for line with point
31860 sdcdbsrc-mode\InsetSpace ~
31876 Toggle Sdcdbsrc mode
31892 dbsrc-srcmode\InsetSpace ~
31916 \begin_layout Chapter
31920 \begin_layout Standard
31921 Here are a few guidelines that will help the compiler generate more efficient
31922 code, some of the tips are specific to this compiler others are generally
31923 good programming practice.
31926 \begin_layout Itemize
31927 Use the smallest data type to represent your data-value.
31928 If it is known in advance that the value is going to be less than 256 then
31929 use an 'unsigned char' instead of a 'short' or 'int'.
31930 Please note, that ANSI C requires both signed and unsigned chars to be
31931 promoted to 'signed int'
31932 \begin_inset LatexCommand index
31933 name "promotion to signed int"
31938 \begin_inset Marginal
31941 \begin_layout Standard
31950 before doing any operation.
31952 \begin_inset LatexCommand index
31953 name "type promotion"
31958 \begin_inset LatexCommand label
31959 name "type promotion"
31963 can be omitted, if the result is the same.
31964 The effect of the promotion rules together with the sign-extension is often
31969 \begin_layout Verse
31972 unsigned char uc = 0xfe;
31974 if (uc * uc < 0) /* this is true! */
31987 \begin_layout Standard
31994 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
32002 \begin_layout Verse
32005 (unsigned char) -12 / (signed char) -3 = ...
32008 \begin_layout Standard
32009 No, the result is not 4:
32012 \begin_layout Verse
32015 (int) (unsigned char) -12 / (int) (signed char) -3 =
32017 (int) (unsigned char)
32018 0xf4 / (int) (signed char) 0xfd =
32020 (int) 0x00f4 / (int) 0xfffd =
32025 (int) 244 / (int) -3 =
32027 (int) -81 = (int) 0xffaf;
32030 \begin_layout Standard
32031 Don't complain, that gcc gives you a different result.
32032 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
32033 Therefore the results are different.
32036 \begin_inset Quotes sld
32040 \begin_inset Quotes srd
32046 \begin_layout Quote
32049 If well-defined overflow characteristics are important and negative values
32050 are not, or if you want to steer clear of sign-extension problems when
32051 manipulating bits or bytes, use one of the corresponding unsigned types.
32052 (Beware when mixing signed and unsigned values in expressions, though.)
32055 character types (especially unsigned char) can be used as "tiny" integers,
32056 doing so is sometimes more trouble than it's worth, due to unpredictable
32057 sign extension and increased code size.
32061 \begin_layout Itemize
32062 Use unsigned when it is known in advance that the value is not going to
32064 This helps especially if you are doing division or multiplication, bit-shifting
32065 or are using an array index.
32068 \begin_layout Itemize
32069 NEVER jump into a LOOP.
32072 \begin_layout Itemize
32073 Declare the variables to be local
32074 \begin_inset LatexCommand index
32075 name "local variables"
32079 whenever possible, especially loop control variables (induction).
32082 \begin_layout Itemize
32083 Have a look at the assembly listing to get a
32084 \begin_inset Quotes sld
32088 \begin_inset Quotes srd
32091 for the code generation.
32094 \begin_layout Section
32095 Porting code from or to other compilers
32096 \begin_inset LatexCommand label
32097 name "sec:Porting-code-to-other-compilers"
32104 \begin_layout Itemize
32105 check whether endianness of the compilers differs and adapt where needed.
32108 \begin_layout Itemize
32109 check the device specific header files
32110 \begin_inset LatexCommand index
32111 name "Header files"
32116 \begin_inset LatexCommand index
32117 name "Include files"
32121 for compiler specific syntax.
32122 Eventually include the file <compiler.h
32123 \begin_inset LatexCommand index
32124 name "compiler.h (include file)"
32129 \begin_inset LatexCommand url
32130 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup"
32134 to allow using common header files.
32137 \begin_inset LatexCommand url
32138 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup"
32145 \begin_layout Itemize
32146 check whether the startup code contains the correct initialization (watchdog,
32150 \begin_layout Itemize
32151 check whether the sizes of short, int, long match.
32154 \begin_layout Itemize
32155 check if some 16 or 32 bit hardware registers require a specific addressing
32156 order (least significant or most significant byte first) and adapt if needed
32165 relate to time and not to lower/upper memory location here, so this is
32170 the same as endianness).
32173 \begin_layout Itemize
32174 check whether the keyword
32178 is used where needed.
32179 The compilers might differ in their optimization characteristics (as different
32180 versions of the same compiler might also use more clever optimizations
32181 this is good idea anyway).
32183 \begin_inset LatexCommand ref
32184 reference "sub:Common-interrupt-pitfall-volatile"
32191 \begin_layout Itemize
32192 check that the compilers are not told to suppress warnings.
32195 \begin_layout Itemize
32196 check and convert compiler specific extensions (interrupts, memory areas,
32200 \begin_layout Itemize
32201 check for differences in type promotion.
32202 Especially check for math operations on
32211 For the sake of C99 compatibility SDCC will probably promote these to
32215 more often than other compilers.
32216 Eventually insert explicit casts to
32225 Also check that the ~\InsetSpace ~
32227 \begin_inset LatexCommand index
32228 name "\\~\\/ Operator"
32235 \begin_inset LatexCommand index
32242 variables, use the !\InsetSpace ~
32245 \begin_inset LatexCommand ref
32246 reference "type promotion"
32251 \begin_inset LatexCommand ref
32252 reference "sec:Compatibility-with-previous"
32259 \begin_layout Itemize
32260 check the assembly code generated for interrupt routines (f.e.
32261 for calls to possibly non-reentrant library functions).
32264 \begin_layout Itemize
32265 check whether timing loops result in proper timing (or preferably consider
32266 a rewrite of the code with timer based delays instead).
32269 \begin_layout Itemize
32270 check for differences in printf parameters (some compilers push (va_arg
32271 \begin_inset LatexCommand index
32272 name "vararg, va\\_arg"
32276 ) char variables as
32280 others push them as
32286 \begin_inset LatexCommand ref
32287 reference "sec:Compatibility-with-previous"
32294 \begin_layout Itemize
32295 check the resulting memory map
32296 \begin_inset LatexCommand index
32302 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
32303 ly idata, pdata, xdata).
32304 Eventually check if unexpected library functions are included.
32307 \begin_layout Section
32309 \begin_inset LatexCommand index
32314 included in the distribution
32317 \begin_layout Standard
32319 \begin_inset Tabular
32320 <lyxtabular version="3" rows="12" columns="3">
32322 <column alignment="left" valignment="top" leftline="true" width="0pt">
32323 <column alignment="left" valignment="top" leftline="true" width="0pt">
32324 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32325 <row topline="true" bottomline="true">
32326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32329 \begin_layout Standard
32337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32340 \begin_layout Standard
32348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32351 \begin_layout Standard
32360 <row topline="true">
32361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32364 \begin_layout Standard
32366 \begin_inset LatexCommand index
32376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32379 \begin_layout Standard
32380 Simulator for various architectures
32385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32388 \begin_layout Standard
32395 <row topline="true">
32396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32399 \begin_layout Standard
32405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32408 \begin_layout Standard
32410 \begin_inset LatexCommand index
32411 name "Header files"
32416 \begin_inset LatexCommand index
32417 name "Include files"
32426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32429 \begin_layout Standard
32430 sdcc/support/scripts
32436 <row topline="true">
32437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32440 \begin_layout Standard
32446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32449 \begin_layout Standard
32450 header file conversion
32455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32458 \begin_layout Standard
32459 sdcc/support/scripts
32465 <row topline="true">
32466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32469 \begin_layout Standard
32475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32478 \begin_layout Standard
32484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32487 \begin_layout Standard
32503 <row topline="true">
32504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32507 \begin_layout Standard
32513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32516 \begin_layout Standard
32522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32525 \begin_layout Standard
32541 <row topline="true">
32542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32545 \begin_layout Standard
32551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32554 \begin_layout Standard
32560 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32563 \begin_layout Standard
32579 <row topline="true">
32580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32583 \begin_layout Standard
32589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32592 \begin_layout Standard
32598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32601 \begin_layout Standard
32617 <row topline="true">
32618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32621 \begin_layout Standard
32627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32630 \begin_layout Standard
32636 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32639 \begin_layout Standard
32655 <row topline="true">
32656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32659 \begin_layout Standard
32665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32668 \begin_layout Standard
32674 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32677 \begin_layout Standard
32693 <row topline="true">
32694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32697 \begin_layout Standard
32703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32706 \begin_layout Standard
32712 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32715 \begin_layout Standard
32731 <row topline="true" bottomline="true">
32732 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32735 \begin_layout Standard
32741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32744 \begin_layout Standard
32746 \begin_inset LatexCommand index
32747 name "packihx (tool)"
32756 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32759 \begin_layout Standard
32784 \begin_layout Section
32786 \begin_inset LatexCommand index
32787 name "Documentation"
32791 included in the distribution
32794 \begin_layout Standard
32796 \begin_inset Tabular
32797 <lyxtabular version="3" rows="10" columns="2">
32799 <column alignment="block" valignment="top" leftline="true" width="40col%">
32800 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
32801 <row topline="true" bottomline="true" endhead="true">
32802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32805 \begin_layout Standard
32813 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32816 \begin_layout Standard
32819 Filename / Where to get
32825 <row topline="true">
32826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32829 \begin_layout Standard
32830 SDCC Compiler User Guide
32835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32838 \begin_layout Standard
32839 You're reading it right now
32851 \begin_inset LatexCommand url
32852 target "http://sdcc.sourceforge.net/doc/sdccman.pdf"
32862 <row topline="true">
32863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32866 \begin_layout Standard
32872 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32875 \begin_layout Standard
32888 \begin_inset LatexCommand url
32889 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog"
32899 <row topline="true">
32900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32903 \begin_layout Standard
32905 \begin_inset LatexCommand index
32906 name "asXXXX (as-gbz80, as-hc08, asx8051, as-z80)"
32911 \begin_inset LatexCommand index
32912 name "Assembler documentation"
32919 \begin_inset LatexCommand index
32925 \begin_inset LatexCommand index
32926 name "Linker documentation"
32935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32938 \begin_layout Standard
32939 sdcc/as/doc/asxhtm.html
32951 \begin_inset LatexCommand url
32952 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html"
32962 <row topline="true">
32963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32966 \begin_layout Standard
32967 SDCC regression test
32968 \begin_inset LatexCommand index
32969 name "Regression test"
32978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32981 \begin_layout Standard
32982 sdcc/doc/test_suite_spec.pdf
32994 \begin_inset LatexCommand url
32995 target "http://sdcc.sourceforge.net/doc/test_suite_spec.pdf"
33005 <row topline="true">
33006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33009 \begin_layout Standard
33015 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33018 \begin_layout Standard
33031 \begin_inset LatexCommand url
33032 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/"
33042 <row topline="true">
33043 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33046 \begin_layout Standard
33047 Notes on debugging with SDCDB
33048 \begin_inset LatexCommand index
33049 name "SDCDB (debugger)"
33058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33061 \begin_layout Standard
33062 sdcc/debugger/README
33074 \begin_inset LatexCommand url
33075 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README"
33085 <row topline="true">
33086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33089 \begin_layout Standard
33091 \begin_inset LatexCommand index
33096 Software simulator for microcontrollers
33101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33104 \begin_layout Standard
33134 \begin_inset LatexCommand url
33135 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html"
33145 <row topline="true">
33146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33149 \begin_layout Standard
33150 Temporary notes on the pic16
33151 \begin_inset LatexCommand index
33161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33164 \begin_layout Standard
33165 sdcc/src/pic16/NOTES
33177 \begin_inset LatexCommand url
33178 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES"
33188 <row topline="true" bottomline="true">
33189 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33192 \begin_layout Standard
33193 SDCC internal documentation (debugging file format)
33198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33201 \begin_layout Standard
33231 \begin_inset LatexCommand url
33232 target "http://sdcc.sourceforge.net/doc/cdbfileformat.pdf"
33251 \begin_layout Section
33252 Related open source tools
33253 \begin_inset LatexCommand label
33254 name "sec:Related-open-source-tools"
33259 \begin_inset LatexCommand index
33260 name "Related tools"
33267 \begin_layout Standard
33269 \begin_inset Tabular
33270 <lyxtabular version="3" rows="16" columns="3">
33272 <column alignment="left" valignment="top" leftline="true" width="0pt">
33273 <column alignment="block" valignment="top" leftline="true" width="30line%">
33274 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
33275 <row topline="true" bottomline="true">
33276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33279 \begin_layout Standard
33287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33290 \begin_layout Standard
33298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33301 \begin_layout Standard
33310 <row topline="true">
33311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33314 \begin_layout Standard
33316 \begin_inset LatexCommand index
33317 name "gpsim (pic simulator)"
33326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33329 \begin_layout Standard
33335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33338 \begin_layout Standard
33339 \begin_inset LatexCommand url
33340 target "http://www.dattalo.com/gnupic/gpsim.html"
33350 <row topline="true">
33351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33354 \begin_layout Standard
33356 \begin_inset LatexCommand index
33357 name "gputils (pic tools)"
33366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33369 \begin_layout Standard
33375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33378 \begin_layout Standard
33379 \begin_inset LatexCommand url
33380 target "http://sourceforge.net/projects/gputils"
33390 <row topline="true">
33391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33394 \begin_layout Standard
33400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33403 \begin_layout Standard
33409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33412 \begin_layout Standard
33413 \begin_inset LatexCommand url
33414 target "http://freshmeat.net/projects/flp5/"
33424 <row topline="true">
33425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33428 \begin_layout Standard
33434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33437 \begin_layout Standard
33438 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
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/ec2drv"
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 "indent (source formatting tool)"
33475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33478 \begin_layout Standard
33479 Formats C source - Master of the white spaces
33484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33487 \begin_layout Standard
33488 \begin_inset LatexCommand url
33489 target "http://directory.fsf.org/GNU/indent.html"
33499 <row topline="true">
33500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33503 \begin_layout Standard
33505 \begin_inset LatexCommand index
33506 name "srecord (bin, hex, ... tool)"
33515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33518 \begin_layout Standard
33519 Object file conversion, checksumming, ...
33524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33527 \begin_layout Standard
33528 \begin_inset LatexCommand url
33529 target "http://sourceforge.net/projects/srecord"
33539 <row topline="true">
33540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33543 \begin_layout Standard
33545 \begin_inset LatexCommand index
33546 name "objdump (tool)"
33555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33558 \begin_layout Standard
33559 Object file conversion, ...
33564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33567 \begin_layout Standard
33568 Part of binutils (should be there anyway)
33574 <row topline="true">
33575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33578 \begin_layout Standard
33584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33587 \begin_layout Standard
33588 8051 monitor (hex up-/download, single step, disassemble)
33593 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33596 \begin_layout Standard
33597 \begin_inset LatexCommand url
33598 target "http://sourceforge.net/projects/cmon51"
33608 <row topline="true">
33609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33612 \begin_layout Standard
33614 \begin_inset LatexCommand index
33615 name "doxygen (source documentation tool)"
33624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33627 \begin_layout Standard
33628 Source code documentation system
33633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33636 \begin_layout Standard
33637 \begin_inset LatexCommand url
33638 target "http://www.doxygen.org"
33648 <row topline="true">
33649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33652 \begin_layout Standard
33658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33661 \begin_layout Standard
33662 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
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.kdevelop.org"
33682 <row topline="true">
33683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33686 \begin_layout Standard
33692 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33695 \begin_layout Standard
33696 8051 monitor (hex up-/download, single step, disassemble)
33701 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33704 \begin_layout Standard
33705 \begin_inset LatexCommand url
33706 target "http://www.pjrc.com/tech/8051/paulmon2.html"
33716 <row topline="true">
33717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33720 \begin_layout Standard
33722 \begin_inset LatexCommand index
33723 name "splint (syntax checking tool)"
33732 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33735 \begin_layout Standard
33736 Statically checks c sources (see
33737 \begin_inset LatexCommand ref
33738 reference "lyx:more-pedantic-SPLINT"
33747 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33750 \begin_layout Standard
33751 \begin_inset LatexCommand url
33752 target "http://www.splint.org"
33762 <row topline="true" bottomline="true">
33763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33766 \begin_layout Standard
33768 \begin_inset LatexCommand index
33769 name "DDD (debugger)"
33778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33781 \begin_layout Standard
33782 Debugger, serves nicely as GUI to SDCDB
33783 \begin_inset LatexCommand index
33784 name "SDCDB (debugger)"
33793 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33796 \begin_layout Standard
33797 \begin_inset LatexCommand url
33798 target "http://www.gnu.org/software/ddd/"
33808 <row bottomline="true">
33809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33812 \begin_layout Standard
33814 \begin_inset LatexCommand index
33820 \begin_inset LatexCommand index
33821 name "d52 (disassembler)"
33830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33833 \begin_layout Standard
33834 Disassembler, can count instruction cycles
33835 \begin_inset LatexCommand index
33836 name "instruction cycles (count)"
33840 , use with options -pnd
33845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33848 \begin_layout Standard
33849 \begin_inset LatexCommand url
33850 target "http://www.8052.com/users/disasm/"
33860 <row bottomline="true">
33861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33864 \begin_layout Standard
33866 \begin_inset LatexCommand index
33876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33879 \begin_layout Standard
33880 Cross platform build system, generates Makefiles
33881 \begin_inset LatexCommand index
33886 and project workspaces
33887 \begin_inset LatexCommand index
33888 name "project workspace"
33897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33900 \begin_layout Standard
33901 \begin_inset LatexCommand url
33902 target "http://www.cmake.org"
33910 and a dedicated wiki entry:
33911 \begin_inset LatexCommand url
33912 target "http://www.cmake.org/Wiki/CmakeSdcc"
33931 \begin_layout Section
33932 Related documentation / recommended reading
33935 \begin_layout Standard
33937 \begin_inset Tabular
33938 <lyxtabular version="3" rows="7" columns="3">
33940 <column alignment="left" valignment="top" leftline="true" width="0pt">
33941 <column alignment="left" valignment="top" leftline="true" width="0">
33942 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
33943 <row topline="true" bottomline="true">
33944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33947 \begin_layout Standard
33955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33958 \begin_layout Standard
33966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33969 \begin_layout Standard
33978 <row topline="true">
33979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33982 \begin_layout Standard
33997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34000 \begin_layout Standard
34002 \begin_inset LatexCommand index
34003 name "C Reference card"
34012 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34015 \begin_layout Standard
34016 \begin_inset LatexCommand url
34017 target "http://refcards.com/refcards/c/index.html"
34027 <row topline="true">
34028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34031 \begin_layout Standard
34037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34040 \begin_layout Standard
34042 \begin_inset LatexCommand index
34052 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34055 \begin_layout Standard
34056 \begin_inset LatexCommand url
34057 target "http://www.c-faq.com"
34067 <row topline="true">
34068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34071 \begin_layout Standard
34077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34080 \begin_layout Standard
34081 \begin_inset Quotes sld
34085 \begin_inset Quotes srd
34093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34096 \begin_layout Standard
34099 \begin_inset LatexCommand url
34100 target "http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899"
34110 <row topline="true">
34111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34114 \begin_layout Standard
34120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34123 \begin_layout Standard
34124 \begin_inset Quotes sld
34127 Extensions for Embedded C
34128 \begin_inset Quotes srd
34136 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34139 \begin_layout Standard
34142 \begin_inset LatexCommand url
34143 target "http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf"
34153 <row topline="true">
34154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34157 \begin_layout Standard
34163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34166 \begin_layout Standard
34167 Latest datasheet of target CPU
34172 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34175 \begin_layout Standard
34182 <row topline="true" bottomline="true">
34183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34186 \begin_layout Standard
34192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34195 \begin_layout Standard
34196 Revision history of datasheet
34201 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34204 \begin_layout Standard
34220 \begin_layout Section
34221 Application notes specifically for SDCC
34224 \begin_layout Standard
34225 SDCC makes no claims about the completeness of this list and about up-to-datenes
34226 s or correctness of the application notes
34227 \begin_inset LatexCommand index
34228 name "Application notes"
34235 \begin_layout Standard
34239 \begin_inset Tabular
34240 <lyxtabular version="3" rows="7" columns="3">
34242 <column alignment="block" valignment="top" leftline="true" width="17col%">
34243 <column alignment="block" valignment="top" leftline="true" width="27col%">
34244 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
34245 <row topline="true" bottomline="true">
34246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34249 \begin_layout Standard
34258 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
34261 \begin_layout Standard
34270 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34273 \begin_layout Standard
34283 <row topline="true">
34284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34287 \begin_layout Standard
34295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34298 \begin_layout Standard
34301 Using the SDCC Compiler for the DS80C400
34302 \begin_inset LatexCommand index
34312 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34315 \begin_layout Standard
34318 \begin_inset LatexCommand url
34319 target "http://pdfserv.maxim-ic.com/en/an/AN3346.pdf"
34329 <row topline="true">
34330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34333 \begin_layout Standard
34341 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
34344 \begin_layout Standard
34347 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
34348 \begin_inset LatexCommand index
34353 Family of Microcontrollers
34358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34361 \begin_layout Standard
34364 \begin_inset LatexCommand url
34365 target "http://pdfserv.maxim-ic.com/en/an/AN3477.pdf"
34375 <row topline="true">
34376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34379 \begin_layout Standard
34382 Silicon Laboratories / Cygnal
34387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34390 \begin_layout Standard
34393 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
34394 \begin_inset LatexCommand index
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.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf"
34421 <row topline="true">
34422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34425 \begin_layout Standard
34428 Ramtron / Goal Semiconductor
34433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34436 \begin_layout Standard
34439 Interfacing SDCC to Syn and Textpad
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://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp"
34461 <row topline="true">
34462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34465 \begin_layout Standard
34468 Ramtron / Goal Semiconductor
34473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34476 \begin_layout Standard
34479 Installing and Configuring SDCC and Crimson Editor
34484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34487 \begin_layout Standard
34490 \begin_inset LatexCommand url
34491 target "http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp"
34501 <row topline="true" bottomline="true">
34502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34505 \begin_layout Standard
34513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34516 \begin_layout Standard
34519 MSC12xx Programming with SDCC
34524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34527 \begin_layout Standard
34530 \begin_inset LatexCommand url
34531 target "http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf"
34548 \begin_layout Section
34552 \begin_layout Standard
34553 Some questions answered, some pointers given - it might be time to in turn
34561 \begin_layout Itemize
34562 can you solve your project with the selected microcontroller? Would you
34563 find out early or rather late that your target is too small/slow/whatever?
34564 Can you switch to a slightly better device if it doesn't fit?
34567 \begin_layout Itemize
34568 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
34569 and/or another programming language be more adequate? Would an operating
34570 system on the target device help?
34573 \begin_layout Itemize
34574 if you solved the problem, will the marketing department be happy?
34577 \begin_layout Itemize
34578 if the marketing department is happy, will customers be happy?
34581 \begin_layout Itemize
34582 if you're the project manager, marketing department and maybe even the customer
34583 in one person, have you tried to see the project from the outside?
34586 \begin_layout Itemize
34587 is the project done if you think it is done? Or is just that other interface/pro
34588 tocol/feature/configuration/option missing? How about website, manual(s),
34589 internationali(z|s)ation, packaging, labels, 2nd source for components,
34590 electromagnetic compatability/interference, documentation for production,
34591 production test software, update mechanism, patent issues?
34594 \begin_layout Itemize
34595 is your project adequately positioned in that magic triangle: fame, fortune,
34599 \begin_layout Standard
34600 Maybe not all answers to these questions are known and some answers may
34605 , nevertheless knowing these questions may help you to avoid burnout
34609 \begin_layout Standard
34610 burnout is bad for electronic devices, programmers and motorcycle tyres
34616 Chances are you didn't want to hear some of them...
34619 \begin_layout Chapter
34621 \begin_inset LatexCommand index
34629 \begin_layout Standard
34630 SDCC has grown to be a large project.
34631 The compiler alone (without the preprocessor, assembler and linker) is
34632 well over 150,000 lines of code (blank stripped).
34633 The open source nature of this project is a key to its continued growth
34635 You gain the benefit and support of many active software developers and
34637 Is SDCC perfect? No, that's why we need your help.
34638 The developers take pride in fixing reported bugs.
34639 You can help by reporting the bugs and helping other SDCC users.
34640 There are lots of ways to contribute, and we encourage you to take part
34641 in making SDCC a great software package.
34645 \begin_layout Standard
34646 The SDCC project is hosted on the SDCC sourceforge site at
34647 \begin_inset LatexCommand htmlurl
34648 target "http://sourceforge.net/projects/sdcc"
34653 You'll find the complete set of mailing lists
34654 \begin_inset LatexCommand index
34655 name "Mailing list(s)"
34659 , forums, bug reporting system, patch submission
34660 \begin_inset LatexCommand index
34661 name "Patch submission"
34666 \begin_inset LatexCommand index
34671 area and Subversion code repository
34672 \begin_inset LatexCommand index
34673 name "Subversion code repository"
34680 \begin_layout Section
34682 \begin_inset LatexCommand index
34683 name "Bug reporting"
34688 \begin_inset LatexCommand index
34689 name "Reporting bugs"
34696 \begin_layout Standard
34697 The recommended way of reporting bugs is using the infrastructure of the
34699 You can follow the status of bug reports there and have an overview about
34703 \begin_layout Standard
34704 Bug reports are automatically forwarded to the developer mailing list and
34705 will be fixed ASAP.
34706 When reporting a bug, it is very useful to include a small test program
34707 (the smaller the better) which reproduces the problem.
34708 If you can isolate the problem by looking at the generated assembly code,
34709 this can be very helpful.
34710 Compiling your program with the -
34714 \begin_layout Standard
34724 \begin_inset LatexCommand index
34725 name "-\\/-dumpall"
34729 option can sometimes be useful in locating optimization problems.
34730 When reporting a bug please make sure you:
34733 \begin_layout Enumerate
34734 Attach the code you are compiling with SDCC.
34738 \begin_layout Enumerate
34739 Specify the exact command you use to run SDCC, or attach your Makefile.
34743 \begin_layout Enumerate
34744 Specify the SDCC version (type "
34750 "), your platform, and operating system.
34754 \begin_layout Enumerate
34755 Provide an exact copy of any error message or incorrect output.
34759 \begin_layout Enumerate
34760 Put something meaningful in the subject of your message.
34763 \begin_layout Standard
34764 Please attempt to include these 5 important parts, as applicable, in all
34765 requests for support or when reporting any problems or bugs with SDCC.
34766 Though this will make your message lengthy, it will greatly improve your
34767 chance that SDCC users and developers will be able to help you.
34768 Some SDCC developers are frustrated by bug reports without code provided
34769 that they can use to reproduce and ultimately fix the problem, so please
34770 be sure to provide sample code if you are reporting a bug!
34773 \begin_layout Standard
34774 Please have a short check that you are using a recent version of SDCC and
34775 the bug is not yet known.
34776 This is the link for reporting bugs:
34777 \begin_inset LatexCommand htmlurl
34778 target "http://sourceforge.net/tracker/?group_id=599&atid=100599"
34783 With SDCC on average having more than 200 downloads
34784 \begin_inset LatexCommand index
34789 on sourceforge per day
34793 \begin_layout Standard
34794 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
34795 between 2002 and 2005.
34796 This does not include other methods of distribution.
34801 there must be some users.
34802 So it's not exactly easy to find a new bug.
34803 If you find one we need it:
34805 reporting bugs is good
34810 \begin_layout Section
34811 Requesting Features
34812 \begin_inset LatexCommand label
34813 name "sub:Requesting-Features"
34818 \begin_inset LatexCommand index
34819 name "Feature request"
34824 \begin_inset LatexCommand index
34825 name "Requesting features"
34832 \begin_layout Standard
34833 Like bug reports feature requests are forwarded to the developer mailing
34835 This is the link for requesting features:
34836 \begin_inset LatexCommand htmlurl
34837 target "http://sourceforge.net/tracker/?group_id=599&atid=350599"
34844 \begin_layout Section
34848 \begin_layout Standard
34849 Like bug reports contributed patches are forwarded to the developer mailing
34851 This is the link for submitting patches
34852 \begin_inset LatexCommand index
34853 name "Patch submission"
34858 \begin_inset LatexCommand url
34859 target "http://sourceforge.net/tracker/?group_id=599&atid=300599"
34866 \begin_layout Standard
34867 You need to specify some parameters to the
34871 command for the patches to be useful.
34872 If you modified more than one file a patch created f.e.
34877 \begin_inset Quotes sld
34880 diff -Naur unmodified_directory modified_directory >my_changes.patch
34881 \begin_inset Quotes srd
34887 will be fine, otherwise
34891 \begin_inset Quotes sld
34894 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
34895 \begin_inset Quotes srd
34904 \begin_layout Section
34908 \begin_layout Standard
34909 These links should take you directly to the
34910 \begin_inset LatexCommand url
34911 name "Mailing lists"
34912 target "http://sourceforge.net/mail/?group_id=599"
34920 \begin_layout Standard
34921 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
34922 automated messages (mid 2003)
34928 \begin_inset LatexCommand url
34930 target "http://sourceforge.net/forum/?group_id=599"
34935 \begin_inset LatexCommand index
34936 name "Mailing list(s)"
34940 and forums are archived and searchable so if you are lucky someone already
34941 had a similar problem.
34942 While mails to the lists themselves are delivered promptly their web front
34943 end on sourceforge sometimes shows a severe time lag (up to several weeks),
34944 if you're seriously using SDCC please consider subscribing to the lists.
34947 \begin_layout Section
34951 \begin_layout Standard
34952 You can follow the status of the Subversion version
34953 \begin_inset LatexCommand index
34958 of SDCC by watching the Changelog
34959 \begin_inset LatexCommand index
34964 in the Subversion repository
34967 \begin_inset LatexCommand htmlurl
34968 target "http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog"
34975 \begin_layout Section
34976 Subversion Source Code Repository
34979 \begin_layout Standard
34989 \begin_layout Standard
35003 or the filenames of the snapshot versions of SDCC include date and its
35005 \begin_inset LatexCommand index
35006 name "Subversion code repository"
35011 Subversion allows to download the source of recent or previous versions
35013 \begin_inset LatexCommand url
35014 target "http://sourceforge.net/svn/?group_id=599"
35018 (by number or by date).
35019 An on-line source code browser and detailled instructions are also available
35021 SDCC versions starting from 1999 up to now are available (currently the
35022 versions prior to the conversion from cvs
35023 \begin_inset LatexCommand index
35024 name "cvs|see{Subversion}"
35028 to Subversion (April 2006) are either by accessible by Subversion or by
35032 \begin_layout Section
35034 \begin_inset LatexCommand index
35035 name "Release policy"
35042 \begin_layout Standard
35043 Historically there often were long delays between official releases and
35044 the sourceforge download area tends to get not updated at all.
35045 Excuses in the past might have referred to problems with live range analysis,
35046 but as this was fixed a while ago, the current problem is that another
35047 excuse has to be found.
35048 Kidding aside, we have to get better there! On the other hand there are
35049 daily snapshots available at
35050 \begin_inset LatexCommand htmlurl
35052 target "http://sdcc.sourceforge.net/snap.php"
35056 , and you can always build the very last version (hopefully with many bugs
35057 fixed, and features added) from the source code available at
35058 \begin_inset LatexCommand htmlurl
35060 target "http://sdcc.sourceforge.net/snap.php#Source"
35066 \begin_inset LatexCommand index
35072 \begin_inset LatexCommand index
35078 \begin_inset LatexCommand url
35079 target "http://sdcc.wiki.sourceforge.net/"
35083 also holds some information about past and future releases.
35086 \begin_layout Section
35088 \begin_inset LatexCommand index
35096 \begin_layout Standard
35097 You'll find some small examples in the directory
35099 sdcc/device/examples/.
35102 More examples and libraries are available at
35104 The SDCC Open Knowledge Resource
35105 \begin_inset LatexCommand url
35106 target "http://sdccokr.dl9sec.de/"
35113 \begin_inset LatexCommand url
35114 target "http://www.pjrc.com/tech/8051/"
35121 \begin_layout Standard
35122 \begin_inset Note Note
35125 \begin_layout Standard
35126 I did insert a reference to Paul's web site here although it seems rather
35127 dedicated to a specific 8032 board (I think it's okay because it f.e.
35128 shows LCD/Harddisc interface and has a free 8051 monitor.
35129 Independent 8032 board vendors face hard competition of heavily subsidized
35130 development boards anyway).
35133 \begin_layout Standard
35134 Maybe we should include some links to real world applications.
35135 Preferably pointer to pointers (one for each architecture) so this stays
35144 \begin_layout Section
35146 \begin_inset LatexCommand label
35147 name "sec:Quality-control"
35152 \begin_inset LatexCommand index
35153 name "Quality control"
35160 \begin_layout Standard
35161 The compiler is passed through snaphot build compile and build checks.
35167 \begin_inset LatexCommand index
35168 name "Regression test"
35172 check that SDCC itself compiles flawlessly on several host platforms (i386,
35173 Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
35174 and checks the quality of the code generated by SDCC by running the code
35175 for several target platforms through simulators.
35176 The regression test suite comprises more than 100 files which expand to
35177 more than 500 test cases which include more than 4500 tests.
35178 The results of these tests are published daily on SDCC's snapshot page
35179 (click on the red or green symbols on the right side of
35180 \begin_inset LatexCommand url
35181 target "http://sdcc.sourceforge.net/snap.php"
35188 \begin_layout Standard
35189 There is a separate document
35192 \begin_inset LatexCommand index
35200 \begin_inset LatexCommand url
35201 target "http://sdcc.sourceforge.net/doc/test_suite_spec.pdf"
35205 about the regression test suite.
35208 \begin_layout Standard
35209 You'll find the test code in the directory
35211 sdcc/support/regression
35214 You can run these tests manually by running
35218 in this directory (or f.e.
35223 \begin_inset Quotes sld
35227 \begin_inset Quotes srd
35233 if you don't want to run the complete tests).
35234 The test code might also be interesting if you want to look for examples
35235 \begin_inset LatexCommand index
35240 checking corner cases of SDCC or if you plan to submit patches
35241 \begin_inset LatexCommand index
35242 name "Patch submission"
35249 \begin_layout Standard
35250 The PIC14 port uses a different set of regression tests
35251 \begin_inset LatexCommand index
35252 name "Regression test (PIC14)"
35256 , you'll find them in the directory
35258 sdcc/src/regression
35263 \begin_layout Section
35264 Use of SDCC in Education
35267 \begin_layout Standard
35276 \begin_layout Standard
35277 the phrase "use in education" might evoke the association "
35281 fit for use in education".
35282 This connotation is not intended but nevertheless risked as the licensing
35283 of SDCC makes it difficult to offer educational discounts
35289 If your rationales are to:
35292 \begin_layout Enumerate
35293 give students a chance to understand the
35297 steps of code generation
35300 \begin_layout Enumerate
35301 have a curriculum that can be extended for years.
35302 Then you could use an fpga board as target and your curriculum will seamlessly
35303 extend from logic synthesis (
35304 \begin_inset LatexCommand url
35305 name "http://www.opencores.org"
35306 target "opencores.org"
35311 \begin_inset LatexCommand url
35313 target "http://www.oregano.at/ip/ip01.htm"
35317 ), over assembly programming, to C to FPGA compilers (
35318 \begin_inset LatexCommand url
35320 target "http://sf.net/projects/fpgac"
35327 \begin_layout Enumerate
35328 be able to insert excursions about skills like using a revision control
35329 system, submitting/applying patches, using a type-setting (as opposed to
35330 word-processing) engine LyX/LaTeX, using
35331 \begin_inset LatexCommand url
35333 target "http://www.sf.net"
35338 \begin_inset LatexCommand url
35340 target "http://en.wikipedia.org/wiki/Netiquette"
35344 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
35345 Source Software, CPU simulation, compiler regression tests
35346 \begin_inset LatexCommand index
35347 name "Regression test"
35354 And if there should be a shortage of ideas then you can always point students
35355 to the ever-growing feature request list
35356 \begin_inset LatexCommand htmlurl
35357 target "http://sourceforge.net/tracker/?group_id=599&atid=350599"
35364 \begin_layout Enumerate
35365 not tie students to a specific host platform and instead allow them to use
35370 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
35372 \begin_inset LatexCommand url
35374 target "http://www.laptop.org"
35381 \begin_layout Enumerate
35382 not encourage students to use illegal copies of educational software
35385 \begin_layout Enumerate
35386 be immune to licensing/availability/price changes of the chosen tool chain
35389 \begin_layout Enumerate
35390 be able to change to a new target platform without having to adopt a new
35394 \begin_layout Enumerate
35395 have complete control over and insight into the tool chain
35398 \begin_layout Enumerate
35399 make your students aware about the pros and cons of open source software
35403 \begin_layout Enumerate
35404 give back to the public as you are probably at least partially publicly
35408 \begin_layout Enumerate
35409 give students a chance to publicly prove their skills and to possibly see
35410 a world wide impact
35413 \begin_layout Standard
35414 then SDCC is probably among the first choices.
35415 Well, probably SDCC might be the only choice.
35420 \begin_layout Chapter
35421 SDCC Technical Data
35424 \begin_layout Section
35426 \begin_inset LatexCommand index
35427 name "Optimizations"
35434 \begin_layout Standard
35435 SDCC performs a host of standard optimizations in addition to some MCU specific
35440 \begin_layout Subsection
35441 Sub-expression Elimination
35442 \begin_inset LatexCommand index
35443 name "Subexpression elimination"
35450 \begin_layout Standard
35451 The compiler does local and
35470 \begin_layout Verse
35478 \begin_layout Standard
35479 will be translated to
35482 \begin_layout Verse
35492 \begin_layout Standard
35493 Some subexpressions are not as obvious as the above example, e.g.:
35496 \begin_layout Verse
35504 \begin_layout Standard
35505 In this case the address arithmetic a->b[i] will be computed only once;
35506 the equivalent code in C would be.
35509 \begin_layout Verse
35519 \begin_layout Standard
35520 The compiler will try to keep these temporary variables in registers.
35523 \begin_layout Subsection
35524 Dead-Code Elimination
35525 \begin_inset LatexCommand index
35526 name "Dead-code elimination"
35533 \begin_layout Verse
35548 i = 1; \InsetSpace ~
35557 global = 1;\InsetSpace ~
35571 global = 3;\InsetSpace ~
35577 \begin_layout Standard
35581 \begin_layout Verse
35597 \begin_layout Subsection
35599 \begin_inset LatexCommand index
35600 name "Copy propagation"
35607 \begin_layout Verse
35631 \begin_layout Standard
35635 \begin_layout Verse
35659 \begin_layout Standard
35660 Note: the dead stores created by this copy propagation will be eliminated
35661 by dead-code elimination.
35664 \begin_layout Subsection
35666 \begin_inset LatexCommand index
35667 name "Loop optimization"
35672 \begin_inset LatexCommand label
35673 name "sub:Loop-Optimizations"
35680 \begin_layout Standard
35681 Two types of loop optimizations are done by SDCC
35689 of loop induction variables.
35690 In addition to the strength reduction the optimizer marks the induction
35691 variables and the register allocator tries to keep the induction variables
35692 in registers for the duration of the loop.
35693 Because of this preference of the register allocator
35694 \begin_inset LatexCommand index
35695 name "Register allocation"
35699 , loop induction optimization causes an increase in register pressure, which
35700 may cause unwanted spilling of other temporary variables into the stack
35701 \begin_inset LatexCommand index
35707 The compiler will generate a warning message when it is forced to allocate
35708 extra space either on the stack or data space.
35709 If this extra space allocation is undesirable then induction optimization
35710 can be eliminated either for the entire source file (with -
35714 \begin_layout Standard
35723 -noinduction option) or for a given function only using #pragma\InsetSpace ~
35725 \begin_inset LatexCommand index
35726 name "\\#pragma noinduction"
35737 \begin_layout Verse
35740 for (i = 0 ; i < 100 ; i ++)
35749 \begin_layout Standard
35753 \begin_layout Verse
35758 for (i = 0; i < 100; i++)
35767 \begin_layout Standard
35768 As mentioned previously some loop invariants are not as apparent, all static
35769 address computations are also moved out of the loop.
35774 \begin_inset LatexCommand index
35775 name "Strength reduction"
35779 , this optimization substitutes an expression by a cheaper expression:
35782 \begin_layout Verse
35785 for (i=0;i < 100; i++)
35794 \begin_layout Standard
35798 \begin_layout Verse
35805 for (i=0;i< 100;i++) {
35811 ar[itemp1] = itemp2;
35829 \begin_layout Standard
35830 The more expensive multiplication
35831 \begin_inset LatexCommand index
35832 name "Multiplication"
35836 is changed to a less expensive addition.
35839 \begin_layout Subsection
35841 \begin_inset LatexCommand index
35842 name "Loop reversing"
35849 \begin_layout Standard
35850 This optimization is done to reduce the overhead of checking loop boundaries
35851 for every iteration.
35852 Some simple loops can be reversed and implemented using a
35853 \begin_inset Quotes eld
35856 decrement and jump if not zero
35857 \begin_inset Quotes erd
35861 SDCC checks for the following criterion to determine if a loop is reversible
35862 (note: more sophisticated compilers use data-dependency analysis to make
35863 this determination, SDCC uses a more simple minded analysis).
35866 \begin_layout Itemize
35867 The 'for' loop is of the form
35873 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
35883 \begin_layout Itemize
35884 The <for body> does not contain
35885 \begin_inset Quotes eld
35889 \begin_inset Quotes erd
35893 \begin_inset Quotes erd
35899 \begin_layout Itemize
35900 All goto's are contained within the loop.
35903 \begin_layout Itemize
35904 No function calls within the loop.
35907 \begin_layout Itemize
35908 The loop control variable <sym> is not assigned any value within the loop
35911 \begin_layout Itemize
35912 The loop control variable does NOT participate in any arithmetic operation
35916 \begin_layout Itemize
35917 There are NO switch statements in the loop.
35920 \begin_layout Subsection
35921 Algebraic Simplifications
35924 \begin_layout Standard
35925 SDCC does numerous algebraic simplifications, the following is a small sub-set
35926 of these optimizations.
35929 \begin_layout Verse
35932 i = j + 0;\InsetSpace ~
35936 /* changed to: */\InsetSpace ~
35942 i /= 2;\InsetSpace ~
35949 /* changed to: */\InsetSpace ~
35956 = j - j;\InsetSpace ~
35960 /* changed to: */\InsetSpace ~
35966 i = j / 1;\InsetSpace ~
35970 /* changed to: */\InsetSpace ~
35977 \begin_layout Standard
35978 Note the subexpressions
35979 \begin_inset LatexCommand index
35980 name "Subexpression"
35984 given above are generally introduced by macro expansions or as a result
35985 of copy/constant propagation.
35988 \begin_layout Subsection
35989 'switch' Statements
35990 \begin_inset LatexCommand label
35991 name "sub:'switch'-Statements"
35996 \begin_inset LatexCommand index
35997 name "switch statement"
36004 \begin_layout Standard
36005 SDCC can optimize switch statements to jump tables
36006 \begin_inset LatexCommand index
36012 It makes the decision based on an estimate of the generated code size.
36013 SDCC is quite liberal in the requirements for jump table generation:
36016 \begin_layout Itemize
36017 The labels need not be in order, and the starting number need not be one
36018 or zero, the case labels are in numerical sequence or not too many case
36019 labels are missing.
36023 \begin_layout Verse
36026 switch(i) {\InsetSpace ~
36057 case 4: ...\InsetSpace ~
36089 case 5: ...\InsetSpace ~
36121 case 3: ...\InsetSpace ~
36152 case 6: ...\InsetSpace ~
36184 case 7: ...\InsetSpace ~
36216 case 8: ...\InsetSpace ~
36248 case 9: ...\InsetSpace ~
36280 case 10: ...\InsetSpace ~
36311 case 11: ...\InsetSpace ~
36378 \begin_layout Standard
36379 Both the above switch statements will be implemented using a jump-table.
36380 The example to the right side is slightly more efficient as the check for
36381 the lower boundary of the jump-table is not needed.
36385 \begin_layout Itemize
36386 The number of case labels is not larger than supported by the target architectur
36390 \begin_layout Itemize
36391 If the case labels are not in numerical sequence ('gaps' between cases)
36392 SDCC checks whether a jump table with additionally inserted dummy cases
36393 is still attractive.
36397 \begin_layout Itemize
36398 If the starting number is not zero and a check for the lower boundary of
36399 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
36404 \begin_layout Standard
36405 Switch statements which have large gaps in the numeric sequence or those
36406 that have too many case labels can be split into more than one switch statement
36407 for efficient code generation, e.g.:
36410 \begin_layout Verse
36488 \begin_layout Standard
36489 If the above switch statement is broken down into two switch statements
36492 \begin_layout Verse
36535 \begin_layout Standard
36539 \begin_layout Verse
36582 \begin_layout Standard
36583 then both the switch statements will be implemented using jump-tables whereas
36584 the unmodified switch statement will not be.
36587 \begin_layout Standard
36588 \begin_inset Note Note
36591 \begin_layout Standard
36592 There might be reasons which SDCC cannot know about to either favour or
36593 not favour jump tables.
36594 If the target system has to be as quick for the last switch case as for
36595 the first (pro jump table), or if the switch argument is known to be zero
36596 in the majority of the cases (contra jump table).
36604 \begin_layout Standard
36605 The pragma nojtbound
36606 \begin_inset LatexCommand index
36607 name "\\#pragma nojtbound"
36611 can be used to turn off checking the
36624 It has no effect if a default label is supplied.
36625 Use of this pragma is dangerous: if the switch
36626 \begin_inset LatexCommand index
36627 name "switch statement"
36631 argument is not matched by a case statement the processor will happily
36635 \begin_layout Subsection
36636 Bit-shifting Operations
36637 \begin_inset LatexCommand index
36638 name "Bit shifting"
36645 \begin_layout Standard
36646 Bit shifting is one of the most frequently used operation in embedded programmin
36648 SDCC tries to implement bit-shift operations in the most efficient way
36652 \begin_layout Verse
36665 \begin_layout Standard
36666 generates the following code:
36669 \begin_layout Verse
36684 \begin_layout Standard
36685 In general SDCC will never setup a loop if the shift count is known.
36689 \begin_layout Verse
36702 \begin_layout Standard
36706 \begin_layout Verse
36730 \begin_layout Subsection
36732 \begin_inset LatexCommand index
36733 name "Bit rotation"
36740 \begin_layout Standard
36741 A special case of the bit-shift operation is bit rotation
36742 \begin_inset LatexCommand index
36743 name "rotating bits"
36747 , SDCC recognizes the following expression to be a left bit-rotation:
36750 \begin_layout Verse
36758 char i;\InsetSpace ~
36769 /* unsigned is needed for rotation */
36774 i = ((i << 1) | (i >> 7));
36783 \begin_layout Standard
36784 will generate the following code:
36787 \begin_layout Verse
36804 \begin_layout Standard
36805 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
36806 ns of this case will also be recognized as bit-rotation, i.e.:
36809 \begin_layout Verse
36812 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
36815 \begin_layout Subsection
36816 Nibble and Byte Swapping
36819 \begin_layout Standard
36820 Other special cases of the bit-shift operations are nibble or byte swapping
36821 \begin_inset LatexCommand index
36822 name "swapping nibbles/bytes"
36826 , SDCC recognizes the following expressions:
36829 \begin_layout Verse
36850 i = ((i << 4) | (i >> 4));
36856 j = ((j << 8) | (j >> 8));
36859 \begin_layout Standard
36860 and generates a swap instruction for the nibble swapping
36861 \begin_inset LatexCommand index
36862 name "Nibble swapping"
36866 or move instructions for the byte swapping
36867 \begin_inset LatexCommand index
36868 name "Byte swapping"
36874 \begin_inset Quotes sld
36878 \begin_inset Quotes srd
36881 example can be used to convert from little to big-endian or vice versa.
36882 If you want to change the endianness of a
36886 integer you have to cast to
36893 \begin_layout Standard
36894 Note that SDCC stores numbers in little-endian
36898 \begin_layout Standard
36899 Usually 8-bit processors don't care much about endianness.
36900 This is not the case for the standard 8051 which only has an instruction
36906 \begin_inset LatexCommand index
36911 -datapointer so little-endian is the more efficient byte order.
36917 \begin_inset LatexCommand index
36918 name "little-endian"
36923 \begin_inset LatexCommand index
36929 lowest order first).
36932 \begin_layout Subsection
36934 \begin_inset LatexCommand index
36935 name "Highest Order Bit"
36940 \begin_inset LatexCommand index
36941 name "Any Order Bit"
36948 \begin_layout Standard
36949 It is frequently required to obtain the highest order bit of an integral
36950 type (long, int, short or char types).
36951 Also obtaining any other order bit is not uncommon.
36952 SDCC recognizes the following expressions to yield the highest order bit
36953 and generates optimized code for it, e.g.:
36956 \begin_layout Verse
36967 unsigned char hob1, aob1;
36971 bit hob2, hob3, aob2,
36981 hob1 = (gint >> 15) & 1;
36985 hob2 = (gint >> 15) & 1;
36989 hob3 = gint & 0x8000;
36994 aob1 = (gint >> 9) & 1;
36998 aob2 = (gint >> 8) & 1;
37002 aob3 = gint & 0x0800;
37012 \begin_layout Standard
37013 will generate the following code:
37016 \begin_layout Verse
37047 000A E5*01\InsetSpace ~
37074 000C 23\InsetSpace ~
37105 000D 54 01\InsetSpace ~
37133 000F F5*02\InsetSpace ~
37188 0011 E5*01\InsetSpace ~
37216 0013 33\InsetSpace ~
37246 0014 92*00\InsetSpace ~
37302 0016 E5*01\InsetSpace ~
37329 0018 33\InsetSpace ~
37359 0019 92*01\InsetSpace ~
37415 001B E5*01\InsetSpace ~
37474 001E 54 01\InsetSpace ~
37501 0020 F5*03\InsetSpace ~
37557 0022 E5*01\InsetSpace ~
37584 0024 13\InsetSpace ~
37614 0025 92*02\InsetSpace ~
37670 0027 E5*01\InsetSpace ~
37725 002B 92*03\InsetSpace ~
37753 \begin_layout Standard
37754 Other variations of these cases however will
37759 They are standard C expressions, so I heartily recommend these be the only
37760 way to get the highest order bit, (it is portable).
37761 Of course it will be recognized even if it is embedded in other expressions,
37765 \begin_layout Verse
37768 xyz = gint + ((gint >> 15) & 1);
37771 \begin_layout Standard
37772 will still be recognized.
37775 \begin_layout Subsection
37777 \begin_inset LatexCommand index
37778 name "Higher Order Byte"
37782 / Higher Order Word
37783 \begin_inset LatexCommand index
37784 name "Higher Order Word"
37791 \begin_layout Standard
37792 It is also frequently required to obtain a higher order byte or word of
37793 a larger integral type (long, int or short types).
37794 SDCC recognizes the following expressions to yield the higher order byte
37795 or word and generates optimized code for it, e.g.:
37798 \begin_layout Verse
37803 unsigned long int glong;
37811 unsigned char hob1,
37816 unsigned int how1, how2;
37825 hob1 = (gint >> 8) & 0xFF;
37829 hob2 = glong >> 24;
37833 how1 = (glong >> 16) & 0xFFFF;
37848 \begin_layout Standard
37849 will generate the following code:
37852 \begin_layout Verse
37883 0037 85*01*06\InsetSpace ~
37905 _foo_hob1_1_1,(_gint + 1)
37936 003A 85*05*07\InsetSpace ~
37958 _foo_hob2_1_1,(_glong + 3)
37988 003D 85*04*08\InsetSpace ~
38011 _foo_how1_1_1,(_glong + 2)
38013 0040 85*05*09\InsetSpace ~
38038 0043 85*03*0A\InsetSpace ~
38060 _foo_how2_1_1,(_glong + 1)
38062 0046 85*04*0B\InsetSpace ~
38085 (_foo_how2_1_1 + 1),(_glong + 2)
38088 \begin_layout Standard
38089 Again, variations of these cases may
38094 They are standard C expressions, so I heartily recommend these be the only
38095 way to get the higher order byte/word, (it is portable).
38096 Of course it will be recognized even if it is embedded in other expressions,
38100 \begin_layout Verse
38103 xyz = gint + ((gint >> 8) & 0xFF);
38106 \begin_layout Standard
38107 will still be recognized.
38110 \begin_layout Subsection
38112 \begin_inset LatexCommand label
38113 name "sub:Peephole-Optimizer"
38118 \begin_inset LatexCommand index
38119 name "Peephole optimizer"
38126 \begin_layout Standard
38127 The compiler uses a rule based, pattern matching and re-writing mechanism
38128 for peep-hole optimization.
38133 a peep-hole optimizer by Christopher W.
38134 Fraser (cwfraser\InsetSpace ~
38137 A default set of rules are compiled into the compiler, additional rules
38138 may be added with the
38144 \begin_layout Standard
38154 \begin_inset LatexCommand index
38155 name "-\\/-peep-file"
38162 The rule language is best illustrated with examples.
38165 \begin_layout Verse
38187 \begin_layout Standard
38188 The above rule will change the following assembly
38189 \begin_inset LatexCommand index
38190 name "Assembler routines"
38197 \begin_layout Verse
38205 \begin_layout Standard
38209 \begin_layout Verse
38215 \begin_layout Standard
38216 Note: All occurrences of a
38220 (pattern variable) must denote the same string.
38221 With the above rule, the assembly sequence:
38224 \begin_layout Verse
38232 \begin_layout Standard
38233 will remain unmodified.
38237 Other special case optimizations may be added by the
38244 \begin_layout Standard
38257 some variants of the 8051 MCU
38258 \begin_inset LatexCommand index
38259 name "MCS51 variants"
38272 The following two rules will change all
38289 \begin_layout Verse
38292 replace { lcall %1 } by { acall %1 }
38294 replace { ljmp %1 } by { ajmp %1 }
38297 \begin_layout Standard
38298 (NOTE: from version 2.7.3 on, you can use option -
38304 \begin_layout Standard
38316 \begin_inset LatexCommand index
38317 name "-\\/-acall-ajmp"
38321 , which also takes care of aligning the interrupt vectors properly.)
38326 \begin_layout Standard
38329 inline-assembler code
38331 is also passed through the peep hole optimizer, thus the peephole optimizer
38332 can also be used as an assembly level macro expander.
38333 The rules themselves are MCU dependent whereas the rule language infra-structur
38334 e is MCU independent.
38335 Peephole optimization rules for other MCU can be easily programmed using
38340 The syntax for a rule is as follows:
38343 \begin_layout Verse
38346 rule := replace [ restart ] '{' <assembly sequence> '
38384 <assembly sequence> '
38402 '}' [if <functionName> ] '
38407 \begin_layout Standard
38408 <assembly sequence> := assembly instruction (each instruction including
38409 labels must be on a separate line).
38413 The optimizer will apply to the rules
38414 one by one from the top in the sequence of their appearance, it will terminate
38415 when all rules are exhausted.
38416 If the 'restart' option is specified, then the optimizer will start matching
38417 the rules again from the top, this option for a rule is expensive (performance)
38418 , it is intended to be used in situations where a transformation will trigger
38419 the same rule again.
38420 An example of this (not a good one, it has side effects) is the following
38424 \begin_layout Verse
38444 \begin_layout Standard
38445 Note that the replace pattern cannot be a blank, but can be a comment line.
38446 Without the 'restart' option only the innermost 'pop' 'push' pair would
38447 be eliminated, i.e.:
38450 \begin_layout Verse
38462 \begin_layout Standard
38466 \begin_layout Verse
38476 \begin_layout Standard
38481 the restart option the rule will be applied again to the resulting code
38482 and then all the pop-push pairs will be eliminated to yield:
38485 \begin_layout Verse
38493 \begin_layout Standard
38494 A conditional function can be attached to a rule.
38495 Attaching rules are somewhat more involved, let me illustrate this with
38499 \begin_layout Verse
38523 \begin_layout Standard
38524 The optimizer does a look-up of a function name table defined in function
38529 in the source file SDCCpeeph.c, with the name
38534 If it finds a corresponding entry the function is called.
38535 Note there can be no parameters specified for these functions, in this
38540 is crucial, since the function
38544 expects to find the label in that particular variable (the hash table containin
38545 g the variable bindings is passed as a parameter).
38546 If you want to code more such functions, take a close look at the function
38547 labelInRange and the calling mechanism in source file SDCCpeeph.c.
38548 Currently implemented are
38550 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
38551 24bitMode, portIsDS390, 24bitModeAndPortDS390
38560 \begin_layout Standard
38561 I know this whole thing is a little kludgey, but maybe some day we will
38562 have some better means.
38563 If you are looking at this file, you will see the default rules that are
38564 compiled into the compiler, you can add your own rules in the default set
38565 there if you get tired of specifying the -
38569 \begin_layout Standard
38581 \begin_layout Section
38583 \begin_inset LatexCommand index
38584 name "ANSI-compliance"
38589 \begin_inset LatexCommand label
38590 name "sub:ANSI-Compliance"
38597 \begin_layout Standard
38598 The latest publicly available version of the standard
38600 ISO/IEC 9899 - Programming languages - C
38602 should be available at:
38603 \begin_inset LatexCommand url
38604 target "http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899"
38613 \begin_layout Standard
38614 Deviations from the compliance:
38617 \begin_layout Itemize
38618 functions are not reentrant
38619 \begin_inset LatexCommand index
38624 unless explicitly declared as such or the
38630 \begin_layout Standard
38640 \begin_inset LatexCommand index
38641 name "-\\/-stack-auto"
38647 command line option is specified.
38650 \begin_layout Itemize
38652 \begin_inset LatexCommand index
38658 \begin_inset LatexCommand index
38663 cannot be assigned values directly, cannot be passed as function parameters
38664 or assigned to each other and cannot be a return value
38665 \begin_inset LatexCommand index
38666 name "return value"
38670 from a function, e.g.:
38674 \begin_layout Verse
38697 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
38722 s parms) /* invalid in SDCC although allowed in ANSI */
38744 return rets; /* is invalid in SDCC although allowed in ANSI */
38750 \begin_layout Itemize
38751 initialization of structure arrays must be fully braced.
38755 \begin_layout Verse
38758 struct s { char x } a[] = {1, 2};\InsetSpace ~
38763 /* invalid in SDCC */
38766 } a[] = {{1}, {2}}; /* OK */
38770 \begin_layout Itemize
38772 \begin_inset LatexCommand index
38773 name "long long (not supported)"
38778 \begin_inset LatexCommand index
38779 name "int (64 bit) (not supported)"
38786 \begin_layout Itemize
38788 \begin_inset LatexCommand index
38789 name "double (not supported)"
38793 ' precision floating point
38794 \begin_inset LatexCommand index
38795 name "Floating point support"
38802 \begin_layout Itemize
38804 \begin_inset LatexCommand index
38809 function declarations are NOT allowed.
38813 \begin_layout Verse
38816 foo(i,j) /* this old style of function declarations */
38818 int i,j; /* is valid
38819 in ANSI but not valid in SDCC */
38834 \begin_layout Itemize
38835 Most enhancements in C99 are not supported, e.g.:
38839 \begin_layout Verse
38849 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
38853 \begin_layout Itemize
38854 But some have been added recently in SDCC 2.7.0.
38855 They must be considered alpha quality however.
38859 \begin_layout Verse
38864 \begin_inset LatexCommand index
38865 name "inline (not supported)"
38874 int increment (int a) { return a+1; } /* inlines the increment without function
38883 \begin_inset LatexCommand index
38884 name "inline (not supported)"
38893 p; /* accepted but ignored */
38897 \begin_layout Itemize
38898 Certain words that are valid identifiers in the standard may be reserved
38899 words in SDCC unless the
38905 \begin_layout Standard
38915 \begin_inset LatexCommand index
38916 name "-\\/-std-c89"
38928 \begin_layout Standard
38938 \begin_inset LatexCommand index
38939 name "-\\/-std-c99"
38945 command line options are used.
38946 These may include (depending on the selected processor): 'at', 'banked',
38947 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
38948 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
38949 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
38951 Compliant equivalents of these keywords are always available in a form
38952 that begin with two underscores
38953 \begin_inset LatexCommand index
38954 name "\\_\\_ (prefix for extended keywords)"
38959 '__data' instead of 'data'.
38962 \begin_layout Itemize
38963 Integer promotion of variable arguments is not performed if the argument
38964 is explicitly taypecasted unless the
38970 \begin_layout Standard
38980 \begin_inset LatexCommand index
38981 name "-\\/-std-c89"
38993 \begin_layout Standard
39003 \begin_inset LatexCommand index
39004 name "-\\/-std-c99"
39010 command line options are used.
39014 \begin_layout Verse
39017 void vararg_func (char *str, ...) { str; }
39034 u is promoted to int before
39039 * passing to function */
39043 vararg_func ("%c", c);
39050 argument u is not promoted to int,
39055 * it is passed as char to function
39061 --std-cXX is not defined;
39066 * is promoted to int before passing
39072 if --std-cXX is defined */
39076 vararg_func ("%bc", (char)u);
39082 \begin_layout Section
39083 Cyclomatic Complexity
39084 \begin_inset LatexCommand index
39085 name "Cyclomatic complexity"
39092 \begin_layout Standard
39093 Cyclomatic complexity of a function is defined as the number of independent
39094 paths the program can take during execution of the function.
39095 This is an important number since it defines the number test cases you
39096 have to generate to validate the function.
39097 The accepted industry standard for complexity number is 10, if the cyclomatic
39098 complexity reported by SDCC exceeds 10 you should think about simplification
39099 of the function logic.
39100 Note that the complexity level is not related to the number of lines of
39101 code in a function.
39102 Large functions can have low complexity, and small functions can have large
39108 SDCC uses the following formula to compute the complexity:
39113 \begin_layout Standard
39114 complexity = (number of edges in control flow graph) - (number of nodes
39115 in control flow graph) + 2;
39119 Having said that the industry standard is 10,
39120 you should be aware that in some cases it be may unavoidable to have a
39121 complexity level of less than 10.
39122 For example if you have switch statement with more than 10 case labels,
39123 each case label adds one to the complexity level.
39124 The complexity level is by no means an absolute measure of the algorithmic
39125 complexity of the function, it does however provide a good starting point
39126 for which functions you might look at for further optimization.
39129 \begin_layout Section
39130 Retargetting for other Processors
39133 \begin_layout Standard
39134 The issues for retargetting the compiler are far too numerous to be covered
39136 What follows is a brief description of each of the seven phases of the
39137 compiler and its MCU dependency.
39140 \begin_layout Itemize
39141 Parsing the source and building the annotated parse tree.
39142 This phase is largely MCU independent (except for the language extensions).
39143 Syntax & semantic checks are also done in this phase, along with some initial
39144 optimizations like back patching labels and the pattern matching optimizations
39145 like bit-rotation etc.
39148 \begin_layout Itemize
39149 The second phase involves generating an intermediate code which can be easy
39150 manipulated during the later phases.
39151 This phase is entirely MCU independent.
39152 The intermediate code generation assumes the target machine has unlimited
39153 number of registers, and designates them with the name iTemp.
39154 The compiler can be made to dump a human readable form of the code generated
39159 \begin_layout Standard
39171 \begin_layout Itemize
39172 This phase does the bulk of the standard optimizations and is also MCU independe
39174 This phase can be broken down into several sub-phases:
39178 Break down intermediate
39179 code (iCode) into basic blocks.
39181 Do control flow & data flow analysis on the
39184 Do local common subexpression elimination, then global subexpressio
39187 Dead code elimination
39191 If loop optimizations
39192 caused any changes then do 'global subexpression elimination' and 'dead
39193 code elimination' again.
39196 \begin_layout Itemize
39197 This phase determines the live-ranges; by live range I mean those iTemp
39198 variables defined by the compiler that still survive after all the optimization
39200 Live range analysis
39201 \begin_inset LatexCommand index
39202 name "Live range analysis"
39206 is essential for register allocation, since these computation determines
39207 which of these iTemps will be assigned to registers, and for how long.
39210 \begin_layout Itemize
39211 Phase five is register allocation.
39212 There are two parts to this process.
39216 The first part I call 'register packing'
39217 (for lack of a better term).
39218 In this case several MCU specific expression folding is done to reduce
39223 The second part is more MCU independent and deals with
39224 allocating registers to the remaining live ranges.
39225 A lot of MCU specific code does creep into this phase because of the limited
39226 number of index registers available in the 8051.
39229 \begin_layout Itemize
39230 The Code generation phase is (unhappily), entirely MCU dependent and very
39231 little (if any at all) of this code can be reused for other MCU.
39232 However the scheme for allocating a homogenized assembler operand for each
39233 iCode operand may be reused.
39236 \begin_layout Itemize
39237 As mentioned in the optimization section the peep-hole optimizer is rule
39238 based system, which can reprogrammed for other MCUs.
39241 \begin_layout Standard
39242 More information is available on SDCC Wiki
39243 \begin_inset LatexCommand index
39249 \begin_inset LatexCommand url
39250 target "http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting"
39254 ) and in the thread
39255 \begin_inset LatexCommand url
39256 target "http://sf.net/mailarchive/message.php?msg_id=13954144"
39263 \begin_layout Chapter
39265 \begin_inset LatexCommand index
39266 name "Compiler internals"
39273 \begin_layout Section
39274 The anatomy of the compiler
39275 \begin_inset LatexCommand label
39276 name "sub:The-anatomy-of"
39283 \begin_layout Standard
39286 This is an excerpt from an article published in Circuit Cellar Magazine
39295 It's a little outdated (the compiler is much more efficient now and user/develo
39296 per friendly), but pretty well exposes the guts of it all.
39302 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
39303 It is fairly easy to retarget for other 8-bit MCU.
39304 Here we take a look at some of the internals of the compiler.
39308 \begin_layout Paragraph*
39310 \begin_inset LatexCommand index
39318 \begin_layout Standard
39319 Parsing the input source file and creating an AST (Annotated Syntax Tree
39320 \begin_inset LatexCommand index
39321 name "Annotated syntax tree"
39326 This phase also involves propagating types (annotating each node of the
39327 parse tree with type information) and semantic analysis.
39328 There are some MCU specific parsing rules.
39329 For example the storage classes, the extended storage classes are MCU specific
39330 while there may be a xdata storage class for 8051 there is no such storage
39331 class for z80 or Atmel AVR.
39332 SDCC allows MCU specific storage class extensions, i.e.
39333 xdata will be treated as a storage class specifier when parsing 8051 C
39334 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
39338 \begin_layout Paragraph*
39340 \begin_inset LatexCommand index
39348 \begin_layout Standard
39349 Intermediate code generation.
39350 In this phase the AST is broken down into three-operand form (iCode).
39351 These three operand forms are represented as doubly linked lists.
39352 ICode is the term given to the intermediate form generated by the compiler.
39353 ICode example section shows some examples of iCode generated for some simple
39354 C source functions.
39357 \begin_layout Paragraph*
39359 \begin_inset LatexCommand index
39360 name "Optimizations"
39367 \begin_layout Standard
39368 Bulk of the target independent optimizations is performed in this phase.
39369 The optimizations include constant propagation, common sub-expression eliminati
39370 on, loop invariant code movement, strength reduction of loop induction variables
39371 and dead-code elimination.
39374 \begin_layout Paragraph*
39375 Live range analysis
39376 \begin_inset LatexCommand index
39377 name "Live range analysis"
39384 \begin_layout Standard
39385 During intermediate code generation phase, the compiler assumes the target
39386 machine has infinite number of registers and generates a lot of temporary
39388 The live range computation determines the lifetime of each of these compiler-ge
39389 nerated temporaries.
39390 A picture speaks a thousand words.
39391 ICode example sections show the live range annotations for each of the
39393 It is important to note here, each iCode is assigned a number in the order
39394 of its execution in the function.
39395 The live ranges are computed in terms of these numbers.
39396 The from number is the number of the iCode which first defines the operand
39397 and the to number signifies the iCode which uses this operand last.
39400 \begin_layout Paragraph*
39401 Register Allocation
39402 \begin_inset LatexCommand index
39403 name "Register allocation"
39410 \begin_layout Standard
39411 The register allocation determines the type and number of registers needed
39413 In most MCUs only a few registers can be used for indirect addressing.
39414 In case of 8051 for example the registers R0 & R1 can be used to indirectly
39415 address the internal ram and DPTR to indirectly address the external ram.
39416 The compiler will try to allocate the appropriate register to pointer variables
39418 ICode example section shows the operands annotated with the registers assigned
39420 The compiler will try to keep operands in registers as much as possible;
39421 there are several schemes the compiler uses to do achieve this.
39422 When the compiler runs out of registers the compiler will check to see
39423 if there are any live operands which is not used or defined in the current
39424 basic block being processed, if there are any found then it will push that
39425 operand and use the registers in this block, the operand will then be popped
39426 at the end of the basic block.
39430 \begin_layout Standard
39431 There are other MCU specific considerations in this phase.
39432 Some MCUs have an accumulator; very short-lived operands could be assigned
39433 to the accumulator instead of a general-purpose register.
39436 \begin_layout Paragraph*
39440 \begin_layout Standard
39441 Figure II gives a table of iCode
39442 \begin_inset LatexCommand index
39447 operations supported by the compiler.
39448 The code generation involves translating these operations into corresponding
39449 assembly code for the processor.
39450 This sounds overly simple but that is the essence of code generation.
39451 Some of the iCode operations are generated on a MCU specific manner for
39452 example, the z80 port does not use registers to pass parameters so the
39453 SEND and RECV iCode operations will not be generated, and it also does
39454 not support JUMPTABLES.
39460 \begin_layout Standard
39464 \begin_inset Tabular
39465 <lyxtabular version="3" rows="39" columns="4">
39466 <features islongtable="true" headBottomDL="true">
39467 <column alignment="block" valignment="top" leftline="true" width="13col%">
39468 <column alignment="left" valignment="top" leftline="true" width="13col%">
39469 <column alignment="block" valignment="top" leftline="true" width="22col%">
39470 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
39471 <row topline="true" bottomline="true" endhead="true">
39472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39475 \begin_layout Standard
39481 \begin_inset LatexCommand index
39491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39494 \begin_layout Standard
39502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39505 \begin_layout Standard
39513 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39516 \begin_layout Standard
39525 <row topline="true">
39526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39529 \begin_layout Standard
39537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39540 \begin_layout Standard
39543 IC_LEFT() IC_RESULT()
39548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39551 \begin_layout Standard
39559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39562 \begin_layout Standard
39565 IC_RESULT = ! IC_LEFT;
39571 <row topline="true">
39572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39575 \begin_layout Standard
39583 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39586 \begin_layout Standard
39589 IC_LEFT() IC_RESULT()
39594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39597 \begin_layout Standard
39600 Bitwise complement of
39605 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39608 \begin_layout Standard
39611 IC_RESULT = ~IC_LEFT;
39617 <row topline="true">
39618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39621 \begin_layout Standard
39629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39632 \begin_layout Standard
39635 IC_LEFT() IC_RESULT()
39640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39643 \begin_layout Standard
39646 Rotate right with carry
39651 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39654 \begin_layout Standard
39657 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
39663 <row topline="true">
39664 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39667 \begin_layout Standard
39675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39678 \begin_layout Standard
39681 IC_LEFT() IC_RESULT()
39686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39689 \begin_layout Standard
39692 Rotate left with carry
39697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39700 \begin_layout Standard
39703 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
39709 <row topline="true">
39710 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39713 \begin_layout Standard
39721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39724 \begin_layout Standard
39727 IC_LEFT() IC_RESULT()
39732 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39735 \begin_layout Standard
39738 Get the highest order bit of IC_LEFT
39743 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39746 \begin_layout Standard
39749 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
39755 <row topline="true">
39756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39759 \begin_layout Standard
39767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39770 \begin_layout Standard
39773 IC_LEFT() IC_RESULT()
39778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39781 \begin_layout Standard
39789 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39792 \begin_layout Standard
39795 IC_RESULT = - IC_LEFT;
39801 <row topline="true">
39802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39805 \begin_layout Standard
39813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39816 \begin_layout Standard
39824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39827 \begin_layout Standard
39830 Push the operand into stack
39835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39838 \begin_layout Standard
39847 <row topline="true">
39848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39851 \begin_layout Standard
39859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39862 \begin_layout Standard
39870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39873 \begin_layout Standard
39876 Pop the operand from the stack
39881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39884 \begin_layout Standard
39893 <row topline="true">
39894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39897 \begin_layout Standard
39905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39908 \begin_layout Standard
39911 IC_LEFT() IC_RESULT()
39916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39919 \begin_layout Standard
39922 Call the function represented by IC_LEFT
39927 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39930 \begin_layout Standard
39933 IC_RESULT = IC_LEFT();
39939 <row topline="true">
39940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39943 \begin_layout Standard
39951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39954 \begin_layout Standard
39957 IC_LEFT() IC_RESULT()
39962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39965 \begin_layout Standard
39968 Call via function pointer
39973 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39976 \begin_layout Standard
39979 IC_RESULT = (*IC_LEFT)();
39985 <row topline="true">
39986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39989 \begin_layout Standard
39997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40000 \begin_layout Standard
40008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40011 \begin_layout Standard
40014 Return the value in operand IC_LEFT
40019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40022 \begin_layout Standard
40031 <row topline="true">
40032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40035 \begin_layout Standard
40043 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40046 \begin_layout Standard
40054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40057 \begin_layout Standard
40065 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40068 \begin_layout Standard
40077 <row topline="true">
40078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40081 \begin_layout Standard
40089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40092 \begin_layout Standard
40100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40103 \begin_layout Standard
40111 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40114 \begin_layout Standard
40123 <row topline="true">
40124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40127 \begin_layout Standard
40135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40138 \begin_layout Standard
40141 IC_LEFT() IC_RIGHT() IC_RESULT()
40146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40149 \begin_layout Standard
40157 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40160 \begin_layout Standard
40163 IC_RESULT = IC_LEFT + IC_RIGHT
40169 <row topline="true">
40170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40173 \begin_layout Standard
40181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40184 \begin_layout Standard
40187 IC_LEFT() IC_RIGHT() IC_RESULT()
40192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40195 \begin_layout Standard
40203 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40206 \begin_layout Standard
40209 IC_RESULT = IC_LEFT - IC_RIGHT
40215 <row topline="true">
40216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40219 \begin_layout Standard
40227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40230 \begin_layout Standard
40233 IC_LEFT() IC_RIGHT() IC_RESULT()
40238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40241 \begin_layout Standard
40249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40252 \begin_layout Standard
40255 IC_RESULT = IC_LEFT * IC_RIGHT;
40261 <row topline="true">
40262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40265 \begin_layout Standard
40273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40276 \begin_layout Standard
40279 IC_LEFT() IC_RIGHT() IC_RESULT()
40284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40287 \begin_layout Standard
40295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40298 \begin_layout Standard
40301 IC_RESULT = IC_LEFT / IC_RIGHT;
40307 <row topline="true">
40308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40311 \begin_layout Standard
40319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40322 \begin_layout Standard
40325 IC_LEFT() IC_RIGHT() IC_RESULT()
40330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40333 \begin_layout Standard
40341 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40344 \begin_layout Standard
40347 IC_RESULT = IC_LEFT % IC_RIGHT;
40353 <row topline="true">
40354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40357 \begin_layout Standard
40365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40368 \begin_layout Standard
40371 IC_LEFT() IC_RIGHT() IC_RESULT()
40376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40379 \begin_layout Standard
40387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40390 \begin_layout Standard
40393 IC_RESULT = IC_LEFT < IC_RIGHT;
40399 <row topline="true">
40400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40403 \begin_layout Standard
40411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40414 \begin_layout Standard
40417 IC_LEFT() IC_RIGHT() IC_RESULT()
40422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40425 \begin_layout Standard
40433 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40436 \begin_layout Standard
40439 IC_RESULT = IC_LEFT > IC_RIGHT;
40445 <row topline="true">
40446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40449 \begin_layout Standard
40457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40460 \begin_layout Standard
40463 IC_LEFT() IC_RIGHT() IC_RESULT()
40468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40471 \begin_layout Standard
40479 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40482 \begin_layout Standard
40485 IC_RESULT = IC_LEFT == IC_RIGHT;
40491 <row topline="true">
40492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40495 \begin_layout Standard
40503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40506 \begin_layout Standard
40509 IC_LEFT() IC_RIGHT() IC_RESULT()
40514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40517 \begin_layout Standard
40520 Logical and operation
40525 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40528 \begin_layout Standard
40531 IC_RESULT = IC_LEFT && IC_RIGHT;
40537 <row topline="true">
40538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40541 \begin_layout Standard
40549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40552 \begin_layout Standard
40555 IC_LEFT() IC_RIGHT() IC_RESULT()
40560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40563 \begin_layout Standard
40566 Logical or operation
40571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40574 \begin_layout Standard
40577 IC_RESULT = IC_LEFT || IC_RIGHT;
40583 <row topline="true">
40584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40587 \begin_layout Standard
40595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40598 \begin_layout Standard
40601 IC_LEFT() IC_RIGHT() IC_RESULT()
40606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40609 \begin_layout Standard
40617 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40620 \begin_layout Standard
40623 IC_RESULT = IC_LEFT ^ IC_RIGHT;
40629 <row topline="true">
40630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40633 \begin_layout Standard
40641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40644 \begin_layout Standard
40647 IC_LEFT() IC_RIGHT() IC_RESULT()
40652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40655 \begin_layout Standard
40663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40666 \begin_layout Standard
40669 IC_RESULT = IC_LEFT | IC_RIGHT;
40675 <row topline="true">
40676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40679 \begin_layout Standard
40687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40690 \begin_layout Standard
40693 IC_LEFT() IC_RIGHT() IC_RESULT()
40698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40701 \begin_layout Standard
40709 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40712 \begin_layout Standard
40715 IC_RESULT = IC_LEFT & IC_RIGHT;
40721 <row topline="true">
40722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40725 \begin_layout Standard
40733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40736 \begin_layout Standard
40739 IC_LEFT() IC_RIGHT() IC_RESULT()
40744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40747 \begin_layout Standard
40755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40758 \begin_layout Standard
40761 IC_RESULT = IC_LEFT << IC_RIGHT
40767 <row topline="true">
40768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40771 \begin_layout Standard
40779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40782 \begin_layout Standard
40785 IC_LEFT() IC_RIGHT() IC_RESULT()
40790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40793 \begin_layout Standard
40801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40804 \begin_layout Standard
40807 IC_RESULT = IC_LEFT >> IC_RIGHT
40813 <row topline="true">
40814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40817 \begin_layout Standard
40827 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40830 \begin_layout Standard
40833 IC_LEFT() IC_RESULT()
40838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40841 \begin_layout Standard
40849 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40852 \begin_layout Standard
40855 IC_RESULT = (*IC_LEFT);
40861 <row topline="true">
40862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40865 \begin_layout Standard
40873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40876 \begin_layout Standard
40879 IC_RIGHT() IC_RESULT()
40884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40887 \begin_layout Standard
40895 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40898 \begin_layout Standard
40901 (*IC_RESULT) = IC_RIGHT;
40907 <row topline="true">
40908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40911 \begin_layout Standard
40919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40922 \begin_layout Standard
40925 IC_RIGHT() IC_RESULT()
40930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40933 \begin_layout Standard
40941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40944 \begin_layout Standard
40947 IC_RESULT = IC_RIGHT;
40953 <row topline="true">
40954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40957 \begin_layout Standard
40965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40968 \begin_layout Standard
40971 IC_COND IC_TRUE IC_LABEL
40976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40979 \begin_layout Standard
40983 If true label is present then jump to true label if condition is true else
40984 jump to false label if condition is false
40989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40992 \begin_layout Standard
40995 if (IC_COND) goto IC_TRUE;
41001 If (!IC_COND) goto IC_FALSE;
41007 <row topline="true">
41008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41011 \begin_layout Standard
41019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41022 \begin_layout Standard
41025 IC_LEFT() IC_RESULT()
41030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41033 \begin_layout Standard
41041 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41044 \begin_layout Standard
41047 IC_RESULT = &IC_LEFT();
41053 <row topline="true">
41054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41057 \begin_layout Standard
41065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41068 \begin_layout Standard
41071 IC_JTCOND IC_JTLABELS
41076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41079 \begin_layout Standard
41082 Jump to list of labels depending on the value of JTCOND
41087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41090 \begin_layout Standard
41099 <row topline="true">
41100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41103 \begin_layout Standard
41111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41114 \begin_layout Standard
41117 IC_RIGHT() IC_LEFT() IC_RESULT()
41122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41125 \begin_layout Standard
41133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41136 \begin_layout Standard
41139 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
41145 <row topline="true">
41146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41149 \begin_layout Standard
41157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41160 \begin_layout Standard
41168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41171 \begin_layout Standard
41174 This is used for passing parameters in registers;
41176 move IC_LEFT to the next
41177 available parameter register.
41182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41185 \begin_layout Standard
41194 <row topline="true">
41195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41198 \begin_layout Standard
41206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41209 \begin_layout Standard
41217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41220 \begin_layout Standard
41223 This is used for receiving parameters passed in registers;
41226 in the next parameter register to IC_RESULT
41231 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41234 \begin_layout Standard
41243 <row topline="true" bottomline="true">
41244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41247 \begin_layout Standard
41251 (some more have been added)
41256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41259 \begin_layout Standard
41265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41268 \begin_layout Standard
41274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41277 \begin_layout Standard
41310 \begin_layout Standard
41311 \begin_inset Note Note
41314 \begin_layout Standard
41315 In the original article Figure II was announced to be downloadable on
41320 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
41328 \begin_layout Paragraph*
41330 \begin_inset LatexCommand index
41338 \begin_layout Standard
41339 This section shows some details of iCode.
41340 The example C code does not do anything useful; it is used as an example
41341 to illustrate the intermediate code generated by the compiler.
41344 \begin_layout Verse
41354 /* This function does nothing useful.
41361 for the purpose of explaining iCode */
41364 short function (data
41373 short i=10; \InsetSpace ~
41375 /* dead initialization eliminated */
41381 /* dead initialization eliminated */
41409 /* compiler detects i,j to be induction
41414 for (i = 0, j = 10 ; i < 10 ; i++, j
41420 \begin_layout Standard
41443 mul += i * 3; \InsetSpace ~
41445 /* this multiplication remains */
41452 j * 3;\InsetSpace ~
41454 /* this multiplication changed to addition */
41468 \begin_layout Standard
41469 In addition to the operands each iCode contains information about the filename
41470 and line it corresponds to in the source file.
41471 The first field in the listing should be interpreted as follows:
41476 Filename(linenumber: iCode Execution sequence number : ICode hash table
41477 key : loop depth of the iCode).
41482 Then follows the human readable form of the ICode operation.
41483 Each operand of this triplet form can be of three basic types a) compiler
41484 generated temporary b) user defined variable c) a constant value.
41485 Note that local variables and parameters are replaced by compiler generated
41488 \begin_inset LatexCommand index
41489 name "Live range analysis"
41493 are computed only for temporaries (i.e.
41494 live ranges are not computed for global variables).
41496 \begin_inset LatexCommand index
41497 name "Register allocation"
41501 are allocated for temporaries only.
41502 Operands are formatted in the following manner:
41507 Operand Name [lr live-from : live-to ] { type information } [ registers
41513 As mentioned earlier the live ranges are computed in terms of the execution
41514 sequence number of the iCodes, for example
41516 the iTemp0 is live from (i.e.
41517 first defined in iCode with execution sequence number 3, and is last used
41518 in the iCode with sequence number 5).
41519 For induction variables such as iTemp21 the live range computation extends
41520 the lifetime from the start to the end of the loop.
41522 The register allocator
41523 used the live range information to allocate registers, the same registers
41524 may be used for different temporaries if their live ranges do not overlap,
41525 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
41526 ranges do not overlap.
41527 In addition the allocator also takes into consideration the type and usage
41528 of a temporary, for example itemp6 is a pointer to near space and is used
41529 as to fetch data from (i.e.
41530 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
41531 Some short lived temporaries are allocated to special registers which have
41532 meaning to the code generator e.g.
41533 iTemp13 is allocated to a pseudo register CC which tells the back end that
41534 the temporary is used only for a conditional jump the code generation makes
41535 use of this information to optimize a compare and jump ICode.
41539 \begin_inset LatexCommand index
41540 name "Loop optimization"
41544 performed by the compiler.
41545 It can detect induction variables iTemp21(i) and iTemp23(j).
41546 Also note the compiler does selective strength reduction
41547 \begin_inset LatexCommand index
41548 name "Strength reduction"
41553 the multiplication of an induction variable in line 18 (gint = j * 3) is
41554 changed to addition, a new temporary iTemp17 is allocated and assigned
41555 a initial value, a constant 3 is then added for each iteration of the loop.
41556 The compiler does not change the multiplication
41557 \begin_inset LatexCommand index
41558 name "Multiplication"
41562 in line 17 however since the processor does support an 8 * 8 bit multiplication.
41565 Note the dead code elimination
41566 \begin_inset LatexCommand index
41567 name "Dead-code elimination"
41571 optimization eliminated the dead assignments in line 7 & 8 to I and sum
41577 \begin_layout Standard
41580 Sample.c (5:1:0:0) _entry($9) :
41583 \begin_layout Standard
41586 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
41589 \begin_layout Standard
41592 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
41595 \begin_layout Standard
41598 Sample.c(11:4:53:0) preHeaderLbl0($11) :
41601 \begin_layout Standard
41604 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
41608 \begin_layout Standard
41611 Sample.c(11:6:5:1) _whilecontinue_0($1) :
41614 \begin_layout Standard
41617 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
41621 \begin_layout Standard
41624 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
41627 \begin_layout Standard
41630 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
41634 \begin_layout Standard
41637 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
41641 \begin_layout Standard
41644 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
41648 \begin_layout Standard
41651 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
41655 \begin_layout Standard
41658 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
41659 * int}[r0] + 0x2 {short}
41662 \begin_layout Standard
41665 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
41668 \begin_layout Standard
41671 Sample.c(11:17:21:0)_whilebreak_0($3) :
41674 \begin_layout Standard
41677 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
41680 \begin_layout Standard
41683 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
41686 \begin_layout Standard
41689 Sample.c(15:20:54:0)preHeaderLbl1($13) :
41692 \begin_layout Standard
41695 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
41698 \begin_layout Standard
41701 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
41704 \begin_layout Standard
41707 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
41710 \begin_layout Standard
41713 Sample.c(15:24:26:1)_forcond_0($4) :
41716 \begin_layout Standard
41719 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
41723 \begin_layout Standard
41726 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
41729 \begin_layout Standard
41732 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
41733 + ITemp21 [lr21:38]{short}[r4]
41736 \begin_layout Standard
41739 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
41743 \begin_layout Standard
41746 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
41747 + iTemp15 [lr29:30]{short}[r1]
41750 \begin_layout Standard
41753 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
41757 \begin_layout Standard
41760 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
41764 \begin_layout Standard
41767 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
41771 \begin_layout Standard
41774 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
41778 \begin_layout Standard
41781 Sample.c(19:38:47:1) goto _forcond_0($4)
41784 \begin_layout Standard
41787 Sample.c(19:39:48:0)_forbreak_0($7) :
41790 \begin_layout Standard
41793 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
41794 + ITemp11 [lr19:40]{short}[r3]
41797 \begin_layout Standard
41800 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
41803 \begin_layout Standard
41806 Sample.c(20:42:51:0)_return($8) :
41809 \begin_layout Standard
41812 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
41818 Finally the code generated for this function:
41823 \begin_layout Standard
41829 \begin_layout Standard
41835 \begin_layout Standard
41843 \begin_layout Standard
41849 \begin_layout Standard
41857 \begin_layout Standard
41863 \begin_layout Standard
41866 ; ----------------------------------------------
41869 \begin_layout Standard
41872 ; function function
41875 \begin_layout Standard
41878 ; ----------------------------------------------
41881 \begin_layout Standard
41887 \begin_layout Standard
41890 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
41893 \begin_layout Standard
41901 \begin_layout Standard
41904 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
41907 \begin_layout Standard
41915 \begin_layout Standard
41918 ;_whilecontinue_0($1) :
41921 \begin_layout Standard
41927 \begin_layout Standard
41930 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
41933 \begin_layout Standard
41936 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
41939 \begin_layout Standard
41947 \begin_layout Standard
41955 \begin_layout Standard
41963 \begin_layout Standard
41971 \begin_layout Standard
41979 \begin_layout Standard
41987 \begin_layout Standard
41995 \begin_layout Standard
42001 \begin_layout Standard
42004 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
42007 \begin_layout Standard
42015 \begin_layout Standard
42023 \begin_layout Standard
42026 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
42029 \begin_layout Standard
42037 \begin_layout Standard
42045 \begin_layout Standard
42053 \begin_layout Standard
42061 \begin_layout Standard
42069 \begin_layout Standard
42077 \begin_layout Standard
42080 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
42083 \begin_layout Standard
42091 \begin_layout Standard
42099 \begin_layout Standard
42107 \begin_layout Standard
42115 \begin_layout Standard
42123 \begin_layout Standard
42126 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
42129 \begin_layout Standard
42137 \begin_layout Standard
42145 \begin_layout Standard
42153 \begin_layout Standard
42156 ; iTemp6 [lr5:16]{_near * int}[r0] =
42159 \begin_layout Standard
42162 ; iTemp6 [lr5:16]{_near * int}[r0] +
42165 \begin_layout Standard
42171 \begin_layout Standard
42179 \begin_layout Standard
42182 ; goto _whilecontinue_0($1)
42185 \begin_layout Standard
42193 \begin_layout Standard
42196 ; _whilebreak_0($3) :
42199 \begin_layout Standard
42205 \begin_layout Standard
42208 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
42211 \begin_layout Standard
42219 \begin_layout Standard
42222 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
42225 \begin_layout Standard
42233 \begin_layout Standard
42236 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
42239 \begin_layout Standard
42247 \begin_layout Standard
42250 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
42253 \begin_layout Standard
42261 \begin_layout Standard
42269 \begin_layout Standard
42272 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
42275 \begin_layout Standard
42283 \begin_layout Standard
42291 \begin_layout Standard
42297 \begin_layout Standard
42303 \begin_layout Standard
42306 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
42309 \begin_layout Standard
42312 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
42315 \begin_layout Standard
42323 \begin_layout Standard
42331 \begin_layout Standard
42339 \begin_layout Standard
42347 \begin_layout Standard
42355 \begin_layout Standard
42361 \begin_layout Standard
42364 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
42367 \begin_layout Standard
42370 ; iTemp21 [lr21:38]{short}[r4]
42373 \begin_layout Standard
42381 \begin_layout Standard
42389 \begin_layout Standard
42397 \begin_layout Standard
42400 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
42403 \begin_layout Standard
42411 \begin_layout Standard
42419 \begin_layout Standard
42427 \begin_layout Standard
42435 \begin_layout Standard
42438 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
42441 \begin_layout Standard
42444 ; iTemp15 [lr29:30]{short}[r1]
42447 \begin_layout Standard
42455 \begin_layout Standard
42463 \begin_layout Standard
42466 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
42469 \begin_layout Standard
42477 \begin_layout Standard
42485 \begin_layout Standard
42493 \begin_layout Standard
42501 \begin_layout Standard
42509 \begin_layout Standard
42517 \begin_layout Standard
42520 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
42523 \begin_layout Standard
42531 \begin_layout Standard
42539 \begin_layout Standard
42547 \begin_layout Standard
42555 \begin_layout Standard
42563 \begin_layout Standard
42571 \begin_layout Standard
42574 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
42577 \begin_layout Standard
42585 \begin_layout Standard
42588 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
42591 \begin_layout Standard
42599 \begin_layout Standard
42604 cjne r5,#0xff,00104$
42607 \begin_layout Standard
42615 \begin_layout Standard
42618 ; goto _forcond_0($4)
42621 \begin_layout Standard
42629 \begin_layout Standard
42632 ; _forbreak_0($7) :
42635 \begin_layout Standard
42641 \begin_layout Standard
42644 ; ret iTemp24 [lr40:41]{short}
42647 \begin_layout Standard
42655 \begin_layout Standard
42663 \begin_layout Standard
42671 \begin_layout Standard
42677 \begin_layout Standard
42683 \begin_layout Standard
42693 \begin_layout Section
42694 A few words about basic block successors, predecessors and dominators
42697 \begin_layout Standard
42698 Successors are basic blocks
42699 \begin_inset LatexCommand index
42700 name "Basic blocks"
42704 that might execute after this basic block.
42706 Predecessors are basic blocks
42707 that might execute before reaching this basic block.
42709 Dominators are basic
42710 blocks that WILL execute before reaching this basic block.
42715 \begin_layout Standard
42719 \begin_layout Standard
42723 \begin_layout Standard
42731 \begin_layout Standard
42735 \begin_layout Standard
42743 \begin_layout Standard
42749 \begin_layout Standard
42750 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
42753 \begin_layout Standard
42754 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
42757 \begin_layout Standard
42758 c) domVect of [BB4] = BB1 ...
42759 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
42763 \begin_layout Chapter
42767 \begin_layout Standard
42768 \begin_inset LatexCommand url
42769 target "http://sdcc.sourceforge.net/#Who"
42779 Thanks to all the other volunteer developers who have helped with coding,
42780 testing, web-page creation, distribution sets, etc.
42781 You know who you are :-)
42789 Thanks to Sourceforge
42790 \begin_inset LatexCommand url
42791 target "http://www.sf.net"
42795 which has hosted the project since 1999 and donates significant download
42804 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
42805 cycles and bandwidth for snapshot builds.
42810 \begin_layout Standard
42811 This document was initially written by Sandeep Dutta
42814 \begin_layout Standard
42815 All product names mentioned herein may be trademarks
42816 \begin_inset LatexCommand index
42821 of their respective companies.
42825 \begin_layout Section*
42829 \begin_layout Standard
42830 To avoid confusion, the installation and building options for SDCC itself
42831 (chapter 2) are not part of the index.
42834 \begin_layout Standard
42835 \begin_inset LatexCommand printindex