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]}
8032 Pass the linkOption to the linker.
8033 If a bootloader is used an option like
8034 \begin_inset Quotes sld
8039 \begin_inset Quotes srd
8042 would be typical to set the start of the code segment.
8043 See also #pragma constseg and #pragma codeseg in section
8044 \begin_inset LatexCommand \ref{sec:Pragmas}
8049 File sdcc/as/doc/asxhtm.html has more on linker options.
8052 \begin_layout Standard
8053 \begin_inset VSpace bigskip
8059 \begin_layout Subsection
8061 \begin_inset LatexCommand \index{Options MCS51}
8066 \begin_inset LatexCommand \index{MCS51 options}
8074 \labelwidthstring 00.00.0000
8081 \begin_layout Standard
8091 \begin_inset LatexCommand \index{-\/-model-small}
8102 Generate code for Small Model programs, see section Memory Models for more
8104 This is the default model.
8108 \labelwidthstring 00.00.0000
8115 \begin_layout Standard
8125 \begin_inset LatexCommand \index{-\/-model-medium}
8131 Generate code for Medium model programs, see section Memory Models for
8133 If this option is used all source files in the project have to be compiled
8135 It must also be used when invoking the linker.
8139 \labelwidthstring 00.00.0000
8146 \begin_layout Standard
8156 \begin_inset LatexCommand \index{-\/-model-large}
8162 Generate code for Large model programs, see section Memory Models for more
8164 If this option is used all source files in the project have to be compiled
8166 It must also be used when invoking the linker.
8170 \labelwidthstring 00.00.0000
8177 \begin_layout Standard
8187 \begin_inset LatexCommand \index{-\/-xstack}
8193 Uses a pseudo stack in the pdata
8194 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8198 area (usually the first 256 bytes in the external ram) for allocating variables
8199 and passing parameters.
8201 \begin_inset LatexCommand \ref{sub:External-Stack}
8206 External Stack for more details.
8210 \labelwidthstring 00.00.0000
8217 \begin_layout Standard
8230 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
8234 Causes the linker to check if the internal ram usage is within limits of
8239 \labelwidthstring 00.00.0000
8246 \begin_layout Standard
8259 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
8263 Causes the linker to check if the external ram usage is within limits of
8268 \labelwidthstring 00.00.0000
8275 \begin_layout Standard
8288 \begin_inset LatexCommand \index{-\/-code-size <Value>}
8292 Causes the linker to check if the code memory usage is within limits of
8297 \labelwidthstring 00.00.0000
8304 \begin_layout Standard
8317 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8321 Causes the linker to check if there is at minimum <Value> bytes for stack.
8325 \labelwidthstring 00.00.0000
8332 \begin_layout Standard
8345 \begin_inset LatexCommand \index{-\/-pack-iram}
8349 Causes the linker to use unused register banks for data variables and pack
8350 data, idata and stack together.
8351 This is the default now.
8355 \labelwidthstring 00.00.0000
8362 \begin_layout Standard
8375 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8379 Causes the linker to use old style for allocating memory areas.
8383 \labelwidthstring 00.00.0000
8390 \begin_layout Standard
8403 \begin_inset LatexCommand \index{-\/-acall-ajmp}
8407 Replaces the three byte instructions lcall/ljmp with the two byte instructions
8409 Only use this option if your code is in the same 2k block of memory.
8410 You may need to use this option for some 8051 derivatives which lack the
8411 lcall/ljmp instructions..
8414 \begin_layout Standard
8415 \begin_inset VSpace bigskip
8421 \begin_layout Subsection
8422 DS390 / DS400 Options
8423 \begin_inset LatexCommand \index{Options DS390}
8428 \begin_inset LatexCommand \index{DS390}
8436 \labelwidthstring 00.00.0000
8443 \begin_layout Standard
8455 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8465 Generate 24-bit flat mode code.
8466 This is the one and only that the ds390 code generator supports right now
8467 and is default when using
8472 See section Memory Models for more details.
8476 \labelwidthstring 00.00.0000
8483 \begin_layout Standard
8493 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8499 disable interrupts during ESP:SP updates.
8503 \labelwidthstring 00.00.0000
8510 \begin_layout Standard
8522 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8526 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8527 This is the one and only that the ds390 code generator supports right now
8528 and is default when using
8533 In this mode, the stack is located in the lower 1K of the internal RAM,
8534 which is mapped to 0x400000.
8535 Note that the support is incomplete, since it still uses a single byte
8536 as the stack pointer.
8537 This means that only the lower 256 bytes of the potential 1K stack space
8538 will actually be used.
8539 However, this does allow you to reclaim the precious 256 bytes of low RAM
8540 for use for the DATA and IDATA segments.
8541 The compiler will not generate any code to put the processor into 10 bit
8543 It is important to ensure that the processor is in this mode before calling
8544 any re-entrant functions compiled with this option.
8545 In principle, this should work with the
8551 \begin_layout Standard
8561 \begin_inset LatexCommand \index{-\/-stack-auto}
8567 option, but that has not been tested.
8568 It is incompatible with the
8574 \begin_layout Standard
8584 \begin_inset LatexCommand \index{-\/-xstack}
8591 It also only makes sense if the processor is in 24 bit contiguous addressing
8598 \begin_layout Standard
8607 -model-flat24 option
8612 \begin_inset Note Note
8616 \labelwidthstring 00.00.0000
8623 \begin_layout Standard
8632 -stack-8-bit - switches off the 10-bit mode
8641 \labelwidthstring 00.00.0000
8648 \begin_layout Standard
8658 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8664 insert call to function __stack_probe at each function prologue.
8668 \labelwidthstring 00.00.0000
8675 \begin_layout Standard
8685 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8691 <nnnn> LibraryID used in -mTININative.
8696 \labelwidthstring 00.00.0000
8703 \begin_layout Standard
8713 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8719 generate code for DS390 Arithmetic Accelerator.
8723 \begin_layout Standard
8724 \begin_inset VSpace bigskip
8730 \begin_layout Subsection
8732 \begin_inset LatexCommand \index{Options Z80}
8737 \begin_inset LatexCommand \index{Z80}
8745 \labelwidthstring 00.00.0000
8752 \begin_layout Standard
8764 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8774 Force a called function to always save BC.
8778 \labelwidthstring 00.00.0000
8785 \begin_layout Standard
8797 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8801 When linking, skip the standard crt0.o object file.
8802 You must provide your own crt0.o for your system when linking.
8806 \labelwidthstring 00.00.0000
8813 \begin_layout Standard
8825 \begin_inset LatexCommand \index{Z80!Options!-\/-portmode=<Value>}
8829 Determinate PORT I/O mode (<Value> is z80 or z180).
8833 \labelwidthstring 00.00.0000
8840 \begin_layout Standard
8852 \begin_inset LatexCommand \index{Z80!Options!-\/-asm=<Value>}
8856 Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
8860 \labelwidthstring 00.00.0000
8867 \begin_layout Standard
8880 \begin_inset LatexCommand \index{Z80!Options!-\/-codeseg <Value>}
8884 Use <Value> for the code segment name.
8888 \labelwidthstring 00.00.0000
8895 \begin_layout Standard
8908 \begin_inset LatexCommand \index{Z80!Options!-\/-constseg <Value>}
8912 Use <Value> for the const segment name.
8916 \labelwidthstring 00.00.0000
8917 \begin_inset VSpace bigskip
8923 \begin_layout Subsection
8925 \begin_inset LatexCommand \index{Options GBZ80}
8930 \begin_inset LatexCommand \index{GBZ80}
8938 \labelwidthstring 00.00.0000
8945 \begin_layout Standard
8957 \begin_inset LatexCommand \index{GBZ80!Options!-\/-callee-saves-bc}
8967 Force a called function to always save BC.
8971 \labelwidthstring 00.00.0000
8978 \begin_layout Standard
8990 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8994 When linking, skip the standard crt0.o object file.
8995 You must provide your own crt0.o for your system when linking.
8999 \labelwidthstring 00.00.0000
9006 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
9010 Use code bank <Num>.
9014 \labelwidthstring 00.00.0000
9021 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
9025 Use data bank <Num>.
9029 \labelwidthstring 00.00.0000
9036 \begin_layout Standard
9049 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
9053 Use <Value> for the code segment name.
9057 \labelwidthstring 00.00.0000
9064 \begin_layout Standard
9077 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
9081 Use <Value> for the const segment name.
9084 \begin_layout Standard
9085 \begin_inset VSpace bigskip
9091 \begin_layout Subsection
9092 Optimization Options
9093 \begin_inset LatexCommand \index{Options optimization}
9098 \begin_inset LatexCommand \index{Optimization options}
9106 \labelwidthstring 00.00.0000
9113 \begin_layout Standard
9123 \begin_inset LatexCommand \index{-\/-nogcse}
9129 Will not do global subexpression elimination, this option may be used when
9130 the compiler creates undesirably large stack/data spaces to store compiler
9140 \begin_inset LatexCommand \index{sloc (spill location)}
9145 A warning message will be generated when this happens and the compiler
9146 will indicate the number of extra bytes it allocated.
9147 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9149 \begin_inset LatexCommand \index{\#pragma nogcse}
9153 can be used to turn off global subexpression elimination
9154 \begin_inset LatexCommand \index{Subexpression elimination}
9158 for a given function only.
9162 \labelwidthstring 00.00.0000
9169 \begin_layout Standard
9179 \begin_inset LatexCommand \index{-\/-noinvariant}
9185 Will not do loop invariant optimizations, this may be turned off for reasons
9186 explained for the previous option.
9187 For more details of loop optimizations performed see Loop Invariants in
9189 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
9194 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9196 \begin_inset LatexCommand \index{\#pragma noinvariant}
9200 can be used to turn off invariant optimizations for a given function only.
9204 \labelwidthstring 00.00.0000
9211 \begin_layout Standard
9221 \begin_inset LatexCommand \index{-\/-noinduction}
9227 Will not do loop induction optimizations, see section strength reduction
9229 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9231 \begin_inset LatexCommand \index{\#pragma noinduction}
9235 can be used to turn off induction optimizations for a given function only.
9239 \labelwidthstring 00.00.0000
9246 \begin_layout Standard
9256 \begin_inset LatexCommand \index{-\/-nojtbound}
9267 Will not generate boundary condition check when switch statements
9268 \begin_inset LatexCommand \index{switch statement}
9272 are implemented using jump-tables.
9274 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
9279 Switch Statements for more details.
9280 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9282 \begin_inset LatexCommand \index{\#pragma nojtbound}
9286 can be used to turn off boundary checking for jump tables for a given function
9291 \labelwidthstring 00.00.0000
9298 \begin_layout Standard
9308 \begin_inset LatexCommand \index{-\/-noloopreverse}
9317 Will not do loop reversal
9318 \begin_inset LatexCommand \index{Loop reversing}
9326 \labelwidthstring 00.00.0000
9331 \begin_layout Standard
9345 \begin_inset LatexCommand \index{-\/-nolabelopt }
9349 Will not optimize labels (makes the dumpfiles more readable).
9353 \labelwidthstring 00.00.0000
9360 \begin_layout Standard
9370 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9376 Will not memcpy initialized data from code space into xdata space.
9377 This saves a few bytes in code space if you don't have initialized data
9378 \begin_inset LatexCommand \index{Variable initialization}
9386 \labelwidthstring 00.00.0000
9393 \begin_layout Standard
9403 \begin_inset LatexCommand \index{-\/-nooverlay}
9409 The compiler will not overlay parameters and local variables of any function,
9410 see section Parameters and local variables for more details.
9414 \labelwidthstring 00.00.0000
9421 \begin_layout Standard
9431 \begin_inset LatexCommand \index{-\/-no-peep}
9437 Disable peep-hole optimization with built-in rules.
9441 \labelwidthstring 00.00.0000
9448 \begin_layout Standard
9460 \begin_inset LatexCommand \index{-\/-peep-file}
9465 <filename> This option can be used to use additional rules to be used by
9466 the peep hole optimizer.
9468 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9473 Peep Hole optimizations for details on how to write these rules.
9477 \labelwidthstring 00.00.0000
9484 \begin_layout Standard
9494 \begin_inset LatexCommand \index{-\/-peep-asm}
9500 Pass the inline assembler code through the peep hole optimizer.
9501 This can cause unexpected changes to inline assembler code, please go through
9502 the peephole optimizer
9503 \begin_inset LatexCommand \index{Peephole optimizer}
9507 rules defined in the source file tree '<target>/peeph.def' before using
9512 \labelwidthstring 00.00.0000
9519 \begin_layout Standard
9529 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9535 The compiler will optimize code generation towards fast code, possibly
9536 at the expense of code size.
9540 \labelwidthstring 00.00.0000
9547 \begin_layout Standard
9557 \begin_inset LatexCommand \index{-\/-opt-code-size}
9563 The compiler will optimize code generation towards compact code, possibly
9564 at the expense of code speed.
9567 \begin_layout Standard
9568 \begin_inset VSpace bigskip
9574 \begin_layout Subsection
9576 \begin_inset LatexCommand \index{Options other}
9584 \labelwidthstring 00.00.0000
9592 \begin_layout Standard
9602 \begin_inset LatexCommand \index{-\/-compile-only}
9607 \begin_inset LatexCommand \index{-c -\/-compile-only}
9613 will compile and assemble the source, but will not call the linkage editor.
9617 \labelwidthstring 00.00.0000
9626 \begin_layout Standard
9638 \begin_inset LatexCommand \index{-\/-c1mode}
9644 reads the preprocessed source from standard input and compiles it.
9645 The file name for the assembler output must be specified using the -o option.
9649 \labelwidthstring 00.00.0000
9653 \begin_inset LatexCommand \index{-E}
9659 Run only the C preprocessor.
9660 Preprocess all the C source files specified and output the results to standard
9665 \labelwidthstring 00.00.0000
9670 \begin_inset LatexCommand \index{-o <path/file>}
9676 The output path where everything will be placed or the file name used for
9677 all generated output files.
9678 If the parameter is a path, it must have a trailing slash (or backslash
9679 for the Windows binaries) to be recognized as a path.
9684 Note for Windows users: if the path contains spaces, it should be surrounded
9686 The trailing backslash should be doubled in order to prevent escaping the
9687 final quote, for example:
9690 \begin_inset Quotes sld
9704 \begin_inset Quotes srd
9709 or put after the final quote, for example:
9712 \begin_inset Quotes sld
9722 \begin_inset Quotes srd
9730 The path using slashes for directory delimiters can be used too, for example:
9734 \begin_inset Quotes sld
9737 F:/Projects/test3/output 1/
9738 \begin_inset Quotes srd
9747 \labelwidthstring 00.00.0000
9754 \begin_layout Standard
9764 \begin_inset LatexCommand \index{-\/-stack-auto}
9775 All functions in the source file will be compiled as
9780 \begin_inset LatexCommand \index{reentrant}
9785 the parameters and local variables will be allocated on the stack
9786 \begin_inset LatexCommand \index{stack}
9792 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9796 Parameters and Local Variables for more details.
9797 If this option is used all source files in the project should be compiled
9799 It automatically implies -
9805 \begin_layout Standard
9816 -int-long-reent and -
9822 \begin_layout Standard
9838 \labelwidthstring 00.00.0000
9845 \begin_layout Standard
9855 \begin_inset LatexCommand \index{-\/-callee-saves}
9860 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9864 function1[,function2][,function3]....
9867 The compiler by default uses a caller saves convention for register saving
9868 across function calls, however this can cause unnecessary register pushing
9869 and popping when calling small functions from larger functions.
9870 This option can be used to switch the register saving convention for the
9871 function names specified.
9872 The compiler will not save registers when calling these functions, no extra
9873 code will be generated at the entry and exit (function prologue
9876 \begin_inset LatexCommand \index{function prologue}
9885 \begin_inset LatexCommand \index{function epilogue}
9891 ) for these functions to save and restore the registers used by these functions,
9892 this can SUBSTANTIALLY reduce code and improve run time performance of
9894 In the future the compiler (with inter procedural analysis) will be able
9895 to determine the appropriate scheme to use for each function call.
9896 DO NOT use this option for built-in functions such as _mulint..., if this
9897 option is used for a library function the appropriate library function
9898 needs to be recompiled with the same option.
9899 If the project consists of multiple source files then all the source file
9900 should be compiled with the same -
9904 \begin_layout Standard
9913 -callee-saves option string.
9914 Also see #pragma\InsetSpace ~
9916 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9921 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9929 \labelwidthstring 00.00.0000
9936 \begin_layout Standard
9946 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9960 \begin_layout Standard
9969 -callee-saves will be applied to all functions by default.
9973 \labelwidthstring 00.00.0000
9980 \begin_layout Standard
9990 \begin_inset LatexCommand \index{-\/-debug}
9999 When this option is used the compiler will generate debug information.
10000 The debug information collected in a file with .cdb extension can be used
10002 For more information see documentation for SDCDB.
10003 Another file with no extension contains debug information in AOMF or AOMF51
10004 \begin_inset LatexCommand \index{AOMF, AOMF51}
10008 format which is commonly used by third party tools.
10012 \labelwidthstring 00.00.0000
10016 \begin_inset LatexCommand \index{-S}
10027 Stop after the stage of compilation proper; do not assemble.
10028 The output is an assembler code file for the input file specified.
10032 \labelwidthstring 00.00.0000
10039 \begin_layout Standard
10049 \begin_inset LatexCommand \index{-\/-int-long-reent}
10055 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
10056 Note by default these libraries are compiled as non-reentrant.
10057 See section Installation for more details.
10061 \labelwidthstring 00.00.0000
10068 \begin_layout Standard
10078 \begin_inset LatexCommand \index{-\/-cyclomatic}
10087 This option will cause the compiler to generate an information message for
10088 each function in the source file.
10089 The message contains some
10093 information about the function.
10094 The number of edges and nodes the compiler detected in the control flow
10095 graph of the function, and most importantly the
10097 cyclomatic complexity
10098 \begin_inset LatexCommand \index{Cyclomatic complexity}
10104 see section on Cyclomatic Complexity for more details.
10108 \labelwidthstring 00.00.0000
10115 \begin_layout Standard
10125 \begin_inset LatexCommand \index{-\/-float-reent}
10131 Floating point library is compiled as reentrant
10132 \begin_inset LatexCommand \index{reentrant}
10137 See section Installation for more details.
10141 \labelwidthstring 00.00.0000
10148 \begin_layout Standard
10158 \begin_inset LatexCommand \index{-\/-funsigned-char}
10164 The default signedness for every type is
10169 In some embedded environments the default signedness of
10178 To set the signess for characters to unsigned, use the option -
10184 \begin_layout Standard
10196 If this option is set and no signedness keyword (unsigned/signed) is given,
10197 a char will be signed.
10198 All other types are unaffected.
10202 \labelwidthstring 00.00.0000
10209 \begin_layout Standard
10219 \begin_inset LatexCommand \index{-\/-main-return}
10225 This option can be used if the code generated is called by a monitor program
10226 or if the main routine includes an endless loop.
10227 This option results in slightly smaller code and saves two bytes of stack
10229 The return from the 'main'
10230 \begin_inset LatexCommand \index{main return}
10234 function will return to the function calling main.
10235 The default setting is to lock up i.e.
10244 \labelwidthstring 00.00.0000
10251 \begin_layout Standard
10261 \begin_inset LatexCommand \index{-\/-nostdinc}
10267 This will prevent the compiler from passing on the default include path
10268 to the preprocessor.
10272 \labelwidthstring 00.00.0000
10279 \begin_layout Standard
10289 \begin_inset LatexCommand \index{-\/-nostdlib}
10295 This will prevent the compiler from passing on the default library
10296 \begin_inset LatexCommand \index{Libraries}
10300 path to the linker.
10304 \labelwidthstring 00.00.0000
10311 \begin_layout Standard
10321 \begin_inset LatexCommand \index{-\/-verbose}
10327 Shows the various actions the compiler is performing.
10331 \labelwidthstring 00.00.0000
10335 \begin_inset LatexCommand \index{-V}
10341 Shows the actual commands the compiler is executing.
10345 \labelwidthstring 00.00.0000
10352 \begin_layout Standard
10362 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
10368 Hides your ugly and inefficient c-code from the asm file, so you can always
10369 blame the compiler :)
10373 \labelwidthstring 00.00.0000
10380 \begin_layout Standard
10390 \begin_inset LatexCommand \index{-\/-no-gen-comments}
10396 Include code generator and peep-hole comments in the generated asm files.
10400 \labelwidthstring 00.00.0000
10407 \begin_layout Standard
10417 \begin_inset LatexCommand \index{-\/-no-peep-comments}
10423 Don't include peep-hole comments in the generated asm files even if -
10429 \begin_layout Standard
10440 -fverbose-asm option is specified.
10444 \labelwidthstring 00.00.0000
10451 \begin_layout Standard
10461 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10467 Include i-codes in the asm file.
10468 Sounds like noise but is most helpful for debugging the compiler itself.
10472 \labelwidthstring 00.00.0000
10479 \begin_layout Standard
10489 \begin_inset LatexCommand \index{pedantic}
10494 \begin_inset LatexCommand \index{-\/-less-pedantic}
10501 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10505 Disable some of the more pedantic warnings
10506 \begin_inset LatexCommand \index{Warnings}
10511 For more details, see the less_pedantic pragma
10512 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10520 \labelwidthstring 00.00.0000
10527 \begin_layout Standard
10536 -disable-warning\InsetSpace ~
10538 \begin_inset LatexCommand \index{-\/-disable-warning}
10544 Disable specific warning with number <nnnn>.
10548 \labelwidthstring 00.00.0000
10555 \begin_layout Standard
10565 \begin_inset LatexCommand \index{-\/-Werror}
10571 Treat all warnings as errors.
10575 \labelwidthstring 00.00.0000
10582 \begin_layout Standard
10592 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10598 Display the directories in the compiler's search path
10602 \labelwidthstring 00.00.0000
10609 \begin_layout Standard
10619 \begin_inset LatexCommand \index{-\/-vc}
10625 Display errors and warnings using MSVC style, so you can use SDCC with
10626 the visual studio IDE
10627 \begin_inset LatexCommand \index{IDE}
10632 With SDCC both offering a GCC-like (the default) and a MSVC-like
10633 \begin_inset LatexCommand \index{MSVC output style}
10637 output style, integration into most programming editors should be straightforwa
10642 \labelwidthstring 00.00.0000
10649 \begin_layout Standard
10659 \begin_inset LatexCommand \index{-\/-use-stdout}
10665 Send errors and warnings to stdout instead of stderr.
10669 \labelwidthstring 00.00.0000
10673 asmOption[,asmOption]
10676 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10681 Pass the asmOption to the assembler
10682 \begin_inset LatexCommand \index{Options assembler}
10687 \begin_inset LatexCommand \index{Assembler options}
10692 See file sdcc/as/doc/asxhtm.html for assembler options.cd
10696 \labelwidthstring 00.00.0000
10703 \begin_layout Standard
10713 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10719 Generally follow the C89 standard, but allow SDCC features that conflict
10720 with the standard (default).
10724 \labelwidthstring 00.00.0000
10731 \begin_layout Standard
10741 \begin_inset LatexCommand \index{-\/-std-c89}
10747 Follow the C89 standard and disable SDCC features that conflict with the
10752 \labelwidthstring 00.00.0000
10759 \begin_layout Standard
10769 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10775 Generally follow the C99 standard, but allow SDCC features that conflict
10776 with the standard (incomplete support).
10780 \labelwidthstring 00.00.0000
10787 \begin_layout Standard
10797 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10803 Follow the C99 standard and disable SDCC features that conflict with the
10804 standard (incomplete support).
10808 \labelwidthstring 00.00.0000
10815 \begin_layout Standard
10827 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10832 <Name> The name to be used for the code
10833 \begin_inset LatexCommand \index{code}
10837 segment, default CSEG.
10838 This is useful if you need to tell the compiler to put the code in a special
10839 segment so you can later on tell the linker to put this segment in a special
10841 Can be used for instance when using bank switching to put the code in a
10846 \labelwidthstring 00.00.0000
10853 \begin_layout Standard
10865 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10870 <Name> The name to be used for the const
10871 \begin_inset LatexCommand \index{const}
10875 segment, default CONST.
10876 This is useful if you need to tell the compiler to put the const data in
10877 a special segment so you can later on tell the linker to put this segment
10878 in a special place in memory.
10879 Can be used for instance when using bank switching to put the const data
10884 \labelwidthstring 00.00.0000
10891 \begin_layout Standard
10900 -fdollars-in-identifiers
10901 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10907 Permit '$' as an identifier character.
10911 \labelwidthstring 00.00.0000
10918 \begin_layout Standard
10930 \begin_inset LatexCommand \index{-\/-more-pedantic}
10935 \begin_inset LatexCommand \index{pedantic}
10945 a SDCC compiler option but if you want
10949 warnings you can use a separate tool dedicated to syntax checking like
10951 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10956 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10961 \begin_inset LatexCommand \url{http://www.splint.org}
10966 To make your source files parseable by splint you will have to include
10972 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10976 in your source file and add brackets around extended keywords (like
10979 \begin_inset Quotes sld
10992 \begin_inset Quotes srd
11000 \begin_inset Quotes sld
11003 __interrupt\InsetSpace ~
11005 \begin_inset Quotes srd
11013 Splint has an excellent on line manual at
11014 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
11018 and it's capabilities go beyond pure syntax checking.
11019 You'll need to tell splint the location of SDCC's include files so a typical
11020 command line could look like this:
11024 splint\InsetSpace ~
11026 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
11032 \labelwidthstring 00.00.0000
11039 \begin_layout Standard
11051 \begin_inset LatexCommand \index{-\/-short-is-8bits}
11056 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
11060 Treat short as 8-bit (for backward compatibility with older versions of
11061 compiler - see section
11062 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
11069 \begin_layout Standard
11070 \begin_inset VSpace bigskip
11076 \begin_layout Subsection
11077 Intermediate Dump Options
11078 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
11083 \begin_inset LatexCommand \index{Options intermediate dump}
11088 \begin_inset LatexCommand \index{Intermediate dump options}
11095 \begin_layout Standard
11096 The following options are provided for the purpose of retargetting and debugging
11098 They provide a means to dump the intermediate code (iCode
11099 \begin_inset LatexCommand \index{iCode}
11103 ) generated by the compiler in human readable form at various stages of
11104 the compilation process.
11105 More on iCodes see chapter
11106 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
11111 \begin_inset Quotes srd
11114 The anatomy of the compiler
11115 \begin_inset Quotes srd
11122 \labelwidthstring 00.00.0000
11129 \begin_layout Standard
11139 \begin_inset LatexCommand \index{-\/-dumpraw}
11145 This option will cause the compiler to dump the intermediate code into
11148 <source filename>.dumpraw
11150 just after the intermediate code has been generated for a function, i.e.
11151 before any optimizations are done.
11153 \begin_inset LatexCommand \index{Basic blocks}
11157 at this stage ordered in the depth first number, so they may not be in
11158 sequence of execution.
11162 \labelwidthstring 00.00.0000
11169 \begin_layout Standard
11179 \begin_inset LatexCommand \index{-\/-dumpgcse}
11185 Will create a dump of iCodes, after global subexpression elimination
11186 \begin_inset LatexCommand \index{Global subexpression elimination}
11190 , into a file named
11192 <source filename>.dumpgcse.
11196 \labelwidthstring 00.00.0000
11203 \begin_layout Standard
11213 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
11219 Will create a dump of iCodes, after deadcode elimination
11220 \begin_inset LatexCommand \index{Dead-code elimination}
11224 , into a file named
11226 <source filename>.dumpdeadcode.
11230 \labelwidthstring 00.00.0000
11237 \begin_layout Standard
11247 \begin_inset LatexCommand \index{-\/-dumploop}
11256 Will create a dump of iCodes, after loop optimizations
11257 \begin_inset LatexCommand \index{Loop optimization}
11261 , into a file named
11263 <source filename>.dumploop.
11267 \labelwidthstring 00.00.0000
11274 \begin_layout Standard
11284 \begin_inset LatexCommand \index{-\/-dumprange}
11293 Will create a dump of iCodes, after live range analysis
11294 \begin_inset LatexCommand \index{Live range analysis}
11298 , into a file named
11300 <source filename>.dumprange.
11304 \labelwidthstring 00.00.0000
11311 \begin_layout Standard
11321 \begin_inset LatexCommand \index{-\/-dumlrange}
11327 Will dump the life ranges
11328 \begin_inset LatexCommand \index{Live range analysis}
11336 \labelwidthstring 00.00.0000
11343 \begin_layout Standard
11353 \begin_inset LatexCommand \index{-\/-dumpregassign}
11362 Will create a dump of iCodes, after register assignment
11363 \begin_inset LatexCommand \index{Register assignment}
11367 , into a file named
11369 <source filename>.dumprassgn.
11373 \labelwidthstring 00.00.0000
11380 \begin_layout Standard
11390 \begin_inset LatexCommand \index{-\/-dumplrange}
11396 Will create a dump of the live ranges of iTemp's
11400 \labelwidthstring 00.00.0000
11407 \begin_layout Standard
11417 \begin_inset LatexCommand \index{-\/-dumpall}
11428 Will cause all the above mentioned dumps to be created.
11431 \begin_layout Standard
11432 \begin_inset VSpace bigskip
11438 \begin_layout Subsection
11439 Redirecting output on Windows Shells
11442 \begin_layout Standard
11443 By default SDCC writes its error messages to
11444 \begin_inset Quotes sld
11448 \begin_inset Quotes srd
11452 To force all messages to
11453 \begin_inset Quotes sld
11457 \begin_inset Quotes srd
11469 \begin_layout Standard
11484 \begin_inset LatexCommand \index{-\/-use-stdout}
11489 Additionally, if you happen to have visual studio installed in your windows
11490 machine, you can use it to compile your sources using a custom build and
11497 \begin_layout Standard
11509 \begin_inset LatexCommand \index{-\/-vc}
11514 Something like this should work:
11533 \begin_layout Standard
11552 \begin_layout Standard
11564 -model-large -c $(InputPath)
11567 \begin_inset VSpace bigskip
11573 \begin_layout Section
11574 Environment variables
11575 \begin_inset LatexCommand \index{Environment variables}
11582 \begin_layout Standard
11583 SDCC recognizes the following environment variables:
11587 \labelwidthstring 00.00.0000
11591 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11597 SDCC installs a signal handler
11598 \begin_inset LatexCommand \index{signal handler}
11602 to be able to delete temporary files after an user break (^C) or an exception.
11603 If this environment variable is set, SDCC won't install the signal handler
11604 in order to be able to debug SDCC.
11608 \labelwidthstring 00.00.0000
11614 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11620 Path, where temporary files will be created.
11621 The order of the variables is the search order.
11622 In a standard *nix environment these variables are not set, and there's
11623 no need to set them.
11624 On Windows it's recommended to set one of them.
11628 \labelwidthstring 00.00.0000
11632 \begin_inset LatexCommand \index{SDCC\_HOME}
11639 \begin_inset LatexCommand \ref{sub:Install-paths}
11645 \begin_inset Quotes sld
11649 \begin_inset Quotes srd
11656 \labelwidthstring 00.00.0000
11660 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11667 \begin_inset LatexCommand \ref{sub:Search-Paths}
11673 \begin_inset Quotes sld
11677 \begin_inset Quotes srd
11684 \labelwidthstring 00.00.0000
11688 \begin_inset LatexCommand \index{SDCC\_LIB}
11695 \begin_inset LatexCommand \ref{sub:Search-Paths}
11701 \begin_inset Quotes sld
11705 \begin_inset Quotes srd
11711 \begin_layout Standard
11712 There are some more environment variables recognized by SDCC, but these
11713 are solely used for debugging purposes.
11714 They can change or disappear very quickly, and will never be documented.
11715 \begin_inset VSpace bigskip
11721 \begin_layout Section
11722 Storage Class Language Extensions
11725 \begin_layout Subsection
11726 MCS51/DS390 Storage Class
11727 \begin_inset LatexCommand \index{Storage class}
11731 Language Extensions
11734 \begin_layout Standard
11735 In addition to the ANSI storage classes SDCC allows the following MCS51
11736 specific storage classes:
11739 \begin_layout Subsubsection
11741 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11746 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11751 \begin_inset LatexCommand \index{near (storage class)}
11756 \begin_inset LatexCommand \index{\_\_near (storage class)}
11763 \begin_layout Standard
11768 storage class for the Small Memory model (
11776 or the more ANSI-C compliant forms
11784 can be used synonymously).
11785 Variables declared with this storage class will be allocated in the directly
11786 addressable portion of the internal RAM of a 8051, e.g.:
11789 \begin_layout Verse
11792 __data unsigned char test_data;
11795 \begin_layout Standard
11796 Writing 0x01 to this variable generates the assembly code:
11799 \begin_layout Verse
11802 75*00 01\InsetSpace ~
11810 \begin_layout Subsubsection
11812 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11817 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11822 \begin_inset LatexCommand \index{far (storage class)}
11827 \begin_inset LatexCommand \index{\_\_far (storage class)}
11834 \begin_layout Standard
11835 Variables declared with this storage class will be placed in the external
11841 storage class for the Large Memory model, e.g.:
11844 \begin_layout Verse
11847 __xdata unsigned char test_xdata;
11850 \begin_layout Standard
11851 Writing 0x01 to this variable generates the assembly code:
11854 \begin_layout Verse
11857 90s00r00\InsetSpace ~
11888 \begin_layout Subsubsection
11890 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11895 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11902 \begin_layout Standard
11903 Variables declared with this storage class will be allocated into the indirectly
11904 addressable portion of the internal ram of a 8051, e.g.:
11907 \begin_layout Verse
11910 __idata unsigned char test_idata;
11913 \begin_layout Standard
11914 Writing 0x01 to this variable generates the assembly code:
11917 \begin_layout Verse
11944 \begin_layout Standard
11945 Please note, the first 128 byte of idata physically access the same RAM
11946 as the data memory.
11947 The original 8051 had 128 byte idata memory, nowadays most devices have
11948 256 byte idata memory.
11950 \begin_inset LatexCommand \index{stack}
11954 is located in idata memory.
11957 \begin_layout Subsubsection
11959 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11964 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11971 \begin_layout Standard
11972 Paged xdata access is just as straightforward as using the other addressing
11974 It is typically located at the start of xdata and has a maximum size of
11976 The following example writes 0x01 to the pdata variable.
11977 Please note, pdata access physically accesses xdata memory.
11978 The high byte of the address is determined by port P2
11979 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11983 (or in case of some 8051 variants by a separate Special Function Register,
11985 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11994 storage class for the Medium Memory model, e.g.:
11997 \begin_layout Verse
12000 __pdata unsigned char test_pdata;
12003 \begin_layout Standard
12004 Writing 0x01 to this variable generates the assembly code:
12007 \begin_layout Verse
12016 mov r0,#_test_pdata
12038 \begin_layout Standard
12043 \begin_layout Standard
12053 \begin_inset LatexCommand \index{-\/-xstack}
12057 option is used the pdata memory area is followed by the xstack memory area
12058 and the sum of their sizes is limited to 256 bytes.
12061 \begin_layout Subsubsection
12063 \begin_inset LatexCommand \index{code}
12068 \begin_inset LatexCommand \index{\_\_code}
12075 \begin_layout Standard
12076 'Variables' declared with this storage class will be placed in the code
12080 \begin_layout Verse
12083 __code unsigned char test_code;
12086 \begin_layout Standard
12087 Read access to this variable generates the assembly code:
12090 \begin_layout Verse
12093 90s00r6F\InsetSpace ~
12096 mov dptr,#_test_code
12121 \begin_layout Standard
12126 indexed arrays of characters in code memory can be accessed efficiently:
12129 \begin_layout Verse
12132 __code char test_array[] = {'c','h','e','a','p'};
12135 \begin_layout Standard
12136 Read access to this array using an 8-bit unsigned index generates the assembly
12140 \begin_layout Verse
12152 \begin_layout Verse
12155 90s00r41\InsetSpace ~
12158 mov dptr,#_test_array
12161 \begin_layout Verse
12176 \begin_layout Subsubsection
12178 \begin_inset LatexCommand \index{bit}
12183 \begin_inset LatexCommand \index{\_\_bit}
12190 \begin_layout Standard
12191 This is a data-type and a storage class specifier.
12192 When a variable is declared as a bit, it is allocated into the bit addressable
12193 memory of 8051, e.g.:
12196 \begin_layout Verse
12202 \begin_layout Standard
12203 Writing 1 to this variable generates the assembly code:
12206 \begin_layout Verse
12220 \begin_layout Standard
12221 The bit addressable memory consists of 128 bits which are located from 0x20
12222 to 0x2f in data memory.
12225 Apart from this 8051 specific storage class most architectures support
12227 \begin_inset LatexCommand \index{bitfields}
12235 \begin_layout Standard
12236 Not really meant as examples, but nevertheless showing what bitfields are
12237 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12243 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12244 signed modifier are implemented as unsigned.
12247 \begin_layout Subsubsection
12249 \begin_inset LatexCommand \index{sfr}
12254 \begin_inset LatexCommand \index{\_\_sfr}
12259 \begin_inset LatexCommand \index{sfr16}
12264 \begin_inset LatexCommand \index{\_\_sfr16}
12269 \begin_inset LatexCommand \index{sfr32}
12274 \begin_inset LatexCommand \index{\_\_sfr32}
12279 \begin_inset LatexCommand \index{\_\_sbit}
12284 \begin_inset LatexCommand \index{sbit}
12291 \begin_layout Standard
12292 Like the bit keyword,
12294 sfr / sfr16 / sfr32 / sbit
12296 signify both a data-type and storage class, they are used to describe the
12317 variables of a 8051, eg:
12320 \begin_layout Verse
12324 \begin_inset LatexCommand \index{at}
12329 \begin_inset LatexCommand \index{\_\_at}
12333 (0x80) P0;\InsetSpace ~
12334 /* special function register P0 at location 0x80 */
12339 special function register combination for timer 0
12343 with the high byte at
12344 location 0x8C and the low byte at location 0x8A */
12346 __sfr16 __at (0x8C8A)
12352 \begin_inset LatexCommand \index{at}
12357 \begin_inset LatexCommand \index{\_\_at}
12361 (0xd7) CY;\InsetSpace ~
12363 \begin_inset LatexCommand \index{Flags}
12368 \begin_inset LatexCommand \index{Carry flag}
12375 \begin_layout Standard
12376 Special function registers which are located on an address dividable by
12377 8 are bit-addressable, an
12381 addresses a specific bit within these sfr.
12383 16 Bit and 32 bit special function
12384 register combinations which require a certain access order are better not
12394 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12395 this is not guaranteed.
12400 \begin_layout Standard
12401 Please note, if you use a header file which was written for another compiler
12402 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
12408 Specifically the syntax
12411 sfr P0 = 0x80;\InsetSpace ~
12418 by SDCC to an assignment of 0x80 to a variable called P0
12421 \begin_inset Marginal
12424 \begin_layout Standard
12436 Nevertheless it is possible to write header files
12437 \begin_inset LatexCommand \index{Header files}
12442 \begin_inset LatexCommand \index{Include files}
12446 which can be shared among different compilers (see section
12447 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
12455 \begin_layout Subsubsection
12457 \begin_inset LatexCommand \index{Pointer}
12461 to MCS51/DS390 specific memory spaces
12464 \begin_layout Standard
12465 SDCC allows (via language extensions) pointers to explicitly point to any
12466 of the memory spaces
12467 \begin_inset LatexCommand \index{Memory model}
12472 In addition to the explicit pointers, the compiler uses (by default) generic
12473 pointers which can be used to point to any of the memory spaces.
12478 declaration examples:
12481 \begin_layout Verse
12484 /* pointer physically in internal ram pointing to object in external ram
12487 __xdata unsigned char * __data p;
12491 /* pointer physically in external ram
12492 pointing to object in internal ram */
12494 __data unsigned char * __xdata p;
12499 pointer physically in code rom pointing to data in xdata space */
12502 unsigned char * __code p;
12506 /* pointer physically in code space pointing to
12507 data in code space */
12509 __code unsigned char * __code p;
12514 physically located in xdata space */
12516 unsigned char * __xdata p;
12521 pointer physically located in default memory space */
12528 the following is a function pointer
12529 \begin_inset LatexCommand \index{function pointer}
12533 physically located in data space */
12535 char (* __data fp)(void);
12538 \begin_layout Standard
12539 Well you get the idea.
12544 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
12557 The highest order byte of the
12561 pointers contains the data space information.
12562 Assembler support routines are called whenever data is stored or retrieved
12568 These are useful for developing reusable library
12569 \begin_inset LatexCommand \index{Libraries}
12574 Explicitly specifying the pointer
12575 \begin_inset LatexCommand \index{pointer}
12579 type will generate the most efficient code.
12582 \begin_layout Subsubsection
12583 Notes on MCS51 memory
12584 \begin_inset LatexCommand \index{MCS51 memory}
12591 \begin_layout Standard
12592 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12593 RAM memory which is structured as follows:
12597 - Bytes 00-1F - 32 bytes to hold
12598 up to 4 banks of the registers R0 to R7,
12600 - Bytes 20-2F - 16 bytes to hold
12602 \begin_inset LatexCommand \index{bit}
12608 - Bytes 30-7F - 80 bytes for general purpose use.
12613 \begin_layout Standard
12614 Additionally some members of the MCS51 family may have up to 128 bytes of
12615 additional, indirectly addressable, internal RAM memory (
12620 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12625 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12630 Furthermore, some chips may have some built in external memory (
12635 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12640 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12644 ) which should not be confused with the internal, directly addressable RAM
12650 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12655 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12660 Sometimes this built in
12664 memory has to be activated before using it (you can probably find this
12665 information on the datasheet of the microcontroller your are using, see
12667 \begin_inset LatexCommand \ref{sub:Startup-Code}
12675 \begin_layout Standard
12676 Normally SDCC will only use the first bank
12677 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12681 of registers (register bank 0), but it is possible to specify that other
12682 banks of registers (keyword
12689 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12694 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12700 ) should be used for example in interrupt
12701 \begin_inset LatexCommand \index{interrupt}
12706 \begin_inset LatexCommand \index{\_\_interrupt}
12711 By default, the compiler will place the stack after the last byte of allocated
12712 memory for variables.
12713 For example, if the first 2 banks of registers are used, and only four
12718 variables, it will position the base of the internal stack at address 20
12720 This implies that as the stack
12721 \begin_inset LatexCommand \index{stack}
12725 grows, it will use up the remaining register banks, and the 16 bytes used
12726 by the 128 bit variables, and 80 bytes for general purpose use.
12727 If any bit variables are used, the data variables will be placed in unused
12728 register banks and after the byte holding the last bit variable.
12729 For example, if register banks 0 and 1 are used, and there are 9 bit variables
12734 variables will be placed starting from address 0x10 to 0x20 and continue
12740 \begin_layout Standard
12750 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12754 to specify the start address of the
12762 \begin_layout Standard
12772 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12776 to specify the size of the total internal RAM (
12790 \begin_layout Standard
12791 By default the 8051 linker will place the stack after the last byte of (i)data
12797 \begin_layout Standard
12807 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12811 allows you to specify the start of the stack, i.e.
12812 you could start it after any data in the general purpose area.
12813 If your microcontroller has additional indirectly addressable internal
12818 ) you can place the stack on it.
12819 You may also need to use -
12823 \begin_layout Standard
12833 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12837 to set the start address of the external RAM (
12845 \begin_layout Standard
12855 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12859 to specify its size.
12860 Same goes for the code memory, using -
12864 \begin_layout Standard
12874 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12882 \begin_layout Standard
12892 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12897 If in doubt, don't specify any options and see if the resulting memory
12898 layout is appropriate, then you can adjust it.
12901 \begin_layout Standard
12902 The linker generates two files with memory allocation information.
12903 The first, with extension .map
12904 \begin_inset LatexCommand \index{<file>.map}
12908 shows all the variables and segments.
12909 The second with extension .mem
12910 \begin_inset LatexCommand \index{<file>.mem}
12914 shows the final memory layout.
12915 The linker will complain either if memory segments overlap, there is not
12916 enough memory, or there is not enough space for stack.
12917 If you get any linking warnings and/or errors related to stack or segments
12918 allocation, take a look at either the .map or .mem files to find out what
12920 The .mem file may even suggest a solution to the problem.
12921 \begin_inset VSpace bigskip
12927 \begin_layout Subsection
12928 Z80/Z180 Storage Class
12929 \begin_inset LatexCommand \index{Z80!Storage class}
12933 Language Extensions
12936 \begin_layout Subsubsection
12938 \begin_inset LatexCommand \index{sfr}
12943 \begin_inset LatexCommand \index{\_\_sfr}
12947 (in/out to 8-bit addresses)
12950 \begin_layout Standard
12952 \begin_inset LatexCommand \index{Z80}
12956 family has separate address spaces for memory and
12966 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12971 \begin_inset LatexCommand \index{Z80!I/O memory}
12976 \begin_inset LatexCommand \index{Z180!I/O memory}
12980 is accessed with special instructions, e.g.:
12983 \begin_layout Verse
12986 sfr at 0x78 IoPort;\InsetSpace ~
12988 /* define a var in I/O space at 78h called IoPort */
12992 \begin_layout Standard
12993 Writing 0x01 to this variable generates the assembly code:
12996 \begin_layout Verse
13016 \begin_layout Subsubsection
13018 \begin_inset LatexCommand \index{sfr}
13023 \begin_inset LatexCommand \index{\_\_sfr}
13027 (in/out to 16-bit addresses)
13030 \begin_layout Standard
13035 is used to support 16 bit addresses in I/O memory e.g.:
13038 \begin_layout Verse
13042 \begin_inset LatexCommand \index{at}
13047 \begin_inset LatexCommand \index{\_\_at}
13054 \begin_layout Standard
13055 Writing 0x01 to this variable generates the assembly code:
13058 \begin_layout Verse
13061 01 23 01\InsetSpace ~
13083 \begin_layout Subsubsection
13085 \begin_inset LatexCommand \index{sfr}
13090 \begin_inset LatexCommand \index{\_\_sfr}
13094 (in0/out0 to 8 bit addresses on Z180
13095 \begin_inset LatexCommand \index{Z180}
13100 \begin_inset LatexCommand \index{HD64180 (see Z180)}
13107 \begin_layout Standard
13108 The compiler option -
13112 \begin_layout Standard
13122 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
13126 =180 (80) and a compiler #pragma\InsetSpace ~
13128 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
13132 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
13142 If you include the file z180.h this will be set automatically.
13143 \begin_inset VSpace bigskip
13149 \begin_layout Subsection
13151 \begin_inset LatexCommand \index{HC08!Storage class}
13155 Language Extensions
13158 \begin_layout Subsubsection
13160 \begin_inset LatexCommand \index{data (hc08 storage class)}
13165 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
13172 \begin_layout Standard
13173 The data storage class declares a variable that resides in the first 256
13174 bytes of memory (the direct page).
13176 \begin_inset LatexCommand \index{HC08}
13180 is most efficient at accessing variables (especially pointers) stored here.
13183 \begin_layout Subsubsection
13185 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
13190 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
13197 \begin_layout Standard
13198 The xdata storage class declares a variable that can reside anywhere in
13200 This is the default if no storage class is specified.
13202 \begin_inset VSpace bigskip
13208 \begin_layout Section
13209 Absolute Addressing
13210 \begin_inset LatexCommand \index{Absolute addressing}
13217 \begin_layout Standard
13218 Data items can be assigned an absolute address with the
13221 \begin_inset LatexCommand \index{at}
13226 \begin_inset LatexCommand \index{\_\_at}
13232 keyword, in addition to a storage class, e.g.:
13235 \begin_layout Verse
13239 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13244 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
13249 \begin_inset LatexCommand \index{at}
13254 \begin_inset LatexCommand \index{\_\_at}
13258 0x7ffe unsigned int chksum;
13261 \begin_layout Standard
13262 or, better conforming to ISO/IEC 9899 C:
13265 \begin_layout Verse
13268 __xdata __at (0x7ffe) unsigned int chksum;
13271 \begin_layout Standard
13272 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
13273 of the external ram.
13278 reserve any space for variables declared in this way
13279 \begin_inset Marginal
13282 \begin_layout Standard
13291 (they are implemented with an equate in the assembler).
13292 Thus it is left to the programmer to make sure there are no overlaps with
13293 other variables that are declared without the absolute address.
13294 The assembler listing file (.lst
13295 \begin_inset LatexCommand \index{<file>.lst}
13299 ) and the linker output files (.rst
13300 \begin_inset LatexCommand \index{<file>.rst}
13305 \begin_inset LatexCommand \index{<file>.map}
13309 ) are good places to look for such overlaps.
13312 \begin_layout Standard
13313 If however you provide an initializer
13314 \begin_inset LatexCommand \index{Variable initialization}
13318 actual memory allocation will take place and overlaps will be detected
13323 \begin_layout Verse
13326 __code __at (0x7ff0) char Id[5] =
13327 \begin_inset Quotes sld
13331 \begin_inset Quotes srd
13337 \begin_layout Standard
13338 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
13342 \begin_layout Standard
13343 In case of memory mapped I/O devices the keyword
13347 has to be used to tell the compiler that accesses might not be removed:
13350 \begin_layout Verse
13354 \begin_inset LatexCommand \index{volatile}
13359 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13364 \begin_inset LatexCommand \index{at}
13368 (0x8000) unsigned char PORTA_8255;
13371 \begin_layout Standard
13372 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
13377 \begin_inset LatexCommand \index{Aligned array}
13384 starts at a block (256 byte) boundary
13385 \begin_inset LatexCommand \index{block boundary}
13390 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13396 Absolute addresses can be specified for variables in all
13397 storage classes, e.g.:
13400 \begin_layout Verse
13404 \begin_inset LatexCommand \index{bit}
13409 \begin_inset LatexCommand \index{at}
13416 \begin_layout Standard
13417 The above example will allocate the variable at offset 0x02 in the bit-addressab
13419 There is no real advantage to assigning absolute addresses to variables
13420 in this manner, unless you want strict control over all the variables allocated.
13421 One possible use would be to write hardware portable code.
13422 For example, if you have a routine that uses one or more of the microcontroller
13423 I/O pins, and such pins are different for two different hardwares, you
13424 can declare the I/O pins in your routine using:
13427 \begin_layout Verse
13431 \begin_inset LatexCommand \index{volatile}
13435 __bit MOSI;\InsetSpace ~
13439 /* master out, slave in */
13441 extern volatile __bit MISO;\InsetSpace ~
13448 extern volatile __bit MCLK;\InsetSpace ~
13457 Output of a byte on a 3-wire serial bus.
13462 If needed adapt polarity of clock,
13463 polarity of data and bit order
13468 unsigned char spi_io(unsigned char out_byte)
13493 MOSI = out_byte & 0x80;
13524 /* _asm nop _endasm; */\InsetSpace ~
13532 /* for slow peripherals */
13584 \begin_layout Standard
13585 Then, someplace in the code for the first hardware you would use
13588 \begin_layout Verse
13592 \begin_inset LatexCommand \index{at}
13597 \begin_inset LatexCommand \index{\_\_at}
13601 (0x80) MOSI;\InsetSpace ~
13605 /* I/O port 0, bit 0 */
13607 __bit __at (0x81) MISO;\InsetSpace ~
13614 __bit __at (0x82) MCLK;\InsetSpace ~
13618 /* I/O port 0, bit 2 */
13621 \begin_layout Standard
13622 Similarly, for the second hardware you would use
13625 \begin_layout Verse
13628 __bit __at (0x83) MOSI;\InsetSpace ~
13632 /* I/O port 0, bit 3 */
13634 __bit __at (0x91) MISO;\InsetSpace ~
13639 I/O port 1, bit 1 */
13642 \begin_inset LatexCommand \index{bit}
13646 __at (0x92) MCLK;\InsetSpace ~
13650 /* I/O port 1, bit 2 */
13653 \begin_layout Standard
13654 and you can use the same hardware dependent routine without changes, as
13655 for example in a library.
13656 This is somehow similar to sbit, but only one absolute address has to be
13657 specified in the whole project.
13658 \begin_inset VSpace bigskip
13664 \begin_layout Section
13666 \begin_inset LatexCommand \index{Parameters}
13671 \begin_inset LatexCommand \index{function parameter}
13676 \begin_inset LatexCommand \index{local variables}
13681 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13688 \begin_layout Standard
13689 Automatic (local) variables and parameters to functions can either be placed
13690 on the stack or in data-space.
13691 The default action of the compiler is to place these variables in the internal
13692 RAM (for small model) or external RAM (for medium or large model).
13693 This in fact makes them similar to
13696 \begin_inset LatexCommand \index{static}
13702 so by default functions are non-reentrant
13703 \begin_inset LatexCommand \index{reentrant}
13712 They can be placed on the stack
13713 \begin_inset LatexCommand \index{stack}
13723 \begin_layout Standard
13733 \begin_inset LatexCommand \index{-\/-stack-auto}
13741 #pragma\InsetSpace ~
13745 \begin_inset LatexCommand \index{\#pragma stackauto}
13752 \begin_inset LatexCommand \index{reentrant}
13758 keyword in the function declaration, e.g.:
13761 \begin_layout Verse
13764 unsigned char foo(char i) __reentrant
13778 \begin_layout Standard
13779 Since stack space on 8051 is limited, the
13789 \begin_layout Standard
13800 option should be used sparingly.
13801 Note that the reentrant keyword just means that the parameters & local
13802 variables will be allocated to the stack, it
13806 mean that the function is register bank
13807 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13816 \begin_inset LatexCommand \index{local variables}
13820 can be assigned storage classes and absolute
13821 \begin_inset LatexCommand \index{Absolute addressing}
13828 \begin_layout Verse
13831 unsigned char foo()
13839 __xdata unsigned char i;
13852 \begin_inset LatexCommand \index{at}
13856 (0x31) unsigned char j;
13868 \begin_layout Standard
13869 In the above example the variable
13873 will be allocated in the external ram,
13877 in bit addressable space and
13888 \begin_layout Standard
13899 or when a function is declared as
13903 this should only be done for static variables.
13906 \begin_layout Standard
13908 \begin_inset LatexCommand \index{function parameter}
13912 however are not allowed any storage class
13913 \begin_inset LatexCommand \index{Storage class}
13917 , (storage classes for parameters will be ignored), their allocation is
13918 governed by the memory model in use, and the reentrancy options.
13921 \begin_layout Standard
13922 It is however allowed to use bit parameters in reentrant functions and also
13923 non-static local bit variables are supported.
13924 Efficient use is limited to 8 semi-bitregisters in bit space.
13925 They are pushed and popped to stack
13926 \begin_inset LatexCommand \index{stack}
13930 as a single byte just like the normal registers.
13933 \begin_layout Section
13935 \begin_inset LatexCommand \label{sub:Overlaying}
13940 \begin_inset LatexCommand \index{Overlaying}
13947 \begin_layout Standard
13949 \begin_inset LatexCommand \index{reentrant}
13953 functions SDCC will try to reduce internal ram space usage by overlaying
13954 parameters and local variables of a function (if possible).
13955 Parameters and local variables
13956 \begin_inset LatexCommand \index{local variables}
13960 of a function will be allocated to an overlayable segment if the function
13963 no other function calls and the function is non-reentrant and the memory
13965 \begin_inset LatexCommand \index{Memory model}
13972 If an explicit storage class
13973 \begin_inset LatexCommand \index{Storage class}
13977 is specified for a local variable, it will NOT be overlayed.
13980 \begin_layout Standard
13981 Note that the compiler (not the linkage editor) makes the decision for overlayin
13983 Functions that are called from an interrupt service routine
13984 \begin_inset Marginal
13987 \begin_layout Standard
13995 should be preceded by a #pragma\InsetSpace ~
13997 \begin_inset LatexCommand \index{\#pragma nooverlay}
14001 if they are not reentrant.
14004 \begin_layout Standard
14005 Also note that the compiler does not do any processing of inline assembler
14006 code, so the compiler might incorrectly assign local variables and parameters
14007 of a function into the overlay segment if the inline assembler code calls
14008 other c-functions that might use the overlay.
14009 In that case the #pragma\InsetSpace ~
14010 nooverlay should be used.
14013 \begin_layout Standard
14014 Parameters and local variables of functions that contain 16 or 32 bit multiplica
14016 \begin_inset LatexCommand \index{Multiplication}
14021 \begin_inset LatexCommand \index{Division}
14025 will NOT be overlayed since these are implemented using external functions,
14029 \begin_layout Verse
14035 \begin_inset LatexCommand \index{\#pragma nooverlay}
14041 void set_error(unsigned char errcd)
14058 some_isr () __interrupt
14059 \begin_inset LatexCommand \index{interrupt}
14089 \begin_layout Standard
14090 In the above example the parameter
14098 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
14100 not present, this could cause unpredictable runtime behavior when called
14101 from an interrupt service routine.
14102 The #pragma\InsetSpace ~
14103 nooverlay ensures that the parameters and local variables for
14104 the function are NOT overlayed.
14105 \begin_inset VSpace bigskip
14111 \begin_layout Section
14112 Interrupt Service Routines
14113 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
14120 \begin_layout Subsection
14121 General Information
14124 \begin_layout Standard
14137 outines to be coded in C, with some extended keywords.
14140 \begin_layout Verse
14143 void timer_isr (void) __interrupt (1) __using (1)
14157 \begin_layout Standard
14158 The optional number following the
14161 \begin_inset LatexCommand \index{interrupt}
14166 \begin_inset LatexCommand \index{\_\_interrupt}
14172 keyword is the interrupt number this routine will service.
14173 When present, the compiler will insert a call to this routine in the interrupt
14175 \begin_inset LatexCommand \index{interrupt vector table}
14179 for the interrupt number specified.
14180 If you have multiple source files in your project, interrupt service routines
14181 can be present in any of them, but a prototype of the isr MUST be present
14182 or included in the file that contains the function
14187 The optional (8051 specific) keyword
14190 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14195 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14201 can be used to tell the compiler to use the specified register bank when
14202 generating code for this function.
14205 Interrupt service routines open the door for some very interesting bugs:
14208 \begin_layout Subsubsection
14209 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
14213 Common interrupt pitfall: variable not declared
14218 \begin_layout Standard
14219 If an interrupt service routine changes variables which are accessed by
14220 other functions these variables have to be declared
14225 \begin_inset LatexCommand \index{volatile}
14231 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
14238 \begin_layout Subsubsection
14239 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
14243 Common interrupt pitfall:
14248 \begin_layout Standard
14249 If the access to these variables is not
14252 \begin_inset LatexCommand \index{atomic}
14259 the processor needs more than one instruction for the access and could
14260 be interrupted while accessing the variable) the interrupt must be disabled
14261 during the access to avoid inconsistent data.
14264 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
14265 and should be protected by disabling interrupts.
14266 You're not automatically on the safe side if you use 8 bit variables though.
14267 We need an example here: f.e.
14268 on the 8051 the harmless looking
14269 \begin_inset Quotes srd
14279 \begin_inset Quotes sld
14288 \begin_inset Quotes srd
14298 \begin_inset Quotes sld
14301 from within an interrupt routine might get lost if the interrupt occurs
14304 \begin_inset Quotes sld
14309 counter\InsetSpace ~
14314 \begin_inset Quotes srd
14317 is not atomic on the 8051 even if
14321 is located in data memory.
14323 Bugs like these are hard to reproduce and can
14324 cause a lot of trouble.
14328 \begin_layout Subsubsection
14329 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
14333 Common interrupt pitfall:
14338 \begin_layout Standard
14339 The return address and the registers used in the interrupt service routine
14340 are saved on the stack
14341 \begin_inset LatexCommand \index{stack}
14345 so there must be sufficient stack space.
14346 If there isn't variables or registers (or even the return address itself)
14353 \begin_inset LatexCommand \index{stack overflow}
14357 is most likely to happen if the interrupt occurs during the
14358 \begin_inset Quotes sld
14362 \begin_inset Quotes srd
14365 subroutine when the stack is already in use for f.e.
14366 many return addresses.
14369 \begin_layout Subsubsection
14370 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
14374 Common interrupt pitfall:
14376 use of non-reentrant functions
14379 \begin_layout Standard
14380 A special note here, int (16 bit) and long (32 bit) integer division
14381 \begin_inset LatexCommand \index{Division}
14386 \begin_inset LatexCommand \index{Multiplication}
14391 \begin_inset LatexCommand \index{Modulus}
14396 \begin_inset LatexCommand \index{Floating point support}
14400 operations are implemented using external support routines.
14401 If an interrupt service routine needs to do any of these operations then
14402 the support routines (as mentioned in a following section) will have to
14403 be recompiled using the
14409 \begin_layout Standard
14419 \begin_inset LatexCommand \index{-\/-stack-auto}
14425 option and the source file will need to be compiled using the
14431 \begin_layout Standard
14443 \begin_inset LatexCommand \index{-\/-int-long-reent}
14450 Note, the type promotion
14451 \begin_inset LatexCommand \index{type promotion}
14455 required by ANSI C can cause 16 bit routines to be used
14456 \begin_inset Marginal
14459 \begin_layout Standard
14468 without the programmer being aware of it.
14472 (unsigned char)(tail-1)
14474 within the if clause in section
14475 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
14482 \begin_layout Standard
14483 Calling other functions from an interrupt service routine is not recommended,
14484 avoid it if possible.
14485 Note that when some function is called from an interrupt service routine
14486 it should be preceded by a #pragma\InsetSpace ~
14488 \begin_inset LatexCommand \index{\#pragma nooverlay}
14492 if it is not reentrant.
14493 Furthermore nonreentrant functions should not be called from the main program
14494 while the interrupt service routine might be active.
14495 They also must not be called from low priority interrupt service routines
14496 while a high priority interrupt service routine might be active.
14497 You could use semaphores or make the function
14501 if all parameters are passed in registers.
14504 \begin_inset LatexCommand \ref{sub:Overlaying}
14509 about Overlaying and section
14510 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14515 about Functions using private register banks.
14516 \begin_inset VSpace bigskip
14522 \begin_layout Subsection
14523 MCS51/DS390 Interrupt Service Routines
14526 \begin_layout Standard
14528 \begin_inset LatexCommand \index{interrupt}
14532 numbers and the corresponding address & descriptions for the Standard 8051/8052
14534 SDCC will automatically adjust the
14535 \begin_inset LatexCommand \index{interrupt vector table}
14539 to the maximum interrupt number specified.
14544 \begin_layout Standard
14546 \begin_inset Tabular
14547 <lyxtabular version="3" rows="9" columns="3">
14549 <column alignment="center" valignment="top" leftline="true" width="0in">
14550 <column alignment="left" valignment="top" leftline="true" width="0in">
14551 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14552 <row topline="true" bottomline="true">
14553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14556 \begin_layout Standard
14562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14565 \begin_layout Standard
14571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14574 \begin_layout Standard
14581 <row topline="true">
14582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14585 \begin_layout Standard
14591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14594 \begin_layout Standard
14600 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14603 \begin_layout Standard
14610 <row topline="true">
14611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14614 \begin_layout Standard
14620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14623 \begin_layout Standard
14629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14632 \begin_layout Standard
14639 <row topline="true">
14640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14643 \begin_layout Standard
14649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14652 \begin_layout Standard
14658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14661 \begin_layout Standard
14668 <row topline="true">
14669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14672 \begin_layout Standard
14678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14681 \begin_layout Standard
14687 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14690 \begin_layout Standard
14697 <row topline="true">
14698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14701 \begin_layout Standard
14707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14710 \begin_layout Standard
14716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14719 \begin_layout Standard
14726 <row topline="true">
14727 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14730 \begin_layout Standard
14736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14739 \begin_layout Standard
14745 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14748 \begin_layout Standard
14755 <row topline="true">
14756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14759 \begin_layout Standard
14765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14768 \begin_layout Standard
14774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14777 \begin_layout Standard
14784 <row topline="true" bottomline="true">
14785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14788 \begin_layout Standard
14794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14797 \begin_layout Standard
14803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14806 \begin_layout Standard
14822 \begin_layout Standard
14823 If the interrupt service routine is defined without
14826 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14831 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14837 a register bank or with register bank 0 (
14841 0), the compiler will save the registers used by itself on the stack upon
14842 entry and restore them at exit, however if such an interrupt service routine
14843 calls another function then the entire register bank will be saved on the
14845 This scheme may be advantageous for small interrupt service routines which
14846 have low register usage.
14849 \begin_layout Standard
14850 If the interrupt service routine is defined to be using a specific register
14855 & psw are saved and restored, if such an interrupt service routine calls
14856 another function (using another register bank) then the entire register
14857 bank of the called function will be saved on the stack
14858 \begin_inset LatexCommand \index{stack}
14863 This scheme is recommended for larger interrupt service routines.
14864 \begin_inset VSpace bigskip
14870 \begin_layout Subsection
14872 \begin_inset LatexCommand \index{HC08}
14876 Interrupt Service Routines
14879 \begin_layout Standard
14880 Since the number of interrupts
14881 \begin_inset LatexCommand \index{HC08!interrupt}
14885 available is chip specific and the interrupt vector table always ends at
14886 the last byte of memory, the interrupt numbers corresponds to the interrupt
14887 vectors in reverse order of address.
14888 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14889 2 will use the interrupt vector at 0xfffa, and so on.
14890 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14891 this way; instead see section
14892 \begin_inset LatexCommand \ref{sub:Startup-Code}
14896 for details on customizing startup.
14897 \begin_inset VSpace bigskip
14903 \begin_layout Subsection
14904 Z80 Interrupt Service Routines
14907 \begin_layout Standard
14909 \begin_inset LatexCommand \index{Z80}
14913 uses several different methods for determining the correct interrupt
14914 \begin_inset LatexCommand \index{Z80!interrupt}
14918 vector depending on the hardware implementation.
14919 Therefore, SDCC ignores the optional interrupt number and does not attempt
14920 to generate an interrupt vector table.
14923 \begin_layout Standard
14924 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14925 instruction to return from the interrupt.
14926 To write an interrupt handler for the non-maskable interrupt, which needs
14927 a RETN instruction instead, add the
14934 \begin_layout Verse
14937 void nmi_isr (void) critical interrupt
14951 \begin_layout Standard
14952 However if you need to create a non-interruptable interrupt service routine
14953 you would also require the
14958 To distinguish between this and an nmi_isr you must provide an interrupt
14960 \begin_inset VSpace bigskip
14966 \begin_layout Section
14967 Enabling and Disabling Interrupts
14970 \begin_layout Subsection
14971 Critical Functions and Critical Statements
14974 \begin_layout Standard
14975 A special keyword may be associated with a block or a function declaring
14981 SDCC will generate code to disable all interrupts
14982 \begin_inset LatexCommand \index{interrupt}
14986 upon entry to a critical function and restore the interrupt enable to the
14987 previous state before returning.
14988 Nesting critical functions will need one additional byte on the stack
14989 \begin_inset LatexCommand \index{stack}
14996 \begin_layout Verse
14999 int foo () __critical
15000 \begin_inset LatexCommand \index{critical}
15005 \begin_inset LatexCommand \index{\_\_critical}
15030 \begin_layout Standard
15031 The critical attribute maybe used with other attributes like
15041 may also be used to disable interrupts more locally:
15044 \begin_layout Verse
15050 \begin_layout Standard
15051 More than one statement could have been included in the block.
15054 \begin_layout Subsection
15055 Enabling and Disabling Interrupts directly
15058 \begin_layout Standard
15060 \begin_inset LatexCommand \index{interrupt}
15064 can also be disabled and enabled directly (8051):
15067 \begin_layout Verse
15070 EA = 0;\InsetSpace ~
15096 \begin_layout Verse
15132 \begin_layout Verse
15135 EA = 1;\InsetSpace ~
15164 \begin_layout Verse
15203 \begin_layout Standard
15204 On other architectures which have seperate opcodes for enabling and disabling
15205 interrupts you might want to make use of defines with inline assembly
15206 \begin_inset LatexCommand \index{Assembler routines}
15211 \begin_inset LatexCommand \index{HC08!interrupt}
15218 \begin_layout Verse
15222 \begin_inset LatexCommand \index{\_asm}
15231 \begin_inset LatexCommand \index{\_endasm}
15238 \begin_layout Verse
15241 #define SEI _asm\InsetSpace ~
15248 \begin_layout Verse
15254 \begin_layout Standard
15255 Note: it is sometimes sufficient to disable only a specific interrupt source
15257 a timer or serial interrupt by manipulating an
15260 \begin_inset LatexCommand \index{interrupt mask}
15270 \begin_layout Standard
15271 Usually the time during which interrupts are disabled should be kept as
15273 This minimizes both
15278 \begin_inset LatexCommand \index{interrupt latency}
15282 (the time between the occurrence of the interrupt and the execution of
15283 the first code in the interrupt routine) and
15288 \begin_inset LatexCommand \index{interrupt jitter}
15292 (the difference between the shortest and the longest interrupt latency).
15293 These really are something different, f.e.
15294 a serial interrupt has to be served before its buffer overruns so it cares
15295 for the maximum interrupt latency, whereas it does not care about jitter.
15296 On a loudspeaker driven via a digital to analog converter which is fed
15297 by an interrupt a latency of a few milliseconds might be tolerable, whereas
15298 a much smaller jitter will be very audible.
15301 \begin_layout Standard
15302 You can reenable interrupts within an interrupt routine and on some architecture
15303 s you can make use of two (or more) levels of
15305 interrupt priorities
15308 \begin_inset LatexCommand \index{interrupt priority}
15313 On some architectures which don't support interrupt priorities these can
15314 be implemented by manipulating the interrupt mask and reenabling interrupts
15315 within the interrupt routine.
15316 Check there is sufficient space on the stack
15317 \begin_inset LatexCommand \index{stack}
15321 and don't add complexity unless you have to.
15325 \begin_layout Subsection
15327 \begin_inset LatexCommand \index{semaphore}
15331 locking (mcs51/ds390)
15334 \begin_layout Standard
15335 Some architectures (mcs51/ds390) have an atomic
15336 \begin_inset LatexCommand \index{atomic}
15349 These type of instructions are typically used in preemptive multitasking
15350 systems, where a routine f.e.
15351 claims the use of a data structure ('acquires a lock
15352 \begin_inset LatexCommand \index{lock}
15356 on it'), makes some modifications and then releases the lock when the data
15357 structure is consistent again.
15358 The instruction may also be used if interrupt and non-interrupt code have
15359 to compete for a resource.
15360 With the atomic bit test and clear instruction interrupts
15361 \begin_inset LatexCommand \index{interrupt}
15365 don't have to be disabled for the locking operation.
15369 \begin_layout Standard
15370 SDCC generates this instruction if the source follows this pattern:
15373 \begin_layout Verse
15377 \begin_inset LatexCommand \index{volatile}
15381 bit resource_is_free;
15385 if (resource_is_free)
15395 resource_is_free=0;
15408 resource_is_free=1;
15415 \begin_layout Standard
15416 Note, mcs51 and ds390 support only an atomic
15417 \begin_inset LatexCommand \index{atomic}
15425 instruction (as opposed to atomic bit test and
15430 \begin_layout Section
15431 Functions using private register banks
15432 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
15439 \begin_layout Standard
15440 Some architectures have support for quickly changing register sets.
15441 SDCC supports this feature with the
15444 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
15449 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
15455 attribute (which tells the compiler to use a register bank
15456 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
15460 other than the default bank zero).
15461 It should only be applied to
15464 \begin_inset LatexCommand \index{interrupt}
15470 functions (see footnote below).
15471 This will in most circumstances make the generated ISR code more efficient
15472 since it will not have to save registers on the stack.
15475 \begin_layout Standard
15480 attribute will have no effect on the generated code for a
15484 function (but may occasionally be useful anyway
15488 \begin_layout Standard
15489 possible exception: if a function is called ONLY from 'interrupt' functions
15490 using a particular bank, it can be declared with the same 'using' attribute
15491 as the calling 'interrupt' functions.
15492 For instance, if you have several ISRs using bank one, and all of them
15493 call memcpy(), it might make sense to create a specialized version of memcpy()
15494 'using 1', since this would prevent the ISR from having to save bank zero
15495 to the stack on entry and switch to bank zero before calling the function
15504 (pending: Note, nowadays the
15508 attribute has an effect on
15512 the generated code for a
15523 \begin_layout Standard
15528 function using a non-zero bank will assume that it can trash that register
15529 bank, and will not save it.
15530 Since high-priority interrupts
15531 \begin_inset LatexCommand \index{interrupts}
15536 \begin_inset LatexCommand \index{interrupt priority}
15540 can interrupt low-priority ones on the 8051 and friends, this means that
15541 if a high-priority ISR
15545 a particular bank occurs while processing a low-priority ISR
15549 the same bank, terrible and bad things can happen.
15550 To prevent this, no single register bank should be
15554 by both a high priority and a low priority ISR.
15555 This is probably most easily done by having all high priority ISRs use
15556 one bank and all low priority ISRs use another.
15557 If you have an ISR which can change priority at runtime, you're on your
15558 own: I suggest using the default bank zero and taking the small performance
15562 \begin_layout Standard
15563 It is most efficient if your ISR calls no other functions.
15564 If your ISR must call other functions, it is most efficient if those functions
15565 use the same bank as the ISR (see note 1 below); the next best is if the
15566 called functions use bank zero.
15567 It is very inefficient to call a function using a different, non-zero bank
15570 \begin_inset VSpace bigskip
15576 \begin_layout Section
15578 \begin_inset LatexCommand \label{sub:Startup-Code}
15583 \begin_inset LatexCommand \index{Startup code}
15590 \begin_layout Subsection
15591 MCS51/DS390 Startup Code
15594 \begin_layout Standard
15595 The compiler triggers the linker to link certain initialization modules
15596 from the runtime library
15597 \begin_inset LatexCommand \index{Runtime library}
15601 called crt<something>.
15602 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15603 GSINIT5) is not linked unless the -
15609 \begin_layout Standard
15620 -xstack option is used.
15621 These modules are highly entangled by the use of special segments/areas,
15622 but a common layout is shown below:
15625 \begin_layout Verse
15633 \begin_layout Verse
15657 ljmp __sdcc_gsinit_startup
15660 \begin_layout Verse
15668 \begin_layout Verse
15680 .area GSINIT0 (CODE)
15682 __sdcc_gsinit_startup::
15692 mov sp,#__start__stack - 1
15695 \begin_layout Verse
15703 \begin_layout Verse
15715 .area GSINIT1 (CODE)
15717 __sdcc_init_xstack::
15719 ; Need to initialize in GSINIT1 in
15720 case the user's __sdcc_external_startup uses the xstack.
15730 mov __XPAGE,#(__start__x
15741 mov _spx,#__start__xstack
15744 \begin_layout Verse
15752 \begin_layout Verse
15764 .area GSINIT2 (CODE)
15774 lcall __sdcc_external_startup
15794 jz __sdcc_init_data
15805 __sdcc_program_startup
15810 \begin_layout Verse
15818 \begin_layout Verse
15830 .area GSINIT3 (CODE)
15883 mov r2,#((l_XINIT+255) >> 8)
15914 __XPAGE,#(s_XISEG >> 8)
15916 00001$:\InsetSpace ~
15980 00002$:\InsetSpace ~
16007 \begin_layout Verse
16015 \begin_layout Verse
16027 .area GSINIT4 (CODE)
16029 __mcs51_genRAMCLEAR::
16051 00004$:\InsetSpace ~
16065 ; _mcs51_genRAMCLEAR() end
16068 \begin_layout Verse
16076 \begin_layout Verse
16088 .area GSINIT4 (CODE)
16090 __mcs51_genXRAMCLEAR::
16151 mov __XPAGE,#(s_PSEG >> 8)
16163 00005$:\InsetSpace ~
16238 mov r1,#((l_XSEG + 255) >> 8)
16260 00007$:\InsetSpace ~
16297 \begin_layout Verse
16305 \begin_layout Verse
16317 .area GSINIT5 (CODE)
16319 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
16322 ; and __mcs51_genRAMCLEAR modifies _spx.
16332 mov __XPAGE,#(__start__x
16343 mov _spx,#__start__xstack
16346 \begin_layout Verse
16351 (application modules)
16354 \begin_layout Verse
16366 .area GSINIT (CODE)
16369 \begin_layout Verse
16377 \begin_layout Verse
16389 .area GSFINAL (CODE)
16399 ljmp __sdcc_program_startup
16401 ;---------------------------------
16402 -----------------------
16406 ;--------------------------------------------------
16429 __sdcc_program_startup:
16442 return from main will lock up
16455 \begin_layout Standard
16456 One of these modules (crtstart.asm) contains a call to the C routine
16458 _sdcc_external_startup()
16459 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
16468 at the start of the CODE area.
16469 This routine is also in the runtime library
16470 \begin_inset LatexCommand \index{Runtime library}
16474 and returns 0 by default.
16475 If this routine returns a non-zero value, the static & global variable
16476 initialization will be skipped and the function main will be invoked.
16477 Otherwise static & global variables will be initialized before the function
16481 _sdcc_external_startup()
16483 routine to your program to override the default if you need to setup hardware
16484 or perform some other critical operation prior to static & global variable
16486 \begin_inset LatexCommand \index{Variable initialization}
16491 On some mcs51 variants xdata
16492 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
16496 memory has to be explicitly enabled before it can be accessed or if the
16498 \begin_inset LatexCommand \index{watchdog}
16502 needs to be disabled, this is the place to do it.
16503 The startup code clears all internal data memory, 256 bytes by default,
16504 but from 0 to n-1 if
16510 \begin_layout Standard
16520 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16527 (recommended for Chipcon CC1010).
16530 \begin_layout Standard
16531 See also the compiler options
16537 \begin_layout Standard
16553 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16563 \begin_layout Standard
16575 \begin_inset LatexCommand \index{-\/-main-return}
16580 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16584 about MCS51-variants.
16589 \begin_layout Standard
16590 While these initialization modules are meant as generic startup code there
16591 might be the need for customization.
16592 Let's assume the return value of
16594 _sdcc_external_startup()
16600 should not be checked (or
16602 _sdcc_external_startup()
16604 should not be called at all).
16605 The recommended way would be to copy
16611 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm}
16615 ) into the source directory, adapt it there, then assemble it with
16621 \begin_layout Standard
16622 \begin_inset Quotes sld
16626 \begin_inset Quotes srd
16629 are the assembler options used in
16630 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup }
16641 and when linking your project explicitely specify
16646 As a bonus a listing of the relocated object file
16653 \begin_layout Standard
16654 \begin_inset VSpace bigskip
16660 \begin_layout Subsection
16664 \begin_layout Standard
16666 \begin_inset LatexCommand \index{HC08}
16670 startup code follows the same scheme as the MCS51 startup code.
16671 \begin_inset VSpace bigskip
16677 \begin_layout Subsection
16681 \begin_layout Standard
16683 \begin_inset LatexCommand \index{Z80}
16687 the startup code is inserted by linking with crt0.o which is generated from
16688 sdcc/device/lib/z80/crt0.s.
16689 If you need a different startup code you can use the compiler option
16698 \begin_layout Standard
16713 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16717 and provide your own crt0.o.
16719 \begin_inset VSpace bigskip
16725 \begin_layout Section
16726 Inline Assembler Code
16727 \begin_inset LatexCommand \index{Assembler routines}
16734 \begin_layout Subsection
16735 A Step by Step Introduction
16736 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16743 \begin_layout Standard
16744 Starting from a small snippet of c-code this example shows for the MCS51
16745 how to use inline assembly, access variables, a function parameter and
16746 an array in xdata memory.
16747 The example uses an MCS51 here but is easily adapted for other architectures.
16748 This is a buffer routine which should be optimized:
16751 \begin_layout Verse
16755 unsigned char __far
16756 \begin_inset LatexCommand \index{far (storage class)}
16761 \begin_inset LatexCommand \index{\_\_far (storage class)}
16766 \begin_inset LatexCommand \index{at}
16771 \begin_inset LatexCommand \index{\_\_at}
16775 (0x7f00) buf[0x100];
16776 \begin_inset LatexCommand \index{Aligned array}
16782 unsigned char head, tail;\InsetSpace ~
16800 \begin_inset LatexCommand \index{interrupt}
16852 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16864 void to_buffer( unsigned char c )
16872 if( head != (unsigned char)(tail-1)
16879 \begin_inset LatexCommand \index{promotion to signed int}
16884 \begin_inset LatexCommand \index{type promotion}
16889 \begin_inset Marginal
16892 \begin_layout Standard
16911 buf[ head++ ] = c;\InsetSpace ~
16927 /* access to a 256 byte aligned array */
16932 \begin_layout Standard
16933 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16934 then a corresponding buffer.asm file is generated.
16935 We define a new function
16939 in file buffer.c in which we cut and paste the generated code, removing
16940 unwanted comments and some ':'.
16942 \begin_inset Quotes sld
16950 \begin_inset Quotes srd
16954 \begin_inset Quotes sld
16962 \begin_inset Quotes srd
16969 \begin_layout Standard
16970 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16971 and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16973 The latter is also used in the library functions.
16978 to the beginning and the end of the function body:
16981 \begin_layout Verse
16985 /* With a cut and paste from the .asm file, we have something to start with.
16991 function is not yet OK! (registers aren't saved) */
16993 void to_buffer_asm(
17003 \begin_inset LatexCommand \index{\_asm}
17008 \begin_inset LatexCommand \index{\_\_asm}
17022 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
17028 \begin_inset LatexCommand \index{promotion to signed int}
17033 \begin_inset LatexCommand \index{type promotion}
17086 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
17087 \begin_inset LatexCommand \index{Aligned array}
17153 \begin_inset LatexCommand \index{\_endasm}
17158 \begin_inset LatexCommand \index{\_\_endasm}
17167 \begin_layout Standard
17168 The new file buffer.c should compile with only one warning about the unreferenced
17169 function argument 'c'.
17170 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
17171 (1) and finally have:
17174 \begin_layout Verse
17178 unsigned char __far __at(0x7f00) buf[0x100];
17180 unsigned char head, tail;
17191 void to_buffer( unsigned char c )
17200 head != (unsigned char)(tail-1) )
17229 c; // to avoid warning: unreferenced function argument
17236 \begin_inset LatexCommand \index{\_asm}
17241 \begin_inset LatexCommand \index{\_\_asm}
17255 ; save used registers here.
17266 ; If we were still using r2,r3 we would have to push them here.
17269 ; if( head != (unsigned char)(tail-1) )
17313 could do an ANL a,#0x0f here to use a smaller buffer (see below)
17349 a,dpl \InsetSpace ~
17356 ; dpl holds lower byte of function argument
17368 dpl,_head \InsetSpace ~
17371 ; buf is 0x100 byte aligned so head can be used directly
17414 ; we could do an ANL _head,#0x0f here to use a
17415 smaller buffer (see above)
17427 ; restore used registers here
17434 \begin_inset LatexCommand \index{\_endasm}
17439 \begin_inset LatexCommand \index{\_\_endasm}
17450 \begin_layout Standard
17451 The inline assembler code can contain any valid code understood by the assembler
17452 , this includes any assembler directives and comment lines.
17453 The assembler does not like some characters like ':' or ''' in comments.
17454 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
17455 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
17460 \begin_inset LatexCommand \index{Assembler documentation}
17465 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
17473 \begin_layout Standard
17474 The compiler does not do any validation of the code within the
17477 \begin_inset LatexCommand \index{\_asm}
17482 \begin_inset LatexCommand \index{\_\_asm}
17490 \begin_inset LatexCommand \index{\_endasm}
17495 \begin_inset LatexCommand \index{\_\_endasm}
17504 Specifically it will not know which registers are used and thus register
17506 \begin_inset LatexCommand \index{push/pop}
17510 has to be done manually.
17514 \begin_layout Standard
17515 It is recommended that each assembly instruction (including labels) be placed
17516 in a separate line (as the example shows).
17521 \begin_layout Standard
17533 \begin_inset LatexCommand \index{-\/-peep-asm}
17539 command line option is used, the inline assembler code will be passed through
17540 the peephole optimizer
17541 \begin_inset LatexCommand \index{Peephole optimizer}
17546 There are only a few (if any) cases where this option makes sense, it might
17547 cause some unexpected changes in the inline assembler code.
17548 Please go through the peephole optimizer rules defined in file
17552 before using this option.
17555 \begin_layout Subsection
17557 \begin_inset LatexCommand \label{sub:Naked-Functions}
17562 \begin_inset LatexCommand \index{Naked functions}
17569 \begin_layout Standard
17570 A special keyword may be associated with a function declaring it as
17573 \begin_inset LatexCommand \index{\_naked}
17578 \begin_inset LatexCommand \index{\_\_naked}
17589 function modifier attribute prevents the compiler from generating prologue
17590 \begin_inset LatexCommand \index{function prologue}
17595 \begin_inset LatexCommand \index{function epilogue}
17599 code for that function.
17600 This means that the user is entirely responsible for such things as saving
17601 any registers that may need to be preserved, selecting the proper register
17602 bank, generating the
17606 instruction at the end, etc.
17607 Practically, this means that the contents of the function must be written
17608 in inline assembler.
17609 This is particularly useful for interrupt functions, which can have a large
17610 (and often unnecessary) prologue/epilogue.
17611 For example, compare the code generated by these two functions:
17614 \begin_layout Verse
17618 \begin_inset LatexCommand \index{volatile}
17622 data unsigned char counter;
17626 void simpleInterrupt(void) __interrupt
17627 \begin_inset LatexCommand \index{interrupt}
17632 \begin_inset LatexCommand \index{\_\_interrupt}
17650 void nakedInterrupt(void) __interrupt (2) __naked
17659 \begin_inset LatexCommand \index{\_asm}
17664 \begin_inset LatexCommand \index{\_\_asm}
17681 _counter ; does not change flags, no need to save psw
17694 include ret or reti in _naked function.
17701 \begin_inset LatexCommand \index{\_endasm}
17706 \begin_inset LatexCommand \index{\_\_endasm}
17715 \begin_layout Standard
17716 For an 8051 target, the generated simpleInterrupt looks like:
17719 \begin_layout Verse
17726 example, recent versions of SDCC generate
17732 code for simpleInterrupt() and nakedInterrupt()!
17873 \begin_layout Standard
17874 whereas nakedInterrupt looks like:
17877 \begin_layout Verse
17890 _counter ; does not change flags, no need to save psw
17909 MUST explicitly include ret or reti in _naked function
17912 \begin_layout Standard
17913 The related directive #pragma exclude
17914 \begin_inset LatexCommand \index{\#pragma exclude}
17918 allows a more fine grained control over pushing & popping
17919 \begin_inset LatexCommand \index{push/pop}
17926 \begin_layout Standard
17927 While there is nothing preventing you from writing C code inside a
17931 function, there are many ways to shoot yourself in the foot doing this,
17932 and it is recommended that you stick to inline assembler.
17935 \begin_layout Subsection
17936 Use of Labels within Inline Assembler
17939 \begin_layout Standard
17940 SDCC allows the use of in-line assembler with a few restrictions regarding
17942 All labels defined within inline assembler code have to be of the form
17947 where nnnnn is a number less than 100 (which implies a limit of utmost
17948 100 inline assembler labels
17959 \begin_layout Standard
17960 This is a slightly more stringent rule than absolutely necessary, but stays
17961 always on the safe side.
17962 Labels in the form of nnnnn$ are local labels in the assembler, locality
17963 of which is confined within two labels of the standard form.
17964 The compiler uses the same form for labels within a function (but starting
17965 from nnnnn=00100); and places always a standard label at the beginning
17966 of a function, thus limiting the locality of labels within the scope of
17968 So, if the inline assembler part would be embedded into C-code, an improperly
17969 placed non-local label in the assembler would break up the reference space
17970 for labels created by the compiler for the C-code, leading to an assembling
17974 \begin_layout Standard
17975 The numeric part of local labels does not need to have 5 digits (although
17976 this is the form of labels output by the compiler), any valid integer will
17978 Please refer to the assemblers documentation for further details.
17986 \begin_layout Verse
17990 \begin_inset LatexCommand \index{\_asm}
17995 \begin_inset LatexCommand \index{\_\_asm}
18025 \begin_inset LatexCommand \index{\_endasm}
18030 \begin_inset LatexCommand \index{\_\_endasm}
18037 \begin_layout Standard
18038 Inline assembler code cannot reference any C-labels, however it can reference
18040 \begin_inset LatexCommand \index{Labels}
18044 defined by the inline assembler, e.g.:
18047 \begin_layout Verse
18070 ; some assembler code
18091 /* some more c code */
18093 clabel:\InsetSpace ~
18095 /* inline assembler cannot reference this
18100 \begin_layout Standard
18105 is translated by the compiler into a local label, so the locality of labels
18106 within the function is not broken.
18123 0003$: ;label (can be referenced by inline assembler only)
18130 \begin_inset LatexCommand \index{\_endasm}
18135 \begin_inset LatexCommand \index{\_\_endasm}
18145 /* some more c code */
18150 \begin_layout Standard
18151 In other words inline assembly code can access labels defined in inline
18152 assembly within the scope of the function.
18153 The same goes the other way, i.e.
18154 labels defines in inline assembly can not be accessed by C statements.
18157 \begin_layout Section
18158 Interfacing with Assembler Code
18159 \begin_inset LatexCommand \index{Assembler routines}
18166 \begin_layout Subsection
18167 Global Registers used for Parameter Passing
18168 \begin_inset LatexCommand \index{Parameter passing}
18175 \begin_layout Standard
18176 The compiler always uses the global registers
18179 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18184 \begin_inset LatexCommand \index{DPTR}
18189 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
18198 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
18204 to pass the first (non-bit) parameter to a function, and also to pass the
18206 \begin_inset LatexCommand \index{return value}
18210 of function; according to the following scheme: one byte return value in
18215 , two byte value in
18224 three byte values (generic pointers) in
18236 , and four byte values in
18254 \begin_inset LatexCommand \index{generic pointer}
18258 contain type of accessed memory in
18279 \begin_inset Note Note
18282 \begin_layout Standard
18283 This might not be the case of certain memory models (medium???)
18291 \begin_layout Standard
18292 The second parameter onwards is either allocated on the stack (for reentrant
18297 \begin_layout Standard
18306 -stack-auto is used) or in data/xdata memory (depending on the memory model).
18309 \begin_layout Standard
18310 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
18311 space for reentrant functions or allocated directly in bit memory otherwise.
18314 \begin_layout Standard
18315 Functions (with two or more parameters or bit parameters) that are called
18316 through function pointers
18317 \begin_inset LatexCommand \index{function pointers}
18321 must therefor be reentrant so the compiler knows how to pass the parameters.
18324 \begin_layout Subsection
18328 \begin_layout Standard
18329 Unless the called function is declared as
18334 \begin_inset LatexCommand \index{naked}
18342 \begin_layout Standard
18352 \begin_inset LatexCommand \index{-\/-callee-saves}
18360 \begin_layout Standard
18369 -all-callee-saves command line option or the corresponding callee_saves
18370 pragma are used, the caller will save the registers (
18374 ) around the call, so the called function can destroy they content freely.
18377 \begin_layout Standard
18378 If the called function is not declared as
18382 , the caller will swap register banks around the call, if caller and callee
18383 use different register banks (having them defined by the
18391 \begin_layout Standard
18392 The called function can also use
18408 observing that they are used for parameter/return value passing.
18411 \begin_layout Subsection
18412 Assembler Routine (non-reentrant)
18415 \begin_layout Standard
18416 In the following example
18417 \begin_inset LatexCommand \index{reentrant}
18422 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
18426 the function c_func calls an assembler routine asm_func, which takes two
18428 \begin_inset LatexCommand \index{function parameter}
18435 \begin_layout Verse
18438 extern int asm_func(unsigned char, unsigned char);
18442 int c_func (unsigned char
18443 i, unsigned char j)
18451 return asm_func(i,j);
18465 return c_func(10,9);
18470 \begin_layout Standard
18471 The corresponding assembler function is:
18474 \begin_layout Verse
18477 .globl _asm_func_PARM_2
18579 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18596 \begin_layout Standard
18597 The parameter naming convention is _<function_name>_PARM_<n>, where n is
18598 the parameter number starting from 1, and counting from the left.
18599 The first parameter is passed in
18615 according to the description above.
18616 The variable name for the second parameter will be _<function_name>_PARM_2.
18621 ble the assembler routine with the following command:
18628 asx8051 -losg asmfunc.asm
18635 Then compile and link the assembler routine to the C source file with the
18643 sdcc cfunc.c asmfunc.rel
18646 \begin_layout Subsection
18647 Assembler Routine (reentrant)
18650 \begin_layout Standard
18652 \begin_inset LatexCommand \index{reentrant}
18657 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18661 the second parameter
18662 \begin_inset LatexCommand \index{function parameter}
18666 onwards will be passed on the stack, the parameters are pushed from right
18668 before the call the second leftmost parameter will be on the top of the
18669 stack (the leftmost parameter is passed in registers).
18670 Here is an example:
18673 \begin_layout Verse
18676 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18681 c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
18690 return asm_func(i,j,k);
18704 return c_func(10,9,8);
18709 \begin_layout Standard
18710 The corresponding (unoptimized) assembler routine is:
18713 \begin_layout Verse
18733 _bp,sp\InsetSpace ~
18739 ;stack contains: _bp, return
18740 address, second parameter, third parameter
18764 a,#0xfd\InsetSpace ~
18770 pointer to the second parameter
18794 a,#0xfc\InsetSpace ~
18800 to the rightmost parameter
18841 result (= sum of all three parameters)
18856 ;return value goes into dptr
18890 \begin_layout Standard
18891 The compiling and linking procedure remains the same, however note the extra
18892 entry & exit linkage required for the assembler code, _bp is the stack
18893 frame pointer and is used to compute the offset into the stack for parameters
18894 and local variables.
18895 \begin_inset VSpace bigskip
18901 \begin_layout Section
18903 \begin_inset LatexCommand \index{int (16 bit)}
18908 \begin_inset LatexCommand \index{long (32 bit)}
18915 \begin_layout Standard
18916 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18917 multiplication and modulus operations are implemented by support routines.
18918 These support routines are all developed in ANSI-C to facilitate porting
18919 to other MCUs, although some model specific assembler optimizations are
18921 The following files contain the described routines, all of them can be
18922 found in <installdir>/share/sdcc/lib.
18927 \begin_layout Standard
18929 \begin_inset Tabular
18930 <lyxtabular version="3" rows="11" columns="2">
18932 <column alignment="left" valignment="top" leftline="true" width="0">
18933 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18934 <row topline="true" bottomline="true">
18935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18938 \begin_layout Standard
18946 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18949 \begin_layout Standard
18958 <row topline="true">
18959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18962 \begin_layout Standard
18968 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18971 \begin_layout Standard
18972 16 bit multiplication
18978 <row topline="true">
18979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18982 \begin_layout Standard
18988 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18991 \begin_layout Standard
18992 signed 16 bit division (calls _divuint)
18998 <row topline="true">
18999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19002 \begin_layout Standard
19008 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19011 \begin_layout Standard
19012 unsigned 16 bit division
19018 <row topline="true">
19019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19022 \begin_layout Standard
19028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19031 \begin_layout Standard
19032 signed 16 bit modulus (calls _moduint)
19038 <row topline="true">
19039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19042 \begin_layout Standard
19048 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19051 \begin_layout Standard
19052 unsigned 16 bit modulus
19058 <row topline="true">
19059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19062 \begin_layout Standard
19068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19071 \begin_layout Standard
19072 32 bit multiplication
19078 <row topline="true">
19079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19082 \begin_layout Standard
19088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19091 \begin_layout Standard
19092 signed 32 division (calls _divulong)
19098 <row topline="true">
19099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19102 \begin_layout Standard
19108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19111 \begin_layout Standard
19112 unsigned 32 division
19118 <row topline="true">
19119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19122 \begin_layout Standard
19128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19131 \begin_layout Standard
19132 signed 32 bit modulus (calls _modulong)
19138 <row topline="true" bottomline="true">
19139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19142 \begin_layout Standard
19148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19151 \begin_layout Standard
19152 unsigned 32 bit modulus
19167 \begin_layout Standard
19168 Since they are compiled as
19173 \begin_inset LatexCommand \index{reentrant}
19178 \begin_inset LatexCommand \index{interrupt}
19182 service routines should not do any of the above operations.
19183 If this is unavoidable then the above routines will need to be compiled
19190 \begin_layout Standard
19200 \begin_inset LatexCommand \index{-\/-stack-auto}
19206 option, after which the source program will have to be compiled with
19212 \begin_layout Standard
19222 \begin_inset LatexCommand \index{-\/-int-long-reent}
19229 Notice that you don't have to call these routines directly.
19230 The compiler will use them automatically every time an integer operation
19234 \begin_layout Section
19235 Floating Point Support
19236 \begin_inset LatexCommand \index{Floating point support}
19243 \begin_layout Standard
19244 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
19245 The floating point support routines are derived from gcc's floatlib.c and
19246 consist of the following routines:
19251 \begin_layout Standard
19255 \begin_inset Tabular
19256 <lyxtabular version="3" rows="17" columns="2">
19258 <column alignment="left" valignment="top" leftline="true" width="0">
19259 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19260 <row topline="true" bottomline="true">
19261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19264 \begin_layout Standard
19279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19282 \begin_layout Standard
19289 <row topline="true">
19290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19293 \begin_layout Standard
19308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19311 \begin_layout Standard
19321 add floating point numbers
19327 <row topline="true">
19328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19331 \begin_layout Standard
19346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19349 \begin_layout Standard
19359 subtract floating point numbers
19365 <row topline="true">
19366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19369 \begin_layout Standard
19384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19387 \begin_layout Standard
19397 divide floating point numbers
19403 <row topline="true">
19404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19407 \begin_layout Standard
19422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19425 \begin_layout Standard
19435 multiply floating point numbers
19441 <row topline="true">
19442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19445 \begin_layout Standard
19460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19463 \begin_layout Standard
19473 convert floating point to unsigned char
19479 <row topline="true">
19480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19483 \begin_layout Standard
19498 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19501 \begin_layout Standard
19511 convert floating point to signed char
19517 <row topline="true">
19518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19521 \begin_layout Standard
19536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19539 \begin_layout Standard
19549 convert floating point to unsigned int
19555 <row topline="true">
19556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19559 \begin_layout Standard
19574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19577 \begin_layout Standard
19587 convert floating point to signed int
19593 <row topline="true">
19594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19597 \begin_layout Standard
19620 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19623 \begin_layout Standard
19633 convert floating point to unsigned long
19639 <row topline="true">
19640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19643 \begin_layout Standard
19658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19661 \begin_layout Standard
19671 convert floating point to signed long
19677 <row topline="true">
19678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19681 \begin_layout Standard
19696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19699 \begin_layout Standard
19709 convert unsigned char to floating point
19715 <row topline="true">
19716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19719 \begin_layout Standard
19734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19737 \begin_layout Standard
19747 convert char to floating point number
19753 <row topline="true">
19754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19757 \begin_layout Standard
19772 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19775 \begin_layout Standard
19785 convert unsigned int to floating point
19791 <row topline="true">
19792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19795 \begin_layout Standard
19810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19813 \begin_layout Standard
19823 convert int to floating point numbers
19829 <row topline="true">
19830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19833 \begin_layout Standard
19848 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19851 \begin_layout Standard
19861 convert unsigned long to floating point number
19867 <row topline="true" bottomline="true">
19868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19871 \begin_layout Standard
19886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19889 \begin_layout Standard
19899 convert long to floating point number
19914 \begin_layout Standard
19915 These support routines are developed in ANSI-C so there is room for space
19916 and speed improvement
19920 \begin_layout Standard
19921 These floating point routines (
19925 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19932 Note if all these routines are used simultaneously the data space might
19934 For serious floating point usage the large model might be needed.
19935 Also notice that you don't have to call this routines directly.
19936 The compiler will use them automatically every time a floating point operation
19938 \begin_inset VSpace bigskip
19944 \begin_layout Section
19946 \begin_inset LatexCommand \index{Libraries}
19953 \begin_layout Standard
19956 <pending: this is messy and incomplete - a little more information is in
19957 sdcc/doc/libdoc.txt
19962 \begin_layout Subsection
19963 Compiler support routines (_gptrget, _mulint etc.)
19966 \begin_layout Subsection
19967 Stdclib functions (puts, printf, strcat etc.)
19970 \begin_layout Subsubsection
19974 \begin_layout Paragraph
19975 getchar(), putchar()
19978 \begin_layout Standard
19979 \begin_inset LatexCommand \index{<stdio.h>}
19983 As usual on embedded systems you have to provide your own
19986 \begin_inset LatexCommand \index{getchar()}
19995 \begin_inset LatexCommand \index{putchar()}
20002 SDCC does not know whether the system connects to a serial line with or
20003 without handshake, LCD, keyboard or other device.
20017 You'll find examples for serial routines f.e.
20018 in sdcc/device/lib.
20019 For the mcs51 this minimalistic polling
20023 routine might be a start:
20026 \begin_layout Verse
20029 void putchar (char c) {
20035 while (!TI)\InsetSpace ~
20038 /* assumes UART is initialized */
20066 \begin_layout Paragraph
20070 \begin_layout Standard
20074 \begin_inset LatexCommand \index{printf()}
20084 does not support float (except on ds390).
20085 To enable this recompile it with the option
20091 \begin_layout Standard
20101 \begin_inset LatexCommand \index{USE\_FLOATS}
20107 on the command line.
20114 \begin_layout Standard
20124 \begin_inset LatexCommand \index{-\/-model-large}
20130 for the mcs51 port, since this uses a lot of memory.
20133 \begin_layout Standard
20134 If you're short on code memory you might want to use
20137 \begin_inset LatexCommand \index{printf\_small()}
20152 For the mcs51 there additionally are assembly versions
20155 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
20161 (subset of printf using less than 270 bytes) and
20164 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
20173 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
20179 (floating-point aware version of printf_fast) which should fit the requirements
20180 of many embedded systems (printf_fast() can be customized by unsetting
20185 support long variables and field widths).
20186 Be sure to use only one of these printf options within a project.
20191 \begin_layout Standard
20192 Feature matrix of different
20199 \begin_layout Standard
20200 \begin_inset Tabular
20201 <lyxtabular version="3" rows="14" columns="7">
20202 <features islongtable="true">
20203 <column alignment="left" valignment="middle" leftline="true" width="14col%">
20204 <column alignment="center" valignment="top" leftline="true" width="0">
20205 <column alignment="center" valignment="top" leftline="true" width="12col%">
20206 <column alignment="center" valignment="top" leftline="true" width="10col%">
20207 <column alignment="center" valignment="top" leftline="true" width="0">
20208 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
20209 <column alignment="center" valignment="top" rightline="true" width="0">
20210 <row topline="true" bottomline="true" endhead="true">
20211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20214 \begin_layout Standard
20223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20226 \begin_layout Standard
20228 \begin_inset LatexCommand \index{printf}
20237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20240 \begin_layout Standard
20248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20251 \begin_layout Standard
20257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20260 \begin_layout Standard
20266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20269 \begin_layout Standard
20275 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20278 \begin_layout Standard
20285 <row topline="true" endhead="true">
20286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20289 \begin_layout Standard
20295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20298 \begin_layout Standard
20306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20309 \begin_layout Standard
20317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20320 \begin_layout Standard
20328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20331 \begin_layout Standard
20339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20342 \begin_layout Standard
20350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20353 \begin_layout Standard
20362 <row topline="true" endhead="true">
20363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20366 \begin_layout Standard
20367 \begin_inset Quotes sld
20371 \begin_inset Quotes srd
20377 \begin_layout Standard
20383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20386 \begin_layout Standard
20392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20395 \begin_layout Standard
20401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20404 \begin_layout Standard
20410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20413 \begin_layout Standard
20419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20422 \begin_layout Standard
20428 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20431 \begin_layout Standard
20438 <row topline="true" endhead="true">
20439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20442 \begin_layout Standard
20446 \begin_layout Standard
20452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20455 \begin_layout Standard
20461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20464 \begin_layout Standard
20470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20473 \begin_layout Standard
20474 0.45k / 0.47k (+ _ltoa)
20479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20482 \begin_layout Standard
20488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20491 \begin_layout Standard
20497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20500 \begin_layout Standard
20507 <row topline="true">
20508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20511 \begin_layout Standard
20517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20520 \begin_layout Standard
20530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20533 \begin_layout Standard
20580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20583 \begin_layout Standard
20622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20625 \begin_layout Standard
20631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20634 \begin_layout Standard
20640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20643 \begin_layout Standard
20650 <row topline="true">
20651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20654 \begin_layout Standard
20655 long (32 bit) support
20660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20663 \begin_layout Standard
20669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20672 \begin_layout Standard
20678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20681 \begin_layout Standard
20687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20690 \begin_layout Standard
20696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20699 \begin_layout Standard
20714 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20717 \begin_layout Standard
20724 <row topline="true">
20725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20728 \begin_layout Standard
20729 byte arguments on stack
20734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20737 \begin_layout Standard
20743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20746 \begin_layout Standard
20752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20755 \begin_layout Standard
20761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20764 \begin_layout Standard
20770 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20773 \begin_layout Standard
20779 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20782 \begin_layout Standard
20789 <row topline="true">
20790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20793 \begin_layout Standard
20795 \begin_inset LatexCommand \index{Floating point support}
20804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20807 \begin_layout Standard
20813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20816 \begin_layout Standard
20822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20825 \begin_layout Standard
20831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20834 \begin_layout Standard
20840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20843 \begin_layout Standard
20848 \begin_layout Standard
20849 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20862 \begin_layout Standard
20869 <row topline="true">
20870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20873 \begin_layout Standard
20874 float formats %e %g
20879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20882 \begin_layout Standard
20888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20891 \begin_layout Standard
20897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20900 \begin_layout Standard
20906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20909 \begin_layout Standard
20915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20918 \begin_layout Standard
20924 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20927 \begin_layout Standard
20934 <row topline="true" bottomline="true">
20935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20938 \begin_layout Standard
20944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20947 \begin_layout Standard
20953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20956 \begin_layout Standard
20962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20965 \begin_layout Standard
20971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20974 \begin_layout Standard
20980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20983 \begin_layout Standard
20989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20992 \begin_layout Standard
20999 <row bottomline="true">
21000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21003 \begin_layout Standard
21008 \begin_layout Standard
21009 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
21013 n'); standard 8051 @ 22.1184 MHz, empty putchar()
21021 \begin_layout Standard
21027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21030 \begin_layout Standard
21036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21039 \begin_layout Standard
21045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21048 \begin_layout Standard
21054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21057 \begin_layout Standard
21063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21066 \begin_layout Standard
21072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21075 \begin_layout Standard
21082 <row bottomline="true">
21083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21086 \begin_layout Standard
21091 \begin_layout Standard
21092 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
21101 \begin_layout Standard
21107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21110 \begin_layout Standard
21116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21119 \begin_layout Standard
21125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21128 \begin_layout Standard
21134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21137 \begin_layout Standard
21143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21146 \begin_layout Standard
21152 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21155 \begin_layout Standard
21160 \begin_layout Standard
21161 printf_tiny integer speed is data dependent, worst case is 0.33 ms
21172 <row bottomline="true">
21173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21176 \begin_layout Standard
21181 \begin_layout Standard
21182 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
21191 \begin_layout Standard
21197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21200 \begin_layout Standard
21206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21209 \begin_layout Standard
21215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21218 \begin_layout Standard
21224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21227 \begin_layout Standard
21233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21236 \begin_layout Standard
21242 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21245 \begin_layout Standard
21252 <row bottomline="true">
21253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21256 \begin_layout Standard
21261 \begin_layout Standard
21262 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
21271 \begin_layout Standard
21277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21280 \begin_layout Standard
21286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21289 \begin_layout Standard
21295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21298 \begin_layout Standard
21304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21307 \begin_layout Standard
21313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21316 \begin_layout Standard
21322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21325 \begin_layout Standard
21339 \begin_layout Subsubsection
21341 \begin_inset LatexCommand \index{malloc.h}
21348 \begin_layout Standard
21349 As of SDCC 2.6.2 you no longer need to call an initialization routine before
21350 using dynamic memory allocation
21351 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
21356 \begin_inset LatexCommand \index{heap (malloc)}
21360 space of 1024 bytes is provided for malloc to allocate memory from.
21361 If you need a different heap size you need to recompile _heap.c with the
21362 required size defined in HEAP_SIZE.
21363 It is recommended to make a copy of this file into your project directory
21364 and compile it there with:
21367 \begin_layout Verse
21370 sdcc -c _heap.c -D HEAD_SIZE=2048
21373 \begin_layout Standard
21374 And then link it with:
21377 \begin_layout Verse
21380 sdcc main.rel _heap.rel
21383 \begin_layout Subsection
21384 Math functions (sinf, powf, sqrtf etc.)
21387 \begin_layout Subsubsection
21391 \begin_layout Standard
21392 See definitions in file <math.h>.
21395 \begin_layout Subsection
21399 \begin_layout Standard
21401 \begin_inset LatexCommand \index{Libraries}
21405 included in SDCC should have a license at least as liberal as the GNU Lesser
21406 General Public License
21407 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
21418 \begin_layout Standard
21419 \begin_inset Note Note
21422 \begin_layout Standard
21423 license statements for the libraries are missing.
21424 sdcc/device/lib/ser_ir.c
21427 \begin_layout Standard
21429 come with a GPL (as opposed to LGPL) License - this will not be liberal
21430 enough for many embedded programmers.
21438 \begin_layout Standard
21439 If you have ported some library or want to share experience about some code
21441 falls into any of these categories Busses (I
21442 \begin_inset Formula $^{\textrm{2}}$
21445 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
21446 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
21447 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
21448 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
21453 would certainly like to hear about it.
21456 \begin_layout Standard
21457 Programmers coding for embedded systems are not especially famous for being
21458 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
21459 e these references are very valuable.
21460 Let's help to create a climate where information is shared.
21461 \begin_inset VSpace bigskip
21467 \begin_layout Section
21471 \begin_layout Subsection
21472 MCS51 Memory Models
21473 \begin_inset LatexCommand \index{Memory model}
21478 \begin_inset LatexCommand \index{MCS51 memory model}
21485 \begin_layout Subsubsection
21486 Small, Medium and Large
21489 \begin_layout Standard
21490 SDCC allows three memory models for MCS51 code,
21499 Modules compiled with different memory models should
21503 be combined together or the results would be unpredictable.
21504 The library routines supplied with the compiler are compiled as small,
21506 The compiled library modules are contained in separate directories as small,
21507 medium and large so that you can link to the appropriate set.
21510 \begin_layout Standard
21511 When the medium or large model is used all variables declared without a
21512 storage class will be allocated into the external ram, this includes all
21513 parameters and local variables (for non-reentrant
21514 \begin_inset LatexCommand \index{reentrant}
21519 When the small model is used variables without storage class are allocated
21520 in the internal ram.
21523 \begin_layout Standard
21524 Judicious usage of the processor specific storage classes
21525 \begin_inset LatexCommand \index{Storage class}
21529 and the 'reentrant' function type will yield much more efficient code,
21530 than using the large model.
21531 Several optimizations are disabled when the program is compiled using the
21532 large model, it is therefore recommended that the small model be used unless
21533 absolutely required.
21536 \begin_layout Subsubsection
21538 \begin_inset LatexCommand \label{sub:External-Stack}
21543 \begin_inset LatexCommand \index{stack}
21548 \begin_inset LatexCommand \index{External stack (mcs51)}
21555 \begin_layout Standard
21556 The external stack (-
21560 \begin_layout Standard
21570 \begin_inset LatexCommand \index{-\/-xstack}
21574 ) is located in pdata
21575 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
21579 memory (usually at the start of the external ram segment) and uses all
21580 unused space in pdata (max.
21586 \begin_layout Standard
21595 -xstack option is used to compile the program, the parameters and local
21597 \begin_inset LatexCommand \index{local variables}
21601 of all reentrant functions are allocated in this area.
21602 This option is provided for programs with large stack space requirements.
21603 When used with the -
21607 \begin_layout Standard
21617 \begin_inset LatexCommand \index{-\/-stack-auto}
21621 option, all parameters and local variables are allocated on the external
21622 stack (note: support libraries will need to be recompiled with the same
21624 There is a predefined target in the library makefile).
21627 \begin_layout Standard
21628 The compiler outputs the higher order address byte of the external ram segment
21630 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21635 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21639 ), therefore when using the External Stack option, this port
21643 be used by the application program.
21646 \begin_layout Subsection
21648 \begin_inset LatexCommand \index{Memory model}
21653 \begin_inset LatexCommand \index{DS390 memory model}
21660 \begin_layout Standard
21661 The only model supported is Flat 24
21662 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21667 This generates code for the 24 bit contiguous addressing mode of the Dallas
21669 In this mode, up to four meg of external RAM or code space can be directly
21671 See the data sheets at www.dalsemi.com for further information on this part.
21676 that the compiler does not generate any code to place the processor into
21677 24 bitmode (although
21681 in the ds390 libraries will do that for you).
21687 \begin_inset LatexCommand \index{Tinibios (DS390)}
21691 , the boot loader or similar code must ensure that the processor is in 24
21692 bit contiguous addressing mode before calling the SDCC startup code.
21703 \begin_layout Standard
21714 option, variables will by default be placed into the XDATA segment.
21719 Segments may be placed anywhere in the 4 meg address space using the usual
21724 \begin_layout Standard
21734 Note that if any segments are located above 64K, the -r flag must be passed
21735 to the linker to generate the proper segment relocations, and the Intel
21736 HEX output format must be used.
21737 The -r flag can be passed to the linker by using the option
21741 on the SDCC command line.
21742 However, currently the linker can not handle code segments > 64k.
21745 \begin_layout Section
21747 \begin_inset LatexCommand \label{sec:Pragmas}
21752 \begin_inset LatexCommand \index{Pragmas}
21759 \begin_layout Standard
21760 Pragmas are used to turn on and/or off certain compiler options.
21761 Some of them are closely related to corresponding command-line options
21763 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21769 Pragmas should be placed before and/or after a function, placing pragmas
21770 inside a function body could have unpredictable results.
21775 following #pragma directives:
21778 \begin_layout Itemize
21784 \begin_inset LatexCommand \index{\#pragma save}
21788 - this will save most current options to the save/restore stack.
21789 See #pragma\InsetSpace ~
21793 \begin_layout Itemize
21799 \begin_inset LatexCommand \index{\#pragma restore}
21803 - will restore saved options from the last save.
21804 saves & restores can be nested.
21805 SDCC uses a save/restore stack: save pushes current options to the stack,
21806 restore pulls current options from the stack.
21807 See #pragma\InsetSpace ~
21813 \begin_layout Itemize
21819 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21824 \begin_inset LatexCommand \index{function prologue}
21828 function1[,function2[,function3...]]
21829 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21833 - The compiler by default uses a caller saves convention for register saving
21834 across function calls, however this can cause unnecessary register pushing
21836 \begin_inset LatexCommand \index{push/pop}
21840 when calling small functions from larger functions.
21841 This option can be used to switch off the register saving convention for
21842 the function names specified.
21843 The compiler will not save registers when calling these functions, extra
21844 code need to be manually inserted at the entry and exit for these functions
21845 to save and restore the registers used by these functions, this can SUBSTANTIAL
21846 LY reduce code and improve run time performance of the generated code.
21847 In the future the compiler (with inter procedural analysis) may be able
21848 to determine the appropriate scheme to use for each function call.
21853 \begin_layout Standard
21862 -callee-saves command line option is used (see page
21863 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21867 ), the function names specified in #pragma\InsetSpace ~
21869 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21873 is appended to the list of functions specified in the command line.
21876 \begin_layout Itemize
21882 \begin_inset LatexCommand \index{\#pragma exclude}
21886 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21887 of pairs of push/pop
21888 \begin_inset LatexCommand \index{push/pop}
21897 \begin_inset LatexCommand \index{interrupt}
21910 The directive should be placed immediately before the ISR function definition
21911 and it affects ALL ISR functions following it.
21912 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21913 exclude\InsetSpace ~
21915 \begin_inset LatexCommand \index{\#pragma exclude}
21920 See also the related keyword _naked
21921 \begin_inset LatexCommand \index{\_naked}
21926 \begin_inset LatexCommand \index{\_\_naked}
21933 \begin_layout Itemize
21939 \begin_inset LatexCommand \index{pedantic}
21944 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21949 \begin_inset LatexCommand \label{ite:less_pedantic}
21953 - the compiler will not warn you anymore for obvious mistakes, you're on
21955 See also the command line option -
21959 \begin_layout Standard
21969 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21976 More specifically, the following warnings will be disabled:
21978 comparison is always [true/false] due to limited range of data type
21982 overflow in implicit constant conversion
21984 (158); [the (in)famous]
21986 conditional flow changed by optimizer: so said EVELYN the modified DOG
21990 function '[function name]' must return value
21995 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21996 level) are disabled, too, namely:
21999 \begin_inset Note Note
22002 \begin_layout Standard
22003 dunno what comes here - this warning appears to be unused altogether
22012 [left/right] shifting more than size of object changed to zero
22020 integer overflow in expression
22024 unmatched #pragma save and #pragma restore
22028 comparison of 'signed char' with 'unsigned char' requires promotion to int
22032 ISO C90 does not support flexible array members
22036 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
22040 \begin_inset Note Note
22043 \begin_layout Standard
22044 appears to be always blank - what was supposed to be here?
22053 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
22054 complexity [number]
22059 \begin_layout Itemize
22065 \begin_inset LatexCommand \index{\#pragma disable\_warning}
22069 - the compiler will not warn you anymore about warning number <nnnn>.
22072 \begin_layout Itemize
22078 \begin_inset LatexCommand \index{\#pragma nogcse}
22082 - will stop global common subexpression elimination.
22085 \begin_layout Itemize
22091 \begin_inset LatexCommand \index{\#pragma noinduction}
22095 - will stop loop induction optimizations.
22098 \begin_layout Itemize
22104 \begin_inset LatexCommand \index{\#pragma noinvariant}
22108 - will not do loop invariant optimizations.
22109 For more details see Loop Invariants in section
22110 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
22117 \begin_layout Itemize
22123 \begin_inset LatexCommand \index{\#pragma noiv}
22127 - Do not generate interrupt
22128 \begin_inset LatexCommand \index{interrupt}
22133 \begin_inset LatexCommand \index{interrupt vector table}
22137 entries for all ISR functions defined after the pragma.
22138 This is useful in cases where the interrupt vector table must be defined
22139 manually, or when there is a secondary, manually defined interrupt vector
22141 for the autovector feature of the Cypress EZ-USB FX2).
22142 More elegantly this can be achieved by obmitting the optional interrupt
22143 number after the interrupt keyword, see section
22144 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
22152 \begin_layout Itemize
22158 \begin_inset LatexCommand \index{\#pragma nojtbound}
22162 - will not generate code for boundary value checking, when switch statements
22163 are turned into jump-tables (dangerous).
22164 For more details see section
22165 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
22172 \begin_layout Itemize
22178 \begin_inset LatexCommand \index{\#pragma noloopreverse}
22182 - Will not do loop reversal optimization
22185 \begin_layout Itemize
22191 \begin_inset LatexCommand \index{\#pragma nooverlay}
22195 - the compiler will not overlay the parameters and local variables of a
22199 \begin_layout Itemize
22205 \begin_inset LatexCommand \index{\#pragma stackauto}
22213 \begin_layout Standard
22223 \begin_inset LatexCommand \index{-\/-stack-auto}
22228 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
22232 Parameters and Local Variables.
22235 \begin_layout Itemize
22241 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
22245 - The compiler will optimize code generation towards fast code, possibly
22246 at the expense of code size.
22247 Currently this has little effect.
22250 \begin_layout Itemize
22256 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
22260 - The compiler will optimize code generation towards compact code, possibly
22261 at the expense of code speed.
22262 Currently this has little effect.
22265 \begin_layout Itemize
22271 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
22275 - The compiler will attempt to generate code that is both compact and fast,
22276 as long as meeting one goal is not a detriment to the other (this is the
22281 \begin_layout Itemize
22287 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
22291 - Generally follow the C89 standard, but allow SDCC features that conflict
22292 with the standard (default).
22295 \begin_layout Itemize
22301 \begin_inset LatexCommand \index{\#pragma std\_c89}
22305 - Follow the C89 standard and disable SDCC features that conflict with the
22309 \begin_layout Itemize
22315 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
22319 - Generally follow the C99 standard, but allow SDCC features that conflict
22320 with the standard (incomplete support).
22323 \begin_layout Itemize
22329 \begin_inset LatexCommand \index{\#pragma std\_c99}
22333 - Follow the C99 standard and disable SDCC features that conflict with the
22334 standard (incomplete support).
22337 \begin_layout Itemize
22343 \begin_inset LatexCommand \index{\#pragma codeseg}
22347 - Use this name (max.
22348 8 characters) for the code segment.
22353 \begin_layout Standard
22365 \begin_layout Itemize
22371 \begin_inset LatexCommand \index{\#pragma constseg}
22375 - Use this name (max.
22376 8 characters) for the const segment.
22381 \begin_layout Standard
22393 \begin_layout Standard
22394 The preprocessor SDCPP
22395 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
22399 supports the following #pragma directives:
22402 \begin_layout Itemize
22405 pedantic_parse_number
22408 \begin_inset LatexCommand \index{pedantic}
22413 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22418 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
22422 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
22423 properly and the macro LO_B(3) gets expanded.
22429 \begin_layout Standard
22438 -pedantic-parse-number command line option
22439 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
22446 Below is an example on how to use this pragma.
22449 Note: this functionality is not in conformance with standard!
22452 \begin_layout Verse
22455 #pragma pedantic_parse_number +
22456 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22464 #define LO_B(x) ((x) & 0xff)
22468 unsigned char foo(void)
22475 unsigned char c=0xfe-LO_B(3)
22490 \begin_layout Itemize
22496 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22500 (+ | -) - switch _asm _endasm block preprocessing on / off.
22502 You use this prama to define multilines of assembly code.
22503 This will prevent the preprocessor from changing the formating required
22505 Below is an example on how to use this pragma.
22508 \begin_layout Verse
22511 #pragma preproc_asm -
22512 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22518 #define MYDELAY _asm
22523 nop ;my assembly comment...
22537 #pragma preproc_asm
22568 \begin_layout Itemize
22574 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22578 (+ | -) - Allow "naked" hash in macro definition, for example:
22582 #define DIR_LO(x) #(x & 0xff)
22587 Below is an example on how to use this pragma.
22590 \begin_layout Verse
22593 #pragma preproc_asm +
22595 #pragma sdcc_hash +
22596 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22611 mov R6_B3, #(x & 0xff)
22618 mov R7_B3, #((x >> 8) & 0xff)
22642 \begin_layout Standard
22643 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22644 ons which might cause the compiler to generate extra stack and/or data space
22645 to store compiler generated temporary variables.
22646 This usually happens in large functions.
22647 Pragma directives should be used as shown in the following example, they
22648 are used to control options and optimizations for a given function.
22652 \begin_layout Verse
22656 \begin_inset LatexCommand \index{\#pragma save}
22667 /* save the current settings */
22670 \begin_inset LatexCommand \index{\#pragma nogcse}
22679 /* turnoff global subexpression elimination */
22681 #pragma noinduction
22682 \begin_inset LatexCommand \index{\#pragma noinduction}
22686 /* turn off induction optimizations */
22709 \begin_inset LatexCommand \index{\#pragma restore}
22713 /* turn the optimizations back on */
22716 \begin_layout Standard
22717 The compiler will generate a warning message when extra space is allocated.
22718 It is strongly recommended that the save and restore pragmas be used when
22719 changing options for a function.
22728 \begin_layout Section
22729 Defines Created by the Compiler
22732 \begin_layout Standard
22733 The compiler creates the following #defines
22734 \begin_inset LatexCommand \index{\#defines}
22739 \begin_inset LatexCommand \index{Defines created by the compiler}
22748 \begin_layout Standard
22749 \begin_inset Tabular
22750 <lyxtabular version="3" rows="15" columns="2">
22752 <column alignment="left" valignment="top" leftline="true" width="3in">
22753 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22754 <row topline="true" bottomline="true">
22755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22758 \begin_layout Standard
22766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22769 \begin_layout Standard
22778 <row topline="true">
22779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22782 \begin_layout Standard
22784 \begin_inset LatexCommand \index{SDCC}
22793 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22796 \begin_layout Standard
22798 Since version 2.5.6 the version number as an int (ex.
22805 <row topline="true">
22806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22809 \begin_layout Standard
22811 \begin_inset LatexCommand \index{SDCC\_mcs51}
22816 \begin_inset LatexCommand \index{SDCC\_ds390}
22821 \begin_inset LatexCommand \index{SDCC\_z80}
22830 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22833 \begin_layout Standard
22834 depending on the model used (e.g.: -mds390)
22840 <row topline="true">
22841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22844 \begin_layout Standard
22846 \begin_inset LatexCommand \index{\_\_mcs51}
22851 \begin_inset LatexCommand \index{\_\_ds390}
22856 \begin_inset LatexCommand \index{\_\_hc08}
22861 \begin_inset LatexCommand \index{\_\_z80}
22870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22873 \begin_layout Standard
22874 depending on the model used (e.g.
22881 <row topline="true">
22882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22885 \begin_layout Standard
22887 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22896 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22899 \begin_layout Standard
22906 \begin_layout Standard
22923 <row topline="true">
22924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22927 \begin_layout Standard
22929 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22941 \begin_layout Standard
22948 \begin_layout Standard
22965 <row topline="true">
22966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22969 \begin_layout Standard
22971 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22983 \begin_layout Standard
22990 \begin_layout Standard
23007 <row topline="true">
23008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23011 \begin_layout Standard
23013 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
23022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23025 \begin_layout Standard
23032 \begin_layout Standard
23049 <row topline="true">
23050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23053 \begin_layout Standard
23055 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
23064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23067 \begin_layout Standard
23074 \begin_layout Standard
23091 <row topline="true">
23092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23095 \begin_layout Standard
23097 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
23106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23109 \begin_layout Standard
23120 <row topline="true">
23121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23124 \begin_layout Standard
23126 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23138 \begin_layout Standard
23149 <row topline="true">
23150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23153 \begin_layout Standard
23155 \begin_inset LatexCommand \index{SDCC\_REVISION}
23164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23167 \begin_layout Standard
23169 SDCC svn revision number
23175 <row topline="true">
23176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23179 \begin_layout Standard
23180 SDCC_PARMS_IN_BANK1
23181 \begin_inset LatexCommand \index{SDCC\_PARMS\_IN\_BANK1}
23190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23193 \begin_layout Standard
23200 \begin_layout Standard
23217 <row topline="true">
23218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23221 \begin_layout Standard
23223 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23232 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23235 \begin_layout Standard
23242 \begin_layout Standard
23259 <row topline="true" bottomline="true">
23260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23263 \begin_layout Standard
23264 SDCC_INT_LONG_REENT
23265 \begin_inset LatexCommand \index{SDCC\_INT\_LONG\_REENT}
23274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23277 \begin_layout Standard
23284 \begin_layout Standard
23308 \begin_layout Chapter
23309 Notes on supported Processors
23312 \begin_layout Section
23314 \begin_inset LatexCommand \label{sub:MCS51-variants}
23319 \begin_inset LatexCommand \index{MCS51 variants}
23326 \begin_layout Standard
23327 MCS51 processors are available from many vendors and come in many different
23329 While they might differ considerably in respect to Special Function Registers
23330 the core MCS51 is usually not modified or is kept compatible.
23334 \begin_layout Subsection
23335 pdata access by SFR
23338 \begin_layout Standard
23339 With the upcome of devices with internal xdata and flash memory devices
23341 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
23345 as dedicated I/O port is becoming more popular.
23346 Switching the high byte for pdata
23347 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
23351 access which was formerly done by port P2 is then achieved by a Special
23353 \begin_inset LatexCommand \index{sfr}
23358 In well-established MCS51 tradition the address of this
23362 is where the chip designers decided to put it.
23363 Needless to say that they didn't agree on a common name either.
23364 So that the startup code can correctly initialize xdata variables, you
23365 should define an sfr with the name _XPAGE
23368 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
23374 at the appropriate location if the default, port P2, is not used for this.
23378 \begin_layout Verse
23381 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
23385 \begin_layout Verse
23388 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
23393 \begin_layout Verse
23396 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
23400 \begin_layout Verse
23403 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23407 \begin_layout Verse
23410 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23414 \begin_layout Standard
23415 For more exotic implementations further customizations may be needed.
23417 \begin_inset LatexCommand \ref{sub:Startup-Code}
23421 for other possibilities.
23424 \begin_layout Subsection
23425 Other Features available by SFR
23428 \begin_layout Standard
23429 Some MCS51 variants offer features like Double DPTR
23430 \begin_inset LatexCommand \index{DPTR}
23434 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
23435 These are currently not used for the MCS51 port.
23436 If you absolutely need them you can fall back to inline assembly or submit
23440 \begin_layout Subsection
23444 \begin_layout Standard
23446 \begin_inset LatexCommand \index{Bankswitching}
23452 \begin_inset LatexCommand \index{code banking}
23456 ) is a technique to increase the code space above the 64k limit of the 8051.
23459 \begin_layout Subsubsection
23463 \begin_layout Standard
23464 \begin_inset Tabular
23465 <lyxtabular version="3" rows="3" columns="4">
23467 <column alignment="center" valignment="top" width="0">
23468 <column alignment="center" valignment="top" leftline="true" width="0">
23469 <column alignment="center" valignment="top" leftline="true" width="0">
23470 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23471 <row topline="true" bottomline="true">
23472 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23475 \begin_layout Standard
23476 \paragraph_spacing other 0.5
23482 <cell alignment="center" valignment="top" topline="true" leftline="true" 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" rightline="true" usebox="none">
23503 \begin_layout Standard
23510 <row topline="true" bottomline="true">
23511 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23514 \begin_layout Standard
23520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23523 \begin_layout Standard
23529 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23532 \begin_layout Standard
23538 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23541 \begin_layout Standard
23549 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23552 \begin_layout Standard
23553 SiLabs C8051F120 example
23558 <cell multicolumn="2" alignment="center" valignment="top" usebox="none">
23561 \begin_layout Standard
23567 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23570 \begin_layout Standard
23576 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23579 \begin_layout Standard
23594 Usually the hardware uses some sfr (an output port or an internal sfr) to
23595 select a bank and put it in the banked area of the memory map.
23596 Because the selected bank usually becomes active immediately you cannot
23597 jump call directly from one bank to another and need to use a so-called
23598 trampoline in the common area.
23599 For SDCC an example trampoline is in crtbank.asm and you may need to change
23600 it to your 8051 derivative or schematic.
23601 The presented code is written for the C8051F120.
23605 When calling a banked function
23606 SDCC will put the LSB of the functions address in register R0, the MSB
23607 in R1 and the bank in R2 and then call this trampoline __sdcc_banked_call.
23608 The current selected bank is saved on the stack, the new bank is selected
23609 and an indirect jump is made.
23610 When the banked function returns it jumps to __sdcc_banked_ret which restores
23611 the previous bank and returns to the caller.
23614 \begin_layout Subsubsection
23618 \begin_layout Standard
23619 When writing banked software using SDCC you need to use some special keywords
23621 You also need to take over a bit of work from the linker.
23625 To create a function
23626 that can be called from another bank it requires the keyword banked.
23627 The caller must see this in the prototype of the callee and the callee
23628 needs it for a proper return.
23629 Called functions within the same bank as the caller do not need the banked
23630 keyword nor do functions in the common area.
23631 Beware: SDCC does not know or check if functions are in the same bank.
23632 This is your responsibility!
23636 Normally all functions you write end up in
23638 If you want a function explicitly to reside in the common area put it in
23640 This applies for instance to interrupt service routines as they should
23644 \begin_layout Standard
23645 Functions that need to be in a switched bank must be put in a named segment.
23646 The name can be mostly anything upto eight characters (e.g.
23648 To do this you either use --codeseg BANK1 on the command line when compiling
23649 or #pragma codeseg BANK1 at the top of the C source file.
23650 The segment name always applies to the whole source file and generated
23651 object so functions for different banks need to be defined in different
23656 When linking your objects you need to tell the linker where
23657 to put your segments.
23658 To do this you use the following command line option to SDCC: -Wl-b BANK1=0x180
23660 This sets the virtual start address of this segment.
23661 It sets the banknumber to 0x01 and maps the bank to 0x8000 and up.
23662 The linker will not check for overflows, again this is your responsibility.
23665 \begin_layout Standard
23666 \begin_inset VSpace bigskip
23672 \begin_layout Section
23676 \begin_layout Standard
23678 \begin_inset LatexCommand \index{DS80C400}
23683 \begin_inset LatexCommand \index{DS400}
23687 microcontroller has a rich set of peripherals.
23688 In its built-in ROM library it includes functions to access some of the
23689 features, among them is a TCP stack with IP4 and IP6 support.
23690 Library headers (currently in beta status) and other files are provided
23694 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
23700 \begin_inset VSpace bigskip
23706 \begin_layout Section
23707 The Z80 and gbz80 port
23710 \begin_layout Standard
23711 SDCC can target both the Zilog Z80
23712 \begin_inset LatexCommand \index{Z80}
23716 and the Nintendo Gameboy's Z80-like gbz80
23717 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
23722 The Z80 port is passed through the same
23725 \begin_inset LatexCommand \index{Regression test}
23732 \begin_inset LatexCommand \ref{sec:Quality-control}
23736 ) as the MCS51 and DS390 ports, so floating point support, support for long
23737 variables and bitfield support is fine.
23738 See mailing lists and forums about interrupt routines.
23741 \begin_layout Standard
23742 As always, the code is the authoritative reference - see z80/ralloc.c and
23745 \begin_inset LatexCommand \index{Z80!stack}
23749 frame is similar to that generated by the IAR Z80 compiler.
23750 IX is used as the base pointer, HL and IY are used as a temporary registers,
23751 and BC and DE are available for holding variables.
23753 \begin_inset LatexCommand \index{Z80!return value}
23757 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
23759 The gbz80 port use the same set of registers for the return values, but
23760 in a different order of significance: E (one byte), DE (two bytes), or
23762 \begin_inset VSpace bigskip
23768 \begin_layout Section
23772 \begin_layout Standard
23773 The port to the Freescale/Motorola HC08
23774 \begin_inset LatexCommand \index{HC08}
23778 family has been added in October 2003, and is still undergoing some basic
23780 The code generator is complete, but the register allocation is still quite
23782 Some of the SDCC's standard C library functions have embedded non-HC08
23783 inline assembly and so are not yet usable.
23786 \begin_layout Standard
23787 The HC08 port passes the regression test suite (see section
23788 \begin_inset LatexCommand \ref{sec:Quality-control}
23793 \begin_inset VSpace bigskip
23801 \begin_layout Section
23803 \begin_inset LatexCommand \index{PIC14}
23810 \begin_layout Standard
23811 The PIC14 port adds support for Microchip
23812 \begin_inset LatexCommand \index{Microchip}
23817 \begin_inset Formula $^{\text{TM}}$
23821 \begin_inset LatexCommand \index{PIC14}
23826 \begin_inset Formula $^{\text{TM}}$
23829 MCUs with 14 bit wide instructions.
23830 This port is not yet mature and still lacks many features.
23831 However, it can work for simple code.
23834 \begin_layout Standard
23835 Currently supported devices include:
23838 \begin_layout Standard
23839 12F: 629, 635, 675, 683
23842 \begin_layout Standard
23846 \begin_layout Standard
23850 \begin_layout Standard
23851 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
23854 \begin_layout Standard
23855 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
23859 \begin_layout Standard
23863 \begin_layout Standard
23864 16F: 627, 627a, 628, 628a, 630, 636, 639, 648a, 676, 684, 685, 687, 688,
23868 \begin_layout Standard
23869 16F: 716, 72, 73, 737, 74, 76, 767, 77, 777, 785
23872 \begin_layout Standard
23873 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
23877 \begin_layout Standard
23878 16F: 913, 914, 916, 917
23881 \begin_layout Standard
23882 An up-to-date list of currently supported devices can be obtained via
23884 sdcc -mpic14 -phelp foo.c
23886 (foo.c must exist...).
23889 \begin_layout Subsection
23891 \begin_inset LatexCommand \index{code page (pic14)}
23896 \begin_inset LatexCommand \index{Memory bank (pic14)}
23903 \begin_layout Standard
23904 The linker organizes allocation for the code page and RAM banks.
23905 It does not have intimate knowledge of the code flow.
23906 It will put all the code section of a single .asm file into a single code
23908 In order to make use of multiple code pages, separate asm files must be
23910 The compiler assigns all
23914 functions of a single .c file into the same code page.
23918 To get the best results,
23919 follow these guidelines:
23922 \begin_layout Enumerate
23923 Make local functions static, as non static functions require code page selection
23926 Due to the way sdcc handles functions, place called functions prior
23927 to calling functions in the file wherever possible: Otherwise sdcc will
23928 insert unneccessary pagesel directives around the call, believing that
23929 the called function is externally defined.
23932 \begin_layout Enumerate
23933 For devices that have multiple code pages it is more efficient to use the
23934 same number of files as pages: Use up to 4 separate .c files for the 16F877,
23935 but only 2 files for the 16F874.
23936 This way the linker can put the code for each file into different code
23937 pages and there will be less page selection overhead.
23940 \begin_layout Enumerate
23941 And as for any 8 bit micro (especially for PIC14 as they have a very simple
23942 instruction set), use `unsigned char' wherever possible instead of `int'.
23945 \begin_layout Subsection
23946 Adding New Devices to the Port
23949 \begin_layout Standard
23950 Adding support for a new 14
23954 \begin_layout Standard
23963 bit PIC MCU requires the following steps:
23966 \begin_layout Enumerate
23967 Create a new device description.
23969 Each device is described in two files: pic16f*.h
23971 These files primarily define SFRs, structs to access their bits, and symbolic
23972 configuration options.
23973 Both files can be generated from gputils' .inc files using the perl script
23976 support/scripts/inc2h.pl
23979 This file also contains further instructions on how to proceed.
23982 \begin_layout Enumerate
23983 Copy the .h file into SDCC's include path and either add the .c file to your
23984 project or copy it to
23986 device/lib/pic/libdev
23989 Afterwards, rebuild and install the libraries.
23992 \begin_layout Enumerate
23993 Edit pic14devices.txt in SDCC's include path (
23995 device/include/pic/
23997 in the source tree or
23999 /usr/local/share/sdcc/include/pic
24001 after installation).
24003 You need to add a device specification here to make
24004 the memory layout (code banks, RAM, aliased memory regions, ...) known to
24006 Probably you can copy and modify an existing entry.
24007 The file format is documented at the top of the file.
24010 \begin_layout Subsection
24014 \begin_layout Standard
24015 For the interrupt function, use the keyword `__interrupt'
24016 \begin_inset LatexCommand \index{PIC14!interrupt}
24020 with level number of 0 (PIC14 only has 1 interrupt so this number is only
24021 there to avoid a syntax error - it ought to be fixed).
24025 \begin_layout Verse
24028 void Intr(void) __interrupt 0
24034 T0IF = 0; /* Clear timer interrupt */
24039 \begin_layout Subsection
24040 Linking and Assembling
24043 \begin_layout Standard
24044 For assembling you can use either GPUTILS'
24045 \begin_inset LatexCommand \index{gputils (pic tools)}
24049 gpasm.exe or MPLAB's mpasmwin.exe.
24050 GPUTILS are available from
24051 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24056 For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
24057 If you use MPLAB and an interrupt function then the linker script file
24058 vectors section will need to be enlarged to link with mplink.
24069 \begin_layout Verse
24082 sdcc -V -mpic14 -p16f877 -c $<
24086 $(PRJ).hex: $(OBJS)
24096 gplink -m -s $(PRJ).lkr
24097 -o $(PRJ).hex $(OBJS) libsdcc.lib
24100 \begin_layout Standard
24108 \begin_layout Verse
24121 sdcc -S -V -mpic14 -p16f877 $<
24131 mpasmwin /q /o $*.asm
24135 $(PRJ).hex: $(OBJS)
24146 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
24149 \begin_layout Standard
24150 Please note that indentations within a
24154 have to be done with a tabulator character.
24157 \begin_layout Subsection
24158 Command-Line Options
24161 \begin_layout Standard
24162 Besides the switches common to all SDCC backends, the PIC14 port accepts
24163 the following options (for an updated list see sdcc -
24167 \begin_layout Standard
24179 \begin_layout Description
24184 \begin_layout Standard
24194 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
24198 emit debug info in assembly output
24201 \begin_layout Description
24206 \begin_layout Standard
24216 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
24220 disable (slightly faulty) optimization on pCode
24223 \begin_layout Description
24228 \begin_layout Standard
24238 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
24242 sets the lowest address of the argument passing stack (defaults to a suitably
24243 large shared databank to reduce BANKSEL overhead)
24246 \begin_layout Description
24251 \begin_layout Standard
24261 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
24265 sets the size if the argument passing stack (default: 16, minimum: 4)
24268 \begin_layout Subsection
24269 Environment Variables
24272 \begin_layout Standard
24273 The PIC14 port recognizes the following environment variables:
24276 \begin_layout Description
24277 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
24278 register (the ones called r0xNNNN) in a section of its own.
24279 By default (if this variable is unset), sdcc tries to cluster registers
24280 in sections in order to reduce the BANKSEL overhead when accessing them.
24283 \begin_layout Subsection
24287 \begin_layout Standard
24288 The PIC14 library currently only contains support routines required by the
24289 compiler to implement multiplication, division, and floating point support.
24290 No libc-like replacement is available at the moment, though many of the
24291 common sdcc library sources (in
24295 ) should also compile with the PIC14 port.
24298 \begin_layout Subsubsection
24299 error: missing definition for symbol ``__gptrget1''
24302 \begin_layout Standard
24303 The PIC14 port uses library routines to provide more complex operations
24304 like multiplication, division/modulus and (generic) pointer dereferencing.
24305 In order to add these routines to your project, you must link with PIC14's
24311 For single source file projects this is done automatically, more complex
24316 to the linker's arguments.
24317 Make sure you also add an include path for the library (using the -I switch
24321 \begin_layout Subsubsection
24322 Processor mismatch in file ``XXX''.
24325 \begin_layout Standard
24326 This warning can usually be ignored due to the very good compatibility amongst
24331 \begin_layout Standard
24341 \begin_inset LatexCommand \index{PIC14}
24348 \begin_layout Standard
24349 You might also consider recompiling the library for your specific device
24350 by changing the ARCH=p16f877 (default target) entry in
24352 device/lib/pic/Makefile.in
24356 device/lib/pic/Makefile
24358 to reflect your device.
24359 This might even improve performance for smaller devices as unneccesary
24360 BANKSELs might be removed.
24363 \begin_layout Subsection
24367 \begin_layout Subsubsection
24371 \begin_layout Standard
24372 Functions with variable argument lists (like printf) are not yet supported.
24373 Similarly, taking the argument of the first argument passed into a function
24374 does not work: It is currently passed in WREG and has no address...
24377 \begin_layout Subsubsection
24378 Regression tests fail
24381 \begin_layout Standard
24382 Though the small subset of regression tests in src/regression passes, SDCC
24383 regression test suite does not, indicating that there are still major bugs
24385 However, many smaller projects have successfully used SDCC in the past...
24388 \begin_layout Standard
24396 \begin_layout Section
24398 \begin_inset LatexCommand \index{PIC16}
24405 \begin_layout Standard
24406 The PIC16 port adds support for Microchip
24407 \begin_inset LatexCommand \index{Microchip}
24412 \begin_inset Formula $^{\text{TM}}$
24416 \begin_inset LatexCommand \index{PIC}
24421 \begin_inset Formula $^{\text{TM}}$
24424 MCUs with 16 bit wide instructions.
24425 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
24426 ; devices supported by the port include:
24429 \begin_layout Standard
24430 18F: 242, 248, 252, 258, 442, 448, 452, 458
24433 \begin_layout Standard
24437 \begin_layout Standard
24438 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 24j10, 2525, 2550, 25j10,
24442 \begin_layout Standard
24443 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 44j10, 4520, 4525, 4550,
24447 \begin_layout Standard
24448 18F: 6520, 6620, 6680, 6720
24451 \begin_layout Standard
24452 18F: 8520, 8620, 8680, 8720
24455 \begin_layout Subsection
24459 \begin_layout Standard
24460 PIC16 port supports the standard command line arguments as supposed, with
24461 the exception of certain cases that will be mentioned in the following
24465 \begin_layout Description
24470 \begin_layout Standard
24480 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
24488 \begin_layout Standard
24500 \begin_layout Description
24505 \begin_layout Standard
24514 -fommit-frame-pointer
24515 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
24519 Frame pointer will be omitted when the function uses no local variables.
24522 \begin_layout Subsection
24523 Port Specific Options
24524 \begin_inset LatexCommand \index{Options PIC16}
24531 \begin_layout Standard
24532 The port specific options appear after the global options in the sdcc -
24536 \begin_layout Standard
24548 \begin_layout Subsubsection
24549 Code Generation Options
24552 \begin_layout Standard
24553 These options influence the generated assembler code.
24556 \begin_layout Description
24561 \begin_layout Standard
24570 -pstack-model=[model] Used in conjuction with the command above.
24571 Defines the stack model to be used, valid stack models are:
24576 \labelwidthstring 00.00.0000
24581 Selects small stack model.
24582 8 bit stack and frame pointers.
24583 Supports 256 bytes stack size.
24587 \labelwidthstring 00.00.0000
24592 Selects large stack model.
24593 16 bit stack and frame pointers.
24594 Supports 65536 bytes stack size.
24598 \begin_layout Description
24603 \begin_layout Standard
24612 -pno-banksel Do not generate BANKSEL assembler directives.
24615 \begin_layout Description
24620 \begin_layout Standard
24629 -extended Enable extended instruction set/literal offset addressing mode.
24633 \begin_layout Subsubsection
24634 Optimization Options
24637 \begin_layout Description
24642 \begin_layout Standard
24651 -obanksel=n Set optimization level for inserting BANKSELs.
24658 \labelwidthstring 00.00.0000
24663 \labelwidthstring 00.00.0000
24664 1 checks previous used register and if it is the same then does not emit
24665 BANKSEL, accounts only for labels.
24669 \labelwidthstring 00.00.0000
24670 2 tries to check the location of (even different) symbols and removes BANKSELs
24671 if they are in the same bank.
24676 Important: There might be problems if the linker script has data sections
24677 across bank borders!
24681 \begin_layout Description
24686 \begin_layout Standard
24695 -denable-peeps Force the usage of peepholes.
24699 \begin_layout Description
24704 \begin_layout Standard
24713 -optimize-goto Try to use (conditional) BRA instead of GOTO.
24716 \begin_layout Description
24721 \begin_layout Standard
24730 -optimize-cmp Try to optimize some compares.
24733 \begin_layout Description
24738 \begin_layout Standard
24747 -optimize-df Analyze the dataflow of the generated code and improve it.
24750 \begin_layout Subsubsection
24754 \begin_layout Description
24759 \begin_layout Standard
24768 -asm= Sets the full path and name of an external assembler to call.
24771 \begin_layout Description
24776 \begin_layout Standard
24786 \begin_inset LatexCommand \index{PIC16!MPLAB}
24790 compatibility option.
24791 Currently only suppresses special gpasm directives.
24794 \begin_layout Subsubsection
24798 \begin_layout Description
24803 \begin_layout Standard
24812 -link= Sets the full path and name of an external linker to call.
24815 \begin_layout Description
24820 \begin_layout Standard
24829 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
24830 unitialized data variables with [kword].
24831 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
24834 \begin_layout Description
24839 \begin_layout Standard
24848 -ivt-loc=n Place the interrupt vector table at address
24853 Useful for bootloaders.
24856 \begin_layout Description
24861 \begin_layout Standard
24870 -nodefaultlibs Do not link default libraries when linking.
24873 \begin_layout Description
24878 \begin_layout Standard
24887 -use-crt= Use a custom run-time module instead of the defaults.
24890 \begin_layout Description
24895 \begin_layout Standard
24904 -no-crt Don't link the default run-time modules
24907 \begin_layout Subsubsection
24911 \begin_layout Standard
24912 Debugging options enable extra debugging information in the output files.
24915 \begin_layout Description
24920 \begin_layout Standard
24929 -debug-xtra Similar to -
24933 \begin_layout Standard
24943 \begin_inset LatexCommand \index{-\/-debug}
24947 , but dumps more information.
24950 \begin_layout Description
24955 \begin_layout Standard
24964 -debug-ralloc Force register allocator to dump <source>.d file with debugging
24966 <source> is the name of the file being compiled.
24969 \begin_layout Description
24974 \begin_layout Standard
24983 -pcode-verbose Enable pcode debugging information in translation.
24986 \begin_layout Description
24991 \begin_layout Standard
25000 -calltree Dump call tree in .calltree file.
25003 \begin_layout Description
25008 \begin_layout Standard
25017 -gstack Trace push/pops for stack pointer overflow.
25020 \begin_layout Subsection
25021 Enviroment Variables
25024 \begin_layout Standard
25025 There is a number of enviromental variables that can be used when running
25026 SDCC to enable certain optimizations or force a specific program behaviour.
25027 these variables are primarily for debugging purposes so they can be enabled/dis
25031 \begin_layout Standard
25032 Currently there is only two such variables available:
25035 \begin_layout Description
25036 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
25037 bitfields is optimized by directly loading FSR0 with the address of the
25038 bitfield structure.
25039 Normally SDCC will cast the bitfield structure to a bitfield pointer and
25041 This step saves data ram and code space for functions that make heavy use
25043 (i.e., 80 bytes of code space are saved when compiling malloc.c with this
25048 \begin_layout Description
25049 NO_REG_OPT Do not perform pCode registers optimization.
25050 This should be used for debugging purposes.
25051 If bugs in the pcode optimizer are found, users can benefit from temporarily
25052 disabling the optimizer until the bug is fixed.
25055 \begin_layout Subsection
25056 Preprocessor Macros
25059 \begin_layout Standard
25061 \begin_inset LatexCommand \index{PIC16}
25065 port defines the following preprocessor macros while translating a source.
25068 \begin_layout Standard
25070 \begin_inset Tabular
25071 <lyxtabular version="3" rows="6" columns="2">
25073 <column alignment="center" valignment="top" leftline="true" width="0">
25074 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25075 <row topline="true" bottomline="true">
25076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25079 \begin_layout Standard
25085 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25088 \begin_layout Standard
25095 <row topline="true">
25096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25099 \begin_layout Standard
25105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25108 \begin_layout Standard
25109 Port identification
25115 <row topline="true">
25116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25119 \begin_layout Standard
25124 \begin_layout Standard
25138 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25141 \begin_layout Standard
25142 Port identification (same as above)
25148 <row topline="true">
25149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25152 \begin_layout Standard
25158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25161 \begin_layout Standard
25162 MCU Identification.
25167 is the microcontrol identification number, i.e.
25174 <row topline="true">
25175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25178 \begin_layout Standard
25183 \begin_layout Standard
25197 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25200 \begin_layout Standard
25201 MCU Identification (same as above)
25207 <row topline="true" bottomline="true">
25208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25211 \begin_layout Standard
25217 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25220 \begin_layout Standard
25221 nnn = SMALL or LARGE respectively according to the stack model used
25234 \begin_layout Standard
25235 In addition the following macros are defined when calling assembler:
25238 \begin_layout Standard
25240 \begin_inset Tabular
25241 <lyxtabular version="3" rows="4" columns="2">
25243 <column alignment="center" valignment="top" leftline="true" width="0">
25244 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25245 <row topline="true" bottomline="true">
25246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25249 \begin_layout Standard
25255 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25258 \begin_layout Standard
25265 <row topline="true">
25266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25269 \begin_layout Standard
25275 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25278 \begin_layout Standard
25279 MCU Identification.
25284 is the microcontrol identification number, i.e.
25291 <row topline="true">
25292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25295 \begin_layout Standard
25301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25304 \begin_layout Standard
25305 nnn = SMALL or LARGE respectively according to the memory model used for
25312 <row topline="true" bottomline="true">
25313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25316 \begin_layout Standard
25322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25325 \begin_layout Standard
25326 nnn = SMALL or LARGE respectively according to the stack model used
25339 \begin_layout Subsection
25343 \begin_layout Standard
25345 \begin_inset LatexCommand \index{PIC16}
25349 port uses the following directories for searching header files and libraries.
25352 \begin_layout Standard
25354 \begin_inset Tabular
25355 <lyxtabular version="3" rows="3" columns="4">
25357 <column alignment="center" valignment="top" leftline="true" width="0">
25358 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25359 <column alignment="center" valignment="top" width="0">
25360 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25361 <row topline="true" bottomline="true">
25362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25365 \begin_layout Standard
25371 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25374 \begin_layout Standard
25380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25383 \begin_layout Standard
25389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25392 \begin_layout Standard
25399 <row topline="true">
25400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25403 \begin_layout Standard
25404 PREFIX/sdcc/include/pic16
25409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25412 \begin_layout Standard
25413 PIC16 specific headers
25418 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25421 \begin_layout Standard
25427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25430 \begin_layout Standard
25437 <row topline="true" bottomline="true">
25438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25441 \begin_layout Standard
25442 PREFIX/sdcc/lib/pic16
25447 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25450 \begin_layout Standard
25451 PIC16 specific libraries
25456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25459 \begin_layout Standard
25465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25468 \begin_layout Standard
25482 \begin_layout Subsection
25484 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
25491 \begin_layout Standard
25493 \begin_inset LatexCommand \index{PIC16}
25497 port currently supports the following pragmas:
25500 \begin_layout Description
25502 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
25506 This forces the code generator to initialize the stack & frame pointers
25507 at a specific address.
25508 This is an ad hoc solution for cases where no STACK directive is available
25509 in the linker script or gplink is not instructed to create a stack section.
25512 stack pragma should be used only once in a project.
25513 Multiple pragmas may result in indeterminate behaviour of the program.
25517 \begin_layout Standard
25518 The old format (ie.
25519 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
25520 cross page boundaries (or even exceed the available data RAM) and crash
25522 Make sure that stack does not cross page boundaries when using the SMALL
25530 The format is as follows:
25535 \begin_layout LyX-Code
25536 #pragma stack bottom_address [stack_size]
25541 \begin_layout Standard
25546 is the lower bound of the stack section.
25547 The stack pointer initially will point at address (bottom_address+stack_size-1).
25550 \begin_layout LyX-Code
25554 \begin_layout LyX-Code
25558 \begin_layout LyX-Code
25559 /* initializes stack of 100 bytes at RAM address 0x200 */
25562 \begin_layout LyX-Code
25563 #pragma stack 0x200 100
25566 \begin_layout Standard
25567 If the stack_size field is omitted then a stack is created with the default
25569 This size might be enough for most programs, but its not enough for operations
25570 with deep function nesting or excessive stack usage.
25573 \begin_layout Description
25575 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
25579 Force a function to a static FLASH address.
25582 \begin_layout LyX-Code
25586 \begin_layout LyX-Code
25590 \begin_layout LyX-Code
25591 /* place function test_func at 0x4000 */
25594 \begin_layout LyX-Code
25595 #pragma code test_func 0x4000
25598 \begin_layout LyX-Code
25602 \begin_layout Description
25603 library instructs the linker to use a library module.
25608 \begin_layout LyX-Code
25609 #pragma library module_name
25612 \begin_layout Standard
25617 can be any library or object file (including its path).
25618 Note that there are four reserved keywords which have special meaning.
25622 \begin_layout Standard
25624 \begin_inset Tabular
25625 <lyxtabular version="3" rows="6" columns="3">
25627 <column alignment="center" valignment="top" leftline="true" width="0">
25628 <column alignment="block" valignment="top" leftline="true" width="20page%">
25629 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
25630 <row topline="true" bottomline="true">
25631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25634 \begin_layout Standard
25640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25643 \begin_layout Standard
25649 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25652 \begin_layout Standard
25659 <row topline="true">
25660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25663 \begin_layout Standard
25671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25674 \begin_layout Standard
25675 ignore all library pragmas
25680 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25683 \begin_layout Standard
25692 <row topline="true">
25693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25696 \begin_layout Standard
25704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25707 \begin_layout Standard
25713 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25716 \begin_layout Standard
25727 <row topline="true">
25728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25731 \begin_layout Standard
25739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25742 \begin_layout Standard
25743 link the Math libarary
25748 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25751 \begin_layout Standard
25762 <row topline="true">
25763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25766 \begin_layout Standard
25774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25777 \begin_layout Standard
25778 link the I/O library
25783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25786 \begin_layout Standard
25797 <row topline="true" bottomline="true">
25798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25801 \begin_layout Standard
25809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25812 \begin_layout Standard
25813 link the debug library
25818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25821 \begin_layout Standard
25838 * is the device number, i.e.
25839 452 for PIC18F452 MCU.
25842 \begin_layout Standard
25843 This feature allows for linking with specific libraries withoug having to
25844 explicit name them in the command line.
25849 keyword will reject all modules specified by the library pragma.
25852 \begin_layout Description
25853 udata The pragma udata instructs the compiler to emit code so that linker
25854 will place a variable at a specific memory bank.
25857 \begin_layout LyX-Code
25861 \begin_layout LyX-Code
25865 \begin_layout LyX-Code
25866 /* places variable foo at bank2 */
25869 \begin_layout LyX-Code
25870 #pragma udata bank2 foo
25873 \begin_layout LyX-Code
25877 \begin_layout Standard
25878 In order for this pragma to work extra SECTION directives should be added
25879 in the .lkr script.
25880 In the following example a sample .lkr file is shown:
25883 \begin_layout LyX-Code
25887 \begin_layout LyX-Code
25888 // Sample linker script for the PIC18F452 processor
25891 \begin_layout LyX-Code
25895 \begin_layout LyX-Code
25896 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
25899 \begin_layout LyX-Code
25900 CODEPAGE NAME=page START=0x2A END=0x7FFF
25903 \begin_layout LyX-Code
25904 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
25907 \begin_layout LyX-Code
25908 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
25911 \begin_layout LyX-Code
25912 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
25915 \begin_layout LyX-Code
25916 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
25919 \begin_layout LyX-Code
25920 ACCESSBANK NAME=accessram START=0x0 END=0x7F
25923 \begin_layout LyX-Code
25927 \begin_layout LyX-Code
25928 DATABANK NAME=gpr0 START=0x80 END=0xFF
25931 \begin_layout LyX-Code
25932 DATABANK NAME=gpr1 START=0x100 END=0x1FF
25935 \begin_layout LyX-Code
25936 DATABANK NAME=gpr2 START=0x200 END=0x2FF
25939 \begin_layout LyX-Code
25940 DATABANK NAME=gpr3 START=0x300 END=0x3FF
25943 \begin_layout LyX-Code
25944 DATABANK NAME=gpr4 START=0x400 END=0x4FF
25947 \begin_layout LyX-Code
25948 DATABANK NAME=gpr5 START=0x500 END=0x5FF
25951 \begin_layout LyX-Code
25952 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
25955 \begin_layout LyX-Code
25959 \begin_layout LyX-Code
25960 SECTION NAME=CONFIG ROM=config
25963 \begin_layout LyX-Code
25967 \begin_layout LyX-Code
25968 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
25971 \begin_layout LyX-Code
25972 SECTION NAME=bank1 RAM=gpr1 # should be added to link
25975 \begin_layout LyX-Code
25976 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
25979 \begin_layout LyX-Code
25980 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
25983 \begin_layout LyX-Code
25984 SECTION NAME=bank4 RAM=gpr4
25987 \begin_layout LyX-Code
25988 SECTION NAME=bank5 RAM=gpr5
25991 \begin_layout Standard
25992 The linker will recognise the section name set in the pragma statement and
25993 will position the variable at the memory bank set with the RAM field at
25994 the SECTION line in the linker script file.
25997 \begin_layout Subsection
25999 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
26006 \begin_layout Standard
26007 There is one main header file
26008 \begin_inset LatexCommand \index{PIC16!Header files}
26012 that can be included to the source files using the pic16
26013 \begin_inset LatexCommand \index{PIC16}
26023 This header file contains the definitions for the processor special registers,
26024 so it is necessary if the source accesses them.
26025 It can be included by adding the following line in the beginning of the
26029 \begin_layout LyX-Code
26030 #include <pic18fregs.h>
26033 \begin_layout Standard
26034 The specific microcontroller is selected within the pic18fregs.h automatically,
26035 so the same source can be used with a variety of devices.
26038 \begin_layout Subsection
26042 \begin_layout Standard
26044 \begin_inset LatexCommand \index{PIC16!Libraries}
26049 \begin_inset LatexCommand \index{PIC16}
26053 port depends on are the microcontroller device libraries which contain
26054 the symbol definitions for the microcontroller special function registers.
26055 These libraries have the format pic18fxxxx.lib, where
26059 is the microcontroller identification number.
26060 The specific library is selected automatically by the compiler at link
26061 stage according to the selected device.
26064 \begin_layout Standard
26065 Libraries are created with gplib which is part of the gputils package
26066 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
26073 \begin_layout Subsubsection*
26074 Building the libraries
26077 \begin_layout Standard
26078 Before using SDCC/pic16 there are some libraries that need to be compiled.
26079 This process is not done automatically by SDCC since not all users use
26080 SDCC for pic16 projects.
26081 So each user should compile the libraries separately.
26084 \begin_layout Standard
26085 The steps to compile the pic16 libraries under Linux and Mac OS X are:
26088 \begin_layout LyX-Code
26089 cd device/lib/pic16
26092 \begin_layout LyX-Code
26096 \begin_layout LyX-Code
26100 \begin_layout LyX-Code
26104 \begin_layout LyX-Code
26108 \begin_layout LyX-Code
26109 su -c 'make install' # install the libraries, you need the root password
26112 \begin_layout Standard
26113 If you need to install the headers too, do:
26116 \begin_layout LyX-Code
26120 \begin_layout LyX-Code
26121 su -c 'make install' # install the headers, you need the root password
26124 \begin_layout Standard
26125 There exist a special target to build the I/O libraries.
26126 This target is not automatically build because it will build the I/O library
26132 This way building will take quite a lot of time.
26133 Users are advised to edit the
26135 device/lib/pic16/pics.build
26137 file and then execute:
26140 \begin_layout LyX-Code
26144 \begin_layout Subsection
26145 Adding New Devices to the Port
26148 \begin_layout Standard
26149 Adding support for a new 16
26153 \begin_layout Standard
26162 bit PIC MCU requires the following steps:
26165 \begin_layout Enumerate
26166 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
26170 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
26174 \begin_layout Enumerate
26177 mv picDEVICE.h /path/to/sdcc/device/include/pic16
26180 \begin_layout Enumerate
26183 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
26186 \begin_layout Enumerate
26189 /path/to/sdcc/device/lib/pic16/pics.all
26197 Note: No 18f prefix here!
26200 \begin_layout Enumerate
26203 /path/to/sdcc/device/lib/pic16/libio/*.ignore
26207 Add your DEVICE if it does not compile in
26222 \begin_layout Enumerate
26225 /path/to/sdcc/device/include/pic16/pic18fregs.h
26228 The file format is self-explanatory, just add
26232 #elif defined(picDEVICE)
26234 # include <picDEVICE.h>
26238 at the right place (keep it sorted).
26241 \begin_layout Enumerate
26244 /path/to/sdcc/src/pic16/devices.inc
26247 Copy and modify an existing entry and insert it at the correct place (keep
26249 The file is hardly documented, look at the entries for the 18f2221...
26252 \begin_layout Enumerate
26253 Recompile SDCC, including the pic16 libraries.
26256 \begin_layout Subsection
26260 \begin_layout Standard
26261 The following memory models are supported by the PIC16 port:
26264 \begin_layout Itemize
26268 \begin_layout Itemize
26272 \begin_layout Standard
26273 Memory model affects the default size of pointers within the source.
26274 The sizes are shown in the next table:
26277 \begin_layout Standard
26279 \begin_inset Tabular
26280 <lyxtabular version="3" rows="3" columns="3">
26282 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26283 <column alignment="center" valignment="top" leftline="true" width="0">
26284 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26285 <row topline="true" bottomline="true">
26286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26289 \begin_layout Standard
26290 Pointer sizes according to memory model
26295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26298 \begin_layout Standard
26304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26307 \begin_layout Standard
26314 <row topline="true" bottomline="true">
26315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26318 \begin_layout Standard
26324 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26327 \begin_layout Standard
26333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26336 \begin_layout Standard
26343 <row topline="true" bottomline="true">
26344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26347 \begin_layout Standard
26353 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
26356 \begin_layout Standard
26362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26365 \begin_layout Standard
26379 \begin_layout Standard
26380 It is advisable that all sources within a project are compiled with the
26382 If one wants to override the default memory model, this can be done by
26383 declaring a pointer as
26392 Far selects large memory model's pointers, while near selects small memory
26396 \begin_layout Standard
26397 The standard device libraries (see
26398 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
26402 ) contain no reference to pointers, so they can be used with both memory
26406 \begin_layout Subsection
26410 \begin_layout Standard
26412 \begin_inset LatexCommand \index{PIC16!stack}
26416 implementation for the PIC16 port uses two indirect registers, FSR1 and
26420 \begin_layout Description
26421 FSR1 is assigned as stack pointer
26424 \begin_layout Description
26425 FSR2 is assigned as frame pointer
26428 \begin_layout Standard
26429 The following stack models are supported by the PIC16 port
26432 \begin_layout Itemize
26440 \begin_layout Itemize
26448 \begin_layout Standard
26453 model means that only the FSRxL byte is used to access stack and frame,
26460 uses both FSRxL and FSRxH registers.
26461 The following table shows the stack/frame pointers sizes according to stack
26462 model and the maximum space they can address:
26465 \begin_layout Standard
26467 \begin_inset Tabular
26468 <lyxtabular version="3" rows="3" columns="3">
26470 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26471 <column alignment="center" valignment="top" leftline="true" width="0">
26472 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26473 <row topline="true" bottomline="true">
26474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26477 \begin_layout Standard
26478 Stack & Frame pointer sizes according to stack model
26483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26486 \begin_layout Standard
26492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26495 \begin_layout Standard
26502 <row topline="true">
26503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26506 \begin_layout Standard
26512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26515 \begin_layout Standard
26521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26524 \begin_layout Standard
26531 <row topline="true" bottomline="true">
26532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26535 \begin_layout Standard
26541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26544 \begin_layout Standard
26550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26553 \begin_layout Standard
26567 \begin_layout Standard
26572 stack model is currently not working properly throughout the code generator.
26573 So its use is not advised.
26574 Also there are some other points that need special care:
26579 \begin_layout Enumerate
26580 Do not create stack sections with size more than one physical bank (that
26584 \begin_layout Enumerate
26585 Stack sections should no cross physical bank limits (i.e.
26586 #pragma stack 0x50 0x100)
26589 \begin_layout Standard
26590 These limitations are caused by the fact that only FSRxL is modified when
26591 using SMALL stack model, so no more than 256 bytes of stack can be used.
26592 This problem will disappear after LARGE model is fully implemented.
26595 \begin_layout Subsection
26599 \begin_layout Standard
26600 In addition to the standard SDCC function keywords, PIC16
26601 \begin_inset LatexCommand \index{PIC16}
26605 port makes available two more:
26608 \begin_layout Description
26610 \begin_inset LatexCommand \index{PIC16!wparam}
26614 Use the WREG to pass one byte of the first function argument.
26615 This improves speed but you may not use this for functions with arguments
26616 that are called via function pointers, otherwise the first byte of the
26617 first parameter will get lost.
26621 \begin_layout LyX-Code
26622 void func_wparam(int a) wparam
26625 \begin_layout LyX-Code
26629 \begin_layout LyX-Code
26630 /* WREG hold the lower part of a */
26633 \begin_layout LyX-Code
26634 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
26638 \begin_layout LyX-Code
26642 \begin_layout LyX-Code
26646 \begin_layout Description
26648 \begin_inset LatexCommand \index{PIC16!shadowregs}
26652 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
26653 hardware shadow registers which hold the values of WREG, STATUS and BSR
26655 This can be done by adding the keyword
26663 keyword in the function's header.
26666 \begin_layout LyX-Code
26667 void isr_shadow(void) shadowregs interrupt 1
26670 \begin_layout LyX-Code
26674 \begin_layout LyX-Code
26678 \begin_layout LyX-Code
26682 \begin_layout Standard
26687 instructs the code generator not to store/restore WREG, STATUS, BSR when
26688 entering/exiting the ISR.
26691 \begin_layout Subsection
26692 Function return values
26695 \begin_layout Standard
26696 Return values from functions are placed to the appropriate registers following
26697 a modified Microchip policy optimized for SDCC.
26698 The following table shows these registers:
26701 \begin_layout Standard
26703 \begin_inset Tabular
26704 <lyxtabular version="3" rows="6" columns="2">
26706 <column alignment="center" valignment="top" leftline="true" width="0">
26707 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26708 <row topline="true" bottomline="true">
26709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26712 \begin_layout Standard
26718 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26721 \begin_layout Standard
26722 destination register
26728 <row topline="true">
26729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26732 \begin_layout Standard
26738 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26741 \begin_layout Standard
26748 <row topline="true">
26749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26752 \begin_layout Standard
26758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26761 \begin_layout Standard
26768 <row topline="true">
26769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26772 \begin_layout Standard
26778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26781 \begin_layout Standard
26788 <row topline="true">
26789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26792 \begin_layout Standard
26798 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26801 \begin_layout Standard
26802 FSR0L:PRODH:PRODL:WREG
26808 <row topline="true" bottomline="true">
26809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26812 \begin_layout Standard
26818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26821 \begin_layout Standard
26822 on stack, FSR0 points to the beginning
26835 \begin_layout Subsection
26839 \begin_layout Standard
26841 \begin_inset LatexCommand \index{PIC16!interrupt}
26845 service routine (ISR) is declared using the
26852 \begin_layout LyX-Code
26853 void isr(void) interrupt
26858 \begin_layout LyX-Code
26862 \begin_layout LyX-Code
26866 \begin_layout LyX-Code
26870 \begin_layout Standard
26875 is the interrupt number, which for PIC18F devices can be:
26878 \begin_layout Standard
26880 \begin_inset Tabular
26881 <lyxtabular version="3" rows="4" columns="3">
26883 <column alignment="center" valignment="top" leftline="true" width="0">
26884 <column alignment="center" valignment="top" leftline="true" width="0">
26885 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26886 <row topline="true" bottomline="true">
26887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26890 \begin_layout Standard
26898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26901 \begin_layout Standard
26907 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26910 \begin_layout Standard
26911 Interrupt Vector Address
26917 <row topline="true">
26918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26921 \begin_layout Standard
26927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26930 \begin_layout Standard
26936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26939 \begin_layout Standard
26946 <row topline="true">
26947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26950 \begin_layout Standard
26965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26968 \begin_layout Standard
26978 HIGH priority interrupts
26983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26986 \begin_layout Standard
26993 <row topline="true" bottomline="true">
26994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26997 \begin_layout Standard
27003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27006 \begin_layout Standard
27007 LOW priority interrupts
27012 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27015 \begin_layout Standard
27029 \begin_layout Standard
27030 When generating assembly code for ISR the code generator places a
27036 Interrupt Vector Address
27038 which points at the genetated ISR.
27039 This single GOTO instruction is part of an automatically generated
27041 interrupt entry point
27044 The actuall ISR code is placed as normally would in the code space.
27045 Upon interrupt request, the GOTO instruction is executed which jumps to
27047 When declaring interrupt functions as _naked this GOTO instruction is
27052 The whole interrupt functions is therefore placed at the Interrupt Vector
27053 Address of the specific interrupt.
27054 This is not a problem for the LOW priority interrupts, but it is a problem
27055 for the RESET and the HIGH priority interrupts because code may be written
27056 at the next interrupt's vector address and cause undeterminate program
27057 behaviour if that interrupt is raised.
27061 \begin_layout Standard
27062 This is not a problem when
27065 \begin_layout Enumerate
27066 this is a HIGH interrupt ISR and LOW interrupts are
27073 \begin_layout Enumerate
27074 when the ISR is small enough not to reach the next interrupt's vector address.
27082 \begin_layout Standard
27088 This way a function is generated similar to an ISR, but it is not assigned
27092 \begin_layout Standard
27093 When entering an interrupt, currently the PIC16
27094 \begin_inset LatexCommand \index{PIC16}
27098 port automatically saves the following registers:
27101 \begin_layout Itemize
27105 \begin_layout Itemize
27109 \begin_layout Itemize
27113 \begin_layout Itemize
27114 PROD (PRODL and PRODH)
27117 \begin_layout Itemize
27118 FSR0 (FSR0L and FSR0H)
27121 \begin_layout Standard
27122 These registers are restored upon return from the interrupt routine.
27126 \begin_layout Standard
27127 NOTE that when the _naked attribute is specified for an interrupt routine,
27128 then NO registers are stored or restored.
27136 \begin_layout Subsection
27140 \begin_layout Standard
27141 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
27142 There are 3 types of generic pointers currently implemented data, code
27143 and eeprom pointers.
27144 They are differentiated by the value of the 7th and 6th bits of the upper
27148 \begin_layout Standard
27150 \begin_inset Tabular
27151 <lyxtabular version="3" rows="5" columns="5">
27153 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27154 <column alignment="center" valignment="top" width="0">
27155 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27156 <column alignment="center" valignment="top" width="0">
27157 <column alignment="left" valignment="top" rightline="true" width="0">
27158 <row topline="true" bottomline="true">
27159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27162 \begin_layout Standard
27168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27171 \begin_layout Standard
27177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27180 \begin_layout Standard
27186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27189 \begin_layout Standard
27190 rest of the pointer
27195 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27198 \begin_layout Standard
27205 <row topline="true" bottomline="true">
27206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27209 \begin_layout Standard
27215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27218 \begin_layout Standard
27224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27227 \begin_layout Standard
27233 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27236 \begin_layout Standard
27241 uuuuuu uuuuxxxx xxxxxxxx
27246 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27249 \begin_layout Standard
27250 a 12-bit data pointer in data RAM memory
27256 <row bottomline="true">
27257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27260 \begin_layout Standard
27266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27269 \begin_layout Standard
27275 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27278 \begin_layout Standard
27284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27287 \begin_layout Standard
27292 uxxxxx xxxxxxxx xxxxxxxx
27297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27300 \begin_layout Standard
27301 a 21-bit code pointer in FLASH memory
27307 <row bottomline="true">
27308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27311 \begin_layout Standard
27317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27320 \begin_layout Standard
27326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27329 \begin_layout Standard
27335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27338 \begin_layout Standard
27343 uuuuuu uuuuuuxx xxxxxxxx
27348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27351 \begin_layout Standard
27352 a 10-bit eeprom pointer in EEPROM memory
27358 <row bottomline="true">
27359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27362 \begin_layout Standard
27368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27371 \begin_layout Standard
27377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27380 \begin_layout Standard
27386 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27389 \begin_layout Standard
27394 xxxxxx xxxxxxxx xxxxxxxx
27399 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27402 \begin_layout Standard
27403 unimplemented pointer type
27416 \begin_layout Standard
27417 Generic pointer are read and written with a set of library functions which
27418 read/write 1, 2, 3, 4 bytes.
27421 \begin_layout Subsection
27425 \begin_layout Subsubsection
27426 Standard I/O Streams
27429 \begin_layout Standard
27434 the type FILE is defined as:
27437 \begin_layout LyX-Code
27438 typedef char * FILE;
27441 \begin_layout Standard
27442 This type is the stream type implemented I/O in the PIC18F devices.
27443 Also the standard input and output streams are declared in stdio.h:
27446 \begin_layout LyX-Code
27447 extern FILE * stdin;
27450 \begin_layout LyX-Code
27451 extern FILE * stdout;
27454 \begin_layout Standard
27455 The FILE type is actually a generic pointer which defines one more type
27456 of generic pointers, the
27461 This new type has the format:
27464 \begin_layout Standard
27466 \begin_inset Tabular
27467 <lyxtabular version="3" rows="2" columns="7">
27469 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27470 <column alignment="center" valignment="top" width="0">
27471 <column alignment="center" valignment="top" leftline="true" width="0">
27472 <column alignment="center" valignment="top" leftline="true" width="0">
27473 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27474 <column alignment="center" valignment="top" width="0">
27475 <column alignment="left" valignment="top" rightline="true" width="0">
27476 <row topline="true" bottomline="true">
27477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27480 \begin_layout Standard
27486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27489 \begin_layout Standard
27495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27498 \begin_layout Standard
27504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27507 \begin_layout Standard
27513 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27516 \begin_layout Standard
27522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27525 \begin_layout Standard
27526 rest of the pointer
27531 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27534 \begin_layout Standard
27541 <row topline="true" bottomline="true">
27542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27545 \begin_layout Standard
27551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27554 \begin_layout Standard
27560 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27563 \begin_layout Standard
27569 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27572 \begin_layout Standard
27578 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27581 \begin_layout Standard
27587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27590 \begin_layout Standard
27600 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27603 \begin_layout Standard
27604 upper byte high nubble is 0x2n, the rest are zeroes
27617 \begin_layout Standard
27618 Currently implemented there are 3 types of streams defined:
27621 \begin_layout Standard
27623 \begin_inset Tabular
27624 <lyxtabular version="3" rows="4" columns="4">
27626 <column alignment="center" valignment="top" leftline="true" width="0">
27627 <column alignment="center" valignment="top" leftline="true" width="0">
27628 <column alignment="center" valignment="top" leftline="true" width="0">
27629 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27630 <row topline="true" bottomline="true">
27631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27634 \begin_layout Standard
27640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27643 \begin_layout Standard
27649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27652 \begin_layout Standard
27658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27661 \begin_layout Standard
27668 <row topline="true">
27669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27672 \begin_layout Standard
27678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27681 \begin_layout Standard
27689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27692 \begin_layout Standard
27698 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27701 \begin_layout Standard
27702 Writes/Reads characters via the USART peripheral
27708 <row topline="true">
27709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27712 \begin_layout Standard
27718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27721 \begin_layout Standard
27729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27732 \begin_layout Standard
27738 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27741 \begin_layout Standard
27742 Writes/Reads characters via the MSSP peripheral
27748 <row topline="true" bottomline="true">
27749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27752 \begin_layout Standard
27758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27761 \begin_layout Standard
27769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27772 \begin_layout Standard
27778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27781 \begin_layout Standard
27782 Writes/Reads characters via used defined functions
27795 \begin_layout Standard
27796 The stream identifiers are declared as macros in the stdio.h header.
27799 \begin_layout Standard
27800 In the libc library there exist the functions that are used to write to
27801 each of the above streams.
27805 \begin_layout Description
27810 \begin_layout Standard
27819 _stream_usart_putchar writes a character at the USART stream
27822 \begin_layout Description
27827 \begin_layout Standard
27836 _stream_mssp_putchar writes a character at the MSSP stream
27839 \begin_layout Description
27840 putchar dummy function.
27841 This writes a character to a user specified manner.
27844 \begin_layout Standard
27845 In order to increase performance
27849 is declared in stdio.h as having its parameter in WREG (it has the wparam
27851 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
27852 in a user-friendly way.
27857 is the name of the variable that holds the character to print.
27858 An example follows:
27861 \begin_layout LyX-Code
27862 #include <pic18fregs.h>
27871 \begin_layout LyX-Code
27875 \begin_layout LyX-Code
27876 PORTA = c; /* dump character c to PORTA */
27879 \begin_layout LyX-Code
27887 \begin_layout LyX-Code
27891 \begin_layout LyX-Code
27892 stdout = STREAM_USER; /* this is not necessary, since stdout points
27895 \begin_layout LyX-Code
27896 * by default to STREAM_USER */
27899 \begin_layout LyX-Code
27901 \begin_inset Quotes sld
27904 This is a printf test
27907 \begin_inset Quotes srd
27913 \begin_layout LyX-Code
27917 \begin_layout LyX-Code
27921 \begin_layout Subsubsection
27925 \begin_layout Standard
27926 PIC16 contains an implementation of the printf-family of functions.
27927 There exist the following functions:
27930 \begin_layout LyX-Code
27931 extern unsigned int sprintf(char *buf, char *fmt, ...);
27934 \begin_layout LyX-Code
27935 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
27938 \begin_layout LyX-Code
27942 \begin_layout LyX-Code
27943 extern unsigned int printf(char *fmt, ...);
27946 \begin_layout LyX-Code
27947 extern unsigned int vprintf(char *fmt, va_lista ap);
27950 \begin_layout LyX-Code
27954 \begin_layout LyX-Code
27955 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
27958 \begin_layout LyX-Code
27959 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
27962 \begin_layout Standard
27963 For sprintf and vsprintf
27967 should normally be a data pointer where the resulting string will be placed.
27968 No range checking is done so the user should allocate the necessery buffer.
27969 For fprintf and vfprintf
27973 should be a stream pointer (i.e.
27974 stdout, STREAM_MSSP, etc...).
27977 \begin_layout Subsubsection
27981 \begin_layout Standard
27982 The PIC18F family of microcontrollers supports a number of interrupt sources.
27983 A list of these interrupts is shown in the following table:
27986 \begin_layout Standard
27988 \begin_inset Tabular
27989 <lyxtabular version="3" rows="11" columns="4">
27991 <column alignment="left" valignment="top" leftline="true" width="0">
27992 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27993 <column alignment="left" valignment="top" leftline="true" width="0">
27994 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27995 <row topline="true" bottomline="true">
27996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27999 \begin_layout Standard
28005 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28008 \begin_layout Standard
28014 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28017 \begin_layout Standard
28023 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28026 \begin_layout Standard
28033 <row topline="true">
28034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28037 \begin_layout Standard
28043 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28046 \begin_layout Standard
28047 PORTB change interrupt
28052 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28055 \begin_layout Standard
28061 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28064 \begin_layout Standard
28065 EEPROM/FLASH write complete interrupt
28071 <row topline="true">
28072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28075 \begin_layout Standard
28081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28084 \begin_layout Standard
28085 INT0 external interrupt
28090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28093 \begin_layout Standard
28099 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28102 \begin_layout Standard
28103 Bus collision interrupt
28109 <row topline="true">
28110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28113 \begin_layout Standard
28119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28122 \begin_layout Standard
28123 INT1 external interrupt
28128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28131 \begin_layout Standard
28137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28140 \begin_layout Standard
28141 Low voltage detect interrupt
28147 <row topline="true">
28148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28151 \begin_layout Standard
28157 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28160 \begin_layout Standard
28161 INT2 external interrupt
28166 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28169 \begin_layout Standard
28175 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28178 \begin_layout Standard
28179 Parallel slave port interrupt
28185 <row topline="true">
28186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28189 \begin_layout Standard
28195 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28198 \begin_layout Standard
28199 CCP1 module interrupt
28204 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28207 \begin_layout Standard
28213 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28216 \begin_layout Standard
28217 AD convertion complete interrupt
28223 <row topline="true">
28224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28227 \begin_layout Standard
28233 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28236 \begin_layout Standard
28237 CCP2 module interrupt
28242 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28245 \begin_layout Standard
28251 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28254 \begin_layout Standard
28255 USART receive interrupt
28261 <row topline="true">
28262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28265 \begin_layout Standard
28271 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28274 \begin_layout Standard
28275 TMR0 overflow interrupt
28280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28283 \begin_layout Standard
28289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28292 \begin_layout Standard
28293 USART transmit interrupt
28299 <row topline="true">
28300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28303 \begin_layout Standard
28309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28312 \begin_layout Standard
28313 TMR1 overflow interrupt
28318 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28321 \begin_layout Standard
28327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28330 \begin_layout Standard
28331 SSP receive/transmit interrupt
28337 <row topline="true">
28338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28341 \begin_layout Standard
28347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28350 \begin_layout Standard
28351 TMR2 matches PR2 interrupt
28356 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28359 \begin_layout Standard
28365 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28368 \begin_layout Standard
28375 <row topline="true" bottomline="true">
28376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28379 \begin_layout Standard
28385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28388 \begin_layout Standard
28389 TMR3 overflow interrupt
28394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28397 \begin_layout Standard
28403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28406 \begin_layout Standard
28420 \begin_layout Standard
28421 The prototypes for these names are defined in the header file
28428 \begin_layout Standard
28429 In order to simplify signal handling, a number of macros is provided:
28433 \labelwidthstring 00.00.0000
28434 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
28435 high priority interrupts.
28440 is the function name to use.
28444 \labelwidthstring 00.00.0000
28445 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
28446 low priority interrupt.
28451 is the function name to use.
28455 \labelwidthstring 00.00.0000
28456 DEF_HANDLER(sig,handler) define a handler for signal
28462 \labelwidthstring 00.00.0000
28463 END_DEF end the declaration of the dispatch table.
28466 \begin_layout Standard
28467 Additionally there are two more macros to simplify the declaration of the
28472 \labelwidthstring 00.00.0000
28475 SIGHANDLER(handler)
28477 this declares the function prototype for the
28485 \labelwidthstring 00.00.0000
28486 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
28489 \begin_layout Standard
28490 An example of using the macros above is shown below:
28493 \begin_layout LyX-Code
28494 #include <pic18fregs.h>
28497 \begin_layout LyX-Code
28498 #include <signal.h>
28502 DEF_INTHIGH(high_int)
28505 \begin_layout LyX-Code
28506 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
28509 \begin_layout LyX-Code
28510 DEF_HANDLER(SIG_BCOL, _bcol_handler)
28513 \begin_layout LyX-Code
28518 SIGHANDLER(_tmr0_handler)
28521 \begin_layout LyX-Code
28525 \begin_layout LyX-Code
28526 /* action to be taken when timer 0 overflows */
28529 \begin_layout LyX-Code
28534 SIGHANDLERNAKED(_bcol_handler)
28537 \begin_layout LyX-Code
28541 \begin_layout LyX-Code
28545 \begin_layout LyX-Code
28546 /* action to be taken when bus collision occurs */
28549 \begin_layout LyX-Code
28553 \begin_layout LyX-Code
28557 \begin_layout LyX-Code
28561 \begin_layout Standard
28566 Special care should be taken when using the above scheme:
28569 \begin_layout Itemize
28570 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
28573 \begin_layout Itemize
28574 when declaring SIGHANDLERNAKED handler never forget to use
28578 for proper returning.
28581 \begin_layout Subsection
28585 \begin_layout Standard
28586 Here you can find some general tips for compiling programs with SDCC/pic16.
28589 \begin_layout Subsubsection
28593 \begin_layout Standard
28595 \begin_inset LatexCommand \index{PIC16!stack}
28599 size (that is 64 bytes) probably is enough for many programs.
28600 One must take care that when there are many levels of function nesting,
28601 or there is excessive usage of stack, its size should be extended.
28602 An example of such a case is the printf/sprintf family of functions.
28603 If you encounter problems like not being able to print integers, then you
28604 need to set the stack size around the maximum (256 for small stack model).
28605 The following diagram shows what happens when calling printf to print an
28609 \begin_layout LyX-Code
28610 printf () --> ltoa () --> ultoa () --> divschar ()
28613 \begin_layout Standard
28614 It is should be understood that stack is easily consumed when calling complicate
28616 Using command line arguments like -
28620 \begin_layout Standard
28629 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
28631 Other ways to reduce stack usage may exist.
28634 \begin_layout Subsection
28638 \begin_layout Standard
28639 The PIC16 Port currently does not pass SDCC's regression test
28640 \begin_inset LatexCommand \index{Regression test (PIC16)}
28645 \begin_inset LatexCommand \ref{sec:Quality-control}
28649 ) and thus the snapshot build regression tests for the PIC16 target are
28650 currently disabled for all hosts
28655 \begin_layout Chapter
28659 \begin_layout Standard
28660 There are several approaches to debugging your code.
28661 This chapter is meant to show your options and to give detail on some of
28666 When writing your code:
28669 \begin_layout Itemize
28670 write your code with debugging in mind (avoid duplicating code, put conceptually
28671 similar variables into structs, use structured code, have strategic points
28672 within your code where all variables are consistent, ...)
28675 \begin_layout Itemize
28676 run a syntax-checking tool like splint
28677 \begin_inset LatexCommand \index{splint (syntax checking tool)}
28682 \begin_inset LatexCommand \index{lint (syntax checking tool)}
28690 \begin_layout Standard
28700 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28707 \begin_layout Itemize
28708 for the high level code use a C-compiler (like f.e.
28709 GCC) to compile run and debug the code on your host.
28714 \begin_layout Standard
28724 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28728 ) on how to handle syntax extensions like __xdata, __at(), ...
28732 \begin_layout Itemize
28733 use another C-compiler to compile code for your target.
28734 Always an option but not recommended:) And not very likely to help you.
28735 If you seriously consider walking this path you should at least occasionally
28736 check portability of your code.
28737 Most commercial compiler vendors will offer an evaluation version so you
28738 can test compile your code or snippets of your code.
28741 \begin_layout Standard
28742 Debugging on a simulator:
28745 \begin_layout Itemize
28746 there is a separate section about SDCDB (section
28747 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
28754 \begin_layout Itemize
28755 or (8051 specific) use a freeware/commercial simulator which interfaces
28757 \begin_inset LatexCommand \index{AOMF, AOMF51}
28762 \begin_inset LatexCommand \ref{OMF file}
28766 ) optionally generated by SDCC.
28769 \begin_layout Standard
28770 Debugging On-target:
28773 \begin_layout Itemize
28774 use a MCU port pin to serially output debug data to the RS232 port of your
28776 You'll probably want some level shifting device typically involving a MAX232
28778 If the hardware serial port of the MCU is not available search for 'Software
28779 UART' in your favourite search machine.
28782 \begin_layout Itemize
28783 use an on-target monitor.
28784 In this context a monitor is a small program which usually accepts commands
28785 via a serial line and allows to set program counter, to single step through
28786 a program and read/write memory locations.
28787 For the 8051 good examples of monitors are paulmon and cmon51 (see section
28789 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
28796 \begin_layout Itemize
28797 toggle MCU port pins at strategic points within your code and use an oscilloscop
28801 digital oscilloscope
28804 \begin_inset LatexCommand \index{Oscilloscope}
28808 with deep trace memory is really helpful especially if you have to debug
28809 a realtime application.
28810 If you need to monitor more pins than your oscilloscope provides you can
28811 sometimes get away with a small R-2R network.
28812 On a single channel oscilloscope you could f.e.
28813 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
28815 \begin_inset Formula $\Omega$
28818 resistor and the other one by a 5\InsetSpace ~
28820 \begin_inset Formula $\Omega$
28823 resistor to the oscilloscope probe (check output drive capability of the
28824 pins you want to monitor).
28825 If you need to monitor many more pins a
28832 \begin_layout Itemize
28846 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
28851 Usually very expensive.
28852 And very nice to have too.
28853 And usually locks you (for years...) to the devices the ICE can emulate.
28857 \begin_layout Itemize
28858 use a remote debugger.
28859 In most 8-bit systems the symbol information is not available on the target,
28860 and a complete debugger is too bulky for the target system.
28861 Therefore usually a debugger on the host system connects to an on-target
28862 debugging stub which accepts only primitive commands.
28865 Terms to enter into your favourite search engine could be 'remote debugging',
28866 'gdb stub' or 'inferior debugger'.
28870 \begin_layout Itemize
28871 use an on target hardware debugger.
28872 Some of the more modern MCUs include hardware support for setting break
28873 points and monitoring/changing variables by using dedicated hardware pins.
28874 This facility doesn't require additional code to run on the target and
28879 doesn't affect runtime behaviour until a breakpoint is hit.
28880 For the mcs51 most hardware debuggers use the AOMF
28881 \begin_inset LatexCommand \index{AOMF, AOMF51}
28886 \begin_inset LatexCommand \ref{OMF file}
28894 \begin_layout Standard
28898 \begin_layout Itemize
28899 if you are not familiar with any of the following terms you're likely to
28900 run into problems rather sooner than later:
28917 As an embedded programmer you
28921 to know them so why not look them up
28925 you have problems?)
28928 \begin_layout Itemize
28929 tell someone else about your problem (actually this is a surprisingly effective
28930 means to hunt down the bug even if the listener is not familiar with your
28932 As 'failure to communicate' is probably one of the job-induced deformations
28933 of an embedded programmer this is highly encouraged.
28936 \begin_layout Section
28937 Debugging with SDCDB
28938 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
28943 \begin_inset LatexCommand \index{SDCDB (debugger)}
28950 \begin_layout Standard
28951 SDCC is distributed with a source level debugger
28952 \begin_inset LatexCommand \index{Debugger}
28957 The debugger uses a command line interface, the command repertoire of the
28958 debugger has been kept as close to gdb
28959 \begin_inset LatexCommand \index{gdb}
28963 (the GNU debugger) as possible.
28964 The configuration and build process is part of the standard compiler installati
28965 on, which also builds and installs the debugger in the target directory
28966 specified during configuration.
28967 The debugger allows you debug BOTH at the C source and at the ASM source
28971 \begin_layout Subsection
28972 Compiling for Debugging
28975 \begin_layout Standard
28980 \begin_layout Standard
28990 \begin_inset LatexCommand \index{-\/-debug}
28994 option must be specified for all files for which debug information is to
28996 The compiler generates a .adb file for each of these files.
28997 The linker creates the .cdb
28998 \begin_inset LatexCommand \index{<file>.cdb}
29003 \begin_inset LatexCommand \index{<file>.adb}
29007 files and the address information.
29008 This .cdb is used by the debugger.
29011 \begin_layout Subsection
29012 How the Debugger Works
29015 \begin_layout Standard
29020 \begin_layout Standard
29029 -debug option is specified the compiler generates extra symbol information
29030 some of which are put into the assembler source and some are put into the
29032 Then the linker creates the .cdb file from the individual .adb files with
29033 the address information for the symbols.
29034 The debugger reads the symbolic information generated by the compiler &
29035 the address information generated by the linker.
29036 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
29037 execution is controlled by the debugger.
29038 When a command is issued for the debugger, it translates it into appropriate
29039 commands for the simulator.
29040 (Currently SDCDM only connects to the simulator but
29045 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
29049 is an effort to connect directly to the hardware.)
29052 \begin_layout Subsection
29053 Starting the Debugger SDCDB
29056 \begin_layout Standard
29057 The debugger can be started using the following command line.
29058 (Assume the file you are debugging has the file name foo).
29072 The debugger will look for the following files.
29075 \begin_layout Itemize
29076 foo.c - the source file.
29079 \begin_layout Itemize
29080 foo.cdb - the debugger symbol information file.
29083 \begin_layout Itemize
29084 foo.ihx - the Intel hex format
29085 \begin_inset LatexCommand \index{Intel hex format}
29092 \begin_layout Subsection
29093 SDCDB Command Line Options
29096 \begin_layout Itemize
29101 \begin_layout Standard
29110 -directory=<source file directory> this option can used to specify the directory
29112 The debugger will look into the directory list specified for source, cdb
29114 The items in the directory list must be separated by ':', e.g.
29115 if the source files can be in the directories /home/src1 and /home/src2,
29120 \begin_layout Standard
29129 -directory option should be -
29133 \begin_layout Standard
29142 -directory=/home/src1:/home/src2.
29143 Note there can be no spaces in the option.
29147 \begin_layout Itemize
29148 -cd <directory> - change to the <directory>.
29151 \begin_layout Itemize
29152 -fullname - used by GUI front ends.
29155 \begin_layout Itemize
29156 -cpu <cpu-type> - this argument is passed to the simulator please see the
29157 simulator docs for details.
29160 \begin_layout Itemize
29161 -X <Clock frequency > this options is passed to the simulator please see
29162 the simulator docs for details.
29165 \begin_layout Itemize
29166 -s <serial port file> passed to simulator see the simulator docs for details.
29169 \begin_layout Itemize
29170 -S <serial in,out> passed to simulator see the simulator docs for details.
29173 \begin_layout Itemize
29174 -k <port number> passed to simulator see the simulator docs for details.
29177 \begin_layout Subsection
29178 SDCDB Debugger Commands
29181 \begin_layout Standard
29182 As mentioned earlier the command interface for the debugger has been deliberatel
29183 y kept as close the GNU debugger gdb, as possible.
29184 This will help the integration with existing graphical user interfaces
29185 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
29186 If you use a graphical user interface for the debugger you can skip this
29190 \begin_layout Subsubsection*
29191 break [line | file:line | function | file:function]
29194 \begin_layout Standard
29195 Set breakpoint at specified line or function:
29204 sdcdb>break foo.c:100
29206 sdcdb>break funcfoo
29208 sdcdb>break foo.c:funcfoo
29211 \begin_layout Subsubsection*
29212 clear [line | file:line | function | file:function ]
29215 \begin_layout Standard
29216 Clear breakpoint at specified line or function:
29225 sdcdb>clear foo.c:100
29227 sdcdb>clear funcfoo
29229 sdcdb>clear foo.c:funcfoo
29232 \begin_layout Subsubsection*
29236 \begin_layout Standard
29237 Continue program being debugged, after breakpoint.
29240 \begin_layout Subsubsection*
29244 \begin_layout Standard
29245 Execute till the end of the current function.
29248 \begin_layout Subsubsection*
29252 \begin_layout Standard
29253 Delete breakpoint number 'n'.
29254 If used without any option clear ALL user defined break points.
29257 \begin_layout Subsubsection*
29258 info [break | stack | frame | registers ]
29261 \begin_layout Itemize
29262 info break - list all breakpoints
29265 \begin_layout Itemize
29266 info stack - show the function call stack.
29269 \begin_layout Itemize
29270 info frame - show information about the current execution frame.
29273 \begin_layout Itemize
29274 info registers - show content of all registers.
29277 \begin_layout Subsubsection*
29281 \begin_layout Standard
29282 Step program until it reaches a different source line.
29283 Note: pressing <return> repeats the last command.
29286 \begin_layout Subsubsection*
29290 \begin_layout Standard
29291 Step program, proceeding through subroutine calls.
29294 \begin_layout Subsubsection*
29298 \begin_layout Standard
29299 Start debugged program.
29302 \begin_layout Subsubsection*
29306 \begin_layout Standard
29307 Print type information of the variable.
29310 \begin_layout Subsubsection*
29314 \begin_layout Standard
29315 print value of variable.
29318 \begin_layout Subsubsection*
29322 \begin_layout Standard
29323 load the given file name.
29324 Note this is an alternate method of loading file for debugging.
29327 \begin_layout Subsubsection*
29331 \begin_layout Standard
29332 print information about current frame.
29335 \begin_layout Subsubsection*
29339 \begin_layout Standard
29340 Toggle between C source & assembly source.
29343 \begin_layout Subsubsection*
29344 ! simulator command
29347 \begin_layout Standard
29348 Send the string following '!' to the simulator, the simulator response is
29350 Note the debugger does not interpret the command being sent to the simulator,
29351 so if a command like 'go' is sent the debugger can loose its execution
29352 context and may display incorrect values.
29355 \begin_layout Subsubsection*
29359 \begin_layout Standard
29362 My name is Bobby Brown"
29365 \begin_layout Subsection
29366 Interfacing SDCDB with DDD
29369 \begin_layout Standard
29370 \begin_inset Note Note
29373 \begin_layout Standard
29374 The screenshot was converted from png to eps with:
29375 \begin_inset Quotes sld
29378 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
29379 \begin_inset Quotes srd
29382 which produces a pretty compact eps file which is free from compression
29386 \begin_layout Standard
29387 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
29388 as this broke the build system on Sourceforge (pdf-file was broken.
29389 pdflatex does not accept eps files).
29397 \begin_layout Standard
29413 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
29419 shows a screenshot of a debugging session with DDD
29420 \begin_inset LatexCommand \index{DDD (debugger)}
29424 (Unix only) on a simulated 8032.
29425 The debugging session might not run as smoothly as the screenshot suggests.
29426 The debugger allows setting of breakpoints, displaying and changing variables,
29427 single stepping through C and assembler code.
29430 The source was compiled with
29444 \begin_layout Standard
29456 -debug ddd_example.c
29469 and DDD was invoked with
29476 ddd -debugger "sdcdb -cpu 8032 ddd_example"
29479 \begin_layout Standard
29480 \begin_inset Note Note
29483 \begin_layout Standard
29484 Check that the double quotes or an apostroph within the command line survive
29485 the LyX tool chain.
29486 Previously the apostrophs got slanted in the PDF output so a cut and paste
29495 \begin_layout Subsection
29496 Interfacing SDCDB with XEmacs
29497 \begin_inset LatexCommand \index{XEmacs}
29502 \begin_inset LatexCommand \index{Emacs}
29509 \begin_layout Standard
29510 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
29511 sdcdb.el and sdcdbsrc.el.
29512 These two files can be found in the $(prefix)/bin directory after the installat
29514 These files need to be loaded into XEmacs for the interface to work.
29515 This can be done at XEmacs startup time by inserting the following into
29516 your '.xemacs' file (which can be found in your HOME directory):
29522 (load-file sdcdbsrc.el)
29528 .xemacs is a lisp file so the () around the command is REQUIRED.
29529 The files can also be loaded dynamically while XEmacs is running, set the
29530 environment variable 'EMACSLOADPATH' to the installation bin directory
29531 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
29532 To start the interface enter the following command:
29546 You will prompted to enter the file name to be debugged.
29551 The command line options that are passed to the simulator directly are
29552 bound to default values in the file sdcdbsrc.el.
29553 The variables are listed below, these values maybe changed as required.
29556 \begin_layout Itemize
29557 sdcdbsrc-cpu-type '51
29560 \begin_layout Itemize
29561 sdcdbsrc-frequency '11059200
29564 \begin_layout Itemize
29565 sdcdbsrc-serial nil
29568 \begin_layout Standard
29569 The following is a list of key mapping for the debugger interface.
29572 \begin_layout Standard
29595 binding\InsetSpace ~
29633 -------\InsetSpace ~
29704 sdcdb-back-from-src\InsetSpace ~
29733 rom-src\InsetSpace ~
29743 SDCDB continue command
29761 sdcdb-step-from-src\InsetSpace ~
29790 hatis-c-sexp\InsetSpace ~
29800 SDCDB ptypecommand for data at
29867 sdcdbsrc-delete\InsetSpace ~
29882 B Delete all breakpoints if no arg
29931 given or delete arg (C-u arg x)
29950 -frame\InsetSpace ~
29965 SDCDB Display current frame if no arg,
30014 given or display frame arg
30082 sdcdbsrc-goto-sdcdb\InsetSpace ~
30092 Goto the SDCDB output buffer
30111 t-c-sexp\InsetSpace ~
30122 SDCDB print command for data at
30189 sdcdbsrc-goto-sdcdb\InsetSpace ~
30200 o the SDCDB output buffer
30218 sdcdbsrc-mode\InsetSpace ~
30234 Toggles Sdcdbsrc mode (turns it
30250 sdcdb-finish-from-src\InsetSpace ~
30258 SDCDB finish command
30292 Set break for line with point
30307 sdcdbsrc-mode\InsetSpace ~
30323 Toggle Sdcdbsrc mode
30339 dbsrc-srcmode\InsetSpace ~
30363 \begin_layout Chapter
30367 \begin_layout Standard
30368 Here are a few guidelines that will help the compiler generate more efficient
30369 code, some of the tips are specific to this compiler others are generally
30370 good programming practice.
30373 \begin_layout Itemize
30374 Use the smallest data type to represent your data-value.
30375 If it is known in advance that the value is going to be less than 256 then
30376 use an 'unsigned char' instead of a 'short' or 'int'.
30377 Please note, that ANSI C requires both signed and unsigned chars to be
30378 promoted to 'signed int'
30379 \begin_inset LatexCommand \index{promotion to signed int}
30384 \begin_inset Marginal
30387 \begin_layout Standard
30396 before doing any operation.
30398 \begin_inset LatexCommand \index{type promotion}
30403 \begin_inset LatexCommand \label{type promotion}
30407 can be omitted, if the result is the same.
30408 The effect of the promotion rules together with the sign-extension is often
30413 \begin_layout Verse
30416 unsigned char uc = 0xfe;
30418 if (uc * uc < 0) /* this is true! */
30431 \begin_layout Standard
30438 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
30446 \begin_layout Verse
30449 (unsigned char) -12 / (signed char) -3 = ...
30452 \begin_layout Standard
30453 No, the result is not 4:
30456 \begin_layout Verse
30459 (int) (unsigned char) -12 / (int) (signed char) -3 =
30461 (int) (unsigned char)
30462 0xf4 / (int) (signed char) 0xfd =
30464 (int) 0x00f4 / (int) 0xfffd =
30469 (int) 244 / (int) -3 =
30471 (int) -81 = (int) 0xffaf;
30474 \begin_layout Standard
30475 Don't complain, that gcc gives you a different result.
30476 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
30477 Therefore the results are different.
30480 \begin_inset Quotes sld
30484 \begin_inset Quotes srd
30490 \begin_layout Quote
30493 If well-defined overflow characteristics are important and negative values
30494 are not, or if you want to steer clear of sign-extension problems when
30495 manipulating bits or bytes, use one of the corresponding unsigned types.
30496 (Beware when mixing signed and unsigned values in expressions, though.)
30499 character types (especially unsigned char) can be used as "tiny" integers,
30500 doing so is sometimes more trouble than it's worth, due to unpredictable
30501 sign extension and increased code size.
30505 \begin_layout Itemize
30506 Use unsigned when it is known in advance that the value is not going to
30508 This helps especially if you are doing division or multiplication, bit-shifting
30509 or are using an array index.
30512 \begin_layout Itemize
30513 NEVER jump into a LOOP.
30516 \begin_layout Itemize
30517 Declare the variables to be local
30518 \begin_inset LatexCommand \index{local variables}
30522 whenever possible, especially loop control variables (induction).
30525 \begin_layout Itemize
30526 Have a look at the assembly listing to get a
30527 \begin_inset Quotes sld
30531 \begin_inset Quotes srd
30534 for the code generation.
30537 \begin_layout Section
30538 Porting code from or to other compilers
30539 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
30546 \begin_layout Itemize
30547 check whether endianness of the compilers differs and adapt where needed.
30550 \begin_layout Itemize
30551 check the device specific header files
30552 \begin_inset LatexCommand \index{Header files}
30557 \begin_inset LatexCommand \index{Include files}
30561 for compiler specific syntax.
30562 Eventually include the file <compiler.h
30563 \begin_inset LatexCommand \index{compiler.h (include file)}
30568 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
30572 to allow using common header files.
30575 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
30582 \begin_layout Itemize
30583 check whether the startup code contains the correct initialization (watchdog,
30587 \begin_layout Itemize
30588 check whether the sizes of short, int, long match.
30591 \begin_layout Itemize
30592 check if some 16 or 32 bit hardware registers require a specific addressing
30593 order (least significant or most significant byte first) and adapt if needed
30602 relate to time and not to lower/upper memory location here, so this is
30607 the same as endianness).
30610 \begin_layout Itemize
30611 check whether the keyword
30615 is used where needed.
30616 The compilers might differ in their optimization characteristics (as different
30617 versions of the same compiler might also use more clever optimizations
30618 this is good idea anyway).
30620 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
30627 \begin_layout Itemize
30628 check that the compilers are not told to supress warnings.
30631 \begin_layout Itemize
30632 check and convert compiler specific extensions (interrupts, memory areas,
30636 \begin_layout Itemize
30637 check for differences in type promotion.
30638 Especially check for math operations on
30647 For the sake of C99 compatibility SDCC will probably promote these to
30651 more often than other compilers.
30652 Eventually insert explicit casts to
30661 Also check that the ~\InsetSpace ~
30663 \begin_inset LatexCommand \index{\~\/ Operator}
30670 \begin_inset LatexCommand \index{bit}
30676 variables, use the !\InsetSpace ~
30679 \begin_inset LatexCommand \ref{type promotion}
30684 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30691 \begin_layout Itemize
30692 check the assembly code generated for interrupt routines (f.e.
30693 for calls to possibly non-reentrant library functions).
30696 \begin_layout Itemize
30697 check whether timing loops result in proper timing (or preferably consider
30698 a rewrite of the code with timer based delays instead).
30701 \begin_layout Itemize
30702 check for differences in printf parameters (some compilers push (va_arg
30703 \begin_inset LatexCommand \index{vararg, va\_arg}
30707 ) char variables as
30711 others push them as
30717 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30724 \begin_layout Itemize
30725 check the resulting memory map
30726 \begin_inset LatexCommand \index{Memory map}
30731 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
30732 ly idata, pdata, xdata).
30733 Eventually check if unexpected library functions are included.
30736 \begin_layout Section
30738 \begin_inset LatexCommand \index{Tools}
30742 included in the distribution
30745 \begin_layout Standard
30747 \begin_inset Tabular
30748 <lyxtabular version="3" rows="12" columns="3">
30750 <column alignment="left" valignment="top" leftline="true" width="0pt">
30751 <column alignment="left" valignment="top" leftline="true" width="0pt">
30752 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30753 <row topline="true" bottomline="true">
30754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30757 \begin_layout Standard
30765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30768 \begin_layout Standard
30776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30779 \begin_layout Standard
30788 <row topline="true">
30789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30792 \begin_layout Standard
30794 \begin_inset LatexCommand \index{uCsim}
30803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30806 \begin_layout Standard
30807 Simulator for various architectures
30812 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30815 \begin_layout Standard
30822 <row topline="true">
30823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30826 \begin_layout Standard
30832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30835 \begin_layout Standard
30837 \begin_inset LatexCommand \index{Header files}
30842 \begin_inset LatexCommand \index{Include files}
30851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30854 \begin_layout Standard
30855 sdcc/support/scripts
30861 <row topline="true">
30862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30865 \begin_layout Standard
30871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30874 \begin_layout Standard
30875 header file conversion
30880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30883 \begin_layout Standard
30884 sdcc/support/scripts
30890 <row topline="true">
30891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30894 \begin_layout Standard
30900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30903 \begin_layout Standard
30909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30912 \begin_layout Standard
30928 <row topline="true">
30929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30932 \begin_layout Standard
30938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30941 \begin_layout Standard
30947 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30950 \begin_layout Standard
30966 <row topline="true">
30967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30970 \begin_layout Standard
30976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30979 \begin_layout Standard
30985 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30988 \begin_layout Standard
31004 <row topline="true">
31005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31008 \begin_layout Standard
31014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31017 \begin_layout Standard
31023 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31026 \begin_layout Standard
31042 <row topline="true">
31043 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31046 \begin_layout Standard
31052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31055 \begin_layout Standard
31061 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31064 \begin_layout Standard
31080 <row topline="true">
31081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31084 \begin_layout Standard
31090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31093 \begin_layout Standard
31099 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31102 \begin_layout Standard
31118 <row topline="true">
31119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31122 \begin_layout Standard
31128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31131 \begin_layout Standard
31137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31140 \begin_layout Standard
31156 <row topline="true" bottomline="true">
31157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31160 \begin_layout Standard
31166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31169 \begin_layout Standard
31171 \begin_inset LatexCommand \index{packihx (tool)}
31180 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31183 \begin_layout Standard
31208 \begin_layout Section
31210 \begin_inset LatexCommand \index{Documentation}
31214 included in the distribution
31217 \begin_layout Standard
31219 \begin_inset Tabular
31220 <lyxtabular version="3" rows="10" columns="2">
31222 <column alignment="block" valignment="top" leftline="true" width="40col%">
31223 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
31224 <row topline="true" bottomline="true" endhead="true">
31225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31228 \begin_layout Standard
31236 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31239 \begin_layout Standard
31242 Filename / Where to get
31248 <row topline="true">
31249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31252 \begin_layout Standard
31253 SDCC Compiler User Guide
31258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31261 \begin_layout Standard
31262 You're reading it right now
31274 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
31284 <row topline="true">
31285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31288 \begin_layout Standard
31294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31297 \begin_layout Standard
31310 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31320 <row topline="true">
31321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31324 \begin_layout Standard
31326 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
31331 \begin_inset LatexCommand \index{Assembler documentation}
31338 \begin_inset LatexCommand \index{aslink}
31343 \begin_inset LatexCommand \index{Linker documentation}
31352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31355 \begin_layout Standard
31356 sdcc/as/doc/asxhtm.html
31368 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
31378 <row topline="true">
31379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31382 \begin_layout Standard
31383 SDCC regression test
31384 \begin_inset LatexCommand \index{Regression test}
31393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31396 \begin_layout Standard
31397 sdcc/doc/test_suite_spec.pdf
31409 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
31419 <row topline="true">
31420 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31423 \begin_layout Standard
31429 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31432 \begin_layout Standard
31445 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
31455 <row topline="true">
31456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31459 \begin_layout Standard
31460 Notes on debugging with SDCDB
31461 \begin_inset LatexCommand \index{SDCDB (debugger)}
31470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31473 \begin_layout Standard
31474 sdcc/debugger/README
31486 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
31496 <row topline="true">
31497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31500 \begin_layout Standard
31502 \begin_inset LatexCommand \index{uCsim}
31506 Software simulator for microcontrollers
31511 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31514 \begin_layout Standard
31544 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
31554 <row topline="true">
31555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31558 \begin_layout Standard
31559 Temporary notes on the pic16
31560 \begin_inset LatexCommand \index{PIC16}
31569 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31572 \begin_layout Standard
31573 sdcc/src/pic16/NOTES
31585 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
31595 <row topline="true" bottomline="true">
31596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31599 \begin_layout Standard
31600 SDCC internal documentation (debugging file format)
31605 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31608 \begin_layout Standard
31638 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
31657 \begin_layout Section
31658 Related open source tools
31659 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
31664 \begin_inset LatexCommand \index{Related tools}
31671 \begin_layout Standard
31673 \begin_inset Tabular
31674 <lyxtabular version="3" rows="16" columns="3">
31676 <column alignment="left" valignment="top" leftline="true" width="0pt">
31677 <column alignment="block" valignment="top" leftline="true" width="30line%">
31678 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
31679 <row topline="true" bottomline="true">
31680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31683 \begin_layout Standard
31691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31694 \begin_layout Standard
31702 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31705 \begin_layout Standard
31714 <row topline="true">
31715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31718 \begin_layout Standard
31720 \begin_inset LatexCommand \index{gpsim (pic simulator)}
31729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31732 \begin_layout Standard
31738 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31741 \begin_layout Standard
31742 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
31752 <row topline="true">
31753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31756 \begin_layout Standard
31758 \begin_inset LatexCommand \index{gputils (pic tools)}
31767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31770 \begin_layout Standard
31776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31779 \begin_layout Standard
31780 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
31790 <row topline="true">
31791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31794 \begin_layout Standard
31800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31803 \begin_layout Standard
31809 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31812 \begin_layout Standard
31813 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
31823 <row topline="true">
31824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31827 \begin_layout Standard
31833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31836 \begin_layout Standard
31837 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
31843 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31846 \begin_layout Standard
31847 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
31857 <row topline="true">
31858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31861 \begin_layout Standard
31863 \begin_inset LatexCommand \index{indent (source formatting tool)}
31872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31875 \begin_layout Standard
31876 Formats C source - Master of the white spaces
31881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31884 \begin_layout Standard
31885 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
31895 <row topline="true">
31896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31899 \begin_layout Standard
31901 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
31910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31913 \begin_layout Standard
31914 Object file conversion, checksumming, ...
31919 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31922 \begin_layout Standard
31923 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
31933 <row topline="true">
31934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31937 \begin_layout Standard
31939 \begin_inset LatexCommand \index{objdump (tool)}
31948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31951 \begin_layout Standard
31952 Object file conversion, ...
31957 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31960 \begin_layout Standard
31961 Part of binutils (should be there anyway)
31967 <row topline="true">
31968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31971 \begin_layout Standard
31977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31980 \begin_layout Standard
31981 8051 monitor (hex up-/download, single step, disassemble)
31986 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31989 \begin_layout Standard
31990 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
32000 <row topline="true">
32001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32004 \begin_layout Standard
32006 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
32015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32018 \begin_layout Standard
32019 Source code documentation system
32024 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32027 \begin_layout Standard
32028 \begin_inset LatexCommand \url{http://www.doxygen.org}
32038 <row topline="true">
32039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32042 \begin_layout Standard
32048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32051 \begin_layout Standard
32052 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
32057 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32060 \begin_layout Standard
32061 \begin_inset LatexCommand \url{http://www.kdevelop.org}
32071 <row topline="true">
32072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32075 \begin_layout Standard
32081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32084 \begin_layout Standard
32085 8051 monitor (hex up-/download, single step, disassemble)
32090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32093 \begin_layout Standard
32094 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
32104 <row topline="true">
32105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32108 \begin_layout Standard
32110 \begin_inset LatexCommand \index{splint (syntax checking tool)}
32119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32122 \begin_layout Standard
32123 Statically checks c sources (see
32124 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
32133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32136 \begin_layout Standard
32137 \begin_inset LatexCommand \url{http://www.splint.org}
32147 <row topline="true" bottomline="true">
32148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32151 \begin_layout Standard
32153 \begin_inset LatexCommand \index{DDD (debugger)}
32162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32165 \begin_layout Standard
32166 Debugger, serves nicely as GUI to SDCDB
32167 \begin_inset LatexCommand \index{SDCDB (debugger)}
32176 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32179 \begin_layout Standard
32180 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
32190 <row bottomline="true">
32191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32194 \begin_layout Standard
32196 \begin_inset LatexCommand \index{d52}
32201 \begin_inset LatexCommand \index{d52 (disassembler)}
32210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32213 \begin_layout Standard
32214 Disassembler, can count instruction cycles
32215 \begin_inset LatexCommand \index{instruction cycles (count)}
32219 , use with options -pnd
32224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32227 \begin_layout Standard
32228 \begin_inset LatexCommand \url{http://www.8052.com/users/disasm/}
32238 <row bottomline="true">
32239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32242 \begin_layout Standard
32244 \begin_inset LatexCommand \index{cmake}
32253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32256 \begin_layout Standard
32257 Cross platform build system, generates Makefiles
32258 \begin_inset LatexCommand \index{Makefile}
32262 and project workspaces
32263 \begin_inset LatexCommand \index{project workspace}
32272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32275 \begin_layout Standard
32276 \begin_inset LatexCommand \url{http://www.cmake.org}
32284 and a dedicated wiki entry:
32285 \begin_inset LatexCommand \url{http://www.cmake.org/Wiki/CmakeSdcc}
32304 \begin_layout Section
32305 Related documentation / recommended reading
32308 \begin_layout Standard
32310 \begin_inset Tabular
32311 <lyxtabular version="3" rows="7" columns="3">
32313 <column alignment="left" valignment="top" leftline="true" width="0pt">
32314 <column alignment="left" valignment="top" leftline="true" width="0">
32315 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32316 <row topline="true" bottomline="true">
32317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32320 \begin_layout Standard
32328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32331 \begin_layout Standard
32339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32342 \begin_layout Standard
32351 <row topline="true">
32352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32355 \begin_layout Standard
32370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32373 \begin_layout Standard
32375 \begin_inset LatexCommand \index{C Reference card}
32384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32387 \begin_layout Standard
32388 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
32398 <row topline="true">
32399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32402 \begin_layout Standard
32408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32411 \begin_layout Standard
32413 \begin_inset LatexCommand \index{C FAQ}
32422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32425 \begin_layout Standard
32426 \begin_inset LatexCommand \url{http://www.c-faq.com}
32436 <row topline="true">
32437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32440 \begin_layout Standard
32446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32449 \begin_layout Standard
32450 \begin_inset Quotes sld
32454 \begin_inset Quotes srd
32462 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32465 \begin_layout Standard
32468 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
32478 <row topline="true">
32479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32482 \begin_layout Standard
32488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32491 \begin_layout Standard
32492 \begin_inset Quotes sld
32495 Extensions for Embedded C
32496 \begin_inset Quotes srd
32504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32507 \begin_layout Standard
32510 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
32520 <row topline="true">
32521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32524 \begin_layout Standard
32530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32533 \begin_layout Standard
32534 Latest datasheet of target CPU
32539 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32542 \begin_layout Standard
32549 <row topline="true" bottomline="true">
32550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32553 \begin_layout Standard
32559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32562 \begin_layout Standard
32563 Revision history of datasheet
32568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32571 \begin_layout Standard
32587 \begin_layout Section
32588 Application notes specifically for SDCC
32591 \begin_layout Standard
32592 SDCC makes no claims about the completeness of this list and about up-to-datenes
32593 s or correctness of the application notes
32594 \begin_inset LatexCommand \index{Application notes}
32601 \begin_layout Standard
32605 \begin_inset Tabular
32606 <lyxtabular version="3" rows="7" columns="3">
32608 <column alignment="block" valignment="top" leftline="true" width="17col%">
32609 <column alignment="block" valignment="top" leftline="true" width="27col%">
32610 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
32611 <row topline="true" bottomline="true">
32612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32615 \begin_layout Standard
32624 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
32627 \begin_layout Standard
32636 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32639 \begin_layout Standard
32649 <row topline="true">
32650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32653 \begin_layout Standard
32661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32664 \begin_layout Standard
32667 Using the SDCC Compiler for the DS80C400
32668 \begin_inset LatexCommand \index{DS80C400}
32677 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32680 \begin_layout Standard
32683 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
32693 <row topline="true">
32694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32697 \begin_layout Standard
32705 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
32708 \begin_layout Standard
32711 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
32712 \begin_inset LatexCommand \index{DS89C4x0}
32716 Family of Microcontrollers
32721 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32724 \begin_layout Standard
32727 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
32737 <row topline="true">
32738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32741 \begin_layout Standard
32744 Silicon Laboratories / Cygnal
32749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32752 \begin_layout Standard
32755 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
32756 \begin_inset LatexCommand \index{IDE}
32765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32768 \begin_layout Standard
32771 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
32781 <row topline="true">
32782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32785 \begin_layout Standard
32788 Ramtron / Goal Semiconductor
32793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32796 \begin_layout Standard
32799 Interfacing SDCC to Syn and Textpad
32804 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32807 \begin_layout Standard
32810 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32820 <row topline="true">
32821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32824 \begin_layout Standard
32827 Ramtron / Goal Semiconductor
32832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32835 \begin_layout Standard
32838 Installing and Configuring SDCC and Crimson Editor
32843 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32846 \begin_layout Standard
32849 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32859 <row topline="true" bottomline="true">
32860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32863 \begin_layout Standard
32871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32874 \begin_layout Standard
32877 MSC12xx Programming with SDCC
32882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32885 \begin_layout Standard
32888 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
32905 \begin_layout Section
32909 \begin_layout Standard
32910 Some questions answered, some pointers given - it might be time to in turn
32918 \begin_layout Itemize
32919 can you solve your project with the selected microcontroller? Would you
32920 find out early or rather late that your target is too small/slow/whatever?
32921 Can you switch to a slightly better device if it doesn't fit?
32924 \begin_layout Itemize
32925 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
32926 and/or another programming language be more adequate? Would an operating
32927 system on the target device help?
32930 \begin_layout Itemize
32931 if you solved the problem, will the marketing department be happy?
32934 \begin_layout Itemize
32935 if the marketing department is happy, will customers be happy?
32938 \begin_layout Itemize
32939 if you're the project manager, marketing department and maybe even the customer
32940 in one person, have you tried to see the project from the outside?
32943 \begin_layout Itemize
32944 is the project done if you think it is done? Or is just that other interface/pro
32945 tocol/feature/configuration/option missing? How about website, manual(s),
32946 internationali(z|s)ation, packaging, labels, 2nd source for components,
32947 electromagnetic compatability/interference, documentation for production,
32948 production test software, update mechanism, patent issues?
32951 \begin_layout Itemize
32952 is your project adequately positioned in that magic triangle: fame, fortune,
32956 \begin_layout Standard
32957 Maybe not all answers to these questions are known and some answers may
32962 , nevertheless knowing these questions may help you to avoid burnout
32966 \begin_layout Standard
32967 burnout is bad for electronic devices, programmers and motorcycle tyres
32973 Chances are you didn't want to hear some of them...
32976 \begin_layout Chapter
32978 \begin_inset LatexCommand \index{Support}
32985 \begin_layout Standard
32986 SDCC has grown to be a large project.
32987 The compiler alone (without the preprocessor, assembler and linker) is
32988 well over 150,000 lines of code (blank stripped).
32989 The open source nature of this project is a key to its continued growth
32991 You gain the benefit and support of many active software developers and
32993 Is SDCC perfect? No, that's why we need your help.
32994 The developers take pride in fixing reported bugs.
32995 You can help by reporting the bugs and helping other SDCC users.
32996 There are lots of ways to contribute, and we encourage you to take part
32997 in making SDCC a great software package.
33001 \begin_layout Standard
33002 The SDCC project is hosted on the SDCC sourceforge site at
33003 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
33008 You'll find the complete set of mailing lists
33009 \begin_inset LatexCommand \index{Mailing list(s)}
33013 , forums, bug reporting system, patch submission
33014 \begin_inset LatexCommand \index{Patch submission}
33019 \begin_inset LatexCommand \index{download}
33023 area and Subversion code repository
33024 \begin_inset LatexCommand \index{Subversion code repository}
33031 \begin_layout Section
33033 \begin_inset LatexCommand \index{Bug reporting}
33038 \begin_inset LatexCommand \index{Reporting bugs}
33045 \begin_layout Standard
33046 The recommended way of reporting bugs is using the infrastructure of the
33048 You can follow the status of bug reports there and have an overview about
33052 \begin_layout Standard
33053 Bug reports are automatically forwarded to the developer mailing list and
33054 will be fixed ASAP.
33055 When reporting a bug, it is very useful to include a small test program
33056 (the smaller the better) which reproduces the problem.
33057 If you can isolate the problem by looking at the generated assembly code,
33058 this can be very helpful.
33059 Compiling your program with the -
33063 \begin_layout Standard
33073 \begin_inset LatexCommand \index{-\/-dumpall}
33077 option can sometimes be useful in locating optimization problems.
33078 When reporting a bug please make sure you:
33081 \begin_layout Enumerate
33082 Attach the code you are compiling with SDCC.
33086 \begin_layout Enumerate
33087 Specify the exact command you use to run SDCC, or attach your Makefile.
33091 \begin_layout Enumerate
33092 Specify the SDCC version (type "
33098 "), your platform, and operating system.
33102 \begin_layout Enumerate
33103 Provide an exact copy of any error message or incorrect output.
33107 \begin_layout Enumerate
33108 Put something meaningful in the subject of your message.
33111 \begin_layout Standard
33112 Please attempt to include these 5 important parts, as applicable, in all
33113 requests for support or when reporting any problems or bugs with SDCC.
33114 Though this will make your message lengthy, it will greatly improve your
33115 chance that SDCC users and developers will be able to help you.
33116 Some SDCC developers are frustrated by bug reports without code provided
33117 that they can use to reproduce and ultimately fix the problem, so please
33118 be sure to provide sample code if you are reporting a bug!
33121 \begin_layout Standard
33122 Please have a short check that you are using a recent version of SDCC and
33123 the bug is not yet known.
33124 This is the link for reporting bugs:
33125 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
33130 With SDCC on average having more than 200 downloads
33131 \begin_inset LatexCommand \index{download}
33135 on sourceforge per day
33139 \begin_layout Standard
33140 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
33141 between 2002 and 2005.
33142 This does not include other methods of distribution.
33147 there must be some users.
33148 So it's not exactly easy to find a new bug.
33149 If you find one we need it:
33151 reporting bugs is good
33156 \begin_layout Section
33157 Requesting Features
33158 \begin_inset LatexCommand \label{sub:Requesting-Features}
33163 \begin_inset LatexCommand \index{Feature request}
33168 \begin_inset LatexCommand \index{Requesting features}
33175 \begin_layout Standard
33176 Like bug reports feature requests are forwarded to the developer mailing
33178 This is the link for requesting features:
33179 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33186 \begin_layout Section
33190 \begin_layout Standard
33191 Like bug reports contributed patches are forwarded to the developer mailing
33193 This is the link for submitting patches
33194 \begin_inset LatexCommand \index{Patch submission}
33199 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
33206 \begin_layout Standard
33207 You need to specify some parameters to the
33211 command for the patches to be useful.
33212 If you modified more than one file a patch created f.e.
33217 \begin_inset Quotes sld
33220 diff -Naur unmodified_directory modified_directory >my_changes.patch
33221 \begin_inset Quotes srd
33227 will be fine, otherwise
33231 \begin_inset Quotes sld
33234 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
33235 \begin_inset Quotes srd
33245 \begin_layout Section
33249 \begin_layout Standard
33250 These links should take you directly to the
33251 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
33259 \begin_layout Standard
33260 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
33261 automated messages (mid 2003)
33267 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
33272 \begin_inset LatexCommand \index{Mailing list(s)}
33276 and forums are archived and searchable so if you are lucky someone already
33277 had a similar problem.
33278 While mails to the lists themselves are delivered promptly their web front
33279 end on sourceforge sometimes shows a severe time lag (up to several weeks),
33280 if you're seriously using SDCC please consider subscribing to the lists.
33283 \begin_layout Section
33287 \begin_layout Standard
33288 You can follow the status of the Subversion version
33289 \begin_inset LatexCommand \index{version}
33293 of SDCC by watching the Changelog
33294 \begin_inset LatexCommand \index{Changelog}
33298 in the Subversion repository
33301 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
33308 \begin_layout Section
33309 Subversion Source Code Repository
33312 \begin_layout Standard
33322 \begin_layout Standard
33336 or the filenames of the snapshot versions of SDCC include date and its
33338 \begin_inset LatexCommand \index{Subversion code repository}
33343 Subversion allows to download the source of recent or previous versions
33345 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
33349 (by number or by date).
33350 An on-line source code browser and detailled instructions are also available
33352 SDCC versions starting from 1999 up to now are available (currently the
33353 versions prior to the conversion from cvs
33354 \begin_inset LatexCommand \index{cvs|see{Subversion}}
33358 to Subversion (April 2006) are either by accessible by Subversion or by
33362 \begin_layout Section
33364 \begin_inset LatexCommand \index{Release policy}
33371 \begin_layout Standard
33372 Historically there often were long delays between official releases and
33373 the sourceforge download area tends to get not updated at all.
33374 Excuses in the past might have referred to problems with live range analysis,
33375 but as this was fixed a while ago, the current problem is that another
33376 excuse has to be found.
33377 Kidding aside, we have to get better there! On the other hand there are
33378 daily snapshots available at
33379 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
33383 , and you can always build the very last version (hopefully with many bugs
33384 fixed, and features added) from the source code available at
33385 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
33391 \begin_inset LatexCommand \index{wiki}
33396 \begin_inset LatexCommand \index{SDCC Wiki}
33401 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/}
33405 also holds some information about past and future releases.
33408 \begin_layout Section
33410 \begin_inset LatexCommand \index{Examples}
33417 \begin_layout Standard
33418 You'll find some small examples in the directory
33420 sdcc/device/examples/.
33423 More examples and libraries are available at
33425 The SDCC Open Knowledge Resource
33426 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
33433 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
33440 \begin_layout Standard
33441 \begin_inset Note Note
33444 \begin_layout Standard
33445 I did insert a reference to Paul's web site here although it seems rather
33446 dedicated to a specific 8032 board (I think it's okay because it f.e.
33447 shows LCD/Harddisc interface and has a free 8051 monitor.
33448 Independent 8032 board vendors face hard competition of heavily subsidized
33449 development boards anyway).
33452 \begin_layout Standard
33453 Maybe we should include some links to real world applications.
33454 Preferably pointer to pointers (one for each architecture) so this stays
33463 \begin_layout Section
33465 \begin_inset LatexCommand \label{sec:Quality-control}
33470 \begin_inset LatexCommand \index{Quality control}
33477 \begin_layout Standard
33478 The compiler is passed through snaphot build compile and build checks.
33484 \begin_inset LatexCommand \index{Regression test}
33488 check that SDCC itself compiles flawlessly on several host platforms (i386,
33489 Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
33490 and checks the quality of the code generated by SDCC by running the code
33491 for several target platforms through simulators.
33492 The regression test suite comprises more than 100 files which expand to
33493 more than 500 test cases which include more than 4500 tests.
33494 The results of these tests are published daily on SDCC's snapshot page
33495 (click on the red or green symbols on the right side of
33496 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
33503 \begin_layout Standard
33504 There is a separate document
33507 \begin_inset LatexCommand \index{Test suite}
33514 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
33518 about the regression test suite.
33521 \begin_layout Standard
33522 You'll find the test code in the directory
33524 sdcc/support/regression
33527 You can run these tests manually by running
33531 in this directory (or f.e.
33536 \begin_inset Quotes sld
33540 \begin_inset Quotes srd
33546 if you don't want to run the complete tests).
33547 The test code might also be interesting if you want to look for examples
33548 \begin_inset LatexCommand \index{Examples}
33552 checking corner cases of SDCC or if you plan to submit patches
33553 \begin_inset LatexCommand \index{Patch submission}
33560 \begin_layout Standard
33561 The PIC14 port uses a different set of regression tests
33562 \begin_inset LatexCommand \index{Regression test (PIC14)}
33566 , you'll find them in the directory
33568 sdcc/src/regression
33573 \begin_layout Section
33574 Use of SDCC in Education
33577 \begin_layout Standard
33586 \begin_layout Standard
33587 the phrase "use in education" might evoke the association "
33591 fit for use in education".
33592 This connotation is not intended but nevertheless risked as the licensing
33593 of SDCC makes it difficult to offer educational discounts
33599 If your rationales are to:
33602 \begin_layout Enumerate
33603 give students a chance to understand the
33607 steps of code generation
33610 \begin_layout Enumerate
33611 have a curriculum that can be extended for years.
33612 Then you could use an fpga board as target and your curriculum will seamlessly
33613 extend from logic synthesis (
33614 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
33619 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
33623 ), over assembly programming, to C to FPGA compilers (
33624 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
33631 \begin_layout Enumerate
33632 be able to insert excursions about skills like using a revision control
33633 system, submitting/applying patches, using a type-setting (as opposed to
33634 word-processing) engine LyX/LaTeX, using
33635 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
33640 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
33644 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
33645 Source Software, CPU simulation, compiler regression tests
33646 \begin_inset LatexCommand \index{Regression test}
33653 And if there should be a shortage of ideas then you can always point students
33654 to the ever-growing feature request list
33655 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33662 \begin_layout Enumerate
33663 not tie students to a specific host platform and instead allow them to use
33668 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
33670 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
33677 \begin_layout Enumerate
33678 not encourage students to use illegal copies of educational software
33681 \begin_layout Enumerate
33682 be immune to licensing/availability/price changes of the chosen tool chain
33685 \begin_layout Enumerate
33686 be able to change to a new target platform without having to adopt a new
33690 \begin_layout Enumerate
33691 have complete control over and insight into the tool chain
33694 \begin_layout Enumerate
33695 make your students aware about the pros and cons of open source software
33699 \begin_layout Enumerate
33700 give back to the public as you are probably at least partially publically
33704 \begin_layout Enumerate
33705 give students a chance to publically prove their skills and to possibly
33706 see a world wide impact
33709 \begin_layout Standard
33710 then SDCC is probably among the first choices.
33711 Well, probably SDCC might be the only choice.
33716 \begin_layout Chapter
33717 SDCC Technical Data
33720 \begin_layout Section
33722 \begin_inset LatexCommand \index{Optimizations}
33729 \begin_layout Standard
33730 SDCC performs a host of standard optimizations in addition to some MCU specific
33735 \begin_layout Subsection
33736 Sub-expression Elimination
33737 \begin_inset LatexCommand \index{Subexpression elimination}
33744 \begin_layout Standard
33745 The compiler does local and
33764 \begin_layout Verse
33772 \begin_layout Standard
33773 will be translated to
33776 \begin_layout Verse
33786 \begin_layout Standard
33787 Some subexpressions are not as obvious as the above example, e.g.:
33790 \begin_layout Verse
33798 \begin_layout Standard
33799 In this case the address arithmetic a->b[i] will be computed only once;
33800 the equivalent code in C would be.
33803 \begin_layout Verse
33813 \begin_layout Standard
33814 The compiler will try to keep these temporary variables in registers.
33817 \begin_layout Subsection
33818 Dead-Code Elimination
33819 \begin_inset LatexCommand \index{Dead-code elimination}
33826 \begin_layout Verse
33841 i = 1; \InsetSpace ~
33850 global = 1;\InsetSpace ~
33864 global = 3;\InsetSpace ~
33870 \begin_layout Standard
33874 \begin_layout Verse
33890 \begin_layout Subsection
33892 \begin_inset LatexCommand \index{Copy propagation}
33899 \begin_layout Verse
33923 \begin_layout Standard
33927 \begin_layout Verse
33951 \begin_layout Standard
33952 Note: the dead stores created by this copy propagation will be eliminated
33953 by dead-code elimination.
33956 \begin_layout Subsection
33958 \begin_inset LatexCommand \index{Loop optimization}
33963 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
33970 \begin_layout Standard
33971 Two types of loop optimizations are done by SDCC
33979 of loop induction variables.
33980 In addition to the strength reduction the optimizer marks the induction
33981 variables and the register allocator tries to keep the induction variables
33982 in registers for the duration of the loop.
33983 Because of this preference of the register allocator
33984 \begin_inset LatexCommand \index{Register allocation}
33988 , loop induction optimization causes an increase in register pressure, which
33989 may cause unwanted spilling of other temporary variables into the stack
33990 \begin_inset LatexCommand \index{stack}
33995 The compiler will generate a warning message when it is forced to allocate
33996 extra space either on the stack or data space.
33997 If this extra space allocation is undesirable then induction optimization
33998 can be eliminated either for the entire source file (with -
34002 \begin_layout Standard
34011 -noinduction option) or for a given function only using #pragma\InsetSpace ~
34013 \begin_inset LatexCommand \index{\#pragma noinduction}
34024 \begin_layout Verse
34027 for (i = 0 ; i < 100 ; i ++)
34036 \begin_layout Standard
34040 \begin_layout Verse
34045 for (i = 0; i < 100; i++)
34054 \begin_layout Standard
34055 As mentioned previously some loop invariants are not as apparent, all static
34056 address computations are also moved out of the loop.
34061 \begin_inset LatexCommand \index{Strength reduction}
34065 , this optimization substitutes an expression by a cheaper expression:
34068 \begin_layout Verse
34071 for (i=0;i < 100; i++)
34080 \begin_layout Standard
34084 \begin_layout Verse
34091 for (i=0;i< 100;i++) {
34097 ar[itemp1] = itemp2;
34115 \begin_layout Standard
34116 The more expensive multiplication
34117 \begin_inset LatexCommand \index{Multiplication}
34121 is changed to a less expensive addition.
34124 \begin_layout Subsection
34126 \begin_inset LatexCommand \index{Loop reversing}
34133 \begin_layout Standard
34134 This optimization is done to reduce the overhead of checking loop boundaries
34135 for every iteration.
34136 Some simple loops can be reversed and implemented using a
34137 \begin_inset Quotes eld
34140 decrement and jump if not zero
34141 \begin_inset Quotes erd
34145 SDCC checks for the following criterion to determine if a loop is reversible
34146 (note: more sophisticated compilers use data-dependency analysis to make
34147 this determination, SDCC uses a more simple minded analysis).
34150 \begin_layout Itemize
34151 The 'for' loop is of the form
34157 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
34167 \begin_layout Itemize
34168 The <for body> does not contain
34169 \begin_inset Quotes eld
34173 \begin_inset Quotes erd
34177 \begin_inset Quotes erd
34183 \begin_layout Itemize
34184 All goto's are contained within the loop.
34187 \begin_layout Itemize
34188 No function calls within the loop.
34191 \begin_layout Itemize
34192 The loop control variable <sym> is not assigned any value within the loop
34195 \begin_layout Itemize
34196 The loop control variable does NOT participate in any arithmetic operation
34200 \begin_layout Itemize
34201 There are NO switch statements in the loop.
34204 \begin_layout Subsection
34205 Algebraic Simplifications
34208 \begin_layout Standard
34209 SDCC does numerous algebraic simplifications, the following is a small sub-set
34210 of these optimizations.
34213 \begin_layout Verse
34216 i = j + 0;\InsetSpace ~
34220 /* changed to: */\InsetSpace ~
34226 i /= 2;\InsetSpace ~
34233 /* changed to: */\InsetSpace ~
34240 = j - j;\InsetSpace ~
34244 /* changed to: */\InsetSpace ~
34250 i = j / 1;\InsetSpace ~
34254 /* changed to: */\InsetSpace ~
34261 \begin_layout Standard
34262 Note the subexpressions
34263 \begin_inset LatexCommand \index{Subexpression}
34267 given above are generally introduced by macro expansions or as a result
34268 of copy/constant propagation.
34271 \begin_layout Subsection
34272 'switch' Statements
34273 \begin_inset LatexCommand \label{sub:'switch'-Statements}
34278 \begin_inset LatexCommand \index{switch statement}
34285 \begin_layout Standard
34286 SDCC can optimize switch statements to jump tables
34287 \begin_inset LatexCommand \index{jump tables}
34292 It makes the decision based on an estimate of the generated code size.
34293 SDCC is quite liberal in the requirements for jump table generation:
34296 \begin_layout Itemize
34297 The labels need not be in order, and the starting number need not be one
34298 or zero, the case labels are in numerical sequence or not too many case
34299 labels are missing.
34303 \begin_layout Verse
34306 switch(i) {\InsetSpace ~
34337 case 4: ...\InsetSpace ~
34369 case 5: ...\InsetSpace ~
34401 case 3: ...\InsetSpace ~
34432 case 6: ...\InsetSpace ~
34464 case 7: ...\InsetSpace ~
34496 case 8: ...\InsetSpace ~
34528 case 9: ...\InsetSpace ~
34560 case 10: ...\InsetSpace ~
34591 case 11: ...\InsetSpace ~
34658 \begin_layout Standard
34659 Both the above switch statements will be implemented using a jump-table.
34660 The example to the right side is slightly more efficient as the check for
34661 the lower boundary of the jump-table is not needed.
34665 \begin_layout Itemize
34666 The number of case labels is not larger than supported by the target architectur
34670 \begin_layout Itemize
34671 If the case labels are not in numerical sequence ('gaps' between cases)
34672 SDCC checks whether a jump table with additionally inserted dummy cases
34673 is still attractive.
34677 \begin_layout Itemize
34678 If the starting number is not zero and a check for the lower boundary of
34679 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
34684 \begin_layout Standard
34685 Switch statements which have large gaps in the numeric sequence or those
34686 that have too many case labels can be split into more than one switch statement
34687 for efficient code generation, e.g.:
34690 \begin_layout Verse
34768 \begin_layout Standard
34769 If the above switch statement is broken down into two switch statements
34772 \begin_layout Verse
34815 \begin_layout Standard
34819 \begin_layout Verse
34862 \begin_layout Standard
34863 then both the switch statements will be implemented using jump-tables whereas
34864 the unmodified switch statement will not be.
34867 \begin_layout Standard
34868 \begin_inset Note Note
34871 \begin_layout Standard
34872 There might be reasons which SDCC cannot know about to either favour or
34873 not favour jump tables.
34874 If the target system has to be as quick for the last switch case as for
34875 the first (pro jump table), or if the switch argument is known to be zero
34876 in the majority of the cases (contra jump table).
34884 \begin_layout Standard
34885 The pragma nojtbound
34886 \begin_inset LatexCommand \index{\#pragma nojtbound}
34890 can be used to turn off checking the
34903 It has no effect if a default label is supplied.
34904 Use of this pragma is dangerous: if the switch
34905 \begin_inset LatexCommand \index{switch statement}
34909 argument is not matched by a case statement the processor will happily
34913 \begin_layout Subsection
34914 Bit-shifting Operations
34915 \begin_inset LatexCommand \index{Bit shifting}
34922 \begin_layout Standard
34923 Bit shifting is one of the most frequently used operation in embedded programmin
34925 SDCC tries to implement bit-shift operations in the most efficient way
34929 \begin_layout Verse
34942 \begin_layout Standard
34943 generates the following code:
34946 \begin_layout Verse
34961 \begin_layout Standard
34962 In general SDCC will never setup a loop if the shift count is known.
34966 \begin_layout Verse
34979 \begin_layout Standard
34983 \begin_layout Verse
35007 \begin_layout Subsection
35009 \begin_inset LatexCommand \index{Bit rotation}
35016 \begin_layout Standard
35017 A special case of the bit-shift operation is bit rotation
35018 \begin_inset LatexCommand \index{rotating bits}
35022 , SDCC recognizes the following expression to be a left bit-rotation:
35025 \begin_layout Verse
35033 char i;\InsetSpace ~
35044 /* unsigned is needed for rotation */
35049 i = ((i << 1) | (i >> 7));
35058 \begin_layout Standard
35059 will generate the following code:
35062 \begin_layout Verse
35079 \begin_layout Standard
35080 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
35081 ns of this case will also be recognized as bit-rotation, i.e.:
35084 \begin_layout Verse
35087 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
35090 \begin_layout Subsection
35091 Nibble and Byte Swapping
35094 \begin_layout Standard
35095 Other special cases of the bit-shift operations are nibble or byte swapping
35096 \begin_inset LatexCommand \index{swapping nibbles/bytes}
35100 , SDCC recognizes the following expressions:
35103 \begin_layout Verse
35124 i = ((i << 4) | (i >> 4));
35130 j = ((j << 8) | (j >> 8));
35133 \begin_layout Standard
35134 and generates a swap instruction for the nibble swapping
35135 \begin_inset LatexCommand \index{Nibble swapping}
35139 or move instructions for the byte swapping
35140 \begin_inset LatexCommand \index{Byte swapping}
35146 \begin_inset Quotes sld
35150 \begin_inset Quotes srd
35153 example can be used to convert from little to big-endian or vice versa.
35154 If you want to change the endianness of a
35158 integer you have to cast to
35165 \begin_layout Standard
35166 Note that SDCC stores numbers in little-endian
35170 \begin_layout Standard
35171 Usually 8-bit processors don't care much about endianness.
35172 This is not the case for the standard 8051 which only has an instruction
35178 \begin_inset LatexCommand \index{DPTR}
35186 so little-endian is the more efficient byte order.
35192 \begin_inset LatexCommand \index{little-endian}
35197 \begin_inset LatexCommand \index{Endianness}
35202 lowest order first).
35205 \begin_layout Subsection
35207 \begin_inset LatexCommand \index{Highest Order Bit}
35212 \begin_inset LatexCommand \index{Any Order Bit}
35219 \begin_layout Standard
35220 It is frequently required to obtain the highest order bit of an integral
35221 type (long, int, short or char types).
35222 Also obtaining any other order bit is not uncommon.
35223 SDCC recognizes the following expressions to yield the highest order bit
35224 and generates optimized code for it, e.g.:
35227 \begin_layout Verse
35238 unsigned char hob1, aob1;
35242 bit hob2, hob3, aob2,
35252 hob1 = (gint >> 15) & 1;
35256 hob2 = (gint >> 15) & 1;
35260 hob3 = gint & 0x8000;
35265 aob1 = (gint >> 9) & 1;
35269 aob2 = (gint >> 8) & 1;
35273 aob3 = gint & 0x0800;
35283 \begin_layout Standard
35284 will generate the following code:
35287 \begin_layout Verse
35318 000A E5*01\InsetSpace ~
35345 000C 23\InsetSpace ~
35376 000D 54 01\InsetSpace ~
35404 000F F5*02\InsetSpace ~
35459 0011 E5*01\InsetSpace ~
35487 0013 33\InsetSpace ~
35517 0014 92*00\InsetSpace ~
35573 0016 E5*01\InsetSpace ~
35600 0018 33\InsetSpace ~
35630 0019 92*01\InsetSpace ~
35686 001B E5*01\InsetSpace ~
35745 001E 54 01\InsetSpace ~
35772 0020 F5*03\InsetSpace ~
35828 0022 E5*01\InsetSpace ~
35855 0024 13\InsetSpace ~
35885 0025 92*02\InsetSpace ~
35941 0027 E5*01\InsetSpace ~
35996 002B 92*03\InsetSpace ~
36024 \begin_layout Standard
36025 Other variations of these cases however will
36030 They are standard C expressions, so I heartily recommend these be the only
36031 way to get the highest order bit, (it is portable).
36032 Of course it will be recognized even if it is embedded in other expressions,
36036 \begin_layout Verse
36039 xyz = gint + ((gint >> 15) & 1);
36042 \begin_layout Standard
36043 will still be recognized.
36046 \begin_layout Subsection
36048 \begin_inset LatexCommand \index{Higher Order Byte}
36052 / Higher Order Word
36053 \begin_inset LatexCommand \index{Higher Order Word}
36060 \begin_layout Standard
36061 It is also frequently required to obtain a higher order byte or word of
36062 a larger integral type (long, int or short types).
36063 SDCC recognizes the following expressions to yield the higher order byte
36064 or word and generates optimized code for it, e.g.:
36067 \begin_layout Verse
36072 unsigned long int glong;
36080 unsigned char hob1,
36085 unsigned int how1, how2;
36094 hob1 = (gint >> 8) & 0xFF;
36098 hob2 = glong >> 24;
36102 how1 = (glong >> 16) & 0xFFFF;
36117 \begin_layout Standard
36118 will generate the following code:
36121 \begin_layout Verse
36152 0037 85*01*06\InsetSpace ~
36174 _foo_hob1_1_1,(_gint + 1)
36205 003A 85*05*07\InsetSpace ~
36227 _foo_hob2_1_1,(_glong + 3)
36257 003D 85*04*08\InsetSpace ~
36280 _foo_how1_1_1,(_glong + 2)
36282 0040 85*05*09\InsetSpace ~
36307 0043 85*03*0A\InsetSpace ~
36329 _foo_how2_1_1,(_glong + 1)
36331 0046 85*04*0B\InsetSpace ~
36354 (_foo_how2_1_1 + 1),(_glong + 2)
36357 \begin_layout Standard
36358 Again, variations of these cases may
36363 They are standard C expressions, so I heartily recommend these be the only
36364 way to get the higher order byte/word, (it is portable).
36365 Of course it will be recognized even if it is embedded in other expressions,
36369 \begin_layout Verse
36372 xyz = gint + ((gint >> 8) & 0xFF);
36375 \begin_layout Standard
36376 will still be recognized.
36379 \begin_layout Subsection
36381 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
36386 \begin_inset LatexCommand \index{Peephole optimizer}
36393 \begin_layout Standard
36394 The compiler uses a rule based, pattern matching and re-writing mechanism
36395 for peep-hole optimization.
36400 a peep-hole optimizer by Christopher W.
36401 Fraser (cwfraser\InsetSpace ~
36404 A default set of rules are compiled into the compiler, additional rules
36405 may be added with the
36411 \begin_layout Standard
36421 \begin_inset LatexCommand \index{-\/-peep-file}
36428 The rule language is best illustrated with examples.
36431 \begin_layout Verse
36453 \begin_layout Standard
36454 The above rule will change the following assembly
36455 \begin_inset LatexCommand \index{Assembler routines}
36462 \begin_layout Verse
36470 \begin_layout Standard
36474 \begin_layout Verse
36480 \begin_layout Standard
36481 Note: All occurrences of a
36485 (pattern variable) must denote the same string.
36486 With the above rule, the assembly sequence:
36489 \begin_layout Verse
36497 \begin_layout Standard
36498 will remain unmodified.
36502 Other special case optimizations may be added by the
36509 \begin_layout Standard
36522 some variants of the 8051 MCU
36523 \begin_inset LatexCommand \index{MCS51 variants}
36536 The following two rules will change all
36553 \begin_layout Verse
36556 replace { lcall %1 } by { acall %1 }
36558 replace { ljmp %1 } by { ajmp %1 }
36561 \begin_layout Standard
36562 (NOTE: from version 2.7.3 on, you can use option -
36568 \begin_layout Standard
36580 \begin_inset LatexCommand \index{-\/-acall-ajmp}
36584 , which also takes care of aligning the interrupt vectors properly.)
36589 \begin_layout Standard
36592 inline-assembler code
36594 is also passed through the peep hole optimizer, thus the peephole optimizer
36595 can also be used as an assembly level macro expander.
36596 The rules themselves are MCU dependent whereas the rule language infra-structur
36597 e is MCU independent.
36598 Peephole optimization rules for other MCU can be easily programmed using
36603 The syntax for a rule is as follows:
36606 \begin_layout Verse
36609 rule := replace [ restart ] '{' <assembly sequence> '
36647 <assembly sequence> '
36665 '}' [if <functionName> ] '
36670 \begin_layout Standard
36671 <assembly sequence> := assembly instruction (each instruction including
36672 labels must be on a separate line).
36676 The optimizer will apply to the rules
36677 one by one from the top in the sequence of their appearance, it will terminate
36678 when all rules are exhausted.
36679 If the 'restart' option is specified, then the optimizer will start matching
36680 the rules again from the top, this option for a rule is expensive (performance)
36681 , it is intended to be used in situations where a transformation will trigger
36682 the same rule again.
36683 An example of this (not a good one, it has side effects) is the following
36687 \begin_layout Verse
36707 \begin_layout Standard
36708 Note that the replace pattern cannot be a blank, but can be a comment line.
36709 Without the 'restart' option only the innermost 'pop' 'push' pair would
36710 be eliminated, i.e.:
36713 \begin_layout Verse
36725 \begin_layout Standard
36729 \begin_layout Verse
36739 \begin_layout Standard
36744 the restart option the rule will be applied again to the resulting code
36745 and then all the pop-push pairs will be eliminated to yield:
36748 \begin_layout Verse
36756 \begin_layout Standard
36757 A conditional function can be attached to a rule.
36758 Attaching rules are somewhat more involved, let me illustrate this with
36762 \begin_layout Verse
36786 \begin_layout Standard
36787 The optimizer does a look-up of a function name table defined in function
36792 in the source file SDCCpeeph.c, with the name
36797 If it finds a corresponding entry the function is called.
36798 Note there can be no parameters specified for these functions, in this
36803 is crucial, since the function
36807 expects to find the label in that particular variable (the hash table containin
36808 g the variable bindings is passed as a parameter).
36809 If you want to code more such functions, take a close look at the function
36810 labelInRange and the calling mechanism in source file SDCCpeeph.c.
36811 Currently implemented are
36813 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
36814 24bitMode, portIsDS390, 24bitModeAndPortDS390
36823 \begin_layout Standard
36824 I know this whole thing is a little kludgey, but maybe some day we will
36825 have some better means.
36826 If you are looking at this file, you will see the default rules that are
36827 compiled into the compiler, you can add your own rules in the default set
36828 there if you get tired of specifying the -
36832 \begin_layout Standard
36844 \begin_layout Section
36846 \begin_inset LatexCommand \index{ANSI-compliance}
36851 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
36858 \begin_layout Standard
36859 The latest publically available version of the standard
36861 ISO/IEC 9899 - Programming languages - C
36863 should be available at:
36864 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
36873 \begin_layout Standard
36874 Deviations from the compliance:
36877 \begin_layout Itemize
36878 functions are not reentrant
36879 \begin_inset LatexCommand \index{reentrant}
36883 unless explicitly declared as such or the
36889 \begin_layout Standard
36899 \begin_inset LatexCommand \index{-\/-stack-auto}
36905 command line option is specified.
36908 \begin_layout Itemize
36910 \begin_inset LatexCommand \index{struct}
36915 \begin_inset LatexCommand \index{union}
36919 cannot be assigned values directly, cannot be passed as function parameters
36920 or assigned to each other and cannot be a return value
36921 \begin_inset LatexCommand \index{return value}
36925 from a function, e.g.:
36929 \begin_layout Verse
36952 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
36971 s parms) /* invalid in SDCC although allowed in ANSI */
36993 return rets; /* is invalid in SDCC although allowed in ANSI */
36999 \begin_layout Itemize
37000 initialization of structure arrays must be fully braced.
37004 \begin_layout Verse
37007 struct s { char x } a[] = {1, 2};\InsetSpace ~
37012 /* invalid in SDCC */
37015 } a[] = {{1}, {2}}; /* OK */
37019 \begin_layout Itemize
37021 \begin_inset LatexCommand \index{long long (not supported)}
37026 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
37033 \begin_layout Itemize
37035 \begin_inset LatexCommand \index{double (not supported)}
37039 ' precision floating point
37040 \begin_inset LatexCommand \index{Floating point support}
37047 \begin_layout Itemize
37049 \begin_inset LatexCommand \index{K\&R style}
37053 function declarations are NOT allowed.
37057 \begin_layout Verse
37060 foo(i,j) /* this old style of function declarations */
37062 int i,j; /* is valid
37063 in ANSI but not valid in SDCC */
37078 \begin_layout Itemize
37079 Most enhancements in C99 are not supported, e.g.:
37083 \begin_layout Verse
37090 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
37094 \begin_layout Itemize
37095 But some have been added recently in SDCC 2.7.0.
37096 They must be considered alpha quality however.
37100 \begin_layout Verse
37105 \begin_inset LatexCommand \index{inline (not supported)}
37111 int increment (int a) { return a+1; } /* inlines the increment without
37112 function call overhead */
37117 \begin_inset LatexCommand \index{inline (not supported)}
37123 p; /* accepted but ignored */
37127 \begin_layout Itemize
37128 Certain words that are valid identifiers in the standard may be reserved
37129 words in SDCC unless the
37135 \begin_layout Standard
37145 \begin_inset LatexCommand \index{-\/-std-c89}
37157 \begin_layout Standard
37167 \begin_inset LatexCommand \index{-\/-std-c99}
37173 command line options are used.
37174 These may include (depending on the selected processor): 'at', 'banked',
37175 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
37176 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
37177 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
37179 Compliant equivalents of these keywords are always available in a form
37180 that begin with two underscores
37181 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
37186 '__data' instead of 'data'.
37189 \begin_layout Itemize
37190 Integer promotion of variable arguments is not performed if the argument
37191 is explicitly taypecasted unless the
37197 \begin_layout Standard
37207 \begin_inset LatexCommand \index{-\/-std-c89}
37219 \begin_layout Standard
37229 \begin_inset LatexCommand \index{-\/-std-c99}
37235 command line options are used.
37239 \begin_layout Verse
37242 void vararg_func (char *str, ...) { str; }
37259 u is promoted to int before
37264 * passing to function */
37268 vararg_func ("%c", c);
37275 argument u is not promoted to int,
37280 * it is passed as char to function
37286 --std-cXX is not defined;
37291 * is promoted to int before passing
37297 if --std-cXX is defined */
37301 vararg_func ("%bc", (char)u);
37307 \begin_layout Section
37308 Cyclomatic Complexity
37309 \begin_inset LatexCommand \index{Cyclomatic complexity}
37316 \begin_layout Standard
37317 Cyclomatic complexity of a function is defined as the number of independent
37318 paths the program can take during execution of the function.
37319 This is an important number since it defines the number test cases you
37320 have to generate to validate the function.
37321 The accepted industry standard for complexity number is 10, if the cyclomatic
37322 complexity reported by SDCC exceeds 10 you should think about simplification
37323 of the function logic.
37324 Note that the complexity level is not related to the number of lines of
37325 code in a function.
37326 Large functions can have low complexity, and small functions can have large
37332 SDCC uses the following formula to compute the complexity:
37337 \begin_layout Standard
37338 complexity = (number of edges in control flow graph) - (number of nodes
37339 in control flow graph) + 2;
37343 Having said that the industry standard is 10,
37344 you should be aware that in some cases it be may unavoidable to have a
37345 complexity level of less than 10.
37346 For example if you have switch statement with more than 10 case labels,
37347 each case label adds one to the complexity level.
37348 The complexity level is by no means an absolute measure of the algorithmic
37349 complexity of the function, it does however provide a good starting point
37350 for which functions you might look at for further optimization.
37353 \begin_layout Section
37354 Retargetting for other Processors
37357 \begin_layout Standard
37358 The issues for retargetting the compiler are far too numerous to be covered
37360 What follows is a brief description of each of the seven phases of the
37361 compiler and its MCU dependency.
37364 \begin_layout Itemize
37365 Parsing the source and building the annotated parse tree.
37366 This phase is largely MCU independent (except for the language extensions).
37367 Syntax & semantic checks are also done in this phase, along with some initial
37368 optimizations like back patching labels and the pattern matching optimizations
37369 like bit-rotation etc.
37372 \begin_layout Itemize
37373 The second phase involves generating an intermediate code which can be easy
37374 manipulated during the later phases.
37375 This phase is entirely MCU independent.
37376 The intermediate code generation assumes the target machine has unlimited
37377 number of registers, and designates them with the name iTemp.
37378 The compiler can be made to dump a human readable form of the code generated
37383 \begin_layout Standard
37395 \begin_layout Itemize
37396 This phase does the bulk of the standard optimizations and is also MCU independe
37398 This phase can be broken down into several sub-phases:
37402 Break down intermediate
37403 code (iCode) into basic blocks.
37405 Do control flow & data flow analysis on the
37408 Do local common subexpression elimination, then global subexpressio
37411 Dead code elimination
37415 If loop optimizations
37416 caused any changes then do 'global subexpression elimination' and 'dead
37417 code elimination' again.
37420 \begin_layout Itemize
37421 This phase determines the live-ranges; by live range I mean those iTemp
37422 variables defined by the compiler that still survive after all the optimization
37424 Live range analysis
37425 \begin_inset LatexCommand \index{Live range analysis}
37429 is essential for register allocation, since these computation determines
37430 which of these iTemps will be assigned to registers, and for how long.
37433 \begin_layout Itemize
37434 Phase five is register allocation.
37435 There are two parts to this process.
37439 The first part I call 'register packing'
37440 (for lack of a better term).
37441 In this case several MCU specific expression folding is done to reduce
37446 The second part is more MCU independent and deals with
37447 allocating registers to the remaining live ranges.
37448 A lot of MCU specific code does creep into this phase because of the limited
37449 number of index registers available in the 8051.
37452 \begin_layout Itemize
37453 The Code generation phase is (unhappily), entirely MCU dependent and very
37454 little (if any at all) of this code can be reused for other MCU.
37455 However the scheme for allocating a homogenized assembler operand for each
37456 iCode operand may be reused.
37459 \begin_layout Itemize
37460 As mentioned in the optimization section the peep-hole optimizer is rule
37461 based system, which can reprogrammed for other MCUs.
37464 \begin_layout Standard
37465 More information is available on SDCC Wiki
37466 \begin_inset LatexCommand \index{wiki}
37471 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting}
37475 ) and in the thread
37476 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
37483 \begin_layout Chapter
37485 \begin_inset LatexCommand \index{Compiler internals}
37492 \begin_layout Section
37493 The anatomy of the compiler
37494 \begin_inset LatexCommand \label{sub:The-anatomy-of}
37501 \begin_layout Standard
37504 This is an excerpt from an article published in Circuit Cellar Magazine
37510 It's a little outdated (the compiler is much more efficient now and user/develo
37511 per friendly), but pretty well exposes the guts of it all.
37517 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
37518 It is fairly easy to retarget for other 8-bit MCU.
37519 Here we take a look at some of the internals of the compiler.
37523 \begin_layout Paragraph*
37525 \begin_inset LatexCommand \index{Parsing}
37532 \begin_layout Standard
37533 Parsing the input source file and creating an AST (Annotated Syntax Tree
37534 \begin_inset LatexCommand \index{Annotated syntax tree}
37539 This phase also involves propagating types (annotating each node of the
37540 parse tree with type information) and semantic analysis.
37541 There are some MCU specific parsing rules.
37542 For example the storage classes, the extended storage classes are MCU specific
37543 while there may be a xdata storage class for 8051 there is no such storage
37544 class for z80 or Atmel AVR.
37545 SDCC allows MCU specific storage class extensions, i.e.
37546 xdata will be treated as a storage class specifier when parsing 8051 C
37547 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
37551 \begin_layout Paragraph*
37553 \begin_inset LatexCommand \index{iCode}
37560 \begin_layout Standard
37561 Intermediate code generation.
37562 In this phase the AST is broken down into three-operand form (iCode).
37563 These three operand forms are represented as doubly linked lists.
37564 ICode is the term given to the intermediate form generated by the compiler.
37565 ICode example section shows some examples of iCode generated for some simple
37566 C source functions.
37569 \begin_layout Paragraph*
37571 \begin_inset LatexCommand \index{Optimizations}
37578 \begin_layout Standard
37579 Bulk of the target independent optimizations is performed in this phase.
37580 The optimizations include constant propagation, common sub-expression eliminati
37581 on, loop invariant code movement, strength reduction of loop induction variables
37582 and dead-code elimination.
37585 \begin_layout Paragraph*
37586 Live range analysis
37587 \begin_inset LatexCommand \index{Live range analysis}
37594 \begin_layout Standard
37595 During intermediate code generation phase, the compiler assumes the target
37596 machine has infinite number of registers and generates a lot of temporary
37598 The live range computation determines the lifetime of each of these compiler-ge
37599 nerated temporaries.
37600 A picture speaks a thousand words.
37601 ICode example sections show the live range annotations for each of the
37603 It is important to note here, each iCode is assigned a number in the order
37604 of its execution in the function.
37605 The live ranges are computed in terms of these numbers.
37606 The from number is the number of the iCode which first defines the operand
37607 and the to number signifies the iCode which uses this operand last.
37610 \begin_layout Paragraph*
37611 Register Allocation
37612 \begin_inset LatexCommand \index{Register allocation}
37619 \begin_layout Standard
37620 The register allocation determines the type and number of registers needed
37622 In most MCUs only a few registers can be used for indirect addressing.
37623 In case of 8051 for example the registers R0 & R1 can be used to indirectly
37624 address the internal ram and DPTR to indirectly address the external ram.
37625 The compiler will try to allocate the appropriate register to pointer variables
37627 ICode example section shows the operands annotated with the registers assigned
37629 The compiler will try to keep operands in registers as much as possible;
37630 there are several schemes the compiler uses to do achieve this.
37631 When the compiler runs out of registers the compiler will check to see
37632 if there are any live operands which is not used or defined in the current
37633 basic block being processed, if there are any found then it will push that
37634 operand and use the registers in this block, the operand will then be popped
37635 at the end of the basic block.
37639 \begin_layout Standard
37640 There are other MCU specific considerations in this phase.
37641 Some MCUs have an accumulator; very short-lived operands could be assigned
37642 to the accumulator instead of a general-purpose register.
37645 \begin_layout Paragraph*
37649 \begin_layout Standard
37650 Figure II gives a table of iCode
37651 \begin_inset LatexCommand \index{iCode}
37655 operations supported by the compiler.
37656 The code generation involves translating these operations into corresponding
37657 assembly code for the processor.
37658 This sounds overly simple but that is the essence of code generation.
37659 Some of the iCode operations are generated on a MCU specific manner for
37660 example, the z80 port does not use registers to pass parameters so the
37661 SEND and RECV iCode operations will not be generated, and it also does
37662 not support JUMPTABLES.
37668 \begin_layout Standard
37672 \begin_inset Tabular
37673 <lyxtabular version="3" rows="39" columns="4">
37674 <features islongtable="true" headBottomDL="true">
37675 <column alignment="block" valignment="top" leftline="true" width="13col%">
37676 <column alignment="left" valignment="top" leftline="true" width="13col%">
37677 <column alignment="block" valignment="top" leftline="true" width="22col%">
37678 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
37679 <row topline="true" bottomline="true" endhead="true">
37680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37683 \begin_layout Standard
37689 \begin_inset LatexCommand \index{iCode}
37698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37701 \begin_layout Standard
37709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37712 \begin_layout Standard
37720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37723 \begin_layout Standard
37732 <row topline="true">
37733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37736 \begin_layout Standard
37744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37747 \begin_layout Standard
37750 IC_LEFT() IC_RESULT()
37755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37758 \begin_layout Standard
37766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37769 \begin_layout Standard
37772 IC_RESULT = ! IC_LEFT;
37778 <row topline="true">
37779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37782 \begin_layout Standard
37790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37793 \begin_layout Standard
37796 IC_LEFT() IC_RESULT()
37801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37804 \begin_layout Standard
37807 Bitwise complement of
37812 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37815 \begin_layout Standard
37818 IC_RESULT = ~IC_LEFT;
37824 <row topline="true">
37825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37828 \begin_layout Standard
37836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37839 \begin_layout Standard
37842 IC_LEFT() IC_RESULT()
37847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37850 \begin_layout Standard
37853 Rotate right with carry
37858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37861 \begin_layout Standard
37864 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
37870 <row topline="true">
37871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37874 \begin_layout Standard
37882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37885 \begin_layout Standard
37888 IC_LEFT() IC_RESULT()
37893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37896 \begin_layout Standard
37899 Rotate left with carry
37904 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37907 \begin_layout Standard
37910 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
37916 <row topline="true">
37917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37920 \begin_layout Standard
37928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37931 \begin_layout Standard
37934 IC_LEFT() IC_RESULT()
37939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37942 \begin_layout Standard
37945 Get the highest order bit of IC_LEFT
37950 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37953 \begin_layout Standard
37956 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
37962 <row topline="true">
37963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37966 \begin_layout Standard
37974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37977 \begin_layout Standard
37980 IC_LEFT() IC_RESULT()
37985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37988 \begin_layout Standard
37996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37999 \begin_layout Standard
38002 IC_RESULT = - IC_LEFT;
38008 <row topline="true">
38009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38012 \begin_layout Standard
38020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38023 \begin_layout Standard
38031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38034 \begin_layout Standard
38037 Push the operand into stack
38042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38045 \begin_layout Standard
38054 <row topline="true">
38055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38058 \begin_layout Standard
38066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38069 \begin_layout Standard
38077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38080 \begin_layout Standard
38083 Pop the operand from the stack
38088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38091 \begin_layout Standard
38100 <row topline="true">
38101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38104 \begin_layout Standard
38112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38115 \begin_layout Standard
38118 IC_LEFT() IC_RESULT()
38123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38126 \begin_layout Standard
38129 Call the function represented by IC_LEFT
38134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38137 \begin_layout Standard
38140 IC_RESULT = IC_LEFT();
38146 <row topline="true">
38147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38150 \begin_layout Standard
38158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38161 \begin_layout Standard
38164 IC_LEFT() IC_RESULT()
38169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38172 \begin_layout Standard
38175 Call via function pointer
38180 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38183 \begin_layout Standard
38186 IC_RESULT = (*IC_LEFT)();
38192 <row topline="true">
38193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38196 \begin_layout Standard
38204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38207 \begin_layout Standard
38215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38218 \begin_layout Standard
38221 Return the value in operand IC_LEFT
38226 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38229 \begin_layout Standard
38238 <row topline="true">
38239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38242 \begin_layout Standard
38250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38253 \begin_layout Standard
38261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38264 \begin_layout Standard
38272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38275 \begin_layout Standard
38284 <row topline="true">
38285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38288 \begin_layout Standard
38296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38299 \begin_layout Standard
38307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38310 \begin_layout Standard
38318 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38321 \begin_layout Standard
38330 <row topline="true">
38331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38334 \begin_layout Standard
38342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38345 \begin_layout Standard
38348 IC_LEFT() IC_RIGHT() IC_RESULT()
38353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38356 \begin_layout Standard
38364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38367 \begin_layout Standard
38370 IC_RESULT = IC_LEFT + IC_RIGHT
38376 <row topline="true">
38377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38380 \begin_layout Standard
38388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38391 \begin_layout Standard
38394 IC_LEFT() IC_RIGHT() IC_RESULT()
38399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38402 \begin_layout Standard
38410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38413 \begin_layout Standard
38416 IC_RESULT = IC_LEFT - IC_RIGHT
38422 <row topline="true">
38423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38426 \begin_layout Standard
38434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38437 \begin_layout Standard
38440 IC_LEFT() IC_RIGHT() IC_RESULT()
38445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38448 \begin_layout Standard
38456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38459 \begin_layout Standard
38462 IC_RESULT = IC_LEFT * IC_RIGHT;
38468 <row topline="true">
38469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38472 \begin_layout Standard
38480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38483 \begin_layout Standard
38486 IC_LEFT() IC_RIGHT() IC_RESULT()
38491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38494 \begin_layout Standard
38502 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38505 \begin_layout Standard
38508 IC_RESULT = IC_LEFT / IC_RIGHT;
38514 <row topline="true">
38515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38518 \begin_layout Standard
38526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38529 \begin_layout Standard
38532 IC_LEFT() IC_RIGHT() IC_RESULT()
38537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38540 \begin_layout Standard
38548 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38551 \begin_layout Standard
38554 IC_RESULT = IC_LEFT % IC_RIGHT;
38560 <row topline="true">
38561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38564 \begin_layout Standard
38572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38575 \begin_layout Standard
38578 IC_LEFT() IC_RIGHT() IC_RESULT()
38583 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38586 \begin_layout Standard
38594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38597 \begin_layout Standard
38600 IC_RESULT = IC_LEFT < IC_RIGHT;
38606 <row topline="true">
38607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38610 \begin_layout Standard
38618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38621 \begin_layout Standard
38624 IC_LEFT() IC_RIGHT() IC_RESULT()
38629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38632 \begin_layout Standard
38640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38643 \begin_layout Standard
38646 IC_RESULT = IC_LEFT > IC_RIGHT;
38652 <row topline="true">
38653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38656 \begin_layout Standard
38664 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38667 \begin_layout Standard
38670 IC_LEFT() IC_RIGHT() IC_RESULT()
38675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38678 \begin_layout Standard
38686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38689 \begin_layout Standard
38692 IC_RESULT = IC_LEFT == IC_RIGHT;
38698 <row topline="true">
38699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38702 \begin_layout Standard
38710 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38713 \begin_layout Standard
38716 IC_LEFT() IC_RIGHT() IC_RESULT()
38721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38724 \begin_layout Standard
38727 Logical and operation
38732 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38735 \begin_layout Standard
38738 IC_RESULT = IC_LEFT && IC_RIGHT;
38744 <row topline="true">
38745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38748 \begin_layout Standard
38756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38759 \begin_layout Standard
38762 IC_LEFT() IC_RIGHT() IC_RESULT()
38767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38770 \begin_layout Standard
38773 Logical or operation
38778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38781 \begin_layout Standard
38784 IC_RESULT = IC_LEFT || IC_RIGHT;
38790 <row topline="true">
38791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38794 \begin_layout Standard
38802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38805 \begin_layout Standard
38808 IC_LEFT() IC_RIGHT() IC_RESULT()
38813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38816 \begin_layout Standard
38824 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38827 \begin_layout Standard
38830 IC_RESULT = IC_LEFT ^ IC_RIGHT;
38836 <row topline="true">
38837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38840 \begin_layout Standard
38848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38851 \begin_layout Standard
38854 IC_LEFT() IC_RIGHT() IC_RESULT()
38859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38862 \begin_layout Standard
38870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38873 \begin_layout Standard
38876 IC_RESULT = IC_LEFT | IC_RIGHT;
38882 <row topline="true">
38883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38886 \begin_layout Standard
38894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38897 \begin_layout Standard
38900 IC_LEFT() IC_RIGHT() IC_RESULT()
38905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38908 \begin_layout Standard
38916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38919 \begin_layout Standard
38922 IC_RESULT = IC_LEFT & IC_RIGHT;
38928 <row topline="true">
38929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38932 \begin_layout Standard
38940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38943 \begin_layout Standard
38946 IC_LEFT() IC_RIGHT() IC_RESULT()
38951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38954 \begin_layout Standard
38962 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38965 \begin_layout Standard
38968 IC_RESULT = IC_LEFT << IC_RIGHT
38974 <row topline="true">
38975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38978 \begin_layout Standard
38986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38989 \begin_layout Standard
38992 IC_LEFT() IC_RIGHT() IC_RESULT()
38997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39000 \begin_layout Standard
39008 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39011 \begin_layout Standard
39014 IC_RESULT = IC_LEFT >> IC_RIGHT
39020 <row topline="true">
39021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39024 \begin_layout Standard
39034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39037 \begin_layout Standard
39040 IC_LEFT() IC_RESULT()
39045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39048 \begin_layout Standard
39056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39059 \begin_layout Standard
39062 IC_RESULT = (*IC_LEFT);
39068 <row topline="true">
39069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39072 \begin_layout Standard
39080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39083 \begin_layout Standard
39086 IC_RIGHT() IC_RESULT()
39091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39094 \begin_layout Standard
39102 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39105 \begin_layout Standard
39108 (*IC_RESULT) = IC_RIGHT;
39114 <row topline="true">
39115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39118 \begin_layout Standard
39126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39129 \begin_layout Standard
39132 IC_RIGHT() IC_RESULT()
39137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39140 \begin_layout Standard
39148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39151 \begin_layout Standard
39154 IC_RESULT = IC_RIGHT;
39160 <row topline="true">
39161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39164 \begin_layout Standard
39172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39175 \begin_layout Standard
39178 IC_COND IC_TRUE IC_LABEL
39183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39186 \begin_layout Standard
39190 If true label is present then jump to true label if condition is true else
39191 jump to false label if condition is false
39196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39199 \begin_layout Standard
39202 if (IC_COND) goto IC_TRUE;
39208 If (!IC_COND) goto IC_FALSE;
39214 <row topline="true">
39215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39218 \begin_layout Standard
39226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39229 \begin_layout Standard
39232 IC_LEFT() IC_RESULT()
39237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39240 \begin_layout Standard
39248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39251 \begin_layout Standard
39254 IC_RESULT = &IC_LEFT();
39260 <row topline="true">
39261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39264 \begin_layout Standard
39272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39275 \begin_layout Standard
39278 IC_JTCOND IC_JTLABELS
39283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39286 \begin_layout Standard
39289 Jump to list of labels depending on the value of JTCOND
39294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39297 \begin_layout Standard
39306 <row topline="true">
39307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39310 \begin_layout Standard
39318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39321 \begin_layout Standard
39324 IC_RIGHT() IC_LEFT() IC_RESULT()
39329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39332 \begin_layout Standard
39340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39343 \begin_layout Standard
39346 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
39352 <row topline="true">
39353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39356 \begin_layout Standard
39364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39367 \begin_layout Standard
39375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39378 \begin_layout Standard
39381 This is used for passing parameters in registers;
39383 move IC_LEFT to the next
39384 available parameter register.
39389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39392 \begin_layout Standard
39401 <row topline="true">
39402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39405 \begin_layout Standard
39413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39416 \begin_layout Standard
39424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39427 \begin_layout Standard
39430 This is used for receiving parameters passed in registers;
39433 in the next parameter register to IC_RESULT
39438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39441 \begin_layout Standard
39450 <row topline="true" bottomline="true">
39451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39454 \begin_layout Standard
39458 (some more have been added)
39463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39466 \begin_layout Standard
39472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39475 \begin_layout Standard
39481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39484 \begin_layout Standard
39508 \begin_layout Standard
39509 \begin_inset Note Note
39512 \begin_layout Standard
39513 In the original article Figure II was announced to be downloadable on
39518 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
39526 \begin_layout Paragraph*
39528 \begin_inset LatexCommand \index{iCode}
39535 \begin_layout Standard
39536 This section shows some details of iCode.
39537 The example C code does not do anything useful; it is used as an example
39538 to illustrate the intermediate code generated by the compiler.
39541 \begin_layout Verse
39551 /* This function does nothing useful.
39558 for the purpose of explaining iCode */
39561 short function (data
39570 short i=10; \InsetSpace ~
39572 /* dead initialization eliminated */
39578 /* dead initialization eliminated */
39606 /* compiler detects i,j to be induction
39611 for (i = 0, j = 10 ; i < 10 ; i++, j
39617 \begin_layout Standard
39640 mul += i * 3; \InsetSpace ~
39642 /* this multiplication remains */
39649 j * 3;\InsetSpace ~
39651 /* this multiplication changed to addition */
39665 \begin_layout Standard
39666 In addition to the operands each iCode contains information about the filename
39667 and line it corresponds to in the source file.
39668 The first field in the listing should be interpreted as follows:
39673 Filename(linenumber: iCode Execution sequence number : ICode hash table
39674 key : loop depth of the iCode).
39679 Then follows the human readable form of the ICode operation.
39680 Each operand of this triplet form can be of three basic types a) compiler
39681 generated temporary b) user defined variable c) a constant value.
39682 Note that local variables and parameters are replaced by compiler generated
39685 \begin_inset LatexCommand \index{Live range analysis}
39689 are computed only for temporaries (i.e.
39690 live ranges are not computed for global variables).
39692 \begin_inset LatexCommand \index{Register allocation}
39696 are allocated for temporaries only.
39697 Operands are formatted in the following manner:
39702 Operand Name [lr live-from : live-to ] { type information } [ registers
39708 As mentioned earlier the live ranges are computed in terms of the execution
39709 sequence number of the iCodes, for example
39711 the iTemp0 is live from (i.e.
39712 first defined in iCode with execution sequence number 3, and is last used
39713 in the iCode with sequence number 5).
39714 For induction variables such as iTemp21 the live range computation extends
39715 the lifetime from the start to the end of the loop.
39717 The register allocator
39718 used the live range information to allocate registers, the same registers
39719 may be used for different temporaries if their live ranges do not overlap,
39720 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
39721 ranges do not overlap.
39722 In addition the allocator also takes into consideration the type and usage
39723 of a temporary, for example itemp6 is a pointer to near space and is used
39724 as to fetch data from (i.e.
39725 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
39726 Some short lived temporaries are allocated to special registers which have
39727 meaning to the code generator e.g.
39728 iTemp13 is allocated to a pseudo register CC which tells the back end that
39729 the temporary is used only for a conditional jump the code generation makes
39730 use of this information to optimize a compare and jump ICode.
39734 \begin_inset LatexCommand \index{Loop optimization}
39738 performed by the compiler.
39739 It can detect induction variables iTemp21(i) and iTemp23(j).
39740 Also note the compiler does selective strength reduction
39741 \begin_inset LatexCommand \index{Strength reduction}
39746 the multiplication of an induction variable in line 18 (gint = j * 3) is
39747 changed to addition, a new temporary iTemp17 is allocated and assigned
39748 a initial value, a constant 3 is then added for each iteration of the loop.
39749 The compiler does not change the multiplication
39750 \begin_inset LatexCommand \index{Multiplication}
39754 in line 17 however since the processor does support an 8 * 8 bit multiplication.
39757 Note the dead code elimination
39758 \begin_inset LatexCommand \index{Dead-code elimination}
39762 optimization eliminated the dead assignments in line 7 & 8 to I and sum
39768 \begin_layout Standard
39771 Sample.c (5:1:0:0) _entry($9) :
39774 \begin_layout Standard
39777 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
39780 \begin_layout Standard
39783 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
39786 \begin_layout Standard
39789 Sample.c(11:4:53:0) preHeaderLbl0($11) :
39792 \begin_layout Standard
39795 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
39799 \begin_layout Standard
39802 Sample.c(11:6:5:1) _whilecontinue_0($1) :
39805 \begin_layout Standard
39808 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
39812 \begin_layout Standard
39815 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39818 \begin_layout Standard
39821 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
39825 \begin_layout Standard
39828 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
39832 \begin_layout Standard
39835 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
39839 \begin_layout Standard
39842 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
39846 \begin_layout Standard
39849 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
39850 * int}[r0] + 0x2 {short}
39853 \begin_layout Standard
39856 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
39859 \begin_layout Standard
39862 Sample.c(11:17:21:0)_whilebreak_0($3) :
39865 \begin_layout Standard
39868 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39871 \begin_layout Standard
39874 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39877 \begin_layout Standard
39880 Sample.c(15:20:54:0)preHeaderLbl1($13) :
39883 \begin_layout Standard
39886 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39889 \begin_layout Standard
39892 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39895 \begin_layout Standard
39898 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39901 \begin_layout Standard
39904 Sample.c(15:24:26:1)_forcond_0($4) :
39907 \begin_layout Standard
39910 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
39914 \begin_layout Standard
39917 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39920 \begin_layout Standard
39923 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
39924 + ITemp21 [lr21:38]{short}[r4]
39927 \begin_layout Standard
39930 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
39934 \begin_layout Standard
39937 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
39938 + iTemp15 [lr29:30]{short}[r1]
39941 \begin_layout Standard
39944 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
39948 \begin_layout Standard
39951 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
39955 \begin_layout Standard
39958 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
39962 \begin_layout Standard
39965 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
39969 \begin_layout Standard
39972 Sample.c(19:38:47:1) goto _forcond_0($4)
39975 \begin_layout Standard
39978 Sample.c(19:39:48:0)_forbreak_0($7) :
39981 \begin_layout Standard
39984 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
39985 + ITemp11 [lr19:40]{short}[r3]
39988 \begin_layout Standard
39991 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
39994 \begin_layout Standard
39997 Sample.c(20:42:51:0)_return($8) :
40000 \begin_layout Standard
40003 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
40009 Finally the code generated for this function:
40014 \begin_layout Standard
40020 \begin_layout Standard
40026 \begin_layout Standard
40034 \begin_layout Standard
40040 \begin_layout Standard
40048 \begin_layout Standard
40054 \begin_layout Standard
40057 ; ----------------------------------------------
40060 \begin_layout Standard
40063 ; function function
40066 \begin_layout Standard
40069 ; ----------------------------------------------
40072 \begin_layout Standard
40078 \begin_layout Standard
40081 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
40084 \begin_layout Standard
40092 \begin_layout Standard
40095 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
40098 \begin_layout Standard
40106 \begin_layout Standard
40109 ;_whilecontinue_0($1) :
40112 \begin_layout Standard
40118 \begin_layout Standard
40121 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
40124 \begin_layout Standard
40127 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
40130 \begin_layout Standard
40138 \begin_layout Standard
40146 \begin_layout Standard
40154 \begin_layout Standard
40162 \begin_layout Standard
40170 \begin_layout Standard
40178 \begin_layout Standard
40186 \begin_layout Standard
40192 \begin_layout Standard
40195 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
40198 \begin_layout Standard
40206 \begin_layout Standard
40214 \begin_layout Standard
40217 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
40220 \begin_layout Standard
40228 \begin_layout Standard
40236 \begin_layout Standard
40244 \begin_layout Standard
40252 \begin_layout Standard
40260 \begin_layout Standard
40268 \begin_layout Standard
40271 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
40274 \begin_layout Standard
40282 \begin_layout Standard
40290 \begin_layout Standard
40298 \begin_layout Standard
40306 \begin_layout Standard
40314 \begin_layout Standard
40317 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
40320 \begin_layout Standard
40328 \begin_layout Standard
40336 \begin_layout Standard
40344 \begin_layout Standard
40347 ; iTemp6 [lr5:16]{_near * int}[r0] =
40350 \begin_layout Standard
40353 ; iTemp6 [lr5:16]{_near * int}[r0] +
40356 \begin_layout Standard
40362 \begin_layout Standard
40370 \begin_layout Standard
40373 ; goto _whilecontinue_0($1)
40376 \begin_layout Standard
40384 \begin_layout Standard
40387 ; _whilebreak_0($3) :
40390 \begin_layout Standard
40396 \begin_layout Standard
40399 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
40402 \begin_layout Standard
40410 \begin_layout Standard
40413 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
40416 \begin_layout Standard
40424 \begin_layout Standard
40427 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
40430 \begin_layout Standard
40438 \begin_layout Standard
40441 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
40444 \begin_layout Standard
40452 \begin_layout Standard
40460 \begin_layout Standard
40463 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
40466 \begin_layout Standard
40474 \begin_layout Standard
40482 \begin_layout Standard
40488 \begin_layout Standard
40494 \begin_layout Standard
40497 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
40500 \begin_layout Standard
40503 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
40506 \begin_layout Standard
40514 \begin_layout Standard
40522 \begin_layout Standard
40530 \begin_layout Standard
40538 \begin_layout Standard
40546 \begin_layout Standard
40552 \begin_layout Standard
40555 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
40558 \begin_layout Standard
40561 ; iTemp21 [lr21:38]{short}[r4]
40564 \begin_layout Standard
40572 \begin_layout Standard
40580 \begin_layout Standard
40588 \begin_layout Standard
40591 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
40594 \begin_layout Standard
40602 \begin_layout Standard
40610 \begin_layout Standard
40618 \begin_layout Standard
40626 \begin_layout Standard
40629 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
40632 \begin_layout Standard
40635 ; iTemp15 [lr29:30]{short}[r1]
40638 \begin_layout Standard
40646 \begin_layout Standard
40654 \begin_layout Standard
40657 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
40660 \begin_layout Standard
40668 \begin_layout Standard
40676 \begin_layout Standard
40684 \begin_layout Standard
40692 \begin_layout Standard
40700 \begin_layout Standard
40708 \begin_layout Standard
40711 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
40714 \begin_layout Standard
40722 \begin_layout Standard
40730 \begin_layout Standard
40738 \begin_layout Standard
40746 \begin_layout Standard
40754 \begin_layout Standard
40762 \begin_layout Standard
40765 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
40768 \begin_layout Standard
40776 \begin_layout Standard
40779 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
40782 \begin_layout Standard
40790 \begin_layout Standard
40795 cjne r5,#0xff,00104$
40798 \begin_layout Standard
40806 \begin_layout Standard
40809 ; goto _forcond_0($4)
40812 \begin_layout Standard
40820 \begin_layout Standard
40823 ; _forbreak_0($7) :
40826 \begin_layout Standard
40832 \begin_layout Standard
40835 ; ret iTemp24 [lr40:41]{short}
40838 \begin_layout Standard
40846 \begin_layout Standard
40854 \begin_layout Standard
40862 \begin_layout Standard
40868 \begin_layout Standard
40874 \begin_layout Standard
40884 \begin_layout Section
40885 A few words about basic block successors, predecessors and dominators
40888 \begin_layout Standard
40889 Successors are basic blocks
40890 \begin_inset LatexCommand \index{Basic blocks}
40894 that might execute after this basic block.
40896 Predecessors are basic blocks
40897 that might execute before reaching this basic block.
40899 Dominators are basic
40900 blocks that WILL execute before reaching this basic block.
40905 \begin_layout Standard
40909 \begin_layout Standard
40913 \begin_layout Standard
40921 \begin_layout Standard
40925 \begin_layout Standard
40933 \begin_layout Standard
40939 \begin_layout Standard
40940 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
40943 \begin_layout Standard
40944 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
40947 \begin_layout Standard
40948 c) domVect of [BB4] = BB1 ...
40949 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
40953 \begin_layout Chapter
40957 \begin_layout Standard
40958 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/#Who}
40968 Thanks to all the other volunteer developers who have helped with coding,
40969 testing, web-page creation, distribution sets, etc.
40970 You know who you are :-)
40978 Thanks to Sourceforge
40979 \begin_inset LatexCommand \url{http://www.sf.net}
40983 which has hosted the project since 1999 and donates significant download
40992 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
40993 cycles and bandwidth for snapshot builds.
40998 \begin_layout Standard
40999 This document was initially written by Sandeep Dutta
41002 \begin_layout Standard
41003 All product names mentioned herein may be trademarks
41004 \begin_inset LatexCommand \index{Trademarks}
41008 of their respective companies.
41012 \begin_layout Section*
41016 \begin_layout Standard
41017 To avoid confusion, the installation and building options for SDCC itself
41018 (chapter 2) are not part of the index.
41021 \begin_layout Standard
41022 \begin_inset LatexCommand \printindex{}