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 HEAP_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, 23k20
25751 \begin_layout Standard
25752 18F: 2410, 2420, 2423, 2431, 2450, 2455, 2480, 24j10, 24k20
25755 \begin_layout Standard
25756 18F: 2510, 2515, 2520, 2523, 2525, 2550, 2580, 2585, 25j10, 25k20
25759 \begin_layout Standard
25760 18F: 2610, 2620, 2680, 2682, 2685
25763 \begin_layout Standard
25764 18F: 4220, 4221, 4320, 4321, 4331, 43k20
25767 \begin_layout Standard
25768 18F: 4410, 4420, 4423, 4431, 4450, 4455, 4480, 44j10, 44k20
25771 \begin_layout Standard
25772 18F: 4510, 4515, 4520, 4523, 4525, 4550, 4580, 4585, 45j10, 45k20
25775 \begin_layout Standard
25776 18F: 4610, 4620, 4680, 4682, 4685, 46k20
25779 \begin_layout Standard
25780 18F: 6520, 6585, 65j50, 6620, 6680, 66j50, 66j55, 66j60, 66j65, 6720, 67j50,
25784 \begin_layout Standard
25785 18F: 8520, 8585, 85j50, 8620, 8680, 86j50, 86j55, 86j60, 86j65, 8720, 87j50,
25789 \begin_layout Standard
25790 18F: 96j60, 96j65, 97j60
25793 \begin_layout Standard
25795 An up-to-date list of supported devices is also available via '
25797 sdcc -mpic16 -plist
25802 \begin_layout Subsection
25806 \begin_layout Standard
25807 PIC16 port supports the standard command line arguments as supposed, with
25808 the exception of certain cases that will be mentioned in the following
25812 \begin_layout Description
25817 \begin_layout Standard
25827 \begin_inset LatexCommand index
25828 name "PIC16!Options!-\\/-callee-saves"
25836 \begin_layout Standard
25848 \begin_layout Description
25853 \begin_layout Standard
25862 -fommit-frame-pointer
25863 \begin_inset LatexCommand index
25864 name "PIC16!Options!-\\/-fommit-frame-pointer"
25868 Frame pointer will be omitted when the function uses no local variables.
25871 \begin_layout Subsection
25872 Port Specific Options
25873 \begin_inset LatexCommand index
25874 name "Options PIC16"
25881 \begin_layout Standard
25882 The port specific options appear after the global options in the sdcc -
25886 \begin_layout Standard
25898 \begin_layout Subsubsection
25899 Code Generation Options
25902 \begin_layout Standard
25903 These options influence the generated assembler code.
25906 \begin_layout Description
25911 \begin_layout Standard
25920 -pstack-model=[model] Used in conjunction with the command above.
25921 Defines the stack model to be used, valid stack models are:
25926 \labelwidthstring 00.00.0000
25931 Selects small stack model.
25932 8 bit stack and frame pointers.
25933 Supports 256 bytes stack size.
25937 \labelwidthstring 00.00.0000
25942 Selects large stack model.
25943 16 bit stack and frame pointers.
25944 Supports 65536 bytes stack size.
25948 \begin_layout Description
25953 \begin_layout Standard
25962 -pno-banksel Do not generate BANKSEL assembler directives.
25965 \begin_layout Description
25970 \begin_layout Standard
25979 -extended Enable extended instruction set/literal offset addressing mode.
25983 \begin_layout Subsubsection
25984 Optimization Options
25987 \begin_layout Description
25992 \begin_layout Standard
26001 -obanksel=n Set optimization level for inserting BANKSELs.
26008 \labelwidthstring 00.00.0000
26013 \labelwidthstring 00.00.0000
26014 1 checks previous used register and if it is the same then does not emit
26015 BANKSEL, accounts only for labels.
26019 \labelwidthstring 00.00.0000
26020 2 tries to check the location of (even different) symbols and removes BANKSELs
26021 if they are in the same bank.
26026 Important: There might be problems if the linker script has data sections
26027 across bank borders!
26031 \begin_layout Description
26036 \begin_layout Standard
26045 -denable-peeps Force the usage of peepholes.
26049 \begin_layout Description
26054 \begin_layout Standard
26063 -no-optimize-goto Do not use (conditional) BRA instead of GOTO.
26066 \begin_layout Description
26071 \begin_layout Standard
26080 -optimize-cmp Try to optimize some compares.
26083 \begin_layout Description
26088 \begin_layout Standard
26097 -optimize-df Analyze the dataflow of the generated code and improve it.
26100 \begin_layout Subsubsection
26104 \begin_layout Description
26109 \begin_layout Standard
26118 -asm= Sets the full path and name of an external assembler to call.
26121 \begin_layout Description
26126 \begin_layout Standard
26136 \begin_inset LatexCommand index
26141 compatibility option.
26142 Currently only suppresses special gpasm directives.
26145 \begin_layout Subsubsection
26149 \begin_layout Description
26154 \begin_layout Standard
26163 -link= Sets the full path and name of an external linker to call.
26166 \begin_layout Description
26171 \begin_layout Standard
26180 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
26181 unitialized data variables with [kword].
26182 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
26185 \begin_layout Description
26190 \begin_layout Standard
26199 -ivt-loc=n Place the interrupt vector table at address
26204 Useful for bootloaders.
26207 \begin_layout Description
26212 \begin_layout Standard
26221 -nodefaultlibs Do not link default libraries when linking.
26224 \begin_layout Description
26229 \begin_layout Standard
26238 -use-crt= Use a custom run-time module instead of the defaults.
26241 \begin_layout Description
26246 \begin_layout Standard
26255 -no-crt Don't link the default run-time modules
26258 \begin_layout Subsubsection
26262 \begin_layout Standard
26263 Debugging options enable extra debugging information in the output files.
26266 \begin_layout Description
26271 \begin_layout Standard
26280 -debug-xtra Similar to -
26284 \begin_layout Standard
26294 \begin_inset LatexCommand index
26299 , but dumps more information.
26302 \begin_layout Description
26307 \begin_layout Standard
26316 -debug-ralloc Force register allocator to dump <source>.d file with debugging
26318 <source> is the name of the file being compiled.
26321 \begin_layout Description
26326 \begin_layout Standard
26335 -pcode-verbose Enable pcode debugging information in translation.
26338 \begin_layout Description
26343 \begin_layout Standard
26352 -calltree Dump call tree in .calltree file.
26355 \begin_layout Description
26360 \begin_layout Standard
26369 -gstack Trace push/pops for stack pointer overflow.
26372 \begin_layout Subsection
26373 Environment Variables
26376 \begin_layout Standard
26377 There is a number of environmental variables that can be used when running
26378 SDCC to enable certain optimizations or force a specific program behaviour.
26379 these variables are primarily for debugging purposes so they can be enabled/dis
26383 \begin_layout Standard
26384 Currently there is only two such variables available:
26387 \begin_layout Description
26388 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
26389 bitfields is optimized by directly loading FSR0 with the address of the
26390 bitfield structure.
26391 Normally SDCC will cast the bitfield structure to a bitfield pointer and
26393 This step saves data ram and code space for functions that make heavy use
26395 (i.e., 80 bytes of code space are saved when compiling malloc.c with this
26400 \begin_layout Description
26401 NO_REG_OPT Do not perform pCode registers optimization.
26402 This should be used for debugging purposes.
26403 If bugs in the pcode optimizer are found, users can benefit from temporarily
26404 disabling the optimizer until the bug is fixed.
26407 \begin_layout Subsection
26408 Preprocessor Macros
26411 \begin_layout Standard
26413 \begin_inset LatexCommand index
26418 port defines the following preprocessor macros while translating a source.
26421 \begin_layout Standard
26423 \begin_inset Tabular
26424 <lyxtabular version="3" rows="6" columns="2">
26426 <column alignment="center" valignment="top" leftline="true" width="0">
26427 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26428 <row topline="true" bottomline="true">
26429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26432 \begin_layout Standard
26438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26441 \begin_layout Standard
26448 <row topline="true">
26449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26452 \begin_layout Standard
26458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26461 \begin_layout Standard
26462 Port identification
26468 <row topline="true">
26469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26472 \begin_layout Standard
26477 \begin_layout Standard
26491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26494 \begin_layout Standard
26495 Port identification (same as above)
26501 <row topline="true">
26502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26505 \begin_layout Standard
26511 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26514 \begin_layout Standard
26515 MCU Identification.
26520 is the microcontrol identification number, i.e.
26527 <row topline="true">
26528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26531 \begin_layout Standard
26536 \begin_layout Standard
26550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26553 \begin_layout Standard
26554 MCU Identification (same as above)
26560 <row topline="true" bottomline="true">
26561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26564 \begin_layout Standard
26570 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26573 \begin_layout Standard
26574 nnn = SMALL or LARGE respectively according to the stack model used
26587 \begin_layout Standard
26589 In addition the following macros are defined when calling assembler:
26592 \begin_layout Standard
26594 \begin_inset Tabular
26595 <lyxtabular version="3" rows="4" columns="2">
26597 <column alignment="center" valignment="top" leftline="true" width="0">
26598 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26599 <row topline="true" bottomline="true">
26600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26603 \begin_layout Standard
26609 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26612 \begin_layout Standard
26619 <row topline="true">
26620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26623 \begin_layout Standard
26629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26632 \begin_layout Standard
26633 MCU Identification.
26638 is the microcontrol identification number, i.e.
26645 <row topline="true">
26646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26649 \begin_layout Standard
26655 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26658 \begin_layout Standard
26659 nnn = SMALL or LARGE respectively according to the memory model used for
26666 <row topline="true" bottomline="true">
26667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26670 \begin_layout Standard
26676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26679 \begin_layout Standard
26680 nnn = SMALL or LARGE respectively according to the stack model used
26693 \begin_layout Subsection
26697 \begin_layout Standard
26699 \begin_inset LatexCommand index
26704 port uses the following directories for searching header files and libraries.
26707 \begin_layout Standard
26709 \begin_inset Tabular
26710 <lyxtabular version="3" rows="3" columns="4">
26712 <column alignment="center" valignment="top" leftline="true" width="0">
26713 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26714 <column alignment="center" valignment="top" width="0">
26715 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26716 <row topline="true" bottomline="true">
26717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26720 \begin_layout Standard
26726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26729 \begin_layout Standard
26735 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26738 \begin_layout Standard
26744 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26747 \begin_layout Standard
26754 <row topline="true">
26755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26758 \begin_layout Standard
26759 PREFIX/sdcc/include/pic16
26764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26767 \begin_layout Standard
26768 PIC16 specific headers
26773 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26776 \begin_layout Standard
26782 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26785 \begin_layout Standard
26792 <row topline="true" bottomline="true">
26793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26796 \begin_layout Standard
26797 PREFIX/sdcc/lib/pic16
26802 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26805 \begin_layout Standard
26806 PIC16 specific libraries
26811 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26814 \begin_layout Standard
26820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26823 \begin_layout Standard
26837 \begin_layout Subsection
26839 \begin_inset LatexCommand label
26840 name "sub:PIC16_Pragmas"
26847 \begin_layout Standard
26849 \begin_inset LatexCommand index
26854 port currently supports the following pragmas:
26857 \begin_layout Description
26859 \begin_inset LatexCommand index
26860 name "PIC16!Pragmas!\\#pragma stack"
26864 This forces the code generator to initialize the stack & frame pointers
26865 at a specific address.
26866 This is an ad hoc solution for cases where no STACK directive is available
26867 in the linker script or gplink is not instructed to create a stack section.
26870 stack pragma should be used only once in a project.
26871 Multiple pragmas may result in indeterminate behaviour of the program.
26875 \begin_layout Standard
26876 The old format (ie.
26877 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
26878 cross page boundaries (or even exceed the available data RAM) and crash
26880 Make sure that stack does not cross page boundaries when using the SMALL
26888 The format is as follows:
26893 \begin_layout LyX-Code
26894 #pragma stack bottom_address [stack_size]
26899 \begin_layout Standard
26904 is the lower bound of the stack section.
26905 The stack pointer initially will point at address (bottom_address+stack_size-1).
26908 \begin_layout LyX-Code
26912 \begin_layout LyX-Code
26916 \begin_layout LyX-Code
26917 /* initializes stack of 100 bytes at RAM address 0x200 */
26920 \begin_layout LyX-Code
26921 #pragma stack 0x200 100
26924 \begin_layout Standard
26925 If the stack_size field is omitted then a stack is created with the default
26927 This size might be enough for most programs, but its not enough for operations
26928 with deep function nesting or excessive stack usage.
26931 \begin_layout Description
26933 \begin_inset LatexCommand index
26934 name "PIC16!Pragmas!\\#pragma code"
26938 Force a function to a static FLASH address.
26941 \begin_layout LyX-Code
26945 \begin_layout LyX-Code
26949 \begin_layout LyX-Code
26950 /* place function test_func at 0x4000 */
26953 \begin_layout LyX-Code
26954 #pragma code test_func 0x4000
26957 \begin_layout LyX-Code
26961 \begin_layout Description
26962 library instructs the linker to use a library module.
26967 \begin_layout LyX-Code
26968 #pragma library module_name
26971 \begin_layout Standard
26976 can be any library or object file (including its path).
26977 Note that there are four reserved keywords which have special meaning.
26981 \begin_layout Standard
26983 \begin_inset Tabular
26984 <lyxtabular version="3" rows="6" columns="3">
26986 <column alignment="center" valignment="top" leftline="true" width="0">
26987 <column alignment="block" valignment="top" leftline="true" width="20page%">
26988 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
26989 <row topline="true" bottomline="true">
26990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26993 \begin_layout Standard
26999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27002 \begin_layout Standard
27008 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27011 \begin_layout Standard
27018 <row topline="true">
27019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27022 \begin_layout Standard
27030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27033 \begin_layout Standard
27034 ignore all library pragmas
27039 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27042 \begin_layout Standard
27051 <row topline="true">
27052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27055 \begin_layout Standard
27063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27066 \begin_layout Standard
27072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27075 \begin_layout Standard
27086 <row topline="true">
27087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27090 \begin_layout Standard
27098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27101 \begin_layout Standard
27102 link the Math libarary
27107 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27110 \begin_layout Standard
27121 <row topline="true">
27122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27125 \begin_layout Standard
27133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27136 \begin_layout Standard
27137 link the I/O library
27142 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27145 \begin_layout Standard
27156 <row topline="true" bottomline="true">
27157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27160 \begin_layout Standard
27168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27171 \begin_layout Standard
27172 link the debug library
27177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27180 \begin_layout Standard
27197 * is the device number, i.e.
27198 452 for PIC18F452 MCU.
27201 \begin_layout Standard
27203 This feature allows for linking with specific libraries without having to
27204 explicit name them in the command line.
27209 keyword will reject all modules specified by the library pragma.
27212 \begin_layout Description
27213 udata The pragma udata instructs the compiler to emit code so that linker
27214 will place a variable at a specific memory bank.
27217 \begin_layout LyX-Code
27221 \begin_layout LyX-Code
27225 \begin_layout LyX-Code
27226 /* places variable foo at bank2 */
27229 \begin_layout LyX-Code
27230 #pragma udata bank2 foo
27233 \begin_layout LyX-Code
27237 \begin_layout Standard
27238 In order for this pragma to work extra SECTION directives should be added
27239 in the .lkr script.
27240 In the following example a sample .lkr file is shown:
27243 \begin_layout LyX-Code
27247 \begin_layout LyX-Code
27248 // Sample linker script for the PIC18F452 processor
27251 \begin_layout LyX-Code
27255 \begin_layout LyX-Code
27256 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
27259 \begin_layout LyX-Code
27260 CODEPAGE NAME=page START=0x2A END=0x7FFF
27263 \begin_layout LyX-Code
27264 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
27267 \begin_layout LyX-Code
27268 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
27271 \begin_layout LyX-Code
27272 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
27275 \begin_layout LyX-Code
27276 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
27279 \begin_layout LyX-Code
27280 ACCESSBANK NAME=accessram START=0x0 END=0x7F
27283 \begin_layout LyX-Code
27287 \begin_layout LyX-Code
27288 DATABANK NAME=gpr0 START=0x80 END=0xFF
27291 \begin_layout LyX-Code
27292 DATABANK NAME=gpr1 START=0x100 END=0x1FF
27295 \begin_layout LyX-Code
27296 DATABANK NAME=gpr2 START=0x200 END=0x2FF
27299 \begin_layout LyX-Code
27300 DATABANK NAME=gpr3 START=0x300 END=0x3FF
27303 \begin_layout LyX-Code
27304 DATABANK NAME=gpr4 START=0x400 END=0x4FF
27307 \begin_layout LyX-Code
27308 DATABANK NAME=gpr5 START=0x500 END=0x5FF
27311 \begin_layout LyX-Code
27312 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
27315 \begin_layout LyX-Code
27319 \begin_layout LyX-Code
27320 SECTION NAME=CONFIG ROM=config
27323 \begin_layout LyX-Code
27327 \begin_layout LyX-Code
27328 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
27331 \begin_layout LyX-Code
27332 SECTION NAME=bank1 RAM=gpr1 # should be added to link
27335 \begin_layout LyX-Code
27336 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
27339 \begin_layout LyX-Code
27340 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
27343 \begin_layout LyX-Code
27344 SECTION NAME=bank4 RAM=gpr4
27347 \begin_layout LyX-Code
27348 SECTION NAME=bank5 RAM=gpr5
27351 \begin_layout Standard
27352 The linker will recognise the section name set in the pragma statement and
27353 will position the variable at the memory bank set with the RAM field at
27354 the SECTION line in the linker script file.
27357 \begin_layout Subsection
27359 \begin_inset LatexCommand label
27360 name "sub:PIC16_Header-Files"
27367 \begin_layout Standard
27368 There is one main header file
27369 \begin_inset LatexCommand index
27370 name "PIC16!Header files"
27374 that can be included to the source files using the pic16
27375 \begin_inset LatexCommand index
27386 This header file contains the definitions for the processor special registers,
27387 so it is necessary if the source accesses them.
27388 It can be included by adding the following line in the beginning of the
27392 \begin_layout LyX-Code
27393 #include <pic18fregs.h>
27396 \begin_layout Standard
27397 The specific microcontroller is selected within the pic18fregs.h automatically,
27398 so the same source can be used with a variety of devices.
27401 \begin_layout Subsection
27403 \begin_inset LatexCommand label
27404 name "sub:pic16Libraries"
27411 \begin_layout Standard
27413 \begin_inset LatexCommand index
27414 name "PIC16!Libraries"
27419 \begin_inset LatexCommand index
27424 port depends on are the microcontroller device libraries which contain
27425 the symbol definitions for the microcontroller special function registers.
27426 These libraries have the format pic18fxxxx.lib, where
27430 is the microcontroller identification number.
27431 The specific library is selected automatically by the compiler at link
27432 stage according to the selected device.
27435 \begin_layout Standard
27437 Libraries are created with gplib which is part of the gputils package
27438 \begin_inset LatexCommand url
27439 target "http://sourceforge.net/projects/gputils"
27446 \begin_layout Subsubsection*
27447 Building the libraries
27450 \begin_layout Standard
27451 Before using SDCC/pic16 there are some libraries that need to be compiled.
27452 This process is done automatically if gputils are found at SDCC's compile
27454 Should you require to rebuild the pic16 libraries manually (e.g.
27455 in order to enable output of float values
27456 \begin_inset LatexCommand index
27457 name "Floating point support"
27465 , see below), these are the steps required to do so under Linux or Mac OS
27466 X (cygwin might work as well, but is untested):
27469 \begin_layout LyX-Code
27470 cd device/lib/pic16
27473 \begin_layout LyX-Code
27477 \begin_layout LyX-Code
27481 \begin_layout LyX-Code
27485 \begin_layout LyX-Code
27486 su -c 'make install' # install the libraries, you need the root password
27489 \begin_layout LyX-Code
27493 \begin_layout Standard
27494 If you need to install the headers too, do:
27497 \begin_layout LyX-Code
27501 \begin_layout LyX-Code
27502 su -c 'make install' # install the headers, you need the root password
27505 \begin_layout Subsubsection*
27506 Output of float values via printf()
27509 \begin_layout Standard
27510 The library is normally built without support for displaying float values,
27512 \begin_inset LatexCommand index
27518 \begin_inset LatexCommand index
27519 name "printf floating point support"
27523 will appear instead of the value.
27524 To change this, rebuild the library as stated above, but call
27526 ./configure.gnu --enable-floats
27533 Also make sure that at least
27535 libc/stdio/vfprintf.c
27537 is actually recompiled, e.g.
27546 run or deleting its
27553 \begin_layout Standard
27554 The more common appraoch of compiling
27562 should also work, but is untested.
27565 \begin_layout Subsection
27566 Adding New Devices to the Port
27569 \begin_layout Standard
27570 Adding support for a new 16
27574 \begin_layout Standard
27583 bit PIC MCU requires the following steps:
27586 \begin_layout Enumerate
27587 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
27591 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
27595 \begin_layout Enumerate
27598 mv picDEVICE.h /path/to/sdcc/device/include/pic16
27601 \begin_layout Enumerate
27604 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
27607 \begin_layout Enumerate
27610 /path/to/sdcc/device/lib/pic16/pics.all
27614 Note: No 18f prefix here!
27617 \begin_layout Enumerate
27620 /path/to/sdcc/device/include/pic16/adc.h
27624 Add the new devices to the correct ADC style class (depending on the number
27631 if the device does not offer any ADC at all.
27634 \begin_layout Enumerate
27637 /path/to/sdcc/device/include/pic16/pic18fregs.h
27641 The file format is self-explanatory, just add
27645 #elif defined(picDEVICE)
27651 \begin_layout Standard
27662 include <picDEVICE.h>
27666 at the right place (keep the file sorted, please).
27669 \begin_layout Enumerate
27672 /path/to/sdcc/device/include/pic16devices.txt
27676 Copy and modify an existing entry or create a new one and insert it at the
27677 correct place (keep the file sorted, please).
27680 \begin_layout Enumerate
27683 /path/to/sdcc/device/lib/pic16/libdev/Makefile.am
27687 Copy an existing entry and adjust the device name.
27690 \begin_layout Enumerate
27693 /path/to/sdcc/device/lib/pic16/libio/Makefile.am
27697 Copy the record from the 18f2220 and adjust the device name.
27700 does not offer ADC, I
27701 \begin_inset Formula $^{\text{2}}$
27704 C, and/or (E)USART functionality as assumed by the library, remove the lines
27720 \begin_layout Enumerate
27739 /path/to/sdcc/device/lib/pic16
27744 \begin_layout Enumerate
27745 Recompile the pic16 libraries as described in
27746 \begin_inset LatexCommand ref
27747 reference "sub:pic16Libraries"
27754 \begin_layout Subsection
27758 \begin_layout Standard
27759 The following memory models are supported by the PIC16 port:
27762 \begin_layout Itemize
27766 \begin_layout Itemize
27770 \begin_layout Standard
27771 Memory model affects the default size of pointers within the source.
27772 The sizes are shown in the next table:
27775 \begin_layout Standard
27777 \begin_inset Tabular
27778 <lyxtabular version="3" rows="3" columns="3">
27780 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27781 <column alignment="center" valignment="top" leftline="true" width="0">
27782 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27783 <row topline="true" bottomline="true">
27784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27787 \begin_layout Standard
27788 Pointer sizes according to memory model
27793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27796 \begin_layout Standard
27802 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27805 \begin_layout Standard
27812 <row topline="true" bottomline="true">
27813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27816 \begin_layout Standard
27822 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27825 \begin_layout Standard
27831 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27834 \begin_layout Standard
27841 <row topline="true" bottomline="true">
27842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27845 \begin_layout Standard
27851 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
27854 \begin_layout Standard
27860 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27863 \begin_layout Standard
27877 \begin_layout Standard
27878 It is advisable that all sources within a project are compiled with the
27880 If one wants to override the default memory model, this can be done by
27881 declaring a pointer as
27890 Far selects large memory model's pointers, while near selects small memory
27894 \begin_layout Standard
27895 The standard device libraries (see
27896 \begin_inset LatexCommand ref
27897 reference "sub:PIC16_Header-Files"
27901 ) contain no reference to pointers, so they can be used with both memory
27905 \begin_layout Subsection
27909 \begin_layout Standard
27911 \begin_inset LatexCommand index
27916 implementation for the PIC16 port uses two indirect registers, FSR1 and
27920 \begin_layout Description
27921 FSR1 is assigned as stack pointer
27924 \begin_layout Description
27925 FSR2 is assigned as frame pointer
27928 \begin_layout Standard
27929 The following stack models are supported by the PIC16 port
27932 \begin_layout Itemize
27940 \begin_layout Itemize
27948 \begin_layout Standard
27953 model means that only the FSRxL byte is used to access stack and frame,
27960 uses both FSRxL and FSRxH registers.
27961 The following table shows the stack/frame pointers sizes according to stack
27962 model and the maximum space they can address:
27965 \begin_layout Standard
27967 \begin_inset Tabular
27968 <lyxtabular version="3" rows="3" columns="3">
27970 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27971 <column alignment="center" valignment="top" leftline="true" width="0">
27972 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27973 <row topline="true" bottomline="true">
27974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27977 \begin_layout Standard
27978 Stack & Frame pointer sizes according to stack model
27983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27986 \begin_layout Standard
27992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27995 \begin_layout Standard
28002 <row topline="true">
28003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28006 \begin_layout Standard
28012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28015 \begin_layout Standard
28021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28024 \begin_layout Standard
28031 <row topline="true" bottomline="true">
28032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28035 \begin_layout Standard
28041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28044 \begin_layout Standard
28050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28053 \begin_layout Standard
28067 \begin_layout Standard
28073 stack model is currently not working properly throughout the code generator.
28074 So its use is not advised.
28075 Also there are some other points that need special care:
28080 \begin_layout Enumerate
28081 Do not create stack sections with size more than one physical bank (that
28085 \begin_layout Enumerate
28086 Stack sections should no cross physical bank limits (i.e.
28087 #pragma stack 0x50 0x100)
28090 \begin_layout Standard
28091 These limitations are caused by the fact that only FSRxL is modified when
28092 using SMALL stack model, so no more than 256 bytes of stack can be used.
28093 This problem will disappear after LARGE model is fully implemented.
28096 \begin_layout Subsection
28100 \begin_layout Standard
28101 In addition to the standard SDCC function keywords, PIC16
28102 \begin_inset LatexCommand index
28107 port makes available two more:
28110 \begin_layout Description
28112 \begin_inset LatexCommand index
28113 name "PIC16!wparam"
28117 Use the WREG to pass one byte of the first function argument.
28118 This improves speed but you may not use this for functions with arguments
28119 that are called via function pointers, otherwise the first byte of the
28120 first parameter will get lost.
28124 \begin_layout LyX-Code
28125 void func_wparam(int a) wparam
28128 \begin_layout LyX-Code
28132 \begin_layout LyX-Code
28133 /* WREG hold the lower part of a */
28136 \begin_layout LyX-Code
28137 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
28141 \begin_layout LyX-Code
28145 \begin_layout LyX-Code
28149 \begin_layout Description
28151 \begin_inset LatexCommand index
28152 name "PIC16!shadowregs"
28156 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
28157 hardware shadow registers which hold the values of WREG, STATUS and BSR
28159 This can be done by adding the keyword
28167 keyword in the function's header.
28170 \begin_layout LyX-Code
28171 void isr_shadow(void) shadowregs interrupt 1
28174 \begin_layout LyX-Code
28178 \begin_layout LyX-Code
28182 \begin_layout LyX-Code
28186 \begin_layout Standard
28191 instructs the code generator not to store/restore WREG, STATUS, BSR when
28192 entering/exiting the ISR.
28195 \begin_layout Subsection
28196 Function return values
28199 \begin_layout Standard
28200 Return values from functions are placed to the appropriate registers following
28201 a modified Microchip policy optimized for SDCC.
28202 The following table shows these registers:
28205 \begin_layout Standard
28207 \begin_inset Tabular
28208 <lyxtabular version="3" rows="6" columns="2">
28210 <column alignment="center" valignment="top" leftline="true" width="0">
28211 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28212 <row topline="true" bottomline="true">
28213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28216 \begin_layout Standard
28222 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28225 \begin_layout Standard
28226 destination register
28232 <row topline="true">
28233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28236 \begin_layout Standard
28242 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28245 \begin_layout Standard
28252 <row topline="true">
28253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28256 \begin_layout Standard
28262 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28265 \begin_layout Standard
28272 <row topline="true">
28273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28276 \begin_layout Standard
28282 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28285 \begin_layout Standard
28292 <row topline="true">
28293 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28296 \begin_layout Standard
28302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28305 \begin_layout Standard
28306 FSR0L:PRODH:PRODL:WREG
28312 <row topline="true" bottomline="true">
28313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28316 \begin_layout Standard
28322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28325 \begin_layout Standard
28326 on stack, FSR0 points to the beginning
28339 \begin_layout Subsection
28343 \begin_layout Standard
28345 \begin_inset LatexCommand index
28346 name "PIC16!interrupt"
28350 service routine (ISR) is declared using the
28357 \begin_layout LyX-Code
28358 void isr(void) interrupt
28363 \begin_layout LyX-Code
28367 \begin_layout LyX-Code
28371 \begin_layout LyX-Code
28375 \begin_layout Standard
28380 is the interrupt number, which for PIC18F devices can be:
28383 \begin_layout Standard
28385 \begin_inset Tabular
28386 <lyxtabular version="3" rows="4" columns="3">
28388 <column alignment="center" valignment="top" leftline="true" width="0">
28389 <column alignment="center" valignment="top" leftline="true" width="0">
28390 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28391 <row topline="true" bottomline="true">
28392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28395 \begin_layout Standard
28403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28406 \begin_layout Standard
28412 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28415 \begin_layout Standard
28416 Interrupt Vector Address
28422 <row topline="true">
28423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28426 \begin_layout Standard
28432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28435 \begin_layout Standard
28441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28444 \begin_layout Standard
28451 <row topline="true">
28452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28455 \begin_layout Standard
28470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28473 \begin_layout Standard
28483 HIGH priority interrupts
28488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28491 \begin_layout Standard
28498 <row topline="true" bottomline="true">
28499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28502 \begin_layout Standard
28508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28511 \begin_layout Standard
28512 LOW priority interrupts
28517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28520 \begin_layout Standard
28534 \begin_layout Standard
28535 When generating assembly code for ISR the code generator places a
28541 Interrupt Vector Address
28543 which points at the generated ISR.
28544 This single GOTO instruction is part of an automatically generated
28546 interrupt entry point
28549 The actuall ISR code is placed as normally would in the code space.
28550 Upon interrupt request, the GOTO instruction is executed which jumps to
28552 When declaring interrupt functions as _naked this GOTO instruction is
28557 The whole interrupt functions is therefore placed at the Interrupt Vector
28558 Address of the specific interrupt.
28559 This is not a problem for the LOW priority interrupts, but it is a problem
28560 for the RESET and the HIGH priority interrupts because code may be written
28561 at the next interrupt's vector address and cause indeterminate program
28562 behaviour if that interrupt is raised.
28566 \begin_layout Standard
28567 This is not a problem when
28570 \begin_layout Enumerate
28571 this is a HIGH interrupt ISR and LOW interrupts are
28578 \begin_layout Enumerate
28579 when the ISR is small enough not to reach the next interrupt's vector address.
28587 \begin_layout Standard
28593 This way a function is generated similar to an ISR, but it is not assigned
28597 \begin_layout Standard
28598 When entering an interrupt, currently the PIC16
28599 \begin_inset LatexCommand index
28604 port automatically saves the following registers:
28607 \begin_layout Itemize
28611 \begin_layout Itemize
28615 \begin_layout Itemize
28619 \begin_layout Itemize
28620 PROD (PRODL and PRODH)
28623 \begin_layout Itemize
28624 FSR0 (FSR0L and FSR0H)
28627 \begin_layout Standard
28628 These registers are restored upon return from the interrupt routine.
28632 \begin_layout Standard
28633 NOTE that when the _naked attribute is specified for an interrupt routine,
28634 then NO registers are stored or restored.
28642 \begin_layout Subsection
28646 \begin_layout Standard
28647 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
28648 There are 3 types of generic pointers currently implemented data, code
28649 and eeprom pointers.
28650 They are differentiated by the value of the 7th and 6th bits of the upper
28654 \begin_layout Standard
28656 \begin_inset Tabular
28657 <lyxtabular version="3" rows="5" columns="5">
28659 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28660 <column alignment="center" valignment="top" width="0">
28661 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28662 <column alignment="center" valignment="top" width="0">
28663 <column alignment="left" valignment="top" rightline="true" width="0">
28664 <row topline="true" bottomline="true">
28665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28668 \begin_layout Standard
28674 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28677 \begin_layout Standard
28683 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28686 \begin_layout Standard
28692 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28695 \begin_layout Standard
28696 rest of the pointer
28701 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28704 \begin_layout Standard
28711 <row topline="true" bottomline="true">
28712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28715 \begin_layout Standard
28721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28724 \begin_layout Standard
28730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28733 \begin_layout Standard
28739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28742 \begin_layout Standard
28747 uuuuuu uuuuxxxx xxxxxxxx
28752 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28755 \begin_layout Standard
28756 a 12-bit data pointer in data RAM memory
28762 <row bottomline="true">
28763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28766 \begin_layout Standard
28772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28775 \begin_layout Standard
28781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28784 \begin_layout Standard
28790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28793 \begin_layout Standard
28798 uxxxxx xxxxxxxx xxxxxxxx
28803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28806 \begin_layout Standard
28807 a 21-bit code pointer in FLASH memory
28813 <row bottomline="true">
28814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28817 \begin_layout Standard
28823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28826 \begin_layout Standard
28832 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28835 \begin_layout Standard
28841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28844 \begin_layout Standard
28849 uuuuuu uuuuuuxx xxxxxxxx
28854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28857 \begin_layout Standard
28858 a 10-bit eeprom pointer in EEPROM memory
28864 <row bottomline="true">
28865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28868 \begin_layout Standard
28874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28877 \begin_layout Standard
28883 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28886 \begin_layout Standard
28892 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28895 \begin_layout Standard
28900 xxxxxx xxxxxxxx xxxxxxxx
28905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28908 \begin_layout Standard
28909 unimplemented pointer type
28922 \begin_layout Standard
28924 Generic pointer are read and written with a set of library functions which
28925 read/write 1, 2, 3, 4 bytes.
28928 \begin_layout Subsection
28932 \begin_layout Subsubsection
28933 Standard I/O Streams
28936 \begin_layout Standard
28941 the type FILE is defined as:
28944 \begin_layout LyX-Code
28945 typedef char * FILE;
28948 \begin_layout Standard
28949 This type is the stream type implemented I/O in the PIC18F devices.
28950 Also the standard input and output streams are declared in stdio.h:
28953 \begin_layout LyX-Code
28954 extern FILE * stdin;
28957 \begin_layout LyX-Code
28958 extern FILE * stdout;
28961 \begin_layout Standard
28962 The FILE type is actually a generic pointer which defines one more type
28963 of generic pointers, the
28968 This new type has the format:
28971 \begin_layout Standard
28974 \begin_inset Tabular
28975 <lyxtabular version="3" rows="2" columns="7">
28977 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28978 <column alignment="center" valignment="top" width="0">
28979 <column alignment="center" valignment="top" leftline="true" width="0">
28980 <column alignment="center" valignment="top" leftline="true" width="0">
28981 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28982 <column alignment="center" valignment="top" width="0">
28983 <column alignment="left" valignment="top" rightline="true" width="0">
28984 <row topline="true" bottomline="true">
28985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28988 \begin_layout Standard
28994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28997 \begin_layout Standard
29003 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29006 \begin_layout Standard
29012 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29015 \begin_layout Standard
29021 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29024 \begin_layout Standard
29030 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29033 \begin_layout Standard
29034 rest of the pointer
29039 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29042 \begin_layout Standard
29049 <row topline="true" bottomline="true">
29050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29053 \begin_layout Standard
29059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29062 \begin_layout Standard
29068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29071 \begin_layout Standard
29077 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29080 \begin_layout Standard
29086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29089 \begin_layout Standard
29095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29098 \begin_layout Standard
29108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29111 \begin_layout Standard
29112 upper byte high nubble is 0x2n, the rest are zeroes
29125 \begin_layout Standard
29127 Currently implemented there are 3 types of streams defined:
29130 \begin_layout Standard
29133 \begin_inset Tabular
29134 <lyxtabular version="3" rows="4" columns="4">
29136 <column alignment="center" valignment="top" leftline="true" width="0">
29137 <column alignment="center" valignment="top" leftline="true" width="0">
29138 <column alignment="center" valignment="top" leftline="true" width="0">
29139 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29140 <row topline="true" bottomline="true">
29141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29144 \begin_layout Standard
29150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29153 \begin_layout Standard
29159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29162 \begin_layout Standard
29168 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29171 \begin_layout Standard
29178 <row topline="true">
29179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29182 \begin_layout Standard
29188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29191 \begin_layout Standard
29199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29202 \begin_layout Standard
29208 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29211 \begin_layout Standard
29212 Writes/Reads characters via the USART peripheral
29218 <row topline="true">
29219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29222 \begin_layout Standard
29228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29231 \begin_layout Standard
29239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29242 \begin_layout Standard
29248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29251 \begin_layout Standard
29252 Writes/Reads characters via the MSSP peripheral
29258 <row topline="true" bottomline="true">
29259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29262 \begin_layout Standard
29268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29271 \begin_layout Standard
29279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29282 \begin_layout Standard
29288 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29291 \begin_layout Standard
29292 Writes/Reads characters via used defined functions
29305 \begin_layout Standard
29307 The stream identifiers are declared as macros in the stdio.h header.
29310 \begin_layout Standard
29312 In the libc library there exist the functions that are used to write to
29313 each of the above streams.
29317 \begin_layout Description
29322 \begin_layout Standard
29331 _stream_usart_putchar writes a character at the USART stream
29334 \begin_layout Description
29339 \begin_layout Standard
29348 _stream_mssp_putchar writes a character at the MSSP stream
29351 \begin_layout Description
29352 putchar dummy function.
29353 This writes a character to a user specified manner.
29356 \begin_layout Standard
29357 In order to increase performance
29361 is declared in stdio.h as having its parameter in WREG (it has the wparam
29363 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
29364 in a user-friendly way.
29369 is the name of the variable that holds the character to print.
29370 An example follows:
29373 \begin_layout LyX-Code
29374 #include <pic18fregs.h>
29383 \begin_layout LyX-Code
29387 \begin_layout LyX-Code
29388 PORTA = c; /* dump character c to PORTA */
29391 \begin_layout LyX-Code
29399 \begin_layout LyX-Code
29403 \begin_layout LyX-Code
29404 stdout = STREAM_USER; /* this is not necessary, since stdout points
29407 \begin_layout LyX-Code
29408 * by default to STREAM_USER */
29411 \begin_layout LyX-Code
29413 \begin_inset Quotes sld
29416 This is a printf test
29419 \begin_inset Quotes srd
29425 \begin_layout LyX-Code
29429 \begin_layout LyX-Code
29433 \begin_layout Subsubsection
29437 \begin_layout Standard
29438 PIC16 contains an implementation of the printf-family of functions.
29439 There exist the following functions:
29442 \begin_layout LyX-Code
29443 extern unsigned int sprintf(char *buf, char *fmt, ...);
29446 \begin_layout LyX-Code
29447 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
29450 \begin_layout LyX-Code
29454 \begin_layout LyX-Code
29455 extern unsigned int printf(char *fmt, ...);
29458 \begin_layout LyX-Code
29459 extern unsigned int vprintf(char *fmt, va_lista ap);
29462 \begin_layout LyX-Code
29466 \begin_layout LyX-Code
29467 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
29470 \begin_layout LyX-Code
29471 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
29474 \begin_layout Standard
29475 For sprintf and vsprintf
29479 should normally be a data pointer where the resulting string will be placed.
29480 No range checking is done so the user should allocate the necessary buffer.
29481 For fprintf and vfprintf
29485 should be a stream pointer (i.e.
29486 stdout, STREAM_MSSP, etc...).
29489 \begin_layout Subsubsection
29493 \begin_layout Standard
29494 The PIC18F family of microcontrollers supports a number of interrupt sources.
29495 A list of these interrupts is shown in the following table:
29498 \begin_layout Standard
29500 \begin_inset Tabular
29501 <lyxtabular version="3" rows="11" columns="4">
29503 <column alignment="left" valignment="top" leftline="true" width="0">
29504 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29505 <column alignment="left" valignment="top" leftline="true" width="0">
29506 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29507 <row topline="true" bottomline="true">
29508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29511 \begin_layout Standard
29517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29520 \begin_layout Standard
29526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29529 \begin_layout Standard
29535 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29538 \begin_layout Standard
29545 <row topline="true">
29546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29549 \begin_layout Standard
29555 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29558 \begin_layout Standard
29559 PORTB change interrupt
29564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29567 \begin_layout Standard
29573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29576 \begin_layout Standard
29577 EEPROM/FLASH write complete interrupt
29583 <row topline="true">
29584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29587 \begin_layout Standard
29593 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29596 \begin_layout Standard
29597 INT0 external interrupt
29602 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29605 \begin_layout Standard
29611 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29614 \begin_layout Standard
29615 Bus collision interrupt
29621 <row topline="true">
29622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29625 \begin_layout Standard
29631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29634 \begin_layout Standard
29635 INT1 external interrupt
29640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29643 \begin_layout Standard
29649 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29652 \begin_layout Standard
29653 Low voltage detect interrupt
29659 <row topline="true">
29660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29663 \begin_layout Standard
29669 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29672 \begin_layout Standard
29673 INT2 external interrupt
29678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29681 \begin_layout Standard
29687 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29690 \begin_layout Standard
29691 Parallel slave port interrupt
29697 <row topline="true">
29698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29701 \begin_layout Standard
29707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29710 \begin_layout Standard
29711 CCP1 module interrupt
29716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29719 \begin_layout Standard
29725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29728 \begin_layout Standard
29729 AD convertion complete interrupt
29735 <row topline="true">
29736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29739 \begin_layout Standard
29745 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29748 \begin_layout Standard
29749 CCP2 module interrupt
29754 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29757 \begin_layout Standard
29763 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29766 \begin_layout Standard
29767 USART receive interrupt
29773 <row topline="true">
29774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29777 \begin_layout Standard
29783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29786 \begin_layout Standard
29787 TMR0 overflow interrupt
29792 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29795 \begin_layout Standard
29801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29804 \begin_layout Standard
29805 USART transmit interrupt
29811 <row topline="true">
29812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29815 \begin_layout Standard
29821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29824 \begin_layout Standard
29825 TMR1 overflow interrupt
29830 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29833 \begin_layout Standard
29839 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29842 \begin_layout Standard
29843 SSP receive/transmit interrupt
29849 <row topline="true">
29850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29853 \begin_layout Standard
29859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29862 \begin_layout Standard
29863 TMR2 matches PR2 interrupt
29868 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29871 \begin_layout Standard
29877 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29880 \begin_layout Standard
29887 <row topline="true" bottomline="true">
29888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29891 \begin_layout Standard
29897 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29900 \begin_layout Standard
29901 TMR3 overflow interrupt
29906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29909 \begin_layout Standard
29915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29918 \begin_layout Standard
29932 \begin_layout Standard
29934 The prototypes for these names are defined in the header file
29941 \begin_layout Standard
29943 In order to simplify signal handling, a number of macros is provided:
29947 \labelwidthstring 00.00.0000
29948 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
29949 high priority interrupts.
29954 is the function name to use.
29958 \labelwidthstring 00.00.0000
29959 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
29960 low priority interrupt.
29965 is the function name to use.
29969 \labelwidthstring 00.00.0000
29970 DEF_HANDLER(sig,handler) define a handler for signal
29976 \labelwidthstring 00.00.0000
29977 END_DEF end the declaration of the dispatch table.
29980 \begin_layout Standard
29981 Additionally there are two more macros to simplify the declaration of the
29986 \labelwidthstring 00.00.0000
29989 SIGHANDLER(handler)
29991 this declares the function prototype for the
29999 \labelwidthstring 00.00.0000
30000 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
30003 \begin_layout Standard
30004 An example of using the macros above is shown below:
30007 \begin_layout LyX-Code
30008 #include <pic18fregs.h>
30011 \begin_layout LyX-Code
30012 #include <signal.h>
30016 DEF_INTHIGH(high_int)
30019 \begin_layout LyX-Code
30020 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
30023 \begin_layout LyX-Code
30024 DEF_HANDLER(SIG_BCOL, _bcol_handler)
30027 \begin_layout LyX-Code
30032 SIGHANDLER(_tmr0_handler)
30035 \begin_layout LyX-Code
30039 \begin_layout LyX-Code
30040 /* action to be taken when timer 0 overflows */
30043 \begin_layout LyX-Code
30048 SIGHANDLERNAKED(_bcol_handler)
30051 \begin_layout LyX-Code
30055 \begin_layout LyX-Code
30059 \begin_layout LyX-Code
30060 /* action to be taken when bus collision occurs */
30063 \begin_layout LyX-Code
30067 \begin_layout LyX-Code
30071 \begin_layout LyX-Code
30075 \begin_layout Standard
30080 Special care should be taken when using the above scheme:
30083 \begin_layout Itemize
30084 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
30087 \begin_layout Itemize
30088 when declaring SIGHANDLERNAKED handler never forget to use
30092 for proper returning.
30095 \begin_layout Subsection
30099 \begin_layout Standard
30100 Here you can find some general tips for compiling programs with SDCC/pic16.
30103 \begin_layout Subsubsection
30107 \begin_layout Standard
30109 \begin_inset LatexCommand index
30114 size (that is 64 bytes) probably is enough for many programs.
30115 One must take care that when there are many levels of function nesting,
30116 or there is excessive usage of stack, its size should be extended.
30117 An example of such a case is the printf/sprintf family of functions.
30118 If you encounter problems like not being able to print integers, then you
30119 need to set the stack size around the maximum (256 for small stack model).
30120 The following diagram shows what happens when calling printf to print an
30124 \begin_layout LyX-Code
30125 printf () --> ltoa () --> ultoa () --> divschar ()
30128 \begin_layout Standard
30129 It is should be understood that stack is easily consumed when calling complicate
30131 Using command line arguments like -
30135 \begin_layout Standard
30144 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
30146 Other ways to reduce stack usage may exist.
30149 \begin_layout Subsection
30153 \begin_layout Subsubsection
30154 Extended Instruction Set
30157 \begin_layout Standard
30158 The PIC16 port emits code which is incompatible with the extended instruction
30159 set available with many newer devices.
30160 Make sure to always explicitly disable it, usually using
30163 \begin_layout Standard
30166 static __code char __at(__CONFIG4L) conf4l = /* more flags & */ _XINST_OFF_4L;
30169 \begin_layout Standard
30171 Some devices (namely 18f2455, 18f2550, 18f4455, and 18f4550) use _ENHCPU_OFF_4L
30172 instead of _XINST_OFF_4L.
30175 \begin_layout Subsubsection
30179 \begin_layout Standard
30180 The PIC16 port currently passes most but not all of the tests in SDCC's
30182 \begin_inset LatexCommand index
30183 name "Regression test (PIC16)"
30188 \begin_inset LatexCommand ref
30189 reference "sec:Quality-control"
30193 ), thus no automatic regression tests are currently performed for the PIC16
30197 \begin_layout Chapter
30201 \begin_layout Standard
30202 There are several approaches to debugging your code.
30203 This chapter is meant to show your options and to give detail on some of
30208 When writing your code:
30211 \begin_layout Itemize
30212 write your code with debugging in mind (avoid duplicating code, put conceptually
30213 similar variables into structs, use structured code, have strategic points
30214 within your code where all variables are consistent, ...)
30217 \begin_layout Itemize
30218 run a syntax-checking tool like splint
30219 \begin_inset LatexCommand index
30220 name "splint (syntax checking tool)"
30225 \begin_inset LatexCommand index
30226 name "lint (syntax checking tool)"
30234 \begin_layout Standard
30244 \begin_inset LatexCommand ref
30245 reference "lyx:more-pedantic-SPLINT"
30252 \begin_layout Itemize
30253 for the high level code use a C-compiler (like f.e.
30254 GCC) to compile run and debug the code on your host.
30259 \begin_layout Standard
30269 \begin_inset LatexCommand ref
30270 reference "lyx:more-pedantic-SPLINT"
30274 ) on how to handle syntax extensions like __xdata, __at(), ...
30278 \begin_layout Itemize
30279 use another C-compiler to compile code for your target.
30280 Always an option but not recommended:) And not very likely to help you.
30281 If you seriously consider walking this path you should at least occasionally
30282 check portability of your code.
30283 Most commercial compiler vendors will offer an evaluation version so you
30284 can test compile your code or snippets of your code.
30287 \begin_layout Standard
30288 Debugging on a simulator:
30291 \begin_layout Itemize
30292 there is a separate section about SDCDB (section
30293 \begin_inset LatexCommand ref
30294 reference "cha:Debugging-with-SDCDB"
30301 \begin_layout Itemize
30302 or (8051 specific) use a freeware/commercial simulator which interfaces
30304 \begin_inset LatexCommand index
30305 name "AOMF, AOMF51"
30310 \begin_inset LatexCommand ref
30311 reference "OMF file"
30315 ) optionally generated by SDCC.
30318 \begin_layout Standard
30319 Debugging On-target:
30322 \begin_layout Itemize
30323 use a MCU port pin to serially output debug data to the RS232 port of your
30325 You'll probably want some level shifting device typically involving a MAX232
30327 If the hardware serial port of the MCU is not available search for 'Software
30328 UART' in your favourite search machine.
30331 \begin_layout Itemize
30332 use an on-target monitor.
30333 In this context a monitor is a small program which usually accepts commands
30334 via a serial line and allows to set program counter, to single step through
30335 a program and read/write memory locations.
30336 For the 8051 good examples of monitors are paulmon and cmon51 (see section
30338 \begin_inset LatexCommand ref
30339 reference "sec:Related-open-source-tools"
30346 \begin_layout Itemize
30347 toggle MCU port pins at strategic points within your code and use an oscilloscop
30351 digital oscilloscope
30354 \begin_inset LatexCommand index
30355 name "Oscilloscope"
30359 with deep trace memory is really helpful especially if you have to debug
30360 a realtime application.
30361 If you need to monitor more pins than your oscilloscope provides you can
30362 sometimes get away with a small R-2R network.
30363 On a single channel oscilloscope you could f.e.
30364 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
30366 \begin_inset Formula $\Omega$
30369 resistor and the other one by a 5\InsetSpace ~
30371 \begin_inset Formula $\Omega$
30374 resistor to the oscilloscope probe (check output drive capability of the
30375 pins you want to monitor).
30376 If you need to monitor many more pins a
30383 \begin_layout Itemize
30397 \begin_inset LatexCommand index
30398 name "ICE (in circuit emulator)"
30403 Usually very expensive.
30404 And very nice to have too.
30405 And usually locks you (for years...) to the devices the ICE can emulate.
30409 \begin_layout Itemize
30410 use a remote debugger.
30411 In most 8-bit systems the symbol information is not available on the target,
30412 and a complete debugger is too bulky for the target system.
30413 Therefore usually a debugger on the host system connects to an on-target
30414 debugging stub which accepts only primitive commands.
30417 Terms to enter into your favourite search engine could be 'remote debugging',
30418 'gdb stub' or 'inferior debugger'.
30422 \begin_layout Itemize
30423 use an on target hardware debugger.
30424 Some of the more modern MCUs include hardware support for setting break
30425 points and monitoring/changing variables by using dedicated hardware pins.
30426 This facility doesn't require additional code to run on the target and
30431 doesn't affect runtime behaviour until a breakpoint is hit.
30432 For the mcs51 most hardware debuggers use the AOMF
30433 \begin_inset LatexCommand index
30434 name "AOMF, AOMF51"
30439 \begin_inset LatexCommand ref
30440 reference "OMF file"
30448 \begin_layout Standard
30452 \begin_layout Itemize
30453 if you are not familiar with any of the following terms you're likely to
30454 run into problems rather sooner than later:
30471 As an embedded programmer you
30475 to know them so why not look them up
30479 you have problems?)
30482 \begin_layout Itemize
30483 tell someone else about your problem (actually this is a surprisingly effective
30484 means to hunt down the bug even if the listener is not familiar with your
30486 As 'failure to communicate' is probably one of the job-induced deformations
30487 of an embedded programmer this is highly encouraged.
30490 \begin_layout Section
30491 Debugging with SDCDB
30492 \begin_inset LatexCommand label
30493 name "cha:Debugging-with-SDCDB"
30498 \begin_inset LatexCommand index
30499 name "SDCDB (debugger)"
30506 \begin_layout Standard
30507 SDCC is distributed with a source level debugger
30508 \begin_inset LatexCommand index
30514 The debugger uses a command line interface, the command repertoire of the
30515 debugger has been kept as close to gdb
30516 \begin_inset LatexCommand index
30521 (the GNU debugger) as possible.
30522 The configuration and build process is part of the standard compiler installati
30523 on, which also builds and installs the debugger in the target directory
30524 specified during configuration.
30525 The debugger allows you debug BOTH at the C source and at the ASM source
30529 \begin_layout Subsection
30530 Compiling for Debugging
30533 \begin_layout Standard
30538 \begin_layout Standard
30548 \begin_inset LatexCommand index
30553 option must be specified for all files for which debug information is to
30555 The compiler generates a .adb file for each of these files.
30556 The linker creates the .cdb
30557 \begin_inset LatexCommand index
30563 \begin_inset LatexCommand index
30568 files and the address information.
30569 This .cdb is used by the debugger.
30572 \begin_layout Subsection
30573 How the Debugger Works
30576 \begin_layout Standard
30581 \begin_layout Standard
30590 -debug option is specified the compiler generates extra symbol information
30591 some of which are put into the assembler source and some are put into the
30593 Then the linker creates the .cdb file from the individual .adb files with
30594 the address information for the symbols.
30595 The debugger reads the symbolic information generated by the compiler &
30596 the address information generated by the linker.
30597 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
30598 execution is controlled by the debugger.
30599 When a command is issued for the debugger, it translates it into appropriate
30600 commands for the simulator.
30601 (Currently SDCDM only connects to the simulator but
30606 \begin_inset LatexCommand url
30607 target "http://ec2drv.sf.net/"
30611 is an effort to connect directly to the hardware.)
30614 \begin_layout Subsection
30615 Starting the Debugger SDCDB
30618 \begin_layout Standard
30619 The debugger can be started using the following command line.
30620 (Assume the file you are debugging has the file name foo).
30634 The debugger will look for the following files.
30637 \begin_layout Itemize
30638 foo.c - the source file.
30641 \begin_layout Itemize
30642 foo.cdb - the debugger symbol information file.
30645 \begin_layout Itemize
30646 foo.ihx - the Intel hex format
30647 \begin_inset LatexCommand index
30648 name "Intel hex format"
30655 \begin_layout Subsection
30656 SDCDB Command Line Options
30659 \begin_layout Itemize
30664 \begin_layout Standard
30673 -directory=<source file directory> this option can used to specify the directory
30675 The debugger will look into the directory list specified for source, cdb
30677 The items in the directory list must be separated by ':', e.g.
30678 if the source files can be in the directories /home/src1 and /home/src2,
30683 \begin_layout Standard
30692 -directory option should be -
30696 \begin_layout Standard
30705 -directory=/home/src1:/home/src2.
30706 Note there can be no spaces in the option.
30710 \begin_layout Itemize
30711 -cd <directory> - change to the <directory>.
30714 \begin_layout Itemize
30715 -fullname - used by GUI front ends.
30718 \begin_layout Itemize
30719 -cpu <cpu-type> - this argument is passed to the simulator please see the
30720 simulator docs for details.
30723 \begin_layout Itemize
30724 -X <Clock frequency > this options is passed to the simulator please see
30725 the simulator docs for details.
30728 \begin_layout Itemize
30729 -s <serial port file> passed to simulator see the simulator docs for details.
30732 \begin_layout Itemize
30733 -S <serial in,out> passed to simulator see the simulator docs for details.
30736 \begin_layout Itemize
30737 -k <port number> passed to simulator see the simulator docs for details.
30740 \begin_layout Subsection
30741 SDCDB Debugger Commands
30744 \begin_layout Standard
30745 As mentioned earlier the command interface for the debugger has been deliberatel
30746 y kept as close the GNU debugger gdb, as possible.
30747 This will help the integration with existing graphical user interfaces
30748 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
30749 If you use a graphical user interface for the debugger you can skip this
30753 \begin_layout Subsubsection*
30754 break [line | file:line | function | file:function]
30757 \begin_layout Standard
30758 Set breakpoint at specified line or function:
30767 sdcdb>break foo.c:100
30769 sdcdb>break funcfoo
30771 sdcdb>break foo.c:funcfoo
30774 \begin_layout Subsubsection*
30775 clear [line | file:line | function | file:function ]
30778 \begin_layout Standard
30779 Clear breakpoint at specified line or function:
30788 sdcdb>clear foo.c:100
30790 sdcdb>clear funcfoo
30792 sdcdb>clear foo.c:funcfoo
30795 \begin_layout Subsubsection*
30799 \begin_layout Standard
30800 Continue program being debugged, after breakpoint.
30803 \begin_layout Subsubsection*
30807 \begin_layout Standard
30808 Execute till the end of the current function.
30811 \begin_layout Subsubsection*
30815 \begin_layout Standard
30816 Delete breakpoint number 'n'.
30817 If used without any option clear ALL user defined break points.
30820 \begin_layout Subsubsection*
30821 info [break | stack | frame | registers ]
30824 \begin_layout Itemize
30825 info break - list all breakpoints
30828 \begin_layout Itemize
30829 info stack - show the function call stack.
30832 \begin_layout Itemize
30833 info frame - show information about the current execution frame.
30836 \begin_layout Itemize
30837 info registers - show content of all registers.
30840 \begin_layout Subsubsection*
30844 \begin_layout Standard
30845 Step program until it reaches a different source line.
30846 Note: pressing <return> repeats the last command.
30849 \begin_layout Subsubsection*
30853 \begin_layout Standard
30854 Step program, proceeding through subroutine calls.
30857 \begin_layout Subsubsection*
30861 \begin_layout Standard
30862 Start debugged program.
30865 \begin_layout Subsubsection*
30869 \begin_layout Standard
30870 Print type information of the variable.
30873 \begin_layout Subsubsection*
30877 \begin_layout Standard
30878 print value of variable.
30881 \begin_layout Subsubsection*
30885 \begin_layout Standard
30886 load the given file name.
30887 Note this is an alternate method of loading file for debugging.
30890 \begin_layout Subsubsection*
30894 \begin_layout Standard
30895 print information about current frame.
30898 \begin_layout Subsubsection*
30902 \begin_layout Standard
30903 Toggle between C source & assembly source.
30906 \begin_layout Subsubsection*
30907 ! simulator command
30910 \begin_layout Standard
30911 Send the string following '!' to the simulator, the simulator response is
30913 Note the debugger does not interpret the command being sent to the simulator,
30914 so if a command like 'go' is sent the debugger can loose its execution
30915 context and may display incorrect values.
30918 \begin_layout Subsubsection*
30922 \begin_layout Standard
30925 My name is Bobby Brown"
30928 \begin_layout Subsection
30929 Interfacing SDCDB with DDD
30932 \begin_layout Standard
30933 \begin_inset Note Note
30936 \begin_layout Standard
30937 The screenshot was converted from png to eps with:
30938 \begin_inset Quotes sld
30941 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
30942 \begin_inset Quotes srd
30945 which produces a pretty compact eps file which is free from compression
30949 \begin_layout Standard
30950 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
30951 as this broke the build system on Sourceforge (pdf-file was broken.
30952 pdflatex does not accept eps files).
30960 \begin_layout Standard
30976 \begin_inset LatexCommand url
30977 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png"
30983 shows a screenshot of a debugging session with DDD
30984 \begin_inset LatexCommand index
30985 name "DDD (debugger)"
30989 (Unix only) on a simulated 8032.
30990 The debugging session might not run as smoothly as the screenshot suggests.
30991 The debugger allows setting of breakpoints, displaying and changing variables,
30992 single stepping through C and assembler code.
30995 The source was compiled with
31009 \begin_layout Standard
31021 -debug ddd_example.c
31034 and DDD was invoked with
31041 ddd -debugger "sdcdb -cpu 8032 ddd_example"
31044 \begin_layout Standard
31045 \begin_inset Note Note
31048 \begin_layout Standard
31049 Check that the double quotes or an apostrophe within the command line survive
31050 the LyX tool chain.
31051 Previously the apostrophes got slanted in the PDF output so a cut and paste
31060 \begin_layout Subsection
31061 Interfacing SDCDB with XEmacs
31062 \begin_inset LatexCommand index
31068 \begin_inset LatexCommand index
31076 \begin_layout Standard
31077 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
31078 sdcdb.el and sdcdbsrc.el.
31079 These two files can be found in the $(prefix)/bin directory after the installat
31081 These files need to be loaded into XEmacs for the interface to work.
31082 This can be done at XEmacs startup time by inserting the following into
31083 your '.xemacs' file (which can be found in your HOME directory):
31089 (load-file sdcdbsrc.el)
31095 .xemacs is a lisp file so the () around the command is REQUIRED.
31096 The files can also be loaded dynamically while XEmacs is running, set the
31097 environment variable 'EMACSLOADPATH' to the installation bin directory
31098 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
31099 To start the interface enter the following command:
31113 You will prompted to enter the file name to be debugged.
31118 The command line options that are passed to the simulator directly are
31119 bound to default values in the file sdcdbsrc.el.
31120 The variables are listed below, these values maybe changed as required.
31123 \begin_layout Itemize
31124 sdcdbsrc-cpu-type '51
31127 \begin_layout Itemize
31128 sdcdbsrc-frequency '11059200
31131 \begin_layout Itemize
31132 sdcdbsrc-serial nil
31135 \begin_layout Standard
31136 The following is a list of key mapping for the debugger interface.
31139 \begin_layout Standard
31162 binding\InsetSpace ~
31200 -------\InsetSpace ~
31271 sdcdb-back-from-src\InsetSpace ~
31300 rom-src\InsetSpace ~
31310 SDCDB continue command
31328 sdcdb-step-from-src\InsetSpace ~
31357 hatis-c-sexp\InsetSpace ~
31367 SDCDB ptypecommand for data at
31434 sdcdbsrc-delete\InsetSpace ~
31449 B Delete all breakpoints if no arg
31498 given or delete arg (C-u arg x)
31517 -frame\InsetSpace ~
31532 SDCDB Display current frame if no arg,
31581 given or display frame arg
31649 sdcdbsrc-goto-sdcdb\InsetSpace ~
31659 Goto the SDCDB output buffer
31678 t-c-sexp\InsetSpace ~
31689 SDCDB print command for data at
31756 sdcdbsrc-goto-sdcdb\InsetSpace ~
31767 o the SDCDB output buffer
31785 sdcdbsrc-mode\InsetSpace ~
31801 Toggles Sdcdbsrc mode (turns it
31817 sdcdb-finish-from-src\InsetSpace ~
31825 SDCDB finish command
31859 Set break for line with point
31874 sdcdbsrc-mode\InsetSpace ~
31890 Toggle Sdcdbsrc mode
31906 dbsrc-srcmode\InsetSpace ~
31930 \begin_layout Chapter
31934 \begin_layout Standard
31935 Here are a few guidelines that will help the compiler generate more efficient
31936 code, some of the tips are specific to this compiler others are generally
31937 good programming practice.
31940 \begin_layout Itemize
31941 Use the smallest data type to represent your data-value.
31942 If it is known in advance that the value is going to be less than 256 then
31943 use an 'unsigned char' instead of a 'short' or 'int'.
31944 Please note, that ANSI C requires both signed and unsigned chars to be
31945 promoted to 'signed int'
31946 \begin_inset LatexCommand index
31947 name "promotion to signed int"
31952 \begin_inset Marginal
31955 \begin_layout Standard
31964 before doing any operation.
31966 \begin_inset LatexCommand index
31967 name "type promotion"
31972 \begin_inset LatexCommand label
31973 name "type promotion"
31977 can be omitted, if the result is the same.
31978 The effect of the promotion rules together with the sign-extension is often
31983 \begin_layout Verse
31986 unsigned char uc = 0xfe;
31988 if (uc * uc < 0) /* this is true! */
32001 \begin_layout Standard
32008 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
32016 \begin_layout Verse
32019 (unsigned char) -12 / (signed char) -3 = ...
32022 \begin_layout Standard
32023 No, the result is not 4:
32026 \begin_layout Verse
32029 (int) (unsigned char) -12 / (int) (signed char) -3 =
32031 (int) (unsigned char)
32032 0xf4 / (int) (signed char) 0xfd =
32034 (int) 0x00f4 / (int) 0xfffd =
32039 (int) 244 / (int) -3 =
32041 (int) -81 = (int) 0xffaf;
32044 \begin_layout Standard
32045 Don't complain, that gcc gives you a different result.
32046 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
32047 Therefore the results are different.
32050 \begin_inset Quotes sld
32054 \begin_inset Quotes srd
32060 \begin_layout Quote
32063 If well-defined overflow characteristics are important and negative values
32064 are not, or if you want to steer clear of sign-extension problems when
32065 manipulating bits or bytes, use one of the corresponding unsigned types.
32066 (Beware when mixing signed and unsigned values in expressions, though.)
32069 character types (especially unsigned char) can be used as "tiny" integers,
32070 doing so is sometimes more trouble than it's worth, due to unpredictable
32071 sign extension and increased code size.
32075 \begin_layout Itemize
32076 Use unsigned when it is known in advance that the value is not going to
32078 This helps especially if you are doing division or multiplication, bit-shifting
32079 or are using an array index.
32082 \begin_layout Itemize
32083 NEVER jump into a LOOP.
32086 \begin_layout Itemize
32087 Declare the variables to be local
32088 \begin_inset LatexCommand index
32089 name "local variables"
32093 whenever possible, especially loop control variables (induction).
32096 \begin_layout Itemize
32097 Have a look at the assembly listing to get a
32098 \begin_inset Quotes sld
32102 \begin_inset Quotes srd
32105 for the code generation.
32108 \begin_layout Section
32109 Porting code from or to other compilers
32110 \begin_inset LatexCommand label
32111 name "sec:Porting-code-to-other-compilers"
32118 \begin_layout Itemize
32119 check whether endianness of the compilers differs and adapt where needed.
32122 \begin_layout Itemize
32123 check the device specific header files
32124 \begin_inset LatexCommand index
32125 name "Header files"
32130 \begin_inset LatexCommand index
32131 name "Include files"
32135 for compiler specific syntax.
32136 Eventually include the file <compiler.h
32137 \begin_inset LatexCommand index
32138 name "compiler.h (include file)"
32143 \begin_inset LatexCommand url
32144 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup"
32148 to allow using common header files.
32151 \begin_inset LatexCommand url
32152 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup"
32159 \begin_layout Itemize
32160 check whether the startup code contains the correct initialization (watchdog,
32164 \begin_layout Itemize
32165 check whether the sizes of short, int, long match.
32168 \begin_layout Itemize
32169 check if some 16 or 32 bit hardware registers require a specific addressing
32170 order (least significant or most significant byte first) and adapt if needed
32179 relate to time and not to lower/upper memory location here, so this is
32184 the same as endianness).
32187 \begin_layout Itemize
32188 check whether the keyword
32192 is used where needed.
32193 The compilers might differ in their optimization characteristics (as different
32194 versions of the same compiler might also use more clever optimizations
32195 this is good idea anyway).
32197 \begin_inset LatexCommand ref
32198 reference "sub:Common-interrupt-pitfall-volatile"
32205 \begin_layout Itemize
32206 check that the compilers are not told to suppress warnings.
32209 \begin_layout Itemize
32210 check and convert compiler specific extensions (interrupts, memory areas,
32214 \begin_layout Itemize
32215 check for differences in type promotion.
32216 Especially check for math operations on
32225 For the sake of C99 compatibility SDCC will probably promote these to
32229 more often than other compilers.
32230 Eventually insert explicit casts to
32239 Also check that the ~\InsetSpace ~
32241 \begin_inset LatexCommand index
32242 name "\\~\\/ Operator"
32249 \begin_inset LatexCommand index
32256 variables, use the !\InsetSpace ~
32259 \begin_inset LatexCommand ref
32260 reference "type promotion"
32265 \begin_inset LatexCommand ref
32266 reference "sec:Compatibility-with-previous"
32273 \begin_layout Itemize
32274 check the assembly code generated for interrupt routines (f.e.
32275 for calls to possibly non-reentrant library functions).
32278 \begin_layout Itemize
32279 check whether timing loops result in proper timing (or preferably consider
32280 a rewrite of the code with timer based delays instead).
32283 \begin_layout Itemize
32284 check for differences in printf parameters (some compilers push (va_arg
32285 \begin_inset LatexCommand index
32286 name "vararg, va\\_arg"
32290 ) char variables as
32294 others push them as
32300 \begin_inset LatexCommand ref
32301 reference "sec:Compatibility-with-previous"
32308 \begin_layout Itemize
32309 check the resulting memory map
32310 \begin_inset LatexCommand index
32316 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
32317 ly idata, pdata, xdata).
32318 Eventually check if unexpected library functions are included.
32321 \begin_layout Section
32323 \begin_inset LatexCommand index
32328 included in the distribution
32331 \begin_layout Standard
32333 \begin_inset Tabular
32334 <lyxtabular version="3" rows="12" columns="3">
32336 <column alignment="left" valignment="top" leftline="true" width="0pt">
32337 <column alignment="left" valignment="top" leftline="true" width="0pt">
32338 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32339 <row topline="true" bottomline="true">
32340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32343 \begin_layout Standard
32351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32354 \begin_layout Standard
32362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32365 \begin_layout Standard
32374 <row topline="true">
32375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32378 \begin_layout Standard
32380 \begin_inset LatexCommand index
32390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32393 \begin_layout Standard
32394 Simulator for various architectures
32399 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32402 \begin_layout Standard
32409 <row topline="true">
32410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32413 \begin_layout Standard
32419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32422 \begin_layout Standard
32424 \begin_inset LatexCommand index
32425 name "Header files"
32430 \begin_inset LatexCommand index
32431 name "Include files"
32440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32443 \begin_layout Standard
32444 sdcc/support/scripts
32450 <row topline="true">
32451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32454 \begin_layout Standard
32460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32463 \begin_layout Standard
32464 header file conversion
32469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32472 \begin_layout Standard
32473 sdcc/support/scripts
32479 <row topline="true">
32480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32483 \begin_layout Standard
32489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32492 \begin_layout Standard
32498 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32501 \begin_layout Standard
32517 <row topline="true">
32518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32521 \begin_layout Standard
32527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32530 \begin_layout Standard
32536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32539 \begin_layout Standard
32555 <row topline="true">
32556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32559 \begin_layout Standard
32565 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32568 \begin_layout Standard
32574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32577 \begin_layout Standard
32593 <row topline="true">
32594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32597 \begin_layout Standard
32603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32606 \begin_layout Standard
32612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32615 \begin_layout Standard
32631 <row topline="true">
32632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32635 \begin_layout Standard
32641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32644 \begin_layout Standard
32650 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32653 \begin_layout Standard
32669 <row topline="true">
32670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32673 \begin_layout Standard
32679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32682 \begin_layout Standard
32688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32691 \begin_layout Standard
32707 <row topline="true">
32708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32711 \begin_layout Standard
32717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32720 \begin_layout Standard
32726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32729 \begin_layout Standard
32745 <row topline="true" bottomline="true">
32746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32749 \begin_layout Standard
32755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32758 \begin_layout Standard
32760 \begin_inset LatexCommand index
32761 name "packihx (tool)"
32770 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32773 \begin_layout Standard
32798 \begin_layout Section
32800 \begin_inset LatexCommand index
32801 name "Documentation"
32805 included in the distribution
32808 \begin_layout Standard
32810 \begin_inset Tabular
32811 <lyxtabular version="3" rows="10" columns="2">
32813 <column alignment="block" valignment="top" leftline="true" width="40col%">
32814 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
32815 <row topline="true" bottomline="true" endhead="true">
32816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32819 \begin_layout Standard
32827 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32830 \begin_layout Standard
32833 Filename / Where to get
32839 <row topline="true">
32840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32843 \begin_layout Standard
32844 SDCC Compiler User Guide
32849 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32852 \begin_layout Standard
32853 You're reading it right now
32865 \begin_inset LatexCommand url
32866 target "http://sdcc.sourceforge.net/doc/sdccman.pdf"
32876 <row topline="true">
32877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32880 \begin_layout Standard
32886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32889 \begin_layout Standard
32902 \begin_inset LatexCommand url
32903 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog"
32913 <row topline="true">
32914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32917 \begin_layout Standard
32919 \begin_inset LatexCommand index
32920 name "asXXXX (as-gbz80, as-hc08, asx8051, as-z80)"
32925 \begin_inset LatexCommand index
32926 name "Assembler documentation"
32933 \begin_inset LatexCommand index
32939 \begin_inset LatexCommand index
32940 name "Linker documentation"
32949 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32952 \begin_layout Standard
32953 sdcc/as/doc/asxhtm.html
32965 \begin_inset LatexCommand url
32966 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html"
32976 <row topline="true">
32977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32980 \begin_layout Standard
32981 SDCC regression test
32982 \begin_inset LatexCommand index
32983 name "Regression test"
32992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32995 \begin_layout Standard
32996 sdcc/doc/test_suite_spec.pdf
33008 \begin_inset LatexCommand url
33009 target "http://sdcc.sourceforge.net/doc/test_suite_spec.pdf"
33019 <row topline="true">
33020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33023 \begin_layout Standard
33029 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33032 \begin_layout Standard
33045 \begin_inset LatexCommand url
33046 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/"
33056 <row topline="true">
33057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33060 \begin_layout Standard
33061 Notes on debugging with SDCDB
33062 \begin_inset LatexCommand index
33063 name "SDCDB (debugger)"
33072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33075 \begin_layout Standard
33076 sdcc/debugger/README
33088 \begin_inset LatexCommand url
33089 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README"
33099 <row topline="true">
33100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33103 \begin_layout Standard
33105 \begin_inset LatexCommand index
33110 Software simulator for microcontrollers
33115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33118 \begin_layout Standard
33148 \begin_inset LatexCommand url
33149 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html"
33159 <row topline="true">
33160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33163 \begin_layout Standard
33164 Temporary notes on the pic16
33165 \begin_inset LatexCommand index
33175 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33178 \begin_layout Standard
33179 sdcc/src/pic16/NOTES
33191 \begin_inset LatexCommand url
33192 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES"
33202 <row topline="true" bottomline="true">
33203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33206 \begin_layout Standard
33207 SDCC internal documentation (debugging file format)
33212 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33215 \begin_layout Standard
33245 \begin_inset LatexCommand url
33246 target "http://sdcc.sourceforge.net/doc/cdbfileformat.pdf"
33265 \begin_layout Section
33266 Related open source tools
33267 \begin_inset LatexCommand label
33268 name "sec:Related-open-source-tools"
33273 \begin_inset LatexCommand index
33274 name "Related tools"
33281 \begin_layout Standard
33283 \begin_inset Tabular
33284 <lyxtabular version="3" rows="16" columns="3">
33286 <column alignment="left" valignment="top" leftline="true" width="0pt">
33287 <column alignment="block" valignment="top" leftline="true" width="30line%">
33288 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
33289 <row topline="true" bottomline="true">
33290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33293 \begin_layout Standard
33301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33304 \begin_layout Standard
33312 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33315 \begin_layout Standard
33324 <row topline="true">
33325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33328 \begin_layout Standard
33330 \begin_inset LatexCommand index
33331 name "gpsim (pic simulator)"
33340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33343 \begin_layout Standard
33349 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33352 \begin_layout Standard
33353 \begin_inset LatexCommand url
33354 target "http://www.dattalo.com/gnupic/gpsim.html"
33364 <row topline="true">
33365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33368 \begin_layout Standard
33370 \begin_inset LatexCommand index
33371 name "gputils (pic tools)"
33380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33383 \begin_layout Standard
33389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33392 \begin_layout Standard
33393 \begin_inset LatexCommand url
33394 target "http://sourceforge.net/projects/gputils"
33404 <row topline="true">
33405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33408 \begin_layout Standard
33414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33417 \begin_layout Standard
33423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33426 \begin_layout Standard
33427 \begin_inset LatexCommand url
33428 target "http://freshmeat.net/projects/flp5/"
33438 <row topline="true">
33439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33442 \begin_layout Standard
33448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33451 \begin_layout Standard
33452 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
33458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33461 \begin_layout Standard
33462 \begin_inset LatexCommand url
33463 target "http://sourceforge.net/projects/ec2drv"
33473 <row topline="true">
33474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33477 \begin_layout Standard
33479 \begin_inset LatexCommand index
33480 name "indent (source formatting tool)"
33489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33492 \begin_layout Standard
33493 Formats C source - Master of the white spaces
33498 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33501 \begin_layout Standard
33502 \begin_inset LatexCommand url
33503 target "http://directory.fsf.org/GNU/indent.html"
33513 <row topline="true">
33514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33517 \begin_layout Standard
33519 \begin_inset LatexCommand index
33520 name "srecord (bin, hex, ... tool)"
33529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33532 \begin_layout Standard
33533 Object file conversion, checksumming, ...
33538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33541 \begin_layout Standard
33542 \begin_inset LatexCommand url
33543 target "http://sourceforge.net/projects/srecord"
33553 <row topline="true">
33554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33557 \begin_layout Standard
33559 \begin_inset LatexCommand index
33560 name "objdump (tool)"
33569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33572 \begin_layout Standard
33573 Object file conversion, ...
33578 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33581 \begin_layout Standard
33582 Part of binutils (should be there anyway)
33588 <row topline="true">
33589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33592 \begin_layout Standard
33598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33601 \begin_layout Standard
33602 8051 monitor (hex up-/download, single step, disassemble)
33607 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33610 \begin_layout Standard
33611 \begin_inset LatexCommand url
33612 target "http://sourceforge.net/projects/cmon51"
33622 <row topline="true">
33623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33626 \begin_layout Standard
33628 \begin_inset LatexCommand index
33629 name "doxygen (source documentation tool)"
33638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33641 \begin_layout Standard
33642 Source code documentation system
33647 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33650 \begin_layout Standard
33651 \begin_inset LatexCommand url
33652 target "http://www.doxygen.org"
33662 <row topline="true">
33663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33666 \begin_layout Standard
33672 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33675 \begin_layout Standard
33676 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
33681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33684 \begin_layout Standard
33685 \begin_inset LatexCommand url
33686 target "http://www.kdevelop.org"
33696 <row topline="true">
33697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33700 \begin_layout Standard
33706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33709 \begin_layout Standard
33710 8051 monitor (hex up-/download, single step, disassemble)
33715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33718 \begin_layout Standard
33719 \begin_inset LatexCommand url
33720 target "http://www.pjrc.com/tech/8051/paulmon2.html"
33730 <row topline="true">
33731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33734 \begin_layout Standard
33736 \begin_inset LatexCommand index
33737 name "splint (syntax checking tool)"
33746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33749 \begin_layout Standard
33750 Statically checks c sources (see
33751 \begin_inset LatexCommand ref
33752 reference "lyx:more-pedantic-SPLINT"
33761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33764 \begin_layout Standard
33765 \begin_inset LatexCommand url
33766 target "http://www.splint.org"
33776 <row topline="true" bottomline="true">
33777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33780 \begin_layout Standard
33782 \begin_inset LatexCommand index
33783 name "DDD (debugger)"
33792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33795 \begin_layout Standard
33796 Debugger, serves nicely as GUI to SDCDB
33797 \begin_inset LatexCommand index
33798 name "SDCDB (debugger)"
33807 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33810 \begin_layout Standard
33811 \begin_inset LatexCommand url
33812 target "http://www.gnu.org/software/ddd/"
33822 <row bottomline="true">
33823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33826 \begin_layout Standard
33828 \begin_inset LatexCommand index
33834 \begin_inset LatexCommand index
33835 name "d52 (disassembler)"
33844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33847 \begin_layout Standard
33848 Disassembler, can count instruction cycles
33849 \begin_inset LatexCommand index
33850 name "instruction cycles (count)"
33854 , use with options -pnd
33859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33862 \begin_layout Standard
33863 \begin_inset LatexCommand url
33864 target "http://www.8052.com/users/disasm/"
33874 <row bottomline="true">
33875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33878 \begin_layout Standard
33880 \begin_inset LatexCommand index
33890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33893 \begin_layout Standard
33894 Cross platform build system, generates Makefiles
33895 \begin_inset LatexCommand index
33900 and project workspaces
33901 \begin_inset LatexCommand index
33902 name "project workspace"
33911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33914 \begin_layout Standard
33915 \begin_inset LatexCommand url
33916 target "http://www.cmake.org"
33924 and a dedicated wiki entry:
33925 \begin_inset LatexCommand url
33926 target "http://www.cmake.org/Wiki/CmakeSdcc"
33945 \begin_layout Section
33946 Related documentation / recommended reading
33949 \begin_layout Standard
33951 \begin_inset Tabular
33952 <lyxtabular version="3" rows="7" columns="3">
33954 <column alignment="left" valignment="top" leftline="true" width="0pt">
33955 <column alignment="left" valignment="top" leftline="true" width="0">
33956 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
33957 <row topline="true" bottomline="true">
33958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33961 \begin_layout Standard
33969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33972 \begin_layout Standard
33980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33983 \begin_layout Standard
33992 <row topline="true">
33993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33996 \begin_layout Standard
34011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34014 \begin_layout Standard
34016 \begin_inset LatexCommand index
34017 name "C Reference card"
34026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34029 \begin_layout Standard
34030 \begin_inset LatexCommand url
34031 target "http://refcards.com/refcards/c/index.html"
34041 <row topline="true">
34042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34045 \begin_layout Standard
34051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34054 \begin_layout Standard
34056 \begin_inset LatexCommand index
34066 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34069 \begin_layout Standard
34070 \begin_inset LatexCommand url
34071 target "http://www.c-faq.com"
34081 <row topline="true">
34082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34085 \begin_layout Standard
34091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34094 \begin_layout Standard
34095 \begin_inset Quotes sld
34099 \begin_inset Quotes srd
34107 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34110 \begin_layout Standard
34113 \begin_inset LatexCommand url
34114 target "http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899"
34124 <row topline="true">
34125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34128 \begin_layout Standard
34134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34137 \begin_layout Standard
34138 \begin_inset Quotes sld
34141 Extensions for Embedded C
34142 \begin_inset Quotes srd
34150 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34153 \begin_layout Standard
34156 \begin_inset LatexCommand url
34157 target "http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf"
34167 <row topline="true">
34168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34171 \begin_layout Standard
34177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34180 \begin_layout Standard
34181 Latest datasheet of target CPU
34186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34189 \begin_layout Standard
34196 <row topline="true" bottomline="true">
34197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34200 \begin_layout Standard
34206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34209 \begin_layout Standard
34210 Revision history of datasheet
34215 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34218 \begin_layout Standard
34234 \begin_layout Section
34235 Application notes specifically for SDCC
34238 \begin_layout Standard
34239 SDCC makes no claims about the completeness of this list and about up-to-datenes
34240 s or correctness of the application notes
34241 \begin_inset LatexCommand index
34242 name "Application notes"
34249 \begin_layout Standard
34253 \begin_inset Tabular
34254 <lyxtabular version="3" rows="7" columns="3">
34256 <column alignment="block" valignment="top" leftline="true" width="17col%">
34257 <column alignment="block" valignment="top" leftline="true" width="27col%">
34258 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
34259 <row topline="true" bottomline="true">
34260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34263 \begin_layout Standard
34272 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
34275 \begin_layout Standard
34284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34287 \begin_layout Standard
34297 <row topline="true">
34298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34301 \begin_layout Standard
34309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34312 \begin_layout Standard
34315 Using the SDCC Compiler for the DS80C400
34316 \begin_inset LatexCommand index
34326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34329 \begin_layout Standard
34332 \begin_inset LatexCommand url
34333 target "http://pdfserv.maxim-ic.com/en/an/AN3346.pdf"
34343 <row topline="true">
34344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34347 \begin_layout Standard
34355 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
34358 \begin_layout Standard
34361 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
34362 \begin_inset LatexCommand index
34367 Family of Microcontrollers
34372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34375 \begin_layout Standard
34378 \begin_inset LatexCommand url
34379 target "http://pdfserv.maxim-ic.com/en/an/AN3477.pdf"
34389 <row topline="true">
34390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34393 \begin_layout Standard
34396 Silicon Laboratories / Cygnal
34401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34404 \begin_layout Standard
34407 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
34408 \begin_inset LatexCommand index
34418 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34421 \begin_layout Standard
34424 \begin_inset LatexCommand url
34425 target "http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf"
34435 <row topline="true">
34436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34439 \begin_layout Standard
34442 Ramtron / Goal Semiconductor
34447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34450 \begin_layout Standard
34453 Interfacing SDCC to Syn and Textpad
34458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34461 \begin_layout Standard
34464 \begin_inset LatexCommand url
34465 target "http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp"
34475 <row topline="true">
34476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34479 \begin_layout Standard
34482 Ramtron / Goal Semiconductor
34487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34490 \begin_layout Standard
34493 Installing and Configuring SDCC and Crimson Editor
34498 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34501 \begin_layout Standard
34504 \begin_inset LatexCommand url
34505 target "http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp"
34515 <row topline="true" bottomline="true">
34516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34519 \begin_layout Standard
34527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34530 \begin_layout Standard
34533 MSC12xx Programming with SDCC
34538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34541 \begin_layout Standard
34544 \begin_inset LatexCommand url
34545 target "http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf"
34562 \begin_layout Section
34566 \begin_layout Standard
34567 Some questions answered, some pointers given - it might be time to in turn
34575 \begin_layout Itemize
34576 can you solve your project with the selected microcontroller? Would you
34577 find out early or rather late that your target is too small/slow/whatever?
34578 Can you switch to a slightly better device if it doesn't fit?
34581 \begin_layout Itemize
34582 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
34583 and/or another programming language be more adequate? Would an operating
34584 system on the target device help?
34587 \begin_layout Itemize
34588 if you solved the problem, will the marketing department be happy?
34591 \begin_layout Itemize
34592 if the marketing department is happy, will customers be happy?
34595 \begin_layout Itemize
34596 if you're the project manager, marketing department and maybe even the customer
34597 in one person, have you tried to see the project from the outside?
34600 \begin_layout Itemize
34601 is the project done if you think it is done? Or is just that other interface/pro
34602 tocol/feature/configuration/option missing? How about website, manual(s),
34603 internationali(z|s)ation, packaging, labels, 2nd source for components,
34604 electromagnetic compatability/interference, documentation for production,
34605 production test software, update mechanism, patent issues?
34608 \begin_layout Itemize
34609 is your project adequately positioned in that magic triangle: fame, fortune,
34613 \begin_layout Standard
34614 Maybe not all answers to these questions are known and some answers may
34619 , nevertheless knowing these questions may help you to avoid burnout
34623 \begin_layout Standard
34624 burnout is bad for electronic devices, programmers and motorcycle tyres
34630 Chances are you didn't want to hear some of them...
34633 \begin_layout Chapter
34635 \begin_inset LatexCommand index
34643 \begin_layout Standard
34644 SDCC has grown to be a large project.
34645 The compiler alone (without the preprocessor, assembler and linker) is
34646 well over 150,000 lines of code (blank stripped).
34647 The open source nature of this project is a key to its continued growth
34649 You gain the benefit and support of many active software developers and
34651 Is SDCC perfect? No, that's why we need your help.
34652 The developers take pride in fixing reported bugs.
34653 You can help by reporting the bugs and helping other SDCC users.
34654 There are lots of ways to contribute, and we encourage you to take part
34655 in making SDCC a great software package.
34659 \begin_layout Standard
34660 The SDCC project is hosted on the SDCC sourceforge site at
34661 \begin_inset LatexCommand htmlurl
34662 target "http://sourceforge.net/projects/sdcc"
34667 You'll find the complete set of mailing lists
34668 \begin_inset LatexCommand index
34669 name "Mailing list(s)"
34673 , forums, bug reporting system, patch submission
34674 \begin_inset LatexCommand index
34675 name "Patch submission"
34680 \begin_inset LatexCommand index
34685 area and Subversion code repository
34686 \begin_inset LatexCommand index
34687 name "Subversion code repository"
34694 \begin_layout Section
34696 \begin_inset LatexCommand index
34697 name "Bug reporting"
34702 \begin_inset LatexCommand index
34703 name "Reporting bugs"
34710 \begin_layout Standard
34711 The recommended way of reporting bugs is using the infrastructure of the
34713 You can follow the status of bug reports there and have an overview about
34717 \begin_layout Standard
34718 Bug reports are automatically forwarded to the developer mailing list and
34719 will be fixed ASAP.
34720 When reporting a bug, it is very useful to include a small test program
34721 (the smaller the better) which reproduces the problem.
34722 If you can isolate the problem by looking at the generated assembly code,
34723 this can be very helpful.
34724 Compiling your program with the -
34728 \begin_layout Standard
34738 \begin_inset LatexCommand index
34739 name "-\\/-dumpall"
34743 option can sometimes be useful in locating optimization problems.
34744 When reporting a bug please make sure you:
34747 \begin_layout Enumerate
34748 Attach the code you are compiling with SDCC.
34752 \begin_layout Enumerate
34753 Specify the exact command you use to run SDCC, or attach your Makefile.
34757 \begin_layout Enumerate
34758 Specify the SDCC version (type "
34764 "), your platform, and operating system.
34768 \begin_layout Enumerate
34769 Provide an exact copy of any error message or incorrect output.
34773 \begin_layout Enumerate
34774 Put something meaningful in the subject of your message.
34777 \begin_layout Standard
34778 Please attempt to include these 5 important parts, as applicable, in all
34779 requests for support or when reporting any problems or bugs with SDCC.
34780 Though this will make your message lengthy, it will greatly improve your
34781 chance that SDCC users and developers will be able to help you.
34782 Some SDCC developers are frustrated by bug reports without code provided
34783 that they can use to reproduce and ultimately fix the problem, so please
34784 be sure to provide sample code if you are reporting a bug!
34787 \begin_layout Standard
34788 Please have a short check that you are using a recent version of SDCC and
34789 the bug is not yet known.
34790 This is the link for reporting bugs:
34791 \begin_inset LatexCommand htmlurl
34792 target "http://sourceforge.net/tracker/?group_id=599&atid=100599"
34797 With SDCC on average having more than 200 downloads
34798 \begin_inset LatexCommand index
34803 on sourceforge per day
34807 \begin_layout Standard
34808 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
34809 between 2002 and 2005.
34810 This does not include other methods of distribution.
34815 there must be some users.
34816 So it's not exactly easy to find a new bug.
34817 If you find one we need it:
34819 reporting bugs is good
34824 \begin_layout Section
34825 Requesting Features
34826 \begin_inset LatexCommand label
34827 name "sub:Requesting-Features"
34832 \begin_inset LatexCommand index
34833 name "Feature request"
34838 \begin_inset LatexCommand index
34839 name "Requesting features"
34846 \begin_layout Standard
34847 Like bug reports feature requests are forwarded to the developer mailing
34849 This is the link for requesting features:
34850 \begin_inset LatexCommand htmlurl
34851 target "http://sourceforge.net/tracker/?group_id=599&atid=350599"
34858 \begin_layout Section
34862 \begin_layout Standard
34863 Like bug reports contributed patches are forwarded to the developer mailing
34865 This is the link for submitting patches
34866 \begin_inset LatexCommand index
34867 name "Patch submission"
34872 \begin_inset LatexCommand url
34873 target "http://sourceforge.net/tracker/?group_id=599&atid=300599"
34880 \begin_layout Standard
34881 You need to specify some parameters to the
34885 command for the patches to be useful.
34886 If you modified more than one file a patch created f.e.
34891 \begin_inset Quotes sld
34894 diff -Naur unmodified_directory modified_directory >my_changes.patch
34895 \begin_inset Quotes srd
34901 will be fine, otherwise
34905 \begin_inset Quotes sld
34908 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
34909 \begin_inset Quotes srd
34918 \begin_layout Section
34922 \begin_layout Standard
34923 These links should take you directly to the
34924 \begin_inset LatexCommand url
34925 name "Mailing lists"
34926 target "http://sourceforge.net/mail/?group_id=599"
34934 \begin_layout Standard
34935 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
34936 automated messages (mid 2003)
34942 \begin_inset LatexCommand url
34944 target "http://sourceforge.net/forum/?group_id=599"
34949 \begin_inset LatexCommand index
34950 name "Mailing list(s)"
34954 and forums are archived and searchable so if you are lucky someone already
34955 had a similar problem.
34956 While mails to the lists themselves are delivered promptly their web front
34957 end on sourceforge sometimes shows a severe time lag (up to several weeks),
34958 if you're seriously using SDCC please consider subscribing to the lists.
34961 \begin_layout Section
34965 \begin_layout Standard
34966 You can follow the status of the Subversion version
34967 \begin_inset LatexCommand index
34972 of SDCC by watching the Changelog
34973 \begin_inset LatexCommand index
34978 in the Subversion repository
34981 \begin_inset LatexCommand htmlurl
34982 target "http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog"
34989 \begin_layout Section
34990 Subversion Source Code Repository
34993 \begin_layout Standard
35003 \begin_layout Standard
35017 or the filenames of the snapshot versions of SDCC include date and its
35019 \begin_inset LatexCommand index
35020 name "Subversion code repository"
35025 Subversion allows to download the source of recent or previous versions
35027 \begin_inset LatexCommand url
35028 target "http://sourceforge.net/svn/?group_id=599"
35032 (by number or by date).
35033 An on-line source code browser and detailled instructions are also available
35035 SDCC versions starting from 1999 up to now are available (currently the
35036 versions prior to the conversion from cvs
35037 \begin_inset LatexCommand index
35038 name "cvs|see{Subversion}"
35042 to Subversion (April 2006) are either by accessible by Subversion or by
35046 \begin_layout Section
35048 \begin_inset LatexCommand index
35049 name "Release policy"
35056 \begin_layout Standard
35057 Historically there often were long delays between official releases and
35058 the sourceforge download area tends to get not updated at all.
35059 Excuses in the past might have referred to problems with live range analysis,
35060 but as this was fixed a while ago, the current problem is that another
35061 excuse has to be found.
35062 Kidding aside, we have to get better there! On the other hand there are
35063 daily snapshots available at
35064 \begin_inset LatexCommand htmlurl
35066 target "http://sdcc.sourceforge.net/snap.php"
35070 , and you can always build the very last version (hopefully with many bugs
35071 fixed, and features added) from the source code available at
35072 \begin_inset LatexCommand htmlurl
35074 target "http://sdcc.sourceforge.net/snap.php#Source"
35080 \begin_inset LatexCommand index
35086 \begin_inset LatexCommand index
35092 \begin_inset LatexCommand url
35093 target "http://sdcc.wiki.sourceforge.net/"
35097 also holds some information about past and future releases.
35100 \begin_layout Section
35102 \begin_inset LatexCommand index
35110 \begin_layout Standard
35111 You'll find some small examples in the directory
35113 sdcc/device/examples/.
35116 More examples and libraries are available at
35118 The SDCC Open Knowledge Resource
35119 \begin_inset LatexCommand url
35120 target "http://sdccokr.dl9sec.de/"
35127 \begin_inset LatexCommand url
35128 target "http://www.pjrc.com/tech/8051/"
35135 \begin_layout Standard
35136 \begin_inset Note Note
35139 \begin_layout Standard
35140 I did insert a reference to Paul's web site here although it seems rather
35141 dedicated to a specific 8032 board (I think it's okay because it f.e.
35142 shows LCD/Harddisc interface and has a free 8051 monitor.
35143 Independent 8032 board vendors face hard competition of heavily subsidized
35144 development boards anyway).
35147 \begin_layout Standard
35148 Maybe we should include some links to real world applications.
35149 Preferably pointer to pointers (one for each architecture) so this stays
35158 \begin_layout Section
35160 \begin_inset LatexCommand label
35161 name "sec:Quality-control"
35166 \begin_inset LatexCommand index
35167 name "Quality control"
35174 \begin_layout Standard
35175 The compiler is passed through snaphot build compile and build checks.
35181 \begin_inset LatexCommand index
35182 name "Regression test"
35186 check that SDCC itself compiles flawlessly on several host platforms (i386,
35187 Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
35188 and checks the quality of the code generated by SDCC by running the code
35189 for several target platforms through simulators.
35190 The regression test suite comprises more than 100 files which expand to
35191 more than 500 test cases which include more than 4500 tests.
35192 The results of these tests are published daily on SDCC's snapshot page
35193 (click on the red or green symbols on the right side of
35194 \begin_inset LatexCommand url
35195 target "http://sdcc.sourceforge.net/snap.php"
35202 \begin_layout Standard
35203 There is a separate document
35206 \begin_inset LatexCommand index
35214 \begin_inset LatexCommand url
35215 target "http://sdcc.sourceforge.net/doc/test_suite_spec.pdf"
35219 about the regression test suite.
35222 \begin_layout Standard
35223 You'll find the test code in the directory
35225 sdcc/support/regression
35228 You can run these tests manually by running
35232 in this directory (or f.e.
35237 \begin_inset Quotes sld
35241 \begin_inset Quotes srd
35247 if you don't want to run the complete tests).
35248 The test code might also be interesting if you want to look for examples
35249 \begin_inset LatexCommand index
35254 checking corner cases of SDCC or if you plan to submit patches
35255 \begin_inset LatexCommand index
35256 name "Patch submission"
35263 \begin_layout Standard
35264 The PIC14 port uses a different set of regression tests
35265 \begin_inset LatexCommand index
35266 name "Regression test (PIC14)"
35270 , you'll find them in the directory
35272 sdcc/src/regression
35277 \begin_layout Section
35278 Use of SDCC in Education
35281 \begin_layout Standard
35290 \begin_layout Standard
35291 the phrase "use in education" might evoke the association "
35295 fit for use in education".
35296 This connotation is not intended but nevertheless risked as the licensing
35297 of SDCC makes it difficult to offer educational discounts
35303 If your rationales are to:
35306 \begin_layout Enumerate
35307 give students a chance to understand the
35311 steps of code generation
35314 \begin_layout Enumerate
35315 have a curriculum that can be extended for years.
35316 Then you could use an fpga board as target and your curriculum will seamlessly
35317 extend from logic synthesis (
35318 \begin_inset LatexCommand url
35319 name "http://www.opencores.org"
35320 target "opencores.org"
35325 \begin_inset LatexCommand url
35327 target "http://www.oregano.at/ip/ip01.htm"
35331 ), over assembly programming, to C to FPGA compilers (
35332 \begin_inset LatexCommand url
35334 target "http://sf.net/projects/fpgac"
35341 \begin_layout Enumerate
35342 be able to insert excursions about skills like using a revision control
35343 system, submitting/applying patches, using a type-setting (as opposed to
35344 word-processing) engine LyX/LaTeX, using
35345 \begin_inset LatexCommand url
35347 target "http://www.sf.net"
35352 \begin_inset LatexCommand url
35354 target "http://en.wikipedia.org/wiki/Netiquette"
35358 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
35359 Source Software, CPU simulation, compiler regression tests
35360 \begin_inset LatexCommand index
35361 name "Regression test"
35368 And if there should be a shortage of ideas then you can always point students
35369 to the ever-growing feature request list
35370 \begin_inset LatexCommand htmlurl
35371 target "http://sourceforge.net/tracker/?group_id=599&atid=350599"
35378 \begin_layout Enumerate
35379 not tie students to a specific host platform and instead allow them to use
35384 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
35386 \begin_inset LatexCommand url
35388 target "http://www.laptop.org"
35395 \begin_layout Enumerate
35396 not encourage students to use illegal copies of educational software
35399 \begin_layout Enumerate
35400 be immune to licensing/availability/price changes of the chosen tool chain
35403 \begin_layout Enumerate
35404 be able to change to a new target platform without having to adopt a new
35408 \begin_layout Enumerate
35409 have complete control over and insight into the tool chain
35412 \begin_layout Enumerate
35413 make your students aware about the pros and cons of open source software
35417 \begin_layout Enumerate
35418 give back to the public as you are probably at least partially publicly
35422 \begin_layout Enumerate
35423 give students a chance to publicly prove their skills and to possibly see
35424 a world wide impact
35427 \begin_layout Standard
35428 then SDCC is probably among the first choices.
35429 Well, probably SDCC might be the only choice.
35434 \begin_layout Chapter
35435 SDCC Technical Data
35438 \begin_layout Section
35440 \begin_inset LatexCommand index
35441 name "Optimizations"
35448 \begin_layout Standard
35449 SDCC performs a host of standard optimizations in addition to some MCU specific
35454 \begin_layout Subsection
35455 Sub-expression Elimination
35456 \begin_inset LatexCommand index
35457 name "Subexpression elimination"
35464 \begin_layout Standard
35465 The compiler does local and
35484 \begin_layout Verse
35492 \begin_layout Standard
35493 will be translated to
35496 \begin_layout Verse
35506 \begin_layout Standard
35507 Some subexpressions are not as obvious as the above example, e.g.:
35510 \begin_layout Verse
35518 \begin_layout Standard
35519 In this case the address arithmetic a->b[i] will be computed only once;
35520 the equivalent code in C would be.
35523 \begin_layout Verse
35533 \begin_layout Standard
35534 The compiler will try to keep these temporary variables in registers.
35537 \begin_layout Subsection
35538 Dead-Code Elimination
35539 \begin_inset LatexCommand index
35540 name "Dead-code elimination"
35547 \begin_layout Verse
35562 i = 1; \InsetSpace ~
35571 global = 1;\InsetSpace ~
35585 global = 3;\InsetSpace ~
35591 \begin_layout Standard
35595 \begin_layout Verse
35611 \begin_layout Subsection
35613 \begin_inset LatexCommand index
35614 name "Copy propagation"
35621 \begin_layout Verse
35645 \begin_layout Standard
35649 \begin_layout Verse
35673 \begin_layout Standard
35674 Note: the dead stores created by this copy propagation will be eliminated
35675 by dead-code elimination.
35678 \begin_layout Subsection
35680 \begin_inset LatexCommand index
35681 name "Loop optimization"
35686 \begin_inset LatexCommand label
35687 name "sub:Loop-Optimizations"
35694 \begin_layout Standard
35695 Two types of loop optimizations are done by SDCC
35703 of loop induction variables.
35704 In addition to the strength reduction the optimizer marks the induction
35705 variables and the register allocator tries to keep the induction variables
35706 in registers for the duration of the loop.
35707 Because of this preference of the register allocator
35708 \begin_inset LatexCommand index
35709 name "Register allocation"
35713 , loop induction optimization causes an increase in register pressure, which
35714 may cause unwanted spilling of other temporary variables into the stack
35715 \begin_inset LatexCommand index
35721 The compiler will generate a warning message when it is forced to allocate
35722 extra space either on the stack or data space.
35723 If this extra space allocation is undesirable then induction optimization
35724 can be eliminated either for the entire source file (with -
35728 \begin_layout Standard
35737 -noinduction option) or for a given function only using #pragma\InsetSpace ~
35739 \begin_inset LatexCommand index
35740 name "\\#pragma noinduction"
35751 \begin_layout Verse
35754 for (i = 0 ; i < 100 ; i ++)
35763 \begin_layout Standard
35767 \begin_layout Verse
35772 for (i = 0; i < 100; i++)
35781 \begin_layout Standard
35782 As mentioned previously some loop invariants are not as apparent, all static
35783 address computations are also moved out of the loop.
35788 \begin_inset LatexCommand index
35789 name "Strength reduction"
35793 , this optimization substitutes an expression by a cheaper expression:
35796 \begin_layout Verse
35799 for (i=0;i < 100; i++)
35808 \begin_layout Standard
35812 \begin_layout Verse
35819 for (i=0;i< 100;i++) {
35825 ar[itemp1] = itemp2;
35843 \begin_layout Standard
35844 The more expensive multiplication
35845 \begin_inset LatexCommand index
35846 name "Multiplication"
35850 is changed to a less expensive addition.
35853 \begin_layout Subsection
35855 \begin_inset LatexCommand index
35856 name "Loop reversing"
35863 \begin_layout Standard
35864 This optimization is done to reduce the overhead of checking loop boundaries
35865 for every iteration.
35866 Some simple loops can be reversed and implemented using a
35867 \begin_inset Quotes eld
35870 decrement and jump if not zero
35871 \begin_inset Quotes erd
35875 SDCC checks for the following criterion to determine if a loop is reversible
35876 (note: more sophisticated compilers use data-dependency analysis to make
35877 this determination, SDCC uses a more simple minded analysis).
35880 \begin_layout Itemize
35881 The 'for' loop is of the form
35887 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
35897 \begin_layout Itemize
35898 The <for body> does not contain
35899 \begin_inset Quotes eld
35903 \begin_inset Quotes erd
35907 \begin_inset Quotes erd
35913 \begin_layout Itemize
35914 All goto's are contained within the loop.
35917 \begin_layout Itemize
35918 No function calls within the loop.
35921 \begin_layout Itemize
35922 The loop control variable <sym> is not assigned any value within the loop
35925 \begin_layout Itemize
35926 The loop control variable does NOT participate in any arithmetic operation
35930 \begin_layout Itemize
35931 There are NO switch statements in the loop.
35934 \begin_layout Subsection
35935 Algebraic Simplifications
35938 \begin_layout Standard
35939 SDCC does numerous algebraic simplifications, the following is a small sub-set
35940 of these optimizations.
35943 \begin_layout Verse
35946 i = j + 0;\InsetSpace ~
35950 /* changed to: */\InsetSpace ~
35956 i /= 2;\InsetSpace ~
35963 /* changed to: */\InsetSpace ~
35970 = j - j;\InsetSpace ~
35974 /* changed to: */\InsetSpace ~
35980 i = j / 1;\InsetSpace ~
35984 /* changed to: */\InsetSpace ~
35991 \begin_layout Standard
35992 Note the subexpressions
35993 \begin_inset LatexCommand index
35994 name "Subexpression"
35998 given above are generally introduced by macro expansions or as a result
35999 of copy/constant propagation.
36002 \begin_layout Subsection
36003 'switch' Statements
36004 \begin_inset LatexCommand label
36005 name "sub:'switch'-Statements"
36010 \begin_inset LatexCommand index
36011 name "switch statement"
36018 \begin_layout Standard
36019 SDCC can optimize switch statements to jump tables
36020 \begin_inset LatexCommand index
36026 It makes the decision based on an estimate of the generated code size.
36027 SDCC is quite liberal in the requirements for jump table generation:
36030 \begin_layout Itemize
36031 The labels need not be in order, and the starting number need not be one
36032 or zero, the case labels are in numerical sequence or not too many case
36033 labels are missing.
36037 \begin_layout Verse
36040 switch(i) {\InsetSpace ~
36071 case 4: ...\InsetSpace ~
36103 case 5: ...\InsetSpace ~
36135 case 3: ...\InsetSpace ~
36166 case 6: ...\InsetSpace ~
36198 case 7: ...\InsetSpace ~
36230 case 8: ...\InsetSpace ~
36262 case 9: ...\InsetSpace ~
36294 case 10: ...\InsetSpace ~
36325 case 11: ...\InsetSpace ~
36392 \begin_layout Standard
36393 Both the above switch statements will be implemented using a jump-table.
36394 The example to the right side is slightly more efficient as the check for
36395 the lower boundary of the jump-table is not needed.
36399 \begin_layout Itemize
36400 The number of case labels is not larger than supported by the target architectur
36404 \begin_layout Itemize
36405 If the case labels are not in numerical sequence ('gaps' between cases)
36406 SDCC checks whether a jump table with additionally inserted dummy cases
36407 is still attractive.
36411 \begin_layout Itemize
36412 If the starting number is not zero and a check for the lower boundary of
36413 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
36418 \begin_layout Standard
36419 Switch statements which have large gaps in the numeric sequence or those
36420 that have too many case labels can be split into more than one switch statement
36421 for efficient code generation, e.g.:
36424 \begin_layout Verse
36502 \begin_layout Standard
36503 If the above switch statement is broken down into two switch statements
36506 \begin_layout Verse
36549 \begin_layout Standard
36553 \begin_layout Verse
36596 \begin_layout Standard
36597 then both the switch statements will be implemented using jump-tables whereas
36598 the unmodified switch statement will not be.
36601 \begin_layout Standard
36602 \begin_inset Note Note
36605 \begin_layout Standard
36606 There might be reasons which SDCC cannot know about to either favour or
36607 not favour jump tables.
36608 If the target system has to be as quick for the last switch case as for
36609 the first (pro jump table), or if the switch argument is known to be zero
36610 in the majority of the cases (contra jump table).
36618 \begin_layout Standard
36619 The pragma nojtbound
36620 \begin_inset LatexCommand index
36621 name "\\#pragma nojtbound"
36625 can be used to turn off checking the
36638 It has no effect if a default label is supplied.
36639 Use of this pragma is dangerous: if the switch
36640 \begin_inset LatexCommand index
36641 name "switch statement"
36645 argument is not matched by a case statement the processor will happily
36649 \begin_layout Subsection
36650 Bit-shifting Operations
36651 \begin_inset LatexCommand index
36652 name "Bit shifting"
36659 \begin_layout Standard
36660 Bit shifting is one of the most frequently used operation in embedded programmin
36662 SDCC tries to implement bit-shift operations in the most efficient way
36666 \begin_layout Verse
36679 \begin_layout Standard
36680 generates the following code:
36683 \begin_layout Verse
36698 \begin_layout Standard
36699 In general SDCC will never setup a loop if the shift count is known.
36703 \begin_layout Verse
36716 \begin_layout Standard
36720 \begin_layout Verse
36744 \begin_layout Subsection
36746 \begin_inset LatexCommand index
36747 name "Bit rotation"
36754 \begin_layout Standard
36755 A special case of the bit-shift operation is bit rotation
36756 \begin_inset LatexCommand index
36757 name "rotating bits"
36761 , SDCC recognizes the following expression to be a left bit-rotation:
36764 \begin_layout Verse
36772 char i;\InsetSpace ~
36783 /* unsigned is needed for rotation */
36788 i = ((i << 1) | (i >> 7));
36797 \begin_layout Standard
36798 will generate the following code:
36801 \begin_layout Verse
36818 \begin_layout Standard
36819 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
36820 ns of this case will also be recognized as bit-rotation, i.e.:
36823 \begin_layout Verse
36826 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
36829 \begin_layout Subsection
36830 Nibble and Byte Swapping
36833 \begin_layout Standard
36834 Other special cases of the bit-shift operations are nibble or byte swapping
36835 \begin_inset LatexCommand index
36836 name "swapping nibbles/bytes"
36840 , SDCC recognizes the following expressions:
36843 \begin_layout Verse
36864 i = ((i << 4) | (i >> 4));
36870 j = ((j << 8) | (j >> 8));
36873 \begin_layout Standard
36874 and generates a swap instruction for the nibble swapping
36875 \begin_inset LatexCommand index
36876 name "Nibble swapping"
36880 or move instructions for the byte swapping
36881 \begin_inset LatexCommand index
36882 name "Byte swapping"
36888 \begin_inset Quotes sld
36892 \begin_inset Quotes srd
36895 example can be used to convert from little to big-endian or vice versa.
36896 If you want to change the endianness of a
36900 integer you have to cast to
36907 \begin_layout Standard
36908 Note that SDCC stores numbers in little-endian
36912 \begin_layout Standard
36913 Usually 8-bit processors don't care much about endianness.
36914 This is not the case for the standard 8051 which only has an instruction
36920 \begin_inset LatexCommand index
36925 -datapointer so little-endian is the more efficient byte order.
36931 \begin_inset LatexCommand index
36932 name "little-endian"
36937 \begin_inset LatexCommand index
36943 lowest order first).
36946 \begin_layout Subsection
36948 \begin_inset LatexCommand index
36949 name "Highest Order Bit"
36954 \begin_inset LatexCommand index
36955 name "Any Order Bit"
36962 \begin_layout Standard
36963 It is frequently required to obtain the highest order bit of an integral
36964 type (long, int, short or char types).
36965 Also obtaining any other order bit is not uncommon.
36966 SDCC recognizes the following expressions to yield the highest order bit
36967 and generates optimized code for it, e.g.:
36970 \begin_layout Verse
36981 unsigned char hob1, aob1;
36985 bit hob2, hob3, aob2,
36995 hob1 = (gint >> 15) & 1;
36999 hob2 = (gint >> 15) & 1;
37003 hob3 = gint & 0x8000;
37008 aob1 = (gint >> 9) & 1;
37012 aob2 = (gint >> 8) & 1;
37016 aob3 = gint & 0x0800;
37026 \begin_layout Standard
37027 will generate the following code:
37030 \begin_layout Verse
37061 000A E5*01\InsetSpace ~
37088 000C 23\InsetSpace ~
37119 000D 54 01\InsetSpace ~
37147 000F F5*02\InsetSpace ~
37202 0011 E5*01\InsetSpace ~
37230 0013 33\InsetSpace ~
37260 0014 92*00\InsetSpace ~
37316 0016 E5*01\InsetSpace ~
37343 0018 33\InsetSpace ~
37373 0019 92*01\InsetSpace ~
37429 001B E5*01\InsetSpace ~
37488 001E 54 01\InsetSpace ~
37515 0020 F5*03\InsetSpace ~
37571 0022 E5*01\InsetSpace ~
37598 0024 13\InsetSpace ~
37628 0025 92*02\InsetSpace ~
37684 0027 E5*01\InsetSpace ~
37739 002B 92*03\InsetSpace ~
37767 \begin_layout Standard
37768 Other variations of these cases however will
37773 They are standard C expressions, so I heartily recommend these be the only
37774 way to get the highest order bit, (it is portable).
37775 Of course it will be recognized even if it is embedded in other expressions,
37779 \begin_layout Verse
37782 xyz = gint + ((gint >> 15) & 1);
37785 \begin_layout Standard
37786 will still be recognized.
37789 \begin_layout Subsection
37791 \begin_inset LatexCommand index
37792 name "Higher Order Byte"
37796 / Higher Order Word
37797 \begin_inset LatexCommand index
37798 name "Higher Order Word"
37805 \begin_layout Standard
37806 It is also frequently required to obtain a higher order byte or word of
37807 a larger integral type (long, int or short types).
37808 SDCC recognizes the following expressions to yield the higher order byte
37809 or word and generates optimized code for it, e.g.:
37812 \begin_layout Verse
37817 unsigned long int glong;
37825 unsigned char hob1,
37830 unsigned int how1, how2;
37839 hob1 = (gint >> 8) & 0xFF;
37843 hob2 = glong >> 24;
37847 how1 = (glong >> 16) & 0xFFFF;
37862 \begin_layout Standard
37863 will generate the following code:
37866 \begin_layout Verse
37897 0037 85*01*06\InsetSpace ~
37919 _foo_hob1_1_1,(_gint + 1)
37950 003A 85*05*07\InsetSpace ~
37972 _foo_hob2_1_1,(_glong + 3)
38002 003D 85*04*08\InsetSpace ~
38025 _foo_how1_1_1,(_glong + 2)
38027 0040 85*05*09\InsetSpace ~
38052 0043 85*03*0A\InsetSpace ~
38074 _foo_how2_1_1,(_glong + 1)
38076 0046 85*04*0B\InsetSpace ~
38099 (_foo_how2_1_1 + 1),(_glong + 2)
38102 \begin_layout Standard
38103 Again, variations of these cases may
38108 They are standard C expressions, so I heartily recommend these be the only
38109 way to get the higher order byte/word, (it is portable).
38110 Of course it will be recognized even if it is embedded in other expressions,
38114 \begin_layout Verse
38117 xyz = gint + ((gint >> 8) & 0xFF);
38120 \begin_layout Standard
38121 will still be recognized.
38124 \begin_layout Subsection
38126 \begin_inset LatexCommand label
38127 name "sub:Peephole-Optimizer"
38132 \begin_inset LatexCommand index
38133 name "Peephole optimizer"
38140 \begin_layout Standard
38141 The compiler uses a rule based, pattern matching and re-writing mechanism
38142 for peep-hole optimization.
38147 a peep-hole optimizer by Christopher W.
38148 Fraser (cwfraser\InsetSpace ~
38151 A default set of rules are compiled into the compiler, additional rules
38152 may be added with the
38158 \begin_layout Standard
38168 \begin_inset LatexCommand index
38169 name "-\\/-peep-file"
38176 The rule language is best illustrated with examples.
38179 \begin_layout Verse
38201 \begin_layout Standard
38202 The above rule will change the following assembly
38203 \begin_inset LatexCommand index
38204 name "Assembler routines"
38211 \begin_layout Verse
38219 \begin_layout Standard
38223 \begin_layout Verse
38229 \begin_layout Standard
38230 Note: All occurrences of a
38234 (pattern variable) must denote the same string.
38235 With the above rule, the assembly sequence:
38238 \begin_layout Verse
38246 \begin_layout Standard
38247 will remain unmodified.
38251 Other special case optimizations may be added by the
38258 \begin_layout Standard
38271 some variants of the 8051 MCU
38272 \begin_inset LatexCommand index
38273 name "MCS51 variants"
38286 The following two rules will change all
38303 \begin_layout Verse
38306 replace { lcall %1 } by { acall %1 }
38308 replace { ljmp %1 } by { ajmp %1 }
38311 \begin_layout Standard
38312 (NOTE: from version 2.7.3 on, you can use option -
38318 \begin_layout Standard
38330 \begin_inset LatexCommand index
38331 name "-\\/-acall-ajmp"
38335 , which also takes care of aligning the interrupt vectors properly.)
38340 \begin_layout Standard
38343 inline-assembler code
38345 is also passed through the peep hole optimizer, thus the peephole optimizer
38346 can also be used as an assembly level macro expander.
38347 The rules themselves are MCU dependent whereas the rule language infra-structur
38348 e is MCU independent.
38349 Peephole optimization rules for other MCU can be easily programmed using
38354 The syntax for a rule is as follows:
38357 \begin_layout Verse
38360 rule := replace [ restart ] '{' <assembly sequence> '
38398 <assembly sequence> '
38416 '}' [if <functionName> ] '
38421 \begin_layout Standard
38422 <assembly sequence> := assembly instruction (each instruction including
38423 labels must be on a separate line).
38427 The optimizer will apply to the rules
38428 one by one from the top in the sequence of their appearance, it will terminate
38429 when all rules are exhausted.
38430 If the 'restart' option is specified, then the optimizer will start matching
38431 the rules again from the top, this option for a rule is expensive (performance)
38432 , it is intended to be used in situations where a transformation will trigger
38433 the same rule again.
38434 An example of this (not a good one, it has side effects) is the following
38438 \begin_layout Verse
38458 \begin_layout Standard
38459 Note that the replace pattern cannot be a blank, but can be a comment line.
38460 Without the 'restart' option only the innermost 'pop' 'push' pair would
38461 be eliminated, i.e.:
38464 \begin_layout Verse
38476 \begin_layout Standard
38480 \begin_layout Verse
38490 \begin_layout Standard
38495 the restart option the rule will be applied again to the resulting code
38496 and then all the pop-push pairs will be eliminated to yield:
38499 \begin_layout Verse
38507 \begin_layout Standard
38508 A conditional function can be attached to a rule.
38509 Attaching rules are somewhat more involved, let me illustrate this with
38513 \begin_layout Verse
38537 \begin_layout Standard
38538 The optimizer does a look-up of a function name table defined in function
38543 in the source file SDCCpeeph.c, with the name
38548 If it finds a corresponding entry the function is called.
38549 Note there can be no parameters specified for these functions, in this
38554 is crucial, since the function
38558 expects to find the label in that particular variable (the hash table containin
38559 g the variable bindings is passed as a parameter).
38560 If you want to code more such functions, take a close look at the function
38561 labelInRange and the calling mechanism in source file SDCCpeeph.c.
38562 Currently implemented are
38564 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
38565 24bitMode, portIsDS390, 24bitModeAndPortDS390
38574 \begin_layout Standard
38575 I know this whole thing is a little kludgey, but maybe some day we will
38576 have some better means.
38577 If you are looking at this file, you will see the default rules that are
38578 compiled into the compiler, you can add your own rules in the default set
38579 there if you get tired of specifying the -
38583 \begin_layout Standard
38595 \begin_layout Section
38597 \begin_inset LatexCommand index
38598 name "ANSI-compliance"
38603 \begin_inset LatexCommand label
38604 name "sub:ANSI-Compliance"
38611 \begin_layout Standard
38612 The latest publicly available version of the standard
38614 ISO/IEC 9899 - Programming languages - C
38616 should be available at:
38617 \begin_inset LatexCommand url
38618 target "http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899"
38627 \begin_layout Standard
38628 Deviations from the compliance:
38631 \begin_layout Itemize
38632 functions are not reentrant
38633 \begin_inset LatexCommand index
38638 unless explicitly declared as such or the
38644 \begin_layout Standard
38654 \begin_inset LatexCommand index
38655 name "-\\/-stack-auto"
38661 command line option is specified.
38664 \begin_layout Itemize
38666 \begin_inset LatexCommand index
38672 \begin_inset LatexCommand index
38677 cannot be assigned values directly, cannot be passed as function parameters
38678 or assigned to each other and cannot be a return value
38679 \begin_inset LatexCommand index
38680 name "return value"
38684 from a function, e.g.:
38688 \begin_layout Verse
38711 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
38736 s parms) /* invalid in SDCC although allowed in ANSI */
38758 return rets; /* is invalid in SDCC although allowed in ANSI */
38764 \begin_layout Itemize
38765 initialization of structure arrays must be fully braced.
38769 \begin_layout Verse
38772 struct s { char x } a[] = {1, 2};\InsetSpace ~
38777 /* invalid in SDCC */
38780 } a[] = {{1}, {2}}; /* OK */
38784 \begin_layout Itemize
38786 \begin_inset LatexCommand index
38787 name "long long (not supported)"
38792 \begin_inset LatexCommand index
38793 name "int (64 bit) (not supported)"
38800 \begin_layout Itemize
38802 \begin_inset LatexCommand index
38803 name "double (not supported)"
38807 ' precision floating point
38808 \begin_inset LatexCommand index
38809 name "Floating point support"
38816 \begin_layout Itemize
38818 \begin_inset LatexCommand index
38823 function declarations are NOT allowed.
38827 \begin_layout Verse
38830 foo(i,j) /* this old style of function declarations */
38832 int i,j; /* is valid
38833 in ANSI but not valid in SDCC */
38848 \begin_layout Itemize
38849 Most enhancements in C99 are not supported, e.g.:
38853 \begin_layout Verse
38863 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
38867 \begin_layout Itemize
38868 But some have been added recently in SDCC 2.7.0.
38869 They must be considered alpha quality however.
38873 \begin_layout Verse
38878 \begin_inset LatexCommand index
38879 name "inline (not supported)"
38888 int increment (int a) { return a+1; } /* inlines the increment without function
38897 \begin_inset LatexCommand index
38898 name "inline (not supported)"
38907 p; /* accepted but ignored */
38911 \begin_layout Itemize
38912 Certain words that are valid identifiers in the standard may be reserved
38913 words in SDCC unless the
38919 \begin_layout Standard
38929 \begin_inset LatexCommand index
38930 name "-\\/-std-c89"
38942 \begin_layout Standard
38952 \begin_inset LatexCommand index
38953 name "-\\/-std-c99"
38959 command line options are used.
38960 These may include (depending on the selected processor): 'at', 'banked',
38961 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
38962 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
38963 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
38965 Compliant equivalents of these keywords are always available in a form
38966 that begin with two underscores
38967 \begin_inset LatexCommand index
38968 name "\\_\\_ (prefix for extended keywords)"
38973 '__data' instead of 'data'.
38976 \begin_layout Itemize
38977 Integer promotion of variable arguments is not performed if the argument
38978 is explicitly taypecasted unless the
38984 \begin_layout Standard
38994 \begin_inset LatexCommand index
38995 name "-\\/-std-c89"
39007 \begin_layout Standard
39017 \begin_inset LatexCommand index
39018 name "-\\/-std-c99"
39024 command line options are used.
39028 \begin_layout Verse
39031 void vararg_func (char *str, ...) { str; }
39048 u is promoted to int before
39053 * passing to function */
39057 vararg_func ("%c", c);
39064 argument u is not promoted to int,
39069 * it is passed as char to function
39075 --std-cXX is not defined;
39080 * is promoted to int before passing
39086 if --std-cXX is defined */
39090 vararg_func ("%bc", (char)u);
39096 \begin_layout Section
39097 Cyclomatic Complexity
39098 \begin_inset LatexCommand index
39099 name "Cyclomatic complexity"
39106 \begin_layout Standard
39107 Cyclomatic complexity of a function is defined as the number of independent
39108 paths the program can take during execution of the function.
39109 This is an important number since it defines the number test cases you
39110 have to generate to validate the function.
39111 The accepted industry standard for complexity number is 10, if the cyclomatic
39112 complexity reported by SDCC exceeds 10 you should think about simplification
39113 of the function logic.
39114 Note that the complexity level is not related to the number of lines of
39115 code in a function.
39116 Large functions can have low complexity, and small functions can have large
39122 SDCC uses the following formula to compute the complexity:
39127 \begin_layout Standard
39128 complexity = (number of edges in control flow graph) - (number of nodes
39129 in control flow graph) + 2;
39133 Having said that the industry standard is 10,
39134 you should be aware that in some cases it be may unavoidable to have a
39135 complexity level of less than 10.
39136 For example if you have switch statement with more than 10 case labels,
39137 each case label adds one to the complexity level.
39138 The complexity level is by no means an absolute measure of the algorithmic
39139 complexity of the function, it does however provide a good starting point
39140 for which functions you might look at for further optimization.
39143 \begin_layout Section
39144 Retargetting for other Processors
39147 \begin_layout Standard
39148 The issues for retargetting the compiler are far too numerous to be covered
39150 What follows is a brief description of each of the seven phases of the
39151 compiler and its MCU dependency.
39154 \begin_layout Itemize
39155 Parsing the source and building the annotated parse tree.
39156 This phase is largely MCU independent (except for the language extensions).
39157 Syntax & semantic checks are also done in this phase, along with some initial
39158 optimizations like back patching labels and the pattern matching optimizations
39159 like bit-rotation etc.
39162 \begin_layout Itemize
39163 The second phase involves generating an intermediate code which can be easy
39164 manipulated during the later phases.
39165 This phase is entirely MCU independent.
39166 The intermediate code generation assumes the target machine has unlimited
39167 number of registers, and designates them with the name iTemp.
39168 The compiler can be made to dump a human readable form of the code generated
39173 \begin_layout Standard
39185 \begin_layout Itemize
39186 This phase does the bulk of the standard optimizations and is also MCU independe
39188 This phase can be broken down into several sub-phases:
39192 Break down intermediate
39193 code (iCode) into basic blocks.
39195 Do control flow & data flow analysis on the
39198 Do local common subexpression elimination, then global subexpressio
39201 Dead code elimination
39205 If loop optimizations
39206 caused any changes then do 'global subexpression elimination' and 'dead
39207 code elimination' again.
39210 \begin_layout Itemize
39211 This phase determines the live-ranges; by live range I mean those iTemp
39212 variables defined by the compiler that still survive after all the optimization
39214 Live range analysis
39215 \begin_inset LatexCommand index
39216 name "Live range analysis"
39220 is essential for register allocation, since these computation determines
39221 which of these iTemps will be assigned to registers, and for how long.
39224 \begin_layout Itemize
39225 Phase five is register allocation.
39226 There are two parts to this process.
39230 The first part I call 'register packing'
39231 (for lack of a better term).
39232 In this case several MCU specific expression folding is done to reduce
39237 The second part is more MCU independent and deals with
39238 allocating registers to the remaining live ranges.
39239 A lot of MCU specific code does creep into this phase because of the limited
39240 number of index registers available in the 8051.
39243 \begin_layout Itemize
39244 The Code generation phase is (unhappily), entirely MCU dependent and very
39245 little (if any at all) of this code can be reused for other MCU.
39246 However the scheme for allocating a homogenized assembler operand for each
39247 iCode operand may be reused.
39250 \begin_layout Itemize
39251 As mentioned in the optimization section the peep-hole optimizer is rule
39252 based system, which can reprogrammed for other MCUs.
39255 \begin_layout Standard
39256 More information is available on SDCC Wiki
39257 \begin_inset LatexCommand index
39263 \begin_inset LatexCommand url
39264 target "http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting"
39268 ) and in the thread
39269 \begin_inset LatexCommand url
39270 target "http://sf.net/mailarchive/message.php?msg_id=13954144"
39277 \begin_layout Chapter
39279 \begin_inset LatexCommand index
39280 name "Compiler internals"
39287 \begin_layout Section
39288 The anatomy of the compiler
39289 \begin_inset LatexCommand label
39290 name "sub:The-anatomy-of"
39297 \begin_layout Standard
39300 This is an excerpt from an article published in Circuit Cellar Magazine
39309 It's a little outdated (the compiler is much more efficient now and user/develo
39310 per friendly), but pretty well exposes the guts of it all.
39316 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
39317 It is fairly easy to retarget for other 8-bit MCU.
39318 Here we take a look at some of the internals of the compiler.
39322 \begin_layout Paragraph*
39324 \begin_inset LatexCommand index
39332 \begin_layout Standard
39333 Parsing the input source file and creating an AST (Annotated Syntax Tree
39334 \begin_inset LatexCommand index
39335 name "Annotated syntax tree"
39340 This phase also involves propagating types (annotating each node of the
39341 parse tree with type information) and semantic analysis.
39342 There are some MCU specific parsing rules.
39343 For example the storage classes, the extended storage classes are MCU specific
39344 while there may be a xdata storage class for 8051 there is no such storage
39345 class for z80 or Atmel AVR.
39346 SDCC allows MCU specific storage class extensions, i.e.
39347 xdata will be treated as a storage class specifier when parsing 8051 C
39348 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
39352 \begin_layout Paragraph*
39354 \begin_inset LatexCommand index
39362 \begin_layout Standard
39363 Intermediate code generation.
39364 In this phase the AST is broken down into three-operand form (iCode).
39365 These three operand forms are represented as doubly linked lists.
39366 ICode is the term given to the intermediate form generated by the compiler.
39367 ICode example section shows some examples of iCode generated for some simple
39368 C source functions.
39371 \begin_layout Paragraph*
39373 \begin_inset LatexCommand index
39374 name "Optimizations"
39381 \begin_layout Standard
39382 Bulk of the target independent optimizations is performed in this phase.
39383 The optimizations include constant propagation, common sub-expression eliminati
39384 on, loop invariant code movement, strength reduction of loop induction variables
39385 and dead-code elimination.
39388 \begin_layout Paragraph*
39389 Live range analysis
39390 \begin_inset LatexCommand index
39391 name "Live range analysis"
39398 \begin_layout Standard
39399 During intermediate code generation phase, the compiler assumes the target
39400 machine has infinite number of registers and generates a lot of temporary
39402 The live range computation determines the lifetime of each of these compiler-ge
39403 nerated temporaries.
39404 A picture speaks a thousand words.
39405 ICode example sections show the live range annotations for each of the
39407 It is important to note here, each iCode is assigned a number in the order
39408 of its execution in the function.
39409 The live ranges are computed in terms of these numbers.
39410 The from number is the number of the iCode which first defines the operand
39411 and the to number signifies the iCode which uses this operand last.
39414 \begin_layout Paragraph*
39415 Register Allocation
39416 \begin_inset LatexCommand index
39417 name "Register allocation"
39424 \begin_layout Standard
39425 The register allocation determines the type and number of registers needed
39427 In most MCUs only a few registers can be used for indirect addressing.
39428 In case of 8051 for example the registers R0 & R1 can be used to indirectly
39429 address the internal ram and DPTR to indirectly address the external ram.
39430 The compiler will try to allocate the appropriate register to pointer variables
39432 ICode example section shows the operands annotated with the registers assigned
39434 The compiler will try to keep operands in registers as much as possible;
39435 there are several schemes the compiler uses to do achieve this.
39436 When the compiler runs out of registers the compiler will check to see
39437 if there are any live operands which is not used or defined in the current
39438 basic block being processed, if there are any found then it will push that
39439 operand and use the registers in this block, the operand will then be popped
39440 at the end of the basic block.
39444 \begin_layout Standard
39445 There are other MCU specific considerations in this phase.
39446 Some MCUs have an accumulator; very short-lived operands could be assigned
39447 to the accumulator instead of a general-purpose register.
39450 \begin_layout Paragraph*
39454 \begin_layout Standard
39455 Figure II gives a table of iCode
39456 \begin_inset LatexCommand index
39461 operations supported by the compiler.
39462 The code generation involves translating these operations into corresponding
39463 assembly code for the processor.
39464 This sounds overly simple but that is the essence of code generation.
39465 Some of the iCode operations are generated on a MCU specific manner for
39466 example, the z80 port does not use registers to pass parameters so the
39467 SEND and RECV iCode operations will not be generated, and it also does
39468 not support JUMPTABLES.
39474 \begin_layout Standard
39478 \begin_inset Tabular
39479 <lyxtabular version="3" rows="39" columns="4">
39480 <features islongtable="true" headBottomDL="true">
39481 <column alignment="block" valignment="top" leftline="true" width="13col%">
39482 <column alignment="left" valignment="top" leftline="true" width="13col%">
39483 <column alignment="block" valignment="top" leftline="true" width="22col%">
39484 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
39485 <row topline="true" bottomline="true" endhead="true">
39486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39489 \begin_layout Standard
39495 \begin_inset LatexCommand index
39505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39508 \begin_layout Standard
39516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39519 \begin_layout Standard
39527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39530 \begin_layout Standard
39539 <row topline="true">
39540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39543 \begin_layout Standard
39551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39554 \begin_layout Standard
39557 IC_LEFT() IC_RESULT()
39562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39565 \begin_layout Standard
39573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39576 \begin_layout Standard
39579 IC_RESULT = ! IC_LEFT;
39585 <row topline="true">
39586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39589 \begin_layout Standard
39597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39600 \begin_layout Standard
39603 IC_LEFT() IC_RESULT()
39608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39611 \begin_layout Standard
39614 Bitwise complement of
39619 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39622 \begin_layout Standard
39625 IC_RESULT = ~IC_LEFT;
39631 <row topline="true">
39632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39635 \begin_layout Standard
39643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39646 \begin_layout Standard
39649 IC_LEFT() IC_RESULT()
39654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39657 \begin_layout Standard
39660 Rotate right with carry
39665 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39668 \begin_layout Standard
39671 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
39677 <row topline="true">
39678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39681 \begin_layout Standard
39689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39692 \begin_layout Standard
39695 IC_LEFT() IC_RESULT()
39700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39703 \begin_layout Standard
39706 Rotate left with carry
39711 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39714 \begin_layout Standard
39717 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
39723 <row topline="true">
39724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39727 \begin_layout Standard
39735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39738 \begin_layout Standard
39741 IC_LEFT() IC_RESULT()
39746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39749 \begin_layout Standard
39752 Get the highest order bit of IC_LEFT
39757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39760 \begin_layout Standard
39763 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
39769 <row topline="true">
39770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39773 \begin_layout Standard
39781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39784 \begin_layout Standard
39787 IC_LEFT() IC_RESULT()
39792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39795 \begin_layout Standard
39803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39806 \begin_layout Standard
39809 IC_RESULT = - IC_LEFT;
39815 <row topline="true">
39816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39819 \begin_layout Standard
39827 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39830 \begin_layout Standard
39838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39841 \begin_layout Standard
39844 Push the operand into stack
39849 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39852 \begin_layout Standard
39861 <row topline="true">
39862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39865 \begin_layout Standard
39873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39876 \begin_layout Standard
39884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39887 \begin_layout Standard
39890 Pop the operand from the stack
39895 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39898 \begin_layout Standard
39907 <row topline="true">
39908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39911 \begin_layout Standard
39919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39922 \begin_layout Standard
39925 IC_LEFT() IC_RESULT()
39930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39933 \begin_layout Standard
39936 Call the function represented by IC_LEFT
39941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39944 \begin_layout Standard
39947 IC_RESULT = IC_LEFT();
39953 <row topline="true">
39954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39957 \begin_layout Standard
39965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39968 \begin_layout Standard
39971 IC_LEFT() IC_RESULT()
39976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39979 \begin_layout Standard
39982 Call via function pointer
39987 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39990 \begin_layout Standard
39993 IC_RESULT = (*IC_LEFT)();
39999 <row topline="true">
40000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40003 \begin_layout Standard
40011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40014 \begin_layout Standard
40022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40025 \begin_layout Standard
40028 Return the value in operand IC_LEFT
40033 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40036 \begin_layout Standard
40045 <row topline="true">
40046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40049 \begin_layout Standard
40057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40060 \begin_layout Standard
40068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40071 \begin_layout Standard
40079 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40082 \begin_layout Standard
40091 <row topline="true">
40092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40095 \begin_layout Standard
40103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40106 \begin_layout Standard
40114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40117 \begin_layout Standard
40125 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40128 \begin_layout Standard
40137 <row topline="true">
40138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40141 \begin_layout Standard
40149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40152 \begin_layout Standard
40155 IC_LEFT() IC_RIGHT() IC_RESULT()
40160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40163 \begin_layout Standard
40171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40174 \begin_layout Standard
40177 IC_RESULT = IC_LEFT + IC_RIGHT
40183 <row topline="true">
40184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40187 \begin_layout Standard
40195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40198 \begin_layout Standard
40201 IC_LEFT() IC_RIGHT() IC_RESULT()
40206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40209 \begin_layout Standard
40217 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40220 \begin_layout Standard
40223 IC_RESULT = IC_LEFT - IC_RIGHT
40229 <row topline="true">
40230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40233 \begin_layout Standard
40241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40244 \begin_layout Standard
40247 IC_LEFT() IC_RIGHT() IC_RESULT()
40252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40255 \begin_layout Standard
40263 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40266 \begin_layout Standard
40269 IC_RESULT = IC_LEFT * IC_RIGHT;
40275 <row topline="true">
40276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40279 \begin_layout Standard
40287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40290 \begin_layout Standard
40293 IC_LEFT() IC_RIGHT() IC_RESULT()
40298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40301 \begin_layout Standard
40309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40312 \begin_layout Standard
40315 IC_RESULT = IC_LEFT / IC_RIGHT;
40321 <row topline="true">
40322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40325 \begin_layout Standard
40333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40336 \begin_layout Standard
40339 IC_LEFT() IC_RIGHT() IC_RESULT()
40344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40347 \begin_layout Standard
40355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40358 \begin_layout Standard
40361 IC_RESULT = IC_LEFT % IC_RIGHT;
40367 <row topline="true">
40368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40371 \begin_layout Standard
40379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40382 \begin_layout Standard
40385 IC_LEFT() IC_RIGHT() IC_RESULT()
40390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40393 \begin_layout Standard
40401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40404 \begin_layout Standard
40407 IC_RESULT = IC_LEFT < IC_RIGHT;
40413 <row topline="true">
40414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40417 \begin_layout Standard
40425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40428 \begin_layout Standard
40431 IC_LEFT() IC_RIGHT() IC_RESULT()
40436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40439 \begin_layout Standard
40447 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40450 \begin_layout Standard
40453 IC_RESULT = IC_LEFT > IC_RIGHT;
40459 <row topline="true">
40460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40463 \begin_layout Standard
40471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40474 \begin_layout Standard
40477 IC_LEFT() IC_RIGHT() IC_RESULT()
40482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40485 \begin_layout Standard
40493 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40496 \begin_layout Standard
40499 IC_RESULT = IC_LEFT == IC_RIGHT;
40505 <row topline="true">
40506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40509 \begin_layout Standard
40517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40520 \begin_layout Standard
40523 IC_LEFT() IC_RIGHT() IC_RESULT()
40528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40531 \begin_layout Standard
40534 Logical and operation
40539 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40542 \begin_layout Standard
40545 IC_RESULT = IC_LEFT && IC_RIGHT;
40551 <row topline="true">
40552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40555 \begin_layout Standard
40563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40566 \begin_layout Standard
40569 IC_LEFT() IC_RIGHT() IC_RESULT()
40574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40577 \begin_layout Standard
40580 Logical or operation
40585 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40588 \begin_layout Standard
40591 IC_RESULT = IC_LEFT || IC_RIGHT;
40597 <row topline="true">
40598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40601 \begin_layout Standard
40609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40612 \begin_layout Standard
40615 IC_LEFT() IC_RIGHT() IC_RESULT()
40620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40623 \begin_layout Standard
40631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40634 \begin_layout Standard
40637 IC_RESULT = IC_LEFT ^ IC_RIGHT;
40643 <row topline="true">
40644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40647 \begin_layout Standard
40655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40658 \begin_layout Standard
40661 IC_LEFT() IC_RIGHT() IC_RESULT()
40666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40669 \begin_layout Standard
40677 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40680 \begin_layout Standard
40683 IC_RESULT = IC_LEFT | IC_RIGHT;
40689 <row topline="true">
40690 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40693 \begin_layout Standard
40701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40704 \begin_layout Standard
40707 IC_LEFT() IC_RIGHT() IC_RESULT()
40712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40715 \begin_layout Standard
40723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40726 \begin_layout Standard
40729 IC_RESULT = IC_LEFT & IC_RIGHT;
40735 <row topline="true">
40736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40739 \begin_layout Standard
40747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40750 \begin_layout Standard
40753 IC_LEFT() IC_RIGHT() IC_RESULT()
40758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40761 \begin_layout Standard
40769 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40772 \begin_layout Standard
40775 IC_RESULT = IC_LEFT << IC_RIGHT
40781 <row topline="true">
40782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40785 \begin_layout Standard
40793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40796 \begin_layout Standard
40799 IC_LEFT() IC_RIGHT() IC_RESULT()
40804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40807 \begin_layout Standard
40815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40818 \begin_layout Standard
40821 IC_RESULT = IC_LEFT >> IC_RIGHT
40827 <row topline="true">
40828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40831 \begin_layout Standard
40841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40844 \begin_layout Standard
40847 IC_LEFT() IC_RESULT()
40852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40855 \begin_layout Standard
40863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40866 \begin_layout Standard
40869 IC_RESULT = (*IC_LEFT);
40875 <row topline="true">
40876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40879 \begin_layout Standard
40887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40890 \begin_layout Standard
40893 IC_RIGHT() IC_RESULT()
40898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40901 \begin_layout Standard
40909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40912 \begin_layout Standard
40915 (*IC_RESULT) = IC_RIGHT;
40921 <row topline="true">
40922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40925 \begin_layout Standard
40933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40936 \begin_layout Standard
40939 IC_RIGHT() IC_RESULT()
40944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40947 \begin_layout Standard
40955 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40958 \begin_layout Standard
40961 IC_RESULT = IC_RIGHT;
40967 <row topline="true">
40968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40971 \begin_layout Standard
40979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40982 \begin_layout Standard
40985 IC_COND IC_TRUE IC_LABEL
40990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40993 \begin_layout Standard
40997 If true label is present then jump to true label if condition is true else
40998 jump to false label if condition is false
41003 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41006 \begin_layout Standard
41009 if (IC_COND) goto IC_TRUE;
41015 If (!IC_COND) goto IC_FALSE;
41021 <row topline="true">
41022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41025 \begin_layout Standard
41033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41036 \begin_layout Standard
41039 IC_LEFT() IC_RESULT()
41044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41047 \begin_layout Standard
41055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41058 \begin_layout Standard
41061 IC_RESULT = &IC_LEFT();
41067 <row topline="true">
41068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41071 \begin_layout Standard
41079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41082 \begin_layout Standard
41085 IC_JTCOND IC_JTLABELS
41090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41093 \begin_layout Standard
41096 Jump to list of labels depending on the value of JTCOND
41101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41104 \begin_layout Standard
41113 <row topline="true">
41114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41117 \begin_layout Standard
41125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41128 \begin_layout Standard
41131 IC_RIGHT() IC_LEFT() IC_RESULT()
41136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41139 \begin_layout Standard
41147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41150 \begin_layout Standard
41153 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
41159 <row topline="true">
41160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41163 \begin_layout Standard
41171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41174 \begin_layout Standard
41182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41185 \begin_layout Standard
41188 This is used for passing parameters in registers;
41190 move IC_LEFT to the next
41191 available parameter register.
41196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41199 \begin_layout Standard
41208 <row topline="true">
41209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41212 \begin_layout Standard
41220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41223 \begin_layout Standard
41231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41234 \begin_layout Standard
41237 This is used for receiving parameters passed in registers;
41240 in the next parameter register to IC_RESULT
41245 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41248 \begin_layout Standard
41257 <row topline="true" bottomline="true">
41258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41261 \begin_layout Standard
41265 (some more have been added)
41270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41273 \begin_layout Standard
41279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41282 \begin_layout Standard
41288 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41291 \begin_layout Standard
41324 \begin_layout Standard
41325 \begin_inset Note Note
41328 \begin_layout Standard
41329 In the original article Figure II was announced to be downloadable on
41334 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
41342 \begin_layout Paragraph*
41344 \begin_inset LatexCommand index
41352 \begin_layout Standard
41353 This section shows some details of iCode.
41354 The example C code does not do anything useful; it is used as an example
41355 to illustrate the intermediate code generated by the compiler.
41358 \begin_layout Verse
41368 /* This function does nothing useful.
41375 for the purpose of explaining iCode */
41378 short function (data
41387 short i=10; \InsetSpace ~
41389 /* dead initialization eliminated */
41395 /* dead initialization eliminated */
41423 /* compiler detects i,j to be induction
41428 for (i = 0, j = 10 ; i < 10 ; i++, j
41434 \begin_layout Standard
41457 mul += i * 3; \InsetSpace ~
41459 /* this multiplication remains */
41466 j * 3;\InsetSpace ~
41468 /* this multiplication changed to addition */
41482 \begin_layout Standard
41483 In addition to the operands each iCode contains information about the filename
41484 and line it corresponds to in the source file.
41485 The first field in the listing should be interpreted as follows:
41490 Filename(linenumber: iCode Execution sequence number : ICode hash table
41491 key : loop depth of the iCode).
41496 Then follows the human readable form of the ICode operation.
41497 Each operand of this triplet form can be of three basic types a) compiler
41498 generated temporary b) user defined variable c) a constant value.
41499 Note that local variables and parameters are replaced by compiler generated
41502 \begin_inset LatexCommand index
41503 name "Live range analysis"
41507 are computed only for temporaries (i.e.
41508 live ranges are not computed for global variables).
41510 \begin_inset LatexCommand index
41511 name "Register allocation"
41515 are allocated for temporaries only.
41516 Operands are formatted in the following manner:
41521 Operand Name [lr live-from : live-to ] { type information } [ registers
41527 As mentioned earlier the live ranges are computed in terms of the execution
41528 sequence number of the iCodes, for example
41530 the iTemp0 is live from (i.e.
41531 first defined in iCode with execution sequence number 3, and is last used
41532 in the iCode with sequence number 5).
41533 For induction variables such as iTemp21 the live range computation extends
41534 the lifetime from the start to the end of the loop.
41536 The register allocator
41537 used the live range information to allocate registers, the same registers
41538 may be used for different temporaries if their live ranges do not overlap,
41539 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
41540 ranges do not overlap.
41541 In addition the allocator also takes into consideration the type and usage
41542 of a temporary, for example itemp6 is a pointer to near space and is used
41543 as to fetch data from (i.e.
41544 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
41545 Some short lived temporaries are allocated to special registers which have
41546 meaning to the code generator e.g.
41547 iTemp13 is allocated to a pseudo register CC which tells the back end that
41548 the temporary is used only for a conditional jump the code generation makes
41549 use of this information to optimize a compare and jump ICode.
41553 \begin_inset LatexCommand index
41554 name "Loop optimization"
41558 performed by the compiler.
41559 It can detect induction variables iTemp21(i) and iTemp23(j).
41560 Also note the compiler does selective strength reduction
41561 \begin_inset LatexCommand index
41562 name "Strength reduction"
41567 the multiplication of an induction variable in line 18 (gint = j * 3) is
41568 changed to addition, a new temporary iTemp17 is allocated and assigned
41569 a initial value, a constant 3 is then added for each iteration of the loop.
41570 The compiler does not change the multiplication
41571 \begin_inset LatexCommand index
41572 name "Multiplication"
41576 in line 17 however since the processor does support an 8 * 8 bit multiplication.
41579 Note the dead code elimination
41580 \begin_inset LatexCommand index
41581 name "Dead-code elimination"
41585 optimization eliminated the dead assignments in line 7 & 8 to I and sum
41591 \begin_layout Standard
41594 Sample.c (5:1:0:0) _entry($9) :
41597 \begin_layout Standard
41600 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
41603 \begin_layout Standard
41606 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
41609 \begin_layout Standard
41612 Sample.c(11:4:53:0) preHeaderLbl0($11) :
41615 \begin_layout Standard
41618 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
41622 \begin_layout Standard
41625 Sample.c(11:6:5:1) _whilecontinue_0($1) :
41628 \begin_layout Standard
41631 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
41635 \begin_layout Standard
41638 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
41641 \begin_layout Standard
41644 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
41648 \begin_layout Standard
41651 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
41655 \begin_layout Standard
41658 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
41662 \begin_layout Standard
41665 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
41669 \begin_layout Standard
41672 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
41673 * int}[r0] + 0x2 {short}
41676 \begin_layout Standard
41679 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
41682 \begin_layout Standard
41685 Sample.c(11:17:21:0)_whilebreak_0($3) :
41688 \begin_layout Standard
41691 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
41694 \begin_layout Standard
41697 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
41700 \begin_layout Standard
41703 Sample.c(15:20:54:0)preHeaderLbl1($13) :
41706 \begin_layout Standard
41709 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
41712 \begin_layout Standard
41715 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
41718 \begin_layout Standard
41721 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
41724 \begin_layout Standard
41727 Sample.c(15:24:26:1)_forcond_0($4) :
41730 \begin_layout Standard
41733 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
41737 \begin_layout Standard
41740 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
41743 \begin_layout Standard
41746 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
41747 + ITemp21 [lr21:38]{short}[r4]
41750 \begin_layout Standard
41753 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
41757 \begin_layout Standard
41760 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
41761 + iTemp15 [lr29:30]{short}[r1]
41764 \begin_layout Standard
41767 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
41771 \begin_layout Standard
41774 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
41778 \begin_layout Standard
41781 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
41785 \begin_layout Standard
41788 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
41792 \begin_layout Standard
41795 Sample.c(19:38:47:1) goto _forcond_0($4)
41798 \begin_layout Standard
41801 Sample.c(19:39:48:0)_forbreak_0($7) :
41804 \begin_layout Standard
41807 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
41808 + ITemp11 [lr19:40]{short}[r3]
41811 \begin_layout Standard
41814 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
41817 \begin_layout Standard
41820 Sample.c(20:42:51:0)_return($8) :
41823 \begin_layout Standard
41826 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
41832 Finally the code generated for this function:
41837 \begin_layout Standard
41843 \begin_layout Standard
41849 \begin_layout Standard
41857 \begin_layout Standard
41863 \begin_layout Standard
41871 \begin_layout Standard
41877 \begin_layout Standard
41880 ; ----------------------------------------------
41883 \begin_layout Standard
41886 ; function function
41889 \begin_layout Standard
41892 ; ----------------------------------------------
41895 \begin_layout Standard
41901 \begin_layout Standard
41904 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
41907 \begin_layout Standard
41915 \begin_layout Standard
41918 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
41921 \begin_layout Standard
41929 \begin_layout Standard
41932 ;_whilecontinue_0($1) :
41935 \begin_layout Standard
41941 \begin_layout Standard
41944 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
41947 \begin_layout Standard
41950 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
41953 \begin_layout Standard
41961 \begin_layout Standard
41969 \begin_layout Standard
41977 \begin_layout Standard
41985 \begin_layout Standard
41993 \begin_layout Standard
42001 \begin_layout Standard
42009 \begin_layout Standard
42015 \begin_layout Standard
42018 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
42021 \begin_layout Standard
42029 \begin_layout Standard
42037 \begin_layout Standard
42040 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
42043 \begin_layout Standard
42051 \begin_layout Standard
42059 \begin_layout Standard
42067 \begin_layout Standard
42075 \begin_layout Standard
42083 \begin_layout Standard
42091 \begin_layout Standard
42094 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
42097 \begin_layout Standard
42105 \begin_layout Standard
42113 \begin_layout Standard
42121 \begin_layout Standard
42129 \begin_layout Standard
42137 \begin_layout Standard
42140 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
42143 \begin_layout Standard
42151 \begin_layout Standard
42159 \begin_layout Standard
42167 \begin_layout Standard
42170 ; iTemp6 [lr5:16]{_near * int}[r0] =
42173 \begin_layout Standard
42176 ; iTemp6 [lr5:16]{_near * int}[r0] +
42179 \begin_layout Standard
42185 \begin_layout Standard
42193 \begin_layout Standard
42196 ; goto _whilecontinue_0($1)
42199 \begin_layout Standard
42207 \begin_layout Standard
42210 ; _whilebreak_0($3) :
42213 \begin_layout Standard
42219 \begin_layout Standard
42222 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
42225 \begin_layout Standard
42233 \begin_layout Standard
42236 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
42239 \begin_layout Standard
42247 \begin_layout Standard
42250 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
42253 \begin_layout Standard
42261 \begin_layout Standard
42264 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
42267 \begin_layout Standard
42275 \begin_layout Standard
42283 \begin_layout Standard
42286 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
42289 \begin_layout Standard
42297 \begin_layout Standard
42305 \begin_layout Standard
42311 \begin_layout Standard
42317 \begin_layout Standard
42320 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
42323 \begin_layout Standard
42326 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
42329 \begin_layout Standard
42337 \begin_layout Standard
42345 \begin_layout Standard
42353 \begin_layout Standard
42361 \begin_layout Standard
42369 \begin_layout Standard
42375 \begin_layout Standard
42378 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
42381 \begin_layout Standard
42384 ; iTemp21 [lr21:38]{short}[r4]
42387 \begin_layout Standard
42395 \begin_layout Standard
42403 \begin_layout Standard
42411 \begin_layout Standard
42414 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
42417 \begin_layout Standard
42425 \begin_layout Standard
42433 \begin_layout Standard
42441 \begin_layout Standard
42449 \begin_layout Standard
42452 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
42455 \begin_layout Standard
42458 ; iTemp15 [lr29:30]{short}[r1]
42461 \begin_layout Standard
42469 \begin_layout Standard
42477 \begin_layout Standard
42480 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
42483 \begin_layout Standard
42491 \begin_layout Standard
42499 \begin_layout Standard
42507 \begin_layout Standard
42515 \begin_layout Standard
42523 \begin_layout Standard
42531 \begin_layout Standard
42534 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
42537 \begin_layout Standard
42545 \begin_layout Standard
42553 \begin_layout Standard
42561 \begin_layout Standard
42569 \begin_layout Standard
42577 \begin_layout Standard
42585 \begin_layout Standard
42588 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
42591 \begin_layout Standard
42599 \begin_layout Standard
42602 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
42605 \begin_layout Standard
42613 \begin_layout Standard
42618 cjne r5,#0xff,00104$
42621 \begin_layout Standard
42629 \begin_layout Standard
42632 ; goto _forcond_0($4)
42635 \begin_layout Standard
42643 \begin_layout Standard
42646 ; _forbreak_0($7) :
42649 \begin_layout Standard
42655 \begin_layout Standard
42658 ; ret iTemp24 [lr40:41]{short}
42661 \begin_layout Standard
42669 \begin_layout Standard
42677 \begin_layout Standard
42685 \begin_layout Standard
42691 \begin_layout Standard
42697 \begin_layout Standard
42707 \begin_layout Section
42708 A few words about basic block successors, predecessors and dominators
42711 \begin_layout Standard
42712 Successors are basic blocks
42713 \begin_inset LatexCommand index
42714 name "Basic blocks"
42718 that might execute after this basic block.
42720 Predecessors are basic blocks
42721 that might execute before reaching this basic block.
42723 Dominators are basic
42724 blocks that WILL execute before reaching this basic block.
42729 \begin_layout Standard
42733 \begin_layout Standard
42737 \begin_layout Standard
42745 \begin_layout Standard
42749 \begin_layout Standard
42757 \begin_layout Standard
42763 \begin_layout Standard
42764 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
42767 \begin_layout Standard
42768 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
42771 \begin_layout Standard
42772 c) domVect of [BB4] = BB1 ...
42773 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
42777 \begin_layout Chapter
42781 \begin_layout Standard
42782 \begin_inset LatexCommand url
42783 target "http://sdcc.sourceforge.net/#Who"
42793 Thanks to all the other volunteer developers who have helped with coding,
42794 testing, web-page creation, distribution sets, etc.
42795 You know who you are :-)
42803 Thanks to Sourceforge
42804 \begin_inset LatexCommand url
42805 target "http://www.sf.net"
42809 which has hosted the project since 1999 and donates significant download
42818 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
42819 cycles and bandwidth for snapshot builds.
42824 \begin_layout Standard
42825 This document was initially written by Sandeep Dutta
42828 \begin_layout Standard
42829 All product names mentioned herein may be trademarks
42830 \begin_inset LatexCommand index
42835 of their respective companies.
42839 \begin_layout Section*
42843 \begin_layout Standard
42844 To avoid confusion, the installation and building options for SDCC itself
42845 (chapter 2) are not part of the index.
42848 \begin_layout Standard
42849 \begin_inset LatexCommand printindex