1 #LyX 1.4.5 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 \paperfontsize default
29 \papersize letterpaper
34 \paperorientation portrait
41 \paragraph_separation indent
43 \quotes_language swedish
47 \tracking_changes false
53 \begin_layout Standard
54 \begin_inset Note Note
57 \begin_layout Standard
58 Please note: double dashed longoptions (e.g.
59 --version) are written this way: -
63 \begin_layout Standard
75 \begin_layout Standard
77 three consecutive dashes would otherwise result in a long resp.
81 \begin_layout Standard
82 Architecture specific stuff (like memory models, code examples) should maybe
86 \begin_layout Standard
87 into seperate sections/chapters/appendices (it is hard to document PIC or
91 \begin_layout Standard
92 a 8051 centered document) - for now simply add.
101 SDCC Compiler User Guide
116 \begin_layout Standard
117 \begin_inset Note Note
120 \begin_layout Standard
121 The above strings enclosed in $ are automatically updated by Subversion
129 \begin_layout Standard
130 \begin_inset LatexCommand \tableofcontents{}
137 \begin_layout Chapter
141 \begin_layout Section
145 \begin_layout Standard
166 ompiler) is free open source, retargettable, optimizing ANSI-C compiler
171 designed for 8 bit Microprocessors.
172 The current version targets Intel MCS51 based Microprocessors (8031, 8032,
174 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
178 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
179 Zilog Z80 based MCUs.
180 It can be retargeted for other microprocessors, support for Microchip PIC,
181 Atmel AVR is under development.
182 The entire source code for the compiler is distributed under GPL.
184 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
189 \begin_inset LatexCommand \index{aslink}
193 , an open source retargetable assembler & linker.
194 SDCC has extensive language extensions suitable for utilizing various microcont
195 rollers and underlying hardware effectively.
200 In addition to the MCU specific optimizations SDCC also does a host of
201 standard optimizations like:
204 \begin_layout Itemize
205 global sub expression elimination,
208 \begin_layout Itemize
209 loop optimizations (loop invariant, strength reduction of induction variables
213 \begin_layout Itemize
214 constant folding & propagation,
217 \begin_layout Itemize
221 \begin_layout Itemize
222 dead code elimination
225 \begin_layout Itemize
233 \begin_layout Standard
234 For the back-end SDCC uses a global register allocation scheme which should
235 be well suited for other 8 bit MCUs.
240 The peep hole optimizer uses a rule based substitution mechanism which
246 Supported data-types are:
249 \begin_layout Standard
251 <lyxtabular version="3" rows="8" columns="5">
253 <column alignment="center" valignment="top" leftline="true" width="0">
254 <column alignment="center" valignment="top" leftline="true" width="0">
255 <column alignment="center" valignment="top" leftline="true" width="0">
256 <column alignment="center" valignment="top" leftline="true" width="0">
257 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
258 <row topline="true" bottomline="true">
259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
262 \begin_layout Standard
268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
271 \begin_layout Standard
277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
280 \begin_layout Standard
286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
289 \begin_layout Standard
295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
298 \begin_layout Standard
306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
309 \begin_layout Standard
315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
318 \begin_layout Standard
324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
327 \begin_layout Standard
333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
336 \begin_layout Standard
342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
345 \begin_layout Standard
353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
356 \begin_layout Standard
362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
365 \begin_layout Standard
371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
374 \begin_layout Standard
380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
383 \begin_layout Standard
389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
392 \begin_layout Standard
400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
403 \begin_layout Standard
409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
412 \begin_layout Standard
418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
421 \begin_layout Standard
427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
430 \begin_layout Standard
436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
439 \begin_layout Standard
447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
450 \begin_layout Standard
456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
459 \begin_layout Standard
465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
468 \begin_layout Standard
474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
477 \begin_layout Standard
483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
486 \begin_layout Standard
493 <row topline="true" bottomline="true">
494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
497 \begin_layout Standard
503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
506 \begin_layout Standard
512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
515 \begin_layout Standard
521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
524 \begin_layout Standard
525 -2.147.483.648, +2.147.483.647
530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
533 \begin_layout Standard
540 <row topline="true" bottomline="true">
541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
544 \begin_layout Standard
550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
553 \begin_layout Standard
559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
562 \begin_layout Standard
568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
571 \begin_layout Standard
577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
580 \begin_layout Standard
596 <row topline="true" bottomline="true">
597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
600 \begin_layout Standard
606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
609 \begin_layout Standard
615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
618 \begin_layout Standard
624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
627 \begin_layout Standard
633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
636 \begin_layout Standard
649 The compiler also allows
651 inline assembler code
653 to be embedded anywhere in a function.
654 In addition, routines developed in assembly can also be called.
659 provides an option (-
663 \begin_layout Standard
672 -cyclomatic) to report the relative complexity of a function.
673 These functions can then be further optimized, or hand coded in assembly
679 SDCC also comes with a companion source level debugger SDCDB.
680 The debugger currently uses ucSim, a free open source simulator for 8051
681 and other micro-controllers.
685 The latest SDCC version can be downloaded from
687 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
697 Please note: the compiler will probably always be some steps ahead of this
702 \begin_inset LatexCommand \index{Status of documentation}
710 \begin_layout Standard
711 Obviously this has pros and cons
719 \begin_layout Section
723 \begin_layout Standard
724 All packages used in this compiler system are
732 ; source code for all the sub-packages (pre-processor, assemblers, linkers
733 etc.) is distributed with the package.
734 This documentation is maintained using a free open source word processor
737 This program is free software; you can redistribute it and/or modify
738 it under the terms of the GNU General Public License
739 \begin_inset LatexCommand \index{GNU General Public License, GPL}
743 as published by the Free Software Foundation; either version 2, or (at
744 your option) any later version.
745 This program is distributed in the hope that it will be useful, but WITHOUT
746 ANY WARRANTY; without even the implied warranty
747 \begin_inset LatexCommand \index{warranty}
751 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
752 See the GNU General Public License for more details.
753 You should have received a copy of the GNU General Public License along
754 with this program; if not, write to the Free Software Foundation, 59 Temple
755 Place - Suite 330, Boston, MA 02111-1307, USA.
756 In other words, you are welcome to use, share and improve this program.
757 You are forbidden to forbid anyone else to use, share and improve what
759 Help stamp out software-hoarding!
762 \begin_layout Section
763 Typographic conventions
764 \begin_inset LatexCommand \index{Typographic conventions}
771 \begin_layout Standard
772 Throughout this manual, we will use the following convention.
773 Commands you have to type in are printed in
781 Code samples are printed in
786 Interesting items and new terms are printed in
791 \begin_layout Section
793 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
797 with previous versions
798 \begin_inset LatexCommand \index{Compatibility with previous versions}
805 \begin_layout Standard
806 Newer versions have usually numerous bug fixes compared with the previous
808 But we also sometimes introduce some incompatibilities with older versions.
809 Not just for the fun of it, but to make the compiler more stable, efficient
811 \begin_inset LatexCommand \index{ANSI-compliance}
816 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
820 for ANSI-Compliance).
822 \begin_inset Note Note
825 \begin_layout Standard
826 It would be fine to add to each item, in which version was it changed.
836 \begin_layout Itemize
837 short is now equivalent to int (16 bits), it used to be equivalent to char
838 (8 bits) which is not ANSI compliant.
839 To maintain compatibility, old programs may be compiled using the -
843 \begin_layout Standard
852 -short-is-8bits commandline option (see
853 \begin_inset LatexCommand \vref{lyx:--short-is-8bits}
860 \begin_layout Itemize
861 the default directory for gcc-builds where include, library and documentation
862 files are stored is now in /usr/local/share.
865 \begin_layout Itemize
866 char type parameters to vararg
867 \begin_inset LatexCommand \index{vararg, va\_arg}
871 functions are casted to int unless explicitly casted and
877 \begin_layout Standard
887 \begin_inset LatexCommand \index{-\/-std-c89}
899 \begin_layout Standard
909 \begin_inset LatexCommand \index{-\/-std-c99}
915 command line option are not defined
916 \begin_inset Marginal
919 \begin_layout Standard
944 will push a as an int and as a char resp if
950 \begin_layout Standard
960 \begin_inset LatexCommand \index{-\/-std-c89}
972 \begin_layout Standard
982 \begin_inset LatexCommand \index{-\/-std-c99}
988 command line options are not defined,
990 will push a as two ints if
996 \begin_layout Standard
1006 \begin_inset LatexCommand \index{-\/-std-c89}
1018 \begin_layout Standard
1028 \begin_inset LatexCommand \index{-\/-std-c99}
1034 command line option is defined.
1037 \begin_layout Itemize
1042 \begin_layout Standard
1051 -regextend has been removed.
1054 \begin_layout Itemize
1059 \begin_layout Standard
1068 -noregparms has been removed.
1071 \begin_layout Itemize
1076 \begin_layout Standard
1085 -stack-after-data has been removed.
1088 \begin_layout Itemize
1090 \begin_inset LatexCommand \index{bit}
1095 \begin_inset LatexCommand \index{sbit}
1100 \begin_inset LatexCommand \index{\_\_sbit}
1104 types now consistently behave like the C99 _Bool type with respect to type
1106 \begin_inset LatexCommand \index{type conversion}
1111 \begin_inset LatexCommand \index{type promotion}
1116 The most common incompatibility resulting from this change is related to
1118 \begin_inset LatexCommand \index{Bit toggling}
1133 \begin_inset LatexCommand \index{\~\/ Operator}
1137 b; /* equivalent to b=1 instead of toggling b */
1138 \begin_inset Marginal
1141 \begin_layout Standard
1154 b = !b; /* toggles b */
1158 In previous versions, both forms would have toggled the bit.
1161 \begin_layout Itemize
1162 in older versions, the preprocessor was always called with -std=c99 regardless
1163 of the --std-xxx setting.
1164 This is no longer true, and can cause compilation failures on code built
1165 with --std-c89 but using c99 preprocessor features, such as one-line (//)
1169 \begin_layout Itemize
1170 in versions older then 2.8.4 the pic16 *printf() and printf_tiny() library
1171 functions supported undocumented and not standard compliant 'b' binary
1172 format specifier ("%b", "%hb" and "%lb").
1173 The 'b' specifier is now disabled by default.
1174 It can be enabled by defining BINARY_SPECIFIER macro in files device/lib/pic16/
1175 libc/stdio/vfprintf.c and device/lib/pic16/libc/stdio/printf_tiny.c and recompilin
1179 \begin_layout Itemize
1180 in versions older then 2.8.5 the unnamed bitfield structure members participated
1181 in initialization, which is not conforming with ISO/IEC 9899:1999 standard
1182 (see section Section 6.7.8 Initialization, clause 9)
1186 Old behaviour, before
1222 /* s.a = 1, s.b = 3 */
1263 /* s.a = 1, s.b = 2 */
1266 \begin_layout Section
1270 \begin_layout Standard
1271 What do you need before you start installation of SDCC? A computer, and
1272 a desire to compute.
1273 The preferred method of installation is to compile SDCC from source using
1275 For Windows some pre-compiled binary distributions are available for your
1277 You should have some experience with command line tools and compiler use.
1280 \begin_layout Section
1284 \begin_layout Standard
1285 The SDCC home page at
1286 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1290 is a great place to find distribution sets.
1291 You can also find links to the user mailing lists that offer help or discuss
1292 SDCC with other SDCC users.
1293 Web links to other SDCC related sites can also be found here.
1294 This document can be found in the DOC directory of the source package as
1295 a text or HTML file.
1296 A pdf version of this document is available at
1297 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1302 Some of the other tools (simulator and assembler) included with SDCC contain
1303 their own documentation and can be found in the source distribution.
1304 If you want the latest unreleased software, the complete source package
1305 is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1309 \begin_layout Section
1310 Wishes for the future
1313 \begin_layout Standard
1314 There are (and always will be) some things that could be done.
1315 Here are some I can think of:
1320 \begin_layout Standard
1323 char KernelFunction3(char p) at 0x340;
1328 \begin_layout Standard
1332 \begin_inset LatexCommand \index{code banking (limited support)}
1342 If you can think of some more, please see the section
1343 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1347 about filing feature requests
1348 \begin_inset LatexCommand \index{Requesting features}
1353 \begin_inset LatexCommand \index{Feature request}
1362 \begin_layout Chapter
1364 \begin_inset LatexCommand \index{Installation}
1371 \begin_layout Standard
1372 For most users it is sufficient to skip to either section
1373 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1378 \begin_inset LatexCommand \ref{sub:Windows-Install}
1383 More detailed instructions follow below.
1386 \begin_layout Section
1388 \begin_inset LatexCommand \index{Options SDCC configuration}
1395 \begin_layout Standard
1396 The install paths, search paths and other options are defined when running
1398 The defaults can be overridden by:
1402 \labelwidthstring 00.00.0000
1407 \begin_layout Standard
1416 -prefix see table below
1420 \labelwidthstring 00.00.0000
1425 \begin_layout Standard
1434 -exec_prefix see table below
1438 \labelwidthstring 00.00.0000
1443 \begin_layout Standard
1452 -bindir see table below
1456 \labelwidthstring 00.00.0000
1461 \begin_layout Standard
1470 -datadir see table below
1474 \labelwidthstring 00.00.0000
1479 \begin_layout Standard
1488 -datarootdir see table below
1494 \labelwidthstring 00.00.0000
1497 docdir environment variable, see table below
1501 \labelwidthstring 00.00.0000
1504 include_dir_suffix environment variable, see table below
1508 \labelwidthstring 00.00.0000
1511 lib_dir_suffix environment variable, see table below
1515 \labelwidthstring 00.00.0000
1518 sdccconf_h_dir_separator environment variable, either / or
1523 This character will only be used in sdccconf.h; don't forget it's a C-header,
1524 therefore a double-backslash is needed there.
1530 \labelwidthstring 00.00.0000
1535 \begin_layout Standard
1544 -disable-mcs51-port Excludes the Intel mcs51 port
1548 \labelwidthstring 00.00.0000
1553 \begin_layout Standard
1562 -disable-gbz80-port Excludes the Gameboy gbz80 port
1566 \labelwidthstring 00.00.0000
1571 \begin_layout Standard
1580 -disable-z80-port Excludes the z80 port
1584 \labelwidthstring 00.00.0000
1589 \begin_layout Standard
1598 -disable-avr-port Excludes the AVR port
1602 \labelwidthstring 00.00.0000
1607 \begin_layout Standard
1616 -disable-ds390-port Excludes the DS390 port
1620 \labelwidthstring 00.00.0000
1625 \begin_layout Standard
1634 -disable-hc08-port Excludes the HC08 port
1638 \labelwidthstring 00.00.0000
1643 \begin_layout Standard
1652 -disable-pic-port Excludes the PIC14 port
1656 \labelwidthstring 00.00.0000
1661 \begin_layout Standard
1670 -disable-pic16-port Excludes the PIC16 port
1674 \labelwidthstring 00.00.0000
1679 \begin_layout Standard
1688 -disable-xa51-port Excludes the XA51 port
1692 \labelwidthstring 00.00.0000
1697 \begin_layout Standard
1706 -disable-ucsim Disables configuring and building of ucsim
1710 \labelwidthstring 00.00.0000
1715 \begin_layout Standard
1724 -disable-device-lib Disables automatically building device libraries
1728 \labelwidthstring 00.00.0000
1733 \begin_layout Standard
1742 -disable-packihx Disables building packihx
1748 \labelwidthstring 00.00.0000
1753 \begin_layout Standard
1762 -enable-doc Build pdf, html and txt files from the lyx sources
1766 \labelwidthstring 00.00.0000
1771 \begin_layout Standard
1780 -enable-libgc Use the Bohem memory allocator.
1781 Lower runtime footprint.
1785 \labelwidthstring 00.00.0000
1790 \begin_layout Standard
1799 -without-ccache Do not use ccache even if available
1802 \begin_layout Standard
1803 Furthermore the environment variables CC, CFLAGS, ...
1804 the tools and their arguments can be influenced.
1805 Please see `configure -
1809 \begin_layout Standard
1818 -help' and the man/info pages of `configure' for details.
1823 standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1824 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1825 SDCC_LIB_NAME are defined by `configure' too.
1826 At the moment it's not possible to change the default settings (it was
1827 simply never required).
1831 These configure options are compiled into the binaries,
1832 and can only be changed by rerunning 'configure' and recompiling SDCC.
1833 The configure options are written in
1837 to distinguish them from run time environment variables (see section search
1843 \begin_inset Quotes sld
1847 \begin_inset Quotes srd
1850 are used by the SDCC team to build the official Win32 binaries.
1851 The SDCC team uses Mingw32 to build the official Windows binaries, because
1855 \begin_layout Enumerate
1859 \begin_layout Enumerate
1860 a gcc compiler and last but not least
1863 \begin_layout Enumerate
1864 the binaries can be built by cross compiling on SDCC Distributed Compile
1868 \begin_layout Standard
1869 See the examples, how to pass the Win32 settings to 'configure'.
1870 The other Win32 builds using Borland, VC or whatever don't use 'configure',
1871 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1881 \begin_layout Standard
1883 \begin_inset Tabular
1884 <lyxtabular version="3" rows="9" columns="3">
1886 <column alignment="block" valignment="top" leftline="true" width="0in">
1887 <column alignment="block" valignment="top" leftline="true" width="0in">
1888 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1889 <row topline="true" bottomline="true">
1890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1893 \begin_layout Standard
1899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1902 \begin_layout Standard
1908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1911 \begin_layout Standard
1918 <row topline="true">
1919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1922 \begin_layout Standard
1930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1933 \begin_layout Standard
1939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1942 \begin_layout Standard
1951 <row topline="true">
1952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1955 \begin_layout Standard
1963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1966 \begin_layout Standard
1974 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1977 \begin_layout Standard
1986 <row topline="true">
1987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1990 \begin_layout Standard
1998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2001 \begin_layout Standard
2011 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2014 \begin_layout Standard
2027 <row topline="true">
2028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2031 \begin_layout Standard
2039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2042 \begin_layout Standard
2050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2053 \begin_layout Standard
2062 <row topline="true">
2063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2066 \begin_layout Standard
2074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2077 \begin_layout Standard
2087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2090 \begin_layout Standard
2099 <row topline="true">
2100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2103 \begin_layout Standard
2111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2114 \begin_layout Standard
2124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2127 \begin_layout Standard
2140 <row topline="true">
2141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2144 \begin_layout Standard
2152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2155 \begin_layout Standard
2161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2164 \begin_layout Standard
2171 <row topline="true" bottomline="true">
2172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2175 \begin_layout Standard
2183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2186 \begin_layout Standard
2192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2195 \begin_layout Standard
2211 \begin_layout Standard
2213 'configure' also computes relative paths.
2214 This is needed for full relocatability of a binary package and to complete
2215 search paths (see section search paths below):
2220 \begin_layout Standard
2222 \begin_inset Tabular
2223 <lyxtabular version="3" rows="4" columns="3">
2225 <column alignment="block" valignment="top" leftline="true" width="0in">
2226 <column alignment="block" valignment="top" leftline="true" width="0in">
2227 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2228 <row topline="true" bottomline="true">
2229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2232 \begin_layout Standard
2238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2241 \begin_layout Standard
2247 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2250 \begin_layout Standard
2257 <row topline="true" bottomline="true">
2258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2261 \begin_layout Standard
2269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2272 \begin_layout Standard
2278 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2281 \begin_layout Standard
2288 <row bottomline="true">
2289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2292 \begin_layout Standard
2300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2303 \begin_layout Standard
2309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2312 \begin_layout Standard
2319 <row bottomline="true">
2320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2323 \begin_layout Standard
2331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2334 \begin_layout Standard
2340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2343 \begin_layout Standard
2359 \begin_layout Standard
2364 \begin_layout LyX-Code
2371 \begin_layout Standard
2381 \begin_inset Quotes srd
2385 \begin_inset Quotes srd
2392 \begin_layout Standard
2402 \begin_inset Quotes srd
2406 \begin_inset Quotes srd
2415 \begin_layout Standard
2428 \begin_layout Standard
2440 \begin_layout Standard
2441 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2445 \begin_layout LyX-Code
2451 \begin_inset Quotes srd
2454 i586-mingw32msvc-gcc
2455 \begin_inset Quotes srd
2459 \begin_inset Quotes srd
2462 i586-mingw32msvc-g++
2463 \begin_inset Quotes srd
2471 \begin_inset Quotes srd
2474 i586-mingw32msvc-ranlib
2475 \begin_inset Quotes srd
2483 \begin_inset Quotes srd
2486 i586-mingw32msvc-strip
2487 \begin_inset Quotes srd
2498 \begin_layout Standard
2508 \begin_inset Quotes srd
2512 \begin_inset Quotes srd
2523 \begin_layout Standard
2533 \begin_inset Quotes srd
2537 \begin_inset Quotes srd
2545 \begin_inset Quotes srd
2551 \begin_inset Quotes srd
2559 \begin_inset Quotes srd
2563 \begin_inset Quotes srd
2571 \begin_inset Quotes srd
2575 \begin_inset Quotes srd
2582 sdccconf_h_dir_separator=
2583 \begin_inset Quotes srd
2595 \begin_inset Quotes srd
2606 \begin_layout Standard
2623 \begin_layout Standard
2632 -host=i586-mingw32msvc
2640 \begin_layout Standard
2649 -build=unknown-unknown-linux-gnu
2652 \begin_layout Standard
2654 \begin_inset Quotes sld
2658 \begin_inset Quotes srd
2661 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2665 \begin_layout LyX-Code
2674 \begin_layout Standard
2684 \begin_inset Quotes srd
2688 \begin_inset Quotes srd
2699 \begin_layout Standard
2709 \begin_inset Quotes srd
2713 \begin_inset Quotes srd
2721 \begin_inset Quotes srd
2727 \begin_inset Quotes srd
2735 \begin_inset Quotes srd
2739 \begin_inset Quotes srd
2747 \begin_inset Quotes srd
2751 \begin_inset Quotes srd
2758 sdccconf_h_dir_separator=
2759 \begin_inset Quotes srd
2771 \begin_inset Quotes srd
2779 \begin_inset Quotes srd
2783 \begin_inset Quotes srd
2791 \begin_inset Quotes srd
2795 \begin_inset Quotes srd
2801 \begin_layout Standard
2802 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2807 \begin_layout Standard
2816 -C' turns on caching, which gives a little bit extra speed.
2817 However if options are changed, it can be necessary to delete the config.cache
2821 \begin_layout Section
2823 \begin_inset LatexCommand \label{sub:Install-paths}
2828 \begin_inset LatexCommand \index{Install paths}
2835 \begin_layout Standard
2836 \begin_inset VSpace medskip
2842 \begin_layout Standard
2844 \begin_inset Tabular
2845 <lyxtabular version="3" rows="5" columns="4">
2847 <column alignment="left" valignment="top" leftline="true" width="0">
2848 <column alignment="left" valignment="top" leftline="true" width="0">
2849 <column alignment="left" valignment="top" leftline="true" width="0">
2850 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2851 <row topline="true" bottomline="true">
2852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2855 \begin_layout Standard
2863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2866 \begin_layout Standard
2874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2877 \begin_layout Standard
2885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2888 \begin_layout Standard
2897 <row topline="true">
2898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2901 \begin_layout Standard
2907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2910 \begin_layout Standard
2918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2921 \begin_layout Standard
2927 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2930 \begin_layout Standard
2941 <row topline="true">
2942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2945 \begin_layout Standard
2951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2954 \begin_layout Standard
2957 $DATADIR/ $INCLUDE_DIR_SUFFIX
2962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2965 \begin_layout Standard
2966 /usr/local/share/sdcc/include
2971 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2974 \begin_layout Standard
2985 <row topline="true">
2986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2989 \begin_layout Standard
2995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2998 \begin_layout Standard
3001 $DATADIR/$LIB_DIR_SUFFIX
3006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3009 \begin_layout Standard
3010 /usr/local/share/sdcc/lib
3015 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3018 \begin_layout Standard
3029 <row topline="true" bottomline="true">
3030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3033 \begin_layout Standard
3039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3042 \begin_layout Standard
3050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3053 \begin_layout Standard
3054 /usr/local/share/sdcc/doc
3059 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3062 \begin_layout Standard
3083 *compiler, preprocessor, assembler, and linker
3089 is auto-appended by the compiler, e.g.
3090 small, large, z80, ds390 etc
3093 \begin_layout Standard
3095 The install paths can still be changed during `make install' with e.g.:
3098 \begin_layout LyX-Code
3099 make install prefix=$(HOME)/local/sdcc
3102 \begin_layout Standard
3103 Of course this doesn't change the search paths compiled into the binaries.
3108 r the install path can be changed by defining DESTDIR
3109 \begin_inset LatexCommand \index{DESTDIR}
3116 \begin_layout LyX-Code
3117 make install DESTDIR=$(HOME)/sdcc.rpm/
3120 \begin_layout Standard
3121 Please note that DESTDIR must have a trailing slash!
3124 \begin_layout Section
3126 \begin_inset LatexCommand \label{sub:Search-Paths}
3131 \begin_inset LatexCommand \index{Search path}
3138 \begin_layout Standard
3139 Some search paths or parts of them are determined by configure variables
3144 , see section above).
3145 Further search paths are determined by environment variables during runtime.
3148 The paths searched when running the compiler are as follows (the first
3154 Binary files (preprocessor, assembler and linker)
3159 \begin_layout Standard
3161 \begin_inset Tabular
3162 <lyxtabular version="3" rows="4" columns="3">
3164 <column alignment="block" valignment="top" leftline="true" width="0in">
3165 <column alignment="block" valignment="top" leftline="true" width="0in">
3166 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3167 <row topline="true" bottomline="true">
3168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3171 \begin_layout Standard
3177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3180 \begin_layout Standard
3186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3189 \begin_layout Standard
3196 <row topline="true">
3197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3200 \begin_layout Standard
3208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3211 \begin_layout Standard
3217 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3220 \begin_layout Standard
3229 <row topline="true">
3230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3233 \begin_layout Standard
3234 Path of argv[0] (if available)
3239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3242 \begin_layout Standard
3248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3251 \begin_layout Standard
3258 <row topline="true" bottomline="true">
3259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3262 \begin_layout Standard
3268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3271 \begin_layout Standard
3277 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3280 \begin_layout Standard
3296 \begin_layout Standard
3304 \begin_layout Standard
3306 \begin_inset Tabular
3307 <lyxtabular version="3" rows="6" columns="3">
3309 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3310 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3311 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3312 <row topline="true" bottomline="true">
3313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3316 \begin_layout Standard
3322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3325 \begin_layout Standard
3331 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3334 \begin_layout Standard
3341 <row topline="true">
3342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3345 \begin_layout Standard
3350 \begin_layout Standard
3364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3367 \begin_layout Standard
3372 \begin_layout Standard
3386 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3389 \begin_layout Standard
3394 \begin_layout Standard
3409 <row topline="true">
3410 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3413 \begin_layout Standard
3419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3422 \begin_layout Standard
3428 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3431 \begin_layout Standard
3438 <row topline="true">
3439 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3442 \begin_layout Standard
3454 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3457 \begin_layout Standard
3467 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3470 \begin_layout Standard
3479 <row topline="true">
3480 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3483 \begin_layout Standard
3499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3502 \begin_layout Standard
3550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3553 \begin_layout Standard
3564 <row topline="true" bottomline="true">
3565 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3568 \begin_layout Standard
3582 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3585 \begin_layout Standard
3586 /usr/local/share/sdcc/
3593 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3596 \begin_layout Standard
3612 \begin_layout Standard
3618 \begin_layout Standard
3627 -nostdinc disables the last two search paths.
3637 \begin_layout Standard
3638 With the exception of
3639 \begin_inset Quotes sld
3646 \begin_layout Standard
3656 \begin_inset Quotes srd
3663 is auto-appended by the compiler (e.g.
3664 small, large, z80, ds390 etc.).
3670 \begin_layout Standard
3672 \begin_inset Tabular
3673 <lyxtabular version="3" rows="6" columns="3">
3675 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3676 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3677 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3678 <row topline="true" bottomline="true">
3679 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3682 \begin_layout Standard
3688 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3691 \begin_layout Standard
3697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3700 \begin_layout Standard
3707 <row topline="true">
3708 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3711 \begin_layout Standard
3716 \begin_layout Standard
3730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3733 \begin_layout Standard
3738 \begin_layout Standard
3752 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3755 \begin_layout Standard
3760 \begin_layout Standard
3775 <row topline="true">
3776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3779 \begin_layout Standard
3789 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3792 \begin_layout Standard
3802 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3805 \begin_layout Standard
3818 <row topline="true">
3819 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3822 \begin_layout Standard
3829 $LIB_DIR_SUFFIX/<model>
3834 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3837 \begin_layout Standard
3849 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3852 \begin_layout Standard
3867 <row topline="true">
3868 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3871 \begin_layout Standard
3882 $LIB_DIR_SUFFIX/<model>
3887 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3890 \begin_layout Standard
3941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3944 \begin_layout Standard
3998 <row topline="true" bottomline="true">
3999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4002 \begin_layout Standard
4007 $LIB_DIR_SUFFIX/<model>
4012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4015 \begin_layout Standard
4016 /usr/local/share/sdcc/
4025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4028 \begin_layout Standard
4044 \begin_layout Standard
4045 \begin_inset Note Note
4048 \begin_layout Standard
4049 Don't delete any of the stray spaces in the table above without checking
4050 the HTML output (last line)!
4058 \begin_layout Standard
4066 \begin_layout Standard
4075 -nostdlib disables the last two search paths.
4078 \begin_layout Section
4080 \begin_inset LatexCommand \index{Building SDCC}
4087 \begin_layout Subsection
4088 Building SDCC on Linux
4089 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
4096 \begin_layout Enumerate
4099 Download the source package
4101 either from the SDCC Subversion repository or from snapshot builds
4103 , it will be named something like sdcc
4114 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
4121 \begin_layout Enumerate
4124 Bring up a command line terminal, such as xterm.
4127 \begin_layout Enumerate
4130 Unpack the file using a command like:
4133 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
4134 \begin_inset Quotes srd
4140 , this will create a sub-directory called sdcc with all of the sources.
4143 \begin_layout Enumerate
4144 Change directory into the main SDCC directory, for example type:
4152 \begin_layout Enumerate
4162 This configures the package for compilation on your system.
4165 \begin_layout Enumerate
4179 All of the source packages will compile, this can take a while.
4182 \begin_layout Enumerate
4196 This copies the binary executables, the include files, the libraries and
4197 the documentation to the install directories.
4198 Proceed with section
4199 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
4206 \begin_layout Subsection
4207 Building SDCC on Mac OS X
4210 \begin_layout Standard
4211 Follow the instruction for Linux.
4215 On Mac OS X 10.2.x it was reported, that the
4216 default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
4217 Fortunately there's also gcc 2.9.x installed, which works fine.
4218 This compiler can be selected by running 'configure' with:
4221 \begin_layout LyX-Code
4222 ./configure CC=gcc2 CXX=g++2
4225 \begin_layout Standard
4226 Universal (ppc and i386) binaries can be produced on Mac OS X 10.4.x with
4228 Run 'configure' with:
4231 \begin_layout LyX-Code
4237 \begin_layout LyX-Code
4238 LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4244 \begin_layout LyX-Code
4245 CXXFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4251 \begin_layout LyX-Code
4252 CFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
4255 \begin_layout Subsection
4256 Cross compiling SDCC on Linux for Windows
4259 \begin_layout Standard
4260 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
4261 See section 'Configure Options'.
4264 \begin_layout Subsection
4265 Building SDCC using Cygwin and Mingw32
4268 \begin_layout Standard
4269 For building and installing a Cygwin executable follow the instructions
4275 \begin_inset Quotes sld
4279 \begin_inset Quotes srd
4282 Win32-binary can be built, which will not need the Cygwin-DLL.
4283 For the necessary 'configure' options see section 'configure options' or
4284 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4289 Cygwin on Windows download setup.exe from
4290 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
4296 \begin_inset Quotes sld
4299 default text file type
4300 \begin_inset Quotes srd
4304 \begin_inset Quotes sld
4308 \begin_inset Quotes srd
4311 and download/install at least the following packages.
4312 Some packages are selected by default, others will be automatically selected
4313 because of dependencies with the manually selected packages.
4314 Never deselect these packages!
4317 \begin_layout Itemize
4321 \begin_layout Itemize
4325 \begin_layout Itemize
4326 gcc ; version 3.x is fine, no need to use the old 2.9x
4329 \begin_layout Itemize
4330 binutils ; selected with gcc
4333 \begin_layout Itemize
4337 \begin_layout Itemize
4338 rxvt ; a nice console, which makes life much easier under windoze (see below)
4341 \begin_layout Itemize
4342 man ; not really needed for building SDCC, but you'll miss it sooner or
4346 \begin_layout Itemize
4347 less ; not really needed for building SDCC, but you'll miss it sooner or
4351 \begin_layout Itemize
4352 svn ; only if you use Subversion access
4355 \begin_layout Standard
4356 If you want to develop something you'll need:
4359 \begin_layout Itemize
4360 python ; for the regression tests
4363 \begin_layout Itemize
4364 gdb ; the gnu debugger, together with the nice GUI
4365 \begin_inset Quotes sld
4369 \begin_inset Quotes srd
4375 \begin_layout Itemize
4376 openssh ; to access the CF or commit changes
4379 \begin_layout Itemize
4380 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4381 use autoconf-stable!
4384 \begin_layout Standard
4385 rxvt is a nice console with history.
4386 Replace in your cygwin.bat the line
4389 \begin_layout LyX-Code
4394 \begin_layout Standard
4406 \begin_layout Standard
4410 \begin_layout LyX-Code
4411 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4414 \begin_layout LyX-Code
4415 -bg black -fg white -geometry 100x65 -e bash -
4419 \begin_layout Standard
4431 \begin_layout Standard
4432 Text selected with the mouse is automatically copied to the clipboard, pasting
4433 works with shift-insert.
4437 The other good tip is to make sure you have no //c/-styl
4438 e paths anywhere, use /cygdrive/c/ instead.
4439 Using // invokes a network lookup which is very slow.
4441 \begin_inset Quotes sld
4445 \begin_inset Quotes srd
4448 is too long, you can change it with e.g.
4451 \begin_layout LyX-Code
4455 \begin_layout Standard
4456 SDCC sources use the unix line ending LF.
4457 Life is much easier, if you store the source tree on a drive which is mounted
4459 And use an editor which can handle LF-only line endings.
4460 Make sure not to commit files with windows line endings.
4461 The tabulator spacing
4462 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4466 used in the project is 8.
4467 Although a tabulator spacing of 8 is a sensible choice for programmers
4468 (it's a power of 2 and allows to display 8/16 bit signed variables without
4469 loosing columns) the plan is to move towards using only spaces in the source.
4472 \begin_layout Subsection
4473 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4476 \begin_layout Standard
4479 Download the source package
4481 either from the SDCC Subversion repository or from the
4482 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4488 , it will be named something like sdcc
4492 -yyyymmdd-rrrr.tar.bz2.
4495 SDCC is distributed with all the projects, workspaces, and files you need
4496 to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4497 The workspace name is 'sdcc.dsw'.
4498 Please note that as it is now, all the executables are created in a folder
4502 Once built you need to copy the executables from sdcc
4506 bin before running SDCC.
4511 WARNING: Visual studio is very picky with line terminations; it expects
4512 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4513 When using the Subversion repository it's easiest to configure the svn
4514 client to convert automatically for you.
4515 If however you are getting a message such as "This makefile was not generated
4516 by Developer Studio etc.
4518 \begin_inset Quotes srd
4521 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4522 need to convert the Unix style line endings to DOS style line endings.
4523 To do so you can use the
4524 \begin_inset Quotes sld
4528 \begin_inset Quotes srd
4531 utility freely available on the internet.
4532 Doug Hawkins reported in the sdcc-user list that this works:
4540 SDCC> unix2dos sdcc.dsw
4546 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4550 In order to build SDCC with MSVC
4551 you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4552 One good place to get them is
4553 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4561 Download the file UnxUtils
4562 \begin_inset LatexCommand \index{UnxUtils}
4567 Now you have to install the utilities and setup MSVC so it can locate the
4569 Here there are two alternatives (choose one!):
4572 \begin_layout Enumerate
4577 a) Extract UnxUtils.zip to your C:
4579 hard disk PRESERVING the original paths, otherwise bison won't work.
4580 (If you are using WinZip make certain that 'Use folder names' is selected)
4585 In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4586 'Show directories for:' select 'Executable files', and in the directories
4587 window add a new path: 'C:
4597 (As a side effect, you get a bunch of Unix utilities that
4598 could be useful, such as diff and patch.)
4601 \begin_layout Enumerate
4606 This one avoids extracting a bunch of files you may not
4607 use, but requires some extra work:
4611 a) Create a directory were to put the
4612 tools needed, or use a directory already present.
4619 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4620 gawk.exe to such directory WITHOUT preserving the original paths.
4621 (If you are using WinZip make certain that 'Use folder names' is not selected)
4626 ) Rename bison.exe to '_bison.exe'.
4630 d) Create a batch file 'bison.bat' in 'C:
4634 ' and add these lines:
4654 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4658 Steps 'c' and 'd' are needed
4659 because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4660 reside in some weird Unix directory, '/usr/local/share/' I think.
4661 So it is necessary to tell bison where those files are located if they
4662 are not in such directory.
4663 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4668 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4669 in 'Show directories for:' select 'Executable files', and in the directories
4670 window add a new path: 'c:
4673 Note that you can use any other path instead of 'c:
4675 util', even the path where the Visual C++ tools are, probably: 'C:
4679 Microsoft Visual Studio
4684 So you don't have to execute step 'e' :)
4687 \begin_layout Standard
4689 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4690 the executables from sdcc
4694 bin, and you can compile using SDCC.
4697 \begin_layout Subsection
4698 Building SDCC Using Borland
4701 \begin_layout Enumerate
4702 From the sdcc directory, run the command "make -f Makefile.bcc".
4703 This should regenerate all the .exe files in the bin directory except for
4707 \begin_layout Enumerate
4708 If you modify any source files and need to rebuild, be aware that the dependenci
4709 es may not be correctly calculated.
4710 The safest option is to delete all .obj files and run the build again.
4711 From a Cygwin BASH prompt, this can easily be done with the command (be
4712 sure you are in the sdcc directory):
4722 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
4724 ) -print -exec rm {}
4733 or on Windows NT/2000/XP from the command prompt with the command:
4740 del /s *.obj *.lib *.rul
4743 from the sdcc directory.
4746 \begin_layout Subsection
4747 Windows Install Using a ZIP Package
4750 \begin_layout Enumerate
4751 Download the binary zip package from
4752 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4756 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4757 This should unpack to a group of sub-directories.
4758 An example directory structure after unpacking the mingw32 package is:
4763 bin for the executables, c:
4771 lib for the include and libraries.
4774 \begin_layout Enumerate
4775 Adjust your environment variable PATH to include the location of the bin
4776 directory or start sdcc using the full path.
4779 \begin_layout Subsection
4780 Windows Install Using the Setup Program
4781 \begin_inset LatexCommand \label{sub:Windows-Install}
4788 \begin_layout Standard
4789 Download the setup program
4791 sdcc-x.y.z-setup.exe
4793 for an official release from
4796 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4800 or a setup program for one of the snapshots
4802 sdcc-yyyymmdd-xxxx-setup.exe
4805 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4810 A windows typical installer will guide you through the installation process.
4813 \begin_layout Subsection
4815 \begin_inset LatexCommand \index{VPATH}
4822 \begin_layout Standard
4823 SDCC supports the VPATH feature provided by configure and make.
4824 It allows to separate the source and build trees.
4828 \begin_layout Standard
4855 \begin_layout Standard
4858 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4859 # extract source to directory sdcc
4862 \begin_layout Standard
4865 mkdir sdcc.build\InsetSpace ~
4874 # put output in sdcc.build
4877 \begin_layout Standard
4883 \begin_layout Standard
4886 ../sdcc/configure\InsetSpace ~
4894 # configure is doing all the magic!
4897 \begin_layout Standard
4903 \begin_layout Standard
4909 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4910 It automagically computes the variables srcdir, top_srcdir and top_buildir
4916 the generated files will be in ~/sdcc.build, while the source files stay
4919 This is not only usefull for building different binaries, e.g.
4920 when cross compiling.
4921 It also gives you a much better overview in the source tree when all the
4922 generated files are not scattered between the source files.
4923 And the best thing is: if you want to change a file you can leave the original
4924 file untouched in the source directory.
4925 Simply copy it to the build directory, edit it, enter `make clean', `rm
4926 Makefile.dep' and `make'.
4931 will do the rest for you!
4934 \begin_layout Section
4935 Building the Documentation
4938 \begin_layout Standard
4943 \begin_layout Standard
4952 -enable-doc to the configure arguments to build the documentation together
4953 with all the other stuff.
4954 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4955 dvips and makeindex) to get the job done.
4956 Another possibility is to change to the doc directory and to type
4960 \begin_inset Quotes srd
4964 \begin_inset Quotes srd
4971 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4974 \begin_inset LatexCommand \url{http://www.lyx.org}
4978 as editor is straightforward.
4979 Prebuilt documentation in html and pdf format is available from
4980 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4987 \begin_layout Section
4988 Reading the Documentation
4989 \begin_inset LatexCommand \index{Documentation}
4996 \begin_layout Standard
4997 Currently reading the document in pdf format is recommended, as for unknown
4998 reason the hyperlinks are working there whereas in the html version they
5003 \begin_layout Standard
5004 If you should know why please drop us a note
5012 You'll find the pdf version
5013 \begin_inset LatexCommand \index{PDF version of this document}
5018 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
5026 \begin_inset LatexCommand \index{HTML version of this document}
5031 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
5037 This documentation is in some aspects different from a commercial documentation:
5041 \begin_layout Itemize
5042 It tries to document SDCC for several processor architectures in one document
5043 (commercially these probably would be separate documents/products).
5045 \begin_inset LatexCommand \index{Status of documentation}
5049 currently matches SDCC for mcs51 and DS390 best and does give too few informati
5051 Z80, PIC14, PIC16 and HC08.
5054 \begin_layout Itemize
5055 There are many references pointing away from this documentation.
5056 Don't let this distract you.
5058 was a reference like
5059 \begin_inset LatexCommand \url{http://www.opencores.org}
5063 together with a statement
5064 \begin_inset Quotes sld
5067 some processors which are targetted by SDCC can be implemented in a
5084 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
5089 \begin_inset Quotes srd
5093 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
5098 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
5103 \begin_inset Quotes sld
5106 have you ever heard of an open source compiler that compiles a subset of
5108 \begin_inset Quotes srd
5111 we expect you to have a quick look there and come back.
5112 If you read this you are on the right track.
5115 \begin_layout Itemize
5116 Some sections attribute more space to problems, restrictions and warnings
5117 than to the solution.
5120 \begin_layout Itemize
5121 The installation section and the section about the debugger is intimidating.
5124 \begin_layout Itemize
5125 There are still lots of typos and there are more different writing styles
5129 \begin_layout Section
5130 Testing the SDCC Compiler
5131 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
5138 \begin_layout Standard
5139 The first thing you should do after installing your SDCC compiler is to
5148 \begin_layout Standard
5158 \begin_inset LatexCommand \index{version}
5165 at the prompt, and the program should run and output its version like:
5170 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
5174 \begin_layout Standard
5175 If it doesn't run, or gives a message about not finding sdcc program, then
5176 you need to check over your installation.
5177 Make sure that the sdcc bin directory is in your executable search path
5178 defined by the PATH environment setting (
5183 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5190 Install trouble-shooting for suggestions
5193 Make sure that the sdcc program is in the bin folder, if not perhaps something
5194 did not install correctly.
5202 is commonly installed as described in section
5203 \begin_inset Quotes sld
5206 Install and search paths
5207 \begin_inset Quotes srd
5216 Make sure the compiler works on a very simple example.
5217 Type in the following test.c program using your favorite
5242 \begin_layout Standard
5245 Compile this using the following command:
5254 If all goes well, the compiler will generate a test.asm and test.rel file.
5255 Congratulations, you've just compiled your first program with SDCC.
5256 We used the -c option to tell SDCC not to link the generated code, just
5257 to keep things simple for this step.
5265 The next step is to try it with the linker.
5275 If all goes well the compiler will link with the libraries and produce
5276 a test.ihx output file.
5281 (no test.ihx, and the linker generates warnings), then the problem is most
5290 usr/local/share/sdcc/lib directory
5297 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5304 Install trouble-shooting for suggestions).
5312 The final test is to ensure
5320 header files and libraries.
5321 Edit test.c and change it to the following:
5339 strcpy(str1, "testing");
5344 \begin_layout Standard
5347 Compile this by typing
5354 This should generate a test.ihx output file, and it should give no warnings
5355 such as not finding the string.h file.
5356 If it cannot find the string.h file, then the problem is that
5360 cannot find the /usr/local/share/sdcc/include directory
5367 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5374 Install trouble-shooting section for suggestions).
5383 \begin_layout Standard
5395 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5399 to find exactly where SDCC is looking for the include and lib files.
5402 \begin_layout Section
5403 Install Trouble-shooting
5404 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5409 \begin_inset LatexCommand \index{Install trouble-shooting}
5416 \begin_layout Subsection
5417 If SDCC does not build correctly
5420 \begin_layout Standard
5421 A thing to try is starting from scratch by unpacking the .tgz source package
5422 again in an empty directory.
5430 ./configure 2>&1 | tee configure.log
5444 make 2>&1 | tee make.log
5451 If anything goes wrong, you can review the log files to locate the problem.
5452 Or a relevant part of this can be attached to an email that could be helpful
5453 when requesting help from the mailing list.
5456 \begin_layout Subsection
5458 \begin_inset Quotes sld
5462 \begin_inset Quotes srd
5468 \begin_layout Standard
5470 \begin_inset Quotes sld
5474 \begin_inset Quotes srd
5477 command is a script that analyzes your system and performs some configuration
5478 to ensure the source package compiles on your system.
5479 It will take a few minutes to run, and will compile a few tests to determine
5480 what compiler features are installed.
5483 \begin_layout Subsection
5485 \begin_inset Quotes sld
5489 \begin_inset Quotes srd
5495 \begin_layout Standard
5496 This runs the GNU make tool, which automatically compiles all the source
5497 packages into the final installed binary executables.
5500 \begin_layout Subsection
5502 \begin_inset Quotes sld
5506 \begin_inset Quotes erd
5512 \begin_layout Standard
5513 This will install the compiler, other executables libraries and include
5514 files into the appropriate directories.
5516 \begin_inset LatexCommand \ref{sub:Install-paths}
5522 \begin_inset LatexCommand \ref{sub:Search-Paths}
5527 about install and search paths.
5529 On most systems you will need super-user privilege
5533 \begin_layout Section
5537 \begin_layout Standard
5538 SDCC is not just a compiler, but a collection of tools by various developers.
5539 These include linkers, assemblers, simulators and other components.
5540 Here is a summary of some of the components.
5541 Note that the included simulator and assembler have separate documentation
5542 which you can find in the source package in their respective directories.
5543 As SDCC grows to include support for other processors, other packages from
5544 various developers are included and may have their own sets of documentation.
5549 might want to look at the files which are installed in <installdir>.
5550 At the time of this writing, we find the following programs for gcc-builds:
5555 In <installdir>/bin:
5558 \begin_layout Itemize
5559 sdcc - The compiler.
5562 \begin_layout Itemize
5563 sdcpp - The C preprocessor.
5566 \begin_layout Itemize
5567 asx8051 - The assembler for 8051 type processors.
5570 \begin_layout Itemize
5575 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5578 \begin_layout Itemize
5579 aslink -The linker for 8051 type processors.
5582 \begin_layout Itemize
5587 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5590 \begin_layout Itemize
5591 s51 - The ucSim 8051 simulator.
5594 \begin_layout Itemize
5595 sdcdb - The source debugger.
5598 \begin_layout Itemize
5599 packihx - A tool to pack (compress) Intel hex files.
5602 \begin_layout Standard
5603 In <installdir>/share/sdcc/include
5606 \begin_layout Itemize
5610 \begin_layout Standard
5611 In <installdir>/share/sdcc/lib
5614 \begin_layout Itemize
5615 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5619 \begin_layout Standard
5620 In <installdir>/share/sdcc/doc
5623 \begin_layout Itemize
5627 \begin_layout Standard
5628 As development for other processors proceeds, this list will expand to include
5629 executables to support processors like AVR, PIC, etc.
5632 \begin_layout Subsection
5636 \begin_layout Standard
5637 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5638 the assembler and linkage editor.
5641 \begin_layout Subsection
5642 sdcpp - The C-Preprocessor
5645 \begin_layout Standard
5647 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5651 is a modified version of the GNU cpp
5652 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5657 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5662 The C preprocessor is used to pull in #include sources, process #ifdef
5663 statements, #defines and so on.
5666 \begin_layout Subsection
5675 - The Assemblers and Linkage Editors
5678 \begin_layout Standard
5679 This is retargettable assembler & linkage editor, it was developed by Alan
5681 John Hartman created the version for 8051, and I (Sandeep) have made some
5682 enhancements and bug fixes for it to work properly with SDCC.
5685 \begin_layout Subsection
5689 \begin_layout Standard
5691 \begin_inset LatexCommand \index{s51}
5695 is a free open source simulator developed by Daniel Drotos.
5696 The simulator is built as part of the build process.
5697 For more information visit Daniel's web site at:
5698 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5703 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5707 \begin_layout Subsection
5708 sdcdb - Source Level Debugger
5711 \begin_layout Standard
5713 \begin_inset LatexCommand \index{SDCDB (debugger)}
5717 is the companion source level debugger.
5718 More about SDCDB in section
5719 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5724 The current version of the debugger uses Daniel's Simulator S51
5725 \begin_inset LatexCommand \index{s51}
5729 , but can be easily changed to use other simulators.
5732 \begin_layout Chapter
5736 \begin_layout Section
5740 \begin_layout Subsection
5741 Single Source File Projects
5744 \begin_layout Standard
5745 For single source file 8051 projects the process is very simple.
5746 Compile your programs with the following command
5749 "sdcc sourcefile.c".
5753 This will compile, assemble and link your source file.
5754 Output files are as follows:
5757 \begin_layout Itemize
5759 \begin_inset LatexCommand \index{<file>.asm}
5764 \begin_inset LatexCommand \index{Assembler source}
5768 file created by the compiler
5771 \begin_layout Itemize
5773 \begin_inset LatexCommand \index{<file>.lst}
5778 \begin_inset LatexCommand \index{Assembler listing}
5782 file created by the Assembler
5785 \begin_layout Itemize
5787 \begin_inset LatexCommand \index{<file>.rst}
5792 \begin_inset LatexCommand \index{Assembler listing}
5796 file updated with linkedit information, created by linkage editor
5799 \begin_layout Itemize
5801 \begin_inset LatexCommand \index{<file>.sym}
5806 \begin_inset LatexCommand \index{Symbol listing}
5810 for the sourcefile, created by the assembler
5813 \begin_layout Itemize
5815 \begin_inset LatexCommand \index{<file>.rel}
5820 \begin_inset LatexCommand \index{<file>.o}
5825 \begin_inset LatexCommand \index{Object file}
5829 created by the assembler, input to Linkage editor
5832 \begin_layout Itemize
5834 \begin_inset LatexCommand \index{<file>.map}
5839 \begin_inset LatexCommand \index{Memory map}
5843 for the load module, created by the Linker
5846 \begin_layout Itemize
5848 \begin_inset LatexCommand \index{<file>.mem}
5852 - A file with a summary of the memory usage
5855 \begin_layout Itemize
5857 \begin_inset LatexCommand \index{<file>.ihx}
5861 - The load module in Intel hex format
5862 \begin_inset LatexCommand \index{Intel hex format}
5866 (you can select the Motorola S19 format
5867 \begin_inset LatexCommand \index{Motorola S19 format}
5875 \begin_layout Standard
5885 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5890 If you need another format you might want to use
5897 \begin_inset LatexCommand \index{objdump (tool)}
5908 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5913 \begin_inset Note Note
5916 \begin_layout Standard
5923 \begin_inset LatexCommand \vref{sub:Postprocessing-the-Intel}
5928 Both formats are documented in the documentation of srecord
5929 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5936 \begin_layout Itemize
5938 \begin_inset LatexCommand \index{<file>.adb}
5942 - An intermediate file containing debug information needed to create the
5947 \begin_layout Standard
5957 \begin_inset LatexCommand \index{-\/-debug}
5964 \begin_layout Itemize
5966 \begin_inset LatexCommand \index{<file>.cdb}
5970 - An optional file (with -
5974 \begin_layout Standard
5983 -debug) containing debug information.
5984 The format is documented in cdbfileformat.pdf
5987 \begin_layout Itemize
5990 \begin_inset LatexCommand \index{<file> (no extension)}
5994 An optional AOMF or AOMF51
5995 \begin_inset LatexCommand \index{AOMF, AOMF51}
6000 \begin_inset LatexCommand \label{OMF file}
6004 file containing debug information (generated with option -
6008 \begin_layout Standard
6034 ormat is a subformat of the OMF51 format and is commonly used by third party
6036 \begin_inset LatexCommand \index{Debugger}
6040 , simulators, emulators).
6043 \begin_layout Itemize
6045 \begin_inset LatexCommand \index{<file>.dump*}
6049 - Dump file to debug the compiler it self (generated with option -
6053 \begin_layout Standard
6062 -dumpall) (see section
6063 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
6069 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
6075 \begin_inset Quotes sld
6078 Anatomy of the compiler
6079 \begin_inset Quotes srd
6085 \begin_layout Subsection
6086 Postprocessing the Intel Hex
6087 \begin_inset LatexCommand \index{Intel hex format}
6092 \begin_inset LatexCommand \label{sub:Postprocessing-the-Intel}
6099 \begin_layout Standard
6100 In most cases this won't be needed but the Intel Hex file
6101 \begin_inset LatexCommand \index{<file>.ihx}
6105 which is generated by SDCC might include lines of varying length and the
6106 addresses within the file are not guaranteed to be strictly ascending.
6107 If your toolchain or a bootloader does not like this you can use the tool
6113 \begin_inset LatexCommand \index{packihx (tool)}
6117 which is part of the SDCC distribution:
6124 packihx sourcefile.ihx >sourcefile.hex
6131 The separately available
6136 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6140 package additionally allows to set undefined locations to a predefined
6141 value, to insert checksums
6142 \begin_inset LatexCommand \index{checksum}
6146 of various flavours (crc, add, xor) and to perform other manipulations
6147 (convert, split, crop, offset, ...).
6155 srec_cat\InsetSpace ~
6157 sourcefile.ihx -intel\InsetSpace ~
6159 -o sourcefile.hex -intel
6166 An example for a more complex command line
6170 \begin_layout Standard
6171 the command backfills
6172 \begin_inset LatexCommand \index{backfill unused memory}
6176 unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
6178 If the program counter on an mcs51 runs wild the backfill pattern 0x12
6179 will be interpreted as an
6187 (where an emergency routine could sit).
6200 srec_cat\InsetSpace ~
6201 sourcefile.ihx -intel\InsetSpace ~
6203 -fill 0x12 0x0000 0xfffe\InsetSpace ~
6204 -little-endian-checksum-nega
6205 tive 0xfffe 0x02 0x02\InsetSpace ~
6207 -o sourcefile.hex -intel
6216 The srecord package is available at
6217 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
6224 \begin_layout Subsection
6225 Projects with Multiple Source Files
6228 \begin_layout Standard
6229 SDCC can compile only ONE file at a time.
6230 Let us for example assume that you have a project containing the following
6235 foo1.c (contains some functions)
6237 foo2.c (contains some more functions)
6240 n.c (contains more functions and the function main)
6248 The first two files will need to be compiled separately with the commands:
6280 Then compile the source file containing the
6285 \begin_inset LatexCommand \index{Linker}
6289 the files together with the following command:
6297 foomain.c\InsetSpace ~
6298 foo1.rel\InsetSpace ~
6303 \begin_inset LatexCommand \index{<file>.rel}
6315 can be separately compiled as well:
6326 sdcc foomain.rel foo1.rel foo2.rel
6333 The file containing the
6348 file specified in the command line, since the linkage editor processes
6349 file in the order they are presented to it.
6350 The linker is invoked from SDCC using a script file with extension .lnk
6351 \begin_inset LatexCommand \index{<file>.lnk}
6356 You can view this file to troubleshoot linking problems such as those arising
6357 from missing libraries.
6360 \begin_layout Subsection
6361 Projects with Additional Libraries
6362 \begin_inset LatexCommand \index{Libraries}
6369 \begin_layout Standard
6370 Some reusable routines may be compiled into a library, see the documentation
6371 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6375 \begin_inset LatexCommand \index{<file>.lib}
6382 Libraries created in this manner can be included in the command line.
6383 Make sure you include the -L <library-path> option to tell the linker where
6384 to look for these files if they are not in the current directory.
6385 Here is an example, assuming you have the source file
6397 (if that is not the same as your current project):
6404 sdcc foomain.c foolib.lib -L mylib
6415 must be an absolute path name.
6419 The most efficient way to use libraries is
6420 to keep separate modules in separate source files.
6421 The lib file now should name all the modules.rel
6422 \begin_inset LatexCommand \index{<file>.rel}
6427 For an example see the standard library file
6431 in the directory <installdir>/share/lib/small.
6434 \begin_layout Subsection
6435 Using sdcclib to Create and Manage Libraries
6436 \begin_inset LatexCommand \index{sdcclib}
6443 \begin_layout Standard
6444 Alternatively, instead of having a .rel file for each entry on the library
6445 file as described in the preceding section, sdcclib can be used to embed
6446 all the modules belonging to such library in the library file itself.
6447 This results in a larger library file, but it greatly reduces the number
6448 of disk files accessed by the linker.
6449 Additionally, the packed library file contains an index of all include
6450 modules and symbols that significantly speeds up the linking process.
6451 To display a list of options supported by sdcclib type:
6456 \begin_layout Standard
6461 \begin_inset LatexCommand \index{sdcclib}
6472 To create a new library file, start by compiling all the required modules.
6478 \begin_layout Standard
6485 \begin_layout Standard
6492 \begin_layout Standard
6499 \begin_layout Standard
6506 \begin_layout Standard
6515 \begin_layout Standard
6516 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6518 The next step is to add the .rel files to the library file:
6523 \begin_layout Standard
6527 sdcclib libint.lib _divsint.rel
6530 \begin_inset LatexCommand \index{sdcclib}
6537 \begin_layout Standard
6541 sdcclib libint.lib _divuint.rel
6544 \begin_layout Standard
6548 sdcclib libint.lib _modsint.rel
6551 \begin_layout Standard
6555 sdcclib libint.lib _moduint.rel
6558 \begin_layout Standard
6562 sdcclib libint.lib _mulint.rel
6570 \begin_layout Standard
6579 \begin_layout Standard
6583 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6591 \begin_layout Standard
6592 If the file already exists in the library, it will be replaced.
6593 If a list of .rel files is available, you can tell sdcclib to add those
6595 For example, if the file 'myliblist.txt' contains
6603 \begin_layout Standard
6610 \begin_layout Standard
6617 \begin_layout Standard
6624 \begin_layout Standard
6631 \begin_layout Standard
6643 \begin_layout Standard
6652 \begin_layout Standard
6656 sdcclib -l libint.lib myliblist.txt
6664 \begin_layout Standard
6665 Additionally, you can instruct sdcclib to compiles the files before adding
6666 them to the library.
6667 This is achieved using the environment variables SDCCLIB_CC and/or SDCCLIB_AS.
6676 \begin_layout Standard
6680 set SDCCLIB_CC=sdcc -c
6683 \begin_layout Standard
6687 sdcclib -l libint.lib myliblist.txt
6695 \begin_layout Standard
6696 To see what modules and symbols are included in the library, options -s
6697 and -m are available.
6705 sdcclib -s libint.lib
6708 \begin_inset LatexCommand \index{sdcclib}
6720 \begin_layout Standard
6726 \begin_layout Standard
6732 \begin_layout Standard
6740 \begin_layout Standard
6746 \begin_layout Standard
6752 \begin_layout Standard
6758 \begin_layout Standard
6764 \begin_layout Standard
6772 \begin_layout Standard
6778 \begin_layout Standard
6784 \begin_layout Standard
6792 \begin_layout Standard
6798 \begin_layout Standard
6804 \begin_layout Standard
6810 \begin_layout Standard
6818 \begin_layout Standard
6824 \begin_layout Standard
6835 \begin_layout Standard
6836 If the source files are compiled using -
6840 \begin_layout Standard
6850 \begin_inset LatexCommand \index{-\/-debug}
6854 , the corresponding debug information file .adb will be include in the library
6856 The library files created with sdcclib are plain text files, so they can
6857 be viewed with a text editor.
6858 It is not recomended to modify a library file created with sdcclib using
6859 a text editor, as there are file indexes numbers located accross the file
6860 used by the linker to quickly locate the required module to link.
6861 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6862 it can be safely deleted, since all the information required for linking
6863 is embedded in the library file itself.
6864 Library files created using sdcclib are used as described in the preceding
6866 \begin_inset VSpace bigskip
6872 \begin_layout Section
6873 Command Line Options
6874 \begin_inset LatexCommand \index{Command Line Options}
6879 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6886 \begin_layout Subsection
6887 Processor Selection Options
6888 \begin_inset LatexCommand \index{Options processor selection}
6893 \begin_inset LatexCommand \index{Processor selection options}
6901 \labelwidthstring 00.00.0000
6905 \begin_inset LatexCommand \index{-mmcs51}
6911 Generate code for the Intel MCS51
6912 \begin_inset LatexCommand \index{MCS51}
6916 family of processors.
6917 This is the default processor target.
6921 \labelwidthstring 00.00.0000
6925 \begin_inset LatexCommand \index{-mds390}
6931 Generate code for the Dallas DS80C390
6932 \begin_inset LatexCommand \index{DS80C390}
6940 \labelwidthstring 00.00.0000
6944 \begin_inset LatexCommand \index{-mds400}
6950 Generate code for the Dallas DS80C400
6951 \begin_inset LatexCommand \index{DS80C400}
6959 \labelwidthstring 00.00.0000
6963 \begin_inset LatexCommand \index{-mhc08}
6969 Generate code for the Freescale/Motorola HC08
6970 \begin_inset LatexCommand \index{HC08}
6974 family of processors.
6978 \labelwidthstring 00.00.0000
6982 \begin_inset LatexCommand \index{-mz80}
6988 Generate code for the Zilog Z80
6989 \begin_inset LatexCommand \index{Z80}
6993 family of processors.
6997 \labelwidthstring 00.00.0000
7001 \begin_inset LatexCommand \index{-mgbz80}
7007 Generate code for the GameBoy Z80
7008 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
7012 processor (Not actively maintained).
7016 \labelwidthstring 00.00.0000
7020 \begin_inset LatexCommand \index{-mavr}
7026 Generate code for the Atmel AVR
7027 \begin_inset LatexCommand \index{AVR}
7031 processor (Not maintained, not complete).
7032 AVR users should probably have a look at winavr
7033 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
7038 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
7042 , which is based on AVR-port of the gcc compiler.
7045 \begin_layout Standard
7046 \begin_inset Note Note
7049 \begin_layout Standard
7050 I think it is fair to direct users there for now.
7051 Open source is also about avoiding unnecessary work .
7052 But I didn't find the 'official' link.
7061 \labelwidthstring 00.00.0000
7065 \begin_inset LatexCommand \index{-mpic14}
7071 Generate code for the Microchip PIC 14
7072 \begin_inset LatexCommand \index{PIC14}
7076 -bit processors (p16f84 and variants.
7077 In development, not complete).
7080 \begin_layout Standard
7081 \begin_inset Note Note
7084 \begin_layout Standard
7085 p16f627 p16f628 p16f84 p16f873 p16f877?
7094 \labelwidthstring 00.00.0000
7098 \begin_inset LatexCommand \index{-mpic16}
7104 Generate code for the Microchip PIC 16
7105 \begin_inset LatexCommand \index{PIC16}
7109 -bit processors (p18f452 and variants.
7110 In development, not complete).
7114 \labelwidthstring 00.00.0000
7119 Generate code for the Toshiba TLCS-900H
7120 \begin_inset LatexCommand \index{TLCS-900H}
7124 processor (Not maintained, not complete).
7128 \labelwidthstring 00.00.0000
7132 \begin_inset LatexCommand \index{-mxa51}
7138 Generate code for the Phillips XA51
7139 \begin_inset LatexCommand \index{XA51}
7143 processor (Not maintained, not complete).
7146 \begin_layout Standard
7147 \begin_inset VSpace bigskip
7153 \begin_layout Subsection
7154 Preprocessor Options
7155 \begin_inset LatexCommand \index{Options preprocessor}
7160 \begin_inset LatexCommand \index{Preprocessor options}
7165 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7173 \labelwidthstring 00.00.0000
7177 \begin_inset LatexCommand \index{-I<path>}
7183 The additional location where the preprocessor will look for <..h> or
7184 \begin_inset Quotes eld
7188 \begin_inset Quotes erd
7195 \labelwidthstring 00.00.0000
7199 \begin_inset LatexCommand \index{-D<macro[=value]>}
7205 Command line definition of macros.
7206 Passed to the preprocessor.
7210 \labelwidthstring 00.00.0000
7214 \begin_inset LatexCommand \index{-M}
7220 Tell the preprocessor to output a rule suitable for make describing the
7221 dependencies of each object file.
7222 For each source file, the preprocessor outputs one make-rule whose target
7223 is the object file name for that source file and whose dependencies are
7224 all the files `#include'd in it.
7225 This rule may be a single line or may be continued with `
7227 '-newline if it is long.
7228 The list of rules is printed on standard output instead of the preprocessed
7231 \begin_inset LatexCommand \index{-E}
7239 \labelwidthstring 00.00.0000
7243 \begin_inset LatexCommand \index{-C}
7249 Tell the preprocessor not to discard comments.
7250 Used with the `-E' option.
7254 \labelwidthstring 00.00.0000
7258 \begin_inset LatexCommand \index{-MM}
7269 Like `-M' but the output mentions only the user header files included with
7271 \begin_inset Quotes eld
7275 System header files included with `#include <file>' are omitted.
7279 \labelwidthstring 00.00.0000
7283 \begin_inset LatexCommand \index{-Aquestion(answer)}
7289 Assert the answer answer for question, in case it is tested with a preprocessor
7290 conditional such as `#if #question(answer)'.
7291 `-A-' disables the standard assertions that normally describe the target
7296 \labelwidthstring 00.00.0000
7300 \begin_inset LatexCommand \index{-Umacro}
7306 Undefine macro macro.
7307 `-U' options are evaluated after all `-D' options, but before any `-include'
7308 and `-imacros' options.
7312 \labelwidthstring 00.00.0000
7316 \begin_inset LatexCommand \index{-dM}
7322 Tell the preprocessor to output only a list of the macro definitions that
7323 are in effect at the end of preprocessing.
7324 Used with the `-E' option.
7328 \labelwidthstring 00.00.0000
7332 \begin_inset LatexCommand \index{-dD}
7338 Tell the preprocessor to pass all macro definitions into the output, in
7339 their proper sequence in the rest of the output.
7343 \labelwidthstring 00.00.0000
7347 \begin_inset LatexCommand \index{-dN}
7358 Like `-dD' except that the macro arguments and contents are omitted.
7359 Only `#define name' is included in the output.
7363 \labelwidthstring 00.00.0000
7366 -pedantic-parse-number
7367 \begin_inset LatexCommand \index{pedantic}
7372 \begin_inset LatexCommand \index{-pedantic-parse-number}
7380 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
7388 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7389 and the macro LO_B(3) gets expanded.
7390 See also #pragma pedantic_parse_number
7391 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
7396 \begin_inset LatexCommand \ref{sec:Pragmas}
7402 Note: this functionality is not in conformance with C99 standard!
7406 \labelwidthstring 00.00.0000
7410 preprocessorOption[,preprocessorOption]
7413 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
7418 Pass the preprocessorOption to the preprocessor
7423 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7428 SDCC uses an adapted version of the preprocessor
7432 of the GNU Compiler Collection
7433 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
7442 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7446 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7451 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7458 \begin_layout Standard
7459 \begin_inset VSpace bigskip
7465 \begin_layout Subsection
7467 \begin_inset LatexCommand \index{Options linker}
7472 \begin_inset LatexCommand \index{Linker options}
7480 \labelwidthstring 00.00.0000
7490 \begin_layout Standard
7502 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7507 \begin_inset LatexCommand \index{-L -\/-lib-path}
7514 <absolute path to additional libraries> This option is passed to the linkage
7515 editor's additional libraries
7516 \begin_inset LatexCommand \index{Libraries}
7521 The path name must be absolute.
7522 Additional library files may be specified in the command line.
7523 See section Compiling programs for more details.
7527 \labelwidthstring 00.00.0000
7534 \begin_layout Standard
7546 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7551 <Value> The start location of the external ram
7552 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7556 , default value is 0.
7557 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7561 \begin_layout Standard
7570 -xram-loc 0x8000 or -
7574 \begin_layout Standard
7587 \labelwidthstring 00.00.0000
7594 \begin_layout Standard
7606 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7611 <Value> The start location of the code
7612 \begin_inset LatexCommand \index{code}
7616 segment, default value 0.
7617 Note when this option is used the interrupt vector table
7618 \begin_inset LatexCommand \index{interrupt vector table}
7622 is also relocated to the given address.
7623 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7627 \begin_layout Standard
7636 -code-loc 0x8000 or -
7640 \begin_layout Standard
7653 \labelwidthstring 00.00.0000
7660 \begin_layout Standard
7672 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7677 <Value> By default the stack
7678 \begin_inset LatexCommand \index{stack}
7682 is placed after the data segment.
7683 Using this option the stack can be placed anywhere in the internal memory
7685 The value entered can be in Hexadecimal or Decimal format, e.g.
7690 \begin_layout Standard
7699 -stack-loc 0x20 or -
7703 \begin_layout Standard
7713 Since the sp register is incremented before a push or call, the initial
7714 sp will be set to one byte prior the provided value.
7715 The provided value should not overlap any other memory areas such as used
7716 register banks or the data segment and with enough space for the current
7724 \begin_layout Standard
7737 \begin_inset LatexCommand \index{-\/-pack-iram}
7741 option (which is now a default setting) will override this setting, so
7742 you should also specify the
7748 \begin_layout Standard
7761 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7765 option if you need to manually place the stack.
7769 \labelwidthstring 00.00.0000
7776 \begin_layout Standard
7788 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7793 <Value> By default the external stack
7794 \begin_inset LatexCommand \index{xstack}
7798 is placed after the pdata
7799 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7804 Using this option the xstack can be placed anywhere in the external memory
7806 The value entered can be in Hexadecimal or Decimal format, e.g.
7811 \begin_layout Standard
7820 -xstack-loc 0x8000 or -
7824 \begin_layout Standard
7834 The provided value should not overlap any other memory areas such as the
7835 pdata or xdata segment and with enough space for the current application.
7839 \labelwidthstring 00.00.0000
7846 \begin_layout Standard
7858 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7863 <Value> The start location of the internal ram data
7864 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7869 The value entered can be in Hexadecimal or Decimal format, eg.
7874 \begin_layout Standard
7887 \begin_layout Standard
7897 (By default, the start location of the internal ram data segment is set
7898 as low as possible in memory, taking into account the used register banks
7899 and the bit segment at address 0x20.
7900 For example if register banks 0 and 1 are used without bit variables, the
7901 data segment will be set, if -
7905 \begin_layout Standard
7914 -data-loc is not used, to location 0x10.)
7918 \labelwidthstring 00.00.0000
7925 \begin_layout Standard
7937 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7942 <Value> The start location of the indirectly addressable internal ram
7943 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7947 of the 8051, default value is 0x80.
7948 The value entered can be in Hexadecimal or Decimal format, eg.
7953 \begin_layout Standard
7962 -idata-loc 0x88 or -
7966 \begin_layout Standard
7979 \labelwidthstring 00.00.0000
7986 \begin_layout Standard
7998 <Value> The start location of the bit
7999 \begin_inset LatexCommand \index{bit}
8003 addressable internal ram of the 8051.
8009 Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
8014 \labelwidthstring 00.00.0000
8021 \begin_layout Standard
8031 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
8040 The linker output (final object code) is in Intel Hex format.
8041 \begin_inset LatexCommand \index{Intel hex format}
8045 This is the default option.
8046 The format itself is documented in the documentation of srecord
8047 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
8055 \labelwidthstring 00.00.0000
8062 \begin_layout Standard
8072 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
8081 The linker output (final object code) is in Motorola S19 format
8082 \begin_inset LatexCommand \index{Motorola S19 format}
8087 The format itself is documented in the documentation of srecord.
8091 \labelwidthstring 00.00.0000
8098 \begin_layout Standard
8108 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
8113 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
8122 The linker output (final object code) is in ELF format
8123 \begin_inset LatexCommand \index{ELF format}
8128 (Currently only supported for the HC08
8129 \begin_inset LatexCommand \index{HC08}
8137 \labelwidthstring 00.00.0000
8141 linkOption[,linkOption]
8144 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
8149 \begin_inset LatexCommand \label{lyx:-Wl option}
8154 Pass the linkOption to the linker.
8155 If a bootloader is used an option like
8156 \begin_inset Quotes sld
8161 \begin_inset Quotes srd
8164 would be typical to set the start of the code segment.
8165 Either use the double quotes around this option or use no space (e.g.
8167 See also #pragma constseg and #pragma codeseg in section
8168 \begin_inset LatexCommand \ref{sec:Pragmas}
8173 File sdcc/as/doc/asxhtm.html has more on linker options.
8176 \begin_layout Standard
8177 \begin_inset VSpace bigskip
8183 \begin_layout Subsection
8185 \begin_inset LatexCommand \index{Options MCS51}
8190 \begin_inset LatexCommand \index{MCS51 options}
8198 \labelwidthstring 00.00.0000
8205 \begin_layout Standard
8215 \begin_inset LatexCommand \index{-\/-model-small}
8226 Generate code for Small Model programs, see section Memory Models for more
8228 This is the default model.
8232 \labelwidthstring 00.00.0000
8239 \begin_layout Standard
8249 \begin_inset LatexCommand \index{-\/-model-medium}
8255 Generate code for Medium model programs, see section Memory Models for
8257 If this option is used all source files in the project have to be compiled
8259 It must also be used when invoking the linker.
8263 \labelwidthstring 00.00.0000
8270 \begin_layout Standard
8280 \begin_inset LatexCommand \index{-\/-model-large}
8286 Generate code for Large model programs, see section Memory Models for more
8288 If this option is used all source files in the project have to be compiled
8290 It must also be used when invoking the linker.
8294 \labelwidthstring 00.00.0000
8301 \begin_layout Standard
8311 \begin_inset LatexCommand \index{-\/-xstack}
8317 Uses a pseudo stack in the pdata
8318 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8322 area (usually the first 256 bytes in the external ram) for allocating variables
8323 and passing parameters.
8325 \begin_inset LatexCommand \ref{sub:External-Stack}
8330 External Stack for more details.
8334 \labelwidthstring 00.00.0000
8341 \begin_layout Standard
8354 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
8358 Causes the linker to check if the internal ram usage is within limits of
8363 \labelwidthstring 00.00.0000
8370 \begin_layout Standard
8383 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
8387 Causes the linker to check if the external ram usage is within limits of
8392 \labelwidthstring 00.00.0000
8399 \begin_layout Standard
8412 \begin_inset LatexCommand \index{-\/-code-size <Value>}
8416 Causes the linker to check if the code memory usage is within limits of
8421 \labelwidthstring 00.00.0000
8428 \begin_layout Standard
8441 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8445 Causes the linker to check if there is at minimum <Value> bytes for stack.
8449 \labelwidthstring 00.00.0000
8456 \begin_layout Standard
8469 \begin_inset LatexCommand \index{-\/-pack-iram}
8473 Causes the linker to use unused register banks for data variables and pack
8474 data, idata and stack together.
8475 This is the default now.
8479 \labelwidthstring 00.00.0000
8486 \begin_layout Standard
8499 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8503 Causes the linker to use old style for allocating memory areas.
8507 \labelwidthstring 00.00.0000
8514 \begin_layout Standard
8527 \begin_inset LatexCommand \index{-\/-acall-ajmp}
8531 Replaces the three byte instructions lcall/ljmp with the two byte instructions
8533 Only use this option if your code is in the same 2k block of memory.
8534 You may need to use this option for some 8051 derivatives which lack the
8535 lcall/ljmp instructions..
8538 \begin_layout Standard
8539 \begin_inset VSpace bigskip
8545 \begin_layout Subsection
8546 DS390 / DS400 Options
8547 \begin_inset LatexCommand \index{Options DS390}
8552 \begin_inset LatexCommand \index{DS390}
8560 \labelwidthstring 00.00.0000
8567 \begin_layout Standard
8579 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8589 Generate 24-bit flat mode code.
8590 This is the one and only that the ds390 code generator supports right now
8591 and is default when using
8596 See section Memory Models for more details.
8600 \labelwidthstring 00.00.0000
8607 \begin_layout Standard
8617 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8623 disable interrupts during ESP:SP updates.
8627 \labelwidthstring 00.00.0000
8634 \begin_layout Standard
8646 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8650 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8651 This is the one and only that the ds390 code generator supports right now
8652 and is default when using
8657 In this mode, the stack is located in the lower 1K of the internal RAM,
8658 which is mapped to 0x400000.
8659 Note that the support is incomplete, since it still uses a single byte
8660 as the stack pointer.
8661 This means that only the lower 256 bytes of the potential 1K stack space
8662 will actually be used.
8663 However, this does allow you to reclaim the precious 256 bytes of low RAM
8664 for use for the DATA and IDATA segments.
8665 The compiler will not generate any code to put the processor into 10 bit
8667 It is important to ensure that the processor is in this mode before calling
8668 any re-entrant functions compiled with this option.
8669 In principle, this should work with the
8675 \begin_layout Standard
8685 \begin_inset LatexCommand \index{-\/-stack-auto}
8691 option, but that has not been tested.
8692 It is incompatible with the
8698 \begin_layout Standard
8708 \begin_inset LatexCommand \index{-\/-xstack}
8715 It also only makes sense if the processor is in 24 bit contiguous addressing
8722 \begin_layout Standard
8731 -model-flat24 option
8736 \begin_inset Note Note
8740 \labelwidthstring 00.00.0000
8747 \begin_layout Standard
8756 -stack-8-bit - switches off the 10-bit mode
8765 \labelwidthstring 00.00.0000
8772 \begin_layout Standard
8782 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8788 insert call to function __stack_probe at each function prologue.
8792 \labelwidthstring 00.00.0000
8799 \begin_layout Standard
8809 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8815 <nnnn> LibraryID used in -mTININative.
8820 \labelwidthstring 00.00.0000
8827 \begin_layout Standard
8837 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8843 generate code for DS390 Arithmetic Accelerator.
8847 \begin_layout Standard
8848 \begin_inset VSpace bigskip
8854 \begin_layout Subsection
8856 \begin_inset LatexCommand \index{Options Z80}
8861 \begin_inset LatexCommand \index{Z80}
8869 \labelwidthstring 00.00.0000
8876 \begin_layout Standard
8888 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8898 Force a called function to always save BC.
8902 \labelwidthstring 00.00.0000
8909 \begin_layout Standard
8921 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8925 When linking, skip the standard crt0.o object file.
8926 You must provide your own crt0.o for your system when linking.
8930 \labelwidthstring 00.00.0000
8937 \begin_layout Standard
8949 \begin_inset LatexCommand \index{Z80!Options!-\/-portmode=<Value>}
8953 Determinate PORT I/O mode (<Value> is z80 or z180).
8957 \labelwidthstring 00.00.0000
8964 \begin_layout Standard
8976 \begin_inset LatexCommand \index{Z80!Options!-\/-asm=<Value>}
8980 Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
8984 \labelwidthstring 00.00.0000
8991 \begin_layout Standard
9004 \begin_inset LatexCommand \index{Z80!Options!-\/-codeseg <Value>}
9008 Use <Value> for the code segment name.
9012 \labelwidthstring 00.00.0000
9019 \begin_layout Standard
9032 \begin_inset LatexCommand \index{Z80!Options!-\/-constseg <Value>}
9036 Use <Value> for the const segment name.
9040 \labelwidthstring 00.00.0000
9041 \begin_inset VSpace bigskip
9047 \begin_layout Subsection
9049 \begin_inset LatexCommand \index{Options GBZ80}
9054 \begin_inset LatexCommand \index{GBZ80}
9062 \labelwidthstring 00.00.0000
9069 \begin_layout Standard
9081 \begin_inset LatexCommand \index{GBZ80!Options!-\/-callee-saves-bc}
9091 Force a called function to always save BC.
9095 \labelwidthstring 00.00.0000
9102 \begin_layout Standard
9114 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
9118 When linking, skip the standard crt0.o object file.
9119 You must provide your own crt0.o for your system when linking.
9123 \labelwidthstring 00.00.0000
9130 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
9134 Use code bank <Num>.
9138 \labelwidthstring 00.00.0000
9145 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
9149 Use data bank <Num>.
9153 \labelwidthstring 00.00.0000
9160 \begin_layout Standard
9173 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
9177 Use <Value> for the code segment name.
9181 \labelwidthstring 00.00.0000
9188 \begin_layout Standard
9201 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
9205 Use <Value> for the const segment name.
9208 \begin_layout Standard
9209 \begin_inset VSpace bigskip
9215 \begin_layout Subsection
9216 Optimization Options
9217 \begin_inset LatexCommand \index{Options optimization}
9222 \begin_inset LatexCommand \index{Optimization options}
9230 \labelwidthstring 00.00.0000
9237 \begin_layout Standard
9247 \begin_inset LatexCommand \index{-\/-nogcse}
9253 Will not do global subexpression elimination, this option may be used when
9254 the compiler creates undesirably large stack/data spaces to store compiler
9264 \begin_inset LatexCommand \index{sloc (spill location)}
9269 A warning message will be generated when this happens and the compiler
9270 will indicate the number of extra bytes it allocated.
9271 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9273 \begin_inset LatexCommand \index{\#pragma nogcse}
9277 can be used to turn off global subexpression elimination
9278 \begin_inset LatexCommand \index{Subexpression elimination}
9282 for a given function only.
9286 \labelwidthstring 00.00.0000
9293 \begin_layout Standard
9303 \begin_inset LatexCommand \index{-\/-noinvariant}
9309 Will not do loop invariant optimizations, this may be turned off for reasons
9310 explained for the previous option.
9311 For more details of loop optimizations performed see Loop Invariants in
9313 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
9318 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9320 \begin_inset LatexCommand \index{\#pragma noinvariant}
9324 can be used to turn off invariant optimizations for a given function only.
9328 \labelwidthstring 00.00.0000
9335 \begin_layout Standard
9345 \begin_inset LatexCommand \index{-\/-noinduction}
9351 Will not do loop induction optimizations, see section strength reduction
9353 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9355 \begin_inset LatexCommand \index{\#pragma noinduction}
9359 can be used to turn off induction optimizations for a given function only.
9363 \labelwidthstring 00.00.0000
9370 \begin_layout Standard
9380 \begin_inset LatexCommand \index{-\/-nojtbound}
9391 Will not generate boundary condition check when switch statements
9392 \begin_inset LatexCommand \index{switch statement}
9396 are implemented using jump-tables.
9398 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
9403 Switch Statements for more details.
9404 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9406 \begin_inset LatexCommand \index{\#pragma nojtbound}
9410 can be used to turn off boundary checking for jump tables for a given function
9415 \labelwidthstring 00.00.0000
9422 \begin_layout Standard
9432 \begin_inset LatexCommand \index{-\/-noloopreverse}
9441 Will not do loop reversal
9442 \begin_inset LatexCommand \index{Loop reversing}
9450 \labelwidthstring 00.00.0000
9455 \begin_layout Standard
9469 \begin_inset LatexCommand \index{-\/-nolabelopt }
9473 Will not optimize labels (makes the dumpfiles more readable).
9477 \labelwidthstring 00.00.0000
9484 \begin_layout Standard
9494 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9500 Will not memcpy initialized data from code space into xdata space.
9501 This saves a few bytes in code space if you don't have initialized data
9502 \begin_inset LatexCommand \index{Variable initialization}
9510 \labelwidthstring 00.00.0000
9517 \begin_layout Standard
9527 \begin_inset LatexCommand \index{-\/-nooverlay}
9533 The compiler will not overlay parameters and local variables of any function,
9534 see section Parameters and local variables for more details.
9538 \labelwidthstring 00.00.0000
9545 \begin_layout Standard
9555 \begin_inset LatexCommand \index{-\/-no-peep}
9561 Disable peep-hole optimization with built-in rules.
9565 \labelwidthstring 00.00.0000
9572 \begin_layout Standard
9584 \begin_inset LatexCommand \index{-\/-peep-file}
9589 <filename> This option can be used to use additional rules to be used by
9590 the peep hole optimizer.
9592 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9597 Peep Hole optimizations for details on how to write these rules.
9601 \labelwidthstring 00.00.0000
9608 \begin_layout Standard
9618 \begin_inset LatexCommand \index{-\/-peep-asm}
9624 Pass the inline assembler code through the peep hole optimizer.
9625 This can cause unexpected changes to inline assembler code, please go through
9626 the peephole optimizer
9627 \begin_inset LatexCommand \index{Peephole optimizer}
9631 rules defined in the source file tree '<target>/peeph.def' before using
9636 \labelwidthstring 00.00.0000
9643 \begin_layout Standard
9653 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9659 The compiler will optimize code generation towards fast code, possibly
9660 at the expense of code size.
9664 \labelwidthstring 00.00.0000
9671 \begin_layout Standard
9681 \begin_inset LatexCommand \index{-\/-opt-code-size}
9687 The compiler will optimize code generation towards compact code, possibly
9688 at the expense of code speed.
9691 \begin_layout Standard
9692 \begin_inset VSpace bigskip
9698 \begin_layout Subsection
9700 \begin_inset LatexCommand \index{Options other}
9708 \labelwidthstring 00.00.0000
9716 \begin_layout Standard
9726 \begin_inset LatexCommand \index{-\/-compile-only}
9731 \begin_inset LatexCommand \index{-c -\/-compile-only}
9737 will compile and assemble the source, but will not call the linkage editor.
9741 \labelwidthstring 00.00.0000
9750 \begin_layout Standard
9762 \begin_inset LatexCommand \index{-\/-c1mode}
9768 reads the preprocessed source from standard input and compiles it.
9769 The file name for the assembler output must be specified using the -o option.
9773 \labelwidthstring 00.00.0000
9777 \begin_inset LatexCommand \index{-E}
9783 Run only the C preprocessor.
9784 Preprocess all the C source files specified and output the results to standard
9789 \labelwidthstring 00.00.0000
9794 \begin_inset LatexCommand \index{-o <path/file>}
9800 The output path where everything will be placed or the file name used for
9801 all generated output files.
9802 If the parameter is a path, it must have a trailing slash (or backslash
9803 for the Windows binaries) to be recognized as a path.
9808 Note for Windows users: if the path contains spaces, it should be surrounded
9810 The trailing backslash should be doubled in order to prevent escaping the
9811 final quote, for example:
9814 \begin_inset Quotes sld
9828 \begin_inset Quotes srd
9833 or put after the final quote, for example:
9836 \begin_inset Quotes sld
9846 \begin_inset Quotes srd
9854 The path using slashes for directory delimiters can be used too, for example:
9858 \begin_inset Quotes sld
9861 F:/Projects/test3/output 1/
9862 \begin_inset Quotes srd
9871 \labelwidthstring 00.00.0000
9878 \begin_layout Standard
9888 \begin_inset LatexCommand \index{-\/-stack-auto}
9899 All functions in the source file will be compiled as
9904 \begin_inset LatexCommand \index{reentrant}
9909 the parameters and local variables will be allocated on the stack
9910 \begin_inset LatexCommand \index{stack}
9916 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9920 Parameters and Local Variables for more details.
9921 If this option is used all source files in the project should be compiled
9923 It automatically implies -
9929 \begin_layout Standard
9940 -int-long-reent and -
9946 \begin_layout Standard
9962 \labelwidthstring 00.00.0000
9969 \begin_layout Standard
9979 \begin_inset LatexCommand \index{-\/-callee-saves}
9984 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9988 function1[,function2][,function3]....
9991 The compiler by default uses a caller saves convention for register saving
9992 across function calls, however this can cause unnecessary register pushing
9993 and popping when calling small functions from larger functions.
9994 This option can be used to switch the register saving convention for the
9995 function names specified.
9996 The compiler will not save registers when calling these functions, no extra
9997 code will be generated at the entry and exit (function prologue
10000 \begin_inset LatexCommand \index{function prologue}
10009 \begin_inset LatexCommand \index{function epilogue}
10015 ) for these functions to save and restore the registers used by these functions,
10016 this can SUBSTANTIALLY reduce code and improve run time performance of
10017 the generated code.
10018 In the future the compiler (with inter procedural analysis) will be able
10019 to determine the appropriate scheme to use for each function call.
10020 DO NOT use this option for built-in functions such as _mulint..., if this
10021 option is used for a library function the appropriate library function
10022 needs to be recompiled with the same option.
10023 If the project consists of multiple source files then all the source file
10024 should be compiled with the same -
10028 \begin_layout Standard
10037 -callee-saves option string.
10038 Also see #pragma\InsetSpace ~
10040 \begin_inset LatexCommand \index{\#pragma callee\_saves}
10045 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
10053 \labelwidthstring 00.00.0000
10060 \begin_layout Standard
10070 \begin_inset LatexCommand \index{-\/-all-callee-saves}
10084 \begin_layout Standard
10093 -callee-saves will be applied to all functions by default.
10097 \labelwidthstring 00.00.0000
10104 \begin_layout Standard
10114 \begin_inset LatexCommand \index{-\/-debug}
10123 When this option is used the compiler will generate debug information.
10124 The debug information collected in a file with .cdb extension can be used
10126 For more information see documentation for SDCDB.
10127 Another file with no extension contains debug information in AOMF or AOMF51
10128 \begin_inset LatexCommand \index{AOMF, AOMF51}
10132 format which is commonly used by third party tools.
10136 \labelwidthstring 00.00.0000
10140 \begin_inset LatexCommand \index{-S}
10151 Stop after the stage of compilation proper; do not assemble.
10152 The output is an assembler code file for the input file specified.
10156 \labelwidthstring 00.00.0000
10163 \begin_layout Standard
10173 \begin_inset LatexCommand \index{-\/-int-long-reent}
10179 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
10180 Note by default these libraries are compiled as non-reentrant.
10181 See section Installation for more details.
10185 \labelwidthstring 00.00.0000
10192 \begin_layout Standard
10202 \begin_inset LatexCommand \index{-\/-cyclomatic}
10211 This option will cause the compiler to generate an information message for
10212 each function in the source file.
10213 The message contains some
10217 information about the function.
10218 The number of edges and nodes the compiler detected in the control flow
10219 graph of the function, and most importantly the
10221 cyclomatic complexity
10222 \begin_inset LatexCommand \index{Cyclomatic complexity}
10228 see section on Cyclomatic Complexity for more details.
10232 \labelwidthstring 00.00.0000
10239 \begin_layout Standard
10249 \begin_inset LatexCommand \index{-\/-float-reent}
10255 Floating point library is compiled as reentrant
10256 \begin_inset LatexCommand \index{reentrant}
10261 See section Installation for more details.
10265 \labelwidthstring 00.00.0000
10272 \begin_layout Standard
10282 \begin_inset LatexCommand \index{-\/-funsigned-char}
10288 The default signedness for every type is
10293 In some embedded environments the default signedness of
10302 To set the signess for characters to unsigned, use the option -
10308 \begin_layout Standard
10320 If this option is set and no signedness keyword (unsigned/signed) is given,
10321 a char will be signed.
10322 All other types are unaffected.
10326 \labelwidthstring 00.00.0000
10333 \begin_layout Standard
10343 \begin_inset LatexCommand \index{-\/-main-return}
10349 This option can be used if the code generated is called by a monitor program
10350 or if the main routine includes an endless loop.
10351 This option results in slightly smaller code and saves two bytes of stack
10353 The return from the 'main'
10354 \begin_inset LatexCommand \index{main return}
10358 function will return to the function calling main.
10359 The default setting is to lock up i.e.
10368 \labelwidthstring 00.00.0000
10375 \begin_layout Standard
10385 \begin_inset LatexCommand \index{-\/-nostdinc}
10391 This will prevent the compiler from passing on the default include path
10392 to the preprocessor.
10396 \labelwidthstring 00.00.0000
10403 \begin_layout Standard
10413 \begin_inset LatexCommand \index{-\/-nostdlib}
10419 This will prevent the compiler from passing on the default library
10420 \begin_inset LatexCommand \index{Libraries}
10424 path to the linker.
10428 \labelwidthstring 00.00.0000
10435 \begin_layout Standard
10445 \begin_inset LatexCommand \index{-\/-verbose}
10451 Shows the various actions the compiler is performing.
10455 \labelwidthstring 00.00.0000
10459 \begin_inset LatexCommand \index{-V}
10465 Shows the actual commands the compiler is executing.
10469 \labelwidthstring 00.00.0000
10476 \begin_layout Standard
10486 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
10492 Hides your ugly and inefficient c-code from the asm file, so you can always
10493 blame the compiler :)
10497 \labelwidthstring 00.00.0000
10504 \begin_layout Standard
10514 \begin_inset LatexCommand \index{-\/-no-gen-comments}
10520 Include code generator and peep-hole comments in the generated asm files.
10524 \labelwidthstring 00.00.0000
10531 \begin_layout Standard
10541 \begin_inset LatexCommand \index{-\/-no-peep-comments}
10547 Don't include peep-hole comments in the generated asm files even if -
10553 \begin_layout Standard
10564 -fverbose-asm option is specified.
10568 \labelwidthstring 00.00.0000
10575 \begin_layout Standard
10585 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10591 Include i-codes in the asm file.
10592 Sounds like noise but is most helpful for debugging the compiler itself.
10596 \labelwidthstring 00.00.0000
10603 \begin_layout Standard
10613 \begin_inset LatexCommand \index{pedantic}
10618 \begin_inset LatexCommand \index{-\/-less-pedantic}
10625 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10629 Disable some of the more pedantic warnings
10630 \begin_inset LatexCommand \index{Warnings}
10635 For more details, see the less_pedantic pragma
10636 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10644 \labelwidthstring 00.00.0000
10651 \begin_layout Standard
10660 -disable-warning\InsetSpace ~
10662 \begin_inset LatexCommand \index{-\/-disable-warning}
10668 Disable specific warning with number <nnnn>.
10672 \labelwidthstring 00.00.0000
10679 \begin_layout Standard
10689 \begin_inset LatexCommand \index{-\/-Werror}
10695 Treat all warnings as errors.
10699 \labelwidthstring 00.00.0000
10706 \begin_layout Standard
10716 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10722 Display the directories in the compiler's search path
10726 \labelwidthstring 00.00.0000
10733 \begin_layout Standard
10743 \begin_inset LatexCommand \index{-\/-vc}
10749 Display errors and warnings using MSVC style, so you can use SDCC with
10750 the visual studio IDE
10751 \begin_inset LatexCommand \index{IDE}
10756 With SDCC both offering a GCC-like (the default) and a MSVC-like
10757 \begin_inset LatexCommand \index{MSVC output style}
10761 output style, integration into most programming editors should be straightforwa
10766 \labelwidthstring 00.00.0000
10773 \begin_layout Standard
10783 \begin_inset LatexCommand \index{-\/-use-stdout}
10789 Send errors and warnings to stdout instead of stderr.
10793 \labelwidthstring 00.00.0000
10797 asmOption[,asmOption]
10800 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10805 Pass the asmOption to the assembler
10806 \begin_inset LatexCommand \index{Options assembler}
10811 \begin_inset LatexCommand \index{Assembler options}
10816 See file sdcc/as/doc/asxhtm.html for assembler options.cd
10820 \labelwidthstring 00.00.0000
10827 \begin_layout Standard
10837 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10843 Generally follow the C89 standard, but allow SDCC features that conflict
10844 with the standard (default).
10848 \labelwidthstring 00.00.0000
10855 \begin_layout Standard
10865 \begin_inset LatexCommand \index{-\/-std-c89}
10871 Follow the C89 standard and disable SDCC features that conflict with the
10876 \labelwidthstring 00.00.0000
10883 \begin_layout Standard
10893 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10899 Generally follow the C99 standard, but allow SDCC features that conflict
10900 with the standard (incomplete support).
10904 \labelwidthstring 00.00.0000
10911 \begin_layout Standard
10921 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10927 Follow the C99 standard and disable SDCC features that conflict with the
10928 standard (incomplete support).
10932 \labelwidthstring 00.00.0000
10939 \begin_layout Standard
10951 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10956 \begin_inset LatexCommand \label{lyx:-codeseg}
10961 <Name> The name to be used for the code
10962 \begin_inset LatexCommand \index{code}
10966 segment, default CSEG.
10967 This is useful if you need to tell the compiler to put the code in a special
10968 segment so you can later on tell the linker to put this segment in a special
10970 Can be used for instance when using bank switching to put the code in a
10975 \labelwidthstring 00.00.0000
10982 \begin_layout Standard
10994 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10999 <Name> The name to be used for the const
11000 \begin_inset LatexCommand \index{const}
11004 segment, default CONST.
11005 This is useful if you need to tell the compiler to put the const data in
11006 a special segment so you can later on tell the linker to put this segment
11007 in a special place in memory.
11008 Can be used for instance when using bank switching to put the const data
11013 \labelwidthstring 00.00.0000
11020 \begin_layout Standard
11029 -fdollars-in-identifiers
11030 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
11036 Permit '$' as an identifier character.
11040 \labelwidthstring 00.00.0000
11047 \begin_layout Standard
11059 \begin_inset LatexCommand \index{-\/-more-pedantic}
11064 \begin_inset LatexCommand \index{pedantic}
11074 a SDCC compiler option but if you want
11078 warnings you can use a separate tool dedicated to syntax checking like
11080 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
11085 \begin_inset LatexCommand \index{lint (syntax checking tool)}
11090 \begin_inset LatexCommand \url{http://www.splint.org}
11095 To make your source files parseable by splint you will have to include
11101 \begin_inset LatexCommand \index{splint (syntax checking tool)}
11105 in your source file and add brackets around extended keywords (like
11108 \begin_inset Quotes sld
11121 \begin_inset Quotes srd
11129 \begin_inset Quotes sld
11132 __interrupt\InsetSpace ~
11134 \begin_inset Quotes srd
11142 Splint has an excellent on line manual at
11143 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
11147 and it's capabilities go beyond pure syntax checking.
11148 You'll need to tell splint the location of SDCC's include files so a typical
11149 command line could look like this:
11153 splint\InsetSpace ~
11155 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
11161 \labelwidthstring 00.00.0000
11168 \begin_layout Standard
11180 \begin_inset LatexCommand \index{-\/-short-is-8bits}
11185 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
11189 Treat short as 8-bit (for backward compatibility with older versions of
11190 compiler - see section
11191 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
11198 \begin_layout Standard
11199 \begin_inset VSpace bigskip
11205 \begin_layout Subsection
11206 Intermediate Dump Options
11207 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
11212 \begin_inset LatexCommand \index{Options intermediate dump}
11217 \begin_inset LatexCommand \index{Intermediate dump options}
11224 \begin_layout Standard
11225 The following options are provided for the purpose of retargetting and debugging
11227 They provide a means to dump the intermediate code (iCode
11228 \begin_inset LatexCommand \index{iCode}
11232 ) generated by the compiler in human readable form at various stages of
11233 the compilation process.
11234 More on iCodes see chapter
11235 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
11240 \begin_inset Quotes srd
11243 The anatomy of the compiler
11244 \begin_inset Quotes srd
11251 \labelwidthstring 00.00.0000
11258 \begin_layout Standard
11268 \begin_inset LatexCommand \index{-\/-dumpraw}
11274 This option will cause the compiler to dump the intermediate code into
11277 <source filename>.dumpraw
11279 just after the intermediate code has been generated for a function, i.e.
11280 before any optimizations are done.
11282 \begin_inset LatexCommand \index{Basic blocks}
11286 at this stage ordered in the depth first number, so they may not be in
11287 sequence of execution.
11291 \labelwidthstring 00.00.0000
11298 \begin_layout Standard
11308 \begin_inset LatexCommand \index{-\/-dumpgcse}
11314 Will create a dump of iCodes, after global subexpression elimination
11315 \begin_inset LatexCommand \index{Global subexpression elimination}
11319 , into a file named
11321 <source filename>.dumpgcse.
11325 \labelwidthstring 00.00.0000
11332 \begin_layout Standard
11342 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
11348 Will create a dump of iCodes, after deadcode elimination
11349 \begin_inset LatexCommand \index{Dead-code elimination}
11353 , into a file named
11355 <source filename>.dumpdeadcode.
11359 \labelwidthstring 00.00.0000
11366 \begin_layout Standard
11376 \begin_inset LatexCommand \index{-\/-dumploop}
11385 Will create a dump of iCodes, after loop optimizations
11386 \begin_inset LatexCommand \index{Loop optimization}
11390 , into a file named
11392 <source filename>.dumploop.
11396 \labelwidthstring 00.00.0000
11403 \begin_layout Standard
11413 \begin_inset LatexCommand \index{-\/-dumprange}
11422 Will create a dump of iCodes, after live range analysis
11423 \begin_inset LatexCommand \index{Live range analysis}
11427 , into a file named
11429 <source filename>.dumprange.
11433 \labelwidthstring 00.00.0000
11440 \begin_layout Standard
11450 \begin_inset LatexCommand \index{-\/-dumlrange}
11456 Will dump the life ranges
11457 \begin_inset LatexCommand \index{Live range analysis}
11465 \labelwidthstring 00.00.0000
11472 \begin_layout Standard
11482 \begin_inset LatexCommand \index{-\/-dumpregassign}
11491 Will create a dump of iCodes, after register assignment
11492 \begin_inset LatexCommand \index{Register assignment}
11496 , into a file named
11498 <source filename>.dumprassgn.
11502 \labelwidthstring 00.00.0000
11509 \begin_layout Standard
11519 \begin_inset LatexCommand \index{-\/-dumplrange}
11525 Will create a dump of the live ranges of iTemp's
11529 \labelwidthstring 00.00.0000
11536 \begin_layout Standard
11546 \begin_inset LatexCommand \index{-\/-dumpall}
11557 Will cause all the above mentioned dumps to be created.
11560 \begin_layout Standard
11561 \begin_inset VSpace bigskip
11567 \begin_layout Subsection
11568 Redirecting output on Windows Shells
11571 \begin_layout Standard
11572 By default SDCC writes its error messages to
11573 \begin_inset Quotes sld
11577 \begin_inset Quotes srd
11581 To force all messages to
11582 \begin_inset Quotes sld
11586 \begin_inset Quotes srd
11598 \begin_layout Standard
11613 \begin_inset LatexCommand \index{-\/-use-stdout}
11618 Additionally, if you happen to have visual studio installed in your windows
11619 machine, you can use it to compile your sources using a custom build and
11626 \begin_layout Standard
11638 \begin_inset LatexCommand \index{-\/-vc}
11643 Something like this should work:
11662 \begin_layout Standard
11681 \begin_layout Standard
11693 -model-large -c $(InputPath)
11696 \begin_inset VSpace bigskip
11702 \begin_layout Section
11703 Environment variables
11704 \begin_inset LatexCommand \index{Environment variables}
11711 \begin_layout Standard
11712 SDCC recognizes the following environment variables:
11716 \labelwidthstring 00.00.0000
11720 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11726 SDCC installs a signal handler
11727 \begin_inset LatexCommand \index{signal handler}
11731 to be able to delete temporary files after an user break (^C) or an exception.
11732 If this environment variable is set, SDCC won't install the signal handler
11733 in order to be able to debug SDCC.
11737 \labelwidthstring 00.00.0000
11743 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11749 Path, where temporary files will be created.
11750 The order of the variables is the search order.
11751 In a standard *nix environment these variables are not set, and there's
11752 no need to set them.
11753 On Windows it's recommended to set one of them.
11757 \labelwidthstring 00.00.0000
11761 \begin_inset LatexCommand \index{SDCC\_HOME}
11768 \begin_inset LatexCommand \ref{sub:Install-paths}
11774 \begin_inset Quotes sld
11778 \begin_inset Quotes srd
11785 \labelwidthstring 00.00.0000
11789 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11796 \begin_inset LatexCommand \ref{sub:Search-Paths}
11802 \begin_inset Quotes sld
11806 \begin_inset Quotes srd
11813 \labelwidthstring 00.00.0000
11817 \begin_inset LatexCommand \index{SDCC\_LIB}
11824 \begin_inset LatexCommand \ref{sub:Search-Paths}
11830 \begin_inset Quotes sld
11834 \begin_inset Quotes srd
11840 \begin_layout Standard
11841 There are some more environment variables recognized by SDCC, but these
11842 are solely used for debugging purposes.
11843 They can change or disappear very quickly, and will never be documented.
11844 \begin_inset VSpace bigskip
11850 \begin_layout Section
11851 Storage Class Language Extensions
11854 \begin_layout Subsection
11855 MCS51/DS390 Storage Class
11856 \begin_inset LatexCommand \index{Storage class}
11860 Language Extensions
11863 \begin_layout Standard
11864 In addition to the ANSI storage classes SDCC allows the following MCS51
11865 specific storage classes:
11868 \begin_layout Subsubsection
11870 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11875 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11880 \begin_inset LatexCommand \index{near (storage class)}
11885 \begin_inset LatexCommand \index{\_\_near (storage class)}
11892 \begin_layout Standard
11897 storage class for the Small Memory model (
11905 or the more ANSI-C compliant forms
11913 can be used synonymously).
11914 Variables declared with this storage class will be allocated in the directly
11915 addressable portion of the internal RAM of a 8051, e.g.:
11918 \begin_layout Verse
11921 __data unsigned char test_data;
11924 \begin_layout Standard
11925 Writing 0x01 to this variable generates the assembly code:
11928 \begin_layout Verse
11931 75*00 01\InsetSpace ~
11939 \begin_layout Subsubsection
11941 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11946 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11951 \begin_inset LatexCommand \index{far (storage class)}
11956 \begin_inset LatexCommand \index{\_\_far (storage class)}
11963 \begin_layout Standard
11964 Variables declared with this storage class will be placed in the external
11970 storage class for the Large Memory model, e.g.:
11973 \begin_layout Verse
11976 __xdata unsigned char test_xdata;
11979 \begin_layout Standard
11980 Writing 0x01 to this variable generates the assembly code:
11983 \begin_layout Verse
11986 90s00r00\InsetSpace ~
12017 \begin_layout Subsubsection
12019 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12024 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12031 \begin_layout Standard
12032 Variables declared with this storage class will be allocated into the indirectly
12033 addressable portion of the internal ram of a 8051, e.g.:
12036 \begin_layout Verse
12039 __idata unsigned char test_idata;
12042 \begin_layout Standard
12043 Writing 0x01 to this variable generates the assembly code:
12046 \begin_layout Verse
12073 \begin_layout Standard
12074 Please note, the first 128 byte of idata physically access the same RAM
12075 as the data memory.
12076 The original 8051 had 128 byte idata memory, nowadays most devices have
12077 256 byte idata memory.
12079 \begin_inset LatexCommand \index{stack}
12083 is located in idata memory.
12086 \begin_layout Subsubsection
12088 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
12093 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
12100 \begin_layout Standard
12101 Paged xdata access is just as straightforward as using the other addressing
12103 It is typically located at the start of xdata and has a maximum size of
12105 The following example writes 0x01 to the pdata variable.
12106 Please note, pdata access physically accesses xdata memory.
12107 The high byte of the address is determined by port P2
12108 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
12112 (or in case of some 8051 variants by a separate Special Function Register,
12114 \begin_inset LatexCommand \ref{sub:MCS51-variants}
12123 storage class for the Medium Memory model, e.g.:
12126 \begin_layout Verse
12129 __pdata unsigned char test_pdata;
12132 \begin_layout Standard
12133 Writing 0x01 to this variable generates the assembly code:
12136 \begin_layout Verse
12145 mov r0,#_test_pdata
12167 \begin_layout Standard
12172 \begin_layout Standard
12182 \begin_inset LatexCommand \index{-\/-xstack}
12186 option is used the pdata memory area is followed by the xstack memory area
12187 and the sum of their sizes is limited to 256 bytes.
12190 \begin_layout Subsubsection
12192 \begin_inset LatexCommand \index{code}
12197 \begin_inset LatexCommand \index{\_\_code}
12204 \begin_layout Standard
12205 'Variables' declared with this storage class will be placed in the code
12209 \begin_layout Verse
12212 __code unsigned char test_code;
12215 \begin_layout Standard
12216 Read access to this variable generates the assembly code:
12219 \begin_layout Verse
12222 90s00r6F\InsetSpace ~
12225 mov dptr,#_test_code
12250 \begin_layout Standard
12255 indexed arrays of characters in code memory can be accessed efficiently:
12258 \begin_layout Verse
12261 __code char test_array[] = {'c','h','e','a','p'};
12264 \begin_layout Standard
12265 Read access to this array using an 8-bit unsigned index generates the assembly
12269 \begin_layout Verse
12281 \begin_layout Verse
12284 90s00r41\InsetSpace ~
12287 mov dptr,#_test_array
12290 \begin_layout Verse
12305 \begin_layout Subsubsection
12307 \begin_inset LatexCommand \index{bit}
12312 \begin_inset LatexCommand \index{\_\_bit}
12319 \begin_layout Standard
12320 This is a data-type and a storage class specifier.
12321 When a variable is declared as a bit, it is allocated into the bit addressable
12322 memory of 8051, e.g.:
12325 \begin_layout Verse
12331 \begin_layout Standard
12332 Writing 1 to this variable generates the assembly code:
12335 \begin_layout Verse
12349 \begin_layout Standard
12350 The bit addressable memory consists of 128 bits which are located from 0x20
12351 to 0x2f in data memory.
12354 Apart from this 8051 specific storage class most architectures support
12356 \begin_inset LatexCommand \index{bitfields}
12364 \begin_layout Standard
12365 Not really meant as examples, but nevertheless showing what bitfields are
12366 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12372 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12373 signed modifier are implemented as unsigned.
12376 \begin_layout Subsubsection
12378 \begin_inset LatexCommand \index{sfr}
12383 \begin_inset LatexCommand \index{\_\_sfr}
12388 \begin_inset LatexCommand \index{sfr16}
12393 \begin_inset LatexCommand \index{\_\_sfr16}
12398 \begin_inset LatexCommand \index{sfr32}
12403 \begin_inset LatexCommand \index{\_\_sfr32}
12408 \begin_inset LatexCommand \index{\_\_sbit}
12413 \begin_inset LatexCommand \index{sbit}
12420 \begin_layout Standard
12421 Like the bit keyword,
12423 sfr / sfr16 / sfr32 / sbit
12425 signify both a data-type and storage class, they are used to describe the
12446 variables of a 8051, eg:
12449 \begin_layout Verse
12453 \begin_inset LatexCommand \index{at}
12458 \begin_inset LatexCommand \index{\_\_at}
12462 (0x80) P0;\InsetSpace ~
12463 /* special function register P0 at location 0x80 */
12468 special function register combination for timer 0
12472 with the high byte at
12473 location 0x8C and the low byte at location 0x8A */
12475 __sfr16 __at (0x8C8A)
12481 \begin_inset LatexCommand \index{at}
12486 \begin_inset LatexCommand \index{\_\_at}
12490 (0xd7) CY;\InsetSpace ~
12492 \begin_inset LatexCommand \index{Flags}
12497 \begin_inset LatexCommand \index{Carry flag}
12504 \begin_layout Standard
12505 Special function registers which are located on an address dividable by
12506 8 are bit-addressable, an
12510 addresses a specific bit within these sfr.
12512 16 Bit and 32 bit special function
12513 register combinations which require a certain access order are better not
12523 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12524 this is not guaranteed.
12529 \begin_layout Standard
12530 Please note, if you use a header file which was written for another compiler
12531 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
12537 Specifically the syntax
12540 sfr P0 = 0x80;\InsetSpace ~
12547 by SDCC to an assignment of 0x80 to a variable called P0
12550 \begin_inset Marginal
12553 \begin_layout Standard
12565 Nevertheless it is possible to write header files
12566 \begin_inset LatexCommand \index{Header files}
12571 \begin_inset LatexCommand \index{Include files}
12575 which can be shared among different compilers (see section
12576 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
12584 \begin_layout Subsubsection
12586 \begin_inset LatexCommand \index{Pointer}
12590 to MCS51/DS390 specific memory spaces
12593 \begin_layout Standard
12594 SDCC allows (via language extensions) pointers to explicitly point to any
12595 of the memory spaces
12596 \begin_inset LatexCommand \index{Memory model}
12601 In addition to the explicit pointers, the compiler uses (by default) generic
12602 pointers which can be used to point to any of the memory spaces.
12607 declaration examples:
12610 \begin_layout Verse
12613 /* pointer physically in internal ram pointing to object in external ram
12616 __xdata unsigned char * __data p;
12620 /* pointer physically in external ram
12621 pointing to object in internal ram */
12623 __data unsigned char * __xdata p;
12628 pointer physically in code rom pointing to data in xdata space */
12631 unsigned char * __code p;
12635 /* pointer physically in code space pointing to
12636 data in code space */
12638 __code unsigned char * __code p;
12643 physically located in xdata space */
12645 unsigned char * __xdata p;
12650 pointer physically located in default memory space */
12657 the following is a function pointer
12658 \begin_inset LatexCommand \index{function pointer}
12662 physically located in data space */
12664 char (* __data fp)(void);
12667 \begin_layout Standard
12668 Well you get the idea.
12673 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
12686 The highest order byte of the
12690 pointers contains the data space information.
12691 Assembler support routines are called whenever data is stored or retrieved
12697 These are useful for developing reusable library
12698 \begin_inset LatexCommand \index{Libraries}
12703 Explicitly specifying the pointer
12704 \begin_inset LatexCommand \index{pointer}
12708 type will generate the most efficient code.
12711 \begin_layout Subsubsection
12712 Notes on MCS51 memory
12713 \begin_inset LatexCommand \index{MCS51 memory}
12720 \begin_layout Standard
12721 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12722 RAM memory which is structured as follows:
12726 - Bytes 00-1F - 32 bytes to hold
12727 up to 4 banks of the registers R0 to R7,
12729 - Bytes 20-2F - 16 bytes to hold
12731 \begin_inset LatexCommand \index{bit}
12737 - Bytes 30-7F - 80 bytes for general purpose use.
12742 \begin_layout Standard
12743 Additionally some members of the MCS51 family may have up to 128 bytes of
12744 additional, indirectly addressable, internal RAM memory (
12749 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12754 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12759 Furthermore, some chips may have some built in external memory (
12764 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12769 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12773 ) which should not be confused with the internal, directly addressable RAM
12779 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12784 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12789 Sometimes this built in
12793 memory has to be activated before using it (you can probably find this
12794 information on the datasheet of the microcontroller your are using, see
12796 \begin_inset LatexCommand \ref{sub:Startup-Code}
12804 \begin_layout Standard
12805 Normally SDCC will only use the first bank
12806 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12810 of registers (register bank 0), but it is possible to specify that other
12811 banks of registers (keyword
12818 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12823 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12829 ) should be used for example in interrupt
12830 \begin_inset LatexCommand \index{interrupt}
12835 \begin_inset LatexCommand \index{\_\_interrupt}
12840 By default, the compiler will place the stack after the last byte of allocated
12841 memory for variables.
12842 For example, if the first 2 banks of registers are used, and only four
12847 variables, it will position the base of the internal stack at address 20
12849 This implies that as the stack
12850 \begin_inset LatexCommand \index{stack}
12854 grows, it will use up the remaining register banks, and the 16 bytes used
12855 by the 128 bit variables, and 80 bytes for general purpose use.
12856 If any bit variables are used, the data variables will be placed in unused
12857 register banks and after the byte holding the last bit variable.
12858 For example, if register banks 0 and 1 are used, and there are 9 bit variables
12863 variables will be placed starting from address 0x10 to 0x20 and continue
12869 \begin_layout Standard
12879 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12883 to specify the start address of the
12891 \begin_layout Standard
12901 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12905 to specify the size of the total internal RAM (
12919 \begin_layout Standard
12920 By default the 8051 linker will place the stack after the last byte of (i)data
12926 \begin_layout Standard
12936 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12940 allows you to specify the start of the stack, i.e.
12941 you could start it after any data in the general purpose area.
12942 If your microcontroller has additional indirectly addressable internal
12947 ) you can place the stack on it.
12948 You may also need to use -
12952 \begin_layout Standard
12962 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12966 to set the start address of the external RAM (
12974 \begin_layout Standard
12984 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12988 to specify its size.
12989 Same goes for the code memory, using -
12993 \begin_layout Standard
13003 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
13011 \begin_layout Standard
13021 \begin_inset LatexCommand \index{-\/-code-size <Value>}
13026 If in doubt, don't specify any options and see if the resulting memory
13027 layout is appropriate, then you can adjust it.
13030 \begin_layout Standard
13031 The linker generates two files with memory allocation information.
13032 The first, with extension .map
13033 \begin_inset LatexCommand \index{<file>.map}
13037 shows all the variables and segments.
13038 The second with extension .mem
13039 \begin_inset LatexCommand \index{<file>.mem}
13043 shows the final memory layout.
13044 The linker will complain either if memory segments overlap, there is not
13045 enough memory, or there is not enough space for stack.
13046 If you get any linking warnings and/or errors related to stack or segments
13047 allocation, take a look at either the .map or .mem files to find out what
13049 The .mem file may even suggest a solution to the problem.
13050 \begin_inset VSpace bigskip
13056 \begin_layout Subsection
13057 Z80/Z180 Storage Class
13058 \begin_inset LatexCommand \index{Z80!Storage class}
13062 Language Extensions
13065 \begin_layout Subsubsection
13067 \begin_inset LatexCommand \index{sfr}
13072 \begin_inset LatexCommand \index{\_\_sfr}
13076 (in/out to 8-bit addresses)
13079 \begin_layout Standard
13081 \begin_inset LatexCommand \index{Z80}
13085 family has separate address spaces for memory and
13095 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
13100 \begin_inset LatexCommand \index{Z80!I/O memory}
13105 \begin_inset LatexCommand \index{Z180!I/O memory}
13109 is accessed with special instructions, e.g.:
13112 \begin_layout Verse
13115 sfr at 0x78 IoPort;\InsetSpace ~
13117 /* define a var in I/O space at 78h called IoPort */
13121 \begin_layout Standard
13122 Writing 0x01 to this variable generates the assembly code:
13125 \begin_layout Verse
13145 \begin_layout Subsubsection
13147 \begin_inset LatexCommand \index{sfr}
13152 \begin_inset LatexCommand \index{\_\_sfr}
13156 (in/out to 16-bit addresses)
13159 \begin_layout Standard
13164 is used to support 16 bit addresses in I/O memory e.g.:
13167 \begin_layout Verse
13171 \begin_inset LatexCommand \index{at}
13176 \begin_inset LatexCommand \index{\_\_at}
13183 \begin_layout Standard
13184 Writing 0x01 to this variable generates the assembly code:
13187 \begin_layout Verse
13190 01 23 01\InsetSpace ~
13212 \begin_layout Subsubsection
13214 \begin_inset LatexCommand \index{sfr}
13219 \begin_inset LatexCommand \index{\_\_sfr}
13223 (in0/out0 to 8 bit addresses on Z180
13224 \begin_inset LatexCommand \index{Z180}
13229 \begin_inset LatexCommand \index{HD64180 (see Z180)}
13236 \begin_layout Standard
13237 The compiler option -
13241 \begin_layout Standard
13251 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
13255 =180 (80) and a compiler #pragma\InsetSpace ~
13257 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
13261 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
13271 If you include the file z180.h this will be set automatically.
13272 \begin_inset VSpace bigskip
13278 \begin_layout Subsection
13280 \begin_inset LatexCommand \index{HC08!Storage class}
13284 Language Extensions
13287 \begin_layout Subsubsection
13289 \begin_inset LatexCommand \index{data (hc08 storage class)}
13294 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
13301 \begin_layout Standard
13302 The data storage class declares a variable that resides in the first 256
13303 bytes of memory (the direct page).
13305 \begin_inset LatexCommand \index{HC08}
13309 is most efficient at accessing variables (especially pointers) stored here.
13312 \begin_layout Subsubsection
13314 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
13319 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
13326 \begin_layout Standard
13327 The xdata storage class declares a variable that can reside anywhere in
13329 This is the default if no storage class is specified.
13331 \begin_inset VSpace bigskip
13337 \begin_layout Section
13338 Other SDCC language extensions
13339 \begin_inset LatexCommand \index{Other SDCC language extensions}
13346 \begin_layout Subsection
13350 \begin_layout Standard
13351 SDCC supports the use of binary constants, such as 0b01100010.
13352 This feature is only enabled when the compiler is invoked using --std-sdccxx.
13355 \begin_layout Standard
13356 \begin_inset VSpace bigskip
13362 \begin_layout Section
13363 Absolute Addressing
13364 \begin_inset LatexCommand \index{Absolute addressing}
13371 \begin_layout Standard
13372 Data items can be assigned an absolute address with the
13375 \begin_inset LatexCommand \index{at}
13380 \begin_inset LatexCommand \index{\_\_at}
13386 keyword, in addition to a storage class, e.g.:
13389 \begin_layout Verse
13393 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13398 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
13403 \begin_inset LatexCommand \index{at}
13408 \begin_inset LatexCommand \index{\_\_at}
13412 0x7ffe unsigned int chksum;
13415 \begin_layout Standard
13416 or, better conforming to ISO/IEC 9899 C:
13419 \begin_layout Verse
13422 __xdata __at (0x7ffe) unsigned int chksum;
13425 \begin_layout Standard
13426 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
13427 of the external ram.
13432 reserve any space for variables declared in this way
13433 \begin_inset Marginal
13436 \begin_layout Standard
13445 (they are implemented with an equate in the assembler).
13446 Thus it is left to the programmer to make sure there are no overlaps with
13447 other variables that are declared without the absolute address.
13448 The assembler listing file (.lst
13449 \begin_inset LatexCommand \index{<file>.lst}
13453 ) and the linker output files (.rst
13454 \begin_inset LatexCommand \index{<file>.rst}
13459 \begin_inset LatexCommand \index{<file>.map}
13463 ) are good places to look for such overlaps.
13466 \begin_layout Standard
13467 If however you provide an initializer
13468 \begin_inset LatexCommand \index{Variable initialization}
13472 actual memory allocation will take place and overlaps will be detected
13477 \begin_layout Verse
13480 __code __at (0x7ff0) char Id[5] =
13481 \begin_inset Quotes sld
13485 \begin_inset Quotes srd
13491 \begin_layout Standard
13492 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
13496 \begin_layout Standard
13497 In case of memory mapped I/O devices the keyword
13501 has to be used to tell the compiler that accesses might not be removed:
13504 \begin_layout Verse
13508 \begin_inset LatexCommand \index{volatile}
13513 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13518 \begin_inset LatexCommand \index{at}
13522 (0x8000) unsigned char PORTA_8255;
13525 \begin_layout Standard
13526 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
13531 \begin_inset LatexCommand \index{Aligned array}
13538 starts at a block (256 byte) boundary
13539 \begin_inset LatexCommand \index{block boundary}
13544 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13550 Absolute addresses can be specified for variables in all
13551 storage classes, e.g.:
13554 \begin_layout Verse
13558 \begin_inset LatexCommand \index{bit}
13563 \begin_inset LatexCommand \index{at}
13570 \begin_layout Standard
13571 The above example will allocate the variable at offset 0x02 in the bit-addressab
13573 There is no real advantage to assigning absolute addresses to variables
13574 in this manner, unless you want strict control over all the variables allocated.
13575 One possible use would be to write hardware portable code.
13576 For example, if you have a routine that uses one or more of the microcontroller
13577 I/O pins, and such pins are different for two different hardwares, you
13578 can declare the I/O pins in your routine using:
13581 \begin_layout Verse
13585 \begin_inset LatexCommand \index{volatile}
13589 __bit MOSI;\InsetSpace ~
13593 /* master out, slave in */
13595 extern volatile __bit MISO;\InsetSpace ~
13602 extern volatile __bit MCLK;\InsetSpace ~
13611 Output of a byte on a 3-wire serial bus.
13616 If needed adapt polarity of clock,
13617 polarity of data and bit order
13622 unsigned char spi_io(unsigned char out_byte)
13647 MOSI = out_byte & 0x80;
13678 /* _asm nop _endasm; */\InsetSpace ~
13686 /* for slow peripherals */
13738 \begin_layout Standard
13739 Then, someplace in the code for the first hardware you would use
13742 \begin_layout Verse
13746 \begin_inset LatexCommand \index{at}
13751 \begin_inset LatexCommand \index{\_\_at}
13755 (0x80) MOSI;\InsetSpace ~
13759 /* I/O port 0, bit 0 */
13761 __bit __at (0x81) MISO;\InsetSpace ~
13768 __bit __at (0x82) MCLK;\InsetSpace ~
13772 /* I/O port 0, bit 2 */
13775 \begin_layout Standard
13776 Similarly, for the second hardware you would use
13779 \begin_layout Verse
13782 __bit __at (0x83) MOSI;\InsetSpace ~
13786 /* I/O port 0, bit 3 */
13788 __bit __at (0x91) MISO;\InsetSpace ~
13793 I/O port 1, bit 1 */
13796 \begin_inset LatexCommand \index{bit}
13800 __at (0x92) MCLK;\InsetSpace ~
13804 /* I/O port 1, bit 2 */
13807 \begin_layout Standard
13808 and you can use the same hardware dependent routine without changes, as
13809 for example in a library.
13810 This is somehow similar to sbit, but only one absolute address has to be
13811 specified in the whole project.
13812 \begin_inset VSpace bigskip
13818 \begin_layout Section
13820 \begin_inset LatexCommand \index{Parameters}
13825 \begin_inset LatexCommand \index{function parameter}
13830 \begin_inset LatexCommand \index{local variables}
13835 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13842 \begin_layout Standard
13843 Automatic (local) variables and parameters to functions can either be placed
13844 on the stack or in data-space.
13845 The default action of the compiler is to place these variables in the internal
13846 RAM (for small model) or external RAM (for medium or large model).
13847 This in fact makes them similar to
13850 \begin_inset LatexCommand \index{static}
13856 so by default functions are non-reentrant
13857 \begin_inset LatexCommand \index{reentrant}
13866 They can be placed on the stack
13867 \begin_inset LatexCommand \index{stack}
13877 \begin_layout Standard
13887 \begin_inset LatexCommand \index{-\/-stack-auto}
13895 #pragma\InsetSpace ~
13899 \begin_inset LatexCommand \index{\#pragma stackauto}
13906 \begin_inset LatexCommand \index{reentrant}
13912 keyword in the function declaration, e.g.:
13915 \begin_layout Verse
13918 unsigned char foo(char i) __reentrant
13932 \begin_layout Standard
13933 Since stack space on 8051 is limited, the
13943 \begin_layout Standard
13954 option should be used sparingly.
13955 Note that the reentrant keyword just means that the parameters & local
13956 variables will be allocated to the stack, it
13960 mean that the function is register bank
13961 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13970 \begin_inset LatexCommand \index{local variables}
13974 can be assigned storage classes and absolute
13975 \begin_inset LatexCommand \index{Absolute addressing}
13982 \begin_layout Verse
13985 unsigned char foo()
13993 __xdata unsigned char i;
14006 \begin_inset LatexCommand \index{at}
14010 (0x31) unsigned char j;
14022 \begin_layout Standard
14023 In the above example the variable
14027 will be allocated in the external ram,
14031 in bit addressable space and
14042 \begin_layout Standard
14053 or when a function is declared as
14057 this should only be done for static variables.
14060 \begin_layout Standard
14062 \begin_inset LatexCommand \index{function parameter}
14066 however are not allowed any storage class
14067 \begin_inset LatexCommand \index{Storage class}
14071 , (storage classes for parameters will be ignored), their allocation is
14072 governed by the memory model in use, and the reentrancy options.
14075 \begin_layout Standard
14076 It is however allowed to use bit parameters in reentrant functions and also
14077 non-static local bit variables are supported.
14078 Efficient use is limited to 8 semi-bitregisters in bit space.
14079 They are pushed and popped to stack
14080 \begin_inset LatexCommand \index{stack}
14084 as a single byte just like the normal registers.
14087 \begin_layout Section
14089 \begin_inset LatexCommand \label{sub:Overlaying}
14094 \begin_inset LatexCommand \index{Overlaying}
14101 \begin_layout Standard
14103 \begin_inset LatexCommand \index{reentrant}
14107 functions SDCC will try to reduce internal ram space usage by overlaying
14108 parameters and local variables of a function (if possible).
14109 Parameters and local variables
14110 \begin_inset LatexCommand \index{local variables}
14114 of a function will be allocated to an overlayable segment if the function
14117 no other function calls and the function is non-reentrant and the memory
14119 \begin_inset LatexCommand \index{Memory model}
14126 If an explicit storage class
14127 \begin_inset LatexCommand \index{Storage class}
14131 is specified for a local variable, it will NOT be overlayed.
14134 \begin_layout Standard
14135 Note that the compiler (not the linkage editor) makes the decision for overlayin
14137 Functions that are called from an interrupt service routine
14138 \begin_inset Marginal
14141 \begin_layout Standard
14149 should be preceded by a #pragma\InsetSpace ~
14151 \begin_inset LatexCommand \index{\#pragma nooverlay}
14155 if they are not reentrant.
14158 \begin_layout Standard
14159 Also note that the compiler does not do any processing of inline assembler
14160 code, so the compiler might incorrectly assign local variables and parameters
14161 of a function into the overlay segment if the inline assembler code calls
14162 other c-functions that might use the overlay.
14163 In that case the #pragma\InsetSpace ~
14164 nooverlay should be used.
14167 \begin_layout Standard
14168 Parameters and local variables of functions that contain 16 or 32 bit multiplica
14170 \begin_inset LatexCommand \index{Multiplication}
14175 \begin_inset LatexCommand \index{Division}
14179 will NOT be overlayed since these are implemented using external functions,
14183 \begin_layout Verse
14189 \begin_inset LatexCommand \index{\#pragma nooverlay}
14195 void set_error(unsigned char errcd)
14212 some_isr () __interrupt
14213 \begin_inset LatexCommand \index{interrupt}
14243 \begin_layout Standard
14244 In the above example the parameter
14252 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
14254 not present, this could cause unpredictable runtime behavior when called
14255 from an interrupt service routine.
14256 The #pragma\InsetSpace ~
14257 nooverlay ensures that the parameters and local variables for
14258 the function are NOT overlayed.
14259 \begin_inset VSpace bigskip
14265 \begin_layout Section
14266 Interrupt Service Routines
14267 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
14274 \begin_layout Subsection
14275 General Information
14278 \begin_layout Standard
14291 outines to be coded in C, with some extended keywords.
14294 \begin_layout Verse
14297 void timer_isr (void) __interrupt (1) __using (1)
14311 \begin_layout Standard
14312 The optional number following the
14315 \begin_inset LatexCommand \index{interrupt}
14320 \begin_inset LatexCommand \index{\_\_interrupt}
14326 keyword is the interrupt number this routine will service.
14327 When present, the compiler will insert a call to this routine in the interrupt
14329 \begin_inset LatexCommand \index{interrupt vector table}
14333 for the interrupt number specified.
14334 If you have multiple source files in your project, interrupt service routines
14335 can be present in any of them, but a prototype of the isr MUST be present
14336 or included in the file that contains the function
14341 The optional (8051 specific) keyword
14344 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14349 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14355 can be used to tell the compiler to use the specified register bank when
14356 generating code for this function.
14359 Interrupt service routines open the door for some very interesting bugs:
14362 \begin_layout Subsubsection
14363 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
14367 Common interrupt pitfall: variable not declared
14372 \begin_layout Standard
14373 If an interrupt service routine changes variables which are accessed by
14374 other functions these variables have to be declared
14379 \begin_inset LatexCommand \index{volatile}
14385 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
14392 \begin_layout Subsubsection
14393 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
14397 Common interrupt pitfall:
14402 \begin_layout Standard
14403 If the access to these variables is not
14406 \begin_inset LatexCommand \index{atomic}
14413 the processor needs more than one instruction for the access and could
14414 be interrupted while accessing the variable) the interrupt must be disabled
14415 during the access to avoid inconsistent data.
14418 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
14419 and should be protected by disabling interrupts.
14420 You're not automatically on the safe side if you use 8 bit variables though.
14421 We need an example here: f.e.
14422 on the 8051 the harmless looking
14423 \begin_inset Quotes srd
14433 \begin_inset Quotes sld
14442 \begin_inset Quotes srd
14452 \begin_inset Quotes sld
14455 from within an interrupt routine might get lost if the interrupt occurs
14458 \begin_inset Quotes sld
14463 counter\InsetSpace ~
14468 \begin_inset Quotes srd
14471 is not atomic on the 8051 even if
14475 is located in data memory.
14477 Bugs like these are hard to reproduce and can
14478 cause a lot of trouble.
14482 \begin_layout Subsubsection
14483 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
14487 Common interrupt pitfall:
14492 \begin_layout Standard
14493 The return address and the registers used in the interrupt service routine
14494 are saved on the stack
14495 \begin_inset LatexCommand \index{stack}
14499 so there must be sufficient stack space.
14500 If there isn't variables or registers (or even the return address itself)
14507 \begin_inset LatexCommand \index{stack overflow}
14511 is most likely to happen if the interrupt occurs during the
14512 \begin_inset Quotes sld
14516 \begin_inset Quotes srd
14519 subroutine when the stack is already in use for f.e.
14520 many return addresses.
14523 \begin_layout Subsubsection
14524 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
14528 Common interrupt pitfall:
14530 use of non-reentrant functions
14533 \begin_layout Standard
14534 A special note here, int (16 bit) and long (32 bit) integer division
14535 \begin_inset LatexCommand \index{Division}
14540 \begin_inset LatexCommand \index{Multiplication}
14545 \begin_inset LatexCommand \index{Modulus}
14550 \begin_inset LatexCommand \index{Floating point support}
14554 operations are implemented using external support routines.
14555 If an interrupt service routine needs to do any of these operations then
14556 the support routines (as mentioned in a following section) will have to
14557 be recompiled using the
14563 \begin_layout Standard
14573 \begin_inset LatexCommand \index{-\/-stack-auto}
14579 option and the source file will need to be compiled using the
14585 \begin_layout Standard
14597 \begin_inset LatexCommand \index{-\/-int-long-reent}
14604 Note, the type promotion
14605 \begin_inset LatexCommand \index{type promotion}
14609 required by ANSI C can cause 16 bit routines to be used
14610 \begin_inset Marginal
14613 \begin_layout Standard
14622 without the programmer being aware of it.
14626 (unsigned char)(tail-1)
14628 within the if clause in section
14629 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
14636 \begin_layout Standard
14637 Calling other functions from an interrupt service routine is not recommended,
14638 avoid it if possible.
14639 Note that when some function is called from an interrupt service routine
14640 it should be preceded by a #pragma\InsetSpace ~
14642 \begin_inset LatexCommand \index{\#pragma nooverlay}
14646 if it is not reentrant.
14647 Furthermore nonreentrant functions should not be called from the main program
14648 while the interrupt service routine might be active.
14649 They also must not be called from low priority interrupt service routines
14650 while a high priority interrupt service routine might be active.
14651 You could use semaphores or make the function
14655 if all parameters are passed in registers.
14658 \begin_inset LatexCommand \ref{sub:Overlaying}
14663 about Overlaying and section
14664 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14669 about Functions using private register banks.
14670 \begin_inset VSpace bigskip
14676 \begin_layout Subsection
14677 MCS51/DS390 Interrupt Service Routines
14680 \begin_layout Standard
14682 \begin_inset LatexCommand \index{interrupt}
14686 numbers and the corresponding address & descriptions for the Standard 8051/8052
14688 SDCC will automatically adjust the
14689 \begin_inset LatexCommand \index{interrupt vector table}
14693 to the maximum interrupt number specified.
14698 \begin_layout Standard
14700 \begin_inset Tabular
14701 <lyxtabular version="3" rows="9" columns="3">
14703 <column alignment="center" valignment="top" leftline="true" width="0in">
14704 <column alignment="left" valignment="top" leftline="true" width="0in">
14705 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14706 <row topline="true" bottomline="true">
14707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14710 \begin_layout Standard
14716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14719 \begin_layout Standard
14725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14728 \begin_layout Standard
14735 <row topline="true">
14736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14739 \begin_layout Standard
14745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14748 \begin_layout Standard
14754 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14757 \begin_layout Standard
14764 <row topline="true">
14765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14768 \begin_layout Standard
14774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14777 \begin_layout Standard
14783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14786 \begin_layout Standard
14793 <row topline="true">
14794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14797 \begin_layout Standard
14803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14806 \begin_layout Standard
14812 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14815 \begin_layout Standard
14822 <row topline="true">
14823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14826 \begin_layout Standard
14832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14835 \begin_layout Standard
14841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14844 \begin_layout Standard
14851 <row topline="true">
14852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14855 \begin_layout Standard
14861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14864 \begin_layout Standard
14870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14873 \begin_layout Standard
14880 <row topline="true">
14881 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14884 \begin_layout Standard
14890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14893 \begin_layout Standard
14899 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14902 \begin_layout Standard
14909 <row topline="true">
14910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14913 \begin_layout Standard
14919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14922 \begin_layout Standard
14928 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14931 \begin_layout Standard
14938 <row topline="true" bottomline="true">
14939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14942 \begin_layout Standard
14948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14951 \begin_layout Standard
14957 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14960 \begin_layout Standard
14976 \begin_layout Standard
14977 If the interrupt service routine is defined without
14980 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14985 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14991 a register bank or with register bank 0 (
14995 0), the compiler will save the registers used by itself on the stack upon
14996 entry and restore them at exit, however if such an interrupt service routine
14997 calls another function then the entire register bank will be saved on the
14999 This scheme may be advantageous for small interrupt service routines which
15000 have low register usage.
15003 \begin_layout Standard
15004 If the interrupt service routine is defined to be using a specific register
15009 & psw are saved and restored, if such an interrupt service routine calls
15010 another function (using another register bank) then the entire register
15011 bank of the called function will be saved on the stack
15012 \begin_inset LatexCommand \index{stack}
15017 This scheme is recommended for larger interrupt service routines.
15018 \begin_inset VSpace bigskip
15024 \begin_layout Subsection
15026 \begin_inset LatexCommand \index{HC08}
15030 Interrupt Service Routines
15033 \begin_layout Standard
15034 Since the number of interrupts
15035 \begin_inset LatexCommand \index{HC08!interrupt}
15039 available is chip specific and the interrupt vector table always ends at
15040 the last byte of memory, the interrupt numbers corresponds to the interrupt
15041 vectors in reverse order of address.
15042 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
15043 2 will use the interrupt vector at 0xfffa, and so on.
15044 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
15045 this way; instead see section
15046 \begin_inset LatexCommand \ref{sub:Startup-Code}
15050 for details on customizing startup.
15051 \begin_inset VSpace bigskip
15057 \begin_layout Subsection
15058 Z80 Interrupt Service Routines
15061 \begin_layout Standard
15063 \begin_inset LatexCommand \index{Z80}
15067 uses several different methods for determining the correct interrupt
15068 \begin_inset LatexCommand \index{Z80!interrupt}
15072 vector depending on the hardware implementation.
15073 Therefore, SDCC ignores the optional interrupt number and does not attempt
15074 to generate an interrupt vector table.
15077 \begin_layout Standard
15078 By default, SDCC generates code for a maskable interrupt, which uses a RETI
15079 instruction to return from the interrupt.
15080 To write an interrupt handler for the non-maskable interrupt, which needs
15081 a RETN instruction instead, add the
15088 \begin_layout Verse
15091 void nmi_isr (void) critical interrupt
15105 \begin_layout Standard
15106 However if you need to create a non-interruptable interrupt service routine
15107 you would also require the
15112 To distinguish between this and an nmi_isr you must provide an interrupt
15114 \begin_inset VSpace bigskip
15120 \begin_layout Section
15121 Enabling and Disabling Interrupts
15124 \begin_layout Subsection
15125 Critical Functions and Critical Statements
15128 \begin_layout Standard
15129 A special keyword may be associated with a block or a function declaring
15135 SDCC will generate code to disable all interrupts
15136 \begin_inset LatexCommand \index{interrupt}
15140 upon entry to a critical function and restore the interrupt enable to the
15141 previous state before returning.
15142 Nesting critical functions will need one additional byte on the stack
15143 \begin_inset LatexCommand \index{stack}
15150 \begin_layout Verse
15153 int foo () __critical
15154 \begin_inset LatexCommand \index{critical}
15159 \begin_inset LatexCommand \index{\_\_critical}
15184 \begin_layout Standard
15185 The critical attribute maybe used with other attributes like
15195 may also be used to disable interrupts more locally:
15198 \begin_layout Verse
15204 \begin_layout Standard
15205 More than one statement could have been included in the block.
15208 \begin_layout Subsection
15209 Enabling and Disabling Interrupts directly
15212 \begin_layout Standard
15214 \begin_inset LatexCommand \index{interrupt}
15218 can also be disabled and enabled directly (8051):
15221 \begin_layout Verse
15224 EA = 0;\InsetSpace ~
15250 \begin_layout Verse
15286 \begin_layout Verse
15289 EA = 1;\InsetSpace ~
15318 \begin_layout Verse
15357 \begin_layout Standard
15358 On other architectures which have seperate opcodes for enabling and disabling
15359 interrupts you might want to make use of defines with inline assembly
15360 \begin_inset LatexCommand \index{Assembler routines}
15365 \begin_inset LatexCommand \index{HC08!interrupt}
15372 \begin_layout Verse
15376 \begin_inset LatexCommand \index{\_asm}
15385 \begin_inset LatexCommand \index{\_endasm}
15392 \begin_layout Verse
15395 #define SEI _asm\InsetSpace ~
15402 \begin_layout Verse
15408 \begin_layout Standard
15409 Note: it is sometimes sufficient to disable only a specific interrupt source
15411 a timer or serial interrupt by manipulating an
15414 \begin_inset LatexCommand \index{interrupt mask}
15424 \begin_layout Standard
15425 Usually the time during which interrupts are disabled should be kept as
15427 This minimizes both
15432 \begin_inset LatexCommand \index{interrupt latency}
15436 (the time between the occurrence of the interrupt and the execution of
15437 the first code in the interrupt routine) and
15442 \begin_inset LatexCommand \index{interrupt jitter}
15446 (the difference between the shortest and the longest interrupt latency).
15447 These really are something different, f.e.
15448 a serial interrupt has to be served before its buffer overruns so it cares
15449 for the maximum interrupt latency, whereas it does not care about jitter.
15450 On a loudspeaker driven via a digital to analog converter which is fed
15451 by an interrupt a latency of a few milliseconds might be tolerable, whereas
15452 a much smaller jitter will be very audible.
15455 \begin_layout Standard
15456 You can reenable interrupts within an interrupt routine and on some architecture
15457 s you can make use of two (or more) levels of
15459 interrupt priorities
15462 \begin_inset LatexCommand \index{interrupt priority}
15467 On some architectures which don't support interrupt priorities these can
15468 be implemented by manipulating the interrupt mask and reenabling interrupts
15469 within the interrupt routine.
15470 Check there is sufficient space on the stack
15471 \begin_inset LatexCommand \index{stack}
15475 and don't add complexity unless you have to.
15479 \begin_layout Subsection
15481 \begin_inset LatexCommand \index{semaphore}
15485 locking (mcs51/ds390)
15488 \begin_layout Standard
15489 Some architectures (mcs51/ds390) have an atomic
15490 \begin_inset LatexCommand \index{atomic}
15503 These type of instructions are typically used in preemptive multitasking
15504 systems, where a routine f.e.
15505 claims the use of a data structure ('acquires a lock
15506 \begin_inset LatexCommand \index{lock}
15510 on it'), makes some modifications and then releases the lock when the data
15511 structure is consistent again.
15512 The instruction may also be used if interrupt and non-interrupt code have
15513 to compete for a resource.
15514 With the atomic bit test and clear instruction interrupts
15515 \begin_inset LatexCommand \index{interrupt}
15519 don't have to be disabled for the locking operation.
15523 \begin_layout Standard
15524 SDCC generates this instruction if the source follows this pattern:
15527 \begin_layout Verse
15531 \begin_inset LatexCommand \index{volatile}
15535 bit resource_is_free;
15539 if (resource_is_free)
15549 resource_is_free=0;
15562 resource_is_free=1;
15569 \begin_layout Standard
15570 Note, mcs51 and ds390 support only an atomic
15571 \begin_inset LatexCommand \index{atomic}
15579 instruction (as opposed to atomic bit test and
15584 \begin_layout Section
15585 Functions using private register banks
15586 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
15593 \begin_layout Standard
15594 Some architectures have support for quickly changing register sets.
15595 SDCC supports this feature with the
15598 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
15603 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
15609 attribute (which tells the compiler to use a register bank
15610 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
15614 other than the default bank zero).
15615 It should only be applied to
15618 \begin_inset LatexCommand \index{interrupt}
15624 functions (see footnote below).
15625 This will in most circumstances make the generated ISR code more efficient
15626 since it will not have to save registers on the stack.
15629 \begin_layout Standard
15634 attribute will have no effect on the generated code for a
15638 function (but may occasionally be useful anyway
15642 \begin_layout Standard
15643 possible exception: if a function is called ONLY from 'interrupt' functions
15644 using a particular bank, it can be declared with the same 'using' attribute
15645 as the calling 'interrupt' functions.
15646 For instance, if you have several ISRs using bank one, and all of them
15647 call memcpy(), it might make sense to create a specialized version of memcpy()
15648 'using 1', since this would prevent the ISR from having to save bank zero
15649 to the stack on entry and switch to bank zero before calling the function
15658 (pending: Note, nowadays the
15662 attribute has an effect on
15666 the generated code for a
15677 \begin_layout Standard
15682 function using a non-zero bank will assume that it can trash that register
15683 bank, and will not save it.
15684 Since high-priority interrupts
15685 \begin_inset LatexCommand \index{interrupts}
15690 \begin_inset LatexCommand \index{interrupt priority}
15694 can interrupt low-priority ones on the 8051 and friends, this means that
15695 if a high-priority ISR
15699 a particular bank occurs while processing a low-priority ISR
15703 the same bank, terrible and bad things can happen.
15704 To prevent this, no single register bank should be
15708 by both a high priority and a low priority ISR.
15709 This is probably most easily done by having all high priority ISRs use
15710 one bank and all low priority ISRs use another.
15711 If you have an ISR which can change priority at runtime, you're on your
15712 own: I suggest using the default bank zero and taking the small performance
15716 \begin_layout Standard
15717 It is most efficient if your ISR calls no other functions.
15718 If your ISR must call other functions, it is most efficient if those functions
15719 use the same bank as the ISR (see note 1 below); the next best is if the
15720 called functions use bank zero.
15721 It is very inefficient to call a function using a different, non-zero bank
15724 \begin_inset VSpace bigskip
15730 \begin_layout Section
15732 \begin_inset LatexCommand \label{sub:Startup-Code}
15737 \begin_inset LatexCommand \index{Startup code}
15744 \begin_layout Subsection
15745 MCS51/DS390 Startup Code
15748 \begin_layout Standard
15749 The compiler triggers the linker to link certain initialization modules
15750 from the runtime library
15751 \begin_inset LatexCommand \index{Runtime library}
15755 called crt<something>.
15756 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15757 GSINIT5) is not linked unless the -
15763 \begin_layout Standard
15774 -xstack option is used.
15775 These modules are highly entangled by the use of special segments/areas,
15776 but a common layout is shown below:
15779 \begin_layout Verse
15787 \begin_layout Verse
15811 ljmp __sdcc_gsinit_startup
15814 \begin_layout Verse
15822 \begin_layout Verse
15834 .area GSINIT0 (CODE)
15836 __sdcc_gsinit_startup::
15846 mov sp,#__start__stack - 1
15849 \begin_layout Verse
15857 \begin_layout Verse
15869 .area GSINIT1 (CODE)
15871 __sdcc_init_xstack::
15873 ; Need to initialize in GSINIT1 in
15874 case the user's __sdcc_external_startup uses the xstack.
15884 mov __XPAGE,#(__start__x
15895 mov _spx,#__start__xstack
15898 \begin_layout Verse
15906 \begin_layout Verse
15918 .area GSINIT2 (CODE)
15928 lcall __sdcc_external_startup
15948 jz __sdcc_init_data
15959 __sdcc_program_startup
15964 \begin_layout Verse
15972 \begin_layout Verse
15984 .area GSINIT3 (CODE)
16037 mov r2,#((l_XINIT+255) >> 8)
16068 __XPAGE,#(s_XISEG >> 8)
16070 00001$:\InsetSpace ~
16134 00002$:\InsetSpace ~
16161 \begin_layout Verse
16169 \begin_layout Verse
16181 .area GSINIT4 (CODE)
16183 __mcs51_genRAMCLEAR::
16205 00004$:\InsetSpace ~
16219 ; _mcs51_genRAMCLEAR() end
16222 \begin_layout Verse
16230 \begin_layout Verse
16242 .area GSINIT4 (CODE)
16244 __mcs51_genXRAMCLEAR::
16305 mov __XPAGE,#(s_PSEG >> 8)
16317 00005$:\InsetSpace ~
16392 mov r1,#((l_XSEG + 255) >> 8)
16414 00007$:\InsetSpace ~
16451 \begin_layout Verse
16459 \begin_layout Verse
16471 .area GSINIT5 (CODE)
16473 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
16476 ; and __mcs51_genRAMCLEAR modifies _spx.
16486 mov __XPAGE,#(__start__x
16497 mov _spx,#__start__xstack
16500 \begin_layout Verse
16505 (application modules)
16508 \begin_layout Verse
16520 .area GSINIT (CODE)
16523 \begin_layout Verse
16531 \begin_layout Verse
16543 .area GSFINAL (CODE)
16553 ljmp __sdcc_program_startup
16555 ;---------------------------------
16556 -----------------------
16560 ;--------------------------------------------------
16583 __sdcc_program_startup:
16596 return from main will lock up
16609 \begin_layout Standard
16610 One of these modules (crtstart.asm) contains a call to the C routine
16612 _sdcc_external_startup()
16613 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
16622 at the start of the CODE area.
16623 This routine is also in the runtime library
16624 \begin_inset LatexCommand \index{Runtime library}
16628 and returns 0 by default.
16629 If this routine returns a non-zero value, the static & global variable
16630 initialization will be skipped and the function main will be invoked.
16631 Otherwise static & global variables will be initialized before the function
16635 _sdcc_external_startup()
16637 routine to your program to override the default if you need to setup hardware
16638 or perform some other critical operation prior to static & global variable
16640 \begin_inset LatexCommand \index{Variable initialization}
16645 On some mcs51 variants xdata
16646 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
16650 memory has to be explicitly enabled before it can be accessed or if the
16652 \begin_inset LatexCommand \index{watchdog}
16656 needs to be disabled, this is the place to do it.
16657 The startup code clears all internal data memory, 256 bytes by default,
16658 but from 0 to n-1 if
16664 \begin_layout Standard
16674 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16681 (recommended for Chipcon CC1010).
16684 \begin_layout Standard
16685 See also the compiler options
16691 \begin_layout Standard
16707 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16717 \begin_layout Standard
16729 \begin_inset LatexCommand \index{-\/-main-return}
16734 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16738 about MCS51-variants.
16743 \begin_layout Standard
16744 While these initialization modules are meant as generic startup code there
16745 might be the need for customization.
16746 Let's assume the return value of
16748 _sdcc_external_startup()
16754 should not be checked (or
16756 _sdcc_external_startup()
16758 should not be called at all).
16759 The recommended way would be to copy
16765 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm}
16769 ) into the source directory, adapt it there, then assemble it with
16775 \begin_layout Standard
16776 \begin_inset Quotes sld
16780 \begin_inset Quotes srd
16783 are the assembler options used in
16784 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup }
16795 and when linking your project explicitely specify
16800 As a bonus a listing of the relocated object file
16807 \begin_layout Standard
16808 \begin_inset VSpace bigskip
16814 \begin_layout Subsection
16818 \begin_layout Standard
16820 \begin_inset LatexCommand \index{HC08}
16824 startup code follows the same scheme as the MCS51 startup code.
16825 \begin_inset VSpace bigskip
16831 \begin_layout Subsection
16835 \begin_layout Standard
16837 \begin_inset LatexCommand \index{Z80}
16841 the startup code is inserted by linking with crt0.o which is generated from
16842 sdcc/device/lib/z80/crt0.s.
16843 If you need a different startup code you can use the compiler option
16852 \begin_layout Standard
16867 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16871 and provide your own crt0.o.
16873 \begin_inset VSpace bigskip
16879 \begin_layout Section
16880 Inline Assembler Code
16881 \begin_inset LatexCommand \index{Assembler routines}
16888 \begin_layout Subsection
16889 A Step by Step Introduction
16890 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16897 \begin_layout Standard
16898 Starting from a small snippet of c-code this example shows for the MCS51
16899 how to use inline assembly, access variables, a function parameter and
16900 an array in xdata memory.
16901 The example uses an MCS51 here but is easily adapted for other architectures.
16902 This is a buffer routine which should be optimized:
16905 \begin_layout Verse
16909 unsigned char __far
16910 \begin_inset LatexCommand \index{far (storage class)}
16915 \begin_inset LatexCommand \index{\_\_far (storage class)}
16920 \begin_inset LatexCommand \index{at}
16925 \begin_inset LatexCommand \index{\_\_at}
16929 (0x7f00) buf[0x100];
16930 \begin_inset LatexCommand \index{Aligned array}
16936 unsigned char head, tail;\InsetSpace ~
16954 \begin_inset LatexCommand \index{interrupt}
17006 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
17018 void to_buffer( unsigned char c )
17026 if( head != (unsigned char)(tail-1)
17033 \begin_inset LatexCommand \index{promotion to signed int}
17038 \begin_inset LatexCommand \index{type promotion}
17043 \begin_inset Marginal
17046 \begin_layout Standard
17065 buf[ head++ ] = c;\InsetSpace ~
17081 /* access to a 256 byte aligned array */
17086 \begin_layout Standard
17087 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
17088 then a corresponding buffer.asm file is generated.
17089 We define a new function
17093 in file buffer.c in which we cut and paste the generated code, removing
17094 unwanted comments and some ':'.
17096 \begin_inset Quotes sld
17104 \begin_inset Quotes srd
17108 \begin_inset Quotes sld
17116 \begin_inset Quotes srd
17123 \begin_layout Standard
17124 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
17125 and for C-99 compatibility, the double-underscore form (__asm and __endasm)
17127 The latter is also used in the library functions.
17132 to the beginning and the end of the function body:
17135 \begin_layout Verse
17139 /* With a cut and paste from the .asm file, we have something to start with.
17145 function is not yet OK! (registers aren't saved) */
17147 void to_buffer_asm(
17157 \begin_inset LatexCommand \index{\_asm}
17162 \begin_inset LatexCommand \index{\_\_asm}
17176 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
17182 \begin_inset LatexCommand \index{promotion to signed int}
17187 \begin_inset LatexCommand \index{type promotion}
17240 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
17241 \begin_inset LatexCommand \index{Aligned array}
17307 \begin_inset LatexCommand \index{\_endasm}
17312 \begin_inset LatexCommand \index{\_\_endasm}
17321 \begin_layout Standard
17322 The new file buffer.c should compile with only one warning about the unreferenced
17323 function argument 'c'.
17324 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
17325 (1) and finally have:
17328 \begin_layout Verse
17332 unsigned char __far __at(0x7f00) buf[0x100];
17334 unsigned char head, tail;
17345 void to_buffer( unsigned char c )
17354 head != (unsigned char)(tail-1) )
17383 c; // to avoid warning: unreferenced function argument
17390 \begin_inset LatexCommand \index{\_asm}
17395 \begin_inset LatexCommand \index{\_\_asm}
17409 ; save used registers here.
17420 ; If we were still using r2,r3 we would have to push them here.
17423 ; if( head != (unsigned char)(tail-1) )
17467 could do an ANL a,#0x0f here to use a smaller buffer (see below)
17503 a,dpl \InsetSpace ~
17510 ; dpl holds lower byte of function argument
17522 dpl,_head \InsetSpace ~
17525 ; buf is 0x100 byte aligned so head can be used directly
17568 ; we could do an ANL _head,#0x0f here to use a
17569 smaller buffer (see above)
17581 ; restore used registers here
17588 \begin_inset LatexCommand \index{\_endasm}
17593 \begin_inset LatexCommand \index{\_\_endasm}
17604 \begin_layout Standard
17605 The inline assembler code can contain any valid code understood by the assembler
17606 , this includes any assembler directives and comment lines.
17607 The assembler does not like some characters like ':' or ''' in comments.
17608 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
17609 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
17614 \begin_inset LatexCommand \index{Assembler documentation}
17619 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
17627 \begin_layout Standard
17628 The compiler does not do any validation of the code within the
17631 \begin_inset LatexCommand \index{\_asm}
17636 \begin_inset LatexCommand \index{\_\_asm}
17644 \begin_inset LatexCommand \index{\_endasm}
17649 \begin_inset LatexCommand \index{\_\_endasm}
17658 Specifically it will not know which registers are used and thus register
17660 \begin_inset LatexCommand \index{push/pop}
17664 has to be done manually.
17668 \begin_layout Standard
17669 It is recommended that each assembly instruction (including labels) be placed
17670 in a separate line (as the example shows).
17675 \begin_layout Standard
17687 \begin_inset LatexCommand \index{-\/-peep-asm}
17693 command line option is used, the inline assembler code will be passed through
17694 the peephole optimizer
17695 \begin_inset LatexCommand \index{Peephole optimizer}
17700 There are only a few (if any) cases where this option makes sense, it might
17701 cause some unexpected changes in the inline assembler code.
17702 Please go through the peephole optimizer rules defined in file
17706 before using this option.
17709 \begin_layout Subsection
17711 \begin_inset LatexCommand \label{sub:Naked-Functions}
17716 \begin_inset LatexCommand \index{Naked functions}
17723 \begin_layout Standard
17724 A special keyword may be associated with a function declaring it as
17727 \begin_inset LatexCommand \index{\_naked}
17732 \begin_inset LatexCommand \index{\_\_naked}
17743 function modifier attribute prevents the compiler from generating prologue
17744 \begin_inset LatexCommand \index{function prologue}
17749 \begin_inset LatexCommand \index{function epilogue}
17753 code for that function.
17754 This means that the user is entirely responsible for such things as saving
17755 any registers that may need to be preserved, selecting the proper register
17756 bank, generating the
17760 instruction at the end, etc.
17761 Practically, this means that the contents of the function must be written
17762 in inline assembler.
17763 This is particularly useful for interrupt functions, which can have a large
17764 (and often unnecessary) prologue/epilogue.
17765 For example, compare the code generated by these two functions:
17768 \begin_layout Verse
17772 \begin_inset LatexCommand \index{volatile}
17776 data unsigned char counter;
17780 void simpleInterrupt(void) __interrupt
17781 \begin_inset LatexCommand \index{interrupt}
17786 \begin_inset LatexCommand \index{\_\_interrupt}
17804 void nakedInterrupt(void) __interrupt (2) __naked
17813 \begin_inset LatexCommand \index{\_asm}
17818 \begin_inset LatexCommand \index{\_\_asm}
17835 _counter ; does not change flags, no need to save psw
17848 include ret or reti in _naked function.
17855 \begin_inset LatexCommand \index{\_endasm}
17860 \begin_inset LatexCommand \index{\_\_endasm}
17869 \begin_layout Standard
17870 For an 8051 target, the generated simpleInterrupt looks like:
17873 \begin_layout Verse
17880 example, recent versions of SDCC generate
17886 code for simpleInterrupt() and nakedInterrupt()!
18027 \begin_layout Standard
18028 whereas nakedInterrupt looks like:
18031 \begin_layout Verse
18044 _counter ; does not change flags, no need to save psw
18063 MUST explicitly include ret or reti in _naked function
18066 \begin_layout Standard
18067 The related directive #pragma exclude
18068 \begin_inset LatexCommand \index{\#pragma exclude}
18072 allows a more fine grained control over pushing & popping
18073 \begin_inset LatexCommand \index{push/pop}
18080 \begin_layout Standard
18081 While there is nothing preventing you from writing C code inside a
18085 function, there are many ways to shoot yourself in the foot doing this,
18086 and it is recommended that you stick to inline assembler.
18089 \begin_layout Subsection
18090 Use of Labels within Inline Assembler
18093 \begin_layout Standard
18094 SDCC allows the use of in-line assembler with a few restrictions regarding
18096 All labels defined within inline assembler code have to be of the form
18101 where nnnnn is a number less than 100 (which implies a limit of utmost
18102 100 inline assembler labels
18113 \begin_layout Standard
18114 This is a slightly more stringent rule than absolutely necessary, but stays
18115 always on the safe side.
18116 Labels in the form of nnnnn$ are local labels in the assembler, locality
18117 of which is confined within two labels of the standard form.
18118 The compiler uses the same form for labels within a function (but starting
18119 from nnnnn=00100); and places always a standard label at the beginning
18120 of a function, thus limiting the locality of labels within the scope of
18122 So, if the inline assembler part would be embedded into C-code, an improperly
18123 placed non-local label in the assembler would break up the reference space
18124 for labels created by the compiler for the C-code, leading to an assembling
18128 \begin_layout Standard
18129 The numeric part of local labels does not need to have 5 digits (although
18130 this is the form of labels output by the compiler), any valid integer will
18132 Please refer to the assemblers documentation for further details.
18140 \begin_layout Verse
18144 \begin_inset LatexCommand \index{\_asm}
18149 \begin_inset LatexCommand \index{\_\_asm}
18179 \begin_inset LatexCommand \index{\_endasm}
18184 \begin_inset LatexCommand \index{\_\_endasm}
18191 \begin_layout Standard
18192 Inline assembler code cannot reference any C-labels, however it can reference
18194 \begin_inset LatexCommand \index{Labels}
18198 defined by the inline assembler, e.g.:
18201 \begin_layout Verse
18224 ; some assembler code
18245 /* some more c code */
18247 clabel:\InsetSpace ~
18249 /* inline assembler cannot reference this
18254 \begin_layout Standard
18259 is translated by the compiler into a local label, so the locality of labels
18260 within the function is not broken.
18277 0003$: ;label (can be referenced by inline assembler only)
18284 \begin_inset LatexCommand \index{\_endasm}
18289 \begin_inset LatexCommand \index{\_\_endasm}
18299 /* some more c code */
18304 \begin_layout Standard
18305 In other words inline assembly code can access labels defined in inline
18306 assembly within the scope of the function.
18307 The same goes the other way, i.e.
18308 labels defines in inline assembly can not be accessed by C statements.
18311 \begin_layout Section
18312 Interfacing with Assembler Code
18313 \begin_inset LatexCommand \index{Assembler routines}
18320 \begin_layout Subsection
18321 Global Registers used for Parameter Passing
18322 \begin_inset LatexCommand \index{Parameter passing}
18329 \begin_layout Standard
18330 The compiler always uses the global registers
18333 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18338 \begin_inset LatexCommand \index{DPTR}
18343 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
18352 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
18358 to pass the first (non-bit) parameter to a function, and also to pass the
18360 \begin_inset LatexCommand \index{return value}
18364 of function; according to the following scheme: one byte return value in
18369 , two byte value in
18378 three byte values (generic pointers) in
18390 , and four byte values in
18408 \begin_inset LatexCommand \index{generic pointer}
18412 contain type of accessed memory in
18433 \begin_inset Note Note
18436 \begin_layout Standard
18437 This might not be the case of certain memory models (medium???)
18445 \begin_layout Standard
18446 The second parameter onwards is either allocated on the stack (for reentrant
18451 \begin_layout Standard
18460 -stack-auto is used) or in data/xdata memory (depending on the memory model).
18463 \begin_layout Standard
18464 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
18465 space for reentrant functions or allocated directly in bit memory otherwise.
18468 \begin_layout Standard
18469 Functions (with two or more parameters or bit parameters) that are called
18470 through function pointers
18471 \begin_inset LatexCommand \index{function pointers}
18475 must therefor be reentrant so the compiler knows how to pass the parameters.
18478 \begin_layout Subsection
18482 \begin_layout Standard
18483 Unless the called function is declared as
18488 \begin_inset LatexCommand \index{naked}
18496 \begin_layout Standard
18506 \begin_inset LatexCommand \index{-\/-callee-saves}
18514 \begin_layout Standard
18523 -all-callee-saves command line option or the corresponding callee_saves
18524 pragma are used, the caller will save the registers (
18528 ) around the call, so the called function can destroy they content freely.
18531 \begin_layout Standard
18532 If the called function is not declared as
18536 , the caller will swap register banks around the call, if caller and callee
18537 use different register banks (having them defined by the
18545 \begin_layout Standard
18546 The called function can also use
18562 observing that they are used for parameter/return value passing.
18565 \begin_layout Subsection
18566 Assembler Routine (non-reentrant)
18569 \begin_layout Standard
18570 In the following example
18571 \begin_inset LatexCommand \index{reentrant}
18576 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
18580 the function c_func calls an assembler routine asm_func, which takes two
18582 \begin_inset LatexCommand \index{function parameter}
18589 \begin_layout Verse
18592 extern int asm_func(unsigned char, unsigned char);
18596 int c_func (unsigned char
18597 i, unsigned char j)
18605 return asm_func(i,j);
18619 return c_func(10,9);
18624 \begin_layout Standard
18625 The corresponding assembler function is:
18628 \begin_layout Verse
18631 .globl _asm_func_PARM_2
18733 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18750 \begin_layout Standard
18751 The parameter naming convention is _<function_name>_PARM_<n>, where n is
18752 the parameter number starting from 1, and counting from the left.
18753 The first parameter is passed in
18769 according to the description above.
18770 The variable name for the second parameter will be _<function_name>_PARM_2.
18775 ble the assembler routine with the following command:
18782 asx8051 -losg asmfunc.asm
18789 Then compile and link the assembler routine to the C source file with the
18797 sdcc cfunc.c asmfunc.rel
18800 \begin_layout Subsection
18801 Assembler Routine (reentrant)
18804 \begin_layout Standard
18806 \begin_inset LatexCommand \index{reentrant}
18811 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18815 the second parameter
18816 \begin_inset LatexCommand \index{function parameter}
18820 onwards will be passed on the stack, the parameters are pushed from right
18822 before the call the second leftmost parameter will be on the top of the
18823 stack (the leftmost parameter is passed in registers).
18824 Here is an example:
18827 \begin_layout Verse
18830 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18835 c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
18844 return asm_func(i,j,k);
18858 return c_func(10,9,8);
18863 \begin_layout Standard
18864 The corresponding (unoptimized) assembler routine is:
18867 \begin_layout Verse
18887 _bp,sp\InsetSpace ~
18893 ;stack contains: _bp, return
18894 address, second parameter, third parameter
18918 a,#0xfd\InsetSpace ~
18924 pointer to the second parameter
18948 a,#0xfc\InsetSpace ~
18954 to the rightmost parameter
18995 result (= sum of all three parameters)
19010 ;return value goes into dptr
19044 \begin_layout Standard
19045 The compiling and linking procedure remains the same, however note the extra
19046 entry & exit linkage required for the assembler code, _bp is the stack
19047 frame pointer and is used to compute the offset into the stack for parameters
19048 and local variables.
19049 \begin_inset VSpace bigskip
19055 \begin_layout Section
19057 \begin_inset LatexCommand \index{int (16 bit)}
19062 \begin_inset LatexCommand \index{long (32 bit)}
19069 \begin_layout Standard
19070 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
19071 multiplication and modulus operations are implemented by support routines.
19072 These support routines are all developed in ANSI-C to facilitate porting
19073 to other MCUs, although some model specific assembler optimizations are
19075 The following files contain the described routines, all of them can be
19076 found in <installdir>/share/sdcc/lib.
19081 \begin_layout Standard
19083 \begin_inset Tabular
19084 <lyxtabular version="3" rows="11" columns="2">
19086 <column alignment="left" valignment="top" leftline="true" width="0">
19087 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19088 <row topline="true" bottomline="true">
19089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19092 \begin_layout Standard
19100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19103 \begin_layout Standard
19112 <row topline="true">
19113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19116 \begin_layout Standard
19122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19125 \begin_layout Standard
19126 16 bit multiplication
19132 <row topline="true">
19133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19136 \begin_layout Standard
19142 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19145 \begin_layout Standard
19146 signed 16 bit division (calls _divuint)
19152 <row topline="true">
19153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19156 \begin_layout Standard
19162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19165 \begin_layout Standard
19166 unsigned 16 bit division
19172 <row topline="true">
19173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19176 \begin_layout Standard
19182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19185 \begin_layout Standard
19186 signed 16 bit modulus (calls _moduint)
19192 <row topline="true">
19193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19196 \begin_layout Standard
19202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19205 \begin_layout Standard
19206 unsigned 16 bit modulus
19212 <row topline="true">
19213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19216 \begin_layout Standard
19222 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19225 \begin_layout Standard
19226 32 bit multiplication
19232 <row topline="true">
19233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19236 \begin_layout Standard
19242 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19245 \begin_layout Standard
19246 signed 32 division (calls _divulong)
19252 <row topline="true">
19253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19256 \begin_layout Standard
19262 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19265 \begin_layout Standard
19266 unsigned 32 division
19272 <row topline="true">
19273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19276 \begin_layout Standard
19282 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19285 \begin_layout Standard
19286 signed 32 bit modulus (calls _modulong)
19292 <row topline="true" bottomline="true">
19293 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19296 \begin_layout Standard
19302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19305 \begin_layout Standard
19306 unsigned 32 bit modulus
19321 \begin_layout Standard
19322 Since they are compiled as
19327 \begin_inset LatexCommand \index{reentrant}
19332 \begin_inset LatexCommand \index{interrupt}
19336 service routines should not do any of the above operations.
19337 If this is unavoidable then the above routines will need to be compiled
19344 \begin_layout Standard
19354 \begin_inset LatexCommand \index{-\/-stack-auto}
19360 option, after which the source program will have to be compiled with
19366 \begin_layout Standard
19376 \begin_inset LatexCommand \index{-\/-int-long-reent}
19383 Notice that you don't have to call these routines directly.
19384 The compiler will use them automatically every time an integer operation
19388 \begin_layout Section
19389 Floating Point Support
19390 \begin_inset LatexCommand \index{Floating point support}
19397 \begin_layout Standard
19398 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
19399 The floating point support routines are derived from gcc's floatlib.c and
19400 consist of the following routines:
19405 \begin_layout Standard
19409 \begin_inset Tabular
19410 <lyxtabular version="3" rows="17" columns="2">
19412 <column alignment="left" valignment="top" leftline="true" width="0">
19413 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19414 <row topline="true" bottomline="true">
19415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19418 \begin_layout Standard
19433 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19436 \begin_layout Standard
19443 <row topline="true">
19444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19447 \begin_layout Standard
19462 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19465 \begin_layout Standard
19475 add floating point numbers
19481 <row topline="true">
19482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19485 \begin_layout Standard
19500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19503 \begin_layout Standard
19513 subtract floating point numbers
19519 <row topline="true">
19520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19523 \begin_layout Standard
19538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19541 \begin_layout Standard
19551 divide floating point numbers
19557 <row topline="true">
19558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19561 \begin_layout Standard
19576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19579 \begin_layout Standard
19589 multiply floating point numbers
19595 <row topline="true">
19596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19599 \begin_layout Standard
19614 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19617 \begin_layout Standard
19627 convert floating point to unsigned char
19633 <row topline="true">
19634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19637 \begin_layout Standard
19652 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19655 \begin_layout Standard
19665 convert floating point to signed char
19671 <row topline="true">
19672 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19675 \begin_layout Standard
19690 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19693 \begin_layout Standard
19703 convert floating point to unsigned int
19709 <row topline="true">
19710 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19713 \begin_layout Standard
19728 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19731 \begin_layout Standard
19741 convert floating point to signed int
19747 <row topline="true">
19748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19751 \begin_layout Standard
19774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19777 \begin_layout Standard
19787 convert floating point to unsigned long
19793 <row topline="true">
19794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19797 \begin_layout Standard
19812 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19815 \begin_layout Standard
19825 convert floating point to signed long
19831 <row topline="true">
19832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19835 \begin_layout Standard
19850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19853 \begin_layout Standard
19863 convert unsigned char to floating point
19869 <row topline="true">
19870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19873 \begin_layout Standard
19888 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19891 \begin_layout Standard
19901 convert char to floating point number
19907 <row topline="true">
19908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19911 \begin_layout Standard
19926 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19929 \begin_layout Standard
19939 convert unsigned int to floating point
19945 <row topline="true">
19946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19949 \begin_layout Standard
19964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19967 \begin_layout Standard
19977 convert int to floating point numbers
19983 <row topline="true">
19984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19987 \begin_layout Standard
20002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20005 \begin_layout Standard
20015 convert unsigned long to floating point number
20021 <row topline="true" bottomline="true">
20022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20025 \begin_layout Standard
20040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20043 \begin_layout Standard
20053 convert long to floating point number
20068 \begin_layout Standard
20069 These support routines are developed in ANSI-C so there is room for space
20070 and speed improvement
20074 \begin_layout Standard
20075 These floating point routines (
20079 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
20086 Note if all these routines are used simultaneously the data space might
20088 For serious floating point usage the large model might be needed.
20089 Also notice that you don't have to call this routines directly.
20090 The compiler will use them automatically every time a floating point operation
20092 \begin_inset VSpace bigskip
20098 \begin_layout Section
20100 \begin_inset LatexCommand \index{Libraries}
20107 \begin_layout Standard
20110 <pending: this is messy and incomplete - a little more information is in
20111 sdcc/doc/libdoc.txt
20116 \begin_layout Subsection
20117 Compiler support routines (_gptrget, _mulint etc.)
20120 \begin_layout Subsection
20121 Stdclib functions (puts, printf, strcat etc.)
20124 \begin_layout Subsubsection
20128 \begin_layout Paragraph
20129 getchar(), putchar()
20132 \begin_layout Standard
20133 \begin_inset LatexCommand \index{<stdio.h>}
20137 As usual on embedded systems you have to provide your own
20140 \begin_inset LatexCommand \index{getchar()}
20149 \begin_inset LatexCommand \index{putchar()}
20156 SDCC does not know whether the system connects to a serial line with or
20157 without handshake, LCD, keyboard or other device.
20171 You'll find examples for serial routines f.e.
20172 in sdcc/device/lib.
20173 For the mcs51 this minimalistic polling
20177 routine might be a start:
20180 \begin_layout Verse
20183 void putchar (char c) {
20189 while (!TI)\InsetSpace ~
20192 /* assumes UART is initialized */
20220 \begin_layout Paragraph
20224 \begin_layout Standard
20228 \begin_inset LatexCommand \index{printf()}
20238 does not support float (except on ds390).
20239 To enable this recompile it with the option
20245 \begin_layout Standard
20255 \begin_inset LatexCommand \index{USE\_FLOATS}
20261 on the command line.
20268 \begin_layout Standard
20278 \begin_inset LatexCommand \index{-\/-model-large}
20284 for the mcs51 port, since this uses a lot of memory.
20287 \begin_layout Standard
20288 If you're short on code memory you might want to use
20291 \begin_inset LatexCommand \index{printf\_small()}
20306 For the mcs51 there additionally are assembly versions
20309 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
20315 (subset of printf using less than 270 bytes) and
20318 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
20327 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
20333 (floating-point aware version of printf_fast) which should fit the requirements
20334 of many embedded systems (printf_fast() can be customized by unsetting
20339 support long variables and field widths).
20340 Be sure to use only one of these printf options within a project.
20345 \begin_layout Standard
20346 Feature matrix of different
20353 \begin_layout Standard
20354 \begin_inset Tabular
20355 <lyxtabular version="3" rows="14" columns="7">
20356 <features islongtable="true">
20357 <column alignment="left" valignment="middle" leftline="true" width="14col%">
20358 <column alignment="center" valignment="top" leftline="true" width="0">
20359 <column alignment="center" valignment="top" leftline="true" width="12col%">
20360 <column alignment="center" valignment="top" leftline="true" width="10col%">
20361 <column alignment="center" valignment="top" leftline="true" width="0">
20362 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
20363 <column alignment="center" valignment="top" rightline="true" width="0">
20364 <row topline="true" bottomline="true" endhead="true">
20365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20368 \begin_layout Standard
20377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20380 \begin_layout Standard
20382 \begin_inset LatexCommand \index{printf}
20391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20394 \begin_layout Standard
20402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20405 \begin_layout Standard
20411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20414 \begin_layout Standard
20420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20423 \begin_layout Standard
20429 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20432 \begin_layout Standard
20439 <row topline="true" endhead="true">
20440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20443 \begin_layout Standard
20449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20452 \begin_layout Standard
20460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20463 \begin_layout Standard
20471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20474 \begin_layout Standard
20482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20485 \begin_layout Standard
20493 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20496 \begin_layout Standard
20504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20507 \begin_layout Standard
20516 <row topline="true" endhead="true">
20517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20520 \begin_layout Standard
20521 \begin_inset Quotes sld
20525 \begin_inset Quotes srd
20531 \begin_layout Standard
20537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20540 \begin_layout Standard
20546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20549 \begin_layout Standard
20555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20558 \begin_layout Standard
20564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20567 \begin_layout Standard
20573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20576 \begin_layout Standard
20582 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20585 \begin_layout Standard
20592 <row topline="true" endhead="true">
20593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20596 \begin_layout Standard
20600 \begin_layout Standard
20606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20609 \begin_layout Standard
20615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20618 \begin_layout Standard
20624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20627 \begin_layout Standard
20628 0.45k / 0.47k (+ _ltoa)
20633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20636 \begin_layout Standard
20642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20645 \begin_layout Standard
20651 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20654 \begin_layout Standard
20661 <row topline="true">
20662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20665 \begin_layout Standard
20671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20674 \begin_layout Standard
20684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20687 \begin_layout Standard
20734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20737 \begin_layout Standard
20776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20779 \begin_layout Standard
20785 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20788 \begin_layout Standard
20794 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20797 \begin_layout Standard
20804 <row topline="true">
20805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20808 \begin_layout Standard
20809 long (32 bit) support
20814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20817 \begin_layout Standard
20823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20826 \begin_layout Standard
20832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20835 \begin_layout Standard
20841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20844 \begin_layout Standard
20850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20853 \begin_layout Standard
20868 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20871 \begin_layout Standard
20878 <row topline="true">
20879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20882 \begin_layout Standard
20883 byte arguments on stack
20888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20891 \begin_layout Standard
20897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20900 \begin_layout Standard
20906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20909 \begin_layout Standard
20915 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20918 \begin_layout Standard
20924 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20927 \begin_layout Standard
20933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20936 \begin_layout Standard
20943 <row topline="true">
20944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20947 \begin_layout Standard
20949 \begin_inset LatexCommand \index{Floating point support}
20958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20961 \begin_layout Standard
20967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20970 \begin_layout Standard
20976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20979 \begin_layout Standard
20985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20988 \begin_layout Standard
20994 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20997 \begin_layout Standard
21002 \begin_layout Standard
21003 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
21013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21016 \begin_layout Standard
21023 <row topline="true">
21024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21027 \begin_layout Standard
21028 float formats %e %g
21033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21036 \begin_layout Standard
21042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21045 \begin_layout Standard
21051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21054 \begin_layout Standard
21060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21063 \begin_layout Standard
21069 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21072 \begin_layout Standard
21078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21081 \begin_layout Standard
21088 <row topline="true" bottomline="true">
21089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21092 \begin_layout Standard
21098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21101 \begin_layout Standard
21107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21110 \begin_layout Standard
21116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21119 \begin_layout Standard
21125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21128 \begin_layout Standard
21134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21137 \begin_layout Standard
21143 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21146 \begin_layout Standard
21153 <row bottomline="true">
21154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21157 \begin_layout Standard
21162 \begin_layout Standard
21163 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
21167 n'); standard 8051 @ 22.1184 MHz, empty putchar()
21175 \begin_layout Standard
21181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21184 \begin_layout Standard
21190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21193 \begin_layout Standard
21199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21202 \begin_layout Standard
21208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21211 \begin_layout Standard
21217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21220 \begin_layout Standard
21226 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21229 \begin_layout Standard
21236 <row bottomline="true">
21237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21240 \begin_layout Standard
21245 \begin_layout Standard
21246 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
21255 \begin_layout Standard
21261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21264 \begin_layout Standard
21270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21273 \begin_layout Standard
21279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21282 \begin_layout Standard
21288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21291 \begin_layout Standard
21297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21300 \begin_layout Standard
21306 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21309 \begin_layout Standard
21314 \begin_layout Standard
21315 printf_tiny integer speed is data dependent, worst case is 0.33 ms
21326 <row bottomline="true">
21327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21330 \begin_layout Standard
21335 \begin_layout Standard
21336 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
21345 \begin_layout Standard
21351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21354 \begin_layout Standard
21360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21363 \begin_layout Standard
21369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21372 \begin_layout Standard
21378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21381 \begin_layout Standard
21387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21390 \begin_layout Standard
21396 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21399 \begin_layout Standard
21406 <row bottomline="true">
21407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21410 \begin_layout Standard
21415 \begin_layout Standard
21416 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
21425 \begin_layout Standard
21431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21434 \begin_layout Standard
21440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21443 \begin_layout Standard
21449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21452 \begin_layout Standard
21458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21461 \begin_layout Standard
21467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21470 \begin_layout Standard
21476 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21479 \begin_layout Standard
21493 \begin_layout Subsubsection
21495 \begin_inset LatexCommand \index{malloc.h}
21502 \begin_layout Standard
21503 As of SDCC 2.6.2 you no longer need to call an initialization routine before
21504 using dynamic memory allocation
21505 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
21510 \begin_inset LatexCommand \index{heap (malloc)}
21514 space of 1024 bytes is provided for malloc to allocate memory from.
21515 If you need a different heap size you need to recompile _heap.c with the
21516 required size defined in HEAP_SIZE.
21517 It is recommended to make a copy of this file into your project directory
21518 and compile it there with:
21521 \begin_layout Verse
21524 sdcc -c _heap.c -D HEAD_SIZE=2048
21527 \begin_layout Standard
21528 And then link it with:
21531 \begin_layout Verse
21534 sdcc main.rel _heap.rel
21537 \begin_layout Subsection
21538 Math functions (sinf, powf, sqrtf etc.)
21541 \begin_layout Subsubsection
21545 \begin_layout Standard
21546 See definitions in file <math.h>.
21549 \begin_layout Subsection
21553 \begin_layout Standard
21555 \begin_inset LatexCommand \index{Libraries}
21559 included in SDCC should have a license at least as liberal as the GNU Lesser
21560 General Public License
21561 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
21572 \begin_layout Standard
21573 \begin_inset Note Note
21576 \begin_layout Standard
21577 license statements for the libraries are missing.
21578 sdcc/device/lib/ser_ir.c
21581 \begin_layout Standard
21583 come with a GPL (as opposed to LGPL) License - this will not be liberal
21584 enough for many embedded programmers.
21592 \begin_layout Standard
21593 If you have ported some library or want to share experience about some code
21595 falls into any of these categories Busses (I
21596 \begin_inset Formula $^{\textrm{2}}$
21599 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
21600 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
21601 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
21602 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
21607 would certainly like to hear about it.
21610 \begin_layout Standard
21611 Programmers coding for embedded systems are not especially famous for being
21612 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
21613 e these references are very valuable.
21614 Let's help to create a climate where information is shared.
21615 \begin_inset VSpace bigskip
21621 \begin_layout Section
21625 \begin_layout Subsection
21626 MCS51 Memory Models
21627 \begin_inset LatexCommand \index{Memory model}
21632 \begin_inset LatexCommand \index{MCS51 memory model}
21639 \begin_layout Subsubsection
21640 Small, Medium and Large
21643 \begin_layout Standard
21644 SDCC allows three memory models for MCS51 code,
21653 Modules compiled with different memory models should
21657 be combined together or the results would be unpredictable.
21658 The library routines supplied with the compiler are compiled as small,
21660 The compiled library modules are contained in separate directories as small,
21661 medium and large so that you can link to the appropriate set.
21664 \begin_layout Standard
21665 When the medium or large model is used all variables declared without a
21666 storage class will be allocated into the external ram, this includes all
21667 parameters and local variables (for non-reentrant
21668 \begin_inset LatexCommand \index{reentrant}
21673 When the small model is used variables without storage class are allocated
21674 in the internal ram.
21677 \begin_layout Standard
21678 Judicious usage of the processor specific storage classes
21679 \begin_inset LatexCommand \index{Storage class}
21683 and the 'reentrant' function type will yield much more efficient code,
21684 than using the large model.
21685 Several optimizations are disabled when the program is compiled using the
21686 large model, it is therefore recommended that the small model be used unless
21687 absolutely required.
21690 \begin_layout Subsubsection
21692 \begin_inset LatexCommand \label{sub:External-Stack}
21697 \begin_inset LatexCommand \index{stack}
21702 \begin_inset LatexCommand \index{External stack (mcs51)}
21709 \begin_layout Standard
21710 The external stack (-
21714 \begin_layout Standard
21724 \begin_inset LatexCommand \index{-\/-xstack}
21728 ) is located in pdata
21729 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
21733 memory (usually at the start of the external ram segment) and uses all
21734 unused space in pdata (max.
21740 \begin_layout Standard
21749 -xstack option is used to compile the program, the parameters and local
21751 \begin_inset LatexCommand \index{local variables}
21755 of all reentrant functions are allocated in this area.
21756 This option is provided for programs with large stack space requirements.
21757 When used with the -
21761 \begin_layout Standard
21771 \begin_inset LatexCommand \index{-\/-stack-auto}
21775 option, all parameters and local variables are allocated on the external
21776 stack (note: support libraries will need to be recompiled with the same
21778 There is a predefined target in the library makefile).
21781 \begin_layout Standard
21782 The compiler outputs the higher order address byte of the external ram segment
21784 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21789 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21793 ), therefore when using the External Stack option, this port
21797 be used by the application program.
21800 \begin_layout Subsection
21802 \begin_inset LatexCommand \index{Memory model}
21807 \begin_inset LatexCommand \index{DS390 memory model}
21814 \begin_layout Standard
21815 The only model supported is Flat 24
21816 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21821 This generates code for the 24 bit contiguous addressing mode of the Dallas
21823 In this mode, up to four meg of external RAM or code space can be directly
21825 See the data sheets at www.dalsemi.com for further information on this part.
21830 that the compiler does not generate any code to place the processor into
21831 24 bitmode (although
21835 in the ds390 libraries will do that for you).
21841 \begin_inset LatexCommand \index{Tinibios (DS390)}
21845 , the boot loader or similar code must ensure that the processor is in 24
21846 bit contiguous addressing mode before calling the SDCC startup code.
21857 \begin_layout Standard
21868 option, variables will by default be placed into the XDATA segment.
21873 Segments may be placed anywhere in the 4 meg address space using the usual
21878 \begin_layout Standard
21888 Note that if any segments are located above 64K, the -r flag must be passed
21889 to the linker to generate the proper segment relocations, and the Intel
21890 HEX output format must be used.
21891 The -r flag can be passed to the linker by using the option
21895 on the SDCC command line.
21896 However, currently the linker can not handle code segments > 64k.
21899 \begin_layout Section
21901 \begin_inset LatexCommand \label{sec:Pragmas}
21906 \begin_inset LatexCommand \index{Pragmas}
21913 \begin_layout Standard
21914 Pragmas are used to turn on and/or off certain compiler options.
21915 Some of them are closely related to corresponding command-line options
21917 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21923 Pragmas should be placed before and/or after a function, placing pragmas
21924 inside a function body could have unpredictable results.
21929 following #pragma directives:
21932 \begin_layout Itemize
21938 \begin_inset LatexCommand \index{\#pragma save}
21942 - this will save most current options to the save/restore stack.
21943 See #pragma\InsetSpace ~
21947 \begin_layout Itemize
21953 \begin_inset LatexCommand \index{\#pragma restore}
21957 - will restore saved options from the last save.
21958 saves & restores can be nested.
21959 SDCC uses a save/restore stack: save pushes current options to the stack,
21960 restore pulls current options from the stack.
21961 See #pragma\InsetSpace ~
21967 \begin_layout Itemize
21973 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21978 \begin_inset LatexCommand \index{function prologue}
21982 function1[,function2[,function3...]]
21983 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21987 - The compiler by default uses a caller saves convention for register saving
21988 across function calls, however this can cause unnecessary register pushing
21990 \begin_inset LatexCommand \index{push/pop}
21994 when calling small functions from larger functions.
21995 This option can be used to switch off the register saving convention for
21996 the function names specified.
21997 The compiler will not save registers when calling these functions, extra
21998 code need to be manually inserted at the entry and exit for these functions
21999 to save and restore the registers used by these functions, this can SUBSTANTIAL
22000 LY reduce code and improve run time performance of the generated code.
22001 In the future the compiler (with inter procedural analysis) may be able
22002 to determine the appropriate scheme to use for each function call.
22007 \begin_layout Standard
22016 -callee-saves command line option is used (see page
22017 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
22021 ), the function names specified in #pragma\InsetSpace ~
22023 \begin_inset LatexCommand \index{\#pragma callee\_saves}
22027 is appended to the list of functions specified in the command line.
22030 \begin_layout Itemize
22036 \begin_inset LatexCommand \index{\#pragma exclude}
22040 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
22041 of pairs of push/pop
22042 \begin_inset LatexCommand \index{push/pop}
22051 \begin_inset LatexCommand \index{interrupt}
22064 The directive should be placed immediately before the ISR function definition
22065 and it affects ALL ISR functions following it.
22066 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
22067 exclude\InsetSpace ~
22069 \begin_inset LatexCommand \index{\#pragma exclude}
22074 See also the related keyword _naked
22075 \begin_inset LatexCommand \index{\_naked}
22080 \begin_inset LatexCommand \index{\_\_naked}
22087 \begin_layout Itemize
22093 \begin_inset LatexCommand \index{pedantic}
22098 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
22103 \begin_inset LatexCommand \label{ite:less_pedantic}
22107 - the compiler will not warn you anymore for obvious mistakes, you're on
22109 See also the command line option -
22113 \begin_layout Standard
22123 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
22130 More specifically, the following warnings will be disabled:
22132 comparison is always [true/false] due to limited range of data type
22136 overflow in implicit constant conversion
22138 (158); [the (in)famous]
22140 conditional flow changed by optimizer: so said EVELYN the modified DOG
22144 function '[function name]' must return value
22149 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
22150 level) are disabled, too, namely:
22153 \begin_inset Note Note
22156 \begin_layout Standard
22157 dunno what comes here - this warning appears to be unused altogether
22166 [left/right] shifting more than size of object changed to zero
22174 integer overflow in expression
22178 unmatched #pragma save and #pragma restore
22182 comparison of 'signed char' with 'unsigned char' requires promotion to int
22186 ISO C90 does not support flexible array members
22190 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
22194 \begin_inset Note Note
22197 \begin_layout Standard
22198 appears to be always blank - what was supposed to be here?
22207 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
22208 complexity [number]
22213 \begin_layout Itemize
22219 \begin_inset LatexCommand \index{\#pragma disable\_warning}
22223 - the compiler will not warn you anymore about warning number <nnnn>.
22226 \begin_layout Itemize
22232 \begin_inset LatexCommand \index{\#pragma nogcse}
22236 - will stop global common subexpression elimination.
22239 \begin_layout Itemize
22245 \begin_inset LatexCommand \index{\#pragma noinduction}
22249 - will stop loop induction optimizations.
22252 \begin_layout Itemize
22258 \begin_inset LatexCommand \index{\#pragma noinvariant}
22262 - will not do loop invariant optimizations.
22263 For more details see Loop Invariants in section
22264 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
22271 \begin_layout Itemize
22277 \begin_inset LatexCommand \index{\#pragma noiv}
22281 - Do not generate interrupt
22282 \begin_inset LatexCommand \index{interrupt}
22287 \begin_inset LatexCommand \index{interrupt vector table}
22291 entries for all ISR functions defined after the pragma.
22292 This is useful in cases where the interrupt vector table must be defined
22293 manually, or when there is a secondary, manually defined interrupt vector
22295 for the autovector feature of the Cypress EZ-USB FX2).
22296 More elegantly this can be achieved by obmitting the optional interrupt
22297 number after the interrupt keyword, see section
22298 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
22306 \begin_layout Itemize
22312 \begin_inset LatexCommand \index{\#pragma nojtbound}
22316 - will not generate code for boundary value checking, when switch statements
22317 are turned into jump-tables (dangerous).
22318 For more details see section
22319 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
22326 \begin_layout Itemize
22332 \begin_inset LatexCommand \index{\#pragma noloopreverse}
22336 - Will not do loop reversal optimization
22339 \begin_layout Itemize
22345 \begin_inset LatexCommand \index{\#pragma nooverlay}
22349 - the compiler will not overlay the parameters and local variables of a
22353 \begin_layout Itemize
22359 \begin_inset LatexCommand \index{\#pragma stackauto}
22367 \begin_layout Standard
22377 \begin_inset LatexCommand \index{-\/-stack-auto}
22382 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
22386 Parameters and Local Variables.
22389 \begin_layout Itemize
22395 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
22399 - The compiler will optimize code generation towards fast code, possibly
22400 at the expense of code size.
22401 Currently this has little effect.
22404 \begin_layout Itemize
22410 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
22414 - The compiler will optimize code generation towards compact code, possibly
22415 at the expense of code speed.
22416 Currently this has little effect.
22419 \begin_layout Itemize
22425 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
22429 - The compiler will attempt to generate code that is both compact and fast,
22430 as long as meeting one goal is not a detriment to the other (this is the
22435 \begin_layout Itemize
22441 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
22445 - Generally follow the C89 standard, but allow SDCC features that conflict
22446 with the standard (default).
22449 \begin_layout Itemize
22455 \begin_inset LatexCommand \index{\#pragma std\_c89}
22459 - Follow the C89 standard and disable SDCC features that conflict with the
22463 \begin_layout Itemize
22469 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
22473 - Generally follow the C99 standard, but allow SDCC features that conflict
22474 with the standard (incomplete support).
22477 \begin_layout Itemize
22483 \begin_inset LatexCommand \index{\#pragma std\_c99}
22487 - Follow the C99 standard and disable SDCC features that conflict with the
22488 standard (incomplete support).
22491 \begin_layout Itemize
22497 \begin_inset LatexCommand \index{\#pragma codeseg}
22501 - Use this name (max.
22502 8 characters) for the code segment.
22507 \begin_layout Standard
22519 \begin_layout Itemize
22525 \begin_inset LatexCommand \index{\#pragma constseg}
22529 - Use this name (max.
22530 8 characters) for the const segment.
22535 \begin_layout Standard
22547 \begin_layout Standard
22548 The preprocessor SDCPP
22549 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
22553 supports the following #pragma directives:
22556 \begin_layout Itemize
22559 pedantic_parse_number
22562 \begin_inset LatexCommand \index{pedantic}
22567 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22572 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
22576 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
22577 properly and the macro LO_B(3) gets expanded.
22583 \begin_layout Standard
22592 -pedantic-parse-number command line option
22593 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
22600 Below is an example on how to use this pragma.
22603 Note: this functionality is not in conformance with standard!
22606 \begin_layout Verse
22609 #pragma pedantic_parse_number +
22610 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22618 #define LO_B(x) ((x) & 0xff)
22622 unsigned char foo(void)
22629 unsigned char c=0xfe-LO_B(3)
22644 \begin_layout Itemize
22650 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22654 (+ | -) - switch _asm _endasm block preprocessing on / off.
22656 You use this prama to define multilines of assembly code.
22657 This will prevent the preprocessor from changing the formating required
22659 Below is an example on how to use this pragma.
22662 \begin_layout Verse
22665 #pragma preproc_asm -
22666 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22672 #define MYDELAY _asm
22677 nop ;my assembly comment...
22691 #pragma preproc_asm
22722 \begin_layout Itemize
22728 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22732 (+ | -) - Allow "naked" hash in macro definition, for example:
22736 #define DIR_LO(x) #(x & 0xff)
22741 Below is an example on how to use this pragma.
22744 \begin_layout Verse
22747 #pragma preproc_asm +
22749 #pragma sdcc_hash +
22750 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22765 mov R6_B3, #(x & 0xff)
22772 mov R7_B3, #((x >> 8) & 0xff)
22796 \begin_layout Standard
22797 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22798 ons which might cause the compiler to generate extra stack and/or data space
22799 to store compiler generated temporary variables.
22800 This usually happens in large functions.
22801 Pragma directives should be used as shown in the following example, they
22802 are used to control options and optimizations for a given function.
22806 \begin_layout Verse
22810 \begin_inset LatexCommand \index{\#pragma save}
22821 /* save the current settings */
22824 \begin_inset LatexCommand \index{\#pragma nogcse}
22833 /* turnoff global subexpression elimination */
22835 #pragma noinduction
22836 \begin_inset LatexCommand \index{\#pragma noinduction}
22840 /* turn off induction optimizations */
22863 \begin_inset LatexCommand \index{\#pragma restore}
22867 /* turn the optimizations back on */
22870 \begin_layout Standard
22871 The compiler will generate a warning message when extra space is allocated.
22872 It is strongly recommended that the save and restore pragmas be used when
22873 changing options for a function.
22882 \begin_layout Section
22883 Defines Created by the Compiler
22886 \begin_layout Standard
22887 The compiler creates the following #defines
22888 \begin_inset LatexCommand \index{\#defines}
22893 \begin_inset LatexCommand \index{Defines created by the compiler}
22902 \begin_layout Standard
22903 \begin_inset Tabular
22904 <lyxtabular version="3" rows="15" columns="2">
22906 <column alignment="left" valignment="top" leftline="true" width="3in">
22907 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22908 <row topline="true" bottomline="true">
22909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22912 \begin_layout Standard
22920 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22923 \begin_layout Standard
22932 <row topline="true">
22933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22936 \begin_layout Standard
22938 \begin_inset LatexCommand \index{SDCC}
22947 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22950 \begin_layout Standard
22952 Since version 2.5.6 the version number as an int (ex.
22959 <row topline="true">
22960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22963 \begin_layout Standard
22965 \begin_inset LatexCommand \index{SDCC\_mcs51}
22970 \begin_inset LatexCommand \index{SDCC\_ds390}
22975 \begin_inset LatexCommand \index{SDCC\_z80}
22984 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22987 \begin_layout Standard
22988 depending on the model used (e.g.: -mds390)
22994 <row topline="true">
22995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22998 \begin_layout Standard
23000 \begin_inset LatexCommand \index{\_\_mcs51}
23005 \begin_inset LatexCommand \index{\_\_ds390}
23010 \begin_inset LatexCommand \index{\_\_hc08}
23015 \begin_inset LatexCommand \index{\_\_z80}
23024 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23027 \begin_layout Standard
23028 depending on the model used (e.g.
23035 <row topline="true">
23036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23039 \begin_layout Standard
23041 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
23050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23053 \begin_layout Standard
23060 \begin_layout Standard
23077 <row topline="true">
23078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23081 \begin_layout Standard
23083 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
23092 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23095 \begin_layout Standard
23102 \begin_layout Standard
23119 <row topline="true">
23120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23123 \begin_layout Standard
23125 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
23134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23137 \begin_layout Standard
23144 \begin_layout Standard
23161 <row topline="true">
23162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23165 \begin_layout Standard
23167 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
23176 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23179 \begin_layout Standard
23186 \begin_layout Standard
23203 <row topline="true">
23204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23207 \begin_layout Standard
23209 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
23218 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23221 \begin_layout Standard
23228 \begin_layout Standard
23245 <row topline="true">
23246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23249 \begin_layout Standard
23251 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
23260 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23263 \begin_layout Standard
23274 <row topline="true">
23275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23278 \begin_layout Standard
23280 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23292 \begin_layout Standard
23303 <row topline="true">
23304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23307 \begin_layout Standard
23309 \begin_inset LatexCommand \index{SDCC\_REVISION}
23318 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23321 \begin_layout Standard
23323 SDCC svn revision number
23329 <row topline="true">
23330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23333 \begin_layout Standard
23334 SDCC_PARMS_IN_BANK1
23335 \begin_inset LatexCommand \index{SDCC\_PARMS\_IN\_BANK1}
23344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23347 \begin_layout Standard
23354 \begin_layout Standard
23371 <row topline="true">
23372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23375 \begin_layout Standard
23377 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23386 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23389 \begin_layout Standard
23396 \begin_layout Standard
23413 <row topline="true" bottomline="true">
23414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23417 \begin_layout Standard
23418 SDCC_INT_LONG_REENT
23419 \begin_inset LatexCommand \index{SDCC\_INT\_LONG\_REENT}
23428 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23431 \begin_layout Standard
23438 \begin_layout Standard
23462 \begin_layout Chapter
23463 Notes on supported Processors
23466 \begin_layout Section
23468 \begin_inset LatexCommand \label{sub:MCS51-variants}
23473 \begin_inset LatexCommand \index{MCS51 variants}
23480 \begin_layout Standard
23481 MCS51 processors are available from many vendors and come in many different
23483 While they might differ considerably in respect to Special Function Registers
23484 the core MCS51 is usually not modified or is kept compatible.
23488 \begin_layout Subsection
23489 pdata access by SFR
23492 \begin_layout Standard
23493 With the upcome of devices with internal xdata and flash memory devices
23495 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
23499 as dedicated I/O port is becoming more popular.
23500 Switching the high byte for pdata
23501 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
23505 access which was formerly done by port P2 is then achieved by a Special
23507 \begin_inset LatexCommand \index{sfr}
23512 In well-established MCS51 tradition the address of this
23516 is where the chip designers decided to put it.
23517 Needless to say that they didn't agree on a common name either.
23518 So that the startup code can correctly initialize xdata variables, you
23519 should define an sfr with the name _XPAGE
23522 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
23528 at the appropriate location if the default, port P2, is not used for this.
23532 \begin_layout Verse
23535 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
23539 \begin_layout Verse
23542 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
23547 \begin_layout Verse
23550 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
23554 \begin_layout Verse
23557 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23561 \begin_layout Verse
23564 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23568 \begin_layout Standard
23569 For more exotic implementations further customizations may be needed.
23571 \begin_inset LatexCommand \ref{sub:Startup-Code}
23575 for other possibilities.
23578 \begin_layout Subsection
23579 Other Features available by SFR
23582 \begin_layout Standard
23583 Some MCS51 variants offer features like Double DPTR
23584 \begin_inset LatexCommand \index{DPTR}
23588 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
23589 These are currently not used for the MCS51 port.
23590 If you absolutely need them you can fall back to inline assembly or submit
23594 \begin_layout Subsection
23598 \begin_layout Standard
23600 \begin_inset LatexCommand \index{Bankswitching}
23606 \begin_inset LatexCommand \index{code banking}
23610 ) is a technique to increase the code space above the 64k limit of the 8051.
23613 \begin_layout Subsubsection
23617 \begin_layout Standard
23618 \begin_inset Tabular
23619 <lyxtabular version="3" rows="3" columns="4">
23621 <column alignment="center" valignment="top" width="0">
23622 <column alignment="center" valignment="top" leftline="true" width="0">
23623 <column alignment="center" valignment="top" leftline="true" width="0">
23624 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23625 <row topline="true" bottomline="true">
23626 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23629 \begin_layout Standard
23635 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23638 \begin_layout Standard
23644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23647 \begin_layout Standard
23653 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23656 \begin_layout Standard
23663 <row topline="true" bottomline="true">
23664 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23667 \begin_layout Standard
23673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23676 \begin_layout Standard
23682 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23685 \begin_layout Standard
23691 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23694 \begin_layout Standard
23702 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23705 \begin_layout Standard
23706 SiLabs C8051F120 example
23711 <cell multicolumn="2" alignment="center" valignment="top" usebox="none">
23714 \begin_layout Standard
23720 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23723 \begin_layout Standard
23729 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23732 \begin_layout Standard
23747 Usually the hardware uses some sfr (an output port or an internal sfr) to
23748 select a bank and put it in the banked area of the memory map.
23749 The selected bank usually becomes active immediately upon assignment to
23750 this sfr and when running inside a bank it will switch out this code it
23751 is currently running.
23752 Therefor you cannot jump or call directly from one bank to another and
23753 need to use a so-called trampoline in the common area.
23754 For SDCC an example trampoline is in crtbank.asm and you may need to change
23755 it to your 8051 derivative or schematic.
23756 The presented code is written for the C8051F120.
23760 When calling a banked function
23761 SDCC will put the LSB of the functions address in register R0, the MSB
23762 in R1 and the bank in R2 and then call this trampoline
23767 The current selected bank is saved on the stack, the new bank is selected
23768 and an indirect jump is made.
23769 When the banked function returns it jumps to
23773 which restores the previous bank and returns to the caller.
23776 \begin_layout Subsubsection
23780 \begin_layout Standard
23781 When writing banked software using SDCC you need to use some special keywords
23783 You also need to take over a bit of work from the linker.
23787 To create a function
23788 that can be called from another bank it requires the keyword
23793 \begin_inset LatexCommand \index{banked}
23798 The caller must see this in the prototype of the callee and the callee
23799 needs it for a proper return.
23800 Called functions within the same bank as the caller do not need the
23804 keyword nor do functions in the common area.
23805 Beware: SDCC does not know or check if functions are in the same bank.
23806 This is your responsibility!
23810 Normally all functions you write end up in
23812 If you want a function explicitly to reside in the common area put it in
23814 This applies for instance to interrupt service routines as they should
23818 \begin_layout Standard
23819 Functions that need to be in a switched bank must be put in a named segment.
23820 The name can be mostly anything upto eight characters (e.g.
23822 To do this you either use -
23826 \begin_layout Standard
23835 -codeseg BANK1 (See
23836 \begin_inset LatexCommand \ref{lyx:-codeseg}
23840 ) on the command line when compiling or #pragma codeseg BANK1 (See
23841 \begin_inset LatexCommand \ref{sec:Pragmas}
23845 ) at the top of the C source file.
23846 The segment name always applies to the whole source file and generated
23847 object so functions for different banks need to be defined in different
23852 When linking your objects you need to tell the linker where
23853 to put your segments.
23854 To do this you use the following command line option to SDCC: -Wl-b BANK1=0x180
23856 \begin_inset LatexCommand \ref{lyx:-Wl option}
23861 This sets the virtual start address of this segment.
23862 It sets the banknumber to 0x01 and maps the bank to 0x8000 and up.
23863 The linker will not check for overflows, again this is your responsibility.
23866 \begin_layout Standard
23867 \begin_inset VSpace bigskip
23873 \begin_layout Section
23877 \begin_layout Standard
23879 \begin_inset LatexCommand \index{DS80C400}
23884 \begin_inset LatexCommand \index{DS400}
23888 microcontroller has a rich set of peripherals.
23889 In its built-in ROM library it includes functions to access some of the
23890 features, among them is a TCP stack with IP4 and IP6 support.
23891 Library headers (currently in beta status) and other files are provided
23895 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
23901 \begin_inset VSpace bigskip
23907 \begin_layout Section
23908 The Z80 and gbz80 port
23911 \begin_layout Standard
23912 SDCC can target both the Zilog Z80
23913 \begin_inset LatexCommand \index{Z80}
23917 and the Nintendo Gameboy's Z80-like gbz80
23918 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
23923 The Z80 port is passed through the same
23926 \begin_inset LatexCommand \index{Regression test}
23933 \begin_inset LatexCommand \ref{sec:Quality-control}
23937 ) as the MCS51 and DS390 ports, so floating point support, support for long
23938 variables and bitfield support is fine.
23939 See mailing lists and forums about interrupt routines.
23942 \begin_layout Standard
23943 As always, the code is the authoritative reference - see z80/ralloc.c and
23946 \begin_inset LatexCommand \index{Z80!stack}
23950 frame is similar to that generated by the IAR Z80 compiler.
23951 IX is used as the base pointer, HL and IY are used as a temporary registers,
23952 and BC and DE are available for holding variables.
23954 \begin_inset LatexCommand \index{Z80!return value}
23958 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
23960 The gbz80 port use the same set of registers for the return values, but
23961 in a different order of significance: E (one byte), DE (two bytes), or
23963 \begin_inset VSpace bigskip
23969 \begin_layout Section
23973 \begin_layout Standard
23974 The port to the Freescale/Motorola HC08
23975 \begin_inset LatexCommand \index{HC08}
23979 family has been added in October 2003, and is still undergoing some basic
23981 The code generator is complete, but the register allocation is still quite
23983 Some of the SDCC's standard C library functions have embedded non-HC08
23984 inline assembly and so are not yet usable.
23987 \begin_layout Standard
23988 The HC08 port passes the regression test suite (see section
23989 \begin_inset LatexCommand \ref{sec:Quality-control}
23994 \begin_inset VSpace bigskip
24000 \begin_layout Section
24002 \begin_inset LatexCommand \index{PIC14}
24009 \begin_layout Standard
24010 The PIC14 port adds support for Microchip
24011 \begin_inset LatexCommand \index{Microchip}
24016 \begin_inset Formula $^{\text{TM}}$
24020 \begin_inset LatexCommand \index{PIC14}
24025 \begin_inset Formula $^{\text{TM}}$
24028 MCUs with 14 bit wide instructions.
24029 This port is not yet mature and still lacks many features.
24030 However, it can work for simple code.
24033 \begin_layout Standard
24035 Currently supported devices include:
24038 \begin_layout Standard
24039 12F: 629, 635, 675, 683
24042 \begin_layout Standard
24046 \begin_layout Standard
24050 \begin_layout Standard
24051 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
24054 \begin_layout Standard
24055 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
24059 \begin_layout Standard
24063 \begin_layout Standard
24064 16CR: 620a, 73, 74, 76, 77
24067 \begin_layout Standard
24068 16F: 616, 627, 627a, 628, 628a, 630, 636, 639, 648, 648a, 676, 684, 685,
24072 \begin_layout Standard
24073 16F: 716, 72, 73, 737, 74, 747, 76, 767, 77, 777, 785
24076 \begin_layout Standard
24077 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
24078 877, 877a, 88, 886, 887
24081 \begin_layout Standard
24082 16F: 913, 914, 916, 917, 946
24085 \begin_layout Standard
24089 \begin_layout Standard
24091 An up-to-date list of currently supported devices can be obtained via
24093 sdcc -mpic14 -phelp foo.c
24095 (foo.c must exist...).
24098 \begin_layout Subsection
24100 \begin_inset LatexCommand \index{code page (pic14)}
24105 \begin_inset LatexCommand \index{Memory bank (pic14)}
24112 \begin_layout Standard
24113 The linker organizes allocation for the code page and RAM banks.
24114 It does not have intimate knowledge of the code flow.
24115 It will put all the code section of a single .asm file into a single code
24117 In order to make use of multiple code pages, separate asm files must be
24119 The compiler assigns all
24123 functions of a single .c file into the same code page.
24127 To get the best results,
24128 follow these guidelines:
24131 \begin_layout Enumerate
24132 Make local functions static, as non static functions require code page selection
24135 Due to the way sdcc handles functions, place called functions prior
24136 to calling functions in the file wherever possible: Otherwise sdcc will
24137 insert unneccessary pagesel directives around the call, believing that
24138 the called function is externally defined.
24141 \begin_layout Enumerate
24142 For devices that have multiple code pages it is more efficient to use the
24143 same number of files as pages: Use up to 4 separate .c files for the 16F877,
24144 but only 2 files for the 16F874.
24145 This way the linker can put the code for each file into different code
24146 pages and there will be less page selection overhead.
24149 \begin_layout Enumerate
24150 And as for any 8 bit micro (especially for PIC14 as they have a very simple
24151 instruction set), use `unsigned char' wherever possible instead of `int'.
24154 \begin_layout Subsection
24155 Adding New Devices to the Port
24158 \begin_layout Standard
24159 Adding support for a new 14
24163 \begin_layout Standard
24172 bit PIC MCU requires the following steps:
24175 \begin_layout Enumerate
24176 Create a new device description.
24178 Each device is described in two files: pic16f*.h
24180 These files primarily define SFRs, structs to access their bits, and symbolic
24181 configuration options.
24182 Both files can be generated from gputils' .inc files using the perl script
24185 support/scripts/inc2h.pl
24188 This file also contains further instructions on how to proceed.
24191 \begin_layout Enumerate
24192 Copy the .h file into SDCC's include path and either add the .c file to your
24193 project or copy it to
24195 device/lib/pic/libdev
24198 Afterwards, rebuild and install the libraries.
24201 \begin_layout Enumerate
24202 Edit pic14devices.txt in SDCC's include path (
24204 device/include/pic/
24206 in the source tree or
24208 /usr/local/share/sdcc/include/pic
24210 after installation).
24212 You need to add a device specification here to make
24213 the memory layout (code banks, RAM, aliased memory regions, ...) known to
24215 Probably you can copy and modify an existing entry.
24216 The file format is documented at the top of the file.
24219 \begin_layout Subsection
24223 \begin_layout Standard
24224 For the interrupt function, use the keyword `__interrupt'
24225 \begin_inset LatexCommand \index{PIC14!interrupt}
24229 with level number of 0 (PIC14 only has 1 interrupt so this number is only
24230 there to avoid a syntax error - it ought to be fixed).
24234 \begin_layout Verse
24237 void Intr(void) __interrupt 0
24243 T0IF = 0; /* Clear timer interrupt */
24248 \begin_layout Subsection
24249 Linking and Assembling
24252 \begin_layout Standard
24253 For assembling you can use either GPUTILS'
24254 \begin_inset LatexCommand \index{gputils (pic tools)}
24258 gpasm.exe or MPLAB's mpasmwin.exe.
24259 GPUTILS are available from
24260 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24265 For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
24266 If you use MPLAB and an interrupt function then the linker script file
24267 vectors section will need to be enlarged to link with mplink.
24278 \begin_layout Verse
24291 sdcc -V -mpic14 -p16f877 -c $<
24295 $(PRJ).hex: $(OBJS)
24305 gplink -m -s $(PRJ).lkr
24306 -o $(PRJ).hex $(OBJS) libsdcc.lib
24309 \begin_layout Standard
24317 \begin_layout Verse
24330 sdcc -S -V -mpic14 -p16f877 $<
24340 mpasmwin /q /o $*.asm
24344 $(PRJ).hex: $(OBJS)
24355 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
24358 \begin_layout Standard
24359 Please note that indentations within a
24363 have to be done with a tabulator character.
24366 \begin_layout Subsection
24367 Command-Line Options
24370 \begin_layout Standard
24371 Besides the switches common to all SDCC backends, the PIC14 port accepts
24372 the following options (for an updated list see sdcc -
24376 \begin_layout Standard
24388 \begin_layout Description
24393 \begin_layout Standard
24403 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
24407 emit debug info in assembly output
24410 \begin_layout Description
24415 \begin_layout Standard
24425 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
24429 disable (slightly faulty) optimization on pCode
24432 \begin_layout Description
24437 \begin_layout Standard
24447 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
24451 sets the lowest address of the argument passing stack (defaults to a suitably
24452 large shared databank to reduce BANKSEL overhead)
24455 \begin_layout Description
24460 \begin_layout Standard
24470 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
24474 sets the size if the argument passing stack (default: 16, minimum: 4)
24477 \begin_layout Subsection
24478 Environment Variables
24481 \begin_layout Standard
24482 The PIC14 port recognizes the following environment variables:
24485 \begin_layout Description
24486 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
24487 register (the ones called r0xNNNN) in a section of its own.
24488 By default (if this variable is unset), sdcc tries to cluster registers
24489 in sections in order to reduce the BANKSEL overhead when accessing them.
24492 \begin_layout Subsection
24496 \begin_layout Standard
24497 The PIC14 library currently only contains support routines required by the
24498 compiler to implement multiplication, division, and floating point support.
24499 No libc-like replacement is available at the moment, though many of the
24500 common sdcc library sources (in
24504 ) should also compile with the PIC14 port.
24507 \begin_layout Subsubsection
24508 error: missing definition for symbol ``__gptrget1''
24511 \begin_layout Standard
24512 The PIC14 port uses library routines to provide more complex operations
24513 like multiplication, division/modulus and (generic) pointer dereferencing.
24514 In order to add these routines to your project, you must link with PIC14's
24520 For single source file projects this is done automatically, more complex
24525 to the linker's arguments.
24526 Make sure you also add an include path for the library (using the -I switch
24530 \begin_layout Subsubsection
24531 Processor mismatch in file ``XXX''.
24534 \begin_layout Standard
24535 This warning can usually be ignored due to the very good compatibility amongst
24540 \begin_layout Standard
24550 \begin_inset LatexCommand \index{PIC14}
24557 \begin_layout Standard
24558 You might also consider recompiling the library for your specific device
24559 by changing the ARCH=p16f877 (default target) entry in
24561 device/lib/pic/Makefile.in
24565 device/lib/pic/Makefile
24567 to reflect your device.
24568 This might even improve performance for smaller devices as unneccesary
24569 BANKSELs might be removed.
24572 \begin_layout Subsection
24576 \begin_layout Subsubsection
24580 \begin_layout Standard
24581 Functions with variable argument lists (like printf) are not yet supported.
24582 Similarly, taking the address of the first argument passed into a function
24583 does not work: It is currently passed in WREG and has no address...
24586 \begin_layout Subsubsection
24587 Regression tests fail
24590 \begin_layout Standard
24591 Though the small subset of regression tests in src/regression passes, SDCC
24592 regression test suite does not, indicating that there are still major bugs
24594 However, many smaller projects have successfully used SDCC in the past...
24597 \begin_layout Standard
24605 \begin_layout Section
24607 \begin_inset LatexCommand \index{PIC16}
24614 \begin_layout Standard
24615 The PIC16 port adds support for Microchip
24616 \begin_inset LatexCommand \index{Microchip}
24621 \begin_inset Formula $^{\text{TM}}$
24625 \begin_inset LatexCommand \index{PIC}
24630 \begin_inset Formula $^{\text{TM}}$
24633 MCUs with 16 bit wide instructions.
24634 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
24635 ; devices supported by the port include:
24638 \begin_layout Standard
24639 18F: 242, 248, 252, 258, 442, 448, 452, 458
24642 \begin_layout Standard
24646 \begin_layout Standard
24647 18F: 2220, 2221, 2320, 2321, 2331, 2410, 2420, 2423, 2431, 2450, 2455, 2480,
24651 \begin_layout Standard
24652 18F: (2510,) 2515, 2520, 2523, 2525, 2550, 2580, 2585, 25j10, 2610, 2620,
24656 \begin_layout Standard
24657 18F: 4220, 4221, 4320, 4321, 4331, 4410, 4420, 4423, 4431, 4450, 4455, 4480,
24661 \begin_layout Standard
24662 18F: 4510, 4515, 4520, 4523, 4525, 4550, 4580, 4585, 45j10, 4610, 4620,
24666 \begin_layout Standard
24667 18F: 6520, 6585, 6620, 6680, 66j60, 66j65, 6720, 67j60
24670 \begin_layout Standard
24671 18F: 8520, 8585, 8620, 8680, 86j60, 86j65, 8720, 87j60
24674 \begin_layout Standard
24675 18F: 96j60, 96j65, 97j60
24678 \begin_layout Standard
24680 An up-to-date list of supported devices is also available via '
24682 sdcc -mpic16 -plist
24687 \begin_layout Subsection
24691 \begin_layout Standard
24692 PIC16 port supports the standard command line arguments as supposed, with
24693 the exception of certain cases that will be mentioned in the following
24697 \begin_layout Description
24702 \begin_layout Standard
24712 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
24720 \begin_layout Standard
24732 \begin_layout Description
24737 \begin_layout Standard
24746 -fommit-frame-pointer
24747 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
24751 Frame pointer will be omitted when the function uses no local variables.
24754 \begin_layout Subsection
24755 Port Specific Options
24756 \begin_inset LatexCommand \index{Options PIC16}
24763 \begin_layout Standard
24764 The port specific options appear after the global options in the sdcc -
24768 \begin_layout Standard
24780 \begin_layout Subsubsection
24781 Code Generation Options
24784 \begin_layout Standard
24785 These options influence the generated assembler code.
24788 \begin_layout Description
24793 \begin_layout Standard
24802 -pstack-model=[model] Used in conjuction with the command above.
24803 Defines the stack model to be used, valid stack models are:
24808 \labelwidthstring 00.00.0000
24813 Selects small stack model.
24814 8 bit stack and frame pointers.
24815 Supports 256 bytes stack size.
24819 \labelwidthstring 00.00.0000
24824 Selects large stack model.
24825 16 bit stack and frame pointers.
24826 Supports 65536 bytes stack size.
24830 \begin_layout Description
24835 \begin_layout Standard
24844 -pno-banksel Do not generate BANKSEL assembler directives.
24847 \begin_layout Description
24852 \begin_layout Standard
24861 -extended Enable extended instruction set/literal offset addressing mode.
24865 \begin_layout Subsubsection
24866 Optimization Options
24869 \begin_layout Description
24874 \begin_layout Standard
24883 -obanksel=n Set optimization level for inserting BANKSELs.
24890 \labelwidthstring 00.00.0000
24895 \labelwidthstring 00.00.0000
24896 1 checks previous used register and if it is the same then does not emit
24897 BANKSEL, accounts only for labels.
24901 \labelwidthstring 00.00.0000
24902 2 tries to check the location of (even different) symbols and removes BANKSELs
24903 if they are in the same bank.
24908 Important: There might be problems if the linker script has data sections
24909 across bank borders!
24913 \begin_layout Description
24918 \begin_layout Standard
24927 -denable-peeps Force the usage of peepholes.
24931 \begin_layout Description
24936 \begin_layout Standard
24945 -no-optimize-goto Do not use (conditional) BRA instead of GOTO.
24948 \begin_layout Description
24953 \begin_layout Standard
24962 -optimize-cmp Try to optimize some compares.
24965 \begin_layout Description
24970 \begin_layout Standard
24979 -optimize-df Analyze the dataflow of the generated code and improve it.
24982 \begin_layout Subsubsection
24986 \begin_layout Description
24991 \begin_layout Standard
25000 -asm= Sets the full path and name of an external assembler to call.
25003 \begin_layout Description
25008 \begin_layout Standard
25018 \begin_inset LatexCommand \index{PIC16!MPLAB}
25022 compatibility option.
25023 Currently only suppresses special gpasm directives.
25026 \begin_layout Subsubsection
25030 \begin_layout Description
25035 \begin_layout Standard
25044 -link= Sets the full path and name of an external linker to call.
25047 \begin_layout Description
25052 \begin_layout Standard
25061 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
25062 unitialized data variables with [kword].
25063 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
25066 \begin_layout Description
25071 \begin_layout Standard
25080 -ivt-loc=n Place the interrupt vector table at address
25085 Useful for bootloaders.
25088 \begin_layout Description
25093 \begin_layout Standard
25102 -nodefaultlibs Do not link default libraries when linking.
25105 \begin_layout Description
25110 \begin_layout Standard
25119 -use-crt= Use a custom run-time module instead of the defaults.
25122 \begin_layout Description
25127 \begin_layout Standard
25136 -no-crt Don't link the default run-time modules
25139 \begin_layout Subsubsection
25143 \begin_layout Standard
25144 Debugging options enable extra debugging information in the output files.
25147 \begin_layout Description
25152 \begin_layout Standard
25161 -debug-xtra Similar to -
25165 \begin_layout Standard
25175 \begin_inset LatexCommand \index{-\/-debug}
25179 , but dumps more information.
25182 \begin_layout Description
25187 \begin_layout Standard
25196 -debug-ralloc Force register allocator to dump <source>.d file with debugging
25198 <source> is the name of the file being compiled.
25201 \begin_layout Description
25206 \begin_layout Standard
25215 -pcode-verbose Enable pcode debugging information in translation.
25218 \begin_layout Description
25223 \begin_layout Standard
25232 -calltree Dump call tree in .calltree file.
25235 \begin_layout Description
25240 \begin_layout Standard
25249 -gstack Trace push/pops for stack pointer overflow.
25252 \begin_layout Subsection
25253 Enviroment Variables
25256 \begin_layout Standard
25257 There is a number of enviromental variables that can be used when running
25258 SDCC to enable certain optimizations or force a specific program behaviour.
25259 these variables are primarily for debugging purposes so they can be enabled/dis
25263 \begin_layout Standard
25264 Currently there is only two such variables available:
25267 \begin_layout Description
25268 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
25269 bitfields is optimized by directly loading FSR0 with the address of the
25270 bitfield structure.
25271 Normally SDCC will cast the bitfield structure to a bitfield pointer and
25273 This step saves data ram and code space for functions that make heavy use
25275 (i.e., 80 bytes of code space are saved when compiling malloc.c with this
25280 \begin_layout Description
25281 NO_REG_OPT Do not perform pCode registers optimization.
25282 This should be used for debugging purposes.
25283 If bugs in the pcode optimizer are found, users can benefit from temporarily
25284 disabling the optimizer until the bug is fixed.
25287 \begin_layout Subsection
25288 Preprocessor Macros
25291 \begin_layout Standard
25293 \begin_inset LatexCommand \index{PIC16}
25297 port defines the following preprocessor macros while translating a source.
25300 \begin_layout Standard
25302 \begin_inset Tabular
25303 <lyxtabular version="3" rows="6" columns="2">
25305 <column alignment="center" valignment="top" leftline="true" width="0">
25306 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25307 <row topline="true" bottomline="true">
25308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25311 \begin_layout Standard
25317 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25320 \begin_layout Standard
25327 <row topline="true">
25328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25331 \begin_layout Standard
25337 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25340 \begin_layout Standard
25341 Port identification
25347 <row topline="true">
25348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25351 \begin_layout Standard
25356 \begin_layout Standard
25370 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25373 \begin_layout Standard
25374 Port identification (same as above)
25380 <row topline="true">
25381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25384 \begin_layout Standard
25390 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25393 \begin_layout Standard
25394 MCU Identification.
25399 is the microcontrol identification number, i.e.
25406 <row topline="true">
25407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25410 \begin_layout Standard
25415 \begin_layout Standard
25429 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25432 \begin_layout Standard
25433 MCU Identification (same as above)
25439 <row topline="true" bottomline="true">
25440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25443 \begin_layout Standard
25449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25452 \begin_layout Standard
25453 nnn = SMALL or LARGE respectively according to the stack model used
25466 \begin_layout Standard
25468 In addition the following macros are defined when calling assembler:
25471 \begin_layout Standard
25473 \begin_inset Tabular
25474 <lyxtabular version="3" rows="4" columns="2">
25476 <column alignment="center" valignment="top" leftline="true" width="0">
25477 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25478 <row topline="true" bottomline="true">
25479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25482 \begin_layout Standard
25488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25491 \begin_layout Standard
25498 <row topline="true">
25499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25502 \begin_layout Standard
25508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25511 \begin_layout Standard
25512 MCU Identification.
25517 is the microcontrol identification number, i.e.
25524 <row topline="true">
25525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25528 \begin_layout Standard
25534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25537 \begin_layout Standard
25538 nnn = SMALL or LARGE respectively according to the memory model used for
25545 <row topline="true" bottomline="true">
25546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25549 \begin_layout Standard
25555 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25558 \begin_layout Standard
25559 nnn = SMALL or LARGE respectively according to the stack model used
25572 \begin_layout Subsection
25576 \begin_layout Standard
25578 \begin_inset LatexCommand \index{PIC16}
25582 port uses the following directories for searching header files and libraries.
25585 \begin_layout Standard
25587 \begin_inset Tabular
25588 <lyxtabular version="3" rows="3" columns="4">
25590 <column alignment="center" valignment="top" leftline="true" width="0">
25591 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25592 <column alignment="center" valignment="top" width="0">
25593 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25594 <row topline="true" bottomline="true">
25595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25598 \begin_layout Standard
25604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25607 \begin_layout Standard
25613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25616 \begin_layout Standard
25622 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25625 \begin_layout Standard
25632 <row topline="true">
25633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25636 \begin_layout Standard
25637 PREFIX/sdcc/include/pic16
25642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25645 \begin_layout Standard
25646 PIC16 specific headers
25651 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25654 \begin_layout Standard
25660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25663 \begin_layout Standard
25670 <row topline="true" bottomline="true">
25671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25674 \begin_layout Standard
25675 PREFIX/sdcc/lib/pic16
25680 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25683 \begin_layout Standard
25684 PIC16 specific libraries
25689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25692 \begin_layout Standard
25698 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25701 \begin_layout Standard
25715 \begin_layout Subsection
25717 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
25724 \begin_layout Standard
25726 \begin_inset LatexCommand \index{PIC16}
25730 port currently supports the following pragmas:
25733 \begin_layout Description
25735 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
25739 This forces the code generator to initialize the stack & frame pointers
25740 at a specific address.
25741 This is an ad hoc solution for cases where no STACK directive is available
25742 in the linker script or gplink is not instructed to create a stack section.
25745 stack pragma should be used only once in a project.
25746 Multiple pragmas may result in indeterminate behaviour of the program.
25750 \begin_layout Standard
25751 The old format (ie.
25752 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
25753 cross page boundaries (or even exceed the available data RAM) and crash
25755 Make sure that stack does not cross page boundaries when using the SMALL
25763 The format is as follows:
25768 \begin_layout LyX-Code
25769 #pragma stack bottom_address [stack_size]
25774 \begin_layout Standard
25779 is the lower bound of the stack section.
25780 The stack pointer initially will point at address (bottom_address+stack_size-1).
25783 \begin_layout LyX-Code
25787 \begin_layout LyX-Code
25791 \begin_layout LyX-Code
25792 /* initializes stack of 100 bytes at RAM address 0x200 */
25795 \begin_layout LyX-Code
25796 #pragma stack 0x200 100
25799 \begin_layout Standard
25800 If the stack_size field is omitted then a stack is created with the default
25802 This size might be enough for most programs, but its not enough for operations
25803 with deep function nesting or excessive stack usage.
25806 \begin_layout Description
25808 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
25812 Force a function to a static FLASH address.
25815 \begin_layout LyX-Code
25819 \begin_layout LyX-Code
25823 \begin_layout LyX-Code
25824 /* place function test_func at 0x4000 */
25827 \begin_layout LyX-Code
25828 #pragma code test_func 0x4000
25831 \begin_layout LyX-Code
25835 \begin_layout Description
25836 library instructs the linker to use a library module.
25841 \begin_layout LyX-Code
25842 #pragma library module_name
25845 \begin_layout Standard
25850 can be any library or object file (including its path).
25851 Note that there are four reserved keywords which have special meaning.
25855 \begin_layout Standard
25857 \begin_inset Tabular
25858 <lyxtabular version="3" rows="6" columns="3">
25860 <column alignment="center" valignment="top" leftline="true" width="0">
25861 <column alignment="block" valignment="top" leftline="true" width="20page%">
25862 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
25863 <row topline="true" bottomline="true">
25864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25867 \begin_layout Standard
25873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25876 \begin_layout Standard
25882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25885 \begin_layout Standard
25892 <row topline="true">
25893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25896 \begin_layout Standard
25904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25907 \begin_layout Standard
25908 ignore all library pragmas
25913 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25916 \begin_layout Standard
25925 <row topline="true">
25926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25929 \begin_layout Standard
25937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25940 \begin_layout Standard
25946 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25949 \begin_layout Standard
25960 <row topline="true">
25961 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25964 \begin_layout Standard
25972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25975 \begin_layout Standard
25976 link the Math libarary
25981 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25984 \begin_layout Standard
25995 <row topline="true">
25996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25999 \begin_layout Standard
26007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26010 \begin_layout Standard
26011 link the I/O library
26016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26019 \begin_layout Standard
26030 <row topline="true" bottomline="true">
26031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26034 \begin_layout Standard
26042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26045 \begin_layout Standard
26046 link the debug library
26051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26054 \begin_layout Standard
26071 * is the device number, i.e.
26072 452 for PIC18F452 MCU.
26075 \begin_layout Standard
26077 This feature allows for linking with specific libraries withoug having to
26078 explicit name them in the command line.
26083 keyword will reject all modules specified by the library pragma.
26086 \begin_layout Description
26087 udata The pragma udata instructs the compiler to emit code so that linker
26088 will place a variable at a specific memory bank.
26091 \begin_layout LyX-Code
26095 \begin_layout LyX-Code
26099 \begin_layout LyX-Code
26100 /* places variable foo at bank2 */
26103 \begin_layout LyX-Code
26104 #pragma udata bank2 foo
26107 \begin_layout LyX-Code
26111 \begin_layout Standard
26112 In order for this pragma to work extra SECTION directives should be added
26113 in the .lkr script.
26114 In the following example a sample .lkr file is shown:
26117 \begin_layout LyX-Code
26121 \begin_layout LyX-Code
26122 // Sample linker script for the PIC18F452 processor
26125 \begin_layout LyX-Code
26129 \begin_layout LyX-Code
26130 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
26133 \begin_layout LyX-Code
26134 CODEPAGE NAME=page START=0x2A END=0x7FFF
26137 \begin_layout LyX-Code
26138 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
26141 \begin_layout LyX-Code
26142 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
26145 \begin_layout LyX-Code
26146 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
26149 \begin_layout LyX-Code
26150 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
26153 \begin_layout LyX-Code
26154 ACCESSBANK NAME=accessram START=0x0 END=0x7F
26157 \begin_layout LyX-Code
26161 \begin_layout LyX-Code
26162 DATABANK NAME=gpr0 START=0x80 END=0xFF
26165 \begin_layout LyX-Code
26166 DATABANK NAME=gpr1 START=0x100 END=0x1FF
26169 \begin_layout LyX-Code
26170 DATABANK NAME=gpr2 START=0x200 END=0x2FF
26173 \begin_layout LyX-Code
26174 DATABANK NAME=gpr3 START=0x300 END=0x3FF
26177 \begin_layout LyX-Code
26178 DATABANK NAME=gpr4 START=0x400 END=0x4FF
26181 \begin_layout LyX-Code
26182 DATABANK NAME=gpr5 START=0x500 END=0x5FF
26185 \begin_layout LyX-Code
26186 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
26189 \begin_layout LyX-Code
26193 \begin_layout LyX-Code
26194 SECTION NAME=CONFIG ROM=config
26197 \begin_layout LyX-Code
26201 \begin_layout LyX-Code
26202 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
26205 \begin_layout LyX-Code
26206 SECTION NAME=bank1 RAM=gpr1 # should be added to link
26209 \begin_layout LyX-Code
26210 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
26213 \begin_layout LyX-Code
26214 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
26217 \begin_layout LyX-Code
26218 SECTION NAME=bank4 RAM=gpr4
26221 \begin_layout LyX-Code
26222 SECTION NAME=bank5 RAM=gpr5
26225 \begin_layout Standard
26226 The linker will recognise the section name set in the pragma statement and
26227 will position the variable at the memory bank set with the RAM field at
26228 the SECTION line in the linker script file.
26231 \begin_layout Subsection
26233 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
26240 \begin_layout Standard
26241 There is one main header file
26242 \begin_inset LatexCommand \index{PIC16!Header files}
26246 that can be included to the source files using the pic16
26247 \begin_inset LatexCommand \index{PIC16}
26257 This header file contains the definitions for the processor special registers,
26258 so it is necessary if the source accesses them.
26259 It can be included by adding the following line in the beginning of the
26263 \begin_layout LyX-Code
26264 #include <pic18fregs.h>
26267 \begin_layout Standard
26268 The specific microcontroller is selected within the pic18fregs.h automatically,
26269 so the same source can be used with a variety of devices.
26272 \begin_layout Subsection
26274 \begin_inset LatexCommand \label{sub:pic16Libraries}
26281 \begin_layout Standard
26283 \begin_inset LatexCommand \index{PIC16!Libraries}
26288 \begin_inset LatexCommand \index{PIC16}
26292 port depends on are the microcontroller device libraries which contain
26293 the symbol definitions for the microcontroller special function registers.
26294 These libraries have the format pic18fxxxx.lib, where
26298 is the microcontroller identification number.
26299 The specific library is selected automatically by the compiler at link
26300 stage according to the selected device.
26303 \begin_layout Standard
26305 Libraries are created with gplib which is part of the gputils package
26306 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
26313 \begin_layout Subsubsection*
26314 Building the libraries
26317 \begin_layout Standard
26318 Before using SDCC/pic16 there are some libraries that need to be compiled.
26319 This process is done automatically if gputils are found at SDCC's compile
26321 Should you require to rebuild the pic16 libraries manually, these are the
26322 steps required to do so under Linux or Mac OS X (cygwin might work as well,
26326 \begin_layout LyX-Code
26327 cd device/lib/pic16
26330 \begin_layout LyX-Code
26334 \begin_layout LyX-Code
26338 \begin_layout LyX-Code
26342 \begin_layout LyX-Code
26343 su -c 'make install' # install the libraries, you need the root password
26346 \begin_layout LyX-Code
26350 \begin_layout Standard
26351 If you need to install the headers too, do:
26354 \begin_layout LyX-Code
26358 \begin_layout LyX-Code
26359 su -c 'make install' # install the headers, you need the root password
26362 \begin_layout Subsection
26363 Adding New Devices to the Port
26366 \begin_layout Standard
26367 Adding support for a new 16
26371 \begin_layout Standard
26380 bit PIC MCU requires the following steps:
26383 \begin_layout Enumerate
26384 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
26388 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
26392 \begin_layout Enumerate
26395 mv picDEVICE.h /path/to/sdcc/device/include/pic16
26398 \begin_layout Enumerate
26401 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
26404 \begin_layout Enumerate
26407 /path/to/sdcc/device/lib/pic16/pics.all
26411 Note: No 18f prefix here!
26414 \begin_layout Enumerate
26417 /path/to/sdcc/device/include/pic16/adc.h
26421 Add the new devices to the correct ADC style class (depending on the number
26428 if the device does not offer any ADC at all.
26431 \begin_layout Enumerate
26434 /path/to/sdcc/device/include/pic16/pic18fregs.h
26438 The file format is self-explanatory, just add
26442 #elif defined(picDEVICE)
26448 \begin_layout Standard
26459 include <picDEVICE.h>
26463 at the right place (keep the file sorted, please).
26466 \begin_layout Enumerate
26469 /path/to/sdcc/device/include/pic16devices.txt
26473 Copy and modify an existing entry or create a new one and insert it at the
26474 correct place (keep the file sorted, please).
26477 \begin_layout Enumerate
26480 /path/to/sdcc/device/lib/pic16/libdev/Makefile.am
26484 Copy an existing entry and adjust the device name.
26487 \begin_layout Enumerate
26490 /path/to/sdcc/device/lib/pic16/libio/Makefile.am
26494 Copy the record from the 18f2220 and adjust the device name.
26497 does not offer ADC, I
26498 \begin_inset Formula $^{\text{2}}$
26501 C, and/or (E)USART functionality as assumed by the library, remove the lines
26517 \begin_layout Enumerate
26536 /path/to/sdcc/device/lib/pic16
26541 \begin_layout Enumerate
26542 Recompile the pic16 libraries as described in
26543 \begin_inset LatexCommand \ref{sub:pic16Libraries}
26550 \begin_layout Subsection
26554 \begin_layout Standard
26555 The following memory models are supported by the PIC16 port:
26558 \begin_layout Itemize
26562 \begin_layout Itemize
26566 \begin_layout Standard
26567 Memory model affects the default size of pointers within the source.
26568 The sizes are shown in the next table:
26571 \begin_layout Standard
26573 \begin_inset Tabular
26574 <lyxtabular version="3" rows="3" columns="3">
26576 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26577 <column alignment="center" valignment="top" leftline="true" width="0">
26578 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26579 <row topline="true" bottomline="true">
26580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26583 \begin_layout Standard
26584 Pointer sizes according to memory model
26589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26592 \begin_layout Standard
26598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26601 \begin_layout Standard
26608 <row topline="true" bottomline="true">
26609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26612 \begin_layout Standard
26618 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26621 \begin_layout Standard
26627 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26630 \begin_layout Standard
26637 <row topline="true" bottomline="true">
26638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26641 \begin_layout Standard
26647 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
26650 \begin_layout Standard
26656 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26659 \begin_layout Standard
26673 \begin_layout Standard
26674 It is advisable that all sources within a project are compiled with the
26676 If one wants to override the default memory model, this can be done by
26677 declaring a pointer as
26686 Far selects large memory model's pointers, while near selects small memory
26690 \begin_layout Standard
26691 The standard device libraries (see
26692 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
26696 ) contain no reference to pointers, so they can be used with both memory
26700 \begin_layout Subsection
26704 \begin_layout Standard
26706 \begin_inset LatexCommand \index{PIC16!stack}
26710 implementation for the PIC16 port uses two indirect registers, FSR1 and
26714 \begin_layout Description
26715 FSR1 is assigned as stack pointer
26718 \begin_layout Description
26719 FSR2 is assigned as frame pointer
26722 \begin_layout Standard
26723 The following stack models are supported by the PIC16 port
26726 \begin_layout Itemize
26734 \begin_layout Itemize
26742 \begin_layout Standard
26747 model means that only the FSRxL byte is used to access stack and frame,
26754 uses both FSRxL and FSRxH registers.
26755 The following table shows the stack/frame pointers sizes according to stack
26756 model and the maximum space they can address:
26759 \begin_layout Standard
26761 \begin_inset Tabular
26762 <lyxtabular version="3" rows="3" columns="3">
26764 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26765 <column alignment="center" valignment="top" leftline="true" width="0">
26766 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26767 <row topline="true" bottomline="true">
26768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26771 \begin_layout Standard
26772 Stack & Frame pointer sizes according to stack model
26777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26780 \begin_layout Standard
26786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26789 \begin_layout Standard
26796 <row topline="true">
26797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26800 \begin_layout Standard
26806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26809 \begin_layout Standard
26815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26818 \begin_layout Standard
26825 <row topline="true" bottomline="true">
26826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26829 \begin_layout Standard
26835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26838 \begin_layout Standard
26844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26847 \begin_layout Standard
26861 \begin_layout Standard
26867 stack model is currently not working properly throughout the code generator.
26868 So its use is not advised.
26869 Also there are some other points that need special care:
26874 \begin_layout Enumerate
26875 Do not create stack sections with size more than one physical bank (that
26879 \begin_layout Enumerate
26880 Stack sections should no cross physical bank limits (i.e.
26881 #pragma stack 0x50 0x100)
26884 \begin_layout Standard
26885 These limitations are caused by the fact that only FSRxL is modified when
26886 using SMALL stack model, so no more than 256 bytes of stack can be used.
26887 This problem will disappear after LARGE model is fully implemented.
26890 \begin_layout Subsection
26894 \begin_layout Standard
26895 In addition to the standard SDCC function keywords, PIC16
26896 \begin_inset LatexCommand \index{PIC16}
26900 port makes available two more:
26903 \begin_layout Description
26905 \begin_inset LatexCommand \index{PIC16!wparam}
26909 Use the WREG to pass one byte of the first function argument.
26910 This improves speed but you may not use this for functions with arguments
26911 that are called via function pointers, otherwise the first byte of the
26912 first parameter will get lost.
26916 \begin_layout LyX-Code
26917 void func_wparam(int a) wparam
26920 \begin_layout LyX-Code
26924 \begin_layout LyX-Code
26925 /* WREG hold the lower part of a */
26928 \begin_layout LyX-Code
26929 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
26933 \begin_layout LyX-Code
26937 \begin_layout LyX-Code
26941 \begin_layout Description
26943 \begin_inset LatexCommand \index{PIC16!shadowregs}
26947 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
26948 hardware shadow registers which hold the values of WREG, STATUS and BSR
26950 This can be done by adding the keyword
26958 keyword in the function's header.
26961 \begin_layout LyX-Code
26962 void isr_shadow(void) shadowregs interrupt 1
26965 \begin_layout LyX-Code
26969 \begin_layout LyX-Code
26973 \begin_layout LyX-Code
26977 \begin_layout Standard
26982 instructs the code generator not to store/restore WREG, STATUS, BSR when
26983 entering/exiting the ISR.
26986 \begin_layout Subsection
26987 Function return values
26990 \begin_layout Standard
26991 Return values from functions are placed to the appropriate registers following
26992 a modified Microchip policy optimized for SDCC.
26993 The following table shows these registers:
26996 \begin_layout Standard
26998 \begin_inset Tabular
26999 <lyxtabular version="3" rows="6" columns="2">
27001 <column alignment="center" valignment="top" leftline="true" width="0">
27002 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27003 <row topline="true" bottomline="true">
27004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27007 \begin_layout Standard
27013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27016 \begin_layout Standard
27017 destination register
27023 <row topline="true">
27024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27027 \begin_layout Standard
27033 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27036 \begin_layout Standard
27043 <row topline="true">
27044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27047 \begin_layout Standard
27053 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27056 \begin_layout Standard
27063 <row topline="true">
27064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27067 \begin_layout Standard
27073 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27076 \begin_layout Standard
27083 <row topline="true">
27084 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27087 \begin_layout Standard
27093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27096 \begin_layout Standard
27097 FSR0L:PRODH:PRODL:WREG
27103 <row topline="true" bottomline="true">
27104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27107 \begin_layout Standard
27113 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27116 \begin_layout Standard
27117 on stack, FSR0 points to the beginning
27130 \begin_layout Subsection
27134 \begin_layout Standard
27136 \begin_inset LatexCommand \index{PIC16!interrupt}
27140 service routine (ISR) is declared using the
27147 \begin_layout LyX-Code
27148 void isr(void) interrupt
27153 \begin_layout LyX-Code
27157 \begin_layout LyX-Code
27161 \begin_layout LyX-Code
27165 \begin_layout Standard
27170 is the interrupt number, which for PIC18F devices can be:
27173 \begin_layout Standard
27175 \begin_inset Tabular
27176 <lyxtabular version="3" rows="4" columns="3">
27178 <column alignment="center" valignment="top" leftline="true" width="0">
27179 <column alignment="center" valignment="top" leftline="true" width="0">
27180 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27181 <row topline="true" bottomline="true">
27182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27185 \begin_layout Standard
27193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27196 \begin_layout Standard
27202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27205 \begin_layout Standard
27206 Interrupt Vector Address
27212 <row topline="true">
27213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27216 \begin_layout Standard
27222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27225 \begin_layout Standard
27231 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27234 \begin_layout Standard
27241 <row topline="true">
27242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27245 \begin_layout Standard
27260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27263 \begin_layout Standard
27273 HIGH priority interrupts
27278 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27281 \begin_layout Standard
27288 <row topline="true" bottomline="true">
27289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27292 \begin_layout Standard
27298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27301 \begin_layout Standard
27302 LOW priority interrupts
27307 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27310 \begin_layout Standard
27324 \begin_layout Standard
27325 When generating assembly code for ISR the code generator places a
27331 Interrupt Vector Address
27333 which points at the genetated ISR.
27334 This single GOTO instruction is part of an automatically generated
27336 interrupt entry point
27339 The actuall ISR code is placed as normally would in the code space.
27340 Upon interrupt request, the GOTO instruction is executed which jumps to
27342 When declaring interrupt functions as _naked this GOTO instruction is
27347 The whole interrupt functions is therefore placed at the Interrupt Vector
27348 Address of the specific interrupt.
27349 This is not a problem for the LOW priority interrupts, but it is a problem
27350 for the RESET and the HIGH priority interrupts because code may be written
27351 at the next interrupt's vector address and cause undeterminate program
27352 behaviour if that interrupt is raised.
27356 \begin_layout Standard
27357 This is not a problem when
27360 \begin_layout Enumerate
27361 this is a HIGH interrupt ISR and LOW interrupts are
27368 \begin_layout Enumerate
27369 when the ISR is small enough not to reach the next interrupt's vector address.
27377 \begin_layout Standard
27383 This way a function is generated similar to an ISR, but it is not assigned
27387 \begin_layout Standard
27388 When entering an interrupt, currently the PIC16
27389 \begin_inset LatexCommand \index{PIC16}
27393 port automatically saves the following registers:
27396 \begin_layout Itemize
27400 \begin_layout Itemize
27404 \begin_layout Itemize
27408 \begin_layout Itemize
27409 PROD (PRODL and PRODH)
27412 \begin_layout Itemize
27413 FSR0 (FSR0L and FSR0H)
27416 \begin_layout Standard
27417 These registers are restored upon return from the interrupt routine.
27421 \begin_layout Standard
27422 NOTE that when the _naked attribute is specified for an interrupt routine,
27423 then NO registers are stored or restored.
27431 \begin_layout Subsection
27435 \begin_layout Standard
27436 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
27437 There are 3 types of generic pointers currently implemented data, code
27438 and eeprom pointers.
27439 They are differentiated by the value of the 7th and 6th bits of the upper
27443 \begin_layout Standard
27445 \begin_inset Tabular
27446 <lyxtabular version="3" rows="5" columns="5">
27448 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27449 <column alignment="center" valignment="top" width="0">
27450 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27451 <column alignment="center" valignment="top" width="0">
27452 <column alignment="left" valignment="top" rightline="true" width="0">
27453 <row topline="true" bottomline="true">
27454 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27457 \begin_layout Standard
27463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27466 \begin_layout Standard
27472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27475 \begin_layout Standard
27481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27484 \begin_layout Standard
27485 rest of the pointer
27490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27493 \begin_layout Standard
27500 <row topline="true" bottomline="true">
27501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27504 \begin_layout Standard
27510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27513 \begin_layout Standard
27519 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27522 \begin_layout Standard
27528 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27531 \begin_layout Standard
27536 uuuuuu uuuuxxxx xxxxxxxx
27541 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27544 \begin_layout Standard
27545 a 12-bit data pointer in data RAM memory
27551 <row bottomline="true">
27552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27555 \begin_layout Standard
27561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27564 \begin_layout Standard
27570 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27573 \begin_layout Standard
27579 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27582 \begin_layout Standard
27587 uxxxxx xxxxxxxx xxxxxxxx
27592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27595 \begin_layout Standard
27596 a 21-bit code pointer in FLASH memory
27602 <row bottomline="true">
27603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27606 \begin_layout Standard
27612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27615 \begin_layout Standard
27621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27624 \begin_layout Standard
27630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27633 \begin_layout Standard
27638 uuuuuu uuuuuuxx xxxxxxxx
27643 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27646 \begin_layout Standard
27647 a 10-bit eeprom pointer in EEPROM memory
27653 <row bottomline="true">
27654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27657 \begin_layout Standard
27663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27666 \begin_layout Standard
27672 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27675 \begin_layout Standard
27681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27684 \begin_layout Standard
27689 xxxxxx xxxxxxxx xxxxxxxx
27694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27697 \begin_layout Standard
27698 unimplemented pointer type
27711 \begin_layout Standard
27713 Generic pointer are read and written with a set of library functions which
27714 read/write 1, 2, 3, 4 bytes.
27717 \begin_layout Subsection
27721 \begin_layout Subsubsection
27722 Standard I/O Streams
27725 \begin_layout Standard
27730 the type FILE is defined as:
27733 \begin_layout LyX-Code
27734 typedef char * FILE;
27737 \begin_layout Standard
27738 This type is the stream type implemented I/O in the PIC18F devices.
27739 Also the standard input and output streams are declared in stdio.h:
27742 \begin_layout LyX-Code
27743 extern FILE * stdin;
27746 \begin_layout LyX-Code
27747 extern FILE * stdout;
27750 \begin_layout Standard
27751 The FILE type is actually a generic pointer which defines one more type
27752 of generic pointers, the
27757 This new type has the format:
27760 \begin_layout Standard
27763 \begin_inset Tabular
27764 <lyxtabular version="3" rows="2" columns="7">
27766 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27767 <column alignment="center" valignment="top" width="0">
27768 <column alignment="center" valignment="top" leftline="true" width="0">
27769 <column alignment="center" valignment="top" leftline="true" width="0">
27770 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27771 <column alignment="center" valignment="top" width="0">
27772 <column alignment="left" valignment="top" rightline="true" width="0">
27773 <row topline="true" bottomline="true">
27774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27777 \begin_layout Standard
27783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27786 \begin_layout Standard
27792 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27795 \begin_layout Standard
27801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27804 \begin_layout Standard
27810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27813 \begin_layout Standard
27819 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27822 \begin_layout Standard
27823 rest of the pointer
27828 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27831 \begin_layout Standard
27838 <row topline="true" bottomline="true">
27839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27842 \begin_layout Standard
27848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27851 \begin_layout Standard
27857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27860 \begin_layout Standard
27866 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27869 \begin_layout Standard
27875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27878 \begin_layout Standard
27884 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27887 \begin_layout Standard
27897 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27900 \begin_layout Standard
27901 upper byte high nubble is 0x2n, the rest are zeroes
27914 \begin_layout Standard
27916 Currently implemented there are 3 types of streams defined:
27919 \begin_layout Standard
27922 \begin_inset Tabular
27923 <lyxtabular version="3" rows="4" columns="4">
27925 <column alignment="center" valignment="top" leftline="true" width="0">
27926 <column alignment="center" valignment="top" leftline="true" width="0">
27927 <column alignment="center" valignment="top" leftline="true" width="0">
27928 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27929 <row topline="true" bottomline="true">
27930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27933 \begin_layout Standard
27939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27942 \begin_layout Standard
27948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27951 \begin_layout Standard
27957 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27960 \begin_layout Standard
27967 <row topline="true">
27968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27971 \begin_layout Standard
27977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27980 \begin_layout Standard
27988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27991 \begin_layout Standard
27997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28000 \begin_layout Standard
28001 Writes/Reads characters via the USART peripheral
28007 <row topline="true">
28008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28011 \begin_layout Standard
28017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28020 \begin_layout Standard
28028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28031 \begin_layout Standard
28037 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28040 \begin_layout Standard
28041 Writes/Reads characters via the MSSP peripheral
28047 <row topline="true" bottomline="true">
28048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28051 \begin_layout Standard
28057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28060 \begin_layout Standard
28068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28071 \begin_layout Standard
28077 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28080 \begin_layout Standard
28081 Writes/Reads characters via used defined functions
28094 \begin_layout Standard
28096 The stream identifiers are declared as macros in the stdio.h header.
28099 \begin_layout Standard
28101 In the libc library there exist the functions that are used to write to
28102 each of the above streams.
28106 \begin_layout Description
28111 \begin_layout Standard
28120 _stream_usart_putchar writes a character at the USART stream
28123 \begin_layout Description
28128 \begin_layout Standard
28137 _stream_mssp_putchar writes a character at the MSSP stream
28140 \begin_layout Description
28141 putchar dummy function.
28142 This writes a character to a user specified manner.
28145 \begin_layout Standard
28146 In order to increase performance
28150 is declared in stdio.h as having its parameter in WREG (it has the wparam
28152 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
28153 in a user-friendly way.
28158 is the name of the variable that holds the character to print.
28159 An example follows:
28162 \begin_layout LyX-Code
28163 #include <pic18fregs.h>
28172 \begin_layout LyX-Code
28176 \begin_layout LyX-Code
28177 PORTA = c; /* dump character c to PORTA */
28180 \begin_layout LyX-Code
28188 \begin_layout LyX-Code
28192 \begin_layout LyX-Code
28193 stdout = STREAM_USER; /* this is not necessary, since stdout points
28196 \begin_layout LyX-Code
28197 * by default to STREAM_USER */
28200 \begin_layout LyX-Code
28202 \begin_inset Quotes sld
28205 This is a printf test
28208 \begin_inset Quotes srd
28214 \begin_layout LyX-Code
28218 \begin_layout LyX-Code
28222 \begin_layout Subsubsection
28226 \begin_layout Standard
28227 PIC16 contains an implementation of the printf-family of functions.
28228 There exist the following functions:
28231 \begin_layout LyX-Code
28232 extern unsigned int sprintf(char *buf, char *fmt, ...);
28235 \begin_layout LyX-Code
28236 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
28239 \begin_layout LyX-Code
28243 \begin_layout LyX-Code
28244 extern unsigned int printf(char *fmt, ...);
28247 \begin_layout LyX-Code
28248 extern unsigned int vprintf(char *fmt, va_lista ap);
28251 \begin_layout LyX-Code
28255 \begin_layout LyX-Code
28256 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
28259 \begin_layout LyX-Code
28260 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
28263 \begin_layout Standard
28264 For sprintf and vsprintf
28268 should normally be a data pointer where the resulting string will be placed.
28269 No range checking is done so the user should allocate the necessery buffer.
28270 For fprintf and vfprintf
28274 should be a stream pointer (i.e.
28275 stdout, STREAM_MSSP, etc...).
28278 \begin_layout Subsubsection
28282 \begin_layout Standard
28283 The PIC18F family of microcontrollers supports a number of interrupt sources.
28284 A list of these interrupts is shown in the following table:
28287 \begin_layout Standard
28289 \begin_inset Tabular
28290 <lyxtabular version="3" rows="11" columns="4">
28292 <column alignment="left" valignment="top" leftline="true" width="0">
28293 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28294 <column alignment="left" valignment="top" leftline="true" width="0">
28295 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28296 <row topline="true" bottomline="true">
28297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28300 \begin_layout Standard
28306 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28309 \begin_layout Standard
28315 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28318 \begin_layout Standard
28324 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28327 \begin_layout Standard
28334 <row topline="true">
28335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28338 \begin_layout Standard
28344 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28347 \begin_layout Standard
28348 PORTB change interrupt
28353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28356 \begin_layout Standard
28362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28365 \begin_layout Standard
28366 EEPROM/FLASH write complete interrupt
28372 <row topline="true">
28373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28376 \begin_layout Standard
28382 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28385 \begin_layout Standard
28386 INT0 external interrupt
28391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28394 \begin_layout Standard
28400 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28403 \begin_layout Standard
28404 Bus collision interrupt
28410 <row topline="true">
28411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28414 \begin_layout Standard
28420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28423 \begin_layout Standard
28424 INT1 external interrupt
28429 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28432 \begin_layout Standard
28438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28441 \begin_layout Standard
28442 Low voltage detect interrupt
28448 <row topline="true">
28449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28452 \begin_layout Standard
28458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28461 \begin_layout Standard
28462 INT2 external interrupt
28467 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28470 \begin_layout Standard
28476 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28479 \begin_layout Standard
28480 Parallel slave port interrupt
28486 <row topline="true">
28487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28490 \begin_layout Standard
28496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28499 \begin_layout Standard
28500 CCP1 module interrupt
28505 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28508 \begin_layout Standard
28514 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28517 \begin_layout Standard
28518 AD convertion complete interrupt
28524 <row topline="true">
28525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28528 \begin_layout Standard
28534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28537 \begin_layout Standard
28538 CCP2 module interrupt
28543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28546 \begin_layout Standard
28552 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28555 \begin_layout Standard
28556 USART receive interrupt
28562 <row topline="true">
28563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28566 \begin_layout Standard
28572 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28575 \begin_layout Standard
28576 TMR0 overflow interrupt
28581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28584 \begin_layout Standard
28590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28593 \begin_layout Standard
28594 USART transmit interrupt
28600 <row topline="true">
28601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28604 \begin_layout Standard
28610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28613 \begin_layout Standard
28614 TMR1 overflow interrupt
28619 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28622 \begin_layout Standard
28628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28631 \begin_layout Standard
28632 SSP receive/transmit interrupt
28638 <row topline="true">
28639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28642 \begin_layout Standard
28648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28651 \begin_layout Standard
28652 TMR2 matches PR2 interrupt
28657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28660 \begin_layout Standard
28666 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28669 \begin_layout Standard
28676 <row topline="true" bottomline="true">
28677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28680 \begin_layout Standard
28686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28689 \begin_layout Standard
28690 TMR3 overflow interrupt
28695 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28698 \begin_layout Standard
28704 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28707 \begin_layout Standard
28721 \begin_layout Standard
28723 The prototypes for these names are defined in the header file
28730 \begin_layout Standard
28732 In order to simplify signal handling, a number of macros is provided:
28736 \labelwidthstring 00.00.0000
28737 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
28738 high priority interrupts.
28743 is the function name to use.
28747 \labelwidthstring 00.00.0000
28748 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
28749 low priority interrupt.
28754 is the function name to use.
28758 \labelwidthstring 00.00.0000
28759 DEF_HANDLER(sig,handler) define a handler for signal
28765 \labelwidthstring 00.00.0000
28766 END_DEF end the declaration of the dispatch table.
28769 \begin_layout Standard
28770 Additionally there are two more macros to simplify the declaration of the
28775 \labelwidthstring 00.00.0000
28778 SIGHANDLER(handler)
28780 this declares the function prototype for the
28788 \labelwidthstring 00.00.0000
28789 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
28792 \begin_layout Standard
28793 An example of using the macros above is shown below:
28796 \begin_layout LyX-Code
28797 #include <pic18fregs.h>
28800 \begin_layout LyX-Code
28801 #include <signal.h>
28805 DEF_INTHIGH(high_int)
28808 \begin_layout LyX-Code
28809 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
28812 \begin_layout LyX-Code
28813 DEF_HANDLER(SIG_BCOL, _bcol_handler)
28816 \begin_layout LyX-Code
28821 SIGHANDLER(_tmr0_handler)
28824 \begin_layout LyX-Code
28828 \begin_layout LyX-Code
28829 /* action to be taken when timer 0 overflows */
28832 \begin_layout LyX-Code
28837 SIGHANDLERNAKED(_bcol_handler)
28840 \begin_layout LyX-Code
28844 \begin_layout LyX-Code
28848 \begin_layout LyX-Code
28849 /* action to be taken when bus collision occurs */
28852 \begin_layout LyX-Code
28856 \begin_layout LyX-Code
28860 \begin_layout LyX-Code
28864 \begin_layout Standard
28869 Special care should be taken when using the above scheme:
28872 \begin_layout Itemize
28873 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
28876 \begin_layout Itemize
28877 when declaring SIGHANDLERNAKED handler never forget to use
28881 for proper returning.
28884 \begin_layout Subsection
28888 \begin_layout Standard
28889 Here you can find some general tips for compiling programs with SDCC/pic16.
28892 \begin_layout Subsubsection
28896 \begin_layout Standard
28898 \begin_inset LatexCommand \index{PIC16!stack}
28902 size (that is 64 bytes) probably is enough for many programs.
28903 One must take care that when there are many levels of function nesting,
28904 or there is excessive usage of stack, its size should be extended.
28905 An example of such a case is the printf/sprintf family of functions.
28906 If you encounter problems like not being able to print integers, then you
28907 need to set the stack size around the maximum (256 for small stack model).
28908 The following diagram shows what happens when calling printf to print an
28912 \begin_layout LyX-Code
28913 printf () --> ltoa () --> ultoa () --> divschar ()
28916 \begin_layout Standard
28917 It is should be understood that stack is easily consumed when calling complicate
28919 Using command line arguments like -
28923 \begin_layout Standard
28932 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
28934 Other ways to reduce stack usage may exist.
28937 \begin_layout Subsection
28941 \begin_layout Subsubsection
28942 Extended Instruction Set
28945 \begin_layout Standard
28946 The PIC16 port emits code which is incompatible with the extended instruction
28947 set available with many newer devices.
28948 Make sure to always explicitly disable it, usually using
28951 \begin_layout Standard
28954 static __code char __at(__CONFIG4L) conf4l = /* more flags & */ _XINST_OFF_4L;
28957 \begin_layout Standard
28959 Some devices (namely 18f2455, 18f2550, 18f4455, and 18f4550) use _ENHCPU_OFF_4L
28960 instead of _XINST_OFF_4L.
28963 \begin_layout Subsubsection
28967 \begin_layout Standard
28968 The PIC16 port currently passes most but not all of the tests in SDCC's
28970 \begin_inset LatexCommand \index{Regression test (PIC16)}
28975 \begin_inset LatexCommand \ref{sec:Quality-control}
28979 ), thus no automatic regression tests are currently performed for the PIC16
28983 \begin_layout Chapter
28987 \begin_layout Standard
28988 There are several approaches to debugging your code.
28989 This chapter is meant to show your options and to give detail on some of
28994 When writing your code:
28997 \begin_layout Itemize
28998 write your code with debugging in mind (avoid duplicating code, put conceptually
28999 similar variables into structs, use structured code, have strategic points
29000 within your code where all variables are consistent, ...)
29003 \begin_layout Itemize
29004 run a syntax-checking tool like splint
29005 \begin_inset LatexCommand \index{splint (syntax checking tool)}
29010 \begin_inset LatexCommand \index{lint (syntax checking tool)}
29018 \begin_layout Standard
29028 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
29035 \begin_layout Itemize
29036 for the high level code use a C-compiler (like f.e.
29037 GCC) to compile run and debug the code on your host.
29042 \begin_layout Standard
29052 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
29056 ) on how to handle syntax extensions like __xdata, __at(), ...
29060 \begin_layout Itemize
29061 use another C-compiler to compile code for your target.
29062 Always an option but not recommended:) And not very likely to help you.
29063 If you seriously consider walking this path you should at least occasionally
29064 check portability of your code.
29065 Most commercial compiler vendors will offer an evaluation version so you
29066 can test compile your code or snippets of your code.
29069 \begin_layout Standard
29070 Debugging on a simulator:
29073 \begin_layout Itemize
29074 there is a separate section about SDCDB (section
29075 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
29082 \begin_layout Itemize
29083 or (8051 specific) use a freeware/commercial simulator which interfaces
29085 \begin_inset LatexCommand \index{AOMF, AOMF51}
29090 \begin_inset LatexCommand \ref{OMF file}
29094 ) optionally generated by SDCC.
29097 \begin_layout Standard
29098 Debugging On-target:
29101 \begin_layout Itemize
29102 use a MCU port pin to serially output debug data to the RS232 port of your
29104 You'll probably want some level shifting device typically involving a MAX232
29106 If the hardware serial port of the MCU is not available search for 'Software
29107 UART' in your favourite search machine.
29110 \begin_layout Itemize
29111 use an on-target monitor.
29112 In this context a monitor is a small program which usually accepts commands
29113 via a serial line and allows to set program counter, to single step through
29114 a program and read/write memory locations.
29115 For the 8051 good examples of monitors are paulmon and cmon51 (see section
29117 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
29124 \begin_layout Itemize
29125 toggle MCU port pins at strategic points within your code and use an oscilloscop
29129 digital oscilloscope
29132 \begin_inset LatexCommand \index{Oscilloscope}
29136 with deep trace memory is really helpful especially if you have to debug
29137 a realtime application.
29138 If you need to monitor more pins than your oscilloscope provides you can
29139 sometimes get away with a small R-2R network.
29140 On a single channel oscilloscope you could f.e.
29141 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
29143 \begin_inset Formula $\Omega$
29146 resistor and the other one by a 5\InsetSpace ~
29148 \begin_inset Formula $\Omega$
29151 resistor to the oscilloscope probe (check output drive capability of the
29152 pins you want to monitor).
29153 If you need to monitor many more pins a
29160 \begin_layout Itemize
29174 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
29179 Usually very expensive.
29180 And very nice to have too.
29181 And usually locks you (for years...) to the devices the ICE can emulate.
29185 \begin_layout Itemize
29186 use a remote debugger.
29187 In most 8-bit systems the symbol information is not available on the target,
29188 and a complete debugger is too bulky for the target system.
29189 Therefore usually a debugger on the host system connects to an on-target
29190 debugging stub which accepts only primitive commands.
29193 Terms to enter into your favourite search engine could be 'remote debugging',
29194 'gdb stub' or 'inferior debugger'.
29198 \begin_layout Itemize
29199 use an on target hardware debugger.
29200 Some of the more modern MCUs include hardware support for setting break
29201 points and monitoring/changing variables by using dedicated hardware pins.
29202 This facility doesn't require additional code to run on the target and
29207 doesn't affect runtime behaviour until a breakpoint is hit.
29208 For the mcs51 most hardware debuggers use the AOMF
29209 \begin_inset LatexCommand \index{AOMF, AOMF51}
29214 \begin_inset LatexCommand \ref{OMF file}
29222 \begin_layout Standard
29226 \begin_layout Itemize
29227 if you are not familiar with any of the following terms you're likely to
29228 run into problems rather sooner than later:
29245 As an embedded programmer you
29249 to know them so why not look them up
29253 you have problems?)
29256 \begin_layout Itemize
29257 tell someone else about your problem (actually this is a surprisingly effective
29258 means to hunt down the bug even if the listener is not familiar with your
29260 As 'failure to communicate' is probably one of the job-induced deformations
29261 of an embedded programmer this is highly encouraged.
29264 \begin_layout Section
29265 Debugging with SDCDB
29266 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
29271 \begin_inset LatexCommand \index{SDCDB (debugger)}
29278 \begin_layout Standard
29279 SDCC is distributed with a source level debugger
29280 \begin_inset LatexCommand \index{Debugger}
29285 The debugger uses a command line interface, the command repertoire of the
29286 debugger has been kept as close to gdb
29287 \begin_inset LatexCommand \index{gdb}
29291 (the GNU debugger) as possible.
29292 The configuration and build process is part of the standard compiler installati
29293 on, which also builds and installs the debugger in the target directory
29294 specified during configuration.
29295 The debugger allows you debug BOTH at the C source and at the ASM source
29299 \begin_layout Subsection
29300 Compiling for Debugging
29303 \begin_layout Standard
29308 \begin_layout Standard
29318 \begin_inset LatexCommand \index{-\/-debug}
29322 option must be specified for all files for which debug information is to
29324 The compiler generates a .adb file for each of these files.
29325 The linker creates the .cdb
29326 \begin_inset LatexCommand \index{<file>.cdb}
29331 \begin_inset LatexCommand \index{<file>.adb}
29335 files and the address information.
29336 This .cdb is used by the debugger.
29339 \begin_layout Subsection
29340 How the Debugger Works
29343 \begin_layout Standard
29348 \begin_layout Standard
29357 -debug option is specified the compiler generates extra symbol information
29358 some of which are put into the assembler source and some are put into the
29360 Then the linker creates the .cdb file from the individual .adb files with
29361 the address information for the symbols.
29362 The debugger reads the symbolic information generated by the compiler &
29363 the address information generated by the linker.
29364 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
29365 execution is controlled by the debugger.
29366 When a command is issued for the debugger, it translates it into appropriate
29367 commands for the simulator.
29368 (Currently SDCDM only connects to the simulator but
29373 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
29377 is an effort to connect directly to the hardware.)
29380 \begin_layout Subsection
29381 Starting the Debugger SDCDB
29384 \begin_layout Standard
29385 The debugger can be started using the following command line.
29386 (Assume the file you are debugging has the file name foo).
29400 The debugger will look for the following files.
29403 \begin_layout Itemize
29404 foo.c - the source file.
29407 \begin_layout Itemize
29408 foo.cdb - the debugger symbol information file.
29411 \begin_layout Itemize
29412 foo.ihx - the Intel hex format
29413 \begin_inset LatexCommand \index{Intel hex format}
29420 \begin_layout Subsection
29421 SDCDB Command Line Options
29424 \begin_layout Itemize
29429 \begin_layout Standard
29438 -directory=<source file directory> this option can used to specify the directory
29440 The debugger will look into the directory list specified for source, cdb
29442 The items in the directory list must be separated by ':', e.g.
29443 if the source files can be in the directories /home/src1 and /home/src2,
29448 \begin_layout Standard
29457 -directory option should be -
29461 \begin_layout Standard
29470 -directory=/home/src1:/home/src2.
29471 Note there can be no spaces in the option.
29475 \begin_layout Itemize
29476 -cd <directory> - change to the <directory>.
29479 \begin_layout Itemize
29480 -fullname - used by GUI front ends.
29483 \begin_layout Itemize
29484 -cpu <cpu-type> - this argument is passed to the simulator please see the
29485 simulator docs for details.
29488 \begin_layout Itemize
29489 -X <Clock frequency > this options is passed to the simulator please see
29490 the simulator docs for details.
29493 \begin_layout Itemize
29494 -s <serial port file> passed to simulator see the simulator docs for details.
29497 \begin_layout Itemize
29498 -S <serial in,out> passed to simulator see the simulator docs for details.
29501 \begin_layout Itemize
29502 -k <port number> passed to simulator see the simulator docs for details.
29505 \begin_layout Subsection
29506 SDCDB Debugger Commands
29509 \begin_layout Standard
29510 As mentioned earlier the command interface for the debugger has been deliberatel
29511 y kept as close the GNU debugger gdb, as possible.
29512 This will help the integration with existing graphical user interfaces
29513 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
29514 If you use a graphical user interface for the debugger you can skip this
29518 \begin_layout Subsubsection*
29519 break [line | file:line | function | file:function]
29522 \begin_layout Standard
29523 Set breakpoint at specified line or function:
29532 sdcdb>break foo.c:100
29534 sdcdb>break funcfoo
29536 sdcdb>break foo.c:funcfoo
29539 \begin_layout Subsubsection*
29540 clear [line | file:line | function | file:function ]
29543 \begin_layout Standard
29544 Clear breakpoint at specified line or function:
29553 sdcdb>clear foo.c:100
29555 sdcdb>clear funcfoo
29557 sdcdb>clear foo.c:funcfoo
29560 \begin_layout Subsubsection*
29564 \begin_layout Standard
29565 Continue program being debugged, after breakpoint.
29568 \begin_layout Subsubsection*
29572 \begin_layout Standard
29573 Execute till the end of the current function.
29576 \begin_layout Subsubsection*
29580 \begin_layout Standard
29581 Delete breakpoint number 'n'.
29582 If used without any option clear ALL user defined break points.
29585 \begin_layout Subsubsection*
29586 info [break | stack | frame | registers ]
29589 \begin_layout Itemize
29590 info break - list all breakpoints
29593 \begin_layout Itemize
29594 info stack - show the function call stack.
29597 \begin_layout Itemize
29598 info frame - show information about the current execution frame.
29601 \begin_layout Itemize
29602 info registers - show content of all registers.
29605 \begin_layout Subsubsection*
29609 \begin_layout Standard
29610 Step program until it reaches a different source line.
29611 Note: pressing <return> repeats the last command.
29614 \begin_layout Subsubsection*
29618 \begin_layout Standard
29619 Step program, proceeding through subroutine calls.
29622 \begin_layout Subsubsection*
29626 \begin_layout Standard
29627 Start debugged program.
29630 \begin_layout Subsubsection*
29634 \begin_layout Standard
29635 Print type information of the variable.
29638 \begin_layout Subsubsection*
29642 \begin_layout Standard
29643 print value of variable.
29646 \begin_layout Subsubsection*
29650 \begin_layout Standard
29651 load the given file name.
29652 Note this is an alternate method of loading file for debugging.
29655 \begin_layout Subsubsection*
29659 \begin_layout Standard
29660 print information about current frame.
29663 \begin_layout Subsubsection*
29667 \begin_layout Standard
29668 Toggle between C source & assembly source.
29671 \begin_layout Subsubsection*
29672 ! simulator command
29675 \begin_layout Standard
29676 Send the string following '!' to the simulator, the simulator response is
29678 Note the debugger does not interpret the command being sent to the simulator,
29679 so if a command like 'go' is sent the debugger can loose its execution
29680 context and may display incorrect values.
29683 \begin_layout Subsubsection*
29687 \begin_layout Standard
29690 My name is Bobby Brown"
29693 \begin_layout Subsection
29694 Interfacing SDCDB with DDD
29697 \begin_layout Standard
29698 \begin_inset Note Note
29701 \begin_layout Standard
29702 The screenshot was converted from png to eps with:
29703 \begin_inset Quotes sld
29706 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
29707 \begin_inset Quotes srd
29710 which produces a pretty compact eps file which is free from compression
29714 \begin_layout Standard
29715 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
29716 as this broke the build system on Sourceforge (pdf-file was broken.
29717 pdflatex does not accept eps files).
29725 \begin_layout Standard
29741 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
29747 shows a screenshot of a debugging session with DDD
29748 \begin_inset LatexCommand \index{DDD (debugger)}
29752 (Unix only) on a simulated 8032.
29753 The debugging session might not run as smoothly as the screenshot suggests.
29754 The debugger allows setting of breakpoints, displaying and changing variables,
29755 single stepping through C and assembler code.
29758 The source was compiled with
29772 \begin_layout Standard
29784 -debug ddd_example.c
29797 and DDD was invoked with
29804 ddd -debugger "sdcdb -cpu 8032 ddd_example"
29807 \begin_layout Standard
29808 \begin_inset Note Note
29811 \begin_layout Standard
29812 Check that the double quotes or an apostroph within the command line survive
29813 the LyX tool chain.
29814 Previously the apostrophs got slanted in the PDF output so a cut and paste
29823 \begin_layout Subsection
29824 Interfacing SDCDB with XEmacs
29825 \begin_inset LatexCommand \index{XEmacs}
29830 \begin_inset LatexCommand \index{Emacs}
29837 \begin_layout Standard
29838 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
29839 sdcdb.el and sdcdbsrc.el.
29840 These two files can be found in the $(prefix)/bin directory after the installat
29842 These files need to be loaded into XEmacs for the interface to work.
29843 This can be done at XEmacs startup time by inserting the following into
29844 your '.xemacs' file (which can be found in your HOME directory):
29850 (load-file sdcdbsrc.el)
29856 .xemacs is a lisp file so the () around the command is REQUIRED.
29857 The files can also be loaded dynamically while XEmacs is running, set the
29858 environment variable 'EMACSLOADPATH' to the installation bin directory
29859 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
29860 To start the interface enter the following command:
29874 You will prompted to enter the file name to be debugged.
29879 The command line options that are passed to the simulator directly are
29880 bound to default values in the file sdcdbsrc.el.
29881 The variables are listed below, these values maybe changed as required.
29884 \begin_layout Itemize
29885 sdcdbsrc-cpu-type '51
29888 \begin_layout Itemize
29889 sdcdbsrc-frequency '11059200
29892 \begin_layout Itemize
29893 sdcdbsrc-serial nil
29896 \begin_layout Standard
29897 The following is a list of key mapping for the debugger interface.
29900 \begin_layout Standard
29923 binding\InsetSpace ~
29961 -------\InsetSpace ~
30032 sdcdb-back-from-src\InsetSpace ~
30061 rom-src\InsetSpace ~
30071 SDCDB continue command
30089 sdcdb-step-from-src\InsetSpace ~
30118 hatis-c-sexp\InsetSpace ~
30128 SDCDB ptypecommand for data at
30195 sdcdbsrc-delete\InsetSpace ~
30210 B Delete all breakpoints if no arg
30259 given or delete arg (C-u arg x)
30278 -frame\InsetSpace ~
30293 SDCDB Display current frame if no arg,
30342 given or display frame arg
30410 sdcdbsrc-goto-sdcdb\InsetSpace ~
30420 Goto the SDCDB output buffer
30439 t-c-sexp\InsetSpace ~
30450 SDCDB print command for data at
30517 sdcdbsrc-goto-sdcdb\InsetSpace ~
30528 o the SDCDB output buffer
30546 sdcdbsrc-mode\InsetSpace ~
30562 Toggles Sdcdbsrc mode (turns it
30578 sdcdb-finish-from-src\InsetSpace ~
30586 SDCDB finish command
30620 Set break for line with point
30635 sdcdbsrc-mode\InsetSpace ~
30651 Toggle Sdcdbsrc mode
30667 dbsrc-srcmode\InsetSpace ~
30691 \begin_layout Chapter
30695 \begin_layout Standard
30696 Here are a few guidelines that will help the compiler generate more efficient
30697 code, some of the tips are specific to this compiler others are generally
30698 good programming practice.
30701 \begin_layout Itemize
30702 Use the smallest data type to represent your data-value.
30703 If it is known in advance that the value is going to be less than 256 then
30704 use an 'unsigned char' instead of a 'short' or 'int'.
30705 Please note, that ANSI C requires both signed and unsigned chars to be
30706 promoted to 'signed int'
30707 \begin_inset LatexCommand \index{promotion to signed int}
30712 \begin_inset Marginal
30715 \begin_layout Standard
30724 before doing any operation.
30726 \begin_inset LatexCommand \index{type promotion}
30731 \begin_inset LatexCommand \label{type promotion}
30735 can be omitted, if the result is the same.
30736 The effect of the promotion rules together with the sign-extension is often
30741 \begin_layout Verse
30744 unsigned char uc = 0xfe;
30746 if (uc * uc < 0) /* this is true! */
30759 \begin_layout Standard
30766 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
30774 \begin_layout Verse
30777 (unsigned char) -12 / (signed char) -3 = ...
30780 \begin_layout Standard
30781 No, the result is not 4:
30784 \begin_layout Verse
30787 (int) (unsigned char) -12 / (int) (signed char) -3 =
30789 (int) (unsigned char)
30790 0xf4 / (int) (signed char) 0xfd =
30792 (int) 0x00f4 / (int) 0xfffd =
30797 (int) 244 / (int) -3 =
30799 (int) -81 = (int) 0xffaf;
30802 \begin_layout Standard
30803 Don't complain, that gcc gives you a different result.
30804 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
30805 Therefore the results are different.
30808 \begin_inset Quotes sld
30812 \begin_inset Quotes srd
30818 \begin_layout Quote
30821 If well-defined overflow characteristics are important and negative values
30822 are not, or if you want to steer clear of sign-extension problems when
30823 manipulating bits or bytes, use one of the corresponding unsigned types.
30824 (Beware when mixing signed and unsigned values in expressions, though.)
30827 character types (especially unsigned char) can be used as "tiny" integers,
30828 doing so is sometimes more trouble than it's worth, due to unpredictable
30829 sign extension and increased code size.
30833 \begin_layout Itemize
30834 Use unsigned when it is known in advance that the value is not going to
30836 This helps especially if you are doing division or multiplication, bit-shifting
30837 or are using an array index.
30840 \begin_layout Itemize
30841 NEVER jump into a LOOP.
30844 \begin_layout Itemize
30845 Declare the variables to be local
30846 \begin_inset LatexCommand \index{local variables}
30850 whenever possible, especially loop control variables (induction).
30853 \begin_layout Itemize
30854 Have a look at the assembly listing to get a
30855 \begin_inset Quotes sld
30859 \begin_inset Quotes srd
30862 for the code generation.
30865 \begin_layout Section
30866 Porting code from or to other compilers
30867 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
30874 \begin_layout Itemize
30875 check whether endianness of the compilers differs and adapt where needed.
30878 \begin_layout Itemize
30879 check the device specific header files
30880 \begin_inset LatexCommand \index{Header files}
30885 \begin_inset LatexCommand \index{Include files}
30889 for compiler specific syntax.
30890 Eventually include the file <compiler.h
30891 \begin_inset LatexCommand \index{compiler.h (include file)}
30896 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
30900 to allow using common header files.
30903 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
30910 \begin_layout Itemize
30911 check whether the startup code contains the correct initialization (watchdog,
30915 \begin_layout Itemize
30916 check whether the sizes of short, int, long match.
30919 \begin_layout Itemize
30920 check if some 16 or 32 bit hardware registers require a specific addressing
30921 order (least significant or most significant byte first) and adapt if needed
30930 relate to time and not to lower/upper memory location here, so this is
30935 the same as endianness).
30938 \begin_layout Itemize
30939 check whether the keyword
30943 is used where needed.
30944 The compilers might differ in their optimization characteristics (as different
30945 versions of the same compiler might also use more clever optimizations
30946 this is good idea anyway).
30948 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
30955 \begin_layout Itemize
30956 check that the compilers are not told to supress warnings.
30959 \begin_layout Itemize
30960 check and convert compiler specific extensions (interrupts, memory areas,
30964 \begin_layout Itemize
30965 check for differences in type promotion.
30966 Especially check for math operations on
30975 For the sake of C99 compatibility SDCC will probably promote these to
30979 more often than other compilers.
30980 Eventually insert explicit casts to
30989 Also check that the ~\InsetSpace ~
30991 \begin_inset LatexCommand \index{\~\/ Operator}
30998 \begin_inset LatexCommand \index{bit}
31004 variables, use the !\InsetSpace ~
31007 \begin_inset LatexCommand \ref{type promotion}
31012 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
31019 \begin_layout Itemize
31020 check the assembly code generated for interrupt routines (f.e.
31021 for calls to possibly non-reentrant library functions).
31024 \begin_layout Itemize
31025 check whether timing loops result in proper timing (or preferably consider
31026 a rewrite of the code with timer based delays instead).
31029 \begin_layout Itemize
31030 check for differences in printf parameters (some compilers push (va_arg
31031 \begin_inset LatexCommand \index{vararg, va\_arg}
31035 ) char variables as
31039 others push them as
31045 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
31052 \begin_layout Itemize
31053 check the resulting memory map
31054 \begin_inset LatexCommand \index{Memory map}
31059 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
31060 ly idata, pdata, xdata).
31061 Eventually check if unexpected library functions are included.
31064 \begin_layout Section
31066 \begin_inset LatexCommand \index{Tools}
31070 included in the distribution
31073 \begin_layout Standard
31075 \begin_inset Tabular
31076 <lyxtabular version="3" rows="12" columns="3">
31078 <column alignment="left" valignment="top" leftline="true" width="0pt">
31079 <column alignment="left" valignment="top" leftline="true" width="0pt">
31080 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
31081 <row topline="true" bottomline="true">
31082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31085 \begin_layout Standard
31093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31096 \begin_layout Standard
31104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31107 \begin_layout Standard
31116 <row topline="true">
31117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31120 \begin_layout Standard
31122 \begin_inset LatexCommand \index{uCsim}
31131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31134 \begin_layout Standard
31135 Simulator for various architectures
31140 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31143 \begin_layout Standard
31150 <row topline="true">
31151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31154 \begin_layout Standard
31160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31163 \begin_layout Standard
31165 \begin_inset LatexCommand \index{Header files}
31170 \begin_inset LatexCommand \index{Include files}
31179 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31182 \begin_layout Standard
31183 sdcc/support/scripts
31189 <row topline="true">
31190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31193 \begin_layout Standard
31199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31202 \begin_layout Standard
31203 header file conversion
31208 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31211 \begin_layout Standard
31212 sdcc/support/scripts
31218 <row topline="true">
31219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31222 \begin_layout Standard
31228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31231 \begin_layout Standard
31237 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31240 \begin_layout Standard
31256 <row topline="true">
31257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31260 \begin_layout Standard
31266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31269 \begin_layout Standard
31275 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31278 \begin_layout Standard
31294 <row topline="true">
31295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31298 \begin_layout Standard
31304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31307 \begin_layout Standard
31313 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31316 \begin_layout Standard
31332 <row topline="true">
31333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31336 \begin_layout Standard
31342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31345 \begin_layout Standard
31351 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31354 \begin_layout Standard
31370 <row topline="true">
31371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31374 \begin_layout Standard
31380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31383 \begin_layout Standard
31389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31392 \begin_layout Standard
31408 <row topline="true">
31409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31412 \begin_layout Standard
31418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31421 \begin_layout Standard
31427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31430 \begin_layout Standard
31446 <row topline="true">
31447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31450 \begin_layout Standard
31456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31459 \begin_layout Standard
31465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31468 \begin_layout Standard
31484 <row topline="true" bottomline="true">
31485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31488 \begin_layout Standard
31494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31497 \begin_layout Standard
31499 \begin_inset LatexCommand \index{packihx (tool)}
31508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31511 \begin_layout Standard
31536 \begin_layout Section
31538 \begin_inset LatexCommand \index{Documentation}
31542 included in the distribution
31545 \begin_layout Standard
31547 \begin_inset Tabular
31548 <lyxtabular version="3" rows="10" columns="2">
31550 <column alignment="block" valignment="top" leftline="true" width="40col%">
31551 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
31552 <row topline="true" bottomline="true" endhead="true">
31553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31556 \begin_layout Standard
31564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31567 \begin_layout Standard
31570 Filename / Where to get
31576 <row topline="true">
31577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31580 \begin_layout Standard
31581 SDCC Compiler User Guide
31586 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31589 \begin_layout Standard
31590 You're reading it right now
31602 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
31612 <row topline="true">
31613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31616 \begin_layout Standard
31622 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31625 \begin_layout Standard
31638 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31648 <row topline="true">
31649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31652 \begin_layout Standard
31654 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
31659 \begin_inset LatexCommand \index{Assembler documentation}
31666 \begin_inset LatexCommand \index{aslink}
31671 \begin_inset LatexCommand \index{Linker documentation}
31680 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31683 \begin_layout Standard
31684 sdcc/as/doc/asxhtm.html
31696 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
31706 <row topline="true">
31707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31710 \begin_layout Standard
31711 SDCC regression test
31712 \begin_inset LatexCommand \index{Regression test}
31721 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31724 \begin_layout Standard
31725 sdcc/doc/test_suite_spec.pdf
31737 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
31747 <row topline="true">
31748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31751 \begin_layout Standard
31757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31760 \begin_layout Standard
31773 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
31783 <row topline="true">
31784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31787 \begin_layout Standard
31788 Notes on debugging with SDCDB
31789 \begin_inset LatexCommand \index{SDCDB (debugger)}
31798 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31801 \begin_layout Standard
31802 sdcc/debugger/README
31814 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
31824 <row topline="true">
31825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31828 \begin_layout Standard
31830 \begin_inset LatexCommand \index{uCsim}
31834 Software simulator for microcontrollers
31839 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31842 \begin_layout Standard
31872 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
31882 <row topline="true">
31883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31886 \begin_layout Standard
31887 Temporary notes on the pic16
31888 \begin_inset LatexCommand \index{PIC16}
31897 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31900 \begin_layout Standard
31901 sdcc/src/pic16/NOTES
31913 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
31923 <row topline="true" bottomline="true">
31924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31927 \begin_layout Standard
31928 SDCC internal documentation (debugging file format)
31933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31936 \begin_layout Standard
31966 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
31985 \begin_layout Section
31986 Related open source tools
31987 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
31992 \begin_inset LatexCommand \index{Related tools}
31999 \begin_layout Standard
32001 \begin_inset Tabular
32002 <lyxtabular version="3" rows="16" columns="3">
32004 <column alignment="left" valignment="top" leftline="true" width="0pt">
32005 <column alignment="block" valignment="top" leftline="true" width="30line%">
32006 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
32007 <row topline="true" bottomline="true">
32008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32011 \begin_layout Standard
32019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32022 \begin_layout Standard
32030 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32033 \begin_layout Standard
32042 <row topline="true">
32043 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32046 \begin_layout Standard
32048 \begin_inset LatexCommand \index{gpsim (pic simulator)}
32057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32060 \begin_layout Standard
32066 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32069 \begin_layout Standard
32070 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
32080 <row topline="true">
32081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32084 \begin_layout Standard
32086 \begin_inset LatexCommand \index{gputils (pic tools)}
32095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32098 \begin_layout Standard
32104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32107 \begin_layout Standard
32108 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
32118 <row topline="true">
32119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32122 \begin_layout Standard
32128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32131 \begin_layout Standard
32137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32140 \begin_layout Standard
32141 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
32151 <row topline="true">
32152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32155 \begin_layout Standard
32161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32164 \begin_layout Standard
32165 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
32171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32174 \begin_layout Standard
32175 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
32185 <row topline="true">
32186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32189 \begin_layout Standard
32191 \begin_inset LatexCommand \index{indent (source formatting tool)}
32200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32203 \begin_layout Standard
32204 Formats C source - Master of the white spaces
32209 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32212 \begin_layout Standard
32213 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
32223 <row topline="true">
32224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32227 \begin_layout Standard
32229 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
32238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32241 \begin_layout Standard
32242 Object file conversion, checksumming, ...
32247 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32250 \begin_layout Standard
32251 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
32261 <row topline="true">
32262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32265 \begin_layout Standard
32267 \begin_inset LatexCommand \index{objdump (tool)}
32276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32279 \begin_layout Standard
32280 Object file conversion, ...
32285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32288 \begin_layout Standard
32289 Part of binutils (should be there anyway)
32295 <row topline="true">
32296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32299 \begin_layout Standard
32305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32308 \begin_layout Standard
32309 8051 monitor (hex up-/download, single step, disassemble)
32314 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32317 \begin_layout Standard
32318 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
32328 <row topline="true">
32329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32332 \begin_layout Standard
32334 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
32343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32346 \begin_layout Standard
32347 Source code documentation system
32352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32355 \begin_layout Standard
32356 \begin_inset LatexCommand \url{http://www.doxygen.org}
32366 <row topline="true">
32367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32370 \begin_layout Standard
32376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32379 \begin_layout Standard
32380 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
32385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32388 \begin_layout Standard
32389 \begin_inset LatexCommand \url{http://www.kdevelop.org}
32399 <row topline="true">
32400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32403 \begin_layout Standard
32409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32412 \begin_layout Standard
32413 8051 monitor (hex up-/download, single step, disassemble)
32418 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32421 \begin_layout Standard
32422 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
32432 <row topline="true">
32433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32436 \begin_layout Standard
32438 \begin_inset LatexCommand \index{splint (syntax checking tool)}
32447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32450 \begin_layout Standard
32451 Statically checks c sources (see
32452 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
32461 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32464 \begin_layout Standard
32465 \begin_inset LatexCommand \url{http://www.splint.org}
32475 <row topline="true" bottomline="true">
32476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32479 \begin_layout Standard
32481 \begin_inset LatexCommand \index{DDD (debugger)}
32490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32493 \begin_layout Standard
32494 Debugger, serves nicely as GUI to SDCDB
32495 \begin_inset LatexCommand \index{SDCDB (debugger)}
32504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32507 \begin_layout Standard
32508 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
32518 <row bottomline="true">
32519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32522 \begin_layout Standard
32524 \begin_inset LatexCommand \index{d52}
32529 \begin_inset LatexCommand \index{d52 (disassembler)}
32538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32541 \begin_layout Standard
32542 Disassembler, can count instruction cycles
32543 \begin_inset LatexCommand \index{instruction cycles (count)}
32547 , use with options -pnd
32552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32555 \begin_layout Standard
32556 \begin_inset LatexCommand \url{http://www.8052.com/users/disasm/}
32566 <row bottomline="true">
32567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32570 \begin_layout Standard
32572 \begin_inset LatexCommand \index{cmake}
32581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32584 \begin_layout Standard
32585 Cross platform build system, generates Makefiles
32586 \begin_inset LatexCommand \index{Makefile}
32590 and project workspaces
32591 \begin_inset LatexCommand \index{project workspace}
32600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32603 \begin_layout Standard
32604 \begin_inset LatexCommand \url{http://www.cmake.org}
32612 and a dedicated wiki entry:
32613 \begin_inset LatexCommand \url{http://www.cmake.org/Wiki/CmakeSdcc}
32632 \begin_layout Section
32633 Related documentation / recommended reading
32636 \begin_layout Standard
32638 \begin_inset Tabular
32639 <lyxtabular version="3" rows="7" columns="3">
32641 <column alignment="left" valignment="top" leftline="true" width="0pt">
32642 <column alignment="left" valignment="top" leftline="true" width="0">
32643 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32644 <row topline="true" bottomline="true">
32645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32648 \begin_layout Standard
32656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32659 \begin_layout Standard
32667 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32670 \begin_layout Standard
32679 <row topline="true">
32680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32683 \begin_layout Standard
32698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32701 \begin_layout Standard
32703 \begin_inset LatexCommand \index{C Reference card}
32712 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32715 \begin_layout Standard
32716 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
32726 <row topline="true">
32727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32730 \begin_layout Standard
32736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32739 \begin_layout Standard
32741 \begin_inset LatexCommand \index{C FAQ}
32750 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32753 \begin_layout Standard
32754 \begin_inset LatexCommand \url{http://www.c-faq.com}
32764 <row topline="true">
32765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32768 \begin_layout Standard
32774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32777 \begin_layout Standard
32778 \begin_inset Quotes sld
32782 \begin_inset Quotes srd
32790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32793 \begin_layout Standard
32796 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
32806 <row topline="true">
32807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32810 \begin_layout Standard
32816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32819 \begin_layout Standard
32820 \begin_inset Quotes sld
32823 Extensions for Embedded C
32824 \begin_inset Quotes srd
32832 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32835 \begin_layout Standard
32838 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
32848 <row topline="true">
32849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32852 \begin_layout Standard
32858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32861 \begin_layout Standard
32862 Latest datasheet of target CPU
32867 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32870 \begin_layout Standard
32877 <row topline="true" bottomline="true">
32878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32881 \begin_layout Standard
32887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32890 \begin_layout Standard
32891 Revision history of datasheet
32896 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32899 \begin_layout Standard
32915 \begin_layout Section
32916 Application notes specifically for SDCC
32919 \begin_layout Standard
32920 SDCC makes no claims about the completeness of this list and about up-to-datenes
32921 s or correctness of the application notes
32922 \begin_inset LatexCommand \index{Application notes}
32929 \begin_layout Standard
32933 \begin_inset Tabular
32934 <lyxtabular version="3" rows="7" columns="3">
32936 <column alignment="block" valignment="top" leftline="true" width="17col%">
32937 <column alignment="block" valignment="top" leftline="true" width="27col%">
32938 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
32939 <row topline="true" bottomline="true">
32940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32943 \begin_layout Standard
32952 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
32955 \begin_layout Standard
32964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32967 \begin_layout Standard
32977 <row topline="true">
32978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32981 \begin_layout Standard
32989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32992 \begin_layout Standard
32995 Using the SDCC Compiler for the DS80C400
32996 \begin_inset LatexCommand \index{DS80C400}
33005 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33008 \begin_layout Standard
33011 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
33021 <row topline="true">
33022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33025 \begin_layout Standard
33033 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
33036 \begin_layout Standard
33039 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
33040 \begin_inset LatexCommand \index{DS89C4x0}
33044 Family of Microcontrollers
33049 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33052 \begin_layout Standard
33055 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
33065 <row topline="true">
33066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33069 \begin_layout Standard
33072 Silicon Laboratories / Cygnal
33077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33080 \begin_layout Standard
33083 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
33084 \begin_inset LatexCommand \index{IDE}
33093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33096 \begin_layout Standard
33099 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
33109 <row topline="true">
33110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33113 \begin_layout Standard
33116 Ramtron / Goal Semiconductor
33121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33124 \begin_layout Standard
33127 Interfacing SDCC to Syn and Textpad
33132 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33135 \begin_layout Standard
33138 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
33148 <row topline="true">
33149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33152 \begin_layout Standard
33155 Ramtron / Goal Semiconductor
33160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33163 \begin_layout Standard
33166 Installing and Configuring SDCC and Crimson Editor
33171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33174 \begin_layout Standard
33177 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
33187 <row topline="true" bottomline="true">
33188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33191 \begin_layout Standard
33199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33202 \begin_layout Standard
33205 MSC12xx Programming with SDCC
33210 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33213 \begin_layout Standard
33216 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
33233 \begin_layout Section
33237 \begin_layout Standard
33238 Some questions answered, some pointers given - it might be time to in turn
33246 \begin_layout Itemize
33247 can you solve your project with the selected microcontroller? Would you
33248 find out early or rather late that your target is too small/slow/whatever?
33249 Can you switch to a slightly better device if it doesn't fit?
33252 \begin_layout Itemize
33253 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
33254 and/or another programming language be more adequate? Would an operating
33255 system on the target device help?
33258 \begin_layout Itemize
33259 if you solved the problem, will the marketing department be happy?
33262 \begin_layout Itemize
33263 if the marketing department is happy, will customers be happy?
33266 \begin_layout Itemize
33267 if you're the project manager, marketing department and maybe even the customer
33268 in one person, have you tried to see the project from the outside?
33271 \begin_layout Itemize
33272 is the project done if you think it is done? Or is just that other interface/pro
33273 tocol/feature/configuration/option missing? How about website, manual(s),
33274 internationali(z|s)ation, packaging, labels, 2nd source for components,
33275 electromagnetic compatability/interference, documentation for production,
33276 production test software, update mechanism, patent issues?
33279 \begin_layout Itemize
33280 is your project adequately positioned in that magic triangle: fame, fortune,
33284 \begin_layout Standard
33285 Maybe not all answers to these questions are known and some answers may
33290 , nevertheless knowing these questions may help you to avoid burnout
33294 \begin_layout Standard
33295 burnout is bad for electronic devices, programmers and motorcycle tyres
33301 Chances are you didn't want to hear some of them...
33304 \begin_layout Chapter
33306 \begin_inset LatexCommand \index{Support}
33313 \begin_layout Standard
33314 SDCC has grown to be a large project.
33315 The compiler alone (without the preprocessor, assembler and linker) is
33316 well over 150,000 lines of code (blank stripped).
33317 The open source nature of this project is a key to its continued growth
33319 You gain the benefit and support of many active software developers and
33321 Is SDCC perfect? No, that's why we need your help.
33322 The developers take pride in fixing reported bugs.
33323 You can help by reporting the bugs and helping other SDCC users.
33324 There are lots of ways to contribute, and we encourage you to take part
33325 in making SDCC a great software package.
33329 \begin_layout Standard
33330 The SDCC project is hosted on the SDCC sourceforge site at
33331 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
33336 You'll find the complete set of mailing lists
33337 \begin_inset LatexCommand \index{Mailing list(s)}
33341 , forums, bug reporting system, patch submission
33342 \begin_inset LatexCommand \index{Patch submission}
33347 \begin_inset LatexCommand \index{download}
33351 area and Subversion code repository
33352 \begin_inset LatexCommand \index{Subversion code repository}
33359 \begin_layout Section
33361 \begin_inset LatexCommand \index{Bug reporting}
33366 \begin_inset LatexCommand \index{Reporting bugs}
33373 \begin_layout Standard
33374 The recommended way of reporting bugs is using the infrastructure of the
33376 You can follow the status of bug reports there and have an overview about
33380 \begin_layout Standard
33381 Bug reports are automatically forwarded to the developer mailing list and
33382 will be fixed ASAP.
33383 When reporting a bug, it is very useful to include a small test program
33384 (the smaller the better) which reproduces the problem.
33385 If you can isolate the problem by looking at the generated assembly code,
33386 this can be very helpful.
33387 Compiling your program with the -
33391 \begin_layout Standard
33401 \begin_inset LatexCommand \index{-\/-dumpall}
33405 option can sometimes be useful in locating optimization problems.
33406 When reporting a bug please make sure you:
33409 \begin_layout Enumerate
33410 Attach the code you are compiling with SDCC.
33414 \begin_layout Enumerate
33415 Specify the exact command you use to run SDCC, or attach your Makefile.
33419 \begin_layout Enumerate
33420 Specify the SDCC version (type "
33426 "), your platform, and operating system.
33430 \begin_layout Enumerate
33431 Provide an exact copy of any error message or incorrect output.
33435 \begin_layout Enumerate
33436 Put something meaningful in the subject of your message.
33439 \begin_layout Standard
33440 Please attempt to include these 5 important parts, as applicable, in all
33441 requests for support or when reporting any problems or bugs with SDCC.
33442 Though this will make your message lengthy, it will greatly improve your
33443 chance that SDCC users and developers will be able to help you.
33444 Some SDCC developers are frustrated by bug reports without code provided
33445 that they can use to reproduce and ultimately fix the problem, so please
33446 be sure to provide sample code if you are reporting a bug!
33449 \begin_layout Standard
33450 Please have a short check that you are using a recent version of SDCC and
33451 the bug is not yet known.
33452 This is the link for reporting bugs:
33453 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
33458 With SDCC on average having more than 200 downloads
33459 \begin_inset LatexCommand \index{download}
33463 on sourceforge per day
33467 \begin_layout Standard
33468 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
33469 between 2002 and 2005.
33470 This does not include other methods of distribution.
33475 there must be some users.
33476 So it's not exactly easy to find a new bug.
33477 If you find one we need it:
33479 reporting bugs is good
33484 \begin_layout Section
33485 Requesting Features
33486 \begin_inset LatexCommand \label{sub:Requesting-Features}
33491 \begin_inset LatexCommand \index{Feature request}
33496 \begin_inset LatexCommand \index{Requesting features}
33503 \begin_layout Standard
33504 Like bug reports feature requests are forwarded to the developer mailing
33506 This is the link for requesting features:
33507 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33514 \begin_layout Section
33518 \begin_layout Standard
33519 Like bug reports contributed patches are forwarded to the developer mailing
33521 This is the link for submitting patches
33522 \begin_inset LatexCommand \index{Patch submission}
33527 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
33534 \begin_layout Standard
33535 You need to specify some parameters to the
33539 command for the patches to be useful.
33540 If you modified more than one file a patch created f.e.
33545 \begin_inset Quotes sld
33548 diff -Naur unmodified_directory modified_directory >my_changes.patch
33549 \begin_inset Quotes srd
33555 will be fine, otherwise
33559 \begin_inset Quotes sld
33562 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
33563 \begin_inset Quotes srd
33573 \begin_layout Section
33577 \begin_layout Standard
33578 These links should take you directly to the
33579 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
33587 \begin_layout Standard
33588 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
33589 automated messages (mid 2003)
33595 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
33600 \begin_inset LatexCommand \index{Mailing list(s)}
33604 and forums are archived and searchable so if you are lucky someone already
33605 had a similar problem.
33606 While mails to the lists themselves are delivered promptly their web front
33607 end on sourceforge sometimes shows a severe time lag (up to several weeks),
33608 if you're seriously using SDCC please consider subscribing to the lists.
33611 \begin_layout Section
33615 \begin_layout Standard
33616 You can follow the status of the Subversion version
33617 \begin_inset LatexCommand \index{version}
33621 of SDCC by watching the Changelog
33622 \begin_inset LatexCommand \index{Changelog}
33626 in the Subversion repository
33629 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
33636 \begin_layout Section
33637 Subversion Source Code Repository
33640 \begin_layout Standard
33650 \begin_layout Standard
33664 or the filenames of the snapshot versions of SDCC include date and its
33666 \begin_inset LatexCommand \index{Subversion code repository}
33671 Subversion allows to download the source of recent or previous versions
33673 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
33677 (by number or by date).
33678 An on-line source code browser and detailled instructions are also available
33680 SDCC versions starting from 1999 up to now are available (currently the
33681 versions prior to the conversion from cvs
33682 \begin_inset LatexCommand \index{cvs|see{Subversion}}
33686 to Subversion (April 2006) are either by accessible by Subversion or by
33690 \begin_layout Section
33692 \begin_inset LatexCommand \index{Release policy}
33699 \begin_layout Standard
33700 Historically there often were long delays between official releases and
33701 the sourceforge download area tends to get not updated at all.
33702 Excuses in the past might have referred to problems with live range analysis,
33703 but as this was fixed a while ago, the current problem is that another
33704 excuse has to be found.
33705 Kidding aside, we have to get better there! On the other hand there are
33706 daily snapshots available at
33707 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
33711 , and you can always build the very last version (hopefully with many bugs
33712 fixed, and features added) from the source code available at
33713 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
33719 \begin_inset LatexCommand \index{wiki}
33724 \begin_inset LatexCommand \index{SDCC Wiki}
33729 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/}
33733 also holds some information about past and future releases.
33736 \begin_layout Section
33738 \begin_inset LatexCommand \index{Examples}
33745 \begin_layout Standard
33746 You'll find some small examples in the directory
33748 sdcc/device/examples/.
33751 More examples and libraries are available at
33753 The SDCC Open Knowledge Resource
33754 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
33761 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
33768 \begin_layout Standard
33769 \begin_inset Note Note
33772 \begin_layout Standard
33773 I did insert a reference to Paul's web site here although it seems rather
33774 dedicated to a specific 8032 board (I think it's okay because it f.e.
33775 shows LCD/Harddisc interface and has a free 8051 monitor.
33776 Independent 8032 board vendors face hard competition of heavily subsidized
33777 development boards anyway).
33780 \begin_layout Standard
33781 Maybe we should include some links to real world applications.
33782 Preferably pointer to pointers (one for each architecture) so this stays
33791 \begin_layout Section
33793 \begin_inset LatexCommand \label{sec:Quality-control}
33798 \begin_inset LatexCommand \index{Quality control}
33805 \begin_layout Standard
33806 The compiler is passed through snaphot build compile and build checks.
33812 \begin_inset LatexCommand \index{Regression test}
33816 check that SDCC itself compiles flawlessly on several host platforms (i386,
33817 Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
33818 and checks the quality of the code generated by SDCC by running the code
33819 for several target platforms through simulators.
33820 The regression test suite comprises more than 100 files which expand to
33821 more than 500 test cases which include more than 4500 tests.
33822 The results of these tests are published daily on SDCC's snapshot page
33823 (click on the red or green symbols on the right side of
33824 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
33831 \begin_layout Standard
33832 There is a separate document
33835 \begin_inset LatexCommand \index{Test suite}
33842 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
33846 about the regression test suite.
33849 \begin_layout Standard
33850 You'll find the test code in the directory
33852 sdcc/support/regression
33855 You can run these tests manually by running
33859 in this directory (or f.e.
33864 \begin_inset Quotes sld
33868 \begin_inset Quotes srd
33874 if you don't want to run the complete tests).
33875 The test code might also be interesting if you want to look for examples
33876 \begin_inset LatexCommand \index{Examples}
33880 checking corner cases of SDCC or if you plan to submit patches
33881 \begin_inset LatexCommand \index{Patch submission}
33888 \begin_layout Standard
33889 The PIC14 port uses a different set of regression tests
33890 \begin_inset LatexCommand \index{Regression test (PIC14)}
33894 , you'll find them in the directory
33896 sdcc/src/regression
33901 \begin_layout Section
33902 Use of SDCC in Education
33905 \begin_layout Standard
33914 \begin_layout Standard
33915 the phrase "use in education" might evoke the association "
33919 fit for use in education".
33920 This connotation is not intended but nevertheless risked as the licensing
33921 of SDCC makes it difficult to offer educational discounts
33927 If your rationales are to:
33930 \begin_layout Enumerate
33931 give students a chance to understand the
33935 steps of code generation
33938 \begin_layout Enumerate
33939 have a curriculum that can be extended for years.
33940 Then you could use an fpga board as target and your curriculum will seamlessly
33941 extend from logic synthesis (
33942 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
33947 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
33951 ), over assembly programming, to C to FPGA compilers (
33952 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
33959 \begin_layout Enumerate
33960 be able to insert excursions about skills like using a revision control
33961 system, submitting/applying patches, using a type-setting (as opposed to
33962 word-processing) engine LyX/LaTeX, using
33963 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
33968 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
33972 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
33973 Source Software, CPU simulation, compiler regression tests
33974 \begin_inset LatexCommand \index{Regression test}
33981 And if there should be a shortage of ideas then you can always point students
33982 to the ever-growing feature request list
33983 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33990 \begin_layout Enumerate
33991 not tie students to a specific host platform and instead allow them to use
33996 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
33998 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
34005 \begin_layout Enumerate
34006 not encourage students to use illegal copies of educational software
34009 \begin_layout Enumerate
34010 be immune to licensing/availability/price changes of the chosen tool chain
34013 \begin_layout Enumerate
34014 be able to change to a new target platform without having to adopt a new
34018 \begin_layout Enumerate
34019 have complete control over and insight into the tool chain
34022 \begin_layout Enumerate
34023 make your students aware about the pros and cons of open source software
34027 \begin_layout Enumerate
34028 give back to the public as you are probably at least partially publically
34032 \begin_layout Enumerate
34033 give students a chance to publically prove their skills and to possibly
34034 see a world wide impact
34037 \begin_layout Standard
34038 then SDCC is probably among the first choices.
34039 Well, probably SDCC might be the only choice.
34044 \begin_layout Chapter
34045 SDCC Technical Data
34048 \begin_layout Section
34050 \begin_inset LatexCommand \index{Optimizations}
34057 \begin_layout Standard
34058 SDCC performs a host of standard optimizations in addition to some MCU specific
34063 \begin_layout Subsection
34064 Sub-expression Elimination
34065 \begin_inset LatexCommand \index{Subexpression elimination}
34072 \begin_layout Standard
34073 The compiler does local and
34092 \begin_layout Verse
34100 \begin_layout Standard
34101 will be translated to
34104 \begin_layout Verse
34114 \begin_layout Standard
34115 Some subexpressions are not as obvious as the above example, e.g.:
34118 \begin_layout Verse
34126 \begin_layout Standard
34127 In this case the address arithmetic a->b[i] will be computed only once;
34128 the equivalent code in C would be.
34131 \begin_layout Verse
34141 \begin_layout Standard
34142 The compiler will try to keep these temporary variables in registers.
34145 \begin_layout Subsection
34146 Dead-Code Elimination
34147 \begin_inset LatexCommand \index{Dead-code elimination}
34154 \begin_layout Verse
34169 i = 1; \InsetSpace ~
34178 global = 1;\InsetSpace ~
34192 global = 3;\InsetSpace ~
34198 \begin_layout Standard
34202 \begin_layout Verse
34218 \begin_layout Subsection
34220 \begin_inset LatexCommand \index{Copy propagation}
34227 \begin_layout Verse
34251 \begin_layout Standard
34255 \begin_layout Verse
34279 \begin_layout Standard
34280 Note: the dead stores created by this copy propagation will be eliminated
34281 by dead-code elimination.
34284 \begin_layout Subsection
34286 \begin_inset LatexCommand \index{Loop optimization}
34291 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
34298 \begin_layout Standard
34299 Two types of loop optimizations are done by SDCC
34307 of loop induction variables.
34308 In addition to the strength reduction the optimizer marks the induction
34309 variables and the register allocator tries to keep the induction variables
34310 in registers for the duration of the loop.
34311 Because of this preference of the register allocator
34312 \begin_inset LatexCommand \index{Register allocation}
34316 , loop induction optimization causes an increase in register pressure, which
34317 may cause unwanted spilling of other temporary variables into the stack
34318 \begin_inset LatexCommand \index{stack}
34323 The compiler will generate a warning message when it is forced to allocate
34324 extra space either on the stack or data space.
34325 If this extra space allocation is undesirable then induction optimization
34326 can be eliminated either for the entire source file (with -
34330 \begin_layout Standard
34339 -noinduction option) or for a given function only using #pragma\InsetSpace ~
34341 \begin_inset LatexCommand \index{\#pragma noinduction}
34352 \begin_layout Verse
34355 for (i = 0 ; i < 100 ; i ++)
34364 \begin_layout Standard
34368 \begin_layout Verse
34373 for (i = 0; i < 100; i++)
34382 \begin_layout Standard
34383 As mentioned previously some loop invariants are not as apparent, all static
34384 address computations are also moved out of the loop.
34389 \begin_inset LatexCommand \index{Strength reduction}
34393 , this optimization substitutes an expression by a cheaper expression:
34396 \begin_layout Verse
34399 for (i=0;i < 100; i++)
34408 \begin_layout Standard
34412 \begin_layout Verse
34419 for (i=0;i< 100;i++) {
34425 ar[itemp1] = itemp2;
34443 \begin_layout Standard
34444 The more expensive multiplication
34445 \begin_inset LatexCommand \index{Multiplication}
34449 is changed to a less expensive addition.
34452 \begin_layout Subsection
34454 \begin_inset LatexCommand \index{Loop reversing}
34461 \begin_layout Standard
34462 This optimization is done to reduce the overhead of checking loop boundaries
34463 for every iteration.
34464 Some simple loops can be reversed and implemented using a
34465 \begin_inset Quotes eld
34468 decrement and jump if not zero
34469 \begin_inset Quotes erd
34473 SDCC checks for the following criterion to determine if a loop is reversible
34474 (note: more sophisticated compilers use data-dependency analysis to make
34475 this determination, SDCC uses a more simple minded analysis).
34478 \begin_layout Itemize
34479 The 'for' loop is of the form
34485 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
34495 \begin_layout Itemize
34496 The <for body> does not contain
34497 \begin_inset Quotes eld
34501 \begin_inset Quotes erd
34505 \begin_inset Quotes erd
34511 \begin_layout Itemize
34512 All goto's are contained within the loop.
34515 \begin_layout Itemize
34516 No function calls within the loop.
34519 \begin_layout Itemize
34520 The loop control variable <sym> is not assigned any value within the loop
34523 \begin_layout Itemize
34524 The loop control variable does NOT participate in any arithmetic operation
34528 \begin_layout Itemize
34529 There are NO switch statements in the loop.
34532 \begin_layout Subsection
34533 Algebraic Simplifications
34536 \begin_layout Standard
34537 SDCC does numerous algebraic simplifications, the following is a small sub-set
34538 of these optimizations.
34541 \begin_layout Verse
34544 i = j + 0;\InsetSpace ~
34548 /* changed to: */\InsetSpace ~
34554 i /= 2;\InsetSpace ~
34561 /* changed to: */\InsetSpace ~
34568 = j - j;\InsetSpace ~
34572 /* changed to: */\InsetSpace ~
34578 i = j / 1;\InsetSpace ~
34582 /* changed to: */\InsetSpace ~
34589 \begin_layout Standard
34590 Note the subexpressions
34591 \begin_inset LatexCommand \index{Subexpression}
34595 given above are generally introduced by macro expansions or as a result
34596 of copy/constant propagation.
34599 \begin_layout Subsection
34600 'switch' Statements
34601 \begin_inset LatexCommand \label{sub:'switch'-Statements}
34606 \begin_inset LatexCommand \index{switch statement}
34613 \begin_layout Standard
34614 SDCC can optimize switch statements to jump tables
34615 \begin_inset LatexCommand \index{jump tables}
34620 It makes the decision based on an estimate of the generated code size.
34621 SDCC is quite liberal in the requirements for jump table generation:
34624 \begin_layout Itemize
34625 The labels need not be in order, and the starting number need not be one
34626 or zero, the case labels are in numerical sequence or not too many case
34627 labels are missing.
34631 \begin_layout Verse
34634 switch(i) {\InsetSpace ~
34665 case 4: ...\InsetSpace ~
34697 case 5: ...\InsetSpace ~
34729 case 3: ...\InsetSpace ~
34760 case 6: ...\InsetSpace ~
34792 case 7: ...\InsetSpace ~
34824 case 8: ...\InsetSpace ~
34856 case 9: ...\InsetSpace ~
34888 case 10: ...\InsetSpace ~
34919 case 11: ...\InsetSpace ~
34986 \begin_layout Standard
34987 Both the above switch statements will be implemented using a jump-table.
34988 The example to the right side is slightly more efficient as the check for
34989 the lower boundary of the jump-table is not needed.
34993 \begin_layout Itemize
34994 The number of case labels is not larger than supported by the target architectur
34998 \begin_layout Itemize
34999 If the case labels are not in numerical sequence ('gaps' between cases)
35000 SDCC checks whether a jump table with additionally inserted dummy cases
35001 is still attractive.
35005 \begin_layout Itemize
35006 If the starting number is not zero and a check for the lower boundary of
35007 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
35012 \begin_layout Standard
35013 Switch statements which have large gaps in the numeric sequence or those
35014 that have too many case labels can be split into more than one switch statement
35015 for efficient code generation, e.g.:
35018 \begin_layout Verse
35096 \begin_layout Standard
35097 If the above switch statement is broken down into two switch statements
35100 \begin_layout Verse
35143 \begin_layout Standard
35147 \begin_layout Verse
35190 \begin_layout Standard
35191 then both the switch statements will be implemented using jump-tables whereas
35192 the unmodified switch statement will not be.
35195 \begin_layout Standard
35196 \begin_inset Note Note
35199 \begin_layout Standard
35200 There might be reasons which SDCC cannot know about to either favour or
35201 not favour jump tables.
35202 If the target system has to be as quick for the last switch case as for
35203 the first (pro jump table), or if the switch argument is known to be zero
35204 in the majority of the cases (contra jump table).
35212 \begin_layout Standard
35213 The pragma nojtbound
35214 \begin_inset LatexCommand \index{\#pragma nojtbound}
35218 can be used to turn off checking the
35231 It has no effect if a default label is supplied.
35232 Use of this pragma is dangerous: if the switch
35233 \begin_inset LatexCommand \index{switch statement}
35237 argument is not matched by a case statement the processor will happily
35241 \begin_layout Subsection
35242 Bit-shifting Operations
35243 \begin_inset LatexCommand \index{Bit shifting}
35250 \begin_layout Standard
35251 Bit shifting is one of the most frequently used operation in embedded programmin
35253 SDCC tries to implement bit-shift operations in the most efficient way
35257 \begin_layout Verse
35270 \begin_layout Standard
35271 generates the following code:
35274 \begin_layout Verse
35289 \begin_layout Standard
35290 In general SDCC will never setup a loop if the shift count is known.
35294 \begin_layout Verse
35307 \begin_layout Standard
35311 \begin_layout Verse
35335 \begin_layout Subsection
35337 \begin_inset LatexCommand \index{Bit rotation}
35344 \begin_layout Standard
35345 A special case of the bit-shift operation is bit rotation
35346 \begin_inset LatexCommand \index{rotating bits}
35350 , SDCC recognizes the following expression to be a left bit-rotation:
35353 \begin_layout Verse
35361 char i;\InsetSpace ~
35372 /* unsigned is needed for rotation */
35377 i = ((i << 1) | (i >> 7));
35386 \begin_layout Standard
35387 will generate the following code:
35390 \begin_layout Verse
35407 \begin_layout Standard
35408 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
35409 ns of this case will also be recognized as bit-rotation, i.e.:
35412 \begin_layout Verse
35415 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
35418 \begin_layout Subsection
35419 Nibble and Byte Swapping
35422 \begin_layout Standard
35423 Other special cases of the bit-shift operations are nibble or byte swapping
35424 \begin_inset LatexCommand \index{swapping nibbles/bytes}
35428 , SDCC recognizes the following expressions:
35431 \begin_layout Verse
35452 i = ((i << 4) | (i >> 4));
35458 j = ((j << 8) | (j >> 8));
35461 \begin_layout Standard
35462 and generates a swap instruction for the nibble swapping
35463 \begin_inset LatexCommand \index{Nibble swapping}
35467 or move instructions for the byte swapping
35468 \begin_inset LatexCommand \index{Byte swapping}
35474 \begin_inset Quotes sld
35478 \begin_inset Quotes srd
35481 example can be used to convert from little to big-endian or vice versa.
35482 If you want to change the endianness of a
35486 integer you have to cast to
35493 \begin_layout Standard
35494 Note that SDCC stores numbers in little-endian
35498 \begin_layout Standard
35499 Usually 8-bit processors don't care much about endianness.
35500 This is not the case for the standard 8051 which only has an instruction
35506 \begin_inset LatexCommand \index{DPTR}
35514 so little-endian is the more efficient byte order.
35520 \begin_inset LatexCommand \index{little-endian}
35525 \begin_inset LatexCommand \index{Endianness}
35530 lowest order first).
35533 \begin_layout Subsection
35535 \begin_inset LatexCommand \index{Highest Order Bit}
35540 \begin_inset LatexCommand \index{Any Order Bit}
35547 \begin_layout Standard
35548 It is frequently required to obtain the highest order bit of an integral
35549 type (long, int, short or char types).
35550 Also obtaining any other order bit is not uncommon.
35551 SDCC recognizes the following expressions to yield the highest order bit
35552 and generates optimized code for it, e.g.:
35555 \begin_layout Verse
35566 unsigned char hob1, aob1;
35570 bit hob2, hob3, aob2,
35580 hob1 = (gint >> 15) & 1;
35584 hob2 = (gint >> 15) & 1;
35588 hob3 = gint & 0x8000;
35593 aob1 = (gint >> 9) & 1;
35597 aob2 = (gint >> 8) & 1;
35601 aob3 = gint & 0x0800;
35611 \begin_layout Standard
35612 will generate the following code:
35615 \begin_layout Verse
35646 000A E5*01\InsetSpace ~
35673 000C 23\InsetSpace ~
35704 000D 54 01\InsetSpace ~
35732 000F F5*02\InsetSpace ~
35787 0011 E5*01\InsetSpace ~
35815 0013 33\InsetSpace ~
35845 0014 92*00\InsetSpace ~
35901 0016 E5*01\InsetSpace ~
35928 0018 33\InsetSpace ~
35958 0019 92*01\InsetSpace ~
36014 001B E5*01\InsetSpace ~
36073 001E 54 01\InsetSpace ~
36100 0020 F5*03\InsetSpace ~
36156 0022 E5*01\InsetSpace ~
36183 0024 13\InsetSpace ~
36213 0025 92*02\InsetSpace ~
36269 0027 E5*01\InsetSpace ~
36324 002B 92*03\InsetSpace ~
36352 \begin_layout Standard
36353 Other variations of these cases however will
36358 They are standard C expressions, so I heartily recommend these be the only
36359 way to get the highest order bit, (it is portable).
36360 Of course it will be recognized even if it is embedded in other expressions,
36364 \begin_layout Verse
36367 xyz = gint + ((gint >> 15) & 1);
36370 \begin_layout Standard
36371 will still be recognized.
36374 \begin_layout Subsection
36376 \begin_inset LatexCommand \index{Higher Order Byte}
36380 / Higher Order Word
36381 \begin_inset LatexCommand \index{Higher Order Word}
36388 \begin_layout Standard
36389 It is also frequently required to obtain a higher order byte or word of
36390 a larger integral type (long, int or short types).
36391 SDCC recognizes the following expressions to yield the higher order byte
36392 or word and generates optimized code for it, e.g.:
36395 \begin_layout Verse
36400 unsigned long int glong;
36408 unsigned char hob1,
36413 unsigned int how1, how2;
36422 hob1 = (gint >> 8) & 0xFF;
36426 hob2 = glong >> 24;
36430 how1 = (glong >> 16) & 0xFFFF;
36445 \begin_layout Standard
36446 will generate the following code:
36449 \begin_layout Verse
36480 0037 85*01*06\InsetSpace ~
36502 _foo_hob1_1_1,(_gint + 1)
36533 003A 85*05*07\InsetSpace ~
36555 _foo_hob2_1_1,(_glong + 3)
36585 003D 85*04*08\InsetSpace ~
36608 _foo_how1_1_1,(_glong + 2)
36610 0040 85*05*09\InsetSpace ~
36635 0043 85*03*0A\InsetSpace ~
36657 _foo_how2_1_1,(_glong + 1)
36659 0046 85*04*0B\InsetSpace ~
36682 (_foo_how2_1_1 + 1),(_glong + 2)
36685 \begin_layout Standard
36686 Again, variations of these cases may
36691 They are standard C expressions, so I heartily recommend these be the only
36692 way to get the higher order byte/word, (it is portable).
36693 Of course it will be recognized even if it is embedded in other expressions,
36697 \begin_layout Verse
36700 xyz = gint + ((gint >> 8) & 0xFF);
36703 \begin_layout Standard
36704 will still be recognized.
36707 \begin_layout Subsection
36709 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
36714 \begin_inset LatexCommand \index{Peephole optimizer}
36721 \begin_layout Standard
36722 The compiler uses a rule based, pattern matching and re-writing mechanism
36723 for peep-hole optimization.
36728 a peep-hole optimizer by Christopher W.
36729 Fraser (cwfraser\InsetSpace ~
36732 A default set of rules are compiled into the compiler, additional rules
36733 may be added with the
36739 \begin_layout Standard
36749 \begin_inset LatexCommand \index{-\/-peep-file}
36756 The rule language is best illustrated with examples.
36759 \begin_layout Verse
36781 \begin_layout Standard
36782 The above rule will change the following assembly
36783 \begin_inset LatexCommand \index{Assembler routines}
36790 \begin_layout Verse
36798 \begin_layout Standard
36802 \begin_layout Verse
36808 \begin_layout Standard
36809 Note: All occurrences of a
36813 (pattern variable) must denote the same string.
36814 With the above rule, the assembly sequence:
36817 \begin_layout Verse
36825 \begin_layout Standard
36826 will remain unmodified.
36830 Other special case optimizations may be added by the
36837 \begin_layout Standard
36850 some variants of the 8051 MCU
36851 \begin_inset LatexCommand \index{MCS51 variants}
36864 The following two rules will change all
36881 \begin_layout Verse
36884 replace { lcall %1 } by { acall %1 }
36886 replace { ljmp %1 } by { ajmp %1 }
36889 \begin_layout Standard
36890 (NOTE: from version 2.7.3 on, you can use option -
36896 \begin_layout Standard
36908 \begin_inset LatexCommand \index{-\/-acall-ajmp}
36912 , which also takes care of aligning the interrupt vectors properly.)
36917 \begin_layout Standard
36920 inline-assembler code
36922 is also passed through the peep hole optimizer, thus the peephole optimizer
36923 can also be used as an assembly level macro expander.
36924 The rules themselves are MCU dependent whereas the rule language infra-structur
36925 e is MCU independent.
36926 Peephole optimization rules for other MCU can be easily programmed using
36931 The syntax for a rule is as follows:
36934 \begin_layout Verse
36937 rule := replace [ restart ] '{' <assembly sequence> '
36975 <assembly sequence> '
36993 '}' [if <functionName> ] '
36998 \begin_layout Standard
36999 <assembly sequence> := assembly instruction (each instruction including
37000 labels must be on a separate line).
37004 The optimizer will apply to the rules
37005 one by one from the top in the sequence of their appearance, it will terminate
37006 when all rules are exhausted.
37007 If the 'restart' option is specified, then the optimizer will start matching
37008 the rules again from the top, this option for a rule is expensive (performance)
37009 , it is intended to be used in situations where a transformation will trigger
37010 the same rule again.
37011 An example of this (not a good one, it has side effects) is the following
37015 \begin_layout Verse
37035 \begin_layout Standard
37036 Note that the replace pattern cannot be a blank, but can be a comment line.
37037 Without the 'restart' option only the innermost 'pop' 'push' pair would
37038 be eliminated, i.e.:
37041 \begin_layout Verse
37053 \begin_layout Standard
37057 \begin_layout Verse
37067 \begin_layout Standard
37072 the restart option the rule will be applied again to the resulting code
37073 and then all the pop-push pairs will be eliminated to yield:
37076 \begin_layout Verse
37084 \begin_layout Standard
37085 A conditional function can be attached to a rule.
37086 Attaching rules are somewhat more involved, let me illustrate this with
37090 \begin_layout Verse
37114 \begin_layout Standard
37115 The optimizer does a look-up of a function name table defined in function
37120 in the source file SDCCpeeph.c, with the name
37125 If it finds a corresponding entry the function is called.
37126 Note there can be no parameters specified for these functions, in this
37131 is crucial, since the function
37135 expects to find the label in that particular variable (the hash table containin
37136 g the variable bindings is passed as a parameter).
37137 If you want to code more such functions, take a close look at the function
37138 labelInRange and the calling mechanism in source file SDCCpeeph.c.
37139 Currently implemented are
37141 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
37142 24bitMode, portIsDS390, 24bitModeAndPortDS390
37151 \begin_layout Standard
37152 I know this whole thing is a little kludgey, but maybe some day we will
37153 have some better means.
37154 If you are looking at this file, you will see the default rules that are
37155 compiled into the compiler, you can add your own rules in the default set
37156 there if you get tired of specifying the -
37160 \begin_layout Standard
37172 \begin_layout Section
37174 \begin_inset LatexCommand \index{ANSI-compliance}
37179 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
37186 \begin_layout Standard
37187 The latest publically available version of the standard
37189 ISO/IEC 9899 - Programming languages - C
37191 should be available at:
37192 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
37201 \begin_layout Standard
37202 Deviations from the compliance:
37205 \begin_layout Itemize
37206 functions are not reentrant
37207 \begin_inset LatexCommand \index{reentrant}
37211 unless explicitly declared as such or the
37217 \begin_layout Standard
37227 \begin_inset LatexCommand \index{-\/-stack-auto}
37233 command line option is specified.
37236 \begin_layout Itemize
37238 \begin_inset LatexCommand \index{struct}
37243 \begin_inset LatexCommand \index{union}
37247 cannot be assigned values directly, cannot be passed as function parameters
37248 or assigned to each other and cannot be a return value
37249 \begin_inset LatexCommand \index{return value}
37253 from a function, e.g.:
37257 \begin_layout Verse
37280 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
37299 s parms) /* invalid in SDCC although allowed in ANSI */
37321 return rets; /* is invalid in SDCC although allowed in ANSI */
37327 \begin_layout Itemize
37328 initialization of structure arrays must be fully braced.
37332 \begin_layout Verse
37335 struct s { char x } a[] = {1, 2};\InsetSpace ~
37340 /* invalid in SDCC */
37343 } a[] = {{1}, {2}}; /* OK */
37347 \begin_layout Itemize
37349 \begin_inset LatexCommand \index{long long (not supported)}
37354 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
37361 \begin_layout Itemize
37363 \begin_inset LatexCommand \index{double (not supported)}
37367 ' precision floating point
37368 \begin_inset LatexCommand \index{Floating point support}
37375 \begin_layout Itemize
37377 \begin_inset LatexCommand \index{K\&R style}
37381 function declarations are NOT allowed.
37385 \begin_layout Verse
37388 foo(i,j) /* this old style of function declarations */
37390 int i,j; /* is valid
37391 in ANSI but not valid in SDCC */
37406 \begin_layout Itemize
37407 Most enhancements in C99 are not supported, e.g.:
37411 \begin_layout Verse
37418 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
37422 \begin_layout Itemize
37423 But some have been added recently in SDCC 2.7.0.
37424 They must be considered alpha quality however.
37428 \begin_layout Verse
37433 \begin_inset LatexCommand \index{inline (not supported)}
37439 int increment (int a) { return a+1; } /* inlines the increment without
37440 function call overhead */
37445 \begin_inset LatexCommand \index{inline (not supported)}
37451 p; /* accepted but ignored */
37455 \begin_layout Itemize
37456 Certain words that are valid identifiers in the standard may be reserved
37457 words in SDCC unless the
37463 \begin_layout Standard
37473 \begin_inset LatexCommand \index{-\/-std-c89}
37485 \begin_layout Standard
37495 \begin_inset LatexCommand \index{-\/-std-c99}
37501 command line options are used.
37502 These may include (depending on the selected processor): 'at', 'banked',
37503 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
37504 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
37505 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
37507 Compliant equivalents of these keywords are always available in a form
37508 that begin with two underscores
37509 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
37514 '__data' instead of 'data'.
37517 \begin_layout Itemize
37518 Integer promotion of variable arguments is not performed if the argument
37519 is explicitly taypecasted unless the
37525 \begin_layout Standard
37535 \begin_inset LatexCommand \index{-\/-std-c89}
37547 \begin_layout Standard
37557 \begin_inset LatexCommand \index{-\/-std-c99}
37563 command line options are used.
37567 \begin_layout Verse
37570 void vararg_func (char *str, ...) { str; }
37587 u is promoted to int before
37592 * passing to function */
37596 vararg_func ("%c", c);
37603 argument u is not promoted to int,
37608 * it is passed as char to function
37614 --std-cXX is not defined;
37619 * is promoted to int before passing
37625 if --std-cXX is defined */
37629 vararg_func ("%bc", (char)u);
37635 \begin_layout Section
37636 Cyclomatic Complexity
37637 \begin_inset LatexCommand \index{Cyclomatic complexity}
37644 \begin_layout Standard
37645 Cyclomatic complexity of a function is defined as the number of independent
37646 paths the program can take during execution of the function.
37647 This is an important number since it defines the number test cases you
37648 have to generate to validate the function.
37649 The accepted industry standard for complexity number is 10, if the cyclomatic
37650 complexity reported by SDCC exceeds 10 you should think about simplification
37651 of the function logic.
37652 Note that the complexity level is not related to the number of lines of
37653 code in a function.
37654 Large functions can have low complexity, and small functions can have large
37660 SDCC uses the following formula to compute the complexity:
37665 \begin_layout Standard
37666 complexity = (number of edges in control flow graph) - (number of nodes
37667 in control flow graph) + 2;
37671 Having said that the industry standard is 10,
37672 you should be aware that in some cases it be may unavoidable to have a
37673 complexity level of less than 10.
37674 For example if you have switch statement with more than 10 case labels,
37675 each case label adds one to the complexity level.
37676 The complexity level is by no means an absolute measure of the algorithmic
37677 complexity of the function, it does however provide a good starting point
37678 for which functions you might look at for further optimization.
37681 \begin_layout Section
37682 Retargetting for other Processors
37685 \begin_layout Standard
37686 The issues for retargetting the compiler are far too numerous to be covered
37688 What follows is a brief description of each of the seven phases of the
37689 compiler and its MCU dependency.
37692 \begin_layout Itemize
37693 Parsing the source and building the annotated parse tree.
37694 This phase is largely MCU independent (except for the language extensions).
37695 Syntax & semantic checks are also done in this phase, along with some initial
37696 optimizations like back patching labels and the pattern matching optimizations
37697 like bit-rotation etc.
37700 \begin_layout Itemize
37701 The second phase involves generating an intermediate code which can be easy
37702 manipulated during the later phases.
37703 This phase is entirely MCU independent.
37704 The intermediate code generation assumes the target machine has unlimited
37705 number of registers, and designates them with the name iTemp.
37706 The compiler can be made to dump a human readable form of the code generated
37711 \begin_layout Standard
37723 \begin_layout Itemize
37724 This phase does the bulk of the standard optimizations and is also MCU independe
37726 This phase can be broken down into several sub-phases:
37730 Break down intermediate
37731 code (iCode) into basic blocks.
37733 Do control flow & data flow analysis on the
37736 Do local common subexpression elimination, then global subexpressio
37739 Dead code elimination
37743 If loop optimizations
37744 caused any changes then do 'global subexpression elimination' and 'dead
37745 code elimination' again.
37748 \begin_layout Itemize
37749 This phase determines the live-ranges; by live range I mean those iTemp
37750 variables defined by the compiler that still survive after all the optimization
37752 Live range analysis
37753 \begin_inset LatexCommand \index{Live range analysis}
37757 is essential for register allocation, since these computation determines
37758 which of these iTemps will be assigned to registers, and for how long.
37761 \begin_layout Itemize
37762 Phase five is register allocation.
37763 There are two parts to this process.
37767 The first part I call 'register packing'
37768 (for lack of a better term).
37769 In this case several MCU specific expression folding is done to reduce
37774 The second part is more MCU independent and deals with
37775 allocating registers to the remaining live ranges.
37776 A lot of MCU specific code does creep into this phase because of the limited
37777 number of index registers available in the 8051.
37780 \begin_layout Itemize
37781 The Code generation phase is (unhappily), entirely MCU dependent and very
37782 little (if any at all) of this code can be reused for other MCU.
37783 However the scheme for allocating a homogenized assembler operand for each
37784 iCode operand may be reused.
37787 \begin_layout Itemize
37788 As mentioned in the optimization section the peep-hole optimizer is rule
37789 based system, which can reprogrammed for other MCUs.
37792 \begin_layout Standard
37793 More information is available on SDCC Wiki
37794 \begin_inset LatexCommand \index{wiki}
37799 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting}
37803 ) and in the thread
37804 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
37811 \begin_layout Chapter
37813 \begin_inset LatexCommand \index{Compiler internals}
37820 \begin_layout Section
37821 The anatomy of the compiler
37822 \begin_inset LatexCommand \label{sub:The-anatomy-of}
37829 \begin_layout Standard
37832 This is an excerpt from an article published in Circuit Cellar Magazine
37838 It's a little outdated (the compiler is much more efficient now and user/develo
37839 per friendly), but pretty well exposes the guts of it all.
37845 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
37846 It is fairly easy to retarget for other 8-bit MCU.
37847 Here we take a look at some of the internals of the compiler.
37851 \begin_layout Paragraph*
37853 \begin_inset LatexCommand \index{Parsing}
37860 \begin_layout Standard
37861 Parsing the input source file and creating an AST (Annotated Syntax Tree
37862 \begin_inset LatexCommand \index{Annotated syntax tree}
37867 This phase also involves propagating types (annotating each node of the
37868 parse tree with type information) and semantic analysis.
37869 There are some MCU specific parsing rules.
37870 For example the storage classes, the extended storage classes are MCU specific
37871 while there may be a xdata storage class for 8051 there is no such storage
37872 class for z80 or Atmel AVR.
37873 SDCC allows MCU specific storage class extensions, i.e.
37874 xdata will be treated as a storage class specifier when parsing 8051 C
37875 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
37879 \begin_layout Paragraph*
37881 \begin_inset LatexCommand \index{iCode}
37888 \begin_layout Standard
37889 Intermediate code generation.
37890 In this phase the AST is broken down into three-operand form (iCode).
37891 These three operand forms are represented as doubly linked lists.
37892 ICode is the term given to the intermediate form generated by the compiler.
37893 ICode example section shows some examples of iCode generated for some simple
37894 C source functions.
37897 \begin_layout Paragraph*
37899 \begin_inset LatexCommand \index{Optimizations}
37906 \begin_layout Standard
37907 Bulk of the target independent optimizations is performed in this phase.
37908 The optimizations include constant propagation, common sub-expression eliminati
37909 on, loop invariant code movement, strength reduction of loop induction variables
37910 and dead-code elimination.
37913 \begin_layout Paragraph*
37914 Live range analysis
37915 \begin_inset LatexCommand \index{Live range analysis}
37922 \begin_layout Standard
37923 During intermediate code generation phase, the compiler assumes the target
37924 machine has infinite number of registers and generates a lot of temporary
37926 The live range computation determines the lifetime of each of these compiler-ge
37927 nerated temporaries.
37928 A picture speaks a thousand words.
37929 ICode example sections show the live range annotations for each of the
37931 It is important to note here, each iCode is assigned a number in the order
37932 of its execution in the function.
37933 The live ranges are computed in terms of these numbers.
37934 The from number is the number of the iCode which first defines the operand
37935 and the to number signifies the iCode which uses this operand last.
37938 \begin_layout Paragraph*
37939 Register Allocation
37940 \begin_inset LatexCommand \index{Register allocation}
37947 \begin_layout Standard
37948 The register allocation determines the type and number of registers needed
37950 In most MCUs only a few registers can be used for indirect addressing.
37951 In case of 8051 for example the registers R0 & R1 can be used to indirectly
37952 address the internal ram and DPTR to indirectly address the external ram.
37953 The compiler will try to allocate the appropriate register to pointer variables
37955 ICode example section shows the operands annotated with the registers assigned
37957 The compiler will try to keep operands in registers as much as possible;
37958 there are several schemes the compiler uses to do achieve this.
37959 When the compiler runs out of registers the compiler will check to see
37960 if there are any live operands which is not used or defined in the current
37961 basic block being processed, if there are any found then it will push that
37962 operand and use the registers in this block, the operand will then be popped
37963 at the end of the basic block.
37967 \begin_layout Standard
37968 There are other MCU specific considerations in this phase.
37969 Some MCUs have an accumulator; very short-lived operands could be assigned
37970 to the accumulator instead of a general-purpose register.
37973 \begin_layout Paragraph*
37977 \begin_layout Standard
37978 Figure II gives a table of iCode
37979 \begin_inset LatexCommand \index{iCode}
37983 operations supported by the compiler.
37984 The code generation involves translating these operations into corresponding
37985 assembly code for the processor.
37986 This sounds overly simple but that is the essence of code generation.
37987 Some of the iCode operations are generated on a MCU specific manner for
37988 example, the z80 port does not use registers to pass parameters so the
37989 SEND and RECV iCode operations will not be generated, and it also does
37990 not support JUMPTABLES.
37996 \begin_layout Standard
38000 \begin_inset Tabular
38001 <lyxtabular version="3" rows="39" columns="4">
38002 <features islongtable="true" headBottomDL="true">
38003 <column alignment="block" valignment="top" leftline="true" width="13col%">
38004 <column alignment="left" valignment="top" leftline="true" width="13col%">
38005 <column alignment="block" valignment="top" leftline="true" width="22col%">
38006 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
38007 <row topline="true" bottomline="true" endhead="true">
38008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38011 \begin_layout Standard
38017 \begin_inset LatexCommand \index{iCode}
38026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38029 \begin_layout Standard
38037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38040 \begin_layout Standard
38048 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38051 \begin_layout Standard
38060 <row topline="true">
38061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38064 \begin_layout Standard
38072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38075 \begin_layout Standard
38078 IC_LEFT() IC_RESULT()
38083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38086 \begin_layout Standard
38094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38097 \begin_layout Standard
38100 IC_RESULT = ! IC_LEFT;
38106 <row topline="true">
38107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38110 \begin_layout Standard
38118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38121 \begin_layout Standard
38124 IC_LEFT() IC_RESULT()
38129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38132 \begin_layout Standard
38135 Bitwise complement of
38140 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38143 \begin_layout Standard
38146 IC_RESULT = ~IC_LEFT;
38152 <row topline="true">
38153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38156 \begin_layout Standard
38164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38167 \begin_layout Standard
38170 IC_LEFT() IC_RESULT()
38175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38178 \begin_layout Standard
38181 Rotate right with carry
38186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38189 \begin_layout Standard
38192 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
38198 <row topline="true">
38199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38202 \begin_layout Standard
38210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38213 \begin_layout Standard
38216 IC_LEFT() IC_RESULT()
38221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38224 \begin_layout Standard
38227 Rotate left with carry
38232 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38235 \begin_layout Standard
38238 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
38244 <row topline="true">
38245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38248 \begin_layout Standard
38256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38259 \begin_layout Standard
38262 IC_LEFT() IC_RESULT()
38267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38270 \begin_layout Standard
38273 Get the highest order bit of IC_LEFT
38278 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38281 \begin_layout Standard
38284 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
38290 <row topline="true">
38291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38294 \begin_layout Standard
38302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38305 \begin_layout Standard
38308 IC_LEFT() IC_RESULT()
38313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38316 \begin_layout Standard
38324 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38327 \begin_layout Standard
38330 IC_RESULT = - IC_LEFT;
38336 <row topline="true">
38337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38340 \begin_layout Standard
38348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38351 \begin_layout Standard
38359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38362 \begin_layout Standard
38365 Push the operand into stack
38370 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38373 \begin_layout Standard
38382 <row topline="true">
38383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38386 \begin_layout Standard
38394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38397 \begin_layout Standard
38405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38408 \begin_layout Standard
38411 Pop the operand from the stack
38416 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38419 \begin_layout Standard
38428 <row topline="true">
38429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38432 \begin_layout Standard
38440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38443 \begin_layout Standard
38446 IC_LEFT() IC_RESULT()
38451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38454 \begin_layout Standard
38457 Call the function represented by IC_LEFT
38462 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38465 \begin_layout Standard
38468 IC_RESULT = IC_LEFT();
38474 <row topline="true">
38475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38478 \begin_layout Standard
38486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38489 \begin_layout Standard
38492 IC_LEFT() IC_RESULT()
38497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38500 \begin_layout Standard
38503 Call via function pointer
38508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38511 \begin_layout Standard
38514 IC_RESULT = (*IC_LEFT)();
38520 <row topline="true">
38521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38524 \begin_layout Standard
38532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38535 \begin_layout Standard
38543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38546 \begin_layout Standard
38549 Return the value in operand IC_LEFT
38554 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38557 \begin_layout Standard
38566 <row topline="true">
38567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38570 \begin_layout Standard
38578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38581 \begin_layout Standard
38589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38592 \begin_layout Standard
38600 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38603 \begin_layout Standard
38612 <row topline="true">
38613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38616 \begin_layout Standard
38624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38627 \begin_layout Standard
38635 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38638 \begin_layout Standard
38646 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38649 \begin_layout Standard
38658 <row topline="true">
38659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38662 \begin_layout Standard
38670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38673 \begin_layout Standard
38676 IC_LEFT() IC_RIGHT() IC_RESULT()
38681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38684 \begin_layout Standard
38692 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38695 \begin_layout Standard
38698 IC_RESULT = IC_LEFT + IC_RIGHT
38704 <row topline="true">
38705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38708 \begin_layout Standard
38716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38719 \begin_layout Standard
38722 IC_LEFT() IC_RIGHT() IC_RESULT()
38727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38730 \begin_layout Standard
38738 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38741 \begin_layout Standard
38744 IC_RESULT = IC_LEFT - IC_RIGHT
38750 <row topline="true">
38751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38754 \begin_layout Standard
38762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38765 \begin_layout Standard
38768 IC_LEFT() IC_RIGHT() IC_RESULT()
38773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38776 \begin_layout Standard
38784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38787 \begin_layout Standard
38790 IC_RESULT = IC_LEFT * IC_RIGHT;
38796 <row topline="true">
38797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38800 \begin_layout Standard
38808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38811 \begin_layout Standard
38814 IC_LEFT() IC_RIGHT() IC_RESULT()
38819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38822 \begin_layout Standard
38830 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38833 \begin_layout Standard
38836 IC_RESULT = IC_LEFT / IC_RIGHT;
38842 <row topline="true">
38843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38846 \begin_layout Standard
38854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38857 \begin_layout Standard
38860 IC_LEFT() IC_RIGHT() IC_RESULT()
38865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38868 \begin_layout Standard
38876 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38879 \begin_layout Standard
38882 IC_RESULT = IC_LEFT % IC_RIGHT;
38888 <row topline="true">
38889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38892 \begin_layout Standard
38900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38903 \begin_layout Standard
38906 IC_LEFT() IC_RIGHT() IC_RESULT()
38911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38914 \begin_layout Standard
38922 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38925 \begin_layout Standard
38928 IC_RESULT = IC_LEFT < IC_RIGHT;
38934 <row topline="true">
38935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38938 \begin_layout Standard
38946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38949 \begin_layout Standard
38952 IC_LEFT() IC_RIGHT() IC_RESULT()
38957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38960 \begin_layout Standard
38968 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38971 \begin_layout Standard
38974 IC_RESULT = IC_LEFT > IC_RIGHT;
38980 <row topline="true">
38981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38984 \begin_layout Standard
38992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38995 \begin_layout Standard
38998 IC_LEFT() IC_RIGHT() IC_RESULT()
39003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39006 \begin_layout Standard
39014 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39017 \begin_layout Standard
39020 IC_RESULT = IC_LEFT == IC_RIGHT;
39026 <row topline="true">
39027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39030 \begin_layout Standard
39038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39041 \begin_layout Standard
39044 IC_LEFT() IC_RIGHT() IC_RESULT()
39049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39052 \begin_layout Standard
39055 Logical and operation
39060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39063 \begin_layout Standard
39066 IC_RESULT = IC_LEFT && IC_RIGHT;
39072 <row topline="true">
39073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39076 \begin_layout Standard
39084 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39087 \begin_layout Standard
39090 IC_LEFT() IC_RIGHT() IC_RESULT()
39095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39098 \begin_layout Standard
39101 Logical or operation
39106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39109 \begin_layout Standard
39112 IC_RESULT = IC_LEFT || IC_RIGHT;
39118 <row topline="true">
39119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39122 \begin_layout Standard
39130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39133 \begin_layout Standard
39136 IC_LEFT() IC_RIGHT() IC_RESULT()
39141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39144 \begin_layout Standard
39152 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39155 \begin_layout Standard
39158 IC_RESULT = IC_LEFT ^ IC_RIGHT;
39164 <row topline="true">
39165 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39168 \begin_layout Standard
39176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39179 \begin_layout Standard
39182 IC_LEFT() IC_RIGHT() IC_RESULT()
39187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39190 \begin_layout Standard
39198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39201 \begin_layout Standard
39204 IC_RESULT = IC_LEFT | IC_RIGHT;
39210 <row topline="true">
39211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39214 \begin_layout Standard
39222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39225 \begin_layout Standard
39228 IC_LEFT() IC_RIGHT() IC_RESULT()
39233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39236 \begin_layout Standard
39244 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39247 \begin_layout Standard
39250 IC_RESULT = IC_LEFT & IC_RIGHT;
39256 <row topline="true">
39257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39260 \begin_layout Standard
39268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39271 \begin_layout Standard
39274 IC_LEFT() IC_RIGHT() IC_RESULT()
39279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39282 \begin_layout Standard
39290 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39293 \begin_layout Standard
39296 IC_RESULT = IC_LEFT << IC_RIGHT
39302 <row topline="true">
39303 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39306 \begin_layout Standard
39314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39317 \begin_layout Standard
39320 IC_LEFT() IC_RIGHT() IC_RESULT()
39325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39328 \begin_layout Standard
39336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39339 \begin_layout Standard
39342 IC_RESULT = IC_LEFT >> IC_RIGHT
39348 <row topline="true">
39349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39352 \begin_layout Standard
39362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39365 \begin_layout Standard
39368 IC_LEFT() IC_RESULT()
39373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39376 \begin_layout Standard
39384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39387 \begin_layout Standard
39390 IC_RESULT = (*IC_LEFT);
39396 <row topline="true">
39397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39400 \begin_layout Standard
39408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39411 \begin_layout Standard
39414 IC_RIGHT() IC_RESULT()
39419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39422 \begin_layout Standard
39430 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39433 \begin_layout Standard
39436 (*IC_RESULT) = IC_RIGHT;
39442 <row topline="true">
39443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39446 \begin_layout Standard
39454 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39457 \begin_layout Standard
39460 IC_RIGHT() IC_RESULT()
39465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39468 \begin_layout Standard
39476 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39479 \begin_layout Standard
39482 IC_RESULT = IC_RIGHT;
39488 <row topline="true">
39489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39492 \begin_layout Standard
39500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39503 \begin_layout Standard
39506 IC_COND IC_TRUE IC_LABEL
39511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39514 \begin_layout Standard
39518 If true label is present then jump to true label if condition is true else
39519 jump to false label if condition is false
39524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39527 \begin_layout Standard
39530 if (IC_COND) goto IC_TRUE;
39536 If (!IC_COND) goto IC_FALSE;
39542 <row topline="true">
39543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39546 \begin_layout Standard
39554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39557 \begin_layout Standard
39560 IC_LEFT() IC_RESULT()
39565 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39568 \begin_layout Standard
39576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39579 \begin_layout Standard
39582 IC_RESULT = &IC_LEFT();
39588 <row topline="true">
39589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39592 \begin_layout Standard
39600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39603 \begin_layout Standard
39606 IC_JTCOND IC_JTLABELS
39611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39614 \begin_layout Standard
39617 Jump to list of labels depending on the value of JTCOND
39622 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39625 \begin_layout Standard
39634 <row topline="true">
39635 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39638 \begin_layout Standard
39646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39649 \begin_layout Standard
39652 IC_RIGHT() IC_LEFT() IC_RESULT()
39657 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39660 \begin_layout Standard
39668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39671 \begin_layout Standard
39674 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
39680 <row topline="true">
39681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39684 \begin_layout Standard
39692 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39695 \begin_layout Standard
39703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39706 \begin_layout Standard
39709 This is used for passing parameters in registers;
39711 move IC_LEFT to the next
39712 available parameter register.
39717 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39720 \begin_layout Standard
39729 <row topline="true">
39730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39733 \begin_layout Standard
39741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39744 \begin_layout Standard
39752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39755 \begin_layout Standard
39758 This is used for receiving parameters passed in registers;
39761 in the next parameter register to IC_RESULT
39766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39769 \begin_layout Standard
39778 <row topline="true" bottomline="true">
39779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39782 \begin_layout Standard
39786 (some more have been added)
39791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39794 \begin_layout Standard
39800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39803 \begin_layout Standard
39809 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39812 \begin_layout Standard
39836 \begin_layout Standard
39837 \begin_inset Note Note
39840 \begin_layout Standard
39841 In the original article Figure II was announced to be downloadable on
39846 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
39854 \begin_layout Paragraph*
39856 \begin_inset LatexCommand \index{iCode}
39863 \begin_layout Standard
39864 This section shows some details of iCode.
39865 The example C code does not do anything useful; it is used as an example
39866 to illustrate the intermediate code generated by the compiler.
39869 \begin_layout Verse
39879 /* This function does nothing useful.
39886 for the purpose of explaining iCode */
39889 short function (data
39898 short i=10; \InsetSpace ~
39900 /* dead initialization eliminated */
39906 /* dead initialization eliminated */
39934 /* compiler detects i,j to be induction
39939 for (i = 0, j = 10 ; i < 10 ; i++, j
39945 \begin_layout Standard
39968 mul += i * 3; \InsetSpace ~
39970 /* this multiplication remains */
39977 j * 3;\InsetSpace ~
39979 /* this multiplication changed to addition */
39993 \begin_layout Standard
39994 In addition to the operands each iCode contains information about the filename
39995 and line it corresponds to in the source file.
39996 The first field in the listing should be interpreted as follows:
40001 Filename(linenumber: iCode Execution sequence number : ICode hash table
40002 key : loop depth of the iCode).
40007 Then follows the human readable form of the ICode operation.
40008 Each operand of this triplet form can be of three basic types a) compiler
40009 generated temporary b) user defined variable c) a constant value.
40010 Note that local variables and parameters are replaced by compiler generated
40013 \begin_inset LatexCommand \index{Live range analysis}
40017 are computed only for temporaries (i.e.
40018 live ranges are not computed for global variables).
40020 \begin_inset LatexCommand \index{Register allocation}
40024 are allocated for temporaries only.
40025 Operands are formatted in the following manner:
40030 Operand Name [lr live-from : live-to ] { type information } [ registers
40036 As mentioned earlier the live ranges are computed in terms of the execution
40037 sequence number of the iCodes, for example
40039 the iTemp0 is live from (i.e.
40040 first defined in iCode with execution sequence number 3, and is last used
40041 in the iCode with sequence number 5).
40042 For induction variables such as iTemp21 the live range computation extends
40043 the lifetime from the start to the end of the loop.
40045 The register allocator
40046 used the live range information to allocate registers, the same registers
40047 may be used for different temporaries if their live ranges do not overlap,
40048 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
40049 ranges do not overlap.
40050 In addition the allocator also takes into consideration the type and usage
40051 of a temporary, for example itemp6 is a pointer to near space and is used
40052 as to fetch data from (i.e.
40053 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
40054 Some short lived temporaries are allocated to special registers which have
40055 meaning to the code generator e.g.
40056 iTemp13 is allocated to a pseudo register CC which tells the back end that
40057 the temporary is used only for a conditional jump the code generation makes
40058 use of this information to optimize a compare and jump ICode.
40062 \begin_inset LatexCommand \index{Loop optimization}
40066 performed by the compiler.
40067 It can detect induction variables iTemp21(i) and iTemp23(j).
40068 Also note the compiler does selective strength reduction
40069 \begin_inset LatexCommand \index{Strength reduction}
40074 the multiplication of an induction variable in line 18 (gint = j * 3) is
40075 changed to addition, a new temporary iTemp17 is allocated and assigned
40076 a initial value, a constant 3 is then added for each iteration of the loop.
40077 The compiler does not change the multiplication
40078 \begin_inset LatexCommand \index{Multiplication}
40082 in line 17 however since the processor does support an 8 * 8 bit multiplication.
40085 Note the dead code elimination
40086 \begin_inset LatexCommand \index{Dead-code elimination}
40090 optimization eliminated the dead assignments in line 7 & 8 to I and sum
40096 \begin_layout Standard
40099 Sample.c (5:1:0:0) _entry($9) :
40102 \begin_layout Standard
40105 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
40108 \begin_layout Standard
40111 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
40114 \begin_layout Standard
40117 Sample.c(11:4:53:0) preHeaderLbl0($11) :
40120 \begin_layout Standard
40123 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
40127 \begin_layout Standard
40130 Sample.c(11:6:5:1) _whilecontinue_0($1) :
40133 \begin_layout Standard
40136 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
40140 \begin_layout Standard
40143 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
40146 \begin_layout Standard
40149 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
40153 \begin_layout Standard
40156 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
40160 \begin_layout Standard
40163 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
40167 \begin_layout Standard
40170 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
40174 \begin_layout Standard
40177 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
40178 * int}[r0] + 0x2 {short}
40181 \begin_layout Standard
40184 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
40187 \begin_layout Standard
40190 Sample.c(11:17:21:0)_whilebreak_0($3) :
40193 \begin_layout Standard
40196 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
40199 \begin_layout Standard
40202 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
40205 \begin_layout Standard
40208 Sample.c(15:20:54:0)preHeaderLbl1($13) :
40211 \begin_layout Standard
40214 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
40217 \begin_layout Standard
40220 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
40223 \begin_layout Standard
40226 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
40229 \begin_layout Standard
40232 Sample.c(15:24:26:1)_forcond_0($4) :
40235 \begin_layout Standard
40238 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
40242 \begin_layout Standard
40245 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
40248 \begin_layout Standard
40251 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
40252 + ITemp21 [lr21:38]{short}[r4]
40255 \begin_layout Standard
40258 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
40262 \begin_layout Standard
40265 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
40266 + iTemp15 [lr29:30]{short}[r1]
40269 \begin_layout Standard
40272 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
40276 \begin_layout Standard
40279 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
40283 \begin_layout Standard
40286 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
40290 \begin_layout Standard
40293 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
40297 \begin_layout Standard
40300 Sample.c(19:38:47:1) goto _forcond_0($4)
40303 \begin_layout Standard
40306 Sample.c(19:39:48:0)_forbreak_0($7) :
40309 \begin_layout Standard
40312 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
40313 + ITemp11 [lr19:40]{short}[r3]
40316 \begin_layout Standard
40319 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
40322 \begin_layout Standard
40325 Sample.c(20:42:51:0)_return($8) :
40328 \begin_layout Standard
40331 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
40337 Finally the code generated for this function:
40342 \begin_layout Standard
40348 \begin_layout Standard
40354 \begin_layout Standard
40362 \begin_layout Standard
40368 \begin_layout Standard
40376 \begin_layout Standard
40382 \begin_layout Standard
40385 ; ----------------------------------------------
40388 \begin_layout Standard
40391 ; function function
40394 \begin_layout Standard
40397 ; ----------------------------------------------
40400 \begin_layout Standard
40406 \begin_layout Standard
40409 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
40412 \begin_layout Standard
40420 \begin_layout Standard
40423 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
40426 \begin_layout Standard
40434 \begin_layout Standard
40437 ;_whilecontinue_0($1) :
40440 \begin_layout Standard
40446 \begin_layout Standard
40449 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
40452 \begin_layout Standard
40455 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
40458 \begin_layout Standard
40466 \begin_layout Standard
40474 \begin_layout Standard
40482 \begin_layout Standard
40490 \begin_layout Standard
40498 \begin_layout Standard
40506 \begin_layout Standard
40514 \begin_layout Standard
40520 \begin_layout Standard
40523 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
40526 \begin_layout Standard
40534 \begin_layout Standard
40542 \begin_layout Standard
40545 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
40548 \begin_layout Standard
40556 \begin_layout Standard
40564 \begin_layout Standard
40572 \begin_layout Standard
40580 \begin_layout Standard
40588 \begin_layout Standard
40596 \begin_layout Standard
40599 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
40602 \begin_layout Standard
40610 \begin_layout Standard
40618 \begin_layout Standard
40626 \begin_layout Standard
40634 \begin_layout Standard
40642 \begin_layout Standard
40645 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
40648 \begin_layout Standard
40656 \begin_layout Standard
40664 \begin_layout Standard
40672 \begin_layout Standard
40675 ; iTemp6 [lr5:16]{_near * int}[r0] =
40678 \begin_layout Standard
40681 ; iTemp6 [lr5:16]{_near * int}[r0] +
40684 \begin_layout Standard
40690 \begin_layout Standard
40698 \begin_layout Standard
40701 ; goto _whilecontinue_0($1)
40704 \begin_layout Standard
40712 \begin_layout Standard
40715 ; _whilebreak_0($3) :
40718 \begin_layout Standard
40724 \begin_layout Standard
40727 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
40730 \begin_layout Standard
40738 \begin_layout Standard
40741 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
40744 \begin_layout Standard
40752 \begin_layout Standard
40755 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
40758 \begin_layout Standard
40766 \begin_layout Standard
40769 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
40772 \begin_layout Standard
40780 \begin_layout Standard
40788 \begin_layout Standard
40791 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
40794 \begin_layout Standard
40802 \begin_layout Standard
40810 \begin_layout Standard
40816 \begin_layout Standard
40822 \begin_layout Standard
40825 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
40828 \begin_layout Standard
40831 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
40834 \begin_layout Standard
40842 \begin_layout Standard
40850 \begin_layout Standard
40858 \begin_layout Standard
40866 \begin_layout Standard
40874 \begin_layout Standard
40880 \begin_layout Standard
40883 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
40886 \begin_layout Standard
40889 ; iTemp21 [lr21:38]{short}[r4]
40892 \begin_layout Standard
40900 \begin_layout Standard
40908 \begin_layout Standard
40916 \begin_layout Standard
40919 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
40922 \begin_layout Standard
40930 \begin_layout Standard
40938 \begin_layout Standard
40946 \begin_layout Standard
40954 \begin_layout Standard
40957 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
40960 \begin_layout Standard
40963 ; iTemp15 [lr29:30]{short}[r1]
40966 \begin_layout Standard
40974 \begin_layout Standard
40982 \begin_layout Standard
40985 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
40988 \begin_layout Standard
40996 \begin_layout Standard
41004 \begin_layout Standard
41012 \begin_layout Standard
41020 \begin_layout Standard
41028 \begin_layout Standard
41036 \begin_layout Standard
41039 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
41042 \begin_layout Standard
41050 \begin_layout Standard
41058 \begin_layout Standard
41066 \begin_layout Standard
41074 \begin_layout Standard
41082 \begin_layout Standard
41090 \begin_layout Standard
41093 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
41096 \begin_layout Standard
41104 \begin_layout Standard
41107 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
41110 \begin_layout Standard
41118 \begin_layout Standard
41123 cjne r5,#0xff,00104$
41126 \begin_layout Standard
41134 \begin_layout Standard
41137 ; goto _forcond_0($4)
41140 \begin_layout Standard
41148 \begin_layout Standard
41151 ; _forbreak_0($7) :
41154 \begin_layout Standard
41160 \begin_layout Standard
41163 ; ret iTemp24 [lr40:41]{short}
41166 \begin_layout Standard
41174 \begin_layout Standard
41182 \begin_layout Standard
41190 \begin_layout Standard
41196 \begin_layout Standard
41202 \begin_layout Standard
41212 \begin_layout Section
41213 A few words about basic block successors, predecessors and dominators
41216 \begin_layout Standard
41217 Successors are basic blocks
41218 \begin_inset LatexCommand \index{Basic blocks}
41222 that might execute after this basic block.
41224 Predecessors are basic blocks
41225 that might execute before reaching this basic block.
41227 Dominators are basic
41228 blocks that WILL execute before reaching this basic block.
41233 \begin_layout Standard
41237 \begin_layout Standard
41241 \begin_layout Standard
41249 \begin_layout Standard
41253 \begin_layout Standard
41261 \begin_layout Standard
41267 \begin_layout Standard
41268 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
41271 \begin_layout Standard
41272 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
41275 \begin_layout Standard
41276 c) domVect of [BB4] = BB1 ...
41277 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
41281 \begin_layout Chapter
41285 \begin_layout Standard
41286 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/#Who}
41296 Thanks to all the other volunteer developers who have helped with coding,
41297 testing, web-page creation, distribution sets, etc.
41298 You know who you are :-)
41306 Thanks to Sourceforge
41307 \begin_inset LatexCommand \url{http://www.sf.net}
41311 which has hosted the project since 1999 and donates significant download
41320 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
41321 cycles and bandwidth for snapshot builds.
41326 \begin_layout Standard
41327 This document was initially written by Sandeep Dutta
41330 \begin_layout Standard
41331 All product names mentioned herein may be trademarks
41332 \begin_inset LatexCommand \index{Trademarks}
41336 of their respective companies.
41340 \begin_layout Section*
41344 \begin_layout Standard
41345 To avoid confusion, the installation and building options for SDCC itself
41346 (chapter 2) are not part of the index.
41349 \begin_layout Standard
41350 \begin_inset LatexCommand \printindex{}