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 Standard
1164 <pending: more incompatibilities?>
1167 \begin_layout Section
1171 \begin_layout Standard
1172 What do you need before you start installation of SDCC? A computer, and
1173 a desire to compute.
1174 The preferred method of installation is to compile SDCC from source using
1176 For Windows some pre-compiled binary distributions are available for your
1178 You should have some experience with command line tools and compiler use.
1181 \begin_layout Section
1185 \begin_layout Standard
1186 The SDCC home page at
1187 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1191 is a great place to find distribution sets.
1192 You can also find links to the user mailing lists that offer help or discuss
1193 SDCC with other SDCC users.
1194 Web links to other SDCC related sites can also be found here.
1195 This document can be found in the DOC directory of the source package as
1196 a text or HTML file.
1197 A pdf version of this document is available at
1198 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1203 Some of the other tools (simulator and assembler) included with SDCC contain
1204 their own documentation and can be found in the source distribution.
1205 If you want the latest unreleased software, the complete source package
1206 is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1210 \begin_layout Section
1211 Wishes for the future
1214 \begin_layout Standard
1215 There are (and always will be) some things that could be done.
1216 Here are some I can think of:
1221 \begin_layout Standard
1224 char KernelFunction3(char p) at 0x340;
1229 \begin_layout Standard
1233 \begin_inset LatexCommand \index{code banking (limited support)}
1243 If you can think of some more, please see the section
1244 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1248 about filing feature requests
1249 \begin_inset LatexCommand \index{Requesting features}
1254 \begin_inset LatexCommand \index{Feature request}
1263 \begin_layout Chapter
1265 \begin_inset LatexCommand \index{Installation}
1272 \begin_layout Standard
1273 For most users it is sufficient to skip to either section
1274 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1279 \begin_inset LatexCommand \ref{sub:Windows-Install}
1284 More detailed instructions follow below.
1287 \begin_layout Section
1289 \begin_inset LatexCommand \index{Options SDCC configuration}
1296 \begin_layout Standard
1297 The install paths, search paths and other options are defined when running
1299 The defaults can be overridden by:
1303 \labelwidthstring 00.00.0000
1308 \begin_layout Standard
1317 -prefix see table below
1321 \labelwidthstring 00.00.0000
1326 \begin_layout Standard
1335 -exec_prefix see table below
1339 \labelwidthstring 00.00.0000
1344 \begin_layout Standard
1353 -bindir see table below
1357 \labelwidthstring 00.00.0000
1362 \begin_layout Standard
1371 -datadir see table below
1375 \labelwidthstring 00.00.0000
1380 \begin_layout Standard
1389 -datarootdir see table below
1395 \labelwidthstring 00.00.0000
1398 docdir environment variable, see table below
1402 \labelwidthstring 00.00.0000
1405 include_dir_suffix environment variable, see table below
1409 \labelwidthstring 00.00.0000
1412 lib_dir_suffix environment variable, see table below
1416 \labelwidthstring 00.00.0000
1419 sdccconf_h_dir_separator environment variable, either / or
1424 This character will only be used in sdccconf.h; don't forget it's a C-header,
1425 therefore a double-backslash is needed there.
1431 \labelwidthstring 00.00.0000
1436 \begin_layout Standard
1445 -disable-mcs51-port Excludes the Intel mcs51 port
1449 \labelwidthstring 00.00.0000
1454 \begin_layout Standard
1463 -disable-gbz80-port Excludes the Gameboy gbz80 port
1467 \labelwidthstring 00.00.0000
1472 \begin_layout Standard
1481 -disable-z80-port Excludes the z80 port
1485 \labelwidthstring 00.00.0000
1490 \begin_layout Standard
1499 -disable-avr-port Excludes the AVR port
1503 \labelwidthstring 00.00.0000
1508 \begin_layout Standard
1517 -disable-ds390-port Excludes the DS390 port
1521 \labelwidthstring 00.00.0000
1526 \begin_layout Standard
1535 -disable-hc08-port Excludes the HC08 port
1539 \labelwidthstring 00.00.0000
1544 \begin_layout Standard
1553 -disable-pic-port Excludes the PIC14 port
1557 \labelwidthstring 00.00.0000
1562 \begin_layout Standard
1571 -disable-pic16-port Excludes the PIC16 port
1575 \labelwidthstring 00.00.0000
1580 \begin_layout Standard
1589 -disable-xa51-port Excludes the XA51 port
1593 \labelwidthstring 00.00.0000
1598 \begin_layout Standard
1607 -disable-ucsim Disables configuring and building of ucsim
1611 \labelwidthstring 00.00.0000
1616 \begin_layout Standard
1625 -disable-device-lib Disables automatically building device libraries
1629 \labelwidthstring 00.00.0000
1634 \begin_layout Standard
1643 -disable-packihx Disables building packihx
1649 \labelwidthstring 00.00.0000
1654 \begin_layout Standard
1663 -enable-doc Build pdf, html and txt files from the lyx sources
1667 \labelwidthstring 00.00.0000
1672 \begin_layout Standard
1681 -enable-libgc Use the Bohem memory allocator.
1682 Lower runtime footprint.
1685 \begin_layout Standard
1686 Furthermore the environment variables CC, CFLAGS, ...
1687 the tools and their arguments can be influenced.
1688 Please see `configure -
1692 \begin_layout Standard
1701 -help' and the man/info pages of `configure' for details.
1706 standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1707 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1708 SDCC_LIB_NAME are defined by `configure' too.
1709 At the moment it's not possible to change the default settings (it was
1710 simply never required).
1714 These configure options are compiled into the binaries,
1715 and can only be changed by rerunning 'configure' and recompiling SDCC.
1716 The configure options are written in
1720 to distinguish them from run time environment variables (see section search
1726 \begin_inset Quotes sld
1730 \begin_inset Quotes srd
1733 are used by the SDCC team to build the official Win32 binaries.
1734 The SDCC team uses Mingw32 to build the official Windows binaries, because
1738 \begin_layout Enumerate
1742 \begin_layout Enumerate
1743 a gcc compiler and last but not least
1746 \begin_layout Enumerate
1747 the binaries can be built by cross compiling on SDCC Distributed Compile
1751 \begin_layout Standard
1752 See the examples, how to pass the Win32 settings to 'configure'.
1753 The other Win32 builds using Borland, VC or whatever don't use 'configure',
1754 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1764 \begin_layout Standard
1766 \begin_inset Tabular
1767 <lyxtabular version="3" rows="9" columns="3">
1769 <column alignment="block" valignment="top" leftline="true" width="0in">
1770 <column alignment="block" valignment="top" leftline="true" width="0in">
1771 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1772 <row topline="true" bottomline="true">
1773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1776 \begin_layout Standard
1782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1785 \begin_layout Standard
1791 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1794 \begin_layout Standard
1801 <row topline="true">
1802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1805 \begin_layout Standard
1813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1816 \begin_layout Standard
1822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1825 \begin_layout Standard
1834 <row topline="true">
1835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1838 \begin_layout Standard
1846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1849 \begin_layout Standard
1857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1860 \begin_layout Standard
1869 <row topline="true">
1870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1873 \begin_layout Standard
1881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1884 \begin_layout Standard
1894 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1897 \begin_layout Standard
1910 <row topline="true">
1911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1914 \begin_layout Standard
1922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1925 \begin_layout Standard
1933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1936 \begin_layout Standard
1945 <row topline="true">
1946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1949 \begin_layout Standard
1957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1960 \begin_layout Standard
1970 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1973 \begin_layout Standard
1982 <row topline="true">
1983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1986 \begin_layout Standard
1994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1997 \begin_layout Standard
2007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2010 \begin_layout Standard
2023 <row topline="true">
2024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2027 \begin_layout Standard
2035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2038 \begin_layout Standard
2044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2047 \begin_layout Standard
2054 <row topline="true" bottomline="true">
2055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2058 \begin_layout Standard
2066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2069 \begin_layout Standard
2075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2078 \begin_layout Standard
2094 \begin_layout Standard
2096 'configure' also computes relative paths.
2097 This is needed for full relocatability of a binary package and to complete
2098 search paths (see section search paths below):
2103 \begin_layout Standard
2105 \begin_inset Tabular
2106 <lyxtabular version="3" rows="4" columns="3">
2108 <column alignment="block" valignment="top" leftline="true" width="0in">
2109 <column alignment="block" valignment="top" leftline="true" width="0in">
2110 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2111 <row topline="true" bottomline="true">
2112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2115 \begin_layout Standard
2121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2124 \begin_layout Standard
2130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2133 \begin_layout Standard
2140 <row topline="true" bottomline="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 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
2202 <row bottomline="true">
2203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2206 \begin_layout Standard
2214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2217 \begin_layout Standard
2223 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2226 \begin_layout Standard
2242 \begin_layout Standard
2247 \begin_layout LyX-Code
2254 \begin_layout Standard
2264 \begin_inset Quotes srd
2268 \begin_inset Quotes srd
2275 \begin_layout Standard
2285 \begin_inset Quotes srd
2289 \begin_inset Quotes srd
2298 \begin_layout Standard
2311 \begin_layout Standard
2323 \begin_layout Standard
2324 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2328 \begin_layout LyX-Code
2334 \begin_inset Quotes srd
2337 i586-mingw32msvc-gcc
2338 \begin_inset Quotes srd
2342 \begin_inset Quotes srd
2345 i586-mingw32msvc-g++
2346 \begin_inset Quotes srd
2354 \begin_inset Quotes srd
2357 i586-mingw32msvc-ranlib
2358 \begin_inset Quotes srd
2366 \begin_inset Quotes srd
2369 i586-mingw32msvc-strip
2370 \begin_inset Quotes srd
2381 \begin_layout Standard
2391 \begin_inset Quotes srd
2395 \begin_inset Quotes srd
2406 \begin_layout Standard
2416 \begin_inset Quotes srd
2420 \begin_inset Quotes srd
2428 \begin_inset Quotes srd
2434 \begin_inset Quotes srd
2442 \begin_inset Quotes srd
2446 \begin_inset Quotes srd
2454 \begin_inset Quotes srd
2458 \begin_inset Quotes srd
2465 sdccconf_h_dir_separator=
2466 \begin_inset Quotes srd
2478 \begin_inset Quotes srd
2489 \begin_layout Standard
2506 \begin_layout Standard
2515 -host=i586-mingw32msvc
2523 \begin_layout Standard
2532 -build=unknown-unknown-linux-gnu
2535 \begin_layout Standard
2537 \begin_inset Quotes sld
2541 \begin_inset Quotes srd
2544 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2548 \begin_layout LyX-Code
2557 \begin_layout Standard
2567 \begin_inset Quotes srd
2571 \begin_inset Quotes srd
2582 \begin_layout Standard
2592 \begin_inset Quotes srd
2596 \begin_inset Quotes srd
2604 \begin_inset Quotes srd
2610 \begin_inset Quotes srd
2618 \begin_inset Quotes srd
2622 \begin_inset Quotes srd
2630 \begin_inset Quotes srd
2634 \begin_inset Quotes srd
2641 sdccconf_h_dir_separator=
2642 \begin_inset Quotes srd
2654 \begin_inset Quotes srd
2662 \begin_inset Quotes srd
2666 \begin_inset Quotes srd
2674 \begin_inset Quotes srd
2678 \begin_inset Quotes srd
2684 \begin_layout Standard
2685 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2690 \begin_layout Standard
2699 -C' turns on caching, which gives a little bit extra speed.
2700 However if options are changed, it can be necessary to delete the config.cache
2704 \begin_layout Section
2706 \begin_inset LatexCommand \label{sub:Install-paths}
2711 \begin_inset LatexCommand \index{Install paths}
2718 \begin_layout Standard
2719 \begin_inset VSpace medskip
2725 \begin_layout Standard
2727 \begin_inset Tabular
2728 <lyxtabular version="3" rows="5" columns="4">
2730 <column alignment="left" valignment="top" leftline="true" width="0">
2731 <column alignment="left" valignment="top" leftline="true" width="0">
2732 <column alignment="left" valignment="top" leftline="true" width="0">
2733 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2734 <row topline="true" bottomline="true">
2735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2738 \begin_layout Standard
2746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2749 \begin_layout Standard
2757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2760 \begin_layout Standard
2768 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2771 \begin_layout Standard
2780 <row topline="true">
2781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2784 \begin_layout Standard
2790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2793 \begin_layout Standard
2801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2804 \begin_layout Standard
2810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2813 \begin_layout Standard
2824 <row topline="true">
2825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2828 \begin_layout Standard
2834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2837 \begin_layout Standard
2840 $DATADIR/ $INCLUDE_DIR_SUFFIX
2845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2848 \begin_layout Standard
2849 /usr/local/share/sdcc/include
2854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2857 \begin_layout Standard
2868 <row topline="true">
2869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2872 \begin_layout Standard
2878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2881 \begin_layout Standard
2884 $DATADIR/$LIB_DIR_SUFFIX
2889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2892 \begin_layout Standard
2893 /usr/local/share/sdcc/lib
2898 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2901 \begin_layout Standard
2912 <row topline="true" bottomline="true">
2913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2916 \begin_layout Standard
2922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2925 \begin_layout Standard
2933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2936 \begin_layout Standard
2937 /usr/local/share/sdcc/doc
2942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2945 \begin_layout Standard
2966 *compiler, preprocessor, assembler, and linker
2972 is auto-appended by the compiler, e.g.
2973 small, large, z80, ds390 etc
2976 \begin_layout Standard
2978 The install paths can still be changed during `make install' with e.g.:
2981 \begin_layout LyX-Code
2982 make install prefix=$(HOME)/local/sdcc
2985 \begin_layout Standard
2986 Of course this doesn't change the search paths compiled into the binaries.
2991 r the install path can be changed by defining DESTDIR
2992 \begin_inset LatexCommand \index{DESTDIR}
2999 \begin_layout LyX-Code
3000 make install DESTDIR=$(HOME)/sdcc.rpm/
3003 \begin_layout Standard
3004 Please note that DESTDIR must have a trailing slash!
3007 \begin_layout Section
3009 \begin_inset LatexCommand \label{sub:Search-Paths}
3014 \begin_inset LatexCommand \index{Search path}
3021 \begin_layout Standard
3022 Some search paths or parts of them are determined by configure variables
3027 , see section above).
3028 Further search paths are determined by environment variables during runtime.
3031 The paths searched when running the compiler are as follows (the first
3037 Binary files (preprocessor, assembler and linker)
3042 \begin_layout Standard
3044 \begin_inset Tabular
3045 <lyxtabular version="3" rows="4" columns="3">
3047 <column alignment="block" valignment="top" leftline="true" width="0in">
3048 <column alignment="block" valignment="top" leftline="true" width="0in">
3049 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3050 <row topline="true" bottomline="true">
3051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3054 \begin_layout Standard
3060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3063 \begin_layout Standard
3069 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3072 \begin_layout Standard
3079 <row topline="true">
3080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3083 \begin_layout Standard
3091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3094 \begin_layout Standard
3100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3103 \begin_layout Standard
3112 <row topline="true">
3113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3116 \begin_layout Standard
3117 Path of argv[0] (if available)
3122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3125 \begin_layout Standard
3131 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3134 \begin_layout Standard
3141 <row topline="true" bottomline="true">
3142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3145 \begin_layout Standard
3151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3154 \begin_layout Standard
3160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3163 \begin_layout Standard
3179 \begin_layout Standard
3187 \begin_layout Standard
3189 \begin_inset Tabular
3190 <lyxtabular version="3" rows="6" columns="3">
3192 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3193 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3194 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3195 <row topline="true" bottomline="true">
3196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3199 \begin_layout Standard
3205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3208 \begin_layout Standard
3214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3217 \begin_layout Standard
3224 <row topline="true">
3225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3228 \begin_layout Standard
3233 \begin_layout Standard
3247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3250 \begin_layout Standard
3255 \begin_layout Standard
3269 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3272 \begin_layout Standard
3277 \begin_layout Standard
3292 <row topline="true">
3293 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3296 \begin_layout Standard
3302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3305 \begin_layout Standard
3311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3314 \begin_layout Standard
3321 <row topline="true">
3322 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3325 \begin_layout Standard
3337 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3340 \begin_layout Standard
3350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3353 \begin_layout Standard
3362 <row topline="true">
3363 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3366 \begin_layout Standard
3382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3385 \begin_layout Standard
3433 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3436 \begin_layout Standard
3447 <row topline="true" bottomline="true">
3448 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3451 \begin_layout Standard
3465 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3468 \begin_layout Standard
3469 /usr/local/share/sdcc/
3476 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3479 \begin_layout Standard
3495 \begin_layout Standard
3501 \begin_layout Standard
3510 -nostdinc disables the last two search paths.
3520 \begin_layout Standard
3521 With the exception of
3522 \begin_inset Quotes sld
3529 \begin_layout Standard
3539 \begin_inset Quotes srd
3546 is auto-appended by the compiler (e.g.
3547 small, large, z80, ds390 etc.).
3553 \begin_layout Standard
3555 \begin_inset Tabular
3556 <lyxtabular version="3" rows="6" columns="3">
3558 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3559 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3560 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3561 <row topline="true" bottomline="true">
3562 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3565 \begin_layout Standard
3571 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3574 \begin_layout Standard
3580 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3583 \begin_layout Standard
3590 <row topline="true">
3591 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3594 \begin_layout Standard
3599 \begin_layout Standard
3613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3616 \begin_layout Standard
3621 \begin_layout Standard
3635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3638 \begin_layout Standard
3643 \begin_layout Standard
3658 <row topline="true">
3659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3662 \begin_layout Standard
3672 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3675 \begin_layout Standard
3685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3688 \begin_layout Standard
3701 <row topline="true">
3702 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3705 \begin_layout Standard
3712 $LIB_DIR_SUFFIX/<model>
3717 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3720 \begin_layout Standard
3732 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3735 \begin_layout Standard
3750 <row topline="true">
3751 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3754 \begin_layout Standard
3765 $LIB_DIR_SUFFIX/<model>
3770 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3773 \begin_layout Standard
3824 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3827 \begin_layout Standard
3881 <row topline="true" bottomline="true">
3882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3885 \begin_layout Standard
3890 $LIB_DIR_SUFFIX/<model>
3895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3898 \begin_layout Standard
3899 /usr/local/share/sdcc/
3908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3911 \begin_layout Standard
3927 \begin_layout Standard
3928 \begin_inset Note Note
3931 \begin_layout Standard
3932 Don't delete any of the stray spaces in the table above without checking
3933 the HTML output (last line)!
3941 \begin_layout Standard
3949 \begin_layout Standard
3958 -nostdlib disables the last two search paths.
3961 \begin_layout Section
3963 \begin_inset LatexCommand \index{Building SDCC}
3970 \begin_layout Subsection
3971 Building SDCC on Linux
3972 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3979 \begin_layout Enumerate
3982 Download the source package
3984 either from the SDCC Subversion repository or from snapshot builds
3986 , it will be named something like sdcc
3997 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
4004 \begin_layout Enumerate
4007 Bring up a command line terminal, such as xterm.
4010 \begin_layout Enumerate
4013 Unpack the file using a command like:
4016 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
4017 \begin_inset Quotes srd
4023 , this will create a sub-directory called sdcc with all of the sources.
4026 \begin_layout Enumerate
4027 Change directory into the main SDCC directory, for example type:
4035 \begin_layout Enumerate
4045 This configures the package for compilation on your system.
4048 \begin_layout Enumerate
4062 All of the source packages will compile, this can take a while.
4065 \begin_layout Enumerate
4079 This copies the binary executables, the include files, the libraries and
4080 the documentation to the install directories.
4081 Proceed with section
4082 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
4089 \begin_layout Subsection
4090 Building SDCC on Mac OS X
4093 \begin_layout Standard
4094 Follow the instruction for Linux.
4098 On Mac OS X 10.2.x it was reported, that the
4099 default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
4100 Fortunately there's also gcc 2.9.x installed, which works fine.
4101 This compiler can be selected by running 'configure' with:
4104 \begin_layout LyX-Code
4105 ./configure CC=gcc2 CXX=g++2
4108 \begin_layout Standard
4109 Universal (ppc and i386) binaries can be produced on Mac OS X 10.4.x with
4111 Run 'configure' with:
4114 \begin_layout LyX-Code
4120 \begin_layout LyX-Code
4121 LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4127 \begin_layout LyX-Code
4128 CXXFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4134 \begin_layout LyX-Code
4135 CFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
4138 \begin_layout Subsection
4139 Cross compiling SDCC on Linux for Windows
4142 \begin_layout Standard
4143 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
4144 See section 'Configure Options'.
4147 \begin_layout Subsection
4148 Building SDCC using Cygwin and Mingw32
4151 \begin_layout Standard
4152 For building and installing a Cygwin executable follow the instructions
4158 \begin_inset Quotes sld
4162 \begin_inset Quotes srd
4165 Win32-binary can be built, which will not need the Cygwin-DLL.
4166 For the necessary 'configure' options see section 'configure options' or
4167 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4172 Cygwin on Windows download setup.exe from
4173 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
4179 \begin_inset Quotes sld
4182 default text file type
4183 \begin_inset Quotes srd
4187 \begin_inset Quotes sld
4191 \begin_inset Quotes srd
4194 and download/install at least the following packages.
4195 Some packages are selected by default, others will be automatically selected
4196 because of dependencies with the manually selected packages.
4197 Never deselect these packages!
4200 \begin_layout Itemize
4204 \begin_layout Itemize
4208 \begin_layout Itemize
4209 gcc ; version 3.x is fine, no need to use the old 2.9x
4212 \begin_layout Itemize
4213 binutils ; selected with gcc
4216 \begin_layout Itemize
4220 \begin_layout Itemize
4221 rxvt ; a nice console, which makes life much easier under windoze (see below)
4224 \begin_layout Itemize
4225 man ; not really needed for building SDCC, but you'll miss it sooner or
4229 \begin_layout Itemize
4230 less ; not really needed for building SDCC, but you'll miss it sooner or
4234 \begin_layout Itemize
4235 svn ; only if you use Subversion access
4238 \begin_layout Standard
4239 If you want to develop something you'll need:
4242 \begin_layout Itemize
4243 python ; for the regression tests
4246 \begin_layout Itemize
4247 gdb ; the gnu debugger, together with the nice GUI
4248 \begin_inset Quotes sld
4252 \begin_inset Quotes srd
4258 \begin_layout Itemize
4259 openssh ; to access the CF or commit changes
4262 \begin_layout Itemize
4263 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4264 use autoconf-stable!
4267 \begin_layout Standard
4268 rxvt is a nice console with history.
4269 Replace in your cygwin.bat the line
4272 \begin_layout LyX-Code
4277 \begin_layout Standard
4289 \begin_layout Standard
4293 \begin_layout LyX-Code
4294 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4297 \begin_layout LyX-Code
4298 -bg black -fg white -geometry 100x65 -e bash -
4302 \begin_layout Standard
4314 \begin_layout Standard
4315 Text selected with the mouse is automatically copied to the clipboard, pasting
4316 works with shift-insert.
4320 The other good tip is to make sure you have no //c/-styl
4321 e paths anywhere, use /cygdrive/c/ instead.
4322 Using // invokes a network lookup which is very slow.
4324 \begin_inset Quotes sld
4328 \begin_inset Quotes srd
4331 is too long, you can change it with e.g.
4334 \begin_layout LyX-Code
4338 \begin_layout Standard
4339 SDCC sources use the unix line ending LF.
4340 Life is much easier, if you store the source tree on a drive which is mounted
4342 And use an editor which can handle LF-only line endings.
4343 Make sure not to commit files with windows line endings.
4344 The tabulator spacing
4345 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4349 used in the project is 8.
4350 Although a tabulator spacing of 8 is a sensible choice for programmers
4351 (it's a power of 2 and allows to display 8/16 bit signed variables without
4352 loosing columns) the plan is to move towards using only spaces in the source.
4355 \begin_layout Subsection
4356 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4359 \begin_layout Standard
4362 Download the source package
4364 either from the SDCC Subversion repository or from the
4365 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4371 , it will be named something like sdcc
4375 -yyyymmdd-rrrr.tar.bz2.
4378 SDCC is distributed with all the projects, workspaces, and files you need
4379 to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4380 The workspace name is 'sdcc.dsw'.
4381 Please note that as it is now, all the executables are created in a folder
4385 Once built you need to copy the executables from sdcc
4389 bin before running SDCC.
4394 WARNING: Visual studio is very picky with line terminations; it expects
4395 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4396 When using the Subversion repository it's easiest to configure the svn
4397 client to convert automatically for you.
4398 If however you are getting a message such as "This makefile was not generated
4399 by Developer Studio etc.
4401 \begin_inset Quotes srd
4404 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4405 need to convert the Unix style line endings to DOS style line endings.
4406 To do so you can use the
4407 \begin_inset Quotes sld
4411 \begin_inset Quotes srd
4414 utility freely available on the internet.
4415 Doug Hawkins reported in the sdcc-user list that this works:
4423 SDCC> unix2dos sdcc.dsw
4429 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4433 In order to build SDCC with MSVC
4434 you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4435 One good place to get them is
4436 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4444 Download the file UnxUtils
4445 \begin_inset LatexCommand \index{UnxUtils}
4450 Now you have to install the utilities and setup MSVC so it can locate the
4452 Here there are two alternatives (choose one!):
4455 \begin_layout Enumerate
4460 a) Extract UnxUtils.zip to your C:
4462 hard disk PRESERVING the original paths, otherwise bison won't work.
4463 (If you are using WinZip make certain that 'Use folder names' is selected)
4468 In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4469 'Show directories for:' select 'Executable files', and in the directories
4470 window add a new path: 'C:
4480 (As a side effect, you get a bunch of Unix utilities that
4481 could be useful, such as diff and patch.)
4484 \begin_layout Enumerate
4489 This one avoids extracting a bunch of files you may not
4490 use, but requires some extra work:
4494 a) Create a directory were to put the
4495 tools needed, or use a directory already present.
4502 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4503 gawk.exe to such directory WITHOUT preserving the original paths.
4504 (If you are using WinZip make certain that 'Use folder names' is not selected)
4509 ) Rename bison.exe to '_bison.exe'.
4513 d) Create a batch file 'bison.bat' in 'C:
4517 ' and add these lines:
4537 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4541 Steps 'c' and 'd' are needed
4542 because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4543 reside in some weird Unix directory, '/usr/local/share/' I think.
4544 So it is necessary to tell bison where those files are located if they
4545 are not in such directory.
4546 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4551 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4552 in 'Show directories for:' select 'Executable files', and in the directories
4553 window add a new path: 'c:
4556 Note that you can use any other path instead of 'c:
4558 util', even the path where the Visual C++ tools are, probably: 'C:
4562 Microsoft Visual Studio
4567 So you don't have to execute step 'e' :)
4570 \begin_layout Standard
4572 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4573 the executables from sdcc
4577 bin, and you can compile using SDCC.
4580 \begin_layout Subsection
4581 Building SDCC Using Borland
4584 \begin_layout Enumerate
4585 From the sdcc directory, run the command "make -f Makefile.bcc".
4586 This should regenerate all the .exe files in the bin directory except for
4590 \begin_layout Enumerate
4591 If you modify any source files and need to rebuild, be aware that the dependenci
4592 es may not be correctly calculated.
4593 The safest option is to delete all .obj files and run the build again.
4594 From a Cygwin BASH prompt, this can easily be done with the command (be
4595 sure you are in the sdcc directory):
4605 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
4607 ) -print -exec rm {}
4616 or on Windows NT/2000/XP from the command prompt with the command:
4623 del /s *.obj *.lib *.rul
4626 from the sdcc directory.
4629 \begin_layout Subsection
4630 Windows Install Using a ZIP Package
4633 \begin_layout Enumerate
4634 Download the binary zip package from
4635 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4639 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4640 This should unpack to a group of sub-directories.
4641 An example directory structure after unpacking the mingw32 package is:
4646 bin for the executables, c:
4654 lib for the include and libraries.
4657 \begin_layout Enumerate
4658 Adjust your environment variable PATH to include the location of the bin
4659 directory or start sdcc using the full path.
4662 \begin_layout Subsection
4663 Windows Install Using the Setup Program
4664 \begin_inset LatexCommand \label{sub:Windows-Install}
4671 \begin_layout Standard
4672 Download the setup program
4674 sdcc-x.y.z-setup.exe
4676 for an official release from
4679 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4683 or a setup program for one of the snapshots
4685 sdcc-yyyymmdd-xxxx-setup.exe
4688 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4693 A windows typical installer will guide you through the installation process.
4696 \begin_layout Subsection
4698 \begin_inset LatexCommand \index{VPATH}
4705 \begin_layout Standard
4706 SDCC supports the VPATH feature provided by configure and make.
4707 It allows to separate the source and build trees.
4711 \begin_layout Standard
4738 \begin_layout Standard
4741 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4742 # extract source to directory sdcc
4745 \begin_layout Standard
4748 mkdir sdcc.build\InsetSpace ~
4757 # put output in sdcc.build
4760 \begin_layout Standard
4766 \begin_layout Standard
4769 ../sdcc/configure\InsetSpace ~
4777 # configure is doing all the magic!
4780 \begin_layout Standard
4786 \begin_layout Standard
4792 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4793 It automagically computes the variables srcdir, top_srcdir and top_buildir
4799 the generated files will be in ~/sdcc.build, while the source files stay
4802 This is not only usefull for building different binaries, e.g.
4803 when cross compiling.
4804 It also gives you a much better overview in the source tree when all the
4805 generated files are not scattered between the source files.
4806 And the best thing is: if you want to change a file you can leave the original
4807 file untouched in the source directory.
4808 Simply copy it to the build directory, edit it, enter `make clean', `rm
4809 Makefile.dep' and `make'.
4814 will do the rest for you!
4817 \begin_layout Section
4818 Building the Documentation
4821 \begin_layout Standard
4826 \begin_layout Standard
4835 -enable-doc to the configure arguments to build the documentation together
4836 with all the other stuff.
4837 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4838 dvips and makeindex) to get the job done.
4839 Another possibility is to change to the doc directory and to type
4843 \begin_inset Quotes srd
4847 \begin_inset Quotes srd
4854 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4857 \begin_inset LatexCommand \url{http://www.lyx.org}
4861 as editor is straightforward.
4862 Prebuilt documentation in html and pdf format is available from
4863 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4870 \begin_layout Section
4871 Reading the Documentation
4872 \begin_inset LatexCommand \index{Documentation}
4879 \begin_layout Standard
4880 Currently reading the document in pdf format is recommended, as for unknown
4881 reason the hyperlinks are working there whereas in the html version they
4886 \begin_layout Standard
4887 If you should know why please drop us a note
4895 You'll find the pdf version
4896 \begin_inset LatexCommand \index{PDF version of this document}
4901 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4909 \begin_inset LatexCommand \index{HTML version of this document}
4914 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4920 This documentation is in some aspects different from a commercial documentation:
4924 \begin_layout Itemize
4925 It tries to document SDCC for several processor architectures in one document
4926 (commercially these probably would be separate documents/products).
4928 \begin_inset LatexCommand \index{Status of documentation}
4932 currently matches SDCC for mcs51 and DS390 best and does give too few informati
4934 Z80, PIC14, PIC16 and HC08.
4937 \begin_layout Itemize
4938 There are many references pointing away from this documentation.
4939 Don't let this distract you.
4941 was a reference like
4942 \begin_inset LatexCommand \url{http://www.opencores.org}
4946 together with a statement
4947 \begin_inset Quotes sld
4950 some processors which are targetted by SDCC can be implemented in a
4967 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4972 \begin_inset Quotes srd
4976 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4981 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4986 \begin_inset Quotes sld
4989 have you ever heard of an open source compiler that compiles a subset of
4991 \begin_inset Quotes srd
4994 we expect you to have a quick look there and come back.
4995 If you read this you are on the right track.
4998 \begin_layout Itemize
4999 Some sections attribute more space to problems, restrictions and warnings
5000 than to the solution.
5003 \begin_layout Itemize
5004 The installation section and the section about the debugger is intimidating.
5007 \begin_layout Itemize
5008 There are still lots of typos and there are more different writing styles
5012 \begin_layout Section
5013 Testing the SDCC Compiler
5014 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
5021 \begin_layout Standard
5022 The first thing you should do after installing your SDCC compiler is to
5031 \begin_layout Standard
5041 \begin_inset LatexCommand \index{version}
5048 at the prompt, and the program should run and output its version like:
5053 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
5057 \begin_layout Standard
5058 If it doesn't run, or gives a message about not finding sdcc program, then
5059 you need to check over your installation.
5060 Make sure that the sdcc bin directory is in your executable search path
5061 defined by the PATH environment setting (
5066 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5073 Install trouble-shooting for suggestions
5076 Make sure that the sdcc program is in the bin folder, if not perhaps something
5077 did not install correctly.
5085 is commonly installed as described in section
5086 \begin_inset Quotes sld
5089 Install and search paths
5090 \begin_inset Quotes srd
5099 Make sure the compiler works on a very simple example.
5100 Type in the following test.c program using your favorite
5125 \begin_layout Standard
5128 Compile this using the following command:
5137 If all goes well, the compiler will generate a test.asm and test.rel file.
5138 Congratulations, you've just compiled your first program with SDCC.
5139 We used the -c option to tell SDCC not to link the generated code, just
5140 to keep things simple for this step.
5148 The next step is to try it with the linker.
5158 If all goes well the compiler will link with the libraries and produce
5159 a test.ihx output file.
5164 (no test.ihx, and the linker generates warnings), then the problem is most
5173 usr/local/share/sdcc/lib directory
5180 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5187 Install trouble-shooting for suggestions).
5195 The final test is to ensure
5203 header files and libraries.
5204 Edit test.c and change it to the following:
5222 strcpy(str1, "testing");
5227 \begin_layout Standard
5230 Compile this by typing
5237 This should generate a test.ihx output file, and it should give no warnings
5238 such as not finding the string.h file.
5239 If it cannot find the string.h file, then the problem is that
5243 cannot find the /usr/local/share/sdcc/include directory
5250 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5257 Install trouble-shooting section for suggestions).
5266 \begin_layout Standard
5278 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5282 to find exactly where SDCC is looking for the include and lib files.
5285 \begin_layout Section
5286 Install Trouble-shooting
5287 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5292 \begin_inset LatexCommand \index{Install trouble-shooting}
5299 \begin_layout Subsection
5300 If SDCC does not build correctly
5303 \begin_layout Standard
5304 A thing to try is starting from scratch by unpacking the .tgz source package
5305 again in an empty directory.
5313 ./configure 2>&1 | tee configure.log
5327 make 2>&1 | tee make.log
5334 If anything goes wrong, you can review the log files to locate the problem.
5335 Or a relevant part of this can be attached to an email that could be helpful
5336 when requesting help from the mailing list.
5339 \begin_layout Subsection
5341 \begin_inset Quotes sld
5345 \begin_inset Quotes srd
5351 \begin_layout Standard
5353 \begin_inset Quotes sld
5357 \begin_inset Quotes srd
5360 command is a script that analyzes your system and performs some configuration
5361 to ensure the source package compiles on your system.
5362 It will take a few minutes to run, and will compile a few tests to determine
5363 what compiler features are installed.
5366 \begin_layout Subsection
5368 \begin_inset Quotes sld
5372 \begin_inset Quotes srd
5378 \begin_layout Standard
5379 This runs the GNU make tool, which automatically compiles all the source
5380 packages into the final installed binary executables.
5383 \begin_layout Subsection
5385 \begin_inset Quotes sld
5389 \begin_inset Quotes erd
5395 \begin_layout Standard
5396 This will install the compiler, other executables libraries and include
5397 files into the appropriate directories.
5399 \begin_inset LatexCommand \ref{sub:Install-paths}
5405 \begin_inset LatexCommand \ref{sub:Search-Paths}
5410 about install and search paths.
5412 On most systems you will need super-user privilege
5416 \begin_layout Section
5420 \begin_layout Standard
5421 SDCC is not just a compiler, but a collection of tools by various developers.
5422 These include linkers, assemblers, simulators and other components.
5423 Here is a summary of some of the components.
5424 Note that the included simulator and assembler have separate documentation
5425 which you can find in the source package in their respective directories.
5426 As SDCC grows to include support for other processors, other packages from
5427 various developers are included and may have their own sets of documentation.
5432 might want to look at the files which are installed in <installdir>.
5433 At the time of this writing, we find the following programs for gcc-builds:
5438 In <installdir>/bin:
5441 \begin_layout Itemize
5442 sdcc - The compiler.
5445 \begin_layout Itemize
5446 sdcpp - The C preprocessor.
5449 \begin_layout Itemize
5450 asx8051 - The assembler for 8051 type processors.
5453 \begin_layout Itemize
5458 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5461 \begin_layout Itemize
5462 aslink -The linker for 8051 type processors.
5465 \begin_layout Itemize
5470 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5473 \begin_layout Itemize
5474 s51 - The ucSim 8051 simulator.
5477 \begin_layout Itemize
5478 sdcdb - The source debugger.
5481 \begin_layout Itemize
5482 packihx - A tool to pack (compress) Intel hex files.
5485 \begin_layout Standard
5486 In <installdir>/share/sdcc/include
5489 \begin_layout Itemize
5493 \begin_layout Standard
5494 In <installdir>/share/sdcc/lib
5497 \begin_layout Itemize
5498 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5502 \begin_layout Standard
5503 In <installdir>/share/sdcc/doc
5506 \begin_layout Itemize
5510 \begin_layout Standard
5511 As development for other processors proceeds, this list will expand to include
5512 executables to support processors like AVR, PIC, etc.
5515 \begin_layout Subsection
5519 \begin_layout Standard
5520 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5521 the assembler and linkage editor.
5524 \begin_layout Subsection
5525 sdcpp - The C-Preprocessor
5528 \begin_layout Standard
5530 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5534 is a modified version of the GNU cpp
5535 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5540 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5545 The C preprocessor is used to pull in #include sources, process #ifdef
5546 statements, #defines and so on.
5549 \begin_layout Subsection
5558 - The Assemblers and Linkage Editors
5561 \begin_layout Standard
5562 This is retargettable assembler & linkage editor, it was developed by Alan
5564 John Hartman created the version for 8051, and I (Sandeep) have made some
5565 enhancements and bug fixes for it to work properly with SDCC.
5568 \begin_layout Subsection
5572 \begin_layout Standard
5574 \begin_inset LatexCommand \index{s51}
5578 is a free open source simulator developed by Daniel Drotos.
5579 The simulator is built as part of the build process.
5580 For more information visit Daniel's web site at:
5581 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5586 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5590 \begin_layout Subsection
5591 sdcdb - Source Level Debugger
5594 \begin_layout Standard
5596 \begin_inset LatexCommand \index{SDCDB (debugger)}
5600 is the companion source level debugger.
5601 More about SDCDB in section
5602 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5607 The current version of the debugger uses Daniel's Simulator S51
5608 \begin_inset LatexCommand \index{s51}
5612 , but can be easily changed to use other simulators.
5615 \begin_layout Chapter
5619 \begin_layout Section
5623 \begin_layout Subsection
5624 Single Source File Projects
5627 \begin_layout Standard
5628 For single source file 8051 projects the process is very simple.
5629 Compile your programs with the following command
5632 "sdcc sourcefile.c".
5636 This will compile, assemble and link your source file.
5637 Output files are as follows:
5640 \begin_layout Itemize
5642 \begin_inset LatexCommand \index{<file>.asm}
5647 \begin_inset LatexCommand \index{Assembler source}
5651 file created by the compiler
5654 \begin_layout Itemize
5656 \begin_inset LatexCommand \index{<file>.lst}
5661 \begin_inset LatexCommand \index{Assembler listing}
5665 file created by the Assembler
5668 \begin_layout Itemize
5670 \begin_inset LatexCommand \index{<file>.rst}
5675 \begin_inset LatexCommand \index{Assembler listing}
5679 file updated with linkedit information, created by linkage editor
5682 \begin_layout Itemize
5684 \begin_inset LatexCommand \index{<file>.sym}
5689 \begin_inset LatexCommand \index{Symbol listing}
5693 for the sourcefile, created by the assembler
5696 \begin_layout Itemize
5698 \begin_inset LatexCommand \index{<file>.rel}
5703 \begin_inset LatexCommand \index{<file>.o}
5708 \begin_inset LatexCommand \index{Object file}
5712 created by the assembler, input to Linkage editor
5715 \begin_layout Itemize
5717 \begin_inset LatexCommand \index{<file>.map}
5722 \begin_inset LatexCommand \index{Memory map}
5726 for the load module, created by the Linker
5729 \begin_layout Itemize
5731 \begin_inset LatexCommand \index{<file>.mem}
5735 - A file with a summary of the memory usage
5738 \begin_layout Itemize
5740 \begin_inset LatexCommand \index{<file>.ihx}
5744 - The load module in Intel hex format
5745 \begin_inset LatexCommand \index{Intel hex format}
5749 (you can select the Motorola S19 format
5750 \begin_inset LatexCommand \index{Motorola S19 format}
5758 \begin_layout Standard
5768 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5773 If you need another format you might want to use
5780 \begin_inset LatexCommand \index{objdump (tool)}
5791 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5796 \begin_inset Note Note
5799 \begin_layout Standard
5806 \begin_inset LatexCommand \vref{sub:Postprocessing-the-Intel}
5811 Both formats are documented in the documentation of srecord
5812 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5819 \begin_layout Itemize
5821 \begin_inset LatexCommand \index{<file>.adb}
5825 - An intermediate file containing debug information needed to create the
5830 \begin_layout Standard
5840 \begin_inset LatexCommand \index{-\/-debug}
5847 \begin_layout Itemize
5849 \begin_inset LatexCommand \index{<file>.cdb}
5853 - An optional file (with -
5857 \begin_layout Standard
5866 -debug) containing debug information.
5867 The format is documented in cdbfileformat.pdf
5870 \begin_layout Itemize
5873 \begin_inset LatexCommand \index{<file> (no extension)}
5877 An optional AOMF or AOMF51
5878 \begin_inset LatexCommand \index{AOMF, AOMF51}
5883 \begin_inset LatexCommand \label{OMF file}
5887 file containing debug information (generated with option -
5891 \begin_layout Standard
5917 ormat is a subformat of the OMF51 format and is commonly used by third party
5919 \begin_inset LatexCommand \index{Debugger}
5923 , simulators, emulators).
5926 \begin_layout Itemize
5928 \begin_inset LatexCommand \index{<file>.dump*}
5932 - Dump file to debug the compiler it self (generated with option -
5936 \begin_layout Standard
5945 -dumpall) (see section
5946 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5952 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5958 \begin_inset Quotes sld
5961 Anatomy of the compiler
5962 \begin_inset Quotes srd
5968 \begin_layout Subsection
5969 Postprocessing the Intel Hex
5970 \begin_inset LatexCommand \index{Intel hex format}
5975 \begin_inset LatexCommand \label{sub:Postprocessing-the-Intel}
5982 \begin_layout Standard
5983 In most cases this won't be needed but the Intel Hex file
5984 \begin_inset LatexCommand \index{<file>.ihx}
5988 which is generated by SDCC might include lines of varying length and the
5989 addresses within the file are not guaranteed to be strictly ascending.
5990 If your toolchain or a bootloader does not like this you can use the tool
5996 \begin_inset LatexCommand \index{packihx (tool)}
6000 which is part of the SDCC distribution:
6007 packihx sourcefile.ihx >sourcefile.hex
6014 The separately available
6019 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6023 package additionally allows to set undefined locations to a predefined
6024 value, to insert checksums
6025 \begin_inset LatexCommand \index{checksum}
6029 of various flavours (crc, add, xor) and to perform other manipulations
6030 (convert, split, crop, offset, ...).
6038 srec_cat\InsetSpace ~
6040 sourcefile.ihx -intel\InsetSpace ~
6042 -o sourcefile.hex -intel
6049 An example for a more complex command line
6053 \begin_layout Standard
6054 the command backfills
6055 \begin_inset LatexCommand \index{backfill unused memory}
6059 unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
6061 If the program counter on an mcs51 runs wild the backfill pattern 0x12
6062 will be interpreted as an
6070 (where an emergency routine could sit).
6083 srec_cat\InsetSpace ~
6084 sourcefile.ihx -intel\InsetSpace ~
6086 -fill 0x12 0x0000 0xfffe\InsetSpace ~
6087 -little-endian-checksum-nega
6088 tive 0xfffe 0x02 0x02\InsetSpace ~
6090 -o sourcefile.hex -intel
6099 The srecord package is available at
6100 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
6107 \begin_layout Subsection
6108 Projects with Multiple Source Files
6111 \begin_layout Standard
6112 SDCC can compile only ONE file at a time.
6113 Let us for example assume that you have a project containing the following
6118 foo1.c (contains some functions)
6120 foo2.c (contains some more functions)
6123 n.c (contains more functions and the function main)
6131 The first two files will need to be compiled separately with the commands:
6163 Then compile the source file containing the
6168 \begin_inset LatexCommand \index{Linker}
6172 the files together with the following command:
6180 foomain.c\InsetSpace ~
6181 foo1.rel\InsetSpace ~
6186 \begin_inset LatexCommand \index{<file>.rel}
6198 can be separately compiled as well:
6209 sdcc foomain.rel foo1.rel foo2.rel
6216 The file containing the
6231 file specified in the command line, since the linkage editor processes
6232 file in the order they are presented to it.
6233 The linker is invoked from SDCC using a script file with extension .lnk
6234 \begin_inset LatexCommand \index{<file>.lnk}
6239 You can view this file to troubleshoot linking problems such as those arising
6240 from missing libraries.
6243 \begin_layout Subsection
6244 Projects with Additional Libraries
6245 \begin_inset LatexCommand \index{Libraries}
6252 \begin_layout Standard
6253 Some reusable routines may be compiled into a library, see the documentation
6254 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6258 \begin_inset LatexCommand \index{<file>.lib}
6265 Libraries created in this manner can be included in the command line.
6266 Make sure you include the -L <library-path> option to tell the linker where
6267 to look for these files if they are not in the current directory.
6268 Here is an example, assuming you have the source file
6280 (if that is not the same as your current project):
6287 sdcc foomain.c foolib.lib -L mylib
6298 must be an absolute path name.
6302 The most efficient way to use libraries is
6303 to keep separate modules in separate source files.
6304 The lib file now should name all the modules.rel
6305 \begin_inset LatexCommand \index{<file>.rel}
6310 For an example see the standard library file
6314 in the directory <installdir>/share/lib/small.
6317 \begin_layout Subsection
6318 Using sdcclib to Create and Manage Libraries
6319 \begin_inset LatexCommand \index{sdcclib}
6326 \begin_layout Standard
6327 Alternatively, instead of having a .rel file for each entry on the library
6328 file as described in the preceding section, sdcclib can be used to embed
6329 all the modules belonging to such library in the library file itself.
6330 This results in a larger library file, but it greatly reduces the number
6331 of disk files accessed by the linker.
6332 Additionally, the packed library file contains an index of all include
6333 modules and symbols that significantly speeds up the linking process.
6334 To display a list of options supported by sdcclib type:
6339 \begin_layout Standard
6344 \begin_inset LatexCommand \index{sdcclib}
6355 To create a new library file, start by compiling all the required modules.
6361 \begin_layout Standard
6368 \begin_layout Standard
6375 \begin_layout Standard
6382 \begin_layout Standard
6389 \begin_layout Standard
6398 \begin_layout Standard
6399 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6401 The next step is to add the .rel files to the library file:
6406 \begin_layout Standard
6410 sdcclib libint.lib _divsint.rel
6413 \begin_inset LatexCommand \index{sdcclib}
6420 \begin_layout Standard
6424 sdcclib libint.lib _divuint.rel
6427 \begin_layout Standard
6431 sdcclib libint.lib _modsint.rel
6434 \begin_layout Standard
6438 sdcclib libint.lib _moduint.rel
6441 \begin_layout Standard
6445 sdcclib libint.lib _mulint.rel
6453 \begin_layout Standard
6462 \begin_layout Standard
6466 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6474 \begin_layout Standard
6475 If the file already exists in the library, it will be replaced.
6476 If a list of .rel files is available, you can tell sdcclib to add those
6478 For example, if the file 'myliblist.txt' contains
6486 \begin_layout Standard
6493 \begin_layout Standard
6500 \begin_layout Standard
6507 \begin_layout Standard
6514 \begin_layout Standard
6526 \begin_layout Standard
6535 \begin_layout Standard
6539 sdcclib -l libint.lib myliblist.txt
6547 \begin_layout Standard
6548 Additionally, you can instruct sdcclib to compiles the files before adding
6549 them to the library.
6550 This is achieved using the environment variables SDCCLIB_CC and/or SDCCLIB_AS.
6559 \begin_layout Standard
6563 set SDCCLIB_CC=sdcc -c
6566 \begin_layout Standard
6570 sdcclib -l libint.lib myliblist.txt
6578 \begin_layout Standard
6579 To see what modules and symbols are included in the library, options -s
6580 and -m are available.
6588 sdcclib -s libint.lib
6591 \begin_inset LatexCommand \index{sdcclib}
6603 \begin_layout Standard
6609 \begin_layout Standard
6615 \begin_layout Standard
6623 \begin_layout Standard
6629 \begin_layout Standard
6635 \begin_layout Standard
6641 \begin_layout Standard
6647 \begin_layout Standard
6655 \begin_layout Standard
6661 \begin_layout Standard
6667 \begin_layout Standard
6675 \begin_layout Standard
6681 \begin_layout Standard
6687 \begin_layout Standard
6693 \begin_layout Standard
6701 \begin_layout Standard
6707 \begin_layout Standard
6718 \begin_layout Standard
6719 If the source files are compiled using -
6723 \begin_layout Standard
6733 \begin_inset LatexCommand \index{-\/-debug}
6737 , the corresponding debug information file .adb will be include in the library
6739 The library files created with sdcclib are plain text files, so they can
6740 be viewed with a text editor.
6741 It is not recomended to modify a library file created with sdcclib using
6742 a text editor, as there are file indexes numbers located accross the file
6743 used by the linker to quickly locate the required module to link.
6744 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6745 it can be safely deleted, since all the information required for linking
6746 is embedded in the library file itself.
6747 Library files created using sdcclib are used as described in the preceding
6749 \begin_inset VSpace bigskip
6755 \begin_layout Section
6756 Command Line Options
6757 \begin_inset LatexCommand \index{Command Line Options}
6762 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6769 \begin_layout Subsection
6770 Processor Selection Options
6771 \begin_inset LatexCommand \index{Options processor selection}
6776 \begin_inset LatexCommand \index{Processor selection options}
6784 \labelwidthstring 00.00.0000
6788 \begin_inset LatexCommand \index{-mmcs51}
6794 Generate code for the Intel MCS51
6795 \begin_inset LatexCommand \index{MCS51}
6799 family of processors.
6800 This is the default processor target.
6804 \labelwidthstring 00.00.0000
6808 \begin_inset LatexCommand \index{-mds390}
6814 Generate code for the Dallas DS80C390
6815 \begin_inset LatexCommand \index{DS80C390}
6823 \labelwidthstring 00.00.0000
6827 \begin_inset LatexCommand \index{-mds400}
6833 Generate code for the Dallas DS80C400
6834 \begin_inset LatexCommand \index{DS80C400}
6842 \labelwidthstring 00.00.0000
6846 \begin_inset LatexCommand \index{-mhc08}
6852 Generate code for the Freescale/Motorola HC08
6853 \begin_inset LatexCommand \index{HC08}
6857 family of processors.
6861 \labelwidthstring 00.00.0000
6865 \begin_inset LatexCommand \index{-mz80}
6871 Generate code for the Zilog Z80
6872 \begin_inset LatexCommand \index{Z80}
6876 family of processors.
6880 \labelwidthstring 00.00.0000
6884 \begin_inset LatexCommand \index{-mgbz80}
6890 Generate code for the GameBoy Z80
6891 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6895 processor (Not actively maintained).
6899 \labelwidthstring 00.00.0000
6903 \begin_inset LatexCommand \index{-mavr}
6909 Generate code for the Atmel AVR
6910 \begin_inset LatexCommand \index{AVR}
6914 processor (Not maintained, not complete).
6915 AVR users should probably have a look at winavr
6916 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6921 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6925 , which is based on AVR-port of the gcc compiler.
6928 \begin_layout Standard
6929 \begin_inset Note Note
6932 \begin_layout Standard
6933 I think it is fair to direct users there for now.
6934 Open source is also about avoiding unnecessary work .
6935 But I didn't find the 'official' link.
6944 \labelwidthstring 00.00.0000
6948 \begin_inset LatexCommand \index{-mpic14}
6954 Generate code for the Microchip PIC 14
6955 \begin_inset LatexCommand \index{PIC14}
6959 -bit processors (p16f84 and variants.
6960 In development, not complete).
6963 \begin_layout Standard
6964 \begin_inset Note Note
6967 \begin_layout Standard
6968 p16f627 p16f628 p16f84 p16f873 p16f877?
6977 \labelwidthstring 00.00.0000
6981 \begin_inset LatexCommand \index{-mpic16}
6987 Generate code for the Microchip PIC 16
6988 \begin_inset LatexCommand \index{PIC16}
6992 -bit processors (p18f452 and variants.
6993 In development, not complete).
6997 \labelwidthstring 00.00.0000
7002 Generate code for the Toshiba TLCS-900H
7003 \begin_inset LatexCommand \index{TLCS-900H}
7007 processor (Not maintained, not complete).
7011 \labelwidthstring 00.00.0000
7015 \begin_inset LatexCommand \index{-mxa51}
7021 Generate code for the Phillips XA51
7022 \begin_inset LatexCommand \index{XA51}
7026 processor (Not maintained, not complete).
7029 \begin_layout Standard
7030 \begin_inset VSpace bigskip
7036 \begin_layout Subsection
7037 Preprocessor Options
7038 \begin_inset LatexCommand \index{Options preprocessor}
7043 \begin_inset LatexCommand \index{Preprocessor options}
7048 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7056 \labelwidthstring 00.00.0000
7060 \begin_inset LatexCommand \index{-I<path>}
7066 The additional location where the preprocessor will look for <..h> or
7067 \begin_inset Quotes eld
7071 \begin_inset Quotes erd
7078 \labelwidthstring 00.00.0000
7082 \begin_inset LatexCommand \index{-D<macro[=value]>}
7088 Command line definition of macros.
7089 Passed to the preprocessor.
7093 \labelwidthstring 00.00.0000
7097 \begin_inset LatexCommand \index{-M}
7103 Tell the preprocessor to output a rule suitable for make describing the
7104 dependencies of each object file.
7105 For each source file, the preprocessor outputs one make-rule whose target
7106 is the object file name for that source file and whose dependencies are
7107 all the files `#include'd in it.
7108 This rule may be a single line or may be continued with `
7110 '-newline if it is long.
7111 The list of rules is printed on standard output instead of the preprocessed
7114 \begin_inset LatexCommand \index{-E}
7122 \labelwidthstring 00.00.0000
7126 \begin_inset LatexCommand \index{-C}
7132 Tell the preprocessor not to discard comments.
7133 Used with the `-E' option.
7137 \labelwidthstring 00.00.0000
7141 \begin_inset LatexCommand \index{-MM}
7152 Like `-M' but the output mentions only the user header files included with
7154 \begin_inset Quotes eld
7158 System header files included with `#include <file>' are omitted.
7162 \labelwidthstring 00.00.0000
7166 \begin_inset LatexCommand \index{-Aquestion(answer)}
7172 Assert the answer answer for question, in case it is tested with a preprocessor
7173 conditional such as `#if #question(answer)'.
7174 `-A-' disables the standard assertions that normally describe the target
7179 \labelwidthstring 00.00.0000
7183 \begin_inset LatexCommand \index{-Umacro}
7189 Undefine macro macro.
7190 `-U' options are evaluated after all `-D' options, but before any `-include'
7191 and `-imacros' options.
7195 \labelwidthstring 00.00.0000
7199 \begin_inset LatexCommand \index{-dM}
7205 Tell the preprocessor to output only a list of the macro definitions that
7206 are in effect at the end of preprocessing.
7207 Used with the `-E' option.
7211 \labelwidthstring 00.00.0000
7215 \begin_inset LatexCommand \index{-dD}
7221 Tell the preprocessor to pass all macro definitions into the output, in
7222 their proper sequence in the rest of the output.
7226 \labelwidthstring 00.00.0000
7230 \begin_inset LatexCommand \index{-dN}
7241 Like `-dD' except that the macro arguments and contents are omitted.
7242 Only `#define name' is included in the output.
7246 \labelwidthstring 00.00.0000
7249 -pedantic-parse-number
7250 \begin_inset LatexCommand \index{pedantic}
7255 \begin_inset LatexCommand \index{-pedantic-parse-number}
7263 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
7271 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7272 and the macro LO_B(3) gets expanded.
7273 See also #pragma pedantic_parse_number
7274 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
7279 \begin_inset LatexCommand \ref{sec:Pragmas}
7285 Note: this functionality is not in conformance with C99 standard!
7289 \labelwidthstring 00.00.0000
7293 preprocessorOption[,preprocessorOption]
7296 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
7301 Pass the preprocessorOption to the preprocessor
7306 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7311 SDCC uses an adapted version of the preprocessor
7315 of the GNU Compiler Collection
7316 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
7325 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7329 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7334 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7341 \begin_layout Standard
7342 \begin_inset VSpace bigskip
7348 \begin_layout Subsection
7350 \begin_inset LatexCommand \index{Options linker}
7355 \begin_inset LatexCommand \index{Linker options}
7363 \labelwidthstring 00.00.0000
7373 \begin_layout Standard
7385 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7390 \begin_inset LatexCommand \index{-L -\/-lib-path}
7397 <absolute path to additional libraries> This option is passed to the linkage
7398 editor's additional libraries
7399 \begin_inset LatexCommand \index{Libraries}
7404 The path name must be absolute.
7405 Additional library files may be specified in the command line.
7406 See section Compiling programs for more details.
7410 \labelwidthstring 00.00.0000
7417 \begin_layout Standard
7429 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7434 <Value> The start location of the external ram
7435 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7439 , default value is 0.
7440 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7444 \begin_layout Standard
7453 -xram-loc 0x8000 or -
7457 \begin_layout Standard
7470 \labelwidthstring 00.00.0000
7477 \begin_layout Standard
7489 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7494 <Value> The start location of the code
7495 \begin_inset LatexCommand \index{code}
7499 segment, default value 0.
7500 Note when this option is used the interrupt vector table
7501 \begin_inset LatexCommand \index{interrupt vector table}
7505 is also relocated to the given address.
7506 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7510 \begin_layout Standard
7519 -code-loc 0x8000 or -
7523 \begin_layout Standard
7536 \labelwidthstring 00.00.0000
7543 \begin_layout Standard
7555 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7560 <Value> By default the stack
7561 \begin_inset LatexCommand \index{stack}
7565 is placed after the data segment.
7566 Using this option the stack can be placed anywhere in the internal memory
7568 The value entered can be in Hexadecimal or Decimal format, e.g.
7573 \begin_layout Standard
7582 -stack-loc 0x20 or -
7586 \begin_layout Standard
7596 Since the sp register is incremented before a push or call, the initial
7597 sp will be set to one byte prior the provided value.
7598 The provided value should not overlap any other memory areas such as used
7599 register banks or the data segment and with enough space for the current
7607 \begin_layout Standard
7620 \begin_inset LatexCommand \index{-\/-pack-iram}
7624 option (which is now a default setting) will override this setting, so
7625 you should also specify the
7631 \begin_layout Standard
7644 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7648 option if you need to manually place the stack.
7652 \labelwidthstring 00.00.0000
7659 \begin_layout Standard
7671 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7676 <Value> By default the external stack
7677 \begin_inset LatexCommand \index{xstack}
7681 is placed after the pdata
7682 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7687 Using this option the xstack can be placed anywhere in the external memory
7689 The value entered can be in Hexadecimal or Decimal format, e.g.
7694 \begin_layout Standard
7703 -xstack-loc 0x8000 or -
7707 \begin_layout Standard
7717 The provided value should not overlap any other memory areas such as the
7718 pdata or xdata segment and with enough space for the current application.
7722 \labelwidthstring 00.00.0000
7729 \begin_layout Standard
7741 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7746 <Value> The start location of the internal ram data
7747 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7752 The value entered can be in Hexadecimal or Decimal format, eg.
7757 \begin_layout Standard
7770 \begin_layout Standard
7780 (By default, the start location of the internal ram data segment is set
7781 as low as possible in memory, taking into account the used register banks
7782 and the bit segment at address 0x20.
7783 For example if register banks 0 and 1 are used without bit variables, the
7784 data segment will be set, if -
7788 \begin_layout Standard
7797 -data-loc is not used, to location 0x10.)
7801 \labelwidthstring 00.00.0000
7808 \begin_layout Standard
7820 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7825 <Value> The start location of the indirectly addressable internal ram
7826 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7830 of the 8051, default value is 0x80.
7831 The value entered can be in Hexadecimal or Decimal format, eg.
7836 \begin_layout Standard
7845 -idata-loc 0x88 or -
7849 \begin_layout Standard
7862 \labelwidthstring 00.00.0000
7869 \begin_layout Standard
7881 <Value> The start location of the bit
7882 \begin_inset LatexCommand \index{bit}
7886 addressable internal ram of the 8051.
7892 Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7897 \labelwidthstring 00.00.0000
7904 \begin_layout Standard
7914 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7923 The linker output (final object code) is in Intel Hex format.
7924 \begin_inset LatexCommand \index{Intel hex format}
7928 This is the default option.
7929 The format itself is documented in the documentation of srecord
7930 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7938 \labelwidthstring 00.00.0000
7945 \begin_layout Standard
7955 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7964 The linker output (final object code) is in Motorola S19 format
7965 \begin_inset LatexCommand \index{Motorola S19 format}
7970 The format itself is documented in the documentation of srecord.
7974 \labelwidthstring 00.00.0000
7981 \begin_layout Standard
7991 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7996 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
8005 The linker output (final object code) is in ELF format
8006 \begin_inset LatexCommand \index{ELF format}
8011 (Currently only supported for the HC08
8012 \begin_inset LatexCommand \index{HC08}
8020 \labelwidthstring 00.00.0000
8024 linkOption[,linkOption]
8027 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
8031 \begin_inset LatexCommand \label{lyx:-Wl option}
8036 Pass the linkOption to the linker.
8037 If a bootloader is used an option like
8038 \begin_inset Quotes sld
8043 \begin_inset Quotes srd
8046 would be typical to set the start of the code segment.
8047 Either use the double quotes around this option or use no space (e.g.
8049 See also #pragma constseg and #pragma codeseg in section
8050 \begin_inset LatexCommand \ref{sec:Pragmas}
8055 File sdcc/as/doc/asxhtm.html has more on linker options.
8058 \begin_layout Standard
8059 \begin_inset VSpace bigskip
8065 \begin_layout Subsection
8067 \begin_inset LatexCommand \index{Options MCS51}
8072 \begin_inset LatexCommand \index{MCS51 options}
8080 \labelwidthstring 00.00.0000
8087 \begin_layout Standard
8097 \begin_inset LatexCommand \index{-\/-model-small}
8108 Generate code for Small Model programs, see section Memory Models for more
8110 This is the default model.
8114 \labelwidthstring 00.00.0000
8121 \begin_layout Standard
8131 \begin_inset LatexCommand \index{-\/-model-medium}
8137 Generate code for Medium model programs, see section Memory Models for
8139 If this option is used all source files in the project have to be compiled
8141 It must also be used when invoking the linker.
8145 \labelwidthstring 00.00.0000
8152 \begin_layout Standard
8162 \begin_inset LatexCommand \index{-\/-model-large}
8168 Generate code for Large model programs, see section Memory Models for more
8170 If this option is used all source files in the project have to be compiled
8172 It must also be used when invoking the linker.
8176 \labelwidthstring 00.00.0000
8183 \begin_layout Standard
8193 \begin_inset LatexCommand \index{-\/-xstack}
8199 Uses a pseudo stack in the pdata
8200 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8204 area (usually the first 256 bytes in the external ram) for allocating variables
8205 and passing parameters.
8207 \begin_inset LatexCommand \ref{sub:External-Stack}
8212 External Stack for more details.
8216 \labelwidthstring 00.00.0000
8223 \begin_layout Standard
8236 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
8240 Causes the linker to check if the internal ram usage is within limits of
8245 \labelwidthstring 00.00.0000
8252 \begin_layout Standard
8265 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
8269 Causes the linker to check if the external ram usage is within limits of
8274 \labelwidthstring 00.00.0000
8281 \begin_layout Standard
8294 \begin_inset LatexCommand \index{-\/-code-size <Value>}
8298 Causes the linker to check if the code memory usage is within limits of
8303 \labelwidthstring 00.00.0000
8310 \begin_layout Standard
8323 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8327 Causes the linker to check if there is at minimum <Value> bytes for stack.
8331 \labelwidthstring 00.00.0000
8338 \begin_layout Standard
8351 \begin_inset LatexCommand \index{-\/-pack-iram}
8355 Causes the linker to use unused register banks for data variables and pack
8356 data, idata and stack together.
8357 This is the default now.
8361 \labelwidthstring 00.00.0000
8368 \begin_layout Standard
8381 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8385 Causes the linker to use old style for allocating memory areas.
8389 \labelwidthstring 00.00.0000
8396 \begin_layout Standard
8409 \begin_inset LatexCommand \index{-\/-acall-ajmp}
8413 Replaces the three byte instructions lcall/ljmp with the two byte instructions
8415 Only use this option if your code is in the same 2k block of memory.
8416 You may need to use this option for some 8051 derivatives which lack the
8417 lcall/ljmp instructions..
8420 \begin_layout Standard
8421 \begin_inset VSpace bigskip
8427 \begin_layout Subsection
8428 DS390 / DS400 Options
8429 \begin_inset LatexCommand \index{Options DS390}
8434 \begin_inset LatexCommand \index{DS390}
8442 \labelwidthstring 00.00.0000
8449 \begin_layout Standard
8461 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8471 Generate 24-bit flat mode code.
8472 This is the one and only that the ds390 code generator supports right now
8473 and is default when using
8478 See section Memory Models for more details.
8482 \labelwidthstring 00.00.0000
8489 \begin_layout Standard
8499 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8505 disable interrupts during ESP:SP updates.
8509 \labelwidthstring 00.00.0000
8516 \begin_layout Standard
8528 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8532 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8533 This is the one and only that the ds390 code generator supports right now
8534 and is default when using
8539 In this mode, the stack is located in the lower 1K of the internal RAM,
8540 which is mapped to 0x400000.
8541 Note that the support is incomplete, since it still uses a single byte
8542 as the stack pointer.
8543 This means that only the lower 256 bytes of the potential 1K stack space
8544 will actually be used.
8545 However, this does allow you to reclaim the precious 256 bytes of low RAM
8546 for use for the DATA and IDATA segments.
8547 The compiler will not generate any code to put the processor into 10 bit
8549 It is important to ensure that the processor is in this mode before calling
8550 any re-entrant functions compiled with this option.
8551 In principle, this should work with the
8557 \begin_layout Standard
8567 \begin_inset LatexCommand \index{-\/-stack-auto}
8573 option, but that has not been tested.
8574 It is incompatible with the
8580 \begin_layout Standard
8590 \begin_inset LatexCommand \index{-\/-xstack}
8597 It also only makes sense if the processor is in 24 bit contiguous addressing
8604 \begin_layout Standard
8613 -model-flat24 option
8618 \begin_inset Note Note
8622 \labelwidthstring 00.00.0000
8629 \begin_layout Standard
8638 -stack-8-bit - switches off the 10-bit mode
8647 \labelwidthstring 00.00.0000
8654 \begin_layout Standard
8664 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8670 insert call to function __stack_probe at each function prologue.
8674 \labelwidthstring 00.00.0000
8681 \begin_layout Standard
8691 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8697 <nnnn> LibraryID used in -mTININative.
8702 \labelwidthstring 00.00.0000
8709 \begin_layout Standard
8719 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8725 generate code for DS390 Arithmetic Accelerator.
8729 \begin_layout Standard
8730 \begin_inset VSpace bigskip
8736 \begin_layout Subsection
8738 \begin_inset LatexCommand \index{Options Z80}
8743 \begin_inset LatexCommand \index{Z80}
8751 \labelwidthstring 00.00.0000
8758 \begin_layout Standard
8770 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8780 Force a called function to always save BC.
8784 \labelwidthstring 00.00.0000
8791 \begin_layout Standard
8803 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8807 When linking, skip the standard crt0.o object file.
8808 You must provide your own crt0.o for your system when linking.
8812 \labelwidthstring 00.00.0000
8819 \begin_layout Standard
8831 \begin_inset LatexCommand \index{Z80!Options!-\/-portmode=<Value>}
8835 Determinate PORT I/O mode (<Value> is z80 or z180).
8839 \labelwidthstring 00.00.0000
8846 \begin_layout Standard
8858 \begin_inset LatexCommand \index{Z80!Options!-\/-asm=<Value>}
8862 Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
8866 \labelwidthstring 00.00.0000
8873 \begin_layout Standard
8886 \begin_inset LatexCommand \index{Z80!Options!-\/-codeseg <Value>}
8890 Use <Value> for the code segment name.
8894 \labelwidthstring 00.00.0000
8901 \begin_layout Standard
8914 \begin_inset LatexCommand \index{Z80!Options!-\/-constseg <Value>}
8918 Use <Value> for the const segment name.
8922 \labelwidthstring 00.00.0000
8923 \begin_inset VSpace bigskip
8929 \begin_layout Subsection
8931 \begin_inset LatexCommand \index{Options GBZ80}
8936 \begin_inset LatexCommand \index{GBZ80}
8944 \labelwidthstring 00.00.0000
8951 \begin_layout Standard
8963 \begin_inset LatexCommand \index{GBZ80!Options!-\/-callee-saves-bc}
8973 Force a called function to always save BC.
8977 \labelwidthstring 00.00.0000
8984 \begin_layout Standard
8996 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
9000 When linking, skip the standard crt0.o object file.
9001 You must provide your own crt0.o for your system when linking.
9005 \labelwidthstring 00.00.0000
9012 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
9016 Use code bank <Num>.
9020 \labelwidthstring 00.00.0000
9027 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
9031 Use data bank <Num>.
9035 \labelwidthstring 00.00.0000
9042 \begin_layout Standard
9055 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
9059 Use <Value> for the code segment name.
9063 \labelwidthstring 00.00.0000
9070 \begin_layout Standard
9083 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
9087 Use <Value> for the const segment name.
9090 \begin_layout Standard
9091 \begin_inset VSpace bigskip
9097 \begin_layout Subsection
9098 Optimization Options
9099 \begin_inset LatexCommand \index{Options optimization}
9104 \begin_inset LatexCommand \index{Optimization options}
9112 \labelwidthstring 00.00.0000
9119 \begin_layout Standard
9129 \begin_inset LatexCommand \index{-\/-nogcse}
9135 Will not do global subexpression elimination, this option may be used when
9136 the compiler creates undesirably large stack/data spaces to store compiler
9146 \begin_inset LatexCommand \index{sloc (spill location)}
9151 A warning message will be generated when this happens and the compiler
9152 will indicate the number of extra bytes it allocated.
9153 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9155 \begin_inset LatexCommand \index{\#pragma nogcse}
9159 can be used to turn off global subexpression elimination
9160 \begin_inset LatexCommand \index{Subexpression elimination}
9164 for a given function only.
9168 \labelwidthstring 00.00.0000
9175 \begin_layout Standard
9185 \begin_inset LatexCommand \index{-\/-noinvariant}
9191 Will not do loop invariant optimizations, this may be turned off for reasons
9192 explained for the previous option.
9193 For more details of loop optimizations performed see Loop Invariants in
9195 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
9200 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9202 \begin_inset LatexCommand \index{\#pragma noinvariant}
9206 can be used to turn off invariant optimizations for a given function only.
9210 \labelwidthstring 00.00.0000
9217 \begin_layout Standard
9227 \begin_inset LatexCommand \index{-\/-noinduction}
9233 Will not do loop induction optimizations, see section strength reduction
9235 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9237 \begin_inset LatexCommand \index{\#pragma noinduction}
9241 can be used to turn off induction optimizations for a given function only.
9245 \labelwidthstring 00.00.0000
9252 \begin_layout Standard
9262 \begin_inset LatexCommand \index{-\/-nojtbound}
9273 Will not generate boundary condition check when switch statements
9274 \begin_inset LatexCommand \index{switch statement}
9278 are implemented using jump-tables.
9280 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
9285 Switch Statements for more details.
9286 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9288 \begin_inset LatexCommand \index{\#pragma nojtbound}
9292 can be used to turn off boundary checking for jump tables for a given function
9297 \labelwidthstring 00.00.0000
9304 \begin_layout Standard
9314 \begin_inset LatexCommand \index{-\/-noloopreverse}
9323 Will not do loop reversal
9324 \begin_inset LatexCommand \index{Loop reversing}
9332 \labelwidthstring 00.00.0000
9337 \begin_layout Standard
9351 \begin_inset LatexCommand \index{-\/-nolabelopt }
9355 Will not optimize labels (makes the dumpfiles more readable).
9359 \labelwidthstring 00.00.0000
9366 \begin_layout Standard
9376 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9382 Will not memcpy initialized data from code space into xdata space.
9383 This saves a few bytes in code space if you don't have initialized data
9384 \begin_inset LatexCommand \index{Variable initialization}
9392 \labelwidthstring 00.00.0000
9399 \begin_layout Standard
9409 \begin_inset LatexCommand \index{-\/-nooverlay}
9415 The compiler will not overlay parameters and local variables of any function,
9416 see section Parameters and local variables for more details.
9420 \labelwidthstring 00.00.0000
9427 \begin_layout Standard
9437 \begin_inset LatexCommand \index{-\/-no-peep}
9443 Disable peep-hole optimization with built-in rules.
9447 \labelwidthstring 00.00.0000
9454 \begin_layout Standard
9466 \begin_inset LatexCommand \index{-\/-peep-file}
9471 <filename> This option can be used to use additional rules to be used by
9472 the peep hole optimizer.
9474 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9479 Peep Hole optimizations for details on how to write these rules.
9483 \labelwidthstring 00.00.0000
9490 \begin_layout Standard
9500 \begin_inset LatexCommand \index{-\/-peep-asm}
9506 Pass the inline assembler code through the peep hole optimizer.
9507 This can cause unexpected changes to inline assembler code, please go through
9508 the peephole optimizer
9509 \begin_inset LatexCommand \index{Peephole optimizer}
9513 rules defined in the source file tree '<target>/peeph.def' before using
9518 \labelwidthstring 00.00.0000
9525 \begin_layout Standard
9535 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9541 The compiler will optimize code generation towards fast code, possibly
9542 at the expense of code size.
9546 \labelwidthstring 00.00.0000
9553 \begin_layout Standard
9563 \begin_inset LatexCommand \index{-\/-opt-code-size}
9569 The compiler will optimize code generation towards compact code, possibly
9570 at the expense of code speed.
9573 \begin_layout Standard
9574 \begin_inset VSpace bigskip
9580 \begin_layout Subsection
9582 \begin_inset LatexCommand \index{Options other}
9590 \labelwidthstring 00.00.0000
9598 \begin_layout Standard
9608 \begin_inset LatexCommand \index{-\/-compile-only}
9613 \begin_inset LatexCommand \index{-c -\/-compile-only}
9619 will compile and assemble the source, but will not call the linkage editor.
9623 \labelwidthstring 00.00.0000
9632 \begin_layout Standard
9644 \begin_inset LatexCommand \index{-\/-c1mode}
9650 reads the preprocessed source from standard input and compiles it.
9651 The file name for the assembler output must be specified using the -o option.
9655 \labelwidthstring 00.00.0000
9659 \begin_inset LatexCommand \index{-E}
9665 Run only the C preprocessor.
9666 Preprocess all the C source files specified and output the results to standard
9671 \labelwidthstring 00.00.0000
9676 \begin_inset LatexCommand \index{-o <path/file>}
9682 The output path where everything will be placed or the file name used for
9683 all generated output files.
9684 If the parameter is a path, it must have a trailing slash (or backslash
9685 for the Windows binaries) to be recognized as a path.
9690 Note for Windows users: if the path contains spaces, it should be surrounded
9692 The trailing backslash should be doubled in order to prevent escaping the
9693 final quote, for example:
9696 \begin_inset Quotes sld
9710 \begin_inset Quotes srd
9715 or put after the final quote, for example:
9718 \begin_inset Quotes sld
9728 \begin_inset Quotes srd
9736 The path using slashes for directory delimiters can be used too, for example:
9740 \begin_inset Quotes sld
9743 F:/Projects/test3/output 1/
9744 \begin_inset Quotes srd
9753 \labelwidthstring 00.00.0000
9760 \begin_layout Standard
9770 \begin_inset LatexCommand \index{-\/-stack-auto}
9781 All functions in the source file will be compiled as
9786 \begin_inset LatexCommand \index{reentrant}
9791 the parameters and local variables will be allocated on the stack
9792 \begin_inset LatexCommand \index{stack}
9798 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9802 Parameters and Local Variables for more details.
9803 If this option is used all source files in the project should be compiled
9805 It automatically implies -
9811 \begin_layout Standard
9822 -int-long-reent and -
9828 \begin_layout Standard
9844 \labelwidthstring 00.00.0000
9851 \begin_layout Standard
9861 \begin_inset LatexCommand \index{-\/-callee-saves}
9866 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9870 function1[,function2][,function3]....
9873 The compiler by default uses a caller saves convention for register saving
9874 across function calls, however this can cause unnecessary register pushing
9875 and popping when calling small functions from larger functions.
9876 This option can be used to switch the register saving convention for the
9877 function names specified.
9878 The compiler will not save registers when calling these functions, no extra
9879 code will be generated at the entry and exit (function prologue
9882 \begin_inset LatexCommand \index{function prologue}
9891 \begin_inset LatexCommand \index{function epilogue}
9897 ) for these functions to save and restore the registers used by these functions,
9898 this can SUBSTANTIALLY reduce code and improve run time performance of
9900 In the future the compiler (with inter procedural analysis) will be able
9901 to determine the appropriate scheme to use for each function call.
9902 DO NOT use this option for built-in functions such as _mulint..., if this
9903 option is used for a library function the appropriate library function
9904 needs to be recompiled with the same option.
9905 If the project consists of multiple source files then all the source file
9906 should be compiled with the same -
9910 \begin_layout Standard
9919 -callee-saves option string.
9920 Also see #pragma\InsetSpace ~
9922 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9927 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9935 \labelwidthstring 00.00.0000
9942 \begin_layout Standard
9952 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9966 \begin_layout Standard
9975 -callee-saves will be applied to all functions by default.
9979 \labelwidthstring 00.00.0000
9986 \begin_layout Standard
9996 \begin_inset LatexCommand \index{-\/-debug}
10005 When this option is used the compiler will generate debug information.
10006 The debug information collected in a file with .cdb extension can be used
10008 For more information see documentation for SDCDB.
10009 Another file with no extension contains debug information in AOMF or AOMF51
10010 \begin_inset LatexCommand \index{AOMF, AOMF51}
10014 format which is commonly used by third party tools.
10018 \labelwidthstring 00.00.0000
10022 \begin_inset LatexCommand \index{-S}
10033 Stop after the stage of compilation proper; do not assemble.
10034 The output is an assembler code file for the input file specified.
10038 \labelwidthstring 00.00.0000
10045 \begin_layout Standard
10055 \begin_inset LatexCommand \index{-\/-int-long-reent}
10061 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
10062 Note by default these libraries are compiled as non-reentrant.
10063 See section Installation for more details.
10067 \labelwidthstring 00.00.0000
10074 \begin_layout Standard
10084 \begin_inset LatexCommand \index{-\/-cyclomatic}
10093 This option will cause the compiler to generate an information message for
10094 each function in the source file.
10095 The message contains some
10099 information about the function.
10100 The number of edges and nodes the compiler detected in the control flow
10101 graph of the function, and most importantly the
10103 cyclomatic complexity
10104 \begin_inset LatexCommand \index{Cyclomatic complexity}
10110 see section on Cyclomatic Complexity for more details.
10114 \labelwidthstring 00.00.0000
10121 \begin_layout Standard
10131 \begin_inset LatexCommand \index{-\/-float-reent}
10137 Floating point library is compiled as reentrant
10138 \begin_inset LatexCommand \index{reentrant}
10143 See section Installation for more details.
10147 \labelwidthstring 00.00.0000
10154 \begin_layout Standard
10164 \begin_inset LatexCommand \index{-\/-funsigned-char}
10170 The default signedness for every type is
10175 In some embedded environments the default signedness of
10184 To set the signess for characters to unsigned, use the option -
10190 \begin_layout Standard
10202 If this option is set and no signedness keyword (unsigned/signed) is given,
10203 a char will be signed.
10204 All other types are unaffected.
10208 \labelwidthstring 00.00.0000
10215 \begin_layout Standard
10225 \begin_inset LatexCommand \index{-\/-main-return}
10231 This option can be used if the code generated is called by a monitor program
10232 or if the main routine includes an endless loop.
10233 This option results in slightly smaller code and saves two bytes of stack
10235 The return from the 'main'
10236 \begin_inset LatexCommand \index{main return}
10240 function will return to the function calling main.
10241 The default setting is to lock up i.e.
10250 \labelwidthstring 00.00.0000
10257 \begin_layout Standard
10267 \begin_inset LatexCommand \index{-\/-nostdinc}
10273 This will prevent the compiler from passing on the default include path
10274 to the preprocessor.
10278 \labelwidthstring 00.00.0000
10285 \begin_layout Standard
10295 \begin_inset LatexCommand \index{-\/-nostdlib}
10301 This will prevent the compiler from passing on the default library
10302 \begin_inset LatexCommand \index{Libraries}
10306 path to the linker.
10310 \labelwidthstring 00.00.0000
10317 \begin_layout Standard
10327 \begin_inset LatexCommand \index{-\/-verbose}
10333 Shows the various actions the compiler is performing.
10337 \labelwidthstring 00.00.0000
10341 \begin_inset LatexCommand \index{-V}
10347 Shows the actual commands the compiler is executing.
10351 \labelwidthstring 00.00.0000
10358 \begin_layout Standard
10368 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
10374 Hides your ugly and inefficient c-code from the asm file, so you can always
10375 blame the compiler :)
10379 \labelwidthstring 00.00.0000
10386 \begin_layout Standard
10396 \begin_inset LatexCommand \index{-\/-no-gen-comments}
10402 Include code generator and peep-hole comments in the generated asm files.
10406 \labelwidthstring 00.00.0000
10413 \begin_layout Standard
10423 \begin_inset LatexCommand \index{-\/-no-peep-comments}
10429 Don't include peep-hole comments in the generated asm files even if -
10435 \begin_layout Standard
10446 -fverbose-asm option is specified.
10450 \labelwidthstring 00.00.0000
10457 \begin_layout Standard
10467 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10473 Include i-codes in the asm file.
10474 Sounds like noise but is most helpful for debugging the compiler itself.
10478 \labelwidthstring 00.00.0000
10485 \begin_layout Standard
10495 \begin_inset LatexCommand \index{pedantic}
10500 \begin_inset LatexCommand \index{-\/-less-pedantic}
10507 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10511 Disable some of the more pedantic warnings
10512 \begin_inset LatexCommand \index{Warnings}
10517 For more details, see the less_pedantic pragma
10518 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10526 \labelwidthstring 00.00.0000
10533 \begin_layout Standard
10542 -disable-warning\InsetSpace ~
10544 \begin_inset LatexCommand \index{-\/-disable-warning}
10550 Disable specific warning with number <nnnn>.
10554 \labelwidthstring 00.00.0000
10561 \begin_layout Standard
10571 \begin_inset LatexCommand \index{-\/-Werror}
10577 Treat all warnings as errors.
10581 \labelwidthstring 00.00.0000
10588 \begin_layout Standard
10598 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10604 Display the directories in the compiler's search path
10608 \labelwidthstring 00.00.0000
10615 \begin_layout Standard
10625 \begin_inset LatexCommand \index{-\/-vc}
10631 Display errors and warnings using MSVC style, so you can use SDCC with
10632 the visual studio IDE
10633 \begin_inset LatexCommand \index{IDE}
10638 With SDCC both offering a GCC-like (the default) and a MSVC-like
10639 \begin_inset LatexCommand \index{MSVC output style}
10643 output style, integration into most programming editors should be straightforwa
10648 \labelwidthstring 00.00.0000
10655 \begin_layout Standard
10665 \begin_inset LatexCommand \index{-\/-use-stdout}
10671 Send errors and warnings to stdout instead of stderr.
10675 \labelwidthstring 00.00.0000
10679 asmOption[,asmOption]
10682 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10687 Pass the asmOption to the assembler
10688 \begin_inset LatexCommand \index{Options assembler}
10693 \begin_inset LatexCommand \index{Assembler options}
10698 See file sdcc/as/doc/asxhtm.html for assembler options.cd
10702 \labelwidthstring 00.00.0000
10709 \begin_layout Standard
10719 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10725 Generally follow the C89 standard, but allow SDCC features that conflict
10726 with the standard (default).
10730 \labelwidthstring 00.00.0000
10737 \begin_layout Standard
10747 \begin_inset LatexCommand \index{-\/-std-c89}
10753 Follow the C89 standard and disable SDCC features that conflict with the
10758 \labelwidthstring 00.00.0000
10765 \begin_layout Standard
10775 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10781 Generally follow the C99 standard, but allow SDCC features that conflict
10782 with the standard (incomplete support).
10786 \labelwidthstring 00.00.0000
10793 \begin_layout Standard
10803 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10809 Follow the C99 standard and disable SDCC features that conflict with the
10810 standard (incomplete support).
10814 \labelwidthstring 00.00.0000
10821 \begin_layout Standard
10833 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10837 \begin_inset LatexCommand \label{lyx:-codeseg}
10842 <Name> The name to be used for the code
10843 \begin_inset LatexCommand \index{code}
10847 segment, default CSEG.
10848 This is useful if you need to tell the compiler to put the code in a special
10849 segment so you can later on tell the linker to put this segment in a special
10851 Can be used for instance when using bank switching to put the code in a
10856 \labelwidthstring 00.00.0000
10863 \begin_layout Standard
10875 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10880 <Name> The name to be used for the const
10881 \begin_inset LatexCommand \index{const}
10885 segment, default CONST.
10886 This is useful if you need to tell the compiler to put the const data in
10887 a special segment so you can later on tell the linker to put this segment
10888 in a special place in memory.
10889 Can be used for instance when using bank switching to put the const data
10894 \labelwidthstring 00.00.0000
10901 \begin_layout Standard
10910 -fdollars-in-identifiers
10911 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10917 Permit '$' as an identifier character.
10921 \labelwidthstring 00.00.0000
10928 \begin_layout Standard
10940 \begin_inset LatexCommand \index{-\/-more-pedantic}
10945 \begin_inset LatexCommand \index{pedantic}
10955 a SDCC compiler option but if you want
10959 warnings you can use a separate tool dedicated to syntax checking like
10961 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10966 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10971 \begin_inset LatexCommand \url{http://www.splint.org}
10976 To make your source files parseable by splint you will have to include
10982 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10986 in your source file and add brackets around extended keywords (like
10989 \begin_inset Quotes sld
11002 \begin_inset Quotes srd
11010 \begin_inset Quotes sld
11013 __interrupt\InsetSpace ~
11015 \begin_inset Quotes srd
11023 Splint has an excellent on line manual at
11024 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
11028 and it's capabilities go beyond pure syntax checking.
11029 You'll need to tell splint the location of SDCC's include files so a typical
11030 command line could look like this:
11034 splint\InsetSpace ~
11036 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
11042 \labelwidthstring 00.00.0000
11049 \begin_layout Standard
11061 \begin_inset LatexCommand \index{-\/-short-is-8bits}
11066 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
11070 Treat short as 8-bit (for backward compatibility with older versions of
11071 compiler - see section
11072 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
11079 \begin_layout Standard
11080 \begin_inset VSpace bigskip
11086 \begin_layout Subsection
11087 Intermediate Dump Options
11088 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
11093 \begin_inset LatexCommand \index{Options intermediate dump}
11098 \begin_inset LatexCommand \index{Intermediate dump options}
11105 \begin_layout Standard
11106 The following options are provided for the purpose of retargetting and debugging
11108 They provide a means to dump the intermediate code (iCode
11109 \begin_inset LatexCommand \index{iCode}
11113 ) generated by the compiler in human readable form at various stages of
11114 the compilation process.
11115 More on iCodes see chapter
11116 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
11121 \begin_inset Quotes srd
11124 The anatomy of the compiler
11125 \begin_inset Quotes srd
11132 \labelwidthstring 00.00.0000
11139 \begin_layout Standard
11149 \begin_inset LatexCommand \index{-\/-dumpraw}
11155 This option will cause the compiler to dump the intermediate code into
11158 <source filename>.dumpraw
11160 just after the intermediate code has been generated for a function, i.e.
11161 before any optimizations are done.
11163 \begin_inset LatexCommand \index{Basic blocks}
11167 at this stage ordered in the depth first number, so they may not be in
11168 sequence of execution.
11172 \labelwidthstring 00.00.0000
11179 \begin_layout Standard
11189 \begin_inset LatexCommand \index{-\/-dumpgcse}
11195 Will create a dump of iCodes, after global subexpression elimination
11196 \begin_inset LatexCommand \index{Global subexpression elimination}
11200 , into a file named
11202 <source filename>.dumpgcse.
11206 \labelwidthstring 00.00.0000
11213 \begin_layout Standard
11223 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
11229 Will create a dump of iCodes, after deadcode elimination
11230 \begin_inset LatexCommand \index{Dead-code elimination}
11234 , into a file named
11236 <source filename>.dumpdeadcode.
11240 \labelwidthstring 00.00.0000
11247 \begin_layout Standard
11257 \begin_inset LatexCommand \index{-\/-dumploop}
11266 Will create a dump of iCodes, after loop optimizations
11267 \begin_inset LatexCommand \index{Loop optimization}
11271 , into a file named
11273 <source filename>.dumploop.
11277 \labelwidthstring 00.00.0000
11284 \begin_layout Standard
11294 \begin_inset LatexCommand \index{-\/-dumprange}
11303 Will create a dump of iCodes, after live range analysis
11304 \begin_inset LatexCommand \index{Live range analysis}
11308 , into a file named
11310 <source filename>.dumprange.
11314 \labelwidthstring 00.00.0000
11321 \begin_layout Standard
11331 \begin_inset LatexCommand \index{-\/-dumlrange}
11337 Will dump the life ranges
11338 \begin_inset LatexCommand \index{Live range analysis}
11346 \labelwidthstring 00.00.0000
11353 \begin_layout Standard
11363 \begin_inset LatexCommand \index{-\/-dumpregassign}
11372 Will create a dump of iCodes, after register assignment
11373 \begin_inset LatexCommand \index{Register assignment}
11377 , into a file named
11379 <source filename>.dumprassgn.
11383 \labelwidthstring 00.00.0000
11390 \begin_layout Standard
11400 \begin_inset LatexCommand \index{-\/-dumplrange}
11406 Will create a dump of the live ranges of iTemp's
11410 \labelwidthstring 00.00.0000
11417 \begin_layout Standard
11427 \begin_inset LatexCommand \index{-\/-dumpall}
11438 Will cause all the above mentioned dumps to be created.
11441 \begin_layout Standard
11442 \begin_inset VSpace bigskip
11448 \begin_layout Subsection
11449 Redirecting output on Windows Shells
11452 \begin_layout Standard
11453 By default SDCC writes its error messages to
11454 \begin_inset Quotes sld
11458 \begin_inset Quotes srd
11462 To force all messages to
11463 \begin_inset Quotes sld
11467 \begin_inset Quotes srd
11479 \begin_layout Standard
11494 \begin_inset LatexCommand \index{-\/-use-stdout}
11499 Additionally, if you happen to have visual studio installed in your windows
11500 machine, you can use it to compile your sources using a custom build and
11507 \begin_layout Standard
11519 \begin_inset LatexCommand \index{-\/-vc}
11524 Something like this should work:
11543 \begin_layout Standard
11562 \begin_layout Standard
11574 -model-large -c $(InputPath)
11577 \begin_inset VSpace bigskip
11583 \begin_layout Section
11584 Environment variables
11585 \begin_inset LatexCommand \index{Environment variables}
11592 \begin_layout Standard
11593 SDCC recognizes the following environment variables:
11597 \labelwidthstring 00.00.0000
11601 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11607 SDCC installs a signal handler
11608 \begin_inset LatexCommand \index{signal handler}
11612 to be able to delete temporary files after an user break (^C) or an exception.
11613 If this environment variable is set, SDCC won't install the signal handler
11614 in order to be able to debug SDCC.
11618 \labelwidthstring 00.00.0000
11624 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11630 Path, where temporary files will be created.
11631 The order of the variables is the search order.
11632 In a standard *nix environment these variables are not set, and there's
11633 no need to set them.
11634 On Windows it's recommended to set one of them.
11638 \labelwidthstring 00.00.0000
11642 \begin_inset LatexCommand \index{SDCC\_HOME}
11649 \begin_inset LatexCommand \ref{sub:Install-paths}
11655 \begin_inset Quotes sld
11659 \begin_inset Quotes srd
11666 \labelwidthstring 00.00.0000
11670 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11677 \begin_inset LatexCommand \ref{sub:Search-Paths}
11683 \begin_inset Quotes sld
11687 \begin_inset Quotes srd
11694 \labelwidthstring 00.00.0000
11698 \begin_inset LatexCommand \index{SDCC\_LIB}
11705 \begin_inset LatexCommand \ref{sub:Search-Paths}
11711 \begin_inset Quotes sld
11715 \begin_inset Quotes srd
11721 \begin_layout Standard
11722 There are some more environment variables recognized by SDCC, but these
11723 are solely used for debugging purposes.
11724 They can change or disappear very quickly, and will never be documented.
11725 \begin_inset VSpace bigskip
11731 \begin_layout Section
11732 Storage Class Language Extensions
11735 \begin_layout Subsection
11736 MCS51/DS390 Storage Class
11737 \begin_inset LatexCommand \index{Storage class}
11741 Language Extensions
11744 \begin_layout Standard
11745 In addition to the ANSI storage classes SDCC allows the following MCS51
11746 specific storage classes:
11749 \begin_layout Subsubsection
11751 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11756 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11761 \begin_inset LatexCommand \index{near (storage class)}
11766 \begin_inset LatexCommand \index{\_\_near (storage class)}
11773 \begin_layout Standard
11778 storage class for the Small Memory model (
11786 or the more ANSI-C compliant forms
11794 can be used synonymously).
11795 Variables declared with this storage class will be allocated in the directly
11796 addressable portion of the internal RAM of a 8051, e.g.:
11799 \begin_layout Verse
11802 __data unsigned char test_data;
11805 \begin_layout Standard
11806 Writing 0x01 to this variable generates the assembly code:
11809 \begin_layout Verse
11812 75*00 01\InsetSpace ~
11820 \begin_layout Subsubsection
11822 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11827 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11832 \begin_inset LatexCommand \index{far (storage class)}
11837 \begin_inset LatexCommand \index{\_\_far (storage class)}
11844 \begin_layout Standard
11845 Variables declared with this storage class will be placed in the external
11851 storage class for the Large Memory model, e.g.:
11854 \begin_layout Verse
11857 __xdata unsigned char test_xdata;
11860 \begin_layout Standard
11861 Writing 0x01 to this variable generates the assembly code:
11864 \begin_layout Verse
11867 90s00r00\InsetSpace ~
11898 \begin_layout Subsubsection
11900 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11905 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11912 \begin_layout Standard
11913 Variables declared with this storage class will be allocated into the indirectly
11914 addressable portion of the internal ram of a 8051, e.g.:
11917 \begin_layout Verse
11920 __idata unsigned char test_idata;
11923 \begin_layout Standard
11924 Writing 0x01 to this variable generates the assembly code:
11927 \begin_layout Verse
11954 \begin_layout Standard
11955 Please note, the first 128 byte of idata physically access the same RAM
11956 as the data memory.
11957 The original 8051 had 128 byte idata memory, nowadays most devices have
11958 256 byte idata memory.
11960 \begin_inset LatexCommand \index{stack}
11964 is located in idata memory.
11967 \begin_layout Subsubsection
11969 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11974 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11981 \begin_layout Standard
11982 Paged xdata access is just as straightforward as using the other addressing
11984 It is typically located at the start of xdata and has a maximum size of
11986 The following example writes 0x01 to the pdata variable.
11987 Please note, pdata access physically accesses xdata memory.
11988 The high byte of the address is determined by port P2
11989 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11993 (or in case of some 8051 variants by a separate Special Function Register,
11995 \begin_inset LatexCommand \ref{sub:MCS51-variants}
12004 storage class for the Medium Memory model, e.g.:
12007 \begin_layout Verse
12010 __pdata unsigned char test_pdata;
12013 \begin_layout Standard
12014 Writing 0x01 to this variable generates the assembly code:
12017 \begin_layout Verse
12026 mov r0,#_test_pdata
12048 \begin_layout Standard
12053 \begin_layout Standard
12063 \begin_inset LatexCommand \index{-\/-xstack}
12067 option is used the pdata memory area is followed by the xstack memory area
12068 and the sum of their sizes is limited to 256 bytes.
12071 \begin_layout Subsubsection
12073 \begin_inset LatexCommand \index{code}
12078 \begin_inset LatexCommand \index{\_\_code}
12085 \begin_layout Standard
12086 'Variables' declared with this storage class will be placed in the code
12090 \begin_layout Verse
12093 __code unsigned char test_code;
12096 \begin_layout Standard
12097 Read access to this variable generates the assembly code:
12100 \begin_layout Verse
12103 90s00r6F\InsetSpace ~
12106 mov dptr,#_test_code
12131 \begin_layout Standard
12136 indexed arrays of characters in code memory can be accessed efficiently:
12139 \begin_layout Verse
12142 __code char test_array[] = {'c','h','e','a','p'};
12145 \begin_layout Standard
12146 Read access to this array using an 8-bit unsigned index generates the assembly
12150 \begin_layout Verse
12162 \begin_layout Verse
12165 90s00r41\InsetSpace ~
12168 mov dptr,#_test_array
12171 \begin_layout Verse
12186 \begin_layout Subsubsection
12188 \begin_inset LatexCommand \index{bit}
12193 \begin_inset LatexCommand \index{\_\_bit}
12200 \begin_layout Standard
12201 This is a data-type and a storage class specifier.
12202 When a variable is declared as a bit, it is allocated into the bit addressable
12203 memory of 8051, e.g.:
12206 \begin_layout Verse
12212 \begin_layout Standard
12213 Writing 1 to this variable generates the assembly code:
12216 \begin_layout Verse
12230 \begin_layout Standard
12231 The bit addressable memory consists of 128 bits which are located from 0x20
12232 to 0x2f in data memory.
12235 Apart from this 8051 specific storage class most architectures support
12237 \begin_inset LatexCommand \index{bitfields}
12245 \begin_layout Standard
12246 Not really meant as examples, but nevertheless showing what bitfields are
12247 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12253 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12254 signed modifier are implemented as unsigned.
12257 \begin_layout Subsubsection
12259 \begin_inset LatexCommand \index{sfr}
12264 \begin_inset LatexCommand \index{\_\_sfr}
12269 \begin_inset LatexCommand \index{sfr16}
12274 \begin_inset LatexCommand \index{\_\_sfr16}
12279 \begin_inset LatexCommand \index{sfr32}
12284 \begin_inset LatexCommand \index{\_\_sfr32}
12289 \begin_inset LatexCommand \index{\_\_sbit}
12294 \begin_inset LatexCommand \index{sbit}
12301 \begin_layout Standard
12302 Like the bit keyword,
12304 sfr / sfr16 / sfr32 / sbit
12306 signify both a data-type and storage class, they are used to describe the
12327 variables of a 8051, eg:
12330 \begin_layout Verse
12334 \begin_inset LatexCommand \index{at}
12339 \begin_inset LatexCommand \index{\_\_at}
12343 (0x80) P0;\InsetSpace ~
12344 /* special function register P0 at location 0x80 */
12349 special function register combination for timer 0
12353 with the high byte at
12354 location 0x8C and the low byte at location 0x8A */
12356 __sfr16 __at (0x8C8A)
12362 \begin_inset LatexCommand \index{at}
12367 \begin_inset LatexCommand \index{\_\_at}
12371 (0xd7) CY;\InsetSpace ~
12373 \begin_inset LatexCommand \index{Flags}
12378 \begin_inset LatexCommand \index{Carry flag}
12385 \begin_layout Standard
12386 Special function registers which are located on an address dividable by
12387 8 are bit-addressable, an
12391 addresses a specific bit within these sfr.
12393 16 Bit and 32 bit special function
12394 register combinations which require a certain access order are better not
12404 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12405 this is not guaranteed.
12410 \begin_layout Standard
12411 Please note, if you use a header file which was written for another compiler
12412 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
12418 Specifically the syntax
12421 sfr P0 = 0x80;\InsetSpace ~
12428 by SDCC to an assignment of 0x80 to a variable called P0
12431 \begin_inset Marginal
12434 \begin_layout Standard
12446 Nevertheless it is possible to write header files
12447 \begin_inset LatexCommand \index{Header files}
12452 \begin_inset LatexCommand \index{Include files}
12456 which can be shared among different compilers (see section
12457 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
12465 \begin_layout Subsubsection
12467 \begin_inset LatexCommand \index{Pointer}
12471 to MCS51/DS390 specific memory spaces
12474 \begin_layout Standard
12475 SDCC allows (via language extensions) pointers to explicitly point to any
12476 of the memory spaces
12477 \begin_inset LatexCommand \index{Memory model}
12482 In addition to the explicit pointers, the compiler uses (by default) generic
12483 pointers which can be used to point to any of the memory spaces.
12488 declaration examples:
12491 \begin_layout Verse
12494 /* pointer physically in internal ram pointing to object in external ram
12497 __xdata unsigned char * __data p;
12501 /* pointer physically in external ram
12502 pointing to object in internal ram */
12504 __data unsigned char * __xdata p;
12509 pointer physically in code rom pointing to data in xdata space */
12512 unsigned char * __code p;
12516 /* pointer physically in code space pointing to
12517 data in code space */
12519 __code unsigned char * __code p;
12524 physically located in xdata space */
12526 unsigned char * __xdata p;
12531 pointer physically located in default memory space */
12538 the following is a function pointer
12539 \begin_inset LatexCommand \index{function pointer}
12543 physically located in data space */
12545 char (* __data fp)(void);
12548 \begin_layout Standard
12549 Well you get the idea.
12554 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
12567 The highest order byte of the
12571 pointers contains the data space information.
12572 Assembler support routines are called whenever data is stored or retrieved
12578 These are useful for developing reusable library
12579 \begin_inset LatexCommand \index{Libraries}
12584 Explicitly specifying the pointer
12585 \begin_inset LatexCommand \index{pointer}
12589 type will generate the most efficient code.
12592 \begin_layout Subsubsection
12593 Notes on MCS51 memory
12594 \begin_inset LatexCommand \index{MCS51 memory}
12601 \begin_layout Standard
12602 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12603 RAM memory which is structured as follows:
12607 - Bytes 00-1F - 32 bytes to hold
12608 up to 4 banks of the registers R0 to R7,
12610 - Bytes 20-2F - 16 bytes to hold
12612 \begin_inset LatexCommand \index{bit}
12618 - Bytes 30-7F - 80 bytes for general purpose use.
12623 \begin_layout Standard
12624 Additionally some members of the MCS51 family may have up to 128 bytes of
12625 additional, indirectly addressable, internal RAM memory (
12630 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12635 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12640 Furthermore, some chips may have some built in external memory (
12645 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12650 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12654 ) which should not be confused with the internal, directly addressable RAM
12660 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12665 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12670 Sometimes this built in
12674 memory has to be activated before using it (you can probably find this
12675 information on the datasheet of the microcontroller your are using, see
12677 \begin_inset LatexCommand \ref{sub:Startup-Code}
12685 \begin_layout Standard
12686 Normally SDCC will only use the first bank
12687 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12691 of registers (register bank 0), but it is possible to specify that other
12692 banks of registers (keyword
12699 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12704 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12710 ) should be used for example in interrupt
12711 \begin_inset LatexCommand \index{interrupt}
12716 \begin_inset LatexCommand \index{\_\_interrupt}
12721 By default, the compiler will place the stack after the last byte of allocated
12722 memory for variables.
12723 For example, if the first 2 banks of registers are used, and only four
12728 variables, it will position the base of the internal stack at address 20
12730 This implies that as the stack
12731 \begin_inset LatexCommand \index{stack}
12735 grows, it will use up the remaining register banks, and the 16 bytes used
12736 by the 128 bit variables, and 80 bytes for general purpose use.
12737 If any bit variables are used, the data variables will be placed in unused
12738 register banks and after the byte holding the last bit variable.
12739 For example, if register banks 0 and 1 are used, and there are 9 bit variables
12744 variables will be placed starting from address 0x10 to 0x20 and continue
12750 \begin_layout Standard
12760 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12764 to specify the start address of the
12772 \begin_layout Standard
12782 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12786 to specify the size of the total internal RAM (
12800 \begin_layout Standard
12801 By default the 8051 linker will place the stack after the last byte of (i)data
12807 \begin_layout Standard
12817 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12821 allows you to specify the start of the stack, i.e.
12822 you could start it after any data in the general purpose area.
12823 If your microcontroller has additional indirectly addressable internal
12828 ) you can place the stack on it.
12829 You may also need to use -
12833 \begin_layout Standard
12843 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12847 to set the start address of the external RAM (
12855 \begin_layout Standard
12865 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12869 to specify its size.
12870 Same goes for the code memory, using -
12874 \begin_layout Standard
12884 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12892 \begin_layout Standard
12902 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12907 If in doubt, don't specify any options and see if the resulting memory
12908 layout is appropriate, then you can adjust it.
12911 \begin_layout Standard
12912 The linker generates two files with memory allocation information.
12913 The first, with extension .map
12914 \begin_inset LatexCommand \index{<file>.map}
12918 shows all the variables and segments.
12919 The second with extension .mem
12920 \begin_inset LatexCommand \index{<file>.mem}
12924 shows the final memory layout.
12925 The linker will complain either if memory segments overlap, there is not
12926 enough memory, or there is not enough space for stack.
12927 If you get any linking warnings and/or errors related to stack or segments
12928 allocation, take a look at either the .map or .mem files to find out what
12930 The .mem file may even suggest a solution to the problem.
12931 \begin_inset VSpace bigskip
12937 \begin_layout Subsection
12938 Z80/Z180 Storage Class
12939 \begin_inset LatexCommand \index{Z80!Storage class}
12943 Language Extensions
12946 \begin_layout Subsubsection
12948 \begin_inset LatexCommand \index{sfr}
12953 \begin_inset LatexCommand \index{\_\_sfr}
12957 (in/out to 8-bit addresses)
12960 \begin_layout Standard
12962 \begin_inset LatexCommand \index{Z80}
12966 family has separate address spaces for memory and
12976 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12981 \begin_inset LatexCommand \index{Z80!I/O memory}
12986 \begin_inset LatexCommand \index{Z180!I/O memory}
12990 is accessed with special instructions, e.g.:
12993 \begin_layout Verse
12996 sfr at 0x78 IoPort;\InsetSpace ~
12998 /* define a var in I/O space at 78h called IoPort */
13002 \begin_layout Standard
13003 Writing 0x01 to this variable generates the assembly code:
13006 \begin_layout Verse
13026 \begin_layout Subsubsection
13028 \begin_inset LatexCommand \index{sfr}
13033 \begin_inset LatexCommand \index{\_\_sfr}
13037 (in/out to 16-bit addresses)
13040 \begin_layout Standard
13045 is used to support 16 bit addresses in I/O memory e.g.:
13048 \begin_layout Verse
13052 \begin_inset LatexCommand \index{at}
13057 \begin_inset LatexCommand \index{\_\_at}
13064 \begin_layout Standard
13065 Writing 0x01 to this variable generates the assembly code:
13068 \begin_layout Verse
13071 01 23 01\InsetSpace ~
13093 \begin_layout Subsubsection
13095 \begin_inset LatexCommand \index{sfr}
13100 \begin_inset LatexCommand \index{\_\_sfr}
13104 (in0/out0 to 8 bit addresses on Z180
13105 \begin_inset LatexCommand \index{Z180}
13110 \begin_inset LatexCommand \index{HD64180 (see Z180)}
13117 \begin_layout Standard
13118 The compiler option -
13122 \begin_layout Standard
13132 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
13136 =180 (80) and a compiler #pragma\InsetSpace ~
13138 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
13142 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
13152 If you include the file z180.h this will be set automatically.
13153 \begin_inset VSpace bigskip
13159 \begin_layout Subsection
13161 \begin_inset LatexCommand \index{HC08!Storage class}
13165 Language Extensions
13168 \begin_layout Subsubsection
13170 \begin_inset LatexCommand \index{data (hc08 storage class)}
13175 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
13182 \begin_layout Standard
13183 The data storage class declares a variable that resides in the first 256
13184 bytes of memory (the direct page).
13186 \begin_inset LatexCommand \index{HC08}
13190 is most efficient at accessing variables (especially pointers) stored here.
13193 \begin_layout Subsubsection
13195 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
13200 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
13207 \begin_layout Standard
13208 The xdata storage class declares a variable that can reside anywhere in
13210 This is the default if no storage class is specified.
13212 \begin_inset VSpace bigskip
13218 \begin_layout Section
13219 Absolute Addressing
13220 \begin_inset LatexCommand \index{Absolute addressing}
13227 \begin_layout Standard
13228 Data items can be assigned an absolute address with the
13231 \begin_inset LatexCommand \index{at}
13236 \begin_inset LatexCommand \index{\_\_at}
13242 keyword, in addition to a storage class, e.g.:
13245 \begin_layout Verse
13249 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13254 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
13259 \begin_inset LatexCommand \index{at}
13264 \begin_inset LatexCommand \index{\_\_at}
13268 0x7ffe unsigned int chksum;
13271 \begin_layout Standard
13272 or, better conforming to ISO/IEC 9899 C:
13275 \begin_layout Verse
13278 __xdata __at (0x7ffe) unsigned int chksum;
13281 \begin_layout Standard
13282 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
13283 of the external ram.
13288 reserve any space for variables declared in this way
13289 \begin_inset Marginal
13292 \begin_layout Standard
13301 (they are implemented with an equate in the assembler).
13302 Thus it is left to the programmer to make sure there are no overlaps with
13303 other variables that are declared without the absolute address.
13304 The assembler listing file (.lst
13305 \begin_inset LatexCommand \index{<file>.lst}
13309 ) and the linker output files (.rst
13310 \begin_inset LatexCommand \index{<file>.rst}
13315 \begin_inset LatexCommand \index{<file>.map}
13319 ) are good places to look for such overlaps.
13322 \begin_layout Standard
13323 If however you provide an initializer
13324 \begin_inset LatexCommand \index{Variable initialization}
13328 actual memory allocation will take place and overlaps will be detected
13333 \begin_layout Verse
13336 __code __at (0x7ff0) char Id[5] =
13337 \begin_inset Quotes sld
13341 \begin_inset Quotes srd
13347 \begin_layout Standard
13348 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
13352 \begin_layout Standard
13353 In case of memory mapped I/O devices the keyword
13357 has to be used to tell the compiler that accesses might not be removed:
13360 \begin_layout Verse
13364 \begin_inset LatexCommand \index{volatile}
13369 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13374 \begin_inset LatexCommand \index{at}
13378 (0x8000) unsigned char PORTA_8255;
13381 \begin_layout Standard
13382 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
13387 \begin_inset LatexCommand \index{Aligned array}
13394 starts at a block (256 byte) boundary
13395 \begin_inset LatexCommand \index{block boundary}
13400 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13406 Absolute addresses can be specified for variables in all
13407 storage classes, e.g.:
13410 \begin_layout Verse
13414 \begin_inset LatexCommand \index{bit}
13419 \begin_inset LatexCommand \index{at}
13426 \begin_layout Standard
13427 The above example will allocate the variable at offset 0x02 in the bit-addressab
13429 There is no real advantage to assigning absolute addresses to variables
13430 in this manner, unless you want strict control over all the variables allocated.
13431 One possible use would be to write hardware portable code.
13432 For example, if you have a routine that uses one or more of the microcontroller
13433 I/O pins, and such pins are different for two different hardwares, you
13434 can declare the I/O pins in your routine using:
13437 \begin_layout Verse
13441 \begin_inset LatexCommand \index{volatile}
13445 __bit MOSI;\InsetSpace ~
13449 /* master out, slave in */
13451 extern volatile __bit MISO;\InsetSpace ~
13458 extern volatile __bit MCLK;\InsetSpace ~
13467 Output of a byte on a 3-wire serial bus.
13472 If needed adapt polarity of clock,
13473 polarity of data and bit order
13478 unsigned char spi_io(unsigned char out_byte)
13503 MOSI = out_byte & 0x80;
13534 /* _asm nop _endasm; */\InsetSpace ~
13542 /* for slow peripherals */
13594 \begin_layout Standard
13595 Then, someplace in the code for the first hardware you would use
13598 \begin_layout Verse
13602 \begin_inset LatexCommand \index{at}
13607 \begin_inset LatexCommand \index{\_\_at}
13611 (0x80) MOSI;\InsetSpace ~
13615 /* I/O port 0, bit 0 */
13617 __bit __at (0x81) MISO;\InsetSpace ~
13624 __bit __at (0x82) MCLK;\InsetSpace ~
13628 /* I/O port 0, bit 2 */
13631 \begin_layout Standard
13632 Similarly, for the second hardware you would use
13635 \begin_layout Verse
13638 __bit __at (0x83) MOSI;\InsetSpace ~
13642 /* I/O port 0, bit 3 */
13644 __bit __at (0x91) MISO;\InsetSpace ~
13649 I/O port 1, bit 1 */
13652 \begin_inset LatexCommand \index{bit}
13656 __at (0x92) MCLK;\InsetSpace ~
13660 /* I/O port 1, bit 2 */
13663 \begin_layout Standard
13664 and you can use the same hardware dependent routine without changes, as
13665 for example in a library.
13666 This is somehow similar to sbit, but only one absolute address has to be
13667 specified in the whole project.
13668 \begin_inset VSpace bigskip
13674 \begin_layout Section
13676 \begin_inset LatexCommand \index{Parameters}
13681 \begin_inset LatexCommand \index{function parameter}
13686 \begin_inset LatexCommand \index{local variables}
13691 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13698 \begin_layout Standard
13699 Automatic (local) variables and parameters to functions can either be placed
13700 on the stack or in data-space.
13701 The default action of the compiler is to place these variables in the internal
13702 RAM (for small model) or external RAM (for medium or large model).
13703 This in fact makes them similar to
13706 \begin_inset LatexCommand \index{static}
13712 so by default functions are non-reentrant
13713 \begin_inset LatexCommand \index{reentrant}
13722 They can be placed on the stack
13723 \begin_inset LatexCommand \index{stack}
13733 \begin_layout Standard
13743 \begin_inset LatexCommand \index{-\/-stack-auto}
13751 #pragma\InsetSpace ~
13755 \begin_inset LatexCommand \index{\#pragma stackauto}
13762 \begin_inset LatexCommand \index{reentrant}
13768 keyword in the function declaration, e.g.:
13771 \begin_layout Verse
13774 unsigned char foo(char i) __reentrant
13788 \begin_layout Standard
13789 Since stack space on 8051 is limited, the
13799 \begin_layout Standard
13810 option should be used sparingly.
13811 Note that the reentrant keyword just means that the parameters & local
13812 variables will be allocated to the stack, it
13816 mean that the function is register bank
13817 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13826 \begin_inset LatexCommand \index{local variables}
13830 can be assigned storage classes and absolute
13831 \begin_inset LatexCommand \index{Absolute addressing}
13838 \begin_layout Verse
13841 unsigned char foo()
13849 __xdata unsigned char i;
13862 \begin_inset LatexCommand \index{at}
13866 (0x31) unsigned char j;
13878 \begin_layout Standard
13879 In the above example the variable
13883 will be allocated in the external ram,
13887 in bit addressable space and
13898 \begin_layout Standard
13909 or when a function is declared as
13913 this should only be done for static variables.
13916 \begin_layout Standard
13918 \begin_inset LatexCommand \index{function parameter}
13922 however are not allowed any storage class
13923 \begin_inset LatexCommand \index{Storage class}
13927 , (storage classes for parameters will be ignored), their allocation is
13928 governed by the memory model in use, and the reentrancy options.
13931 \begin_layout Standard
13932 It is however allowed to use bit parameters in reentrant functions and also
13933 non-static local bit variables are supported.
13934 Efficient use is limited to 8 semi-bitregisters in bit space.
13935 They are pushed and popped to stack
13936 \begin_inset LatexCommand \index{stack}
13940 as a single byte just like the normal registers.
13943 \begin_layout Section
13945 \begin_inset LatexCommand \label{sub:Overlaying}
13950 \begin_inset LatexCommand \index{Overlaying}
13957 \begin_layout Standard
13959 \begin_inset LatexCommand \index{reentrant}
13963 functions SDCC will try to reduce internal ram space usage by overlaying
13964 parameters and local variables of a function (if possible).
13965 Parameters and local variables
13966 \begin_inset LatexCommand \index{local variables}
13970 of a function will be allocated to an overlayable segment if the function
13973 no other function calls and the function is non-reentrant and the memory
13975 \begin_inset LatexCommand \index{Memory model}
13982 If an explicit storage class
13983 \begin_inset LatexCommand \index{Storage class}
13987 is specified for a local variable, it will NOT be overlayed.
13990 \begin_layout Standard
13991 Note that the compiler (not the linkage editor) makes the decision for overlayin
13993 Functions that are called from an interrupt service routine
13994 \begin_inset Marginal
13997 \begin_layout Standard
14005 should be preceded by a #pragma\InsetSpace ~
14007 \begin_inset LatexCommand \index{\#pragma nooverlay}
14011 if they are not reentrant.
14014 \begin_layout Standard
14015 Also note that the compiler does not do any processing of inline assembler
14016 code, so the compiler might incorrectly assign local variables and parameters
14017 of a function into the overlay segment if the inline assembler code calls
14018 other c-functions that might use the overlay.
14019 In that case the #pragma\InsetSpace ~
14020 nooverlay should be used.
14023 \begin_layout Standard
14024 Parameters and local variables of functions that contain 16 or 32 bit multiplica
14026 \begin_inset LatexCommand \index{Multiplication}
14031 \begin_inset LatexCommand \index{Division}
14035 will NOT be overlayed since these are implemented using external functions,
14039 \begin_layout Verse
14045 \begin_inset LatexCommand \index{\#pragma nooverlay}
14051 void set_error(unsigned char errcd)
14068 some_isr () __interrupt
14069 \begin_inset LatexCommand \index{interrupt}
14099 \begin_layout Standard
14100 In the above example the parameter
14108 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
14110 not present, this could cause unpredictable runtime behavior when called
14111 from an interrupt service routine.
14112 The #pragma\InsetSpace ~
14113 nooverlay ensures that the parameters and local variables for
14114 the function are NOT overlayed.
14115 \begin_inset VSpace bigskip
14121 \begin_layout Section
14122 Interrupt Service Routines
14123 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
14130 \begin_layout Subsection
14131 General Information
14134 \begin_layout Standard
14147 outines to be coded in C, with some extended keywords.
14150 \begin_layout Verse
14153 void timer_isr (void) __interrupt (1) __using (1)
14167 \begin_layout Standard
14168 The optional number following the
14171 \begin_inset LatexCommand \index{interrupt}
14176 \begin_inset LatexCommand \index{\_\_interrupt}
14182 keyword is the interrupt number this routine will service.
14183 When present, the compiler will insert a call to this routine in the interrupt
14185 \begin_inset LatexCommand \index{interrupt vector table}
14189 for the interrupt number specified.
14190 If you have multiple source files in your project, interrupt service routines
14191 can be present in any of them, but a prototype of the isr MUST be present
14192 or included in the file that contains the function
14197 The optional (8051 specific) keyword
14200 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14205 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14211 can be used to tell the compiler to use the specified register bank when
14212 generating code for this function.
14215 Interrupt service routines open the door for some very interesting bugs:
14218 \begin_layout Subsubsection
14219 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
14223 Common interrupt pitfall: variable not declared
14228 \begin_layout Standard
14229 If an interrupt service routine changes variables which are accessed by
14230 other functions these variables have to be declared
14235 \begin_inset LatexCommand \index{volatile}
14241 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
14248 \begin_layout Subsubsection
14249 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
14253 Common interrupt pitfall:
14258 \begin_layout Standard
14259 If the access to these variables is not
14262 \begin_inset LatexCommand \index{atomic}
14269 the processor needs more than one instruction for the access and could
14270 be interrupted while accessing the variable) the interrupt must be disabled
14271 during the access to avoid inconsistent data.
14274 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
14275 and should be protected by disabling interrupts.
14276 You're not automatically on the safe side if you use 8 bit variables though.
14277 We need an example here: f.e.
14278 on the 8051 the harmless looking
14279 \begin_inset Quotes srd
14289 \begin_inset Quotes sld
14298 \begin_inset Quotes srd
14308 \begin_inset Quotes sld
14311 from within an interrupt routine might get lost if the interrupt occurs
14314 \begin_inset Quotes sld
14319 counter\InsetSpace ~
14324 \begin_inset Quotes srd
14327 is not atomic on the 8051 even if
14331 is located in data memory.
14333 Bugs like these are hard to reproduce and can
14334 cause a lot of trouble.
14338 \begin_layout Subsubsection
14339 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
14343 Common interrupt pitfall:
14348 \begin_layout Standard
14349 The return address and the registers used in the interrupt service routine
14350 are saved on the stack
14351 \begin_inset LatexCommand \index{stack}
14355 so there must be sufficient stack space.
14356 If there isn't variables or registers (or even the return address itself)
14363 \begin_inset LatexCommand \index{stack overflow}
14367 is most likely to happen if the interrupt occurs during the
14368 \begin_inset Quotes sld
14372 \begin_inset Quotes srd
14375 subroutine when the stack is already in use for f.e.
14376 many return addresses.
14379 \begin_layout Subsubsection
14380 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
14384 Common interrupt pitfall:
14386 use of non-reentrant functions
14389 \begin_layout Standard
14390 A special note here, int (16 bit) and long (32 bit) integer division
14391 \begin_inset LatexCommand \index{Division}
14396 \begin_inset LatexCommand \index{Multiplication}
14401 \begin_inset LatexCommand \index{Modulus}
14406 \begin_inset LatexCommand \index{Floating point support}
14410 operations are implemented using external support routines.
14411 If an interrupt service routine needs to do any of these operations then
14412 the support routines (as mentioned in a following section) will have to
14413 be recompiled using the
14419 \begin_layout Standard
14429 \begin_inset LatexCommand \index{-\/-stack-auto}
14435 option and the source file will need to be compiled using the
14441 \begin_layout Standard
14453 \begin_inset LatexCommand \index{-\/-int-long-reent}
14460 Note, the type promotion
14461 \begin_inset LatexCommand \index{type promotion}
14465 required by ANSI C can cause 16 bit routines to be used
14466 \begin_inset Marginal
14469 \begin_layout Standard
14478 without the programmer being aware of it.
14482 (unsigned char)(tail-1)
14484 within the if clause in section
14485 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
14492 \begin_layout Standard
14493 Calling other functions from an interrupt service routine is not recommended,
14494 avoid it if possible.
14495 Note that when some function is called from an interrupt service routine
14496 it should be preceded by a #pragma\InsetSpace ~
14498 \begin_inset LatexCommand \index{\#pragma nooverlay}
14502 if it is not reentrant.
14503 Furthermore nonreentrant functions should not be called from the main program
14504 while the interrupt service routine might be active.
14505 They also must not be called from low priority interrupt service routines
14506 while a high priority interrupt service routine might be active.
14507 You could use semaphores or make the function
14511 if all parameters are passed in registers.
14514 \begin_inset LatexCommand \ref{sub:Overlaying}
14519 about Overlaying and section
14520 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14525 about Functions using private register banks.
14526 \begin_inset VSpace bigskip
14532 \begin_layout Subsection
14533 MCS51/DS390 Interrupt Service Routines
14536 \begin_layout Standard
14538 \begin_inset LatexCommand \index{interrupt}
14542 numbers and the corresponding address & descriptions for the Standard 8051/8052
14544 SDCC will automatically adjust the
14545 \begin_inset LatexCommand \index{interrupt vector table}
14549 to the maximum interrupt number specified.
14554 \begin_layout Standard
14556 \begin_inset Tabular
14557 <lyxtabular version="3" rows="9" columns="3">
14559 <column alignment="center" valignment="top" leftline="true" width="0in">
14560 <column alignment="left" valignment="top" leftline="true" width="0in">
14561 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14562 <row topline="true" bottomline="true">
14563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14566 \begin_layout Standard
14572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14575 \begin_layout Standard
14581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14584 \begin_layout Standard
14591 <row topline="true">
14592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14595 \begin_layout Standard
14601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14604 \begin_layout Standard
14610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14613 \begin_layout Standard
14620 <row topline="true">
14621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14624 \begin_layout Standard
14630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14633 \begin_layout Standard
14639 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14642 \begin_layout Standard
14649 <row topline="true">
14650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14653 \begin_layout Standard
14659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14662 \begin_layout Standard
14668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14671 \begin_layout Standard
14678 <row topline="true">
14679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14682 \begin_layout Standard
14688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14691 \begin_layout Standard
14697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14700 \begin_layout Standard
14707 <row topline="true">
14708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14711 \begin_layout Standard
14717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14720 \begin_layout Standard
14726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14729 \begin_layout Standard
14736 <row topline="true">
14737 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14740 \begin_layout Standard
14746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14749 \begin_layout Standard
14755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14758 \begin_layout Standard
14765 <row topline="true">
14766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14769 \begin_layout Standard
14775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14778 \begin_layout Standard
14784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14787 \begin_layout Standard
14794 <row topline="true" bottomline="true">
14795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14798 \begin_layout Standard
14804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14807 \begin_layout Standard
14813 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14816 \begin_layout Standard
14832 \begin_layout Standard
14833 If the interrupt service routine is defined without
14836 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14841 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14847 a register bank or with register bank 0 (
14851 0), the compiler will save the registers used by itself on the stack upon
14852 entry and restore them at exit, however if such an interrupt service routine
14853 calls another function then the entire register bank will be saved on the
14855 This scheme may be advantageous for small interrupt service routines which
14856 have low register usage.
14859 \begin_layout Standard
14860 If the interrupt service routine is defined to be using a specific register
14865 & psw are saved and restored, if such an interrupt service routine calls
14866 another function (using another register bank) then the entire register
14867 bank of the called function will be saved on the stack
14868 \begin_inset LatexCommand \index{stack}
14873 This scheme is recommended for larger interrupt service routines.
14874 \begin_inset VSpace bigskip
14880 \begin_layout Subsection
14882 \begin_inset LatexCommand \index{HC08}
14886 Interrupt Service Routines
14889 \begin_layout Standard
14890 Since the number of interrupts
14891 \begin_inset LatexCommand \index{HC08!interrupt}
14895 available is chip specific and the interrupt vector table always ends at
14896 the last byte of memory, the interrupt numbers corresponds to the interrupt
14897 vectors in reverse order of address.
14898 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14899 2 will use the interrupt vector at 0xfffa, and so on.
14900 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14901 this way; instead see section
14902 \begin_inset LatexCommand \ref{sub:Startup-Code}
14906 for details on customizing startup.
14907 \begin_inset VSpace bigskip
14913 \begin_layout Subsection
14914 Z80 Interrupt Service Routines
14917 \begin_layout Standard
14919 \begin_inset LatexCommand \index{Z80}
14923 uses several different methods for determining the correct interrupt
14924 \begin_inset LatexCommand \index{Z80!interrupt}
14928 vector depending on the hardware implementation.
14929 Therefore, SDCC ignores the optional interrupt number and does not attempt
14930 to generate an interrupt vector table.
14933 \begin_layout Standard
14934 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14935 instruction to return from the interrupt.
14936 To write an interrupt handler for the non-maskable interrupt, which needs
14937 a RETN instruction instead, add the
14944 \begin_layout Verse
14947 void nmi_isr (void) critical interrupt
14961 \begin_layout Standard
14962 However if you need to create a non-interruptable interrupt service routine
14963 you would also require the
14968 To distinguish between this and an nmi_isr you must provide an interrupt
14970 \begin_inset VSpace bigskip
14976 \begin_layout Section
14977 Enabling and Disabling Interrupts
14980 \begin_layout Subsection
14981 Critical Functions and Critical Statements
14984 \begin_layout Standard
14985 A special keyword may be associated with a block or a function declaring
14991 SDCC will generate code to disable all interrupts
14992 \begin_inset LatexCommand \index{interrupt}
14996 upon entry to a critical function and restore the interrupt enable to the
14997 previous state before returning.
14998 Nesting critical functions will need one additional byte on the stack
14999 \begin_inset LatexCommand \index{stack}
15006 \begin_layout Verse
15009 int foo () __critical
15010 \begin_inset LatexCommand \index{critical}
15015 \begin_inset LatexCommand \index{\_\_critical}
15040 \begin_layout Standard
15041 The critical attribute maybe used with other attributes like
15051 may also be used to disable interrupts more locally:
15054 \begin_layout Verse
15060 \begin_layout Standard
15061 More than one statement could have been included in the block.
15064 \begin_layout Subsection
15065 Enabling and Disabling Interrupts directly
15068 \begin_layout Standard
15070 \begin_inset LatexCommand \index{interrupt}
15074 can also be disabled and enabled directly (8051):
15077 \begin_layout Verse
15080 EA = 0;\InsetSpace ~
15106 \begin_layout Verse
15142 \begin_layout Verse
15145 EA = 1;\InsetSpace ~
15174 \begin_layout Verse
15213 \begin_layout Standard
15214 On other architectures which have seperate opcodes for enabling and disabling
15215 interrupts you might want to make use of defines with inline assembly
15216 \begin_inset LatexCommand \index{Assembler routines}
15221 \begin_inset LatexCommand \index{HC08!interrupt}
15228 \begin_layout Verse
15232 \begin_inset LatexCommand \index{\_asm}
15241 \begin_inset LatexCommand \index{\_endasm}
15248 \begin_layout Verse
15251 #define SEI _asm\InsetSpace ~
15258 \begin_layout Verse
15264 \begin_layout Standard
15265 Note: it is sometimes sufficient to disable only a specific interrupt source
15267 a timer or serial interrupt by manipulating an
15270 \begin_inset LatexCommand \index{interrupt mask}
15280 \begin_layout Standard
15281 Usually the time during which interrupts are disabled should be kept as
15283 This minimizes both
15288 \begin_inset LatexCommand \index{interrupt latency}
15292 (the time between the occurrence of the interrupt and the execution of
15293 the first code in the interrupt routine) and
15298 \begin_inset LatexCommand \index{interrupt jitter}
15302 (the difference between the shortest and the longest interrupt latency).
15303 These really are something different, f.e.
15304 a serial interrupt has to be served before its buffer overruns so it cares
15305 for the maximum interrupt latency, whereas it does not care about jitter.
15306 On a loudspeaker driven via a digital to analog converter which is fed
15307 by an interrupt a latency of a few milliseconds might be tolerable, whereas
15308 a much smaller jitter will be very audible.
15311 \begin_layout Standard
15312 You can reenable interrupts within an interrupt routine and on some architecture
15313 s you can make use of two (or more) levels of
15315 interrupt priorities
15318 \begin_inset LatexCommand \index{interrupt priority}
15323 On some architectures which don't support interrupt priorities these can
15324 be implemented by manipulating the interrupt mask and reenabling interrupts
15325 within the interrupt routine.
15326 Check there is sufficient space on the stack
15327 \begin_inset LatexCommand \index{stack}
15331 and don't add complexity unless you have to.
15335 \begin_layout Subsection
15337 \begin_inset LatexCommand \index{semaphore}
15341 locking (mcs51/ds390)
15344 \begin_layout Standard
15345 Some architectures (mcs51/ds390) have an atomic
15346 \begin_inset LatexCommand \index{atomic}
15359 These type of instructions are typically used in preemptive multitasking
15360 systems, where a routine f.e.
15361 claims the use of a data structure ('acquires a lock
15362 \begin_inset LatexCommand \index{lock}
15366 on it'), makes some modifications and then releases the lock when the data
15367 structure is consistent again.
15368 The instruction may also be used if interrupt and non-interrupt code have
15369 to compete for a resource.
15370 With the atomic bit test and clear instruction interrupts
15371 \begin_inset LatexCommand \index{interrupt}
15375 don't have to be disabled for the locking operation.
15379 \begin_layout Standard
15380 SDCC generates this instruction if the source follows this pattern:
15383 \begin_layout Verse
15387 \begin_inset LatexCommand \index{volatile}
15391 bit resource_is_free;
15395 if (resource_is_free)
15405 resource_is_free=0;
15418 resource_is_free=1;
15425 \begin_layout Standard
15426 Note, mcs51 and ds390 support only an atomic
15427 \begin_inset LatexCommand \index{atomic}
15435 instruction (as opposed to atomic bit test and
15440 \begin_layout Section
15441 Functions using private register banks
15442 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
15449 \begin_layout Standard
15450 Some architectures have support for quickly changing register sets.
15451 SDCC supports this feature with the
15454 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
15459 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
15465 attribute (which tells the compiler to use a register bank
15466 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
15470 other than the default bank zero).
15471 It should only be applied to
15474 \begin_inset LatexCommand \index{interrupt}
15480 functions (see footnote below).
15481 This will in most circumstances make the generated ISR code more efficient
15482 since it will not have to save registers on the stack.
15485 \begin_layout Standard
15490 attribute will have no effect on the generated code for a
15494 function (but may occasionally be useful anyway
15498 \begin_layout Standard
15499 possible exception: if a function is called ONLY from 'interrupt' functions
15500 using a particular bank, it can be declared with the same 'using' attribute
15501 as the calling 'interrupt' functions.
15502 For instance, if you have several ISRs using bank one, and all of them
15503 call memcpy(), it might make sense to create a specialized version of memcpy()
15504 'using 1', since this would prevent the ISR from having to save bank zero
15505 to the stack on entry and switch to bank zero before calling the function
15514 (pending: Note, nowadays the
15518 attribute has an effect on
15522 the generated code for a
15533 \begin_layout Standard
15538 function using a non-zero bank will assume that it can trash that register
15539 bank, and will not save it.
15540 Since high-priority interrupts
15541 \begin_inset LatexCommand \index{interrupts}
15546 \begin_inset LatexCommand \index{interrupt priority}
15550 can interrupt low-priority ones on the 8051 and friends, this means that
15551 if a high-priority ISR
15555 a particular bank occurs while processing a low-priority ISR
15559 the same bank, terrible and bad things can happen.
15560 To prevent this, no single register bank should be
15564 by both a high priority and a low priority ISR.
15565 This is probably most easily done by having all high priority ISRs use
15566 one bank and all low priority ISRs use another.
15567 If you have an ISR which can change priority at runtime, you're on your
15568 own: I suggest using the default bank zero and taking the small performance
15572 \begin_layout Standard
15573 It is most efficient if your ISR calls no other functions.
15574 If your ISR must call other functions, it is most efficient if those functions
15575 use the same bank as the ISR (see note 1 below); the next best is if the
15576 called functions use bank zero.
15577 It is very inefficient to call a function using a different, non-zero bank
15580 \begin_inset VSpace bigskip
15586 \begin_layout Section
15588 \begin_inset LatexCommand \label{sub:Startup-Code}
15593 \begin_inset LatexCommand \index{Startup code}
15600 \begin_layout Subsection
15601 MCS51/DS390 Startup Code
15604 \begin_layout Standard
15605 The compiler triggers the linker to link certain initialization modules
15606 from the runtime library
15607 \begin_inset LatexCommand \index{Runtime library}
15611 called crt<something>.
15612 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15613 GSINIT5) is not linked unless the -
15619 \begin_layout Standard
15630 -xstack option is used.
15631 These modules are highly entangled by the use of special segments/areas,
15632 but a common layout is shown below:
15635 \begin_layout Verse
15643 \begin_layout Verse
15667 ljmp __sdcc_gsinit_startup
15670 \begin_layout Verse
15678 \begin_layout Verse
15690 .area GSINIT0 (CODE)
15692 __sdcc_gsinit_startup::
15702 mov sp,#__start__stack - 1
15705 \begin_layout Verse
15713 \begin_layout Verse
15725 .area GSINIT1 (CODE)
15727 __sdcc_init_xstack::
15729 ; Need to initialize in GSINIT1 in
15730 case the user's __sdcc_external_startup uses the xstack.
15740 mov __XPAGE,#(__start__x
15751 mov _spx,#__start__xstack
15754 \begin_layout Verse
15762 \begin_layout Verse
15774 .area GSINIT2 (CODE)
15784 lcall __sdcc_external_startup
15804 jz __sdcc_init_data
15815 __sdcc_program_startup
15820 \begin_layout Verse
15828 \begin_layout Verse
15840 .area GSINIT3 (CODE)
15893 mov r2,#((l_XINIT+255) >> 8)
15924 __XPAGE,#(s_XISEG >> 8)
15926 00001$:\InsetSpace ~
15990 00002$:\InsetSpace ~
16017 \begin_layout Verse
16025 \begin_layout Verse
16037 .area GSINIT4 (CODE)
16039 __mcs51_genRAMCLEAR::
16061 00004$:\InsetSpace ~
16075 ; _mcs51_genRAMCLEAR() end
16078 \begin_layout Verse
16086 \begin_layout Verse
16098 .area GSINIT4 (CODE)
16100 __mcs51_genXRAMCLEAR::
16161 mov __XPAGE,#(s_PSEG >> 8)
16173 00005$:\InsetSpace ~
16248 mov r1,#((l_XSEG + 255) >> 8)
16270 00007$:\InsetSpace ~
16307 \begin_layout Verse
16315 \begin_layout Verse
16327 .area GSINIT5 (CODE)
16329 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
16332 ; and __mcs51_genRAMCLEAR modifies _spx.
16342 mov __XPAGE,#(__start__x
16353 mov _spx,#__start__xstack
16356 \begin_layout Verse
16361 (application modules)
16364 \begin_layout Verse
16376 .area GSINIT (CODE)
16379 \begin_layout Verse
16387 \begin_layout Verse
16399 .area GSFINAL (CODE)
16409 ljmp __sdcc_program_startup
16411 ;---------------------------------
16412 -----------------------
16416 ;--------------------------------------------------
16439 __sdcc_program_startup:
16452 return from main will lock up
16465 \begin_layout Standard
16466 One of these modules (crtstart.asm) contains a call to the C routine
16468 _sdcc_external_startup()
16469 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
16478 at the start of the CODE area.
16479 This routine is also in the runtime library
16480 \begin_inset LatexCommand \index{Runtime library}
16484 and returns 0 by default.
16485 If this routine returns a non-zero value, the static & global variable
16486 initialization will be skipped and the function main will be invoked.
16487 Otherwise static & global variables will be initialized before the function
16491 _sdcc_external_startup()
16493 routine to your program to override the default if you need to setup hardware
16494 or perform some other critical operation prior to static & global variable
16496 \begin_inset LatexCommand \index{Variable initialization}
16501 On some mcs51 variants xdata
16502 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
16506 memory has to be explicitly enabled before it can be accessed or if the
16508 \begin_inset LatexCommand \index{watchdog}
16512 needs to be disabled, this is the place to do it.
16513 The startup code clears all internal data memory, 256 bytes by default,
16514 but from 0 to n-1 if
16520 \begin_layout Standard
16530 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16537 (recommended for Chipcon CC1010).
16540 \begin_layout Standard
16541 See also the compiler options
16547 \begin_layout Standard
16563 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16573 \begin_layout Standard
16585 \begin_inset LatexCommand \index{-\/-main-return}
16590 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16594 about MCS51-variants.
16599 \begin_layout Standard
16600 While these initialization modules are meant as generic startup code there
16601 might be the need for customization.
16602 Let's assume the return value of
16604 _sdcc_external_startup()
16610 should not be checked (or
16612 _sdcc_external_startup()
16614 should not be called at all).
16615 The recommended way would be to copy
16621 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm}
16625 ) into the source directory, adapt it there, then assemble it with
16631 \begin_layout Standard
16632 \begin_inset Quotes sld
16636 \begin_inset Quotes srd
16639 are the assembler options used in
16640 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup }
16651 and when linking your project explicitely specify
16656 As a bonus a listing of the relocated object file
16663 \begin_layout Standard
16664 \begin_inset VSpace bigskip
16670 \begin_layout Subsection
16674 \begin_layout Standard
16676 \begin_inset LatexCommand \index{HC08}
16680 startup code follows the same scheme as the MCS51 startup code.
16681 \begin_inset VSpace bigskip
16687 \begin_layout Subsection
16691 \begin_layout Standard
16693 \begin_inset LatexCommand \index{Z80}
16697 the startup code is inserted by linking with crt0.o which is generated from
16698 sdcc/device/lib/z80/crt0.s.
16699 If you need a different startup code you can use the compiler option
16708 \begin_layout Standard
16723 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16727 and provide your own crt0.o.
16729 \begin_inset VSpace bigskip
16735 \begin_layout Section
16736 Inline Assembler Code
16737 \begin_inset LatexCommand \index{Assembler routines}
16744 \begin_layout Subsection
16745 A Step by Step Introduction
16746 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16753 \begin_layout Standard
16754 Starting from a small snippet of c-code this example shows for the MCS51
16755 how to use inline assembly, access variables, a function parameter and
16756 an array in xdata memory.
16757 The example uses an MCS51 here but is easily adapted for other architectures.
16758 This is a buffer routine which should be optimized:
16761 \begin_layout Verse
16765 unsigned char __far
16766 \begin_inset LatexCommand \index{far (storage class)}
16771 \begin_inset LatexCommand \index{\_\_far (storage class)}
16776 \begin_inset LatexCommand \index{at}
16781 \begin_inset LatexCommand \index{\_\_at}
16785 (0x7f00) buf[0x100];
16786 \begin_inset LatexCommand \index{Aligned array}
16792 unsigned char head, tail;\InsetSpace ~
16810 \begin_inset LatexCommand \index{interrupt}
16862 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16874 void to_buffer( unsigned char c )
16882 if( head != (unsigned char)(tail-1)
16889 \begin_inset LatexCommand \index{promotion to signed int}
16894 \begin_inset LatexCommand \index{type promotion}
16899 \begin_inset Marginal
16902 \begin_layout Standard
16921 buf[ head++ ] = c;\InsetSpace ~
16937 /* access to a 256 byte aligned array */
16942 \begin_layout Standard
16943 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16944 then a corresponding buffer.asm file is generated.
16945 We define a new function
16949 in file buffer.c in which we cut and paste the generated code, removing
16950 unwanted comments and some ':'.
16952 \begin_inset Quotes sld
16960 \begin_inset Quotes srd
16964 \begin_inset Quotes sld
16972 \begin_inset Quotes srd
16979 \begin_layout Standard
16980 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16981 and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16983 The latter is also used in the library functions.
16988 to the beginning and the end of the function body:
16991 \begin_layout Verse
16995 /* With a cut and paste from the .asm file, we have something to start with.
17001 function is not yet OK! (registers aren't saved) */
17003 void to_buffer_asm(
17013 \begin_inset LatexCommand \index{\_asm}
17018 \begin_inset LatexCommand \index{\_\_asm}
17032 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
17038 \begin_inset LatexCommand \index{promotion to signed int}
17043 \begin_inset LatexCommand \index{type promotion}
17096 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
17097 \begin_inset LatexCommand \index{Aligned array}
17163 \begin_inset LatexCommand \index{\_endasm}
17168 \begin_inset LatexCommand \index{\_\_endasm}
17177 \begin_layout Standard
17178 The new file buffer.c should compile with only one warning about the unreferenced
17179 function argument 'c'.
17180 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
17181 (1) and finally have:
17184 \begin_layout Verse
17188 unsigned char __far __at(0x7f00) buf[0x100];
17190 unsigned char head, tail;
17201 void to_buffer( unsigned char c )
17210 head != (unsigned char)(tail-1) )
17239 c; // to avoid warning: unreferenced function argument
17246 \begin_inset LatexCommand \index{\_asm}
17251 \begin_inset LatexCommand \index{\_\_asm}
17265 ; save used registers here.
17276 ; If we were still using r2,r3 we would have to push them here.
17279 ; if( head != (unsigned char)(tail-1) )
17323 could do an ANL a,#0x0f here to use a smaller buffer (see below)
17359 a,dpl \InsetSpace ~
17366 ; dpl holds lower byte of function argument
17378 dpl,_head \InsetSpace ~
17381 ; buf is 0x100 byte aligned so head can be used directly
17424 ; we could do an ANL _head,#0x0f here to use a
17425 smaller buffer (see above)
17437 ; restore used registers here
17444 \begin_inset LatexCommand \index{\_endasm}
17449 \begin_inset LatexCommand \index{\_\_endasm}
17460 \begin_layout Standard
17461 The inline assembler code can contain any valid code understood by the assembler
17462 , this includes any assembler directives and comment lines.
17463 The assembler does not like some characters like ':' or ''' in comments.
17464 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
17465 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
17470 \begin_inset LatexCommand \index{Assembler documentation}
17475 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
17483 \begin_layout Standard
17484 The compiler does not do any validation of the code within the
17487 \begin_inset LatexCommand \index{\_asm}
17492 \begin_inset LatexCommand \index{\_\_asm}
17500 \begin_inset LatexCommand \index{\_endasm}
17505 \begin_inset LatexCommand \index{\_\_endasm}
17514 Specifically it will not know which registers are used and thus register
17516 \begin_inset LatexCommand \index{push/pop}
17520 has to be done manually.
17524 \begin_layout Standard
17525 It is recommended that each assembly instruction (including labels) be placed
17526 in a separate line (as the example shows).
17531 \begin_layout Standard
17543 \begin_inset LatexCommand \index{-\/-peep-asm}
17549 command line option is used, the inline assembler code will be passed through
17550 the peephole optimizer
17551 \begin_inset LatexCommand \index{Peephole optimizer}
17556 There are only a few (if any) cases where this option makes sense, it might
17557 cause some unexpected changes in the inline assembler code.
17558 Please go through the peephole optimizer rules defined in file
17562 before using this option.
17565 \begin_layout Subsection
17567 \begin_inset LatexCommand \label{sub:Naked-Functions}
17572 \begin_inset LatexCommand \index{Naked functions}
17579 \begin_layout Standard
17580 A special keyword may be associated with a function declaring it as
17583 \begin_inset LatexCommand \index{\_naked}
17588 \begin_inset LatexCommand \index{\_\_naked}
17599 function modifier attribute prevents the compiler from generating prologue
17600 \begin_inset LatexCommand \index{function prologue}
17605 \begin_inset LatexCommand \index{function epilogue}
17609 code for that function.
17610 This means that the user is entirely responsible for such things as saving
17611 any registers that may need to be preserved, selecting the proper register
17612 bank, generating the
17616 instruction at the end, etc.
17617 Practically, this means that the contents of the function must be written
17618 in inline assembler.
17619 This is particularly useful for interrupt functions, which can have a large
17620 (and often unnecessary) prologue/epilogue.
17621 For example, compare the code generated by these two functions:
17624 \begin_layout Verse
17628 \begin_inset LatexCommand \index{volatile}
17632 data unsigned char counter;
17636 void simpleInterrupt(void) __interrupt
17637 \begin_inset LatexCommand \index{interrupt}
17642 \begin_inset LatexCommand \index{\_\_interrupt}
17660 void nakedInterrupt(void) __interrupt (2) __naked
17669 \begin_inset LatexCommand \index{\_asm}
17674 \begin_inset LatexCommand \index{\_\_asm}
17691 _counter ; does not change flags, no need to save psw
17704 include ret or reti in _naked function.
17711 \begin_inset LatexCommand \index{\_endasm}
17716 \begin_inset LatexCommand \index{\_\_endasm}
17725 \begin_layout Standard
17726 For an 8051 target, the generated simpleInterrupt looks like:
17729 \begin_layout Verse
17736 example, recent versions of SDCC generate
17742 code for simpleInterrupt() and nakedInterrupt()!
17883 \begin_layout Standard
17884 whereas nakedInterrupt looks like:
17887 \begin_layout Verse
17900 _counter ; does not change flags, no need to save psw
17919 MUST explicitly include ret or reti in _naked function
17922 \begin_layout Standard
17923 The related directive #pragma exclude
17924 \begin_inset LatexCommand \index{\#pragma exclude}
17928 allows a more fine grained control over pushing & popping
17929 \begin_inset LatexCommand \index{push/pop}
17936 \begin_layout Standard
17937 While there is nothing preventing you from writing C code inside a
17941 function, there are many ways to shoot yourself in the foot doing this,
17942 and it is recommended that you stick to inline assembler.
17945 \begin_layout Subsection
17946 Use of Labels within Inline Assembler
17949 \begin_layout Standard
17950 SDCC allows the use of in-line assembler with a few restrictions regarding
17952 All labels defined within inline assembler code have to be of the form
17957 where nnnnn is a number less than 100 (which implies a limit of utmost
17958 100 inline assembler labels
17969 \begin_layout Standard
17970 This is a slightly more stringent rule than absolutely necessary, but stays
17971 always on the safe side.
17972 Labels in the form of nnnnn$ are local labels in the assembler, locality
17973 of which is confined within two labels of the standard form.
17974 The compiler uses the same form for labels within a function (but starting
17975 from nnnnn=00100); and places always a standard label at the beginning
17976 of a function, thus limiting the locality of labels within the scope of
17978 So, if the inline assembler part would be embedded into C-code, an improperly
17979 placed non-local label in the assembler would break up the reference space
17980 for labels created by the compiler for the C-code, leading to an assembling
17984 \begin_layout Standard
17985 The numeric part of local labels does not need to have 5 digits (although
17986 this is the form of labels output by the compiler), any valid integer will
17988 Please refer to the assemblers documentation for further details.
17996 \begin_layout Verse
18000 \begin_inset LatexCommand \index{\_asm}
18005 \begin_inset LatexCommand \index{\_\_asm}
18035 \begin_inset LatexCommand \index{\_endasm}
18040 \begin_inset LatexCommand \index{\_\_endasm}
18047 \begin_layout Standard
18048 Inline assembler code cannot reference any C-labels, however it can reference
18050 \begin_inset LatexCommand \index{Labels}
18054 defined by the inline assembler, e.g.:
18057 \begin_layout Verse
18080 ; some assembler code
18101 /* some more c code */
18103 clabel:\InsetSpace ~
18105 /* inline assembler cannot reference this
18110 \begin_layout Standard
18115 is translated by the compiler into a local label, so the locality of labels
18116 within the function is not broken.
18133 0003$: ;label (can be referenced by inline assembler only)
18140 \begin_inset LatexCommand \index{\_endasm}
18145 \begin_inset LatexCommand \index{\_\_endasm}
18155 /* some more c code */
18160 \begin_layout Standard
18161 In other words inline assembly code can access labels defined in inline
18162 assembly within the scope of the function.
18163 The same goes the other way, i.e.
18164 labels defines in inline assembly can not be accessed by C statements.
18167 \begin_layout Section
18168 Interfacing with Assembler Code
18169 \begin_inset LatexCommand \index{Assembler routines}
18176 \begin_layout Subsection
18177 Global Registers used for Parameter Passing
18178 \begin_inset LatexCommand \index{Parameter passing}
18185 \begin_layout Standard
18186 The compiler always uses the global registers
18189 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18194 \begin_inset LatexCommand \index{DPTR}
18199 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
18208 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
18214 to pass the first (non-bit) parameter to a function, and also to pass the
18216 \begin_inset LatexCommand \index{return value}
18220 of function; according to the following scheme: one byte return value in
18225 , two byte value in
18234 three byte values (generic pointers) in
18246 , and four byte values in
18264 \begin_inset LatexCommand \index{generic pointer}
18268 contain type of accessed memory in
18289 \begin_inset Note Note
18292 \begin_layout Standard
18293 This might not be the case of certain memory models (medium???)
18301 \begin_layout Standard
18302 The second parameter onwards is either allocated on the stack (for reentrant
18307 \begin_layout Standard
18316 -stack-auto is used) or in data/xdata memory (depending on the memory model).
18319 \begin_layout Standard
18320 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
18321 space for reentrant functions or allocated directly in bit memory otherwise.
18324 \begin_layout Standard
18325 Functions (with two or more parameters or bit parameters) that are called
18326 through function pointers
18327 \begin_inset LatexCommand \index{function pointers}
18331 must therefor be reentrant so the compiler knows how to pass the parameters.
18334 \begin_layout Subsection
18338 \begin_layout Standard
18339 Unless the called function is declared as
18344 \begin_inset LatexCommand \index{naked}
18352 \begin_layout Standard
18362 \begin_inset LatexCommand \index{-\/-callee-saves}
18370 \begin_layout Standard
18379 -all-callee-saves command line option or the corresponding callee_saves
18380 pragma are used, the caller will save the registers (
18384 ) around the call, so the called function can destroy they content freely.
18387 \begin_layout Standard
18388 If the called function is not declared as
18392 , the caller will swap register banks around the call, if caller and callee
18393 use different register banks (having them defined by the
18401 \begin_layout Standard
18402 The called function can also use
18418 observing that they are used for parameter/return value passing.
18421 \begin_layout Subsection
18422 Assembler Routine (non-reentrant)
18425 \begin_layout Standard
18426 In the following example
18427 \begin_inset LatexCommand \index{reentrant}
18432 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
18436 the function c_func calls an assembler routine asm_func, which takes two
18438 \begin_inset LatexCommand \index{function parameter}
18445 \begin_layout Verse
18448 extern int asm_func(unsigned char, unsigned char);
18452 int c_func (unsigned char
18453 i, unsigned char j)
18461 return asm_func(i,j);
18475 return c_func(10,9);
18480 \begin_layout Standard
18481 The corresponding assembler function is:
18484 \begin_layout Verse
18487 .globl _asm_func_PARM_2
18589 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18606 \begin_layout Standard
18607 The parameter naming convention is _<function_name>_PARM_<n>, where n is
18608 the parameter number starting from 1, and counting from the left.
18609 The first parameter is passed in
18625 according to the description above.
18626 The variable name for the second parameter will be _<function_name>_PARM_2.
18631 ble the assembler routine with the following command:
18638 asx8051 -losg asmfunc.asm
18645 Then compile and link the assembler routine to the C source file with the
18653 sdcc cfunc.c asmfunc.rel
18656 \begin_layout Subsection
18657 Assembler Routine (reentrant)
18660 \begin_layout Standard
18662 \begin_inset LatexCommand \index{reentrant}
18667 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18671 the second parameter
18672 \begin_inset LatexCommand \index{function parameter}
18676 onwards will be passed on the stack, the parameters are pushed from right
18678 before the call the second leftmost parameter will be on the top of the
18679 stack (the leftmost parameter is passed in registers).
18680 Here is an example:
18683 \begin_layout Verse
18686 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18691 c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
18700 return asm_func(i,j,k);
18714 return c_func(10,9,8);
18719 \begin_layout Standard
18720 The corresponding (unoptimized) assembler routine is:
18723 \begin_layout Verse
18743 _bp,sp\InsetSpace ~
18749 ;stack contains: _bp, return
18750 address, second parameter, third parameter
18774 a,#0xfd\InsetSpace ~
18780 pointer to the second parameter
18804 a,#0xfc\InsetSpace ~
18810 to the rightmost parameter
18851 result (= sum of all three parameters)
18866 ;return value goes into dptr
18900 \begin_layout Standard
18901 The compiling and linking procedure remains the same, however note the extra
18902 entry & exit linkage required for the assembler code, _bp is the stack
18903 frame pointer and is used to compute the offset into the stack for parameters
18904 and local variables.
18905 \begin_inset VSpace bigskip
18911 \begin_layout Section
18913 \begin_inset LatexCommand \index{int (16 bit)}
18918 \begin_inset LatexCommand \index{long (32 bit)}
18925 \begin_layout Standard
18926 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18927 multiplication and modulus operations are implemented by support routines.
18928 These support routines are all developed in ANSI-C to facilitate porting
18929 to other MCUs, although some model specific assembler optimizations are
18931 The following files contain the described routines, all of them can be
18932 found in <installdir>/share/sdcc/lib.
18937 \begin_layout Standard
18939 \begin_inset Tabular
18940 <lyxtabular version="3" rows="11" columns="2">
18942 <column alignment="left" valignment="top" leftline="true" width="0">
18943 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18944 <row topline="true" bottomline="true">
18945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18948 \begin_layout Standard
18956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18959 \begin_layout Standard
18968 <row topline="true">
18969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18972 \begin_layout Standard
18978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18981 \begin_layout Standard
18982 16 bit multiplication
18988 <row topline="true">
18989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18992 \begin_layout Standard
18998 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19001 \begin_layout Standard
19002 signed 16 bit division (calls _divuint)
19008 <row topline="true">
19009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19012 \begin_layout Standard
19018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19021 \begin_layout Standard
19022 unsigned 16 bit division
19028 <row topline="true">
19029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19032 \begin_layout Standard
19038 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19041 \begin_layout Standard
19042 signed 16 bit modulus (calls _moduint)
19048 <row topline="true">
19049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19052 \begin_layout Standard
19058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19061 \begin_layout Standard
19062 unsigned 16 bit modulus
19068 <row topline="true">
19069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19072 \begin_layout Standard
19078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19081 \begin_layout Standard
19082 32 bit multiplication
19088 <row topline="true">
19089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19092 \begin_layout Standard
19098 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19101 \begin_layout Standard
19102 signed 32 division (calls _divulong)
19108 <row topline="true">
19109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19112 \begin_layout Standard
19118 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19121 \begin_layout Standard
19122 unsigned 32 division
19128 <row topline="true">
19129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19132 \begin_layout Standard
19138 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19141 \begin_layout Standard
19142 signed 32 bit modulus (calls _modulong)
19148 <row topline="true" bottomline="true">
19149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19152 \begin_layout Standard
19158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19161 \begin_layout Standard
19162 unsigned 32 bit modulus
19177 \begin_layout Standard
19178 Since they are compiled as
19183 \begin_inset LatexCommand \index{reentrant}
19188 \begin_inset LatexCommand \index{interrupt}
19192 service routines should not do any of the above operations.
19193 If this is unavoidable then the above routines will need to be compiled
19200 \begin_layout Standard
19210 \begin_inset LatexCommand \index{-\/-stack-auto}
19216 option, after which the source program will have to be compiled with
19222 \begin_layout Standard
19232 \begin_inset LatexCommand \index{-\/-int-long-reent}
19239 Notice that you don't have to call these routines directly.
19240 The compiler will use them automatically every time an integer operation
19244 \begin_layout Section
19245 Floating Point Support
19246 \begin_inset LatexCommand \index{Floating point support}
19253 \begin_layout Standard
19254 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
19255 The floating point support routines are derived from gcc's floatlib.c and
19256 consist of the following routines:
19261 \begin_layout Standard
19265 \begin_inset Tabular
19266 <lyxtabular version="3" rows="17" columns="2">
19268 <column alignment="left" valignment="top" leftline="true" width="0">
19269 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19270 <row topline="true" bottomline="true">
19271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19274 \begin_layout Standard
19289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19292 \begin_layout Standard
19299 <row topline="true">
19300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19303 \begin_layout Standard
19318 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19321 \begin_layout Standard
19331 add floating point numbers
19337 <row topline="true">
19338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19341 \begin_layout Standard
19356 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19359 \begin_layout Standard
19369 subtract floating point numbers
19375 <row topline="true">
19376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19379 \begin_layout Standard
19394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19397 \begin_layout Standard
19407 divide floating point numbers
19413 <row topline="true">
19414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19417 \begin_layout Standard
19432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19435 \begin_layout Standard
19445 multiply floating point numbers
19451 <row topline="true">
19452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19455 \begin_layout Standard
19470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19473 \begin_layout Standard
19483 convert floating point to unsigned char
19489 <row topline="true">
19490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19493 \begin_layout Standard
19508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19511 \begin_layout Standard
19521 convert floating point to signed char
19527 <row topline="true">
19528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19531 \begin_layout Standard
19546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19549 \begin_layout Standard
19559 convert floating point to unsigned int
19565 <row topline="true">
19566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19569 \begin_layout Standard
19584 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19587 \begin_layout Standard
19597 convert floating point to signed int
19603 <row topline="true">
19604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19607 \begin_layout Standard
19630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19633 \begin_layout Standard
19643 convert floating point to unsigned long
19649 <row topline="true">
19650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19653 \begin_layout Standard
19668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19671 \begin_layout Standard
19681 convert floating point to signed long
19687 <row topline="true">
19688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19691 \begin_layout Standard
19706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19709 \begin_layout Standard
19719 convert unsigned char to floating point
19725 <row topline="true">
19726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19729 \begin_layout Standard
19744 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19747 \begin_layout Standard
19757 convert char to floating point number
19763 <row topline="true">
19764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19767 \begin_layout Standard
19782 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19785 \begin_layout Standard
19795 convert unsigned int to floating point
19801 <row topline="true">
19802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19805 \begin_layout Standard
19820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19823 \begin_layout Standard
19833 convert int to floating point numbers
19839 <row topline="true">
19840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19843 \begin_layout Standard
19858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19861 \begin_layout Standard
19871 convert unsigned long to floating point number
19877 <row topline="true" bottomline="true">
19878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19881 \begin_layout Standard
19896 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19899 \begin_layout Standard
19909 convert long to floating point number
19924 \begin_layout Standard
19925 These support routines are developed in ANSI-C so there is room for space
19926 and speed improvement
19930 \begin_layout Standard
19931 These floating point routines (
19935 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19942 Note if all these routines are used simultaneously the data space might
19944 For serious floating point usage the large model might be needed.
19945 Also notice that you don't have to call this routines directly.
19946 The compiler will use them automatically every time a floating point operation
19948 \begin_inset VSpace bigskip
19954 \begin_layout Section
19956 \begin_inset LatexCommand \index{Libraries}
19963 \begin_layout Standard
19966 <pending: this is messy and incomplete - a little more information is in
19967 sdcc/doc/libdoc.txt
19972 \begin_layout Subsection
19973 Compiler support routines (_gptrget, _mulint etc.)
19976 \begin_layout Subsection
19977 Stdclib functions (puts, printf, strcat etc.)
19980 \begin_layout Subsubsection
19984 \begin_layout Paragraph
19985 getchar(), putchar()
19988 \begin_layout Standard
19989 \begin_inset LatexCommand \index{<stdio.h>}
19993 As usual on embedded systems you have to provide your own
19996 \begin_inset LatexCommand \index{getchar()}
20005 \begin_inset LatexCommand \index{putchar()}
20012 SDCC does not know whether the system connects to a serial line with or
20013 without handshake, LCD, keyboard or other device.
20027 You'll find examples for serial routines f.e.
20028 in sdcc/device/lib.
20029 For the mcs51 this minimalistic polling
20033 routine might be a start:
20036 \begin_layout Verse
20039 void putchar (char c) {
20045 while (!TI)\InsetSpace ~
20048 /* assumes UART is initialized */
20076 \begin_layout Paragraph
20080 \begin_layout Standard
20084 \begin_inset LatexCommand \index{printf()}
20094 does not support float (except on ds390).
20095 To enable this recompile it with the option
20101 \begin_layout Standard
20111 \begin_inset LatexCommand \index{USE\_FLOATS}
20117 on the command line.
20124 \begin_layout Standard
20134 \begin_inset LatexCommand \index{-\/-model-large}
20140 for the mcs51 port, since this uses a lot of memory.
20143 \begin_layout Standard
20144 If you're short on code memory you might want to use
20147 \begin_inset LatexCommand \index{printf\_small()}
20162 For the mcs51 there additionally are assembly versions
20165 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
20171 (subset of printf using less than 270 bytes) and
20174 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
20183 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
20189 (floating-point aware version of printf_fast) which should fit the requirements
20190 of many embedded systems (printf_fast() can be customized by unsetting
20195 support long variables and field widths).
20196 Be sure to use only one of these printf options within a project.
20201 \begin_layout Standard
20202 Feature matrix of different
20209 \begin_layout Standard
20210 \begin_inset Tabular
20211 <lyxtabular version="3" rows="14" columns="7">
20212 <features islongtable="true">
20213 <column alignment="left" valignment="middle" leftline="true" width="14col%">
20214 <column alignment="center" valignment="top" leftline="true" width="0">
20215 <column alignment="center" valignment="top" leftline="true" width="12col%">
20216 <column alignment="center" valignment="top" leftline="true" width="10col%">
20217 <column alignment="center" valignment="top" leftline="true" width="0">
20218 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
20219 <column alignment="center" valignment="top" rightline="true" width="0">
20220 <row topline="true" bottomline="true" endhead="true">
20221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20224 \begin_layout Standard
20233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20236 \begin_layout Standard
20238 \begin_inset LatexCommand \index{printf}
20247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20250 \begin_layout Standard
20258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20261 \begin_layout Standard
20267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20270 \begin_layout Standard
20276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20279 \begin_layout Standard
20285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20288 \begin_layout Standard
20295 <row topline="true" endhead="true">
20296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20299 \begin_layout Standard
20305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20308 \begin_layout Standard
20316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20319 \begin_layout Standard
20327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20330 \begin_layout Standard
20338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20341 \begin_layout Standard
20349 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20352 \begin_layout Standard
20360 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20363 \begin_layout Standard
20372 <row topline="true" endhead="true">
20373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20376 \begin_layout Standard
20377 \begin_inset Quotes sld
20381 \begin_inset Quotes srd
20387 \begin_layout Standard
20393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20396 \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" usebox="none">
20423 \begin_layout Standard
20429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20432 \begin_layout Standard
20438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20441 \begin_layout Standard
20448 <row topline="true" endhead="true">
20449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20452 \begin_layout Standard
20456 \begin_layout Standard
20462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20465 \begin_layout Standard
20471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20474 \begin_layout Standard
20480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20483 \begin_layout Standard
20484 0.45k / 0.47k (+ _ltoa)
20489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20492 \begin_layout Standard
20498 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20501 \begin_layout Standard
20507 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20510 \begin_layout Standard
20517 <row topline="true">
20518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20521 \begin_layout Standard
20527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20530 \begin_layout Standard
20540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20543 \begin_layout Standard
20590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20593 \begin_layout Standard
20632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20635 \begin_layout Standard
20641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20644 \begin_layout Standard
20650 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20653 \begin_layout Standard
20660 <row topline="true">
20661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20664 \begin_layout Standard
20665 long (32 bit) support
20670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20673 \begin_layout Standard
20679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20682 \begin_layout Standard
20688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20691 \begin_layout Standard
20697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20700 \begin_layout Standard
20706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20709 \begin_layout Standard
20724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20727 \begin_layout Standard
20734 <row topline="true">
20735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20738 \begin_layout Standard
20739 byte arguments on stack
20744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20747 \begin_layout Standard
20753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20756 \begin_layout Standard
20762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20765 \begin_layout Standard
20771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20774 \begin_layout Standard
20780 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20783 \begin_layout Standard
20789 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20792 \begin_layout Standard
20799 <row topline="true">
20800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20803 \begin_layout Standard
20805 \begin_inset LatexCommand \index{Floating point 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
20858 \begin_layout Standard
20859 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20869 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20872 \begin_layout Standard
20879 <row topline="true">
20880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20883 \begin_layout Standard
20884 float formats %e %g
20889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20892 \begin_layout Standard
20898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20901 \begin_layout Standard
20907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20910 \begin_layout Standard
20916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20919 \begin_layout Standard
20925 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20928 \begin_layout Standard
20934 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20937 \begin_layout Standard
20944 <row topline="true" bottomline="true">
20945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20948 \begin_layout Standard
20954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20957 \begin_layout Standard
20963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20966 \begin_layout Standard
20972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20975 \begin_layout Standard
20981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20984 \begin_layout Standard
20990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20993 \begin_layout Standard
20999 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21002 \begin_layout Standard
21009 <row bottomline="true">
21010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21013 \begin_layout Standard
21018 \begin_layout Standard
21019 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
21023 n'); standard 8051 @ 22.1184 MHz, empty putchar()
21031 \begin_layout Standard
21037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21040 \begin_layout Standard
21046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21049 \begin_layout Standard
21055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21058 \begin_layout Standard
21064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21067 \begin_layout Standard
21073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21076 \begin_layout Standard
21082 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21085 \begin_layout Standard
21092 <row bottomline="true">
21093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21096 \begin_layout Standard
21101 \begin_layout Standard
21102 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
21111 \begin_layout Standard
21117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21120 \begin_layout Standard
21126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21129 \begin_layout Standard
21135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21138 \begin_layout Standard
21144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21147 \begin_layout Standard
21153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21156 \begin_layout Standard
21162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21165 \begin_layout Standard
21170 \begin_layout Standard
21171 printf_tiny integer speed is data dependent, worst case is 0.33 ms
21182 <row bottomline="true">
21183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21186 \begin_layout Standard
21191 \begin_layout Standard
21192 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
21201 \begin_layout Standard
21207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21210 \begin_layout Standard
21216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21219 \begin_layout Standard
21225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21228 \begin_layout Standard
21234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21237 \begin_layout Standard
21243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21246 \begin_layout Standard
21252 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21255 \begin_layout Standard
21262 <row bottomline="true">
21263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21266 \begin_layout Standard
21271 \begin_layout Standard
21272 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
21281 \begin_layout Standard
21287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21290 \begin_layout Standard
21296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21299 \begin_layout Standard
21305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21308 \begin_layout Standard
21314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21317 \begin_layout Standard
21323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21326 \begin_layout Standard
21332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21335 \begin_layout Standard
21349 \begin_layout Subsubsection
21351 \begin_inset LatexCommand \index{malloc.h}
21358 \begin_layout Standard
21359 As of SDCC 2.6.2 you no longer need to call an initialization routine before
21360 using dynamic memory allocation
21361 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
21366 \begin_inset LatexCommand \index{heap (malloc)}
21370 space of 1024 bytes is provided for malloc to allocate memory from.
21371 If you need a different heap size you need to recompile _heap.c with the
21372 required size defined in HEAP_SIZE.
21373 It is recommended to make a copy of this file into your project directory
21374 and compile it there with:
21377 \begin_layout Verse
21380 sdcc -c _heap.c -D HEAD_SIZE=2048
21383 \begin_layout Standard
21384 And then link it with:
21387 \begin_layout Verse
21390 sdcc main.rel _heap.rel
21393 \begin_layout Subsection
21394 Math functions (sinf, powf, sqrtf etc.)
21397 \begin_layout Subsubsection
21401 \begin_layout Standard
21402 See definitions in file <math.h>.
21405 \begin_layout Subsection
21409 \begin_layout Standard
21411 \begin_inset LatexCommand \index{Libraries}
21415 included in SDCC should have a license at least as liberal as the GNU Lesser
21416 General Public License
21417 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
21428 \begin_layout Standard
21429 \begin_inset Note Note
21432 \begin_layout Standard
21433 license statements for the libraries are missing.
21434 sdcc/device/lib/ser_ir.c
21437 \begin_layout Standard
21439 come with a GPL (as opposed to LGPL) License - this will not be liberal
21440 enough for many embedded programmers.
21448 \begin_layout Standard
21449 If you have ported some library or want to share experience about some code
21451 falls into any of these categories Busses (I
21452 \begin_inset Formula $^{\textrm{2}}$
21455 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
21456 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
21457 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
21458 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
21463 would certainly like to hear about it.
21466 \begin_layout Standard
21467 Programmers coding for embedded systems are not especially famous for being
21468 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
21469 e these references are very valuable.
21470 Let's help to create a climate where information is shared.
21471 \begin_inset VSpace bigskip
21477 \begin_layout Section
21481 \begin_layout Subsection
21482 MCS51 Memory Models
21483 \begin_inset LatexCommand \index{Memory model}
21488 \begin_inset LatexCommand \index{MCS51 memory model}
21495 \begin_layout Subsubsection
21496 Small, Medium and Large
21499 \begin_layout Standard
21500 SDCC allows three memory models for MCS51 code,
21509 Modules compiled with different memory models should
21513 be combined together or the results would be unpredictable.
21514 The library routines supplied with the compiler are compiled as small,
21516 The compiled library modules are contained in separate directories as small,
21517 medium and large so that you can link to the appropriate set.
21520 \begin_layout Standard
21521 When the medium or large model is used all variables declared without a
21522 storage class will be allocated into the external ram, this includes all
21523 parameters and local variables (for non-reentrant
21524 \begin_inset LatexCommand \index{reentrant}
21529 When the small model is used variables without storage class are allocated
21530 in the internal ram.
21533 \begin_layout Standard
21534 Judicious usage of the processor specific storage classes
21535 \begin_inset LatexCommand \index{Storage class}
21539 and the 'reentrant' function type will yield much more efficient code,
21540 than using the large model.
21541 Several optimizations are disabled when the program is compiled using the
21542 large model, it is therefore recommended that the small model be used unless
21543 absolutely required.
21546 \begin_layout Subsubsection
21548 \begin_inset LatexCommand \label{sub:External-Stack}
21553 \begin_inset LatexCommand \index{stack}
21558 \begin_inset LatexCommand \index{External stack (mcs51)}
21565 \begin_layout Standard
21566 The external stack (-
21570 \begin_layout Standard
21580 \begin_inset LatexCommand \index{-\/-xstack}
21584 ) is located in pdata
21585 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
21589 memory (usually at the start of the external ram segment) and uses all
21590 unused space in pdata (max.
21596 \begin_layout Standard
21605 -xstack option is used to compile the program, the parameters and local
21607 \begin_inset LatexCommand \index{local variables}
21611 of all reentrant functions are allocated in this area.
21612 This option is provided for programs with large stack space requirements.
21613 When used with the -
21617 \begin_layout Standard
21627 \begin_inset LatexCommand \index{-\/-stack-auto}
21631 option, all parameters and local variables are allocated on the external
21632 stack (note: support libraries will need to be recompiled with the same
21634 There is a predefined target in the library makefile).
21637 \begin_layout Standard
21638 The compiler outputs the higher order address byte of the external ram segment
21640 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21645 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21649 ), therefore when using the External Stack option, this port
21653 be used by the application program.
21656 \begin_layout Subsection
21658 \begin_inset LatexCommand \index{Memory model}
21663 \begin_inset LatexCommand \index{DS390 memory model}
21670 \begin_layout Standard
21671 The only model supported is Flat 24
21672 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21677 This generates code for the 24 bit contiguous addressing mode of the Dallas
21679 In this mode, up to four meg of external RAM or code space can be directly
21681 See the data sheets at www.dalsemi.com for further information on this part.
21686 that the compiler does not generate any code to place the processor into
21687 24 bitmode (although
21691 in the ds390 libraries will do that for you).
21697 \begin_inset LatexCommand \index{Tinibios (DS390)}
21701 , the boot loader or similar code must ensure that the processor is in 24
21702 bit contiguous addressing mode before calling the SDCC startup code.
21713 \begin_layout Standard
21724 option, variables will by default be placed into the XDATA segment.
21729 Segments may be placed anywhere in the 4 meg address space using the usual
21734 \begin_layout Standard
21744 Note that if any segments are located above 64K, the -r flag must be passed
21745 to the linker to generate the proper segment relocations, and the Intel
21746 HEX output format must be used.
21747 The -r flag can be passed to the linker by using the option
21751 on the SDCC command line.
21752 However, currently the linker can not handle code segments > 64k.
21755 \begin_layout Section
21757 \begin_inset LatexCommand \label{sec:Pragmas}
21762 \begin_inset LatexCommand \index{Pragmas}
21769 \begin_layout Standard
21770 Pragmas are used to turn on and/or off certain compiler options.
21771 Some of them are closely related to corresponding command-line options
21773 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21779 Pragmas should be placed before and/or after a function, placing pragmas
21780 inside a function body could have unpredictable results.
21785 following #pragma directives:
21788 \begin_layout Itemize
21794 \begin_inset LatexCommand \index{\#pragma save}
21798 - this will save most current options to the save/restore stack.
21799 See #pragma\InsetSpace ~
21803 \begin_layout Itemize
21809 \begin_inset LatexCommand \index{\#pragma restore}
21813 - will restore saved options from the last save.
21814 saves & restores can be nested.
21815 SDCC uses a save/restore stack: save pushes current options to the stack,
21816 restore pulls current options from the stack.
21817 See #pragma\InsetSpace ~
21823 \begin_layout Itemize
21829 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21834 \begin_inset LatexCommand \index{function prologue}
21838 function1[,function2[,function3...]]
21839 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21843 - The compiler by default uses a caller saves convention for register saving
21844 across function calls, however this can cause unnecessary register pushing
21846 \begin_inset LatexCommand \index{push/pop}
21850 when calling small functions from larger functions.
21851 This option can be used to switch off the register saving convention for
21852 the function names specified.
21853 The compiler will not save registers when calling these functions, extra
21854 code need to be manually inserted at the entry and exit for these functions
21855 to save and restore the registers used by these functions, this can SUBSTANTIAL
21856 LY reduce code and improve run time performance of the generated code.
21857 In the future the compiler (with inter procedural analysis) may be able
21858 to determine the appropriate scheme to use for each function call.
21863 \begin_layout Standard
21872 -callee-saves command line option is used (see page
21873 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21877 ), the function names specified in #pragma\InsetSpace ~
21879 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21883 is appended to the list of functions specified in the command line.
21886 \begin_layout Itemize
21892 \begin_inset LatexCommand \index{\#pragma exclude}
21896 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21897 of pairs of push/pop
21898 \begin_inset LatexCommand \index{push/pop}
21907 \begin_inset LatexCommand \index{interrupt}
21920 The directive should be placed immediately before the ISR function definition
21921 and it affects ALL ISR functions following it.
21922 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21923 exclude\InsetSpace ~
21925 \begin_inset LatexCommand \index{\#pragma exclude}
21930 See also the related keyword _naked
21931 \begin_inset LatexCommand \index{\_naked}
21936 \begin_inset LatexCommand \index{\_\_naked}
21943 \begin_layout Itemize
21949 \begin_inset LatexCommand \index{pedantic}
21954 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21959 \begin_inset LatexCommand \label{ite:less_pedantic}
21963 - the compiler will not warn you anymore for obvious mistakes, you're on
21965 See also the command line option -
21969 \begin_layout Standard
21979 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21986 More specifically, the following warnings will be disabled:
21988 comparison is always [true/false] due to limited range of data type
21992 overflow in implicit constant conversion
21994 (158); [the (in)famous]
21996 conditional flow changed by optimizer: so said EVELYN the modified DOG
22000 function '[function name]' must return value
22005 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
22006 level) are disabled, too, namely:
22009 \begin_inset Note Note
22012 \begin_layout Standard
22013 dunno what comes here - this warning appears to be unused altogether
22022 [left/right] shifting more than size of object changed to zero
22030 integer overflow in expression
22034 unmatched #pragma save and #pragma restore
22038 comparison of 'signed char' with 'unsigned char' requires promotion to int
22042 ISO C90 does not support flexible array members
22046 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
22050 \begin_inset Note Note
22053 \begin_layout Standard
22054 appears to be always blank - what was supposed to be here?
22063 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
22064 complexity [number]
22069 \begin_layout Itemize
22075 \begin_inset LatexCommand \index{\#pragma disable\_warning}
22079 - the compiler will not warn you anymore about warning number <nnnn>.
22082 \begin_layout Itemize
22088 \begin_inset LatexCommand \index{\#pragma nogcse}
22092 - will stop global common subexpression elimination.
22095 \begin_layout Itemize
22101 \begin_inset LatexCommand \index{\#pragma noinduction}
22105 - will stop loop induction optimizations.
22108 \begin_layout Itemize
22114 \begin_inset LatexCommand \index{\#pragma noinvariant}
22118 - will not do loop invariant optimizations.
22119 For more details see Loop Invariants in section
22120 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
22127 \begin_layout Itemize
22133 \begin_inset LatexCommand \index{\#pragma noiv}
22137 - Do not generate interrupt
22138 \begin_inset LatexCommand \index{interrupt}
22143 \begin_inset LatexCommand \index{interrupt vector table}
22147 entries for all ISR functions defined after the pragma.
22148 This is useful in cases where the interrupt vector table must be defined
22149 manually, or when there is a secondary, manually defined interrupt vector
22151 for the autovector feature of the Cypress EZ-USB FX2).
22152 More elegantly this can be achieved by obmitting the optional interrupt
22153 number after the interrupt keyword, see section
22154 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
22162 \begin_layout Itemize
22168 \begin_inset LatexCommand \index{\#pragma nojtbound}
22172 - will not generate code for boundary value checking, when switch statements
22173 are turned into jump-tables (dangerous).
22174 For more details see section
22175 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
22182 \begin_layout Itemize
22188 \begin_inset LatexCommand \index{\#pragma noloopreverse}
22192 - Will not do loop reversal optimization
22195 \begin_layout Itemize
22201 \begin_inset LatexCommand \index{\#pragma nooverlay}
22205 - the compiler will not overlay the parameters and local variables of a
22209 \begin_layout Itemize
22215 \begin_inset LatexCommand \index{\#pragma stackauto}
22223 \begin_layout Standard
22233 \begin_inset LatexCommand \index{-\/-stack-auto}
22238 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
22242 Parameters and Local Variables.
22245 \begin_layout Itemize
22251 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
22255 - The compiler will optimize code generation towards fast code, possibly
22256 at the expense of code size.
22257 Currently this has little effect.
22260 \begin_layout Itemize
22266 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
22270 - The compiler will optimize code generation towards compact code, possibly
22271 at the expense of code speed.
22272 Currently this has little effect.
22275 \begin_layout Itemize
22281 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
22285 - The compiler will attempt to generate code that is both compact and fast,
22286 as long as meeting one goal is not a detriment to the other (this is the
22291 \begin_layout Itemize
22297 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
22301 - Generally follow the C89 standard, but allow SDCC features that conflict
22302 with the standard (default).
22305 \begin_layout Itemize
22311 \begin_inset LatexCommand \index{\#pragma std\_c89}
22315 - Follow the C89 standard and disable SDCC features that conflict with the
22319 \begin_layout Itemize
22325 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
22329 - Generally follow the C99 standard, but allow SDCC features that conflict
22330 with the standard (incomplete support).
22333 \begin_layout Itemize
22339 \begin_inset LatexCommand \index{\#pragma std\_c99}
22343 - Follow the C99 standard and disable SDCC features that conflict with the
22344 standard (incomplete support).
22347 \begin_layout Itemize
22353 \begin_inset LatexCommand \index{\#pragma codeseg}
22357 - Use this name (max.
22358 8 characters) for the code segment.
22363 \begin_layout Standard
22375 \begin_layout Itemize
22381 \begin_inset LatexCommand \index{\#pragma constseg}
22385 - Use this name (max.
22386 8 characters) for the const segment.
22391 \begin_layout Standard
22403 \begin_layout Standard
22404 The preprocessor SDCPP
22405 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
22409 supports the following #pragma directives:
22412 \begin_layout Itemize
22415 pedantic_parse_number
22418 \begin_inset LatexCommand \index{pedantic}
22423 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22428 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
22432 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
22433 properly and the macro LO_B(3) gets expanded.
22439 \begin_layout Standard
22448 -pedantic-parse-number command line option
22449 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
22456 Below is an example on how to use this pragma.
22459 Note: this functionality is not in conformance with standard!
22462 \begin_layout Verse
22465 #pragma pedantic_parse_number +
22466 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22474 #define LO_B(x) ((x) & 0xff)
22478 unsigned char foo(void)
22485 unsigned char c=0xfe-LO_B(3)
22500 \begin_layout Itemize
22506 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22510 (+ | -) - switch _asm _endasm block preprocessing on / off.
22512 You use this prama to define multilines of assembly code.
22513 This will prevent the preprocessor from changing the formating required
22515 Below is an example on how to use this pragma.
22518 \begin_layout Verse
22521 #pragma preproc_asm -
22522 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22528 #define MYDELAY _asm
22533 nop ;my assembly comment...
22547 #pragma preproc_asm
22578 \begin_layout Itemize
22584 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22588 (+ | -) - Allow "naked" hash in macro definition, for example:
22592 #define DIR_LO(x) #(x & 0xff)
22597 Below is an example on how to use this pragma.
22600 \begin_layout Verse
22603 #pragma preproc_asm +
22605 #pragma sdcc_hash +
22606 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22621 mov R6_B3, #(x & 0xff)
22628 mov R7_B3, #((x >> 8) & 0xff)
22652 \begin_layout Standard
22653 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22654 ons which might cause the compiler to generate extra stack and/or data space
22655 to store compiler generated temporary variables.
22656 This usually happens in large functions.
22657 Pragma directives should be used as shown in the following example, they
22658 are used to control options and optimizations for a given function.
22662 \begin_layout Verse
22666 \begin_inset LatexCommand \index{\#pragma save}
22677 /* save the current settings */
22680 \begin_inset LatexCommand \index{\#pragma nogcse}
22689 /* turnoff global subexpression elimination */
22691 #pragma noinduction
22692 \begin_inset LatexCommand \index{\#pragma noinduction}
22696 /* turn off induction optimizations */
22719 \begin_inset LatexCommand \index{\#pragma restore}
22723 /* turn the optimizations back on */
22726 \begin_layout Standard
22727 The compiler will generate a warning message when extra space is allocated.
22728 It is strongly recommended that the save and restore pragmas be used when
22729 changing options for a function.
22738 \begin_layout Section
22739 Defines Created by the Compiler
22742 \begin_layout Standard
22743 The compiler creates the following #defines
22744 \begin_inset LatexCommand \index{\#defines}
22749 \begin_inset LatexCommand \index{Defines created by the compiler}
22758 \begin_layout Standard
22759 \begin_inset Tabular
22760 <lyxtabular version="3" rows="15" columns="2">
22762 <column alignment="left" valignment="top" leftline="true" width="3in">
22763 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22764 <row topline="true" bottomline="true">
22765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22768 \begin_layout Standard
22776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22779 \begin_layout Standard
22788 <row topline="true">
22789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22792 \begin_layout Standard
22794 \begin_inset LatexCommand \index{SDCC}
22803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22806 \begin_layout Standard
22808 Since version 2.5.6 the version number as an int (ex.
22815 <row topline="true">
22816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22819 \begin_layout Standard
22821 \begin_inset LatexCommand \index{SDCC\_mcs51}
22826 \begin_inset LatexCommand \index{SDCC\_ds390}
22831 \begin_inset LatexCommand \index{SDCC\_z80}
22840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22843 \begin_layout Standard
22844 depending on the model used (e.g.: -mds390)
22850 <row topline="true">
22851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22854 \begin_layout Standard
22856 \begin_inset LatexCommand \index{\_\_mcs51}
22861 \begin_inset LatexCommand \index{\_\_ds390}
22866 \begin_inset LatexCommand \index{\_\_hc08}
22871 \begin_inset LatexCommand \index{\_\_z80}
22880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22883 \begin_layout Standard
22884 depending on the model used (e.g.
22891 <row topline="true">
22892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22895 \begin_layout Standard
22897 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22909 \begin_layout Standard
22916 \begin_layout Standard
22933 <row topline="true">
22934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22937 \begin_layout Standard
22939 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22951 \begin_layout Standard
22958 \begin_layout Standard
22975 <row topline="true">
22976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22979 \begin_layout Standard
22981 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22993 \begin_layout Standard
23000 \begin_layout Standard
23017 <row topline="true">
23018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23021 \begin_layout Standard
23023 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
23032 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23035 \begin_layout Standard
23042 \begin_layout Standard
23059 <row topline="true">
23060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23063 \begin_layout Standard
23065 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
23074 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23077 \begin_layout Standard
23084 \begin_layout Standard
23101 <row topline="true">
23102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23105 \begin_layout Standard
23107 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
23116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23119 \begin_layout Standard
23130 <row topline="true">
23131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23134 \begin_layout Standard
23136 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23145 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23148 \begin_layout Standard
23159 <row topline="true">
23160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23163 \begin_layout Standard
23165 \begin_inset LatexCommand \index{SDCC\_REVISION}
23174 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23177 \begin_layout Standard
23179 SDCC svn revision number
23185 <row topline="true">
23186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23189 \begin_layout Standard
23190 SDCC_PARMS_IN_BANK1
23191 \begin_inset LatexCommand \index{SDCC\_PARMS\_IN\_BANK1}
23200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23203 \begin_layout Standard
23210 \begin_layout Standard
23227 <row topline="true">
23228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23231 \begin_layout Standard
23233 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23242 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23245 \begin_layout Standard
23252 \begin_layout Standard
23269 <row topline="true" bottomline="true">
23270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23273 \begin_layout Standard
23274 SDCC_INT_LONG_REENT
23275 \begin_inset LatexCommand \index{SDCC\_INT\_LONG\_REENT}
23284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23287 \begin_layout Standard
23294 \begin_layout Standard
23318 \begin_layout Chapter
23319 Notes on supported Processors
23322 \begin_layout Section
23324 \begin_inset LatexCommand \label{sub:MCS51-variants}
23329 \begin_inset LatexCommand \index{MCS51 variants}
23336 \begin_layout Standard
23337 MCS51 processors are available from many vendors and come in many different
23339 While they might differ considerably in respect to Special Function Registers
23340 the core MCS51 is usually not modified or is kept compatible.
23344 \begin_layout Subsection
23345 pdata access by SFR
23348 \begin_layout Standard
23349 With the upcome of devices with internal xdata and flash memory devices
23351 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
23355 as dedicated I/O port is becoming more popular.
23356 Switching the high byte for pdata
23357 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
23361 access which was formerly done by port P2 is then achieved by a Special
23363 \begin_inset LatexCommand \index{sfr}
23368 In well-established MCS51 tradition the address of this
23372 is where the chip designers decided to put it.
23373 Needless to say that they didn't agree on a common name either.
23374 So that the startup code can correctly initialize xdata variables, you
23375 should define an sfr with the name _XPAGE
23378 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
23384 at the appropriate location if the default, port P2, is not used for this.
23388 \begin_layout Verse
23391 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
23395 \begin_layout Verse
23398 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
23403 \begin_layout Verse
23406 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
23410 \begin_layout Verse
23413 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23417 \begin_layout Verse
23420 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23424 \begin_layout Standard
23425 For more exotic implementations further customizations may be needed.
23427 \begin_inset LatexCommand \ref{sub:Startup-Code}
23431 for other possibilities.
23434 \begin_layout Subsection
23435 Other Features available by SFR
23438 \begin_layout Standard
23439 Some MCS51 variants offer features like Double DPTR
23440 \begin_inset LatexCommand \index{DPTR}
23444 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
23445 These are currently not used for the MCS51 port.
23446 If you absolutely need them you can fall back to inline assembly or submit
23450 \begin_layout Subsection
23454 \begin_layout Standard
23456 \begin_inset LatexCommand \index{Bankswitching}
23462 \begin_inset LatexCommand \index{code banking}
23466 ) is a technique to increase the code space above the 64k limit of the 8051.
23469 \begin_layout Subsubsection
23473 \begin_layout Standard
23474 \begin_inset Tabular
23475 <lyxtabular version="3" rows="3" columns="4">
23477 <column alignment="center" valignment="top" width="0">
23478 <column alignment="center" valignment="top" leftline="true" width="0">
23479 <column alignment="center" valignment="top" leftline="true" width="0">
23480 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23481 <row topline="true" bottomline="true">
23482 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23485 \begin_layout Standard
23491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23494 \begin_layout Standard
23500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23503 \begin_layout Standard
23509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23512 \begin_layout Standard
23519 <row topline="true" bottomline="true">
23520 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23523 \begin_layout Standard
23529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23532 \begin_layout Standard
23538 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23541 \begin_layout Standard
23547 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23550 \begin_layout Standard
23558 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23561 \begin_layout Standard
23562 SiLabs C8051F120 example
23567 <cell multicolumn="2" alignment="center" valignment="top" usebox="none">
23570 \begin_layout Standard
23576 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23579 \begin_layout Standard
23585 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23588 \begin_layout Standard
23603 Usually the hardware uses some sfr (an output port or an internal sfr) to
23604 select a bank and put it in the banked area of the memory map.
23605 The selected bank usually becomes active immediately upon assignment to
23606 this sfr and when running inside a bank it will switch out this code it
23607 is currently running.
23608 Therefor you cannot jump or call directly from one bank to another and
23609 need to use a so-called trampoline in the common area.
23610 For SDCC an example trampoline is in crtbank.asm and you may need to change
23611 it to your 8051 derivative or schematic.
23612 The presented code is written for the C8051F120.
23616 When calling a banked function
23617 SDCC will put the LSB of the functions address in register R0, the MSB
23618 in R1 and the bank in R2 and then call this trampoline
23623 The current selected bank is saved on the stack, the new bank is selected
23624 and an indirect jump is made.
23625 When the banked function returns it jumps to
23629 which restores the previous bank and returns to the caller.
23632 \begin_layout Subsubsection
23636 \begin_layout Standard
23637 When writing banked software using SDCC you need to use some special keywords
23639 You also need to take over a bit of work from the linker.
23643 To create a function
23644 that can be called from another bank it requires the keyword
23649 \begin_inset LatexCommand \index{banked}
23654 The caller must see this in the prototype of the callee and the callee
23655 needs it for a proper return.
23656 Called functions within the same bank as the caller do not need the
23660 keyword nor do functions in the common area.
23661 Beware: SDCC does not know or check if functions are in the same bank.
23662 This is your responsibility!
23666 Normally all functions you write end up in
23668 If you want a function explicitly to reside in the common area put it in
23670 This applies for instance to interrupt service routines as they should
23674 \begin_layout Standard
23675 Functions that need to be in a switched bank must be put in a named segment.
23676 The name can be mostly anything upto eight characters (e.g.
23678 To do this you either use -
23682 \begin_layout Standard
23691 -codeseg BANK1 (See
23692 \begin_inset LatexCommand \ref{lyx:-codeseg}
23696 ) on the command line when compiling or #pragma codeseg BANK1 (See
23697 \begin_inset LatexCommand \ref{sec:Pragmas}
23701 ) at the top of the C source file.
23702 The segment name always applies to the whole source file and generated
23703 object so functions for different banks need to be defined in different
23708 When linking your objects you need to tell the linker where
23709 to put your segments.
23710 To do this you use the following command line option to SDCC: -Wl-b BANK1=0x180
23712 \begin_inset LatexCommand \ref{lyx:-Wl option}
23717 This sets the virtual start address of this segment.
23718 It sets the banknumber to 0x01 and maps the bank to 0x8000 and up.
23719 The linker will not check for overflows, again this is your responsibility.
23722 \begin_layout Standard
23723 \begin_inset VSpace bigskip
23729 \begin_layout Section
23733 \begin_layout Standard
23735 \begin_inset LatexCommand \index{DS80C400}
23740 \begin_inset LatexCommand \index{DS400}
23744 microcontroller has a rich set of peripherals.
23745 In its built-in ROM library it includes functions to access some of the
23746 features, among them is a TCP stack with IP4 and IP6 support.
23747 Library headers (currently in beta status) and other files are provided
23751 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
23757 \begin_inset VSpace bigskip
23763 \begin_layout Section
23764 The Z80 and gbz80 port
23767 \begin_layout Standard
23768 SDCC can target both the Zilog Z80
23769 \begin_inset LatexCommand \index{Z80}
23773 and the Nintendo Gameboy's Z80-like gbz80
23774 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
23779 The Z80 port is passed through the same
23782 \begin_inset LatexCommand \index{Regression test}
23789 \begin_inset LatexCommand \ref{sec:Quality-control}
23793 ) as the MCS51 and DS390 ports, so floating point support, support for long
23794 variables and bitfield support is fine.
23795 See mailing lists and forums about interrupt routines.
23798 \begin_layout Standard
23799 As always, the code is the authoritative reference - see z80/ralloc.c and
23802 \begin_inset LatexCommand \index{Z80!stack}
23806 frame is similar to that generated by the IAR Z80 compiler.
23807 IX is used as the base pointer, HL and IY are used as a temporary registers,
23808 and BC and DE are available for holding variables.
23810 \begin_inset LatexCommand \index{Z80!return value}
23814 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
23816 The gbz80 port use the same set of registers for the return values, but
23817 in a different order of significance: E (one byte), DE (two bytes), or
23819 \begin_inset VSpace bigskip
23825 \begin_layout Section
23829 \begin_layout Standard
23830 The port to the Freescale/Motorola HC08
23831 \begin_inset LatexCommand \index{HC08}
23835 family has been added in October 2003, and is still undergoing some basic
23837 The code generator is complete, but the register allocation is still quite
23839 Some of the SDCC's standard C library functions have embedded non-HC08
23840 inline assembly and so are not yet usable.
23843 \begin_layout Standard
23844 The HC08 port passes the regression test suite (see section
23845 \begin_inset LatexCommand \ref{sec:Quality-control}
23850 \begin_inset VSpace bigskip
23856 \begin_layout Section
23858 \begin_inset LatexCommand \index{PIC14}
23865 \begin_layout Standard
23866 The PIC14 port adds support for Microchip
23867 \begin_inset LatexCommand \index{Microchip}
23872 \begin_inset Formula $^{\text{TM}}$
23876 \begin_inset LatexCommand \index{PIC14}
23881 \begin_inset Formula $^{\text{TM}}$
23884 MCUs with 14 bit wide instructions.
23885 This port is not yet mature and still lacks many features.
23886 However, it can work for simple code.
23889 \begin_layout Standard
23890 Currently supported devices include:
23893 \begin_layout Standard
23894 12F: 629, 635, 675, 683
23897 \begin_layout Standard
23901 \begin_layout Standard
23905 \begin_layout Standard
23906 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
23909 \begin_layout Standard
23910 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
23914 \begin_layout Standard
23918 \begin_layout Standard
23919 16CR: 620a, 73, 74, 76, 77
23922 \begin_layout Standard
23923 16F: 616, 627, 627a, 628, 628a, 630, 636, 639, 648, 648a, 676, 684, 685,
23927 \begin_layout Standard
23928 16F: 716, 72, 73, 737, 74, 747, 76, 767, 77, 777, 785
23931 \begin_layout Standard
23932 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
23933 877, 877a, 88, 886, 887
23936 \begin_layout Standard
23937 16F: 913, 914, 916, 917, 946
23940 \begin_layout Standard
23944 \begin_layout Standard
23945 An up-to-date list of currently supported devices can be obtained via
23947 sdcc -mpic14 -phelp foo.c
23949 (foo.c must exist...).
23952 \begin_layout Subsection
23954 \begin_inset LatexCommand \index{code page (pic14)}
23959 \begin_inset LatexCommand \index{Memory bank (pic14)}
23966 \begin_layout Standard
23967 The linker organizes allocation for the code page and RAM banks.
23968 It does not have intimate knowledge of the code flow.
23969 It will put all the code section of a single .asm file into a single code
23971 In order to make use of multiple code pages, separate asm files must be
23973 The compiler assigns all
23977 functions of a single .c file into the same code page.
23981 To get the best results,
23982 follow these guidelines:
23985 \begin_layout Enumerate
23986 Make local functions static, as non static functions require code page selection
23989 Due to the way sdcc handles functions, place called functions prior
23990 to calling functions in the file wherever possible: Otherwise sdcc will
23991 insert unneccessary pagesel directives around the call, believing that
23992 the called function is externally defined.
23995 \begin_layout Enumerate
23996 For devices that have multiple code pages it is more efficient to use the
23997 same number of files as pages: Use up to 4 separate .c files for the 16F877,
23998 but only 2 files for the 16F874.
23999 This way the linker can put the code for each file into different code
24000 pages and there will be less page selection overhead.
24003 \begin_layout Enumerate
24004 And as for any 8 bit micro (especially for PIC14 as they have a very simple
24005 instruction set), use `unsigned char' wherever possible instead of `int'.
24008 \begin_layout Subsection
24009 Adding New Devices to the Port
24012 \begin_layout Standard
24013 Adding support for a new 14
24017 \begin_layout Standard
24026 bit PIC MCU requires the following steps:
24029 \begin_layout Enumerate
24030 Create a new device description.
24032 Each device is described in two files: pic16f*.h
24034 These files primarily define SFRs, structs to access their bits, and symbolic
24035 configuration options.
24036 Both files can be generated from gputils' .inc files using the perl script
24039 support/scripts/inc2h.pl
24042 This file also contains further instructions on how to proceed.
24045 \begin_layout Enumerate
24046 Copy the .h file into SDCC's include path and either add the .c file to your
24047 project or copy it to
24049 device/lib/pic/libdev
24052 Afterwards, rebuild and install the libraries.
24055 \begin_layout Enumerate
24056 Edit pic14devices.txt in SDCC's include path (
24058 device/include/pic/
24060 in the source tree or
24062 /usr/local/share/sdcc/include/pic
24064 after installation).
24066 You need to add a device specification here to make
24067 the memory layout (code banks, RAM, aliased memory regions, ...) known to
24069 Probably you can copy and modify an existing entry.
24070 The file format is documented at the top of the file.
24073 \begin_layout Subsection
24077 \begin_layout Standard
24078 For the interrupt function, use the keyword `__interrupt'
24079 \begin_inset LatexCommand \index{PIC14!interrupt}
24083 with level number of 0 (PIC14 only has 1 interrupt so this number is only
24084 there to avoid a syntax error - it ought to be fixed).
24088 \begin_layout Verse
24091 void Intr(void) __interrupt 0
24097 T0IF = 0; /* Clear timer interrupt */
24102 \begin_layout Subsection
24103 Linking and Assembling
24106 \begin_layout Standard
24107 For assembling you can use either GPUTILS'
24108 \begin_inset LatexCommand \index{gputils (pic tools)}
24112 gpasm.exe or MPLAB's mpasmwin.exe.
24113 GPUTILS are available from
24114 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24119 For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
24120 If you use MPLAB and an interrupt function then the linker script file
24121 vectors section will need to be enlarged to link with mplink.
24132 \begin_layout Verse
24145 sdcc -V -mpic14 -p16f877 -c $<
24149 $(PRJ).hex: $(OBJS)
24159 gplink -m -s $(PRJ).lkr
24160 -o $(PRJ).hex $(OBJS) libsdcc.lib
24163 \begin_layout Standard
24171 \begin_layout Verse
24184 sdcc -S -V -mpic14 -p16f877 $<
24194 mpasmwin /q /o $*.asm
24198 $(PRJ).hex: $(OBJS)
24209 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
24212 \begin_layout Standard
24213 Please note that indentations within a
24217 have to be done with a tabulator character.
24220 \begin_layout Subsection
24221 Command-Line Options
24224 \begin_layout Standard
24225 Besides the switches common to all SDCC backends, the PIC14 port accepts
24226 the following options (for an updated list see sdcc -
24230 \begin_layout Standard
24242 \begin_layout Description
24247 \begin_layout Standard
24257 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
24261 emit debug info in assembly output
24264 \begin_layout Description
24269 \begin_layout Standard
24279 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
24283 disable (slightly faulty) optimization on pCode
24286 \begin_layout Description
24291 \begin_layout Standard
24301 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
24305 sets the lowest address of the argument passing stack (defaults to a suitably
24306 large shared databank to reduce BANKSEL overhead)
24309 \begin_layout Description
24314 \begin_layout Standard
24324 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
24328 sets the size if the argument passing stack (default: 16, minimum: 4)
24331 \begin_layout Subsection
24332 Environment Variables
24335 \begin_layout Standard
24336 The PIC14 port recognizes the following environment variables:
24339 \begin_layout Description
24340 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
24341 register (the ones called r0xNNNN) in a section of its own.
24342 By default (if this variable is unset), sdcc tries to cluster registers
24343 in sections in order to reduce the BANKSEL overhead when accessing them.
24346 \begin_layout Subsection
24350 \begin_layout Standard
24351 The PIC14 library currently only contains support routines required by the
24352 compiler to implement multiplication, division, and floating point support.
24353 No libc-like replacement is available at the moment, though many of the
24354 common sdcc library sources (in
24358 ) should also compile with the PIC14 port.
24361 \begin_layout Subsubsection
24362 error: missing definition for symbol ``__gptrget1''
24365 \begin_layout Standard
24366 The PIC14 port uses library routines to provide more complex operations
24367 like multiplication, division/modulus and (generic) pointer dereferencing.
24368 In order to add these routines to your project, you must link with PIC14's
24374 For single source file projects this is done automatically, more complex
24379 to the linker's arguments.
24380 Make sure you also add an include path for the library (using the -I switch
24384 \begin_layout Subsubsection
24385 Processor mismatch in file ``XXX''.
24388 \begin_layout Standard
24389 This warning can usually be ignored due to the very good compatibility amongst
24394 \begin_layout Standard
24404 \begin_inset LatexCommand \index{PIC14}
24411 \begin_layout Standard
24412 You might also consider recompiling the library for your specific device
24413 by changing the ARCH=p16f877 (default target) entry in
24415 device/lib/pic/Makefile.in
24419 device/lib/pic/Makefile
24421 to reflect your device.
24422 This might even improve performance for smaller devices as unneccesary
24423 BANKSELs might be removed.
24426 \begin_layout Subsection
24430 \begin_layout Subsubsection
24434 \begin_layout Standard
24435 Functions with variable argument lists (like printf) are not yet supported.
24436 Similarly, taking the address of the first argument passed into a function
24437 does not work: It is currently passed in WREG and has no address...
24440 \begin_layout Subsubsection
24441 Regression tests fail
24444 \begin_layout Standard
24445 Though the small subset of regression tests in src/regression passes, SDCC
24446 regression test suite does not, indicating that there are still major bugs
24448 However, many smaller projects have successfully used SDCC in the past...
24451 \begin_layout Standard
24459 \begin_layout Section
24461 \begin_inset LatexCommand \index{PIC16}
24468 \begin_layout Standard
24469 The PIC16 port adds support for Microchip
24470 \begin_inset LatexCommand \index{Microchip}
24475 \begin_inset Formula $^{\text{TM}}$
24479 \begin_inset LatexCommand \index{PIC}
24484 \begin_inset Formula $^{\text{TM}}$
24487 MCUs with 16 bit wide instructions.
24488 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
24489 ; devices supported by the port include:
24492 \begin_layout Standard
24493 18F: 242, 248, 252, 258, 442, 448, 452, 458
24496 \begin_layout Standard
24500 \begin_layout Standard
24501 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 24j10, 2525, 2550, 25j10,
24505 \begin_layout Standard
24506 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 44j10, 4520, 4525, 4550,
24510 \begin_layout Standard
24511 18F: 6520, 6620, 6680, 6720
24514 \begin_layout Standard
24515 18F: 8520, 8620, 8680, 8720
24518 \begin_layout Subsection
24522 \begin_layout Standard
24523 PIC16 port supports the standard command line arguments as supposed, with
24524 the exception of certain cases that will be mentioned in the following
24528 \begin_layout Description
24533 \begin_layout Standard
24543 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
24551 \begin_layout Standard
24563 \begin_layout Description
24568 \begin_layout Standard
24577 -fommit-frame-pointer
24578 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
24582 Frame pointer will be omitted when the function uses no local variables.
24585 \begin_layout Subsection
24586 Port Specific Options
24587 \begin_inset LatexCommand \index{Options PIC16}
24594 \begin_layout Standard
24595 The port specific options appear after the global options in the sdcc -
24599 \begin_layout Standard
24611 \begin_layout Subsubsection
24612 Code Generation Options
24615 \begin_layout Standard
24616 These options influence the generated assembler code.
24619 \begin_layout Description
24624 \begin_layout Standard
24633 -pstack-model=[model] Used in conjuction with the command above.
24634 Defines the stack model to be used, valid stack models are:
24639 \labelwidthstring 00.00.0000
24644 Selects small stack model.
24645 8 bit stack and frame pointers.
24646 Supports 256 bytes stack size.
24650 \labelwidthstring 00.00.0000
24655 Selects large stack model.
24656 16 bit stack and frame pointers.
24657 Supports 65536 bytes stack size.
24661 \begin_layout Description
24666 \begin_layout Standard
24675 -pno-banksel Do not generate BANKSEL assembler directives.
24678 \begin_layout Description
24683 \begin_layout Standard
24692 -extended Enable extended instruction set/literal offset addressing mode.
24696 \begin_layout Subsubsection
24697 Optimization Options
24700 \begin_layout Description
24705 \begin_layout Standard
24714 -obanksel=n Set optimization level for inserting BANKSELs.
24721 \labelwidthstring 00.00.0000
24726 \labelwidthstring 00.00.0000
24727 1 checks previous used register and if it is the same then does not emit
24728 BANKSEL, accounts only for labels.
24732 \labelwidthstring 00.00.0000
24733 2 tries to check the location of (even different) symbols and removes BANKSELs
24734 if they are in the same bank.
24739 Important: There might be problems if the linker script has data sections
24740 across bank borders!
24744 \begin_layout Description
24749 \begin_layout Standard
24758 -denable-peeps Force the usage of peepholes.
24762 \begin_layout Description
24767 \begin_layout Standard
24776 -optimize-goto Try to use (conditional) BRA instead of GOTO.
24779 \begin_layout Description
24784 \begin_layout Standard
24793 -optimize-cmp Try to optimize some compares.
24796 \begin_layout Description
24801 \begin_layout Standard
24810 -optimize-df Analyze the dataflow of the generated code and improve it.
24813 \begin_layout Subsubsection
24817 \begin_layout Description
24822 \begin_layout Standard
24831 -asm= Sets the full path and name of an external assembler to call.
24834 \begin_layout Description
24839 \begin_layout Standard
24849 \begin_inset LatexCommand \index{PIC16!MPLAB}
24853 compatibility option.
24854 Currently only suppresses special gpasm directives.
24857 \begin_layout Subsubsection
24861 \begin_layout Description
24866 \begin_layout Standard
24875 -link= Sets the full path and name of an external linker to call.
24878 \begin_layout Description
24883 \begin_layout Standard
24892 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
24893 unitialized data variables with [kword].
24894 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
24897 \begin_layout Description
24902 \begin_layout Standard
24911 -ivt-loc=n Place the interrupt vector table at address
24916 Useful for bootloaders.
24919 \begin_layout Description
24924 \begin_layout Standard
24933 -nodefaultlibs Do not link default libraries when linking.
24936 \begin_layout Description
24941 \begin_layout Standard
24950 -use-crt= Use a custom run-time module instead of the defaults.
24953 \begin_layout Description
24958 \begin_layout Standard
24967 -no-crt Don't link the default run-time modules
24970 \begin_layout Subsubsection
24974 \begin_layout Standard
24975 Debugging options enable extra debugging information in the output files.
24978 \begin_layout Description
24983 \begin_layout Standard
24992 -debug-xtra Similar to -
24996 \begin_layout Standard
25006 \begin_inset LatexCommand \index{-\/-debug}
25010 , but dumps more information.
25013 \begin_layout Description
25018 \begin_layout Standard
25027 -debug-ralloc Force register allocator to dump <source>.d file with debugging
25029 <source> is the name of the file being compiled.
25032 \begin_layout Description
25037 \begin_layout Standard
25046 -pcode-verbose Enable pcode debugging information in translation.
25049 \begin_layout Description
25054 \begin_layout Standard
25063 -calltree Dump call tree in .calltree file.
25066 \begin_layout Description
25071 \begin_layout Standard
25080 -gstack Trace push/pops for stack pointer overflow.
25083 \begin_layout Subsection
25084 Enviroment Variables
25087 \begin_layout Standard
25088 There is a number of enviromental variables that can be used when running
25089 SDCC to enable certain optimizations or force a specific program behaviour.
25090 these variables are primarily for debugging purposes so they can be enabled/dis
25094 \begin_layout Standard
25095 Currently there is only two such variables available:
25098 \begin_layout Description
25099 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
25100 bitfields is optimized by directly loading FSR0 with the address of the
25101 bitfield structure.
25102 Normally SDCC will cast the bitfield structure to a bitfield pointer and
25104 This step saves data ram and code space for functions that make heavy use
25106 (i.e., 80 bytes of code space are saved when compiling malloc.c with this
25111 \begin_layout Description
25112 NO_REG_OPT Do not perform pCode registers optimization.
25113 This should be used for debugging purposes.
25114 If bugs in the pcode optimizer are found, users can benefit from temporarily
25115 disabling the optimizer until the bug is fixed.
25118 \begin_layout Subsection
25119 Preprocessor Macros
25122 \begin_layout Standard
25124 \begin_inset LatexCommand \index{PIC16}
25128 port defines the following preprocessor macros while translating a source.
25131 \begin_layout Standard
25133 \begin_inset Tabular
25134 <lyxtabular version="3" rows="6" columns="2">
25136 <column alignment="center" valignment="top" leftline="true" width="0">
25137 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25138 <row topline="true" bottomline="true">
25139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25142 \begin_layout Standard
25148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25151 \begin_layout Standard
25158 <row topline="true">
25159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25162 \begin_layout Standard
25168 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25171 \begin_layout Standard
25172 Port identification
25178 <row topline="true">
25179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25182 \begin_layout Standard
25187 \begin_layout Standard
25201 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25204 \begin_layout Standard
25205 Port identification (same as above)
25211 <row topline="true">
25212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25215 \begin_layout Standard
25221 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25224 \begin_layout Standard
25225 MCU Identification.
25230 is the microcontrol identification number, i.e.
25237 <row topline="true">
25238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25241 \begin_layout Standard
25246 \begin_layout Standard
25260 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25263 \begin_layout Standard
25264 MCU Identification (same as above)
25270 <row topline="true" bottomline="true">
25271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25274 \begin_layout Standard
25280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25283 \begin_layout Standard
25284 nnn = SMALL or LARGE respectively according to the stack model used
25297 \begin_layout Standard
25298 In addition the following macros are defined when calling assembler:
25301 \begin_layout Standard
25303 \begin_inset Tabular
25304 <lyxtabular version="3" rows="4" columns="2">
25306 <column alignment="center" valignment="top" leftline="true" width="0">
25307 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25308 <row topline="true" bottomline="true">
25309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25312 \begin_layout Standard
25318 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25321 \begin_layout Standard
25328 <row topline="true">
25329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25332 \begin_layout Standard
25338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25341 \begin_layout Standard
25342 MCU Identification.
25347 is the microcontrol identification number, i.e.
25354 <row topline="true">
25355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25358 \begin_layout Standard
25364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25367 \begin_layout Standard
25368 nnn = SMALL or LARGE respectively according to the memory model used for
25375 <row topline="true" bottomline="true">
25376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25379 \begin_layout Standard
25385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25388 \begin_layout Standard
25389 nnn = SMALL or LARGE respectively according to the stack model used
25402 \begin_layout Subsection
25406 \begin_layout Standard
25408 \begin_inset LatexCommand \index{PIC16}
25412 port uses the following directories for searching header files and libraries.
25415 \begin_layout Standard
25417 \begin_inset Tabular
25418 <lyxtabular version="3" rows="3" columns="4">
25420 <column alignment="center" valignment="top" leftline="true" width="0">
25421 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25422 <column alignment="center" valignment="top" width="0">
25423 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25424 <row topline="true" bottomline="true">
25425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25428 \begin_layout Standard
25434 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25437 \begin_layout Standard
25443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25446 \begin_layout Standard
25452 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25455 \begin_layout Standard
25462 <row topline="true">
25463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25466 \begin_layout Standard
25467 PREFIX/sdcc/include/pic16
25472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25475 \begin_layout Standard
25476 PIC16 specific headers
25481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25484 \begin_layout Standard
25490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25493 \begin_layout Standard
25500 <row topline="true" bottomline="true">
25501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25504 \begin_layout Standard
25505 PREFIX/sdcc/lib/pic16
25510 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25513 \begin_layout Standard
25514 PIC16 specific libraries
25519 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25522 \begin_layout Standard
25528 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25531 \begin_layout Standard
25545 \begin_layout Subsection
25547 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
25554 \begin_layout Standard
25556 \begin_inset LatexCommand \index{PIC16}
25560 port currently supports the following pragmas:
25563 \begin_layout Description
25565 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
25569 This forces the code generator to initialize the stack & frame pointers
25570 at a specific address.
25571 This is an ad hoc solution for cases where no STACK directive is available
25572 in the linker script or gplink is not instructed to create a stack section.
25575 stack pragma should be used only once in a project.
25576 Multiple pragmas may result in indeterminate behaviour of the program.
25580 \begin_layout Standard
25581 The old format (ie.
25582 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
25583 cross page boundaries (or even exceed the available data RAM) and crash
25585 Make sure that stack does not cross page boundaries when using the SMALL
25593 The format is as follows:
25598 \begin_layout LyX-Code
25599 #pragma stack bottom_address [stack_size]
25604 \begin_layout Standard
25609 is the lower bound of the stack section.
25610 The stack pointer initially will point at address (bottom_address+stack_size-1).
25613 \begin_layout LyX-Code
25617 \begin_layout LyX-Code
25621 \begin_layout LyX-Code
25622 /* initializes stack of 100 bytes at RAM address 0x200 */
25625 \begin_layout LyX-Code
25626 #pragma stack 0x200 100
25629 \begin_layout Standard
25630 If the stack_size field is omitted then a stack is created with the default
25632 This size might be enough for most programs, but its not enough for operations
25633 with deep function nesting or excessive stack usage.
25636 \begin_layout Description
25638 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
25642 Force a function to a static FLASH address.
25645 \begin_layout LyX-Code
25649 \begin_layout LyX-Code
25653 \begin_layout LyX-Code
25654 /* place function test_func at 0x4000 */
25657 \begin_layout LyX-Code
25658 #pragma code test_func 0x4000
25661 \begin_layout LyX-Code
25665 \begin_layout Description
25666 library instructs the linker to use a library module.
25671 \begin_layout LyX-Code
25672 #pragma library module_name
25675 \begin_layout Standard
25680 can be any library or object file (including its path).
25681 Note that there are four reserved keywords which have special meaning.
25685 \begin_layout Standard
25687 \begin_inset Tabular
25688 <lyxtabular version="3" rows="6" columns="3">
25690 <column alignment="center" valignment="top" leftline="true" width="0">
25691 <column alignment="block" valignment="top" leftline="true" width="20page%">
25692 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
25693 <row topline="true" bottomline="true">
25694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25697 \begin_layout Standard
25703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25706 \begin_layout Standard
25712 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25715 \begin_layout Standard
25722 <row topline="true">
25723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25726 \begin_layout Standard
25734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25737 \begin_layout Standard
25738 ignore all library pragmas
25743 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25746 \begin_layout Standard
25755 <row topline="true">
25756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25759 \begin_layout Standard
25767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25770 \begin_layout Standard
25776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25779 \begin_layout Standard
25790 <row topline="true">
25791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25794 \begin_layout Standard
25802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25805 \begin_layout Standard
25806 link the Math libarary
25811 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25814 \begin_layout Standard
25825 <row topline="true">
25826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25829 \begin_layout Standard
25837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25840 \begin_layout Standard
25841 link the I/O library
25846 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25849 \begin_layout Standard
25860 <row topline="true" bottomline="true">
25861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25864 \begin_layout Standard
25872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25875 \begin_layout Standard
25876 link the debug library
25881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25884 \begin_layout Standard
25901 * is the device number, i.e.
25902 452 for PIC18F452 MCU.
25905 \begin_layout Standard
25906 This feature allows for linking with specific libraries withoug having to
25907 explicit name them in the command line.
25912 keyword will reject all modules specified by the library pragma.
25915 \begin_layout Description
25916 udata The pragma udata instructs the compiler to emit code so that linker
25917 will place a variable at a specific memory bank.
25920 \begin_layout LyX-Code
25924 \begin_layout LyX-Code
25928 \begin_layout LyX-Code
25929 /* places variable foo at bank2 */
25932 \begin_layout LyX-Code
25933 #pragma udata bank2 foo
25936 \begin_layout LyX-Code
25940 \begin_layout Standard
25941 In order for this pragma to work extra SECTION directives should be added
25942 in the .lkr script.
25943 In the following example a sample .lkr file is shown:
25946 \begin_layout LyX-Code
25950 \begin_layout LyX-Code
25951 // Sample linker script for the PIC18F452 processor
25954 \begin_layout LyX-Code
25958 \begin_layout LyX-Code
25959 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
25962 \begin_layout LyX-Code
25963 CODEPAGE NAME=page START=0x2A END=0x7FFF
25966 \begin_layout LyX-Code
25967 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
25970 \begin_layout LyX-Code
25971 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
25974 \begin_layout LyX-Code
25975 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
25978 \begin_layout LyX-Code
25979 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
25982 \begin_layout LyX-Code
25983 ACCESSBANK NAME=accessram START=0x0 END=0x7F
25986 \begin_layout LyX-Code
25990 \begin_layout LyX-Code
25991 DATABANK NAME=gpr0 START=0x80 END=0xFF
25994 \begin_layout LyX-Code
25995 DATABANK NAME=gpr1 START=0x100 END=0x1FF
25998 \begin_layout LyX-Code
25999 DATABANK NAME=gpr2 START=0x200 END=0x2FF
26002 \begin_layout LyX-Code
26003 DATABANK NAME=gpr3 START=0x300 END=0x3FF
26006 \begin_layout LyX-Code
26007 DATABANK NAME=gpr4 START=0x400 END=0x4FF
26010 \begin_layout LyX-Code
26011 DATABANK NAME=gpr5 START=0x500 END=0x5FF
26014 \begin_layout LyX-Code
26015 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
26018 \begin_layout LyX-Code
26022 \begin_layout LyX-Code
26023 SECTION NAME=CONFIG ROM=config
26026 \begin_layout LyX-Code
26030 \begin_layout LyX-Code
26031 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
26034 \begin_layout LyX-Code
26035 SECTION NAME=bank1 RAM=gpr1 # should be added to link
26038 \begin_layout LyX-Code
26039 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
26042 \begin_layout LyX-Code
26043 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
26046 \begin_layout LyX-Code
26047 SECTION NAME=bank4 RAM=gpr4
26050 \begin_layout LyX-Code
26051 SECTION NAME=bank5 RAM=gpr5
26054 \begin_layout Standard
26055 The linker will recognise the section name set in the pragma statement and
26056 will position the variable at the memory bank set with the RAM field at
26057 the SECTION line in the linker script file.
26060 \begin_layout Subsection
26062 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
26069 \begin_layout Standard
26070 There is one main header file
26071 \begin_inset LatexCommand \index{PIC16!Header files}
26075 that can be included to the source files using the pic16
26076 \begin_inset LatexCommand \index{PIC16}
26086 This header file contains the definitions for the processor special registers,
26087 so it is necessary if the source accesses them.
26088 It can be included by adding the following line in the beginning of the
26092 \begin_layout LyX-Code
26093 #include <pic18fregs.h>
26096 \begin_layout Standard
26097 The specific microcontroller is selected within the pic18fregs.h automatically,
26098 so the same source can be used with a variety of devices.
26101 \begin_layout Subsection
26105 \begin_layout Standard
26107 \begin_inset LatexCommand \index{PIC16!Libraries}
26112 \begin_inset LatexCommand \index{PIC16}
26116 port depends on are the microcontroller device libraries which contain
26117 the symbol definitions for the microcontroller special function registers.
26118 These libraries have the format pic18fxxxx.lib, where
26122 is the microcontroller identification number.
26123 The specific library is selected automatically by the compiler at link
26124 stage according to the selected device.
26127 \begin_layout Standard
26128 Libraries are created with gplib which is part of the gputils package
26129 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
26136 \begin_layout Subsubsection*
26137 Building the libraries
26140 \begin_layout Standard
26141 Before using SDCC/pic16 there are some libraries that need to be compiled.
26142 This process is not done automatically by SDCC since not all users use
26143 SDCC for pic16 projects.
26144 So each user should compile the libraries separately.
26147 \begin_layout Standard
26148 The steps to compile the pic16 libraries under Linux and Mac OS X are:
26151 \begin_layout LyX-Code
26152 cd device/lib/pic16
26155 \begin_layout LyX-Code
26159 \begin_layout LyX-Code
26163 \begin_layout LyX-Code
26167 \begin_layout LyX-Code
26171 \begin_layout LyX-Code
26172 su -c 'make install' # install the libraries, you need the root password
26175 \begin_layout Standard
26176 If you need to install the headers too, do:
26179 \begin_layout LyX-Code
26183 \begin_layout LyX-Code
26184 su -c 'make install' # install the headers, you need the root password
26187 \begin_layout Standard
26188 There exist a special target to build the I/O libraries.
26189 This target is not automatically build because it will build the I/O library
26195 This way building will take quite a lot of time.
26196 Users are advised to edit the
26198 device/lib/pic16/pics.build
26200 file and then execute:
26203 \begin_layout LyX-Code
26207 \begin_layout Subsection
26208 Adding New Devices to the Port
26211 \begin_layout Standard
26212 Adding support for a new 16
26216 \begin_layout Standard
26225 bit PIC MCU requires the following steps:
26228 \begin_layout Enumerate
26229 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
26233 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
26237 \begin_layout Enumerate
26240 mv picDEVICE.h /path/to/sdcc/device/include/pic16
26243 \begin_layout Enumerate
26246 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
26249 \begin_layout Enumerate
26252 /path/to/sdcc/device/lib/pic16/pics.all
26260 Note: No 18f prefix here!
26263 \begin_layout Enumerate
26266 /path/to/sdcc/device/lib/pic16/libio/*.ignore
26270 Add your DEVICE if it does not compile in
26285 \begin_layout Enumerate
26288 /path/to/sdcc/device/include/pic16/pic18fregs.h
26291 The file format is self-explanatory, just add
26295 #elif defined(picDEVICE)
26297 # include <picDEVICE.h>
26301 at the right place (keep it sorted).
26304 \begin_layout Enumerate
26307 /path/to/sdcc/src/pic16/devices.inc
26310 Copy and modify an existing entry and insert it at the correct place (keep
26312 The file is hardly documented, look at the entries for the 18f2221...
26315 \begin_layout Enumerate
26316 Recompile SDCC, including the pic16 libraries.
26319 \begin_layout Subsection
26323 \begin_layout Standard
26324 The following memory models are supported by the PIC16 port:
26327 \begin_layout Itemize
26331 \begin_layout Itemize
26335 \begin_layout Standard
26336 Memory model affects the default size of pointers within the source.
26337 The sizes are shown in the next table:
26340 \begin_layout Standard
26342 \begin_inset Tabular
26343 <lyxtabular version="3" rows="3" columns="3">
26345 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26346 <column alignment="center" valignment="top" leftline="true" width="0">
26347 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26348 <row topline="true" bottomline="true">
26349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26352 \begin_layout Standard
26353 Pointer sizes according to memory model
26358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26361 \begin_layout Standard
26367 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26370 \begin_layout Standard
26377 <row topline="true" bottomline="true">
26378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26381 \begin_layout Standard
26387 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26390 \begin_layout Standard
26396 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26399 \begin_layout Standard
26406 <row topline="true" bottomline="true">
26407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26410 \begin_layout Standard
26416 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
26419 \begin_layout Standard
26425 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26428 \begin_layout Standard
26442 \begin_layout Standard
26443 It is advisable that all sources within a project are compiled with the
26445 If one wants to override the default memory model, this can be done by
26446 declaring a pointer as
26455 Far selects large memory model's pointers, while near selects small memory
26459 \begin_layout Standard
26460 The standard device libraries (see
26461 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
26465 ) contain no reference to pointers, so they can be used with both memory
26469 \begin_layout Subsection
26473 \begin_layout Standard
26475 \begin_inset LatexCommand \index{PIC16!stack}
26479 implementation for the PIC16 port uses two indirect registers, FSR1 and
26483 \begin_layout Description
26484 FSR1 is assigned as stack pointer
26487 \begin_layout Description
26488 FSR2 is assigned as frame pointer
26491 \begin_layout Standard
26492 The following stack models are supported by the PIC16 port
26495 \begin_layout Itemize
26503 \begin_layout Itemize
26511 \begin_layout Standard
26516 model means that only the FSRxL byte is used to access stack and frame,
26523 uses both FSRxL and FSRxH registers.
26524 The following table shows the stack/frame pointers sizes according to stack
26525 model and the maximum space they can address:
26528 \begin_layout Standard
26530 \begin_inset Tabular
26531 <lyxtabular version="3" rows="3" columns="3">
26533 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26534 <column alignment="center" valignment="top" leftline="true" width="0">
26535 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26536 <row topline="true" bottomline="true">
26537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26540 \begin_layout Standard
26541 Stack & Frame pointer sizes according to stack model
26546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26549 \begin_layout Standard
26555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26558 \begin_layout Standard
26565 <row topline="true">
26566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26569 \begin_layout Standard
26575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26578 \begin_layout Standard
26584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26587 \begin_layout Standard
26594 <row topline="true" bottomline="true">
26595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26598 \begin_layout Standard
26604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26607 \begin_layout Standard
26613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26616 \begin_layout Standard
26630 \begin_layout Standard
26635 stack model is currently not working properly throughout the code generator.
26636 So its use is not advised.
26637 Also there are some other points that need special care:
26642 \begin_layout Enumerate
26643 Do not create stack sections with size more than one physical bank (that
26647 \begin_layout Enumerate
26648 Stack sections should no cross physical bank limits (i.e.
26649 #pragma stack 0x50 0x100)
26652 \begin_layout Standard
26653 These limitations are caused by the fact that only FSRxL is modified when
26654 using SMALL stack model, so no more than 256 bytes of stack can be used.
26655 This problem will disappear after LARGE model is fully implemented.
26658 \begin_layout Subsection
26662 \begin_layout Standard
26663 In addition to the standard SDCC function keywords, PIC16
26664 \begin_inset LatexCommand \index{PIC16}
26668 port makes available two more:
26671 \begin_layout Description
26673 \begin_inset LatexCommand \index{PIC16!wparam}
26677 Use the WREG to pass one byte of the first function argument.
26678 This improves speed but you may not use this for functions with arguments
26679 that are called via function pointers, otherwise the first byte of the
26680 first parameter will get lost.
26684 \begin_layout LyX-Code
26685 void func_wparam(int a) wparam
26688 \begin_layout LyX-Code
26692 \begin_layout LyX-Code
26693 /* WREG hold the lower part of a */
26696 \begin_layout LyX-Code
26697 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
26701 \begin_layout LyX-Code
26705 \begin_layout LyX-Code
26709 \begin_layout Description
26711 \begin_inset LatexCommand \index{PIC16!shadowregs}
26715 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
26716 hardware shadow registers which hold the values of WREG, STATUS and BSR
26718 This can be done by adding the keyword
26726 keyword in the function's header.
26729 \begin_layout LyX-Code
26730 void isr_shadow(void) shadowregs interrupt 1
26733 \begin_layout LyX-Code
26737 \begin_layout LyX-Code
26741 \begin_layout LyX-Code
26745 \begin_layout Standard
26750 instructs the code generator not to store/restore WREG, STATUS, BSR when
26751 entering/exiting the ISR.
26754 \begin_layout Subsection
26755 Function return values
26758 \begin_layout Standard
26759 Return values from functions are placed to the appropriate registers following
26760 a modified Microchip policy optimized for SDCC.
26761 The following table shows these registers:
26764 \begin_layout Standard
26766 \begin_inset Tabular
26767 <lyxtabular version="3" rows="6" columns="2">
26769 <column alignment="center" valignment="top" leftline="true" width="0">
26770 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26771 <row topline="true" bottomline="true">
26772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26775 \begin_layout Standard
26781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26784 \begin_layout Standard
26785 destination register
26791 <row topline="true">
26792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26795 \begin_layout Standard
26801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26804 \begin_layout Standard
26811 <row topline="true">
26812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26815 \begin_layout Standard
26821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26824 \begin_layout Standard
26831 <row topline="true">
26832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26835 \begin_layout Standard
26841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26844 \begin_layout Standard
26851 <row topline="true">
26852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26855 \begin_layout Standard
26861 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26864 \begin_layout Standard
26865 FSR0L:PRODH:PRODL:WREG
26871 <row topline="true" bottomline="true">
26872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26875 \begin_layout Standard
26881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26884 \begin_layout Standard
26885 on stack, FSR0 points to the beginning
26898 \begin_layout Subsection
26902 \begin_layout Standard
26904 \begin_inset LatexCommand \index{PIC16!interrupt}
26908 service routine (ISR) is declared using the
26915 \begin_layout LyX-Code
26916 void isr(void) interrupt
26921 \begin_layout LyX-Code
26925 \begin_layout LyX-Code
26929 \begin_layout LyX-Code
26933 \begin_layout Standard
26938 is the interrupt number, which for PIC18F devices can be:
26941 \begin_layout Standard
26943 \begin_inset Tabular
26944 <lyxtabular version="3" rows="4" columns="3">
26946 <column alignment="center" valignment="top" leftline="true" width="0">
26947 <column alignment="center" valignment="top" leftline="true" width="0">
26948 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26949 <row topline="true" bottomline="true">
26950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26953 \begin_layout Standard
26961 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26964 \begin_layout Standard
26970 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26973 \begin_layout Standard
26974 Interrupt Vector Address
26980 <row topline="true">
26981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26984 \begin_layout Standard
26990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26993 \begin_layout Standard
26999 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27002 \begin_layout Standard
27009 <row topline="true">
27010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27013 \begin_layout Standard
27028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27031 \begin_layout Standard
27041 HIGH priority interrupts
27046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27049 \begin_layout Standard
27056 <row topline="true" bottomline="true">
27057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27060 \begin_layout Standard
27066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27069 \begin_layout Standard
27070 LOW priority interrupts
27075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27078 \begin_layout Standard
27092 \begin_layout Standard
27093 When generating assembly code for ISR the code generator places a
27099 Interrupt Vector Address
27101 which points at the genetated ISR.
27102 This single GOTO instruction is part of an automatically generated
27104 interrupt entry point
27107 The actuall ISR code is placed as normally would in the code space.
27108 Upon interrupt request, the GOTO instruction is executed which jumps to
27110 When declaring interrupt functions as _naked this GOTO instruction is
27115 The whole interrupt functions is therefore placed at the Interrupt Vector
27116 Address of the specific interrupt.
27117 This is not a problem for the LOW priority interrupts, but it is a problem
27118 for the RESET and the HIGH priority interrupts because code may be written
27119 at the next interrupt's vector address and cause undeterminate program
27120 behaviour if that interrupt is raised.
27124 \begin_layout Standard
27125 This is not a problem when
27128 \begin_layout Enumerate
27129 this is a HIGH interrupt ISR and LOW interrupts are
27136 \begin_layout Enumerate
27137 when the ISR is small enough not to reach the next interrupt's vector address.
27145 \begin_layout Standard
27151 This way a function is generated similar to an ISR, but it is not assigned
27155 \begin_layout Standard
27156 When entering an interrupt, currently the PIC16
27157 \begin_inset LatexCommand \index{PIC16}
27161 port automatically saves the following registers:
27164 \begin_layout Itemize
27168 \begin_layout Itemize
27172 \begin_layout Itemize
27176 \begin_layout Itemize
27177 PROD (PRODL and PRODH)
27180 \begin_layout Itemize
27181 FSR0 (FSR0L and FSR0H)
27184 \begin_layout Standard
27185 These registers are restored upon return from the interrupt routine.
27189 \begin_layout Standard
27190 NOTE that when the _naked attribute is specified for an interrupt routine,
27191 then NO registers are stored or restored.
27199 \begin_layout Subsection
27203 \begin_layout Standard
27204 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
27205 There are 3 types of generic pointers currently implemented data, code
27206 and eeprom pointers.
27207 They are differentiated by the value of the 7th and 6th bits of the upper
27211 \begin_layout Standard
27213 \begin_inset Tabular
27214 <lyxtabular version="3" rows="5" columns="5">
27216 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27217 <column alignment="center" valignment="top" width="0">
27218 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27219 <column alignment="center" valignment="top" width="0">
27220 <column alignment="left" valignment="top" rightline="true" width="0">
27221 <row topline="true" bottomline="true">
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" usebox="none">
27234 \begin_layout Standard
27240 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27243 \begin_layout Standard
27249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27252 \begin_layout Standard
27253 rest of the pointer
27258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27261 \begin_layout Standard
27268 <row topline="true" bottomline="true">
27269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27272 \begin_layout Standard
27278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27281 \begin_layout Standard
27287 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27290 \begin_layout Standard
27296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27299 \begin_layout Standard
27304 uuuuuu uuuuxxxx xxxxxxxx
27309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27312 \begin_layout Standard
27313 a 12-bit data pointer in data RAM memory
27319 <row bottomline="true">
27320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27323 \begin_layout Standard
27329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27332 \begin_layout Standard
27338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27341 \begin_layout Standard
27347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27350 \begin_layout Standard
27355 uxxxxx xxxxxxxx xxxxxxxx
27360 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27363 \begin_layout Standard
27364 a 21-bit code pointer in FLASH memory
27370 <row bottomline="true">
27371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27374 \begin_layout Standard
27380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27383 \begin_layout Standard
27389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27392 \begin_layout Standard
27398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27401 \begin_layout Standard
27406 uuuuuu uuuuuuxx xxxxxxxx
27411 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27414 \begin_layout Standard
27415 a 10-bit eeprom pointer in EEPROM memory
27421 <row bottomline="true">
27422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27425 \begin_layout Standard
27431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27434 \begin_layout Standard
27440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27443 \begin_layout Standard
27449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27452 \begin_layout Standard
27457 xxxxxx xxxxxxxx xxxxxxxx
27462 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27465 \begin_layout Standard
27466 unimplemented pointer type
27479 \begin_layout Standard
27480 Generic pointer are read and written with a set of library functions which
27481 read/write 1, 2, 3, 4 bytes.
27484 \begin_layout Subsection
27488 \begin_layout Subsubsection
27489 Standard I/O Streams
27492 \begin_layout Standard
27497 the type FILE is defined as:
27500 \begin_layout LyX-Code
27501 typedef char * FILE;
27504 \begin_layout Standard
27505 This type is the stream type implemented I/O in the PIC18F devices.
27506 Also the standard input and output streams are declared in stdio.h:
27509 \begin_layout LyX-Code
27510 extern FILE * stdin;
27513 \begin_layout LyX-Code
27514 extern FILE * stdout;
27517 \begin_layout Standard
27518 The FILE type is actually a generic pointer which defines one more type
27519 of generic pointers, the
27524 This new type has the format:
27527 \begin_layout Standard
27529 \begin_inset Tabular
27530 <lyxtabular version="3" rows="2" columns="7">
27532 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27533 <column alignment="center" valignment="top" width="0">
27534 <column alignment="center" valignment="top" leftline="true" width="0">
27535 <column alignment="center" valignment="top" leftline="true" width="0">
27536 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27537 <column alignment="center" valignment="top" width="0">
27538 <column alignment="left" valignment="top" rightline="true" width="0">
27539 <row topline="true" bottomline="true">
27540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27543 \begin_layout Standard
27549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27552 \begin_layout Standard
27558 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27561 \begin_layout Standard
27567 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27570 \begin_layout Standard
27576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27579 \begin_layout Standard
27585 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27588 \begin_layout Standard
27589 rest of the pointer
27594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27597 \begin_layout Standard
27604 <row topline="true" bottomline="true">
27605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27608 \begin_layout Standard
27614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27617 \begin_layout Standard
27623 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27626 \begin_layout Standard
27632 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27635 \begin_layout Standard
27641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27644 \begin_layout Standard
27650 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27653 \begin_layout Standard
27663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27666 \begin_layout Standard
27667 upper byte high nubble is 0x2n, the rest are zeroes
27680 \begin_layout Standard
27681 Currently implemented there are 3 types of streams defined:
27684 \begin_layout Standard
27686 \begin_inset Tabular
27687 <lyxtabular version="3" rows="4" columns="4">
27689 <column alignment="center" valignment="top" leftline="true" width="0">
27690 <column alignment="center" valignment="top" leftline="true" width="0">
27691 <column alignment="center" valignment="top" leftline="true" width="0">
27692 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27693 <row topline="true" bottomline="true">
27694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27697 \begin_layout Standard
27703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27706 \begin_layout Standard
27712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27715 \begin_layout Standard
27721 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27724 \begin_layout Standard
27731 <row topline="true">
27732 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27735 \begin_layout Standard
27741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27744 \begin_layout Standard
27752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27755 \begin_layout Standard
27761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27764 \begin_layout Standard
27765 Writes/Reads characters via the USART peripheral
27771 <row topline="true">
27772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27775 \begin_layout Standard
27781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27784 \begin_layout Standard
27792 <cell alignment="center" valignment="top" topline="true" leftline="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
27805 Writes/Reads characters via the MSSP peripheral
27811 <row topline="true" bottomline="true">
27812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27815 \begin_layout Standard
27821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27824 \begin_layout Standard
27832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27835 \begin_layout Standard
27841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27844 \begin_layout Standard
27845 Writes/Reads characters via used defined functions
27858 \begin_layout Standard
27859 The stream identifiers are declared as macros in the stdio.h header.
27862 \begin_layout Standard
27863 In the libc library there exist the functions that are used to write to
27864 each of the above streams.
27868 \begin_layout Description
27873 \begin_layout Standard
27882 _stream_usart_putchar writes a character at the USART stream
27885 \begin_layout Description
27890 \begin_layout Standard
27899 _stream_mssp_putchar writes a character at the MSSP stream
27902 \begin_layout Description
27903 putchar dummy function.
27904 This writes a character to a user specified manner.
27907 \begin_layout Standard
27908 In order to increase performance
27912 is declared in stdio.h as having its parameter in WREG (it has the wparam
27914 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
27915 in a user-friendly way.
27920 is the name of the variable that holds the character to print.
27921 An example follows:
27924 \begin_layout LyX-Code
27925 #include <pic18fregs.h>
27934 \begin_layout LyX-Code
27938 \begin_layout LyX-Code
27939 PORTA = c; /* dump character c to PORTA */
27942 \begin_layout LyX-Code
27950 \begin_layout LyX-Code
27954 \begin_layout LyX-Code
27955 stdout = STREAM_USER; /* this is not necessary, since stdout points
27958 \begin_layout LyX-Code
27959 * by default to STREAM_USER */
27962 \begin_layout LyX-Code
27964 \begin_inset Quotes sld
27967 This is a printf test
27970 \begin_inset Quotes srd
27976 \begin_layout LyX-Code
27980 \begin_layout LyX-Code
27984 \begin_layout Subsubsection
27988 \begin_layout Standard
27989 PIC16 contains an implementation of the printf-family of functions.
27990 There exist the following functions:
27993 \begin_layout LyX-Code
27994 extern unsigned int sprintf(char *buf, char *fmt, ...);
27997 \begin_layout LyX-Code
27998 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
28001 \begin_layout LyX-Code
28005 \begin_layout LyX-Code
28006 extern unsigned int printf(char *fmt, ...);
28009 \begin_layout LyX-Code
28010 extern unsigned int vprintf(char *fmt, va_lista ap);
28013 \begin_layout LyX-Code
28017 \begin_layout LyX-Code
28018 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
28021 \begin_layout LyX-Code
28022 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
28025 \begin_layout Standard
28026 For sprintf and vsprintf
28030 should normally be a data pointer where the resulting string will be placed.
28031 No range checking is done so the user should allocate the necessery buffer.
28032 For fprintf and vfprintf
28036 should be a stream pointer (i.e.
28037 stdout, STREAM_MSSP, etc...).
28040 \begin_layout Subsubsection
28044 \begin_layout Standard
28045 The PIC18F family of microcontrollers supports a number of interrupt sources.
28046 A list of these interrupts is shown in the following table:
28049 \begin_layout Standard
28051 \begin_inset Tabular
28052 <lyxtabular version="3" rows="11" columns="4">
28054 <column alignment="left" valignment="top" leftline="true" width="0">
28055 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28056 <column alignment="left" valignment="top" leftline="true" width="0">
28057 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28058 <row topline="true" bottomline="true">
28059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28062 \begin_layout Standard
28068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="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
28086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28089 \begin_layout Standard
28096 <row topline="true">
28097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28100 \begin_layout Standard
28106 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28109 \begin_layout Standard
28110 PORTB change interrupt
28115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28118 \begin_layout Standard
28124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28127 \begin_layout Standard
28128 EEPROM/FLASH write complete interrupt
28134 <row topline="true">
28135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28138 \begin_layout Standard
28144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28147 \begin_layout Standard
28148 INT0 external interrupt
28153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28156 \begin_layout Standard
28162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28165 \begin_layout Standard
28166 Bus collision interrupt
28172 <row topline="true">
28173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28176 \begin_layout Standard
28182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28185 \begin_layout Standard
28186 INT1 external interrupt
28191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28194 \begin_layout Standard
28200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28203 \begin_layout Standard
28204 Low voltage detect interrupt
28210 <row topline="true">
28211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28214 \begin_layout Standard
28220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28223 \begin_layout Standard
28224 INT2 external interrupt
28229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28232 \begin_layout Standard
28238 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28241 \begin_layout Standard
28242 Parallel slave port interrupt
28248 <row topline="true">
28249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28252 \begin_layout Standard
28258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28261 \begin_layout Standard
28262 CCP1 module interrupt
28267 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28270 \begin_layout Standard
28276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28279 \begin_layout Standard
28280 AD convertion complete interrupt
28286 <row topline="true">
28287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28290 \begin_layout Standard
28296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28299 \begin_layout Standard
28300 CCP2 module interrupt
28305 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28308 \begin_layout Standard
28314 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28317 \begin_layout Standard
28318 USART receive interrupt
28324 <row topline="true">
28325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28328 \begin_layout Standard
28334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28337 \begin_layout Standard
28338 TMR0 overflow interrupt
28343 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28346 \begin_layout Standard
28352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28355 \begin_layout Standard
28356 USART transmit interrupt
28362 <row topline="true">
28363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28366 \begin_layout Standard
28372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28375 \begin_layout Standard
28376 TMR1 overflow interrupt
28381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28384 \begin_layout Standard
28390 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28393 \begin_layout Standard
28394 SSP receive/transmit interrupt
28400 <row topline="true">
28401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28404 \begin_layout Standard
28410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28413 \begin_layout Standard
28414 TMR2 matches PR2 interrupt
28419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28422 \begin_layout Standard
28428 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28431 \begin_layout Standard
28438 <row topline="true" bottomline="true">
28439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28442 \begin_layout Standard
28448 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28451 \begin_layout Standard
28452 TMR3 overflow interrupt
28457 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28460 \begin_layout Standard
28466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28469 \begin_layout Standard
28483 \begin_layout Standard
28484 The prototypes for these names are defined in the header file
28491 \begin_layout Standard
28492 In order to simplify signal handling, a number of macros is provided:
28496 \labelwidthstring 00.00.0000
28497 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
28498 high priority interrupts.
28503 is the function name to use.
28507 \labelwidthstring 00.00.0000
28508 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
28509 low priority interrupt.
28514 is the function name to use.
28518 \labelwidthstring 00.00.0000
28519 DEF_HANDLER(sig,handler) define a handler for signal
28525 \labelwidthstring 00.00.0000
28526 END_DEF end the declaration of the dispatch table.
28529 \begin_layout Standard
28530 Additionally there are two more macros to simplify the declaration of the
28535 \labelwidthstring 00.00.0000
28538 SIGHANDLER(handler)
28540 this declares the function prototype for the
28548 \labelwidthstring 00.00.0000
28549 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
28552 \begin_layout Standard
28553 An example of using the macros above is shown below:
28556 \begin_layout LyX-Code
28557 #include <pic18fregs.h>
28560 \begin_layout LyX-Code
28561 #include <signal.h>
28565 DEF_INTHIGH(high_int)
28568 \begin_layout LyX-Code
28569 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
28572 \begin_layout LyX-Code
28573 DEF_HANDLER(SIG_BCOL, _bcol_handler)
28576 \begin_layout LyX-Code
28581 SIGHANDLER(_tmr0_handler)
28584 \begin_layout LyX-Code
28588 \begin_layout LyX-Code
28589 /* action to be taken when timer 0 overflows */
28592 \begin_layout LyX-Code
28597 SIGHANDLERNAKED(_bcol_handler)
28600 \begin_layout LyX-Code
28604 \begin_layout LyX-Code
28608 \begin_layout LyX-Code
28609 /* action to be taken when bus collision occurs */
28612 \begin_layout LyX-Code
28616 \begin_layout LyX-Code
28620 \begin_layout LyX-Code
28624 \begin_layout Standard
28629 Special care should be taken when using the above scheme:
28632 \begin_layout Itemize
28633 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
28636 \begin_layout Itemize
28637 when declaring SIGHANDLERNAKED handler never forget to use
28641 for proper returning.
28644 \begin_layout Subsection
28648 \begin_layout Standard
28649 Here you can find some general tips for compiling programs with SDCC/pic16.
28652 \begin_layout Subsubsection
28656 \begin_layout Standard
28658 \begin_inset LatexCommand \index{PIC16!stack}
28662 size (that is 64 bytes) probably is enough for many programs.
28663 One must take care that when there are many levels of function nesting,
28664 or there is excessive usage of stack, its size should be extended.
28665 An example of such a case is the printf/sprintf family of functions.
28666 If you encounter problems like not being able to print integers, then you
28667 need to set the stack size around the maximum (256 for small stack model).
28668 The following diagram shows what happens when calling printf to print an
28672 \begin_layout LyX-Code
28673 printf () --> ltoa () --> ultoa () --> divschar ()
28676 \begin_layout Standard
28677 It is should be understood that stack is easily consumed when calling complicate
28679 Using command line arguments like -
28683 \begin_layout Standard
28692 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
28694 Other ways to reduce stack usage may exist.
28697 \begin_layout Subsection
28701 \begin_layout Standard
28702 The PIC16 Port currently does not pass SDCC's regression test
28703 \begin_inset LatexCommand \index{Regression test (PIC16)}
28708 \begin_inset LatexCommand \ref{sec:Quality-control}
28712 ) and thus the snapshot build regression tests for the PIC16 target are
28713 currently disabled for all hosts
28718 \begin_layout Chapter
28722 \begin_layout Standard
28723 There are several approaches to debugging your code.
28724 This chapter is meant to show your options and to give detail on some of
28729 When writing your code:
28732 \begin_layout Itemize
28733 write your code with debugging in mind (avoid duplicating code, put conceptually
28734 similar variables into structs, use structured code, have strategic points
28735 within your code where all variables are consistent, ...)
28738 \begin_layout Itemize
28739 run a syntax-checking tool like splint
28740 \begin_inset LatexCommand \index{splint (syntax checking tool)}
28745 \begin_inset LatexCommand \index{lint (syntax checking tool)}
28753 \begin_layout Standard
28763 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28770 \begin_layout Itemize
28771 for the high level code use a C-compiler (like f.e.
28772 GCC) to compile run and debug the code on your host.
28777 \begin_layout Standard
28787 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28791 ) on how to handle syntax extensions like __xdata, __at(), ...
28795 \begin_layout Itemize
28796 use another C-compiler to compile code for your target.
28797 Always an option but not recommended:) And not very likely to help you.
28798 If you seriously consider walking this path you should at least occasionally
28799 check portability of your code.
28800 Most commercial compiler vendors will offer an evaluation version so you
28801 can test compile your code or snippets of your code.
28804 \begin_layout Standard
28805 Debugging on a simulator:
28808 \begin_layout Itemize
28809 there is a separate section about SDCDB (section
28810 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
28817 \begin_layout Itemize
28818 or (8051 specific) use a freeware/commercial simulator which interfaces
28820 \begin_inset LatexCommand \index{AOMF, AOMF51}
28825 \begin_inset LatexCommand \ref{OMF file}
28829 ) optionally generated by SDCC.
28832 \begin_layout Standard
28833 Debugging On-target:
28836 \begin_layout Itemize
28837 use a MCU port pin to serially output debug data to the RS232 port of your
28839 You'll probably want some level shifting device typically involving a MAX232
28841 If the hardware serial port of the MCU is not available search for 'Software
28842 UART' in your favourite search machine.
28845 \begin_layout Itemize
28846 use an on-target monitor.
28847 In this context a monitor is a small program which usually accepts commands
28848 via a serial line and allows to set program counter, to single step through
28849 a program and read/write memory locations.
28850 For the 8051 good examples of monitors are paulmon and cmon51 (see section
28852 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
28859 \begin_layout Itemize
28860 toggle MCU port pins at strategic points within your code and use an oscilloscop
28864 digital oscilloscope
28867 \begin_inset LatexCommand \index{Oscilloscope}
28871 with deep trace memory is really helpful especially if you have to debug
28872 a realtime application.
28873 If you need to monitor more pins than your oscilloscope provides you can
28874 sometimes get away with a small R-2R network.
28875 On a single channel oscilloscope you could f.e.
28876 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
28878 \begin_inset Formula $\Omega$
28881 resistor and the other one by a 5\InsetSpace ~
28883 \begin_inset Formula $\Omega$
28886 resistor to the oscilloscope probe (check output drive capability of the
28887 pins you want to monitor).
28888 If you need to monitor many more pins a
28895 \begin_layout Itemize
28909 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
28914 Usually very expensive.
28915 And very nice to have too.
28916 And usually locks you (for years...) to the devices the ICE can emulate.
28920 \begin_layout Itemize
28921 use a remote debugger.
28922 In most 8-bit systems the symbol information is not available on the target,
28923 and a complete debugger is too bulky for the target system.
28924 Therefore usually a debugger on the host system connects to an on-target
28925 debugging stub which accepts only primitive commands.
28928 Terms to enter into your favourite search engine could be 'remote debugging',
28929 'gdb stub' or 'inferior debugger'.
28933 \begin_layout Itemize
28934 use an on target hardware debugger.
28935 Some of the more modern MCUs include hardware support for setting break
28936 points and monitoring/changing variables by using dedicated hardware pins.
28937 This facility doesn't require additional code to run on the target and
28942 doesn't affect runtime behaviour until a breakpoint is hit.
28943 For the mcs51 most hardware debuggers use the AOMF
28944 \begin_inset LatexCommand \index{AOMF, AOMF51}
28949 \begin_inset LatexCommand \ref{OMF file}
28957 \begin_layout Standard
28961 \begin_layout Itemize
28962 if you are not familiar with any of the following terms you're likely to
28963 run into problems rather sooner than later:
28980 As an embedded programmer you
28984 to know them so why not look them up
28988 you have problems?)
28991 \begin_layout Itemize
28992 tell someone else about your problem (actually this is a surprisingly effective
28993 means to hunt down the bug even if the listener is not familiar with your
28995 As 'failure to communicate' is probably one of the job-induced deformations
28996 of an embedded programmer this is highly encouraged.
28999 \begin_layout Section
29000 Debugging with SDCDB
29001 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
29006 \begin_inset LatexCommand \index{SDCDB (debugger)}
29013 \begin_layout Standard
29014 SDCC is distributed with a source level debugger
29015 \begin_inset LatexCommand \index{Debugger}
29020 The debugger uses a command line interface, the command repertoire of the
29021 debugger has been kept as close to gdb
29022 \begin_inset LatexCommand \index{gdb}
29026 (the GNU debugger) as possible.
29027 The configuration and build process is part of the standard compiler installati
29028 on, which also builds and installs the debugger in the target directory
29029 specified during configuration.
29030 The debugger allows you debug BOTH at the C source and at the ASM source
29034 \begin_layout Subsection
29035 Compiling for Debugging
29038 \begin_layout Standard
29043 \begin_layout Standard
29053 \begin_inset LatexCommand \index{-\/-debug}
29057 option must be specified for all files for which debug information is to
29059 The compiler generates a .adb file for each of these files.
29060 The linker creates the .cdb
29061 \begin_inset LatexCommand \index{<file>.cdb}
29066 \begin_inset LatexCommand \index{<file>.adb}
29070 files and the address information.
29071 This .cdb is used by the debugger.
29074 \begin_layout Subsection
29075 How the Debugger Works
29078 \begin_layout Standard
29083 \begin_layout Standard
29092 -debug option is specified the compiler generates extra symbol information
29093 some of which are put into the assembler source and some are put into the
29095 Then the linker creates the .cdb file from the individual .adb files with
29096 the address information for the symbols.
29097 The debugger reads the symbolic information generated by the compiler &
29098 the address information generated by the linker.
29099 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
29100 execution is controlled by the debugger.
29101 When a command is issued for the debugger, it translates it into appropriate
29102 commands for the simulator.
29103 (Currently SDCDM only connects to the simulator but
29108 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
29112 is an effort to connect directly to the hardware.)
29115 \begin_layout Subsection
29116 Starting the Debugger SDCDB
29119 \begin_layout Standard
29120 The debugger can be started using the following command line.
29121 (Assume the file you are debugging has the file name foo).
29135 The debugger will look for the following files.
29138 \begin_layout Itemize
29139 foo.c - the source file.
29142 \begin_layout Itemize
29143 foo.cdb - the debugger symbol information file.
29146 \begin_layout Itemize
29147 foo.ihx - the Intel hex format
29148 \begin_inset LatexCommand \index{Intel hex format}
29155 \begin_layout Subsection
29156 SDCDB Command Line Options
29159 \begin_layout Itemize
29164 \begin_layout Standard
29173 -directory=<source file directory> this option can used to specify the directory
29175 The debugger will look into the directory list specified for source, cdb
29177 The items in the directory list must be separated by ':', e.g.
29178 if the source files can be in the directories /home/src1 and /home/src2,
29183 \begin_layout Standard
29192 -directory option should be -
29196 \begin_layout Standard
29205 -directory=/home/src1:/home/src2.
29206 Note there can be no spaces in the option.
29210 \begin_layout Itemize
29211 -cd <directory> - change to the <directory>.
29214 \begin_layout Itemize
29215 -fullname - used by GUI front ends.
29218 \begin_layout Itemize
29219 -cpu <cpu-type> - this argument is passed to the simulator please see the
29220 simulator docs for details.
29223 \begin_layout Itemize
29224 -X <Clock frequency > this options is passed to the simulator please see
29225 the simulator docs for details.
29228 \begin_layout Itemize
29229 -s <serial port file> passed to simulator see the simulator docs for details.
29232 \begin_layout Itemize
29233 -S <serial in,out> passed to simulator see the simulator docs for details.
29236 \begin_layout Itemize
29237 -k <port number> passed to simulator see the simulator docs for details.
29240 \begin_layout Subsection
29241 SDCDB Debugger Commands
29244 \begin_layout Standard
29245 As mentioned earlier the command interface for the debugger has been deliberatel
29246 y kept as close the GNU debugger gdb, as possible.
29247 This will help the integration with existing graphical user interfaces
29248 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
29249 If you use a graphical user interface for the debugger you can skip this
29253 \begin_layout Subsubsection*
29254 break [line | file:line | function | file:function]
29257 \begin_layout Standard
29258 Set breakpoint at specified line or function:
29267 sdcdb>break foo.c:100
29269 sdcdb>break funcfoo
29271 sdcdb>break foo.c:funcfoo
29274 \begin_layout Subsubsection*
29275 clear [line | file:line | function | file:function ]
29278 \begin_layout Standard
29279 Clear breakpoint at specified line or function:
29288 sdcdb>clear foo.c:100
29290 sdcdb>clear funcfoo
29292 sdcdb>clear foo.c:funcfoo
29295 \begin_layout Subsubsection*
29299 \begin_layout Standard
29300 Continue program being debugged, after breakpoint.
29303 \begin_layout Subsubsection*
29307 \begin_layout Standard
29308 Execute till the end of the current function.
29311 \begin_layout Subsubsection*
29315 \begin_layout Standard
29316 Delete breakpoint number 'n'.
29317 If used without any option clear ALL user defined break points.
29320 \begin_layout Subsubsection*
29321 info [break | stack | frame | registers ]
29324 \begin_layout Itemize
29325 info break - list all breakpoints
29328 \begin_layout Itemize
29329 info stack - show the function call stack.
29332 \begin_layout Itemize
29333 info frame - show information about the current execution frame.
29336 \begin_layout Itemize
29337 info registers - show content of all registers.
29340 \begin_layout Subsubsection*
29344 \begin_layout Standard
29345 Step program until it reaches a different source line.
29346 Note: pressing <return> repeats the last command.
29349 \begin_layout Subsubsection*
29353 \begin_layout Standard
29354 Step program, proceeding through subroutine calls.
29357 \begin_layout Subsubsection*
29361 \begin_layout Standard
29362 Start debugged program.
29365 \begin_layout Subsubsection*
29369 \begin_layout Standard
29370 Print type information of the variable.
29373 \begin_layout Subsubsection*
29377 \begin_layout Standard
29378 print value of variable.
29381 \begin_layout Subsubsection*
29385 \begin_layout Standard
29386 load the given file name.
29387 Note this is an alternate method of loading file for debugging.
29390 \begin_layout Subsubsection*
29394 \begin_layout Standard
29395 print information about current frame.
29398 \begin_layout Subsubsection*
29402 \begin_layout Standard
29403 Toggle between C source & assembly source.
29406 \begin_layout Subsubsection*
29407 ! simulator command
29410 \begin_layout Standard
29411 Send the string following '!' to the simulator, the simulator response is
29413 Note the debugger does not interpret the command being sent to the simulator,
29414 so if a command like 'go' is sent the debugger can loose its execution
29415 context and may display incorrect values.
29418 \begin_layout Subsubsection*
29422 \begin_layout Standard
29425 My name is Bobby Brown"
29428 \begin_layout Subsection
29429 Interfacing SDCDB with DDD
29432 \begin_layout Standard
29433 \begin_inset Note Note
29436 \begin_layout Standard
29437 The screenshot was converted from png to eps with:
29438 \begin_inset Quotes sld
29441 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
29442 \begin_inset Quotes srd
29445 which produces a pretty compact eps file which is free from compression
29449 \begin_layout Standard
29450 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
29451 as this broke the build system on Sourceforge (pdf-file was broken.
29452 pdflatex does not accept eps files).
29460 \begin_layout Standard
29476 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
29482 shows a screenshot of a debugging session with DDD
29483 \begin_inset LatexCommand \index{DDD (debugger)}
29487 (Unix only) on a simulated 8032.
29488 The debugging session might not run as smoothly as the screenshot suggests.
29489 The debugger allows setting of breakpoints, displaying and changing variables,
29490 single stepping through C and assembler code.
29493 The source was compiled with
29507 \begin_layout Standard
29519 -debug ddd_example.c
29532 and DDD was invoked with
29539 ddd -debugger "sdcdb -cpu 8032 ddd_example"
29542 \begin_layout Standard
29543 \begin_inset Note Note
29546 \begin_layout Standard
29547 Check that the double quotes or an apostroph within the command line survive
29548 the LyX tool chain.
29549 Previously the apostrophs got slanted in the PDF output so a cut and paste
29558 \begin_layout Subsection
29559 Interfacing SDCDB with XEmacs
29560 \begin_inset LatexCommand \index{XEmacs}
29565 \begin_inset LatexCommand \index{Emacs}
29572 \begin_layout Standard
29573 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
29574 sdcdb.el and sdcdbsrc.el.
29575 These two files can be found in the $(prefix)/bin directory after the installat
29577 These files need to be loaded into XEmacs for the interface to work.
29578 This can be done at XEmacs startup time by inserting the following into
29579 your '.xemacs' file (which can be found in your HOME directory):
29585 (load-file sdcdbsrc.el)
29591 .xemacs is a lisp file so the () around the command is REQUIRED.
29592 The files can also be loaded dynamically while XEmacs is running, set the
29593 environment variable 'EMACSLOADPATH' to the installation bin directory
29594 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
29595 To start the interface enter the following command:
29609 You will prompted to enter the file name to be debugged.
29614 The command line options that are passed to the simulator directly are
29615 bound to default values in the file sdcdbsrc.el.
29616 The variables are listed below, these values maybe changed as required.
29619 \begin_layout Itemize
29620 sdcdbsrc-cpu-type '51
29623 \begin_layout Itemize
29624 sdcdbsrc-frequency '11059200
29627 \begin_layout Itemize
29628 sdcdbsrc-serial nil
29631 \begin_layout Standard
29632 The following is a list of key mapping for the debugger interface.
29635 \begin_layout Standard
29658 binding\InsetSpace ~
29696 -------\InsetSpace ~
29767 sdcdb-back-from-src\InsetSpace ~
29796 rom-src\InsetSpace ~
29806 SDCDB continue command
29824 sdcdb-step-from-src\InsetSpace ~
29853 hatis-c-sexp\InsetSpace ~
29863 SDCDB ptypecommand for data at
29930 sdcdbsrc-delete\InsetSpace ~
29945 B Delete all breakpoints if no arg
29994 given or delete arg (C-u arg x)
30013 -frame\InsetSpace ~
30028 SDCDB Display current frame if no arg,
30077 given or display frame arg
30145 sdcdbsrc-goto-sdcdb\InsetSpace ~
30155 Goto the SDCDB output buffer
30174 t-c-sexp\InsetSpace ~
30185 SDCDB print command for data at
30252 sdcdbsrc-goto-sdcdb\InsetSpace ~
30263 o the SDCDB output buffer
30281 sdcdbsrc-mode\InsetSpace ~
30297 Toggles Sdcdbsrc mode (turns it
30313 sdcdb-finish-from-src\InsetSpace ~
30321 SDCDB finish command
30355 Set break for line with point
30370 sdcdbsrc-mode\InsetSpace ~
30386 Toggle Sdcdbsrc mode
30402 dbsrc-srcmode\InsetSpace ~
30426 \begin_layout Chapter
30430 \begin_layout Standard
30431 Here are a few guidelines that will help the compiler generate more efficient
30432 code, some of the tips are specific to this compiler others are generally
30433 good programming practice.
30436 \begin_layout Itemize
30437 Use the smallest data type to represent your data-value.
30438 If it is known in advance that the value is going to be less than 256 then
30439 use an 'unsigned char' instead of a 'short' or 'int'.
30440 Please note, that ANSI C requires both signed and unsigned chars to be
30441 promoted to 'signed int'
30442 \begin_inset LatexCommand \index{promotion to signed int}
30447 \begin_inset Marginal
30450 \begin_layout Standard
30459 before doing any operation.
30461 \begin_inset LatexCommand \index{type promotion}
30466 \begin_inset LatexCommand \label{type promotion}
30470 can be omitted, if the result is the same.
30471 The effect of the promotion rules together with the sign-extension is often
30476 \begin_layout Verse
30479 unsigned char uc = 0xfe;
30481 if (uc * uc < 0) /* this is true! */
30494 \begin_layout Standard
30501 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
30509 \begin_layout Verse
30512 (unsigned char) -12 / (signed char) -3 = ...
30515 \begin_layout Standard
30516 No, the result is not 4:
30519 \begin_layout Verse
30522 (int) (unsigned char) -12 / (int) (signed char) -3 =
30524 (int) (unsigned char)
30525 0xf4 / (int) (signed char) 0xfd =
30527 (int) 0x00f4 / (int) 0xfffd =
30532 (int) 244 / (int) -3 =
30534 (int) -81 = (int) 0xffaf;
30537 \begin_layout Standard
30538 Don't complain, that gcc gives you a different result.
30539 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
30540 Therefore the results are different.
30543 \begin_inset Quotes sld
30547 \begin_inset Quotes srd
30553 \begin_layout Quote
30556 If well-defined overflow characteristics are important and negative values
30557 are not, or if you want to steer clear of sign-extension problems when
30558 manipulating bits or bytes, use one of the corresponding unsigned types.
30559 (Beware when mixing signed and unsigned values in expressions, though.)
30562 character types (especially unsigned char) can be used as "tiny" integers,
30563 doing so is sometimes more trouble than it's worth, due to unpredictable
30564 sign extension and increased code size.
30568 \begin_layout Itemize
30569 Use unsigned when it is known in advance that the value is not going to
30571 This helps especially if you are doing division or multiplication, bit-shifting
30572 or are using an array index.
30575 \begin_layout Itemize
30576 NEVER jump into a LOOP.
30579 \begin_layout Itemize
30580 Declare the variables to be local
30581 \begin_inset LatexCommand \index{local variables}
30585 whenever possible, especially loop control variables (induction).
30588 \begin_layout Itemize
30589 Have a look at the assembly listing to get a
30590 \begin_inset Quotes sld
30594 \begin_inset Quotes srd
30597 for the code generation.
30600 \begin_layout Section
30601 Porting code from or to other compilers
30602 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
30609 \begin_layout Itemize
30610 check whether endianness of the compilers differs and adapt where needed.
30613 \begin_layout Itemize
30614 check the device specific header files
30615 \begin_inset LatexCommand \index{Header files}
30620 \begin_inset LatexCommand \index{Include files}
30624 for compiler specific syntax.
30625 Eventually include the file <compiler.h
30626 \begin_inset LatexCommand \index{compiler.h (include file)}
30631 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
30635 to allow using common header files.
30638 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
30645 \begin_layout Itemize
30646 check whether the startup code contains the correct initialization (watchdog,
30650 \begin_layout Itemize
30651 check whether the sizes of short, int, long match.
30654 \begin_layout Itemize
30655 check if some 16 or 32 bit hardware registers require a specific addressing
30656 order (least significant or most significant byte first) and adapt if needed
30665 relate to time and not to lower/upper memory location here, so this is
30670 the same as endianness).
30673 \begin_layout Itemize
30674 check whether the keyword
30678 is used where needed.
30679 The compilers might differ in their optimization characteristics (as different
30680 versions of the same compiler might also use more clever optimizations
30681 this is good idea anyway).
30683 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
30690 \begin_layout Itemize
30691 check that the compilers are not told to supress warnings.
30694 \begin_layout Itemize
30695 check and convert compiler specific extensions (interrupts, memory areas,
30699 \begin_layout Itemize
30700 check for differences in type promotion.
30701 Especially check for math operations on
30710 For the sake of C99 compatibility SDCC will probably promote these to
30714 more often than other compilers.
30715 Eventually insert explicit casts to
30724 Also check that the ~\InsetSpace ~
30726 \begin_inset LatexCommand \index{\~\/ Operator}
30733 \begin_inset LatexCommand \index{bit}
30739 variables, use the !\InsetSpace ~
30742 \begin_inset LatexCommand \ref{type promotion}
30747 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30754 \begin_layout Itemize
30755 check the assembly code generated for interrupt routines (f.e.
30756 for calls to possibly non-reentrant library functions).
30759 \begin_layout Itemize
30760 check whether timing loops result in proper timing (or preferably consider
30761 a rewrite of the code with timer based delays instead).
30764 \begin_layout Itemize
30765 check for differences in printf parameters (some compilers push (va_arg
30766 \begin_inset LatexCommand \index{vararg, va\_arg}
30770 ) char variables as
30774 others push them as
30780 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30787 \begin_layout Itemize
30788 check the resulting memory map
30789 \begin_inset LatexCommand \index{Memory map}
30794 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
30795 ly idata, pdata, xdata).
30796 Eventually check if unexpected library functions are included.
30799 \begin_layout Section
30801 \begin_inset LatexCommand \index{Tools}
30805 included in the distribution
30808 \begin_layout Standard
30810 \begin_inset Tabular
30811 <lyxtabular version="3" rows="12" columns="3">
30813 <column alignment="left" valignment="top" leftline="true" width="0pt">
30814 <column alignment="left" valignment="top" leftline="true" width="0pt">
30815 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30816 <row topline="true" bottomline="true">
30817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30820 \begin_layout Standard
30828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30831 \begin_layout Standard
30839 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30842 \begin_layout Standard
30851 <row topline="true">
30852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30855 \begin_layout Standard
30857 \begin_inset LatexCommand \index{uCsim}
30866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30869 \begin_layout Standard
30870 Simulator for various architectures
30875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30878 \begin_layout Standard
30885 <row topline="true">
30886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30889 \begin_layout Standard
30895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30898 \begin_layout Standard
30900 \begin_inset LatexCommand \index{Header files}
30905 \begin_inset LatexCommand \index{Include files}
30914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30917 \begin_layout Standard
30918 sdcc/support/scripts
30924 <row topline="true">
30925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30928 \begin_layout Standard
30934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30937 \begin_layout Standard
30938 header file conversion
30943 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30946 \begin_layout Standard
30947 sdcc/support/scripts
30953 <row topline="true">
30954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30957 \begin_layout Standard
30963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30966 \begin_layout Standard
30972 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30975 \begin_layout Standard
30991 <row topline="true">
30992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30995 \begin_layout Standard
31001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31004 \begin_layout Standard
31010 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31013 \begin_layout Standard
31029 <row topline="true">
31030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31033 \begin_layout Standard
31039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31042 \begin_layout Standard
31048 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31051 \begin_layout Standard
31067 <row topline="true">
31068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31071 \begin_layout Standard
31077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31080 \begin_layout Standard
31086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31089 \begin_layout Standard
31105 <row topline="true">
31106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31109 \begin_layout Standard
31115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31118 \begin_layout Standard
31124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31127 \begin_layout Standard
31143 <row topline="true">
31144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31147 \begin_layout Standard
31153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31156 \begin_layout Standard
31162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31165 \begin_layout Standard
31181 <row topline="true">
31182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31185 \begin_layout Standard
31191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31194 \begin_layout Standard
31200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31203 \begin_layout Standard
31219 <row topline="true" bottomline="true">
31220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31223 \begin_layout Standard
31229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31232 \begin_layout Standard
31234 \begin_inset LatexCommand \index{packihx (tool)}
31243 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31246 \begin_layout Standard
31271 \begin_layout Section
31273 \begin_inset LatexCommand \index{Documentation}
31277 included in the distribution
31280 \begin_layout Standard
31282 \begin_inset Tabular
31283 <lyxtabular version="3" rows="10" columns="2">
31285 <column alignment="block" valignment="top" leftline="true" width="40col%">
31286 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
31287 <row topline="true" bottomline="true" endhead="true">
31288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31291 \begin_layout Standard
31299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31302 \begin_layout Standard
31305 Filename / Where to get
31311 <row topline="true">
31312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31315 \begin_layout Standard
31316 SDCC Compiler User Guide
31321 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31324 \begin_layout Standard
31325 You're reading it right now
31337 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
31347 <row topline="true">
31348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31351 \begin_layout Standard
31357 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31360 \begin_layout Standard
31373 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31383 <row topline="true">
31384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31387 \begin_layout Standard
31389 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
31394 \begin_inset LatexCommand \index{Assembler documentation}
31401 \begin_inset LatexCommand \index{aslink}
31406 \begin_inset LatexCommand \index{Linker documentation}
31415 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31418 \begin_layout Standard
31419 sdcc/as/doc/asxhtm.html
31431 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
31441 <row topline="true">
31442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31445 \begin_layout Standard
31446 SDCC regression test
31447 \begin_inset LatexCommand \index{Regression test}
31456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31459 \begin_layout Standard
31460 sdcc/doc/test_suite_spec.pdf
31472 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
31482 <row topline="true">
31483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31486 \begin_layout Standard
31492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31495 \begin_layout Standard
31508 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
31518 <row topline="true">
31519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31522 \begin_layout Standard
31523 Notes on debugging with SDCDB
31524 \begin_inset LatexCommand \index{SDCDB (debugger)}
31533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31536 \begin_layout Standard
31537 sdcc/debugger/README
31549 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
31559 <row topline="true">
31560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31563 \begin_layout Standard
31565 \begin_inset LatexCommand \index{uCsim}
31569 Software simulator for microcontrollers
31574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31577 \begin_layout Standard
31607 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
31617 <row topline="true">
31618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31621 \begin_layout Standard
31622 Temporary notes on the pic16
31623 \begin_inset LatexCommand \index{PIC16}
31632 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31635 \begin_layout Standard
31636 sdcc/src/pic16/NOTES
31648 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
31658 <row topline="true" bottomline="true">
31659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31662 \begin_layout Standard
31663 SDCC internal documentation (debugging file format)
31668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31671 \begin_layout Standard
31701 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
31720 \begin_layout Section
31721 Related open source tools
31722 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
31727 \begin_inset LatexCommand \index{Related tools}
31734 \begin_layout Standard
31736 \begin_inset Tabular
31737 <lyxtabular version="3" rows="16" columns="3">
31739 <column alignment="left" valignment="top" leftline="true" width="0pt">
31740 <column alignment="block" valignment="top" leftline="true" width="30line%">
31741 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
31742 <row topline="true" bottomline="true">
31743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31746 \begin_layout Standard
31754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31757 \begin_layout Standard
31765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31768 \begin_layout Standard
31777 <row topline="true">
31778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31781 \begin_layout Standard
31783 \begin_inset LatexCommand \index{gpsim (pic simulator)}
31792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31795 \begin_layout Standard
31801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31804 \begin_layout Standard
31805 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
31815 <row topline="true">
31816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31819 \begin_layout Standard
31821 \begin_inset LatexCommand \index{gputils (pic tools)}
31830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31833 \begin_layout Standard
31839 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31842 \begin_layout Standard
31843 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
31853 <row topline="true">
31854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31857 \begin_layout Standard
31863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31866 \begin_layout Standard
31872 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31875 \begin_layout Standard
31876 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
31886 <row topline="true">
31887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31890 \begin_layout Standard
31896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31899 \begin_layout Standard
31900 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
31906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31909 \begin_layout Standard
31910 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
31920 <row topline="true">
31921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31924 \begin_layout Standard
31926 \begin_inset LatexCommand \index{indent (source formatting tool)}
31935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31938 \begin_layout Standard
31939 Formats C source - Master of the white spaces
31944 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31947 \begin_layout Standard
31948 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
31958 <row topline="true">
31959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31962 \begin_layout Standard
31964 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
31973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31976 \begin_layout Standard
31977 Object file conversion, checksumming, ...
31982 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31985 \begin_layout Standard
31986 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
31996 <row topline="true">
31997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32000 \begin_layout Standard
32002 \begin_inset LatexCommand \index{objdump (tool)}
32011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32014 \begin_layout Standard
32015 Object file conversion, ...
32020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32023 \begin_layout Standard
32024 Part of binutils (should be there anyway)
32030 <row topline="true">
32031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32034 \begin_layout Standard
32040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32043 \begin_layout Standard
32044 8051 monitor (hex up-/download, single step, disassemble)
32049 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32052 \begin_layout Standard
32053 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
32063 <row topline="true">
32064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32067 \begin_layout Standard
32069 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
32078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32081 \begin_layout Standard
32082 Source code documentation system
32087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32090 \begin_layout Standard
32091 \begin_inset LatexCommand \url{http://www.doxygen.org}
32101 <row topline="true">
32102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32105 \begin_layout Standard
32111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32114 \begin_layout Standard
32115 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
32120 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32123 \begin_layout Standard
32124 \begin_inset LatexCommand \url{http://www.kdevelop.org}
32134 <row topline="true">
32135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32138 \begin_layout Standard
32144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32147 \begin_layout Standard
32148 8051 monitor (hex up-/download, single step, disassemble)
32153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32156 \begin_layout Standard
32157 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
32167 <row topline="true">
32168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32171 \begin_layout Standard
32173 \begin_inset LatexCommand \index{splint (syntax checking tool)}
32182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32185 \begin_layout Standard
32186 Statically checks c sources (see
32187 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
32196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32199 \begin_layout Standard
32200 \begin_inset LatexCommand \url{http://www.splint.org}
32210 <row topline="true" bottomline="true">
32211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32214 \begin_layout Standard
32216 \begin_inset LatexCommand \index{DDD (debugger)}
32225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32228 \begin_layout Standard
32229 Debugger, serves nicely as GUI to SDCDB
32230 \begin_inset LatexCommand \index{SDCDB (debugger)}
32239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32242 \begin_layout Standard
32243 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
32253 <row bottomline="true">
32254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32257 \begin_layout Standard
32259 \begin_inset LatexCommand \index{d52}
32264 \begin_inset LatexCommand \index{d52 (disassembler)}
32273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32276 \begin_layout Standard
32277 Disassembler, can count instruction cycles
32278 \begin_inset LatexCommand \index{instruction cycles (count)}
32282 , use with options -pnd
32287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32290 \begin_layout Standard
32291 \begin_inset LatexCommand \url{http://www.8052.com/users/disasm/}
32301 <row bottomline="true">
32302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32305 \begin_layout Standard
32307 \begin_inset LatexCommand \index{cmake}
32316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32319 \begin_layout Standard
32320 Cross platform build system, generates Makefiles
32321 \begin_inset LatexCommand \index{Makefile}
32325 and project workspaces
32326 \begin_inset LatexCommand \index{project workspace}
32335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32338 \begin_layout Standard
32339 \begin_inset LatexCommand \url{http://www.cmake.org}
32347 and a dedicated wiki entry:
32348 \begin_inset LatexCommand \url{http://www.cmake.org/Wiki/CmakeSdcc}
32367 \begin_layout Section
32368 Related documentation / recommended reading
32371 \begin_layout Standard
32373 \begin_inset Tabular
32374 <lyxtabular version="3" rows="7" columns="3">
32376 <column alignment="left" valignment="top" leftline="true" width="0pt">
32377 <column alignment="left" valignment="top" leftline="true" width="0">
32378 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32379 <row topline="true" bottomline="true">
32380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32383 \begin_layout Standard
32391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32394 \begin_layout Standard
32402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32405 \begin_layout Standard
32414 <row topline="true">
32415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32418 \begin_layout Standard
32433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32436 \begin_layout Standard
32438 \begin_inset LatexCommand \index{C Reference card}
32447 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32450 \begin_layout Standard
32451 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
32461 <row topline="true">
32462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32465 \begin_layout Standard
32471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32474 \begin_layout Standard
32476 \begin_inset LatexCommand \index{C FAQ}
32485 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32488 \begin_layout Standard
32489 \begin_inset LatexCommand \url{http://www.c-faq.com}
32499 <row topline="true">
32500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32503 \begin_layout Standard
32509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32512 \begin_layout Standard
32513 \begin_inset Quotes sld
32517 \begin_inset Quotes srd
32525 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32528 \begin_layout Standard
32531 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
32541 <row topline="true">
32542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32545 \begin_layout Standard
32551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32554 \begin_layout Standard
32555 \begin_inset Quotes sld
32558 Extensions for Embedded C
32559 \begin_inset Quotes srd
32567 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32570 \begin_layout Standard
32573 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
32583 <row topline="true">
32584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32587 \begin_layout Standard
32593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32596 \begin_layout Standard
32597 Latest datasheet of target CPU
32602 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32605 \begin_layout Standard
32612 <row topline="true" bottomline="true">
32613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32616 \begin_layout Standard
32622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32625 \begin_layout Standard
32626 Revision history of datasheet
32631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32634 \begin_layout Standard
32650 \begin_layout Section
32651 Application notes specifically for SDCC
32654 \begin_layout Standard
32655 SDCC makes no claims about the completeness of this list and about up-to-datenes
32656 s or correctness of the application notes
32657 \begin_inset LatexCommand \index{Application notes}
32664 \begin_layout Standard
32668 \begin_inset Tabular
32669 <lyxtabular version="3" rows="7" columns="3">
32671 <column alignment="block" valignment="top" leftline="true" width="17col%">
32672 <column alignment="block" valignment="top" leftline="true" width="27col%">
32673 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
32674 <row topline="true" bottomline="true">
32675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32678 \begin_layout Standard
32687 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
32690 \begin_layout Standard
32699 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32702 \begin_layout Standard
32712 <row topline="true">
32713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32716 \begin_layout Standard
32724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32727 \begin_layout Standard
32730 Using the SDCC Compiler for the DS80C400
32731 \begin_inset LatexCommand \index{DS80C400}
32740 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32743 \begin_layout Standard
32746 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
32756 <row topline="true">
32757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32760 \begin_layout Standard
32768 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
32771 \begin_layout Standard
32774 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
32775 \begin_inset LatexCommand \index{DS89C4x0}
32779 Family of Microcontrollers
32784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32787 \begin_layout Standard
32790 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
32800 <row topline="true">
32801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32804 \begin_layout Standard
32807 Silicon Laboratories / Cygnal
32812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32815 \begin_layout Standard
32818 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
32819 \begin_inset LatexCommand \index{IDE}
32828 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32831 \begin_layout Standard
32834 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
32844 <row topline="true">
32845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32848 \begin_layout Standard
32851 Ramtron / Goal Semiconductor
32856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32859 \begin_layout Standard
32862 Interfacing SDCC to Syn and Textpad
32867 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32870 \begin_layout Standard
32873 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32883 <row topline="true">
32884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32887 \begin_layout Standard
32890 Ramtron / Goal Semiconductor
32895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32898 \begin_layout Standard
32901 Installing and Configuring SDCC and Crimson Editor
32906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32909 \begin_layout Standard
32912 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32922 <row topline="true" bottomline="true">
32923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32926 \begin_layout Standard
32934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32937 \begin_layout Standard
32940 MSC12xx Programming with SDCC
32945 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32948 \begin_layout Standard
32951 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
32968 \begin_layout Section
32972 \begin_layout Standard
32973 Some questions answered, some pointers given - it might be time to in turn
32981 \begin_layout Itemize
32982 can you solve your project with the selected microcontroller? Would you
32983 find out early or rather late that your target is too small/slow/whatever?
32984 Can you switch to a slightly better device if it doesn't fit?
32987 \begin_layout Itemize
32988 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
32989 and/or another programming language be more adequate? Would an operating
32990 system on the target device help?
32993 \begin_layout Itemize
32994 if you solved the problem, will the marketing department be happy?
32997 \begin_layout Itemize
32998 if the marketing department is happy, will customers be happy?
33001 \begin_layout Itemize
33002 if you're the project manager, marketing department and maybe even the customer
33003 in one person, have you tried to see the project from the outside?
33006 \begin_layout Itemize
33007 is the project done if you think it is done? Or is just that other interface/pro
33008 tocol/feature/configuration/option missing? How about website, manual(s),
33009 internationali(z|s)ation, packaging, labels, 2nd source for components,
33010 electromagnetic compatability/interference, documentation for production,
33011 production test software, update mechanism, patent issues?
33014 \begin_layout Itemize
33015 is your project adequately positioned in that magic triangle: fame, fortune,
33019 \begin_layout Standard
33020 Maybe not all answers to these questions are known and some answers may
33025 , nevertheless knowing these questions may help you to avoid burnout
33029 \begin_layout Standard
33030 burnout is bad for electronic devices, programmers and motorcycle tyres
33036 Chances are you didn't want to hear some of them...
33039 \begin_layout Chapter
33041 \begin_inset LatexCommand \index{Support}
33048 \begin_layout Standard
33049 SDCC has grown to be a large project.
33050 The compiler alone (without the preprocessor, assembler and linker) is
33051 well over 150,000 lines of code (blank stripped).
33052 The open source nature of this project is a key to its continued growth
33054 You gain the benefit and support of many active software developers and
33056 Is SDCC perfect? No, that's why we need your help.
33057 The developers take pride in fixing reported bugs.
33058 You can help by reporting the bugs and helping other SDCC users.
33059 There are lots of ways to contribute, and we encourage you to take part
33060 in making SDCC a great software package.
33064 \begin_layout Standard
33065 The SDCC project is hosted on the SDCC sourceforge site at
33066 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
33071 You'll find the complete set of mailing lists
33072 \begin_inset LatexCommand \index{Mailing list(s)}
33076 , forums, bug reporting system, patch submission
33077 \begin_inset LatexCommand \index{Patch submission}
33082 \begin_inset LatexCommand \index{download}
33086 area and Subversion code repository
33087 \begin_inset LatexCommand \index{Subversion code repository}
33094 \begin_layout Section
33096 \begin_inset LatexCommand \index{Bug reporting}
33101 \begin_inset LatexCommand \index{Reporting bugs}
33108 \begin_layout Standard
33109 The recommended way of reporting bugs is using the infrastructure of the
33111 You can follow the status of bug reports there and have an overview about
33115 \begin_layout Standard
33116 Bug reports are automatically forwarded to the developer mailing list and
33117 will be fixed ASAP.
33118 When reporting a bug, it is very useful to include a small test program
33119 (the smaller the better) which reproduces the problem.
33120 If you can isolate the problem by looking at the generated assembly code,
33121 this can be very helpful.
33122 Compiling your program with the -
33126 \begin_layout Standard
33136 \begin_inset LatexCommand \index{-\/-dumpall}
33140 option can sometimes be useful in locating optimization problems.
33141 When reporting a bug please make sure you:
33144 \begin_layout Enumerate
33145 Attach the code you are compiling with SDCC.
33149 \begin_layout Enumerate
33150 Specify the exact command you use to run SDCC, or attach your Makefile.
33154 \begin_layout Enumerate
33155 Specify the SDCC version (type "
33161 "), your platform, and operating system.
33165 \begin_layout Enumerate
33166 Provide an exact copy of any error message or incorrect output.
33170 \begin_layout Enumerate
33171 Put something meaningful in the subject of your message.
33174 \begin_layout Standard
33175 Please attempt to include these 5 important parts, as applicable, in all
33176 requests for support or when reporting any problems or bugs with SDCC.
33177 Though this will make your message lengthy, it will greatly improve your
33178 chance that SDCC users and developers will be able to help you.
33179 Some SDCC developers are frustrated by bug reports without code provided
33180 that they can use to reproduce and ultimately fix the problem, so please
33181 be sure to provide sample code if you are reporting a bug!
33184 \begin_layout Standard
33185 Please have a short check that you are using a recent version of SDCC and
33186 the bug is not yet known.
33187 This is the link for reporting bugs:
33188 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
33193 With SDCC on average having more than 200 downloads
33194 \begin_inset LatexCommand \index{download}
33198 on sourceforge per day
33202 \begin_layout Standard
33203 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
33204 between 2002 and 2005.
33205 This does not include other methods of distribution.
33210 there must be some users.
33211 So it's not exactly easy to find a new bug.
33212 If you find one we need it:
33214 reporting bugs is good
33219 \begin_layout Section
33220 Requesting Features
33221 \begin_inset LatexCommand \label{sub:Requesting-Features}
33226 \begin_inset LatexCommand \index{Feature request}
33231 \begin_inset LatexCommand \index{Requesting features}
33238 \begin_layout Standard
33239 Like bug reports feature requests are forwarded to the developer mailing
33241 This is the link for requesting features:
33242 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33249 \begin_layout Section
33253 \begin_layout Standard
33254 Like bug reports contributed patches are forwarded to the developer mailing
33256 This is the link for submitting patches
33257 \begin_inset LatexCommand \index{Patch submission}
33262 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
33269 \begin_layout Standard
33270 You need to specify some parameters to the
33274 command for the patches to be useful.
33275 If you modified more than one file a patch created f.e.
33280 \begin_inset Quotes sld
33283 diff -Naur unmodified_directory modified_directory >my_changes.patch
33284 \begin_inset Quotes srd
33290 will be fine, otherwise
33294 \begin_inset Quotes sld
33297 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
33298 \begin_inset Quotes srd
33308 \begin_layout Section
33312 \begin_layout Standard
33313 These links should take you directly to the
33314 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
33322 \begin_layout Standard
33323 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
33324 automated messages (mid 2003)
33330 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
33335 \begin_inset LatexCommand \index{Mailing list(s)}
33339 and forums are archived and searchable so if you are lucky someone already
33340 had a similar problem.
33341 While mails to the lists themselves are delivered promptly their web front
33342 end on sourceforge sometimes shows a severe time lag (up to several weeks),
33343 if you're seriously using SDCC please consider subscribing to the lists.
33346 \begin_layout Section
33350 \begin_layout Standard
33351 You can follow the status of the Subversion version
33352 \begin_inset LatexCommand \index{version}
33356 of SDCC by watching the Changelog
33357 \begin_inset LatexCommand \index{Changelog}
33361 in the Subversion repository
33364 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
33371 \begin_layout Section
33372 Subversion Source Code Repository
33375 \begin_layout Standard
33385 \begin_layout Standard
33399 or the filenames of the snapshot versions of SDCC include date and its
33401 \begin_inset LatexCommand \index{Subversion code repository}
33406 Subversion allows to download the source of recent or previous versions
33408 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
33412 (by number or by date).
33413 An on-line source code browser and detailled instructions are also available
33415 SDCC versions starting from 1999 up to now are available (currently the
33416 versions prior to the conversion from cvs
33417 \begin_inset LatexCommand \index{cvs|see{Subversion}}
33421 to Subversion (April 2006) are either by accessible by Subversion or by
33425 \begin_layout Section
33427 \begin_inset LatexCommand \index{Release policy}
33434 \begin_layout Standard
33435 Historically there often were long delays between official releases and
33436 the sourceforge download area tends to get not updated at all.
33437 Excuses in the past might have referred to problems with live range analysis,
33438 but as this was fixed a while ago, the current problem is that another
33439 excuse has to be found.
33440 Kidding aside, we have to get better there! On the other hand there are
33441 daily snapshots available at
33442 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
33446 , and you can always build the very last version (hopefully with many bugs
33447 fixed, and features added) from the source code available at
33448 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
33454 \begin_inset LatexCommand \index{wiki}
33459 \begin_inset LatexCommand \index{SDCC Wiki}
33464 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/}
33468 also holds some information about past and future releases.
33471 \begin_layout Section
33473 \begin_inset LatexCommand \index{Examples}
33480 \begin_layout Standard
33481 You'll find some small examples in the directory
33483 sdcc/device/examples/.
33486 More examples and libraries are available at
33488 The SDCC Open Knowledge Resource
33489 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
33496 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
33503 \begin_layout Standard
33504 \begin_inset Note Note
33507 \begin_layout Standard
33508 I did insert a reference to Paul's web site here although it seems rather
33509 dedicated to a specific 8032 board (I think it's okay because it f.e.
33510 shows LCD/Harddisc interface and has a free 8051 monitor.
33511 Independent 8032 board vendors face hard competition of heavily subsidized
33512 development boards anyway).
33515 \begin_layout Standard
33516 Maybe we should include some links to real world applications.
33517 Preferably pointer to pointers (one for each architecture) so this stays
33526 \begin_layout Section
33528 \begin_inset LatexCommand \label{sec:Quality-control}
33533 \begin_inset LatexCommand \index{Quality control}
33540 \begin_layout Standard
33541 The compiler is passed through snaphot build compile and build checks.
33547 \begin_inset LatexCommand \index{Regression test}
33551 check that SDCC itself compiles flawlessly on several host platforms (i386,
33552 Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
33553 and checks the quality of the code generated by SDCC by running the code
33554 for several target platforms through simulators.
33555 The regression test suite comprises more than 100 files which expand to
33556 more than 500 test cases which include more than 4500 tests.
33557 The results of these tests are published daily on SDCC's snapshot page
33558 (click on the red or green symbols on the right side of
33559 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
33566 \begin_layout Standard
33567 There is a separate document
33570 \begin_inset LatexCommand \index{Test suite}
33577 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
33581 about the regression test suite.
33584 \begin_layout Standard
33585 You'll find the test code in the directory
33587 sdcc/support/regression
33590 You can run these tests manually by running
33594 in this directory (or f.e.
33599 \begin_inset Quotes sld
33603 \begin_inset Quotes srd
33609 if you don't want to run the complete tests).
33610 The test code might also be interesting if you want to look for examples
33611 \begin_inset LatexCommand \index{Examples}
33615 checking corner cases of SDCC or if you plan to submit patches
33616 \begin_inset LatexCommand \index{Patch submission}
33623 \begin_layout Standard
33624 The PIC14 port uses a different set of regression tests
33625 \begin_inset LatexCommand \index{Regression test (PIC14)}
33629 , you'll find them in the directory
33631 sdcc/src/regression
33636 \begin_layout Section
33637 Use of SDCC in Education
33640 \begin_layout Standard
33649 \begin_layout Standard
33650 the phrase "use in education" might evoke the association "
33654 fit for use in education".
33655 This connotation is not intended but nevertheless risked as the licensing
33656 of SDCC makes it difficult to offer educational discounts
33662 If your rationales are to:
33665 \begin_layout Enumerate
33666 give students a chance to understand the
33670 steps of code generation
33673 \begin_layout Enumerate
33674 have a curriculum that can be extended for years.
33675 Then you could use an fpga board as target and your curriculum will seamlessly
33676 extend from logic synthesis (
33677 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
33682 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
33686 ), over assembly programming, to C to FPGA compilers (
33687 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
33694 \begin_layout Enumerate
33695 be able to insert excursions about skills like using a revision control
33696 system, submitting/applying patches, using a type-setting (as opposed to
33697 word-processing) engine LyX/LaTeX, using
33698 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
33703 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
33707 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
33708 Source Software, CPU simulation, compiler regression tests
33709 \begin_inset LatexCommand \index{Regression test}
33716 And if there should be a shortage of ideas then you can always point students
33717 to the ever-growing feature request list
33718 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33725 \begin_layout Enumerate
33726 not tie students to a specific host platform and instead allow them to use
33731 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
33733 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
33740 \begin_layout Enumerate
33741 not encourage students to use illegal copies of educational software
33744 \begin_layout Enumerate
33745 be immune to licensing/availability/price changes of the chosen tool chain
33748 \begin_layout Enumerate
33749 be able to change to a new target platform without having to adopt a new
33753 \begin_layout Enumerate
33754 have complete control over and insight into the tool chain
33757 \begin_layout Enumerate
33758 make your students aware about the pros and cons of open source software
33762 \begin_layout Enumerate
33763 give back to the public as you are probably at least partially publically
33767 \begin_layout Enumerate
33768 give students a chance to publically prove their skills and to possibly
33769 see a world wide impact
33772 \begin_layout Standard
33773 then SDCC is probably among the first choices.
33774 Well, probably SDCC might be the only choice.
33779 \begin_layout Chapter
33780 SDCC Technical Data
33783 \begin_layout Section
33785 \begin_inset LatexCommand \index{Optimizations}
33792 \begin_layout Standard
33793 SDCC performs a host of standard optimizations in addition to some MCU specific
33798 \begin_layout Subsection
33799 Sub-expression Elimination
33800 \begin_inset LatexCommand \index{Subexpression elimination}
33807 \begin_layout Standard
33808 The compiler does local and
33827 \begin_layout Verse
33835 \begin_layout Standard
33836 will be translated to
33839 \begin_layout Verse
33849 \begin_layout Standard
33850 Some subexpressions are not as obvious as the above example, e.g.:
33853 \begin_layout Verse
33861 \begin_layout Standard
33862 In this case the address arithmetic a->b[i] will be computed only once;
33863 the equivalent code in C would be.
33866 \begin_layout Verse
33876 \begin_layout Standard
33877 The compiler will try to keep these temporary variables in registers.
33880 \begin_layout Subsection
33881 Dead-Code Elimination
33882 \begin_inset LatexCommand \index{Dead-code elimination}
33889 \begin_layout Verse
33904 i = 1; \InsetSpace ~
33913 global = 1;\InsetSpace ~
33927 global = 3;\InsetSpace ~
33933 \begin_layout Standard
33937 \begin_layout Verse
33953 \begin_layout Subsection
33955 \begin_inset LatexCommand \index{Copy propagation}
33962 \begin_layout Verse
33986 \begin_layout Standard
33990 \begin_layout Verse
34014 \begin_layout Standard
34015 Note: the dead stores created by this copy propagation will be eliminated
34016 by dead-code elimination.
34019 \begin_layout Subsection
34021 \begin_inset LatexCommand \index{Loop optimization}
34026 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
34033 \begin_layout Standard
34034 Two types of loop optimizations are done by SDCC
34042 of loop induction variables.
34043 In addition to the strength reduction the optimizer marks the induction
34044 variables and the register allocator tries to keep the induction variables
34045 in registers for the duration of the loop.
34046 Because of this preference of the register allocator
34047 \begin_inset LatexCommand \index{Register allocation}
34051 , loop induction optimization causes an increase in register pressure, which
34052 may cause unwanted spilling of other temporary variables into the stack
34053 \begin_inset LatexCommand \index{stack}
34058 The compiler will generate a warning message when it is forced to allocate
34059 extra space either on the stack or data space.
34060 If this extra space allocation is undesirable then induction optimization
34061 can be eliminated either for the entire source file (with -
34065 \begin_layout Standard
34074 -noinduction option) or for a given function only using #pragma\InsetSpace ~
34076 \begin_inset LatexCommand \index{\#pragma noinduction}
34087 \begin_layout Verse
34090 for (i = 0 ; i < 100 ; i ++)
34099 \begin_layout Standard
34103 \begin_layout Verse
34108 for (i = 0; i < 100; i++)
34117 \begin_layout Standard
34118 As mentioned previously some loop invariants are not as apparent, all static
34119 address computations are also moved out of the loop.
34124 \begin_inset LatexCommand \index{Strength reduction}
34128 , this optimization substitutes an expression by a cheaper expression:
34131 \begin_layout Verse
34134 for (i=0;i < 100; i++)
34143 \begin_layout Standard
34147 \begin_layout Verse
34154 for (i=0;i< 100;i++) {
34160 ar[itemp1] = itemp2;
34178 \begin_layout Standard
34179 The more expensive multiplication
34180 \begin_inset LatexCommand \index{Multiplication}
34184 is changed to a less expensive addition.
34187 \begin_layout Subsection
34189 \begin_inset LatexCommand \index{Loop reversing}
34196 \begin_layout Standard
34197 This optimization is done to reduce the overhead of checking loop boundaries
34198 for every iteration.
34199 Some simple loops can be reversed and implemented using a
34200 \begin_inset Quotes eld
34203 decrement and jump if not zero
34204 \begin_inset Quotes erd
34208 SDCC checks for the following criterion to determine if a loop is reversible
34209 (note: more sophisticated compilers use data-dependency analysis to make
34210 this determination, SDCC uses a more simple minded analysis).
34213 \begin_layout Itemize
34214 The 'for' loop is of the form
34220 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
34230 \begin_layout Itemize
34231 The <for body> does not contain
34232 \begin_inset Quotes eld
34236 \begin_inset Quotes erd
34240 \begin_inset Quotes erd
34246 \begin_layout Itemize
34247 All goto's are contained within the loop.
34250 \begin_layout Itemize
34251 No function calls within the loop.
34254 \begin_layout Itemize
34255 The loop control variable <sym> is not assigned any value within the loop
34258 \begin_layout Itemize
34259 The loop control variable does NOT participate in any arithmetic operation
34263 \begin_layout Itemize
34264 There are NO switch statements in the loop.
34267 \begin_layout Subsection
34268 Algebraic Simplifications
34271 \begin_layout Standard
34272 SDCC does numerous algebraic simplifications, the following is a small sub-set
34273 of these optimizations.
34276 \begin_layout Verse
34279 i = j + 0;\InsetSpace ~
34283 /* changed to: */\InsetSpace ~
34289 i /= 2;\InsetSpace ~
34296 /* changed to: */\InsetSpace ~
34303 = j - j;\InsetSpace ~
34307 /* changed to: */\InsetSpace ~
34313 i = j / 1;\InsetSpace ~
34317 /* changed to: */\InsetSpace ~
34324 \begin_layout Standard
34325 Note the subexpressions
34326 \begin_inset LatexCommand \index{Subexpression}
34330 given above are generally introduced by macro expansions or as a result
34331 of copy/constant propagation.
34334 \begin_layout Subsection
34335 'switch' Statements
34336 \begin_inset LatexCommand \label{sub:'switch'-Statements}
34341 \begin_inset LatexCommand \index{switch statement}
34348 \begin_layout Standard
34349 SDCC can optimize switch statements to jump tables
34350 \begin_inset LatexCommand \index{jump tables}
34355 It makes the decision based on an estimate of the generated code size.
34356 SDCC is quite liberal in the requirements for jump table generation:
34359 \begin_layout Itemize
34360 The labels need not be in order, and the starting number need not be one
34361 or zero, the case labels are in numerical sequence or not too many case
34362 labels are missing.
34366 \begin_layout Verse
34369 switch(i) {\InsetSpace ~
34400 case 4: ...\InsetSpace ~
34432 case 5: ...\InsetSpace ~
34464 case 3: ...\InsetSpace ~
34495 case 6: ...\InsetSpace ~
34527 case 7: ...\InsetSpace ~
34559 case 8: ...\InsetSpace ~
34591 case 9: ...\InsetSpace ~
34623 case 10: ...\InsetSpace ~
34654 case 11: ...\InsetSpace ~
34721 \begin_layout Standard
34722 Both the above switch statements will be implemented using a jump-table.
34723 The example to the right side is slightly more efficient as the check for
34724 the lower boundary of the jump-table is not needed.
34728 \begin_layout Itemize
34729 The number of case labels is not larger than supported by the target architectur
34733 \begin_layout Itemize
34734 If the case labels are not in numerical sequence ('gaps' between cases)
34735 SDCC checks whether a jump table with additionally inserted dummy cases
34736 is still attractive.
34740 \begin_layout Itemize
34741 If the starting number is not zero and a check for the lower boundary of
34742 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
34747 \begin_layout Standard
34748 Switch statements which have large gaps in the numeric sequence or those
34749 that have too many case labels can be split into more than one switch statement
34750 for efficient code generation, e.g.:
34753 \begin_layout Verse
34831 \begin_layout Standard
34832 If the above switch statement is broken down into two switch statements
34835 \begin_layout Verse
34878 \begin_layout Standard
34882 \begin_layout Verse
34925 \begin_layout Standard
34926 then both the switch statements will be implemented using jump-tables whereas
34927 the unmodified switch statement will not be.
34930 \begin_layout Standard
34931 \begin_inset Note Note
34934 \begin_layout Standard
34935 There might be reasons which SDCC cannot know about to either favour or
34936 not favour jump tables.
34937 If the target system has to be as quick for the last switch case as for
34938 the first (pro jump table), or if the switch argument is known to be zero
34939 in the majority of the cases (contra jump table).
34947 \begin_layout Standard
34948 The pragma nojtbound
34949 \begin_inset LatexCommand \index{\#pragma nojtbound}
34953 can be used to turn off checking the
34966 It has no effect if a default label is supplied.
34967 Use of this pragma is dangerous: if the switch
34968 \begin_inset LatexCommand \index{switch statement}
34972 argument is not matched by a case statement the processor will happily
34976 \begin_layout Subsection
34977 Bit-shifting Operations
34978 \begin_inset LatexCommand \index{Bit shifting}
34985 \begin_layout Standard
34986 Bit shifting is one of the most frequently used operation in embedded programmin
34988 SDCC tries to implement bit-shift operations in the most efficient way
34992 \begin_layout Verse
35005 \begin_layout Standard
35006 generates the following code:
35009 \begin_layout Verse
35024 \begin_layout Standard
35025 In general SDCC will never setup a loop if the shift count is known.
35029 \begin_layout Verse
35042 \begin_layout Standard
35046 \begin_layout Verse
35070 \begin_layout Subsection
35072 \begin_inset LatexCommand \index{Bit rotation}
35079 \begin_layout Standard
35080 A special case of the bit-shift operation is bit rotation
35081 \begin_inset LatexCommand \index{rotating bits}
35085 , SDCC recognizes the following expression to be a left bit-rotation:
35088 \begin_layout Verse
35096 char i;\InsetSpace ~
35107 /* unsigned is needed for rotation */
35112 i = ((i << 1) | (i >> 7));
35121 \begin_layout Standard
35122 will generate the following code:
35125 \begin_layout Verse
35142 \begin_layout Standard
35143 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
35144 ns of this case will also be recognized as bit-rotation, i.e.:
35147 \begin_layout Verse
35150 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
35153 \begin_layout Subsection
35154 Nibble and Byte Swapping
35157 \begin_layout Standard
35158 Other special cases of the bit-shift operations are nibble or byte swapping
35159 \begin_inset LatexCommand \index{swapping nibbles/bytes}
35163 , SDCC recognizes the following expressions:
35166 \begin_layout Verse
35187 i = ((i << 4) | (i >> 4));
35193 j = ((j << 8) | (j >> 8));
35196 \begin_layout Standard
35197 and generates a swap instruction for the nibble swapping
35198 \begin_inset LatexCommand \index{Nibble swapping}
35202 or move instructions for the byte swapping
35203 \begin_inset LatexCommand \index{Byte swapping}
35209 \begin_inset Quotes sld
35213 \begin_inset Quotes srd
35216 example can be used to convert from little to big-endian or vice versa.
35217 If you want to change the endianness of a
35221 integer you have to cast to
35228 \begin_layout Standard
35229 Note that SDCC stores numbers in little-endian
35233 \begin_layout Standard
35234 Usually 8-bit processors don't care much about endianness.
35235 This is not the case for the standard 8051 which only has an instruction
35241 \begin_inset LatexCommand \index{DPTR}
35249 so little-endian is the more efficient byte order.
35255 \begin_inset LatexCommand \index{little-endian}
35260 \begin_inset LatexCommand \index{Endianness}
35265 lowest order first).
35268 \begin_layout Subsection
35270 \begin_inset LatexCommand \index{Highest Order Bit}
35275 \begin_inset LatexCommand \index{Any Order Bit}
35282 \begin_layout Standard
35283 It is frequently required to obtain the highest order bit of an integral
35284 type (long, int, short or char types).
35285 Also obtaining any other order bit is not uncommon.
35286 SDCC recognizes the following expressions to yield the highest order bit
35287 and generates optimized code for it, e.g.:
35290 \begin_layout Verse
35301 unsigned char hob1, aob1;
35305 bit hob2, hob3, aob2,
35315 hob1 = (gint >> 15) & 1;
35319 hob2 = (gint >> 15) & 1;
35323 hob3 = gint & 0x8000;
35328 aob1 = (gint >> 9) & 1;
35332 aob2 = (gint >> 8) & 1;
35336 aob3 = gint & 0x0800;
35346 \begin_layout Standard
35347 will generate the following code:
35350 \begin_layout Verse
35381 000A E5*01\InsetSpace ~
35408 000C 23\InsetSpace ~
35439 000D 54 01\InsetSpace ~
35467 000F F5*02\InsetSpace ~
35522 0011 E5*01\InsetSpace ~
35550 0013 33\InsetSpace ~
35580 0014 92*00\InsetSpace ~
35636 0016 E5*01\InsetSpace ~
35663 0018 33\InsetSpace ~
35693 0019 92*01\InsetSpace ~
35749 001B E5*01\InsetSpace ~
35808 001E 54 01\InsetSpace ~
35835 0020 F5*03\InsetSpace ~
35891 0022 E5*01\InsetSpace ~
35918 0024 13\InsetSpace ~
35948 0025 92*02\InsetSpace ~
36004 0027 E5*01\InsetSpace ~
36059 002B 92*03\InsetSpace ~
36087 \begin_layout Standard
36088 Other variations of these cases however will
36093 They are standard C expressions, so I heartily recommend these be the only
36094 way to get the highest order bit, (it is portable).
36095 Of course it will be recognized even if it is embedded in other expressions,
36099 \begin_layout Verse
36102 xyz = gint + ((gint >> 15) & 1);
36105 \begin_layout Standard
36106 will still be recognized.
36109 \begin_layout Subsection
36111 \begin_inset LatexCommand \index{Higher Order Byte}
36115 / Higher Order Word
36116 \begin_inset LatexCommand \index{Higher Order Word}
36123 \begin_layout Standard
36124 It is also frequently required to obtain a higher order byte or word of
36125 a larger integral type (long, int or short types).
36126 SDCC recognizes the following expressions to yield the higher order byte
36127 or word and generates optimized code for it, e.g.:
36130 \begin_layout Verse
36135 unsigned long int glong;
36143 unsigned char hob1,
36148 unsigned int how1, how2;
36157 hob1 = (gint >> 8) & 0xFF;
36161 hob2 = glong >> 24;
36165 how1 = (glong >> 16) & 0xFFFF;
36180 \begin_layout Standard
36181 will generate the following code:
36184 \begin_layout Verse
36215 0037 85*01*06\InsetSpace ~
36237 _foo_hob1_1_1,(_gint + 1)
36268 003A 85*05*07\InsetSpace ~
36290 _foo_hob2_1_1,(_glong + 3)
36320 003D 85*04*08\InsetSpace ~
36343 _foo_how1_1_1,(_glong + 2)
36345 0040 85*05*09\InsetSpace ~
36370 0043 85*03*0A\InsetSpace ~
36392 _foo_how2_1_1,(_glong + 1)
36394 0046 85*04*0B\InsetSpace ~
36417 (_foo_how2_1_1 + 1),(_glong + 2)
36420 \begin_layout Standard
36421 Again, variations of these cases may
36426 They are standard C expressions, so I heartily recommend these be the only
36427 way to get the higher order byte/word, (it is portable).
36428 Of course it will be recognized even if it is embedded in other expressions,
36432 \begin_layout Verse
36435 xyz = gint + ((gint >> 8) & 0xFF);
36438 \begin_layout Standard
36439 will still be recognized.
36442 \begin_layout Subsection
36444 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
36449 \begin_inset LatexCommand \index{Peephole optimizer}
36456 \begin_layout Standard
36457 The compiler uses a rule based, pattern matching and re-writing mechanism
36458 for peep-hole optimization.
36463 a peep-hole optimizer by Christopher W.
36464 Fraser (cwfraser\InsetSpace ~
36467 A default set of rules are compiled into the compiler, additional rules
36468 may be added with the
36474 \begin_layout Standard
36484 \begin_inset LatexCommand \index{-\/-peep-file}
36491 The rule language is best illustrated with examples.
36494 \begin_layout Verse
36516 \begin_layout Standard
36517 The above rule will change the following assembly
36518 \begin_inset LatexCommand \index{Assembler routines}
36525 \begin_layout Verse
36533 \begin_layout Standard
36537 \begin_layout Verse
36543 \begin_layout Standard
36544 Note: All occurrences of a
36548 (pattern variable) must denote the same string.
36549 With the above rule, the assembly sequence:
36552 \begin_layout Verse
36560 \begin_layout Standard
36561 will remain unmodified.
36565 Other special case optimizations may be added by the
36572 \begin_layout Standard
36585 some variants of the 8051 MCU
36586 \begin_inset LatexCommand \index{MCS51 variants}
36599 The following two rules will change all
36616 \begin_layout Verse
36619 replace { lcall %1 } by { acall %1 }
36621 replace { ljmp %1 } by { ajmp %1 }
36624 \begin_layout Standard
36625 (NOTE: from version 2.7.3 on, you can use option -
36631 \begin_layout Standard
36643 \begin_inset LatexCommand \index{-\/-acall-ajmp}
36647 , which also takes care of aligning the interrupt vectors properly.)
36652 \begin_layout Standard
36655 inline-assembler code
36657 is also passed through the peep hole optimizer, thus the peephole optimizer
36658 can also be used as an assembly level macro expander.
36659 The rules themselves are MCU dependent whereas the rule language infra-structur
36660 e is MCU independent.
36661 Peephole optimization rules for other MCU can be easily programmed using
36666 The syntax for a rule is as follows:
36669 \begin_layout Verse
36672 rule := replace [ restart ] '{' <assembly sequence> '
36710 <assembly sequence> '
36728 '}' [if <functionName> ] '
36733 \begin_layout Standard
36734 <assembly sequence> := assembly instruction (each instruction including
36735 labels must be on a separate line).
36739 The optimizer will apply to the rules
36740 one by one from the top in the sequence of their appearance, it will terminate
36741 when all rules are exhausted.
36742 If the 'restart' option is specified, then the optimizer will start matching
36743 the rules again from the top, this option for a rule is expensive (performance)
36744 , it is intended to be used in situations where a transformation will trigger
36745 the same rule again.
36746 An example of this (not a good one, it has side effects) is the following
36750 \begin_layout Verse
36770 \begin_layout Standard
36771 Note that the replace pattern cannot be a blank, but can be a comment line.
36772 Without the 'restart' option only the innermost 'pop' 'push' pair would
36773 be eliminated, i.e.:
36776 \begin_layout Verse
36788 \begin_layout Standard
36792 \begin_layout Verse
36802 \begin_layout Standard
36807 the restart option the rule will be applied again to the resulting code
36808 and then all the pop-push pairs will be eliminated to yield:
36811 \begin_layout Verse
36819 \begin_layout Standard
36820 A conditional function can be attached to a rule.
36821 Attaching rules are somewhat more involved, let me illustrate this with
36825 \begin_layout Verse
36849 \begin_layout Standard
36850 The optimizer does a look-up of a function name table defined in function
36855 in the source file SDCCpeeph.c, with the name
36860 If it finds a corresponding entry the function is called.
36861 Note there can be no parameters specified for these functions, in this
36866 is crucial, since the function
36870 expects to find the label in that particular variable (the hash table containin
36871 g the variable bindings is passed as a parameter).
36872 If you want to code more such functions, take a close look at the function
36873 labelInRange and the calling mechanism in source file SDCCpeeph.c.
36874 Currently implemented are
36876 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
36877 24bitMode, portIsDS390, 24bitModeAndPortDS390
36886 \begin_layout Standard
36887 I know this whole thing is a little kludgey, but maybe some day we will
36888 have some better means.
36889 If you are looking at this file, you will see the default rules that are
36890 compiled into the compiler, you can add your own rules in the default set
36891 there if you get tired of specifying the -
36895 \begin_layout Standard
36907 \begin_layout Section
36909 \begin_inset LatexCommand \index{ANSI-compliance}
36914 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
36921 \begin_layout Standard
36922 The latest publically available version of the standard
36924 ISO/IEC 9899 - Programming languages - C
36926 should be available at:
36927 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
36936 \begin_layout Standard
36937 Deviations from the compliance:
36940 \begin_layout Itemize
36941 functions are not reentrant
36942 \begin_inset LatexCommand \index{reentrant}
36946 unless explicitly declared as such or the
36952 \begin_layout Standard
36962 \begin_inset LatexCommand \index{-\/-stack-auto}
36968 command line option is specified.
36971 \begin_layout Itemize
36973 \begin_inset LatexCommand \index{struct}
36978 \begin_inset LatexCommand \index{union}
36982 cannot be assigned values directly, cannot be passed as function parameters
36983 or assigned to each other and cannot be a return value
36984 \begin_inset LatexCommand \index{return value}
36988 from a function, e.g.:
36992 \begin_layout Verse
37015 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
37034 s parms) /* invalid in SDCC although allowed in ANSI */
37056 return rets; /* is invalid in SDCC although allowed in ANSI */
37062 \begin_layout Itemize
37063 initialization of structure arrays must be fully braced.
37067 \begin_layout Verse
37070 struct s { char x } a[] = {1, 2};\InsetSpace ~
37075 /* invalid in SDCC */
37078 } a[] = {{1}, {2}}; /* OK */
37082 \begin_layout Itemize
37084 \begin_inset LatexCommand \index{long long (not supported)}
37089 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
37096 \begin_layout Itemize
37098 \begin_inset LatexCommand \index{double (not supported)}
37102 ' precision floating point
37103 \begin_inset LatexCommand \index{Floating point support}
37110 \begin_layout Itemize
37112 \begin_inset LatexCommand \index{K\&R style}
37116 function declarations are NOT allowed.
37120 \begin_layout Verse
37123 foo(i,j) /* this old style of function declarations */
37125 int i,j; /* is valid
37126 in ANSI but not valid in SDCC */
37141 \begin_layout Itemize
37142 Most enhancements in C99 are not supported, e.g.:
37146 \begin_layout Verse
37153 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
37157 \begin_layout Itemize
37158 But some have been added recently in SDCC 2.7.0.
37159 They must be considered alpha quality however.
37163 \begin_layout Verse
37168 \begin_inset LatexCommand \index{inline (not supported)}
37174 int increment (int a) { return a+1; } /* inlines the increment without
37175 function call overhead */
37180 \begin_inset LatexCommand \index{inline (not supported)}
37186 p; /* accepted but ignored */
37190 \begin_layout Itemize
37191 Certain words that are valid identifiers in the standard may be reserved
37192 words in SDCC unless the
37198 \begin_layout Standard
37208 \begin_inset LatexCommand \index{-\/-std-c89}
37220 \begin_layout Standard
37230 \begin_inset LatexCommand \index{-\/-std-c99}
37236 command line options are used.
37237 These may include (depending on the selected processor): 'at', 'banked',
37238 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
37239 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
37240 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
37242 Compliant equivalents of these keywords are always available in a form
37243 that begin with two underscores
37244 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
37249 '__data' instead of 'data'.
37252 \begin_layout Itemize
37253 Integer promotion of variable arguments is not performed if the argument
37254 is explicitly taypecasted unless the
37260 \begin_layout Standard
37270 \begin_inset LatexCommand \index{-\/-std-c89}
37282 \begin_layout Standard
37292 \begin_inset LatexCommand \index{-\/-std-c99}
37298 command line options are used.
37302 \begin_layout Verse
37305 void vararg_func (char *str, ...) { str; }
37322 u is promoted to int before
37327 * passing to function */
37331 vararg_func ("%c", c);
37338 argument u is not promoted to int,
37343 * it is passed as char to function
37349 --std-cXX is not defined;
37354 * is promoted to int before passing
37360 if --std-cXX is defined */
37364 vararg_func ("%bc", (char)u);
37370 \begin_layout Section
37371 Cyclomatic Complexity
37372 \begin_inset LatexCommand \index{Cyclomatic complexity}
37379 \begin_layout Standard
37380 Cyclomatic complexity of a function is defined as the number of independent
37381 paths the program can take during execution of the function.
37382 This is an important number since it defines the number test cases you
37383 have to generate to validate the function.
37384 The accepted industry standard for complexity number is 10, if the cyclomatic
37385 complexity reported by SDCC exceeds 10 you should think about simplification
37386 of the function logic.
37387 Note that the complexity level is not related to the number of lines of
37388 code in a function.
37389 Large functions can have low complexity, and small functions can have large
37395 SDCC uses the following formula to compute the complexity:
37400 \begin_layout Standard
37401 complexity = (number of edges in control flow graph) - (number of nodes
37402 in control flow graph) + 2;
37406 Having said that the industry standard is 10,
37407 you should be aware that in some cases it be may unavoidable to have a
37408 complexity level of less than 10.
37409 For example if you have switch statement with more than 10 case labels,
37410 each case label adds one to the complexity level.
37411 The complexity level is by no means an absolute measure of the algorithmic
37412 complexity of the function, it does however provide a good starting point
37413 for which functions you might look at for further optimization.
37416 \begin_layout Section
37417 Retargetting for other Processors
37420 \begin_layout Standard
37421 The issues for retargetting the compiler are far too numerous to be covered
37423 What follows is a brief description of each of the seven phases of the
37424 compiler and its MCU dependency.
37427 \begin_layout Itemize
37428 Parsing the source and building the annotated parse tree.
37429 This phase is largely MCU independent (except for the language extensions).
37430 Syntax & semantic checks are also done in this phase, along with some initial
37431 optimizations like back patching labels and the pattern matching optimizations
37432 like bit-rotation etc.
37435 \begin_layout Itemize
37436 The second phase involves generating an intermediate code which can be easy
37437 manipulated during the later phases.
37438 This phase is entirely MCU independent.
37439 The intermediate code generation assumes the target machine has unlimited
37440 number of registers, and designates them with the name iTemp.
37441 The compiler can be made to dump a human readable form of the code generated
37446 \begin_layout Standard
37458 \begin_layout Itemize
37459 This phase does the bulk of the standard optimizations and is also MCU independe
37461 This phase can be broken down into several sub-phases:
37465 Break down intermediate
37466 code (iCode) into basic blocks.
37468 Do control flow & data flow analysis on the
37471 Do local common subexpression elimination, then global subexpressio
37474 Dead code elimination
37478 If loop optimizations
37479 caused any changes then do 'global subexpression elimination' and 'dead
37480 code elimination' again.
37483 \begin_layout Itemize
37484 This phase determines the live-ranges; by live range I mean those iTemp
37485 variables defined by the compiler that still survive after all the optimization
37487 Live range analysis
37488 \begin_inset LatexCommand \index{Live range analysis}
37492 is essential for register allocation, since these computation determines
37493 which of these iTemps will be assigned to registers, and for how long.
37496 \begin_layout Itemize
37497 Phase five is register allocation.
37498 There are two parts to this process.
37502 The first part I call 'register packing'
37503 (for lack of a better term).
37504 In this case several MCU specific expression folding is done to reduce
37509 The second part is more MCU independent and deals with
37510 allocating registers to the remaining live ranges.
37511 A lot of MCU specific code does creep into this phase because of the limited
37512 number of index registers available in the 8051.
37515 \begin_layout Itemize
37516 The Code generation phase is (unhappily), entirely MCU dependent and very
37517 little (if any at all) of this code can be reused for other MCU.
37518 However the scheme for allocating a homogenized assembler operand for each
37519 iCode operand may be reused.
37522 \begin_layout Itemize
37523 As mentioned in the optimization section the peep-hole optimizer is rule
37524 based system, which can reprogrammed for other MCUs.
37527 \begin_layout Standard
37528 More information is available on SDCC Wiki
37529 \begin_inset LatexCommand \index{wiki}
37534 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting}
37538 ) and in the thread
37539 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
37546 \begin_layout Chapter
37548 \begin_inset LatexCommand \index{Compiler internals}
37555 \begin_layout Section
37556 The anatomy of the compiler
37557 \begin_inset LatexCommand \label{sub:The-anatomy-of}
37564 \begin_layout Standard
37567 This is an excerpt from an article published in Circuit Cellar Magazine
37573 It's a little outdated (the compiler is much more efficient now and user/develo
37574 per friendly), but pretty well exposes the guts of it all.
37580 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
37581 It is fairly easy to retarget for other 8-bit MCU.
37582 Here we take a look at some of the internals of the compiler.
37586 \begin_layout Paragraph*
37588 \begin_inset LatexCommand \index{Parsing}
37595 \begin_layout Standard
37596 Parsing the input source file and creating an AST (Annotated Syntax Tree
37597 \begin_inset LatexCommand \index{Annotated syntax tree}
37602 This phase also involves propagating types (annotating each node of the
37603 parse tree with type information) and semantic analysis.
37604 There are some MCU specific parsing rules.
37605 For example the storage classes, the extended storage classes are MCU specific
37606 while there may be a xdata storage class for 8051 there is no such storage
37607 class for z80 or Atmel AVR.
37608 SDCC allows MCU specific storage class extensions, i.e.
37609 xdata will be treated as a storage class specifier when parsing 8051 C
37610 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
37614 \begin_layout Paragraph*
37616 \begin_inset LatexCommand \index{iCode}
37623 \begin_layout Standard
37624 Intermediate code generation.
37625 In this phase the AST is broken down into three-operand form (iCode).
37626 These three operand forms are represented as doubly linked lists.
37627 ICode is the term given to the intermediate form generated by the compiler.
37628 ICode example section shows some examples of iCode generated for some simple
37629 C source functions.
37632 \begin_layout Paragraph*
37634 \begin_inset LatexCommand \index{Optimizations}
37641 \begin_layout Standard
37642 Bulk of the target independent optimizations is performed in this phase.
37643 The optimizations include constant propagation, common sub-expression eliminati
37644 on, loop invariant code movement, strength reduction of loop induction variables
37645 and dead-code elimination.
37648 \begin_layout Paragraph*
37649 Live range analysis
37650 \begin_inset LatexCommand \index{Live range analysis}
37657 \begin_layout Standard
37658 During intermediate code generation phase, the compiler assumes the target
37659 machine has infinite number of registers and generates a lot of temporary
37661 The live range computation determines the lifetime of each of these compiler-ge
37662 nerated temporaries.
37663 A picture speaks a thousand words.
37664 ICode example sections show the live range annotations for each of the
37666 It is important to note here, each iCode is assigned a number in the order
37667 of its execution in the function.
37668 The live ranges are computed in terms of these numbers.
37669 The from number is the number of the iCode which first defines the operand
37670 and the to number signifies the iCode which uses this operand last.
37673 \begin_layout Paragraph*
37674 Register Allocation
37675 \begin_inset LatexCommand \index{Register allocation}
37682 \begin_layout Standard
37683 The register allocation determines the type and number of registers needed
37685 In most MCUs only a few registers can be used for indirect addressing.
37686 In case of 8051 for example the registers R0 & R1 can be used to indirectly
37687 address the internal ram and DPTR to indirectly address the external ram.
37688 The compiler will try to allocate the appropriate register to pointer variables
37690 ICode example section shows the operands annotated with the registers assigned
37692 The compiler will try to keep operands in registers as much as possible;
37693 there are several schemes the compiler uses to do achieve this.
37694 When the compiler runs out of registers the compiler will check to see
37695 if there are any live operands which is not used or defined in the current
37696 basic block being processed, if there are any found then it will push that
37697 operand and use the registers in this block, the operand will then be popped
37698 at the end of the basic block.
37702 \begin_layout Standard
37703 There are other MCU specific considerations in this phase.
37704 Some MCUs have an accumulator; very short-lived operands could be assigned
37705 to the accumulator instead of a general-purpose register.
37708 \begin_layout Paragraph*
37712 \begin_layout Standard
37713 Figure II gives a table of iCode
37714 \begin_inset LatexCommand \index{iCode}
37718 operations supported by the compiler.
37719 The code generation involves translating these operations into corresponding
37720 assembly code for the processor.
37721 This sounds overly simple but that is the essence of code generation.
37722 Some of the iCode operations are generated on a MCU specific manner for
37723 example, the z80 port does not use registers to pass parameters so the
37724 SEND and RECV iCode operations will not be generated, and it also does
37725 not support JUMPTABLES.
37731 \begin_layout Standard
37735 \begin_inset Tabular
37736 <lyxtabular version="3" rows="39" columns="4">
37737 <features islongtable="true" headBottomDL="true">
37738 <column alignment="block" valignment="top" leftline="true" width="13col%">
37739 <column alignment="left" valignment="top" leftline="true" width="13col%">
37740 <column alignment="block" valignment="top" leftline="true" width="22col%">
37741 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
37742 <row topline="true" bottomline="true" endhead="true">
37743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37746 \begin_layout Standard
37752 \begin_inset LatexCommand \index{iCode}
37761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37764 \begin_layout Standard
37772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37775 \begin_layout Standard
37783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37786 \begin_layout Standard
37795 <row topline="true">
37796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37799 \begin_layout Standard
37807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37810 \begin_layout Standard
37813 IC_LEFT() IC_RESULT()
37818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37821 \begin_layout Standard
37829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37832 \begin_layout Standard
37835 IC_RESULT = ! IC_LEFT;
37841 <row topline="true">
37842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37845 \begin_layout Standard
37853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37856 \begin_layout Standard
37859 IC_LEFT() IC_RESULT()
37864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37867 \begin_layout Standard
37870 Bitwise complement of
37875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37878 \begin_layout Standard
37881 IC_RESULT = ~IC_LEFT;
37887 <row topline="true">
37888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37891 \begin_layout Standard
37899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37902 \begin_layout Standard
37905 IC_LEFT() IC_RESULT()
37910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37913 \begin_layout Standard
37916 Rotate right with carry
37921 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37924 \begin_layout Standard
37927 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
37933 <row topline="true">
37934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37937 \begin_layout Standard
37945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37948 \begin_layout Standard
37951 IC_LEFT() IC_RESULT()
37956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37959 \begin_layout Standard
37962 Rotate left with carry
37967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37970 \begin_layout Standard
37973 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
37979 <row topline="true">
37980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37983 \begin_layout Standard
37991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37994 \begin_layout Standard
37997 IC_LEFT() IC_RESULT()
38002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38005 \begin_layout Standard
38008 Get the highest order bit of IC_LEFT
38013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38016 \begin_layout Standard
38019 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
38025 <row topline="true">
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
38043 IC_LEFT() IC_RESULT()
38048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38051 \begin_layout Standard
38059 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38062 \begin_layout Standard
38065 IC_RESULT = - IC_LEFT;
38071 <row topline="true">
38072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38075 \begin_layout Standard
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" usebox="none">
38097 \begin_layout Standard
38100 Push the operand into stack
38105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38108 \begin_layout Standard
38117 <row topline="true">
38118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38121 \begin_layout Standard
38129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38132 \begin_layout Standard
38140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38143 \begin_layout Standard
38146 Pop the operand from the stack
38151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38154 \begin_layout Standard
38163 <row topline="true">
38164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38167 \begin_layout Standard
38175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38178 \begin_layout Standard
38181 IC_LEFT() IC_RESULT()
38186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38189 \begin_layout Standard
38192 Call the function represented by IC_LEFT
38197 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38200 \begin_layout Standard
38203 IC_RESULT = IC_LEFT();
38209 <row topline="true">
38210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38213 \begin_layout Standard
38221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38224 \begin_layout Standard
38227 IC_LEFT() IC_RESULT()
38232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38235 \begin_layout Standard
38238 Call via function pointer
38243 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38246 \begin_layout Standard
38249 IC_RESULT = (*IC_LEFT)();
38255 <row topline="true">
38256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38259 \begin_layout Standard
38267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38270 \begin_layout Standard
38278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38281 \begin_layout Standard
38284 Return the value in operand IC_LEFT
38289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38292 \begin_layout Standard
38301 <row topline="true">
38302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38305 \begin_layout Standard
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" usebox="none">
38327 \begin_layout Standard
38335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38338 \begin_layout Standard
38347 <row topline="true">
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
38370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38373 \begin_layout Standard
38381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38384 \begin_layout Standard
38393 <row topline="true">
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 IC_LEFT() IC_RIGHT() IC_RESULT()
38416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38419 \begin_layout Standard
38427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38430 \begin_layout Standard
38433 IC_RESULT = IC_LEFT + IC_RIGHT
38439 <row topline="true">
38440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38443 \begin_layout Standard
38451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38454 \begin_layout Standard
38457 IC_LEFT() IC_RIGHT() IC_RESULT()
38462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38465 \begin_layout Standard
38473 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38476 \begin_layout Standard
38479 IC_RESULT = IC_LEFT - IC_RIGHT
38485 <row topline="true">
38486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38489 \begin_layout Standard
38497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38500 \begin_layout Standard
38503 IC_LEFT() IC_RIGHT() IC_RESULT()
38508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38511 \begin_layout Standard
38519 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38522 \begin_layout Standard
38525 IC_RESULT = IC_LEFT * IC_RIGHT;
38531 <row topline="true">
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 IC_LEFT() IC_RIGHT() IC_RESULT()
38554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38557 \begin_layout Standard
38565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38568 \begin_layout Standard
38571 IC_RESULT = IC_LEFT / IC_RIGHT;
38577 <row topline="true">
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
38595 IC_LEFT() IC_RIGHT() IC_RESULT()
38600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38603 \begin_layout Standard
38611 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38614 \begin_layout Standard
38617 IC_RESULT = IC_LEFT % IC_RIGHT;
38623 <row topline="true">
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
38641 IC_LEFT() IC_RIGHT() IC_RESULT()
38646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38649 \begin_layout Standard
38657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38660 \begin_layout Standard
38663 IC_RESULT = IC_LEFT < IC_RIGHT;
38669 <row topline="true">
38670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38673 \begin_layout Standard
38681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38684 \begin_layout Standard
38687 IC_LEFT() IC_RIGHT() IC_RESULT()
38692 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38695 \begin_layout Standard
38703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38706 \begin_layout Standard
38709 IC_RESULT = IC_LEFT > IC_RIGHT;
38715 <row topline="true">
38716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38719 \begin_layout Standard
38727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38730 \begin_layout Standard
38733 IC_LEFT() IC_RIGHT() IC_RESULT()
38738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38741 \begin_layout Standard
38749 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38752 \begin_layout Standard
38755 IC_RESULT = IC_LEFT == IC_RIGHT;
38761 <row topline="true">
38762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38765 \begin_layout Standard
38773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38776 \begin_layout Standard
38779 IC_LEFT() IC_RIGHT() IC_RESULT()
38784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38787 \begin_layout Standard
38790 Logical and operation
38795 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38798 \begin_layout Standard
38801 IC_RESULT = IC_LEFT && IC_RIGHT;
38807 <row topline="true">
38808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38811 \begin_layout Standard
38819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38822 \begin_layout Standard
38825 IC_LEFT() IC_RIGHT() IC_RESULT()
38830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38833 \begin_layout Standard
38836 Logical or operation
38841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38844 \begin_layout Standard
38847 IC_RESULT = IC_LEFT || IC_RIGHT;
38853 <row topline="true">
38854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38857 \begin_layout Standard
38865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38868 \begin_layout Standard
38871 IC_LEFT() IC_RIGHT() IC_RESULT()
38876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38879 \begin_layout Standard
38887 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38890 \begin_layout Standard
38893 IC_RESULT = IC_LEFT ^ IC_RIGHT;
38899 <row topline="true">
38900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38903 \begin_layout Standard
38911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38914 \begin_layout Standard
38917 IC_LEFT() IC_RIGHT() IC_RESULT()
38922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38925 \begin_layout Standard
38933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38936 \begin_layout Standard
38939 IC_RESULT = IC_LEFT | IC_RIGHT;
38945 <row topline="true">
38946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38949 \begin_layout Standard
38957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38960 \begin_layout Standard
38963 IC_LEFT() IC_RIGHT() IC_RESULT()
38968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38971 \begin_layout Standard
38979 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38982 \begin_layout Standard
38985 IC_RESULT = IC_LEFT & IC_RIGHT;
38991 <row topline="true">
38992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38995 \begin_layout Standard
39003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39006 \begin_layout Standard
39009 IC_LEFT() IC_RIGHT() IC_RESULT()
39014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39017 \begin_layout Standard
39025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39028 \begin_layout Standard
39031 IC_RESULT = IC_LEFT << IC_RIGHT
39037 <row topline="true">
39038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39041 \begin_layout Standard
39049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39052 \begin_layout Standard
39055 IC_LEFT() IC_RIGHT() IC_RESULT()
39060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39063 \begin_layout Standard
39071 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39074 \begin_layout Standard
39077 IC_RESULT = IC_LEFT >> IC_RIGHT
39083 <row topline="true">
39084 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39087 \begin_layout Standard
39097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39100 \begin_layout Standard
39103 IC_LEFT() IC_RESULT()
39108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39111 \begin_layout Standard
39119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39122 \begin_layout Standard
39125 IC_RESULT = (*IC_LEFT);
39131 <row topline="true">
39132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39135 \begin_layout Standard
39143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39146 \begin_layout Standard
39149 IC_RIGHT() IC_RESULT()
39154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39157 \begin_layout Standard
39165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39168 \begin_layout Standard
39171 (*IC_RESULT) = IC_RIGHT;
39177 <row topline="true">
39178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39181 \begin_layout Standard
39189 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39192 \begin_layout Standard
39195 IC_RIGHT() IC_RESULT()
39200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39203 \begin_layout Standard
39211 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39214 \begin_layout Standard
39217 IC_RESULT = IC_RIGHT;
39223 <row topline="true">
39224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39227 \begin_layout Standard
39235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39238 \begin_layout Standard
39241 IC_COND IC_TRUE IC_LABEL
39246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39249 \begin_layout Standard
39253 If true label is present then jump to true label if condition is true else
39254 jump to false label if condition is false
39259 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39262 \begin_layout Standard
39265 if (IC_COND) goto IC_TRUE;
39271 If (!IC_COND) goto IC_FALSE;
39277 <row topline="true">
39278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39281 \begin_layout Standard
39289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39292 \begin_layout Standard
39295 IC_LEFT() IC_RESULT()
39300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39303 \begin_layout Standard
39311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39314 \begin_layout Standard
39317 IC_RESULT = &IC_LEFT();
39323 <row topline="true">
39324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39327 \begin_layout Standard
39335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39338 \begin_layout Standard
39341 IC_JTCOND IC_JTLABELS
39346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39349 \begin_layout Standard
39352 Jump to list of labels depending on the value of JTCOND
39357 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39360 \begin_layout Standard
39369 <row topline="true">
39370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39373 \begin_layout Standard
39381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39384 \begin_layout Standard
39387 IC_RIGHT() IC_LEFT() IC_RESULT()
39392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39395 \begin_layout Standard
39403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39406 \begin_layout Standard
39409 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
39415 <row topline="true">
39416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39419 \begin_layout Standard
39427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39430 \begin_layout Standard
39438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39441 \begin_layout Standard
39444 This is used for passing parameters in registers;
39446 move IC_LEFT to the next
39447 available parameter register.
39452 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39455 \begin_layout Standard
39464 <row topline="true">
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" usebox="none">
39479 \begin_layout Standard
39487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39490 \begin_layout Standard
39493 This is used for receiving parameters passed in registers;
39496 in the next parameter register to IC_RESULT
39501 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39504 \begin_layout Standard
39513 <row topline="true" bottomline="true">
39514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39517 \begin_layout Standard
39521 (some more have been added)
39526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39529 \begin_layout Standard
39535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39538 \begin_layout Standard
39544 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39547 \begin_layout Standard
39571 \begin_layout Standard
39572 \begin_inset Note Note
39575 \begin_layout Standard
39576 In the original article Figure II was announced to be downloadable on
39581 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
39589 \begin_layout Paragraph*
39591 \begin_inset LatexCommand \index{iCode}
39598 \begin_layout Standard
39599 This section shows some details of iCode.
39600 The example C code does not do anything useful; it is used as an example
39601 to illustrate the intermediate code generated by the compiler.
39604 \begin_layout Verse
39614 /* This function does nothing useful.
39621 for the purpose of explaining iCode */
39624 short function (data
39633 short i=10; \InsetSpace ~
39635 /* dead initialization eliminated */
39641 /* dead initialization eliminated */
39669 /* compiler detects i,j to be induction
39674 for (i = 0, j = 10 ; i < 10 ; i++, j
39680 \begin_layout Standard
39703 mul += i * 3; \InsetSpace ~
39705 /* this multiplication remains */
39712 j * 3;\InsetSpace ~
39714 /* this multiplication changed to addition */
39728 \begin_layout Standard
39729 In addition to the operands each iCode contains information about the filename
39730 and line it corresponds to in the source file.
39731 The first field in the listing should be interpreted as follows:
39736 Filename(linenumber: iCode Execution sequence number : ICode hash table
39737 key : loop depth of the iCode).
39742 Then follows the human readable form of the ICode operation.
39743 Each operand of this triplet form can be of three basic types a) compiler
39744 generated temporary b) user defined variable c) a constant value.
39745 Note that local variables and parameters are replaced by compiler generated
39748 \begin_inset LatexCommand \index{Live range analysis}
39752 are computed only for temporaries (i.e.
39753 live ranges are not computed for global variables).
39755 \begin_inset LatexCommand \index{Register allocation}
39759 are allocated for temporaries only.
39760 Operands are formatted in the following manner:
39765 Operand Name [lr live-from : live-to ] { type information } [ registers
39771 As mentioned earlier the live ranges are computed in terms of the execution
39772 sequence number of the iCodes, for example
39774 the iTemp0 is live from (i.e.
39775 first defined in iCode with execution sequence number 3, and is last used
39776 in the iCode with sequence number 5).
39777 For induction variables such as iTemp21 the live range computation extends
39778 the lifetime from the start to the end of the loop.
39780 The register allocator
39781 used the live range information to allocate registers, the same registers
39782 may be used for different temporaries if their live ranges do not overlap,
39783 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
39784 ranges do not overlap.
39785 In addition the allocator also takes into consideration the type and usage
39786 of a temporary, for example itemp6 is a pointer to near space and is used
39787 as to fetch data from (i.e.
39788 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
39789 Some short lived temporaries are allocated to special registers which have
39790 meaning to the code generator e.g.
39791 iTemp13 is allocated to a pseudo register CC which tells the back end that
39792 the temporary is used only for a conditional jump the code generation makes
39793 use of this information to optimize a compare and jump ICode.
39797 \begin_inset LatexCommand \index{Loop optimization}
39801 performed by the compiler.
39802 It can detect induction variables iTemp21(i) and iTemp23(j).
39803 Also note the compiler does selective strength reduction
39804 \begin_inset LatexCommand \index{Strength reduction}
39809 the multiplication of an induction variable in line 18 (gint = j * 3) is
39810 changed to addition, a new temporary iTemp17 is allocated and assigned
39811 a initial value, a constant 3 is then added for each iteration of the loop.
39812 The compiler does not change the multiplication
39813 \begin_inset LatexCommand \index{Multiplication}
39817 in line 17 however since the processor does support an 8 * 8 bit multiplication.
39820 Note the dead code elimination
39821 \begin_inset LatexCommand \index{Dead-code elimination}
39825 optimization eliminated the dead assignments in line 7 & 8 to I and sum
39831 \begin_layout Standard
39834 Sample.c (5:1:0:0) _entry($9) :
39837 \begin_layout Standard
39840 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
39843 \begin_layout Standard
39846 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
39849 \begin_layout Standard
39852 Sample.c(11:4:53:0) preHeaderLbl0($11) :
39855 \begin_layout Standard
39858 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
39862 \begin_layout Standard
39865 Sample.c(11:6:5:1) _whilecontinue_0($1) :
39868 \begin_layout Standard
39871 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
39875 \begin_layout Standard
39878 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39881 \begin_layout Standard
39884 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
39888 \begin_layout Standard
39891 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
39895 \begin_layout Standard
39898 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
39902 \begin_layout Standard
39905 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
39909 \begin_layout Standard
39912 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
39913 * int}[r0] + 0x2 {short}
39916 \begin_layout Standard
39919 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
39922 \begin_layout Standard
39925 Sample.c(11:17:21:0)_whilebreak_0($3) :
39928 \begin_layout Standard
39931 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39934 \begin_layout Standard
39937 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39940 \begin_layout Standard
39943 Sample.c(15:20:54:0)preHeaderLbl1($13) :
39946 \begin_layout Standard
39949 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39952 \begin_layout Standard
39955 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39958 \begin_layout Standard
39961 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39964 \begin_layout Standard
39967 Sample.c(15:24:26:1)_forcond_0($4) :
39970 \begin_layout Standard
39973 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
39977 \begin_layout Standard
39980 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39983 \begin_layout Standard
39986 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
39987 + ITemp21 [lr21:38]{short}[r4]
39990 \begin_layout Standard
39993 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
39997 \begin_layout Standard
40000 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
40001 + iTemp15 [lr29:30]{short}[r1]
40004 \begin_layout Standard
40007 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
40011 \begin_layout Standard
40014 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
40018 \begin_layout Standard
40021 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
40025 \begin_layout Standard
40028 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
40032 \begin_layout Standard
40035 Sample.c(19:38:47:1) goto _forcond_0($4)
40038 \begin_layout Standard
40041 Sample.c(19:39:48:0)_forbreak_0($7) :
40044 \begin_layout Standard
40047 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
40048 + ITemp11 [lr19:40]{short}[r3]
40051 \begin_layout Standard
40054 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
40057 \begin_layout Standard
40060 Sample.c(20:42:51:0)_return($8) :
40063 \begin_layout Standard
40066 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
40072 Finally the code generated for this function:
40077 \begin_layout Standard
40083 \begin_layout Standard
40089 \begin_layout Standard
40097 \begin_layout Standard
40103 \begin_layout Standard
40111 \begin_layout Standard
40117 \begin_layout Standard
40120 ; ----------------------------------------------
40123 \begin_layout Standard
40126 ; function function
40129 \begin_layout Standard
40132 ; ----------------------------------------------
40135 \begin_layout Standard
40141 \begin_layout Standard
40144 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
40147 \begin_layout Standard
40155 \begin_layout Standard
40158 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
40161 \begin_layout Standard
40169 \begin_layout Standard
40172 ;_whilecontinue_0($1) :
40175 \begin_layout Standard
40181 \begin_layout Standard
40184 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
40187 \begin_layout Standard
40190 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
40193 \begin_layout Standard
40201 \begin_layout Standard
40209 \begin_layout Standard
40217 \begin_layout Standard
40225 \begin_layout Standard
40233 \begin_layout Standard
40241 \begin_layout Standard
40249 \begin_layout Standard
40255 \begin_layout Standard
40258 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
40261 \begin_layout Standard
40269 \begin_layout Standard
40277 \begin_layout Standard
40280 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
40283 \begin_layout Standard
40291 \begin_layout Standard
40299 \begin_layout Standard
40307 \begin_layout Standard
40315 \begin_layout Standard
40323 \begin_layout Standard
40331 \begin_layout Standard
40334 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
40337 \begin_layout Standard
40345 \begin_layout Standard
40353 \begin_layout Standard
40361 \begin_layout Standard
40369 \begin_layout Standard
40377 \begin_layout Standard
40380 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
40383 \begin_layout Standard
40391 \begin_layout Standard
40399 \begin_layout Standard
40407 \begin_layout Standard
40410 ; iTemp6 [lr5:16]{_near * int}[r0] =
40413 \begin_layout Standard
40416 ; iTemp6 [lr5:16]{_near * int}[r0] +
40419 \begin_layout Standard
40425 \begin_layout Standard
40433 \begin_layout Standard
40436 ; goto _whilecontinue_0($1)
40439 \begin_layout Standard
40447 \begin_layout Standard
40450 ; _whilebreak_0($3) :
40453 \begin_layout Standard
40459 \begin_layout Standard
40462 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
40465 \begin_layout Standard
40473 \begin_layout Standard
40476 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
40479 \begin_layout Standard
40487 \begin_layout Standard
40490 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
40493 \begin_layout Standard
40501 \begin_layout Standard
40504 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
40507 \begin_layout Standard
40515 \begin_layout Standard
40523 \begin_layout Standard
40526 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
40529 \begin_layout Standard
40537 \begin_layout Standard
40545 \begin_layout Standard
40551 \begin_layout Standard
40557 \begin_layout Standard
40560 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
40563 \begin_layout Standard
40566 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
40569 \begin_layout Standard
40577 \begin_layout Standard
40585 \begin_layout Standard
40593 \begin_layout Standard
40601 \begin_layout Standard
40609 \begin_layout Standard
40615 \begin_layout Standard
40618 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
40621 \begin_layout Standard
40624 ; iTemp21 [lr21:38]{short}[r4]
40627 \begin_layout Standard
40635 \begin_layout Standard
40643 \begin_layout Standard
40651 \begin_layout Standard
40654 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
40657 \begin_layout Standard
40665 \begin_layout Standard
40673 \begin_layout Standard
40681 \begin_layout Standard
40689 \begin_layout Standard
40692 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
40695 \begin_layout Standard
40698 ; iTemp15 [lr29:30]{short}[r1]
40701 \begin_layout Standard
40709 \begin_layout Standard
40717 \begin_layout Standard
40720 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
40723 \begin_layout Standard
40731 \begin_layout Standard
40739 \begin_layout Standard
40747 \begin_layout Standard
40755 \begin_layout Standard
40763 \begin_layout Standard
40771 \begin_layout Standard
40774 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
40777 \begin_layout Standard
40785 \begin_layout Standard
40793 \begin_layout Standard
40801 \begin_layout Standard
40809 \begin_layout Standard
40817 \begin_layout Standard
40825 \begin_layout Standard
40828 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
40831 \begin_layout Standard
40839 \begin_layout Standard
40842 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
40845 \begin_layout Standard
40853 \begin_layout Standard
40858 cjne r5,#0xff,00104$
40861 \begin_layout Standard
40869 \begin_layout Standard
40872 ; goto _forcond_0($4)
40875 \begin_layout Standard
40883 \begin_layout Standard
40886 ; _forbreak_0($7) :
40889 \begin_layout Standard
40895 \begin_layout Standard
40898 ; ret iTemp24 [lr40:41]{short}
40901 \begin_layout Standard
40909 \begin_layout Standard
40917 \begin_layout Standard
40925 \begin_layout Standard
40931 \begin_layout Standard
40937 \begin_layout Standard
40947 \begin_layout Section
40948 A few words about basic block successors, predecessors and dominators
40951 \begin_layout Standard
40952 Successors are basic blocks
40953 \begin_inset LatexCommand \index{Basic blocks}
40957 that might execute after this basic block.
40959 Predecessors are basic blocks
40960 that might execute before reaching this basic block.
40962 Dominators are basic
40963 blocks that WILL execute before reaching this basic block.
40968 \begin_layout Standard
40972 \begin_layout Standard
40976 \begin_layout Standard
40984 \begin_layout Standard
40988 \begin_layout Standard
40996 \begin_layout Standard
41002 \begin_layout Standard
41003 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
41006 \begin_layout Standard
41007 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
41010 \begin_layout Standard
41011 c) domVect of [BB4] = BB1 ...
41012 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
41016 \begin_layout Chapter
41020 \begin_layout Standard
41021 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/#Who}
41031 Thanks to all the other volunteer developers who have helped with coding,
41032 testing, web-page creation, distribution sets, etc.
41033 You know who you are :-)
41041 Thanks to Sourceforge
41042 \begin_inset LatexCommand \url{http://www.sf.net}
41046 which has hosted the project since 1999 and donates significant download
41055 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
41056 cycles and bandwidth for snapshot builds.
41061 \begin_layout Standard
41062 This document was initially written by Sandeep Dutta
41065 \begin_layout Standard
41066 All product names mentioned herein may be trademarks
41067 \begin_inset LatexCommand \index{Trademarks}
41071 of their respective companies.
41075 \begin_layout Section*
41079 \begin_layout Standard
41080 To avoid confusion, the installation and building options for SDCC itself
41081 (chapter 2) are not part of the index.
41084 \begin_layout Standard
41085 \begin_inset LatexCommand \printindex{}