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, 2420, 2423, 2431, 2455, 2480, 24j10
24504 \begin_layout Standard
24505 18F: 2520, 2523, 2525, 2550, 2580, 2585, 25j10, 2620, 2680, 2682, 2685
24508 \begin_layout Standard
24509 18F: 4220, 4221, 4320, 4321, 4331, 4420, 4423, 4431, 4455, 4480, 44j10
24512 \begin_layout Standard
24513 18F: 4520, 4523, 4525, 4550, 4580, 4585, 45j10, 4620, 4680, 4682, 4685
24516 \begin_layout Standard
24517 18F: 6520, 6585, 6620, 6680, 6720
24520 \begin_layout Standard
24521 18F: 8520, 8585, 8620, 8680, 8720
24524 \begin_layout Standard
24525 A list of supported devices is also available via '
24527 sdcc -mpic16 -plist
24532 \begin_layout Subsection
24536 \begin_layout Standard
24537 PIC16 port supports the standard command line arguments as supposed, with
24538 the exception of certain cases that will be mentioned in the following
24542 \begin_layout Description
24547 \begin_layout Standard
24557 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
24565 \begin_layout Standard
24577 \begin_layout Description
24582 \begin_layout Standard
24591 -fommit-frame-pointer
24592 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
24596 Frame pointer will be omitted when the function uses no local variables.
24599 \begin_layout Subsection
24600 Port Specific Options
24601 \begin_inset LatexCommand \index{Options PIC16}
24608 \begin_layout Standard
24609 The port specific options appear after the global options in the sdcc -
24613 \begin_layout Standard
24625 \begin_layout Subsubsection
24626 Code Generation Options
24629 \begin_layout Standard
24630 These options influence the generated assembler code.
24633 \begin_layout Description
24638 \begin_layout Standard
24647 -pstack-model=[model] Used in conjuction with the command above.
24648 Defines the stack model to be used, valid stack models are:
24653 \labelwidthstring 00.00.0000
24658 Selects small stack model.
24659 8 bit stack and frame pointers.
24660 Supports 256 bytes stack size.
24664 \labelwidthstring 00.00.0000
24669 Selects large stack model.
24670 16 bit stack and frame pointers.
24671 Supports 65536 bytes stack size.
24675 \begin_layout Description
24680 \begin_layout Standard
24689 -pno-banksel Do not generate BANKSEL assembler directives.
24692 \begin_layout Description
24697 \begin_layout Standard
24706 -extended Enable extended instruction set/literal offset addressing mode.
24710 \begin_layout Subsubsection
24711 Optimization Options
24714 \begin_layout Description
24719 \begin_layout Standard
24728 -obanksel=n Set optimization level for inserting BANKSELs.
24735 \labelwidthstring 00.00.0000
24740 \labelwidthstring 00.00.0000
24741 1 checks previous used register and if it is the same then does not emit
24742 BANKSEL, accounts only for labels.
24746 \labelwidthstring 00.00.0000
24747 2 tries to check the location of (even different) symbols and removes BANKSELs
24748 if they are in the same bank.
24753 Important: There might be problems if the linker script has data sections
24754 across bank borders!
24758 \begin_layout Description
24763 \begin_layout Standard
24772 -denable-peeps Force the usage of peepholes.
24776 \begin_layout Description
24781 \begin_layout Standard
24790 -no-optimize-goto Do not use (conditional) BRA instead of GOTO.
24793 \begin_layout Description
24798 \begin_layout Standard
24807 -optimize-cmp Try to optimize some compares.
24810 \begin_layout Description
24815 \begin_layout Standard
24824 -optimize-df Analyze the dataflow of the generated code and improve it.
24827 \begin_layout Subsubsection
24831 \begin_layout Description
24836 \begin_layout Standard
24845 -asm= Sets the full path and name of an external assembler to call.
24848 \begin_layout Description
24853 \begin_layout Standard
24863 \begin_inset LatexCommand \index{PIC16!MPLAB}
24867 compatibility option.
24868 Currently only suppresses special gpasm directives.
24871 \begin_layout Subsubsection
24875 \begin_layout Description
24880 \begin_layout Standard
24889 -link= Sets the full path and name of an external linker to call.
24892 \begin_layout Description
24897 \begin_layout Standard
24906 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
24907 unitialized data variables with [kword].
24908 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
24911 \begin_layout Description
24916 \begin_layout Standard
24925 -ivt-loc=n Place the interrupt vector table at address
24930 Useful for bootloaders.
24933 \begin_layout Description
24938 \begin_layout Standard
24947 -nodefaultlibs Do not link default libraries when linking.
24950 \begin_layout Description
24955 \begin_layout Standard
24964 -use-crt= Use a custom run-time module instead of the defaults.
24967 \begin_layout Description
24972 \begin_layout Standard
24981 -no-crt Don't link the default run-time modules
24984 \begin_layout Subsubsection
24988 \begin_layout Standard
24989 Debugging options enable extra debugging information in the output files.
24992 \begin_layout Description
24997 \begin_layout Standard
25006 -debug-xtra Similar to -
25010 \begin_layout Standard
25020 \begin_inset LatexCommand \index{-\/-debug}
25024 , but dumps more information.
25027 \begin_layout Description
25032 \begin_layout Standard
25041 -debug-ralloc Force register allocator to dump <source>.d file with debugging
25043 <source> is the name of the file being compiled.
25046 \begin_layout Description
25051 \begin_layout Standard
25060 -pcode-verbose Enable pcode debugging information in translation.
25063 \begin_layout Description
25068 \begin_layout Standard
25077 -calltree Dump call tree in .calltree file.
25080 \begin_layout Description
25085 \begin_layout Standard
25094 -gstack Trace push/pops for stack pointer overflow.
25097 \begin_layout Subsection
25098 Enviroment Variables
25101 \begin_layout Standard
25102 There is a number of enviromental variables that can be used when running
25103 SDCC to enable certain optimizations or force a specific program behaviour.
25104 these variables are primarily for debugging purposes so they can be enabled/dis
25108 \begin_layout Standard
25109 Currently there is only two such variables available:
25112 \begin_layout Description
25113 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
25114 bitfields is optimized by directly loading FSR0 with the address of the
25115 bitfield structure.
25116 Normally SDCC will cast the bitfield structure to a bitfield pointer and
25118 This step saves data ram and code space for functions that make heavy use
25120 (i.e., 80 bytes of code space are saved when compiling malloc.c with this
25125 \begin_layout Description
25126 NO_REG_OPT Do not perform pCode registers optimization.
25127 This should be used for debugging purposes.
25128 If bugs in the pcode optimizer are found, users can benefit from temporarily
25129 disabling the optimizer until the bug is fixed.
25132 \begin_layout Subsection
25133 Preprocessor Macros
25136 \begin_layout Standard
25138 \begin_inset LatexCommand \index{PIC16}
25142 port defines the following preprocessor macros while translating a source.
25145 \begin_layout Standard
25147 \begin_inset Tabular
25148 <lyxtabular version="3" rows="6" columns="2">
25150 <column alignment="center" valignment="top" leftline="true" width="0">
25151 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25152 <row topline="true" bottomline="true">
25153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25156 \begin_layout Standard
25162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25165 \begin_layout Standard
25172 <row topline="true">
25173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25176 \begin_layout Standard
25182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25185 \begin_layout Standard
25186 Port identification
25192 <row topline="true">
25193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25196 \begin_layout Standard
25201 \begin_layout Standard
25215 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25218 \begin_layout Standard
25219 Port identification (same as above)
25225 <row topline="true">
25226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25229 \begin_layout Standard
25235 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25238 \begin_layout Standard
25239 MCU Identification.
25244 is the microcontrol identification number, i.e.
25251 <row topline="true">
25252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25255 \begin_layout Standard
25260 \begin_layout Standard
25274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25277 \begin_layout Standard
25278 MCU Identification (same as above)
25284 <row topline="true" bottomline="true">
25285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25288 \begin_layout Standard
25294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25297 \begin_layout Standard
25298 nnn = SMALL or LARGE respectively according to the stack model used
25311 \begin_layout Standard
25312 In addition the following macros are defined when calling assembler:
25315 \begin_layout Standard
25317 \begin_inset Tabular
25318 <lyxtabular version="3" rows="4" columns="2">
25320 <column alignment="center" valignment="top" leftline="true" width="0">
25321 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25322 <row topline="true" bottomline="true">
25323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25326 \begin_layout Standard
25332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25335 \begin_layout Standard
25342 <row topline="true">
25343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25346 \begin_layout Standard
25352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25355 \begin_layout Standard
25356 MCU Identification.
25361 is the microcontrol identification number, i.e.
25368 <row topline="true">
25369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25372 \begin_layout Standard
25378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25381 \begin_layout Standard
25382 nnn = SMALL or LARGE respectively according to the memory model used for
25389 <row topline="true" bottomline="true">
25390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25393 \begin_layout Standard
25399 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25402 \begin_layout Standard
25403 nnn = SMALL or LARGE respectively according to the stack model used
25416 \begin_layout Subsection
25420 \begin_layout Standard
25422 \begin_inset LatexCommand \index{PIC16}
25426 port uses the following directories for searching header files and libraries.
25429 \begin_layout Standard
25431 \begin_inset Tabular
25432 <lyxtabular version="3" rows="3" columns="4">
25434 <column alignment="center" valignment="top" leftline="true" width="0">
25435 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25436 <column alignment="center" valignment="top" width="0">
25437 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25438 <row topline="true" bottomline="true">
25439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25442 \begin_layout Standard
25448 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25451 \begin_layout Standard
25457 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25460 \begin_layout Standard
25466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25469 \begin_layout Standard
25476 <row topline="true">
25477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25480 \begin_layout Standard
25481 PREFIX/sdcc/include/pic16
25486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25489 \begin_layout Standard
25490 PIC16 specific headers
25495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25498 \begin_layout Standard
25504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25507 \begin_layout Standard
25514 <row topline="true" bottomline="true">
25515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25518 \begin_layout Standard
25519 PREFIX/sdcc/lib/pic16
25524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25527 \begin_layout Standard
25528 PIC16 specific libraries
25533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25536 \begin_layout Standard
25542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25545 \begin_layout Standard
25559 \begin_layout Subsection
25561 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
25568 \begin_layout Standard
25570 \begin_inset LatexCommand \index{PIC16}
25574 port currently supports the following pragmas:
25577 \begin_layout Description
25579 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
25583 This forces the code generator to initialize the stack & frame pointers
25584 at a specific address.
25585 This is an ad hoc solution for cases where no STACK directive is available
25586 in the linker script or gplink is not instructed to create a stack section.
25589 stack pragma should be used only once in a project.
25590 Multiple pragmas may result in indeterminate behaviour of the program.
25594 \begin_layout Standard
25595 The old format (ie.
25596 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
25597 cross page boundaries (or even exceed the available data RAM) and crash
25599 Make sure that stack does not cross page boundaries when using the SMALL
25607 The format is as follows:
25612 \begin_layout LyX-Code
25613 #pragma stack bottom_address [stack_size]
25618 \begin_layout Standard
25623 is the lower bound of the stack section.
25624 The stack pointer initially will point at address (bottom_address+stack_size-1).
25627 \begin_layout LyX-Code
25631 \begin_layout LyX-Code
25635 \begin_layout LyX-Code
25636 /* initializes stack of 100 bytes at RAM address 0x200 */
25639 \begin_layout LyX-Code
25640 #pragma stack 0x200 100
25643 \begin_layout Standard
25644 If the stack_size field is omitted then a stack is created with the default
25646 This size might be enough for most programs, but its not enough for operations
25647 with deep function nesting or excessive stack usage.
25650 \begin_layout Description
25652 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
25656 Force a function to a static FLASH address.
25659 \begin_layout LyX-Code
25663 \begin_layout LyX-Code
25667 \begin_layout LyX-Code
25668 /* place function test_func at 0x4000 */
25671 \begin_layout LyX-Code
25672 #pragma code test_func 0x4000
25675 \begin_layout LyX-Code
25679 \begin_layout Description
25680 library instructs the linker to use a library module.
25685 \begin_layout LyX-Code
25686 #pragma library module_name
25689 \begin_layout Standard
25694 can be any library or object file (including its path).
25695 Note that there are four reserved keywords which have special meaning.
25699 \begin_layout Standard
25701 \begin_inset Tabular
25702 <lyxtabular version="3" rows="6" columns="3">
25704 <column alignment="center" valignment="top" leftline="true" width="0">
25705 <column alignment="block" valignment="top" leftline="true" width="20page%">
25706 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
25707 <row topline="true" bottomline="true">
25708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25711 \begin_layout Standard
25717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25720 \begin_layout Standard
25726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25729 \begin_layout Standard
25736 <row topline="true">
25737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25740 \begin_layout Standard
25748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25751 \begin_layout Standard
25752 ignore all library pragmas
25757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25760 \begin_layout Standard
25769 <row topline="true">
25770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25773 \begin_layout Standard
25781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25784 \begin_layout Standard
25790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25793 \begin_layout Standard
25804 <row topline="true">
25805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25808 \begin_layout Standard
25816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25819 \begin_layout Standard
25820 link the Math libarary
25825 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25828 \begin_layout Standard
25839 <row topline="true">
25840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25843 \begin_layout Standard
25851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25854 \begin_layout Standard
25855 link the I/O library
25860 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25863 \begin_layout Standard
25874 <row topline="true" bottomline="true">
25875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25878 \begin_layout Standard
25886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25889 \begin_layout Standard
25890 link the debug library
25895 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25898 \begin_layout Standard
25915 * is the device number, i.e.
25916 452 for PIC18F452 MCU.
25919 \begin_layout Standard
25920 This feature allows for linking with specific libraries withoug having to
25921 explicit name them in the command line.
25926 keyword will reject all modules specified by the library pragma.
25929 \begin_layout Description
25930 udata The pragma udata instructs the compiler to emit code so that linker
25931 will place a variable at a specific memory bank.
25934 \begin_layout LyX-Code
25938 \begin_layout LyX-Code
25942 \begin_layout LyX-Code
25943 /* places variable foo at bank2 */
25946 \begin_layout LyX-Code
25947 #pragma udata bank2 foo
25950 \begin_layout LyX-Code
25954 \begin_layout Standard
25955 In order for this pragma to work extra SECTION directives should be added
25956 in the .lkr script.
25957 In the following example a sample .lkr file is shown:
25960 \begin_layout LyX-Code
25964 \begin_layout LyX-Code
25965 // Sample linker script for the PIC18F452 processor
25968 \begin_layout LyX-Code
25972 \begin_layout LyX-Code
25973 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
25976 \begin_layout LyX-Code
25977 CODEPAGE NAME=page START=0x2A END=0x7FFF
25980 \begin_layout LyX-Code
25981 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
25984 \begin_layout LyX-Code
25985 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
25988 \begin_layout LyX-Code
25989 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
25992 \begin_layout LyX-Code
25993 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
25996 \begin_layout LyX-Code
25997 ACCESSBANK NAME=accessram START=0x0 END=0x7F
26000 \begin_layout LyX-Code
26004 \begin_layout LyX-Code
26005 DATABANK NAME=gpr0 START=0x80 END=0xFF
26008 \begin_layout LyX-Code
26009 DATABANK NAME=gpr1 START=0x100 END=0x1FF
26012 \begin_layout LyX-Code
26013 DATABANK NAME=gpr2 START=0x200 END=0x2FF
26016 \begin_layout LyX-Code
26017 DATABANK NAME=gpr3 START=0x300 END=0x3FF
26020 \begin_layout LyX-Code
26021 DATABANK NAME=gpr4 START=0x400 END=0x4FF
26024 \begin_layout LyX-Code
26025 DATABANK NAME=gpr5 START=0x500 END=0x5FF
26028 \begin_layout LyX-Code
26029 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
26032 \begin_layout LyX-Code
26036 \begin_layout LyX-Code
26037 SECTION NAME=CONFIG ROM=config
26040 \begin_layout LyX-Code
26044 \begin_layout LyX-Code
26045 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
26048 \begin_layout LyX-Code
26049 SECTION NAME=bank1 RAM=gpr1 # should be added to link
26052 \begin_layout LyX-Code
26053 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
26056 \begin_layout LyX-Code
26057 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
26060 \begin_layout LyX-Code
26061 SECTION NAME=bank4 RAM=gpr4
26064 \begin_layout LyX-Code
26065 SECTION NAME=bank5 RAM=gpr5
26068 \begin_layout Standard
26069 The linker will recognise the section name set in the pragma statement and
26070 will position the variable at the memory bank set with the RAM field at
26071 the SECTION line in the linker script file.
26074 \begin_layout Subsection
26076 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
26083 \begin_layout Standard
26084 There is one main header file
26085 \begin_inset LatexCommand \index{PIC16!Header files}
26089 that can be included to the source files using the pic16
26090 \begin_inset LatexCommand \index{PIC16}
26100 This header file contains the definitions for the processor special registers,
26101 so it is necessary if the source accesses them.
26102 It can be included by adding the following line in the beginning of the
26106 \begin_layout LyX-Code
26107 #include <pic18fregs.h>
26110 \begin_layout Standard
26111 The specific microcontroller is selected within the pic18fregs.h automatically,
26112 so the same source can be used with a variety of devices.
26115 \begin_layout Subsection
26119 \begin_layout Standard
26121 \begin_inset LatexCommand \index{PIC16!Libraries}
26126 \begin_inset LatexCommand \index{PIC16}
26130 port depends on are the microcontroller device libraries which contain
26131 the symbol definitions for the microcontroller special function registers.
26132 These libraries have the format pic18fxxxx.lib, where
26136 is the microcontroller identification number.
26137 The specific library is selected automatically by the compiler at link
26138 stage according to the selected device.
26141 \begin_layout Standard
26142 Libraries are created with gplib which is part of the gputils package
26143 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
26150 \begin_layout Subsubsection*
26151 Building the libraries
26154 \begin_layout Standard
26155 Before using SDCC/pic16 there are some libraries that need to be compiled.
26156 This process is not done automatically by SDCC since not all users use
26157 SDCC for pic16 projects.
26158 So each user should compile the libraries separately.
26161 \begin_layout Standard
26162 The steps to compile the pic16 libraries under Linux and Mac OS X are:
26165 \begin_layout LyX-Code
26166 cd device/lib/pic16
26169 \begin_layout LyX-Code
26173 \begin_layout LyX-Code
26177 \begin_layout LyX-Code
26181 \begin_layout LyX-Code
26185 \begin_layout LyX-Code
26186 su -c 'make install' # install the libraries, you need the root password
26189 \begin_layout Standard
26190 If you need to install the headers too, do:
26193 \begin_layout LyX-Code
26197 \begin_layout LyX-Code
26198 su -c 'make install' # install the headers, you need the root password
26201 \begin_layout Standard
26202 There exist a special target to build the I/O libraries.
26203 This target is not automatically build because it will build the I/O library
26209 This way building will take quite a lot of time.
26210 Users are advised to edit the
26212 device/lib/pic16/pics.build
26214 file and then execute:
26217 \begin_layout LyX-Code
26221 \begin_layout Subsection
26222 Adding New Devices to the Port
26225 \begin_layout Standard
26226 Adding support for a new 16
26230 \begin_layout Standard
26239 bit PIC MCU requires the following steps:
26242 \begin_layout Enumerate
26243 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
26247 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
26251 \begin_layout Enumerate
26254 mv picDEVICE.h /path/to/sdcc/device/include/pic16
26257 \begin_layout Enumerate
26260 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
26263 \begin_layout Enumerate
26266 /path/to/sdcc/device/lib/pic16/pics.all
26274 Note: No 18f prefix here!
26277 \begin_layout Enumerate
26278 Set up the I/O library by doing
26286 \begin_layout Enumerate
26289 /path/to/sdcc/device/lib/pic16/libio/*.ignore
26293 Add your DEVICE if it does not compile in
26308 \begin_layout Enumerate
26311 /path/to/sdcc/device/include/pic16/adc.h
26315 Add the new devices to the correct ADC style class.
26319 \begin_layout Enumerate
26322 /path/to/sdcc/device/include/pic16/pic18fregs.h
26325 The file format is self-explanatory, just add
26329 #elif defined(picDEVICE)
26331 # include <picDEVICE.h>
26335 at the right place (keep it sorted).
26338 \begin_layout Enumerate
26341 /path/to/sdcc/device/include/pic16devices.txt
26345 Copy and modify an existing entry or create a new one and insert it at the
26346 correct place (keep the file sorted).
26349 \begin_layout Enumerate
26350 Recompile the pic16 libraries.
26353 \begin_layout Subsection
26357 \begin_layout Standard
26358 The following memory models are supported by the PIC16 port:
26361 \begin_layout Itemize
26365 \begin_layout Itemize
26369 \begin_layout Standard
26370 Memory model affects the default size of pointers within the source.
26371 The sizes are shown in the next table:
26374 \begin_layout Standard
26376 \begin_inset Tabular
26377 <lyxtabular version="3" rows="3" columns="3">
26379 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26380 <column alignment="center" valignment="top" leftline="true" width="0">
26381 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26382 <row topline="true" bottomline="true">
26383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26386 \begin_layout Standard
26387 Pointer sizes according to memory model
26392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26395 \begin_layout Standard
26401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26404 \begin_layout Standard
26411 <row topline="true" bottomline="true">
26412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26415 \begin_layout Standard
26421 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26424 \begin_layout Standard
26430 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26433 \begin_layout Standard
26440 <row topline="true" bottomline="true">
26441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26444 \begin_layout Standard
26450 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
26453 \begin_layout Standard
26459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26462 \begin_layout Standard
26476 \begin_layout Standard
26477 It is advisable that all sources within a project are compiled with the
26479 If one wants to override the default memory model, this can be done by
26480 declaring a pointer as
26489 Far selects large memory model's pointers, while near selects small memory
26493 \begin_layout Standard
26494 The standard device libraries (see
26495 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
26499 ) contain no reference to pointers, so they can be used with both memory
26503 \begin_layout Subsection
26507 \begin_layout Standard
26509 \begin_inset LatexCommand \index{PIC16!stack}
26513 implementation for the PIC16 port uses two indirect registers, FSR1 and
26517 \begin_layout Description
26518 FSR1 is assigned as stack pointer
26521 \begin_layout Description
26522 FSR2 is assigned as frame pointer
26525 \begin_layout Standard
26526 The following stack models are supported by the PIC16 port
26529 \begin_layout Itemize
26537 \begin_layout Itemize
26545 \begin_layout Standard
26550 model means that only the FSRxL byte is used to access stack and frame,
26557 uses both FSRxL and FSRxH registers.
26558 The following table shows the stack/frame pointers sizes according to stack
26559 model and the maximum space they can address:
26562 \begin_layout Standard
26564 \begin_inset Tabular
26565 <lyxtabular version="3" rows="3" columns="3">
26567 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26568 <column alignment="center" valignment="top" leftline="true" width="0">
26569 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26570 <row topline="true" bottomline="true">
26571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26574 \begin_layout Standard
26575 Stack & Frame pointer sizes according to stack model
26580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26583 \begin_layout Standard
26589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26592 \begin_layout Standard
26599 <row topline="true">
26600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26603 \begin_layout Standard
26609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26612 \begin_layout Standard
26618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26621 \begin_layout Standard
26628 <row topline="true" bottomline="true">
26629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26632 \begin_layout Standard
26638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26641 \begin_layout Standard
26647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26650 \begin_layout Standard
26664 \begin_layout Standard
26669 stack model is currently not working properly throughout the code generator.
26670 So its use is not advised.
26671 Also there are some other points that need special care:
26676 \begin_layout Enumerate
26677 Do not create stack sections with size more than one physical bank (that
26681 \begin_layout Enumerate
26682 Stack sections should no cross physical bank limits (i.e.
26683 #pragma stack 0x50 0x100)
26686 \begin_layout Standard
26687 These limitations are caused by the fact that only FSRxL is modified when
26688 using SMALL stack model, so no more than 256 bytes of stack can be used.
26689 This problem will disappear after LARGE model is fully implemented.
26692 \begin_layout Subsection
26696 \begin_layout Standard
26697 In addition to the standard SDCC function keywords, PIC16
26698 \begin_inset LatexCommand \index{PIC16}
26702 port makes available two more:
26705 \begin_layout Description
26707 \begin_inset LatexCommand \index{PIC16!wparam}
26711 Use the WREG to pass one byte of the first function argument.
26712 This improves speed but you may not use this for functions with arguments
26713 that are called via function pointers, otherwise the first byte of the
26714 first parameter will get lost.
26718 \begin_layout LyX-Code
26719 void func_wparam(int a) wparam
26722 \begin_layout LyX-Code
26726 \begin_layout LyX-Code
26727 /* WREG hold the lower part of a */
26730 \begin_layout LyX-Code
26731 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
26735 \begin_layout LyX-Code
26739 \begin_layout LyX-Code
26743 \begin_layout Description
26745 \begin_inset LatexCommand \index{PIC16!shadowregs}
26749 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
26750 hardware shadow registers which hold the values of WREG, STATUS and BSR
26752 This can be done by adding the keyword
26760 keyword in the function's header.
26763 \begin_layout LyX-Code
26764 void isr_shadow(void) shadowregs interrupt 1
26767 \begin_layout LyX-Code
26771 \begin_layout LyX-Code
26775 \begin_layout LyX-Code
26779 \begin_layout Standard
26784 instructs the code generator not to store/restore WREG, STATUS, BSR when
26785 entering/exiting the ISR.
26788 \begin_layout Subsection
26789 Function return values
26792 \begin_layout Standard
26793 Return values from functions are placed to the appropriate registers following
26794 a modified Microchip policy optimized for SDCC.
26795 The following table shows these registers:
26798 \begin_layout Standard
26800 \begin_inset Tabular
26801 <lyxtabular version="3" rows="6" columns="2">
26803 <column alignment="center" valignment="top" leftline="true" width="0">
26804 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26805 <row topline="true" bottomline="true">
26806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26809 \begin_layout Standard
26815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26818 \begin_layout Standard
26819 destination register
26825 <row topline="true">
26826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26829 \begin_layout Standard
26835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26838 \begin_layout Standard
26845 <row topline="true">
26846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26849 \begin_layout Standard
26855 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26858 \begin_layout Standard
26865 <row topline="true">
26866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26869 \begin_layout Standard
26875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26878 \begin_layout Standard
26885 <row topline="true">
26886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26889 \begin_layout Standard
26895 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26898 \begin_layout Standard
26899 FSR0L:PRODH:PRODL:WREG
26905 <row topline="true" bottomline="true">
26906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26909 \begin_layout Standard
26915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26918 \begin_layout Standard
26919 on stack, FSR0 points to the beginning
26932 \begin_layout Subsection
26936 \begin_layout Standard
26938 \begin_inset LatexCommand \index{PIC16!interrupt}
26942 service routine (ISR) is declared using the
26949 \begin_layout LyX-Code
26950 void isr(void) interrupt
26955 \begin_layout LyX-Code
26959 \begin_layout LyX-Code
26963 \begin_layout LyX-Code
26967 \begin_layout Standard
26972 is the interrupt number, which for PIC18F devices can be:
26975 \begin_layout Standard
26977 \begin_inset Tabular
26978 <lyxtabular version="3" rows="4" columns="3">
26980 <column alignment="center" valignment="top" leftline="true" width="0">
26981 <column alignment="center" valignment="top" leftline="true" width="0">
26982 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26983 <row topline="true" bottomline="true">
26984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26987 \begin_layout Standard
26995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26998 \begin_layout Standard
27004 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27007 \begin_layout Standard
27008 Interrupt Vector Address
27014 <row topline="true">
27015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27018 \begin_layout Standard
27024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27027 \begin_layout Standard
27033 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27036 \begin_layout Standard
27043 <row topline="true">
27044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27047 \begin_layout Standard
27062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27065 \begin_layout Standard
27075 HIGH priority interrupts
27080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27083 \begin_layout Standard
27090 <row topline="true" bottomline="true">
27091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27094 \begin_layout Standard
27100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27103 \begin_layout Standard
27104 LOW priority interrupts
27109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27112 \begin_layout Standard
27126 \begin_layout Standard
27127 When generating assembly code for ISR the code generator places a
27133 Interrupt Vector Address
27135 which points at the genetated ISR.
27136 This single GOTO instruction is part of an automatically generated
27138 interrupt entry point
27141 The actuall ISR code is placed as normally would in the code space.
27142 Upon interrupt request, the GOTO instruction is executed which jumps to
27144 When declaring interrupt functions as _naked this GOTO instruction is
27149 The whole interrupt functions is therefore placed at the Interrupt Vector
27150 Address of the specific interrupt.
27151 This is not a problem for the LOW priority interrupts, but it is a problem
27152 for the RESET and the HIGH priority interrupts because code may be written
27153 at the next interrupt's vector address and cause undeterminate program
27154 behaviour if that interrupt is raised.
27158 \begin_layout Standard
27159 This is not a problem when
27162 \begin_layout Enumerate
27163 this is a HIGH interrupt ISR and LOW interrupts are
27170 \begin_layout Enumerate
27171 when the ISR is small enough not to reach the next interrupt's vector address.
27179 \begin_layout Standard
27185 This way a function is generated similar to an ISR, but it is not assigned
27189 \begin_layout Standard
27190 When entering an interrupt, currently the PIC16
27191 \begin_inset LatexCommand \index{PIC16}
27195 port automatically saves the following registers:
27198 \begin_layout Itemize
27202 \begin_layout Itemize
27206 \begin_layout Itemize
27210 \begin_layout Itemize
27211 PROD (PRODL and PRODH)
27214 \begin_layout Itemize
27215 FSR0 (FSR0L and FSR0H)
27218 \begin_layout Standard
27219 These registers are restored upon return from the interrupt routine.
27223 \begin_layout Standard
27224 NOTE that when the _naked attribute is specified for an interrupt routine,
27225 then NO registers are stored or restored.
27233 \begin_layout Subsection
27237 \begin_layout Standard
27238 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
27239 There are 3 types of generic pointers currently implemented data, code
27240 and eeprom pointers.
27241 They are differentiated by the value of the 7th and 6th bits of the upper
27245 \begin_layout Standard
27247 \begin_inset Tabular
27248 <lyxtabular version="3" rows="5" columns="5">
27250 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27251 <column alignment="center" valignment="top" width="0">
27252 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27253 <column alignment="center" valignment="top" width="0">
27254 <column alignment="left" valignment="top" rightline="true" width="0">
27255 <row topline="true" bottomline="true">
27256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27259 \begin_layout Standard
27265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27268 \begin_layout Standard
27274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27277 \begin_layout Standard
27283 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27286 \begin_layout Standard
27287 rest of the pointer
27292 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27295 \begin_layout Standard
27302 <row topline="true" bottomline="true">
27303 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27306 \begin_layout Standard
27312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27315 \begin_layout Standard
27321 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27324 \begin_layout Standard
27330 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27333 \begin_layout Standard
27338 uuuuuu uuuuxxxx xxxxxxxx
27343 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27346 \begin_layout Standard
27347 a 12-bit data pointer in data RAM memory
27353 <row bottomline="true">
27354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27357 \begin_layout Standard
27363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27366 \begin_layout Standard
27372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27375 \begin_layout Standard
27381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27384 \begin_layout Standard
27389 uxxxxx xxxxxxxx xxxxxxxx
27394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27397 \begin_layout Standard
27398 a 21-bit code pointer in FLASH memory
27404 <row bottomline="true">
27405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27408 \begin_layout Standard
27414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27417 \begin_layout Standard
27423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27426 \begin_layout Standard
27432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27435 \begin_layout Standard
27440 uuuuuu uuuuuuxx xxxxxxxx
27445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27448 \begin_layout Standard
27449 a 10-bit eeprom pointer in EEPROM memory
27455 <row bottomline="true">
27456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27459 \begin_layout Standard
27465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27468 \begin_layout Standard
27474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27477 \begin_layout Standard
27483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27486 \begin_layout Standard
27491 xxxxxx xxxxxxxx xxxxxxxx
27496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27499 \begin_layout Standard
27500 unimplemented pointer type
27513 \begin_layout Standard
27514 Generic pointer are read and written with a set of library functions which
27515 read/write 1, 2, 3, 4 bytes.
27518 \begin_layout Subsection
27522 \begin_layout Subsubsection
27523 Standard I/O Streams
27526 \begin_layout Standard
27531 the type FILE is defined as:
27534 \begin_layout LyX-Code
27535 typedef char * FILE;
27538 \begin_layout Standard
27539 This type is the stream type implemented I/O in the PIC18F devices.
27540 Also the standard input and output streams are declared in stdio.h:
27543 \begin_layout LyX-Code
27544 extern FILE * stdin;
27547 \begin_layout LyX-Code
27548 extern FILE * stdout;
27551 \begin_layout Standard
27552 The FILE type is actually a generic pointer which defines one more type
27553 of generic pointers, the
27558 This new type has the format:
27561 \begin_layout Standard
27563 \begin_inset Tabular
27564 <lyxtabular version="3" rows="2" columns="7">
27566 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27567 <column alignment="center" valignment="top" width="0">
27568 <column alignment="center" valignment="top" leftline="true" width="0">
27569 <column alignment="center" valignment="top" leftline="true" width="0">
27570 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27571 <column alignment="center" valignment="top" width="0">
27572 <column alignment="left" valignment="top" rightline="true" width="0">
27573 <row topline="true" bottomline="true">
27574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27577 \begin_layout Standard
27583 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27586 \begin_layout Standard
27592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27595 \begin_layout Standard
27601 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27604 \begin_layout Standard
27610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27613 \begin_layout Standard
27619 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27622 \begin_layout Standard
27623 rest of the pointer
27628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27631 \begin_layout Standard
27638 <row topline="true" bottomline="true">
27639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27642 \begin_layout Standard
27648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27651 \begin_layout Standard
27657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27660 \begin_layout Standard
27666 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27669 \begin_layout Standard
27675 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27678 \begin_layout Standard
27684 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27687 \begin_layout Standard
27697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27700 \begin_layout Standard
27701 upper byte high nubble is 0x2n, the rest are zeroes
27714 \begin_layout Standard
27715 Currently implemented there are 3 types of streams defined:
27718 \begin_layout Standard
27720 \begin_inset Tabular
27721 <lyxtabular version="3" rows="4" columns="4">
27723 <column alignment="center" valignment="top" leftline="true" width="0">
27724 <column alignment="center" valignment="top" leftline="true" width="0">
27725 <column alignment="center" valignment="top" leftline="true" width="0">
27726 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27727 <row topline="true" bottomline="true">
27728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27731 \begin_layout Standard
27737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27740 \begin_layout Standard
27746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27749 \begin_layout Standard
27755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27758 \begin_layout Standard
27765 <row topline="true">
27766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27769 \begin_layout Standard
27775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27778 \begin_layout Standard
27786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27789 \begin_layout Standard
27795 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27798 \begin_layout Standard
27799 Writes/Reads characters via the USART peripheral
27805 <row topline="true">
27806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27809 \begin_layout Standard
27815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27818 \begin_layout Standard
27826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27829 \begin_layout Standard
27835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27838 \begin_layout Standard
27839 Writes/Reads characters via the MSSP peripheral
27845 <row topline="true" bottomline="true">
27846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27849 \begin_layout Standard
27855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27858 \begin_layout Standard
27866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27869 \begin_layout Standard
27875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27878 \begin_layout Standard
27879 Writes/Reads characters via used defined functions
27892 \begin_layout Standard
27893 The stream identifiers are declared as macros in the stdio.h header.
27896 \begin_layout Standard
27897 In the libc library there exist the functions that are used to write to
27898 each of the above streams.
27902 \begin_layout Description
27907 \begin_layout Standard
27916 _stream_usart_putchar writes a character at the USART stream
27919 \begin_layout Description
27924 \begin_layout Standard
27933 _stream_mssp_putchar writes a character at the MSSP stream
27936 \begin_layout Description
27937 putchar dummy function.
27938 This writes a character to a user specified manner.
27941 \begin_layout Standard
27942 In order to increase performance
27946 is declared in stdio.h as having its parameter in WREG (it has the wparam
27948 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
27949 in a user-friendly way.
27954 is the name of the variable that holds the character to print.
27955 An example follows:
27958 \begin_layout LyX-Code
27959 #include <pic18fregs.h>
27968 \begin_layout LyX-Code
27972 \begin_layout LyX-Code
27973 PORTA = c; /* dump character c to PORTA */
27976 \begin_layout LyX-Code
27984 \begin_layout LyX-Code
27988 \begin_layout LyX-Code
27989 stdout = STREAM_USER; /* this is not necessary, since stdout points
27992 \begin_layout LyX-Code
27993 * by default to STREAM_USER */
27996 \begin_layout LyX-Code
27998 \begin_inset Quotes sld
28001 This is a printf test
28004 \begin_inset Quotes srd
28010 \begin_layout LyX-Code
28014 \begin_layout LyX-Code
28018 \begin_layout Subsubsection
28022 \begin_layout Standard
28023 PIC16 contains an implementation of the printf-family of functions.
28024 There exist the following functions:
28027 \begin_layout LyX-Code
28028 extern unsigned int sprintf(char *buf, char *fmt, ...);
28031 \begin_layout LyX-Code
28032 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
28035 \begin_layout LyX-Code
28039 \begin_layout LyX-Code
28040 extern unsigned int printf(char *fmt, ...);
28043 \begin_layout LyX-Code
28044 extern unsigned int vprintf(char *fmt, va_lista ap);
28047 \begin_layout LyX-Code
28051 \begin_layout LyX-Code
28052 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
28055 \begin_layout LyX-Code
28056 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
28059 \begin_layout Standard
28060 For sprintf and vsprintf
28064 should normally be a data pointer where the resulting string will be placed.
28065 No range checking is done so the user should allocate the necessery buffer.
28066 For fprintf and vfprintf
28070 should be a stream pointer (i.e.
28071 stdout, STREAM_MSSP, etc...).
28074 \begin_layout Subsubsection
28078 \begin_layout Standard
28079 The PIC18F family of microcontrollers supports a number of interrupt sources.
28080 A list of these interrupts is shown in the following table:
28083 \begin_layout Standard
28085 \begin_inset Tabular
28086 <lyxtabular version="3" rows="11" columns="4">
28088 <column alignment="left" valignment="top" leftline="true" width="0">
28089 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28090 <column alignment="left" valignment="top" leftline="true" width="0">
28091 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28092 <row topline="true" bottomline="true">
28093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28096 \begin_layout Standard
28102 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28105 \begin_layout Standard
28111 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28114 \begin_layout Standard
28120 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28123 \begin_layout Standard
28130 <row topline="true">
28131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28134 \begin_layout Standard
28140 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28143 \begin_layout Standard
28144 PORTB change interrupt
28149 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28152 \begin_layout Standard
28158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28161 \begin_layout Standard
28162 EEPROM/FLASH write complete interrupt
28168 <row topline="true">
28169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28172 \begin_layout Standard
28178 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28181 \begin_layout Standard
28182 INT0 external interrupt
28187 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28190 \begin_layout Standard
28196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28199 \begin_layout Standard
28200 Bus collision interrupt
28206 <row topline="true">
28207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28210 \begin_layout Standard
28216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28219 \begin_layout Standard
28220 INT1 external interrupt
28225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28228 \begin_layout Standard
28234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28237 \begin_layout Standard
28238 Low voltage detect interrupt
28244 <row topline="true">
28245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28248 \begin_layout Standard
28254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28257 \begin_layout Standard
28258 INT2 external interrupt
28263 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28266 \begin_layout Standard
28272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28275 \begin_layout Standard
28276 Parallel slave port interrupt
28282 <row topline="true">
28283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28286 \begin_layout Standard
28292 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28295 \begin_layout Standard
28296 CCP1 module interrupt
28301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28304 \begin_layout Standard
28310 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28313 \begin_layout Standard
28314 AD convertion complete interrupt
28320 <row topline="true">
28321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28324 \begin_layout Standard
28330 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28333 \begin_layout Standard
28334 CCP2 module interrupt
28339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28342 \begin_layout Standard
28348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28351 \begin_layout Standard
28352 USART receive interrupt
28358 <row topline="true">
28359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28362 \begin_layout Standard
28368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28371 \begin_layout Standard
28372 TMR0 overflow interrupt
28377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28380 \begin_layout Standard
28386 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28389 \begin_layout Standard
28390 USART transmit interrupt
28396 <row topline="true">
28397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28400 \begin_layout Standard
28406 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28409 \begin_layout Standard
28410 TMR1 overflow interrupt
28415 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28418 \begin_layout Standard
28424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28427 \begin_layout Standard
28428 SSP receive/transmit interrupt
28434 <row topline="true">
28435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28438 \begin_layout Standard
28444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28447 \begin_layout Standard
28448 TMR2 matches PR2 interrupt
28453 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28456 \begin_layout Standard
28462 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28465 \begin_layout Standard
28472 <row topline="true" bottomline="true">
28473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28476 \begin_layout Standard
28482 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28485 \begin_layout Standard
28486 TMR3 overflow interrupt
28491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28494 \begin_layout Standard
28500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28503 \begin_layout Standard
28517 \begin_layout Standard
28518 The prototypes for these names are defined in the header file
28525 \begin_layout Standard
28526 In order to simplify signal handling, a number of macros is provided:
28530 \labelwidthstring 00.00.0000
28531 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
28532 high priority interrupts.
28537 is the function name to use.
28541 \labelwidthstring 00.00.0000
28542 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
28543 low priority interrupt.
28548 is the function name to use.
28552 \labelwidthstring 00.00.0000
28553 DEF_HANDLER(sig,handler) define a handler for signal
28559 \labelwidthstring 00.00.0000
28560 END_DEF end the declaration of the dispatch table.
28563 \begin_layout Standard
28564 Additionally there are two more macros to simplify the declaration of the
28569 \labelwidthstring 00.00.0000
28572 SIGHANDLER(handler)
28574 this declares the function prototype for the
28582 \labelwidthstring 00.00.0000
28583 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
28586 \begin_layout Standard
28587 An example of using the macros above is shown below:
28590 \begin_layout LyX-Code
28591 #include <pic18fregs.h>
28594 \begin_layout LyX-Code
28595 #include <signal.h>
28599 DEF_INTHIGH(high_int)
28602 \begin_layout LyX-Code
28603 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
28606 \begin_layout LyX-Code
28607 DEF_HANDLER(SIG_BCOL, _bcol_handler)
28610 \begin_layout LyX-Code
28615 SIGHANDLER(_tmr0_handler)
28618 \begin_layout LyX-Code
28622 \begin_layout LyX-Code
28623 /* action to be taken when timer 0 overflows */
28626 \begin_layout LyX-Code
28631 SIGHANDLERNAKED(_bcol_handler)
28634 \begin_layout LyX-Code
28638 \begin_layout LyX-Code
28642 \begin_layout LyX-Code
28643 /* action to be taken when bus collision occurs */
28646 \begin_layout LyX-Code
28650 \begin_layout LyX-Code
28654 \begin_layout LyX-Code
28658 \begin_layout Standard
28663 Special care should be taken when using the above scheme:
28666 \begin_layout Itemize
28667 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
28670 \begin_layout Itemize
28671 when declaring SIGHANDLERNAKED handler never forget to use
28675 for proper returning.
28678 \begin_layout Subsection
28682 \begin_layout Standard
28683 Here you can find some general tips for compiling programs with SDCC/pic16.
28686 \begin_layout Subsubsection
28690 \begin_layout Standard
28692 \begin_inset LatexCommand \index{PIC16!stack}
28696 size (that is 64 bytes) probably is enough for many programs.
28697 One must take care that when there are many levels of function nesting,
28698 or there is excessive usage of stack, its size should be extended.
28699 An example of such a case is the printf/sprintf family of functions.
28700 If you encounter problems like not being able to print integers, then you
28701 need to set the stack size around the maximum (256 for small stack model).
28702 The following diagram shows what happens when calling printf to print an
28706 \begin_layout LyX-Code
28707 printf () --> ltoa () --> ultoa () --> divschar ()
28710 \begin_layout Standard
28711 It is should be understood that stack is easily consumed when calling complicate
28713 Using command line arguments like -
28717 \begin_layout Standard
28726 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
28728 Other ways to reduce stack usage may exist.
28731 \begin_layout Subsection
28735 \begin_layout Standard
28736 The PIC16 Port currently does not pass SDCC's regression test
28737 \begin_inset LatexCommand \index{Regression test (PIC16)}
28742 \begin_inset LatexCommand \ref{sec:Quality-control}
28746 ) and thus the snapshot build regression tests for the PIC16 target are
28747 currently disabled for all hosts
28752 \begin_layout Chapter
28756 \begin_layout Standard
28757 There are several approaches to debugging your code.
28758 This chapter is meant to show your options and to give detail on some of
28763 When writing your code:
28766 \begin_layout Itemize
28767 write your code with debugging in mind (avoid duplicating code, put conceptually
28768 similar variables into structs, use structured code, have strategic points
28769 within your code where all variables are consistent, ...)
28772 \begin_layout Itemize
28773 run a syntax-checking tool like splint
28774 \begin_inset LatexCommand \index{splint (syntax checking tool)}
28779 \begin_inset LatexCommand \index{lint (syntax checking tool)}
28787 \begin_layout Standard
28797 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28804 \begin_layout Itemize
28805 for the high level code use a C-compiler (like f.e.
28806 GCC) to compile run and debug the code on your host.
28811 \begin_layout Standard
28821 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28825 ) on how to handle syntax extensions like __xdata, __at(), ...
28829 \begin_layout Itemize
28830 use another C-compiler to compile code for your target.
28831 Always an option but not recommended:) And not very likely to help you.
28832 If you seriously consider walking this path you should at least occasionally
28833 check portability of your code.
28834 Most commercial compiler vendors will offer an evaluation version so you
28835 can test compile your code or snippets of your code.
28838 \begin_layout Standard
28839 Debugging on a simulator:
28842 \begin_layout Itemize
28843 there is a separate section about SDCDB (section
28844 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
28851 \begin_layout Itemize
28852 or (8051 specific) use a freeware/commercial simulator which interfaces
28854 \begin_inset LatexCommand \index{AOMF, AOMF51}
28859 \begin_inset LatexCommand \ref{OMF file}
28863 ) optionally generated by SDCC.
28866 \begin_layout Standard
28867 Debugging On-target:
28870 \begin_layout Itemize
28871 use a MCU port pin to serially output debug data to the RS232 port of your
28873 You'll probably want some level shifting device typically involving a MAX232
28875 If the hardware serial port of the MCU is not available search for 'Software
28876 UART' in your favourite search machine.
28879 \begin_layout Itemize
28880 use an on-target monitor.
28881 In this context a monitor is a small program which usually accepts commands
28882 via a serial line and allows to set program counter, to single step through
28883 a program and read/write memory locations.
28884 For the 8051 good examples of monitors are paulmon and cmon51 (see section
28886 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
28893 \begin_layout Itemize
28894 toggle MCU port pins at strategic points within your code and use an oscilloscop
28898 digital oscilloscope
28901 \begin_inset LatexCommand \index{Oscilloscope}
28905 with deep trace memory is really helpful especially if you have to debug
28906 a realtime application.
28907 If you need to monitor more pins than your oscilloscope provides you can
28908 sometimes get away with a small R-2R network.
28909 On a single channel oscilloscope you could f.e.
28910 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
28912 \begin_inset Formula $\Omega$
28915 resistor and the other one by a 5\InsetSpace ~
28917 \begin_inset Formula $\Omega$
28920 resistor to the oscilloscope probe (check output drive capability of the
28921 pins you want to monitor).
28922 If you need to monitor many more pins a
28929 \begin_layout Itemize
28943 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
28948 Usually very expensive.
28949 And very nice to have too.
28950 And usually locks you (for years...) to the devices the ICE can emulate.
28954 \begin_layout Itemize
28955 use a remote debugger.
28956 In most 8-bit systems the symbol information is not available on the target,
28957 and a complete debugger is too bulky for the target system.
28958 Therefore usually a debugger on the host system connects to an on-target
28959 debugging stub which accepts only primitive commands.
28962 Terms to enter into your favourite search engine could be 'remote debugging',
28963 'gdb stub' or 'inferior debugger'.
28967 \begin_layout Itemize
28968 use an on target hardware debugger.
28969 Some of the more modern MCUs include hardware support for setting break
28970 points and monitoring/changing variables by using dedicated hardware pins.
28971 This facility doesn't require additional code to run on the target and
28976 doesn't affect runtime behaviour until a breakpoint is hit.
28977 For the mcs51 most hardware debuggers use the AOMF
28978 \begin_inset LatexCommand \index{AOMF, AOMF51}
28983 \begin_inset LatexCommand \ref{OMF file}
28991 \begin_layout Standard
28995 \begin_layout Itemize
28996 if you are not familiar with any of the following terms you're likely to
28997 run into problems rather sooner than later:
29014 As an embedded programmer you
29018 to know them so why not look them up
29022 you have problems?)
29025 \begin_layout Itemize
29026 tell someone else about your problem (actually this is a surprisingly effective
29027 means to hunt down the bug even if the listener is not familiar with your
29029 As 'failure to communicate' is probably one of the job-induced deformations
29030 of an embedded programmer this is highly encouraged.
29033 \begin_layout Section
29034 Debugging with SDCDB
29035 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
29040 \begin_inset LatexCommand \index{SDCDB (debugger)}
29047 \begin_layout Standard
29048 SDCC is distributed with a source level debugger
29049 \begin_inset LatexCommand \index{Debugger}
29054 The debugger uses a command line interface, the command repertoire of the
29055 debugger has been kept as close to gdb
29056 \begin_inset LatexCommand \index{gdb}
29060 (the GNU debugger) as possible.
29061 The configuration and build process is part of the standard compiler installati
29062 on, which also builds and installs the debugger in the target directory
29063 specified during configuration.
29064 The debugger allows you debug BOTH at the C source and at the ASM source
29068 \begin_layout Subsection
29069 Compiling for Debugging
29072 \begin_layout Standard
29077 \begin_layout Standard
29087 \begin_inset LatexCommand \index{-\/-debug}
29091 option must be specified for all files for which debug information is to
29093 The compiler generates a .adb file for each of these files.
29094 The linker creates the .cdb
29095 \begin_inset LatexCommand \index{<file>.cdb}
29100 \begin_inset LatexCommand \index{<file>.adb}
29104 files and the address information.
29105 This .cdb is used by the debugger.
29108 \begin_layout Subsection
29109 How the Debugger Works
29112 \begin_layout Standard
29117 \begin_layout Standard
29126 -debug option is specified the compiler generates extra symbol information
29127 some of which are put into the assembler source and some are put into the
29129 Then the linker creates the .cdb file from the individual .adb files with
29130 the address information for the symbols.
29131 The debugger reads the symbolic information generated by the compiler &
29132 the address information generated by the linker.
29133 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
29134 execution is controlled by the debugger.
29135 When a command is issued for the debugger, it translates it into appropriate
29136 commands for the simulator.
29137 (Currently SDCDM only connects to the simulator but
29142 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
29146 is an effort to connect directly to the hardware.)
29149 \begin_layout Subsection
29150 Starting the Debugger SDCDB
29153 \begin_layout Standard
29154 The debugger can be started using the following command line.
29155 (Assume the file you are debugging has the file name foo).
29169 The debugger will look for the following files.
29172 \begin_layout Itemize
29173 foo.c - the source file.
29176 \begin_layout Itemize
29177 foo.cdb - the debugger symbol information file.
29180 \begin_layout Itemize
29181 foo.ihx - the Intel hex format
29182 \begin_inset LatexCommand \index{Intel hex format}
29189 \begin_layout Subsection
29190 SDCDB Command Line Options
29193 \begin_layout Itemize
29198 \begin_layout Standard
29207 -directory=<source file directory> this option can used to specify the directory
29209 The debugger will look into the directory list specified for source, cdb
29211 The items in the directory list must be separated by ':', e.g.
29212 if the source files can be in the directories /home/src1 and /home/src2,
29217 \begin_layout Standard
29226 -directory option should be -
29230 \begin_layout Standard
29239 -directory=/home/src1:/home/src2.
29240 Note there can be no spaces in the option.
29244 \begin_layout Itemize
29245 -cd <directory> - change to the <directory>.
29248 \begin_layout Itemize
29249 -fullname - used by GUI front ends.
29252 \begin_layout Itemize
29253 -cpu <cpu-type> - this argument is passed to the simulator please see the
29254 simulator docs for details.
29257 \begin_layout Itemize
29258 -X <Clock frequency > this options is passed to the simulator please see
29259 the simulator docs for details.
29262 \begin_layout Itemize
29263 -s <serial port file> passed to simulator see the simulator docs for details.
29266 \begin_layout Itemize
29267 -S <serial in,out> passed to simulator see the simulator docs for details.
29270 \begin_layout Itemize
29271 -k <port number> passed to simulator see the simulator docs for details.
29274 \begin_layout Subsection
29275 SDCDB Debugger Commands
29278 \begin_layout Standard
29279 As mentioned earlier the command interface for the debugger has been deliberatel
29280 y kept as close the GNU debugger gdb, as possible.
29281 This will help the integration with existing graphical user interfaces
29282 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
29283 If you use a graphical user interface for the debugger you can skip this
29287 \begin_layout Subsubsection*
29288 break [line | file:line | function | file:function]
29291 \begin_layout Standard
29292 Set breakpoint at specified line or function:
29301 sdcdb>break foo.c:100
29303 sdcdb>break funcfoo
29305 sdcdb>break foo.c:funcfoo
29308 \begin_layout Subsubsection*
29309 clear [line | file:line | function | file:function ]
29312 \begin_layout Standard
29313 Clear breakpoint at specified line or function:
29322 sdcdb>clear foo.c:100
29324 sdcdb>clear funcfoo
29326 sdcdb>clear foo.c:funcfoo
29329 \begin_layout Subsubsection*
29333 \begin_layout Standard
29334 Continue program being debugged, after breakpoint.
29337 \begin_layout Subsubsection*
29341 \begin_layout Standard
29342 Execute till the end of the current function.
29345 \begin_layout Subsubsection*
29349 \begin_layout Standard
29350 Delete breakpoint number 'n'.
29351 If used without any option clear ALL user defined break points.
29354 \begin_layout Subsubsection*
29355 info [break | stack | frame | registers ]
29358 \begin_layout Itemize
29359 info break - list all breakpoints
29362 \begin_layout Itemize
29363 info stack - show the function call stack.
29366 \begin_layout Itemize
29367 info frame - show information about the current execution frame.
29370 \begin_layout Itemize
29371 info registers - show content of all registers.
29374 \begin_layout Subsubsection*
29378 \begin_layout Standard
29379 Step program until it reaches a different source line.
29380 Note: pressing <return> repeats the last command.
29383 \begin_layout Subsubsection*
29387 \begin_layout Standard
29388 Step program, proceeding through subroutine calls.
29391 \begin_layout Subsubsection*
29395 \begin_layout Standard
29396 Start debugged program.
29399 \begin_layout Subsubsection*
29403 \begin_layout Standard
29404 Print type information of the variable.
29407 \begin_layout Subsubsection*
29411 \begin_layout Standard
29412 print value of variable.
29415 \begin_layout Subsubsection*
29419 \begin_layout Standard
29420 load the given file name.
29421 Note this is an alternate method of loading file for debugging.
29424 \begin_layout Subsubsection*
29428 \begin_layout Standard
29429 print information about current frame.
29432 \begin_layout Subsubsection*
29436 \begin_layout Standard
29437 Toggle between C source & assembly source.
29440 \begin_layout Subsubsection*
29441 ! simulator command
29444 \begin_layout Standard
29445 Send the string following '!' to the simulator, the simulator response is
29447 Note the debugger does not interpret the command being sent to the simulator,
29448 so if a command like 'go' is sent the debugger can loose its execution
29449 context and may display incorrect values.
29452 \begin_layout Subsubsection*
29456 \begin_layout Standard
29459 My name is Bobby Brown"
29462 \begin_layout Subsection
29463 Interfacing SDCDB with DDD
29466 \begin_layout Standard
29467 \begin_inset Note Note
29470 \begin_layout Standard
29471 The screenshot was converted from png to eps with:
29472 \begin_inset Quotes sld
29475 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
29476 \begin_inset Quotes srd
29479 which produces a pretty compact eps file which is free from compression
29483 \begin_layout Standard
29484 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
29485 as this broke the build system on Sourceforge (pdf-file was broken.
29486 pdflatex does not accept eps files).
29494 \begin_layout Standard
29510 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
29516 shows a screenshot of a debugging session with DDD
29517 \begin_inset LatexCommand \index{DDD (debugger)}
29521 (Unix only) on a simulated 8032.
29522 The debugging session might not run as smoothly as the screenshot suggests.
29523 The debugger allows setting of breakpoints, displaying and changing variables,
29524 single stepping through C and assembler code.
29527 The source was compiled with
29541 \begin_layout Standard
29553 -debug ddd_example.c
29566 and DDD was invoked with
29573 ddd -debugger "sdcdb -cpu 8032 ddd_example"
29576 \begin_layout Standard
29577 \begin_inset Note Note
29580 \begin_layout Standard
29581 Check that the double quotes or an apostroph within the command line survive
29582 the LyX tool chain.
29583 Previously the apostrophs got slanted in the PDF output so a cut and paste
29592 \begin_layout Subsection
29593 Interfacing SDCDB with XEmacs
29594 \begin_inset LatexCommand \index{XEmacs}
29599 \begin_inset LatexCommand \index{Emacs}
29606 \begin_layout Standard
29607 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
29608 sdcdb.el and sdcdbsrc.el.
29609 These two files can be found in the $(prefix)/bin directory after the installat
29611 These files need to be loaded into XEmacs for the interface to work.
29612 This can be done at XEmacs startup time by inserting the following into
29613 your '.xemacs' file (which can be found in your HOME directory):
29619 (load-file sdcdbsrc.el)
29625 .xemacs is a lisp file so the () around the command is REQUIRED.
29626 The files can also be loaded dynamically while XEmacs is running, set the
29627 environment variable 'EMACSLOADPATH' to the installation bin directory
29628 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
29629 To start the interface enter the following command:
29643 You will prompted to enter the file name to be debugged.
29648 The command line options that are passed to the simulator directly are
29649 bound to default values in the file sdcdbsrc.el.
29650 The variables are listed below, these values maybe changed as required.
29653 \begin_layout Itemize
29654 sdcdbsrc-cpu-type '51
29657 \begin_layout Itemize
29658 sdcdbsrc-frequency '11059200
29661 \begin_layout Itemize
29662 sdcdbsrc-serial nil
29665 \begin_layout Standard
29666 The following is a list of key mapping for the debugger interface.
29669 \begin_layout Standard
29692 binding\InsetSpace ~
29730 -------\InsetSpace ~
29801 sdcdb-back-from-src\InsetSpace ~
29830 rom-src\InsetSpace ~
29840 SDCDB continue command
29858 sdcdb-step-from-src\InsetSpace ~
29887 hatis-c-sexp\InsetSpace ~
29897 SDCDB ptypecommand for data at
29964 sdcdbsrc-delete\InsetSpace ~
29979 B Delete all breakpoints if no arg
30028 given or delete arg (C-u arg x)
30047 -frame\InsetSpace ~
30062 SDCDB Display current frame if no arg,
30111 given or display frame arg
30179 sdcdbsrc-goto-sdcdb\InsetSpace ~
30189 Goto the SDCDB output buffer
30208 t-c-sexp\InsetSpace ~
30219 SDCDB print command for data at
30286 sdcdbsrc-goto-sdcdb\InsetSpace ~
30297 o the SDCDB output buffer
30315 sdcdbsrc-mode\InsetSpace ~
30331 Toggles Sdcdbsrc mode (turns it
30347 sdcdb-finish-from-src\InsetSpace ~
30355 SDCDB finish command
30389 Set break for line with point
30404 sdcdbsrc-mode\InsetSpace ~
30420 Toggle Sdcdbsrc mode
30436 dbsrc-srcmode\InsetSpace ~
30460 \begin_layout Chapter
30464 \begin_layout Standard
30465 Here are a few guidelines that will help the compiler generate more efficient
30466 code, some of the tips are specific to this compiler others are generally
30467 good programming practice.
30470 \begin_layout Itemize
30471 Use the smallest data type to represent your data-value.
30472 If it is known in advance that the value is going to be less than 256 then
30473 use an 'unsigned char' instead of a 'short' or 'int'.
30474 Please note, that ANSI C requires both signed and unsigned chars to be
30475 promoted to 'signed int'
30476 \begin_inset LatexCommand \index{promotion to signed int}
30481 \begin_inset Marginal
30484 \begin_layout Standard
30493 before doing any operation.
30495 \begin_inset LatexCommand \index{type promotion}
30500 \begin_inset LatexCommand \label{type promotion}
30504 can be omitted, if the result is the same.
30505 The effect of the promotion rules together with the sign-extension is often
30510 \begin_layout Verse
30513 unsigned char uc = 0xfe;
30515 if (uc * uc < 0) /* this is true! */
30528 \begin_layout Standard
30535 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
30543 \begin_layout Verse
30546 (unsigned char) -12 / (signed char) -3 = ...
30549 \begin_layout Standard
30550 No, the result is not 4:
30553 \begin_layout Verse
30556 (int) (unsigned char) -12 / (int) (signed char) -3 =
30558 (int) (unsigned char)
30559 0xf4 / (int) (signed char) 0xfd =
30561 (int) 0x00f4 / (int) 0xfffd =
30566 (int) 244 / (int) -3 =
30568 (int) -81 = (int) 0xffaf;
30571 \begin_layout Standard
30572 Don't complain, that gcc gives you a different result.
30573 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
30574 Therefore the results are different.
30577 \begin_inset Quotes sld
30581 \begin_inset Quotes srd
30587 \begin_layout Quote
30590 If well-defined overflow characteristics are important and negative values
30591 are not, or if you want to steer clear of sign-extension problems when
30592 manipulating bits or bytes, use one of the corresponding unsigned types.
30593 (Beware when mixing signed and unsigned values in expressions, though.)
30596 character types (especially unsigned char) can be used as "tiny" integers,
30597 doing so is sometimes more trouble than it's worth, due to unpredictable
30598 sign extension and increased code size.
30602 \begin_layout Itemize
30603 Use unsigned when it is known in advance that the value is not going to
30605 This helps especially if you are doing division or multiplication, bit-shifting
30606 or are using an array index.
30609 \begin_layout Itemize
30610 NEVER jump into a LOOP.
30613 \begin_layout Itemize
30614 Declare the variables to be local
30615 \begin_inset LatexCommand \index{local variables}
30619 whenever possible, especially loop control variables (induction).
30622 \begin_layout Itemize
30623 Have a look at the assembly listing to get a
30624 \begin_inset Quotes sld
30628 \begin_inset Quotes srd
30631 for the code generation.
30634 \begin_layout Section
30635 Porting code from or to other compilers
30636 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
30643 \begin_layout Itemize
30644 check whether endianness of the compilers differs and adapt where needed.
30647 \begin_layout Itemize
30648 check the device specific header files
30649 \begin_inset LatexCommand \index{Header files}
30654 \begin_inset LatexCommand \index{Include files}
30658 for compiler specific syntax.
30659 Eventually include the file <compiler.h
30660 \begin_inset LatexCommand \index{compiler.h (include file)}
30665 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
30669 to allow using common header files.
30672 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
30679 \begin_layout Itemize
30680 check whether the startup code contains the correct initialization (watchdog,
30684 \begin_layout Itemize
30685 check whether the sizes of short, int, long match.
30688 \begin_layout Itemize
30689 check if some 16 or 32 bit hardware registers require a specific addressing
30690 order (least significant or most significant byte first) and adapt if needed
30699 relate to time and not to lower/upper memory location here, so this is
30704 the same as endianness).
30707 \begin_layout Itemize
30708 check whether the keyword
30712 is used where needed.
30713 The compilers might differ in their optimization characteristics (as different
30714 versions of the same compiler might also use more clever optimizations
30715 this is good idea anyway).
30717 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
30724 \begin_layout Itemize
30725 check that the compilers are not told to supress warnings.
30728 \begin_layout Itemize
30729 check and convert compiler specific extensions (interrupts, memory areas,
30733 \begin_layout Itemize
30734 check for differences in type promotion.
30735 Especially check for math operations on
30744 For the sake of C99 compatibility SDCC will probably promote these to
30748 more often than other compilers.
30749 Eventually insert explicit casts to
30758 Also check that the ~\InsetSpace ~
30760 \begin_inset LatexCommand \index{\~\/ Operator}
30767 \begin_inset LatexCommand \index{bit}
30773 variables, use the !\InsetSpace ~
30776 \begin_inset LatexCommand \ref{type promotion}
30781 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30788 \begin_layout Itemize
30789 check the assembly code generated for interrupt routines (f.e.
30790 for calls to possibly non-reentrant library functions).
30793 \begin_layout Itemize
30794 check whether timing loops result in proper timing (or preferably consider
30795 a rewrite of the code with timer based delays instead).
30798 \begin_layout Itemize
30799 check for differences in printf parameters (some compilers push (va_arg
30800 \begin_inset LatexCommand \index{vararg, va\_arg}
30804 ) char variables as
30808 others push them as
30814 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30821 \begin_layout Itemize
30822 check the resulting memory map
30823 \begin_inset LatexCommand \index{Memory map}
30828 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
30829 ly idata, pdata, xdata).
30830 Eventually check if unexpected library functions are included.
30833 \begin_layout Section
30835 \begin_inset LatexCommand \index{Tools}
30839 included in the distribution
30842 \begin_layout Standard
30844 \begin_inset Tabular
30845 <lyxtabular version="3" rows="12" columns="3">
30847 <column alignment="left" valignment="top" leftline="true" width="0pt">
30848 <column alignment="left" valignment="top" leftline="true" width="0pt">
30849 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30850 <row topline="true" bottomline="true">
30851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30854 \begin_layout Standard
30862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30865 \begin_layout Standard
30873 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30876 \begin_layout Standard
30885 <row topline="true">
30886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30889 \begin_layout Standard
30891 \begin_inset LatexCommand \index{uCsim}
30900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30903 \begin_layout Standard
30904 Simulator for various architectures
30909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30912 \begin_layout Standard
30919 <row topline="true">
30920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30923 \begin_layout Standard
30929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30932 \begin_layout Standard
30934 \begin_inset LatexCommand \index{Header files}
30939 \begin_inset LatexCommand \index{Include files}
30948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30951 \begin_layout Standard
30952 sdcc/support/scripts
30958 <row topline="true">
30959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30962 \begin_layout Standard
30968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30971 \begin_layout Standard
30972 header file conversion
30977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30980 \begin_layout Standard
30981 sdcc/support/scripts
30987 <row topline="true">
30988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30991 \begin_layout Standard
30997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31000 \begin_layout Standard
31006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31009 \begin_layout Standard
31025 <row topline="true">
31026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31029 \begin_layout Standard
31035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31038 \begin_layout Standard
31044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31047 \begin_layout Standard
31063 <row topline="true">
31064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31067 \begin_layout Standard
31073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31076 \begin_layout Standard
31082 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31085 \begin_layout Standard
31101 <row topline="true">
31102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31105 \begin_layout Standard
31111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31114 \begin_layout Standard
31120 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31123 \begin_layout Standard
31139 <row topline="true">
31140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31143 \begin_layout Standard
31149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31152 \begin_layout Standard
31158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31161 \begin_layout Standard
31177 <row topline="true">
31178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31181 \begin_layout Standard
31187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31190 \begin_layout Standard
31196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31199 \begin_layout Standard
31215 <row topline="true">
31216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31219 \begin_layout Standard
31225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31228 \begin_layout Standard
31234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31237 \begin_layout Standard
31253 <row topline="true" bottomline="true">
31254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31257 \begin_layout Standard
31263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31266 \begin_layout Standard
31268 \begin_inset LatexCommand \index{packihx (tool)}
31277 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31280 \begin_layout Standard
31305 \begin_layout Section
31307 \begin_inset LatexCommand \index{Documentation}
31311 included in the distribution
31314 \begin_layout Standard
31316 \begin_inset Tabular
31317 <lyxtabular version="3" rows="10" columns="2">
31319 <column alignment="block" valignment="top" leftline="true" width="40col%">
31320 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
31321 <row topline="true" bottomline="true" endhead="true">
31322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31325 \begin_layout Standard
31333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31336 \begin_layout Standard
31339 Filename / Where to get
31345 <row topline="true">
31346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31349 \begin_layout Standard
31350 SDCC Compiler User Guide
31355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31358 \begin_layout Standard
31359 You're reading it right now
31371 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
31381 <row topline="true">
31382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31385 \begin_layout Standard
31391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31394 \begin_layout Standard
31407 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31417 <row topline="true">
31418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31421 \begin_layout Standard
31423 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
31428 \begin_inset LatexCommand \index{Assembler documentation}
31435 \begin_inset LatexCommand \index{aslink}
31440 \begin_inset LatexCommand \index{Linker documentation}
31449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31452 \begin_layout Standard
31453 sdcc/as/doc/asxhtm.html
31465 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
31475 <row topline="true">
31476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31479 \begin_layout Standard
31480 SDCC regression test
31481 \begin_inset LatexCommand \index{Regression test}
31490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31493 \begin_layout Standard
31494 sdcc/doc/test_suite_spec.pdf
31506 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
31516 <row topline="true">
31517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31520 \begin_layout Standard
31526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31529 \begin_layout Standard
31542 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
31552 <row topline="true">
31553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31556 \begin_layout Standard
31557 Notes on debugging with SDCDB
31558 \begin_inset LatexCommand \index{SDCDB (debugger)}
31567 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31570 \begin_layout Standard
31571 sdcc/debugger/README
31583 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
31593 <row topline="true">
31594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31597 \begin_layout Standard
31599 \begin_inset LatexCommand \index{uCsim}
31603 Software simulator for microcontrollers
31608 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31611 \begin_layout Standard
31641 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
31651 <row topline="true">
31652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31655 \begin_layout Standard
31656 Temporary notes on the pic16
31657 \begin_inset LatexCommand \index{PIC16}
31666 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31669 \begin_layout Standard
31670 sdcc/src/pic16/NOTES
31682 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
31692 <row topline="true" bottomline="true">
31693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31696 \begin_layout Standard
31697 SDCC internal documentation (debugging file format)
31702 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31705 \begin_layout Standard
31735 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
31754 \begin_layout Section
31755 Related open source tools
31756 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
31761 \begin_inset LatexCommand \index{Related tools}
31768 \begin_layout Standard
31770 \begin_inset Tabular
31771 <lyxtabular version="3" rows="16" columns="3">
31773 <column alignment="left" valignment="top" leftline="true" width="0pt">
31774 <column alignment="block" valignment="top" leftline="true" width="30line%">
31775 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
31776 <row topline="true" bottomline="true">
31777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31780 \begin_layout Standard
31788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31791 \begin_layout Standard
31799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31802 \begin_layout Standard
31811 <row topline="true">
31812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31815 \begin_layout Standard
31817 \begin_inset LatexCommand \index{gpsim (pic simulator)}
31826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31829 \begin_layout Standard
31835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31838 \begin_layout Standard
31839 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
31849 <row topline="true">
31850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31853 \begin_layout Standard
31855 \begin_inset LatexCommand \index{gputils (pic tools)}
31864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31867 \begin_layout Standard
31873 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31876 \begin_layout Standard
31877 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
31887 <row topline="true">
31888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31891 \begin_layout Standard
31897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31900 \begin_layout Standard
31906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31909 \begin_layout Standard
31910 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
31920 <row topline="true">
31921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31924 \begin_layout Standard
31930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31933 \begin_layout Standard
31934 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
31940 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31943 \begin_layout Standard
31944 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
31954 <row topline="true">
31955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31958 \begin_layout Standard
31960 \begin_inset LatexCommand \index{indent (source formatting tool)}
31969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31972 \begin_layout Standard
31973 Formats C source - Master of the white spaces
31978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31981 \begin_layout Standard
31982 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
31992 <row topline="true">
31993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31996 \begin_layout Standard
31998 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
32007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32010 \begin_layout Standard
32011 Object file conversion, checksumming, ...
32016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32019 \begin_layout Standard
32020 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
32030 <row topline="true">
32031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32034 \begin_layout Standard
32036 \begin_inset LatexCommand \index{objdump (tool)}
32045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32048 \begin_layout Standard
32049 Object file conversion, ...
32054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32057 \begin_layout Standard
32058 Part of binutils (should be there anyway)
32064 <row topline="true">
32065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32068 \begin_layout Standard
32074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32077 \begin_layout Standard
32078 8051 monitor (hex up-/download, single step, disassemble)
32083 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32086 \begin_layout Standard
32087 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
32097 <row topline="true">
32098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32101 \begin_layout Standard
32103 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
32112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32115 \begin_layout Standard
32116 Source code documentation system
32121 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32124 \begin_layout Standard
32125 \begin_inset LatexCommand \url{http://www.doxygen.org}
32135 <row topline="true">
32136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32139 \begin_layout Standard
32145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32148 \begin_layout Standard
32149 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
32154 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32157 \begin_layout Standard
32158 \begin_inset LatexCommand \url{http://www.kdevelop.org}
32168 <row topline="true">
32169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32172 \begin_layout Standard
32178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32181 \begin_layout Standard
32182 8051 monitor (hex up-/download, single step, disassemble)
32187 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32190 \begin_layout Standard
32191 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
32201 <row topline="true">
32202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32205 \begin_layout Standard
32207 \begin_inset LatexCommand \index{splint (syntax checking tool)}
32216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32219 \begin_layout Standard
32220 Statically checks c sources (see
32221 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
32230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32233 \begin_layout Standard
32234 \begin_inset LatexCommand \url{http://www.splint.org}
32244 <row topline="true" bottomline="true">
32245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32248 \begin_layout Standard
32250 \begin_inset LatexCommand \index{DDD (debugger)}
32259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32262 \begin_layout Standard
32263 Debugger, serves nicely as GUI to SDCDB
32264 \begin_inset LatexCommand \index{SDCDB (debugger)}
32273 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32276 \begin_layout Standard
32277 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
32287 <row bottomline="true">
32288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32291 \begin_layout Standard
32293 \begin_inset LatexCommand \index{d52}
32298 \begin_inset LatexCommand \index{d52 (disassembler)}
32307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32310 \begin_layout Standard
32311 Disassembler, can count instruction cycles
32312 \begin_inset LatexCommand \index{instruction cycles (count)}
32316 , use with options -pnd
32321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32324 \begin_layout Standard
32325 \begin_inset LatexCommand \url{http://www.8052.com/users/disasm/}
32335 <row bottomline="true">
32336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32339 \begin_layout Standard
32341 \begin_inset LatexCommand \index{cmake}
32350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32353 \begin_layout Standard
32354 Cross platform build system, generates Makefiles
32355 \begin_inset LatexCommand \index{Makefile}
32359 and project workspaces
32360 \begin_inset LatexCommand \index{project workspace}
32369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32372 \begin_layout Standard
32373 \begin_inset LatexCommand \url{http://www.cmake.org}
32381 and a dedicated wiki entry:
32382 \begin_inset LatexCommand \url{http://www.cmake.org/Wiki/CmakeSdcc}
32401 \begin_layout Section
32402 Related documentation / recommended reading
32405 \begin_layout Standard
32407 \begin_inset Tabular
32408 <lyxtabular version="3" rows="7" columns="3">
32410 <column alignment="left" valignment="top" leftline="true" width="0pt">
32411 <column alignment="left" valignment="top" leftline="true" width="0">
32412 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32413 <row topline="true" bottomline="true">
32414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32417 \begin_layout Standard
32425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32428 \begin_layout Standard
32436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32439 \begin_layout Standard
32448 <row topline="true">
32449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32452 \begin_layout Standard
32467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32470 \begin_layout Standard
32472 \begin_inset LatexCommand \index{C Reference card}
32481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32484 \begin_layout Standard
32485 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
32495 <row topline="true">
32496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32499 \begin_layout Standard
32505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32508 \begin_layout Standard
32510 \begin_inset LatexCommand \index{C FAQ}
32519 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32522 \begin_layout Standard
32523 \begin_inset LatexCommand \url{http://www.c-faq.com}
32533 <row topline="true">
32534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32537 \begin_layout Standard
32543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32546 \begin_layout Standard
32547 \begin_inset Quotes sld
32551 \begin_inset Quotes srd
32559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32562 \begin_layout Standard
32565 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
32575 <row topline="true">
32576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32579 \begin_layout Standard
32585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32588 \begin_layout Standard
32589 \begin_inset Quotes sld
32592 Extensions for Embedded C
32593 \begin_inset Quotes srd
32601 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32604 \begin_layout Standard
32607 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
32617 <row topline="true">
32618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32621 \begin_layout Standard
32627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32630 \begin_layout Standard
32631 Latest datasheet of target CPU
32636 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32639 \begin_layout Standard
32646 <row topline="true" bottomline="true">
32647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32650 \begin_layout Standard
32656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32659 \begin_layout Standard
32660 Revision history of datasheet
32665 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32668 \begin_layout Standard
32684 \begin_layout Section
32685 Application notes specifically for SDCC
32688 \begin_layout Standard
32689 SDCC makes no claims about the completeness of this list and about up-to-datenes
32690 s or correctness of the application notes
32691 \begin_inset LatexCommand \index{Application notes}
32698 \begin_layout Standard
32702 \begin_inset Tabular
32703 <lyxtabular version="3" rows="7" columns="3">
32705 <column alignment="block" valignment="top" leftline="true" width="17col%">
32706 <column alignment="block" valignment="top" leftline="true" width="27col%">
32707 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
32708 <row topline="true" bottomline="true">
32709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32712 \begin_layout Standard
32721 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
32724 \begin_layout Standard
32733 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32736 \begin_layout Standard
32746 <row topline="true">
32747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32750 \begin_layout Standard
32758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32761 \begin_layout Standard
32764 Using the SDCC Compiler for the DS80C400
32765 \begin_inset LatexCommand \index{DS80C400}
32774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32777 \begin_layout Standard
32780 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
32790 <row topline="true">
32791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32794 \begin_layout Standard
32802 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
32805 \begin_layout Standard
32808 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
32809 \begin_inset LatexCommand \index{DS89C4x0}
32813 Family of Microcontrollers
32818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32821 \begin_layout Standard
32824 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
32834 <row topline="true">
32835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32838 \begin_layout Standard
32841 Silicon Laboratories / Cygnal
32846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32849 \begin_layout Standard
32852 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
32853 \begin_inset LatexCommand \index{IDE}
32862 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32865 \begin_layout Standard
32868 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
32878 <row topline="true">
32879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32882 \begin_layout Standard
32885 Ramtron / Goal Semiconductor
32890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32893 \begin_layout Standard
32896 Interfacing SDCC to Syn and Textpad
32901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32904 \begin_layout Standard
32907 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32917 <row topline="true">
32918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32921 \begin_layout Standard
32924 Ramtron / Goal Semiconductor
32929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32932 \begin_layout Standard
32935 Installing and Configuring SDCC and Crimson Editor
32940 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32943 \begin_layout Standard
32946 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32956 <row topline="true" bottomline="true">
32957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32960 \begin_layout Standard
32968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32971 \begin_layout Standard
32974 MSC12xx Programming with SDCC
32979 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32982 \begin_layout Standard
32985 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
33002 \begin_layout Section
33006 \begin_layout Standard
33007 Some questions answered, some pointers given - it might be time to in turn
33015 \begin_layout Itemize
33016 can you solve your project with the selected microcontroller? Would you
33017 find out early or rather late that your target is too small/slow/whatever?
33018 Can you switch to a slightly better device if it doesn't fit?
33021 \begin_layout Itemize
33022 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
33023 and/or another programming language be more adequate? Would an operating
33024 system on the target device help?
33027 \begin_layout Itemize
33028 if you solved the problem, will the marketing department be happy?
33031 \begin_layout Itemize
33032 if the marketing department is happy, will customers be happy?
33035 \begin_layout Itemize
33036 if you're the project manager, marketing department and maybe even the customer
33037 in one person, have you tried to see the project from the outside?
33040 \begin_layout Itemize
33041 is the project done if you think it is done? Or is just that other interface/pro
33042 tocol/feature/configuration/option missing? How about website, manual(s),
33043 internationali(z|s)ation, packaging, labels, 2nd source for components,
33044 electromagnetic compatability/interference, documentation for production,
33045 production test software, update mechanism, patent issues?
33048 \begin_layout Itemize
33049 is your project adequately positioned in that magic triangle: fame, fortune,
33053 \begin_layout Standard
33054 Maybe not all answers to these questions are known and some answers may
33059 , nevertheless knowing these questions may help you to avoid burnout
33063 \begin_layout Standard
33064 burnout is bad for electronic devices, programmers and motorcycle tyres
33070 Chances are you didn't want to hear some of them...
33073 \begin_layout Chapter
33075 \begin_inset LatexCommand \index{Support}
33082 \begin_layout Standard
33083 SDCC has grown to be a large project.
33084 The compiler alone (without the preprocessor, assembler and linker) is
33085 well over 150,000 lines of code (blank stripped).
33086 The open source nature of this project is a key to its continued growth
33088 You gain the benefit and support of many active software developers and
33090 Is SDCC perfect? No, that's why we need your help.
33091 The developers take pride in fixing reported bugs.
33092 You can help by reporting the bugs and helping other SDCC users.
33093 There are lots of ways to contribute, and we encourage you to take part
33094 in making SDCC a great software package.
33098 \begin_layout Standard
33099 The SDCC project is hosted on the SDCC sourceforge site at
33100 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
33105 You'll find the complete set of mailing lists
33106 \begin_inset LatexCommand \index{Mailing list(s)}
33110 , forums, bug reporting system, patch submission
33111 \begin_inset LatexCommand \index{Patch submission}
33116 \begin_inset LatexCommand \index{download}
33120 area and Subversion code repository
33121 \begin_inset LatexCommand \index{Subversion code repository}
33128 \begin_layout Section
33130 \begin_inset LatexCommand \index{Bug reporting}
33135 \begin_inset LatexCommand \index{Reporting bugs}
33142 \begin_layout Standard
33143 The recommended way of reporting bugs is using the infrastructure of the
33145 You can follow the status of bug reports there and have an overview about
33149 \begin_layout Standard
33150 Bug reports are automatically forwarded to the developer mailing list and
33151 will be fixed ASAP.
33152 When reporting a bug, it is very useful to include a small test program
33153 (the smaller the better) which reproduces the problem.
33154 If you can isolate the problem by looking at the generated assembly code,
33155 this can be very helpful.
33156 Compiling your program with the -
33160 \begin_layout Standard
33170 \begin_inset LatexCommand \index{-\/-dumpall}
33174 option can sometimes be useful in locating optimization problems.
33175 When reporting a bug please make sure you:
33178 \begin_layout Enumerate
33179 Attach the code you are compiling with SDCC.
33183 \begin_layout Enumerate
33184 Specify the exact command you use to run SDCC, or attach your Makefile.
33188 \begin_layout Enumerate
33189 Specify the SDCC version (type "
33195 "), your platform, and operating system.
33199 \begin_layout Enumerate
33200 Provide an exact copy of any error message or incorrect output.
33204 \begin_layout Enumerate
33205 Put something meaningful in the subject of your message.
33208 \begin_layout Standard
33209 Please attempt to include these 5 important parts, as applicable, in all
33210 requests for support or when reporting any problems or bugs with SDCC.
33211 Though this will make your message lengthy, it will greatly improve your
33212 chance that SDCC users and developers will be able to help you.
33213 Some SDCC developers are frustrated by bug reports without code provided
33214 that they can use to reproduce and ultimately fix the problem, so please
33215 be sure to provide sample code if you are reporting a bug!
33218 \begin_layout Standard
33219 Please have a short check that you are using a recent version of SDCC and
33220 the bug is not yet known.
33221 This is the link for reporting bugs:
33222 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
33227 With SDCC on average having more than 200 downloads
33228 \begin_inset LatexCommand \index{download}
33232 on sourceforge per day
33236 \begin_layout Standard
33237 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
33238 between 2002 and 2005.
33239 This does not include other methods of distribution.
33244 there must be some users.
33245 So it's not exactly easy to find a new bug.
33246 If you find one we need it:
33248 reporting bugs is good
33253 \begin_layout Section
33254 Requesting Features
33255 \begin_inset LatexCommand \label{sub:Requesting-Features}
33260 \begin_inset LatexCommand \index{Feature request}
33265 \begin_inset LatexCommand \index{Requesting features}
33272 \begin_layout Standard
33273 Like bug reports feature requests are forwarded to the developer mailing
33275 This is the link for requesting features:
33276 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33283 \begin_layout Section
33287 \begin_layout Standard
33288 Like bug reports contributed patches are forwarded to the developer mailing
33290 This is the link for submitting patches
33291 \begin_inset LatexCommand \index{Patch submission}
33296 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
33303 \begin_layout Standard
33304 You need to specify some parameters to the
33308 command for the patches to be useful.
33309 If you modified more than one file a patch created f.e.
33314 \begin_inset Quotes sld
33317 diff -Naur unmodified_directory modified_directory >my_changes.patch
33318 \begin_inset Quotes srd
33324 will be fine, otherwise
33328 \begin_inset Quotes sld
33331 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
33332 \begin_inset Quotes srd
33342 \begin_layout Section
33346 \begin_layout Standard
33347 These links should take you directly to the
33348 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
33356 \begin_layout Standard
33357 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
33358 automated messages (mid 2003)
33364 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
33369 \begin_inset LatexCommand \index{Mailing list(s)}
33373 and forums are archived and searchable so if you are lucky someone already
33374 had a similar problem.
33375 While mails to the lists themselves are delivered promptly their web front
33376 end on sourceforge sometimes shows a severe time lag (up to several weeks),
33377 if you're seriously using SDCC please consider subscribing to the lists.
33380 \begin_layout Section
33384 \begin_layout Standard
33385 You can follow the status of the Subversion version
33386 \begin_inset LatexCommand \index{version}
33390 of SDCC by watching the Changelog
33391 \begin_inset LatexCommand \index{Changelog}
33395 in the Subversion repository
33398 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
33405 \begin_layout Section
33406 Subversion Source Code Repository
33409 \begin_layout Standard
33419 \begin_layout Standard
33433 or the filenames of the snapshot versions of SDCC include date and its
33435 \begin_inset LatexCommand \index{Subversion code repository}
33440 Subversion allows to download the source of recent or previous versions
33442 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
33446 (by number or by date).
33447 An on-line source code browser and detailled instructions are also available
33449 SDCC versions starting from 1999 up to now are available (currently the
33450 versions prior to the conversion from cvs
33451 \begin_inset LatexCommand \index{cvs|see{Subversion}}
33455 to Subversion (April 2006) are either by accessible by Subversion or by
33459 \begin_layout Section
33461 \begin_inset LatexCommand \index{Release policy}
33468 \begin_layout Standard
33469 Historically there often were long delays between official releases and
33470 the sourceforge download area tends to get not updated at all.
33471 Excuses in the past might have referred to problems with live range analysis,
33472 but as this was fixed a while ago, the current problem is that another
33473 excuse has to be found.
33474 Kidding aside, we have to get better there! On the other hand there are
33475 daily snapshots available at
33476 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
33480 , and you can always build the very last version (hopefully with many bugs
33481 fixed, and features added) from the source code available at
33482 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
33488 \begin_inset LatexCommand \index{wiki}
33493 \begin_inset LatexCommand \index{SDCC Wiki}
33498 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/}
33502 also holds some information about past and future releases.
33505 \begin_layout Section
33507 \begin_inset LatexCommand \index{Examples}
33514 \begin_layout Standard
33515 You'll find some small examples in the directory
33517 sdcc/device/examples/.
33520 More examples and libraries are available at
33522 The SDCC Open Knowledge Resource
33523 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
33530 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
33537 \begin_layout Standard
33538 \begin_inset Note Note
33541 \begin_layout Standard
33542 I did insert a reference to Paul's web site here although it seems rather
33543 dedicated to a specific 8032 board (I think it's okay because it f.e.
33544 shows LCD/Harddisc interface and has a free 8051 monitor.
33545 Independent 8032 board vendors face hard competition of heavily subsidized
33546 development boards anyway).
33549 \begin_layout Standard
33550 Maybe we should include some links to real world applications.
33551 Preferably pointer to pointers (one for each architecture) so this stays
33560 \begin_layout Section
33562 \begin_inset LatexCommand \label{sec:Quality-control}
33567 \begin_inset LatexCommand \index{Quality control}
33574 \begin_layout Standard
33575 The compiler is passed through snaphot build compile and build checks.
33581 \begin_inset LatexCommand \index{Regression test}
33585 check that SDCC itself compiles flawlessly on several host platforms (i386,
33586 Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
33587 and checks the quality of the code generated by SDCC by running the code
33588 for several target platforms through simulators.
33589 The regression test suite comprises more than 100 files which expand to
33590 more than 500 test cases which include more than 4500 tests.
33591 The results of these tests are published daily on SDCC's snapshot page
33592 (click on the red or green symbols on the right side of
33593 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
33600 \begin_layout Standard
33601 There is a separate document
33604 \begin_inset LatexCommand \index{Test suite}
33611 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
33615 about the regression test suite.
33618 \begin_layout Standard
33619 You'll find the test code in the directory
33621 sdcc/support/regression
33624 You can run these tests manually by running
33628 in this directory (or f.e.
33633 \begin_inset Quotes sld
33637 \begin_inset Quotes srd
33643 if you don't want to run the complete tests).
33644 The test code might also be interesting if you want to look for examples
33645 \begin_inset LatexCommand \index{Examples}
33649 checking corner cases of SDCC or if you plan to submit patches
33650 \begin_inset LatexCommand \index{Patch submission}
33657 \begin_layout Standard
33658 The PIC14 port uses a different set of regression tests
33659 \begin_inset LatexCommand \index{Regression test (PIC14)}
33663 , you'll find them in the directory
33665 sdcc/src/regression
33670 \begin_layout Section
33671 Use of SDCC in Education
33674 \begin_layout Standard
33683 \begin_layout Standard
33684 the phrase "use in education" might evoke the association "
33688 fit for use in education".
33689 This connotation is not intended but nevertheless risked as the licensing
33690 of SDCC makes it difficult to offer educational discounts
33696 If your rationales are to:
33699 \begin_layout Enumerate
33700 give students a chance to understand the
33704 steps of code generation
33707 \begin_layout Enumerate
33708 have a curriculum that can be extended for years.
33709 Then you could use an fpga board as target and your curriculum will seamlessly
33710 extend from logic synthesis (
33711 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
33716 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
33720 ), over assembly programming, to C to FPGA compilers (
33721 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
33728 \begin_layout Enumerate
33729 be able to insert excursions about skills like using a revision control
33730 system, submitting/applying patches, using a type-setting (as opposed to
33731 word-processing) engine LyX/LaTeX, using
33732 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
33737 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
33741 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
33742 Source Software, CPU simulation, compiler regression tests
33743 \begin_inset LatexCommand \index{Regression test}
33750 And if there should be a shortage of ideas then you can always point students
33751 to the ever-growing feature request list
33752 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33759 \begin_layout Enumerate
33760 not tie students to a specific host platform and instead allow them to use
33765 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
33767 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
33774 \begin_layout Enumerate
33775 not encourage students to use illegal copies of educational software
33778 \begin_layout Enumerate
33779 be immune to licensing/availability/price changes of the chosen tool chain
33782 \begin_layout Enumerate
33783 be able to change to a new target platform without having to adopt a new
33787 \begin_layout Enumerate
33788 have complete control over and insight into the tool chain
33791 \begin_layout Enumerate
33792 make your students aware about the pros and cons of open source software
33796 \begin_layout Enumerate
33797 give back to the public as you are probably at least partially publically
33801 \begin_layout Enumerate
33802 give students a chance to publically prove their skills and to possibly
33803 see a world wide impact
33806 \begin_layout Standard
33807 then SDCC is probably among the first choices.
33808 Well, probably SDCC might be the only choice.
33813 \begin_layout Chapter
33814 SDCC Technical Data
33817 \begin_layout Section
33819 \begin_inset LatexCommand \index{Optimizations}
33826 \begin_layout Standard
33827 SDCC performs a host of standard optimizations in addition to some MCU specific
33832 \begin_layout Subsection
33833 Sub-expression Elimination
33834 \begin_inset LatexCommand \index{Subexpression elimination}
33841 \begin_layout Standard
33842 The compiler does local and
33861 \begin_layout Verse
33869 \begin_layout Standard
33870 will be translated to
33873 \begin_layout Verse
33883 \begin_layout Standard
33884 Some subexpressions are not as obvious as the above example, e.g.:
33887 \begin_layout Verse
33895 \begin_layout Standard
33896 In this case the address arithmetic a->b[i] will be computed only once;
33897 the equivalent code in C would be.
33900 \begin_layout Verse
33910 \begin_layout Standard
33911 The compiler will try to keep these temporary variables in registers.
33914 \begin_layout Subsection
33915 Dead-Code Elimination
33916 \begin_inset LatexCommand \index{Dead-code elimination}
33923 \begin_layout Verse
33938 i = 1; \InsetSpace ~
33947 global = 1;\InsetSpace ~
33961 global = 3;\InsetSpace ~
33967 \begin_layout Standard
33971 \begin_layout Verse
33987 \begin_layout Subsection
33989 \begin_inset LatexCommand \index{Copy propagation}
33996 \begin_layout Verse
34020 \begin_layout Standard
34024 \begin_layout Verse
34048 \begin_layout Standard
34049 Note: the dead stores created by this copy propagation will be eliminated
34050 by dead-code elimination.
34053 \begin_layout Subsection
34055 \begin_inset LatexCommand \index{Loop optimization}
34060 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
34067 \begin_layout Standard
34068 Two types of loop optimizations are done by SDCC
34076 of loop induction variables.
34077 In addition to the strength reduction the optimizer marks the induction
34078 variables and the register allocator tries to keep the induction variables
34079 in registers for the duration of the loop.
34080 Because of this preference of the register allocator
34081 \begin_inset LatexCommand \index{Register allocation}
34085 , loop induction optimization causes an increase in register pressure, which
34086 may cause unwanted spilling of other temporary variables into the stack
34087 \begin_inset LatexCommand \index{stack}
34092 The compiler will generate a warning message when it is forced to allocate
34093 extra space either on the stack or data space.
34094 If this extra space allocation is undesirable then induction optimization
34095 can be eliminated either for the entire source file (with -
34099 \begin_layout Standard
34108 -noinduction option) or for a given function only using #pragma\InsetSpace ~
34110 \begin_inset LatexCommand \index{\#pragma noinduction}
34121 \begin_layout Verse
34124 for (i = 0 ; i < 100 ; i ++)
34133 \begin_layout Standard
34137 \begin_layout Verse
34142 for (i = 0; i < 100; i++)
34151 \begin_layout Standard
34152 As mentioned previously some loop invariants are not as apparent, all static
34153 address computations are also moved out of the loop.
34158 \begin_inset LatexCommand \index{Strength reduction}
34162 , this optimization substitutes an expression by a cheaper expression:
34165 \begin_layout Verse
34168 for (i=0;i < 100; i++)
34177 \begin_layout Standard
34181 \begin_layout Verse
34188 for (i=0;i< 100;i++) {
34194 ar[itemp1] = itemp2;
34212 \begin_layout Standard
34213 The more expensive multiplication
34214 \begin_inset LatexCommand \index{Multiplication}
34218 is changed to a less expensive addition.
34221 \begin_layout Subsection
34223 \begin_inset LatexCommand \index{Loop reversing}
34230 \begin_layout Standard
34231 This optimization is done to reduce the overhead of checking loop boundaries
34232 for every iteration.
34233 Some simple loops can be reversed and implemented using a
34234 \begin_inset Quotes eld
34237 decrement and jump if not zero
34238 \begin_inset Quotes erd
34242 SDCC checks for the following criterion to determine if a loop is reversible
34243 (note: more sophisticated compilers use data-dependency analysis to make
34244 this determination, SDCC uses a more simple minded analysis).
34247 \begin_layout Itemize
34248 The 'for' loop is of the form
34254 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
34264 \begin_layout Itemize
34265 The <for body> does not contain
34266 \begin_inset Quotes eld
34270 \begin_inset Quotes erd
34274 \begin_inset Quotes erd
34280 \begin_layout Itemize
34281 All goto's are contained within the loop.
34284 \begin_layout Itemize
34285 No function calls within the loop.
34288 \begin_layout Itemize
34289 The loop control variable <sym> is not assigned any value within the loop
34292 \begin_layout Itemize
34293 The loop control variable does NOT participate in any arithmetic operation
34297 \begin_layout Itemize
34298 There are NO switch statements in the loop.
34301 \begin_layout Subsection
34302 Algebraic Simplifications
34305 \begin_layout Standard
34306 SDCC does numerous algebraic simplifications, the following is a small sub-set
34307 of these optimizations.
34310 \begin_layout Verse
34313 i = j + 0;\InsetSpace ~
34317 /* changed to: */\InsetSpace ~
34323 i /= 2;\InsetSpace ~
34330 /* changed to: */\InsetSpace ~
34337 = j - j;\InsetSpace ~
34341 /* changed to: */\InsetSpace ~
34347 i = j / 1;\InsetSpace ~
34351 /* changed to: */\InsetSpace ~
34358 \begin_layout Standard
34359 Note the subexpressions
34360 \begin_inset LatexCommand \index{Subexpression}
34364 given above are generally introduced by macro expansions or as a result
34365 of copy/constant propagation.
34368 \begin_layout Subsection
34369 'switch' Statements
34370 \begin_inset LatexCommand \label{sub:'switch'-Statements}
34375 \begin_inset LatexCommand \index{switch statement}
34382 \begin_layout Standard
34383 SDCC can optimize switch statements to jump tables
34384 \begin_inset LatexCommand \index{jump tables}
34389 It makes the decision based on an estimate of the generated code size.
34390 SDCC is quite liberal in the requirements for jump table generation:
34393 \begin_layout Itemize
34394 The labels need not be in order, and the starting number need not be one
34395 or zero, the case labels are in numerical sequence or not too many case
34396 labels are missing.
34400 \begin_layout Verse
34403 switch(i) {\InsetSpace ~
34434 case 4: ...\InsetSpace ~
34466 case 5: ...\InsetSpace ~
34498 case 3: ...\InsetSpace ~
34529 case 6: ...\InsetSpace ~
34561 case 7: ...\InsetSpace ~
34593 case 8: ...\InsetSpace ~
34625 case 9: ...\InsetSpace ~
34657 case 10: ...\InsetSpace ~
34688 case 11: ...\InsetSpace ~
34755 \begin_layout Standard
34756 Both the above switch statements will be implemented using a jump-table.
34757 The example to the right side is slightly more efficient as the check for
34758 the lower boundary of the jump-table is not needed.
34762 \begin_layout Itemize
34763 The number of case labels is not larger than supported by the target architectur
34767 \begin_layout Itemize
34768 If the case labels are not in numerical sequence ('gaps' between cases)
34769 SDCC checks whether a jump table with additionally inserted dummy cases
34770 is still attractive.
34774 \begin_layout Itemize
34775 If the starting number is not zero and a check for the lower boundary of
34776 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
34781 \begin_layout Standard
34782 Switch statements which have large gaps in the numeric sequence or those
34783 that have too many case labels can be split into more than one switch statement
34784 for efficient code generation, e.g.:
34787 \begin_layout Verse
34865 \begin_layout Standard
34866 If the above switch statement is broken down into two switch statements
34869 \begin_layout Verse
34912 \begin_layout Standard
34916 \begin_layout Verse
34959 \begin_layout Standard
34960 then both the switch statements will be implemented using jump-tables whereas
34961 the unmodified switch statement will not be.
34964 \begin_layout Standard
34965 \begin_inset Note Note
34968 \begin_layout Standard
34969 There might be reasons which SDCC cannot know about to either favour or
34970 not favour jump tables.
34971 If the target system has to be as quick for the last switch case as for
34972 the first (pro jump table), or if the switch argument is known to be zero
34973 in the majority of the cases (contra jump table).
34981 \begin_layout Standard
34982 The pragma nojtbound
34983 \begin_inset LatexCommand \index{\#pragma nojtbound}
34987 can be used to turn off checking the
35000 It has no effect if a default label is supplied.
35001 Use of this pragma is dangerous: if the switch
35002 \begin_inset LatexCommand \index{switch statement}
35006 argument is not matched by a case statement the processor will happily
35010 \begin_layout Subsection
35011 Bit-shifting Operations
35012 \begin_inset LatexCommand \index{Bit shifting}
35019 \begin_layout Standard
35020 Bit shifting is one of the most frequently used operation in embedded programmin
35022 SDCC tries to implement bit-shift operations in the most efficient way
35026 \begin_layout Verse
35039 \begin_layout Standard
35040 generates the following code:
35043 \begin_layout Verse
35058 \begin_layout Standard
35059 In general SDCC will never setup a loop if the shift count is known.
35063 \begin_layout Verse
35076 \begin_layout Standard
35080 \begin_layout Verse
35104 \begin_layout Subsection
35106 \begin_inset LatexCommand \index{Bit rotation}
35113 \begin_layout Standard
35114 A special case of the bit-shift operation is bit rotation
35115 \begin_inset LatexCommand \index{rotating bits}
35119 , SDCC recognizes the following expression to be a left bit-rotation:
35122 \begin_layout Verse
35130 char i;\InsetSpace ~
35141 /* unsigned is needed for rotation */
35146 i = ((i << 1) | (i >> 7));
35155 \begin_layout Standard
35156 will generate the following code:
35159 \begin_layout Verse
35176 \begin_layout Standard
35177 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
35178 ns of this case will also be recognized as bit-rotation, i.e.:
35181 \begin_layout Verse
35184 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
35187 \begin_layout Subsection
35188 Nibble and Byte Swapping
35191 \begin_layout Standard
35192 Other special cases of the bit-shift operations are nibble or byte swapping
35193 \begin_inset LatexCommand \index{swapping nibbles/bytes}
35197 , SDCC recognizes the following expressions:
35200 \begin_layout Verse
35221 i = ((i << 4) | (i >> 4));
35227 j = ((j << 8) | (j >> 8));
35230 \begin_layout Standard
35231 and generates a swap instruction for the nibble swapping
35232 \begin_inset LatexCommand \index{Nibble swapping}
35236 or move instructions for the byte swapping
35237 \begin_inset LatexCommand \index{Byte swapping}
35243 \begin_inset Quotes sld
35247 \begin_inset Quotes srd
35250 example can be used to convert from little to big-endian or vice versa.
35251 If you want to change the endianness of a
35255 integer you have to cast to
35262 \begin_layout Standard
35263 Note that SDCC stores numbers in little-endian
35267 \begin_layout Standard
35268 Usually 8-bit processors don't care much about endianness.
35269 This is not the case for the standard 8051 which only has an instruction
35275 \begin_inset LatexCommand \index{DPTR}
35283 so little-endian is the more efficient byte order.
35289 \begin_inset LatexCommand \index{little-endian}
35294 \begin_inset LatexCommand \index{Endianness}
35299 lowest order first).
35302 \begin_layout Subsection
35304 \begin_inset LatexCommand \index{Highest Order Bit}
35309 \begin_inset LatexCommand \index{Any Order Bit}
35316 \begin_layout Standard
35317 It is frequently required to obtain the highest order bit of an integral
35318 type (long, int, short or char types).
35319 Also obtaining any other order bit is not uncommon.
35320 SDCC recognizes the following expressions to yield the highest order bit
35321 and generates optimized code for it, e.g.:
35324 \begin_layout Verse
35335 unsigned char hob1, aob1;
35339 bit hob2, hob3, aob2,
35349 hob1 = (gint >> 15) & 1;
35353 hob2 = (gint >> 15) & 1;
35357 hob3 = gint & 0x8000;
35362 aob1 = (gint >> 9) & 1;
35366 aob2 = (gint >> 8) & 1;
35370 aob3 = gint & 0x0800;
35380 \begin_layout Standard
35381 will generate the following code:
35384 \begin_layout Verse
35415 000A E5*01\InsetSpace ~
35442 000C 23\InsetSpace ~
35473 000D 54 01\InsetSpace ~
35501 000F F5*02\InsetSpace ~
35556 0011 E5*01\InsetSpace ~
35584 0013 33\InsetSpace ~
35614 0014 92*00\InsetSpace ~
35670 0016 E5*01\InsetSpace ~
35697 0018 33\InsetSpace ~
35727 0019 92*01\InsetSpace ~
35783 001B E5*01\InsetSpace ~
35842 001E 54 01\InsetSpace ~
35869 0020 F5*03\InsetSpace ~
35925 0022 E5*01\InsetSpace ~
35952 0024 13\InsetSpace ~
35982 0025 92*02\InsetSpace ~
36038 0027 E5*01\InsetSpace ~
36093 002B 92*03\InsetSpace ~
36121 \begin_layout Standard
36122 Other variations of these cases however will
36127 They are standard C expressions, so I heartily recommend these be the only
36128 way to get the highest order bit, (it is portable).
36129 Of course it will be recognized even if it is embedded in other expressions,
36133 \begin_layout Verse
36136 xyz = gint + ((gint >> 15) & 1);
36139 \begin_layout Standard
36140 will still be recognized.
36143 \begin_layout Subsection
36145 \begin_inset LatexCommand \index{Higher Order Byte}
36149 / Higher Order Word
36150 \begin_inset LatexCommand \index{Higher Order Word}
36157 \begin_layout Standard
36158 It is also frequently required to obtain a higher order byte or word of
36159 a larger integral type (long, int or short types).
36160 SDCC recognizes the following expressions to yield the higher order byte
36161 or word and generates optimized code for it, e.g.:
36164 \begin_layout Verse
36169 unsigned long int glong;
36177 unsigned char hob1,
36182 unsigned int how1, how2;
36191 hob1 = (gint >> 8) & 0xFF;
36195 hob2 = glong >> 24;
36199 how1 = (glong >> 16) & 0xFFFF;
36214 \begin_layout Standard
36215 will generate the following code:
36218 \begin_layout Verse
36249 0037 85*01*06\InsetSpace ~
36271 _foo_hob1_1_1,(_gint + 1)
36302 003A 85*05*07\InsetSpace ~
36324 _foo_hob2_1_1,(_glong + 3)
36354 003D 85*04*08\InsetSpace ~
36377 _foo_how1_1_1,(_glong + 2)
36379 0040 85*05*09\InsetSpace ~
36404 0043 85*03*0A\InsetSpace ~
36426 _foo_how2_1_1,(_glong + 1)
36428 0046 85*04*0B\InsetSpace ~
36451 (_foo_how2_1_1 + 1),(_glong + 2)
36454 \begin_layout Standard
36455 Again, variations of these cases may
36460 They are standard C expressions, so I heartily recommend these be the only
36461 way to get the higher order byte/word, (it is portable).
36462 Of course it will be recognized even if it is embedded in other expressions,
36466 \begin_layout Verse
36469 xyz = gint + ((gint >> 8) & 0xFF);
36472 \begin_layout Standard
36473 will still be recognized.
36476 \begin_layout Subsection
36478 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
36483 \begin_inset LatexCommand \index{Peephole optimizer}
36490 \begin_layout Standard
36491 The compiler uses a rule based, pattern matching and re-writing mechanism
36492 for peep-hole optimization.
36497 a peep-hole optimizer by Christopher W.
36498 Fraser (cwfraser\InsetSpace ~
36501 A default set of rules are compiled into the compiler, additional rules
36502 may be added with the
36508 \begin_layout Standard
36518 \begin_inset LatexCommand \index{-\/-peep-file}
36525 The rule language is best illustrated with examples.
36528 \begin_layout Verse
36550 \begin_layout Standard
36551 The above rule will change the following assembly
36552 \begin_inset LatexCommand \index{Assembler routines}
36559 \begin_layout Verse
36567 \begin_layout Standard
36571 \begin_layout Verse
36577 \begin_layout Standard
36578 Note: All occurrences of a
36582 (pattern variable) must denote the same string.
36583 With the above rule, the assembly sequence:
36586 \begin_layout Verse
36594 \begin_layout Standard
36595 will remain unmodified.
36599 Other special case optimizations may be added by the
36606 \begin_layout Standard
36619 some variants of the 8051 MCU
36620 \begin_inset LatexCommand \index{MCS51 variants}
36633 The following two rules will change all
36650 \begin_layout Verse
36653 replace { lcall %1 } by { acall %1 }
36655 replace { ljmp %1 } by { ajmp %1 }
36658 \begin_layout Standard
36659 (NOTE: from version 2.7.3 on, you can use option -
36665 \begin_layout Standard
36677 \begin_inset LatexCommand \index{-\/-acall-ajmp}
36681 , which also takes care of aligning the interrupt vectors properly.)
36686 \begin_layout Standard
36689 inline-assembler code
36691 is also passed through the peep hole optimizer, thus the peephole optimizer
36692 can also be used as an assembly level macro expander.
36693 The rules themselves are MCU dependent whereas the rule language infra-structur
36694 e is MCU independent.
36695 Peephole optimization rules for other MCU can be easily programmed using
36700 The syntax for a rule is as follows:
36703 \begin_layout Verse
36706 rule := replace [ restart ] '{' <assembly sequence> '
36744 <assembly sequence> '
36762 '}' [if <functionName> ] '
36767 \begin_layout Standard
36768 <assembly sequence> := assembly instruction (each instruction including
36769 labels must be on a separate line).
36773 The optimizer will apply to the rules
36774 one by one from the top in the sequence of their appearance, it will terminate
36775 when all rules are exhausted.
36776 If the 'restart' option is specified, then the optimizer will start matching
36777 the rules again from the top, this option for a rule is expensive (performance)
36778 , it is intended to be used in situations where a transformation will trigger
36779 the same rule again.
36780 An example of this (not a good one, it has side effects) is the following
36784 \begin_layout Verse
36804 \begin_layout Standard
36805 Note that the replace pattern cannot be a blank, but can be a comment line.
36806 Without the 'restart' option only the innermost 'pop' 'push' pair would
36807 be eliminated, i.e.:
36810 \begin_layout Verse
36822 \begin_layout Standard
36826 \begin_layout Verse
36836 \begin_layout Standard
36841 the restart option the rule will be applied again to the resulting code
36842 and then all the pop-push pairs will be eliminated to yield:
36845 \begin_layout Verse
36853 \begin_layout Standard
36854 A conditional function can be attached to a rule.
36855 Attaching rules are somewhat more involved, let me illustrate this with
36859 \begin_layout Verse
36883 \begin_layout Standard
36884 The optimizer does a look-up of a function name table defined in function
36889 in the source file SDCCpeeph.c, with the name
36894 If it finds a corresponding entry the function is called.
36895 Note there can be no parameters specified for these functions, in this
36900 is crucial, since the function
36904 expects to find the label in that particular variable (the hash table containin
36905 g the variable bindings is passed as a parameter).
36906 If you want to code more such functions, take a close look at the function
36907 labelInRange and the calling mechanism in source file SDCCpeeph.c.
36908 Currently implemented are
36910 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
36911 24bitMode, portIsDS390, 24bitModeAndPortDS390
36920 \begin_layout Standard
36921 I know this whole thing is a little kludgey, but maybe some day we will
36922 have some better means.
36923 If you are looking at this file, you will see the default rules that are
36924 compiled into the compiler, you can add your own rules in the default set
36925 there if you get tired of specifying the -
36929 \begin_layout Standard
36941 \begin_layout Section
36943 \begin_inset LatexCommand \index{ANSI-compliance}
36948 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
36955 \begin_layout Standard
36956 The latest publically available version of the standard
36958 ISO/IEC 9899 - Programming languages - C
36960 should be available at:
36961 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
36970 \begin_layout Standard
36971 Deviations from the compliance:
36974 \begin_layout Itemize
36975 functions are not reentrant
36976 \begin_inset LatexCommand \index{reentrant}
36980 unless explicitly declared as such or the
36986 \begin_layout Standard
36996 \begin_inset LatexCommand \index{-\/-stack-auto}
37002 command line option is specified.
37005 \begin_layout Itemize
37007 \begin_inset LatexCommand \index{struct}
37012 \begin_inset LatexCommand \index{union}
37016 cannot be assigned values directly, cannot be passed as function parameters
37017 or assigned to each other and cannot be a return value
37018 \begin_inset LatexCommand \index{return value}
37022 from a function, e.g.:
37026 \begin_layout Verse
37049 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
37068 s parms) /* invalid in SDCC although allowed in ANSI */
37090 return rets; /* is invalid in SDCC although allowed in ANSI */
37096 \begin_layout Itemize
37097 initialization of structure arrays must be fully braced.
37101 \begin_layout Verse
37104 struct s { char x } a[] = {1, 2};\InsetSpace ~
37109 /* invalid in SDCC */
37112 } a[] = {{1}, {2}}; /* OK */
37116 \begin_layout Itemize
37118 \begin_inset LatexCommand \index{long long (not supported)}
37123 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
37130 \begin_layout Itemize
37132 \begin_inset LatexCommand \index{double (not supported)}
37136 ' precision floating point
37137 \begin_inset LatexCommand \index{Floating point support}
37144 \begin_layout Itemize
37146 \begin_inset LatexCommand \index{K\&R style}
37150 function declarations are NOT allowed.
37154 \begin_layout Verse
37157 foo(i,j) /* this old style of function declarations */
37159 int i,j; /* is valid
37160 in ANSI but not valid in SDCC */
37175 \begin_layout Itemize
37176 Most enhancements in C99 are not supported, e.g.:
37180 \begin_layout Verse
37187 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
37191 \begin_layout Itemize
37192 But some have been added recently in SDCC 2.7.0.
37193 They must be considered alpha quality however.
37197 \begin_layout Verse
37202 \begin_inset LatexCommand \index{inline (not supported)}
37208 int increment (int a) { return a+1; } /* inlines the increment without
37209 function call overhead */
37214 \begin_inset LatexCommand \index{inline (not supported)}
37220 p; /* accepted but ignored */
37224 \begin_layout Itemize
37225 Certain words that are valid identifiers in the standard may be reserved
37226 words in SDCC unless the
37232 \begin_layout Standard
37242 \begin_inset LatexCommand \index{-\/-std-c89}
37254 \begin_layout Standard
37264 \begin_inset LatexCommand \index{-\/-std-c99}
37270 command line options are used.
37271 These may include (depending on the selected processor): 'at', 'banked',
37272 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
37273 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
37274 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
37276 Compliant equivalents of these keywords are always available in a form
37277 that begin with two underscores
37278 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
37283 '__data' instead of 'data'.
37286 \begin_layout Itemize
37287 Integer promotion of variable arguments is not performed if the argument
37288 is explicitly taypecasted unless the
37294 \begin_layout Standard
37304 \begin_inset LatexCommand \index{-\/-std-c89}
37316 \begin_layout Standard
37326 \begin_inset LatexCommand \index{-\/-std-c99}
37332 command line options are used.
37336 \begin_layout Verse
37339 void vararg_func (char *str, ...) { str; }
37356 u is promoted to int before
37361 * passing to function */
37365 vararg_func ("%c", c);
37372 argument u is not promoted to int,
37377 * it is passed as char to function
37383 --std-cXX is not defined;
37388 * is promoted to int before passing
37394 if --std-cXX is defined */
37398 vararg_func ("%bc", (char)u);
37404 \begin_layout Section
37405 Cyclomatic Complexity
37406 \begin_inset LatexCommand \index{Cyclomatic complexity}
37413 \begin_layout Standard
37414 Cyclomatic complexity of a function is defined as the number of independent
37415 paths the program can take during execution of the function.
37416 This is an important number since it defines the number test cases you
37417 have to generate to validate the function.
37418 The accepted industry standard for complexity number is 10, if the cyclomatic
37419 complexity reported by SDCC exceeds 10 you should think about simplification
37420 of the function logic.
37421 Note that the complexity level is not related to the number of lines of
37422 code in a function.
37423 Large functions can have low complexity, and small functions can have large
37429 SDCC uses the following formula to compute the complexity:
37434 \begin_layout Standard
37435 complexity = (number of edges in control flow graph) - (number of nodes
37436 in control flow graph) + 2;
37440 Having said that the industry standard is 10,
37441 you should be aware that in some cases it be may unavoidable to have a
37442 complexity level of less than 10.
37443 For example if you have switch statement with more than 10 case labels,
37444 each case label adds one to the complexity level.
37445 The complexity level is by no means an absolute measure of the algorithmic
37446 complexity of the function, it does however provide a good starting point
37447 for which functions you might look at for further optimization.
37450 \begin_layout Section
37451 Retargetting for other Processors
37454 \begin_layout Standard
37455 The issues for retargetting the compiler are far too numerous to be covered
37457 What follows is a brief description of each of the seven phases of the
37458 compiler and its MCU dependency.
37461 \begin_layout Itemize
37462 Parsing the source and building the annotated parse tree.
37463 This phase is largely MCU independent (except for the language extensions).
37464 Syntax & semantic checks are also done in this phase, along with some initial
37465 optimizations like back patching labels and the pattern matching optimizations
37466 like bit-rotation etc.
37469 \begin_layout Itemize
37470 The second phase involves generating an intermediate code which can be easy
37471 manipulated during the later phases.
37472 This phase is entirely MCU independent.
37473 The intermediate code generation assumes the target machine has unlimited
37474 number of registers, and designates them with the name iTemp.
37475 The compiler can be made to dump a human readable form of the code generated
37480 \begin_layout Standard
37492 \begin_layout Itemize
37493 This phase does the bulk of the standard optimizations and is also MCU independe
37495 This phase can be broken down into several sub-phases:
37499 Break down intermediate
37500 code (iCode) into basic blocks.
37502 Do control flow & data flow analysis on the
37505 Do local common subexpression elimination, then global subexpressio
37508 Dead code elimination
37512 If loop optimizations
37513 caused any changes then do 'global subexpression elimination' and 'dead
37514 code elimination' again.
37517 \begin_layout Itemize
37518 This phase determines the live-ranges; by live range I mean those iTemp
37519 variables defined by the compiler that still survive after all the optimization
37521 Live range analysis
37522 \begin_inset LatexCommand \index{Live range analysis}
37526 is essential for register allocation, since these computation determines
37527 which of these iTemps will be assigned to registers, and for how long.
37530 \begin_layout Itemize
37531 Phase five is register allocation.
37532 There are two parts to this process.
37536 The first part I call 'register packing'
37537 (for lack of a better term).
37538 In this case several MCU specific expression folding is done to reduce
37543 The second part is more MCU independent and deals with
37544 allocating registers to the remaining live ranges.
37545 A lot of MCU specific code does creep into this phase because of the limited
37546 number of index registers available in the 8051.
37549 \begin_layout Itemize
37550 The Code generation phase is (unhappily), entirely MCU dependent and very
37551 little (if any at all) of this code can be reused for other MCU.
37552 However the scheme for allocating a homogenized assembler operand for each
37553 iCode operand may be reused.
37556 \begin_layout Itemize
37557 As mentioned in the optimization section the peep-hole optimizer is rule
37558 based system, which can reprogrammed for other MCUs.
37561 \begin_layout Standard
37562 More information is available on SDCC Wiki
37563 \begin_inset LatexCommand \index{wiki}
37568 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting}
37572 ) and in the thread
37573 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
37580 \begin_layout Chapter
37582 \begin_inset LatexCommand \index{Compiler internals}
37589 \begin_layout Section
37590 The anatomy of the compiler
37591 \begin_inset LatexCommand \label{sub:The-anatomy-of}
37598 \begin_layout Standard
37601 This is an excerpt from an article published in Circuit Cellar Magazine
37607 It's a little outdated (the compiler is much more efficient now and user/develo
37608 per friendly), but pretty well exposes the guts of it all.
37614 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
37615 It is fairly easy to retarget for other 8-bit MCU.
37616 Here we take a look at some of the internals of the compiler.
37620 \begin_layout Paragraph*
37622 \begin_inset LatexCommand \index{Parsing}
37629 \begin_layout Standard
37630 Parsing the input source file and creating an AST (Annotated Syntax Tree
37631 \begin_inset LatexCommand \index{Annotated syntax tree}
37636 This phase also involves propagating types (annotating each node of the
37637 parse tree with type information) and semantic analysis.
37638 There are some MCU specific parsing rules.
37639 For example the storage classes, the extended storage classes are MCU specific
37640 while there may be a xdata storage class for 8051 there is no such storage
37641 class for z80 or Atmel AVR.
37642 SDCC allows MCU specific storage class extensions, i.e.
37643 xdata will be treated as a storage class specifier when parsing 8051 C
37644 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
37648 \begin_layout Paragraph*
37650 \begin_inset LatexCommand \index{iCode}
37657 \begin_layout Standard
37658 Intermediate code generation.
37659 In this phase the AST is broken down into three-operand form (iCode).
37660 These three operand forms are represented as doubly linked lists.
37661 ICode is the term given to the intermediate form generated by the compiler.
37662 ICode example section shows some examples of iCode generated for some simple
37663 C source functions.
37666 \begin_layout Paragraph*
37668 \begin_inset LatexCommand \index{Optimizations}
37675 \begin_layout Standard
37676 Bulk of the target independent optimizations is performed in this phase.
37677 The optimizations include constant propagation, common sub-expression eliminati
37678 on, loop invariant code movement, strength reduction of loop induction variables
37679 and dead-code elimination.
37682 \begin_layout Paragraph*
37683 Live range analysis
37684 \begin_inset LatexCommand \index{Live range analysis}
37691 \begin_layout Standard
37692 During intermediate code generation phase, the compiler assumes the target
37693 machine has infinite number of registers and generates a lot of temporary
37695 The live range computation determines the lifetime of each of these compiler-ge
37696 nerated temporaries.
37697 A picture speaks a thousand words.
37698 ICode example sections show the live range annotations for each of the
37700 It is important to note here, each iCode is assigned a number in the order
37701 of its execution in the function.
37702 The live ranges are computed in terms of these numbers.
37703 The from number is the number of the iCode which first defines the operand
37704 and the to number signifies the iCode which uses this operand last.
37707 \begin_layout Paragraph*
37708 Register Allocation
37709 \begin_inset LatexCommand \index{Register allocation}
37716 \begin_layout Standard
37717 The register allocation determines the type and number of registers needed
37719 In most MCUs only a few registers can be used for indirect addressing.
37720 In case of 8051 for example the registers R0 & R1 can be used to indirectly
37721 address the internal ram and DPTR to indirectly address the external ram.
37722 The compiler will try to allocate the appropriate register to pointer variables
37724 ICode example section shows the operands annotated with the registers assigned
37726 The compiler will try to keep operands in registers as much as possible;
37727 there are several schemes the compiler uses to do achieve this.
37728 When the compiler runs out of registers the compiler will check to see
37729 if there are any live operands which is not used or defined in the current
37730 basic block being processed, if there are any found then it will push that
37731 operand and use the registers in this block, the operand will then be popped
37732 at the end of the basic block.
37736 \begin_layout Standard
37737 There are other MCU specific considerations in this phase.
37738 Some MCUs have an accumulator; very short-lived operands could be assigned
37739 to the accumulator instead of a general-purpose register.
37742 \begin_layout Paragraph*
37746 \begin_layout Standard
37747 Figure II gives a table of iCode
37748 \begin_inset LatexCommand \index{iCode}
37752 operations supported by the compiler.
37753 The code generation involves translating these operations into corresponding
37754 assembly code for the processor.
37755 This sounds overly simple but that is the essence of code generation.
37756 Some of the iCode operations are generated on a MCU specific manner for
37757 example, the z80 port does not use registers to pass parameters so the
37758 SEND and RECV iCode operations will not be generated, and it also does
37759 not support JUMPTABLES.
37765 \begin_layout Standard
37769 \begin_inset Tabular
37770 <lyxtabular version="3" rows="39" columns="4">
37771 <features islongtable="true" headBottomDL="true">
37772 <column alignment="block" valignment="top" leftline="true" width="13col%">
37773 <column alignment="left" valignment="top" leftline="true" width="13col%">
37774 <column alignment="block" valignment="top" leftline="true" width="22col%">
37775 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
37776 <row topline="true" bottomline="true" endhead="true">
37777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37780 \begin_layout Standard
37786 \begin_inset LatexCommand \index{iCode}
37795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37798 \begin_layout Standard
37806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37809 \begin_layout Standard
37817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37820 \begin_layout Standard
37829 <row topline="true">
37830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37833 \begin_layout Standard
37841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37844 \begin_layout Standard
37847 IC_LEFT() IC_RESULT()
37852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37855 \begin_layout Standard
37863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37866 \begin_layout Standard
37869 IC_RESULT = ! IC_LEFT;
37875 <row topline="true">
37876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37879 \begin_layout Standard
37887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37890 \begin_layout Standard
37893 IC_LEFT() IC_RESULT()
37898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37901 \begin_layout Standard
37904 Bitwise complement of
37909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37912 \begin_layout Standard
37915 IC_RESULT = ~IC_LEFT;
37921 <row topline="true">
37922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37925 \begin_layout Standard
37933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37936 \begin_layout Standard
37939 IC_LEFT() IC_RESULT()
37944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37947 \begin_layout Standard
37950 Rotate right with carry
37955 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37958 \begin_layout Standard
37961 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
37967 <row topline="true">
37968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37971 \begin_layout Standard
37979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37982 \begin_layout Standard
37985 IC_LEFT() IC_RESULT()
37990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37993 \begin_layout Standard
37996 Rotate left with carry
38001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38004 \begin_layout Standard
38007 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
38013 <row topline="true">
38014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38017 \begin_layout Standard
38025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38028 \begin_layout Standard
38031 IC_LEFT() IC_RESULT()
38036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38039 \begin_layout Standard
38042 Get the highest order bit of IC_LEFT
38047 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38050 \begin_layout Standard
38053 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
38059 <row topline="true">
38060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38063 \begin_layout Standard
38071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38074 \begin_layout Standard
38077 IC_LEFT() IC_RESULT()
38082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38085 \begin_layout Standard
38093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38096 \begin_layout Standard
38099 IC_RESULT = - IC_LEFT;
38105 <row topline="true">
38106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38109 \begin_layout Standard
38117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38120 \begin_layout Standard
38128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38131 \begin_layout Standard
38134 Push the operand into stack
38139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38142 \begin_layout Standard
38151 <row topline="true">
38152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38155 \begin_layout Standard
38163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38166 \begin_layout Standard
38174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38177 \begin_layout Standard
38180 Pop the operand from the stack
38185 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38188 \begin_layout Standard
38197 <row topline="true">
38198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38201 \begin_layout Standard
38209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38212 \begin_layout Standard
38215 IC_LEFT() IC_RESULT()
38220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38223 \begin_layout Standard
38226 Call the function represented by IC_LEFT
38231 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38234 \begin_layout Standard
38237 IC_RESULT = IC_LEFT();
38243 <row topline="true">
38244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38247 \begin_layout Standard
38255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38258 \begin_layout Standard
38261 IC_LEFT() IC_RESULT()
38266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38269 \begin_layout Standard
38272 Call via function pointer
38277 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38280 \begin_layout Standard
38283 IC_RESULT = (*IC_LEFT)();
38289 <row topline="true">
38290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38293 \begin_layout Standard
38301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38304 \begin_layout Standard
38312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38315 \begin_layout Standard
38318 Return the value in operand IC_LEFT
38323 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38326 \begin_layout Standard
38335 <row topline="true">
38336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38339 \begin_layout Standard
38347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38350 \begin_layout Standard
38358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38361 \begin_layout Standard
38369 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38372 \begin_layout Standard
38381 <row topline="true">
38382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38385 \begin_layout Standard
38393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38396 \begin_layout Standard
38404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38407 \begin_layout Standard
38415 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38418 \begin_layout Standard
38427 <row topline="true">
38428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38431 \begin_layout Standard
38439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38442 \begin_layout Standard
38445 IC_LEFT() IC_RIGHT() IC_RESULT()
38450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38453 \begin_layout Standard
38461 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38464 \begin_layout Standard
38467 IC_RESULT = IC_LEFT + IC_RIGHT
38473 <row topline="true">
38474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38477 \begin_layout Standard
38485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38488 \begin_layout Standard
38491 IC_LEFT() IC_RIGHT() IC_RESULT()
38496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38499 \begin_layout Standard
38507 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38510 \begin_layout Standard
38513 IC_RESULT = IC_LEFT - IC_RIGHT
38519 <row topline="true">
38520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38523 \begin_layout Standard
38531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38534 \begin_layout Standard
38537 IC_LEFT() IC_RIGHT() IC_RESULT()
38542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38545 \begin_layout Standard
38553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38556 \begin_layout Standard
38559 IC_RESULT = IC_LEFT * IC_RIGHT;
38565 <row topline="true">
38566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38569 \begin_layout Standard
38577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38580 \begin_layout Standard
38583 IC_LEFT() IC_RIGHT() IC_RESULT()
38588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38591 \begin_layout Standard
38599 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38602 \begin_layout Standard
38605 IC_RESULT = IC_LEFT / IC_RIGHT;
38611 <row topline="true">
38612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38615 \begin_layout Standard
38623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38626 \begin_layout Standard
38629 IC_LEFT() IC_RIGHT() IC_RESULT()
38634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38637 \begin_layout Standard
38645 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38648 \begin_layout Standard
38651 IC_RESULT = IC_LEFT % IC_RIGHT;
38657 <row topline="true">
38658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38661 \begin_layout Standard
38669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38672 \begin_layout Standard
38675 IC_LEFT() IC_RIGHT() IC_RESULT()
38680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38683 \begin_layout Standard
38691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38694 \begin_layout Standard
38697 IC_RESULT = IC_LEFT < IC_RIGHT;
38703 <row topline="true">
38704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38707 \begin_layout Standard
38715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38718 \begin_layout Standard
38721 IC_LEFT() IC_RIGHT() IC_RESULT()
38726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38729 \begin_layout Standard
38737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38740 \begin_layout Standard
38743 IC_RESULT = IC_LEFT > IC_RIGHT;
38749 <row topline="true">
38750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38753 \begin_layout Standard
38761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38764 \begin_layout Standard
38767 IC_LEFT() IC_RIGHT() IC_RESULT()
38772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38775 \begin_layout Standard
38783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38786 \begin_layout Standard
38789 IC_RESULT = IC_LEFT == IC_RIGHT;
38795 <row topline="true">
38796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38799 \begin_layout Standard
38807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38810 \begin_layout Standard
38813 IC_LEFT() IC_RIGHT() IC_RESULT()
38818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38821 \begin_layout Standard
38824 Logical and operation
38829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38832 \begin_layout Standard
38835 IC_RESULT = IC_LEFT && IC_RIGHT;
38841 <row topline="true">
38842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38845 \begin_layout Standard
38853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38856 \begin_layout Standard
38859 IC_LEFT() IC_RIGHT() IC_RESULT()
38864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38867 \begin_layout Standard
38870 Logical or operation
38875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38878 \begin_layout Standard
38881 IC_RESULT = IC_LEFT || IC_RIGHT;
38887 <row topline="true">
38888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38891 \begin_layout Standard
38899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38902 \begin_layout Standard
38905 IC_LEFT() IC_RIGHT() IC_RESULT()
38910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38913 \begin_layout Standard
38921 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38924 \begin_layout Standard
38927 IC_RESULT = IC_LEFT ^ IC_RIGHT;
38933 <row topline="true">
38934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38937 \begin_layout Standard
38945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38948 \begin_layout Standard
38951 IC_LEFT() IC_RIGHT() IC_RESULT()
38956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38959 \begin_layout Standard
38967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38970 \begin_layout Standard
38973 IC_RESULT = IC_LEFT | IC_RIGHT;
38979 <row topline="true">
38980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38983 \begin_layout Standard
38991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38994 \begin_layout Standard
38997 IC_LEFT() IC_RIGHT() IC_RESULT()
39002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39005 \begin_layout Standard
39013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39016 \begin_layout Standard
39019 IC_RESULT = IC_LEFT & IC_RIGHT;
39025 <row topline="true">
39026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39029 \begin_layout Standard
39037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39040 \begin_layout Standard
39043 IC_LEFT() IC_RIGHT() IC_RESULT()
39048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39051 \begin_layout Standard
39059 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39062 \begin_layout Standard
39065 IC_RESULT = IC_LEFT << IC_RIGHT
39071 <row topline="true">
39072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39075 \begin_layout Standard
39083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39086 \begin_layout Standard
39089 IC_LEFT() IC_RIGHT() IC_RESULT()
39094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39097 \begin_layout Standard
39105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39108 \begin_layout Standard
39111 IC_RESULT = IC_LEFT >> IC_RIGHT
39117 <row topline="true">
39118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39121 \begin_layout Standard
39131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39134 \begin_layout Standard
39137 IC_LEFT() IC_RESULT()
39142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39145 \begin_layout Standard
39153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39156 \begin_layout Standard
39159 IC_RESULT = (*IC_LEFT);
39165 <row topline="true">
39166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39169 \begin_layout Standard
39177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39180 \begin_layout Standard
39183 IC_RIGHT() IC_RESULT()
39188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39191 \begin_layout Standard
39199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39202 \begin_layout Standard
39205 (*IC_RESULT) = IC_RIGHT;
39211 <row topline="true">
39212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39215 \begin_layout Standard
39223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39226 \begin_layout Standard
39229 IC_RIGHT() IC_RESULT()
39234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39237 \begin_layout Standard
39245 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39248 \begin_layout Standard
39251 IC_RESULT = IC_RIGHT;
39257 <row topline="true">
39258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39261 \begin_layout Standard
39269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39272 \begin_layout Standard
39275 IC_COND IC_TRUE IC_LABEL
39280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39283 \begin_layout Standard
39287 If true label is present then jump to true label if condition is true else
39288 jump to false label if condition is false
39293 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39296 \begin_layout Standard
39299 if (IC_COND) goto IC_TRUE;
39305 If (!IC_COND) goto IC_FALSE;
39311 <row topline="true">
39312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39315 \begin_layout Standard
39323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39326 \begin_layout Standard
39329 IC_LEFT() IC_RESULT()
39334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39337 \begin_layout Standard
39345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39348 \begin_layout Standard
39351 IC_RESULT = &IC_LEFT();
39357 <row topline="true">
39358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39361 \begin_layout Standard
39369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39372 \begin_layout Standard
39375 IC_JTCOND IC_JTLABELS
39380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39383 \begin_layout Standard
39386 Jump to list of labels depending on the value of JTCOND
39391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39394 \begin_layout Standard
39403 <row topline="true">
39404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39407 \begin_layout Standard
39415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39418 \begin_layout Standard
39421 IC_RIGHT() IC_LEFT() IC_RESULT()
39426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39429 \begin_layout Standard
39437 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39440 \begin_layout Standard
39443 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
39449 <row topline="true">
39450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39453 \begin_layout Standard
39461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39464 \begin_layout Standard
39472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39475 \begin_layout Standard
39478 This is used for passing parameters in registers;
39480 move IC_LEFT to the next
39481 available parameter register.
39486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39489 \begin_layout Standard
39498 <row topline="true">
39499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39502 \begin_layout Standard
39510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39513 \begin_layout Standard
39521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39524 \begin_layout Standard
39527 This is used for receiving parameters passed in registers;
39530 in the next parameter register to IC_RESULT
39535 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39538 \begin_layout Standard
39547 <row topline="true" bottomline="true">
39548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39551 \begin_layout Standard
39555 (some more have been added)
39560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39563 \begin_layout Standard
39569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39572 \begin_layout Standard
39578 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39581 \begin_layout Standard
39605 \begin_layout Standard
39606 \begin_inset Note Note
39609 \begin_layout Standard
39610 In the original article Figure II was announced to be downloadable on
39615 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
39623 \begin_layout Paragraph*
39625 \begin_inset LatexCommand \index{iCode}
39632 \begin_layout Standard
39633 This section shows some details of iCode.
39634 The example C code does not do anything useful; it is used as an example
39635 to illustrate the intermediate code generated by the compiler.
39638 \begin_layout Verse
39648 /* This function does nothing useful.
39655 for the purpose of explaining iCode */
39658 short function (data
39667 short i=10; \InsetSpace ~
39669 /* dead initialization eliminated */
39675 /* dead initialization eliminated */
39703 /* compiler detects i,j to be induction
39708 for (i = 0, j = 10 ; i < 10 ; i++, j
39714 \begin_layout Standard
39737 mul += i * 3; \InsetSpace ~
39739 /* this multiplication remains */
39746 j * 3;\InsetSpace ~
39748 /* this multiplication changed to addition */
39762 \begin_layout Standard
39763 In addition to the operands each iCode contains information about the filename
39764 and line it corresponds to in the source file.
39765 The first field in the listing should be interpreted as follows:
39770 Filename(linenumber: iCode Execution sequence number : ICode hash table
39771 key : loop depth of the iCode).
39776 Then follows the human readable form of the ICode operation.
39777 Each operand of this triplet form can be of three basic types a) compiler
39778 generated temporary b) user defined variable c) a constant value.
39779 Note that local variables and parameters are replaced by compiler generated
39782 \begin_inset LatexCommand \index{Live range analysis}
39786 are computed only for temporaries (i.e.
39787 live ranges are not computed for global variables).
39789 \begin_inset LatexCommand \index{Register allocation}
39793 are allocated for temporaries only.
39794 Operands are formatted in the following manner:
39799 Operand Name [lr live-from : live-to ] { type information } [ registers
39805 As mentioned earlier the live ranges are computed in terms of the execution
39806 sequence number of the iCodes, for example
39808 the iTemp0 is live from (i.e.
39809 first defined in iCode with execution sequence number 3, and is last used
39810 in the iCode with sequence number 5).
39811 For induction variables such as iTemp21 the live range computation extends
39812 the lifetime from the start to the end of the loop.
39814 The register allocator
39815 used the live range information to allocate registers, the same registers
39816 may be used for different temporaries if their live ranges do not overlap,
39817 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
39818 ranges do not overlap.
39819 In addition the allocator also takes into consideration the type and usage
39820 of a temporary, for example itemp6 is a pointer to near space and is used
39821 as to fetch data from (i.e.
39822 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
39823 Some short lived temporaries are allocated to special registers which have
39824 meaning to the code generator e.g.
39825 iTemp13 is allocated to a pseudo register CC which tells the back end that
39826 the temporary is used only for a conditional jump the code generation makes
39827 use of this information to optimize a compare and jump ICode.
39831 \begin_inset LatexCommand \index{Loop optimization}
39835 performed by the compiler.
39836 It can detect induction variables iTemp21(i) and iTemp23(j).
39837 Also note the compiler does selective strength reduction
39838 \begin_inset LatexCommand \index{Strength reduction}
39843 the multiplication of an induction variable in line 18 (gint = j * 3) is
39844 changed to addition, a new temporary iTemp17 is allocated and assigned
39845 a initial value, a constant 3 is then added for each iteration of the loop.
39846 The compiler does not change the multiplication
39847 \begin_inset LatexCommand \index{Multiplication}
39851 in line 17 however since the processor does support an 8 * 8 bit multiplication.
39854 Note the dead code elimination
39855 \begin_inset LatexCommand \index{Dead-code elimination}
39859 optimization eliminated the dead assignments in line 7 & 8 to I and sum
39865 \begin_layout Standard
39868 Sample.c (5:1:0:0) _entry($9) :
39871 \begin_layout Standard
39874 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
39877 \begin_layout Standard
39880 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
39883 \begin_layout Standard
39886 Sample.c(11:4:53:0) preHeaderLbl0($11) :
39889 \begin_layout Standard
39892 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
39896 \begin_layout Standard
39899 Sample.c(11:6:5:1) _whilecontinue_0($1) :
39902 \begin_layout Standard
39905 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
39909 \begin_layout Standard
39912 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39915 \begin_layout Standard
39918 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
39922 \begin_layout Standard
39925 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
39929 \begin_layout Standard
39932 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
39936 \begin_layout Standard
39939 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
39943 \begin_layout Standard
39946 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
39947 * int}[r0] + 0x2 {short}
39950 \begin_layout Standard
39953 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
39956 \begin_layout Standard
39959 Sample.c(11:17:21:0)_whilebreak_0($3) :
39962 \begin_layout Standard
39965 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39968 \begin_layout Standard
39971 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39974 \begin_layout Standard
39977 Sample.c(15:20:54:0)preHeaderLbl1($13) :
39980 \begin_layout Standard
39983 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39986 \begin_layout Standard
39989 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39992 \begin_layout Standard
39995 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39998 \begin_layout Standard
40001 Sample.c(15:24:26:1)_forcond_0($4) :
40004 \begin_layout Standard
40007 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
40011 \begin_layout Standard
40014 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
40017 \begin_layout Standard
40020 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
40021 + ITemp21 [lr21:38]{short}[r4]
40024 \begin_layout Standard
40027 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
40031 \begin_layout Standard
40034 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
40035 + iTemp15 [lr29:30]{short}[r1]
40038 \begin_layout Standard
40041 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
40045 \begin_layout Standard
40048 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
40052 \begin_layout Standard
40055 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
40059 \begin_layout Standard
40062 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
40066 \begin_layout Standard
40069 Sample.c(19:38:47:1) goto _forcond_0($4)
40072 \begin_layout Standard
40075 Sample.c(19:39:48:0)_forbreak_0($7) :
40078 \begin_layout Standard
40081 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
40082 + ITemp11 [lr19:40]{short}[r3]
40085 \begin_layout Standard
40088 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
40091 \begin_layout Standard
40094 Sample.c(20:42:51:0)_return($8) :
40097 \begin_layout Standard
40100 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
40106 Finally the code generated for this function:
40111 \begin_layout Standard
40117 \begin_layout Standard
40123 \begin_layout Standard
40131 \begin_layout Standard
40137 \begin_layout Standard
40145 \begin_layout Standard
40151 \begin_layout Standard
40154 ; ----------------------------------------------
40157 \begin_layout Standard
40160 ; function function
40163 \begin_layout Standard
40166 ; ----------------------------------------------
40169 \begin_layout Standard
40175 \begin_layout Standard
40178 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
40181 \begin_layout Standard
40189 \begin_layout Standard
40192 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
40195 \begin_layout Standard
40203 \begin_layout Standard
40206 ;_whilecontinue_0($1) :
40209 \begin_layout Standard
40215 \begin_layout Standard
40218 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
40221 \begin_layout Standard
40224 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
40227 \begin_layout Standard
40235 \begin_layout Standard
40243 \begin_layout Standard
40251 \begin_layout Standard
40259 \begin_layout Standard
40267 \begin_layout Standard
40275 \begin_layout Standard
40283 \begin_layout Standard
40289 \begin_layout Standard
40292 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
40295 \begin_layout Standard
40303 \begin_layout Standard
40311 \begin_layout Standard
40314 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
40317 \begin_layout Standard
40325 \begin_layout Standard
40333 \begin_layout Standard
40341 \begin_layout Standard
40349 \begin_layout Standard
40357 \begin_layout Standard
40365 \begin_layout Standard
40368 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
40371 \begin_layout Standard
40379 \begin_layout Standard
40387 \begin_layout Standard
40395 \begin_layout Standard
40403 \begin_layout Standard
40411 \begin_layout Standard
40414 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
40417 \begin_layout Standard
40425 \begin_layout Standard
40433 \begin_layout Standard
40441 \begin_layout Standard
40444 ; iTemp6 [lr5:16]{_near * int}[r0] =
40447 \begin_layout Standard
40450 ; iTemp6 [lr5:16]{_near * int}[r0] +
40453 \begin_layout Standard
40459 \begin_layout Standard
40467 \begin_layout Standard
40470 ; goto _whilecontinue_0($1)
40473 \begin_layout Standard
40481 \begin_layout Standard
40484 ; _whilebreak_0($3) :
40487 \begin_layout Standard
40493 \begin_layout Standard
40496 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
40499 \begin_layout Standard
40507 \begin_layout Standard
40510 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
40513 \begin_layout Standard
40521 \begin_layout Standard
40524 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
40527 \begin_layout Standard
40535 \begin_layout Standard
40538 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
40541 \begin_layout Standard
40549 \begin_layout Standard
40557 \begin_layout Standard
40560 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
40563 \begin_layout Standard
40571 \begin_layout Standard
40579 \begin_layout Standard
40585 \begin_layout Standard
40591 \begin_layout Standard
40594 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
40597 \begin_layout Standard
40600 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
40603 \begin_layout Standard
40611 \begin_layout Standard
40619 \begin_layout Standard
40627 \begin_layout Standard
40635 \begin_layout Standard
40643 \begin_layout Standard
40649 \begin_layout Standard
40652 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
40655 \begin_layout Standard
40658 ; iTemp21 [lr21:38]{short}[r4]
40661 \begin_layout Standard
40669 \begin_layout Standard
40677 \begin_layout Standard
40685 \begin_layout Standard
40688 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
40691 \begin_layout Standard
40699 \begin_layout Standard
40707 \begin_layout Standard
40715 \begin_layout Standard
40723 \begin_layout Standard
40726 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
40729 \begin_layout Standard
40732 ; iTemp15 [lr29:30]{short}[r1]
40735 \begin_layout Standard
40743 \begin_layout Standard
40751 \begin_layout Standard
40754 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
40757 \begin_layout Standard
40765 \begin_layout Standard
40773 \begin_layout Standard
40781 \begin_layout Standard
40789 \begin_layout Standard
40797 \begin_layout Standard
40805 \begin_layout Standard
40808 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
40811 \begin_layout Standard
40819 \begin_layout Standard
40827 \begin_layout Standard
40835 \begin_layout Standard
40843 \begin_layout Standard
40851 \begin_layout Standard
40859 \begin_layout Standard
40862 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
40865 \begin_layout Standard
40873 \begin_layout Standard
40876 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
40879 \begin_layout Standard
40887 \begin_layout Standard
40892 cjne r5,#0xff,00104$
40895 \begin_layout Standard
40903 \begin_layout Standard
40906 ; goto _forcond_0($4)
40909 \begin_layout Standard
40917 \begin_layout Standard
40920 ; _forbreak_0($7) :
40923 \begin_layout Standard
40929 \begin_layout Standard
40932 ; ret iTemp24 [lr40:41]{short}
40935 \begin_layout Standard
40943 \begin_layout Standard
40951 \begin_layout Standard
40959 \begin_layout Standard
40965 \begin_layout Standard
40971 \begin_layout Standard
40981 \begin_layout Section
40982 A few words about basic block successors, predecessors and dominators
40985 \begin_layout Standard
40986 Successors are basic blocks
40987 \begin_inset LatexCommand \index{Basic blocks}
40991 that might execute after this basic block.
40993 Predecessors are basic blocks
40994 that might execute before reaching this basic block.
40996 Dominators are basic
40997 blocks that WILL execute before reaching this basic block.
41002 \begin_layout Standard
41006 \begin_layout Standard
41010 \begin_layout Standard
41018 \begin_layout Standard
41022 \begin_layout Standard
41030 \begin_layout Standard
41036 \begin_layout Standard
41037 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
41040 \begin_layout Standard
41041 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
41044 \begin_layout Standard
41045 c) domVect of [BB4] = BB1 ...
41046 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
41050 \begin_layout Chapter
41054 \begin_layout Standard
41055 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/#Who}
41065 Thanks to all the other volunteer developers who have helped with coding,
41066 testing, web-page creation, distribution sets, etc.
41067 You know who you are :-)
41075 Thanks to Sourceforge
41076 \begin_inset LatexCommand \url{http://www.sf.net}
41080 which has hosted the project since 1999 and donates significant download
41089 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
41090 cycles and bandwidth for snapshot builds.
41095 \begin_layout Standard
41096 This document was initially written by Sandeep Dutta
41099 \begin_layout Standard
41100 All product names mentioned herein may be trademarks
41101 \begin_inset LatexCommand \index{Trademarks}
41105 of their respective companies.
41109 \begin_layout Section*
41113 \begin_layout Standard
41114 To avoid confusion, the installation and building options for SDCC itself
41115 (chapter 2) are not part of the index.
41118 \begin_layout Standard
41119 \begin_inset LatexCommand \printindex{}