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_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
8982 Use code bank <Num>.
8986 \labelwidthstring 00.00.0000
8993 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
8997 Use data bank <Num>.
9001 \labelwidthstring 00.00.0000
9008 \begin_layout Standard
9021 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
9025 Use <Value> for the code segment name.
9029 \labelwidthstring 00.00.0000
9036 \begin_layout Standard
9049 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
9053 Use <Value> for the const segment name.
9056 \begin_layout Standard
9057 \begin_inset VSpace bigskip
9063 \begin_layout Subsection
9064 Optimization Options
9065 \begin_inset LatexCommand \index{Options optimization}
9070 \begin_inset LatexCommand \index{Optimization options}
9078 \labelwidthstring 00.00.0000
9085 \begin_layout Standard
9095 \begin_inset LatexCommand \index{-\/-nogcse}
9101 Will not do global subexpression elimination, this option may be used when
9102 the compiler creates undesirably large stack/data spaces to store compiler
9112 \begin_inset LatexCommand \index{sloc (spill location)}
9117 A warning message will be generated when this happens and the compiler
9118 will indicate the number of extra bytes it allocated.
9119 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9121 \begin_inset LatexCommand \index{\#pragma nogcse}
9125 can be used to turn off global subexpression elimination
9126 \begin_inset LatexCommand \index{Subexpression elimination}
9130 for a given function only.
9134 \labelwidthstring 00.00.0000
9141 \begin_layout Standard
9151 \begin_inset LatexCommand \index{-\/-noinvariant}
9157 Will not do loop invariant optimizations, this may be turned off for reasons
9158 explained for the previous option.
9159 For more details of loop optimizations performed see Loop Invariants in
9161 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
9166 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9168 \begin_inset LatexCommand \index{\#pragma noinvariant}
9172 can be used to turn off invariant optimizations for a given function only.
9176 \labelwidthstring 00.00.0000
9183 \begin_layout Standard
9193 \begin_inset LatexCommand \index{-\/-noinduction}
9199 Will not do loop induction optimizations, see section strength reduction
9201 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9203 \begin_inset LatexCommand \index{\#pragma noinduction}
9207 can be used to turn off induction optimizations for a given function only.
9211 \labelwidthstring 00.00.0000
9218 \begin_layout Standard
9228 \begin_inset LatexCommand \index{-\/-nojtbound}
9239 Will not generate boundary condition check when switch statements
9240 \begin_inset LatexCommand \index{switch statement}
9244 are implemented using jump-tables.
9246 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
9251 Switch Statements for more details.
9252 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9254 \begin_inset LatexCommand \index{\#pragma nojtbound}
9258 can be used to turn off boundary checking for jump tables for a given function
9263 \labelwidthstring 00.00.0000
9270 \begin_layout Standard
9280 \begin_inset LatexCommand \index{-\/-noloopreverse}
9289 Will not do loop reversal
9290 \begin_inset LatexCommand \index{Loop reversing}
9298 \labelwidthstring 00.00.0000
9303 \begin_layout Standard
9317 \begin_inset LatexCommand \index{-\/-nolabelopt }
9321 Will not optimize labels (makes the dumpfiles more readable).
9325 \labelwidthstring 00.00.0000
9332 \begin_layout Standard
9342 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9348 Will not memcpy initialized data from code space into xdata space.
9349 This saves a few bytes in code space if you don't have initialized data
9350 \begin_inset LatexCommand \index{Variable initialization}
9358 \labelwidthstring 00.00.0000
9365 \begin_layout Standard
9375 \begin_inset LatexCommand \index{-\/-nooverlay}
9381 The compiler will not overlay parameters and local variables of any function,
9382 see section Parameters and local variables for more details.
9386 \labelwidthstring 00.00.0000
9393 \begin_layout Standard
9403 \begin_inset LatexCommand \index{-\/-no-peep}
9409 Disable peep-hole optimization with built-in rules.
9413 \labelwidthstring 00.00.0000
9420 \begin_layout Standard
9432 \begin_inset LatexCommand \index{-\/-peep-file}
9437 <filename> This option can be used to use additional rules to be used by
9438 the peep hole optimizer.
9440 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9445 Peep Hole optimizations for details on how to write these rules.
9449 \labelwidthstring 00.00.0000
9456 \begin_layout Standard
9466 \begin_inset LatexCommand \index{-\/-peep-asm}
9472 Pass the inline assembler code through the peep hole optimizer.
9473 This can cause unexpected changes to inline assembler code, please go through
9474 the peephole optimizer
9475 \begin_inset LatexCommand \index{Peephole optimizer}
9479 rules defined in the source file tree '<target>/peeph.def' before using
9484 \labelwidthstring 00.00.0000
9491 \begin_layout Standard
9501 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9507 The compiler will optimize code generation towards fast code, possibly
9508 at the expense of code size.
9512 \labelwidthstring 00.00.0000
9519 \begin_layout Standard
9529 \begin_inset LatexCommand \index{-\/-opt-code-size}
9535 The compiler will optimize code generation towards compact code, possibly
9536 at the expense of code speed.
9539 \begin_layout Standard
9540 \begin_inset VSpace bigskip
9546 \begin_layout Subsection
9548 \begin_inset LatexCommand \index{Options other}
9556 \labelwidthstring 00.00.0000
9564 \begin_layout Standard
9574 \begin_inset LatexCommand \index{-\/-compile-only}
9579 \begin_inset LatexCommand \index{-c -\/-compile-only}
9585 will compile and assemble the source, but will not call the linkage editor.
9589 \labelwidthstring 00.00.0000
9598 \begin_layout Standard
9610 \begin_inset LatexCommand \index{-\/-c1mode}
9616 reads the preprocessed source from standard input and compiles it.
9617 The file name for the assembler output must be specified using the -o option.
9621 \labelwidthstring 00.00.0000
9625 \begin_inset LatexCommand \index{-E}
9631 Run only the C preprocessor.
9632 Preprocess all the C source files specified and output the results to standard
9637 \labelwidthstring 00.00.0000
9642 \begin_inset LatexCommand \index{-o <path/file>}
9648 The output path where everything will be placed or the file name used for
9649 all generated output files.
9650 If the parameter is a path, it must have a trailing slash (or backslash
9651 for the Windows binaries) to be recognized as a path.
9656 Note for Windows users: if the path contains spaces, it should be surrounded
9658 The trailing backslash should be doubled in order to prevent escaping the
9659 final quote, for example:
9662 \begin_inset Quotes sld
9676 \begin_inset Quotes srd
9681 or put after the final quote, for example:
9684 \begin_inset Quotes sld
9694 \begin_inset Quotes srd
9702 The path using slashes for directory delimiters can be used too, for example:
9706 \begin_inset Quotes sld
9709 F:/Projects/test3/output 1/
9710 \begin_inset Quotes srd
9719 \labelwidthstring 00.00.0000
9726 \begin_layout Standard
9736 \begin_inset LatexCommand \index{-\/-stack-auto}
9747 All functions in the source file will be compiled as
9752 \begin_inset LatexCommand \index{reentrant}
9757 the parameters and local variables will be allocated on the stack
9758 \begin_inset LatexCommand \index{stack}
9764 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9768 Parameters and Local Variables for more details.
9769 If this option is used all source files in the project should be compiled
9771 It automatically implies -
9777 \begin_layout Standard
9788 -int-long-reent and -
9794 \begin_layout Standard
9810 \labelwidthstring 00.00.0000
9817 \begin_layout Standard
9827 \begin_inset LatexCommand \index{-\/-callee-saves}
9832 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9836 function1[,function2][,function3]....
9839 The compiler by default uses a caller saves convention for register saving
9840 across function calls, however this can cause unnecessary register pushing
9841 and popping when calling small functions from larger functions.
9842 This option can be used to switch the register saving convention for the
9843 function names specified.
9844 The compiler will not save registers when calling these functions, no extra
9845 code will be generated at the entry and exit (function prologue
9848 \begin_inset LatexCommand \index{function prologue}
9857 \begin_inset LatexCommand \index{function epilogue}
9863 ) for these functions to save and restore the registers used by these functions,
9864 this can SUBSTANTIALLY reduce code and improve run time performance of
9866 In the future the compiler (with inter procedural analysis) will be able
9867 to determine the appropriate scheme to use for each function call.
9868 DO NOT use this option for built-in functions such as _mulint..., if this
9869 option is used for a library function the appropriate library function
9870 needs to be recompiled with the same option.
9871 If the project consists of multiple source files then all the source file
9872 should be compiled with the same -
9876 \begin_layout Standard
9885 -callee-saves option string.
9886 Also see #pragma\InsetSpace ~
9888 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9893 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9901 \labelwidthstring 00.00.0000
9908 \begin_layout Standard
9918 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9932 \begin_layout Standard
9941 -callee-saves will be applied to all functions by default.
9945 \labelwidthstring 00.00.0000
9952 \begin_layout Standard
9962 \begin_inset LatexCommand \index{-\/-debug}
9971 When this option is used the compiler will generate debug information.
9972 The debug information collected in a file with .cdb extension can be used
9974 For more information see documentation for SDCDB.
9975 Another file with no extension contains debug information in AOMF or AOMF51
9976 \begin_inset LatexCommand \index{AOMF, AOMF51}
9980 format which is commonly used by third party tools.
9984 \labelwidthstring 00.00.0000
9988 \begin_inset LatexCommand \index{-S}
9999 Stop after the stage of compilation proper; do not assemble.
10000 The output is an assembler code file for the input file specified.
10004 \labelwidthstring 00.00.0000
10011 \begin_layout Standard
10021 \begin_inset LatexCommand \index{-\/-int-long-reent}
10027 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
10028 Note by default these libraries are compiled as non-reentrant.
10029 See section Installation for more details.
10033 \labelwidthstring 00.00.0000
10040 \begin_layout Standard
10050 \begin_inset LatexCommand \index{-\/-cyclomatic}
10059 This option will cause the compiler to generate an information message for
10060 each function in the source file.
10061 The message contains some
10065 information about the function.
10066 The number of edges and nodes the compiler detected in the control flow
10067 graph of the function, and most importantly the
10069 cyclomatic complexity
10070 \begin_inset LatexCommand \index{Cyclomatic complexity}
10076 see section on Cyclomatic Complexity for more details.
10080 \labelwidthstring 00.00.0000
10087 \begin_layout Standard
10097 \begin_inset LatexCommand \index{-\/-float-reent}
10103 Floating point library is compiled as reentrant
10104 \begin_inset LatexCommand \index{reentrant}
10109 See section Installation for more details.
10113 \labelwidthstring 00.00.0000
10120 \begin_layout Standard
10130 \begin_inset LatexCommand \index{-\/-funsigned-char}
10136 The default signedness for every type is
10141 In some embedded environments the default signedness of
10150 To set the signess for characters to unsigned, use the option -
10156 \begin_layout Standard
10168 If this option is set and no signedness keyword (unsigned/signed) is given,
10169 a char will be signed.
10170 All other types are unaffected.
10174 \labelwidthstring 00.00.0000
10181 \begin_layout Standard
10191 \begin_inset LatexCommand \index{-\/-main-return}
10197 This option can be used if the code generated is called by a monitor program
10198 or if the main routine includes an endless loop.
10199 This option results in slightly smaller code and saves two bytes of stack
10201 The return from the 'main'
10202 \begin_inset LatexCommand \index{main return}
10206 function will return to the function calling main.
10207 The default setting is to lock up i.e.
10216 \labelwidthstring 00.00.0000
10223 \begin_layout Standard
10233 \begin_inset LatexCommand \index{-\/-nostdinc}
10239 This will prevent the compiler from passing on the default include path
10240 to the preprocessor.
10244 \labelwidthstring 00.00.0000
10251 \begin_layout Standard
10261 \begin_inset LatexCommand \index{-\/-nostdlib}
10267 This will prevent the compiler from passing on the default library
10268 \begin_inset LatexCommand \index{Libraries}
10272 path to the linker.
10276 \labelwidthstring 00.00.0000
10283 \begin_layout Standard
10293 \begin_inset LatexCommand \index{-\/-verbose}
10299 Shows the various actions the compiler is performing.
10303 \labelwidthstring 00.00.0000
10307 \begin_inset LatexCommand \index{-V}
10313 Shows the actual commands the compiler is executing.
10317 \labelwidthstring 00.00.0000
10324 \begin_layout Standard
10334 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
10340 Hides your ugly and inefficient c-code from the asm file, so you can always
10341 blame the compiler :)
10345 \labelwidthstring 00.00.0000
10352 \begin_layout Standard
10362 \begin_inset LatexCommand \index{-\/-no-gen-comments}
10368 Include code generator and peep-hole comments in the generated asm files.
10372 \labelwidthstring 00.00.0000
10379 \begin_layout Standard
10389 \begin_inset LatexCommand \index{-\/-no-peep-comments}
10395 Don't include peep-hole comments in the generated asm files even if -
10401 \begin_layout Standard
10412 -fverbose-asm option is specified.
10416 \labelwidthstring 00.00.0000
10423 \begin_layout Standard
10433 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10439 Include i-codes in the asm file.
10440 Sounds like noise but is most helpful for debugging the compiler itself.
10444 \labelwidthstring 00.00.0000
10451 \begin_layout Standard
10461 \begin_inset LatexCommand \index{pedantic}
10466 \begin_inset LatexCommand \index{-\/-less-pedantic}
10473 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10477 Disable some of the more pedantic warnings
10478 \begin_inset LatexCommand \index{Warnings}
10483 For more details, see the less_pedantic pragma
10484 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10492 \labelwidthstring 00.00.0000
10499 \begin_layout Standard
10508 -disable-warning\InsetSpace ~
10510 \begin_inset LatexCommand \index{-\/-disable-warning}
10516 Disable specific warning with number <nnnn>.
10520 \labelwidthstring 00.00.0000
10527 \begin_layout Standard
10537 \begin_inset LatexCommand \index{-\/-Werror}
10543 Treat all warnings as errors.
10547 \labelwidthstring 00.00.0000
10554 \begin_layout Standard
10564 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10570 Display the directories in the compiler's search path
10574 \labelwidthstring 00.00.0000
10581 \begin_layout Standard
10591 \begin_inset LatexCommand \index{-\/-vc}
10597 Display errors and warnings using MSVC style, so you can use SDCC with
10598 the visual studio IDE
10599 \begin_inset LatexCommand \index{IDE}
10604 With SDCC both offering a GCC-like (the default) and a MSVC-like
10605 \begin_inset LatexCommand \index{MSVC output style}
10609 output style, integration into most programming editors should be straightforwa
10614 \labelwidthstring 00.00.0000
10621 \begin_layout Standard
10631 \begin_inset LatexCommand \index{-\/-use-stdout}
10637 Send errors and warnings to stdout instead of stderr.
10641 \labelwidthstring 00.00.0000
10645 asmOption[,asmOption]
10648 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10653 Pass the asmOption to the assembler
10654 \begin_inset LatexCommand \index{Options assembler}
10659 \begin_inset LatexCommand \index{Assembler options}
10664 See file sdcc/as/doc/asxhtm.html for assembler options.cd
10668 \labelwidthstring 00.00.0000
10675 \begin_layout Standard
10685 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10691 Generally follow the C89 standard, but allow SDCC features that conflict
10692 with the standard (default).
10696 \labelwidthstring 00.00.0000
10703 \begin_layout Standard
10713 \begin_inset LatexCommand \index{-\/-std-c89}
10719 Follow the C89 standard and disable SDCC features that conflict with the
10724 \labelwidthstring 00.00.0000
10731 \begin_layout Standard
10741 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10747 Generally follow the C99 standard, but allow SDCC features that conflict
10748 with the standard (incomplete support).
10752 \labelwidthstring 00.00.0000
10759 \begin_layout Standard
10769 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10775 Follow the C99 standard and disable SDCC features that conflict with the
10776 standard (incomplete support).
10780 \labelwidthstring 00.00.0000
10787 \begin_layout Standard
10799 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10804 <Name> The name to be used for the code
10805 \begin_inset LatexCommand \index{code}
10809 segment, default CSEG.
10810 This is useful if you need to tell the compiler to put the code in a special
10811 segment so you can later on tell the linker to put this segment in a special
10813 Can be used for instance when using bank switching to put the code in a
10818 \labelwidthstring 00.00.0000
10825 \begin_layout Standard
10837 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10842 <Name> The name to be used for the const
10843 \begin_inset LatexCommand \index{const}
10847 segment, default CONST.
10848 This is useful if you need to tell the compiler to put the const data in
10849 a special segment so you can later on tell the linker to put this segment
10850 in a special place in memory.
10851 Can be used for instance when using bank switching to put the const data
10856 \labelwidthstring 00.00.0000
10863 \begin_layout Standard
10872 -fdollars-in-identifiers
10873 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10879 Permit '$' as an identifier character.
10883 \labelwidthstring 00.00.0000
10890 \begin_layout Standard
10902 \begin_inset LatexCommand \index{-\/-more-pedantic}
10907 \begin_inset LatexCommand \index{pedantic}
10917 a SDCC compiler option but if you want
10921 warnings you can use a separate tool dedicated to syntax checking like
10923 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10928 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10933 \begin_inset LatexCommand \url{http://www.splint.org}
10938 To make your source files parseable by splint you will have to include
10944 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10948 in your source file and add brackets around extended keywords (like
10951 \begin_inset Quotes sld
10964 \begin_inset Quotes srd
10972 \begin_inset Quotes sld
10975 __interrupt\InsetSpace ~
10977 \begin_inset Quotes srd
10985 Splint has an excellent on line manual at
10986 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10990 and it's capabilities go beyond pure syntax checking.
10991 You'll need to tell splint the location of SDCC's include files so a typical
10992 command line could look like this:
10996 splint\InsetSpace ~
10998 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
11004 \labelwidthstring 00.00.0000
11011 \begin_layout Standard
11023 \begin_inset LatexCommand \index{-\/-short-is-8bits}
11028 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
11032 Treat short as 8-bit (for backward compatibility with older versions of
11033 compiler - see section
11034 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
11041 \begin_layout Standard
11042 \begin_inset VSpace bigskip
11048 \begin_layout Subsection
11049 Intermediate Dump Options
11050 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
11055 \begin_inset LatexCommand \index{Options intermediate dump}
11060 \begin_inset LatexCommand \index{Intermediate dump options}
11067 \begin_layout Standard
11068 The following options are provided for the purpose of retargetting and debugging
11070 They provide a means to dump the intermediate code (iCode
11071 \begin_inset LatexCommand \index{iCode}
11075 ) generated by the compiler in human readable form at various stages of
11076 the compilation process.
11077 More on iCodes see chapter
11078 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
11083 \begin_inset Quotes srd
11086 The anatomy of the compiler
11087 \begin_inset Quotes srd
11094 \labelwidthstring 00.00.0000
11101 \begin_layout Standard
11111 \begin_inset LatexCommand \index{-\/-dumpraw}
11117 This option will cause the compiler to dump the intermediate code into
11120 <source filename>.dumpraw
11122 just after the intermediate code has been generated for a function, i.e.
11123 before any optimizations are done.
11125 \begin_inset LatexCommand \index{Basic blocks}
11129 at this stage ordered in the depth first number, so they may not be in
11130 sequence of execution.
11134 \labelwidthstring 00.00.0000
11141 \begin_layout Standard
11151 \begin_inset LatexCommand \index{-\/-dumpgcse}
11157 Will create a dump of iCodes, after global subexpression elimination
11158 \begin_inset LatexCommand \index{Global subexpression elimination}
11162 , into a file named
11164 <source filename>.dumpgcse.
11168 \labelwidthstring 00.00.0000
11175 \begin_layout Standard
11185 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
11191 Will create a dump of iCodes, after deadcode elimination
11192 \begin_inset LatexCommand \index{Dead-code elimination}
11196 , into a file named
11198 <source filename>.dumpdeadcode.
11202 \labelwidthstring 00.00.0000
11209 \begin_layout Standard
11219 \begin_inset LatexCommand \index{-\/-dumploop}
11228 Will create a dump of iCodes, after loop optimizations
11229 \begin_inset LatexCommand \index{Loop optimization}
11233 , into a file named
11235 <source filename>.dumploop.
11239 \labelwidthstring 00.00.0000
11246 \begin_layout Standard
11256 \begin_inset LatexCommand \index{-\/-dumprange}
11265 Will create a dump of iCodes, after live range analysis
11266 \begin_inset LatexCommand \index{Live range analysis}
11270 , into a file named
11272 <source filename>.dumprange.
11276 \labelwidthstring 00.00.0000
11283 \begin_layout Standard
11293 \begin_inset LatexCommand \index{-\/-dumlrange}
11299 Will dump the life ranges
11300 \begin_inset LatexCommand \index{Live range analysis}
11308 \labelwidthstring 00.00.0000
11315 \begin_layout Standard
11325 \begin_inset LatexCommand \index{-\/-dumpregassign}
11334 Will create a dump of iCodes, after register assignment
11335 \begin_inset LatexCommand \index{Register assignment}
11339 , into a file named
11341 <source filename>.dumprassgn.
11345 \labelwidthstring 00.00.0000
11352 \begin_layout Standard
11362 \begin_inset LatexCommand \index{-\/-dumplrange}
11368 Will create a dump of the live ranges of iTemp's
11372 \labelwidthstring 00.00.0000
11379 \begin_layout Standard
11389 \begin_inset LatexCommand \index{-\/-dumpall}
11400 Will cause all the above mentioned dumps to be created.
11403 \begin_layout Standard
11404 \begin_inset VSpace bigskip
11410 \begin_layout Subsection
11411 Redirecting output on Windows Shells
11414 \begin_layout Standard
11415 By default SDCC writes its error messages to
11416 \begin_inset Quotes sld
11420 \begin_inset Quotes srd
11424 To force all messages to
11425 \begin_inset Quotes sld
11429 \begin_inset Quotes srd
11441 \begin_layout Standard
11456 \begin_inset LatexCommand \index{-\/-use-stdout}
11461 Additionally, if you happen to have visual studio installed in your windows
11462 machine, you can use it to compile your sources using a custom build and
11469 \begin_layout Standard
11481 \begin_inset LatexCommand \index{-\/-vc}
11486 Something like this should work:
11505 \begin_layout Standard
11524 \begin_layout Standard
11536 -model-large -c $(InputPath)
11539 \begin_inset VSpace bigskip
11545 \begin_layout Section
11546 Environment variables
11547 \begin_inset LatexCommand \index{Environment variables}
11554 \begin_layout Standard
11555 SDCC recognizes the following environment variables:
11559 \labelwidthstring 00.00.0000
11563 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11569 SDCC installs a signal handler
11570 \begin_inset LatexCommand \index{signal handler}
11574 to be able to delete temporary files after an user break (^C) or an exception.
11575 If this environment variable is set, SDCC won't install the signal handler
11576 in order to be able to debug SDCC.
11580 \labelwidthstring 00.00.0000
11586 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11592 Path, where temporary files will be created.
11593 The order of the variables is the search order.
11594 In a standard *nix environment these variables are not set, and there's
11595 no need to set them.
11596 On Windows it's recommended to set one of them.
11600 \labelwidthstring 00.00.0000
11604 \begin_inset LatexCommand \index{SDCC\_HOME}
11611 \begin_inset LatexCommand \ref{sub:Install-paths}
11617 \begin_inset Quotes sld
11621 \begin_inset Quotes srd
11628 \labelwidthstring 00.00.0000
11632 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11639 \begin_inset LatexCommand \ref{sub:Search-Paths}
11645 \begin_inset Quotes sld
11649 \begin_inset Quotes srd
11656 \labelwidthstring 00.00.0000
11660 \begin_inset LatexCommand \index{SDCC\_LIB}
11667 \begin_inset LatexCommand \ref{sub:Search-Paths}
11673 \begin_inset Quotes sld
11677 \begin_inset Quotes srd
11683 \begin_layout Standard
11684 There are some more environment variables recognized by SDCC, but these
11685 are solely used for debugging purposes.
11686 They can change or disappear very quickly, and will never be documented.
11687 \begin_inset VSpace bigskip
11693 \begin_layout Section
11694 Storage Class Language Extensions
11697 \begin_layout Subsection
11698 MCS51/DS390 Storage Class
11699 \begin_inset LatexCommand \index{Storage class}
11703 Language Extensions
11706 \begin_layout Standard
11707 In addition to the ANSI storage classes SDCC allows the following MCS51
11708 specific storage classes:
11711 \begin_layout Subsubsection
11713 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11718 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11723 \begin_inset LatexCommand \index{near (storage class)}
11728 \begin_inset LatexCommand \index{\_\_near (storage class)}
11735 \begin_layout Standard
11740 storage class for the Small Memory model (
11748 or the more ANSI-C compliant forms
11756 can be used synonymously).
11757 Variables declared with this storage class will be allocated in the directly
11758 addressable portion of the internal RAM of a 8051, e.g.:
11761 \begin_layout Verse
11764 __data unsigned char test_data;
11767 \begin_layout Standard
11768 Writing 0x01 to this variable generates the assembly code:
11771 \begin_layout Verse
11774 75*00 01\InsetSpace ~
11782 \begin_layout Subsubsection
11784 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11789 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11794 \begin_inset LatexCommand \index{far (storage class)}
11799 \begin_inset LatexCommand \index{\_\_far (storage class)}
11806 \begin_layout Standard
11807 Variables declared with this storage class will be placed in the external
11813 storage class for the Large Memory model, e.g.:
11816 \begin_layout Verse
11819 __xdata unsigned char test_xdata;
11822 \begin_layout Standard
11823 Writing 0x01 to this variable generates the assembly code:
11826 \begin_layout Verse
11829 90s00r00\InsetSpace ~
11860 \begin_layout Subsubsection
11862 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11867 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11874 \begin_layout Standard
11875 Variables declared with this storage class will be allocated into the indirectly
11876 addressable portion of the internal ram of a 8051, e.g.:
11879 \begin_layout Verse
11882 __idata unsigned char test_idata;
11885 \begin_layout Standard
11886 Writing 0x01 to this variable generates the assembly code:
11889 \begin_layout Verse
11916 \begin_layout Standard
11917 Please note, the first 128 byte of idata physically access the same RAM
11918 as the data memory.
11919 The original 8051 had 128 byte idata memory, nowadays most devices have
11920 256 byte idata memory.
11922 \begin_inset LatexCommand \index{stack}
11926 is located in idata memory.
11929 \begin_layout Subsubsection
11931 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11936 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11943 \begin_layout Standard
11944 Paged xdata access is just as straightforward as using the other addressing
11946 It is typically located at the start of xdata and has a maximum size of
11948 The following example writes 0x01 to the pdata variable.
11949 Please note, pdata access physically accesses xdata memory.
11950 The high byte of the address is determined by port P2
11951 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11955 (or in case of some 8051 variants by a separate Special Function Register,
11957 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11966 storage class for the Medium Memory model, e.g.:
11969 \begin_layout Verse
11972 __pdata unsigned char test_pdata;
11975 \begin_layout Standard
11976 Writing 0x01 to this variable generates the assembly code:
11979 \begin_layout Verse
11988 mov r0,#_test_pdata
12010 \begin_layout Standard
12015 \begin_layout Standard
12025 \begin_inset LatexCommand \index{-\/-xstack}
12029 option is used the pdata memory area is followed by the xstack memory area
12030 and the sum of their sizes is limited to 256 bytes.
12033 \begin_layout Subsubsection
12035 \begin_inset LatexCommand \index{code}
12040 \begin_inset LatexCommand \index{\_\_code}
12047 \begin_layout Standard
12048 'Variables' declared with this storage class will be placed in the code
12052 \begin_layout Verse
12055 __code unsigned char test_code;
12058 \begin_layout Standard
12059 Read access to this variable generates the assembly code:
12062 \begin_layout Verse
12065 90s00r6F\InsetSpace ~
12068 mov dptr,#_test_code
12093 \begin_layout Standard
12098 indexed arrays of characters in code memory can be accessed efficiently:
12101 \begin_layout Verse
12104 __code char test_array[] = {'c','h','e','a','p'};
12107 \begin_layout Standard
12108 Read access to this array using an 8-bit unsigned index generates the assembly
12112 \begin_layout Verse
12124 \begin_layout Verse
12127 90s00r41\InsetSpace ~
12130 mov dptr,#_test_array
12133 \begin_layout Verse
12148 \begin_layout Subsubsection
12150 \begin_inset LatexCommand \index{bit}
12155 \begin_inset LatexCommand \index{\_\_bit}
12162 \begin_layout Standard
12163 This is a data-type and a storage class specifier.
12164 When a variable is declared as a bit, it is allocated into the bit addressable
12165 memory of 8051, e.g.:
12168 \begin_layout Verse
12174 \begin_layout Standard
12175 Writing 1 to this variable generates the assembly code:
12178 \begin_layout Verse
12192 \begin_layout Standard
12193 The bit addressable memory consists of 128 bits which are located from 0x20
12194 to 0x2f in data memory.
12197 Apart from this 8051 specific storage class most architectures support
12199 \begin_inset LatexCommand \index{bitfields}
12207 \begin_layout Standard
12208 Not really meant as examples, but nevertheless showing what bitfields are
12209 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12215 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12216 signed modifier are implemented as unsigned.
12219 \begin_layout Subsubsection
12221 \begin_inset LatexCommand \index{sfr}
12226 \begin_inset LatexCommand \index{\_\_sfr}
12231 \begin_inset LatexCommand \index{sfr16}
12236 \begin_inset LatexCommand \index{\_\_sfr16}
12241 \begin_inset LatexCommand \index{sfr32}
12246 \begin_inset LatexCommand \index{\_\_sfr32}
12251 \begin_inset LatexCommand \index{\_\_sbit}
12256 \begin_inset LatexCommand \index{sbit}
12263 \begin_layout Standard
12264 Like the bit keyword,
12266 sfr / sfr16 / sfr32 / sbit
12268 signify both a data-type and storage class, they are used to describe the
12289 variables of a 8051, eg:
12292 \begin_layout Verse
12296 \begin_inset LatexCommand \index{at}
12301 \begin_inset LatexCommand \index{\_\_at}
12305 (0x80) P0;\InsetSpace ~
12306 /* special function register P0 at location 0x80 */
12311 special function register combination for timer 0
12315 with the high byte at
12316 location 0x8C and the low byte at location 0x8A */
12318 __sfr16 __at (0x8C8A)
12324 \begin_inset LatexCommand \index{at}
12329 \begin_inset LatexCommand \index{\_\_at}
12333 (0xd7) CY;\InsetSpace ~
12335 \begin_inset LatexCommand \index{Flags}
12340 \begin_inset LatexCommand \index{Carry flag}
12347 \begin_layout Standard
12348 Special function registers which are located on an address dividable by
12349 8 are bit-addressable, an
12353 addresses a specific bit within these sfr.
12355 16 Bit and 32 bit special function
12356 register combinations which require a certain access order are better not
12366 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12367 this is not guaranteed.
12372 \begin_layout Standard
12373 Please note, if you use a header file which was written for another compiler
12374 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
12380 Specifically the syntax
12383 sfr P0 = 0x80;\InsetSpace ~
12390 by SDCC to an assignment of 0x80 to a variable called P0
12393 \begin_inset Marginal
12396 \begin_layout Standard
12408 Nevertheless it is possible to write header files
12409 \begin_inset LatexCommand \index{Header files}
12414 \begin_inset LatexCommand \index{Include files}
12418 which can be shared among different compilers (see section
12419 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
12427 \begin_layout Subsubsection
12429 \begin_inset LatexCommand \index{Pointer}
12433 to MCS51/DS390 specific memory spaces
12436 \begin_layout Standard
12437 SDCC allows (via language extensions) pointers to explicitly point to any
12438 of the memory spaces
12439 \begin_inset LatexCommand \index{Memory model}
12444 In addition to the explicit pointers, the compiler uses (by default) generic
12445 pointers which can be used to point to any of the memory spaces.
12450 declaration examples:
12453 \begin_layout Verse
12456 /* pointer physically in internal ram pointing to object in external ram
12459 __xdata unsigned char * __data p;
12463 /* pointer physically in external ram
12464 pointing to object in internal ram */
12466 __data unsigned char * __xdata p;
12471 pointer physically in code rom pointing to data in xdata space */
12474 unsigned char * __code p;
12478 /* pointer physically in code space pointing to
12479 data in code space */
12481 __code unsigned char * __code p;
12486 physically located in xdata space */
12488 unsigned char * __xdata p;
12493 pointer physically located in default memory space */
12500 the following is a function pointer
12501 \begin_inset LatexCommand \index{function pointer}
12505 physically located in data space */
12507 char (* __data fp)(void);
12510 \begin_layout Standard
12511 Well you get the idea.
12516 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
12529 The highest order byte of the
12533 pointers contains the data space information.
12534 Assembler support routines are called whenever data is stored or retrieved
12540 These are useful for developing reusable library
12541 \begin_inset LatexCommand \index{Libraries}
12546 Explicitly specifying the pointer
12547 \begin_inset LatexCommand \index{pointer}
12551 type will generate the most efficient code.
12554 \begin_layout Subsubsection
12555 Notes on MCS51 memory
12556 \begin_inset LatexCommand \index{MCS51 memory}
12563 \begin_layout Standard
12564 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12565 RAM memory which is structured as follows:
12569 - Bytes 00-1F - 32 bytes to hold
12570 up to 4 banks of the registers R0 to R7,
12572 - Bytes 20-2F - 16 bytes to hold
12574 \begin_inset LatexCommand \index{bit}
12580 - Bytes 30-7F - 80 bytes for general purpose use.
12585 \begin_layout Standard
12586 Additionally some members of the MCS51 family may have up to 128 bytes of
12587 additional, indirectly addressable, internal RAM memory (
12592 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12597 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12602 Furthermore, some chips may have some built in external memory (
12607 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12612 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12616 ) which should not be confused with the internal, directly addressable RAM
12622 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12627 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12632 Sometimes this built in
12636 memory has to be activated before using it (you can probably find this
12637 information on the datasheet of the microcontroller your are using, see
12639 \begin_inset LatexCommand \ref{sub:Startup-Code}
12647 \begin_layout Standard
12648 Normally SDCC will only use the first bank
12649 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12653 of registers (register bank 0), but it is possible to specify that other
12654 banks of registers (keyword
12661 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12666 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12672 ) should be used for example in interrupt
12673 \begin_inset LatexCommand \index{interrupt}
12678 \begin_inset LatexCommand \index{\_\_interrupt}
12683 By default, the compiler will place the stack after the last byte of allocated
12684 memory for variables.
12685 For example, if the first 2 banks of registers are used, and only four
12690 variables, it will position the base of the internal stack at address 20
12692 This implies that as the stack
12693 \begin_inset LatexCommand \index{stack}
12697 grows, it will use up the remaining register banks, and the 16 bytes used
12698 by the 128 bit variables, and 80 bytes for general purpose use.
12699 If any bit variables are used, the data variables will be placed in unused
12700 register banks and after the byte holding the last bit variable.
12701 For example, if register banks 0 and 1 are used, and there are 9 bit variables
12706 variables will be placed starting from address 0x10 to 0x20 and continue
12712 \begin_layout Standard
12722 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12726 to specify the start address of the
12734 \begin_layout Standard
12744 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12748 to specify the size of the total internal RAM (
12762 \begin_layout Standard
12763 By default the 8051 linker will place the stack after the last byte of (i)data
12769 \begin_layout Standard
12779 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12783 allows you to specify the start of the stack, i.e.
12784 you could start it after any data in the general purpose area.
12785 If your microcontroller has additional indirectly addressable internal
12790 ) you can place the stack on it.
12791 You may also need to use -
12795 \begin_layout Standard
12805 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12809 to set the start address of the external RAM (
12817 \begin_layout Standard
12827 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12831 to specify its size.
12832 Same goes for the code memory, using -
12836 \begin_layout Standard
12846 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12854 \begin_layout Standard
12864 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12869 If in doubt, don't specify any options and see if the resulting memory
12870 layout is appropriate, then you can adjust it.
12873 \begin_layout Standard
12874 The linker generates two files with memory allocation information.
12875 The first, with extension .map
12876 \begin_inset LatexCommand \index{<file>.map}
12880 shows all the variables and segments.
12881 The second with extension .mem
12882 \begin_inset LatexCommand \index{<file>.mem}
12886 shows the final memory layout.
12887 The linker will complain either if memory segments overlap, there is not
12888 enough memory, or there is not enough space for stack.
12889 If you get any linking warnings and/or errors related to stack or segments
12890 allocation, take a look at either the .map or .mem files to find out what
12892 The .mem file may even suggest a solution to the problem.
12893 \begin_inset VSpace bigskip
12899 \begin_layout Subsection
12900 Z80/Z180 Storage Class
12901 \begin_inset LatexCommand \index{Z80!Storage class}
12905 Language Extensions
12908 \begin_layout Subsubsection
12910 \begin_inset LatexCommand \index{sfr}
12915 \begin_inset LatexCommand \index{\_\_sfr}
12919 (in/out to 8-bit addresses)
12922 \begin_layout Standard
12924 \begin_inset LatexCommand \index{Z80}
12928 family has separate address spaces for memory and
12938 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12943 \begin_inset LatexCommand \index{Z80!I/O memory}
12948 \begin_inset LatexCommand \index{Z180!I/O memory}
12952 is accessed with special instructions, e.g.:
12955 \begin_layout Verse
12958 sfr at 0x78 IoPort;\InsetSpace ~
12960 /* define a var in I/O space at 78h called IoPort */
12964 \begin_layout Standard
12965 Writing 0x01 to this variable generates the assembly code:
12968 \begin_layout Verse
12988 \begin_layout Subsubsection
12990 \begin_inset LatexCommand \index{sfr}
12995 \begin_inset LatexCommand \index{\_\_sfr}
12999 (in/out to 16-bit addresses)
13002 \begin_layout Standard
13007 is used to support 16 bit addresses in I/O memory e.g.:
13010 \begin_layout Verse
13014 \begin_inset LatexCommand \index{at}
13019 \begin_inset LatexCommand \index{\_\_at}
13026 \begin_layout Standard
13027 Writing 0x01 to this variable generates the assembly code:
13030 \begin_layout Verse
13033 01 23 01\InsetSpace ~
13055 \begin_layout Subsubsection
13057 \begin_inset LatexCommand \index{sfr}
13062 \begin_inset LatexCommand \index{\_\_sfr}
13066 (in0/out0 to 8 bit addresses on Z180
13067 \begin_inset LatexCommand \index{Z180}
13072 \begin_inset LatexCommand \index{HD64180 (see Z180)}
13079 \begin_layout Standard
13080 The compiler option -
13084 \begin_layout Standard
13094 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
13098 =180 (80) and a compiler #pragma\InsetSpace ~
13100 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
13104 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
13114 If you include the file z180.h this will be set automatically.
13115 \begin_inset VSpace bigskip
13121 \begin_layout Subsection
13123 \begin_inset LatexCommand \index{HC08!Storage class}
13127 Language Extensions
13130 \begin_layout Subsubsection
13132 \begin_inset LatexCommand \index{data (hc08 storage class)}
13137 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
13144 \begin_layout Standard
13145 The data storage class declares a variable that resides in the first 256
13146 bytes of memory (the direct page).
13148 \begin_inset LatexCommand \index{HC08}
13152 is most efficient at accessing variables (especially pointers) stored here.
13155 \begin_layout Subsubsection
13157 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
13162 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
13169 \begin_layout Standard
13170 The xdata storage class declares a variable that can reside anywhere in
13172 This is the default if no storage class is specified.
13174 \begin_inset VSpace bigskip
13180 \begin_layout Section
13181 Absolute Addressing
13182 \begin_inset LatexCommand \index{Absolute addressing}
13189 \begin_layout Standard
13190 Data items can be assigned an absolute address with the
13193 \begin_inset LatexCommand \index{at}
13198 \begin_inset LatexCommand \index{\_\_at}
13204 keyword, in addition to a storage class, e.g.:
13207 \begin_layout Verse
13211 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13216 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
13221 \begin_inset LatexCommand \index{at}
13226 \begin_inset LatexCommand \index{\_\_at}
13230 0x7ffe unsigned int chksum;
13233 \begin_layout Standard
13234 or, better conforming to ISO/IEC 9899 C:
13237 \begin_layout Verse
13240 __xdata __at (0x7ffe) unsigned int chksum;
13243 \begin_layout Standard
13244 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
13245 of the external ram.
13250 reserve any space for variables declared in this way
13251 \begin_inset Marginal
13254 \begin_layout Standard
13263 (they are implemented with an equate in the assembler).
13264 Thus it is left to the programmer to make sure there are no overlaps with
13265 other variables that are declared without the absolute address.
13266 The assembler listing file (.lst
13267 \begin_inset LatexCommand \index{<file>.lst}
13271 ) and the linker output files (.rst
13272 \begin_inset LatexCommand \index{<file>.rst}
13277 \begin_inset LatexCommand \index{<file>.map}
13281 ) are good places to look for such overlaps.
13284 \begin_layout Standard
13285 If however you provide an initializer
13286 \begin_inset LatexCommand \index{Variable initialization}
13290 actual memory allocation will take place and overlaps will be detected
13295 \begin_layout Verse
13298 __code __at (0x7ff0) char Id[5] =
13299 \begin_inset Quotes sld
13303 \begin_inset Quotes srd
13309 \begin_layout Standard
13310 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
13314 \begin_layout Standard
13315 In case of memory mapped I/O devices the keyword
13319 has to be used to tell the compiler that accesses might not be removed:
13322 \begin_layout Verse
13326 \begin_inset LatexCommand \index{volatile}
13331 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13336 \begin_inset LatexCommand \index{at}
13340 (0x8000) unsigned char PORTA_8255;
13343 \begin_layout Standard
13344 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
13349 \begin_inset LatexCommand \index{Aligned array}
13356 starts at a block (256 byte) boundary
13357 \begin_inset LatexCommand \index{block boundary}
13362 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13368 Absolute addresses can be specified for variables in all
13369 storage classes, e.g.:
13372 \begin_layout Verse
13376 \begin_inset LatexCommand \index{bit}
13381 \begin_inset LatexCommand \index{at}
13388 \begin_layout Standard
13389 The above example will allocate the variable at offset 0x02 in the bit-addressab
13391 There is no real advantage to assigning absolute addresses to variables
13392 in this manner, unless you want strict control over all the variables allocated.
13393 One possible use would be to write hardware portable code.
13394 For example, if you have a routine that uses one or more of the microcontroller
13395 I/O pins, and such pins are different for two different hardwares, you
13396 can declare the I/O pins in your routine using:
13399 \begin_layout Verse
13403 \begin_inset LatexCommand \index{volatile}
13407 __bit MOSI;\InsetSpace ~
13411 /* master out, slave in */
13413 extern volatile __bit MISO;\InsetSpace ~
13420 extern volatile __bit MCLK;\InsetSpace ~
13429 Output of a byte on a 3-wire serial bus.
13434 If needed adapt polarity of clock,
13435 polarity of data and bit order
13440 unsigned char spi_io(unsigned char out_byte)
13465 MOSI = out_byte & 0x80;
13496 /* _asm nop _endasm; */\InsetSpace ~
13504 /* for slow peripherals */
13556 \begin_layout Standard
13557 Then, someplace in the code for the first hardware you would use
13560 \begin_layout Verse
13564 \begin_inset LatexCommand \index{at}
13569 \begin_inset LatexCommand \index{\_\_at}
13573 (0x80) MOSI;\InsetSpace ~
13577 /* I/O port 0, bit 0 */
13579 __bit __at (0x81) MISO;\InsetSpace ~
13586 __bit __at (0x82) MCLK;\InsetSpace ~
13590 /* I/O port 0, bit 2 */
13593 \begin_layout Standard
13594 Similarly, for the second hardware you would use
13597 \begin_layout Verse
13600 __bit __at (0x83) MOSI;\InsetSpace ~
13604 /* I/O port 0, bit 3 */
13606 __bit __at (0x91) MISO;\InsetSpace ~
13611 I/O port 1, bit 1 */
13614 \begin_inset LatexCommand \index{bit}
13618 __at (0x92) MCLK;\InsetSpace ~
13622 /* I/O port 1, bit 2 */
13625 \begin_layout Standard
13626 and you can use the same hardware dependent routine without changes, as
13627 for example in a library.
13628 This is somehow similar to sbit, but only one absolute address has to be
13629 specified in the whole project.
13630 \begin_inset VSpace bigskip
13636 \begin_layout Section
13638 \begin_inset LatexCommand \index{Parameters}
13643 \begin_inset LatexCommand \index{function parameter}
13648 \begin_inset LatexCommand \index{local variables}
13653 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13660 \begin_layout Standard
13661 Automatic (local) variables and parameters to functions can either be placed
13662 on the stack or in data-space.
13663 The default action of the compiler is to place these variables in the internal
13664 RAM (for small model) or external RAM (for medium or large model).
13665 This in fact makes them similar to
13668 \begin_inset LatexCommand \index{static}
13674 so by default functions are non-reentrant
13675 \begin_inset LatexCommand \index{reentrant}
13684 They can be placed on the stack
13685 \begin_inset LatexCommand \index{stack}
13695 \begin_layout Standard
13705 \begin_inset LatexCommand \index{-\/-stack-auto}
13713 #pragma\InsetSpace ~
13717 \begin_inset LatexCommand \index{\#pragma stackauto}
13724 \begin_inset LatexCommand \index{reentrant}
13730 keyword in the function declaration, e.g.:
13733 \begin_layout Verse
13736 unsigned char foo(char i) __reentrant
13750 \begin_layout Standard
13751 Since stack space on 8051 is limited, the
13761 \begin_layout Standard
13772 option should be used sparingly.
13773 Note that the reentrant keyword just means that the parameters & local
13774 variables will be allocated to the stack, it
13778 mean that the function is register bank
13779 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13788 \begin_inset LatexCommand \index{local variables}
13792 can be assigned storage classes and absolute
13793 \begin_inset LatexCommand \index{Absolute addressing}
13800 \begin_layout Verse
13803 unsigned char foo()
13811 __xdata unsigned char i;
13824 \begin_inset LatexCommand \index{at}
13828 (0x31) unsigned char j;
13840 \begin_layout Standard
13841 In the above example the variable
13845 will be allocated in the external ram,
13849 in bit addressable space and
13860 \begin_layout Standard
13871 or when a function is declared as
13875 this should only be done for static variables.
13878 \begin_layout Standard
13880 \begin_inset LatexCommand \index{function parameter}
13884 however are not allowed any storage class
13885 \begin_inset LatexCommand \index{Storage class}
13889 , (storage classes for parameters will be ignored), their allocation is
13890 governed by the memory model in use, and the reentrancy options.
13893 \begin_layout Standard
13894 It is however allowed to use bit parameters in reentrant functions and also
13895 non-static local bit variables are supported.
13896 Efficient use is limited to 8 semi-bitregisters in bit space.
13897 They are pushed and popped to stack
13898 \begin_inset LatexCommand \index{stack}
13902 as a single byte just like the normal registers.
13905 \begin_layout Section
13907 \begin_inset LatexCommand \label{sub:Overlaying}
13912 \begin_inset LatexCommand \index{Overlaying}
13919 \begin_layout Standard
13921 \begin_inset LatexCommand \index{reentrant}
13925 functions SDCC will try to reduce internal ram space usage by overlaying
13926 parameters and local variables of a function (if possible).
13927 Parameters and local variables
13928 \begin_inset LatexCommand \index{local variables}
13932 of a function will be allocated to an overlayable segment if the function
13935 no other function calls and the function is non-reentrant and the memory
13937 \begin_inset LatexCommand \index{Memory model}
13944 If an explicit storage class
13945 \begin_inset LatexCommand \index{Storage class}
13949 is specified for a local variable, it will NOT be overlayed.
13952 \begin_layout Standard
13953 Note that the compiler (not the linkage editor) makes the decision for overlayin
13955 Functions that are called from an interrupt service routine
13956 \begin_inset Marginal
13959 \begin_layout Standard
13967 should be preceded by a #pragma\InsetSpace ~
13969 \begin_inset LatexCommand \index{\#pragma nooverlay}
13973 if they are not reentrant.
13976 \begin_layout Standard
13977 Also note that the compiler does not do any processing of inline assembler
13978 code, so the compiler might incorrectly assign local variables and parameters
13979 of a function into the overlay segment if the inline assembler code calls
13980 other c-functions that might use the overlay.
13981 In that case the #pragma\InsetSpace ~
13982 nooverlay should be used.
13985 \begin_layout Standard
13986 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13988 \begin_inset LatexCommand \index{Multiplication}
13993 \begin_inset LatexCommand \index{Division}
13997 will NOT be overlayed since these are implemented using external functions,
14001 \begin_layout Verse
14007 \begin_inset LatexCommand \index{\#pragma nooverlay}
14013 void set_error(unsigned char errcd)
14030 some_isr () __interrupt
14031 \begin_inset LatexCommand \index{interrupt}
14061 \begin_layout Standard
14062 In the above example the parameter
14070 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
14072 not present, this could cause unpredictable runtime behavior when called
14073 from an interrupt service routine.
14074 The #pragma\InsetSpace ~
14075 nooverlay ensures that the parameters and local variables for
14076 the function are NOT overlayed.
14077 \begin_inset VSpace bigskip
14083 \begin_layout Section
14084 Interrupt Service Routines
14085 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
14092 \begin_layout Subsection
14093 General Information
14096 \begin_layout Standard
14109 outines to be coded in C, with some extended keywords.
14112 \begin_layout Verse
14115 void timer_isr (void) __interrupt (1) __using (1)
14129 \begin_layout Standard
14130 The optional number following the
14133 \begin_inset LatexCommand \index{interrupt}
14138 \begin_inset LatexCommand \index{\_\_interrupt}
14144 keyword is the interrupt number this routine will service.
14145 When present, the compiler will insert a call to this routine in the interrupt
14147 \begin_inset LatexCommand \index{interrupt vector table}
14151 for the interrupt number specified.
14152 If you have multiple source files in your project, interrupt service routines
14153 can be present in any of them, but a prototype of the isr MUST be present
14154 or included in the file that contains the function
14159 The optional (8051 specific) keyword
14162 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14167 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14173 can be used to tell the compiler to use the specified register bank when
14174 generating code for this function.
14177 Interrupt service routines open the door for some very interesting bugs:
14180 \begin_layout Subsubsection
14181 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
14185 Common interrupt pitfall: variable not declared
14190 \begin_layout Standard
14191 If an interrupt service routine changes variables which are accessed by
14192 other functions these variables have to be declared
14197 \begin_inset LatexCommand \index{volatile}
14203 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
14210 \begin_layout Subsubsection
14211 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
14215 Common interrupt pitfall:
14220 \begin_layout Standard
14221 If the access to these variables is not
14224 \begin_inset LatexCommand \index{atomic}
14231 the processor needs more than one instruction for the access and could
14232 be interrupted while accessing the variable) the interrupt must be disabled
14233 during the access to avoid inconsistent data.
14236 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
14237 and should be protected by disabling interrupts.
14238 You're not automatically on the safe side if you use 8 bit variables though.
14239 We need an example here: f.e.
14240 on the 8051 the harmless looking
14241 \begin_inset Quotes srd
14251 \begin_inset Quotes sld
14260 \begin_inset Quotes srd
14270 \begin_inset Quotes sld
14273 from within an interrupt routine might get lost if the interrupt occurs
14276 \begin_inset Quotes sld
14281 counter\InsetSpace ~
14286 \begin_inset Quotes srd
14289 is not atomic on the 8051 even if
14293 is located in data memory.
14295 Bugs like these are hard to reproduce and can
14296 cause a lot of trouble.
14300 \begin_layout Subsubsection
14301 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
14305 Common interrupt pitfall:
14310 \begin_layout Standard
14311 The return address and the registers used in the interrupt service routine
14312 are saved on the stack
14313 \begin_inset LatexCommand \index{stack}
14317 so there must be sufficient stack space.
14318 If there isn't variables or registers (or even the return address itself)
14325 \begin_inset LatexCommand \index{stack overflow}
14329 is most likely to happen if the interrupt occurs during the
14330 \begin_inset Quotes sld
14334 \begin_inset Quotes srd
14337 subroutine when the stack is already in use for f.e.
14338 many return addresses.
14341 \begin_layout Subsubsection
14342 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
14346 Common interrupt pitfall:
14348 use of non-reentrant functions
14351 \begin_layout Standard
14352 A special note here, int (16 bit) and long (32 bit) integer division
14353 \begin_inset LatexCommand \index{Division}
14358 \begin_inset LatexCommand \index{Multiplication}
14363 \begin_inset LatexCommand \index{Modulus}
14368 \begin_inset LatexCommand \index{Floating point support}
14372 operations are implemented using external support routines.
14373 If an interrupt service routine needs to do any of these operations then
14374 the support routines (as mentioned in a following section) will have to
14375 be recompiled using the
14381 \begin_layout Standard
14391 \begin_inset LatexCommand \index{-\/-stack-auto}
14397 option and the source file will need to be compiled using the
14403 \begin_layout Standard
14415 \begin_inset LatexCommand \index{-\/-int-long-reent}
14422 Note, the type promotion
14423 \begin_inset LatexCommand \index{type promotion}
14427 required by ANSI C can cause 16 bit routines to be used
14428 \begin_inset Marginal
14431 \begin_layout Standard
14440 without the programmer being aware of it.
14444 (unsigned char)(tail-1)
14446 within the if clause in section
14447 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
14454 \begin_layout Standard
14455 Calling other functions from an interrupt service routine is not recommended,
14456 avoid it if possible.
14457 Note that when some function is called from an interrupt service routine
14458 it should be preceded by a #pragma\InsetSpace ~
14460 \begin_inset LatexCommand \index{\#pragma nooverlay}
14464 if it is not reentrant.
14465 Furthermore nonreentrant functions should not be called from the main program
14466 while the interrupt service routine might be active.
14467 They also must not be called from low priority interrupt service routines
14468 while a high priority interrupt service routine might be active.
14469 You could use semaphores or make the function
14473 if all parameters are passed in registers.
14476 \begin_inset LatexCommand \ref{sub:Overlaying}
14481 about Overlaying and section
14482 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14487 about Functions using private register banks.
14488 \begin_inset VSpace bigskip
14494 \begin_layout Subsection
14495 MCS51/DS390 Interrupt Service Routines
14498 \begin_layout Standard
14500 \begin_inset LatexCommand \index{interrupt}
14504 numbers and the corresponding address & descriptions for the Standard 8051/8052
14506 SDCC will automatically adjust the
14507 \begin_inset LatexCommand \index{interrupt vector table}
14511 to the maximum interrupt number specified.
14516 \begin_layout Standard
14518 \begin_inset Tabular
14519 <lyxtabular version="3" rows="9" columns="3">
14521 <column alignment="center" valignment="top" leftline="true" width="0in">
14522 <column alignment="left" valignment="top" leftline="true" width="0in">
14523 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14524 <row topline="true" bottomline="true">
14525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14528 \begin_layout Standard
14534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14537 \begin_layout Standard
14543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14546 \begin_layout Standard
14553 <row topline="true">
14554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14557 \begin_layout Standard
14563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14566 \begin_layout Standard
14572 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14575 \begin_layout Standard
14582 <row topline="true">
14583 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14586 \begin_layout Standard
14592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14595 \begin_layout Standard
14601 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14604 \begin_layout Standard
14611 <row topline="true">
14612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14615 \begin_layout Standard
14621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14624 \begin_layout Standard
14630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14633 \begin_layout Standard
14640 <row topline="true">
14641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14644 \begin_layout Standard
14650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14653 \begin_layout Standard
14659 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14662 \begin_layout Standard
14669 <row topline="true">
14670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14673 \begin_layout Standard
14679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14682 \begin_layout Standard
14688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14691 \begin_layout Standard
14698 <row topline="true">
14699 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14702 \begin_layout Standard
14708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14711 \begin_layout Standard
14717 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14720 \begin_layout Standard
14727 <row topline="true">
14728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14731 \begin_layout Standard
14737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14740 \begin_layout Standard
14746 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14749 \begin_layout Standard
14756 <row topline="true" bottomline="true">
14757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14760 \begin_layout Standard
14766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14769 \begin_layout Standard
14775 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14778 \begin_layout Standard
14794 \begin_layout Standard
14795 If the interrupt service routine is defined without
14798 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14803 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14809 a register bank or with register bank 0 (
14813 0), the compiler will save the registers used by itself on the stack upon
14814 entry and restore them at exit, however if such an interrupt service routine
14815 calls another function then the entire register bank will be saved on the
14817 This scheme may be advantageous for small interrupt service routines which
14818 have low register usage.
14821 \begin_layout Standard
14822 If the interrupt service routine is defined to be using a specific register
14827 & psw are saved and restored, if such an interrupt service routine calls
14828 another function (using another register bank) then the entire register
14829 bank of the called function will be saved on the stack
14830 \begin_inset LatexCommand \index{stack}
14835 This scheme is recommended for larger interrupt service routines.
14836 \begin_inset VSpace bigskip
14842 \begin_layout Subsection
14844 \begin_inset LatexCommand \index{HC08}
14848 Interrupt Service Routines
14851 \begin_layout Standard
14852 Since the number of interrupts
14853 \begin_inset LatexCommand \index{HC08!interrupt}
14857 available is chip specific and the interrupt vector table always ends at
14858 the last byte of memory, the interrupt numbers corresponds to the interrupt
14859 vectors in reverse order of address.
14860 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14861 2 will use the interrupt vector at 0xfffa, and so on.
14862 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14863 this way; instead see section
14864 \begin_inset LatexCommand \ref{sub:Startup-Code}
14868 for details on customizing startup.
14869 \begin_inset VSpace bigskip
14875 \begin_layout Subsection
14876 Z80 Interrupt Service Routines
14879 \begin_layout Standard
14881 \begin_inset LatexCommand \index{Z80}
14885 uses several different methods for determining the correct interrupt
14886 \begin_inset LatexCommand \index{Z80!interrupt}
14890 vector depending on the hardware implementation.
14891 Therefore, SDCC ignores the optional interrupt number and does not attempt
14892 to generate an interrupt vector table.
14895 \begin_layout Standard
14896 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14897 instruction to return from the interrupt.
14898 To write an interrupt handler for the non-maskable interrupt, which needs
14899 a RETN instruction instead, add the
14906 \begin_layout Verse
14909 void nmi_isr (void) critical interrupt
14923 \begin_layout Standard
14924 However if you need to create a non-interruptable interrupt service routine
14925 you would also require the
14930 To distinguish between this and an nmi_isr you must provide an interrupt
14932 \begin_inset VSpace bigskip
14938 \begin_layout Section
14939 Enabling and Disabling Interrupts
14942 \begin_layout Subsection
14943 Critical Functions and Critical Statements
14946 \begin_layout Standard
14947 A special keyword may be associated with a block or a function declaring
14953 SDCC will generate code to disable all interrupts
14954 \begin_inset LatexCommand \index{interrupt}
14958 upon entry to a critical function and restore the interrupt enable to the
14959 previous state before returning.
14960 Nesting critical functions will need one additional byte on the stack
14961 \begin_inset LatexCommand \index{stack}
14968 \begin_layout Verse
14971 int foo () __critical
14972 \begin_inset LatexCommand \index{critical}
14977 \begin_inset LatexCommand \index{\_\_critical}
15002 \begin_layout Standard
15003 The critical attribute maybe used with other attributes like
15013 may also be used to disable interrupts more locally:
15016 \begin_layout Verse
15022 \begin_layout Standard
15023 More than one statement could have been included in the block.
15026 \begin_layout Subsection
15027 Enabling and Disabling Interrupts directly
15030 \begin_layout Standard
15032 \begin_inset LatexCommand \index{interrupt}
15036 can also be disabled and enabled directly (8051):
15039 \begin_layout Verse
15042 EA = 0;\InsetSpace ~
15068 \begin_layout Verse
15104 \begin_layout Verse
15107 EA = 1;\InsetSpace ~
15136 \begin_layout Verse
15175 \begin_layout Standard
15176 On other architectures which have seperate opcodes for enabling and disabling
15177 interrupts you might want to make use of defines with inline assembly
15178 \begin_inset LatexCommand \index{Assembler routines}
15183 \begin_inset LatexCommand \index{HC08!interrupt}
15190 \begin_layout Verse
15194 \begin_inset LatexCommand \index{\_asm}
15203 \begin_inset LatexCommand \index{\_endasm}
15210 \begin_layout Verse
15213 #define SEI _asm\InsetSpace ~
15220 \begin_layout Verse
15226 \begin_layout Standard
15227 Note: it is sometimes sufficient to disable only a specific interrupt source
15229 a timer or serial interrupt by manipulating an
15232 \begin_inset LatexCommand \index{interrupt mask}
15242 \begin_layout Standard
15243 Usually the time during which interrupts are disabled should be kept as
15245 This minimizes both
15250 \begin_inset LatexCommand \index{interrupt latency}
15254 (the time between the occurrence of the interrupt and the execution of
15255 the first code in the interrupt routine) and
15260 \begin_inset LatexCommand \index{interrupt jitter}
15264 (the difference between the shortest and the longest interrupt latency).
15265 These really are something different, f.e.
15266 a serial interrupt has to be served before its buffer overruns so it cares
15267 for the maximum interrupt latency, whereas it does not care about jitter.
15268 On a loudspeaker driven via a digital to analog converter which is fed
15269 by an interrupt a latency of a few milliseconds might be tolerable, whereas
15270 a much smaller jitter will be very audible.
15273 \begin_layout Standard
15274 You can reenable interrupts within an interrupt routine and on some architecture
15275 s you can make use of two (or more) levels of
15277 interrupt priorities
15280 \begin_inset LatexCommand \index{interrupt priority}
15285 On some architectures which don't support interrupt priorities these can
15286 be implemented by manipulating the interrupt mask and reenabling interrupts
15287 within the interrupt routine.
15288 Check there is sufficient space on the stack
15289 \begin_inset LatexCommand \index{stack}
15293 and don't add complexity unless you have to.
15297 \begin_layout Subsection
15299 \begin_inset LatexCommand \index{semaphore}
15303 locking (mcs51/ds390)
15306 \begin_layout Standard
15307 Some architectures (mcs51/ds390) have an atomic
15308 \begin_inset LatexCommand \index{atomic}
15321 These type of instructions are typically used in preemptive multitasking
15322 systems, where a routine f.e.
15323 claims the use of a data structure ('acquires a lock
15324 \begin_inset LatexCommand \index{lock}
15328 on it'), makes some modifications and then releases the lock when the data
15329 structure is consistent again.
15330 The instruction may also be used if interrupt and non-interrupt code have
15331 to compete for a resource.
15332 With the atomic bit test and clear instruction interrupts
15333 \begin_inset LatexCommand \index{interrupt}
15337 don't have to be disabled for the locking operation.
15341 \begin_layout Standard
15342 SDCC generates this instruction if the source follows this pattern:
15345 \begin_layout Verse
15349 \begin_inset LatexCommand \index{volatile}
15353 bit resource_is_free;
15357 if (resource_is_free)
15367 resource_is_free=0;
15380 resource_is_free=1;
15387 \begin_layout Standard
15388 Note, mcs51 and ds390 support only an atomic
15389 \begin_inset LatexCommand \index{atomic}
15397 instruction (as opposed to atomic bit test and
15402 \begin_layout Section
15403 Functions using private register banks
15404 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
15411 \begin_layout Standard
15412 Some architectures have support for quickly changing register sets.
15413 SDCC supports this feature with the
15416 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
15421 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
15427 attribute (which tells the compiler to use a register bank
15428 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
15432 other than the default bank zero).
15433 It should only be applied to
15436 \begin_inset LatexCommand \index{interrupt}
15442 functions (see footnote below).
15443 This will in most circumstances make the generated ISR code more efficient
15444 since it will not have to save registers on the stack.
15447 \begin_layout Standard
15452 attribute will have no effect on the generated code for a
15456 function (but may occasionally be useful anyway
15460 \begin_layout Standard
15461 possible exception: if a function is called ONLY from 'interrupt' functions
15462 using a particular bank, it can be declared with the same 'using' attribute
15463 as the calling 'interrupt' functions.
15464 For instance, if you have several ISRs using bank one, and all of them
15465 call memcpy(), it might make sense to create a specialized version of memcpy()
15466 'using 1', since this would prevent the ISR from having to save bank zero
15467 to the stack on entry and switch to bank zero before calling the function
15476 (pending: Note, nowadays the
15480 attribute has an effect on
15484 the generated code for a
15495 \begin_layout Standard
15500 function using a non-zero bank will assume that it can trash that register
15501 bank, and will not save it.
15502 Since high-priority interrupts
15503 \begin_inset LatexCommand \index{interrupts}
15508 \begin_inset LatexCommand \index{interrupt priority}
15512 can interrupt low-priority ones on the 8051 and friends, this means that
15513 if a high-priority ISR
15517 a particular bank occurs while processing a low-priority ISR
15521 the same bank, terrible and bad things can happen.
15522 To prevent this, no single register bank should be
15526 by both a high priority and a low priority ISR.
15527 This is probably most easily done by having all high priority ISRs use
15528 one bank and all low priority ISRs use another.
15529 If you have an ISR which can change priority at runtime, you're on your
15530 own: I suggest using the default bank zero and taking the small performance
15534 \begin_layout Standard
15535 It is most efficient if your ISR calls no other functions.
15536 If your ISR must call other functions, it is most efficient if those functions
15537 use the same bank as the ISR (see note 1 below); the next best is if the
15538 called functions use bank zero.
15539 It is very inefficient to call a function using a different, non-zero bank
15542 \begin_inset VSpace bigskip
15548 \begin_layout Section
15550 \begin_inset LatexCommand \label{sub:Startup-Code}
15555 \begin_inset LatexCommand \index{Startup code}
15562 \begin_layout Subsection
15563 MCS51/DS390 Startup Code
15566 \begin_layout Standard
15567 The compiler triggers the linker to link certain initialization modules
15568 from the runtime library
15569 \begin_inset LatexCommand \index{Runtime library}
15573 called crt<something>.
15574 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15575 GSINIT5) is not linked unless the -
15581 \begin_layout Standard
15592 -xstack option is used.
15593 These modules are highly entangled by the use of special segments/areas,
15594 but a common layout is shown below:
15597 \begin_layout Verse
15605 \begin_layout Verse
15629 ljmp __sdcc_gsinit_startup
15632 \begin_layout Verse
15640 \begin_layout Verse
15652 .area GSINIT0 (CODE)
15654 __sdcc_gsinit_startup::
15664 mov sp,#__start__stack - 1
15667 \begin_layout Verse
15675 \begin_layout Verse
15687 .area GSINIT1 (CODE)
15689 __sdcc_init_xstack::
15691 ; Need to initialize in GSINIT1 in
15692 case the user's __sdcc_external_startup uses the xstack.
15702 mov __XPAGE,#(__start__x
15713 mov _spx,#__start__xstack
15716 \begin_layout Verse
15724 \begin_layout Verse
15736 .area GSINIT2 (CODE)
15746 lcall __sdcc_external_startup
15766 jz __sdcc_init_data
15777 __sdcc_program_startup
15782 \begin_layout Verse
15790 \begin_layout Verse
15802 .area GSINIT3 (CODE)
15855 mov r2,#((l_XINIT+255) >> 8)
15886 __XPAGE,#(s_XISEG >> 8)
15888 00001$:\InsetSpace ~
15952 00002$:\InsetSpace ~
15979 \begin_layout Verse
15987 \begin_layout Verse
15999 .area GSINIT4 (CODE)
16001 __mcs51_genRAMCLEAR::
16023 00004$:\InsetSpace ~
16037 ; _mcs51_genRAMCLEAR() end
16040 \begin_layout Verse
16048 \begin_layout Verse
16060 .area GSINIT4 (CODE)
16062 __mcs51_genXRAMCLEAR::
16123 mov __XPAGE,#(s_PSEG >> 8)
16135 00005$:\InsetSpace ~
16210 mov r1,#((l_XSEG + 255) >> 8)
16232 00007$:\InsetSpace ~
16269 \begin_layout Verse
16277 \begin_layout Verse
16289 .area GSINIT5 (CODE)
16291 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
16294 ; and __mcs51_genRAMCLEAR modifies _spx.
16304 mov __XPAGE,#(__start__x
16315 mov _spx,#__start__xstack
16318 \begin_layout Verse
16323 (application modules)
16326 \begin_layout Verse
16338 .area GSINIT (CODE)
16341 \begin_layout Verse
16349 \begin_layout Verse
16361 .area GSFINAL (CODE)
16371 ljmp __sdcc_program_startup
16373 ;---------------------------------
16374 -----------------------
16378 ;--------------------------------------------------
16401 __sdcc_program_startup:
16414 return from main will lock up
16427 \begin_layout Standard
16428 One of these modules (crtstart.asm) contains a call to the C routine
16430 _sdcc_external_startup()
16431 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
16440 at the start of the CODE area.
16441 This routine is also in the runtime library
16442 \begin_inset LatexCommand \index{Runtime library}
16446 and returns 0 by default.
16447 If this routine returns a non-zero value, the static & global variable
16448 initialization will be skipped and the function main will be invoked.
16449 Otherwise static & global variables will be initialized before the function
16453 _sdcc_external_startup()
16455 routine to your program to override the default if you need to setup hardware
16456 or perform some other critical operation prior to static & global variable
16458 \begin_inset LatexCommand \index{Variable initialization}
16463 On some mcs51 variants xdata
16464 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
16468 memory has to be explicitly enabled before it can be accessed or if the
16470 \begin_inset LatexCommand \index{watchdog}
16474 needs to be disabled, this is the place to do it.
16475 The startup code clears all internal data memory, 256 bytes by default,
16476 but from 0 to n-1 if
16482 \begin_layout Standard
16492 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16499 (recommended for Chipcon CC1010).
16502 \begin_layout Standard
16503 See also the compiler options
16509 \begin_layout Standard
16525 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16535 \begin_layout Standard
16547 \begin_inset LatexCommand \index{-\/-main-return}
16552 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16556 about MCS51-variants.
16561 \begin_layout Standard
16562 While these initialization modules are meant as generic startup code there
16563 might be the need for customization.
16564 Let's assume the return value of
16566 _sdcc_external_startup()
16572 should not be checked (or
16574 _sdcc_external_startup()
16576 should not be called at all).
16577 The recommended way would be to copy
16583 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm}
16587 ) into the source directory, adapt it there, then assemble it with
16593 \begin_layout Standard
16594 \begin_inset Quotes sld
16598 \begin_inset Quotes srd
16601 are the assembler options used in
16602 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup }
16613 and when linking your project explicitely specify
16618 As a bonus a listing of the relocated object file
16625 \begin_layout Standard
16626 \begin_inset VSpace bigskip
16632 \begin_layout Subsection
16636 \begin_layout Standard
16638 \begin_inset LatexCommand \index{HC08}
16642 startup code follows the same scheme as the MCS51 startup code.
16643 \begin_inset VSpace bigskip
16649 \begin_layout Subsection
16653 \begin_layout Standard
16655 \begin_inset LatexCommand \index{Z80}
16659 the startup code is inserted by linking with crt0.o which is generated from
16660 sdcc/device/lib/z80/crt0.s.
16661 If you need a different startup code you can use the compiler option
16670 \begin_layout Standard
16685 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16689 and provide your own crt0.o.
16691 \begin_inset VSpace bigskip
16697 \begin_layout Section
16698 Inline Assembler Code
16699 \begin_inset LatexCommand \index{Assembler routines}
16706 \begin_layout Subsection
16707 A Step by Step Introduction
16708 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16715 \begin_layout Standard
16716 Starting from a small snippet of c-code this example shows for the MCS51
16717 how to use inline assembly, access variables, a function parameter and
16718 an array in xdata memory.
16719 The example uses an MCS51 here but is easily adapted for other architectures.
16720 This is a buffer routine which should be optimized:
16723 \begin_layout Verse
16727 unsigned char __far
16728 \begin_inset LatexCommand \index{far (storage class)}
16733 \begin_inset LatexCommand \index{\_\_far (storage class)}
16738 \begin_inset LatexCommand \index{at}
16743 \begin_inset LatexCommand \index{\_\_at}
16747 (0x7f00) buf[0x100];
16748 \begin_inset LatexCommand \index{Aligned array}
16754 unsigned char head, tail;\InsetSpace ~
16772 \begin_inset LatexCommand \index{interrupt}
16824 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16836 void to_buffer( unsigned char c )
16844 if( head != (unsigned char)(tail-1)
16851 \begin_inset LatexCommand \index{promotion to signed int}
16856 \begin_inset LatexCommand \index{type promotion}
16861 \begin_inset Marginal
16864 \begin_layout Standard
16883 buf[ head++ ] = c;\InsetSpace ~
16899 /* access to a 256 byte aligned array */
16904 \begin_layout Standard
16905 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16906 then a corresponding buffer.asm file is generated.
16907 We define a new function
16911 in file buffer.c in which we cut and paste the generated code, removing
16912 unwanted comments and some ':'.
16914 \begin_inset Quotes sld
16922 \begin_inset Quotes srd
16926 \begin_inset Quotes sld
16934 \begin_inset Quotes srd
16941 \begin_layout Standard
16942 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16943 and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16945 The latter is also used in the library functions.
16950 to the beginning and the end of the function body:
16953 \begin_layout Verse
16957 /* With a cut and paste from the .asm file, we have something to start with.
16963 function is not yet OK! (registers aren't saved) */
16965 void to_buffer_asm(
16975 \begin_inset LatexCommand \index{\_asm}
16980 \begin_inset LatexCommand \index{\_\_asm}
16994 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
17000 \begin_inset LatexCommand \index{promotion to signed int}
17005 \begin_inset LatexCommand \index{type promotion}
17058 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
17059 \begin_inset LatexCommand \index{Aligned array}
17125 \begin_inset LatexCommand \index{\_endasm}
17130 \begin_inset LatexCommand \index{\_\_endasm}
17139 \begin_layout Standard
17140 The new file buffer.c should compile with only one warning about the unreferenced
17141 function argument 'c'.
17142 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
17143 (1) and finally have:
17146 \begin_layout Verse
17150 unsigned char __far __at(0x7f00) buf[0x100];
17152 unsigned char head, tail;
17163 void to_buffer( unsigned char c )
17172 head != (unsigned char)(tail-1) )
17201 c; // to avoid warning: unreferenced function argument
17208 \begin_inset LatexCommand \index{\_asm}
17213 \begin_inset LatexCommand \index{\_\_asm}
17227 ; save used registers here.
17238 ; If we were still using r2,r3 we would have to push them here.
17241 ; if( head != (unsigned char)(tail-1) )
17285 could do an ANL a,#0x0f here to use a smaller buffer (see below)
17321 a,dpl \InsetSpace ~
17328 ; dpl holds lower byte of function argument
17340 dpl,_head \InsetSpace ~
17343 ; buf is 0x100 byte aligned so head can be used directly
17386 ; we could do an ANL _head,#0x0f here to use a
17387 smaller buffer (see above)
17399 ; restore used registers here
17406 \begin_inset LatexCommand \index{\_endasm}
17411 \begin_inset LatexCommand \index{\_\_endasm}
17422 \begin_layout Standard
17423 The inline assembler code can contain any valid code understood by the assembler
17424 , this includes any assembler directives and comment lines.
17425 The assembler does not like some characters like ':' or ''' in comments.
17426 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
17427 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
17432 \begin_inset LatexCommand \index{Assembler documentation}
17437 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
17445 \begin_layout Standard
17446 The compiler does not do any validation of the code within the
17449 \begin_inset LatexCommand \index{\_asm}
17454 \begin_inset LatexCommand \index{\_\_asm}
17462 \begin_inset LatexCommand \index{\_endasm}
17467 \begin_inset LatexCommand \index{\_\_endasm}
17476 Specifically it will not know which registers are used and thus register
17478 \begin_inset LatexCommand \index{push/pop}
17482 has to be done manually.
17486 \begin_layout Standard
17487 It is recommended that each assembly instruction (including labels) be placed
17488 in a separate line (as the example shows).
17493 \begin_layout Standard
17505 \begin_inset LatexCommand \index{-\/-peep-asm}
17511 command line option is used, the inline assembler code will be passed through
17512 the peephole optimizer
17513 \begin_inset LatexCommand \index{Peephole optimizer}
17518 There are only a few (if any) cases where this option makes sense, it might
17519 cause some unexpected changes in the inline assembler code.
17520 Please go through the peephole optimizer rules defined in file
17524 before using this option.
17527 \begin_layout Subsection
17529 \begin_inset LatexCommand \label{sub:Naked-Functions}
17534 \begin_inset LatexCommand \index{Naked functions}
17541 \begin_layout Standard
17542 A special keyword may be associated with a function declaring it as
17545 \begin_inset LatexCommand \index{\_naked}
17550 \begin_inset LatexCommand \index{\_\_naked}
17561 function modifier attribute prevents the compiler from generating prologue
17562 \begin_inset LatexCommand \index{function prologue}
17567 \begin_inset LatexCommand \index{function epilogue}
17571 code for that function.
17572 This means that the user is entirely responsible for such things as saving
17573 any registers that may need to be preserved, selecting the proper register
17574 bank, generating the
17578 instruction at the end, etc.
17579 Practically, this means that the contents of the function must be written
17580 in inline assembler.
17581 This is particularly useful for interrupt functions, which can have a large
17582 (and often unnecessary) prologue/epilogue.
17583 For example, compare the code generated by these two functions:
17586 \begin_layout Verse
17590 \begin_inset LatexCommand \index{volatile}
17594 data unsigned char counter;
17598 void simpleInterrupt(void) __interrupt
17599 \begin_inset LatexCommand \index{interrupt}
17604 \begin_inset LatexCommand \index{\_\_interrupt}
17622 void nakedInterrupt(void) __interrupt (2) __naked
17631 \begin_inset LatexCommand \index{\_asm}
17636 \begin_inset LatexCommand \index{\_\_asm}
17653 _counter ; does not change flags, no need to save psw
17666 include ret or reti in _naked function.
17673 \begin_inset LatexCommand \index{\_endasm}
17678 \begin_inset LatexCommand \index{\_\_endasm}
17687 \begin_layout Standard
17688 For an 8051 target, the generated simpleInterrupt looks like:
17691 \begin_layout Verse
17698 example, recent versions of SDCC generate
17704 code for simpleInterrupt() and nakedInterrupt()!
17845 \begin_layout Standard
17846 whereas nakedInterrupt looks like:
17849 \begin_layout Verse
17862 _counter ; does not change flags, no need to save psw
17881 MUST explicitly include ret or reti in _naked function
17884 \begin_layout Standard
17885 The related directive #pragma exclude
17886 \begin_inset LatexCommand \index{\#pragma exclude}
17890 allows a more fine grained control over pushing & popping
17891 \begin_inset LatexCommand \index{push/pop}
17898 \begin_layout Standard
17899 While there is nothing preventing you from writing C code inside a
17903 function, there are many ways to shoot yourself in the foot doing this,
17904 and it is recommended that you stick to inline assembler.
17907 \begin_layout Subsection
17908 Use of Labels within Inline Assembler
17911 \begin_layout Standard
17912 SDCC allows the use of in-line assembler with a few restrictions regarding
17914 All labels defined within inline assembler code have to be of the form
17919 where nnnnn is a number less than 100 (which implies a limit of utmost
17920 100 inline assembler labels
17931 \begin_layout Standard
17932 This is a slightly more stringent rule than absolutely necessary, but stays
17933 always on the safe side.
17934 Labels in the form of nnnnn$ are local labels in the assembler, locality
17935 of which is confined within two labels of the standard form.
17936 The compiler uses the same form for labels within a function (but starting
17937 from nnnnn=00100); and places always a standard label at the beginning
17938 of a function, thus limiting the locality of labels within the scope of
17940 So, if the inline assembler part would be embedded into C-code, an improperly
17941 placed non-local label in the assembler would break up the reference space
17942 for labels created by the compiler for the C-code, leading to an assembling
17946 \begin_layout Standard
17947 The numeric part of local labels does not need to have 5 digits (although
17948 this is the form of labels output by the compiler), any valid integer will
17950 Please refer to the assemblers documentation for further details.
17958 \begin_layout Verse
17962 \begin_inset LatexCommand \index{\_asm}
17967 \begin_inset LatexCommand \index{\_\_asm}
17997 \begin_inset LatexCommand \index{\_endasm}
18002 \begin_inset LatexCommand \index{\_\_endasm}
18009 \begin_layout Standard
18010 Inline assembler code cannot reference any C-labels, however it can reference
18012 \begin_inset LatexCommand \index{Labels}
18016 defined by the inline assembler, e.g.:
18019 \begin_layout Verse
18042 ; some assembler code
18063 /* some more c code */
18065 clabel:\InsetSpace ~
18067 /* inline assembler cannot reference this
18072 \begin_layout Standard
18077 is translated by the compiler into a local label, so the locality of labels
18078 within the function is not broken.
18095 0003$: ;label (can be referenced by inline assembler only)
18102 \begin_inset LatexCommand \index{\_endasm}
18107 \begin_inset LatexCommand \index{\_\_endasm}
18117 /* some more c code */
18122 \begin_layout Standard
18123 In other words inline assembly code can access labels defined in inline
18124 assembly within the scope of the function.
18125 The same goes the other way, i.e.
18126 labels defines in inline assembly can not be accessed by C statements.
18129 \begin_layout Section
18130 Interfacing with Assembler Code
18131 \begin_inset LatexCommand \index{Assembler routines}
18138 \begin_layout Subsection
18139 Global Registers used for Parameter Passing
18140 \begin_inset LatexCommand \index{Parameter passing}
18147 \begin_layout Standard
18148 The compiler always uses the global registers
18151 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18156 \begin_inset LatexCommand \index{DPTR}
18161 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
18170 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
18176 to pass the first (non-bit) parameter to a function, and also to pass the
18178 \begin_inset LatexCommand \index{return value}
18182 of function; according to the following scheme: one byte return value in
18187 , two byte value in
18196 three byte values (generic pointers) in
18208 , and four byte values in
18226 \begin_inset LatexCommand \index{generic pointer}
18230 contain type of accessed memory in
18251 \begin_inset Note Note
18254 \begin_layout Standard
18255 This might not be the case of certain memory models (medium???)
18263 \begin_layout Standard
18264 The second parameter onwards is either allocated on the stack (for reentrant
18269 \begin_layout Standard
18278 -stack-auto is used) or in data/xdata memory (depending on the memory model).
18281 \begin_layout Standard
18282 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
18283 space for reentrant functions or allocated directly in bit memory otherwise.
18286 \begin_layout Standard
18287 Functions (with two or more parameters or bit parameters) that are called
18288 through function pointers
18289 \begin_inset LatexCommand \index{function pointers}
18293 must therefor be reentrant so the compiler knows how to pass the parameters.
18296 \begin_layout Subsection
18300 \begin_layout Standard
18301 Unless the called function is declared as
18306 \begin_inset LatexCommand \index{naked}
18314 \begin_layout Standard
18324 \begin_inset LatexCommand \index{-\/-callee-saves}
18332 \begin_layout Standard
18341 -all-callee-saves command line option or the corresponding callee_saves
18342 pragma are used, the caller will save the registers (
18346 ) around the call, so the called function can destroy they content freely.
18349 \begin_layout Standard
18350 If the called function is not declared as
18354 , the caller will swap register banks around the call, if caller and callee
18355 use different register banks (having them defined by the
18363 \begin_layout Standard
18364 The called function can also use
18380 observing that they are used for parameter/return value passing.
18383 \begin_layout Subsection
18384 Assembler Routine (non-reentrant)
18387 \begin_layout Standard
18388 In the following example
18389 \begin_inset LatexCommand \index{reentrant}
18394 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
18398 the function c_func calls an assembler routine asm_func, which takes two
18400 \begin_inset LatexCommand \index{function parameter}
18407 \begin_layout Verse
18410 extern int asm_func(unsigned char, unsigned char);
18414 int c_func (unsigned char
18415 i, unsigned char j)
18423 return asm_func(i,j);
18437 return c_func(10,9);
18442 \begin_layout Standard
18443 The corresponding assembler function is:
18446 \begin_layout Verse
18449 .globl _asm_func_PARM_2
18551 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18568 \begin_layout Standard
18569 The parameter naming convention is _<function_name>_PARM_<n>, where n is
18570 the parameter number starting from 1, and counting from the left.
18571 The first parameter is passed in
18587 according to the description above.
18588 The variable name for the second parameter will be _<function_name>_PARM_2.
18593 ble the assembler routine with the following command:
18600 asx8051 -losg asmfunc.asm
18607 Then compile and link the assembler routine to the C source file with the
18615 sdcc cfunc.c asmfunc.rel
18618 \begin_layout Subsection
18619 Assembler Routine (reentrant)
18622 \begin_layout Standard
18624 \begin_inset LatexCommand \index{reentrant}
18629 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18633 the second parameter
18634 \begin_inset LatexCommand \index{function parameter}
18638 onwards will be passed on the stack, the parameters are pushed from right
18640 before the call the second leftmost parameter will be on the top of the
18641 stack (the leftmost parameter is passed in registers).
18642 Here is an example:
18645 \begin_layout Verse
18648 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18653 c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
18662 return asm_func(i,j,k);
18676 return c_func(10,9,8);
18681 \begin_layout Standard
18682 The corresponding (unoptimized) assembler routine is:
18685 \begin_layout Verse
18705 _bp,sp\InsetSpace ~
18711 ;stack contains: _bp, return
18712 address, second parameter, third parameter
18736 a,#0xfd\InsetSpace ~
18742 pointer to the second parameter
18766 a,#0xfc\InsetSpace ~
18772 to the rightmost parameter
18813 result (= sum of all three parameters)
18828 ;return value goes into dptr
18862 \begin_layout Standard
18863 The compiling and linking procedure remains the same, however note the extra
18864 entry & exit linkage required for the assembler code, _bp is the stack
18865 frame pointer and is used to compute the offset into the stack for parameters
18866 and local variables.
18867 \begin_inset VSpace bigskip
18873 \begin_layout Section
18875 \begin_inset LatexCommand \index{int (16 bit)}
18880 \begin_inset LatexCommand \index{long (32 bit)}
18887 \begin_layout Standard
18888 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18889 multiplication and modulus operations are implemented by support routines.
18890 These support routines are all developed in ANSI-C to facilitate porting
18891 to other MCUs, although some model specific assembler optimizations are
18893 The following files contain the described routines, all of them can be
18894 found in <installdir>/share/sdcc/lib.
18899 \begin_layout Standard
18901 \begin_inset Tabular
18902 <lyxtabular version="3" rows="11" columns="2">
18904 <column alignment="left" valignment="top" leftline="true" width="0">
18905 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18906 <row topline="true" bottomline="true">
18907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18910 \begin_layout Standard
18918 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18921 \begin_layout Standard
18930 <row topline="true">
18931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18934 \begin_layout Standard
18940 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18943 \begin_layout Standard
18944 16 bit multiplication
18950 <row topline="true">
18951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18954 \begin_layout Standard
18960 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18963 \begin_layout Standard
18964 signed 16 bit division (calls _divuint)
18970 <row topline="true">
18971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18974 \begin_layout Standard
18980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18983 \begin_layout Standard
18984 unsigned 16 bit division
18990 <row topline="true">
18991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18994 \begin_layout Standard
19000 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19003 \begin_layout Standard
19004 signed 16 bit modulus (calls _moduint)
19010 <row topline="true">
19011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19014 \begin_layout Standard
19020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19023 \begin_layout Standard
19024 unsigned 16 bit modulus
19030 <row topline="true">
19031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19034 \begin_layout Standard
19040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19043 \begin_layout Standard
19044 32 bit multiplication
19050 <row topline="true">
19051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19054 \begin_layout Standard
19060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19063 \begin_layout Standard
19064 signed 32 division (calls _divulong)
19070 <row topline="true">
19071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19074 \begin_layout Standard
19080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19083 \begin_layout Standard
19084 unsigned 32 division
19090 <row topline="true">
19091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19094 \begin_layout Standard
19100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19103 \begin_layout Standard
19104 signed 32 bit modulus (calls _modulong)
19110 <row topline="true" bottomline="true">
19111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19114 \begin_layout Standard
19120 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19123 \begin_layout Standard
19124 unsigned 32 bit modulus
19139 \begin_layout Standard
19140 Since they are compiled as
19145 \begin_inset LatexCommand \index{reentrant}
19150 \begin_inset LatexCommand \index{interrupt}
19154 service routines should not do any of the above operations.
19155 If this is unavoidable then the above routines will need to be compiled
19162 \begin_layout Standard
19172 \begin_inset LatexCommand \index{-\/-stack-auto}
19178 option, after which the source program will have to be compiled with
19184 \begin_layout Standard
19194 \begin_inset LatexCommand \index{-\/-int-long-reent}
19201 Notice that you don't have to call these routines directly.
19202 The compiler will use them automatically every time an integer operation
19206 \begin_layout Section
19207 Floating Point Support
19208 \begin_inset LatexCommand \index{Floating point support}
19215 \begin_layout Standard
19216 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
19217 The floating point support routines are derived from gcc's floatlib.c and
19218 consist of the following routines:
19223 \begin_layout Standard
19227 \begin_inset Tabular
19228 <lyxtabular version="3" rows="17" columns="2">
19230 <column alignment="left" valignment="top" leftline="true" width="0">
19231 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19232 <row topline="true" bottomline="true">
19233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19236 \begin_layout Standard
19251 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19254 \begin_layout Standard
19261 <row topline="true">
19262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19265 \begin_layout Standard
19280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19283 \begin_layout Standard
19293 add floating point numbers
19299 <row topline="true">
19300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19303 \begin_layout Standard
19318 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19321 \begin_layout Standard
19331 subtract floating point numbers
19337 <row topline="true">
19338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19341 \begin_layout Standard
19356 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19359 \begin_layout Standard
19369 divide floating point numbers
19375 <row topline="true">
19376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19379 \begin_layout Standard
19394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19397 \begin_layout Standard
19407 multiply floating point numbers
19413 <row topline="true">
19414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19417 \begin_layout Standard
19432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19435 \begin_layout Standard
19445 convert floating point to unsigned char
19451 <row topline="true">
19452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19455 \begin_layout Standard
19470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19473 \begin_layout Standard
19483 convert floating point to signed char
19489 <row topline="true">
19490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19493 \begin_layout Standard
19508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19511 \begin_layout Standard
19521 convert floating point to unsigned int
19527 <row topline="true">
19528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19531 \begin_layout Standard
19546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19549 \begin_layout Standard
19559 convert floating point to signed int
19565 <row topline="true">
19566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19569 \begin_layout Standard
19592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19595 \begin_layout Standard
19605 convert floating point to unsigned long
19611 <row topline="true">
19612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19615 \begin_layout Standard
19630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19633 \begin_layout Standard
19643 convert floating point to signed long
19649 <row topline="true">
19650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19653 \begin_layout Standard
19668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19671 \begin_layout Standard
19681 convert unsigned char to floating point
19687 <row topline="true">
19688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19691 \begin_layout Standard
19706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19709 \begin_layout Standard
19719 convert char to floating point number
19725 <row topline="true">
19726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19729 \begin_layout Standard
19744 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19747 \begin_layout Standard
19757 convert unsigned int to floating point
19763 <row topline="true">
19764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19767 \begin_layout Standard
19782 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19785 \begin_layout Standard
19795 convert int to floating point numbers
19801 <row topline="true">
19802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19805 \begin_layout Standard
19820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19823 \begin_layout Standard
19833 convert unsigned long to floating point number
19839 <row topline="true" bottomline="true">
19840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19843 \begin_layout Standard
19858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19861 \begin_layout Standard
19871 convert long to floating point number
19886 \begin_layout Standard
19887 These support routines are developed in ANSI-C so there is room for space
19888 and speed improvement
19892 \begin_layout Standard
19893 These floating point routines (
19897 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19904 Note if all these routines are used simultaneously the data space might
19906 For serious floating point usage the large model might be needed.
19907 Also notice that you don't have to call this routines directly.
19908 The compiler will use them automatically every time a floating point operation
19910 \begin_inset VSpace bigskip
19916 \begin_layout Section
19918 \begin_inset LatexCommand \index{Libraries}
19925 \begin_layout Standard
19928 <pending: this is messy and incomplete - a little more information is in
19929 sdcc/doc/libdoc.txt
19934 \begin_layout Subsection
19935 Compiler support routines (_gptrget, _mulint etc.)
19938 \begin_layout Subsection
19939 Stdclib functions (puts, printf, strcat etc.)
19942 \begin_layout Subsubsection
19946 \begin_layout Paragraph
19947 getchar(), putchar()
19950 \begin_layout Standard
19951 \begin_inset LatexCommand \index{<stdio.h>}
19955 As usual on embedded systems you have to provide your own
19958 \begin_inset LatexCommand \index{getchar()}
19967 \begin_inset LatexCommand \index{putchar()}
19974 SDCC does not know whether the system connects to a serial line with or
19975 without handshake, LCD, keyboard or other device.
19989 You'll find examples for serial routines f.e.
19990 in sdcc/device/lib.
19991 For the mcs51 this minimalistic polling
19995 routine might be a start:
19998 \begin_layout Verse
20001 void putchar (char c) {
20007 while (!TI)\InsetSpace ~
20010 /* assumes UART is initialized */
20038 \begin_layout Paragraph
20042 \begin_layout Standard
20046 \begin_inset LatexCommand \index{printf()}
20056 does not support float (except on ds390).
20057 To enable this recompile it with the option
20063 \begin_layout Standard
20073 \begin_inset LatexCommand \index{USE\_FLOATS}
20079 on the command line.
20086 \begin_layout Standard
20096 \begin_inset LatexCommand \index{-\/-model-large}
20102 for the mcs51 port, since this uses a lot of memory.
20105 \begin_layout Standard
20106 If you're short on code memory you might want to use
20109 \begin_inset LatexCommand \index{printf\_small()}
20124 For the mcs51 there additionally are assembly versions
20127 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
20133 (subset of printf using less than 270 bytes) and
20136 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
20145 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
20151 (floating-point aware version of printf_fast) which should fit the requirements
20152 of many embedded systems (printf_fast() can be customized by unsetting
20157 support long variables and field widths).
20158 Be sure to use only one of these printf options within a project.
20163 \begin_layout Standard
20164 Feature matrix of different
20171 \begin_layout Standard
20172 \begin_inset Tabular
20173 <lyxtabular version="3" rows="14" columns="7">
20174 <features islongtable="true">
20175 <column alignment="left" valignment="middle" leftline="true" width="14col%">
20176 <column alignment="center" valignment="top" leftline="true" width="0">
20177 <column alignment="center" valignment="top" leftline="true" width="12col%">
20178 <column alignment="center" valignment="top" leftline="true" width="10col%">
20179 <column alignment="center" valignment="top" leftline="true" width="0">
20180 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
20181 <column alignment="center" valignment="top" rightline="true" width="0">
20182 <row topline="true" bottomline="true" endhead="true">
20183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20186 \begin_layout Standard
20195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20198 \begin_layout Standard
20200 \begin_inset LatexCommand \index{printf}
20209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20212 \begin_layout Standard
20220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20223 \begin_layout Standard
20229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20232 \begin_layout Standard
20238 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20241 \begin_layout Standard
20247 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20250 \begin_layout Standard
20257 <row topline="true" endhead="true">
20258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20261 \begin_layout Standard
20267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20270 \begin_layout Standard
20278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20281 \begin_layout Standard
20289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20292 \begin_layout Standard
20300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20303 \begin_layout Standard
20311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20314 \begin_layout Standard
20322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20325 \begin_layout Standard
20334 <row topline="true" endhead="true">
20335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20338 \begin_layout Standard
20339 \begin_inset Quotes sld
20343 \begin_inset Quotes srd
20349 \begin_layout Standard
20355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20358 \begin_layout Standard
20364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20367 \begin_layout Standard
20373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20376 \begin_layout Standard
20382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20385 \begin_layout Standard
20391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20394 \begin_layout Standard
20400 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20403 \begin_layout Standard
20410 <row topline="true" endhead="true">
20411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20414 \begin_layout Standard
20418 \begin_layout Standard
20424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20427 \begin_layout Standard
20433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20436 \begin_layout Standard
20442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20445 \begin_layout Standard
20446 0.45k / 0.47k (+ _ltoa)
20451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20454 \begin_layout Standard
20460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20463 \begin_layout Standard
20469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20472 \begin_layout Standard
20479 <row topline="true">
20480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20483 \begin_layout Standard
20489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20492 \begin_layout Standard
20502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20505 \begin_layout Standard
20552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20555 \begin_layout Standard
20594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20597 \begin_layout Standard
20603 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20606 \begin_layout Standard
20612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20615 \begin_layout Standard
20622 <row topline="true">
20623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20626 \begin_layout Standard
20627 long (32 bit) support
20632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20635 \begin_layout Standard
20641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20644 \begin_layout Standard
20650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20653 \begin_layout Standard
20659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20662 \begin_layout Standard
20668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20671 \begin_layout Standard
20686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20689 \begin_layout Standard
20696 <row topline="true">
20697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20700 \begin_layout Standard
20701 byte arguments on stack
20706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20709 \begin_layout Standard
20715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20718 \begin_layout Standard
20724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20727 \begin_layout Standard
20733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20736 \begin_layout Standard
20742 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20745 \begin_layout Standard
20751 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20754 \begin_layout Standard
20761 <row topline="true">
20762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20765 \begin_layout Standard
20767 \begin_inset LatexCommand \index{Floating point support}
20776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20779 \begin_layout Standard
20785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20788 \begin_layout Standard
20794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20797 \begin_layout Standard
20803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20806 \begin_layout Standard
20812 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20815 \begin_layout Standard
20820 \begin_layout Standard
20821 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20831 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20834 \begin_layout Standard
20841 <row topline="true">
20842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20845 \begin_layout Standard
20846 float formats %e %g
20851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20854 \begin_layout Standard
20860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20863 \begin_layout Standard
20869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20872 \begin_layout Standard
20878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20881 \begin_layout Standard
20887 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20890 \begin_layout Standard
20896 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20899 \begin_layout Standard
20906 <row topline="true" bottomline="true">
20907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20910 \begin_layout Standard
20916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20919 \begin_layout Standard
20925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20928 \begin_layout Standard
20934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20937 \begin_layout Standard
20943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20946 \begin_layout Standard
20952 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20955 \begin_layout Standard
20961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20964 \begin_layout Standard
20971 <row bottomline="true">
20972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20975 \begin_layout Standard
20980 \begin_layout Standard
20981 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20985 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20993 \begin_layout Standard
20999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21002 \begin_layout Standard
21008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21011 \begin_layout Standard
21017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21020 \begin_layout Standard
21026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21029 \begin_layout Standard
21035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21038 \begin_layout Standard
21044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21047 \begin_layout Standard
21054 <row bottomline="true">
21055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21058 \begin_layout Standard
21063 \begin_layout Standard
21064 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
21073 \begin_layout Standard
21079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21082 \begin_layout Standard
21088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21091 \begin_layout Standard
21097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21100 \begin_layout Standard
21106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21109 \begin_layout Standard
21115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21118 \begin_layout Standard
21124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21127 \begin_layout Standard
21132 \begin_layout Standard
21133 printf_tiny integer speed is data dependent, worst case is 0.33 ms
21144 <row bottomline="true">
21145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21148 \begin_layout Standard
21153 \begin_layout Standard
21154 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
21163 \begin_layout Standard
21169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21172 \begin_layout Standard
21178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21181 \begin_layout Standard
21187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21190 \begin_layout Standard
21196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21199 \begin_layout Standard
21205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21208 \begin_layout Standard
21214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21217 \begin_layout Standard
21224 <row bottomline="true">
21225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21228 \begin_layout Standard
21233 \begin_layout Standard
21234 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
21243 \begin_layout Standard
21249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21252 \begin_layout Standard
21258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21261 \begin_layout Standard
21267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21270 \begin_layout Standard
21276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21279 \begin_layout Standard
21285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21288 \begin_layout Standard
21294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21297 \begin_layout Standard
21311 \begin_layout Subsubsection
21313 \begin_inset LatexCommand \index{malloc.h}
21320 \begin_layout Standard
21321 As of SDCC 2.6.2 you no longer need to call an initialization routine before
21322 using dynamic memory allocation
21323 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
21328 \begin_inset LatexCommand \index{heap (malloc)}
21332 space of 1024 bytes is provided for malloc to allocate memory from.
21333 If you need a different heap size you need to recompile _heap.c with the
21334 required size defined in HEAP_SIZE.
21335 It is recommended to make a copy of this file into your project directory
21336 and compile it there with:
21339 \begin_layout Verse
21342 sdcc -c _heap.c -D HEAD_SIZE=2048
21345 \begin_layout Standard
21346 And then link it with:
21349 \begin_layout Verse
21352 sdcc main.rel _heap.rel
21355 \begin_layout Subsection
21356 Math functions (sinf, powf, sqrtf etc.)
21359 \begin_layout Subsubsection
21363 \begin_layout Standard
21364 See definitions in file <math.h>.
21367 \begin_layout Subsection
21371 \begin_layout Standard
21373 \begin_inset LatexCommand \index{Libraries}
21377 included in SDCC should have a license at least as liberal as the GNU Lesser
21378 General Public License
21379 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
21390 \begin_layout Standard
21391 \begin_inset Note Note
21394 \begin_layout Standard
21395 license statements for the libraries are missing.
21396 sdcc/device/lib/ser_ir.c
21399 \begin_layout Standard
21401 come with a GPL (as opposed to LGPL) License - this will not be liberal
21402 enough for many embedded programmers.
21410 \begin_layout Standard
21411 If you have ported some library or want to share experience about some code
21413 falls into any of these categories Busses (I
21414 \begin_inset Formula $^{\textrm{2}}$
21417 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
21418 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
21419 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
21420 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
21425 would certainly like to hear about it.
21428 \begin_layout Standard
21429 Programmers coding for embedded systems are not especially famous for being
21430 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
21431 e these references are very valuable.
21432 Let's help to create a climate where information is shared.
21433 \begin_inset VSpace bigskip
21439 \begin_layout Section
21443 \begin_layout Subsection
21444 MCS51 Memory Models
21445 \begin_inset LatexCommand \index{Memory model}
21450 \begin_inset LatexCommand \index{MCS51 memory model}
21457 \begin_layout Subsubsection
21458 Small, Medium and Large
21461 \begin_layout Standard
21462 SDCC allows three memory models for MCS51 code,
21471 Modules compiled with different memory models should
21475 be combined together or the results would be unpredictable.
21476 The library routines supplied with the compiler are compiled as small,
21478 The compiled library modules are contained in separate directories as small,
21479 medium and large so that you can link to the appropriate set.
21482 \begin_layout Standard
21483 When the medium or large model is used all variables declared without a
21484 storage class will be allocated into the external ram, this includes all
21485 parameters and local variables (for non-reentrant
21486 \begin_inset LatexCommand \index{reentrant}
21491 When the small model is used variables without storage class are allocated
21492 in the internal ram.
21495 \begin_layout Standard
21496 Judicious usage of the processor specific storage classes
21497 \begin_inset LatexCommand \index{Storage class}
21501 and the 'reentrant' function type will yield much more efficient code,
21502 than using the large model.
21503 Several optimizations are disabled when the program is compiled using the
21504 large model, it is therefore recommended that the small model be used unless
21505 absolutely required.
21508 \begin_layout Subsubsection
21510 \begin_inset LatexCommand \label{sub:External-Stack}
21515 \begin_inset LatexCommand \index{stack}
21520 \begin_inset LatexCommand \index{External stack (mcs51)}
21527 \begin_layout Standard
21528 The external stack (-
21532 \begin_layout Standard
21542 \begin_inset LatexCommand \index{-\/-xstack}
21546 ) is located in pdata
21547 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
21551 memory (usually at the start of the external ram segment) and uses all
21552 unused space in pdata (max.
21558 \begin_layout Standard
21567 -xstack option is used to compile the program, the parameters and local
21569 \begin_inset LatexCommand \index{local variables}
21573 of all reentrant functions are allocated in this area.
21574 This option is provided for programs with large stack space requirements.
21575 When used with the -
21579 \begin_layout Standard
21589 \begin_inset LatexCommand \index{-\/-stack-auto}
21593 option, all parameters and local variables are allocated on the external
21594 stack (note: support libraries will need to be recompiled with the same
21596 There is a predefined target in the library makefile).
21599 \begin_layout Standard
21600 The compiler outputs the higher order address byte of the external ram segment
21602 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21607 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21611 ), therefore when using the External Stack option, this port
21615 be used by the application program.
21618 \begin_layout Subsection
21620 \begin_inset LatexCommand \index{Memory model}
21625 \begin_inset LatexCommand \index{DS390 memory model}
21632 \begin_layout Standard
21633 The only model supported is Flat 24
21634 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21639 This generates code for the 24 bit contiguous addressing mode of the Dallas
21641 In this mode, up to four meg of external RAM or code space can be directly
21643 See the data sheets at www.dalsemi.com for further information on this part.
21648 that the compiler does not generate any code to place the processor into
21649 24 bitmode (although
21653 in the ds390 libraries will do that for you).
21659 \begin_inset LatexCommand \index{Tinibios (DS390)}
21663 , the boot loader or similar code must ensure that the processor is in 24
21664 bit contiguous addressing mode before calling the SDCC startup code.
21675 \begin_layout Standard
21686 option, variables will by default be placed into the XDATA segment.
21691 Segments may be placed anywhere in the 4 meg address space using the usual
21696 \begin_layout Standard
21706 Note that if any segments are located above 64K, the -r flag must be passed
21707 to the linker to generate the proper segment relocations, and the Intel
21708 HEX output format must be used.
21709 The -r flag can be passed to the linker by using the option
21713 on the SDCC command line.
21714 However, currently the linker can not handle code segments > 64k.
21717 \begin_layout Section
21719 \begin_inset LatexCommand \label{sec:Pragmas}
21724 \begin_inset LatexCommand \index{Pragmas}
21731 \begin_layout Standard
21732 Pragmas are used to turn on and/or off certain compiler options.
21733 Some of them are closely related to corresponding command-line options
21735 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21741 Pragmas should be placed before and/or after a function, placing pragmas
21742 inside a function body could have unpredictable results.
21747 following #pragma directives:
21750 \begin_layout Itemize
21756 \begin_inset LatexCommand \index{\#pragma save}
21760 - this will save most current options to the save/restore stack.
21761 See #pragma\InsetSpace ~
21765 \begin_layout Itemize
21771 \begin_inset LatexCommand \index{\#pragma restore}
21775 - will restore saved options from the last save.
21776 saves & restores can be nested.
21777 SDCC uses a save/restore stack: save pushes current options to the stack,
21778 restore pulls current options from the stack.
21779 See #pragma\InsetSpace ~
21785 \begin_layout Itemize
21791 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21796 \begin_inset LatexCommand \index{function prologue}
21800 function1[,function2[,function3...]]
21801 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21805 - The compiler by default uses a caller saves convention for register saving
21806 across function calls, however this can cause unnecessary register pushing
21808 \begin_inset LatexCommand \index{push/pop}
21812 when calling small functions from larger functions.
21813 This option can be used to switch off the register saving convention for
21814 the function names specified.
21815 The compiler will not save registers when calling these functions, extra
21816 code need to be manually inserted at the entry and exit for these functions
21817 to save and restore the registers used by these functions, this can SUBSTANTIAL
21818 LY reduce code and improve run time performance of the generated code.
21819 In the future the compiler (with inter procedural analysis) may be able
21820 to determine the appropriate scheme to use for each function call.
21825 \begin_layout Standard
21834 -callee-saves command line option is used (see page
21835 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21839 ), the function names specified in #pragma\InsetSpace ~
21841 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21845 is appended to the list of functions specified in the command line.
21848 \begin_layout Itemize
21854 \begin_inset LatexCommand \index{\#pragma exclude}
21858 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21859 of pairs of push/pop
21860 \begin_inset LatexCommand \index{push/pop}
21869 \begin_inset LatexCommand \index{interrupt}
21882 The directive should be placed immediately before the ISR function definition
21883 and it affects ALL ISR functions following it.
21884 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21885 exclude\InsetSpace ~
21887 \begin_inset LatexCommand \index{\#pragma exclude}
21892 See also the related keyword _naked
21893 \begin_inset LatexCommand \index{\_naked}
21898 \begin_inset LatexCommand \index{\_\_naked}
21905 \begin_layout Itemize
21911 \begin_inset LatexCommand \index{pedantic}
21916 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21921 \begin_inset LatexCommand \label{ite:less_pedantic}
21925 - the compiler will not warn you anymore for obvious mistakes, you're on
21927 See also the command line option -
21931 \begin_layout Standard
21941 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21948 More specifically, the following warnings will be disabled:
21950 comparison is always [true/false] due to limited range of data type
21954 overflow in implicit constant conversion
21956 (158); [the (in)famous]
21958 conditional flow changed by optimizer: so said EVELYN the modified DOG
21962 function '[function name]' must return value
21967 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21968 level) are disabled, too, namely:
21971 \begin_inset Note Note
21974 \begin_layout Standard
21975 dunno what comes here - this warning appears to be unused altogether
21984 [left/right] shifting more than size of object changed to zero
21992 integer overflow in expression
21996 unmatched #pragma save and #pragma restore
22000 comparison of 'signed char' with 'unsigned char' requires promotion to int
22004 ISO C90 does not support flexible array members
22008 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
22012 \begin_inset Note Note
22015 \begin_layout Standard
22016 appears to be always blank - what was supposed to be here?
22025 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
22026 complexity [number]
22031 \begin_layout Itemize
22037 \begin_inset LatexCommand \index{\#pragma disable\_warning}
22041 - the compiler will not warn you anymore about warning number <nnnn>.
22044 \begin_layout Itemize
22050 \begin_inset LatexCommand \index{\#pragma nogcse}
22054 - will stop global common subexpression elimination.
22057 \begin_layout Itemize
22063 \begin_inset LatexCommand \index{\#pragma noinduction}
22067 - will stop loop induction optimizations.
22070 \begin_layout Itemize
22076 \begin_inset LatexCommand \index{\#pragma noinvariant}
22080 - will not do loop invariant optimizations.
22081 For more details see Loop Invariants in section
22082 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
22089 \begin_layout Itemize
22095 \begin_inset LatexCommand \index{\#pragma noiv}
22099 - Do not generate interrupt
22100 \begin_inset LatexCommand \index{interrupt}
22105 \begin_inset LatexCommand \index{interrupt vector table}
22109 entries for all ISR functions defined after the pragma.
22110 This is useful in cases where the interrupt vector table must be defined
22111 manually, or when there is a secondary, manually defined interrupt vector
22113 for the autovector feature of the Cypress EZ-USB FX2).
22114 More elegantly this can be achieved by obmitting the optional interrupt
22115 number after the interrupt keyword, see section
22116 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
22124 \begin_layout Itemize
22130 \begin_inset LatexCommand \index{\#pragma nojtbound}
22134 - will not generate code for boundary value checking, when switch statements
22135 are turned into jump-tables (dangerous).
22136 For more details see section
22137 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
22144 \begin_layout Itemize
22150 \begin_inset LatexCommand \index{\#pragma noloopreverse}
22154 - Will not do loop reversal optimization
22157 \begin_layout Itemize
22163 \begin_inset LatexCommand \index{\#pragma nooverlay}
22167 - the compiler will not overlay the parameters and local variables of a
22171 \begin_layout Itemize
22177 \begin_inset LatexCommand \index{\#pragma stackauto}
22185 \begin_layout Standard
22195 \begin_inset LatexCommand \index{-\/-stack-auto}
22200 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
22204 Parameters and Local Variables.
22207 \begin_layout Itemize
22213 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
22217 - The compiler will optimize code generation towards fast code, possibly
22218 at the expense of code size.
22219 Currently this has little effect.
22222 \begin_layout Itemize
22228 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
22232 - The compiler will optimize code generation towards compact code, possibly
22233 at the expense of code speed.
22234 Currently this has little effect.
22237 \begin_layout Itemize
22243 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
22247 - The compiler will attempt to generate code that is both compact and fast,
22248 as long as meeting one goal is not a detriment to the other (this is the
22253 \begin_layout Itemize
22259 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
22263 - Generally follow the C89 standard, but allow SDCC features that conflict
22264 with the standard (default).
22267 \begin_layout Itemize
22273 \begin_inset LatexCommand \index{\#pragma std\_c89}
22277 - Follow the C89 standard and disable SDCC features that conflict with the
22281 \begin_layout Itemize
22287 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
22291 - Generally follow the C99 standard, but allow SDCC features that conflict
22292 with the standard (incomplete support).
22295 \begin_layout Itemize
22301 \begin_inset LatexCommand \index{\#pragma std\_c99}
22305 - Follow the C99 standard and disable SDCC features that conflict with the
22306 standard (incomplete support).
22309 \begin_layout Itemize
22315 \begin_inset LatexCommand \index{\#pragma codeseg}
22319 - Use this name (max.
22320 8 characters) for the code segment.
22325 \begin_layout Standard
22337 \begin_layout Itemize
22343 \begin_inset LatexCommand \index{\#pragma constseg}
22347 - Use this name (max.
22348 8 characters) for the const segment.
22353 \begin_layout Standard
22365 \begin_layout Standard
22366 The preprocessor SDCPP
22367 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
22371 supports the following #pragma directives:
22374 \begin_layout Itemize
22377 pedantic_parse_number
22380 \begin_inset LatexCommand \index{pedantic}
22385 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22390 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
22394 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
22395 properly and the macro LO_B(3) gets expanded.
22401 \begin_layout Standard
22410 -pedantic-parse-number command line option
22411 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
22418 Below is an example on how to use this pragma.
22421 Note: this functionality is not in conformance with standard!
22424 \begin_layout Verse
22427 #pragma pedantic_parse_number +
22428 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22436 #define LO_B(x) ((x) & 0xff)
22440 unsigned char foo(void)
22447 unsigned char c=0xfe-LO_B(3)
22462 \begin_layout Itemize
22468 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22472 (+ | -) - switch _asm _endasm block preprocessing on / off.
22474 You use this prama to define multilines of assembly code.
22475 This will prevent the preprocessor from changing the formating required
22477 Below is an example on how to use this pragma.
22480 \begin_layout Verse
22483 #pragma preproc_asm -
22484 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22490 #define MYDELAY _asm
22495 nop ;my assembly comment...
22509 #pragma preproc_asm
22540 \begin_layout Itemize
22546 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22550 (+ | -) - Allow "naked" hash in macro definition, for example:
22554 #define DIR_LO(x) #(x & 0xff)
22559 Below is an example on how to use this pragma.
22562 \begin_layout Verse
22565 #pragma preproc_asm +
22567 #pragma sdcc_hash +
22568 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22583 mov R6_B3, #(x & 0xff)
22590 mov R7_B3, #((x >> 8) & 0xff)
22614 \begin_layout Standard
22615 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22616 ons which might cause the compiler to generate extra stack and/or data space
22617 to store compiler generated temporary variables.
22618 This usually happens in large functions.
22619 Pragma directives should be used as shown in the following example, they
22620 are used to control options and optimizations for a given function.
22624 \begin_layout Verse
22628 \begin_inset LatexCommand \index{\#pragma save}
22639 /* save the current settings */
22642 \begin_inset LatexCommand \index{\#pragma nogcse}
22651 /* turnoff global subexpression elimination */
22653 #pragma noinduction
22654 \begin_inset LatexCommand \index{\#pragma noinduction}
22658 /* turn off induction optimizations */
22681 \begin_inset LatexCommand \index{\#pragma restore}
22685 /* turn the optimizations back on */
22688 \begin_layout Standard
22689 The compiler will generate a warning message when extra space is allocated.
22690 It is strongly recommended that the save and restore pragmas be used when
22691 changing options for a function.
22700 \begin_layout Section
22701 Defines Created by the Compiler
22704 \begin_layout Standard
22705 The compiler creates the following #defines
22706 \begin_inset LatexCommand \index{\#defines}
22711 \begin_inset LatexCommand \index{Defines created by the compiler}
22720 \begin_layout Standard
22721 \begin_inset Tabular
22722 <lyxtabular version="3" rows="15" columns="2">
22724 <column alignment="left" valignment="top" leftline="true" width="3in">
22725 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22726 <row topline="true" bottomline="true">
22727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22730 \begin_layout Standard
22738 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22741 \begin_layout Standard
22750 <row topline="true">
22751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22754 \begin_layout Standard
22756 \begin_inset LatexCommand \index{SDCC}
22765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22768 \begin_layout Standard
22770 Since version 2.5.6 the version number as an int (ex.
22777 <row topline="true">
22778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22781 \begin_layout Standard
22783 \begin_inset LatexCommand \index{SDCC\_mcs51}
22788 \begin_inset LatexCommand \index{SDCC\_ds390}
22793 \begin_inset LatexCommand \index{SDCC\_z80}
22802 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22805 \begin_layout Standard
22806 depending on the model used (e.g.: -mds390)
22812 <row topline="true">
22813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22816 \begin_layout Standard
22818 \begin_inset LatexCommand \index{\_\_mcs51}
22823 \begin_inset LatexCommand \index{\_\_ds390}
22828 \begin_inset LatexCommand \index{\_\_hc08}
22833 \begin_inset LatexCommand \index{\_\_z80}
22842 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22845 \begin_layout Standard
22846 depending on the model used (e.g.
22853 <row topline="true">
22854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22857 \begin_layout Standard
22859 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22868 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22871 \begin_layout Standard
22878 \begin_layout Standard
22895 <row topline="true">
22896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22899 \begin_layout Standard
22901 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22913 \begin_layout Standard
22920 \begin_layout Standard
22937 <row topline="true">
22938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22941 \begin_layout Standard
22943 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22952 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22955 \begin_layout Standard
22962 \begin_layout Standard
22979 <row topline="true">
22980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22983 \begin_layout Standard
22985 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22994 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22997 \begin_layout Standard
23004 \begin_layout Standard
23021 <row topline="true">
23022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23025 \begin_layout Standard
23027 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
23036 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23039 \begin_layout Standard
23046 \begin_layout Standard
23063 <row topline="true">
23064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23067 \begin_layout Standard
23069 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
23078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23081 \begin_layout Standard
23092 <row topline="true">
23093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23096 \begin_layout Standard
23098 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23107 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23110 \begin_layout Standard
23121 <row topline="true">
23122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23125 \begin_layout Standard
23127 \begin_inset LatexCommand \index{SDCC\_REVISION}
23136 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23139 \begin_layout Standard
23141 SDCC svn revision number
23147 <row topline="true">
23148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23151 \begin_layout Standard
23152 SDCC_PARMS_IN_BANK1
23153 \begin_inset LatexCommand \index{SDCC\_PARMS\_IN\_BANK1}
23162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23165 \begin_layout Standard
23172 \begin_layout Standard
23189 <row topline="true">
23190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23193 \begin_layout Standard
23195 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23204 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23207 \begin_layout Standard
23214 \begin_layout Standard
23231 <row topline="true" bottomline="true">
23232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23235 \begin_layout Standard
23236 SDCC_INT_LONG_REENT
23237 \begin_inset LatexCommand \index{SDCC\_INT\_LONG\_REENT}
23246 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23249 \begin_layout Standard
23256 \begin_layout Standard
23280 \begin_layout Chapter
23281 Notes on supported Processors
23284 \begin_layout Section
23286 \begin_inset LatexCommand \label{sub:MCS51-variants}
23291 \begin_inset LatexCommand \index{MCS51 variants}
23298 \begin_layout Standard
23299 MCS51 processors are available from many vendors and come in many different
23301 While they might differ considerably in respect to Special Function Registers
23302 the core MCS51 is usually not modified or is kept compatible.
23306 \begin_layout Subsection
23307 pdata access by SFR
23310 \begin_layout Standard
23311 With the upcome of devices with internal xdata and flash memory devices
23313 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
23317 as dedicated I/O port is becoming more popular.
23318 Switching the high byte for pdata
23319 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
23323 access which was formerly done by port P2 is then achieved by a Special
23325 \begin_inset LatexCommand \index{sfr}
23330 In well-established MCS51 tradition the address of this
23334 is where the chip designers decided to put it.
23335 Needless to say that they didn't agree on a common name either.
23336 So that the startup code can correctly initialize xdata variables, you
23337 should define an sfr with the name _XPAGE
23340 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
23346 at the appropriate location if the default, port P2, is not used for this.
23350 \begin_layout Verse
23353 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
23357 \begin_layout Verse
23360 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
23365 \begin_layout Verse
23368 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
23372 \begin_layout Verse
23375 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23379 \begin_layout Verse
23382 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23386 \begin_layout Standard
23387 For more exotic implementations further customizations may be needed.
23389 \begin_inset LatexCommand \ref{sub:Startup-Code}
23393 for other possibilities.
23396 \begin_layout Subsection
23397 Other Features available by SFR
23400 \begin_layout Standard
23401 Some MCS51 variants offer features like Double DPTR
23402 \begin_inset LatexCommand \index{DPTR}
23406 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
23407 These are currently not used for the MCS51 port.
23408 If you absolutely need them you can fall back to inline assembly or submit
23410 \begin_inset VSpace bigskip
23416 \begin_layout Section
23420 \begin_layout Standard
23422 \begin_inset LatexCommand \index{DS80C400}
23427 \begin_inset LatexCommand \index{DS400}
23431 microcontroller has a rich set of peripherals.
23432 In its built-in ROM library it includes functions to access some of the
23433 features, among them is a TCP stack with IP4 and IP6 support.
23434 Library headers (currently in beta status) and other files are provided
23438 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
23444 \begin_inset VSpace bigskip
23450 \begin_layout Section
23451 The Z80 and gbz80 port
23454 \begin_layout Standard
23455 SDCC can target both the Zilog Z80
23456 \begin_inset LatexCommand \index{Z80}
23460 and the Nintendo Gameboy's Z80-like gbz80
23461 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
23466 The Z80 port is passed through the same
23469 \begin_inset LatexCommand \index{Regression test}
23476 \begin_inset LatexCommand \ref{sec:Quality-control}
23480 ) as the MCS51 and DS390 ports, so floating point support, support for long
23481 variables and bitfield support is fine.
23482 See mailing lists and forums about interrupt routines.
23485 \begin_layout Standard
23486 As always, the code is the authoritative reference - see z80/ralloc.c and
23489 \begin_inset LatexCommand \index{Z80!stack}
23493 frame is similar to that generated by the IAR Z80 compiler.
23494 IX is used as the base pointer, HL and IY are used as a temporary registers,
23495 and BC and DE are available for holding variables.
23497 \begin_inset LatexCommand \index{Z80!return value}
23501 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
23503 The gbz80 port use the same set of registers for the return values, but
23504 in a different order of significance: E (one byte), DE (two bytes), or
23506 \begin_inset VSpace bigskip
23512 \begin_layout Section
23516 \begin_layout Standard
23517 The port to the Freescale/Motorola HC08
23518 \begin_inset LatexCommand \index{HC08}
23522 family has been added in October 2003, and is still undergoing some basic
23524 The code generator is complete, but the register allocation is still quite
23526 Some of the SDCC's standard C library functions have embedded non-HC08
23527 inline assembly and so are not yet usable.
23530 \begin_layout Standard
23531 The HC08 port passes the regression test suite (see section
23532 \begin_inset LatexCommand \ref{sec:Quality-control}
23537 \begin_inset VSpace bigskip
23545 \begin_layout Section
23547 \begin_inset LatexCommand \index{PIC14}
23554 \begin_layout Standard
23555 The PIC14 port adds support for Microchip
23556 \begin_inset LatexCommand \index{Microchip}
23561 \begin_inset Formula $^{\text{TM}}$
23565 \begin_inset LatexCommand \index{PIC14}
23570 \begin_inset Formula $^{\text{TM}}$
23573 MCUs with 14 bit wide instructions.
23574 This port is not yet mature and still lacks many features.
23575 However, it can work for simple code.
23578 \begin_layout Standard
23579 Currently supported devices include:
23582 \begin_layout Standard
23583 12F: 629, 635, 675, 683
23586 \begin_layout Standard
23590 \begin_layout Standard
23594 \begin_layout Standard
23595 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
23598 \begin_layout Standard
23599 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
23603 \begin_layout Standard
23607 \begin_layout Standard
23608 16F: 627, 627a, 628, 628a, 630, 636, 639, 648a, 676, 684, 685, 687, 688,
23612 \begin_layout Standard
23613 16F: 716, 72, 73, 737, 74, 76, 767, 77, 777, 785
23616 \begin_layout Standard
23617 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
23621 \begin_layout Standard
23622 16F: 913, 914, 916, 917
23625 \begin_layout Standard
23626 An up-to-date list of currently supported devices can be obtained via
23628 sdcc -mpic14 -phelp foo.c
23630 (foo.c must exist...).
23633 \begin_layout Subsection
23635 \begin_inset LatexCommand \index{code page (pic14)}
23640 \begin_inset LatexCommand \index{Memory bank (pic14)}
23647 \begin_layout Standard
23648 The linker organizes allocation for the code page and RAM banks.
23649 It does not have intimate knowledge of the code flow.
23650 It will put all the code section of a single .asm file into a single code
23652 In order to make use of multiple code pages, separate asm files must be
23654 The compiler assigns all
23658 functions of a single .c file into the same code page.
23662 To get the best results,
23663 follow these guidelines:
23666 \begin_layout Enumerate
23667 Make local functions static, as non static functions require code page selection
23670 Due to the way sdcc handles functions, place called functions prior
23671 to calling functions in the file wherever possible: Otherwise sdcc will
23672 insert unneccessary pagesel directives around the call, believing that
23673 the called function is externally defined.
23676 \begin_layout Enumerate
23677 For devices that have multiple code pages it is more efficient to use the
23678 same number of files as pages: Use up to 4 separate .c files for the 16F877,
23679 but only 2 files for the 16F874.
23680 This way the linker can put the code for each file into different code
23681 pages and there will be less page selection overhead.
23684 \begin_layout Enumerate
23685 And as for any 8 bit micro (especially for PIC14 as they have a very simple
23686 instruction set), use `unsigned char' wherever possible instead of `int'.
23689 \begin_layout Subsection
23690 Adding New Devices to the Port
23693 \begin_layout Standard
23694 Adding support for a new 14
23698 \begin_layout Standard
23707 bit PIC MCU requires the following steps:
23710 \begin_layout Enumerate
23711 Create a new device description.
23713 Each device is described in two files: pic16f*.h
23715 These files primarily define SFRs, structs to access their bits, and symbolic
23716 configuration options.
23717 Both files can be generated from gputils' .inc files using the perl script
23720 support/scripts/inc2h.pl
23723 This file also contains further instructions on how to proceed.
23726 \begin_layout Enumerate
23727 Copy the .h file into SDCC's include path and either add the .c file to your
23728 project or copy it to
23730 device/lib/pic/libdev
23733 Afterwards, rebuild and install the libraries.
23736 \begin_layout Enumerate
23737 Edit pic14devices.txt in SDCC's include path (
23739 device/include/pic/
23741 in the source tree or
23743 /usr/local/share/sdcc/include/pic
23745 after installation).
23747 You need to add a device specification here to make
23748 the memory layout (code banks, RAM, aliased memory regions, ...) known to
23750 Probably you can copy and modify an existing entry.
23751 The file format is documented at the top of the file.
23754 \begin_layout Subsection
23758 \begin_layout Standard
23759 For the interrupt function, use the keyword `__interrupt'
23760 \begin_inset LatexCommand \index{PIC14!interrupt}
23764 with level number of 0 (PIC14 only has 1 interrupt so this number is only
23765 there to avoid a syntax error - it ought to be fixed).
23769 \begin_layout Verse
23772 void Intr(void) __interrupt 0
23778 T0IF = 0; /* Clear timer interrupt */
23783 \begin_layout Subsection
23784 Linking and Assembling
23787 \begin_layout Standard
23788 For assembling you can use either GPUTILS'
23789 \begin_inset LatexCommand \index{gputils (pic tools)}
23793 gpasm.exe or MPLAB's mpasmwin.exe.
23794 GPUTILS are available from
23795 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23800 For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
23801 If you use MPLAB and an interrupt function then the linker script file
23802 vectors section will need to be enlarged to link with mplink.
23813 \begin_layout Verse
23826 sdcc -V -mpic14 -p16f877 -c $<
23830 $(PRJ).hex: $(OBJS)
23840 gplink -m -s $(PRJ).lkr
23841 -o $(PRJ).hex $(OBJS) libsdcc.lib
23844 \begin_layout Standard
23852 \begin_layout Verse
23865 sdcc -S -V -mpic14 -p16f877 $<
23875 mpasmwin /q /o $*.asm
23879 $(PRJ).hex: $(OBJS)
23890 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
23893 \begin_layout Standard
23894 Please note that indentations within a
23898 have to be done with a tabulator character.
23901 \begin_layout Subsection
23902 Command-Line Options
23905 \begin_layout Standard
23906 Besides the switches common to all SDCC backends, the PIC14 port accepts
23907 the following options (for an updated list see sdcc -
23911 \begin_layout Standard
23923 \begin_layout Description
23928 \begin_layout Standard
23938 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
23942 emit debug info in assembly output
23945 \begin_layout Description
23950 \begin_layout Standard
23960 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
23964 disable (slightly faulty) optimization on pCode
23967 \begin_layout Description
23972 \begin_layout Standard
23982 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
23986 sets the lowest address of the argument passing stack (defaults to a suitably
23987 large shared databank to reduce BANKSEL overhead)
23990 \begin_layout Description
23995 \begin_layout Standard
24005 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
24009 sets the size if the argument passing stack (default: 16, minimum: 4)
24012 \begin_layout Subsection
24013 Environment Variables
24016 \begin_layout Standard
24017 The PIC14 port recognizes the following environment variables:
24020 \begin_layout Description
24021 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
24022 register (the ones called r0xNNNN) in a section of its own.
24023 By default (if this variable is unset), sdcc tries to cluster registers
24024 in sections in order to reduce the BANKSEL overhead when accessing them.
24027 \begin_layout Subsection
24031 \begin_layout Standard
24032 The PIC14 library currently only contains support routines required by the
24033 compiler to implement multiplication, division, and floating point support.
24034 No libc-like replacement is available at the moment, though many of the
24035 common sdcc library sources (in
24039 ) should also compile with the PIC14 port.
24042 \begin_layout Subsubsection
24043 error: missing definition for symbol ``__gptrget1''
24046 \begin_layout Standard
24047 The PIC14 port uses library routines to provide more complex operations
24048 like multiplication, division/modulus and (generic) pointer dereferencing.
24049 In order to add these routines to your project, you must link with PIC14's
24055 For single source file projects this is done automatically, more complex
24060 to the linker's arguments.
24061 Make sure you also add an include path for the library (using the -I switch
24065 \begin_layout Subsubsection
24066 Processor mismatch in file ``XXX''.
24069 \begin_layout Standard
24070 This warning can usually be ignored due to the very good compatibility amongst
24075 \begin_layout Standard
24085 \begin_inset LatexCommand \index{PIC14}
24092 \begin_layout Standard
24093 You might also consider recompiling the library for your specific device
24094 by changing the ARCH=p16f877 (default target) entry in
24096 device/lib/pic/Makefile.in
24100 device/lib/pic/Makefile
24102 to reflect your device.
24103 This might even improve performance for smaller devices as unneccesary
24104 BANKSELs might be removed.
24107 \begin_layout Subsection
24111 \begin_layout Subsubsection
24115 \begin_layout Standard
24116 Functions with variable argument lists (like printf) are not yet supported.
24117 Similarly, taking the argument of the first argument passed into a function
24118 does not work: It is currently passed in WREG and has no address...
24121 \begin_layout Subsubsection
24122 Regression tests fail
24125 \begin_layout Standard
24126 Though the small subset of regression tests in src/regression passes, SDCC
24127 regression test suite does not, indicating that there are still major bugs
24129 However, many smaller projects have successfully used SDCC in the past...
24132 \begin_layout Standard
24140 \begin_layout Section
24142 \begin_inset LatexCommand \index{PIC16}
24149 \begin_layout Standard
24150 The PIC16 port adds support for Microchip
24151 \begin_inset LatexCommand \index{Microchip}
24156 \begin_inset Formula $^{\text{TM}}$
24160 \begin_inset LatexCommand \index{PIC}
24165 \begin_inset Formula $^{\text{TM}}$
24168 MCUs with 16 bit wide instructions.
24169 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
24170 ; devices supported by the port include:
24173 \begin_layout Standard
24174 18F: 242, 248, 252, 258, 442, 448, 452, 458
24177 \begin_layout Standard
24181 \begin_layout Standard
24182 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 24j10, 2525, 2550, 25j10,
24186 \begin_layout Standard
24187 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 44j10, 4520, 4525, 4550,
24191 \begin_layout Standard
24192 18F: 6520, 6620, 6680, 6720
24195 \begin_layout Standard
24196 18F: 8520, 8620, 8680, 8720
24199 \begin_layout Subsection
24203 \begin_layout Standard
24204 PIC16 port supports the standard command line arguments as supposed, with
24205 the exception of certain cases that will be mentioned in the following
24209 \begin_layout Description
24214 \begin_layout Standard
24224 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
24232 \begin_layout Standard
24244 \begin_layout Description
24249 \begin_layout Standard
24258 -fommit-frame-pointer
24259 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
24263 Frame pointer will be omitted when the function uses no local variables.
24266 \begin_layout Subsection
24267 Port Specific Options
24268 \begin_inset LatexCommand \index{Options PIC16}
24275 \begin_layout Standard
24276 The port specific options appear after the global options in the sdcc -
24280 \begin_layout Standard
24292 \begin_layout Subsubsection
24293 Code Generation Options
24296 \begin_layout Standard
24297 These options influence the generated assembler code.
24300 \begin_layout Description
24305 \begin_layout Standard
24314 -pstack-model=[model] Used in conjuction with the command above.
24315 Defines the stack model to be used, valid stack models are:
24320 \labelwidthstring 00.00.0000
24325 Selects small stack model.
24326 8 bit stack and frame pointers.
24327 Supports 256 bytes stack size.
24331 \labelwidthstring 00.00.0000
24336 Selects large stack model.
24337 16 bit stack and frame pointers.
24338 Supports 65536 bytes stack size.
24342 \begin_layout Description
24347 \begin_layout Standard
24356 -pno-banksel Do not generate BANKSEL assembler directives.
24359 \begin_layout Description
24364 \begin_layout Standard
24373 -extended Enable extended instruction set/literal offset addressing mode.
24377 \begin_layout Subsubsection
24378 Optimization Options
24381 \begin_layout Description
24386 \begin_layout Standard
24395 -obanksel=n Set optimization level for inserting BANKSELs.
24402 \labelwidthstring 00.00.0000
24407 \labelwidthstring 00.00.0000
24408 1 checks previous used register and if it is the same then does not emit
24409 BANKSEL, accounts only for labels.
24413 \labelwidthstring 00.00.0000
24414 2 tries to check the location of (even different) symbols and removes BANKSELs
24415 if they are in the same bank.
24420 Important: There might be problems if the linker script has data sections
24421 across bank borders!
24425 \begin_layout Description
24430 \begin_layout Standard
24439 -denable-peeps Force the usage of peepholes.
24443 \begin_layout Description
24448 \begin_layout Standard
24457 -optimize-goto Try to use (conditional) BRA instead of GOTO.
24460 \begin_layout Description
24465 \begin_layout Standard
24474 -optimize-cmp Try to optimize some compares.
24477 \begin_layout Description
24482 \begin_layout Standard
24491 -optimize-df Analyze the dataflow of the generated code and improve it.
24494 \begin_layout Subsubsection
24498 \begin_layout Description
24503 \begin_layout Standard
24512 -asm= Sets the full path and name of an external assembler to call.
24515 \begin_layout Description
24520 \begin_layout Standard
24530 \begin_inset LatexCommand \index{PIC16!MPLAB}
24534 compatibility option.
24535 Currently only suppresses special gpasm directives.
24538 \begin_layout Subsubsection
24542 \begin_layout Description
24547 \begin_layout Standard
24556 -link= Sets the full path and name of an external linker to call.
24559 \begin_layout Description
24564 \begin_layout Standard
24573 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
24574 unitialized data variables with [kword].
24575 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
24578 \begin_layout Description
24583 \begin_layout Standard
24592 -ivt-loc=n Place the interrupt vector table at address
24597 Useful for bootloaders.
24600 \begin_layout Description
24605 \begin_layout Standard
24614 -nodefaultlibs Do not link default libraries when linking.
24617 \begin_layout Description
24622 \begin_layout Standard
24631 -use-crt= Use a custom run-time module instead of the defaults.
24634 \begin_layout Description
24639 \begin_layout Standard
24648 -no-crt Don't link the default run-time modules
24651 \begin_layout Subsubsection
24655 \begin_layout Standard
24656 Debugging options enable extra debugging information in the output files.
24659 \begin_layout Description
24664 \begin_layout Standard
24673 -debug-xtra Similar to -
24677 \begin_layout Standard
24687 \begin_inset LatexCommand \index{-\/-debug}
24691 , but dumps more information.
24694 \begin_layout Description
24699 \begin_layout Standard
24708 -debug-ralloc Force register allocator to dump <source>.d file with debugging
24710 <source> is the name of the file being compiled.
24713 \begin_layout Description
24718 \begin_layout Standard
24727 -pcode-verbose Enable pcode debugging information in translation.
24730 \begin_layout Description
24735 \begin_layout Standard
24744 -calltree Dump call tree in .calltree file.
24747 \begin_layout Description
24752 \begin_layout Standard
24761 -gstack Trace push/pops for stack pointer overflow.
24764 \begin_layout Subsection
24765 Enviroment Variables
24768 \begin_layout Standard
24769 There is a number of enviromental variables that can be used when running
24770 SDCC to enable certain optimizations or force a specific program behaviour.
24771 these variables are primarily for debugging purposes so they can be enabled/dis
24775 \begin_layout Standard
24776 Currently there is only two such variables available:
24779 \begin_layout Description
24780 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
24781 bitfields is optimized by directly loading FSR0 with the address of the
24782 bitfield structure.
24783 Normally SDCC will cast the bitfield structure to a bitfield pointer and
24785 This step saves data ram and code space for functions that make heavy use
24787 (i.e., 80 bytes of code space are saved when compiling malloc.c with this
24792 \begin_layout Description
24793 NO_REG_OPT Do not perform pCode registers optimization.
24794 This should be used for debugging purposes.
24795 If bugs in the pcode optimizer are found, users can benefit from temporarily
24796 disabling the optimizer until the bug is fixed.
24799 \begin_layout Subsection
24800 Preprocessor Macros
24803 \begin_layout Standard
24805 \begin_inset LatexCommand \index{PIC16}
24809 port defines the following preprocessor macros while translating a source.
24812 \begin_layout Standard
24814 \begin_inset Tabular
24815 <lyxtabular version="3" rows="6" columns="2">
24817 <column alignment="center" valignment="top" leftline="true" width="0">
24818 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24819 <row topline="true" bottomline="true">
24820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24823 \begin_layout Standard
24829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24832 \begin_layout Standard
24839 <row topline="true">
24840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24843 \begin_layout Standard
24849 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24852 \begin_layout Standard
24853 Port identification
24859 <row topline="true">
24860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24863 \begin_layout Standard
24868 \begin_layout Standard
24882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24885 \begin_layout Standard
24886 Port identification (same as above)
24892 <row topline="true">
24893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24896 \begin_layout Standard
24902 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24905 \begin_layout Standard
24906 MCU Identification.
24911 is the microcontrol identification number, i.e.
24918 <row topline="true">
24919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24922 \begin_layout Standard
24927 \begin_layout Standard
24941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24944 \begin_layout Standard
24945 MCU Identification (same as above)
24951 <row topline="true" bottomline="true">
24952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24955 \begin_layout Standard
24961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24964 \begin_layout Standard
24965 nnn = SMALL or LARGE respectively according to the stack model used
24978 \begin_layout Standard
24979 In addition the following macros are defined when calling assembler:
24982 \begin_layout Standard
24984 \begin_inset Tabular
24985 <lyxtabular version="3" rows="4" columns="2">
24987 <column alignment="center" valignment="top" leftline="true" width="0">
24988 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24989 <row topline="true" bottomline="true">
24990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24993 \begin_layout Standard
24999 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25002 \begin_layout Standard
25009 <row topline="true">
25010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25013 \begin_layout Standard
25019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25022 \begin_layout Standard
25023 MCU Identification.
25028 is the microcontrol identification number, i.e.
25035 <row topline="true">
25036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25039 \begin_layout Standard
25045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25048 \begin_layout Standard
25049 nnn = SMALL or LARGE respectively according to the memory model used for
25056 <row topline="true" bottomline="true">
25057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25060 \begin_layout Standard
25066 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25069 \begin_layout Standard
25070 nnn = SMALL or LARGE respectively according to the stack model used
25083 \begin_layout Subsection
25087 \begin_layout Standard
25089 \begin_inset LatexCommand \index{PIC16}
25093 port uses the following directories for searching header files and libraries.
25096 \begin_layout Standard
25098 \begin_inset Tabular
25099 <lyxtabular version="3" rows="3" columns="4">
25101 <column alignment="center" valignment="top" leftline="true" width="0">
25102 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25103 <column alignment="center" valignment="top" width="0">
25104 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25105 <row topline="true" bottomline="true">
25106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25109 \begin_layout Standard
25115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25118 \begin_layout Standard
25124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25127 \begin_layout Standard
25133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25136 \begin_layout Standard
25143 <row topline="true">
25144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25147 \begin_layout Standard
25148 PREFIX/sdcc/include/pic16
25153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25156 \begin_layout Standard
25157 PIC16 specific headers
25162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25165 \begin_layout Standard
25171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25174 \begin_layout Standard
25181 <row topline="true" bottomline="true">
25182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25185 \begin_layout Standard
25186 PREFIX/sdcc/lib/pic16
25191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25194 \begin_layout Standard
25195 PIC16 specific libraries
25200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25203 \begin_layout Standard
25209 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25212 \begin_layout Standard
25226 \begin_layout Subsection
25228 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
25235 \begin_layout Standard
25237 \begin_inset LatexCommand \index{PIC16}
25241 port currently supports the following pragmas:
25244 \begin_layout Description
25246 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
25250 This forces the code generator to initialize the stack & frame pointers
25251 at a specific address.
25252 This is an ad hoc solution for cases where no STACK directive is available
25253 in the linker script or gplink is not instructed to create a stack section.
25256 stack pragma should be used only once in a project.
25257 Multiple pragmas may result in indeterminate behaviour of the program.
25261 \begin_layout Standard
25262 The old format (ie.
25263 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
25264 cross page boundaries (or even exceed the available data RAM) and crash
25266 Make sure that stack does not cross page boundaries when using the SMALL
25274 The format is as follows:
25279 \begin_layout LyX-Code
25280 #pragma stack bottom_address [stack_size]
25285 \begin_layout Standard
25290 is the lower bound of the stack section.
25291 The stack pointer initially will point at address (bottom_address+stack_size-1).
25294 \begin_layout LyX-Code
25298 \begin_layout LyX-Code
25302 \begin_layout LyX-Code
25303 /* initializes stack of 100 bytes at RAM address 0x200 */
25306 \begin_layout LyX-Code
25307 #pragma stack 0x200 100
25310 \begin_layout Standard
25311 If the stack_size field is omitted then a stack is created with the default
25313 This size might be enough for most programs, but its not enough for operations
25314 with deep function nesting or excessive stack usage.
25317 \begin_layout Description
25319 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
25323 Force a function to a static FLASH address.
25326 \begin_layout LyX-Code
25330 \begin_layout LyX-Code
25334 \begin_layout LyX-Code
25335 /* place function test_func at 0x4000 */
25338 \begin_layout LyX-Code
25339 #pragma code test_func 0x4000
25342 \begin_layout LyX-Code
25346 \begin_layout Description
25347 library instructs the linker to use a library module.
25352 \begin_layout LyX-Code
25353 #pragma library module_name
25356 \begin_layout Standard
25361 can be any library or object file (including its path).
25362 Note that there are four reserved keywords which have special meaning.
25366 \begin_layout Standard
25368 \begin_inset Tabular
25369 <lyxtabular version="3" rows="6" columns="3">
25371 <column alignment="center" valignment="top" leftline="true" width="0">
25372 <column alignment="block" valignment="top" leftline="true" width="20page%">
25373 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
25374 <row topline="true" bottomline="true">
25375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25378 \begin_layout Standard
25384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25387 \begin_layout Standard
25393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25396 \begin_layout Standard
25403 <row topline="true">
25404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25407 \begin_layout Standard
25415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25418 \begin_layout Standard
25419 ignore all library pragmas
25424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25427 \begin_layout Standard
25436 <row topline="true">
25437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25440 \begin_layout Standard
25448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25451 \begin_layout Standard
25457 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25460 \begin_layout Standard
25471 <row topline="true">
25472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25475 \begin_layout Standard
25483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25486 \begin_layout Standard
25487 link the Math libarary
25492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25495 \begin_layout Standard
25506 <row topline="true">
25507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25510 \begin_layout Standard
25518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25521 \begin_layout Standard
25522 link the I/O library
25527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25530 \begin_layout Standard
25541 <row topline="true" bottomline="true">
25542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25545 \begin_layout Standard
25553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25556 \begin_layout Standard
25557 link the debug library
25562 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25565 \begin_layout Standard
25582 * is the device number, i.e.
25583 452 for PIC18F452 MCU.
25586 \begin_layout Standard
25587 This feature allows for linking with specific libraries withoug having to
25588 explicit name them in the command line.
25593 keyword will reject all modules specified by the library pragma.
25596 \begin_layout Description
25597 udata The pragma udata instructs the compiler to emit code so that linker
25598 will place a variable at a specific memory bank.
25601 \begin_layout LyX-Code
25605 \begin_layout LyX-Code
25609 \begin_layout LyX-Code
25610 /* places variable foo at bank2 */
25613 \begin_layout LyX-Code
25614 #pragma udata bank2 foo
25617 \begin_layout LyX-Code
25621 \begin_layout Standard
25622 In order for this pragma to work extra SECTION directives should be added
25623 in the .lkr script.
25624 In the following example a sample .lkr file is shown:
25627 \begin_layout LyX-Code
25631 \begin_layout LyX-Code
25632 // Sample linker script for the PIC18F452 processor
25635 \begin_layout LyX-Code
25639 \begin_layout LyX-Code
25640 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
25643 \begin_layout LyX-Code
25644 CODEPAGE NAME=page START=0x2A END=0x7FFF
25647 \begin_layout LyX-Code
25648 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
25651 \begin_layout LyX-Code
25652 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
25655 \begin_layout LyX-Code
25656 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
25659 \begin_layout LyX-Code
25660 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
25663 \begin_layout LyX-Code
25664 ACCESSBANK NAME=accessram START=0x0 END=0x7F
25667 \begin_layout LyX-Code
25671 \begin_layout LyX-Code
25672 DATABANK NAME=gpr0 START=0x80 END=0xFF
25675 \begin_layout LyX-Code
25676 DATABANK NAME=gpr1 START=0x100 END=0x1FF
25679 \begin_layout LyX-Code
25680 DATABANK NAME=gpr2 START=0x200 END=0x2FF
25683 \begin_layout LyX-Code
25684 DATABANK NAME=gpr3 START=0x300 END=0x3FF
25687 \begin_layout LyX-Code
25688 DATABANK NAME=gpr4 START=0x400 END=0x4FF
25691 \begin_layout LyX-Code
25692 DATABANK NAME=gpr5 START=0x500 END=0x5FF
25695 \begin_layout LyX-Code
25696 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
25699 \begin_layout LyX-Code
25703 \begin_layout LyX-Code
25704 SECTION NAME=CONFIG ROM=config
25707 \begin_layout LyX-Code
25711 \begin_layout LyX-Code
25712 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
25715 \begin_layout LyX-Code
25716 SECTION NAME=bank1 RAM=gpr1 # should be added to link
25719 \begin_layout LyX-Code
25720 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
25723 \begin_layout LyX-Code
25724 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
25727 \begin_layout LyX-Code
25728 SECTION NAME=bank4 RAM=gpr4
25731 \begin_layout LyX-Code
25732 SECTION NAME=bank5 RAM=gpr5
25735 \begin_layout Standard
25736 The linker will recognise the section name set in the pragma statement and
25737 will position the variable at the memory bank set with the RAM field at
25738 the SECTION line in the linker script file.
25741 \begin_layout Subsection
25743 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
25750 \begin_layout Standard
25751 There is one main header file
25752 \begin_inset LatexCommand \index{PIC16!Header files}
25756 that can be included to the source files using the pic16
25757 \begin_inset LatexCommand \index{PIC16}
25767 This header file contains the definitions for the processor special registers,
25768 so it is necessary if the source accesses them.
25769 It can be included by adding the following line in the beginning of the
25773 \begin_layout LyX-Code
25774 #include <pic18fregs.h>
25777 \begin_layout Standard
25778 The specific microcontroller is selected within the pic18fregs.h automatically,
25779 so the same source can be used with a variety of devices.
25782 \begin_layout Subsection
25786 \begin_layout Standard
25788 \begin_inset LatexCommand \index{PIC16!Libraries}
25793 \begin_inset LatexCommand \index{PIC16}
25797 port depends on are the microcontroller device libraries which contain
25798 the symbol definitions for the microcontroller special function registers.
25799 These libraries have the format pic18fxxxx.lib, where
25803 is the microcontroller identification number.
25804 The specific library is selected automatically by the compiler at link
25805 stage according to the selected device.
25808 \begin_layout Standard
25809 Libraries are created with gplib which is part of the gputils package
25810 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
25817 \begin_layout Subsubsection*
25818 Building the libraries
25821 \begin_layout Standard
25822 Before using SDCC/pic16 there are some libraries that need to be compiled.
25823 This process is not done automatically by SDCC since not all users use
25824 SDCC for pic16 projects.
25825 So each user should compile the libraries separately.
25828 \begin_layout Standard
25829 The steps to compile the pic16 libraries under Linux and Mac OS X are:
25832 \begin_layout LyX-Code
25833 cd device/lib/pic16
25836 \begin_layout LyX-Code
25840 \begin_layout LyX-Code
25844 \begin_layout LyX-Code
25848 \begin_layout LyX-Code
25852 \begin_layout LyX-Code
25853 su -c 'make install' # install the libraries, you need the root password
25856 \begin_layout Standard
25857 If you need to install the headers too, do:
25860 \begin_layout LyX-Code
25864 \begin_layout LyX-Code
25865 su -c 'make install' # install the headers, you need the root password
25868 \begin_layout Standard
25869 There exist a special target to build the I/O libraries.
25870 This target is not automatically build because it will build the I/O library
25876 This way building will take quite a lot of time.
25877 Users are advised to edit the
25879 device/lib/pic16/pics.build
25881 file and then execute:
25884 \begin_layout LyX-Code
25888 \begin_layout Subsection
25889 Adding New Devices to the Port
25892 \begin_layout Standard
25893 Adding support for a new 16
25897 \begin_layout Standard
25906 bit PIC MCU requires the following steps:
25909 \begin_layout Enumerate
25910 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
25914 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
25918 \begin_layout Enumerate
25921 mv picDEVICE.h /path/to/sdcc/device/include/pic16
25924 \begin_layout Enumerate
25927 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
25930 \begin_layout Enumerate
25933 /path/to/sdcc/device/lib/pic16/pics.all
25941 Note: No 18f prefix here!
25944 \begin_layout Enumerate
25947 /path/to/sdcc/device/lib/pic16/libio/*.ignore
25951 Add your DEVICE if it does not compile in
25966 \begin_layout Enumerate
25969 /path/to/sdcc/device/include/pic16/pic18fregs.h
25972 The file format is self-explanatory, just add
25976 #elif defined(picDEVICE)
25978 # include <picDEVICE.h>
25982 at the right place (keep it sorted).
25985 \begin_layout Enumerate
25988 /path/to/sdcc/src/pic16/devices.inc
25991 Copy and modify an existing entry and insert it at the correct place (keep
25993 The file is hardly documented, look at the entries for the 18f2221...
25996 \begin_layout Enumerate
25997 Recompile SDCC, including the pic16 libraries.
26000 \begin_layout Subsection
26004 \begin_layout Standard
26005 The following memory models are supported by the PIC16 port:
26008 \begin_layout Itemize
26012 \begin_layout Itemize
26016 \begin_layout Standard
26017 Memory model affects the default size of pointers within the source.
26018 The sizes are shown in the next table:
26021 \begin_layout Standard
26023 \begin_inset Tabular
26024 <lyxtabular version="3" rows="3" columns="3">
26026 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26027 <column alignment="center" valignment="top" leftline="true" width="0">
26028 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26029 <row topline="true" bottomline="true">
26030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26033 \begin_layout Standard
26034 Pointer sizes according to memory model
26039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26042 \begin_layout Standard
26048 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26051 \begin_layout Standard
26058 <row topline="true" bottomline="true">
26059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26062 \begin_layout Standard
26068 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26071 \begin_layout Standard
26077 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26080 \begin_layout Standard
26087 <row topline="true" bottomline="true">
26088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26091 \begin_layout Standard
26097 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
26100 \begin_layout Standard
26106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26109 \begin_layout Standard
26123 \begin_layout Standard
26124 It is advisable that all sources within a project are compiled with the
26126 If one wants to override the default memory model, this can be done by
26127 declaring a pointer as
26136 Far selects large memory model's pointers, while near selects small memory
26140 \begin_layout Standard
26141 The standard device libraries (see
26142 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
26146 ) contain no reference to pointers, so they can be used with both memory
26150 \begin_layout Subsection
26154 \begin_layout Standard
26156 \begin_inset LatexCommand \index{PIC16!stack}
26160 implementation for the PIC16 port uses two indirect registers, FSR1 and
26164 \begin_layout Description
26165 FSR1 is assigned as stack pointer
26168 \begin_layout Description
26169 FSR2 is assigned as frame pointer
26172 \begin_layout Standard
26173 The following stack models are supported by the PIC16 port
26176 \begin_layout Itemize
26184 \begin_layout Itemize
26192 \begin_layout Standard
26197 model means that only the FSRxL byte is used to access stack and frame,
26204 uses both FSRxL and FSRxH registers.
26205 The following table shows the stack/frame pointers sizes according to stack
26206 model and the maximum space they can address:
26209 \begin_layout Standard
26211 \begin_inset Tabular
26212 <lyxtabular version="3" rows="3" columns="3">
26214 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26215 <column alignment="center" valignment="top" leftline="true" width="0">
26216 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26217 <row topline="true" bottomline="true">
26218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26221 \begin_layout Standard
26222 Stack & Frame pointer sizes according to stack model
26227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26230 \begin_layout Standard
26236 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26239 \begin_layout Standard
26246 <row topline="true">
26247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26250 \begin_layout Standard
26256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26259 \begin_layout Standard
26265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26268 \begin_layout Standard
26275 <row topline="true" bottomline="true">
26276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26279 \begin_layout Standard
26285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26288 \begin_layout Standard
26294 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26297 \begin_layout Standard
26311 \begin_layout Standard
26316 stack model is currently not working properly throughout the code generator.
26317 So its use is not advised.
26318 Also there are some other points that need special care:
26323 \begin_layout Enumerate
26324 Do not create stack sections with size more than one physical bank (that
26328 \begin_layout Enumerate
26329 Stack sections should no cross physical bank limits (i.e.
26330 #pragma stack 0x50 0x100)
26333 \begin_layout Standard
26334 These limitations are caused by the fact that only FSRxL is modified when
26335 using SMALL stack model, so no more than 256 bytes of stack can be used.
26336 This problem will disappear after LARGE model is fully implemented.
26339 \begin_layout Subsection
26343 \begin_layout Standard
26344 In addition to the standard SDCC function keywords, PIC16
26345 \begin_inset LatexCommand \index{PIC16}
26349 port makes available two more:
26352 \begin_layout Description
26354 \begin_inset LatexCommand \index{PIC16!wparam}
26358 Use the WREG to pass one byte of the first function argument.
26359 This improves speed but you may not use this for functions with arguments
26360 that are called via function pointers, otherwise the first byte of the
26361 first parameter will get lost.
26365 \begin_layout LyX-Code
26366 void func_wparam(int a) wparam
26369 \begin_layout LyX-Code
26373 \begin_layout LyX-Code
26374 /* WREG hold the lower part of a */
26377 \begin_layout LyX-Code
26378 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
26382 \begin_layout LyX-Code
26386 \begin_layout LyX-Code
26390 \begin_layout Description
26392 \begin_inset LatexCommand \index{PIC16!shadowregs}
26396 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
26397 hardware shadow registers which hold the values of WREG, STATUS and BSR
26399 This can be done by adding the keyword
26407 keyword in the function's header.
26410 \begin_layout LyX-Code
26411 void isr_shadow(void) shadowregs interrupt 1
26414 \begin_layout LyX-Code
26418 \begin_layout LyX-Code
26422 \begin_layout LyX-Code
26426 \begin_layout Standard
26431 instructs the code generator not to store/restore WREG, STATUS, BSR when
26432 entering/exiting the ISR.
26435 \begin_layout Subsection
26436 Function return values
26439 \begin_layout Standard
26440 Return values from functions are placed to the appropriate registers following
26441 a modified Microchip policy optimized for SDCC.
26442 The following table shows these registers:
26445 \begin_layout Standard
26447 \begin_inset Tabular
26448 <lyxtabular version="3" rows="6" columns="2">
26450 <column alignment="center" valignment="top" leftline="true" width="0">
26451 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26452 <row topline="true" bottomline="true">
26453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26456 \begin_layout Standard
26462 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26465 \begin_layout Standard
26466 destination register
26472 <row topline="true">
26473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26476 \begin_layout Standard
26482 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26485 \begin_layout Standard
26492 <row topline="true">
26493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26496 \begin_layout Standard
26502 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26505 \begin_layout Standard
26512 <row topline="true">
26513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26516 \begin_layout Standard
26522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26525 \begin_layout Standard
26532 <row topline="true">
26533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26536 \begin_layout Standard
26542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26545 \begin_layout Standard
26546 FSR0L:PRODH:PRODL:WREG
26552 <row topline="true" bottomline="true">
26553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26556 \begin_layout Standard
26562 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26565 \begin_layout Standard
26566 on stack, FSR0 points to the beginning
26579 \begin_layout Subsection
26583 \begin_layout Standard
26585 \begin_inset LatexCommand \index{PIC16!interrupt}
26589 service routine (ISR) is declared using the
26596 \begin_layout LyX-Code
26597 void isr(void) interrupt
26602 \begin_layout LyX-Code
26606 \begin_layout LyX-Code
26610 \begin_layout LyX-Code
26614 \begin_layout Standard
26619 is the interrupt number, which for PIC18F devices can be:
26622 \begin_layout Standard
26624 \begin_inset Tabular
26625 <lyxtabular version="3" rows="4" columns="3">
26627 <column alignment="center" valignment="top" leftline="true" width="0">
26628 <column alignment="center" valignment="top" leftline="true" width="0">
26629 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26630 <row topline="true" bottomline="true">
26631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26634 \begin_layout Standard
26642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26645 \begin_layout Standard
26651 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26654 \begin_layout Standard
26655 Interrupt Vector Address
26661 <row topline="true">
26662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26665 \begin_layout Standard
26671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26674 \begin_layout Standard
26680 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26683 \begin_layout Standard
26690 <row topline="true">
26691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26694 \begin_layout Standard
26709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26712 \begin_layout Standard
26722 HIGH priority interrupts
26727 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26730 \begin_layout Standard
26737 <row topline="true" bottomline="true">
26738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26741 \begin_layout Standard
26747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26750 \begin_layout Standard
26751 LOW priority interrupts
26756 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26759 \begin_layout Standard
26773 \begin_layout Standard
26774 When generating assembly code for ISR the code generator places a
26780 Interrupt Vector Address
26782 which points at the genetated ISR.
26783 This single GOTO instruction is part of an automatically generated
26785 interrupt entry point
26788 The actuall ISR code is placed as normally would in the code space.
26789 Upon interrupt request, the GOTO instruction is executed which jumps to
26791 When declaring interrupt functions as _naked this GOTO instruction is
26796 The whole interrupt functions is therefore placed at the Interrupt Vector
26797 Address of the specific interrupt.
26798 This is not a problem for the LOW priority interrupts, but it is a problem
26799 for the RESET and the HIGH priority interrupts because code may be written
26800 at the next interrupt's vector address and cause undeterminate program
26801 behaviour if that interrupt is raised.
26805 \begin_layout Standard
26806 This is not a problem when
26809 \begin_layout Enumerate
26810 this is a HIGH interrupt ISR and LOW interrupts are
26817 \begin_layout Enumerate
26818 when the ISR is small enough not to reach the next interrupt's vector address.
26826 \begin_layout Standard
26832 This way a function is generated similar to an ISR, but it is not assigned
26836 \begin_layout Standard
26837 When entering an interrupt, currently the PIC16
26838 \begin_inset LatexCommand \index{PIC16}
26842 port automatically saves the following registers:
26845 \begin_layout Itemize
26849 \begin_layout Itemize
26853 \begin_layout Itemize
26857 \begin_layout Itemize
26858 PROD (PRODL and PRODH)
26861 \begin_layout Itemize
26862 FSR0 (FSR0L and FSR0H)
26865 \begin_layout Standard
26866 These registers are restored upon return from the interrupt routine.
26870 \begin_layout Standard
26871 NOTE that when the _naked attribute is specified for an interrupt routine,
26872 then NO registers are stored or restored.
26880 \begin_layout Subsection
26884 \begin_layout Standard
26885 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
26886 There are 3 types of generic pointers currently implemented data, code
26887 and eeprom pointers.
26888 They are differentiated by the value of the 7th and 6th bits of the upper
26892 \begin_layout Standard
26894 \begin_inset Tabular
26895 <lyxtabular version="3" rows="5" columns="5">
26897 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26898 <column alignment="center" valignment="top" width="0">
26899 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26900 <column alignment="center" valignment="top" width="0">
26901 <column alignment="left" valignment="top" rightline="true" width="0">
26902 <row topline="true" bottomline="true">
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" usebox="none">
26915 \begin_layout Standard
26921 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26924 \begin_layout Standard
26930 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26933 \begin_layout Standard
26934 rest of the pointer
26939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26942 \begin_layout Standard
26949 <row topline="true" bottomline="true">
26950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26953 \begin_layout Standard
26959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26962 \begin_layout Standard
26968 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26971 \begin_layout Standard
26977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26980 \begin_layout Standard
26985 uuuuuu uuuuxxxx xxxxxxxx
26990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26993 \begin_layout Standard
26994 a 12-bit data pointer in data RAM memory
27000 <row bottomline="true">
27001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27004 \begin_layout Standard
27010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27013 \begin_layout Standard
27019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27022 \begin_layout Standard
27028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27031 \begin_layout Standard
27036 uxxxxx xxxxxxxx xxxxxxxx
27041 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27044 \begin_layout Standard
27045 a 21-bit code pointer in FLASH memory
27051 <row bottomline="true">
27052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27055 \begin_layout Standard
27061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27064 \begin_layout Standard
27070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27073 \begin_layout Standard
27079 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27082 \begin_layout Standard
27087 uuuuuu uuuuuuxx xxxxxxxx
27092 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27095 \begin_layout Standard
27096 a 10-bit eeprom pointer in EEPROM memory
27102 <row bottomline="true">
27103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27106 \begin_layout Standard
27112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27115 \begin_layout Standard
27121 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27124 \begin_layout Standard
27130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27133 \begin_layout Standard
27138 xxxxxx xxxxxxxx xxxxxxxx
27143 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27146 \begin_layout Standard
27147 unimplemented pointer type
27160 \begin_layout Standard
27161 Generic pointer are read and written with a set of library functions which
27162 read/write 1, 2, 3, 4 bytes.
27165 \begin_layout Subsection
27169 \begin_layout Subsubsection
27170 Standard I/O Streams
27173 \begin_layout Standard
27178 the type FILE is defined as:
27181 \begin_layout LyX-Code
27182 typedef char * FILE;
27185 \begin_layout Standard
27186 This type is the stream type implemented I/O in the PIC18F devices.
27187 Also the standard input and output streams are declared in stdio.h:
27190 \begin_layout LyX-Code
27191 extern FILE * stdin;
27194 \begin_layout LyX-Code
27195 extern FILE * stdout;
27198 \begin_layout Standard
27199 The FILE type is actually a generic pointer which defines one more type
27200 of generic pointers, the
27205 This new type has the format:
27208 \begin_layout Standard
27210 \begin_inset Tabular
27211 <lyxtabular version="3" rows="2" columns="7">
27213 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27214 <column alignment="center" valignment="top" width="0">
27215 <column alignment="center" valignment="top" leftline="true" width="0">
27216 <column alignment="center" valignment="top" leftline="true" width="0">
27217 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27218 <column alignment="center" valignment="top" width="0">
27219 <column alignment="left" valignment="top" rightline="true" width="0">
27220 <row topline="true" bottomline="true">
27221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27224 \begin_layout Standard
27230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27233 \begin_layout Standard
27239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27242 \begin_layout Standard
27248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27251 \begin_layout Standard
27257 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27260 \begin_layout Standard
27266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27269 \begin_layout Standard
27270 rest of the pointer
27275 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27278 \begin_layout Standard
27285 <row topline="true" bottomline="true">
27286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27289 \begin_layout Standard
27295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27298 \begin_layout Standard
27304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27307 \begin_layout Standard
27313 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27316 \begin_layout Standard
27322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="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
27344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27347 \begin_layout Standard
27348 upper byte high nubble is 0x2n, the rest are zeroes
27361 \begin_layout Standard
27362 Currently implemented there are 3 types of streams defined:
27365 \begin_layout Standard
27367 \begin_inset Tabular
27368 <lyxtabular version="3" rows="4" columns="4">
27370 <column alignment="center" valignment="top" leftline="true" width="0">
27371 <column alignment="center" valignment="top" leftline="true" width="0">
27372 <column alignment="center" valignment="top" leftline="true" width="0">
27373 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27374 <row topline="true" bottomline="true">
27375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27378 \begin_layout Standard
27384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27387 \begin_layout Standard
27393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27396 \begin_layout Standard
27402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27405 \begin_layout Standard
27412 <row topline="true">
27413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27416 \begin_layout Standard
27422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27425 \begin_layout Standard
27433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27436 \begin_layout Standard
27442 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27445 \begin_layout Standard
27446 Writes/Reads characters via the USART peripheral
27452 <row topline="true">
27453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27456 \begin_layout Standard
27462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27465 \begin_layout Standard
27473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27476 \begin_layout Standard
27482 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27485 \begin_layout Standard
27486 Writes/Reads characters via the MSSP peripheral
27492 <row topline="true" bottomline="true">
27493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27496 \begin_layout Standard
27502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27505 \begin_layout Standard
27513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27516 \begin_layout Standard
27522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27525 \begin_layout Standard
27526 Writes/Reads characters via used defined functions
27539 \begin_layout Standard
27540 The stream identifiers are declared as macros in the stdio.h header.
27543 \begin_layout Standard
27544 In the libc library there exist the functions that are used to write to
27545 each of the above streams.
27549 \begin_layout Description
27554 \begin_layout Standard
27563 _stream_usart_putchar writes a character at the USART stream
27566 \begin_layout Description
27571 \begin_layout Standard
27580 _stream_mssp_putchar writes a character at the MSSP stream
27583 \begin_layout Description
27584 putchar dummy function.
27585 This writes a character to a user specified manner.
27588 \begin_layout Standard
27589 In order to increase performance
27593 is declared in stdio.h as having its parameter in WREG (it has the wparam
27595 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
27596 in a user-friendly way.
27601 is the name of the variable that holds the character to print.
27602 An example follows:
27605 \begin_layout LyX-Code
27606 #include <pic18fregs.h>
27615 \begin_layout LyX-Code
27619 \begin_layout LyX-Code
27620 PORTA = c; /* dump character c to PORTA */
27623 \begin_layout LyX-Code
27631 \begin_layout LyX-Code
27635 \begin_layout LyX-Code
27636 stdout = STREAM_USER; /* this is not necessary, since stdout points
27639 \begin_layout LyX-Code
27640 * by default to STREAM_USER */
27643 \begin_layout LyX-Code
27645 \begin_inset Quotes sld
27648 This is a printf test
27651 \begin_inset Quotes srd
27657 \begin_layout LyX-Code
27661 \begin_layout LyX-Code
27665 \begin_layout Subsubsection
27669 \begin_layout Standard
27670 PIC16 contains an implementation of the printf-family of functions.
27671 There exist the following functions:
27674 \begin_layout LyX-Code
27675 extern unsigned int sprintf(char *buf, char *fmt, ...);
27678 \begin_layout LyX-Code
27679 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
27682 \begin_layout LyX-Code
27686 \begin_layout LyX-Code
27687 extern unsigned int printf(char *fmt, ...);
27690 \begin_layout LyX-Code
27691 extern unsigned int vprintf(char *fmt, va_lista ap);
27694 \begin_layout LyX-Code
27698 \begin_layout LyX-Code
27699 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
27702 \begin_layout LyX-Code
27703 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
27706 \begin_layout Standard
27707 For sprintf and vsprintf
27711 should normally be a data pointer where the resulting string will be placed.
27712 No range checking is done so the user should allocate the necessery buffer.
27713 For fprintf and vfprintf
27717 should be a stream pointer (i.e.
27718 stdout, STREAM_MSSP, etc...).
27721 \begin_layout Subsubsection
27725 \begin_layout Standard
27726 The PIC18F family of microcontrollers supports a number of interrupt sources.
27727 A list of these interrupts is shown in the following table:
27730 \begin_layout Standard
27732 \begin_inset Tabular
27733 <lyxtabular version="3" rows="11" columns="4">
27735 <column alignment="left" valignment="top" leftline="true" width="0">
27736 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27737 <column alignment="left" valignment="top" leftline="true" width="0">
27738 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27739 <row topline="true" bottomline="true">
27740 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27743 \begin_layout Standard
27749 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27752 \begin_layout Standard
27758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27761 \begin_layout Standard
27767 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27770 \begin_layout Standard
27777 <row topline="true">
27778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27781 \begin_layout Standard
27787 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27790 \begin_layout Standard
27791 PORTB change interrupt
27796 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27799 \begin_layout Standard
27805 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27808 \begin_layout Standard
27809 EEPROM/FLASH write complete interrupt
27815 <row topline="true">
27816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27819 \begin_layout Standard
27825 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27828 \begin_layout Standard
27829 INT0 external interrupt
27834 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27837 \begin_layout Standard
27843 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27846 \begin_layout Standard
27847 Bus collision interrupt
27853 <row topline="true">
27854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27857 \begin_layout Standard
27863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27866 \begin_layout Standard
27867 INT1 external interrupt
27872 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27875 \begin_layout Standard
27881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27884 \begin_layout Standard
27885 Low voltage detect interrupt
27891 <row topline="true">
27892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27895 \begin_layout Standard
27901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27904 \begin_layout Standard
27905 INT2 external interrupt
27910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27913 \begin_layout Standard
27919 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27922 \begin_layout Standard
27923 Parallel slave port interrupt
27929 <row topline="true">
27930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27933 \begin_layout Standard
27939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27942 \begin_layout Standard
27943 CCP1 module interrupt
27948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27951 \begin_layout Standard
27957 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27960 \begin_layout Standard
27961 AD convertion complete interrupt
27967 <row topline="true">
27968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27971 \begin_layout Standard
27977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27980 \begin_layout Standard
27981 CCP2 module interrupt
27986 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27989 \begin_layout Standard
27995 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27998 \begin_layout Standard
27999 USART receive interrupt
28005 <row topline="true">
28006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28009 \begin_layout Standard
28015 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28018 \begin_layout Standard
28019 TMR0 overflow interrupt
28024 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28027 \begin_layout Standard
28033 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28036 \begin_layout Standard
28037 USART transmit interrupt
28043 <row topline="true">
28044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28047 \begin_layout Standard
28053 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28056 \begin_layout Standard
28057 TMR1 overflow interrupt
28062 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28065 \begin_layout Standard
28071 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28074 \begin_layout Standard
28075 SSP receive/transmit interrupt
28081 <row topline="true">
28082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28085 \begin_layout Standard
28091 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28094 \begin_layout Standard
28095 TMR2 matches PR2 interrupt
28100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28103 \begin_layout Standard
28109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28112 \begin_layout Standard
28119 <row topline="true" bottomline="true">
28120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28123 \begin_layout Standard
28129 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28132 \begin_layout Standard
28133 TMR3 overflow interrupt
28138 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28141 \begin_layout Standard
28147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28150 \begin_layout Standard
28164 \begin_layout Standard
28165 The prototypes for these names are defined in the header file
28172 \begin_layout Standard
28173 In order to simplify signal handling, a number of macros is provided:
28177 \labelwidthstring 00.00.0000
28178 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
28179 high priority interrupts.
28184 is the function name to use.
28188 \labelwidthstring 00.00.0000
28189 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
28190 low priority interrupt.
28195 is the function name to use.
28199 \labelwidthstring 00.00.0000
28200 DEF_HANDLER(sig,handler) define a handler for signal
28206 \labelwidthstring 00.00.0000
28207 END_DEF end the declaration of the dispatch table.
28210 \begin_layout Standard
28211 Additionally there are two more macros to simplify the declaration of the
28216 \labelwidthstring 00.00.0000
28219 SIGHANDLER(handler)
28221 this declares the function prototype for the
28229 \labelwidthstring 00.00.0000
28230 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
28233 \begin_layout Standard
28234 An example of using the macros above is shown below:
28237 \begin_layout LyX-Code
28238 #include <pic18fregs.h>
28241 \begin_layout LyX-Code
28242 #include <signal.h>
28246 DEF_INTHIGH(high_int)
28249 \begin_layout LyX-Code
28250 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
28253 \begin_layout LyX-Code
28254 DEF_HANDLER(SIG_BCOL, _bcol_handler)
28257 \begin_layout LyX-Code
28262 SIGHANDLER(_tmr0_handler)
28265 \begin_layout LyX-Code
28269 \begin_layout LyX-Code
28270 /* action to be taken when timer 0 overflows */
28273 \begin_layout LyX-Code
28278 SIGHANDLERNAKED(_bcol_handler)
28281 \begin_layout LyX-Code
28285 \begin_layout LyX-Code
28289 \begin_layout LyX-Code
28290 /* action to be taken when bus collision occurs */
28293 \begin_layout LyX-Code
28297 \begin_layout LyX-Code
28301 \begin_layout LyX-Code
28305 \begin_layout Standard
28310 Special care should be taken when using the above scheme:
28313 \begin_layout Itemize
28314 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
28317 \begin_layout Itemize
28318 when declaring SIGHANDLERNAKED handler never forget to use
28322 for proper returning.
28325 \begin_layout Subsection
28329 \begin_layout Standard
28330 Here you can find some general tips for compiling programs with SDCC/pic16.
28333 \begin_layout Subsubsection
28337 \begin_layout Standard
28339 \begin_inset LatexCommand \index{PIC16!stack}
28343 size (that is 64 bytes) probably is enough for many programs.
28344 One must take care that when there are many levels of function nesting,
28345 or there is excessive usage of stack, its size should be extended.
28346 An example of such a case is the printf/sprintf family of functions.
28347 If you encounter problems like not being able to print integers, then you
28348 need to set the stack size around the maximum (256 for small stack model).
28349 The following diagram shows what happens when calling printf to print an
28353 \begin_layout LyX-Code
28354 printf () --> ltoa () --> ultoa () --> divschar ()
28357 \begin_layout Standard
28358 It is should be understood that stack is easily consumed when calling complicate
28360 Using command line arguments like -
28364 \begin_layout Standard
28373 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
28375 Other ways to reduce stack usage may exist.
28378 \begin_layout Subsection
28382 \begin_layout Standard
28383 The PIC16 Port currently does not pass SDCC's regression test
28384 \begin_inset LatexCommand \index{Regression test (PIC16)}
28389 \begin_inset LatexCommand \ref{sec:Quality-control}
28393 ) and thus the snapshot build regression tests for the PIC16 target are
28394 currently disabled for all hosts
28399 \begin_layout Chapter
28403 \begin_layout Standard
28404 There are several approaches to debugging your code.
28405 This chapter is meant to show your options and to give detail on some of
28410 When writing your code:
28413 \begin_layout Itemize
28414 write your code with debugging in mind (avoid duplicating code, put conceptually
28415 similar variables into structs, use structured code, have strategic points
28416 within your code where all variables are consistent, ...)
28419 \begin_layout Itemize
28420 run a syntax-checking tool like splint
28421 \begin_inset LatexCommand \index{splint (syntax checking tool)}
28426 \begin_inset LatexCommand \index{lint (syntax checking tool)}
28434 \begin_layout Standard
28444 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28451 \begin_layout Itemize
28452 for the high level code use a C-compiler (like f.e.
28453 GCC) to compile run and debug the code on your host.
28458 \begin_layout Standard
28468 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28472 ) on how to handle syntax extensions like __xdata, __at(), ...
28476 \begin_layout Itemize
28477 use another C-compiler to compile code for your target.
28478 Always an option but not recommended:) And not very likely to help you.
28479 If you seriously consider walking this path you should at least occasionally
28480 check portability of your code.
28481 Most commercial compiler vendors will offer an evaluation version so you
28482 can test compile your code or snippets of your code.
28485 \begin_layout Standard
28486 Debugging on a simulator:
28489 \begin_layout Itemize
28490 there is a separate section about SDCDB (section
28491 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
28498 \begin_layout Itemize
28499 or (8051 specific) use a freeware/commercial simulator which interfaces
28501 \begin_inset LatexCommand \index{AOMF, AOMF51}
28506 \begin_inset LatexCommand \ref{OMF file}
28510 ) optionally generated by SDCC.
28513 \begin_layout Standard
28514 Debugging On-target:
28517 \begin_layout Itemize
28518 use a MCU port pin to serially output debug data to the RS232 port of your
28520 You'll probably want some level shifting device typically involving a MAX232
28522 If the hardware serial port of the MCU is not available search for 'Software
28523 UART' in your favourite search machine.
28526 \begin_layout Itemize
28527 use an on-target monitor.
28528 In this context a monitor is a small program which usually accepts commands
28529 via a serial line and allows to set program counter, to single step through
28530 a program and read/write memory locations.
28531 For the 8051 good examples of monitors are paulmon and cmon51 (see section
28533 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
28540 \begin_layout Itemize
28541 toggle MCU port pins at strategic points within your code and use an oscilloscop
28545 digital oscilloscope
28548 \begin_inset LatexCommand \index{Oscilloscope}
28552 with deep trace memory is really helpful especially if you have to debug
28553 a realtime application.
28554 If you need to monitor more pins than your oscilloscope provides you can
28555 sometimes get away with a small R-2R network.
28556 On a single channel oscilloscope you could f.e.
28557 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
28559 \begin_inset Formula $\Omega$
28562 resistor and the other one by a 5\InsetSpace ~
28564 \begin_inset Formula $\Omega$
28567 resistor to the oscilloscope probe (check output drive capability of the
28568 pins you want to monitor).
28569 If you need to monitor many more pins a
28576 \begin_layout Itemize
28590 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
28595 Usually very expensive.
28596 And very nice to have too.
28597 And usually locks you (for years...) to the devices the ICE can emulate.
28601 \begin_layout Itemize
28602 use a remote debugger.
28603 In most 8-bit systems the symbol information is not available on the target,
28604 and a complete debugger is too bulky for the target system.
28605 Therefore usually a debugger on the host system connects to an on-target
28606 debugging stub which accepts only primitive commands.
28609 Terms to enter into your favourite search engine could be 'remote debugging',
28610 'gdb stub' or 'inferior debugger'.
28614 \begin_layout Itemize
28615 use an on target hardware debugger.
28616 Some of the more modern MCUs include hardware support for setting break
28617 points and monitoring/changing variables by using dedicated hardware pins.
28618 This facility doesn't require additional code to run on the target and
28623 doesn't affect runtime behaviour until a breakpoint is hit.
28624 For the mcs51 most hardware debuggers use the AOMF
28625 \begin_inset LatexCommand \index{AOMF, AOMF51}
28630 \begin_inset LatexCommand \ref{OMF file}
28638 \begin_layout Standard
28642 \begin_layout Itemize
28643 if you are not familiar with any of the following terms you're likely to
28644 run into problems rather sooner than later:
28661 As an embedded programmer you
28665 to know them so why not look them up
28669 you have problems?)
28672 \begin_layout Itemize
28673 tell someone else about your problem (actually this is a surprisingly effective
28674 means to hunt down the bug even if the listener is not familiar with your
28676 As 'failure to communicate' is probably one of the job-induced deformations
28677 of an embedded programmer this is highly encouraged.
28680 \begin_layout Section
28681 Debugging with SDCDB
28682 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
28687 \begin_inset LatexCommand \index{SDCDB (debugger)}
28694 \begin_layout Standard
28695 SDCC is distributed with a source level debugger
28696 \begin_inset LatexCommand \index{Debugger}
28701 The debugger uses a command line interface, the command repertoire of the
28702 debugger has been kept as close to gdb
28703 \begin_inset LatexCommand \index{gdb}
28707 (the GNU debugger) as possible.
28708 The configuration and build process is part of the standard compiler installati
28709 on, which also builds and installs the debugger in the target directory
28710 specified during configuration.
28711 The debugger allows you debug BOTH at the C source and at the ASM source
28715 \begin_layout Subsection
28716 Compiling for Debugging
28719 \begin_layout Standard
28724 \begin_layout Standard
28734 \begin_inset LatexCommand \index{-\/-debug}
28738 option must be specified for all files for which debug information is to
28740 The compiler generates a .adb file for each of these files.
28741 The linker creates the .cdb
28742 \begin_inset LatexCommand \index{<file>.cdb}
28747 \begin_inset LatexCommand \index{<file>.adb}
28751 files and the address information.
28752 This .cdb is used by the debugger.
28755 \begin_layout Subsection
28756 How the Debugger Works
28759 \begin_layout Standard
28764 \begin_layout Standard
28773 -debug option is specified the compiler generates extra symbol information
28774 some of which are put into the assembler source and some are put into the
28776 Then the linker creates the .cdb file from the individual .adb files with
28777 the address information for the symbols.
28778 The debugger reads the symbolic information generated by the compiler &
28779 the address information generated by the linker.
28780 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
28781 execution is controlled by the debugger.
28782 When a command is issued for the debugger, it translates it into appropriate
28783 commands for the simulator.
28784 (Currently SDCDM only connects to the simulator but
28789 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
28793 is an effort to connect directly to the hardware.)
28796 \begin_layout Subsection
28797 Starting the Debugger SDCDB
28800 \begin_layout Standard
28801 The debugger can be started using the following command line.
28802 (Assume the file you are debugging has the file name foo).
28816 The debugger will look for the following files.
28819 \begin_layout Itemize
28820 foo.c - the source file.
28823 \begin_layout Itemize
28824 foo.cdb - the debugger symbol information file.
28827 \begin_layout Itemize
28828 foo.ihx - the Intel hex format
28829 \begin_inset LatexCommand \index{Intel hex format}
28836 \begin_layout Subsection
28837 SDCDB Command Line Options
28840 \begin_layout Itemize
28845 \begin_layout Standard
28854 -directory=<source file directory> this option can used to specify the directory
28856 The debugger will look into the directory list specified for source, cdb
28858 The items in the directory list must be separated by ':', e.g.
28859 if the source files can be in the directories /home/src1 and /home/src2,
28864 \begin_layout Standard
28873 -directory option should be -
28877 \begin_layout Standard
28886 -directory=/home/src1:/home/src2.
28887 Note there can be no spaces in the option.
28891 \begin_layout Itemize
28892 -cd <directory> - change to the <directory>.
28895 \begin_layout Itemize
28896 -fullname - used by GUI front ends.
28899 \begin_layout Itemize
28900 -cpu <cpu-type> - this argument is passed to the simulator please see the
28901 simulator docs for details.
28904 \begin_layout Itemize
28905 -X <Clock frequency > this options is passed to the simulator please see
28906 the simulator docs for details.
28909 \begin_layout Itemize
28910 -s <serial port file> passed to simulator see the simulator docs for details.
28913 \begin_layout Itemize
28914 -S <serial in,out> passed to simulator see the simulator docs for details.
28917 \begin_layout Itemize
28918 -k <port number> passed to simulator see the simulator docs for details.
28921 \begin_layout Subsection
28922 SDCDB Debugger Commands
28925 \begin_layout Standard
28926 As mentioned earlier the command interface for the debugger has been deliberatel
28927 y kept as close the GNU debugger gdb, as possible.
28928 This will help the integration with existing graphical user interfaces
28929 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
28930 If you use a graphical user interface for the debugger you can skip this
28934 \begin_layout Subsubsection*
28935 break [line | file:line | function | file:function]
28938 \begin_layout Standard
28939 Set breakpoint at specified line or function:
28948 sdcdb>break foo.c:100
28950 sdcdb>break funcfoo
28952 sdcdb>break foo.c:funcfoo
28955 \begin_layout Subsubsection*
28956 clear [line | file:line | function | file:function ]
28959 \begin_layout Standard
28960 Clear breakpoint at specified line or function:
28969 sdcdb>clear foo.c:100
28971 sdcdb>clear funcfoo
28973 sdcdb>clear foo.c:funcfoo
28976 \begin_layout Subsubsection*
28980 \begin_layout Standard
28981 Continue program being debugged, after breakpoint.
28984 \begin_layout Subsubsection*
28988 \begin_layout Standard
28989 Execute till the end of the current function.
28992 \begin_layout Subsubsection*
28996 \begin_layout Standard
28997 Delete breakpoint number 'n'.
28998 If used without any option clear ALL user defined break points.
29001 \begin_layout Subsubsection*
29002 info [break | stack | frame | registers ]
29005 \begin_layout Itemize
29006 info break - list all breakpoints
29009 \begin_layout Itemize
29010 info stack - show the function call stack.
29013 \begin_layout Itemize
29014 info frame - show information about the current execution frame.
29017 \begin_layout Itemize
29018 info registers - show content of all registers.
29021 \begin_layout Subsubsection*
29025 \begin_layout Standard
29026 Step program until it reaches a different source line.
29027 Note: pressing <return> repeats the last command.
29030 \begin_layout Subsubsection*
29034 \begin_layout Standard
29035 Step program, proceeding through subroutine calls.
29038 \begin_layout Subsubsection*
29042 \begin_layout Standard
29043 Start debugged program.
29046 \begin_layout Subsubsection*
29050 \begin_layout Standard
29051 Print type information of the variable.
29054 \begin_layout Subsubsection*
29058 \begin_layout Standard
29059 print value of variable.
29062 \begin_layout Subsubsection*
29066 \begin_layout Standard
29067 load the given file name.
29068 Note this is an alternate method of loading file for debugging.
29071 \begin_layout Subsubsection*
29075 \begin_layout Standard
29076 print information about current frame.
29079 \begin_layout Subsubsection*
29083 \begin_layout Standard
29084 Toggle between C source & assembly source.
29087 \begin_layout Subsubsection*
29088 ! simulator command
29091 \begin_layout Standard
29092 Send the string following '!' to the simulator, the simulator response is
29094 Note the debugger does not interpret the command being sent to the simulator,
29095 so if a command like 'go' is sent the debugger can loose its execution
29096 context and may display incorrect values.
29099 \begin_layout Subsubsection*
29103 \begin_layout Standard
29106 My name is Bobby Brown"
29109 \begin_layout Subsection
29110 Interfacing SDCDB with DDD
29113 \begin_layout Standard
29114 \begin_inset Note Note
29117 \begin_layout Standard
29118 The screenshot was converted from png to eps with:
29119 \begin_inset Quotes sld
29122 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
29123 \begin_inset Quotes srd
29126 which produces a pretty compact eps file which is free from compression
29130 \begin_layout Standard
29131 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
29132 as this broke the build system on Sourceforge (pdf-file was broken.
29133 pdflatex does not accept eps files).
29141 \begin_layout Standard
29157 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
29163 shows a screenshot of a debugging session with DDD
29164 \begin_inset LatexCommand \index{DDD (debugger)}
29168 (Unix only) on a simulated 8032.
29169 The debugging session might not run as smoothly as the screenshot suggests.
29170 The debugger allows setting of breakpoints, displaying and changing variables,
29171 single stepping through C and assembler code.
29174 The source was compiled with
29188 \begin_layout Standard
29200 -debug ddd_example.c
29213 and DDD was invoked with
29220 ddd -debugger "sdcdb -cpu 8032 ddd_example"
29223 \begin_layout Standard
29224 \begin_inset Note Note
29227 \begin_layout Standard
29228 Check that the double quotes or an apostroph within the command line survive
29229 the LyX tool chain.
29230 Previously the apostrophs got slanted in the PDF output so a cut and paste
29239 \begin_layout Subsection
29240 Interfacing SDCDB with XEmacs
29241 \begin_inset LatexCommand \index{XEmacs}
29246 \begin_inset LatexCommand \index{Emacs}
29253 \begin_layout Standard
29254 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
29255 sdcdb.el and sdcdbsrc.el.
29256 These two files can be found in the $(prefix)/bin directory after the installat
29258 These files need to be loaded into XEmacs for the interface to work.
29259 This can be done at XEmacs startup time by inserting the following into
29260 your '.xemacs' file (which can be found in your HOME directory):
29266 (load-file sdcdbsrc.el)
29272 .xemacs is a lisp file so the () around the command is REQUIRED.
29273 The files can also be loaded dynamically while XEmacs is running, set the
29274 environment variable 'EMACSLOADPATH' to the installation bin directory
29275 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
29276 To start the interface enter the following command:
29290 You will prompted to enter the file name to be debugged.
29295 The command line options that are passed to the simulator directly are
29296 bound to default values in the file sdcdbsrc.el.
29297 The variables are listed below, these values maybe changed as required.
29300 \begin_layout Itemize
29301 sdcdbsrc-cpu-type '51
29304 \begin_layout Itemize
29305 sdcdbsrc-frequency '11059200
29308 \begin_layout Itemize
29309 sdcdbsrc-serial nil
29312 \begin_layout Standard
29313 The following is a list of key mapping for the debugger interface.
29316 \begin_layout Standard
29339 binding\InsetSpace ~
29377 -------\InsetSpace ~
29448 sdcdb-back-from-src\InsetSpace ~
29477 rom-src\InsetSpace ~
29487 SDCDB continue command
29505 sdcdb-step-from-src\InsetSpace ~
29534 hatis-c-sexp\InsetSpace ~
29544 SDCDB ptypecommand for data at
29611 sdcdbsrc-delete\InsetSpace ~
29626 B Delete all breakpoints if no arg
29675 given or delete arg (C-u arg x)
29694 -frame\InsetSpace ~
29709 SDCDB Display current frame if no arg,
29758 given or display frame arg
29826 sdcdbsrc-goto-sdcdb\InsetSpace ~
29836 Goto the SDCDB output buffer
29855 t-c-sexp\InsetSpace ~
29866 SDCDB print command for data at
29933 sdcdbsrc-goto-sdcdb\InsetSpace ~
29944 o the SDCDB output buffer
29962 sdcdbsrc-mode\InsetSpace ~
29978 Toggles Sdcdbsrc mode (turns it
29994 sdcdb-finish-from-src\InsetSpace ~
30002 SDCDB finish command
30036 Set break for line with point
30051 sdcdbsrc-mode\InsetSpace ~
30067 Toggle Sdcdbsrc mode
30083 dbsrc-srcmode\InsetSpace ~
30107 \begin_layout Chapter
30111 \begin_layout Standard
30112 Here are a few guidelines that will help the compiler generate more efficient
30113 code, some of the tips are specific to this compiler others are generally
30114 good programming practice.
30117 \begin_layout Itemize
30118 Use the smallest data type to represent your data-value.
30119 If it is known in advance that the value is going to be less than 256 then
30120 use an 'unsigned char' instead of a 'short' or 'int'.
30121 Please note, that ANSI C requires both signed and unsigned chars to be
30122 promoted to 'signed int'
30123 \begin_inset LatexCommand \index{promotion to signed int}
30128 \begin_inset Marginal
30131 \begin_layout Standard
30140 before doing any operation.
30142 \begin_inset LatexCommand \index{type promotion}
30147 \begin_inset LatexCommand \label{type promotion}
30151 can be omitted, if the result is the same.
30152 The effect of the promotion rules together with the sign-extension is often
30157 \begin_layout Verse
30160 unsigned char uc = 0xfe;
30162 if (uc * uc < 0) /* this is true! */
30175 \begin_layout Standard
30182 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
30190 \begin_layout Verse
30193 (unsigned char) -12 / (signed char) -3 = ...
30196 \begin_layout Standard
30197 No, the result is not 4:
30200 \begin_layout Verse
30203 (int) (unsigned char) -12 / (int) (signed char) -3 =
30205 (int) (unsigned char)
30206 0xf4 / (int) (signed char) 0xfd =
30208 (int) 0x00f4 / (int) 0xfffd =
30213 (int) 244 / (int) -3 =
30215 (int) -81 = (int) 0xffaf;
30218 \begin_layout Standard
30219 Don't complain, that gcc gives you a different result.
30220 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
30221 Therefore the results are different.
30224 \begin_inset Quotes sld
30228 \begin_inset Quotes srd
30234 \begin_layout Quote
30237 If well-defined overflow characteristics are important and negative values
30238 are not, or if you want to steer clear of sign-extension problems when
30239 manipulating bits or bytes, use one of the corresponding unsigned types.
30240 (Beware when mixing signed and unsigned values in expressions, though.)
30243 character types (especially unsigned char) can be used as "tiny" integers,
30244 doing so is sometimes more trouble than it's worth, due to unpredictable
30245 sign extension and increased code size.
30249 \begin_layout Itemize
30250 Use unsigned when it is known in advance that the value is not going to
30252 This helps especially if you are doing division or multiplication, bit-shifting
30253 or are using an array index.
30256 \begin_layout Itemize
30257 NEVER jump into a LOOP.
30260 \begin_layout Itemize
30261 Declare the variables to be local
30262 \begin_inset LatexCommand \index{local variables}
30266 whenever possible, especially loop control variables (induction).
30269 \begin_layout Itemize
30270 Have a look at the assembly listing to get a
30271 \begin_inset Quotes sld
30275 \begin_inset Quotes srd
30278 for the code generation.
30281 \begin_layout Section
30282 Porting code from or to other compilers
30283 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
30290 \begin_layout Itemize
30291 check whether endianness of the compilers differs and adapt where needed.
30294 \begin_layout Itemize
30295 check the device specific header files
30296 \begin_inset LatexCommand \index{Header files}
30301 \begin_inset LatexCommand \index{Include files}
30305 for compiler specific syntax.
30306 Eventually include the file <compiler.h
30307 \begin_inset LatexCommand \index{compiler.h (include file)}
30312 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
30316 to allow using common header files.
30319 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
30326 \begin_layout Itemize
30327 check whether the startup code contains the correct initialization (watchdog,
30331 \begin_layout Itemize
30332 check whether the sizes of short, int, long match.
30335 \begin_layout Itemize
30336 check if some 16 or 32 bit hardware registers require a specific addressing
30337 order (least significant or most significant byte first) and adapt if needed
30346 relate to time and not to lower/upper memory location here, so this is
30351 the same as endianness).
30354 \begin_layout Itemize
30355 check whether the keyword
30359 is used where needed.
30360 The compilers might differ in their optimization characteristics (as different
30361 versions of the same compiler might also use more clever optimizations
30362 this is good idea anyway).
30364 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
30371 \begin_layout Itemize
30372 check that the compilers are not told to supress warnings.
30375 \begin_layout Itemize
30376 check and convert compiler specific extensions (interrupts, memory areas,
30380 \begin_layout Itemize
30381 check for differences in type promotion.
30382 Especially check for math operations on
30391 For the sake of C99 compatibility SDCC will probably promote these to
30395 more often than other compilers.
30396 Eventually insert explicit casts to
30405 Also check that the ~\InsetSpace ~
30407 \begin_inset LatexCommand \index{\~\/ Operator}
30414 \begin_inset LatexCommand \index{bit}
30420 variables, use the !\InsetSpace ~
30423 \begin_inset LatexCommand \ref{type promotion}
30428 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30435 \begin_layout Itemize
30436 check the assembly code generated for interrupt routines (f.e.
30437 for calls to possibly non-reentrant library functions).
30440 \begin_layout Itemize
30441 check whether timing loops result in proper timing (or preferably consider
30442 a rewrite of the code with timer based delays instead).
30445 \begin_layout Itemize
30446 check for differences in printf parameters (some compilers push (va_arg
30447 \begin_inset LatexCommand \index{vararg, va\_arg}
30451 ) char variables as
30455 others push them as
30461 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30468 \begin_layout Itemize
30469 check the resulting memory map
30470 \begin_inset LatexCommand \index{Memory map}
30475 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
30476 ly idata, pdata, xdata).
30477 Eventually check if unexpected library functions are included.
30480 \begin_layout Section
30482 \begin_inset LatexCommand \index{Tools}
30486 included in the distribution
30489 \begin_layout Standard
30491 \begin_inset Tabular
30492 <lyxtabular version="3" rows="12" columns="3">
30494 <column alignment="left" valignment="top" leftline="true" width="0pt">
30495 <column alignment="left" valignment="top" leftline="true" width="0pt">
30496 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30497 <row topline="true" bottomline="true">
30498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30501 \begin_layout Standard
30509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30512 \begin_layout Standard
30520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30523 \begin_layout Standard
30532 <row topline="true">
30533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30536 \begin_layout Standard
30538 \begin_inset LatexCommand \index{uCsim}
30547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30550 \begin_layout Standard
30551 Simulator for various architectures
30556 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30559 \begin_layout Standard
30566 <row topline="true">
30567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30570 \begin_layout Standard
30576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30579 \begin_layout Standard
30581 \begin_inset LatexCommand \index{Header files}
30586 \begin_inset LatexCommand \index{Include files}
30595 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30598 \begin_layout Standard
30599 sdcc/support/scripts
30605 <row topline="true">
30606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30609 \begin_layout Standard
30615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30618 \begin_layout Standard
30619 header file conversion
30624 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30627 \begin_layout Standard
30628 sdcc/support/scripts
30634 <row topline="true">
30635 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30638 \begin_layout Standard
30644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30647 \begin_layout Standard
30653 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30656 \begin_layout Standard
30672 <row topline="true">
30673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30676 \begin_layout Standard
30682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30685 \begin_layout Standard
30691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30694 \begin_layout Standard
30710 <row topline="true">
30711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30714 \begin_layout Standard
30720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30723 \begin_layout Standard
30729 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30732 \begin_layout Standard
30748 <row topline="true">
30749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30752 \begin_layout Standard
30758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30761 \begin_layout Standard
30767 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30770 \begin_layout Standard
30786 <row topline="true">
30787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30790 \begin_layout Standard
30796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30799 \begin_layout Standard
30805 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30808 \begin_layout Standard
30824 <row topline="true">
30825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30828 \begin_layout Standard
30834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30837 \begin_layout Standard
30843 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30846 \begin_layout Standard
30862 <row topline="true">
30863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30866 \begin_layout Standard
30872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30875 \begin_layout Standard
30881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30884 \begin_layout Standard
30900 <row topline="true" bottomline="true">
30901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30904 \begin_layout Standard
30910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30913 \begin_layout Standard
30915 \begin_inset LatexCommand \index{packihx (tool)}
30924 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30927 \begin_layout Standard
30952 \begin_layout Section
30954 \begin_inset LatexCommand \index{Documentation}
30958 included in the distribution
30961 \begin_layout Standard
30963 \begin_inset Tabular
30964 <lyxtabular version="3" rows="10" columns="2">
30966 <column alignment="block" valignment="top" leftline="true" width="40col%">
30967 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
30968 <row topline="true" bottomline="true" endhead="true">
30969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30972 \begin_layout Standard
30980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30983 \begin_layout Standard
30986 Filename / Where to get
30992 <row topline="true">
30993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30996 \begin_layout Standard
30997 SDCC Compiler User Guide
31002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31005 \begin_layout Standard
31006 You're reading it right now
31018 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
31028 <row topline="true">
31029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31032 \begin_layout Standard
31038 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31041 \begin_layout Standard
31054 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31064 <row topline="true">
31065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31068 \begin_layout Standard
31070 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
31075 \begin_inset LatexCommand \index{Assembler documentation}
31082 \begin_inset LatexCommand \index{aslink}
31087 \begin_inset LatexCommand \index{Linker documentation}
31096 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31099 \begin_layout Standard
31100 sdcc/as/doc/asxhtm.html
31112 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
31122 <row topline="true">
31123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31126 \begin_layout Standard
31127 SDCC regression test
31128 \begin_inset LatexCommand \index{Regression test}
31137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31140 \begin_layout Standard
31141 sdcc/doc/test_suite_spec.pdf
31153 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
31163 <row topline="true">
31164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31167 \begin_layout Standard
31173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31176 \begin_layout Standard
31189 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
31199 <row topline="true">
31200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31203 \begin_layout Standard
31204 Notes on debugging with SDCDB
31205 \begin_inset LatexCommand \index{SDCDB (debugger)}
31214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31217 \begin_layout Standard
31218 sdcc/debugger/README
31230 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
31240 <row topline="true">
31241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31244 \begin_layout Standard
31246 \begin_inset LatexCommand \index{uCsim}
31250 Software simulator for microcontrollers
31255 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31258 \begin_layout Standard
31288 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
31298 <row topline="true">
31299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31302 \begin_layout Standard
31303 Temporary notes on the pic16
31304 \begin_inset LatexCommand \index{PIC16}
31313 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31316 \begin_layout Standard
31317 sdcc/src/pic16/NOTES
31329 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
31339 <row topline="true" bottomline="true">
31340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31343 \begin_layout Standard
31344 SDCC internal documentation (debugging file format)
31349 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31352 \begin_layout Standard
31382 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
31401 \begin_layout Section
31402 Related open source tools
31403 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
31408 \begin_inset LatexCommand \index{Related tools}
31415 \begin_layout Standard
31417 \begin_inset Tabular
31418 <lyxtabular version="3" rows="16" columns="3">
31420 <column alignment="left" valignment="top" leftline="true" width="0pt">
31421 <column alignment="block" valignment="top" leftline="true" width="30line%">
31422 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
31423 <row topline="true" bottomline="true">
31424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31427 \begin_layout Standard
31435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31438 \begin_layout Standard
31446 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31449 \begin_layout Standard
31458 <row topline="true">
31459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31462 \begin_layout Standard
31464 \begin_inset LatexCommand \index{gpsim (pic simulator)}
31473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31476 \begin_layout Standard
31482 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31485 \begin_layout Standard
31486 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
31496 <row topline="true">
31497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31500 \begin_layout Standard
31502 \begin_inset LatexCommand \index{gputils (pic tools)}
31511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31514 \begin_layout Standard
31520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31523 \begin_layout Standard
31524 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
31534 <row topline="true">
31535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31538 \begin_layout Standard
31544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31547 \begin_layout Standard
31553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31556 \begin_layout Standard
31557 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
31567 <row topline="true">
31568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31571 \begin_layout Standard
31577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31580 \begin_layout Standard
31581 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
31587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31590 \begin_layout Standard
31591 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
31601 <row topline="true">
31602 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31605 \begin_layout Standard
31607 \begin_inset LatexCommand \index{indent (source formatting tool)}
31616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31619 \begin_layout Standard
31620 Formats C source - Master of the white spaces
31625 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31628 \begin_layout Standard
31629 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
31639 <row topline="true">
31640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31643 \begin_layout Standard
31645 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
31654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31657 \begin_layout Standard
31658 Object file conversion, checksumming, ...
31663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31666 \begin_layout Standard
31667 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
31677 <row topline="true">
31678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31681 \begin_layout Standard
31683 \begin_inset LatexCommand \index{objdump (tool)}
31692 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31695 \begin_layout Standard
31696 Object file conversion, ...
31701 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31704 \begin_layout Standard
31705 Part of binutils (should be there anyway)
31711 <row topline="true">
31712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31715 \begin_layout Standard
31721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31724 \begin_layout Standard
31725 8051 monitor (hex up-/download, single step, disassemble)
31730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31733 \begin_layout Standard
31734 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
31744 <row topline="true">
31745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31748 \begin_layout Standard
31750 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
31759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31762 \begin_layout Standard
31763 Source code documentation system
31768 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31771 \begin_layout Standard
31772 \begin_inset LatexCommand \url{http://www.doxygen.org}
31782 <row topline="true">
31783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31786 \begin_layout Standard
31792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31795 \begin_layout Standard
31796 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
31801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31804 \begin_layout Standard
31805 \begin_inset LatexCommand \url{http://www.kdevelop.org}
31815 <row topline="true">
31816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31819 \begin_layout Standard
31825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31828 \begin_layout Standard
31829 8051 monitor (hex up-/download, single step, disassemble)
31834 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31837 \begin_layout Standard
31838 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
31848 <row topline="true">
31849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31852 \begin_layout Standard
31854 \begin_inset LatexCommand \index{splint (syntax checking tool)}
31863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31866 \begin_layout Standard
31867 Statically checks c sources (see
31868 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
31877 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31880 \begin_layout Standard
31881 \begin_inset LatexCommand \url{http://www.splint.org}
31891 <row topline="true" bottomline="true">
31892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31895 \begin_layout Standard
31897 \begin_inset LatexCommand \index{DDD (debugger)}
31906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31909 \begin_layout Standard
31910 Debugger, serves nicely as GUI to SDCDB
31911 \begin_inset LatexCommand \index{SDCDB (debugger)}
31920 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31923 \begin_layout Standard
31924 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
31934 <row bottomline="true">
31935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31938 \begin_layout Standard
31940 \begin_inset LatexCommand \index{d52}
31945 \begin_inset LatexCommand \index{d52 (disassembler)}
31954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31957 \begin_layout Standard
31958 Disassembler, can count instruction cycles
31959 \begin_inset LatexCommand \index{instruction cycles (count)}
31963 , use with options -pnd
31968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31971 \begin_layout Standard
31972 \begin_inset LatexCommand \url{http://www.8052.com/users/disasm/}
31982 <row bottomline="true">
31983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31986 \begin_layout Standard
31988 \begin_inset LatexCommand \index{cmake}
31997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32000 \begin_layout Standard
32001 Cross platform build system, generates Makefiles
32002 \begin_inset LatexCommand \index{Makefile}
32006 and project workspaces
32007 \begin_inset LatexCommand \index{project workspace}
32016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32019 \begin_layout Standard
32020 \begin_inset LatexCommand \url{http://www.cmake.org}
32028 and a dedicated wiki entry:
32029 \begin_inset LatexCommand \url{http://www.cmake.org/Wiki/CmakeSdcc}
32048 \begin_layout Section
32049 Related documentation / recommended reading
32052 \begin_layout Standard
32054 \begin_inset Tabular
32055 <lyxtabular version="3" rows="7" columns="3">
32057 <column alignment="left" valignment="top" leftline="true" width="0pt">
32058 <column alignment="left" valignment="top" leftline="true" width="0">
32059 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32060 <row topline="true" bottomline="true">
32061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32064 \begin_layout Standard
32072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32075 \begin_layout Standard
32083 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32086 \begin_layout Standard
32095 <row topline="true">
32096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32099 \begin_layout Standard
32114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32117 \begin_layout Standard
32119 \begin_inset LatexCommand \index{C Reference card}
32128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32131 \begin_layout Standard
32132 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
32142 <row topline="true">
32143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32146 \begin_layout Standard
32152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32155 \begin_layout Standard
32157 \begin_inset LatexCommand \index{C FAQ}
32166 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32169 \begin_layout Standard
32170 \begin_inset LatexCommand \url{http://www.c-faq.com}
32180 <row topline="true">
32181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32184 \begin_layout Standard
32190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32193 \begin_layout Standard
32194 \begin_inset Quotes sld
32198 \begin_inset Quotes srd
32206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32209 \begin_layout Standard
32212 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
32222 <row topline="true">
32223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32226 \begin_layout Standard
32232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32235 \begin_layout Standard
32236 \begin_inset Quotes sld
32239 Extensions for Embedded C
32240 \begin_inset Quotes srd
32248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32251 \begin_layout Standard
32254 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
32264 <row topline="true">
32265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32268 \begin_layout Standard
32274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32277 \begin_layout Standard
32278 Latest datasheet of target CPU
32283 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32286 \begin_layout Standard
32293 <row topline="true" bottomline="true">
32294 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32297 \begin_layout Standard
32303 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32306 \begin_layout Standard
32307 Revision history of datasheet
32312 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32315 \begin_layout Standard
32331 \begin_layout Section
32332 Application notes specifically for SDCC
32335 \begin_layout Standard
32336 SDCC makes no claims about the completeness of this list and about up-to-datenes
32337 s or correctness of the application notes
32338 \begin_inset LatexCommand \index{Application notes}
32345 \begin_layout Standard
32349 \begin_inset Tabular
32350 <lyxtabular version="3" rows="7" columns="3">
32352 <column alignment="block" valignment="top" leftline="true" width="17col%">
32353 <column alignment="block" valignment="top" leftline="true" width="27col%">
32354 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
32355 <row topline="true" bottomline="true">
32356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32359 \begin_layout Standard
32368 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
32371 \begin_layout Standard
32380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32383 \begin_layout Standard
32393 <row topline="true">
32394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32397 \begin_layout Standard
32405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32408 \begin_layout Standard
32411 Using the SDCC Compiler for the DS80C400
32412 \begin_inset LatexCommand \index{DS80C400}
32421 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32424 \begin_layout Standard
32427 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
32437 <row topline="true">
32438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32441 \begin_layout Standard
32449 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
32452 \begin_layout Standard
32455 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
32456 \begin_inset LatexCommand \index{DS89C4x0}
32460 Family of Microcontrollers
32465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32468 \begin_layout Standard
32471 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
32481 <row topline="true">
32482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32485 \begin_layout Standard
32488 Silicon Laboratories / Cygnal
32493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32496 \begin_layout Standard
32499 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
32500 \begin_inset LatexCommand \index{IDE}
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.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
32525 <row topline="true">
32526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32529 \begin_layout Standard
32532 Ramtron / Goal Semiconductor
32537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32540 \begin_layout Standard
32543 Interfacing SDCC to Syn and Textpad
32548 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32551 \begin_layout Standard
32554 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32564 <row topline="true">
32565 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32568 \begin_layout Standard
32571 Ramtron / Goal Semiconductor
32576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32579 \begin_layout Standard
32582 Installing and Configuring SDCC and Crimson Editor
32587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32590 \begin_layout Standard
32593 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32603 <row topline="true" bottomline="true">
32604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32607 \begin_layout Standard
32615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32618 \begin_layout Standard
32621 MSC12xx Programming with SDCC
32626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32629 \begin_layout Standard
32632 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
32649 \begin_layout Section
32653 \begin_layout Standard
32654 Some questions answered, some pointers given - it might be time to in turn
32662 \begin_layout Itemize
32663 can you solve your project with the selected microcontroller? Would you
32664 find out early or rather late that your target is too small/slow/whatever?
32665 Can you switch to a slightly better device if it doesn't fit?
32668 \begin_layout Itemize
32669 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
32670 and/or another programming language be more adequate? Would an operating
32671 system on the target device help?
32674 \begin_layout Itemize
32675 if you solved the problem, will the marketing department be happy?
32678 \begin_layout Itemize
32679 if the marketing department is happy, will customers be happy?
32682 \begin_layout Itemize
32683 if you're the project manager, marketing department and maybe even the customer
32684 in one person, have you tried to see the project from the outside?
32687 \begin_layout Itemize
32688 is the project done if you think it is done? Or is just that other interface/pro
32689 tocol/feature/configuration/option missing? How about website, manual(s),
32690 internationali(z|s)ation, packaging, labels, 2nd source for components,
32691 electromagnetic compatability/interference, documentation for production,
32692 production test software, update mechanism, patent issues?
32695 \begin_layout Itemize
32696 is your project adequately positioned in that magic triangle: fame, fortune,
32700 \begin_layout Standard
32701 Maybe not all answers to these questions are known and some answers may
32706 , nevertheless knowing these questions may help you to avoid burnout
32710 \begin_layout Standard
32711 burnout is bad for electronic devices, programmers and motorcycle tyres
32717 Chances are you didn't want to hear some of them...
32720 \begin_layout Chapter
32722 \begin_inset LatexCommand \index{Support}
32729 \begin_layout Standard
32730 SDCC has grown to be a large project.
32731 The compiler alone (without the preprocessor, assembler and linker) is
32732 well over 150,000 lines of code (blank stripped).
32733 The open source nature of this project is a key to its continued growth
32735 You gain the benefit and support of many active software developers and
32737 Is SDCC perfect? No, that's why we need your help.
32738 The developers take pride in fixing reported bugs.
32739 You can help by reporting the bugs and helping other SDCC users.
32740 There are lots of ways to contribute, and we encourage you to take part
32741 in making SDCC a great software package.
32745 \begin_layout Standard
32746 The SDCC project is hosted on the SDCC sourceforge site at
32747 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
32752 You'll find the complete set of mailing lists
32753 \begin_inset LatexCommand \index{Mailing list(s)}
32757 , forums, bug reporting system, patch submission
32758 \begin_inset LatexCommand \index{Patch submission}
32763 \begin_inset LatexCommand \index{download}
32767 area and Subversion code repository
32768 \begin_inset LatexCommand \index{Subversion code repository}
32775 \begin_layout Section
32777 \begin_inset LatexCommand \index{Bug reporting}
32782 \begin_inset LatexCommand \index{Reporting bugs}
32789 \begin_layout Standard
32790 The recommended way of reporting bugs is using the infrastructure of the
32792 You can follow the status of bug reports there and have an overview about
32796 \begin_layout Standard
32797 Bug reports are automatically forwarded to the developer mailing list and
32798 will be fixed ASAP.
32799 When reporting a bug, it is very useful to include a small test program
32800 (the smaller the better) which reproduces the problem.
32801 If you can isolate the problem by looking at the generated assembly code,
32802 this can be very helpful.
32803 Compiling your program with the -
32807 \begin_layout Standard
32817 \begin_inset LatexCommand \index{-\/-dumpall}
32821 option can sometimes be useful in locating optimization problems.
32822 When reporting a bug please make sure you:
32825 \begin_layout Enumerate
32826 Attach the code you are compiling with SDCC.
32830 \begin_layout Enumerate
32831 Specify the exact command you use to run SDCC, or attach your Makefile.
32835 \begin_layout Enumerate
32836 Specify the SDCC version (type "
32842 "), your platform, and operating system.
32846 \begin_layout Enumerate
32847 Provide an exact copy of any error message or incorrect output.
32851 \begin_layout Enumerate
32852 Put something meaningful in the subject of your message.
32855 \begin_layout Standard
32856 Please attempt to include these 5 important parts, as applicable, in all
32857 requests for support or when reporting any problems or bugs with SDCC.
32858 Though this will make your message lengthy, it will greatly improve your
32859 chance that SDCC users and developers will be able to help you.
32860 Some SDCC developers are frustrated by bug reports without code provided
32861 that they can use to reproduce and ultimately fix the problem, so please
32862 be sure to provide sample code if you are reporting a bug!
32865 \begin_layout Standard
32866 Please have a short check that you are using a recent version of SDCC and
32867 the bug is not yet known.
32868 This is the link for reporting bugs:
32869 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
32874 With SDCC on average having more than 200 downloads
32875 \begin_inset LatexCommand \index{download}
32879 on sourceforge per day
32883 \begin_layout Standard
32884 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
32885 between 2002 and 2005.
32886 This does not include other methods of distribution.
32891 there must be some users.
32892 So it's not exactly easy to find a new bug.
32893 If you find one we need it:
32895 reporting bugs is good
32900 \begin_layout Section
32901 Requesting Features
32902 \begin_inset LatexCommand \label{sub:Requesting-Features}
32907 \begin_inset LatexCommand \index{Feature request}
32912 \begin_inset LatexCommand \index{Requesting features}
32919 \begin_layout Standard
32920 Like bug reports feature requests are forwarded to the developer mailing
32922 This is the link for requesting features:
32923 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32930 \begin_layout Section
32934 \begin_layout Standard
32935 Like bug reports contributed patches are forwarded to the developer mailing
32937 This is the link for submitting patches
32938 \begin_inset LatexCommand \index{Patch submission}
32943 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
32950 \begin_layout Standard
32951 You need to specify some parameters to the
32955 command for the patches to be useful.
32956 If you modified more than one file a patch created f.e.
32961 \begin_inset Quotes sld
32964 diff -Naur unmodified_directory modified_directory >my_changes.patch
32965 \begin_inset Quotes srd
32971 will be fine, otherwise
32975 \begin_inset Quotes sld
32978 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
32979 \begin_inset Quotes srd
32989 \begin_layout Section
32993 \begin_layout Standard
32994 These links should take you directly to the
32995 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
33003 \begin_layout Standard
33004 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
33005 automated messages (mid 2003)
33011 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
33016 \begin_inset LatexCommand \index{Mailing list(s)}
33020 and forums are archived and searchable so if you are lucky someone already
33021 had a similar problem.
33022 While mails to the lists themselves are delivered promptly their web front
33023 end on sourceforge sometimes shows a severe time lag (up to several weeks),
33024 if you're seriously using SDCC please consider subscribing to the lists.
33027 \begin_layout Section
33031 \begin_layout Standard
33032 You can follow the status of the Subversion version
33033 \begin_inset LatexCommand \index{version}
33037 of SDCC by watching the Changelog
33038 \begin_inset LatexCommand \index{Changelog}
33042 in the Subversion repository
33045 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
33052 \begin_layout Section
33053 Subversion Source Code Repository
33056 \begin_layout Standard
33066 \begin_layout Standard
33080 or the filenames of the snapshot versions of SDCC include date and its
33082 \begin_inset LatexCommand \index{Subversion code repository}
33087 Subversion allows to download the source of recent or previous versions
33089 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
33093 (by number or by date).
33094 An on-line source code browser and detailled instructions are also available
33096 SDCC versions starting from 1999 up to now are available (currently the
33097 versions prior to the conversion from cvs
33098 \begin_inset LatexCommand \index{cvs|see{Subversion}}
33102 to Subversion (April 2006) are either by accessible by Subversion or by
33106 \begin_layout Section
33108 \begin_inset LatexCommand \index{Release policy}
33115 \begin_layout Standard
33116 Historically there often were long delays between official releases and
33117 the sourceforge download area tends to get not updated at all.
33118 Excuses in the past might have referred to problems with live range analysis,
33119 but as this was fixed a while ago, the current problem is that another
33120 excuse has to be found.
33121 Kidding aside, we have to get better there! On the other hand there are
33122 daily snapshots available at
33123 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
33127 , and you can always build the very last version (hopefully with many bugs
33128 fixed, and features added) from the source code available at
33129 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
33135 \begin_inset LatexCommand \index{wiki}
33140 \begin_inset LatexCommand \index{SDCC Wiki}
33145 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/}
33149 also holds some information about past and future releases.
33152 \begin_layout Section
33154 \begin_inset LatexCommand \index{Examples}
33161 \begin_layout Standard
33162 You'll find some small examples in the directory
33164 sdcc/device/examples/.
33167 More examples and libraries are available at
33169 The SDCC Open Knowledge Resource
33170 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
33177 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
33184 \begin_layout Standard
33185 \begin_inset Note Note
33188 \begin_layout Standard
33189 I did insert a reference to Paul's web site here although it seems rather
33190 dedicated to a specific 8032 board (I think it's okay because it f.e.
33191 shows LCD/Harddisc interface and has a free 8051 monitor.
33192 Independent 8032 board vendors face hard competition of heavily subsidized
33193 development boards anyway).
33196 \begin_layout Standard
33197 Maybe we should include some links to real world applications.
33198 Preferably pointer to pointers (one for each architecture) so this stays
33207 \begin_layout Section
33209 \begin_inset LatexCommand \label{sec:Quality-control}
33214 \begin_inset LatexCommand \index{Quality control}
33221 \begin_layout Standard
33222 The compiler is passed through snaphot build compile and build checks.
33228 \begin_inset LatexCommand \index{Regression test}
33232 check that SDCC itself compiles flawlessly on several host platforms (i386,
33233 Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
33234 and checks the quality of the code generated by SDCC by running the code
33235 for several target platforms through simulators.
33236 The regression test suite comprises more than 100 files which expand to
33237 more than 500 test cases which include more than 4500 tests.
33238 The results of these tests are published daily on SDCC's snapshot page
33239 (click on the red or green symbols on the right side of
33240 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
33247 \begin_layout Standard
33248 There is a separate document
33251 \begin_inset LatexCommand \index{Test suite}
33258 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
33262 about the regression test suite.
33265 \begin_layout Standard
33266 You'll find the test code in the directory
33268 sdcc/support/regression
33271 You can run these tests manually by running
33275 in this directory (or f.e.
33280 \begin_inset Quotes sld
33284 \begin_inset Quotes srd
33290 if you don't want to run the complete tests).
33291 The test code might also be interesting if you want to look for examples
33292 \begin_inset LatexCommand \index{Examples}
33296 checking corner cases of SDCC or if you plan to submit patches
33297 \begin_inset LatexCommand \index{Patch submission}
33304 \begin_layout Standard
33305 The PIC14 port uses a different set of regression tests
33306 \begin_inset LatexCommand \index{Regression test (PIC14)}
33310 , you'll find them in the directory
33312 sdcc/src/regression
33317 \begin_layout Section
33318 Use of SDCC in Education
33321 \begin_layout Standard
33330 \begin_layout Standard
33331 the phrase "use in education" might evoke the association "
33335 fit for use in education".
33336 This connotation is not intended but nevertheless risked as the licensing
33337 of SDCC makes it difficult to offer educational discounts
33343 If your rationales are to:
33346 \begin_layout Enumerate
33347 give students a chance to understand the
33351 steps of code generation
33354 \begin_layout Enumerate
33355 have a curriculum that can be extended for years.
33356 Then you could use an fpga board as target and your curriculum will seamlessly
33357 extend from logic synthesis (
33358 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
33363 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
33367 ), over assembly programming, to C to FPGA compilers (
33368 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
33375 \begin_layout Enumerate
33376 be able to insert excursions about skills like using a revision control
33377 system, submitting/applying patches, using a type-setting (as opposed to
33378 word-processing) engine LyX/LaTeX, using
33379 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
33384 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
33388 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
33389 Source Software, CPU simulation, compiler regression tests
33390 \begin_inset LatexCommand \index{Regression test}
33397 And if there should be a shortage of ideas then you can always point students
33398 to the ever-growing feature request list
33399 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33406 \begin_layout Enumerate
33407 not tie students to a specific host platform and instead allow them to use
33412 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
33414 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
33421 \begin_layout Enumerate
33422 not encourage students to use illegal copies of educational software
33425 \begin_layout Enumerate
33426 be immune to licensing/availability/price changes of the chosen tool chain
33429 \begin_layout Enumerate
33430 be able to change to a new target platform without having to adopt a new
33434 \begin_layout Enumerate
33435 have complete control over and insight into the tool chain
33438 \begin_layout Enumerate
33439 make your students aware about the pros and cons of open source software
33443 \begin_layout Enumerate
33444 give back to the public as you are probably at least partially publically
33448 \begin_layout Enumerate
33449 give students a chance to publically prove their skills and to possibly
33450 see a world wide impact
33453 \begin_layout Standard
33454 then SDCC is probably among the first choices.
33455 Well, probably SDCC might be the only choice.
33460 \begin_layout Chapter
33461 SDCC Technical Data
33464 \begin_layout Section
33466 \begin_inset LatexCommand \index{Optimizations}
33473 \begin_layout Standard
33474 SDCC performs a host of standard optimizations in addition to some MCU specific
33479 \begin_layout Subsection
33480 Sub-expression Elimination
33481 \begin_inset LatexCommand \index{Subexpression elimination}
33488 \begin_layout Standard
33489 The compiler does local and
33508 \begin_layout Verse
33516 \begin_layout Standard
33517 will be translated to
33520 \begin_layout Verse
33530 \begin_layout Standard
33531 Some subexpressions are not as obvious as the above example, e.g.:
33534 \begin_layout Verse
33542 \begin_layout Standard
33543 In this case the address arithmetic a->b[i] will be computed only once;
33544 the equivalent code in C would be.
33547 \begin_layout Verse
33557 \begin_layout Standard
33558 The compiler will try to keep these temporary variables in registers.
33561 \begin_layout Subsection
33562 Dead-Code Elimination
33563 \begin_inset LatexCommand \index{Dead-code elimination}
33570 \begin_layout Verse
33585 i = 1; \InsetSpace ~
33594 global = 1;\InsetSpace ~
33608 global = 3;\InsetSpace ~
33614 \begin_layout Standard
33618 \begin_layout Verse
33634 \begin_layout Subsection
33636 \begin_inset LatexCommand \index{Copy propagation}
33643 \begin_layout Verse
33667 \begin_layout Standard
33671 \begin_layout Verse
33695 \begin_layout Standard
33696 Note: the dead stores created by this copy propagation will be eliminated
33697 by dead-code elimination.
33700 \begin_layout Subsection
33702 \begin_inset LatexCommand \index{Loop optimization}
33707 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
33714 \begin_layout Standard
33715 Two types of loop optimizations are done by SDCC
33723 of loop induction variables.
33724 In addition to the strength reduction the optimizer marks the induction
33725 variables and the register allocator tries to keep the induction variables
33726 in registers for the duration of the loop.
33727 Because of this preference of the register allocator
33728 \begin_inset LatexCommand \index{Register allocation}
33732 , loop induction optimization causes an increase in register pressure, which
33733 may cause unwanted spilling of other temporary variables into the stack
33734 \begin_inset LatexCommand \index{stack}
33739 The compiler will generate a warning message when it is forced to allocate
33740 extra space either on the stack or data space.
33741 If this extra space allocation is undesirable then induction optimization
33742 can be eliminated either for the entire source file (with -
33746 \begin_layout Standard
33755 -noinduction option) or for a given function only using #pragma\InsetSpace ~
33757 \begin_inset LatexCommand \index{\#pragma noinduction}
33768 \begin_layout Verse
33771 for (i = 0 ; i < 100 ; i ++)
33780 \begin_layout Standard
33784 \begin_layout Verse
33789 for (i = 0; i < 100; i++)
33798 \begin_layout Standard
33799 As mentioned previously some loop invariants are not as apparent, all static
33800 address computations are also moved out of the loop.
33805 \begin_inset LatexCommand \index{Strength reduction}
33809 , this optimization substitutes an expression by a cheaper expression:
33812 \begin_layout Verse
33815 for (i=0;i < 100; i++)
33824 \begin_layout Standard
33828 \begin_layout Verse
33835 for (i=0;i< 100;i++) {
33841 ar[itemp1] = itemp2;
33859 \begin_layout Standard
33860 The more expensive multiplication
33861 \begin_inset LatexCommand \index{Multiplication}
33865 is changed to a less expensive addition.
33868 \begin_layout Subsection
33870 \begin_inset LatexCommand \index{Loop reversing}
33877 \begin_layout Standard
33878 This optimization is done to reduce the overhead of checking loop boundaries
33879 for every iteration.
33880 Some simple loops can be reversed and implemented using a
33881 \begin_inset Quotes eld
33884 decrement and jump if not zero
33885 \begin_inset Quotes erd
33889 SDCC checks for the following criterion to determine if a loop is reversible
33890 (note: more sophisticated compilers use data-dependency analysis to make
33891 this determination, SDCC uses a more simple minded analysis).
33894 \begin_layout Itemize
33895 The 'for' loop is of the form
33901 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
33911 \begin_layout Itemize
33912 The <for body> does not contain
33913 \begin_inset Quotes eld
33917 \begin_inset Quotes erd
33921 \begin_inset Quotes erd
33927 \begin_layout Itemize
33928 All goto's are contained within the loop.
33931 \begin_layout Itemize
33932 No function calls within the loop.
33935 \begin_layout Itemize
33936 The loop control variable <sym> is not assigned any value within the loop
33939 \begin_layout Itemize
33940 The loop control variable does NOT participate in any arithmetic operation
33944 \begin_layout Itemize
33945 There are NO switch statements in the loop.
33948 \begin_layout Subsection
33949 Algebraic Simplifications
33952 \begin_layout Standard
33953 SDCC does numerous algebraic simplifications, the following is a small sub-set
33954 of these optimizations.
33957 \begin_layout Verse
33960 i = j + 0;\InsetSpace ~
33964 /* changed to: */\InsetSpace ~
33970 i /= 2;\InsetSpace ~
33977 /* changed to: */\InsetSpace ~
33984 = j - j;\InsetSpace ~
33988 /* changed to: */\InsetSpace ~
33994 i = j / 1;\InsetSpace ~
33998 /* changed to: */\InsetSpace ~
34005 \begin_layout Standard
34006 Note the subexpressions
34007 \begin_inset LatexCommand \index{Subexpression}
34011 given above are generally introduced by macro expansions or as a result
34012 of copy/constant propagation.
34015 \begin_layout Subsection
34016 'switch' Statements
34017 \begin_inset LatexCommand \label{sub:'switch'-Statements}
34022 \begin_inset LatexCommand \index{switch statement}
34029 \begin_layout Standard
34030 SDCC can optimize switch statements to jump tables
34031 \begin_inset LatexCommand \index{jump tables}
34036 It makes the decision based on an estimate of the generated code size.
34037 SDCC is quite liberal in the requirements for jump table generation:
34040 \begin_layout Itemize
34041 The labels need not be in order, and the starting number need not be one
34042 or zero, the case labels are in numerical sequence or not too many case
34043 labels are missing.
34047 \begin_layout Verse
34050 switch(i) {\InsetSpace ~
34081 case 4: ...\InsetSpace ~
34113 case 5: ...\InsetSpace ~
34145 case 3: ...\InsetSpace ~
34176 case 6: ...\InsetSpace ~
34208 case 7: ...\InsetSpace ~
34240 case 8: ...\InsetSpace ~
34272 case 9: ...\InsetSpace ~
34304 case 10: ...\InsetSpace ~
34335 case 11: ...\InsetSpace ~
34402 \begin_layout Standard
34403 Both the above switch statements will be implemented using a jump-table.
34404 The example to the right side is slightly more efficient as the check for
34405 the lower boundary of the jump-table is not needed.
34409 \begin_layout Itemize
34410 The number of case labels is not larger than supported by the target architectur
34414 \begin_layout Itemize
34415 If the case labels are not in numerical sequence ('gaps' between cases)
34416 SDCC checks whether a jump table with additionally inserted dummy cases
34417 is still attractive.
34421 \begin_layout Itemize
34422 If the starting number is not zero and a check for the lower boundary of
34423 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
34428 \begin_layout Standard
34429 Switch statements which have large gaps in the numeric sequence or those
34430 that have too many case labels can be split into more than one switch statement
34431 for efficient code generation, e.g.:
34434 \begin_layout Verse
34512 \begin_layout Standard
34513 If the above switch statement is broken down into two switch statements
34516 \begin_layout Verse
34559 \begin_layout Standard
34563 \begin_layout Verse
34606 \begin_layout Standard
34607 then both the switch statements will be implemented using jump-tables whereas
34608 the unmodified switch statement will not be.
34611 \begin_layout Standard
34612 \begin_inset Note Note
34615 \begin_layout Standard
34616 There might be reasons which SDCC cannot know about to either favour or
34617 not favour jump tables.
34618 If the target system has to be as quick for the last switch case as for
34619 the first (pro jump table), or if the switch argument is known to be zero
34620 in the majority of the cases (contra jump table).
34628 \begin_layout Standard
34629 The pragma nojtbound
34630 \begin_inset LatexCommand \index{\#pragma nojtbound}
34634 can be used to turn off checking the
34647 It has no effect if a default label is supplied.
34648 Use of this pragma is dangerous: if the switch
34649 \begin_inset LatexCommand \index{switch statement}
34653 argument is not matched by a case statement the processor will happily
34657 \begin_layout Subsection
34658 Bit-shifting Operations
34659 \begin_inset LatexCommand \index{Bit shifting}
34666 \begin_layout Standard
34667 Bit shifting is one of the most frequently used operation in embedded programmin
34669 SDCC tries to implement bit-shift operations in the most efficient way
34673 \begin_layout Verse
34686 \begin_layout Standard
34687 generates the following code:
34690 \begin_layout Verse
34705 \begin_layout Standard
34706 In general SDCC will never setup a loop if the shift count is known.
34710 \begin_layout Verse
34723 \begin_layout Standard
34727 \begin_layout Verse
34751 \begin_layout Subsection
34753 \begin_inset LatexCommand \index{Bit rotation}
34760 \begin_layout Standard
34761 A special case of the bit-shift operation is bit rotation
34762 \begin_inset LatexCommand \index{rotating bits}
34766 , SDCC recognizes the following expression to be a left bit-rotation:
34769 \begin_layout Verse
34777 char i;\InsetSpace ~
34788 /* unsigned is needed for rotation */
34793 i = ((i << 1) | (i >> 7));
34802 \begin_layout Standard
34803 will generate the following code:
34806 \begin_layout Verse
34823 \begin_layout Standard
34824 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
34825 ns of this case will also be recognized as bit-rotation, i.e.:
34828 \begin_layout Verse
34831 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
34834 \begin_layout Subsection
34835 Nibble and Byte Swapping
34838 \begin_layout Standard
34839 Other special cases of the bit-shift operations are nibble or byte swapping
34840 \begin_inset LatexCommand \index{swapping nibbles/bytes}
34844 , SDCC recognizes the following expressions:
34847 \begin_layout Verse
34868 i = ((i << 4) | (i >> 4));
34874 j = ((j << 8) | (j >> 8));
34877 \begin_layout Standard
34878 and generates a swap instruction for the nibble swapping
34879 \begin_inset LatexCommand \index{Nibble swapping}
34883 or move instructions for the byte swapping
34884 \begin_inset LatexCommand \index{Byte swapping}
34890 \begin_inset Quotes sld
34894 \begin_inset Quotes srd
34897 example can be used to convert from little to big-endian or vice versa.
34898 If you want to change the endianness of a
34902 integer you have to cast to
34909 \begin_layout Standard
34910 Note that SDCC stores numbers in little-endian
34914 \begin_layout Standard
34915 Usually 8-bit processors don't care much about endianness.
34916 This is not the case for the standard 8051 which only has an instruction
34922 \begin_inset LatexCommand \index{DPTR}
34930 so little-endian is the more efficient byte order.
34936 \begin_inset LatexCommand \index{little-endian}
34941 \begin_inset LatexCommand \index{Endianness}
34946 lowest order first).
34949 \begin_layout Subsection
34951 \begin_inset LatexCommand \index{Highest Order Bit}
34956 \begin_inset LatexCommand \index{Any Order Bit}
34963 \begin_layout Standard
34964 It is frequently required to obtain the highest order bit of an integral
34965 type (long, int, short or char types).
34966 Also obtaining any other order bit is not uncommon.
34967 SDCC recognizes the following expressions to yield the highest order bit
34968 and generates optimized code for it, e.g.:
34971 \begin_layout Verse
34982 unsigned char hob1, aob1;
34986 bit hob2, hob3, aob2,
34996 hob1 = (gint >> 15) & 1;
35000 hob2 = (gint >> 15) & 1;
35004 hob3 = gint & 0x8000;
35009 aob1 = (gint >> 9) & 1;
35013 aob2 = (gint >> 8) & 1;
35017 aob3 = gint & 0x0800;
35027 \begin_layout Standard
35028 will generate the following code:
35031 \begin_layout Verse
35062 000A E5*01\InsetSpace ~
35089 000C 23\InsetSpace ~
35120 000D 54 01\InsetSpace ~
35148 000F F5*02\InsetSpace ~
35203 0011 E5*01\InsetSpace ~
35231 0013 33\InsetSpace ~
35261 0014 92*00\InsetSpace ~
35317 0016 E5*01\InsetSpace ~
35344 0018 33\InsetSpace ~
35374 0019 92*01\InsetSpace ~
35430 001B E5*01\InsetSpace ~
35489 001E 54 01\InsetSpace ~
35516 0020 F5*03\InsetSpace ~
35572 0022 E5*01\InsetSpace ~
35599 0024 13\InsetSpace ~
35629 0025 92*02\InsetSpace ~
35685 0027 E5*01\InsetSpace ~
35740 002B 92*03\InsetSpace ~
35768 \begin_layout Standard
35769 Other variations of these cases however will
35774 They are standard C expressions, so I heartily recommend these be the only
35775 way to get the highest order bit, (it is portable).
35776 Of course it will be recognized even if it is embedded in other expressions,
35780 \begin_layout Verse
35783 xyz = gint + ((gint >> 15) & 1);
35786 \begin_layout Standard
35787 will still be recognized.
35790 \begin_layout Subsection
35792 \begin_inset LatexCommand \index{Higher Order Byte}
35796 / Higher Order Word
35797 \begin_inset LatexCommand \index{Higher Order Word}
35804 \begin_layout Standard
35805 It is also frequently required to obtain a higher order byte or word of
35806 a larger integral type (long, int or short types).
35807 SDCC recognizes the following expressions to yield the higher order byte
35808 or word and generates optimized code for it, e.g.:
35811 \begin_layout Verse
35816 unsigned long int glong;
35824 unsigned char hob1,
35829 unsigned int how1, how2;
35838 hob1 = (gint >> 8) & 0xFF;
35842 hob2 = glong >> 24;
35846 how1 = (glong >> 16) & 0xFFFF;
35861 \begin_layout Standard
35862 will generate the following code:
35865 \begin_layout Verse
35896 0037 85*01*06\InsetSpace ~
35918 _foo_hob1_1_1,(_gint + 1)
35949 003A 85*05*07\InsetSpace ~
35971 _foo_hob2_1_1,(_glong + 3)
36001 003D 85*04*08\InsetSpace ~
36024 _foo_how1_1_1,(_glong + 2)
36026 0040 85*05*09\InsetSpace ~
36051 0043 85*03*0A\InsetSpace ~
36073 _foo_how2_1_1,(_glong + 1)
36075 0046 85*04*0B\InsetSpace ~
36098 (_foo_how2_1_1 + 1),(_glong + 2)
36101 \begin_layout Standard
36102 Again, variations of these cases may
36107 They are standard C expressions, so I heartily recommend these be the only
36108 way to get the higher order byte/word, (it is portable).
36109 Of course it will be recognized even if it is embedded in other expressions,
36113 \begin_layout Verse
36116 xyz = gint + ((gint >> 8) & 0xFF);
36119 \begin_layout Standard
36120 will still be recognized.
36123 \begin_layout Subsection
36125 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
36130 \begin_inset LatexCommand \index{Peephole optimizer}
36137 \begin_layout Standard
36138 The compiler uses a rule based, pattern matching and re-writing mechanism
36139 for peep-hole optimization.
36144 a peep-hole optimizer by Christopher W.
36145 Fraser (cwfraser\InsetSpace ~
36148 A default set of rules are compiled into the compiler, additional rules
36149 may be added with the
36155 \begin_layout Standard
36165 \begin_inset LatexCommand \index{-\/-peep-file}
36172 The rule language is best illustrated with examples.
36175 \begin_layout Verse
36197 \begin_layout Standard
36198 The above rule will change the following assembly
36199 \begin_inset LatexCommand \index{Assembler routines}
36206 \begin_layout Verse
36214 \begin_layout Standard
36218 \begin_layout Verse
36224 \begin_layout Standard
36225 Note: All occurrences of a
36229 (pattern variable) must denote the same string.
36230 With the above rule, the assembly sequence:
36233 \begin_layout Verse
36241 \begin_layout Standard
36242 will remain unmodified.
36246 Other special case optimizations may be added by the
36253 \begin_layout Standard
36266 some variants of the 8051 MCU
36267 \begin_inset LatexCommand \index{MCS51 variants}
36280 The following two rules will change all
36297 \begin_layout Verse
36300 replace { lcall %1 } by { acall %1 }
36302 replace { ljmp %1 } by { ajmp %1 }
36305 \begin_layout Standard
36306 (NOTE: from version 2.7.3 on, you can use option -
36312 \begin_layout Standard
36324 \begin_inset LatexCommand \index{-\/-acall-ajmp}
36328 , which also takes care of aligning the interrupt vectors properly.)
36333 \begin_layout Standard
36336 inline-assembler code
36338 is also passed through the peep hole optimizer, thus the peephole optimizer
36339 can also be used as an assembly level macro expander.
36340 The rules themselves are MCU dependent whereas the rule language infra-structur
36341 e is MCU independent.
36342 Peephole optimization rules for other MCU can be easily programmed using
36347 The syntax for a rule is as follows:
36350 \begin_layout Verse
36353 rule := replace [ restart ] '{' <assembly sequence> '
36391 <assembly sequence> '
36409 '}' [if <functionName> ] '
36414 \begin_layout Standard
36415 <assembly sequence> := assembly instruction (each instruction including
36416 labels must be on a separate line).
36420 The optimizer will apply to the rules
36421 one by one from the top in the sequence of their appearance, it will terminate
36422 when all rules are exhausted.
36423 If the 'restart' option is specified, then the optimizer will start matching
36424 the rules again from the top, this option for a rule is expensive (performance)
36425 , it is intended to be used in situations where a transformation will trigger
36426 the same rule again.
36427 An example of this (not a good one, it has side effects) is the following
36431 \begin_layout Verse
36451 \begin_layout Standard
36452 Note that the replace pattern cannot be a blank, but can be a comment line.
36453 Without the 'restart' option only the innermost 'pop' 'push' pair would
36454 be eliminated, i.e.:
36457 \begin_layout Verse
36469 \begin_layout Standard
36473 \begin_layout Verse
36483 \begin_layout Standard
36488 the restart option the rule will be applied again to the resulting code
36489 and then all the pop-push pairs will be eliminated to yield:
36492 \begin_layout Verse
36500 \begin_layout Standard
36501 A conditional function can be attached to a rule.
36502 Attaching rules are somewhat more involved, let me illustrate this with
36506 \begin_layout Verse
36530 \begin_layout Standard
36531 The optimizer does a look-up of a function name table defined in function
36536 in the source file SDCCpeeph.c, with the name
36541 If it finds a corresponding entry the function is called.
36542 Note there can be no parameters specified for these functions, in this
36547 is crucial, since the function
36551 expects to find the label in that particular variable (the hash table containin
36552 g the variable bindings is passed as a parameter).
36553 If you want to code more such functions, take a close look at the function
36554 labelInRange and the calling mechanism in source file SDCCpeeph.c.
36555 Currently implemented are
36557 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
36558 24bitMode, portIsDS390, 24bitModeAndPortDS390
36567 \begin_layout Standard
36568 I know this whole thing is a little kludgey, but maybe some day we will
36569 have some better means.
36570 If you are looking at this file, you will see the default rules that are
36571 compiled into the compiler, you can add your own rules in the default set
36572 there if you get tired of specifying the -
36576 \begin_layout Standard
36588 \begin_layout Section
36590 \begin_inset LatexCommand \index{ANSI-compliance}
36595 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
36602 \begin_layout Standard
36603 The latest publically available version of the standard
36605 ISO/IEC 9899 - Programming languages - C
36607 should be available at:
36608 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
36617 \begin_layout Standard
36618 Deviations from the compliance:
36621 \begin_layout Itemize
36622 functions are not reentrant
36623 \begin_inset LatexCommand \index{reentrant}
36627 unless explicitly declared as such or the
36633 \begin_layout Standard
36643 \begin_inset LatexCommand \index{-\/-stack-auto}
36649 command line option is specified.
36652 \begin_layout Itemize
36654 \begin_inset LatexCommand \index{struct}
36659 \begin_inset LatexCommand \index{union}
36663 cannot be assigned values directly, cannot be passed as function parameters
36664 or assigned to each other and cannot be a return value
36665 \begin_inset LatexCommand \index{return value}
36669 from a function, e.g.:
36673 \begin_layout Verse
36696 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
36715 s parms) /* invalid in SDCC although allowed in ANSI */
36737 return rets; /* is invalid in SDCC although allowed in ANSI */
36743 \begin_layout Itemize
36744 initialization of structure arrays must be fully braced.
36748 \begin_layout Verse
36751 struct s { char x } a[] = {1, 2};\InsetSpace ~
36756 /* invalid in SDCC */
36759 } a[] = {{1}, {2}}; /* OK */
36763 \begin_layout Itemize
36765 \begin_inset LatexCommand \index{long long (not supported)}
36770 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
36777 \begin_layout Itemize
36779 \begin_inset LatexCommand \index{double (not supported)}
36783 ' precision floating point
36784 \begin_inset LatexCommand \index{Floating point support}
36791 \begin_layout Itemize
36793 \begin_inset LatexCommand \index{K\&R style}
36797 function declarations are NOT allowed.
36801 \begin_layout Verse
36804 foo(i,j) /* this old style of function declarations */
36806 int i,j; /* is valid
36807 in ANSI but not valid in SDCC */
36822 \begin_layout Itemize
36823 Most enhancements in C99 are not supported, e.g.:
36827 \begin_layout Verse
36834 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
36838 \begin_layout Itemize
36839 But some have been added recently in SDCC 2.7.0.
36840 They must be considered alpha quality however.
36844 \begin_layout Verse
36849 \begin_inset LatexCommand \index{inline (not supported)}
36855 int increment (int a) { return a+1; } /* inlines the increment without
36856 function call overhead */
36861 \begin_inset LatexCommand \index{inline (not supported)}
36867 p; /* accepted but ignored */
36871 \begin_layout Itemize
36872 Certain words that are valid identifiers in the standard may be reserved
36873 words in SDCC unless the
36879 \begin_layout Standard
36889 \begin_inset LatexCommand \index{-\/-std-c89}
36901 \begin_layout Standard
36911 \begin_inset LatexCommand \index{-\/-std-c99}
36917 command line options are used.
36918 These may include (depending on the selected processor): 'at', 'banked',
36919 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
36920 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
36921 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
36923 Compliant equivalents of these keywords are always available in a form
36924 that begin with two underscores
36925 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
36930 '__data' instead of 'data'.
36933 \begin_layout Itemize
36934 Integer promotion of variable arguments is not performed if the argument
36935 is explicitly taypecasted unless the
36941 \begin_layout Standard
36951 \begin_inset LatexCommand \index{-\/-std-c89}
36963 \begin_layout Standard
36973 \begin_inset LatexCommand \index{-\/-std-c99}
36979 command line options are used.
36983 \begin_layout Verse
36986 void vararg_func (char *str, ...) { str; }
37003 u is promoted to int before
37008 * passing to function */
37012 vararg_func ("%c", c);
37019 argument u is not promoted to int,
37024 * it is passed as char to function
37030 --std-cXX is not defined;
37035 * is promoted to int before passing
37041 if --std-cXX is defined */
37045 vararg_func ("%bc", (char)u);
37051 \begin_layout Section
37052 Cyclomatic Complexity
37053 \begin_inset LatexCommand \index{Cyclomatic complexity}
37060 \begin_layout Standard
37061 Cyclomatic complexity of a function is defined as the number of independent
37062 paths the program can take during execution of the function.
37063 This is an important number since it defines the number test cases you
37064 have to generate to validate the function.
37065 The accepted industry standard for complexity number is 10, if the cyclomatic
37066 complexity reported by SDCC exceeds 10 you should think about simplification
37067 of the function logic.
37068 Note that the complexity level is not related to the number of lines of
37069 code in a function.
37070 Large functions can have low complexity, and small functions can have large
37076 SDCC uses the following formula to compute the complexity:
37081 \begin_layout Standard
37082 complexity = (number of edges in control flow graph) - (number of nodes
37083 in control flow graph) + 2;
37087 Having said that the industry standard is 10,
37088 you should be aware that in some cases it be may unavoidable to have a
37089 complexity level of less than 10.
37090 For example if you have switch statement with more than 10 case labels,
37091 each case label adds one to the complexity level.
37092 The complexity level is by no means an absolute measure of the algorithmic
37093 complexity of the function, it does however provide a good starting point
37094 for which functions you might look at for further optimization.
37097 \begin_layout Section
37098 Retargetting for other Processors
37101 \begin_layout Standard
37102 The issues for retargetting the compiler are far too numerous to be covered
37104 What follows is a brief description of each of the seven phases of the
37105 compiler and its MCU dependency.
37108 \begin_layout Itemize
37109 Parsing the source and building the annotated parse tree.
37110 This phase is largely MCU independent (except for the language extensions).
37111 Syntax & semantic checks are also done in this phase, along with some initial
37112 optimizations like back patching labels and the pattern matching optimizations
37113 like bit-rotation etc.
37116 \begin_layout Itemize
37117 The second phase involves generating an intermediate code which can be easy
37118 manipulated during the later phases.
37119 This phase is entirely MCU independent.
37120 The intermediate code generation assumes the target machine has unlimited
37121 number of registers, and designates them with the name iTemp.
37122 The compiler can be made to dump a human readable form of the code generated
37127 \begin_layout Standard
37139 \begin_layout Itemize
37140 This phase does the bulk of the standard optimizations and is also MCU independe
37142 This phase can be broken down into several sub-phases:
37146 Break down intermediate
37147 code (iCode) into basic blocks.
37149 Do control flow & data flow analysis on the
37152 Do local common subexpression elimination, then global subexpressio
37155 Dead code elimination
37159 If loop optimizations
37160 caused any changes then do 'global subexpression elimination' and 'dead
37161 code elimination' again.
37164 \begin_layout Itemize
37165 This phase determines the live-ranges; by live range I mean those iTemp
37166 variables defined by the compiler that still survive after all the optimization
37168 Live range analysis
37169 \begin_inset LatexCommand \index{Live range analysis}
37173 is essential for register allocation, since these computation determines
37174 which of these iTemps will be assigned to registers, and for how long.
37177 \begin_layout Itemize
37178 Phase five is register allocation.
37179 There are two parts to this process.
37183 The first part I call 'register packing'
37184 (for lack of a better term).
37185 In this case several MCU specific expression folding is done to reduce
37190 The second part is more MCU independent and deals with
37191 allocating registers to the remaining live ranges.
37192 A lot of MCU specific code does creep into this phase because of the limited
37193 number of index registers available in the 8051.
37196 \begin_layout Itemize
37197 The Code generation phase is (unhappily), entirely MCU dependent and very
37198 little (if any at all) of this code can be reused for other MCU.
37199 However the scheme for allocating a homogenized assembler operand for each
37200 iCode operand may be reused.
37203 \begin_layout Itemize
37204 As mentioned in the optimization section the peep-hole optimizer is rule
37205 based system, which can reprogrammed for other MCUs.
37208 \begin_layout Standard
37209 More information is available on SDCC Wiki
37210 \begin_inset LatexCommand \index{wiki}
37215 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting}
37219 ) and in the thread
37220 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
37227 \begin_layout Chapter
37229 \begin_inset LatexCommand \index{Compiler internals}
37236 \begin_layout Section
37237 The anatomy of the compiler
37238 \begin_inset LatexCommand \label{sub:The-anatomy-of}
37245 \begin_layout Standard
37248 This is an excerpt from an article published in Circuit Cellar Magazine
37254 It's a little outdated (the compiler is much more efficient now and user/develo
37255 per friendly), but pretty well exposes the guts of it all.
37261 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
37262 It is fairly easy to retarget for other 8-bit MCU.
37263 Here we take a look at some of the internals of the compiler.
37267 \begin_layout Paragraph*
37269 \begin_inset LatexCommand \index{Parsing}
37276 \begin_layout Standard
37277 Parsing the input source file and creating an AST (Annotated Syntax Tree
37278 \begin_inset LatexCommand \index{Annotated syntax tree}
37283 This phase also involves propagating types (annotating each node of the
37284 parse tree with type information) and semantic analysis.
37285 There are some MCU specific parsing rules.
37286 For example the storage classes, the extended storage classes are MCU specific
37287 while there may be a xdata storage class for 8051 there is no such storage
37288 class for z80 or Atmel AVR.
37289 SDCC allows MCU specific storage class extensions, i.e.
37290 xdata will be treated as a storage class specifier when parsing 8051 C
37291 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
37295 \begin_layout Paragraph*
37297 \begin_inset LatexCommand \index{iCode}
37304 \begin_layout Standard
37305 Intermediate code generation.
37306 In this phase the AST is broken down into three-operand form (iCode).
37307 These three operand forms are represented as doubly linked lists.
37308 ICode is the term given to the intermediate form generated by the compiler.
37309 ICode example section shows some examples of iCode generated for some simple
37310 C source functions.
37313 \begin_layout Paragraph*
37315 \begin_inset LatexCommand \index{Optimizations}
37322 \begin_layout Standard
37323 Bulk of the target independent optimizations is performed in this phase.
37324 The optimizations include constant propagation, common sub-expression eliminati
37325 on, loop invariant code movement, strength reduction of loop induction variables
37326 and dead-code elimination.
37329 \begin_layout Paragraph*
37330 Live range analysis
37331 \begin_inset LatexCommand \index{Live range analysis}
37338 \begin_layout Standard
37339 During intermediate code generation phase, the compiler assumes the target
37340 machine has infinite number of registers and generates a lot of temporary
37342 The live range computation determines the lifetime of each of these compiler-ge
37343 nerated temporaries.
37344 A picture speaks a thousand words.
37345 ICode example sections show the live range annotations for each of the
37347 It is important to note here, each iCode is assigned a number in the order
37348 of its execution in the function.
37349 The live ranges are computed in terms of these numbers.
37350 The from number is the number of the iCode which first defines the operand
37351 and the to number signifies the iCode which uses this operand last.
37354 \begin_layout Paragraph*
37355 Register Allocation
37356 \begin_inset LatexCommand \index{Register allocation}
37363 \begin_layout Standard
37364 The register allocation determines the type and number of registers needed
37366 In most MCUs only a few registers can be used for indirect addressing.
37367 In case of 8051 for example the registers R0 & R1 can be used to indirectly
37368 address the internal ram and DPTR to indirectly address the external ram.
37369 The compiler will try to allocate the appropriate register to pointer variables
37371 ICode example section shows the operands annotated with the registers assigned
37373 The compiler will try to keep operands in registers as much as possible;
37374 there are several schemes the compiler uses to do achieve this.
37375 When the compiler runs out of registers the compiler will check to see
37376 if there are any live operands which is not used or defined in the current
37377 basic block being processed, if there are any found then it will push that
37378 operand and use the registers in this block, the operand will then be popped
37379 at the end of the basic block.
37383 \begin_layout Standard
37384 There are other MCU specific considerations in this phase.
37385 Some MCUs have an accumulator; very short-lived operands could be assigned
37386 to the accumulator instead of a general-purpose register.
37389 \begin_layout Paragraph*
37393 \begin_layout Standard
37394 Figure II gives a table of iCode
37395 \begin_inset LatexCommand \index{iCode}
37399 operations supported by the compiler.
37400 The code generation involves translating these operations into corresponding
37401 assembly code for the processor.
37402 This sounds overly simple but that is the essence of code generation.
37403 Some of the iCode operations are generated on a MCU specific manner for
37404 example, the z80 port does not use registers to pass parameters so the
37405 SEND and RECV iCode operations will not be generated, and it also does
37406 not support JUMPTABLES.
37412 \begin_layout Standard
37416 \begin_inset Tabular
37417 <lyxtabular version="3" rows="39" columns="4">
37418 <features islongtable="true" headBottomDL="true">
37419 <column alignment="block" valignment="top" leftline="true" width="13col%">
37420 <column alignment="left" valignment="top" leftline="true" width="13col%">
37421 <column alignment="block" valignment="top" leftline="true" width="22col%">
37422 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
37423 <row topline="true" bottomline="true" endhead="true">
37424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37427 \begin_layout Standard
37433 \begin_inset LatexCommand \index{iCode}
37442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37445 \begin_layout Standard
37453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37456 \begin_layout Standard
37464 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37467 \begin_layout Standard
37476 <row topline="true">
37477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37480 \begin_layout Standard
37488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37491 \begin_layout Standard
37494 IC_LEFT() IC_RESULT()
37499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37502 \begin_layout Standard
37510 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37513 \begin_layout Standard
37516 IC_RESULT = ! IC_LEFT;
37522 <row topline="true">
37523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37526 \begin_layout Standard
37534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37537 \begin_layout Standard
37540 IC_LEFT() IC_RESULT()
37545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37548 \begin_layout Standard
37551 Bitwise complement of
37556 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37559 \begin_layout Standard
37562 IC_RESULT = ~IC_LEFT;
37568 <row topline="true">
37569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37572 \begin_layout Standard
37580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37583 \begin_layout Standard
37586 IC_LEFT() IC_RESULT()
37591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37594 \begin_layout Standard
37597 Rotate right with carry
37602 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37605 \begin_layout Standard
37608 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
37614 <row topline="true">
37615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37618 \begin_layout Standard
37626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37629 \begin_layout Standard
37632 IC_LEFT() IC_RESULT()
37637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37640 \begin_layout Standard
37643 Rotate left with carry
37648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37651 \begin_layout Standard
37654 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
37660 <row topline="true">
37661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37664 \begin_layout Standard
37672 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37675 \begin_layout Standard
37678 IC_LEFT() IC_RESULT()
37683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37686 \begin_layout Standard
37689 Get the highest order bit of IC_LEFT
37694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37697 \begin_layout Standard
37700 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
37706 <row topline="true">
37707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37710 \begin_layout Standard
37718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37721 \begin_layout Standard
37724 IC_LEFT() IC_RESULT()
37729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37732 \begin_layout Standard
37740 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37743 \begin_layout Standard
37746 IC_RESULT = - IC_LEFT;
37752 <row topline="true">
37753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37756 \begin_layout Standard
37764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37767 \begin_layout Standard
37775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37778 \begin_layout Standard
37781 Push the operand into stack
37786 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37789 \begin_layout Standard
37798 <row topline="true">
37799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37802 \begin_layout Standard
37810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37813 \begin_layout Standard
37821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37824 \begin_layout Standard
37827 Pop the operand from the stack
37832 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37835 \begin_layout Standard
37844 <row topline="true">
37845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37848 \begin_layout Standard
37856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37859 \begin_layout Standard
37862 IC_LEFT() IC_RESULT()
37867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37870 \begin_layout Standard
37873 Call the function represented by IC_LEFT
37878 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37881 \begin_layout Standard
37884 IC_RESULT = IC_LEFT();
37890 <row topline="true">
37891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37894 \begin_layout Standard
37902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37905 \begin_layout Standard
37908 IC_LEFT() IC_RESULT()
37913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37916 \begin_layout Standard
37919 Call via function pointer
37924 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37927 \begin_layout Standard
37930 IC_RESULT = (*IC_LEFT)();
37936 <row topline="true">
37937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37940 \begin_layout Standard
37948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37951 \begin_layout Standard
37959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37962 \begin_layout Standard
37965 Return the value in operand IC_LEFT
37970 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37973 \begin_layout Standard
37982 <row topline="true">
37983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37986 \begin_layout Standard
37994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37997 \begin_layout Standard
38005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38008 \begin_layout Standard
38016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38019 \begin_layout Standard
38028 <row topline="true">
38029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38032 \begin_layout Standard
38040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38043 \begin_layout Standard
38051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38054 \begin_layout Standard
38062 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38065 \begin_layout Standard
38074 <row topline="true">
38075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38078 \begin_layout Standard
38086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38089 \begin_layout Standard
38092 IC_LEFT() IC_RIGHT() IC_RESULT()
38097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38100 \begin_layout Standard
38108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38111 \begin_layout Standard
38114 IC_RESULT = IC_LEFT + IC_RIGHT
38120 <row topline="true">
38121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38124 \begin_layout Standard
38132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38135 \begin_layout Standard
38138 IC_LEFT() IC_RIGHT() IC_RESULT()
38143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38146 \begin_layout Standard
38154 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38157 \begin_layout Standard
38160 IC_RESULT = IC_LEFT - IC_RIGHT
38166 <row topline="true">
38167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38170 \begin_layout Standard
38178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38181 \begin_layout Standard
38184 IC_LEFT() IC_RIGHT() IC_RESULT()
38189 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38192 \begin_layout Standard
38200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38203 \begin_layout Standard
38206 IC_RESULT = IC_LEFT * IC_RIGHT;
38212 <row topline="true">
38213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38216 \begin_layout Standard
38224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38227 \begin_layout Standard
38230 IC_LEFT() IC_RIGHT() IC_RESULT()
38235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38238 \begin_layout Standard
38246 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38249 \begin_layout Standard
38252 IC_RESULT = IC_LEFT / IC_RIGHT;
38258 <row topline="true">
38259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38262 \begin_layout Standard
38270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38273 \begin_layout Standard
38276 IC_LEFT() IC_RIGHT() IC_RESULT()
38281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38284 \begin_layout Standard
38292 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38295 \begin_layout Standard
38298 IC_RESULT = IC_LEFT % IC_RIGHT;
38304 <row topline="true">
38305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38308 \begin_layout Standard
38316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38319 \begin_layout Standard
38322 IC_LEFT() IC_RIGHT() IC_RESULT()
38327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38330 \begin_layout Standard
38338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38341 \begin_layout Standard
38344 IC_RESULT = IC_LEFT < IC_RIGHT;
38350 <row topline="true">
38351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38354 \begin_layout Standard
38362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38365 \begin_layout Standard
38368 IC_LEFT() IC_RIGHT() IC_RESULT()
38373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38376 \begin_layout Standard
38384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38387 \begin_layout Standard
38390 IC_RESULT = IC_LEFT > IC_RIGHT;
38396 <row topline="true">
38397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38400 \begin_layout Standard
38408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38411 \begin_layout Standard
38414 IC_LEFT() IC_RIGHT() IC_RESULT()
38419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38422 \begin_layout Standard
38430 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38433 \begin_layout Standard
38436 IC_RESULT = IC_LEFT == IC_RIGHT;
38442 <row topline="true">
38443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38446 \begin_layout Standard
38454 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38457 \begin_layout Standard
38460 IC_LEFT() IC_RIGHT() IC_RESULT()
38465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38468 \begin_layout Standard
38471 Logical and operation
38476 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38479 \begin_layout Standard
38482 IC_RESULT = IC_LEFT && IC_RIGHT;
38488 <row topline="true">
38489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38492 \begin_layout Standard
38500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38503 \begin_layout Standard
38506 IC_LEFT() IC_RIGHT() IC_RESULT()
38511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38514 \begin_layout Standard
38517 Logical or operation
38522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38525 \begin_layout Standard
38528 IC_RESULT = IC_LEFT || IC_RIGHT;
38534 <row topline="true">
38535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38538 \begin_layout Standard
38546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38549 \begin_layout Standard
38552 IC_LEFT() IC_RIGHT() IC_RESULT()
38557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38560 \begin_layout Standard
38568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38571 \begin_layout Standard
38574 IC_RESULT = IC_LEFT ^ IC_RIGHT;
38580 <row topline="true">
38581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38584 \begin_layout Standard
38592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38595 \begin_layout Standard
38598 IC_LEFT() IC_RIGHT() IC_RESULT()
38603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38606 \begin_layout Standard
38614 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38617 \begin_layout Standard
38620 IC_RESULT = IC_LEFT | IC_RIGHT;
38626 <row topline="true">
38627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38630 \begin_layout Standard
38638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38641 \begin_layout Standard
38644 IC_LEFT() IC_RIGHT() IC_RESULT()
38649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38652 \begin_layout Standard
38660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38663 \begin_layout Standard
38666 IC_RESULT = IC_LEFT & IC_RIGHT;
38672 <row topline="true">
38673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38676 \begin_layout Standard
38684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38687 \begin_layout Standard
38690 IC_LEFT() IC_RIGHT() IC_RESULT()
38695 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38698 \begin_layout Standard
38706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38709 \begin_layout Standard
38712 IC_RESULT = IC_LEFT << IC_RIGHT
38718 <row topline="true">
38719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38722 \begin_layout Standard
38730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38733 \begin_layout Standard
38736 IC_LEFT() IC_RIGHT() IC_RESULT()
38741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38744 \begin_layout Standard
38752 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38755 \begin_layout Standard
38758 IC_RESULT = IC_LEFT >> IC_RIGHT
38764 <row topline="true">
38765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38768 \begin_layout Standard
38778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38781 \begin_layout Standard
38784 IC_LEFT() IC_RESULT()
38789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38792 \begin_layout Standard
38800 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38803 \begin_layout Standard
38806 IC_RESULT = (*IC_LEFT);
38812 <row topline="true">
38813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38816 \begin_layout Standard
38824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38827 \begin_layout Standard
38830 IC_RIGHT() IC_RESULT()
38835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38838 \begin_layout Standard
38846 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38849 \begin_layout Standard
38852 (*IC_RESULT) = IC_RIGHT;
38858 <row topline="true">
38859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38862 \begin_layout Standard
38870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38873 \begin_layout Standard
38876 IC_RIGHT() IC_RESULT()
38881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38884 \begin_layout Standard
38892 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38895 \begin_layout Standard
38898 IC_RESULT = IC_RIGHT;
38904 <row topline="true">
38905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38908 \begin_layout Standard
38916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38919 \begin_layout Standard
38922 IC_COND IC_TRUE IC_LABEL
38927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38930 \begin_layout Standard
38934 If true label is present then jump to true label if condition is true else
38935 jump to false label if condition is false
38940 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38943 \begin_layout Standard
38946 if (IC_COND) goto IC_TRUE;
38952 If (!IC_COND) goto IC_FALSE;
38958 <row topline="true">
38959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38962 \begin_layout Standard
38970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38973 \begin_layout Standard
38976 IC_LEFT() IC_RESULT()
38981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38984 \begin_layout Standard
38992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38995 \begin_layout Standard
38998 IC_RESULT = &IC_LEFT();
39004 <row topline="true">
39005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39008 \begin_layout Standard
39016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39019 \begin_layout Standard
39022 IC_JTCOND IC_JTLABELS
39027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39030 \begin_layout Standard
39033 Jump to list of labels depending on the value of JTCOND
39038 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39041 \begin_layout Standard
39050 <row topline="true">
39051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39054 \begin_layout Standard
39062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39065 \begin_layout Standard
39068 IC_RIGHT() IC_LEFT() IC_RESULT()
39073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39076 \begin_layout Standard
39084 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39087 \begin_layout Standard
39090 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
39096 <row topline="true">
39097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39100 \begin_layout Standard
39108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39111 \begin_layout Standard
39119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39122 \begin_layout Standard
39125 This is used for passing parameters in registers;
39127 move IC_LEFT to the next
39128 available parameter register.
39133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39136 \begin_layout Standard
39145 <row topline="true">
39146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39149 \begin_layout Standard
39157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39160 \begin_layout Standard
39168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39171 \begin_layout Standard
39174 This is used for receiving parameters passed in registers;
39177 in the next parameter register to IC_RESULT
39182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39185 \begin_layout Standard
39194 <row topline="true" bottomline="true">
39195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39198 \begin_layout Standard
39202 (some more have been added)
39207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39210 \begin_layout Standard
39216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39219 \begin_layout Standard
39225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39228 \begin_layout Standard
39252 \begin_layout Standard
39253 \begin_inset Note Note
39256 \begin_layout Standard
39257 In the original article Figure II was announced to be downloadable on
39262 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
39270 \begin_layout Paragraph*
39272 \begin_inset LatexCommand \index{iCode}
39279 \begin_layout Standard
39280 This section shows some details of iCode.
39281 The example C code does not do anything useful; it is used as an example
39282 to illustrate the intermediate code generated by the compiler.
39285 \begin_layout Verse
39295 /* This function does nothing useful.
39302 for the purpose of explaining iCode */
39305 short function (data
39314 short i=10; \InsetSpace ~
39316 /* dead initialization eliminated */
39322 /* dead initialization eliminated */
39350 /* compiler detects i,j to be induction
39355 for (i = 0, j = 10 ; i < 10 ; i++, j
39361 \begin_layout Standard
39384 mul += i * 3; \InsetSpace ~
39386 /* this multiplication remains */
39393 j * 3;\InsetSpace ~
39395 /* this multiplication changed to addition */
39409 \begin_layout Standard
39410 In addition to the operands each iCode contains information about the filename
39411 and line it corresponds to in the source file.
39412 The first field in the listing should be interpreted as follows:
39417 Filename(linenumber: iCode Execution sequence number : ICode hash table
39418 key : loop depth of the iCode).
39423 Then follows the human readable form of the ICode operation.
39424 Each operand of this triplet form can be of three basic types a) compiler
39425 generated temporary b) user defined variable c) a constant value.
39426 Note that local variables and parameters are replaced by compiler generated
39429 \begin_inset LatexCommand \index{Live range analysis}
39433 are computed only for temporaries (i.e.
39434 live ranges are not computed for global variables).
39436 \begin_inset LatexCommand \index{Register allocation}
39440 are allocated for temporaries only.
39441 Operands are formatted in the following manner:
39446 Operand Name [lr live-from : live-to ] { type information } [ registers
39452 As mentioned earlier the live ranges are computed in terms of the execution
39453 sequence number of the iCodes, for example
39455 the iTemp0 is live from (i.e.
39456 first defined in iCode with execution sequence number 3, and is last used
39457 in the iCode with sequence number 5).
39458 For induction variables such as iTemp21 the live range computation extends
39459 the lifetime from the start to the end of the loop.
39461 The register allocator
39462 used the live range information to allocate registers, the same registers
39463 may be used for different temporaries if their live ranges do not overlap,
39464 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
39465 ranges do not overlap.
39466 In addition the allocator also takes into consideration the type and usage
39467 of a temporary, for example itemp6 is a pointer to near space and is used
39468 as to fetch data from (i.e.
39469 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
39470 Some short lived temporaries are allocated to special registers which have
39471 meaning to the code generator e.g.
39472 iTemp13 is allocated to a pseudo register CC which tells the back end that
39473 the temporary is used only for a conditional jump the code generation makes
39474 use of this information to optimize a compare and jump ICode.
39478 \begin_inset LatexCommand \index{Loop optimization}
39482 performed by the compiler.
39483 It can detect induction variables iTemp21(i) and iTemp23(j).
39484 Also note the compiler does selective strength reduction
39485 \begin_inset LatexCommand \index{Strength reduction}
39490 the multiplication of an induction variable in line 18 (gint = j * 3) is
39491 changed to addition, a new temporary iTemp17 is allocated and assigned
39492 a initial value, a constant 3 is then added for each iteration of the loop.
39493 The compiler does not change the multiplication
39494 \begin_inset LatexCommand \index{Multiplication}
39498 in line 17 however since the processor does support an 8 * 8 bit multiplication.
39501 Note the dead code elimination
39502 \begin_inset LatexCommand \index{Dead-code elimination}
39506 optimization eliminated the dead assignments in line 7 & 8 to I and sum
39512 \begin_layout Standard
39515 Sample.c (5:1:0:0) _entry($9) :
39518 \begin_layout Standard
39521 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
39524 \begin_layout Standard
39527 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
39530 \begin_layout Standard
39533 Sample.c(11:4:53:0) preHeaderLbl0($11) :
39536 \begin_layout Standard
39539 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
39543 \begin_layout Standard
39546 Sample.c(11:6:5:1) _whilecontinue_0($1) :
39549 \begin_layout Standard
39552 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
39556 \begin_layout Standard
39559 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39562 \begin_layout Standard
39565 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
39569 \begin_layout Standard
39572 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
39576 \begin_layout Standard
39579 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
39583 \begin_layout Standard
39586 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
39590 \begin_layout Standard
39593 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
39594 * int}[r0] + 0x2 {short}
39597 \begin_layout Standard
39600 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
39603 \begin_layout Standard
39606 Sample.c(11:17:21:0)_whilebreak_0($3) :
39609 \begin_layout Standard
39612 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39615 \begin_layout Standard
39618 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39621 \begin_layout Standard
39624 Sample.c(15:20:54:0)preHeaderLbl1($13) :
39627 \begin_layout Standard
39630 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39633 \begin_layout Standard
39636 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39639 \begin_layout Standard
39642 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39645 \begin_layout Standard
39648 Sample.c(15:24:26:1)_forcond_0($4) :
39651 \begin_layout Standard
39654 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
39658 \begin_layout Standard
39661 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39664 \begin_layout Standard
39667 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
39668 + ITemp21 [lr21:38]{short}[r4]
39671 \begin_layout Standard
39674 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
39678 \begin_layout Standard
39681 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
39682 + iTemp15 [lr29:30]{short}[r1]
39685 \begin_layout Standard
39688 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
39692 \begin_layout Standard
39695 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
39699 \begin_layout Standard
39702 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
39706 \begin_layout Standard
39709 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
39713 \begin_layout Standard
39716 Sample.c(19:38:47:1) goto _forcond_0($4)
39719 \begin_layout Standard
39722 Sample.c(19:39:48:0)_forbreak_0($7) :
39725 \begin_layout Standard
39728 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
39729 + ITemp11 [lr19:40]{short}[r3]
39732 \begin_layout Standard
39735 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
39738 \begin_layout Standard
39741 Sample.c(20:42:51:0)_return($8) :
39744 \begin_layout Standard
39747 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
39753 Finally the code generated for this function:
39758 \begin_layout Standard
39764 \begin_layout Standard
39770 \begin_layout Standard
39778 \begin_layout Standard
39784 \begin_layout Standard
39792 \begin_layout Standard
39798 \begin_layout Standard
39801 ; ----------------------------------------------
39804 \begin_layout Standard
39807 ; function function
39810 \begin_layout Standard
39813 ; ----------------------------------------------
39816 \begin_layout Standard
39822 \begin_layout Standard
39825 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
39828 \begin_layout Standard
39836 \begin_layout Standard
39839 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
39842 \begin_layout Standard
39850 \begin_layout Standard
39853 ;_whilecontinue_0($1) :
39856 \begin_layout Standard
39862 \begin_layout Standard
39865 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
39868 \begin_layout Standard
39871 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39874 \begin_layout Standard
39882 \begin_layout Standard
39890 \begin_layout Standard
39898 \begin_layout Standard
39906 \begin_layout Standard
39914 \begin_layout Standard
39922 \begin_layout Standard
39930 \begin_layout Standard
39936 \begin_layout Standard
39939 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
39942 \begin_layout Standard
39950 \begin_layout Standard
39958 \begin_layout Standard
39961 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
39964 \begin_layout Standard
39972 \begin_layout Standard
39980 \begin_layout Standard
39988 \begin_layout Standard
39996 \begin_layout Standard
40004 \begin_layout Standard
40012 \begin_layout Standard
40015 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
40018 \begin_layout Standard
40026 \begin_layout Standard
40034 \begin_layout Standard
40042 \begin_layout Standard
40050 \begin_layout Standard
40058 \begin_layout Standard
40061 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
40064 \begin_layout Standard
40072 \begin_layout Standard
40080 \begin_layout Standard
40088 \begin_layout Standard
40091 ; iTemp6 [lr5:16]{_near * int}[r0] =
40094 \begin_layout Standard
40097 ; iTemp6 [lr5:16]{_near * int}[r0] +
40100 \begin_layout Standard
40106 \begin_layout Standard
40114 \begin_layout Standard
40117 ; goto _whilecontinue_0($1)
40120 \begin_layout Standard
40128 \begin_layout Standard
40131 ; _whilebreak_0($3) :
40134 \begin_layout Standard
40140 \begin_layout Standard
40143 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
40146 \begin_layout Standard
40154 \begin_layout Standard
40157 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
40160 \begin_layout Standard
40168 \begin_layout Standard
40171 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
40174 \begin_layout Standard
40182 \begin_layout Standard
40185 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
40188 \begin_layout Standard
40196 \begin_layout Standard
40204 \begin_layout Standard
40207 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
40210 \begin_layout Standard
40218 \begin_layout Standard
40226 \begin_layout Standard
40232 \begin_layout Standard
40238 \begin_layout Standard
40241 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
40244 \begin_layout Standard
40247 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
40250 \begin_layout Standard
40258 \begin_layout Standard
40266 \begin_layout Standard
40274 \begin_layout Standard
40282 \begin_layout Standard
40290 \begin_layout Standard
40296 \begin_layout Standard
40299 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
40302 \begin_layout Standard
40305 ; iTemp21 [lr21:38]{short}[r4]
40308 \begin_layout Standard
40316 \begin_layout Standard
40324 \begin_layout Standard
40332 \begin_layout Standard
40335 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
40338 \begin_layout Standard
40346 \begin_layout Standard
40354 \begin_layout Standard
40362 \begin_layout Standard
40370 \begin_layout Standard
40373 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
40376 \begin_layout Standard
40379 ; iTemp15 [lr29:30]{short}[r1]
40382 \begin_layout Standard
40390 \begin_layout Standard
40398 \begin_layout Standard
40401 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
40404 \begin_layout Standard
40412 \begin_layout Standard
40420 \begin_layout Standard
40428 \begin_layout Standard
40436 \begin_layout Standard
40444 \begin_layout Standard
40452 \begin_layout Standard
40455 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
40458 \begin_layout Standard
40466 \begin_layout Standard
40474 \begin_layout Standard
40482 \begin_layout Standard
40490 \begin_layout Standard
40498 \begin_layout Standard
40506 \begin_layout Standard
40509 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
40512 \begin_layout Standard
40520 \begin_layout Standard
40523 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
40526 \begin_layout Standard
40534 \begin_layout Standard
40539 cjne r5,#0xff,00104$
40542 \begin_layout Standard
40550 \begin_layout Standard
40553 ; goto _forcond_0($4)
40556 \begin_layout Standard
40564 \begin_layout Standard
40567 ; _forbreak_0($7) :
40570 \begin_layout Standard
40576 \begin_layout Standard
40579 ; ret iTemp24 [lr40:41]{short}
40582 \begin_layout Standard
40590 \begin_layout Standard
40598 \begin_layout Standard
40606 \begin_layout Standard
40612 \begin_layout Standard
40618 \begin_layout Standard
40628 \begin_layout Section
40629 A few words about basic block successors, predecessors and dominators
40632 \begin_layout Standard
40633 Successors are basic blocks
40634 \begin_inset LatexCommand \index{Basic blocks}
40638 that might execute after this basic block.
40640 Predecessors are basic blocks
40641 that might execute before reaching this basic block.
40643 Dominators are basic
40644 blocks that WILL execute before reaching this basic block.
40649 \begin_layout Standard
40653 \begin_layout Standard
40657 \begin_layout Standard
40665 \begin_layout Standard
40669 \begin_layout Standard
40677 \begin_layout Standard
40683 \begin_layout Standard
40684 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
40687 \begin_layout Standard
40688 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
40691 \begin_layout Standard
40692 c) domVect of [BB4] = BB1 ...
40693 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
40697 \begin_layout Chapter
40701 \begin_layout Standard
40702 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/#Who}
40712 Thanks to all the other volunteer developers who have helped with coding,
40713 testing, web-page creation, distribution sets, etc.
40714 You know who you are :-)
40722 Thanks to Sourceforge
40723 \begin_inset LatexCommand \url{http://www.sf.net}
40727 which has hosted the project since 1999 and donates significant download
40736 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
40737 cycles and bandwidth for snapshot builds.
40742 \begin_layout Standard
40743 This document was initially written by Sandeep Dutta
40746 \begin_layout Standard
40747 All product names mentioned herein may be trademarks
40748 \begin_inset LatexCommand \index{Trademarks}
40752 of their respective companies.
40756 \begin_layout Section*
40760 \begin_layout Standard
40761 To avoid confusion, the installation and building options for SDCC itself
40762 (chapter 2) are not part of the index.
40765 \begin_layout Standard
40766 \begin_inset LatexCommand \printindex{}