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
23481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23484 \begin_layout Standard
23490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23493 \begin_layout Standard
23499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23502 \begin_layout Standard
23509 <row topline="true" bottomline="true">
23510 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23513 \begin_layout Standard
23519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23522 \begin_layout Standard
23528 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23531 \begin_layout Standard
23537 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23540 \begin_layout Standard
23548 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23551 \begin_layout Standard
23552 SiLabs C8051F120 example
23557 <cell multicolumn="2" alignment="center" valignment="top" usebox="none">
23560 \begin_layout Standard
23566 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23569 \begin_layout Standard
23575 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23578 \begin_layout Standard
23593 Usually the hardware uses some sfr (an output port or an internal sfr) to
23594 select a bank and put it in the banked area of the memory map.
23595 Because the selected bank usually becomes active immediately you cannot
23596 jump call directly from one bank to another and need to use a so-called
23597 trampoline in the common area.
23598 For SDCC an example trampoline is in crtbank.asm and you may need to change
23599 it to your 8051 derivative or schematic.
23600 The presented code is written for the C8051F120.
23604 When calling a banked function
23605 SDCC will put the LSB of the functions address in register R0, the MSB
23606 in R1 and the bank in R2 and then call this trampoline __sdcc_banked_call.
23607 The current selected bank is saved on the stack, the new bank is selected
23608 and an indirect jump is made.
23609 When the banked function returns it jumps to __sdcc_banked_ret which restores
23610 the previous bank and returns to the caller.
23613 \begin_layout Subsubsection
23617 \begin_layout Standard
23618 When writing banked software using SDCC you need to use some special keywords
23620 You also need to take over a bit of work from the linker.
23624 To create a function
23625 that can be called from another bank it requires the keyword banked.
23626 The caller must see this in the prototype of the callee and the callee
23627 needs it for a proper return.
23628 Called functions within the same bank as the caller do not need the banked
23629 keyword nor do functions in the common area.
23630 Beware: SDCC does not know or check if functions are in the same bank.
23631 This is your responsibility!
23635 Normally all functions you write end up in
23637 If you want a function explicitly to reside in the common area put it in
23639 This applies for instance to interrupt service routines as they should
23643 \begin_layout Standard
23644 Functions that need to be in a switched bank must be put in a named segment.
23645 The name can be mostly anything upto eight characters (e.g.
23647 To do this you either use --codeseg BANK1 on the command line when compiling
23648 or #pragma codeseg BANK1 at the top of the C source file.
23649 The segment name always applies to the whole source file and generated
23650 object so functions for different banks need to be defined in different
23655 When linking your objects you need to tell the linker where
23656 to put your segments.
23657 To do this you use the following command line option to SDCC: -Wl-b BANK1=0x180
23659 This sets the virtual start address of this segment.
23660 It sets the banknumber to 0x01 and maps the bank to 0x8000 and up.
23661 The linker will not check for overflows, again this is your responsibility.
23664 \begin_layout Standard
23665 \begin_inset VSpace bigskip
23671 \begin_layout Section
23675 \begin_layout Standard
23677 \begin_inset LatexCommand \index{DS80C400}
23682 \begin_inset LatexCommand \index{DS400}
23686 microcontroller has a rich set of peripherals.
23687 In its built-in ROM library it includes functions to access some of the
23688 features, among them is a TCP stack with IP4 and IP6 support.
23689 Library headers (currently in beta status) and other files are provided
23693 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
23699 \begin_inset VSpace bigskip
23705 \begin_layout Section
23706 The Z80 and gbz80 port
23709 \begin_layout Standard
23710 SDCC can target both the Zilog Z80
23711 \begin_inset LatexCommand \index{Z80}
23715 and the Nintendo Gameboy's Z80-like gbz80
23716 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
23721 The Z80 port is passed through the same
23724 \begin_inset LatexCommand \index{Regression test}
23731 \begin_inset LatexCommand \ref{sec:Quality-control}
23735 ) as the MCS51 and DS390 ports, so floating point support, support for long
23736 variables and bitfield support is fine.
23737 See mailing lists and forums about interrupt routines.
23740 \begin_layout Standard
23741 As always, the code is the authoritative reference - see z80/ralloc.c and
23744 \begin_inset LatexCommand \index{Z80!stack}
23748 frame is similar to that generated by the IAR Z80 compiler.
23749 IX is used as the base pointer, HL and IY are used as a temporary registers,
23750 and BC and DE are available for holding variables.
23752 \begin_inset LatexCommand \index{Z80!return value}
23756 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
23758 The gbz80 port use the same set of registers for the return values, but
23759 in a different order of significance: E (one byte), DE (two bytes), or
23761 \begin_inset VSpace bigskip
23767 \begin_layout Section
23771 \begin_layout Standard
23772 The port to the Freescale/Motorola HC08
23773 \begin_inset LatexCommand \index{HC08}
23777 family has been added in October 2003, and is still undergoing some basic
23779 The code generator is complete, but the register allocation is still quite
23781 Some of the SDCC's standard C library functions have embedded non-HC08
23782 inline assembly and so are not yet usable.
23785 \begin_layout Standard
23786 The HC08 port passes the regression test suite (see section
23787 \begin_inset LatexCommand \ref{sec:Quality-control}
23792 \begin_inset VSpace bigskip
23798 \begin_layout Section
23800 \begin_inset LatexCommand \index{PIC14}
23807 \begin_layout Standard
23808 The PIC14 port adds support for Microchip
23809 \begin_inset LatexCommand \index{Microchip}
23814 \begin_inset Formula $^{\text{TM}}$
23818 \begin_inset LatexCommand \index{PIC14}
23823 \begin_inset Formula $^{\text{TM}}$
23826 MCUs with 14 bit wide instructions.
23827 This port is not yet mature and still lacks many features.
23828 However, it can work for simple code.
23831 \begin_layout Standard
23832 Currently supported devices include:
23835 \begin_layout Standard
23836 12F: 629, 635, 675, 683
23839 \begin_layout Standard
23843 \begin_layout Standard
23847 \begin_layout Standard
23848 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
23851 \begin_layout Standard
23852 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
23856 \begin_layout Standard
23860 \begin_layout Standard
23861 16CR: 620a, 73, 74, 76, 77
23864 \begin_layout Standard
23865 16F: 616, 627, 627a, 628, 628a, 630, 636, 639, 648, 648a, 676, 684, 685,
23869 \begin_layout Standard
23870 16F: 716, 72, 73, 737, 74, 747, 76, 767, 77, 777, 785
23873 \begin_layout Standard
23874 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
23875 877, 877a, 88, 886, 887
23878 \begin_layout Standard
23879 16F: 913, 914, 916, 917, 946
23882 \begin_layout Standard
23886 \begin_layout Standard
23887 An up-to-date list of currently supported devices can be obtained via
23889 sdcc -mpic14 -phelp foo.c
23891 (foo.c must exist...).
23894 \begin_layout Subsection
23896 \begin_inset LatexCommand \index{code page (pic14)}
23901 \begin_inset LatexCommand \index{Memory bank (pic14)}
23908 \begin_layout Standard
23909 The linker organizes allocation for the code page and RAM banks.
23910 It does not have intimate knowledge of the code flow.
23911 It will put all the code section of a single .asm file into a single code
23913 In order to make use of multiple code pages, separate asm files must be
23915 The compiler assigns all
23919 functions of a single .c file into the same code page.
23923 To get the best results,
23924 follow these guidelines:
23927 \begin_layout Enumerate
23928 Make local functions static, as non static functions require code page selection
23931 Due to the way sdcc handles functions, place called functions prior
23932 to calling functions in the file wherever possible: Otherwise sdcc will
23933 insert unneccessary pagesel directives around the call, believing that
23934 the called function is externally defined.
23937 \begin_layout Enumerate
23938 For devices that have multiple code pages it is more efficient to use the
23939 same number of files as pages: Use up to 4 separate .c files for the 16F877,
23940 but only 2 files for the 16F874.
23941 This way the linker can put the code for each file into different code
23942 pages and there will be less page selection overhead.
23945 \begin_layout Enumerate
23946 And as for any 8 bit micro (especially for PIC14 as they have a very simple
23947 instruction set), use `unsigned char' wherever possible instead of `int'.
23950 \begin_layout Subsection
23951 Adding New Devices to the Port
23954 \begin_layout Standard
23955 Adding support for a new 14
23959 \begin_layout Standard
23968 bit PIC MCU requires the following steps:
23971 \begin_layout Enumerate
23972 Create a new device description.
23974 Each device is described in two files: pic16f*.h
23976 These files primarily define SFRs, structs to access their bits, and symbolic
23977 configuration options.
23978 Both files can be generated from gputils' .inc files using the perl script
23981 support/scripts/inc2h.pl
23984 This file also contains further instructions on how to proceed.
23987 \begin_layout Enumerate
23988 Copy the .h file into SDCC's include path and either add the .c file to your
23989 project or copy it to
23991 device/lib/pic/libdev
23994 Afterwards, rebuild and install the libraries.
23997 \begin_layout Enumerate
23998 Edit pic14devices.txt in SDCC's include path (
24000 device/include/pic/
24002 in the source tree or
24004 /usr/local/share/sdcc/include/pic
24006 after installation).
24008 You need to add a device specification here to make
24009 the memory layout (code banks, RAM, aliased memory regions, ...) known to
24011 Probably you can copy and modify an existing entry.
24012 The file format is documented at the top of the file.
24015 \begin_layout Subsection
24019 \begin_layout Standard
24020 For the interrupt function, use the keyword `__interrupt'
24021 \begin_inset LatexCommand \index{PIC14!interrupt}
24025 with level number of 0 (PIC14 only has 1 interrupt so this number is only
24026 there to avoid a syntax error - it ought to be fixed).
24030 \begin_layout Verse
24033 void Intr(void) __interrupt 0
24039 T0IF = 0; /* Clear timer interrupt */
24044 \begin_layout Subsection
24045 Linking and Assembling
24048 \begin_layout Standard
24049 For assembling you can use either GPUTILS'
24050 \begin_inset LatexCommand \index{gputils (pic tools)}
24054 gpasm.exe or MPLAB's mpasmwin.exe.
24055 GPUTILS are available from
24056 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24061 For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
24062 If you use MPLAB and an interrupt function then the linker script file
24063 vectors section will need to be enlarged to link with mplink.
24074 \begin_layout Verse
24087 sdcc -V -mpic14 -p16f877 -c $<
24091 $(PRJ).hex: $(OBJS)
24101 gplink -m -s $(PRJ).lkr
24102 -o $(PRJ).hex $(OBJS) libsdcc.lib
24105 \begin_layout Standard
24113 \begin_layout Verse
24126 sdcc -S -V -mpic14 -p16f877 $<
24136 mpasmwin /q /o $*.asm
24140 $(PRJ).hex: $(OBJS)
24151 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
24154 \begin_layout Standard
24155 Please note that indentations within a
24159 have to be done with a tabulator character.
24162 \begin_layout Subsection
24163 Command-Line Options
24166 \begin_layout Standard
24167 Besides the switches common to all SDCC backends, the PIC14 port accepts
24168 the following options (for an updated list see sdcc -
24172 \begin_layout Standard
24184 \begin_layout Description
24189 \begin_layout Standard
24199 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
24203 emit debug info in assembly output
24206 \begin_layout Description
24211 \begin_layout Standard
24221 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
24225 disable (slightly faulty) optimization on pCode
24228 \begin_layout Description
24233 \begin_layout Standard
24243 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
24247 sets the lowest address of the argument passing stack (defaults to a suitably
24248 large shared databank to reduce BANKSEL overhead)
24251 \begin_layout Description
24256 \begin_layout Standard
24266 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
24270 sets the size if the argument passing stack (default: 16, minimum: 4)
24273 \begin_layout Subsection
24274 Environment Variables
24277 \begin_layout Standard
24278 The PIC14 port recognizes the following environment variables:
24281 \begin_layout Description
24282 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
24283 register (the ones called r0xNNNN) in a section of its own.
24284 By default (if this variable is unset), sdcc tries to cluster registers
24285 in sections in order to reduce the BANKSEL overhead when accessing them.
24288 \begin_layout Subsection
24292 \begin_layout Standard
24293 The PIC14 library currently only contains support routines required by the
24294 compiler to implement multiplication, division, and floating point support.
24295 No libc-like replacement is available at the moment, though many of the
24296 common sdcc library sources (in
24300 ) should also compile with the PIC14 port.
24303 \begin_layout Subsubsection
24304 error: missing definition for symbol ``__gptrget1''
24307 \begin_layout Standard
24308 The PIC14 port uses library routines to provide more complex operations
24309 like multiplication, division/modulus and (generic) pointer dereferencing.
24310 In order to add these routines to your project, you must link with PIC14's
24316 For single source file projects this is done automatically, more complex
24321 to the linker's arguments.
24322 Make sure you also add an include path for the library (using the -I switch
24326 \begin_layout Subsubsection
24327 Processor mismatch in file ``XXX''.
24330 \begin_layout Standard
24331 This warning can usually be ignored due to the very good compatibility amongst
24336 \begin_layout Standard
24346 \begin_inset LatexCommand \index{PIC14}
24353 \begin_layout Standard
24354 You might also consider recompiling the library for your specific device
24355 by changing the ARCH=p16f877 (default target) entry in
24357 device/lib/pic/Makefile.in
24361 device/lib/pic/Makefile
24363 to reflect your device.
24364 This might even improve performance for smaller devices as unneccesary
24365 BANKSELs might be removed.
24368 \begin_layout Subsection
24372 \begin_layout Subsubsection
24376 \begin_layout Standard
24377 Functions with variable argument lists (like printf) are not yet supported.
24378 Similarly, taking the address of the first argument passed into a function
24379 does not work: It is currently passed in WREG and has no address...
24382 \begin_layout Subsubsection
24383 Regression tests fail
24386 \begin_layout Standard
24387 Though the small subset of regression tests in src/regression passes, SDCC
24388 regression test suite does not, indicating that there are still major bugs
24390 However, many smaller projects have successfully used SDCC in the past...
24393 \begin_layout Standard
24401 \begin_layout Section
24403 \begin_inset LatexCommand \index{PIC16}
24410 \begin_layout Standard
24411 The PIC16 port adds support for Microchip
24412 \begin_inset LatexCommand \index{Microchip}
24417 \begin_inset Formula $^{\text{TM}}$
24421 \begin_inset LatexCommand \index{PIC}
24426 \begin_inset Formula $^{\text{TM}}$
24429 MCUs with 16 bit wide instructions.
24430 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
24431 ; devices supported by the port include:
24434 \begin_layout Standard
24435 18F: 242, 248, 252, 258, 442, 448, 452, 458
24438 \begin_layout Standard
24442 \begin_layout Standard
24443 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 24j10, 2525, 2550, 25j10,
24447 \begin_layout Standard
24448 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 44j10, 4520, 4525, 4550,
24452 \begin_layout Standard
24453 18F: 6520, 6620, 6680, 6720
24456 \begin_layout Standard
24457 18F: 8520, 8620, 8680, 8720
24460 \begin_layout Subsection
24464 \begin_layout Standard
24465 PIC16 port supports the standard command line arguments as supposed, with
24466 the exception of certain cases that will be mentioned in the following
24470 \begin_layout Description
24475 \begin_layout Standard
24485 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
24493 \begin_layout Standard
24505 \begin_layout Description
24510 \begin_layout Standard
24519 -fommit-frame-pointer
24520 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
24524 Frame pointer will be omitted when the function uses no local variables.
24527 \begin_layout Subsection
24528 Port Specific Options
24529 \begin_inset LatexCommand \index{Options PIC16}
24536 \begin_layout Standard
24537 The port specific options appear after the global options in the sdcc -
24541 \begin_layout Standard
24553 \begin_layout Subsubsection
24554 Code Generation Options
24557 \begin_layout Standard
24558 These options influence the generated assembler code.
24561 \begin_layout Description
24566 \begin_layout Standard
24575 -pstack-model=[model] Used in conjuction with the command above.
24576 Defines the stack model to be used, valid stack models are:
24581 \labelwidthstring 00.00.0000
24586 Selects small stack model.
24587 8 bit stack and frame pointers.
24588 Supports 256 bytes stack size.
24592 \labelwidthstring 00.00.0000
24597 Selects large stack model.
24598 16 bit stack and frame pointers.
24599 Supports 65536 bytes stack size.
24603 \begin_layout Description
24608 \begin_layout Standard
24617 -pno-banksel Do not generate BANKSEL assembler directives.
24620 \begin_layout Description
24625 \begin_layout Standard
24634 -extended Enable extended instruction set/literal offset addressing mode.
24638 \begin_layout Subsubsection
24639 Optimization Options
24642 \begin_layout Description
24647 \begin_layout Standard
24656 -obanksel=n Set optimization level for inserting BANKSELs.
24663 \labelwidthstring 00.00.0000
24668 \labelwidthstring 00.00.0000
24669 1 checks previous used register and if it is the same then does not emit
24670 BANKSEL, accounts only for labels.
24674 \labelwidthstring 00.00.0000
24675 2 tries to check the location of (even different) symbols and removes BANKSELs
24676 if they are in the same bank.
24681 Important: There might be problems if the linker script has data sections
24682 across bank borders!
24686 \begin_layout Description
24691 \begin_layout Standard
24700 -denable-peeps Force the usage of peepholes.
24704 \begin_layout Description
24709 \begin_layout Standard
24718 -optimize-goto Try to use (conditional) BRA instead of GOTO.
24721 \begin_layout Description
24726 \begin_layout Standard
24735 -optimize-cmp Try to optimize some compares.
24738 \begin_layout Description
24743 \begin_layout Standard
24752 -optimize-df Analyze the dataflow of the generated code and improve it.
24755 \begin_layout Subsubsection
24759 \begin_layout Description
24764 \begin_layout Standard
24773 -asm= Sets the full path and name of an external assembler to call.
24776 \begin_layout Description
24781 \begin_layout Standard
24791 \begin_inset LatexCommand \index{PIC16!MPLAB}
24795 compatibility option.
24796 Currently only suppresses special gpasm directives.
24799 \begin_layout Subsubsection
24803 \begin_layout Description
24808 \begin_layout Standard
24817 -link= Sets the full path and name of an external linker to call.
24820 \begin_layout Description
24825 \begin_layout Standard
24834 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
24835 unitialized data variables with [kword].
24836 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
24839 \begin_layout Description
24844 \begin_layout Standard
24853 -ivt-loc=n Place the interrupt vector table at address
24858 Useful for bootloaders.
24861 \begin_layout Description
24866 \begin_layout Standard
24875 -nodefaultlibs Do not link default libraries when linking.
24878 \begin_layout Description
24883 \begin_layout Standard
24892 -use-crt= Use a custom run-time module instead of the defaults.
24895 \begin_layout Description
24900 \begin_layout Standard
24909 -no-crt Don't link the default run-time modules
24912 \begin_layout Subsubsection
24916 \begin_layout Standard
24917 Debugging options enable extra debugging information in the output files.
24920 \begin_layout Description
24925 \begin_layout Standard
24934 -debug-xtra Similar to -
24938 \begin_layout Standard
24948 \begin_inset LatexCommand \index{-\/-debug}
24952 , but dumps more information.
24955 \begin_layout Description
24960 \begin_layout Standard
24969 -debug-ralloc Force register allocator to dump <source>.d file with debugging
24971 <source> is the name of the file being compiled.
24974 \begin_layout Description
24979 \begin_layout Standard
24988 -pcode-verbose Enable pcode debugging information in translation.
24991 \begin_layout Description
24996 \begin_layout Standard
25005 -calltree Dump call tree in .calltree file.
25008 \begin_layout Description
25013 \begin_layout Standard
25022 -gstack Trace push/pops for stack pointer overflow.
25025 \begin_layout Subsection
25026 Enviroment Variables
25029 \begin_layout Standard
25030 There is a number of enviromental variables that can be used when running
25031 SDCC to enable certain optimizations or force a specific program behaviour.
25032 these variables are primarily for debugging purposes so they can be enabled/dis
25036 \begin_layout Standard
25037 Currently there is only two such variables available:
25040 \begin_layout Description
25041 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
25042 bitfields is optimized by directly loading FSR0 with the address of the
25043 bitfield structure.
25044 Normally SDCC will cast the bitfield structure to a bitfield pointer and
25046 This step saves data ram and code space for functions that make heavy use
25048 (i.e., 80 bytes of code space are saved when compiling malloc.c with this
25053 \begin_layout Description
25054 NO_REG_OPT Do not perform pCode registers optimization.
25055 This should be used for debugging purposes.
25056 If bugs in the pcode optimizer are found, users can benefit from temporarily
25057 disabling the optimizer until the bug is fixed.
25060 \begin_layout Subsection
25061 Preprocessor Macros
25064 \begin_layout Standard
25066 \begin_inset LatexCommand \index{PIC16}
25070 port defines the following preprocessor macros while translating a source.
25073 \begin_layout Standard
25075 \begin_inset Tabular
25076 <lyxtabular version="3" rows="6" columns="2">
25078 <column alignment="center" valignment="top" leftline="true" width="0">
25079 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25080 <row topline="true" bottomline="true">
25081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25084 \begin_layout Standard
25090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25093 \begin_layout Standard
25100 <row topline="true">
25101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25104 \begin_layout Standard
25110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25113 \begin_layout Standard
25114 Port identification
25120 <row topline="true">
25121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25124 \begin_layout Standard
25129 \begin_layout Standard
25143 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25146 \begin_layout Standard
25147 Port identification (same as above)
25153 <row topline="true">
25154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25157 \begin_layout Standard
25163 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25166 \begin_layout Standard
25167 MCU Identification.
25172 is the microcontrol identification number, i.e.
25179 <row topline="true">
25180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25183 \begin_layout Standard
25188 \begin_layout Standard
25202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25205 \begin_layout Standard
25206 MCU Identification (same as above)
25212 <row topline="true" bottomline="true">
25213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25216 \begin_layout Standard
25222 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25225 \begin_layout Standard
25226 nnn = SMALL or LARGE respectively according to the stack model used
25239 \begin_layout Standard
25240 In addition the following macros are defined when calling assembler:
25243 \begin_layout Standard
25245 \begin_inset Tabular
25246 <lyxtabular version="3" rows="4" columns="2">
25248 <column alignment="center" valignment="top" leftline="true" width="0">
25249 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25250 <row topline="true" bottomline="true">
25251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25254 \begin_layout Standard
25260 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25263 \begin_layout Standard
25270 <row topline="true">
25271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25274 \begin_layout Standard
25280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25283 \begin_layout Standard
25284 MCU Identification.
25289 is the microcontrol identification number, i.e.
25296 <row topline="true">
25297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25300 \begin_layout Standard
25306 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25309 \begin_layout Standard
25310 nnn = SMALL or LARGE respectively according to the memory model used for
25317 <row topline="true" bottomline="true">
25318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25321 \begin_layout Standard
25327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25330 \begin_layout Standard
25331 nnn = SMALL or LARGE respectively according to the stack model used
25344 \begin_layout Subsection
25348 \begin_layout Standard
25350 \begin_inset LatexCommand \index{PIC16}
25354 port uses the following directories for searching header files and libraries.
25357 \begin_layout Standard
25359 \begin_inset Tabular
25360 <lyxtabular version="3" rows="3" columns="4">
25362 <column alignment="center" valignment="top" leftline="true" width="0">
25363 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25364 <column alignment="center" valignment="top" width="0">
25365 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25366 <row topline="true" bottomline="true">
25367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25370 \begin_layout Standard
25376 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25379 \begin_layout Standard
25385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25388 \begin_layout Standard
25394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25397 \begin_layout Standard
25404 <row topline="true">
25405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25408 \begin_layout Standard
25409 PREFIX/sdcc/include/pic16
25414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25417 \begin_layout Standard
25418 PIC16 specific headers
25423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25426 \begin_layout Standard
25432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25435 \begin_layout Standard
25442 <row topline="true" bottomline="true">
25443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25446 \begin_layout Standard
25447 PREFIX/sdcc/lib/pic16
25452 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25455 \begin_layout Standard
25456 PIC16 specific libraries
25461 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25464 \begin_layout Standard
25470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25473 \begin_layout Standard
25487 \begin_layout Subsection
25489 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
25496 \begin_layout Standard
25498 \begin_inset LatexCommand \index{PIC16}
25502 port currently supports the following pragmas:
25505 \begin_layout Description
25507 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
25511 This forces the code generator to initialize the stack & frame pointers
25512 at a specific address.
25513 This is an ad hoc solution for cases where no STACK directive is available
25514 in the linker script or gplink is not instructed to create a stack section.
25517 stack pragma should be used only once in a project.
25518 Multiple pragmas may result in indeterminate behaviour of the program.
25522 \begin_layout Standard
25523 The old format (ie.
25524 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
25525 cross page boundaries (or even exceed the available data RAM) and crash
25527 Make sure that stack does not cross page boundaries when using the SMALL
25535 The format is as follows:
25540 \begin_layout LyX-Code
25541 #pragma stack bottom_address [stack_size]
25546 \begin_layout Standard
25551 is the lower bound of the stack section.
25552 The stack pointer initially will point at address (bottom_address+stack_size-1).
25555 \begin_layout LyX-Code
25559 \begin_layout LyX-Code
25563 \begin_layout LyX-Code
25564 /* initializes stack of 100 bytes at RAM address 0x200 */
25567 \begin_layout LyX-Code
25568 #pragma stack 0x200 100
25571 \begin_layout Standard
25572 If the stack_size field is omitted then a stack is created with the default
25574 This size might be enough for most programs, but its not enough for operations
25575 with deep function nesting or excessive stack usage.
25578 \begin_layout Description
25580 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
25584 Force a function to a static FLASH address.
25587 \begin_layout LyX-Code
25591 \begin_layout LyX-Code
25595 \begin_layout LyX-Code
25596 /* place function test_func at 0x4000 */
25599 \begin_layout LyX-Code
25600 #pragma code test_func 0x4000
25603 \begin_layout LyX-Code
25607 \begin_layout Description
25608 library instructs the linker to use a library module.
25613 \begin_layout LyX-Code
25614 #pragma library module_name
25617 \begin_layout Standard
25622 can be any library or object file (including its path).
25623 Note that there are four reserved keywords which have special meaning.
25627 \begin_layout Standard
25629 \begin_inset Tabular
25630 <lyxtabular version="3" rows="6" columns="3">
25632 <column alignment="center" valignment="top" leftline="true" width="0">
25633 <column alignment="block" valignment="top" leftline="true" width="20page%">
25634 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
25635 <row topline="true" bottomline="true">
25636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25639 \begin_layout Standard
25645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25648 \begin_layout Standard
25654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25657 \begin_layout Standard
25664 <row topline="true">
25665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25668 \begin_layout Standard
25676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25679 \begin_layout Standard
25680 ignore all library pragmas
25685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25688 \begin_layout Standard
25697 <row topline="true">
25698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25701 \begin_layout Standard
25709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25712 \begin_layout Standard
25718 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25721 \begin_layout Standard
25732 <row topline="true">
25733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25736 \begin_layout Standard
25744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25747 \begin_layout Standard
25748 link the Math libarary
25753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25756 \begin_layout Standard
25767 <row topline="true">
25768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25771 \begin_layout Standard
25779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25782 \begin_layout Standard
25783 link the I/O library
25788 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25791 \begin_layout Standard
25802 <row topline="true" bottomline="true">
25803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25806 \begin_layout Standard
25814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25817 \begin_layout Standard
25818 link the debug library
25823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25826 \begin_layout Standard
25843 * is the device number, i.e.
25844 452 for PIC18F452 MCU.
25847 \begin_layout Standard
25848 This feature allows for linking with specific libraries withoug having to
25849 explicit name them in the command line.
25854 keyword will reject all modules specified by the library pragma.
25857 \begin_layout Description
25858 udata The pragma udata instructs the compiler to emit code so that linker
25859 will place a variable at a specific memory bank.
25862 \begin_layout LyX-Code
25866 \begin_layout LyX-Code
25870 \begin_layout LyX-Code
25871 /* places variable foo at bank2 */
25874 \begin_layout LyX-Code
25875 #pragma udata bank2 foo
25878 \begin_layout LyX-Code
25882 \begin_layout Standard
25883 In order for this pragma to work extra SECTION directives should be added
25884 in the .lkr script.
25885 In the following example a sample .lkr file is shown:
25888 \begin_layout LyX-Code
25892 \begin_layout LyX-Code
25893 // Sample linker script for the PIC18F452 processor
25896 \begin_layout LyX-Code
25900 \begin_layout LyX-Code
25901 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
25904 \begin_layout LyX-Code
25905 CODEPAGE NAME=page START=0x2A END=0x7FFF
25908 \begin_layout LyX-Code
25909 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
25912 \begin_layout LyX-Code
25913 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
25916 \begin_layout LyX-Code
25917 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
25920 \begin_layout LyX-Code
25921 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
25924 \begin_layout LyX-Code
25925 ACCESSBANK NAME=accessram START=0x0 END=0x7F
25928 \begin_layout LyX-Code
25932 \begin_layout LyX-Code
25933 DATABANK NAME=gpr0 START=0x80 END=0xFF
25936 \begin_layout LyX-Code
25937 DATABANK NAME=gpr1 START=0x100 END=0x1FF
25940 \begin_layout LyX-Code
25941 DATABANK NAME=gpr2 START=0x200 END=0x2FF
25944 \begin_layout LyX-Code
25945 DATABANK NAME=gpr3 START=0x300 END=0x3FF
25948 \begin_layout LyX-Code
25949 DATABANK NAME=gpr4 START=0x400 END=0x4FF
25952 \begin_layout LyX-Code
25953 DATABANK NAME=gpr5 START=0x500 END=0x5FF
25956 \begin_layout LyX-Code
25957 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
25960 \begin_layout LyX-Code
25964 \begin_layout LyX-Code
25965 SECTION NAME=CONFIG ROM=config
25968 \begin_layout LyX-Code
25972 \begin_layout LyX-Code
25973 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
25976 \begin_layout LyX-Code
25977 SECTION NAME=bank1 RAM=gpr1 # should be added to link
25980 \begin_layout LyX-Code
25981 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
25984 \begin_layout LyX-Code
25985 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
25988 \begin_layout LyX-Code
25989 SECTION NAME=bank4 RAM=gpr4
25992 \begin_layout LyX-Code
25993 SECTION NAME=bank5 RAM=gpr5
25996 \begin_layout Standard
25997 The linker will recognise the section name set in the pragma statement and
25998 will position the variable at the memory bank set with the RAM field at
25999 the SECTION line in the linker script file.
26002 \begin_layout Subsection
26004 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
26011 \begin_layout Standard
26012 There is one main header file
26013 \begin_inset LatexCommand \index{PIC16!Header files}
26017 that can be included to the source files using the pic16
26018 \begin_inset LatexCommand \index{PIC16}
26028 This header file contains the definitions for the processor special registers,
26029 so it is necessary if the source accesses them.
26030 It can be included by adding the following line in the beginning of the
26034 \begin_layout LyX-Code
26035 #include <pic18fregs.h>
26038 \begin_layout Standard
26039 The specific microcontroller is selected within the pic18fregs.h automatically,
26040 so the same source can be used with a variety of devices.
26043 \begin_layout Subsection
26047 \begin_layout Standard
26049 \begin_inset LatexCommand \index{PIC16!Libraries}
26054 \begin_inset LatexCommand \index{PIC16}
26058 port depends on are the microcontroller device libraries which contain
26059 the symbol definitions for the microcontroller special function registers.
26060 These libraries have the format pic18fxxxx.lib, where
26064 is the microcontroller identification number.
26065 The specific library is selected automatically by the compiler at link
26066 stage according to the selected device.
26069 \begin_layout Standard
26070 Libraries are created with gplib which is part of the gputils package
26071 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
26078 \begin_layout Subsubsection*
26079 Building the libraries
26082 \begin_layout Standard
26083 Before using SDCC/pic16 there are some libraries that need to be compiled.
26084 This process is not done automatically by SDCC since not all users use
26085 SDCC for pic16 projects.
26086 So each user should compile the libraries separately.
26089 \begin_layout Standard
26090 The steps to compile the pic16 libraries under Linux and Mac OS X are:
26093 \begin_layout LyX-Code
26094 cd device/lib/pic16
26097 \begin_layout LyX-Code
26101 \begin_layout LyX-Code
26105 \begin_layout LyX-Code
26109 \begin_layout LyX-Code
26113 \begin_layout LyX-Code
26114 su -c 'make install' # install the libraries, you need the root password
26117 \begin_layout Standard
26118 If you need to install the headers too, do:
26121 \begin_layout LyX-Code
26125 \begin_layout LyX-Code
26126 su -c 'make install' # install the headers, you need the root password
26129 \begin_layout Standard
26130 There exist a special target to build the I/O libraries.
26131 This target is not automatically build because it will build the I/O library
26137 This way building will take quite a lot of time.
26138 Users are advised to edit the
26140 device/lib/pic16/pics.build
26142 file and then execute:
26145 \begin_layout LyX-Code
26149 \begin_layout Subsection
26150 Adding New Devices to the Port
26153 \begin_layout Standard
26154 Adding support for a new 16
26158 \begin_layout Standard
26167 bit PIC MCU requires the following steps:
26170 \begin_layout Enumerate
26171 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
26175 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
26179 \begin_layout Enumerate
26182 mv picDEVICE.h /path/to/sdcc/device/include/pic16
26185 \begin_layout Enumerate
26188 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
26191 \begin_layout Enumerate
26194 /path/to/sdcc/device/lib/pic16/pics.all
26202 Note: No 18f prefix here!
26205 \begin_layout Enumerate
26208 /path/to/sdcc/device/lib/pic16/libio/*.ignore
26212 Add your DEVICE if it does not compile in
26227 \begin_layout Enumerate
26230 /path/to/sdcc/device/include/pic16/pic18fregs.h
26233 The file format is self-explanatory, just add
26237 #elif defined(picDEVICE)
26239 # include <picDEVICE.h>
26243 at the right place (keep it sorted).
26246 \begin_layout Enumerate
26249 /path/to/sdcc/src/pic16/devices.inc
26252 Copy and modify an existing entry and insert it at the correct place (keep
26254 The file is hardly documented, look at the entries for the 18f2221...
26257 \begin_layout Enumerate
26258 Recompile SDCC, including the pic16 libraries.
26261 \begin_layout Subsection
26265 \begin_layout Standard
26266 The following memory models are supported by the PIC16 port:
26269 \begin_layout Itemize
26273 \begin_layout Itemize
26277 \begin_layout Standard
26278 Memory model affects the default size of pointers within the source.
26279 The sizes are shown in the next table:
26282 \begin_layout Standard
26284 \begin_inset Tabular
26285 <lyxtabular version="3" rows="3" columns="3">
26287 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26288 <column alignment="center" valignment="top" leftline="true" width="0">
26289 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26290 <row topline="true" bottomline="true">
26291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26294 \begin_layout Standard
26295 Pointer sizes according to memory model
26300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26303 \begin_layout Standard
26309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26312 \begin_layout Standard
26319 <row topline="true" bottomline="true">
26320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26323 \begin_layout Standard
26329 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26332 \begin_layout Standard
26338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26341 \begin_layout Standard
26348 <row topline="true" bottomline="true">
26349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26352 \begin_layout Standard
26358 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
26361 \begin_layout Standard
26367 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26370 \begin_layout Standard
26384 \begin_layout Standard
26385 It is advisable that all sources within a project are compiled with the
26387 If one wants to override the default memory model, this can be done by
26388 declaring a pointer as
26397 Far selects large memory model's pointers, while near selects small memory
26401 \begin_layout Standard
26402 The standard device libraries (see
26403 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
26407 ) contain no reference to pointers, so they can be used with both memory
26411 \begin_layout Subsection
26415 \begin_layout Standard
26417 \begin_inset LatexCommand \index{PIC16!stack}
26421 implementation for the PIC16 port uses two indirect registers, FSR1 and
26425 \begin_layout Description
26426 FSR1 is assigned as stack pointer
26429 \begin_layout Description
26430 FSR2 is assigned as frame pointer
26433 \begin_layout Standard
26434 The following stack models are supported by the PIC16 port
26437 \begin_layout Itemize
26445 \begin_layout Itemize
26453 \begin_layout Standard
26458 model means that only the FSRxL byte is used to access stack and frame,
26465 uses both FSRxL and FSRxH registers.
26466 The following table shows the stack/frame pointers sizes according to stack
26467 model and the maximum space they can address:
26470 \begin_layout Standard
26472 \begin_inset Tabular
26473 <lyxtabular version="3" rows="3" columns="3">
26475 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26476 <column alignment="center" valignment="top" leftline="true" width="0">
26477 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26478 <row topline="true" bottomline="true">
26479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26482 \begin_layout Standard
26483 Stack & Frame pointer sizes according to stack model
26488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26491 \begin_layout Standard
26497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26500 \begin_layout Standard
26507 <row topline="true">
26508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26511 \begin_layout Standard
26517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26520 \begin_layout Standard
26526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26529 \begin_layout Standard
26536 <row topline="true" bottomline="true">
26537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26540 \begin_layout Standard
26546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26549 \begin_layout Standard
26555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26558 \begin_layout Standard
26572 \begin_layout Standard
26577 stack model is currently not working properly throughout the code generator.
26578 So its use is not advised.
26579 Also there are some other points that need special care:
26584 \begin_layout Enumerate
26585 Do not create stack sections with size more than one physical bank (that
26589 \begin_layout Enumerate
26590 Stack sections should no cross physical bank limits (i.e.
26591 #pragma stack 0x50 0x100)
26594 \begin_layout Standard
26595 These limitations are caused by the fact that only FSRxL is modified when
26596 using SMALL stack model, so no more than 256 bytes of stack can be used.
26597 This problem will disappear after LARGE model is fully implemented.
26600 \begin_layout Subsection
26604 \begin_layout Standard
26605 In addition to the standard SDCC function keywords, PIC16
26606 \begin_inset LatexCommand \index{PIC16}
26610 port makes available two more:
26613 \begin_layout Description
26615 \begin_inset LatexCommand \index{PIC16!wparam}
26619 Use the WREG to pass one byte of the first function argument.
26620 This improves speed but you may not use this for functions with arguments
26621 that are called via function pointers, otherwise the first byte of the
26622 first parameter will get lost.
26626 \begin_layout LyX-Code
26627 void func_wparam(int a) wparam
26630 \begin_layout LyX-Code
26634 \begin_layout LyX-Code
26635 /* WREG hold the lower part of a */
26638 \begin_layout LyX-Code
26639 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
26643 \begin_layout LyX-Code
26647 \begin_layout LyX-Code
26651 \begin_layout Description
26653 \begin_inset LatexCommand \index{PIC16!shadowregs}
26657 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
26658 hardware shadow registers which hold the values of WREG, STATUS and BSR
26660 This can be done by adding the keyword
26668 keyword in the function's header.
26671 \begin_layout LyX-Code
26672 void isr_shadow(void) shadowregs interrupt 1
26675 \begin_layout LyX-Code
26679 \begin_layout LyX-Code
26683 \begin_layout LyX-Code
26687 \begin_layout Standard
26692 instructs the code generator not to store/restore WREG, STATUS, BSR when
26693 entering/exiting the ISR.
26696 \begin_layout Subsection
26697 Function return values
26700 \begin_layout Standard
26701 Return values from functions are placed to the appropriate registers following
26702 a modified Microchip policy optimized for SDCC.
26703 The following table shows these registers:
26706 \begin_layout Standard
26708 \begin_inset Tabular
26709 <lyxtabular version="3" rows="6" columns="2">
26711 <column alignment="center" valignment="top" leftline="true" width="0">
26712 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26713 <row topline="true" bottomline="true">
26714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26717 \begin_layout Standard
26723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26726 \begin_layout Standard
26727 destination register
26733 <row topline="true">
26734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26737 \begin_layout Standard
26743 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26746 \begin_layout Standard
26753 <row topline="true">
26754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26757 \begin_layout Standard
26763 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26766 \begin_layout Standard
26773 <row topline="true">
26774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26777 \begin_layout Standard
26783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26786 \begin_layout Standard
26793 <row topline="true">
26794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26797 \begin_layout Standard
26803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26806 \begin_layout Standard
26807 FSR0L:PRODH:PRODL:WREG
26813 <row topline="true" bottomline="true">
26814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26817 \begin_layout Standard
26823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26826 \begin_layout Standard
26827 on stack, FSR0 points to the beginning
26840 \begin_layout Subsection
26844 \begin_layout Standard
26846 \begin_inset LatexCommand \index{PIC16!interrupt}
26850 service routine (ISR) is declared using the
26857 \begin_layout LyX-Code
26858 void isr(void) interrupt
26863 \begin_layout LyX-Code
26867 \begin_layout LyX-Code
26871 \begin_layout LyX-Code
26875 \begin_layout Standard
26880 is the interrupt number, which for PIC18F devices can be:
26883 \begin_layout Standard
26885 \begin_inset Tabular
26886 <lyxtabular version="3" rows="4" columns="3">
26888 <column alignment="center" valignment="top" leftline="true" width="0">
26889 <column alignment="center" valignment="top" leftline="true" width="0">
26890 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26891 <row topline="true" bottomline="true">
26892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26895 \begin_layout Standard
26903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26906 \begin_layout Standard
26912 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26915 \begin_layout Standard
26916 Interrupt Vector Address
26922 <row topline="true">
26923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26926 \begin_layout Standard
26932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26935 \begin_layout Standard
26941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26944 \begin_layout Standard
26951 <row topline="true">
26952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26955 \begin_layout Standard
26970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26973 \begin_layout Standard
26983 HIGH priority interrupts
26988 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26991 \begin_layout Standard
26998 <row topline="true" bottomline="true">
26999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27002 \begin_layout Standard
27008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27011 \begin_layout Standard
27012 LOW priority interrupts
27017 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27020 \begin_layout Standard
27034 \begin_layout Standard
27035 When generating assembly code for ISR the code generator places a
27041 Interrupt Vector Address
27043 which points at the genetated ISR.
27044 This single GOTO instruction is part of an automatically generated
27046 interrupt entry point
27049 The actuall ISR code is placed as normally would in the code space.
27050 Upon interrupt request, the GOTO instruction is executed which jumps to
27052 When declaring interrupt functions as _naked this GOTO instruction is
27057 The whole interrupt functions is therefore placed at the Interrupt Vector
27058 Address of the specific interrupt.
27059 This is not a problem for the LOW priority interrupts, but it is a problem
27060 for the RESET and the HIGH priority interrupts because code may be written
27061 at the next interrupt's vector address and cause undeterminate program
27062 behaviour if that interrupt is raised.
27066 \begin_layout Standard
27067 This is not a problem when
27070 \begin_layout Enumerate
27071 this is a HIGH interrupt ISR and LOW interrupts are
27078 \begin_layout Enumerate
27079 when the ISR is small enough not to reach the next interrupt's vector address.
27087 \begin_layout Standard
27093 This way a function is generated similar to an ISR, but it is not assigned
27097 \begin_layout Standard
27098 When entering an interrupt, currently the PIC16
27099 \begin_inset LatexCommand \index{PIC16}
27103 port automatically saves the following registers:
27106 \begin_layout Itemize
27110 \begin_layout Itemize
27114 \begin_layout Itemize
27118 \begin_layout Itemize
27119 PROD (PRODL and PRODH)
27122 \begin_layout Itemize
27123 FSR0 (FSR0L and FSR0H)
27126 \begin_layout Standard
27127 These registers are restored upon return from the interrupt routine.
27131 \begin_layout Standard
27132 NOTE that when the _naked attribute is specified for an interrupt routine,
27133 then NO registers are stored or restored.
27141 \begin_layout Subsection
27145 \begin_layout Standard
27146 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
27147 There are 3 types of generic pointers currently implemented data, code
27148 and eeprom pointers.
27149 They are differentiated by the value of the 7th and 6th bits of the upper
27153 \begin_layout Standard
27155 \begin_inset Tabular
27156 <lyxtabular version="3" rows="5" columns="5">
27158 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27159 <column alignment="center" valignment="top" width="0">
27160 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27161 <column alignment="center" valignment="top" width="0">
27162 <column alignment="left" valignment="top" rightline="true" width="0">
27163 <row topline="true" bottomline="true">
27164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27167 \begin_layout Standard
27173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27176 \begin_layout Standard
27182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27185 \begin_layout Standard
27191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27194 \begin_layout Standard
27195 rest of the pointer
27200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27203 \begin_layout Standard
27210 <row topline="true" bottomline="true">
27211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27214 \begin_layout Standard
27220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27223 \begin_layout Standard
27229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27232 \begin_layout Standard
27238 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27241 \begin_layout Standard
27246 uuuuuu uuuuxxxx xxxxxxxx
27251 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27254 \begin_layout Standard
27255 a 12-bit data pointer in data RAM memory
27261 <row bottomline="true">
27262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27265 \begin_layout Standard
27271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27274 \begin_layout Standard
27280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27283 \begin_layout Standard
27289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27292 \begin_layout Standard
27297 uxxxxx xxxxxxxx xxxxxxxx
27302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27305 \begin_layout Standard
27306 a 21-bit code pointer in FLASH memory
27312 <row bottomline="true">
27313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27316 \begin_layout Standard
27322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27325 \begin_layout Standard
27331 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27334 \begin_layout Standard
27340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27343 \begin_layout Standard
27348 uuuuuu uuuuuuxx xxxxxxxx
27353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27356 \begin_layout Standard
27357 a 10-bit eeprom pointer in EEPROM memory
27363 <row bottomline="true">
27364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27367 \begin_layout Standard
27373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27376 \begin_layout Standard
27382 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27385 \begin_layout Standard
27391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27394 \begin_layout Standard
27399 xxxxxx xxxxxxxx xxxxxxxx
27404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27407 \begin_layout Standard
27408 unimplemented pointer type
27421 \begin_layout Standard
27422 Generic pointer are read and written with a set of library functions which
27423 read/write 1, 2, 3, 4 bytes.
27426 \begin_layout Subsection
27430 \begin_layout Subsubsection
27431 Standard I/O Streams
27434 \begin_layout Standard
27439 the type FILE is defined as:
27442 \begin_layout LyX-Code
27443 typedef char * FILE;
27446 \begin_layout Standard
27447 This type is the stream type implemented I/O in the PIC18F devices.
27448 Also the standard input and output streams are declared in stdio.h:
27451 \begin_layout LyX-Code
27452 extern FILE * stdin;
27455 \begin_layout LyX-Code
27456 extern FILE * stdout;
27459 \begin_layout Standard
27460 The FILE type is actually a generic pointer which defines one more type
27461 of generic pointers, the
27466 This new type has the format:
27469 \begin_layout Standard
27471 \begin_inset Tabular
27472 <lyxtabular version="3" rows="2" columns="7">
27474 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27475 <column alignment="center" valignment="top" width="0">
27476 <column alignment="center" valignment="top" leftline="true" width="0">
27477 <column alignment="center" valignment="top" leftline="true" width="0">
27478 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27479 <column alignment="center" valignment="top" width="0">
27480 <column alignment="left" valignment="top" rightline="true" width="0">
27481 <row topline="true" bottomline="true">
27482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27485 \begin_layout Standard
27491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27494 \begin_layout Standard
27500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27503 \begin_layout Standard
27509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27512 \begin_layout Standard
27518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27521 \begin_layout Standard
27527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27530 \begin_layout Standard
27531 rest of the pointer
27536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27539 \begin_layout Standard
27546 <row topline="true" bottomline="true">
27547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27550 \begin_layout Standard
27556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27559 \begin_layout Standard
27565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27568 \begin_layout Standard
27574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27577 \begin_layout Standard
27583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27586 \begin_layout Standard
27592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27595 \begin_layout Standard
27605 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27608 \begin_layout Standard
27609 upper byte high nubble is 0x2n, the rest are zeroes
27622 \begin_layout Standard
27623 Currently implemented there are 3 types of streams defined:
27626 \begin_layout Standard
27628 \begin_inset Tabular
27629 <lyxtabular version="3" rows="4" columns="4">
27631 <column alignment="center" valignment="top" leftline="true" width="0">
27632 <column alignment="center" valignment="top" leftline="true" width="0">
27633 <column alignment="center" valignment="top" leftline="true" width="0">
27634 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27635 <row topline="true" bottomline="true">
27636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27639 \begin_layout Standard
27645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27648 \begin_layout Standard
27654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27657 \begin_layout Standard
27663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27666 \begin_layout Standard
27673 <row topline="true">
27674 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27677 \begin_layout Standard
27683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27686 \begin_layout Standard
27694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27697 \begin_layout Standard
27703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27706 \begin_layout Standard
27707 Writes/Reads characters via the USART peripheral
27713 <row topline="true">
27714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27717 \begin_layout Standard
27723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27726 \begin_layout Standard
27734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27737 \begin_layout Standard
27743 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27746 \begin_layout Standard
27747 Writes/Reads characters via the MSSP peripheral
27753 <row topline="true" bottomline="true">
27754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27757 \begin_layout Standard
27763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27766 \begin_layout Standard
27774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27777 \begin_layout Standard
27783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27786 \begin_layout Standard
27787 Writes/Reads characters via used defined functions
27800 \begin_layout Standard
27801 The stream identifiers are declared as macros in the stdio.h header.
27804 \begin_layout Standard
27805 In the libc library there exist the functions that are used to write to
27806 each of the above streams.
27810 \begin_layout Description
27815 \begin_layout Standard
27824 _stream_usart_putchar writes a character at the USART stream
27827 \begin_layout Description
27832 \begin_layout Standard
27841 _stream_mssp_putchar writes a character at the MSSP stream
27844 \begin_layout Description
27845 putchar dummy function.
27846 This writes a character to a user specified manner.
27849 \begin_layout Standard
27850 In order to increase performance
27854 is declared in stdio.h as having its parameter in WREG (it has the wparam
27856 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
27857 in a user-friendly way.
27862 is the name of the variable that holds the character to print.
27863 An example follows:
27866 \begin_layout LyX-Code
27867 #include <pic18fregs.h>
27876 \begin_layout LyX-Code
27880 \begin_layout LyX-Code
27881 PORTA = c; /* dump character c to PORTA */
27884 \begin_layout LyX-Code
27892 \begin_layout LyX-Code
27896 \begin_layout LyX-Code
27897 stdout = STREAM_USER; /* this is not necessary, since stdout points
27900 \begin_layout LyX-Code
27901 * by default to STREAM_USER */
27904 \begin_layout LyX-Code
27906 \begin_inset Quotes sld
27909 This is a printf test
27912 \begin_inset Quotes srd
27918 \begin_layout LyX-Code
27922 \begin_layout LyX-Code
27926 \begin_layout Subsubsection
27930 \begin_layout Standard
27931 PIC16 contains an implementation of the printf-family of functions.
27932 There exist the following functions:
27935 \begin_layout LyX-Code
27936 extern unsigned int sprintf(char *buf, char *fmt, ...);
27939 \begin_layout LyX-Code
27940 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
27943 \begin_layout LyX-Code
27947 \begin_layout LyX-Code
27948 extern unsigned int printf(char *fmt, ...);
27951 \begin_layout LyX-Code
27952 extern unsigned int vprintf(char *fmt, va_lista ap);
27955 \begin_layout LyX-Code
27959 \begin_layout LyX-Code
27960 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
27963 \begin_layout LyX-Code
27964 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
27967 \begin_layout Standard
27968 For sprintf and vsprintf
27972 should normally be a data pointer where the resulting string will be placed.
27973 No range checking is done so the user should allocate the necessery buffer.
27974 For fprintf and vfprintf
27978 should be a stream pointer (i.e.
27979 stdout, STREAM_MSSP, etc...).
27982 \begin_layout Subsubsection
27986 \begin_layout Standard
27987 The PIC18F family of microcontrollers supports a number of interrupt sources.
27988 A list of these interrupts is shown in the following table:
27991 \begin_layout Standard
27993 \begin_inset Tabular
27994 <lyxtabular version="3" rows="11" columns="4">
27996 <column alignment="left" valignment="top" leftline="true" width="0">
27997 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27998 <column alignment="left" valignment="top" leftline="true" width="0">
27999 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28000 <row topline="true" bottomline="true">
28001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28004 \begin_layout Standard
28010 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28013 \begin_layout Standard
28019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28022 \begin_layout Standard
28028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28031 \begin_layout Standard
28038 <row topline="true">
28039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28042 \begin_layout Standard
28048 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28051 \begin_layout Standard
28052 PORTB change interrupt
28057 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28060 \begin_layout Standard
28066 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28069 \begin_layout Standard
28070 EEPROM/FLASH write complete interrupt
28076 <row topline="true">
28077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28080 \begin_layout Standard
28086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28089 \begin_layout Standard
28090 INT0 external interrupt
28095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28098 \begin_layout Standard
28104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28107 \begin_layout Standard
28108 Bus collision interrupt
28114 <row topline="true">
28115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28118 \begin_layout Standard
28124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28127 \begin_layout Standard
28128 INT1 external interrupt
28133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28136 \begin_layout Standard
28142 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28145 \begin_layout Standard
28146 Low voltage detect interrupt
28152 <row topline="true">
28153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28156 \begin_layout Standard
28162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28165 \begin_layout Standard
28166 INT2 external interrupt
28171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28174 \begin_layout Standard
28180 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28183 \begin_layout Standard
28184 Parallel slave port interrupt
28190 <row topline="true">
28191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28194 \begin_layout Standard
28200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28203 \begin_layout Standard
28204 CCP1 module interrupt
28209 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28212 \begin_layout Standard
28218 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28221 \begin_layout Standard
28222 AD convertion complete interrupt
28228 <row topline="true">
28229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28232 \begin_layout Standard
28238 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28241 \begin_layout Standard
28242 CCP2 module interrupt
28247 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28250 \begin_layout Standard
28256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28259 \begin_layout Standard
28260 USART receive interrupt
28266 <row topline="true">
28267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28270 \begin_layout Standard
28276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28279 \begin_layout Standard
28280 TMR0 overflow interrupt
28285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28288 \begin_layout Standard
28294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28297 \begin_layout Standard
28298 USART transmit interrupt
28304 <row topline="true">
28305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28308 \begin_layout Standard
28314 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28317 \begin_layout Standard
28318 TMR1 overflow interrupt
28323 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28326 \begin_layout Standard
28332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28335 \begin_layout Standard
28336 SSP receive/transmit interrupt
28342 <row topline="true">
28343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28346 \begin_layout Standard
28352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28355 \begin_layout Standard
28356 TMR2 matches PR2 interrupt
28361 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28364 \begin_layout Standard
28370 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28373 \begin_layout Standard
28380 <row topline="true" bottomline="true">
28381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28384 \begin_layout Standard
28390 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28393 \begin_layout Standard
28394 TMR3 overflow interrupt
28399 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28402 \begin_layout Standard
28408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28411 \begin_layout Standard
28425 \begin_layout Standard
28426 The prototypes for these names are defined in the header file
28433 \begin_layout Standard
28434 In order to simplify signal handling, a number of macros is provided:
28438 \labelwidthstring 00.00.0000
28439 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
28440 high priority interrupts.
28445 is the function name to use.
28449 \labelwidthstring 00.00.0000
28450 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
28451 low priority interrupt.
28456 is the function name to use.
28460 \labelwidthstring 00.00.0000
28461 DEF_HANDLER(sig,handler) define a handler for signal
28467 \labelwidthstring 00.00.0000
28468 END_DEF end the declaration of the dispatch table.
28471 \begin_layout Standard
28472 Additionally there are two more macros to simplify the declaration of the
28477 \labelwidthstring 00.00.0000
28480 SIGHANDLER(handler)
28482 this declares the function prototype for the
28490 \labelwidthstring 00.00.0000
28491 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
28494 \begin_layout Standard
28495 An example of using the macros above is shown below:
28498 \begin_layout LyX-Code
28499 #include <pic18fregs.h>
28502 \begin_layout LyX-Code
28503 #include <signal.h>
28507 DEF_INTHIGH(high_int)
28510 \begin_layout LyX-Code
28511 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
28514 \begin_layout LyX-Code
28515 DEF_HANDLER(SIG_BCOL, _bcol_handler)
28518 \begin_layout LyX-Code
28523 SIGHANDLER(_tmr0_handler)
28526 \begin_layout LyX-Code
28530 \begin_layout LyX-Code
28531 /* action to be taken when timer 0 overflows */
28534 \begin_layout LyX-Code
28539 SIGHANDLERNAKED(_bcol_handler)
28542 \begin_layout LyX-Code
28546 \begin_layout LyX-Code
28550 \begin_layout LyX-Code
28551 /* action to be taken when bus collision occurs */
28554 \begin_layout LyX-Code
28558 \begin_layout LyX-Code
28562 \begin_layout LyX-Code
28566 \begin_layout Standard
28571 Special care should be taken when using the above scheme:
28574 \begin_layout Itemize
28575 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
28578 \begin_layout Itemize
28579 when declaring SIGHANDLERNAKED handler never forget to use
28583 for proper returning.
28586 \begin_layout Subsection
28590 \begin_layout Standard
28591 Here you can find some general tips for compiling programs with SDCC/pic16.
28594 \begin_layout Subsubsection
28598 \begin_layout Standard
28600 \begin_inset LatexCommand \index{PIC16!stack}
28604 size (that is 64 bytes) probably is enough for many programs.
28605 One must take care that when there are many levels of function nesting,
28606 or there is excessive usage of stack, its size should be extended.
28607 An example of such a case is the printf/sprintf family of functions.
28608 If you encounter problems like not being able to print integers, then you
28609 need to set the stack size around the maximum (256 for small stack model).
28610 The following diagram shows what happens when calling printf to print an
28614 \begin_layout LyX-Code
28615 printf () --> ltoa () --> ultoa () --> divschar ()
28618 \begin_layout Standard
28619 It is should be understood that stack is easily consumed when calling complicate
28621 Using command line arguments like -
28625 \begin_layout Standard
28634 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
28636 Other ways to reduce stack usage may exist.
28639 \begin_layout Subsection
28643 \begin_layout Standard
28644 The PIC16 Port currently does not pass SDCC's regression test
28645 \begin_inset LatexCommand \index{Regression test (PIC16)}
28650 \begin_inset LatexCommand \ref{sec:Quality-control}
28654 ) and thus the snapshot build regression tests for the PIC16 target are
28655 currently disabled for all hosts
28660 \begin_layout Chapter
28664 \begin_layout Standard
28665 There are several approaches to debugging your code.
28666 This chapter is meant to show your options and to give detail on some of
28671 When writing your code:
28674 \begin_layout Itemize
28675 write your code with debugging in mind (avoid duplicating code, put conceptually
28676 similar variables into structs, use structured code, have strategic points
28677 within your code where all variables are consistent, ...)
28680 \begin_layout Itemize
28681 run a syntax-checking tool like splint
28682 \begin_inset LatexCommand \index{splint (syntax checking tool)}
28687 \begin_inset LatexCommand \index{lint (syntax checking tool)}
28695 \begin_layout Standard
28705 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28712 \begin_layout Itemize
28713 for the high level code use a C-compiler (like f.e.
28714 GCC) to compile run and debug the code on your host.
28719 \begin_layout Standard
28729 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28733 ) on how to handle syntax extensions like __xdata, __at(), ...
28737 \begin_layout Itemize
28738 use another C-compiler to compile code for your target.
28739 Always an option but not recommended:) And not very likely to help you.
28740 If you seriously consider walking this path you should at least occasionally
28741 check portability of your code.
28742 Most commercial compiler vendors will offer an evaluation version so you
28743 can test compile your code or snippets of your code.
28746 \begin_layout Standard
28747 Debugging on a simulator:
28750 \begin_layout Itemize
28751 there is a separate section about SDCDB (section
28752 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
28759 \begin_layout Itemize
28760 or (8051 specific) use a freeware/commercial simulator which interfaces
28762 \begin_inset LatexCommand \index{AOMF, AOMF51}
28767 \begin_inset LatexCommand \ref{OMF file}
28771 ) optionally generated by SDCC.
28774 \begin_layout Standard
28775 Debugging On-target:
28778 \begin_layout Itemize
28779 use a MCU port pin to serially output debug data to the RS232 port of your
28781 You'll probably want some level shifting device typically involving a MAX232
28783 If the hardware serial port of the MCU is not available search for 'Software
28784 UART' in your favourite search machine.
28787 \begin_layout Itemize
28788 use an on-target monitor.
28789 In this context a monitor is a small program which usually accepts commands
28790 via a serial line and allows to set program counter, to single step through
28791 a program and read/write memory locations.
28792 For the 8051 good examples of monitors are paulmon and cmon51 (see section
28794 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
28801 \begin_layout Itemize
28802 toggle MCU port pins at strategic points within your code and use an oscilloscop
28806 digital oscilloscope
28809 \begin_inset LatexCommand \index{Oscilloscope}
28813 with deep trace memory is really helpful especially if you have to debug
28814 a realtime application.
28815 If you need to monitor more pins than your oscilloscope provides you can
28816 sometimes get away with a small R-2R network.
28817 On a single channel oscilloscope you could f.e.
28818 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
28820 \begin_inset Formula $\Omega$
28823 resistor and the other one by a 5\InsetSpace ~
28825 \begin_inset Formula $\Omega$
28828 resistor to the oscilloscope probe (check output drive capability of the
28829 pins you want to monitor).
28830 If you need to monitor many more pins a
28837 \begin_layout Itemize
28851 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
28856 Usually very expensive.
28857 And very nice to have too.
28858 And usually locks you (for years...) to the devices the ICE can emulate.
28862 \begin_layout Itemize
28863 use a remote debugger.
28864 In most 8-bit systems the symbol information is not available on the target,
28865 and a complete debugger is too bulky for the target system.
28866 Therefore usually a debugger on the host system connects to an on-target
28867 debugging stub which accepts only primitive commands.
28870 Terms to enter into your favourite search engine could be 'remote debugging',
28871 'gdb stub' or 'inferior debugger'.
28875 \begin_layout Itemize
28876 use an on target hardware debugger.
28877 Some of the more modern MCUs include hardware support for setting break
28878 points and monitoring/changing variables by using dedicated hardware pins.
28879 This facility doesn't require additional code to run on the target and
28884 doesn't affect runtime behaviour until a breakpoint is hit.
28885 For the mcs51 most hardware debuggers use the AOMF
28886 \begin_inset LatexCommand \index{AOMF, AOMF51}
28891 \begin_inset LatexCommand \ref{OMF file}
28899 \begin_layout Standard
28903 \begin_layout Itemize
28904 if you are not familiar with any of the following terms you're likely to
28905 run into problems rather sooner than later:
28922 As an embedded programmer you
28926 to know them so why not look them up
28930 you have problems?)
28933 \begin_layout Itemize
28934 tell someone else about your problem (actually this is a surprisingly effective
28935 means to hunt down the bug even if the listener is not familiar with your
28937 As 'failure to communicate' is probably one of the job-induced deformations
28938 of an embedded programmer this is highly encouraged.
28941 \begin_layout Section
28942 Debugging with SDCDB
28943 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
28948 \begin_inset LatexCommand \index{SDCDB (debugger)}
28955 \begin_layout Standard
28956 SDCC is distributed with a source level debugger
28957 \begin_inset LatexCommand \index{Debugger}
28962 The debugger uses a command line interface, the command repertoire of the
28963 debugger has been kept as close to gdb
28964 \begin_inset LatexCommand \index{gdb}
28968 (the GNU debugger) as possible.
28969 The configuration and build process is part of the standard compiler installati
28970 on, which also builds and installs the debugger in the target directory
28971 specified during configuration.
28972 The debugger allows you debug BOTH at the C source and at the ASM source
28976 \begin_layout Subsection
28977 Compiling for Debugging
28980 \begin_layout Standard
28985 \begin_layout Standard
28995 \begin_inset LatexCommand \index{-\/-debug}
28999 option must be specified for all files for which debug information is to
29001 The compiler generates a .adb file for each of these files.
29002 The linker creates the .cdb
29003 \begin_inset LatexCommand \index{<file>.cdb}
29008 \begin_inset LatexCommand \index{<file>.adb}
29012 files and the address information.
29013 This .cdb is used by the debugger.
29016 \begin_layout Subsection
29017 How the Debugger Works
29020 \begin_layout Standard
29025 \begin_layout Standard
29034 -debug option is specified the compiler generates extra symbol information
29035 some of which are put into the assembler source and some are put into the
29037 Then the linker creates the .cdb file from the individual .adb files with
29038 the address information for the symbols.
29039 The debugger reads the symbolic information generated by the compiler &
29040 the address information generated by the linker.
29041 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
29042 execution is controlled by the debugger.
29043 When a command is issued for the debugger, it translates it into appropriate
29044 commands for the simulator.
29045 (Currently SDCDM only connects to the simulator but
29050 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
29054 is an effort to connect directly to the hardware.)
29057 \begin_layout Subsection
29058 Starting the Debugger SDCDB
29061 \begin_layout Standard
29062 The debugger can be started using the following command line.
29063 (Assume the file you are debugging has the file name foo).
29077 The debugger will look for the following files.
29080 \begin_layout Itemize
29081 foo.c - the source file.
29084 \begin_layout Itemize
29085 foo.cdb - the debugger symbol information file.
29088 \begin_layout Itemize
29089 foo.ihx - the Intel hex format
29090 \begin_inset LatexCommand \index{Intel hex format}
29097 \begin_layout Subsection
29098 SDCDB Command Line Options
29101 \begin_layout Itemize
29106 \begin_layout Standard
29115 -directory=<source file directory> this option can used to specify the directory
29117 The debugger will look into the directory list specified for source, cdb
29119 The items in the directory list must be separated by ':', e.g.
29120 if the source files can be in the directories /home/src1 and /home/src2,
29125 \begin_layout Standard
29134 -directory option should be -
29138 \begin_layout Standard
29147 -directory=/home/src1:/home/src2.
29148 Note there can be no spaces in the option.
29152 \begin_layout Itemize
29153 -cd <directory> - change to the <directory>.
29156 \begin_layout Itemize
29157 -fullname - used by GUI front ends.
29160 \begin_layout Itemize
29161 -cpu <cpu-type> - this argument is passed to the simulator please see the
29162 simulator docs for details.
29165 \begin_layout Itemize
29166 -X <Clock frequency > this options is passed to the simulator please see
29167 the simulator docs for details.
29170 \begin_layout Itemize
29171 -s <serial port file> passed to simulator see the simulator docs for details.
29174 \begin_layout Itemize
29175 -S <serial in,out> passed to simulator see the simulator docs for details.
29178 \begin_layout Itemize
29179 -k <port number> passed to simulator see the simulator docs for details.
29182 \begin_layout Subsection
29183 SDCDB Debugger Commands
29186 \begin_layout Standard
29187 As mentioned earlier the command interface for the debugger has been deliberatel
29188 y kept as close the GNU debugger gdb, as possible.
29189 This will help the integration with existing graphical user interfaces
29190 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
29191 If you use a graphical user interface for the debugger you can skip this
29195 \begin_layout Subsubsection*
29196 break [line | file:line | function | file:function]
29199 \begin_layout Standard
29200 Set breakpoint at specified line or function:
29209 sdcdb>break foo.c:100
29211 sdcdb>break funcfoo
29213 sdcdb>break foo.c:funcfoo
29216 \begin_layout Subsubsection*
29217 clear [line | file:line | function | file:function ]
29220 \begin_layout Standard
29221 Clear breakpoint at specified line or function:
29230 sdcdb>clear foo.c:100
29232 sdcdb>clear funcfoo
29234 sdcdb>clear foo.c:funcfoo
29237 \begin_layout Subsubsection*
29241 \begin_layout Standard
29242 Continue program being debugged, after breakpoint.
29245 \begin_layout Subsubsection*
29249 \begin_layout Standard
29250 Execute till the end of the current function.
29253 \begin_layout Subsubsection*
29257 \begin_layout Standard
29258 Delete breakpoint number 'n'.
29259 If used without any option clear ALL user defined break points.
29262 \begin_layout Subsubsection*
29263 info [break | stack | frame | registers ]
29266 \begin_layout Itemize
29267 info break - list all breakpoints
29270 \begin_layout Itemize
29271 info stack - show the function call stack.
29274 \begin_layout Itemize
29275 info frame - show information about the current execution frame.
29278 \begin_layout Itemize
29279 info registers - show content of all registers.
29282 \begin_layout Subsubsection*
29286 \begin_layout Standard
29287 Step program until it reaches a different source line.
29288 Note: pressing <return> repeats the last command.
29291 \begin_layout Subsubsection*
29295 \begin_layout Standard
29296 Step program, proceeding through subroutine calls.
29299 \begin_layout Subsubsection*
29303 \begin_layout Standard
29304 Start debugged program.
29307 \begin_layout Subsubsection*
29311 \begin_layout Standard
29312 Print type information of the variable.
29315 \begin_layout Subsubsection*
29319 \begin_layout Standard
29320 print value of variable.
29323 \begin_layout Subsubsection*
29327 \begin_layout Standard
29328 load the given file name.
29329 Note this is an alternate method of loading file for debugging.
29332 \begin_layout Subsubsection*
29336 \begin_layout Standard
29337 print information about current frame.
29340 \begin_layout Subsubsection*
29344 \begin_layout Standard
29345 Toggle between C source & assembly source.
29348 \begin_layout Subsubsection*
29349 ! simulator command
29352 \begin_layout Standard
29353 Send the string following '!' to the simulator, the simulator response is
29355 Note the debugger does not interpret the command being sent to the simulator,
29356 so if a command like 'go' is sent the debugger can loose its execution
29357 context and may display incorrect values.
29360 \begin_layout Subsubsection*
29364 \begin_layout Standard
29367 My name is Bobby Brown"
29370 \begin_layout Subsection
29371 Interfacing SDCDB with DDD
29374 \begin_layout Standard
29375 \begin_inset Note Note
29378 \begin_layout Standard
29379 The screenshot was converted from png to eps with:
29380 \begin_inset Quotes sld
29383 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
29384 \begin_inset Quotes srd
29387 which produces a pretty compact eps file which is free from compression
29391 \begin_layout Standard
29392 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
29393 as this broke the build system on Sourceforge (pdf-file was broken.
29394 pdflatex does not accept eps files).
29402 \begin_layout Standard
29418 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
29424 shows a screenshot of a debugging session with DDD
29425 \begin_inset LatexCommand \index{DDD (debugger)}
29429 (Unix only) on a simulated 8032.
29430 The debugging session might not run as smoothly as the screenshot suggests.
29431 The debugger allows setting of breakpoints, displaying and changing variables,
29432 single stepping through C and assembler code.
29435 The source was compiled with
29449 \begin_layout Standard
29461 -debug ddd_example.c
29474 and DDD was invoked with
29481 ddd -debugger "sdcdb -cpu 8032 ddd_example"
29484 \begin_layout Standard
29485 \begin_inset Note Note
29488 \begin_layout Standard
29489 Check that the double quotes or an apostroph within the command line survive
29490 the LyX tool chain.
29491 Previously the apostrophs got slanted in the PDF output so a cut and paste
29500 \begin_layout Subsection
29501 Interfacing SDCDB with XEmacs
29502 \begin_inset LatexCommand \index{XEmacs}
29507 \begin_inset LatexCommand \index{Emacs}
29514 \begin_layout Standard
29515 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
29516 sdcdb.el and sdcdbsrc.el.
29517 These two files can be found in the $(prefix)/bin directory after the installat
29519 These files need to be loaded into XEmacs for the interface to work.
29520 This can be done at XEmacs startup time by inserting the following into
29521 your '.xemacs' file (which can be found in your HOME directory):
29527 (load-file sdcdbsrc.el)
29533 .xemacs is a lisp file so the () around the command is REQUIRED.
29534 The files can also be loaded dynamically while XEmacs is running, set the
29535 environment variable 'EMACSLOADPATH' to the installation bin directory
29536 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
29537 To start the interface enter the following command:
29551 You will prompted to enter the file name to be debugged.
29556 The command line options that are passed to the simulator directly are
29557 bound to default values in the file sdcdbsrc.el.
29558 The variables are listed below, these values maybe changed as required.
29561 \begin_layout Itemize
29562 sdcdbsrc-cpu-type '51
29565 \begin_layout Itemize
29566 sdcdbsrc-frequency '11059200
29569 \begin_layout Itemize
29570 sdcdbsrc-serial nil
29573 \begin_layout Standard
29574 The following is a list of key mapping for the debugger interface.
29577 \begin_layout Standard
29600 binding\InsetSpace ~
29638 -------\InsetSpace ~
29709 sdcdb-back-from-src\InsetSpace ~
29738 rom-src\InsetSpace ~
29748 SDCDB continue command
29766 sdcdb-step-from-src\InsetSpace ~
29795 hatis-c-sexp\InsetSpace ~
29805 SDCDB ptypecommand for data at
29872 sdcdbsrc-delete\InsetSpace ~
29887 B Delete all breakpoints if no arg
29936 given or delete arg (C-u arg x)
29955 -frame\InsetSpace ~
29970 SDCDB Display current frame if no arg,
30019 given or display frame arg
30087 sdcdbsrc-goto-sdcdb\InsetSpace ~
30097 Goto the SDCDB output buffer
30116 t-c-sexp\InsetSpace ~
30127 SDCDB print command for data at
30194 sdcdbsrc-goto-sdcdb\InsetSpace ~
30205 o the SDCDB output buffer
30223 sdcdbsrc-mode\InsetSpace ~
30239 Toggles Sdcdbsrc mode (turns it
30255 sdcdb-finish-from-src\InsetSpace ~
30263 SDCDB finish command
30297 Set break for line with point
30312 sdcdbsrc-mode\InsetSpace ~
30328 Toggle Sdcdbsrc mode
30344 dbsrc-srcmode\InsetSpace ~
30368 \begin_layout Chapter
30372 \begin_layout Standard
30373 Here are a few guidelines that will help the compiler generate more efficient
30374 code, some of the tips are specific to this compiler others are generally
30375 good programming practice.
30378 \begin_layout Itemize
30379 Use the smallest data type to represent your data-value.
30380 If it is known in advance that the value is going to be less than 256 then
30381 use an 'unsigned char' instead of a 'short' or 'int'.
30382 Please note, that ANSI C requires both signed and unsigned chars to be
30383 promoted to 'signed int'
30384 \begin_inset LatexCommand \index{promotion to signed int}
30389 \begin_inset Marginal
30392 \begin_layout Standard
30401 before doing any operation.
30403 \begin_inset LatexCommand \index{type promotion}
30408 \begin_inset LatexCommand \label{type promotion}
30412 can be omitted, if the result is the same.
30413 The effect of the promotion rules together with the sign-extension is often
30418 \begin_layout Verse
30421 unsigned char uc = 0xfe;
30423 if (uc * uc < 0) /* this is true! */
30436 \begin_layout Standard
30443 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
30451 \begin_layout Verse
30454 (unsigned char) -12 / (signed char) -3 = ...
30457 \begin_layout Standard
30458 No, the result is not 4:
30461 \begin_layout Verse
30464 (int) (unsigned char) -12 / (int) (signed char) -3 =
30466 (int) (unsigned char)
30467 0xf4 / (int) (signed char) 0xfd =
30469 (int) 0x00f4 / (int) 0xfffd =
30474 (int) 244 / (int) -3 =
30476 (int) -81 = (int) 0xffaf;
30479 \begin_layout Standard
30480 Don't complain, that gcc gives you a different result.
30481 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
30482 Therefore the results are different.
30485 \begin_inset Quotes sld
30489 \begin_inset Quotes srd
30495 \begin_layout Quote
30498 If well-defined overflow characteristics are important and negative values
30499 are not, or if you want to steer clear of sign-extension problems when
30500 manipulating bits or bytes, use one of the corresponding unsigned types.
30501 (Beware when mixing signed and unsigned values in expressions, though.)
30504 character types (especially unsigned char) can be used as "tiny" integers,
30505 doing so is sometimes more trouble than it's worth, due to unpredictable
30506 sign extension and increased code size.
30510 \begin_layout Itemize
30511 Use unsigned when it is known in advance that the value is not going to
30513 This helps especially if you are doing division or multiplication, bit-shifting
30514 or are using an array index.
30517 \begin_layout Itemize
30518 NEVER jump into a LOOP.
30521 \begin_layout Itemize
30522 Declare the variables to be local
30523 \begin_inset LatexCommand \index{local variables}
30527 whenever possible, especially loop control variables (induction).
30530 \begin_layout Itemize
30531 Have a look at the assembly listing to get a
30532 \begin_inset Quotes sld
30536 \begin_inset Quotes srd
30539 for the code generation.
30542 \begin_layout Section
30543 Porting code from or to other compilers
30544 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
30551 \begin_layout Itemize
30552 check whether endianness of the compilers differs and adapt where needed.
30555 \begin_layout Itemize
30556 check the device specific header files
30557 \begin_inset LatexCommand \index{Header files}
30562 \begin_inset LatexCommand \index{Include files}
30566 for compiler specific syntax.
30567 Eventually include the file <compiler.h
30568 \begin_inset LatexCommand \index{compiler.h (include file)}
30573 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
30577 to allow using common header files.
30580 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
30587 \begin_layout Itemize
30588 check whether the startup code contains the correct initialization (watchdog,
30592 \begin_layout Itemize
30593 check whether the sizes of short, int, long match.
30596 \begin_layout Itemize
30597 check if some 16 or 32 bit hardware registers require a specific addressing
30598 order (least significant or most significant byte first) and adapt if needed
30607 relate to time and not to lower/upper memory location here, so this is
30612 the same as endianness).
30615 \begin_layout Itemize
30616 check whether the keyword
30620 is used where needed.
30621 The compilers might differ in their optimization characteristics (as different
30622 versions of the same compiler might also use more clever optimizations
30623 this is good idea anyway).
30625 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
30632 \begin_layout Itemize
30633 check that the compilers are not told to supress warnings.
30636 \begin_layout Itemize
30637 check and convert compiler specific extensions (interrupts, memory areas,
30641 \begin_layout Itemize
30642 check for differences in type promotion.
30643 Especially check for math operations on
30652 For the sake of C99 compatibility SDCC will probably promote these to
30656 more often than other compilers.
30657 Eventually insert explicit casts to
30666 Also check that the ~\InsetSpace ~
30668 \begin_inset LatexCommand \index{\~\/ Operator}
30675 \begin_inset LatexCommand \index{bit}
30681 variables, use the !\InsetSpace ~
30684 \begin_inset LatexCommand \ref{type promotion}
30689 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30696 \begin_layout Itemize
30697 check the assembly code generated for interrupt routines (f.e.
30698 for calls to possibly non-reentrant library functions).
30701 \begin_layout Itemize
30702 check whether timing loops result in proper timing (or preferably consider
30703 a rewrite of the code with timer based delays instead).
30706 \begin_layout Itemize
30707 check for differences in printf parameters (some compilers push (va_arg
30708 \begin_inset LatexCommand \index{vararg, va\_arg}
30712 ) char variables as
30716 others push them as
30722 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30729 \begin_layout Itemize
30730 check the resulting memory map
30731 \begin_inset LatexCommand \index{Memory map}
30736 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
30737 ly idata, pdata, xdata).
30738 Eventually check if unexpected library functions are included.
30741 \begin_layout Section
30743 \begin_inset LatexCommand \index{Tools}
30747 included in the distribution
30750 \begin_layout Standard
30752 \begin_inset Tabular
30753 <lyxtabular version="3" rows="12" columns="3">
30755 <column alignment="left" valignment="top" leftline="true" width="0pt">
30756 <column alignment="left" valignment="top" leftline="true" width="0pt">
30757 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30758 <row topline="true" bottomline="true">
30759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30762 \begin_layout Standard
30770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30773 \begin_layout Standard
30781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30784 \begin_layout Standard
30793 <row topline="true">
30794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30797 \begin_layout Standard
30799 \begin_inset LatexCommand \index{uCsim}
30808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30811 \begin_layout Standard
30812 Simulator for various architectures
30817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30820 \begin_layout Standard
30827 <row topline="true">
30828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30831 \begin_layout Standard
30837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30840 \begin_layout Standard
30842 \begin_inset LatexCommand \index{Header files}
30847 \begin_inset LatexCommand \index{Include files}
30856 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30859 \begin_layout Standard
30860 sdcc/support/scripts
30866 <row topline="true">
30867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30870 \begin_layout Standard
30876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30879 \begin_layout Standard
30880 header file conversion
30885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30888 \begin_layout Standard
30889 sdcc/support/scripts
30895 <row topline="true">
30896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30899 \begin_layout Standard
30905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30908 \begin_layout Standard
30914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30917 \begin_layout Standard
30933 <row topline="true">
30934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30937 \begin_layout Standard
30943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30946 \begin_layout Standard
30952 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30955 \begin_layout Standard
30971 <row topline="true">
30972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30975 \begin_layout Standard
30981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30984 \begin_layout Standard
30990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30993 \begin_layout Standard
31009 <row topline="true">
31010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31013 \begin_layout Standard
31019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31022 \begin_layout Standard
31028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31031 \begin_layout Standard
31047 <row topline="true">
31048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31051 \begin_layout Standard
31057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31060 \begin_layout Standard
31066 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31069 \begin_layout Standard
31085 <row topline="true">
31086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31089 \begin_layout Standard
31095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31098 \begin_layout Standard
31104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31107 \begin_layout Standard
31123 <row topline="true">
31124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31127 \begin_layout Standard
31133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31136 \begin_layout Standard
31142 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31145 \begin_layout Standard
31161 <row topline="true" bottomline="true">
31162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31165 \begin_layout Standard
31171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31174 \begin_layout Standard
31176 \begin_inset LatexCommand \index{packihx (tool)}
31185 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31188 \begin_layout Standard
31213 \begin_layout Section
31215 \begin_inset LatexCommand \index{Documentation}
31219 included in the distribution
31222 \begin_layout Standard
31224 \begin_inset Tabular
31225 <lyxtabular version="3" rows="10" columns="2">
31227 <column alignment="block" valignment="top" leftline="true" width="40col%">
31228 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
31229 <row topline="true" bottomline="true" endhead="true">
31230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31233 \begin_layout Standard
31241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31244 \begin_layout Standard
31247 Filename / Where to get
31253 <row topline="true">
31254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31257 \begin_layout Standard
31258 SDCC Compiler User Guide
31263 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31266 \begin_layout Standard
31267 You're reading it right now
31279 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
31289 <row topline="true">
31290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31293 \begin_layout Standard
31299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31302 \begin_layout Standard
31315 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31325 <row topline="true">
31326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31329 \begin_layout Standard
31331 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
31336 \begin_inset LatexCommand \index{Assembler documentation}
31343 \begin_inset LatexCommand \index{aslink}
31348 \begin_inset LatexCommand \index{Linker documentation}
31357 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31360 \begin_layout Standard
31361 sdcc/as/doc/asxhtm.html
31373 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
31383 <row topline="true">
31384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31387 \begin_layout Standard
31388 SDCC regression test
31389 \begin_inset LatexCommand \index{Regression test}
31398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31401 \begin_layout Standard
31402 sdcc/doc/test_suite_spec.pdf
31414 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
31424 <row topline="true">
31425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31428 \begin_layout Standard
31434 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31437 \begin_layout Standard
31450 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
31460 <row topline="true">
31461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31464 \begin_layout Standard
31465 Notes on debugging with SDCDB
31466 \begin_inset LatexCommand \index{SDCDB (debugger)}
31475 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31478 \begin_layout Standard
31479 sdcc/debugger/README
31491 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
31501 <row topline="true">
31502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31505 \begin_layout Standard
31507 \begin_inset LatexCommand \index{uCsim}
31511 Software simulator for microcontrollers
31516 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31519 \begin_layout Standard
31549 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
31559 <row topline="true">
31560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31563 \begin_layout Standard
31564 Temporary notes on the pic16
31565 \begin_inset LatexCommand \index{PIC16}
31574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31577 \begin_layout Standard
31578 sdcc/src/pic16/NOTES
31590 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
31600 <row topline="true" bottomline="true">
31601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31604 \begin_layout Standard
31605 SDCC internal documentation (debugging file format)
31610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31613 \begin_layout Standard
31643 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
31662 \begin_layout Section
31663 Related open source tools
31664 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
31669 \begin_inset LatexCommand \index{Related tools}
31676 \begin_layout Standard
31678 \begin_inset Tabular
31679 <lyxtabular version="3" rows="16" columns="3">
31681 <column alignment="left" valignment="top" leftline="true" width="0pt">
31682 <column alignment="block" valignment="top" leftline="true" width="30line%">
31683 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
31684 <row topline="true" bottomline="true">
31685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31688 \begin_layout Standard
31696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31699 \begin_layout Standard
31707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31710 \begin_layout Standard
31719 <row topline="true">
31720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31723 \begin_layout Standard
31725 \begin_inset LatexCommand \index{gpsim (pic simulator)}
31734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31737 \begin_layout Standard
31743 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31746 \begin_layout Standard
31747 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
31757 <row topline="true">
31758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31761 \begin_layout Standard
31763 \begin_inset LatexCommand \index{gputils (pic tools)}
31772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31775 \begin_layout Standard
31781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31784 \begin_layout Standard
31785 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
31795 <row topline="true">
31796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31799 \begin_layout Standard
31805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31808 \begin_layout Standard
31814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31817 \begin_layout Standard
31818 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
31828 <row topline="true">
31829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31832 \begin_layout Standard
31838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31841 \begin_layout Standard
31842 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
31848 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31851 \begin_layout Standard
31852 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
31862 <row topline="true">
31863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31866 \begin_layout Standard
31868 \begin_inset LatexCommand \index{indent (source formatting tool)}
31877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31880 \begin_layout Standard
31881 Formats C source - Master of the white spaces
31886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31889 \begin_layout Standard
31890 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
31900 <row topline="true">
31901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31904 \begin_layout Standard
31906 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
31915 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31918 \begin_layout Standard
31919 Object file conversion, checksumming, ...
31924 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31927 \begin_layout Standard
31928 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
31938 <row topline="true">
31939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31942 \begin_layout Standard
31944 \begin_inset LatexCommand \index{objdump (tool)}
31953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31956 \begin_layout Standard
31957 Object file conversion, ...
31962 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31965 \begin_layout Standard
31966 Part of binutils (should be there anyway)
31972 <row topline="true">
31973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31976 \begin_layout Standard
31982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31985 \begin_layout Standard
31986 8051 monitor (hex up-/download, single step, disassemble)
31991 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31994 \begin_layout Standard
31995 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
32005 <row topline="true">
32006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32009 \begin_layout Standard
32011 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
32020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32023 \begin_layout Standard
32024 Source code documentation system
32029 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32032 \begin_layout Standard
32033 \begin_inset LatexCommand \url{http://www.doxygen.org}
32043 <row topline="true">
32044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32047 \begin_layout Standard
32053 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32056 \begin_layout Standard
32057 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
32062 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32065 \begin_layout Standard
32066 \begin_inset LatexCommand \url{http://www.kdevelop.org}
32076 <row topline="true">
32077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32080 \begin_layout Standard
32086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32089 \begin_layout Standard
32090 8051 monitor (hex up-/download, single step, disassemble)
32095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32098 \begin_layout Standard
32099 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
32109 <row topline="true">
32110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32113 \begin_layout Standard
32115 \begin_inset LatexCommand \index{splint (syntax checking tool)}
32124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32127 \begin_layout Standard
32128 Statically checks c sources (see
32129 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
32138 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32141 \begin_layout Standard
32142 \begin_inset LatexCommand \url{http://www.splint.org}
32152 <row topline="true" bottomline="true">
32153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32156 \begin_layout Standard
32158 \begin_inset LatexCommand \index{DDD (debugger)}
32167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32170 \begin_layout Standard
32171 Debugger, serves nicely as GUI to SDCDB
32172 \begin_inset LatexCommand \index{SDCDB (debugger)}
32181 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32184 \begin_layout Standard
32185 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
32195 <row bottomline="true">
32196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32199 \begin_layout Standard
32201 \begin_inset LatexCommand \index{d52}
32206 \begin_inset LatexCommand \index{d52 (disassembler)}
32215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32218 \begin_layout Standard
32219 Disassembler, can count instruction cycles
32220 \begin_inset LatexCommand \index{instruction cycles (count)}
32224 , use with options -pnd
32229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32232 \begin_layout Standard
32233 \begin_inset LatexCommand \url{http://www.8052.com/users/disasm/}
32243 <row bottomline="true">
32244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32247 \begin_layout Standard
32249 \begin_inset LatexCommand \index{cmake}
32258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32261 \begin_layout Standard
32262 Cross platform build system, generates Makefiles
32263 \begin_inset LatexCommand \index{Makefile}
32267 and project workspaces
32268 \begin_inset LatexCommand \index{project workspace}
32277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32280 \begin_layout Standard
32281 \begin_inset LatexCommand \url{http://www.cmake.org}
32289 and a dedicated wiki entry:
32290 \begin_inset LatexCommand \url{http://www.cmake.org/Wiki/CmakeSdcc}
32309 \begin_layout Section
32310 Related documentation / recommended reading
32313 \begin_layout Standard
32315 \begin_inset Tabular
32316 <lyxtabular version="3" rows="7" columns="3">
32318 <column alignment="left" valignment="top" leftline="true" width="0pt">
32319 <column alignment="left" valignment="top" leftline="true" width="0">
32320 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32321 <row topline="true" bottomline="true">
32322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32325 \begin_layout Standard
32333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32336 \begin_layout Standard
32344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32347 \begin_layout Standard
32356 <row topline="true">
32357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32360 \begin_layout Standard
32375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32378 \begin_layout Standard
32380 \begin_inset LatexCommand \index{C Reference card}
32389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32392 \begin_layout Standard
32393 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
32403 <row topline="true">
32404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32407 \begin_layout Standard
32413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32416 \begin_layout Standard
32418 \begin_inset LatexCommand \index{C FAQ}
32427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32430 \begin_layout Standard
32431 \begin_inset LatexCommand \url{http://www.c-faq.com}
32441 <row topline="true">
32442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32445 \begin_layout Standard
32451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32454 \begin_layout Standard
32455 \begin_inset Quotes sld
32459 \begin_inset Quotes srd
32467 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32470 \begin_layout Standard
32473 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
32483 <row topline="true">
32484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32487 \begin_layout Standard
32493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32496 \begin_layout Standard
32497 \begin_inset Quotes sld
32500 Extensions for Embedded C
32501 \begin_inset Quotes srd
32509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32512 \begin_layout Standard
32515 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
32525 <row topline="true">
32526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32529 \begin_layout Standard
32535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32538 \begin_layout Standard
32539 Latest datasheet of target CPU
32544 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32547 \begin_layout Standard
32554 <row topline="true" bottomline="true">
32555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32558 \begin_layout Standard
32564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32567 \begin_layout Standard
32568 Revision history of datasheet
32573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32576 \begin_layout Standard
32592 \begin_layout Section
32593 Application notes specifically for SDCC
32596 \begin_layout Standard
32597 SDCC makes no claims about the completeness of this list and about up-to-datenes
32598 s or correctness of the application notes
32599 \begin_inset LatexCommand \index{Application notes}
32606 \begin_layout Standard
32610 \begin_inset Tabular
32611 <lyxtabular version="3" rows="7" columns="3">
32613 <column alignment="block" valignment="top" leftline="true" width="17col%">
32614 <column alignment="block" valignment="top" leftline="true" width="27col%">
32615 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
32616 <row topline="true" bottomline="true">
32617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32620 \begin_layout Standard
32629 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
32632 \begin_layout Standard
32641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32644 \begin_layout Standard
32654 <row topline="true">
32655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32658 \begin_layout Standard
32666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32669 \begin_layout Standard
32672 Using the SDCC Compiler for the DS80C400
32673 \begin_inset LatexCommand \index{DS80C400}
32682 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32685 \begin_layout Standard
32688 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
32698 <row topline="true">
32699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32702 \begin_layout Standard
32710 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
32713 \begin_layout Standard
32716 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
32717 \begin_inset LatexCommand \index{DS89C4x0}
32721 Family of Microcontrollers
32726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32729 \begin_layout Standard
32732 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
32742 <row topline="true">
32743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32746 \begin_layout Standard
32749 Silicon Laboratories / Cygnal
32754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32757 \begin_layout Standard
32760 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
32761 \begin_inset LatexCommand \index{IDE}
32770 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32773 \begin_layout Standard
32776 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
32786 <row topline="true">
32787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32790 \begin_layout Standard
32793 Ramtron / Goal Semiconductor
32798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32801 \begin_layout Standard
32804 Interfacing SDCC to Syn and Textpad
32809 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32812 \begin_layout Standard
32815 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32825 <row topline="true">
32826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32829 \begin_layout Standard
32832 Ramtron / Goal Semiconductor
32837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32840 \begin_layout Standard
32843 Installing and Configuring SDCC and Crimson Editor
32848 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32851 \begin_layout Standard
32854 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32864 <row topline="true" bottomline="true">
32865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32868 \begin_layout Standard
32876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32879 \begin_layout Standard
32882 MSC12xx Programming with SDCC
32887 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32890 \begin_layout Standard
32893 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
32910 \begin_layout Section
32914 \begin_layout Standard
32915 Some questions answered, some pointers given - it might be time to in turn
32923 \begin_layout Itemize
32924 can you solve your project with the selected microcontroller? Would you
32925 find out early or rather late that your target is too small/slow/whatever?
32926 Can you switch to a slightly better device if it doesn't fit?
32929 \begin_layout Itemize
32930 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
32931 and/or another programming language be more adequate? Would an operating
32932 system on the target device help?
32935 \begin_layout Itemize
32936 if you solved the problem, will the marketing department be happy?
32939 \begin_layout Itemize
32940 if the marketing department is happy, will customers be happy?
32943 \begin_layout Itemize
32944 if you're the project manager, marketing department and maybe even the customer
32945 in one person, have you tried to see the project from the outside?
32948 \begin_layout Itemize
32949 is the project done if you think it is done? Or is just that other interface/pro
32950 tocol/feature/configuration/option missing? How about website, manual(s),
32951 internationali(z|s)ation, packaging, labels, 2nd source for components,
32952 electromagnetic compatability/interference, documentation for production,
32953 production test software, update mechanism, patent issues?
32956 \begin_layout Itemize
32957 is your project adequately positioned in that magic triangle: fame, fortune,
32961 \begin_layout Standard
32962 Maybe not all answers to these questions are known and some answers may
32967 , nevertheless knowing these questions may help you to avoid burnout
32971 \begin_layout Standard
32972 burnout is bad for electronic devices, programmers and motorcycle tyres
32978 Chances are you didn't want to hear some of them...
32981 \begin_layout Chapter
32983 \begin_inset LatexCommand \index{Support}
32990 \begin_layout Standard
32991 SDCC has grown to be a large project.
32992 The compiler alone (without the preprocessor, assembler and linker) is
32993 well over 150,000 lines of code (blank stripped).
32994 The open source nature of this project is a key to its continued growth
32996 You gain the benefit and support of many active software developers and
32998 Is SDCC perfect? No, that's why we need your help.
32999 The developers take pride in fixing reported bugs.
33000 You can help by reporting the bugs and helping other SDCC users.
33001 There are lots of ways to contribute, and we encourage you to take part
33002 in making SDCC a great software package.
33006 \begin_layout Standard
33007 The SDCC project is hosted on the SDCC sourceforge site at
33008 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
33013 You'll find the complete set of mailing lists
33014 \begin_inset LatexCommand \index{Mailing list(s)}
33018 , forums, bug reporting system, patch submission
33019 \begin_inset LatexCommand \index{Patch submission}
33024 \begin_inset LatexCommand \index{download}
33028 area and Subversion code repository
33029 \begin_inset LatexCommand \index{Subversion code repository}
33036 \begin_layout Section
33038 \begin_inset LatexCommand \index{Bug reporting}
33043 \begin_inset LatexCommand \index{Reporting bugs}
33050 \begin_layout Standard
33051 The recommended way of reporting bugs is using the infrastructure of the
33053 You can follow the status of bug reports there and have an overview about
33057 \begin_layout Standard
33058 Bug reports are automatically forwarded to the developer mailing list and
33059 will be fixed ASAP.
33060 When reporting a bug, it is very useful to include a small test program
33061 (the smaller the better) which reproduces the problem.
33062 If you can isolate the problem by looking at the generated assembly code,
33063 this can be very helpful.
33064 Compiling your program with the -
33068 \begin_layout Standard
33078 \begin_inset LatexCommand \index{-\/-dumpall}
33082 option can sometimes be useful in locating optimization problems.
33083 When reporting a bug please make sure you:
33086 \begin_layout Enumerate
33087 Attach the code you are compiling with SDCC.
33091 \begin_layout Enumerate
33092 Specify the exact command you use to run SDCC, or attach your Makefile.
33096 \begin_layout Enumerate
33097 Specify the SDCC version (type "
33103 "), your platform, and operating system.
33107 \begin_layout Enumerate
33108 Provide an exact copy of any error message or incorrect output.
33112 \begin_layout Enumerate
33113 Put something meaningful in the subject of your message.
33116 \begin_layout Standard
33117 Please attempt to include these 5 important parts, as applicable, in all
33118 requests for support or when reporting any problems or bugs with SDCC.
33119 Though this will make your message lengthy, it will greatly improve your
33120 chance that SDCC users and developers will be able to help you.
33121 Some SDCC developers are frustrated by bug reports without code provided
33122 that they can use to reproduce and ultimately fix the problem, so please
33123 be sure to provide sample code if you are reporting a bug!
33126 \begin_layout Standard
33127 Please have a short check that you are using a recent version of SDCC and
33128 the bug is not yet known.
33129 This is the link for reporting bugs:
33130 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
33135 With SDCC on average having more than 200 downloads
33136 \begin_inset LatexCommand \index{download}
33140 on sourceforge per day
33144 \begin_layout Standard
33145 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
33146 between 2002 and 2005.
33147 This does not include other methods of distribution.
33152 there must be some users.
33153 So it's not exactly easy to find a new bug.
33154 If you find one we need it:
33156 reporting bugs is good
33161 \begin_layout Section
33162 Requesting Features
33163 \begin_inset LatexCommand \label{sub:Requesting-Features}
33168 \begin_inset LatexCommand \index{Feature request}
33173 \begin_inset LatexCommand \index{Requesting features}
33180 \begin_layout Standard
33181 Like bug reports feature requests are forwarded to the developer mailing
33183 This is the link for requesting features:
33184 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33191 \begin_layout Section
33195 \begin_layout Standard
33196 Like bug reports contributed patches are forwarded to the developer mailing
33198 This is the link for submitting patches
33199 \begin_inset LatexCommand \index{Patch submission}
33204 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
33211 \begin_layout Standard
33212 You need to specify some parameters to the
33216 command for the patches to be useful.
33217 If you modified more than one file a patch created f.e.
33222 \begin_inset Quotes sld
33225 diff -Naur unmodified_directory modified_directory >my_changes.patch
33226 \begin_inset Quotes srd
33232 will be fine, otherwise
33236 \begin_inset Quotes sld
33239 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
33240 \begin_inset Quotes srd
33250 \begin_layout Section
33254 \begin_layout Standard
33255 These links should take you directly to the
33256 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
33264 \begin_layout Standard
33265 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
33266 automated messages (mid 2003)
33272 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
33277 \begin_inset LatexCommand \index{Mailing list(s)}
33281 and forums are archived and searchable so if you are lucky someone already
33282 had a similar problem.
33283 While mails to the lists themselves are delivered promptly their web front
33284 end on sourceforge sometimes shows a severe time lag (up to several weeks),
33285 if you're seriously using SDCC please consider subscribing to the lists.
33288 \begin_layout Section
33292 \begin_layout Standard
33293 You can follow the status of the Subversion version
33294 \begin_inset LatexCommand \index{version}
33298 of SDCC by watching the Changelog
33299 \begin_inset LatexCommand \index{Changelog}
33303 in the Subversion repository
33306 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
33313 \begin_layout Section
33314 Subversion Source Code Repository
33317 \begin_layout Standard
33327 \begin_layout Standard
33341 or the filenames of the snapshot versions of SDCC include date and its
33343 \begin_inset LatexCommand \index{Subversion code repository}
33348 Subversion allows to download the source of recent or previous versions
33350 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
33354 (by number or by date).
33355 An on-line source code browser and detailled instructions are also available
33357 SDCC versions starting from 1999 up to now are available (currently the
33358 versions prior to the conversion from cvs
33359 \begin_inset LatexCommand \index{cvs|see{Subversion}}
33363 to Subversion (April 2006) are either by accessible by Subversion or by
33367 \begin_layout Section
33369 \begin_inset LatexCommand \index{Release policy}
33376 \begin_layout Standard
33377 Historically there often were long delays between official releases and
33378 the sourceforge download area tends to get not updated at all.
33379 Excuses in the past might have referred to problems with live range analysis,
33380 but as this was fixed a while ago, the current problem is that another
33381 excuse has to be found.
33382 Kidding aside, we have to get better there! On the other hand there are
33383 daily snapshots available at
33384 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
33388 , and you can always build the very last version (hopefully with many bugs
33389 fixed, and features added) from the source code available at
33390 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
33396 \begin_inset LatexCommand \index{wiki}
33401 \begin_inset LatexCommand \index{SDCC Wiki}
33406 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/}
33410 also holds some information about past and future releases.
33413 \begin_layout Section
33415 \begin_inset LatexCommand \index{Examples}
33422 \begin_layout Standard
33423 You'll find some small examples in the directory
33425 sdcc/device/examples/.
33428 More examples and libraries are available at
33430 The SDCC Open Knowledge Resource
33431 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
33438 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
33445 \begin_layout Standard
33446 \begin_inset Note Note
33449 \begin_layout Standard
33450 I did insert a reference to Paul's web site here although it seems rather
33451 dedicated to a specific 8032 board (I think it's okay because it f.e.
33452 shows LCD/Harddisc interface and has a free 8051 monitor.
33453 Independent 8032 board vendors face hard competition of heavily subsidized
33454 development boards anyway).
33457 \begin_layout Standard
33458 Maybe we should include some links to real world applications.
33459 Preferably pointer to pointers (one for each architecture) so this stays
33468 \begin_layout Section
33470 \begin_inset LatexCommand \label{sec:Quality-control}
33475 \begin_inset LatexCommand \index{Quality control}
33482 \begin_layout Standard
33483 The compiler is passed through snaphot build compile and build checks.
33489 \begin_inset LatexCommand \index{Regression test}
33493 check that SDCC itself compiles flawlessly on several host platforms (i386,
33494 Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
33495 and checks the quality of the code generated by SDCC by running the code
33496 for several target platforms through simulators.
33497 The regression test suite comprises more than 100 files which expand to
33498 more than 500 test cases which include more than 4500 tests.
33499 The results of these tests are published daily on SDCC's snapshot page
33500 (click on the red or green symbols on the right side of
33501 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
33508 \begin_layout Standard
33509 There is a separate document
33512 \begin_inset LatexCommand \index{Test suite}
33519 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
33523 about the regression test suite.
33526 \begin_layout Standard
33527 You'll find the test code in the directory
33529 sdcc/support/regression
33532 You can run these tests manually by running
33536 in this directory (or f.e.
33541 \begin_inset Quotes sld
33545 \begin_inset Quotes srd
33551 if you don't want to run the complete tests).
33552 The test code might also be interesting if you want to look for examples
33553 \begin_inset LatexCommand \index{Examples}
33557 checking corner cases of SDCC or if you plan to submit patches
33558 \begin_inset LatexCommand \index{Patch submission}
33565 \begin_layout Standard
33566 The PIC14 port uses a different set of regression tests
33567 \begin_inset LatexCommand \index{Regression test (PIC14)}
33571 , you'll find them in the directory
33573 sdcc/src/regression
33578 \begin_layout Section
33579 Use of SDCC in Education
33582 \begin_layout Standard
33591 \begin_layout Standard
33592 the phrase "use in education" might evoke the association "
33596 fit for use in education".
33597 This connotation is not intended but nevertheless risked as the licensing
33598 of SDCC makes it difficult to offer educational discounts
33604 If your rationales are to:
33607 \begin_layout Enumerate
33608 give students a chance to understand the
33612 steps of code generation
33615 \begin_layout Enumerate
33616 have a curriculum that can be extended for years.
33617 Then you could use an fpga board as target and your curriculum will seamlessly
33618 extend from logic synthesis (
33619 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
33624 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
33628 ), over assembly programming, to C to FPGA compilers (
33629 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
33636 \begin_layout Enumerate
33637 be able to insert excursions about skills like using a revision control
33638 system, submitting/applying patches, using a type-setting (as opposed to
33639 word-processing) engine LyX/LaTeX, using
33640 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
33645 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
33649 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
33650 Source Software, CPU simulation, compiler regression tests
33651 \begin_inset LatexCommand \index{Regression test}
33658 And if there should be a shortage of ideas then you can always point students
33659 to the ever-growing feature request list
33660 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33667 \begin_layout Enumerate
33668 not tie students to a specific host platform and instead allow them to use
33673 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
33675 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
33682 \begin_layout Enumerate
33683 not encourage students to use illegal copies of educational software
33686 \begin_layout Enumerate
33687 be immune to licensing/availability/price changes of the chosen tool chain
33690 \begin_layout Enumerate
33691 be able to change to a new target platform without having to adopt a new
33695 \begin_layout Enumerate
33696 have complete control over and insight into the tool chain
33699 \begin_layout Enumerate
33700 make your students aware about the pros and cons of open source software
33704 \begin_layout Enumerate
33705 give back to the public as you are probably at least partially publically
33709 \begin_layout Enumerate
33710 give students a chance to publically prove their skills and to possibly
33711 see a world wide impact
33714 \begin_layout Standard
33715 then SDCC is probably among the first choices.
33716 Well, probably SDCC might be the only choice.
33721 \begin_layout Chapter
33722 SDCC Technical Data
33725 \begin_layout Section
33727 \begin_inset LatexCommand \index{Optimizations}
33734 \begin_layout Standard
33735 SDCC performs a host of standard optimizations in addition to some MCU specific
33740 \begin_layout Subsection
33741 Sub-expression Elimination
33742 \begin_inset LatexCommand \index{Subexpression elimination}
33749 \begin_layout Standard
33750 The compiler does local and
33769 \begin_layout Verse
33777 \begin_layout Standard
33778 will be translated to
33781 \begin_layout Verse
33791 \begin_layout Standard
33792 Some subexpressions are not as obvious as the above example, e.g.:
33795 \begin_layout Verse
33803 \begin_layout Standard
33804 In this case the address arithmetic a->b[i] will be computed only once;
33805 the equivalent code in C would be.
33808 \begin_layout Verse
33818 \begin_layout Standard
33819 The compiler will try to keep these temporary variables in registers.
33822 \begin_layout Subsection
33823 Dead-Code Elimination
33824 \begin_inset LatexCommand \index{Dead-code elimination}
33831 \begin_layout Verse
33846 i = 1; \InsetSpace ~
33855 global = 1;\InsetSpace ~
33869 global = 3;\InsetSpace ~
33875 \begin_layout Standard
33879 \begin_layout Verse
33895 \begin_layout Subsection
33897 \begin_inset LatexCommand \index{Copy propagation}
33904 \begin_layout Verse
33928 \begin_layout Standard
33932 \begin_layout Verse
33956 \begin_layout Standard
33957 Note: the dead stores created by this copy propagation will be eliminated
33958 by dead-code elimination.
33961 \begin_layout Subsection
33963 \begin_inset LatexCommand \index{Loop optimization}
33968 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
33975 \begin_layout Standard
33976 Two types of loop optimizations are done by SDCC
33984 of loop induction variables.
33985 In addition to the strength reduction the optimizer marks the induction
33986 variables and the register allocator tries to keep the induction variables
33987 in registers for the duration of the loop.
33988 Because of this preference of the register allocator
33989 \begin_inset LatexCommand \index{Register allocation}
33993 , loop induction optimization causes an increase in register pressure, which
33994 may cause unwanted spilling of other temporary variables into the stack
33995 \begin_inset LatexCommand \index{stack}
34000 The compiler will generate a warning message when it is forced to allocate
34001 extra space either on the stack or data space.
34002 If this extra space allocation is undesirable then induction optimization
34003 can be eliminated either for the entire source file (with -
34007 \begin_layout Standard
34016 -noinduction option) or for a given function only using #pragma\InsetSpace ~
34018 \begin_inset LatexCommand \index{\#pragma noinduction}
34029 \begin_layout Verse
34032 for (i = 0 ; i < 100 ; i ++)
34041 \begin_layout Standard
34045 \begin_layout Verse
34050 for (i = 0; i < 100; i++)
34059 \begin_layout Standard
34060 As mentioned previously some loop invariants are not as apparent, all static
34061 address computations are also moved out of the loop.
34066 \begin_inset LatexCommand \index{Strength reduction}
34070 , this optimization substitutes an expression by a cheaper expression:
34073 \begin_layout Verse
34076 for (i=0;i < 100; i++)
34085 \begin_layout Standard
34089 \begin_layout Verse
34096 for (i=0;i< 100;i++) {
34102 ar[itemp1] = itemp2;
34120 \begin_layout Standard
34121 The more expensive multiplication
34122 \begin_inset LatexCommand \index{Multiplication}
34126 is changed to a less expensive addition.
34129 \begin_layout Subsection
34131 \begin_inset LatexCommand \index{Loop reversing}
34138 \begin_layout Standard
34139 This optimization is done to reduce the overhead of checking loop boundaries
34140 for every iteration.
34141 Some simple loops can be reversed and implemented using a
34142 \begin_inset Quotes eld
34145 decrement and jump if not zero
34146 \begin_inset Quotes erd
34150 SDCC checks for the following criterion to determine if a loop is reversible
34151 (note: more sophisticated compilers use data-dependency analysis to make
34152 this determination, SDCC uses a more simple minded analysis).
34155 \begin_layout Itemize
34156 The 'for' loop is of the form
34162 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
34172 \begin_layout Itemize
34173 The <for body> does not contain
34174 \begin_inset Quotes eld
34178 \begin_inset Quotes erd
34182 \begin_inset Quotes erd
34188 \begin_layout Itemize
34189 All goto's are contained within the loop.
34192 \begin_layout Itemize
34193 No function calls within the loop.
34196 \begin_layout Itemize
34197 The loop control variable <sym> is not assigned any value within the loop
34200 \begin_layout Itemize
34201 The loop control variable does NOT participate in any arithmetic operation
34205 \begin_layout Itemize
34206 There are NO switch statements in the loop.
34209 \begin_layout Subsection
34210 Algebraic Simplifications
34213 \begin_layout Standard
34214 SDCC does numerous algebraic simplifications, the following is a small sub-set
34215 of these optimizations.
34218 \begin_layout Verse
34221 i = j + 0;\InsetSpace ~
34225 /* changed to: */\InsetSpace ~
34231 i /= 2;\InsetSpace ~
34238 /* changed to: */\InsetSpace ~
34245 = j - j;\InsetSpace ~
34249 /* changed to: */\InsetSpace ~
34255 i = j / 1;\InsetSpace ~
34259 /* changed to: */\InsetSpace ~
34266 \begin_layout Standard
34267 Note the subexpressions
34268 \begin_inset LatexCommand \index{Subexpression}
34272 given above are generally introduced by macro expansions or as a result
34273 of copy/constant propagation.
34276 \begin_layout Subsection
34277 'switch' Statements
34278 \begin_inset LatexCommand \label{sub:'switch'-Statements}
34283 \begin_inset LatexCommand \index{switch statement}
34290 \begin_layout Standard
34291 SDCC can optimize switch statements to jump tables
34292 \begin_inset LatexCommand \index{jump tables}
34297 It makes the decision based on an estimate of the generated code size.
34298 SDCC is quite liberal in the requirements for jump table generation:
34301 \begin_layout Itemize
34302 The labels need not be in order, and the starting number need not be one
34303 or zero, the case labels are in numerical sequence or not too many case
34304 labels are missing.
34308 \begin_layout Verse
34311 switch(i) {\InsetSpace ~
34342 case 4: ...\InsetSpace ~
34374 case 5: ...\InsetSpace ~
34406 case 3: ...\InsetSpace ~
34437 case 6: ...\InsetSpace ~
34469 case 7: ...\InsetSpace ~
34501 case 8: ...\InsetSpace ~
34533 case 9: ...\InsetSpace ~
34565 case 10: ...\InsetSpace ~
34596 case 11: ...\InsetSpace ~
34663 \begin_layout Standard
34664 Both the above switch statements will be implemented using a jump-table.
34665 The example to the right side is slightly more efficient as the check for
34666 the lower boundary of the jump-table is not needed.
34670 \begin_layout Itemize
34671 The number of case labels is not larger than supported by the target architectur
34675 \begin_layout Itemize
34676 If the case labels are not in numerical sequence ('gaps' between cases)
34677 SDCC checks whether a jump table with additionally inserted dummy cases
34678 is still attractive.
34682 \begin_layout Itemize
34683 If the starting number is not zero and a check for the lower boundary of
34684 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
34689 \begin_layout Standard
34690 Switch statements which have large gaps in the numeric sequence or those
34691 that have too many case labels can be split into more than one switch statement
34692 for efficient code generation, e.g.:
34695 \begin_layout Verse
34773 \begin_layout Standard
34774 If the above switch statement is broken down into two switch statements
34777 \begin_layout Verse
34820 \begin_layout Standard
34824 \begin_layout Verse
34867 \begin_layout Standard
34868 then both the switch statements will be implemented using jump-tables whereas
34869 the unmodified switch statement will not be.
34872 \begin_layout Standard
34873 \begin_inset Note Note
34876 \begin_layout Standard
34877 There might be reasons which SDCC cannot know about to either favour or
34878 not favour jump tables.
34879 If the target system has to be as quick for the last switch case as for
34880 the first (pro jump table), or if the switch argument is known to be zero
34881 in the majority of the cases (contra jump table).
34889 \begin_layout Standard
34890 The pragma nojtbound
34891 \begin_inset LatexCommand \index{\#pragma nojtbound}
34895 can be used to turn off checking the
34908 It has no effect if a default label is supplied.
34909 Use of this pragma is dangerous: if the switch
34910 \begin_inset LatexCommand \index{switch statement}
34914 argument is not matched by a case statement the processor will happily
34918 \begin_layout Subsection
34919 Bit-shifting Operations
34920 \begin_inset LatexCommand \index{Bit shifting}
34927 \begin_layout Standard
34928 Bit shifting is one of the most frequently used operation in embedded programmin
34930 SDCC tries to implement bit-shift operations in the most efficient way
34934 \begin_layout Verse
34947 \begin_layout Standard
34948 generates the following code:
34951 \begin_layout Verse
34966 \begin_layout Standard
34967 In general SDCC will never setup a loop if the shift count is known.
34971 \begin_layout Verse
34984 \begin_layout Standard
34988 \begin_layout Verse
35012 \begin_layout Subsection
35014 \begin_inset LatexCommand \index{Bit rotation}
35021 \begin_layout Standard
35022 A special case of the bit-shift operation is bit rotation
35023 \begin_inset LatexCommand \index{rotating bits}
35027 , SDCC recognizes the following expression to be a left bit-rotation:
35030 \begin_layout Verse
35038 char i;\InsetSpace ~
35049 /* unsigned is needed for rotation */
35054 i = ((i << 1) | (i >> 7));
35063 \begin_layout Standard
35064 will generate the following code:
35067 \begin_layout Verse
35084 \begin_layout Standard
35085 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
35086 ns of this case will also be recognized as bit-rotation, i.e.:
35089 \begin_layout Verse
35092 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
35095 \begin_layout Subsection
35096 Nibble and Byte Swapping
35099 \begin_layout Standard
35100 Other special cases of the bit-shift operations are nibble or byte swapping
35101 \begin_inset LatexCommand \index{swapping nibbles/bytes}
35105 , SDCC recognizes the following expressions:
35108 \begin_layout Verse
35129 i = ((i << 4) | (i >> 4));
35135 j = ((j << 8) | (j >> 8));
35138 \begin_layout Standard
35139 and generates a swap instruction for the nibble swapping
35140 \begin_inset LatexCommand \index{Nibble swapping}
35144 or move instructions for the byte swapping
35145 \begin_inset LatexCommand \index{Byte swapping}
35151 \begin_inset Quotes sld
35155 \begin_inset Quotes srd
35158 example can be used to convert from little to big-endian or vice versa.
35159 If you want to change the endianness of a
35163 integer you have to cast to
35170 \begin_layout Standard
35171 Note that SDCC stores numbers in little-endian
35175 \begin_layout Standard
35176 Usually 8-bit processors don't care much about endianness.
35177 This is not the case for the standard 8051 which only has an instruction
35183 \begin_inset LatexCommand \index{DPTR}
35191 so little-endian is the more efficient byte order.
35197 \begin_inset LatexCommand \index{little-endian}
35202 \begin_inset LatexCommand \index{Endianness}
35207 lowest order first).
35210 \begin_layout Subsection
35212 \begin_inset LatexCommand \index{Highest Order Bit}
35217 \begin_inset LatexCommand \index{Any Order Bit}
35224 \begin_layout Standard
35225 It is frequently required to obtain the highest order bit of an integral
35226 type (long, int, short or char types).
35227 Also obtaining any other order bit is not uncommon.
35228 SDCC recognizes the following expressions to yield the highest order bit
35229 and generates optimized code for it, e.g.:
35232 \begin_layout Verse
35243 unsigned char hob1, aob1;
35247 bit hob2, hob3, aob2,
35257 hob1 = (gint >> 15) & 1;
35261 hob2 = (gint >> 15) & 1;
35265 hob3 = gint & 0x8000;
35270 aob1 = (gint >> 9) & 1;
35274 aob2 = (gint >> 8) & 1;
35278 aob3 = gint & 0x0800;
35288 \begin_layout Standard
35289 will generate the following code:
35292 \begin_layout Verse
35323 000A E5*01\InsetSpace ~
35350 000C 23\InsetSpace ~
35381 000D 54 01\InsetSpace ~
35409 000F F5*02\InsetSpace ~
35464 0011 E5*01\InsetSpace ~
35492 0013 33\InsetSpace ~
35522 0014 92*00\InsetSpace ~
35578 0016 E5*01\InsetSpace ~
35605 0018 33\InsetSpace ~
35635 0019 92*01\InsetSpace ~
35691 001B E5*01\InsetSpace ~
35750 001E 54 01\InsetSpace ~
35777 0020 F5*03\InsetSpace ~
35833 0022 E5*01\InsetSpace ~
35860 0024 13\InsetSpace ~
35890 0025 92*02\InsetSpace ~
35946 0027 E5*01\InsetSpace ~
36001 002B 92*03\InsetSpace ~
36029 \begin_layout Standard
36030 Other variations of these cases however will
36035 They are standard C expressions, so I heartily recommend these be the only
36036 way to get the highest order bit, (it is portable).
36037 Of course it will be recognized even if it is embedded in other expressions,
36041 \begin_layout Verse
36044 xyz = gint + ((gint >> 15) & 1);
36047 \begin_layout Standard
36048 will still be recognized.
36051 \begin_layout Subsection
36053 \begin_inset LatexCommand \index{Higher Order Byte}
36057 / Higher Order Word
36058 \begin_inset LatexCommand \index{Higher Order Word}
36065 \begin_layout Standard
36066 It is also frequently required to obtain a higher order byte or word of
36067 a larger integral type (long, int or short types).
36068 SDCC recognizes the following expressions to yield the higher order byte
36069 or word and generates optimized code for it, e.g.:
36072 \begin_layout Verse
36077 unsigned long int glong;
36085 unsigned char hob1,
36090 unsigned int how1, how2;
36099 hob1 = (gint >> 8) & 0xFF;
36103 hob2 = glong >> 24;
36107 how1 = (glong >> 16) & 0xFFFF;
36122 \begin_layout Standard
36123 will generate the following code:
36126 \begin_layout Verse
36157 0037 85*01*06\InsetSpace ~
36179 _foo_hob1_1_1,(_gint + 1)
36210 003A 85*05*07\InsetSpace ~
36232 _foo_hob2_1_1,(_glong + 3)
36262 003D 85*04*08\InsetSpace ~
36285 _foo_how1_1_1,(_glong + 2)
36287 0040 85*05*09\InsetSpace ~
36312 0043 85*03*0A\InsetSpace ~
36334 _foo_how2_1_1,(_glong + 1)
36336 0046 85*04*0B\InsetSpace ~
36359 (_foo_how2_1_1 + 1),(_glong + 2)
36362 \begin_layout Standard
36363 Again, variations of these cases may
36368 They are standard C expressions, so I heartily recommend these be the only
36369 way to get the higher order byte/word, (it is portable).
36370 Of course it will be recognized even if it is embedded in other expressions,
36374 \begin_layout Verse
36377 xyz = gint + ((gint >> 8) & 0xFF);
36380 \begin_layout Standard
36381 will still be recognized.
36384 \begin_layout Subsection
36386 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
36391 \begin_inset LatexCommand \index{Peephole optimizer}
36398 \begin_layout Standard
36399 The compiler uses a rule based, pattern matching and re-writing mechanism
36400 for peep-hole optimization.
36405 a peep-hole optimizer by Christopher W.
36406 Fraser (cwfraser\InsetSpace ~
36409 A default set of rules are compiled into the compiler, additional rules
36410 may be added with the
36416 \begin_layout Standard
36426 \begin_inset LatexCommand \index{-\/-peep-file}
36433 The rule language is best illustrated with examples.
36436 \begin_layout Verse
36458 \begin_layout Standard
36459 The above rule will change the following assembly
36460 \begin_inset LatexCommand \index{Assembler routines}
36467 \begin_layout Verse
36475 \begin_layout Standard
36479 \begin_layout Verse
36485 \begin_layout Standard
36486 Note: All occurrences of a
36490 (pattern variable) must denote the same string.
36491 With the above rule, the assembly sequence:
36494 \begin_layout Verse
36502 \begin_layout Standard
36503 will remain unmodified.
36507 Other special case optimizations may be added by the
36514 \begin_layout Standard
36527 some variants of the 8051 MCU
36528 \begin_inset LatexCommand \index{MCS51 variants}
36541 The following two rules will change all
36558 \begin_layout Verse
36561 replace { lcall %1 } by { acall %1 }
36563 replace { ljmp %1 } by { ajmp %1 }
36566 \begin_layout Standard
36567 (NOTE: from version 2.7.3 on, you can use option -
36573 \begin_layout Standard
36585 \begin_inset LatexCommand \index{-\/-acall-ajmp}
36589 , which also takes care of aligning the interrupt vectors properly.)
36594 \begin_layout Standard
36597 inline-assembler code
36599 is also passed through the peep hole optimizer, thus the peephole optimizer
36600 can also be used as an assembly level macro expander.
36601 The rules themselves are MCU dependent whereas the rule language infra-structur
36602 e is MCU independent.
36603 Peephole optimization rules for other MCU can be easily programmed using
36608 The syntax for a rule is as follows:
36611 \begin_layout Verse
36614 rule := replace [ restart ] '{' <assembly sequence> '
36652 <assembly sequence> '
36670 '}' [if <functionName> ] '
36675 \begin_layout Standard
36676 <assembly sequence> := assembly instruction (each instruction including
36677 labels must be on a separate line).
36681 The optimizer will apply to the rules
36682 one by one from the top in the sequence of their appearance, it will terminate
36683 when all rules are exhausted.
36684 If the 'restart' option is specified, then the optimizer will start matching
36685 the rules again from the top, this option for a rule is expensive (performance)
36686 , it is intended to be used in situations where a transformation will trigger
36687 the same rule again.
36688 An example of this (not a good one, it has side effects) is the following
36692 \begin_layout Verse
36712 \begin_layout Standard
36713 Note that the replace pattern cannot be a blank, but can be a comment line.
36714 Without the 'restart' option only the innermost 'pop' 'push' pair would
36715 be eliminated, i.e.:
36718 \begin_layout Verse
36730 \begin_layout Standard
36734 \begin_layout Verse
36744 \begin_layout Standard
36749 the restart option the rule will be applied again to the resulting code
36750 and then all the pop-push pairs will be eliminated to yield:
36753 \begin_layout Verse
36761 \begin_layout Standard
36762 A conditional function can be attached to a rule.
36763 Attaching rules are somewhat more involved, let me illustrate this with
36767 \begin_layout Verse
36791 \begin_layout Standard
36792 The optimizer does a look-up of a function name table defined in function
36797 in the source file SDCCpeeph.c, with the name
36802 If it finds a corresponding entry the function is called.
36803 Note there can be no parameters specified for these functions, in this
36808 is crucial, since the function
36812 expects to find the label in that particular variable (the hash table containin
36813 g the variable bindings is passed as a parameter).
36814 If you want to code more such functions, take a close look at the function
36815 labelInRange and the calling mechanism in source file SDCCpeeph.c.
36816 Currently implemented are
36818 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
36819 24bitMode, portIsDS390, 24bitModeAndPortDS390
36828 \begin_layout Standard
36829 I know this whole thing is a little kludgey, but maybe some day we will
36830 have some better means.
36831 If you are looking at this file, you will see the default rules that are
36832 compiled into the compiler, you can add your own rules in the default set
36833 there if you get tired of specifying the -
36837 \begin_layout Standard
36849 \begin_layout Section
36851 \begin_inset LatexCommand \index{ANSI-compliance}
36856 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
36863 \begin_layout Standard
36864 The latest publically available version of the standard
36866 ISO/IEC 9899 - Programming languages - C
36868 should be available at:
36869 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
36878 \begin_layout Standard
36879 Deviations from the compliance:
36882 \begin_layout Itemize
36883 functions are not reentrant
36884 \begin_inset LatexCommand \index{reentrant}
36888 unless explicitly declared as such or the
36894 \begin_layout Standard
36904 \begin_inset LatexCommand \index{-\/-stack-auto}
36910 command line option is specified.
36913 \begin_layout Itemize
36915 \begin_inset LatexCommand \index{struct}
36920 \begin_inset LatexCommand \index{union}
36924 cannot be assigned values directly, cannot be passed as function parameters
36925 or assigned to each other and cannot be a return value
36926 \begin_inset LatexCommand \index{return value}
36930 from a function, e.g.:
36934 \begin_layout Verse
36957 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
36976 s parms) /* invalid in SDCC although allowed in ANSI */
36998 return rets; /* is invalid in SDCC although allowed in ANSI */
37004 \begin_layout Itemize
37005 initialization of structure arrays must be fully braced.
37009 \begin_layout Verse
37012 struct s { char x } a[] = {1, 2};\InsetSpace ~
37017 /* invalid in SDCC */
37020 } a[] = {{1}, {2}}; /* OK */
37024 \begin_layout Itemize
37026 \begin_inset LatexCommand \index{long long (not supported)}
37031 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
37038 \begin_layout Itemize
37040 \begin_inset LatexCommand \index{double (not supported)}
37044 ' precision floating point
37045 \begin_inset LatexCommand \index{Floating point support}
37052 \begin_layout Itemize
37054 \begin_inset LatexCommand \index{K\&R style}
37058 function declarations are NOT allowed.
37062 \begin_layout Verse
37065 foo(i,j) /* this old style of function declarations */
37067 int i,j; /* is valid
37068 in ANSI but not valid in SDCC */
37083 \begin_layout Itemize
37084 Most enhancements in C99 are not supported, e.g.:
37088 \begin_layout Verse
37095 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
37099 \begin_layout Itemize
37100 But some have been added recently in SDCC 2.7.0.
37101 They must be considered alpha quality however.
37105 \begin_layout Verse
37110 \begin_inset LatexCommand \index{inline (not supported)}
37116 int increment (int a) { return a+1; } /* inlines the increment without
37117 function call overhead */
37122 \begin_inset LatexCommand \index{inline (not supported)}
37128 p; /* accepted but ignored */
37132 \begin_layout Itemize
37133 Certain words that are valid identifiers in the standard may be reserved
37134 words in SDCC unless the
37140 \begin_layout Standard
37150 \begin_inset LatexCommand \index{-\/-std-c89}
37162 \begin_layout Standard
37172 \begin_inset LatexCommand \index{-\/-std-c99}
37178 command line options are used.
37179 These may include (depending on the selected processor): 'at', 'banked',
37180 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
37181 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
37182 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
37184 Compliant equivalents of these keywords are always available in a form
37185 that begin with two underscores
37186 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
37191 '__data' instead of 'data'.
37194 \begin_layout Itemize
37195 Integer promotion of variable arguments is not performed if the argument
37196 is explicitly taypecasted unless the
37202 \begin_layout Standard
37212 \begin_inset LatexCommand \index{-\/-std-c89}
37224 \begin_layout Standard
37234 \begin_inset LatexCommand \index{-\/-std-c99}
37240 command line options are used.
37244 \begin_layout Verse
37247 void vararg_func (char *str, ...) { str; }
37264 u is promoted to int before
37269 * passing to function */
37273 vararg_func ("%c", c);
37280 argument u is not promoted to int,
37285 * it is passed as char to function
37291 --std-cXX is not defined;
37296 * is promoted to int before passing
37302 if --std-cXX is defined */
37306 vararg_func ("%bc", (char)u);
37312 \begin_layout Section
37313 Cyclomatic Complexity
37314 \begin_inset LatexCommand \index{Cyclomatic complexity}
37321 \begin_layout Standard
37322 Cyclomatic complexity of a function is defined as the number of independent
37323 paths the program can take during execution of the function.
37324 This is an important number since it defines the number test cases you
37325 have to generate to validate the function.
37326 The accepted industry standard for complexity number is 10, if the cyclomatic
37327 complexity reported by SDCC exceeds 10 you should think about simplification
37328 of the function logic.
37329 Note that the complexity level is not related to the number of lines of
37330 code in a function.
37331 Large functions can have low complexity, and small functions can have large
37337 SDCC uses the following formula to compute the complexity:
37342 \begin_layout Standard
37343 complexity = (number of edges in control flow graph) - (number of nodes
37344 in control flow graph) + 2;
37348 Having said that the industry standard is 10,
37349 you should be aware that in some cases it be may unavoidable to have a
37350 complexity level of less than 10.
37351 For example if you have switch statement with more than 10 case labels,
37352 each case label adds one to the complexity level.
37353 The complexity level is by no means an absolute measure of the algorithmic
37354 complexity of the function, it does however provide a good starting point
37355 for which functions you might look at for further optimization.
37358 \begin_layout Section
37359 Retargetting for other Processors
37362 \begin_layout Standard
37363 The issues for retargetting the compiler are far too numerous to be covered
37365 What follows is a brief description of each of the seven phases of the
37366 compiler and its MCU dependency.
37369 \begin_layout Itemize
37370 Parsing the source and building the annotated parse tree.
37371 This phase is largely MCU independent (except for the language extensions).
37372 Syntax & semantic checks are also done in this phase, along with some initial
37373 optimizations like back patching labels and the pattern matching optimizations
37374 like bit-rotation etc.
37377 \begin_layout Itemize
37378 The second phase involves generating an intermediate code which can be easy
37379 manipulated during the later phases.
37380 This phase is entirely MCU independent.
37381 The intermediate code generation assumes the target machine has unlimited
37382 number of registers, and designates them with the name iTemp.
37383 The compiler can be made to dump a human readable form of the code generated
37388 \begin_layout Standard
37400 \begin_layout Itemize
37401 This phase does the bulk of the standard optimizations and is also MCU independe
37403 This phase can be broken down into several sub-phases:
37407 Break down intermediate
37408 code (iCode) into basic blocks.
37410 Do control flow & data flow analysis on the
37413 Do local common subexpression elimination, then global subexpressio
37416 Dead code elimination
37420 If loop optimizations
37421 caused any changes then do 'global subexpression elimination' and 'dead
37422 code elimination' again.
37425 \begin_layout Itemize
37426 This phase determines the live-ranges; by live range I mean those iTemp
37427 variables defined by the compiler that still survive after all the optimization
37429 Live range analysis
37430 \begin_inset LatexCommand \index{Live range analysis}
37434 is essential for register allocation, since these computation determines
37435 which of these iTemps will be assigned to registers, and for how long.
37438 \begin_layout Itemize
37439 Phase five is register allocation.
37440 There are two parts to this process.
37444 The first part I call 'register packing'
37445 (for lack of a better term).
37446 In this case several MCU specific expression folding is done to reduce
37451 The second part is more MCU independent and deals with
37452 allocating registers to the remaining live ranges.
37453 A lot of MCU specific code does creep into this phase because of the limited
37454 number of index registers available in the 8051.
37457 \begin_layout Itemize
37458 The Code generation phase is (unhappily), entirely MCU dependent and very
37459 little (if any at all) of this code can be reused for other MCU.
37460 However the scheme for allocating a homogenized assembler operand for each
37461 iCode operand may be reused.
37464 \begin_layout Itemize
37465 As mentioned in the optimization section the peep-hole optimizer is rule
37466 based system, which can reprogrammed for other MCUs.
37469 \begin_layout Standard
37470 More information is available on SDCC Wiki
37471 \begin_inset LatexCommand \index{wiki}
37476 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting}
37480 ) and in the thread
37481 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
37488 \begin_layout Chapter
37490 \begin_inset LatexCommand \index{Compiler internals}
37497 \begin_layout Section
37498 The anatomy of the compiler
37499 \begin_inset LatexCommand \label{sub:The-anatomy-of}
37506 \begin_layout Standard
37509 This is an excerpt from an article published in Circuit Cellar Magazine
37515 It's a little outdated (the compiler is much more efficient now and user/develo
37516 per friendly), but pretty well exposes the guts of it all.
37522 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
37523 It is fairly easy to retarget for other 8-bit MCU.
37524 Here we take a look at some of the internals of the compiler.
37528 \begin_layout Paragraph*
37530 \begin_inset LatexCommand \index{Parsing}
37537 \begin_layout Standard
37538 Parsing the input source file and creating an AST (Annotated Syntax Tree
37539 \begin_inset LatexCommand \index{Annotated syntax tree}
37544 This phase also involves propagating types (annotating each node of the
37545 parse tree with type information) and semantic analysis.
37546 There are some MCU specific parsing rules.
37547 For example the storage classes, the extended storage classes are MCU specific
37548 while there may be a xdata storage class for 8051 there is no such storage
37549 class for z80 or Atmel AVR.
37550 SDCC allows MCU specific storage class extensions, i.e.
37551 xdata will be treated as a storage class specifier when parsing 8051 C
37552 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
37556 \begin_layout Paragraph*
37558 \begin_inset LatexCommand \index{iCode}
37565 \begin_layout Standard
37566 Intermediate code generation.
37567 In this phase the AST is broken down into three-operand form (iCode).
37568 These three operand forms are represented as doubly linked lists.
37569 ICode is the term given to the intermediate form generated by the compiler.
37570 ICode example section shows some examples of iCode generated for some simple
37571 C source functions.
37574 \begin_layout Paragraph*
37576 \begin_inset LatexCommand \index{Optimizations}
37583 \begin_layout Standard
37584 Bulk of the target independent optimizations is performed in this phase.
37585 The optimizations include constant propagation, common sub-expression eliminati
37586 on, loop invariant code movement, strength reduction of loop induction variables
37587 and dead-code elimination.
37590 \begin_layout Paragraph*
37591 Live range analysis
37592 \begin_inset LatexCommand \index{Live range analysis}
37599 \begin_layout Standard
37600 During intermediate code generation phase, the compiler assumes the target
37601 machine has infinite number of registers and generates a lot of temporary
37603 The live range computation determines the lifetime of each of these compiler-ge
37604 nerated temporaries.
37605 A picture speaks a thousand words.
37606 ICode example sections show the live range annotations for each of the
37608 It is important to note here, each iCode is assigned a number in the order
37609 of its execution in the function.
37610 The live ranges are computed in terms of these numbers.
37611 The from number is the number of the iCode which first defines the operand
37612 and the to number signifies the iCode which uses this operand last.
37615 \begin_layout Paragraph*
37616 Register Allocation
37617 \begin_inset LatexCommand \index{Register allocation}
37624 \begin_layout Standard
37625 The register allocation determines the type and number of registers needed
37627 In most MCUs only a few registers can be used for indirect addressing.
37628 In case of 8051 for example the registers R0 & R1 can be used to indirectly
37629 address the internal ram and DPTR to indirectly address the external ram.
37630 The compiler will try to allocate the appropriate register to pointer variables
37632 ICode example section shows the operands annotated with the registers assigned
37634 The compiler will try to keep operands in registers as much as possible;
37635 there are several schemes the compiler uses to do achieve this.
37636 When the compiler runs out of registers the compiler will check to see
37637 if there are any live operands which is not used or defined in the current
37638 basic block being processed, if there are any found then it will push that
37639 operand and use the registers in this block, the operand will then be popped
37640 at the end of the basic block.
37644 \begin_layout Standard
37645 There are other MCU specific considerations in this phase.
37646 Some MCUs have an accumulator; very short-lived operands could be assigned
37647 to the accumulator instead of a general-purpose register.
37650 \begin_layout Paragraph*
37654 \begin_layout Standard
37655 Figure II gives a table of iCode
37656 \begin_inset LatexCommand \index{iCode}
37660 operations supported by the compiler.
37661 The code generation involves translating these operations into corresponding
37662 assembly code for the processor.
37663 This sounds overly simple but that is the essence of code generation.
37664 Some of the iCode operations are generated on a MCU specific manner for
37665 example, the z80 port does not use registers to pass parameters so the
37666 SEND and RECV iCode operations will not be generated, and it also does
37667 not support JUMPTABLES.
37673 \begin_layout Standard
37677 \begin_inset Tabular
37678 <lyxtabular version="3" rows="39" columns="4">
37679 <features islongtable="true" headBottomDL="true">
37680 <column alignment="block" valignment="top" leftline="true" width="13col%">
37681 <column alignment="left" valignment="top" leftline="true" width="13col%">
37682 <column alignment="block" valignment="top" leftline="true" width="22col%">
37683 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
37684 <row topline="true" bottomline="true" endhead="true">
37685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37688 \begin_layout Standard
37694 \begin_inset LatexCommand \index{iCode}
37703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37706 \begin_layout Standard
37714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37717 \begin_layout Standard
37725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37728 \begin_layout Standard
37737 <row topline="true">
37738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37741 \begin_layout Standard
37749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37752 \begin_layout Standard
37755 IC_LEFT() IC_RESULT()
37760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37763 \begin_layout Standard
37771 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37774 \begin_layout Standard
37777 IC_RESULT = ! IC_LEFT;
37783 <row topline="true">
37784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37787 \begin_layout Standard
37795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37798 \begin_layout Standard
37801 IC_LEFT() IC_RESULT()
37806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37809 \begin_layout Standard
37812 Bitwise complement of
37817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37820 \begin_layout Standard
37823 IC_RESULT = ~IC_LEFT;
37829 <row topline="true">
37830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37833 \begin_layout Standard
37841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37844 \begin_layout Standard
37847 IC_LEFT() IC_RESULT()
37852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37855 \begin_layout Standard
37858 Rotate right with carry
37863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37866 \begin_layout Standard
37869 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
37875 <row topline="true">
37876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37879 \begin_layout Standard
37887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37890 \begin_layout Standard
37893 IC_LEFT() IC_RESULT()
37898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37901 \begin_layout Standard
37904 Rotate left with carry
37909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37912 \begin_layout Standard
37915 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
37921 <row topline="true">
37922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37925 \begin_layout Standard
37933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37936 \begin_layout Standard
37939 IC_LEFT() IC_RESULT()
37944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37947 \begin_layout Standard
37950 Get the highest order bit of IC_LEFT
37955 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37958 \begin_layout Standard
37961 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
37967 <row topline="true">
37968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37971 \begin_layout Standard
37979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37982 \begin_layout Standard
37985 IC_LEFT() IC_RESULT()
37990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37993 \begin_layout Standard
38001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38004 \begin_layout Standard
38007 IC_RESULT = - IC_LEFT;
38013 <row topline="true">
38014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38017 \begin_layout Standard
38025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38028 \begin_layout Standard
38036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38039 \begin_layout Standard
38042 Push the operand into stack
38047 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38050 \begin_layout Standard
38059 <row topline="true">
38060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38063 \begin_layout Standard
38071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38074 \begin_layout Standard
38082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38085 \begin_layout Standard
38088 Pop the operand from the stack
38093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38096 \begin_layout Standard
38105 <row topline="true">
38106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38109 \begin_layout Standard
38117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38120 \begin_layout Standard
38123 IC_LEFT() IC_RESULT()
38128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38131 \begin_layout Standard
38134 Call the function represented by IC_LEFT
38139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38142 \begin_layout Standard
38145 IC_RESULT = IC_LEFT();
38151 <row topline="true">
38152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38155 \begin_layout Standard
38163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38166 \begin_layout Standard
38169 IC_LEFT() IC_RESULT()
38174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38177 \begin_layout Standard
38180 Call via function pointer
38185 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38188 \begin_layout Standard
38191 IC_RESULT = (*IC_LEFT)();
38197 <row topline="true">
38198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38201 \begin_layout Standard
38209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38212 \begin_layout Standard
38220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38223 \begin_layout Standard
38226 Return the value in operand IC_LEFT
38231 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38234 \begin_layout Standard
38243 <row topline="true">
38244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38247 \begin_layout Standard
38255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38258 \begin_layout Standard
38266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38269 \begin_layout Standard
38277 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38280 \begin_layout Standard
38289 <row topline="true">
38290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38293 \begin_layout Standard
38301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38304 \begin_layout Standard
38312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38315 \begin_layout Standard
38323 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38326 \begin_layout Standard
38335 <row topline="true">
38336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38339 \begin_layout Standard
38347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38350 \begin_layout Standard
38353 IC_LEFT() IC_RIGHT() IC_RESULT()
38358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38361 \begin_layout Standard
38369 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38372 \begin_layout Standard
38375 IC_RESULT = IC_LEFT + IC_RIGHT
38381 <row topline="true">
38382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38385 \begin_layout Standard
38393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38396 \begin_layout Standard
38399 IC_LEFT() IC_RIGHT() IC_RESULT()
38404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38407 \begin_layout Standard
38415 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38418 \begin_layout Standard
38421 IC_RESULT = IC_LEFT - IC_RIGHT
38427 <row topline="true">
38428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38431 \begin_layout Standard
38439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38442 \begin_layout Standard
38445 IC_LEFT() IC_RIGHT() IC_RESULT()
38450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38453 \begin_layout Standard
38461 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38464 \begin_layout Standard
38467 IC_RESULT = IC_LEFT * IC_RIGHT;
38473 <row topline="true">
38474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38477 \begin_layout Standard
38485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38488 \begin_layout Standard
38491 IC_LEFT() IC_RIGHT() IC_RESULT()
38496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38499 \begin_layout Standard
38507 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38510 \begin_layout Standard
38513 IC_RESULT = IC_LEFT / IC_RIGHT;
38519 <row topline="true">
38520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38523 \begin_layout Standard
38531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38534 \begin_layout Standard
38537 IC_LEFT() IC_RIGHT() IC_RESULT()
38542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38545 \begin_layout Standard
38553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38556 \begin_layout Standard
38559 IC_RESULT = IC_LEFT % IC_RIGHT;
38565 <row topline="true">
38566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38569 \begin_layout Standard
38577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38580 \begin_layout Standard
38583 IC_LEFT() IC_RIGHT() IC_RESULT()
38588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38591 \begin_layout Standard
38599 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38602 \begin_layout Standard
38605 IC_RESULT = IC_LEFT < IC_RIGHT;
38611 <row topline="true">
38612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38615 \begin_layout Standard
38623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38626 \begin_layout Standard
38629 IC_LEFT() IC_RIGHT() IC_RESULT()
38634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38637 \begin_layout Standard
38645 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38648 \begin_layout Standard
38651 IC_RESULT = IC_LEFT > IC_RIGHT;
38657 <row topline="true">
38658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38661 \begin_layout Standard
38669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38672 \begin_layout Standard
38675 IC_LEFT() IC_RIGHT() IC_RESULT()
38680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38683 \begin_layout Standard
38691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38694 \begin_layout Standard
38697 IC_RESULT = IC_LEFT == IC_RIGHT;
38703 <row topline="true">
38704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38707 \begin_layout Standard
38715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38718 \begin_layout Standard
38721 IC_LEFT() IC_RIGHT() IC_RESULT()
38726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38729 \begin_layout Standard
38732 Logical and operation
38737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38740 \begin_layout Standard
38743 IC_RESULT = IC_LEFT && IC_RIGHT;
38749 <row topline="true">
38750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38753 \begin_layout Standard
38761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38764 \begin_layout Standard
38767 IC_LEFT() IC_RIGHT() IC_RESULT()
38772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38775 \begin_layout Standard
38778 Logical or operation
38783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38786 \begin_layout Standard
38789 IC_RESULT = IC_LEFT || IC_RIGHT;
38795 <row topline="true">
38796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38799 \begin_layout Standard
38807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38810 \begin_layout Standard
38813 IC_LEFT() IC_RIGHT() IC_RESULT()
38818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38821 \begin_layout Standard
38829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38832 \begin_layout Standard
38835 IC_RESULT = IC_LEFT ^ IC_RIGHT;
38841 <row topline="true">
38842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38845 \begin_layout Standard
38853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38856 \begin_layout Standard
38859 IC_LEFT() IC_RIGHT() IC_RESULT()
38864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38867 \begin_layout Standard
38875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38878 \begin_layout Standard
38881 IC_RESULT = IC_LEFT | IC_RIGHT;
38887 <row topline="true">
38888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38891 \begin_layout Standard
38899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38902 \begin_layout Standard
38905 IC_LEFT() IC_RIGHT() IC_RESULT()
38910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38913 \begin_layout Standard
38921 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38924 \begin_layout Standard
38927 IC_RESULT = IC_LEFT & IC_RIGHT;
38933 <row topline="true">
38934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38937 \begin_layout Standard
38945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38948 \begin_layout Standard
38951 IC_LEFT() IC_RIGHT() IC_RESULT()
38956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38959 \begin_layout Standard
38967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38970 \begin_layout Standard
38973 IC_RESULT = IC_LEFT << IC_RIGHT
38979 <row topline="true">
38980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38983 \begin_layout Standard
38991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38994 \begin_layout Standard
38997 IC_LEFT() IC_RIGHT() IC_RESULT()
39002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39005 \begin_layout Standard
39013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39016 \begin_layout Standard
39019 IC_RESULT = IC_LEFT >> IC_RIGHT
39025 <row topline="true">
39026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39029 \begin_layout Standard
39039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39042 \begin_layout Standard
39045 IC_LEFT() IC_RESULT()
39050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39053 \begin_layout Standard
39061 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39064 \begin_layout Standard
39067 IC_RESULT = (*IC_LEFT);
39073 <row topline="true">
39074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39077 \begin_layout Standard
39085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39088 \begin_layout Standard
39091 IC_RIGHT() IC_RESULT()
39096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39099 \begin_layout Standard
39107 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39110 \begin_layout Standard
39113 (*IC_RESULT) = IC_RIGHT;
39119 <row topline="true">
39120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39123 \begin_layout Standard
39131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39134 \begin_layout Standard
39137 IC_RIGHT() IC_RESULT()
39142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39145 \begin_layout Standard
39153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39156 \begin_layout Standard
39159 IC_RESULT = IC_RIGHT;
39165 <row topline="true">
39166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39169 \begin_layout Standard
39177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39180 \begin_layout Standard
39183 IC_COND IC_TRUE IC_LABEL
39188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39191 \begin_layout Standard
39195 If true label is present then jump to true label if condition is true else
39196 jump to false label if condition is false
39201 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39204 \begin_layout Standard
39207 if (IC_COND) goto IC_TRUE;
39213 If (!IC_COND) goto IC_FALSE;
39219 <row topline="true">
39220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39223 \begin_layout Standard
39231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39234 \begin_layout Standard
39237 IC_LEFT() IC_RESULT()
39242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39245 \begin_layout Standard
39253 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39256 \begin_layout Standard
39259 IC_RESULT = &IC_LEFT();
39265 <row topline="true">
39266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39269 \begin_layout Standard
39277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39280 \begin_layout Standard
39283 IC_JTCOND IC_JTLABELS
39288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39291 \begin_layout Standard
39294 Jump to list of labels depending on the value of JTCOND
39299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39302 \begin_layout Standard
39311 <row topline="true">
39312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39315 \begin_layout Standard
39323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39326 \begin_layout Standard
39329 IC_RIGHT() IC_LEFT() IC_RESULT()
39334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39337 \begin_layout Standard
39345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39348 \begin_layout Standard
39351 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
39357 <row topline="true">
39358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39361 \begin_layout Standard
39369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39372 \begin_layout Standard
39380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39383 \begin_layout Standard
39386 This is used for passing parameters in registers;
39388 move IC_LEFT to the next
39389 available parameter register.
39394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39397 \begin_layout Standard
39406 <row topline="true">
39407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39410 \begin_layout Standard
39418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39421 \begin_layout Standard
39429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39432 \begin_layout Standard
39435 This is used for receiving parameters passed in registers;
39438 in the next parameter register to IC_RESULT
39443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39446 \begin_layout Standard
39455 <row topline="true" bottomline="true">
39456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39459 \begin_layout Standard
39463 (some more have been added)
39468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39471 \begin_layout Standard
39477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39480 \begin_layout Standard
39486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39489 \begin_layout Standard
39513 \begin_layout Standard
39514 \begin_inset Note Note
39517 \begin_layout Standard
39518 In the original article Figure II was announced to be downloadable on
39523 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
39531 \begin_layout Paragraph*
39533 \begin_inset LatexCommand \index{iCode}
39540 \begin_layout Standard
39541 This section shows some details of iCode.
39542 The example C code does not do anything useful; it is used as an example
39543 to illustrate the intermediate code generated by the compiler.
39546 \begin_layout Verse
39556 /* This function does nothing useful.
39563 for the purpose of explaining iCode */
39566 short function (data
39575 short i=10; \InsetSpace ~
39577 /* dead initialization eliminated */
39583 /* dead initialization eliminated */
39611 /* compiler detects i,j to be induction
39616 for (i = 0, j = 10 ; i < 10 ; i++, j
39622 \begin_layout Standard
39645 mul += i * 3; \InsetSpace ~
39647 /* this multiplication remains */
39654 j * 3;\InsetSpace ~
39656 /* this multiplication changed to addition */
39670 \begin_layout Standard
39671 In addition to the operands each iCode contains information about the filename
39672 and line it corresponds to in the source file.
39673 The first field in the listing should be interpreted as follows:
39678 Filename(linenumber: iCode Execution sequence number : ICode hash table
39679 key : loop depth of the iCode).
39684 Then follows the human readable form of the ICode operation.
39685 Each operand of this triplet form can be of three basic types a) compiler
39686 generated temporary b) user defined variable c) a constant value.
39687 Note that local variables and parameters are replaced by compiler generated
39690 \begin_inset LatexCommand \index{Live range analysis}
39694 are computed only for temporaries (i.e.
39695 live ranges are not computed for global variables).
39697 \begin_inset LatexCommand \index{Register allocation}
39701 are allocated for temporaries only.
39702 Operands are formatted in the following manner:
39707 Operand Name [lr live-from : live-to ] { type information } [ registers
39713 As mentioned earlier the live ranges are computed in terms of the execution
39714 sequence number of the iCodes, for example
39716 the iTemp0 is live from (i.e.
39717 first defined in iCode with execution sequence number 3, and is last used
39718 in the iCode with sequence number 5).
39719 For induction variables such as iTemp21 the live range computation extends
39720 the lifetime from the start to the end of the loop.
39722 The register allocator
39723 used the live range information to allocate registers, the same registers
39724 may be used for different temporaries if their live ranges do not overlap,
39725 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
39726 ranges do not overlap.
39727 In addition the allocator also takes into consideration the type and usage
39728 of a temporary, for example itemp6 is a pointer to near space and is used
39729 as to fetch data from (i.e.
39730 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
39731 Some short lived temporaries are allocated to special registers which have
39732 meaning to the code generator e.g.
39733 iTemp13 is allocated to a pseudo register CC which tells the back end that
39734 the temporary is used only for a conditional jump the code generation makes
39735 use of this information to optimize a compare and jump ICode.
39739 \begin_inset LatexCommand \index{Loop optimization}
39743 performed by the compiler.
39744 It can detect induction variables iTemp21(i) and iTemp23(j).
39745 Also note the compiler does selective strength reduction
39746 \begin_inset LatexCommand \index{Strength reduction}
39751 the multiplication of an induction variable in line 18 (gint = j * 3) is
39752 changed to addition, a new temporary iTemp17 is allocated and assigned
39753 a initial value, a constant 3 is then added for each iteration of the loop.
39754 The compiler does not change the multiplication
39755 \begin_inset LatexCommand \index{Multiplication}
39759 in line 17 however since the processor does support an 8 * 8 bit multiplication.
39762 Note the dead code elimination
39763 \begin_inset LatexCommand \index{Dead-code elimination}
39767 optimization eliminated the dead assignments in line 7 & 8 to I and sum
39773 \begin_layout Standard
39776 Sample.c (5:1:0:0) _entry($9) :
39779 \begin_layout Standard
39782 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
39785 \begin_layout Standard
39788 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
39791 \begin_layout Standard
39794 Sample.c(11:4:53:0) preHeaderLbl0($11) :
39797 \begin_layout Standard
39800 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
39804 \begin_layout Standard
39807 Sample.c(11:6:5:1) _whilecontinue_0($1) :
39810 \begin_layout Standard
39813 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
39817 \begin_layout Standard
39820 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39823 \begin_layout Standard
39826 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
39830 \begin_layout Standard
39833 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
39837 \begin_layout Standard
39840 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
39844 \begin_layout Standard
39847 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
39851 \begin_layout Standard
39854 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
39855 * int}[r0] + 0x2 {short}
39858 \begin_layout Standard
39861 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
39864 \begin_layout Standard
39867 Sample.c(11:17:21:0)_whilebreak_0($3) :
39870 \begin_layout Standard
39873 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39876 \begin_layout Standard
39879 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39882 \begin_layout Standard
39885 Sample.c(15:20:54:0)preHeaderLbl1($13) :
39888 \begin_layout Standard
39891 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39894 \begin_layout Standard
39897 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39900 \begin_layout Standard
39903 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39906 \begin_layout Standard
39909 Sample.c(15:24:26:1)_forcond_0($4) :
39912 \begin_layout Standard
39915 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
39919 \begin_layout Standard
39922 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39925 \begin_layout Standard
39928 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
39929 + ITemp21 [lr21:38]{short}[r4]
39932 \begin_layout Standard
39935 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
39939 \begin_layout Standard
39942 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
39943 + iTemp15 [lr29:30]{short}[r1]
39946 \begin_layout Standard
39949 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
39953 \begin_layout Standard
39956 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
39960 \begin_layout Standard
39963 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
39967 \begin_layout Standard
39970 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
39974 \begin_layout Standard
39977 Sample.c(19:38:47:1) goto _forcond_0($4)
39980 \begin_layout Standard
39983 Sample.c(19:39:48:0)_forbreak_0($7) :
39986 \begin_layout Standard
39989 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
39990 + ITemp11 [lr19:40]{short}[r3]
39993 \begin_layout Standard
39996 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
39999 \begin_layout Standard
40002 Sample.c(20:42:51:0)_return($8) :
40005 \begin_layout Standard
40008 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
40014 Finally the code generated for this function:
40019 \begin_layout Standard
40025 \begin_layout Standard
40031 \begin_layout Standard
40039 \begin_layout Standard
40045 \begin_layout Standard
40053 \begin_layout Standard
40059 \begin_layout Standard
40062 ; ----------------------------------------------
40065 \begin_layout Standard
40068 ; function function
40071 \begin_layout Standard
40074 ; ----------------------------------------------
40077 \begin_layout Standard
40083 \begin_layout Standard
40086 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
40089 \begin_layout Standard
40097 \begin_layout Standard
40100 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
40103 \begin_layout Standard
40111 \begin_layout Standard
40114 ;_whilecontinue_0($1) :
40117 \begin_layout Standard
40123 \begin_layout Standard
40126 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
40129 \begin_layout Standard
40132 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
40135 \begin_layout Standard
40143 \begin_layout Standard
40151 \begin_layout Standard
40159 \begin_layout Standard
40167 \begin_layout Standard
40175 \begin_layout Standard
40183 \begin_layout Standard
40191 \begin_layout Standard
40197 \begin_layout Standard
40200 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
40203 \begin_layout Standard
40211 \begin_layout Standard
40219 \begin_layout Standard
40222 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
40225 \begin_layout Standard
40233 \begin_layout Standard
40241 \begin_layout Standard
40249 \begin_layout Standard
40257 \begin_layout Standard
40265 \begin_layout Standard
40273 \begin_layout Standard
40276 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
40279 \begin_layout Standard
40287 \begin_layout Standard
40295 \begin_layout Standard
40303 \begin_layout Standard
40311 \begin_layout Standard
40319 \begin_layout Standard
40322 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
40325 \begin_layout Standard
40333 \begin_layout Standard
40341 \begin_layout Standard
40349 \begin_layout Standard
40352 ; iTemp6 [lr5:16]{_near * int}[r0] =
40355 \begin_layout Standard
40358 ; iTemp6 [lr5:16]{_near * int}[r0] +
40361 \begin_layout Standard
40367 \begin_layout Standard
40375 \begin_layout Standard
40378 ; goto _whilecontinue_0($1)
40381 \begin_layout Standard
40389 \begin_layout Standard
40392 ; _whilebreak_0($3) :
40395 \begin_layout Standard
40401 \begin_layout Standard
40404 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
40407 \begin_layout Standard
40415 \begin_layout Standard
40418 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
40421 \begin_layout Standard
40429 \begin_layout Standard
40432 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
40435 \begin_layout Standard
40443 \begin_layout Standard
40446 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
40449 \begin_layout Standard
40457 \begin_layout Standard
40465 \begin_layout Standard
40468 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
40471 \begin_layout Standard
40479 \begin_layout Standard
40487 \begin_layout Standard
40493 \begin_layout Standard
40499 \begin_layout Standard
40502 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
40505 \begin_layout Standard
40508 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
40511 \begin_layout Standard
40519 \begin_layout Standard
40527 \begin_layout Standard
40535 \begin_layout Standard
40543 \begin_layout Standard
40551 \begin_layout Standard
40557 \begin_layout Standard
40560 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
40563 \begin_layout Standard
40566 ; iTemp21 [lr21:38]{short}[r4]
40569 \begin_layout Standard
40577 \begin_layout Standard
40585 \begin_layout Standard
40593 \begin_layout Standard
40596 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
40599 \begin_layout Standard
40607 \begin_layout Standard
40615 \begin_layout Standard
40623 \begin_layout Standard
40631 \begin_layout Standard
40634 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
40637 \begin_layout Standard
40640 ; iTemp15 [lr29:30]{short}[r1]
40643 \begin_layout Standard
40651 \begin_layout Standard
40659 \begin_layout Standard
40662 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
40665 \begin_layout Standard
40673 \begin_layout Standard
40681 \begin_layout Standard
40689 \begin_layout Standard
40697 \begin_layout Standard
40705 \begin_layout Standard
40713 \begin_layout Standard
40716 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
40719 \begin_layout Standard
40727 \begin_layout Standard
40735 \begin_layout Standard
40743 \begin_layout Standard
40751 \begin_layout Standard
40759 \begin_layout Standard
40767 \begin_layout Standard
40770 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
40773 \begin_layout Standard
40781 \begin_layout Standard
40784 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
40787 \begin_layout Standard
40795 \begin_layout Standard
40800 cjne r5,#0xff,00104$
40803 \begin_layout Standard
40811 \begin_layout Standard
40814 ; goto _forcond_0($4)
40817 \begin_layout Standard
40825 \begin_layout Standard
40828 ; _forbreak_0($7) :
40831 \begin_layout Standard
40837 \begin_layout Standard
40840 ; ret iTemp24 [lr40:41]{short}
40843 \begin_layout Standard
40851 \begin_layout Standard
40859 \begin_layout Standard
40867 \begin_layout Standard
40873 \begin_layout Standard
40879 \begin_layout Standard
40889 \begin_layout Section
40890 A few words about basic block successors, predecessors and dominators
40893 \begin_layout Standard
40894 Successors are basic blocks
40895 \begin_inset LatexCommand \index{Basic blocks}
40899 that might execute after this basic block.
40901 Predecessors are basic blocks
40902 that might execute before reaching this basic block.
40904 Dominators are basic
40905 blocks that WILL execute before reaching this basic block.
40910 \begin_layout Standard
40914 \begin_layout Standard
40918 \begin_layout Standard
40926 \begin_layout Standard
40930 \begin_layout Standard
40938 \begin_layout Standard
40944 \begin_layout Standard
40945 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
40948 \begin_layout Standard
40949 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
40952 \begin_layout Standard
40953 c) domVect of [BB4] = BB1 ...
40954 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
40958 \begin_layout Chapter
40962 \begin_layout Standard
40963 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/#Who}
40973 Thanks to all the other volunteer developers who have helped with coding,
40974 testing, web-page creation, distribution sets, etc.
40975 You know who you are :-)
40983 Thanks to Sourceforge
40984 \begin_inset LatexCommand \url{http://www.sf.net}
40988 which has hosted the project since 1999 and donates significant download
40997 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
40998 cycles and bandwidth for snapshot builds.
41003 \begin_layout Standard
41004 This document was initially written by Sandeep Dutta
41007 \begin_layout Standard
41008 All product names mentioned herein may be trademarks
41009 \begin_inset LatexCommand \index{Trademarks}
41013 of their respective companies.
41017 \begin_layout Section*
41021 \begin_layout Standard
41022 To avoid confusion, the installation and building options for SDCC itself
41023 (chapter 2) are not part of the index.
41026 \begin_layout Standard
41027 \begin_inset LatexCommand \printindex{}