1 #LyX 1.4.5 created this file. For more info see http://www.lyx.org/
7 \pdfoptionpdfminorversion=3
9 pdftitle={SDCC Compiler User Guide},
10 pdfauthor={SDCC development team},
11 pdfsubject={installation, user manual},
12 pdfkeywords={68hc08 8032 8051 ansi c compiler assembler CPU DS390 embedded development free Floating Point Arithmetic Freescale GPL HC08 inline Intel ISO/IEC 9899:1990 Linux MAC OS X manual Maxim mcs51 Microchip microcontroller open source PIC Unix Windows Z80 Zilog},
13 pdfpagemode=UseOutlines,
15 linkcolor=blue] {hyperref}
19 \emergencystretch=30pt
24 \inputencoding default
27 \paperfontsize default
29 \papersize letterpaper
34 \paperorientation portrait
41 \paragraph_separation indent
43 \quotes_language swedish
47 \tracking_changes false
53 \begin_layout Standard
54 \begin_inset Note Note
57 \begin_layout Standard
58 Please note: double dashed longoptions (e.g.
59 --version) are written this way: -
63 \begin_layout Standard
75 \begin_layout Standard
77 three consecutive dashes would otherwise result in a long resp.
81 \begin_layout Standard
82 Architecture specific stuff (like memory models, code examples) should maybe
86 \begin_layout Standard
87 into seperate sections/chapters/appendices (it is hard to document PIC or
91 \begin_layout Standard
92 a 8051 centered document) - for now simply add.
101 SDCC Compiler User Guide
116 \begin_layout Standard
117 \begin_inset Note Note
120 \begin_layout Standard
121 The above strings enclosed in $ are automatically updated by Subversion
129 \begin_layout Standard
130 \begin_inset LatexCommand \tableofcontents{}
137 \begin_layout Chapter
141 \begin_layout Section
145 \begin_layout Standard
166 ompiler) is free open source, retargettable, optimizing ANSI-C compiler
171 designed for 8 bit Microprocessors.
172 The current version targets Intel MCS51 based Microprocessors (8031, 8032,
174 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
178 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
179 Zilog Z80 based MCUs.
180 It can be retargeted for other microprocessors, support for Microchip PIC,
181 Atmel AVR is under development.
182 The entire source code for the compiler is distributed under GPL.
184 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
189 \begin_inset LatexCommand \index{aslink}
193 , an open source retargetable assembler & linker.
194 SDCC has extensive language extensions suitable for utilizing various microcont
195 rollers and underlying hardware effectively.
200 In addition to the MCU specific optimizations SDCC also does a host of
201 standard optimizations like:
204 \begin_layout Itemize
205 global sub expression elimination,
208 \begin_layout Itemize
209 loop optimizations (loop invariant, strength reduction of induction variables
213 \begin_layout Itemize
214 constant folding & propagation,
217 \begin_layout Itemize
221 \begin_layout Itemize
222 dead code elimination
225 \begin_layout Itemize
233 \begin_layout Standard
234 For the back-end SDCC uses a global register allocation scheme which should
235 be well suited for other 8 bit MCUs.
240 The peep hole optimizer uses a rule based substitution mechanism which
246 Supported data-types are:
249 \begin_layout Standard
251 <lyxtabular version="3" rows="8" columns="5">
253 <column alignment="center" valignment="top" leftline="true" width="0">
254 <column alignment="center" valignment="top" leftline="true" width="0">
255 <column alignment="center" valignment="top" leftline="true" width="0">
256 <column alignment="center" valignment="top" leftline="true" width="0">
257 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
258 <row topline="true" bottomline="true">
259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
262 \begin_layout Standard
268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
271 \begin_layout Standard
277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
280 \begin_layout Standard
286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
289 \begin_layout Standard
295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
298 \begin_layout Standard
306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
309 \begin_layout Standard
315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
318 \begin_layout Standard
324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
327 \begin_layout Standard
333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
336 \begin_layout Standard
342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
345 \begin_layout Standard
353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
356 \begin_layout Standard
362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
365 \begin_layout Standard
371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
374 \begin_layout Standard
380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
383 \begin_layout Standard
389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
392 \begin_layout Standard
400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
403 \begin_layout Standard
409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
412 \begin_layout Standard
418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
421 \begin_layout Standard
427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
430 \begin_layout Standard
436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
439 \begin_layout Standard
447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
450 \begin_layout Standard
456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
459 \begin_layout Standard
465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
468 \begin_layout Standard
474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
477 \begin_layout Standard
483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
486 \begin_layout Standard
493 <row topline="true" bottomline="true">
494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
497 \begin_layout Standard
503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
506 \begin_layout Standard
512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
515 \begin_layout Standard
521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
524 \begin_layout Standard
525 -2.147.483.648, +2.147.483.647
530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
533 \begin_layout Standard
540 <row topline="true" bottomline="true">
541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
544 \begin_layout Standard
550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
553 \begin_layout Standard
559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
562 \begin_layout Standard
568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
571 \begin_layout Standard
577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
580 \begin_layout Standard
596 <row topline="true" bottomline="true">
597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
600 \begin_layout Standard
606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
609 \begin_layout Standard
615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
618 \begin_layout Standard
624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
627 \begin_layout Standard
633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
636 \begin_layout Standard
649 The compiler also allows
651 inline assembler code
653 to be embedded anywhere in a function.
654 In addition, routines developed in assembly can also be called.
659 provides an option (-
663 \begin_layout Standard
672 -cyclomatic) to report the relative complexity of a function.
673 These functions can then be further optimized, or hand coded in assembly
679 SDCC also comes with a companion source level debugger SDCDB.
680 The debugger currently uses ucSim, a free open source simulator for 8051
681 and other micro-controllers.
685 The latest SDCC version can be downloaded from
687 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
697 Please note: the compiler will probably always be some steps ahead of this
702 \begin_inset LatexCommand \index{Status of documentation}
710 \begin_layout Standard
711 Obviously this has pros and cons
719 \begin_layout Section
723 \begin_layout Standard
724 All packages used in this compiler system are
732 ; source code for all the sub-packages (pre-processor, assemblers, linkers
733 etc.) is distributed with the package.
734 This documentation is maintained using a free open source word processor
737 This program is free software; you can redistribute it and/or modify
738 it under the terms of the GNU General Public License
739 \begin_inset LatexCommand \index{GNU General Public License, GPL}
743 as published by the Free Software Foundation; either version 2, or (at
744 your option) any later version.
745 This program is distributed in the hope that it will be useful, but WITHOUT
746 ANY WARRANTY; without even the implied warranty
747 \begin_inset LatexCommand \index{warranty}
751 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
752 See the GNU General Public License for more details.
753 You should have received a copy of the GNU General Public License along
754 with this program; if not, write to the Free Software Foundation, 59 Temple
755 Place - Suite 330, Boston, MA 02111-1307, USA.
756 In other words, you are welcome to use, share and improve this program.
757 You are forbidden to forbid anyone else to use, share and improve what
759 Help stamp out software-hoarding!
762 \begin_layout Section
763 Typographic conventions
764 \begin_inset LatexCommand \index{Typographic conventions}
771 \begin_layout Standard
772 Throughout this manual, we will use the following convention.
773 Commands you have to type in are printed in
781 Code samples are printed in
786 Interesting items and new terms are printed in
791 \begin_layout Section
793 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
797 with previous versions
798 \begin_inset LatexCommand \index{Compatibility with previous versions}
805 \begin_layout Standard
806 Newer versions have usually numerous bug fixes compared with the previous
808 But we also sometimes introduce some incompatibilities with older versions.
809 Not just for the fun of it, but to make the compiler more stable, efficient
811 \begin_inset LatexCommand \index{ANSI-compliance}
816 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
820 for ANSI-Compliance).
822 \begin_inset Note Note
825 \begin_layout Standard
826 It would be fine to add to each item, in which version was it changed.
836 \begin_layout Itemize
837 short is now equivalent to int (16 bits), it used to be equivalent to char
838 (8 bits) which is not ANSI compliant.
839 To maintain compatibility, old programs may be compiled using the -
843 \begin_layout Standard
852 -short-is-8bits commandline option (see
853 \begin_inset LatexCommand \vref{lyx:--short-is-8bits}
860 \begin_layout Itemize
861 the default directory for gcc-builds where include, library and documentation
862 files are stored is now in /usr/local/share.
865 \begin_layout Itemize
866 char type parameters to vararg
867 \begin_inset LatexCommand \index{vararg, va\_arg}
871 functions are casted to int unless explicitly casted and
877 \begin_layout Standard
887 \begin_inset LatexCommand \index{-\/-std-c89}
899 \begin_layout Standard
909 \begin_inset LatexCommand \index{-\/-std-c99}
915 command line option are not defined
916 \begin_inset Marginal
919 \begin_layout Standard
944 will push a as an int and as a char resp if
950 \begin_layout Standard
960 \begin_inset LatexCommand \index{-\/-std-c89}
972 \begin_layout Standard
982 \begin_inset LatexCommand \index{-\/-std-c99}
988 command line options are not defined,
990 will push a as two ints if
996 \begin_layout Standard
1006 \begin_inset LatexCommand \index{-\/-std-c89}
1018 \begin_layout Standard
1028 \begin_inset LatexCommand \index{-\/-std-c99}
1034 command line option is defined.
1037 \begin_layout Itemize
1042 \begin_layout Standard
1051 -regextend has been removed.
1054 \begin_layout Itemize
1059 \begin_layout Standard
1068 -noregparms has been removed.
1071 \begin_layout Itemize
1076 \begin_layout Standard
1085 -stack-after-data has been removed.
1088 \begin_layout Itemize
1090 \begin_inset LatexCommand \index{bit}
1095 \begin_inset LatexCommand \index{sbit}
1100 \begin_inset LatexCommand \index{\_\_sbit}
1104 types now consistently behave like the C99 _Bool type with respect to type
1106 \begin_inset LatexCommand \index{type conversion}
1111 \begin_inset LatexCommand \index{type promotion}
1116 The most common incompatibility resulting from this change is related to
1118 \begin_inset LatexCommand \index{Bit toggling}
1133 \begin_inset LatexCommand \index{\~\/ Operator}
1137 b; /* equivalent to b=1 instead of toggling b */
1138 \begin_inset Marginal
1141 \begin_layout Standard
1154 b = !b; /* toggles b */
1158 In previous versions, both forms would have toggled the bit.
1161 \begin_layout Standard
1164 <pending: more incompatibilities?>
1167 \begin_layout Section
1171 \begin_layout Standard
1172 What do you need before you start installation of SDCC? A computer, and
1173 a desire to compute.
1174 The preferred method of installation is to compile SDCC from source using
1176 For Windows some pre-compiled binary distributions are available for your
1178 You should have some experience with command line tools and compiler use.
1181 \begin_layout Section
1185 \begin_layout Standard
1186 The SDCC home page at
1187 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1191 is a great place to find distribution sets.
1192 You can also find links to the user mailing lists that offer help or discuss
1193 SDCC with other SDCC users.
1194 Web links to other SDCC related sites can also be found here.
1195 This document can be found in the DOC directory of the source package as
1196 a text or HTML file.
1197 A pdf version of this document is available at
1198 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1203 Some of the other tools (simulator and assembler) included with SDCC contain
1204 their own documentation and can be found in the source distribution.
1205 If you want the latest unreleased software, the complete source package
1206 is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1210 \begin_layout Section
1211 Wishes for the future
1214 \begin_layout Standard
1215 There are (and always will be) some things that could be done.
1216 Here are some I can think of:
1221 \begin_layout Standard
1224 char KernelFunction3(char p) at 0x340;
1229 \begin_layout Standard
1233 \begin_inset LatexCommand \index{code banking (limited support)}
1243 If you can think of some more, please see the section
1244 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1248 about filing feature requests
1249 \begin_inset LatexCommand \index{Requesting features}
1254 \begin_inset LatexCommand \index{Feature request}
1263 \begin_layout Chapter
1265 \begin_inset LatexCommand \index{Installation}
1272 \begin_layout Standard
1273 For most users it is sufficient to skip to either section
1274 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1279 \begin_inset LatexCommand \ref{sub:Windows-Install}
1284 More detailed instructions follow below.
1287 \begin_layout Section
1289 \begin_inset LatexCommand \index{Options SDCC configuration}
1296 \begin_layout Standard
1297 The install paths, search paths and other options are defined when running
1299 The defaults can be overridden by:
1303 \labelwidthstring 00.00.0000
1308 \begin_layout Standard
1317 -prefix see table below
1321 \labelwidthstring 00.00.0000
1326 \begin_layout Standard
1335 -exec_prefix see table below
1339 \labelwidthstring 00.00.0000
1344 \begin_layout Standard
1353 -bindir see table below
1357 \labelwidthstring 00.00.0000
1362 \begin_layout Standard
1371 -datadir see table below
1375 \labelwidthstring 00.00.0000
1380 \begin_layout Standard
1389 -datarootdir see table below
1395 \labelwidthstring 00.00.0000
1398 docdir environment variable, see table below
1402 \labelwidthstring 00.00.0000
1405 include_dir_suffix environment variable, see table below
1409 \labelwidthstring 00.00.0000
1412 lib_dir_suffix environment variable, see table below
1416 \labelwidthstring 00.00.0000
1419 sdccconf_h_dir_separator environment variable, either / or
1424 This character will only be used in sdccconf.h; don't forget it's a C-header,
1425 therefore a double-backslash is needed there.
1431 \labelwidthstring 00.00.0000
1436 \begin_layout Standard
1445 -disable-mcs51-port Excludes the Intel mcs51 port
1449 \labelwidthstring 00.00.0000
1454 \begin_layout Standard
1463 -disable-gbz80-port Excludes the Gameboy gbz80 port
1467 \labelwidthstring 00.00.0000
1472 \begin_layout Standard
1481 -disable-z80-port Excludes the z80 port
1485 \labelwidthstring 00.00.0000
1490 \begin_layout Standard
1499 -disable-avr-port Excludes the AVR port
1503 \labelwidthstring 00.00.0000
1508 \begin_layout Standard
1517 -disable-ds390-port Excludes the DS390 port
1521 \labelwidthstring 00.00.0000
1526 \begin_layout Standard
1535 -disable-hc08-port Excludes the HC08 port
1539 \labelwidthstring 00.00.0000
1544 \begin_layout Standard
1553 -disable-pic-port Excludes the PIC14 port
1557 \labelwidthstring 00.00.0000
1562 \begin_layout Standard
1571 -disable-pic16-port Excludes the PIC16 port
1575 \labelwidthstring 00.00.0000
1580 \begin_layout Standard
1589 -disable-xa51-port Excludes the XA51 port
1593 \labelwidthstring 00.00.0000
1598 \begin_layout Standard
1607 -disable-ucsim Disables configuring and building of ucsim
1611 \labelwidthstring 00.00.0000
1616 \begin_layout Standard
1625 -disable-device-lib Disables automatically building device libraries
1629 \labelwidthstring 00.00.0000
1634 \begin_layout Standard
1643 -disable-packihx Disables building packihx
1649 \labelwidthstring 00.00.0000
1654 \begin_layout Standard
1663 -enable-doc Build pdf, html and txt files from the lyx sources
1667 \labelwidthstring 00.00.0000
1672 \begin_layout Standard
1681 -enable-libgc Use the Bohem memory allocator.
1682 Lower runtime footprint.
1685 \begin_layout Standard
1686 Furthermore the environment variables CC, CFLAGS, ...
1687 the tools and their arguments can be influenced.
1688 Please see `configure -
1692 \begin_layout Standard
1701 -help' and the man/info pages of `configure' for details.
1706 standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1707 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1708 SDCC_LIB_NAME are defined by `configure' too.
1709 At the moment it's not possible to change the default settings (it was
1710 simply never required).
1714 These configure options are compiled into the binaries,
1715 and can only be changed by rerunning 'configure' and recompiling SDCC.
1716 The configure options are written in
1720 to distinguish them from run time environment variables (see section search
1726 \begin_inset Quotes sld
1730 \begin_inset Quotes srd
1733 are used by the SDCC team to build the official Win32 binaries.
1734 The SDCC team uses Mingw32 to build the official Windows binaries, because
1738 \begin_layout Enumerate
1742 \begin_layout Enumerate
1743 a gcc compiler and last but not least
1746 \begin_layout Enumerate
1747 the binaries can be built by cross compiling on SDCC Distributed Compile
1751 \begin_layout Standard
1752 See the examples, how to pass the Win32 settings to 'configure'.
1753 The other Win32 builds using Borland, VC or whatever don't use 'configure',
1754 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1764 \begin_layout Standard
1766 \begin_inset Tabular
1767 <lyxtabular version="3" rows="9" columns="3">
1769 <column alignment="block" valignment="top" leftline="true" width="0in">
1770 <column alignment="block" valignment="top" leftline="true" width="0in">
1771 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1772 <row topline="true" bottomline="true">
1773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1776 \begin_layout Standard
1782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1785 \begin_layout Standard
1791 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1794 \begin_layout Standard
1801 <row topline="true">
1802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1805 \begin_layout Standard
1813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1816 \begin_layout Standard
1822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1825 \begin_layout Standard
1834 <row topline="true">
1835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1838 \begin_layout Standard
1846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1849 \begin_layout Standard
1857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1860 \begin_layout Standard
1869 <row topline="true">
1870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1873 \begin_layout Standard
1881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1884 \begin_layout Standard
1894 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1897 \begin_layout Standard
1910 <row topline="true">
1911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1914 \begin_layout Standard
1922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1925 \begin_layout Standard
1933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1936 \begin_layout Standard
1945 <row topline="true">
1946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1949 \begin_layout Standard
1957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1960 \begin_layout Standard
1970 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1973 \begin_layout Standard
1982 <row topline="true">
1983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1986 \begin_layout Standard
1994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1997 \begin_layout Standard
2007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2010 \begin_layout Standard
2023 <row topline="true">
2024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2027 \begin_layout Standard
2035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2038 \begin_layout Standard
2044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2047 \begin_layout Standard
2054 <row topline="true" bottomline="true">
2055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2058 \begin_layout Standard
2066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2069 \begin_layout Standard
2075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2078 \begin_layout Standard
2094 \begin_layout Standard
2096 'configure' also computes relative paths.
2097 This is needed for full relocatability of a binary package and to complete
2098 search paths (see section search paths below):
2103 \begin_layout Standard
2105 \begin_inset Tabular
2106 <lyxtabular version="3" rows="4" columns="3">
2108 <column alignment="block" valignment="top" leftline="true" width="0in">
2109 <column alignment="block" valignment="top" leftline="true" width="0in">
2110 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2111 <row topline="true" bottomline="true">
2112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2115 \begin_layout Standard
2121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2124 \begin_layout Standard
2130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2133 \begin_layout Standard
2140 <row topline="true" bottomline="true">
2141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2144 \begin_layout Standard
2152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2155 \begin_layout Standard
2161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2164 \begin_layout Standard
2171 <row bottomline="true">
2172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2175 \begin_layout Standard
2183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2186 \begin_layout Standard
2192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2195 \begin_layout Standard
2202 <row bottomline="true">
2203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2206 \begin_layout Standard
2214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2217 \begin_layout Standard
2223 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2226 \begin_layout Standard
2242 \begin_layout Standard
2247 \begin_layout LyX-Code
2254 \begin_layout Standard
2264 \begin_inset Quotes srd
2268 \begin_inset Quotes srd
2275 \begin_layout Standard
2285 \begin_inset Quotes srd
2289 \begin_inset Quotes srd
2298 \begin_layout Standard
2311 \begin_layout Standard
2323 \begin_layout Standard
2324 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2328 \begin_layout LyX-Code
2334 \begin_inset Quotes srd
2337 i586-mingw32msvc-gcc
2338 \begin_inset Quotes srd
2342 \begin_inset Quotes srd
2345 i586-mingw32msvc-g++
2346 \begin_inset Quotes srd
2354 \begin_inset Quotes srd
2357 i586-mingw32msvc-ranlib
2358 \begin_inset Quotes srd
2366 \begin_inset Quotes srd
2369 i586-mingw32msvc-strip
2370 \begin_inset Quotes srd
2381 \begin_layout Standard
2391 \begin_inset Quotes srd
2395 \begin_inset Quotes srd
2406 \begin_layout Standard
2416 \begin_inset Quotes srd
2420 \begin_inset Quotes srd
2428 \begin_inset Quotes srd
2434 \begin_inset Quotes srd
2442 \begin_inset Quotes srd
2446 \begin_inset Quotes srd
2454 \begin_inset Quotes srd
2458 \begin_inset Quotes srd
2465 sdccconf_h_dir_separator=
2466 \begin_inset Quotes srd
2478 \begin_inset Quotes srd
2489 \begin_layout Standard
2506 \begin_layout Standard
2515 -host=i586-mingw32msvc
2523 \begin_layout Standard
2532 -build=unknown-unknown-linux-gnu
2535 \begin_layout Standard
2537 \begin_inset Quotes sld
2541 \begin_inset Quotes srd
2544 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2548 \begin_layout LyX-Code
2557 \begin_layout Standard
2567 \begin_inset Quotes srd
2571 \begin_inset Quotes srd
2582 \begin_layout Standard
2592 \begin_inset Quotes srd
2596 \begin_inset Quotes srd
2604 \begin_inset Quotes srd
2610 \begin_inset Quotes srd
2618 \begin_inset Quotes srd
2622 \begin_inset Quotes srd
2630 \begin_inset Quotes srd
2634 \begin_inset Quotes srd
2641 sdccconf_h_dir_separator=
2642 \begin_inset Quotes srd
2654 \begin_inset Quotes srd
2662 \begin_inset Quotes srd
2666 \begin_inset Quotes srd
2674 \begin_inset Quotes srd
2678 \begin_inset Quotes srd
2684 \begin_layout Standard
2685 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2690 \begin_layout Standard
2699 -C' turns on caching, which gives a little bit extra speed.
2700 However if options are changed, it can be necessary to delete the config.cache
2704 \begin_layout Section
2706 \begin_inset LatexCommand \label{sub:Install-paths}
2711 \begin_inset LatexCommand \index{Install paths}
2718 \begin_layout Standard
2719 \begin_inset VSpace medskip
2725 \begin_layout Standard
2727 \begin_inset Tabular
2728 <lyxtabular version="3" rows="5" columns="4">
2730 <column alignment="left" valignment="top" leftline="true" width="0">
2731 <column alignment="left" valignment="top" leftline="true" width="0">
2732 <column alignment="left" valignment="top" leftline="true" width="0">
2733 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2734 <row topline="true" bottomline="true">
2735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2738 \begin_layout Standard
2746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2749 \begin_layout Standard
2757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2760 \begin_layout Standard
2768 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2771 \begin_layout Standard
2780 <row topline="true">
2781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2784 \begin_layout Standard
2790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2793 \begin_layout Standard
2801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2804 \begin_layout Standard
2810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2813 \begin_layout Standard
2824 <row topline="true">
2825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2828 \begin_layout Standard
2834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2837 \begin_layout Standard
2840 $DATADIR/ $INCLUDE_DIR_SUFFIX
2845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2848 \begin_layout Standard
2849 /usr/local/share/sdcc/include
2854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2857 \begin_layout Standard
2868 <row topline="true">
2869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2872 \begin_layout Standard
2878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2881 \begin_layout Standard
2884 $DATADIR/$LIB_DIR_SUFFIX
2889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2892 \begin_layout Standard
2893 /usr/local/share/sdcc/lib
2898 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2901 \begin_layout Standard
2912 <row topline="true" bottomline="true">
2913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2916 \begin_layout Standard
2922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2925 \begin_layout Standard
2933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2936 \begin_layout Standard
2937 /usr/local/share/sdcc/doc
2942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2945 \begin_layout Standard
2966 *compiler, preprocessor, assembler, and linker
2972 is auto-appended by the compiler, e.g.
2973 small, large, z80, ds390 etc
2976 \begin_layout Standard
2978 The install paths can still be changed during `make install' with e.g.:
2981 \begin_layout LyX-Code
2982 make install prefix=$(HOME)/local/sdcc
2985 \begin_layout Standard
2986 Of course this doesn't change the search paths compiled into the binaries.
2991 r the install path can be changed by defining DESTDIR
2992 \begin_inset LatexCommand \index{DESTDIR}
2999 \begin_layout LyX-Code
3000 make install DESTDIR=$(HOME)/sdcc.rpm/
3003 \begin_layout Standard
3004 Please note that DESTDIR must have a trailing slash!
3007 \begin_layout Section
3009 \begin_inset LatexCommand \label{sub:Search-Paths}
3014 \begin_inset LatexCommand \index{Search path}
3021 \begin_layout Standard
3022 Some search paths or parts of them are determined by configure variables
3027 , see section above).
3028 Further search paths are determined by environment variables during runtime.
3031 The paths searched when running the compiler are as follows (the first
3037 Binary files (preprocessor, assembler and linker)
3042 \begin_layout Standard
3044 \begin_inset Tabular
3045 <lyxtabular version="3" rows="4" columns="3">
3047 <column alignment="block" valignment="top" leftline="true" width="0in">
3048 <column alignment="block" valignment="top" leftline="true" width="0in">
3049 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3050 <row topline="true" bottomline="true">
3051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3054 \begin_layout Standard
3060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3063 \begin_layout Standard
3069 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3072 \begin_layout Standard
3079 <row topline="true">
3080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3083 \begin_layout Standard
3091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3094 \begin_layout Standard
3100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3103 \begin_layout Standard
3112 <row topline="true">
3113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3116 \begin_layout Standard
3117 Path of argv[0] (if available)
3122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3125 \begin_layout Standard
3131 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3134 \begin_layout Standard
3141 <row topline="true" bottomline="true">
3142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3145 \begin_layout Standard
3151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3154 \begin_layout Standard
3160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3163 \begin_layout Standard
3179 \begin_layout Standard
3187 \begin_layout Standard
3189 \begin_inset Tabular
3190 <lyxtabular version="3" rows="6" columns="3">
3192 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3193 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3194 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3195 <row topline="true" bottomline="true">
3196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3199 \begin_layout Standard
3205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3208 \begin_layout Standard
3214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3217 \begin_layout Standard
3224 <row topline="true">
3225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3228 \begin_layout Standard
3233 \begin_layout Standard
3247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3250 \begin_layout Standard
3255 \begin_layout Standard
3269 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3272 \begin_layout Standard
3277 \begin_layout Standard
3292 <row topline="true">
3293 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3296 \begin_layout Standard
3302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3305 \begin_layout Standard
3311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3314 \begin_layout Standard
3321 <row topline="true">
3322 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3325 \begin_layout Standard
3337 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3340 \begin_layout Standard
3350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3353 \begin_layout Standard
3362 <row topline="true">
3363 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3366 \begin_layout Standard
3382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3385 \begin_layout Standard
3433 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3436 \begin_layout Standard
3447 <row topline="true" bottomline="true">
3448 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3451 \begin_layout Standard
3465 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3468 \begin_layout Standard
3469 /usr/local/share/sdcc/
3476 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3479 \begin_layout Standard
3495 \begin_layout Standard
3501 \begin_layout Standard
3510 -nostdinc disables the last two search paths.
3520 \begin_layout Standard
3521 With the exception of
3522 \begin_inset Quotes sld
3529 \begin_layout Standard
3539 \begin_inset Quotes srd
3546 is auto-appended by the compiler (e.g.
3547 small, large, z80, ds390 etc.).
3553 \begin_layout Standard
3555 \begin_inset Tabular
3556 <lyxtabular version="3" rows="6" columns="3">
3558 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3559 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3560 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3561 <row topline="true" bottomline="true">
3562 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3565 \begin_layout Standard
3571 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3574 \begin_layout Standard
3580 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3583 \begin_layout Standard
3590 <row topline="true">
3591 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3594 \begin_layout Standard
3599 \begin_layout Standard
3613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3616 \begin_layout Standard
3621 \begin_layout Standard
3635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3638 \begin_layout Standard
3643 \begin_layout Standard
3658 <row topline="true">
3659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3662 \begin_layout Standard
3672 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3675 \begin_layout Standard
3685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3688 \begin_layout Standard
3701 <row topline="true">
3702 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3705 \begin_layout Standard
3712 $LIB_DIR_SUFFIX/<model>
3717 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3720 \begin_layout Standard
3732 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3735 \begin_layout Standard
3750 <row topline="true">
3751 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3754 \begin_layout Standard
3765 $LIB_DIR_SUFFIX/<model>
3770 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3773 \begin_layout Standard
3824 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3827 \begin_layout Standard
3881 <row topline="true" bottomline="true">
3882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3885 \begin_layout Standard
3890 $LIB_DIR_SUFFIX/<model>
3895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3898 \begin_layout Standard
3899 /usr/local/share/sdcc/
3908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3911 \begin_layout Standard
3927 \begin_layout Standard
3928 \begin_inset Note Note
3931 \begin_layout Standard
3932 Don't delete any of the stray spaces in the table above without checking
3933 the HTML output (last line)!
3941 \begin_layout Standard
3949 \begin_layout Standard
3958 -nostdlib disables the last two search paths.
3961 \begin_layout Section
3963 \begin_inset LatexCommand \index{Building SDCC}
3970 \begin_layout Subsection
3971 Building SDCC on Linux
3972 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3979 \begin_layout Enumerate
3982 Download the source package
3984 either from the SDCC Subversion repository or from snapshot builds
3986 , it will be named something like sdcc
3997 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
4004 \begin_layout Enumerate
4007 Bring up a command line terminal, such as xterm.
4010 \begin_layout Enumerate
4013 Unpack the file using a command like:
4016 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
4017 \begin_inset Quotes srd
4023 , this will create a sub-directory called sdcc with all of the sources.
4026 \begin_layout Enumerate
4027 Change directory into the main SDCC directory, for example type:
4035 \begin_layout Enumerate
4045 This configures the package for compilation on your system.
4048 \begin_layout Enumerate
4062 All of the source packages will compile, this can take a while.
4065 \begin_layout Enumerate
4079 This copies the binary executables, the include files, the libraries and
4080 the documentation to the install directories.
4081 Proceed with section
4082 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
4089 \begin_layout Subsection
4090 Building SDCC on Mac OS X
4093 \begin_layout Standard
4094 Follow the instruction for Linux.
4098 On Mac OS X 10.2.x it was reported, that the
4099 default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
4100 Fortunately there's also gcc 2.9.x installed, which works fine.
4101 This compiler can be selected by running 'configure' with:
4104 \begin_layout LyX-Code
4105 ./configure CC=gcc2 CXX=g++2
4108 \begin_layout Standard
4109 Universal (ppc and i386) binaries can be produced on Mac OS X 10.4.x with
4111 Run 'configure' with:
4114 \begin_layout LyX-Code
4120 \begin_layout LyX-Code
4121 LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4127 \begin_layout LyX-Code
4128 CXXFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4134 \begin_layout LyX-Code
4135 CFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
4138 \begin_layout Subsection
4139 Cross compiling SDCC on Linux for Windows
4142 \begin_layout Standard
4143 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
4144 See section 'Configure Options'.
4147 \begin_layout Subsection
4148 Building SDCC using Cygwin and Mingw32
4151 \begin_layout Standard
4152 For building and installing a Cygwin executable follow the instructions
4158 \begin_inset Quotes sld
4162 \begin_inset Quotes srd
4165 Win32-binary can be built, which will not need the Cygwin-DLL.
4166 For the necessary 'configure' options see section 'configure options' or
4167 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4172 Cygwin on Windows download setup.exe from
4173 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
4179 \begin_inset Quotes sld
4182 default text file type
4183 \begin_inset Quotes srd
4187 \begin_inset Quotes sld
4191 \begin_inset Quotes srd
4194 and download/install at least the following packages.
4195 Some packages are selected by default, others will be automatically selected
4196 because of dependencies with the manually selected packages.
4197 Never deselect these packages!
4200 \begin_layout Itemize
4204 \begin_layout Itemize
4208 \begin_layout Itemize
4209 gcc ; version 3.x is fine, no need to use the old 2.9x
4212 \begin_layout Itemize
4213 binutils ; selected with gcc
4216 \begin_layout Itemize
4220 \begin_layout Itemize
4221 rxvt ; a nice console, which makes life much easier under windoze (see below)
4224 \begin_layout Itemize
4225 man ; not really needed for building SDCC, but you'll miss it sooner or
4229 \begin_layout Itemize
4230 less ; not really needed for building SDCC, but you'll miss it sooner or
4234 \begin_layout Itemize
4235 svn ; only if you use Subversion access
4238 \begin_layout Standard
4239 If you want to develop something you'll need:
4242 \begin_layout Itemize
4243 python ; for the regression tests
4246 \begin_layout Itemize
4247 gdb ; the gnu debugger, together with the nice GUI
4248 \begin_inset Quotes sld
4252 \begin_inset Quotes srd
4258 \begin_layout Itemize
4259 openssh ; to access the CF or commit changes
4262 \begin_layout Itemize
4263 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4264 use autoconf-stable!
4267 \begin_layout Standard
4268 rxvt is a nice console with history.
4269 Replace in your cygwin.bat the line
4272 \begin_layout LyX-Code
4277 \begin_layout Standard
4289 \begin_layout Standard
4293 \begin_layout LyX-Code
4294 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4297 \begin_layout LyX-Code
4298 -bg black -fg white -geometry 100x65 -e bash -
4302 \begin_layout Standard
4314 \begin_layout Standard
4315 Text selected with the mouse is automatically copied to the clipboard, pasting
4316 works with shift-insert.
4320 The other good tip is to make sure you have no //c/-styl
4321 e paths anywhere, use /cygdrive/c/ instead.
4322 Using // invokes a network lookup which is very slow.
4324 \begin_inset Quotes sld
4328 \begin_inset Quotes srd
4331 is too long, you can change it with e.g.
4334 \begin_layout LyX-Code
4338 \begin_layout Standard
4339 SDCC sources use the unix line ending LF.
4340 Life is much easier, if you store the source tree on a drive which is mounted
4342 And use an editor which can handle LF-only line endings.
4343 Make sure not to commit files with windows line endings.
4344 The tabulator spacing
4345 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4349 used in the project is 8.
4350 Although a tabulator spacing of 8 is a sensible choice for programmers
4351 (it's a power of 2 and allows to display 8/16 bit signed variables without
4352 loosing columns) the plan is to move towards using only spaces in the source.
4355 \begin_layout Subsection
4356 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4359 \begin_layout Standard
4362 Download the source package
4364 either from the SDCC Subversion repository or from the
4365 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4371 , it will be named something like sdcc
4375 -yyyymmdd-rrrr.tar.bz2.
4378 SDCC is distributed with all the projects, workspaces, and files you need
4379 to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4380 The workspace name is 'sdcc.dsw'.
4381 Please note that as it is now, all the executables are created in a folder
4385 Once built you need to copy the executables from sdcc
4389 bin before running SDCC.
4394 WARNING: Visual studio is very picky with line terminations; it expects
4395 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4396 When using the Subversion repository it's easiest to configure the svn
4397 client to convert automatically for you.
4398 If however you are getting a message such as "This makefile was not generated
4399 by Developer Studio etc.
4401 \begin_inset Quotes srd
4404 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4405 need to convert the Unix style line endings to DOS style line endings.
4406 To do so you can use the
4407 \begin_inset Quotes sld
4411 \begin_inset Quotes srd
4414 utility freely available on the internet.
4415 Doug Hawkins reported in the sdcc-user list that this works:
4423 SDCC> unix2dos sdcc.dsw
4429 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4433 In order to build SDCC with MSVC
4434 you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4435 One good place to get them is
4436 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4444 Download the file UnxUtils
4445 \begin_inset LatexCommand \index{UnxUtils}
4450 Now you have to install the utilities and setup MSVC so it can locate the
4452 Here there are two alternatives (choose one!):
4455 \begin_layout Enumerate
4460 a) Extract UnxUtils.zip to your C:
4462 hard disk PRESERVING the original paths, otherwise bison won't work.
4463 (If you are using WinZip make certain that 'Use folder names' is selected)
4468 In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4469 'Show directories for:' select 'Executable files', and in the directories
4470 window add a new path: 'C:
4480 (As a side effect, you get a bunch of Unix utilities that
4481 could be useful, such as diff and patch.)
4484 \begin_layout Enumerate
4489 This one avoids extracting a bunch of files you may not
4490 use, but requires some extra work:
4494 a) Create a directory were to put the
4495 tools needed, or use a directory already present.
4502 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4503 gawk.exe to such directory WITHOUT preserving the original paths.
4504 (If you are using WinZip make certain that 'Use folder names' is not selected)
4509 ) Rename bison.exe to '_bison.exe'.
4513 d) Create a batch file 'bison.bat' in 'C:
4517 ' and add these lines:
4537 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4541 Steps 'c' and 'd' are needed
4542 because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4543 reside in some weird Unix directory, '/usr/local/share/' I think.
4544 So it is necessary to tell bison where those files are located if they
4545 are not in such directory.
4546 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4551 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4552 in 'Show directories for:' select 'Executable files', and in the directories
4553 window add a new path: 'c:
4556 Note that you can use any other path instead of 'c:
4558 util', even the path where the Visual C++ tools are, probably: 'C:
4562 Microsoft Visual Studio
4567 So you don't have to execute step 'e' :)
4570 \begin_layout Standard
4572 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4573 the executables from sdcc
4577 bin, and you can compile using SDCC.
4580 \begin_layout Subsection
4581 Building SDCC Using Borland
4584 \begin_layout Enumerate
4585 From the sdcc directory, run the command "make -f Makefile.bcc".
4586 This should regenerate all the .exe files in the bin directory except for
4590 \begin_layout Enumerate
4591 If you modify any source files and need to rebuild, be aware that the dependenci
4592 es may not be correctly calculated.
4593 The safest option is to delete all .obj files and run the build again.
4594 From a Cygwin BASH prompt, this can easily be done with the command (be
4595 sure you are in the sdcc directory):
4605 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
4607 ) -print -exec rm {}
4616 or on Windows NT/2000/XP from the command prompt with the command:
4623 del /s *.obj *.lib *.rul
4626 from the sdcc directory.
4629 \begin_layout Subsection
4630 Windows Install Using a ZIP Package
4633 \begin_layout Enumerate
4634 Download the binary zip package from
4635 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4639 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4640 This should unpack to a group of sub-directories.
4641 An example directory structure after unpacking the mingw32 package is:
4646 bin for the executables, c:
4654 lib for the include and libraries.
4657 \begin_layout Enumerate
4658 Adjust your environment variable PATH to include the location of the bin
4659 directory or start sdcc using the full path.
4662 \begin_layout Subsection
4663 Windows Install Using the Setup Program
4664 \begin_inset LatexCommand \label{sub:Windows-Install}
4671 \begin_layout Standard
4672 Download the setup program
4674 sdcc-x.y.z-setup.exe
4676 for an official release from
4679 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4683 or a setup program for one of the snapshots
4685 sdcc-yyyymmdd-xxxx-setup.exe
4688 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4693 A windows typical installer will guide you through the installation process.
4696 \begin_layout Subsection
4698 \begin_inset LatexCommand \index{VPATH}
4705 \begin_layout Standard
4706 SDCC supports the VPATH feature provided by configure and make.
4707 It allows to separate the source and build trees.
4711 \begin_layout Standard
4738 \begin_layout Standard
4741 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4742 # extract source to directory sdcc
4745 \begin_layout Standard
4748 mkdir sdcc.build\InsetSpace ~
4757 # put output in sdcc.build
4760 \begin_layout Standard
4766 \begin_layout Standard
4769 ../sdcc/configure\InsetSpace ~
4777 # configure is doing all the magic!
4780 \begin_layout Standard
4786 \begin_layout Standard
4792 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4793 It automagically computes the variables srcdir, top_srcdir and top_buildir
4799 the generated files will be in ~/sdcc.build, while the source files stay
4802 This is not only usefull for building different binaries, e.g.
4803 when cross compiling.
4804 It also gives you a much better overview in the source tree when all the
4805 generated files are not scattered between the source files.
4806 And the best thing is: if you want to change a file you can leave the original
4807 file untouched in the source directory.
4808 Simply copy it to the build directory, edit it, enter `make clean', `rm
4809 Makefile.dep' and `make'.
4814 will do the rest for you!
4817 \begin_layout Section
4818 Building the Documentation
4821 \begin_layout Standard
4826 \begin_layout Standard
4835 -enable-doc to the configure arguments to build the documentation together
4836 with all the other stuff.
4837 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4838 dvips and makeindex) to get the job done.
4839 Another possibility is to change to the doc directory and to type
4843 \begin_inset Quotes srd
4847 \begin_inset Quotes srd
4854 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4857 \begin_inset LatexCommand \url{http://www.lyx.org}
4861 as editor is straightforward.
4862 Prebuilt documentation in html and pdf format is available from
4863 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4870 \begin_layout Section
4871 Reading the Documentation
4872 \begin_inset LatexCommand \index{Documentation}
4879 \begin_layout Standard
4880 Currently reading the document in pdf format is recommended, as for unknown
4881 reason the hyperlinks are working there whereas in the html version they
4886 \begin_layout Standard
4887 If you should know why please drop us a note
4895 You'll find the pdf version
4896 \begin_inset LatexCommand \index{PDF version of this document}
4901 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4909 \begin_inset LatexCommand \index{HTML version of this document}
4914 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4920 This documentation is in some aspects different from a commercial documentation:
4924 \begin_layout Itemize
4925 It tries to document SDCC for several processor architectures in one document
4926 (commercially these probably would be separate documents/products).
4928 \begin_inset LatexCommand \index{Status of documentation}
4932 currently matches SDCC for mcs51 and DS390 best and does give too few informati
4934 Z80, PIC14, PIC16 and HC08.
4937 \begin_layout Itemize
4938 There are many references pointing away from this documentation.
4939 Don't let this distract you.
4941 was a reference like
4942 \begin_inset LatexCommand \url{http://www.opencores.org}
4946 together with a statement
4947 \begin_inset Quotes sld
4950 some processors which are targetted by SDCC can be implemented in a
4967 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4972 \begin_inset Quotes srd
4976 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4981 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4986 \begin_inset Quotes sld
4989 have you ever heard of an open source compiler that compiles a subset of
4991 \begin_inset Quotes srd
4994 we expect you to have a quick look there and come back.
4995 If you read this you are on the right track.
4998 \begin_layout Itemize
4999 Some sections attribute more space to problems, restrictions and warnings
5000 than to the solution.
5003 \begin_layout Itemize
5004 The installation section and the section about the debugger is intimidating.
5007 \begin_layout Itemize
5008 There are still lots of typos and there are more different writing styles
5012 \begin_layout Section
5013 Testing the SDCC Compiler
5014 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
5021 \begin_layout Standard
5022 The first thing you should do after installing your SDCC compiler is to
5031 \begin_layout Standard
5041 \begin_inset LatexCommand \index{version}
5048 at the prompt, and the program should run and output its version like:
5053 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
5057 \begin_layout Standard
5058 If it doesn't run, or gives a message about not finding sdcc program, then
5059 you need to check over your installation.
5060 Make sure that the sdcc bin directory is in your executable search path
5061 defined by the PATH environment setting (
5066 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5073 Install trouble-shooting for suggestions
5076 Make sure that the sdcc program is in the bin folder, if not perhaps something
5077 did not install correctly.
5085 is commonly installed as described in section
5086 \begin_inset Quotes sld
5089 Install and search paths
5090 \begin_inset Quotes srd
5099 Make sure the compiler works on a very simple example.
5100 Type in the following test.c program using your favorite
5125 \begin_layout Standard
5128 Compile this using the following command:
5137 If all goes well, the compiler will generate a test.asm and test.rel file.
5138 Congratulations, you've just compiled your first program with SDCC.
5139 We used the -c option to tell SDCC not to link the generated code, just
5140 to keep things simple for this step.
5148 The next step is to try it with the linker.
5158 If all goes well the compiler will link with the libraries and produce
5159 a test.ihx output file.
5164 (no test.ihx, and the linker generates warnings), then the problem is most
5173 usr/local/share/sdcc/lib directory
5180 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5187 Install trouble-shooting for suggestions).
5195 The final test is to ensure
5203 header files and libraries.
5204 Edit test.c and change it to the following:
5222 strcpy(str1, "testing");
5227 \begin_layout Standard
5230 Compile this by typing
5237 This should generate a test.ihx output file, and it should give no warnings
5238 such as not finding the string.h file.
5239 If it cannot find the string.h file, then the problem is that
5243 cannot find the /usr/local/share/sdcc/include directory
5250 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5257 Install trouble-shooting section for suggestions).
5266 \begin_layout Standard
5278 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5282 to find exactly where SDCC is looking for the include and lib files.
5285 \begin_layout Section
5286 Install Trouble-shooting
5287 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5292 \begin_inset LatexCommand \index{Install trouble-shooting}
5299 \begin_layout Subsection
5300 If SDCC does not build correctly
5303 \begin_layout Standard
5304 A thing to try is starting from scratch by unpacking the .tgz source package
5305 again in an empty directory.
5313 ./configure 2>&1 | tee configure.log
5327 make 2>&1 | tee make.log
5334 If anything goes wrong, you can review the log files to locate the problem.
5335 Or a relevant part of this can be attached to an email that could be helpful
5336 when requesting help from the mailing list.
5339 \begin_layout Subsection
5341 \begin_inset Quotes sld
5345 \begin_inset Quotes srd
5351 \begin_layout Standard
5353 \begin_inset Quotes sld
5357 \begin_inset Quotes srd
5360 command is a script that analyzes your system and performs some configuration
5361 to ensure the source package compiles on your system.
5362 It will take a few minutes to run, and will compile a few tests to determine
5363 what compiler features are installed.
5366 \begin_layout Subsection
5368 \begin_inset Quotes sld
5372 \begin_inset Quotes srd
5378 \begin_layout Standard
5379 This runs the GNU make tool, which automatically compiles all the source
5380 packages into the final installed binary executables.
5383 \begin_layout Subsection
5385 \begin_inset Quotes sld
5389 \begin_inset Quotes erd
5395 \begin_layout Standard
5396 This will install the compiler, other executables libraries and include
5397 files into the appropriate directories.
5399 \begin_inset LatexCommand \ref{sub:Install-paths}
5405 \begin_inset LatexCommand \ref{sub:Search-Paths}
5410 about install and search paths.
5412 On most systems you will need super-user privilege
5416 \begin_layout Section
5420 \begin_layout Standard
5421 SDCC is not just a compiler, but a collection of tools by various developers.
5422 These include linkers, assemblers, simulators and other components.
5423 Here is a summary of some of the components.
5424 Note that the included simulator and assembler have separate documentation
5425 which you can find in the source package in their respective directories.
5426 As SDCC grows to include support for other processors, other packages from
5427 various developers are included and may have their own sets of documentation.
5432 might want to look at the files which are installed in <installdir>.
5433 At the time of this writing, we find the following programs for gcc-builds:
5438 In <installdir>/bin:
5441 \begin_layout Itemize
5442 sdcc - The compiler.
5445 \begin_layout Itemize
5446 sdcpp - The C preprocessor.
5449 \begin_layout Itemize
5450 asx8051 - The assembler for 8051 type processors.
5453 \begin_layout Itemize
5458 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5461 \begin_layout Itemize
5462 aslink -The linker for 8051 type processors.
5465 \begin_layout Itemize
5470 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5473 \begin_layout Itemize
5474 s51 - The ucSim 8051 simulator.
5477 \begin_layout Itemize
5478 sdcdb - The source debugger.
5481 \begin_layout Itemize
5482 packihx - A tool to pack (compress) Intel hex files.
5485 \begin_layout Standard
5486 In <installdir>/share/sdcc/include
5489 \begin_layout Itemize
5493 \begin_layout Standard
5494 In <installdir>/share/sdcc/lib
5497 \begin_layout Itemize
5498 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5502 \begin_layout Standard
5503 In <installdir>/share/sdcc/doc
5506 \begin_layout Itemize
5510 \begin_layout Standard
5511 As development for other processors proceeds, this list will expand to include
5512 executables to support processors like AVR, PIC, etc.
5515 \begin_layout Subsection
5519 \begin_layout Standard
5520 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5521 the assembler and linkage editor.
5524 \begin_layout Subsection
5525 sdcpp - The C-Preprocessor
5528 \begin_layout Standard
5530 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5534 is a modified version of the GNU cpp
5535 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5540 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5545 The C preprocessor is used to pull in #include sources, process #ifdef
5546 statements, #defines and so on.
5549 \begin_layout Subsection
5558 - The Assemblers and Linkage Editors
5561 \begin_layout Standard
5562 This is retargettable assembler & linkage editor, it was developed by Alan
5564 John Hartman created the version for 8051, and I (Sandeep) have made some
5565 enhancements and bug fixes for it to work properly with SDCC.
5568 \begin_layout Subsection
5572 \begin_layout Standard
5574 \begin_inset LatexCommand \index{s51}
5578 is a free open source simulator developed by Daniel Drotos.
5579 The simulator is built as part of the build process.
5580 For more information visit Daniel's web site at:
5581 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5586 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5590 \begin_layout Subsection
5591 sdcdb - Source Level Debugger
5594 \begin_layout Standard
5596 \begin_inset LatexCommand \index{SDCDB (debugger)}
5600 is the companion source level debugger.
5601 More about SDCDB in section
5602 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5607 The current version of the debugger uses Daniel's Simulator S51
5608 \begin_inset LatexCommand \index{s51}
5612 , but can be easily changed to use other simulators.
5615 \begin_layout Chapter
5619 \begin_layout Section
5623 \begin_layout Subsection
5624 Single Source File Projects
5627 \begin_layout Standard
5628 For single source file 8051 projects the process is very simple.
5629 Compile your programs with the following command
5632 "sdcc sourcefile.c".
5636 This will compile, assemble and link your source file.
5637 Output files are as follows:
5640 \begin_layout Itemize
5642 \begin_inset LatexCommand \index{<file>.asm}
5647 \begin_inset LatexCommand \index{Assembler source}
5651 file created by the compiler
5654 \begin_layout Itemize
5656 \begin_inset LatexCommand \index{<file>.lst}
5661 \begin_inset LatexCommand \index{Assembler listing}
5665 file created by the Assembler
5668 \begin_layout Itemize
5670 \begin_inset LatexCommand \index{<file>.rst}
5675 \begin_inset LatexCommand \index{Assembler listing}
5679 file updated with linkedit information, created by linkage editor
5682 \begin_layout Itemize
5684 \begin_inset LatexCommand \index{<file>.sym}
5689 \begin_inset LatexCommand \index{Symbol listing}
5693 for the sourcefile, created by the assembler
5696 \begin_layout Itemize
5698 \begin_inset LatexCommand \index{<file>.rel}
5703 \begin_inset LatexCommand \index{<file>.o}
5708 \begin_inset LatexCommand \index{Object file}
5712 created by the assembler, input to Linkage editor
5715 \begin_layout Itemize
5717 \begin_inset LatexCommand \index{<file>.map}
5722 \begin_inset LatexCommand \index{Memory map}
5726 for the load module, created by the Linker
5729 \begin_layout Itemize
5731 \begin_inset LatexCommand \index{<file>.mem}
5735 - A file with a summary of the memory usage
5738 \begin_layout Itemize
5740 \begin_inset LatexCommand \index{<file>.ihx}
5744 - The load module in Intel hex format
5745 \begin_inset LatexCommand \index{Intel hex format}
5749 (you can select the Motorola S19 format
5750 \begin_inset LatexCommand \index{Motorola S19 format}
5758 \begin_layout Standard
5768 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5773 If you need another format you might want to use
5780 \begin_inset LatexCommand \index{objdump (tool)}
5791 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5796 \begin_inset Note Note
5799 \begin_layout Standard
5806 \begin_inset LatexCommand \vref{sub:Postprocessing-the-Intel}
5811 Both formats are documented in the documentation of srecord
5812 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5819 \begin_layout Itemize
5821 \begin_inset LatexCommand \index{<file>.adb}
5825 - An intermediate file containing debug information needed to create the
5830 \begin_layout Standard
5840 \begin_inset LatexCommand \index{-\/-debug}
5847 \begin_layout Itemize
5849 \begin_inset LatexCommand \index{<file>.cdb}
5853 - An optional file (with -
5857 \begin_layout Standard
5866 -debug) containing debug information.
5867 The format is documented in cdbfileformat.pdf
5870 \begin_layout Itemize
5873 \begin_inset LatexCommand \index{<file> (no extension)}
5877 An optional AOMF or AOMF51
5878 \begin_inset LatexCommand \index{AOMF, AOMF51}
5883 \begin_inset LatexCommand \label{OMF file}
5887 file containing debug information (generated with option -
5891 \begin_layout Standard
5917 ormat is a subformat of the OMF51 format and is commonly used by third party
5919 \begin_inset LatexCommand \index{Debugger}
5923 , simulators, emulators).
5926 \begin_layout Itemize
5928 \begin_inset LatexCommand \index{<file>.dump*}
5932 - Dump file to debug the compiler it self (generated with option -
5936 \begin_layout Standard
5945 -dumpall) (see section
5946 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5952 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5958 \begin_inset Quotes sld
5961 Anatomy of the compiler
5962 \begin_inset Quotes srd
5968 \begin_layout Subsection
5969 Postprocessing the Intel Hex
5970 \begin_inset LatexCommand \index{Intel hex format}
5975 \begin_inset LatexCommand \label{sub:Postprocessing-the-Intel}
5982 \begin_layout Standard
5983 In most cases this won't be needed but the Intel Hex file
5984 \begin_inset LatexCommand \index{<file>.ihx}
5988 which is generated by SDCC might include lines of varying length and the
5989 addresses within the file are not guaranteed to be strictly ascending.
5990 If your toolchain or a bootloader does not like this you can use the tool
5996 \begin_inset LatexCommand \index{packihx (tool)}
6000 which is part of the SDCC distribution:
6007 packihx sourcefile.ihx >sourcefile.hex
6014 The separately available
6019 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6023 package additionally allows to set undefined locations to a predefined
6024 value, to insert checksums
6025 \begin_inset LatexCommand \index{checksum}
6029 of various flavours (crc, add, xor) and to perform other manipulations
6030 (convert, split, crop, offset, ...).
6038 srec_cat\InsetSpace ~
6040 sourcefile.ihx -intel\InsetSpace ~
6042 -o sourcefile.hex -intel
6049 An example for a more complex command line
6053 \begin_layout Standard
6054 the command backfills
6055 \begin_inset LatexCommand \index{backfill unused memory}
6059 unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
6061 If the program counter on an mcs51 runs wild the backfill pattern 0x12
6062 will be interpreted as an
6070 (where an emergency routine could sit).
6083 srec_cat\InsetSpace ~
6084 sourcefile.ihx -intel\InsetSpace ~
6086 -fill 0x12 0x0000 0xfffe\InsetSpace ~
6087 -little-endian-checksum-nega
6088 tive 0xfffe 0x02 0x02\InsetSpace ~
6090 -o sourcefile.hex -intel
6099 The srecord package is available at
6100 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
6107 \begin_layout Subsection
6108 Projects with Multiple Source Files
6111 \begin_layout Standard
6112 SDCC can compile only ONE file at a time.
6113 Let us for example assume that you have a project containing the following
6118 foo1.c (contains some functions)
6120 foo2.c (contains some more functions)
6123 n.c (contains more functions and the function main)
6131 The first two files will need to be compiled separately with the commands:
6163 Then compile the source file containing the
6168 \begin_inset LatexCommand \index{Linker}
6172 the files together with the following command:
6180 foomain.c\InsetSpace ~
6181 foo1.rel\InsetSpace ~
6186 \begin_inset LatexCommand \index{<file>.rel}
6198 can be separately compiled as well:
6209 sdcc foomain.rel foo1.rel foo2.rel
6216 The file containing the
6231 file specified in the command line, since the linkage editor processes
6232 file in the order they are presented to it.
6233 The linker is invoked from SDCC using a script file with extension .lnk
6234 \begin_inset LatexCommand \index{<file>.lnk}
6239 You can view this file to troubleshoot linking problems such as those arising
6240 from missing libraries.
6243 \begin_layout Subsection
6244 Projects with Additional Libraries
6245 \begin_inset LatexCommand \index{Libraries}
6252 \begin_layout Standard
6253 Some reusable routines may be compiled into a library, see the documentation
6254 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6258 \begin_inset LatexCommand \index{<file>.lib}
6265 Libraries created in this manner can be included in the command line.
6266 Make sure you include the -L <library-path> option to tell the linker where
6267 to look for these files if they are not in the current directory.
6268 Here is an example, assuming you have the source file
6280 (if that is not the same as your current project):
6287 sdcc foomain.c foolib.lib -L mylib
6298 must be an absolute path name.
6302 The most efficient way to use libraries is
6303 to keep separate modules in separate source files.
6304 The lib file now should name all the modules.rel
6305 \begin_inset LatexCommand \index{<file>.rel}
6310 For an example see the standard library file
6314 in the directory <installdir>/share/lib/small.
6317 \begin_layout Subsection
6318 Using sdcclib to Create and Manage Libraries
6319 \begin_inset LatexCommand \index{sdcclib}
6326 \begin_layout Standard
6327 Alternatively, instead of having a .rel file for each entry on the library
6328 file as described in the preceding section, sdcclib can be used to embed
6329 all the modules belonging to such library in the library file itself.
6330 This results in a larger library file, but it greatly reduces the number
6331 of disk files accessed by the linker.
6332 Additionally, the packed library file contains an index of all include
6333 modules and symbols that significantly speeds up the linking process.
6334 To display a list of options supported by sdcclib type:
6339 \begin_layout Standard
6344 \begin_inset LatexCommand \index{sdcclib}
6355 To create a new library file, start by compiling all the required modules.
6361 \begin_layout Standard
6368 \begin_layout Standard
6375 \begin_layout Standard
6382 \begin_layout Standard
6389 \begin_layout Standard
6398 \begin_layout Standard
6399 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6401 The next step is to add the .rel files to the library file:
6406 \begin_layout Standard
6410 sdcclib libint.lib _divsint.rel
6413 \begin_inset LatexCommand \index{sdcclib}
6420 \begin_layout Standard
6424 sdcclib libint.lib _divuint.rel
6427 \begin_layout Standard
6431 sdcclib libint.lib _modsint.rel
6434 \begin_layout Standard
6438 sdcclib libint.lib _moduint.rel
6441 \begin_layout Standard
6445 sdcclib libint.lib _mulint.rel
6453 \begin_layout Standard
6462 \begin_layout Standard
6466 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6474 \begin_layout Standard
6475 If the file already exists in the library, it will be replaced.
6476 If a list of .rel files is available, you can tell sdcclib to add those
6478 For example, if the file 'myliblist.txt' contains
6486 \begin_layout Standard
6493 \begin_layout Standard
6500 \begin_layout Standard
6507 \begin_layout Standard
6514 \begin_layout Standard
6526 \begin_layout Standard
6535 \begin_layout Standard
6539 sdcclib -l libint.lib myliblist.txt
6547 \begin_layout Standard
6548 Additionally, you can instruct sdcclib to compiles the files before adding
6549 them to the library.
6550 This is achieved using the environment variables SDCCLIB_CC and/or SDCCLIB_AS.
6559 \begin_layout Standard
6563 set SDCCLIB_CC=sdcc -c
6566 \begin_layout Standard
6570 sdcclib -l libint.lib myliblist.txt
6578 \begin_layout Standard
6579 To see what modules and symbols are included in the library, options -s
6580 and -m are available.
6588 sdcclib -s libint.lib
6591 \begin_inset LatexCommand \index{sdcclib}
6603 \begin_layout Standard
6609 \begin_layout Standard
6615 \begin_layout Standard
6623 \begin_layout Standard
6629 \begin_layout Standard
6635 \begin_layout Standard
6641 \begin_layout Standard
6647 \begin_layout Standard
6655 \begin_layout Standard
6661 \begin_layout Standard
6667 \begin_layout Standard
6675 \begin_layout Standard
6681 \begin_layout Standard
6687 \begin_layout Standard
6693 \begin_layout Standard
6701 \begin_layout Standard
6707 \begin_layout Standard
6718 \begin_layout Standard
6719 If the source files are compiled using -
6723 \begin_layout Standard
6733 \begin_inset LatexCommand \index{-\/-debug}
6737 , the corresponding debug information file .adb will be include in the library
6739 The library files created with sdcclib are plain text files, so they can
6740 be viewed with a text editor.
6741 It is not recomended to modify a library file created with sdcclib using
6742 a text editor, as there are file indexes numbers located accross the file
6743 used by the linker to quickly locate the required module to link.
6744 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6745 it can be safely deleted, since all the information required for linking
6746 is embedded in the library file itself.
6747 Library files created using sdcclib are used as described in the preceding
6749 \begin_inset VSpace bigskip
6755 \begin_layout Section
6756 Command Line Options
6757 \begin_inset LatexCommand \index{Command Line Options}
6762 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6769 \begin_layout Subsection
6770 Processor Selection Options
6771 \begin_inset LatexCommand \index{Options processor selection}
6776 \begin_inset LatexCommand \index{Processor selection options}
6784 \labelwidthstring 00.00.0000
6788 \begin_inset LatexCommand \index{-mmcs51}
6794 Generate code for the Intel MCS51
6795 \begin_inset LatexCommand \index{MCS51}
6799 family of processors.
6800 This is the default processor target.
6804 \labelwidthstring 00.00.0000
6808 \begin_inset LatexCommand \index{-mds390}
6814 Generate code for the Dallas DS80C390
6815 \begin_inset LatexCommand \index{DS80C390}
6823 \labelwidthstring 00.00.0000
6827 \begin_inset LatexCommand \index{-mds400}
6833 Generate code for the Dallas DS80C400
6834 \begin_inset LatexCommand \index{DS80C400}
6842 \labelwidthstring 00.00.0000
6846 \begin_inset LatexCommand \index{-mhc08}
6852 Generate code for the Freescale/Motorola HC08
6853 \begin_inset LatexCommand \index{HC08}
6857 family of processors.
6861 \labelwidthstring 00.00.0000
6865 \begin_inset LatexCommand \index{-mz80}
6871 Generate code for the Zilog Z80
6872 \begin_inset LatexCommand \index{Z80}
6876 family of processors.
6880 \labelwidthstring 00.00.0000
6884 \begin_inset LatexCommand \index{-mgbz80}
6890 Generate code for the GameBoy Z80
6891 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6895 processor (Not actively maintained).
6899 \labelwidthstring 00.00.0000
6903 \begin_inset LatexCommand \index{-mavr}
6909 Generate code for the Atmel AVR
6910 \begin_inset LatexCommand \index{AVR}
6914 processor (Not maintained, not complete).
6915 AVR users should probably have a look at winavr
6916 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6921 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6925 , which is based on AVR-port of the gcc compiler.
6928 \begin_layout Standard
6929 \begin_inset Note Note
6932 \begin_layout Standard
6933 I think it is fair to direct users there for now.
6934 Open source is also about avoiding unnecessary work .
6935 But I didn't find the 'official' link.
6944 \labelwidthstring 00.00.0000
6948 \begin_inset LatexCommand \index{-mpic14}
6954 Generate code for the Microchip PIC 14
6955 \begin_inset LatexCommand \index{PIC14}
6959 -bit processors (p16f84 and variants.
6960 In development, not complete).
6963 \begin_layout Standard
6964 \begin_inset Note Note
6967 \begin_layout Standard
6968 p16f627 p16f628 p16f84 p16f873 p16f877?
6977 \labelwidthstring 00.00.0000
6981 \begin_inset LatexCommand \index{-mpic16}
6987 Generate code for the Microchip PIC 16
6988 \begin_inset LatexCommand \index{PIC16}
6992 -bit processors (p18f452 and variants.
6993 In development, not complete).
6997 \labelwidthstring 00.00.0000
7002 Generate code for the Toshiba TLCS-900H
7003 \begin_inset LatexCommand \index{TLCS-900H}
7007 processor (Not maintained, not complete).
7011 \labelwidthstring 00.00.0000
7015 \begin_inset LatexCommand \index{-mxa51}
7021 Generate code for the Phillips XA51
7022 \begin_inset LatexCommand \index{XA51}
7026 processor (Not maintained, not complete).
7029 \begin_layout Standard
7030 \begin_inset VSpace bigskip
7036 \begin_layout Subsection
7037 Preprocessor Options
7038 \begin_inset LatexCommand \index{Options preprocessor}
7043 \begin_inset LatexCommand \index{Preprocessor options}
7048 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7056 \labelwidthstring 00.00.0000
7060 \begin_inset LatexCommand \index{-I<path>}
7066 The additional location where the preprocessor will look for <..h> or
7067 \begin_inset Quotes eld
7071 \begin_inset Quotes erd
7078 \labelwidthstring 00.00.0000
7082 \begin_inset LatexCommand \index{-D<macro[=value]>}
7088 Command line definition of macros.
7089 Passed to the preprocessor.
7093 \labelwidthstring 00.00.0000
7097 \begin_inset LatexCommand \index{-M}
7103 Tell the preprocessor to output a rule suitable for make describing the
7104 dependencies of each object file.
7105 For each source file, the preprocessor outputs one make-rule whose target
7106 is the object file name for that source file and whose dependencies are
7107 all the files `#include'd in it.
7108 This rule may be a single line or may be continued with `
7110 '-newline if it is long.
7111 The list of rules is printed on standard output instead of the preprocessed
7114 \begin_inset LatexCommand \index{-E}
7122 \labelwidthstring 00.00.0000
7126 \begin_inset LatexCommand \index{-C}
7132 Tell the preprocessor not to discard comments.
7133 Used with the `-E' option.
7137 \labelwidthstring 00.00.0000
7141 \begin_inset LatexCommand \index{-MM}
7152 Like `-M' but the output mentions only the user header files included with
7154 \begin_inset Quotes eld
7158 System header files included with `#include <file>' are omitted.
7162 \labelwidthstring 00.00.0000
7166 \begin_inset LatexCommand \index{-Aquestion(answer)}
7172 Assert the answer answer for question, in case it is tested with a preprocessor
7173 conditional such as `#if #question(answer)'.
7174 `-A-' disables the standard assertions that normally describe the target
7179 \labelwidthstring 00.00.0000
7183 \begin_inset LatexCommand \index{-Umacro}
7189 Undefine macro macro.
7190 `-U' options are evaluated after all `-D' options, but before any `-include'
7191 and `-imacros' options.
7195 \labelwidthstring 00.00.0000
7199 \begin_inset LatexCommand \index{-dM}
7205 Tell the preprocessor to output only a list of the macro definitions that
7206 are in effect at the end of preprocessing.
7207 Used with the `-E' option.
7211 \labelwidthstring 00.00.0000
7215 \begin_inset LatexCommand \index{-dD}
7221 Tell the preprocessor to pass all macro definitions into the output, in
7222 their proper sequence in the rest of the output.
7226 \labelwidthstring 00.00.0000
7230 \begin_inset LatexCommand \index{-dN}
7241 Like `-dD' except that the macro arguments and contents are omitted.
7242 Only `#define name' is included in the output.
7246 \labelwidthstring 00.00.0000
7249 -pedantic-parse-number
7250 \begin_inset LatexCommand \index{pedantic}
7255 \begin_inset LatexCommand \index{-pedantic-parse-number}
7263 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
7271 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7272 and the macro LO_B(3) gets expanded.
7273 See also #pragma pedantic_parse_number
7274 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
7279 \begin_inset LatexCommand \ref{sec:Pragmas}
7285 Note: this functionality is not in conformance with C99 standard!
7289 \labelwidthstring 00.00.0000
7293 preprocessorOption[,preprocessorOption]
7296 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
7301 Pass the preprocessorOption to the preprocessor
7306 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7311 SDCC uses an adapted version of the preprocessor
7315 of the GNU Compiler Collection
7316 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
7325 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7329 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7334 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7341 \begin_layout Standard
7342 \begin_inset VSpace bigskip
7348 \begin_layout Subsection
7350 \begin_inset LatexCommand \index{Options linker}
7355 \begin_inset LatexCommand \index{Linker options}
7363 \labelwidthstring 00.00.0000
7373 \begin_layout Standard
7385 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7390 \begin_inset LatexCommand \index{-L -\/-lib-path}
7397 <absolute path to additional libraries> This option is passed to the linkage
7398 editor's additional libraries
7399 \begin_inset LatexCommand \index{Libraries}
7404 The path name must be absolute.
7405 Additional library files may be specified in the command line.
7406 See section Compiling programs for more details.
7410 \labelwidthstring 00.00.0000
7417 \begin_layout Standard
7429 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7434 <Value> The start location of the external ram
7435 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7439 , default value is 0.
7440 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7444 \begin_layout Standard
7453 -xram-loc 0x8000 or -
7457 \begin_layout Standard
7470 \labelwidthstring 00.00.0000
7477 \begin_layout Standard
7489 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7494 <Value> The start location of the code
7495 \begin_inset LatexCommand \index{code}
7499 segment, default value 0.
7500 Note when this option is used the interrupt vector table
7501 \begin_inset LatexCommand \index{interrupt vector table}
7505 is also relocated to the given address.
7506 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7510 \begin_layout Standard
7519 -code-loc 0x8000 or -
7523 \begin_layout Standard
7536 \labelwidthstring 00.00.0000
7543 \begin_layout Standard
7555 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7560 <Value> By default the stack
7561 \begin_inset LatexCommand \index{stack}
7565 is placed after the data segment.
7566 Using this option the stack can be placed anywhere in the internal memory
7568 The value entered can be in Hexadecimal or Decimal format, e.g.
7573 \begin_layout Standard
7582 -stack-loc 0x20 or -
7586 \begin_layout Standard
7596 Since the sp register is incremented before a push or call, the initial
7597 sp will be set to one byte prior the provided value.
7598 The provided value should not overlap any other memory areas such as used
7599 register banks or the data segment and with enough space for the current
7607 \begin_layout Standard
7620 \begin_inset LatexCommand \index{-\/-pack-iram}
7624 option (which is now a default setting) will override this setting, so
7625 you should also specify the
7631 \begin_layout Standard
7644 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7648 option if you need to manually place the stack.
7652 \labelwidthstring 00.00.0000
7659 \begin_layout Standard
7671 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7676 <Value> By default the external stack
7677 \begin_inset LatexCommand \index{xstack}
7681 is placed after the pdata
7682 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7687 Using this option the xstack can be placed anywhere in the external memory
7689 The value entered can be in Hexadecimal or Decimal format, e.g.
7694 \begin_layout Standard
7703 -xstack-loc 0x8000 or -
7707 \begin_layout Standard
7717 The provided value should not overlap any other memory areas such as the
7718 pdata or xdata segment and with enough space for the current application.
7722 \labelwidthstring 00.00.0000
7729 \begin_layout Standard
7741 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7746 <Value> The start location of the internal ram data
7747 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7752 The value entered can be in Hexadecimal or Decimal format, eg.
7757 \begin_layout Standard
7770 \begin_layout Standard
7780 (By default, the start location of the internal ram data segment is set
7781 as low as possible in memory, taking into account the used register banks
7782 and the bit segment at address 0x20.
7783 For example if register banks 0 and 1 are used without bit variables, the
7784 data segment will be set, if -
7788 \begin_layout Standard
7797 -data-loc is not used, to location 0x10.)
7801 \labelwidthstring 00.00.0000
7808 \begin_layout Standard
7820 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7825 <Value> The start location of the indirectly addressable internal ram
7826 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7830 of the 8051, default value is 0x80.
7831 The value entered can be in Hexadecimal or Decimal format, eg.
7836 \begin_layout Standard
7845 -idata-loc 0x88 or -
7849 \begin_layout Standard
7862 \labelwidthstring 00.00.0000
7869 \begin_layout Standard
7881 <Value> The start location of the bit
7882 \begin_inset LatexCommand \index{bit}
7886 addressable internal ram of the 8051.
7892 Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7897 \labelwidthstring 00.00.0000
7904 \begin_layout Standard
7914 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7923 The linker output (final object code) is in Intel Hex format.
7924 \begin_inset LatexCommand \index{Intel hex format}
7928 This is the default option.
7929 The format itself is documented in the documentation of srecord
7930 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7938 \labelwidthstring 00.00.0000
7945 \begin_layout Standard
7955 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7964 The linker output (final object code) is in Motorola S19 format
7965 \begin_inset LatexCommand \index{Motorola S19 format}
7970 The format itself is documented in the documentation of srecord.
7974 \labelwidthstring 00.00.0000
7981 \begin_layout Standard
7991 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7996 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
8005 The linker output (final object code) is in ELF format
8006 \begin_inset LatexCommand \index{ELF format}
8011 (Currently only supported for the HC08
8012 \begin_inset LatexCommand \index{HC08}
8020 \labelwidthstring 00.00.0000
8024 linkOption[,linkOption]
8027 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
8032 Pass the linkOption to the linker.
8033 If a bootloader is used an option like
8034 \begin_inset Quotes sld
8039 \begin_inset Quotes srd
8042 would be typical to set the start of the code segment.
8043 See also #pragma constseg and #pragma codeseg in section
8044 \begin_inset LatexCommand \ref{sec:Pragmas}
8049 File sdcc/as/doc/asxhtm.html has more on linker options.
8052 \begin_layout Standard
8053 \begin_inset VSpace bigskip
8059 \begin_layout Subsection
8061 \begin_inset LatexCommand \index{Options MCS51}
8066 \begin_inset LatexCommand \index{MCS51 options}
8074 \labelwidthstring 00.00.0000
8081 \begin_layout Standard
8091 \begin_inset LatexCommand \index{-\/-model-small}
8102 Generate code for Small Model programs, see section Memory Models for more
8104 This is the default model.
8108 \labelwidthstring 00.00.0000
8115 \begin_layout Standard
8125 \begin_inset LatexCommand \index{-\/-model-medium}
8131 Generate code for Medium model programs, see section Memory Models for
8133 If this option is used all source files in the project have to be compiled
8135 It must also be used when invoking the linker.
8139 \labelwidthstring 00.00.0000
8146 \begin_layout Standard
8156 \begin_inset LatexCommand \index{-\/-model-large}
8162 Generate code for Large model programs, see section Memory Models for more
8164 If this option is used all source files in the project have to be compiled
8166 It must also be used when invoking the linker.
8170 \labelwidthstring 00.00.0000
8177 \begin_layout Standard
8187 \begin_inset LatexCommand \index{-\/-xstack}
8193 Uses a pseudo stack in the pdata
8194 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8198 area (usually the first 256 bytes in the external ram) for allocating variables
8199 and passing parameters.
8201 \begin_inset LatexCommand \ref{sub:External-Stack}
8206 External Stack for more details.
8210 \labelwidthstring 00.00.0000
8217 \begin_layout Standard
8230 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
8234 Causes the linker to check if the internal ram usage is within limits of
8239 \labelwidthstring 00.00.0000
8246 \begin_layout Standard
8259 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
8263 Causes the linker to check if the external ram usage is within limits of
8268 \labelwidthstring 00.00.0000
8275 \begin_layout Standard
8288 \begin_inset LatexCommand \index{-\/-code-size <Value>}
8292 Causes the linker to check if the code memory usage is within limits of
8297 \labelwidthstring 00.00.0000
8304 \begin_layout Standard
8317 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8321 Causes the linker to check if there is at minimum <Value> bytes for stack.
8325 \labelwidthstring 00.00.0000
8332 \begin_layout Standard
8345 \begin_inset LatexCommand \index{-\/-pack-iram}
8349 Causes the linker to use unused register banks for data variables and pack
8350 data, idata and stack together.
8351 This is the default now.
8355 \labelwidthstring 00.00.0000
8362 \begin_layout Standard
8375 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8379 Causes the linker to use old style for allocating memory areas.
8383 \labelwidthstring 00.00.0000
8390 \begin_layout Standard
8403 \begin_inset LatexCommand \index{-\/-acall-ajmp}
8407 Replaces the three byte instructions lcall/ljmp with the two byte instructions
8409 Only use this option if your code is in the same 2k block of memory.
8410 You may need to use this option for some 8051 derivatives which lack the
8411 lcall/ljmp instructions..
8414 \begin_layout Standard
8415 \begin_inset VSpace bigskip
8421 \begin_layout Subsection
8422 DS390 / DS400 Options
8423 \begin_inset LatexCommand \index{Options DS390}
8428 \begin_inset LatexCommand \index{DS390}
8436 \labelwidthstring 00.00.0000
8443 \begin_layout Standard
8455 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8465 Generate 24-bit flat mode code.
8466 This is the one and only that the ds390 code generator supports right now
8467 and is default when using
8472 See section Memory Models for more details.
8476 \labelwidthstring 00.00.0000
8483 \begin_layout Standard
8493 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8499 disable interrupts during ESP:SP updates.
8503 \labelwidthstring 00.00.0000
8510 \begin_layout Standard
8522 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8526 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8527 This is the one and only that the ds390 code generator supports right now
8528 and is default when using
8533 In this mode, the stack is located in the lower 1K of the internal RAM,
8534 which is mapped to 0x400000.
8535 Note that the support is incomplete, since it still uses a single byte
8536 as the stack pointer.
8537 This means that only the lower 256 bytes of the potential 1K stack space
8538 will actually be used.
8539 However, this does allow you to reclaim the precious 256 bytes of low RAM
8540 for use for the DATA and IDATA segments.
8541 The compiler will not generate any code to put the processor into 10 bit
8543 It is important to ensure that the processor is in this mode before calling
8544 any re-entrant functions compiled with this option.
8545 In principle, this should work with the
8551 \begin_layout Standard
8561 \begin_inset LatexCommand \index{-\/-stack-auto}
8567 option, but that has not been tested.
8568 It is incompatible with the
8574 \begin_layout Standard
8584 \begin_inset LatexCommand \index{-\/-xstack}
8591 It also only makes sense if the processor is in 24 bit contiguous addressing
8598 \begin_layout Standard
8607 -model-flat24 option
8612 \begin_inset Note Note
8616 \labelwidthstring 00.00.0000
8623 \begin_layout Standard
8632 -stack-8-bit - switches off the 10-bit mode
8641 \labelwidthstring 00.00.0000
8648 \begin_layout Standard
8658 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8664 insert call to function __stack_probe at each function prologue.
8668 \labelwidthstring 00.00.0000
8675 \begin_layout Standard
8685 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8691 <nnnn> LibraryID used in -mTININative.
8696 \labelwidthstring 00.00.0000
8703 \begin_layout Standard
8713 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8719 generate code for DS390 Arithmetic Accelerator.
8723 \begin_layout Standard
8724 \begin_inset VSpace bigskip
8730 \begin_layout Subsection
8732 \begin_inset LatexCommand \index{Options Z80}
8737 \begin_inset LatexCommand \index{Z80}
8745 \labelwidthstring 00.00.0000
8752 \begin_layout Standard
8764 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8774 Force a called function to always save BC.
8778 \labelwidthstring 00.00.0000
8785 \begin_layout Standard
8797 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8801 When linking, skip the standard crt0.o object file.
8802 You must provide your own crt0.o for your system when linking.
8806 \labelwidthstring 00.00.0000
8813 \begin_layout Standard
8825 \begin_inset LatexCommand \index{Z80!Options!-\/-portmode=<Value>}
8829 Determinate PORT I/O mode (<Value> is z80 or z180).
8833 \labelwidthstring 00.00.0000
8840 \begin_layout Standard
8852 \begin_inset LatexCommand \index{Z80!Options!-\/-asm=<Value>}
8856 Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
8860 \labelwidthstring 00.00.0000
8867 \begin_layout Standard
8880 \begin_inset LatexCommand \index{Z80!Options!-\/-codeseg <Value>}
8884 Use <Value> for the code segment name.
8888 \labelwidthstring 00.00.0000
8895 \begin_layout Standard
8908 \begin_inset LatexCommand \index{Z80!Options!-\/-constseg <Value>}
8912 Use <Value> for the const segment name.
8916 \labelwidthstring 00.00.0000
8917 \begin_inset VSpace bigskip
8923 \begin_layout Subsection
8925 \begin_inset LatexCommand \index{Options GBZ80}
8930 \begin_inset LatexCommand \index{GBZ80}
8938 \labelwidthstring 00.00.0000
8945 \begin_layout Standard
8957 \begin_inset LatexCommand \index{GBZ80!Options!-\/-callee-saves-bc}
8967 Force a called function to always save BC.
8971 \labelwidthstring 00.00.0000
8978 \begin_layout Standard
8990 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8994 When linking, skip the standard crt0.o object file.
8995 You must provide your own crt0.o for your system when linking.
8999 \labelwidthstring 00.00.0000
9006 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
9010 Use code bank <Num>.
9014 \labelwidthstring 00.00.0000
9021 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
9025 Use data bank <Num>.
9029 \labelwidthstring 00.00.0000
9036 \begin_layout Standard
9049 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
9053 Use <Value> for the code segment name.
9057 \labelwidthstring 00.00.0000
9064 \begin_layout Standard
9077 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
9081 Use <Value> for the const segment name.
9084 \begin_layout Standard
9085 \begin_inset VSpace bigskip
9091 \begin_layout Subsection
9092 Optimization Options
9093 \begin_inset LatexCommand \index{Options optimization}
9098 \begin_inset LatexCommand \index{Optimization options}
9106 \labelwidthstring 00.00.0000
9113 \begin_layout Standard
9123 \begin_inset LatexCommand \index{-\/-nogcse}
9129 Will not do global subexpression elimination, this option may be used when
9130 the compiler creates undesirably large stack/data spaces to store compiler
9140 \begin_inset LatexCommand \index{sloc (spill location)}
9145 A warning message will be generated when this happens and the compiler
9146 will indicate the number of extra bytes it allocated.
9147 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9149 \begin_inset LatexCommand \index{\#pragma nogcse}
9153 can be used to turn off global subexpression elimination
9154 \begin_inset LatexCommand \index{Subexpression elimination}
9158 for a given function only.
9162 \labelwidthstring 00.00.0000
9169 \begin_layout Standard
9179 \begin_inset LatexCommand \index{-\/-noinvariant}
9185 Will not do loop invariant optimizations, this may be turned off for reasons
9186 explained for the previous option.
9187 For more details of loop optimizations performed see Loop Invariants in
9189 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
9194 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9196 \begin_inset LatexCommand \index{\#pragma noinvariant}
9200 can be used to turn off invariant optimizations for a given function only.
9204 \labelwidthstring 00.00.0000
9211 \begin_layout Standard
9221 \begin_inset LatexCommand \index{-\/-noinduction}
9227 Will not do loop induction optimizations, see section strength reduction
9229 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9231 \begin_inset LatexCommand \index{\#pragma noinduction}
9235 can be used to turn off induction optimizations for a given function only.
9239 \labelwidthstring 00.00.0000
9246 \begin_layout Standard
9256 \begin_inset LatexCommand \index{-\/-nojtbound}
9267 Will not generate boundary condition check when switch statements
9268 \begin_inset LatexCommand \index{switch statement}
9272 are implemented using jump-tables.
9274 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
9279 Switch Statements for more details.
9280 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9282 \begin_inset LatexCommand \index{\#pragma nojtbound}
9286 can be used to turn off boundary checking for jump tables for a given function
9291 \labelwidthstring 00.00.0000
9298 \begin_layout Standard
9308 \begin_inset LatexCommand \index{-\/-noloopreverse}
9317 Will not do loop reversal
9318 \begin_inset LatexCommand \index{Loop reversing}
9326 \labelwidthstring 00.00.0000
9331 \begin_layout Standard
9345 \begin_inset LatexCommand \index{-\/-nolabelopt }
9349 Will not optimize labels (makes the dumpfiles more readable).
9353 \labelwidthstring 00.00.0000
9360 \begin_layout Standard
9370 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9376 Will not memcpy initialized data from code space into xdata space.
9377 This saves a few bytes in code space if you don't have initialized data
9378 \begin_inset LatexCommand \index{Variable initialization}
9386 \labelwidthstring 00.00.0000
9393 \begin_layout Standard
9403 \begin_inset LatexCommand \index{-\/-nooverlay}
9409 The compiler will not overlay parameters and local variables of any function,
9410 see section Parameters and local variables for more details.
9414 \labelwidthstring 00.00.0000
9421 \begin_layout Standard
9431 \begin_inset LatexCommand \index{-\/-no-peep}
9437 Disable peep-hole optimization with built-in rules.
9441 \labelwidthstring 00.00.0000
9448 \begin_layout Standard
9460 \begin_inset LatexCommand \index{-\/-peep-file}
9465 <filename> This option can be used to use additional rules to be used by
9466 the peep hole optimizer.
9468 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9473 Peep Hole optimizations for details on how to write these rules.
9477 \labelwidthstring 00.00.0000
9484 \begin_layout Standard
9494 \begin_inset LatexCommand \index{-\/-peep-asm}
9500 Pass the inline assembler code through the peep hole optimizer.
9501 This can cause unexpected changes to inline assembler code, please go through
9502 the peephole optimizer
9503 \begin_inset LatexCommand \index{Peephole optimizer}
9507 rules defined in the source file tree '<target>/peeph.def' before using
9512 \labelwidthstring 00.00.0000
9519 \begin_layout Standard
9529 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9535 The compiler will optimize code generation towards fast code, possibly
9536 at the expense of code size.
9540 \labelwidthstring 00.00.0000
9547 \begin_layout Standard
9557 \begin_inset LatexCommand \index{-\/-opt-code-size}
9563 The compiler will optimize code generation towards compact code, possibly
9564 at the expense of code speed.
9567 \begin_layout Standard
9568 \begin_inset VSpace bigskip
9574 \begin_layout Subsection
9576 \begin_inset LatexCommand \index{Options other}
9584 \labelwidthstring 00.00.0000
9592 \begin_layout Standard
9602 \begin_inset LatexCommand \index{-\/-compile-only}
9607 \begin_inset LatexCommand \index{-c -\/-compile-only}
9613 will compile and assemble the source, but will not call the linkage editor.
9617 \labelwidthstring 00.00.0000
9626 \begin_layout Standard
9638 \begin_inset LatexCommand \index{-\/-c1mode}
9644 reads the preprocessed source from standard input and compiles it.
9645 The file name for the assembler output must be specified using the -o option.
9649 \labelwidthstring 00.00.0000
9653 \begin_inset LatexCommand \index{-E}
9659 Run only the C preprocessor.
9660 Preprocess all the C source files specified and output the results to standard
9665 \labelwidthstring 00.00.0000
9670 \begin_inset LatexCommand \index{-o <path/file>}
9676 The output path where everything will be placed or the file name used for
9677 all generated output files.
9678 If the parameter is a path, it must have a trailing slash (or backslash
9679 for the Windows binaries) to be recognized as a path.
9684 Note for Windows users: if the path contains spaces, it should be surrounded
9686 The trailing backslash should be doubled in order to prevent escaping the
9687 final quote, for example:
9690 \begin_inset Quotes sld
9704 \begin_inset Quotes srd
9709 or put after the final quote, for example:
9712 \begin_inset Quotes sld
9722 \begin_inset Quotes srd
9730 The path using slashes for directory delimiters can be used too, for example:
9734 \begin_inset Quotes sld
9737 F:/Projects/test3/output 1/
9738 \begin_inset Quotes srd
9747 \labelwidthstring 00.00.0000
9754 \begin_layout Standard
9764 \begin_inset LatexCommand \index{-\/-stack-auto}
9775 All functions in the source file will be compiled as
9780 \begin_inset LatexCommand \index{reentrant}
9785 the parameters and local variables will be allocated on the stack
9786 \begin_inset LatexCommand \index{stack}
9792 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9796 Parameters and Local Variables for more details.
9797 If this option is used all source files in the project should be compiled
9799 It automatically implies -
9805 \begin_layout Standard
9816 -int-long-reent and -
9822 \begin_layout Standard
9838 \labelwidthstring 00.00.0000
9845 \begin_layout Standard
9855 \begin_inset LatexCommand \index{-\/-callee-saves}
9860 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9864 function1[,function2][,function3]....
9867 The compiler by default uses a caller saves convention for register saving
9868 across function calls, however this can cause unnecessary register pushing
9869 and popping when calling small functions from larger functions.
9870 This option can be used to switch the register saving convention for the
9871 function names specified.
9872 The compiler will not save registers when calling these functions, no extra
9873 code will be generated at the entry and exit (function prologue
9876 \begin_inset LatexCommand \index{function prologue}
9885 \begin_inset LatexCommand \index{function epilogue}
9891 ) for these functions to save and restore the registers used by these functions,
9892 this can SUBSTANTIALLY reduce code and improve run time performance of
9894 In the future the compiler (with inter procedural analysis) will be able
9895 to determine the appropriate scheme to use for each function call.
9896 DO NOT use this option for built-in functions such as _mulint..., if this
9897 option is used for a library function the appropriate library function
9898 needs to be recompiled with the same option.
9899 If the project consists of multiple source files then all the source file
9900 should be compiled with the same -
9904 \begin_layout Standard
9913 -callee-saves option string.
9914 Also see #pragma\InsetSpace ~
9916 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9921 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9929 \labelwidthstring 00.00.0000
9936 \begin_layout Standard
9946 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9960 \begin_layout Standard
9969 -callee-saves will be applied to all functions by default.
9973 \labelwidthstring 00.00.0000
9980 \begin_layout Standard
9990 \begin_inset LatexCommand \index{-\/-debug}
9999 When this option is used the compiler will generate debug information.
10000 The debug information collected in a file with .cdb extension can be used
10002 For more information see documentation for SDCDB.
10003 Another file with no extension contains debug information in AOMF or AOMF51
10004 \begin_inset LatexCommand \index{AOMF, AOMF51}
10008 format which is commonly used by third party tools.
10012 \labelwidthstring 00.00.0000
10016 \begin_inset LatexCommand \index{-S}
10027 Stop after the stage of compilation proper; do not assemble.
10028 The output is an assembler code file for the input file specified.
10032 \labelwidthstring 00.00.0000
10039 \begin_layout Standard
10049 \begin_inset LatexCommand \index{-\/-int-long-reent}
10055 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
10056 Note by default these libraries are compiled as non-reentrant.
10057 See section Installation for more details.
10061 \labelwidthstring 00.00.0000
10068 \begin_layout Standard
10078 \begin_inset LatexCommand \index{-\/-cyclomatic}
10087 This option will cause the compiler to generate an information message for
10088 each function in the source file.
10089 The message contains some
10093 information about the function.
10094 The number of edges and nodes the compiler detected in the control flow
10095 graph of the function, and most importantly the
10097 cyclomatic complexity
10098 \begin_inset LatexCommand \index{Cyclomatic complexity}
10104 see section on Cyclomatic Complexity for more details.
10108 \labelwidthstring 00.00.0000
10115 \begin_layout Standard
10125 \begin_inset LatexCommand \index{-\/-float-reent}
10131 Floating point library is compiled as reentrant
10132 \begin_inset LatexCommand \index{reentrant}
10137 See section Installation for more details.
10141 \labelwidthstring 00.00.0000
10148 \begin_layout Standard
10158 \begin_inset LatexCommand \index{-\/-funsigned-char}
10164 The default signedness for every type is
10169 In some embedded environments the default signedness of
10178 To set the signess for characters to unsigned, use the option -
10184 \begin_layout Standard
10196 If this option is set and no signedness keyword (unsigned/signed) is given,
10197 a char will be signed.
10198 All other types are unaffected.
10202 \labelwidthstring 00.00.0000
10209 \begin_layout Standard
10219 \begin_inset LatexCommand \index{-\/-main-return}
10225 This option can be used if the code generated is called by a monitor program
10226 or if the main routine includes an endless loop.
10227 This option results in slightly smaller code and saves two bytes of stack
10229 The return from the 'main'
10230 \begin_inset LatexCommand \index{main return}
10234 function will return to the function calling main.
10235 The default setting is to lock up i.e.
10244 \labelwidthstring 00.00.0000
10251 \begin_layout Standard
10261 \begin_inset LatexCommand \index{-\/-nostdinc}
10267 This will prevent the compiler from passing on the default include path
10268 to the preprocessor.
10272 \labelwidthstring 00.00.0000
10279 \begin_layout Standard
10289 \begin_inset LatexCommand \index{-\/-nostdlib}
10295 This will prevent the compiler from passing on the default library
10296 \begin_inset LatexCommand \index{Libraries}
10300 path to the linker.
10304 \labelwidthstring 00.00.0000
10311 \begin_layout Standard
10321 \begin_inset LatexCommand \index{-\/-verbose}
10327 Shows the various actions the compiler is performing.
10331 \labelwidthstring 00.00.0000
10335 \begin_inset LatexCommand \index{-V}
10341 Shows the actual commands the compiler is executing.
10345 \labelwidthstring 00.00.0000
10352 \begin_layout Standard
10362 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
10368 Hides your ugly and inefficient c-code from the asm file, so you can always
10369 blame the compiler :)
10373 \labelwidthstring 00.00.0000
10380 \begin_layout Standard
10390 \begin_inset LatexCommand \index{-\/-no-gen-comments}
10396 Include code generator and peep-hole comments in the generated asm files.
10400 \labelwidthstring 00.00.0000
10407 \begin_layout Standard
10417 \begin_inset LatexCommand \index{-\/-no-peep-comments}
10423 Don't include peep-hole comments in the generated asm files even if -
10429 \begin_layout Standard
10440 -fverbose-asm option is specified.
10444 \labelwidthstring 00.00.0000
10451 \begin_layout Standard
10461 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10467 Include i-codes in the asm file.
10468 Sounds like noise but is most helpful for debugging the compiler itself.
10472 \labelwidthstring 00.00.0000
10479 \begin_layout Standard
10489 \begin_inset LatexCommand \index{pedantic}
10494 \begin_inset LatexCommand \index{-\/-less-pedantic}
10501 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10505 Disable some of the more pedantic warnings
10506 \begin_inset LatexCommand \index{Warnings}
10511 For more details, see the less_pedantic pragma
10512 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10520 \labelwidthstring 00.00.0000
10527 \begin_layout Standard
10536 -disable-warning\InsetSpace ~
10538 \begin_inset LatexCommand \index{-\/-disable-warning}
10544 Disable specific warning with number <nnnn>.
10548 \labelwidthstring 00.00.0000
10555 \begin_layout Standard
10565 \begin_inset LatexCommand \index{-\/-Werror}
10571 Treat all warnings as errors.
10575 \labelwidthstring 00.00.0000
10582 \begin_layout Standard
10592 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10598 Display the directories in the compiler's search path
10602 \labelwidthstring 00.00.0000
10609 \begin_layout Standard
10619 \begin_inset LatexCommand \index{-\/-vc}
10625 Display errors and warnings using MSVC style, so you can use SDCC with
10626 the visual studio IDE
10627 \begin_inset LatexCommand \index{IDE}
10632 With SDCC both offering a GCC-like (the default) and a MSVC-like
10633 \begin_inset LatexCommand \index{MSVC output style}
10637 output style, integration into most programming editors should be straightforwa
10642 \labelwidthstring 00.00.0000
10649 \begin_layout Standard
10659 \begin_inset LatexCommand \index{-\/-use-stdout}
10665 Send errors and warnings to stdout instead of stderr.
10669 \labelwidthstring 00.00.0000
10673 asmOption[,asmOption]
10676 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10681 Pass the asmOption to the assembler
10682 \begin_inset LatexCommand \index{Options assembler}
10687 \begin_inset LatexCommand \index{Assembler options}
10692 See file sdcc/as/doc/asxhtm.html for assembler options.cd
10696 \labelwidthstring 00.00.0000
10703 \begin_layout Standard
10713 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10719 Generally follow the C89 standard, but allow SDCC features that conflict
10720 with the standard (default).
10724 \labelwidthstring 00.00.0000
10731 \begin_layout Standard
10741 \begin_inset LatexCommand \index{-\/-std-c89}
10747 Follow the C89 standard and disable SDCC features that conflict with the
10752 \labelwidthstring 00.00.0000
10759 \begin_layout Standard
10769 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10775 Generally follow the C99 standard, but allow SDCC features that conflict
10776 with the standard (incomplete support).
10780 \labelwidthstring 00.00.0000
10787 \begin_layout Standard
10797 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10803 Follow the C99 standard and disable SDCC features that conflict with the
10804 standard (incomplete support).
10808 \labelwidthstring 00.00.0000
10815 \begin_layout Standard
10827 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10832 <Name> The name to be used for the code
10833 \begin_inset LatexCommand \index{code}
10837 segment, default CSEG.
10838 This is useful if you need to tell the compiler to put the code in a special
10839 segment so you can later on tell the linker to put this segment in a special
10841 Can be used for instance when using bank switching to put the code in a
10846 \labelwidthstring 00.00.0000
10853 \begin_layout Standard
10865 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10870 <Name> The name to be used for the const
10871 \begin_inset LatexCommand \index{const}
10875 segment, default CONST.
10876 This is useful if you need to tell the compiler to put the const data in
10877 a special segment so you can later on tell the linker to put this segment
10878 in a special place in memory.
10879 Can be used for instance when using bank switching to put the const data
10884 \labelwidthstring 00.00.0000
10891 \begin_layout Standard
10900 -fdollars-in-identifiers
10901 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10907 Permit '$' as an identifier character.
10911 \labelwidthstring 00.00.0000
10918 \begin_layout Standard
10930 \begin_inset LatexCommand \index{-\/-more-pedantic}
10935 \begin_inset LatexCommand \index{pedantic}
10945 a SDCC compiler option but if you want
10949 warnings you can use a separate tool dedicated to syntax checking like
10951 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10956 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10961 \begin_inset LatexCommand \url{http://www.splint.org}
10966 To make your source files parseable by splint you will have to include
10972 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10976 in your source file and add brackets around extended keywords (like
10979 \begin_inset Quotes sld
10992 \begin_inset Quotes srd
11000 \begin_inset Quotes sld
11003 __interrupt\InsetSpace ~
11005 \begin_inset Quotes srd
11013 Splint has an excellent on line manual at
11014 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
11018 and it's capabilities go beyond pure syntax checking.
11019 You'll need to tell splint the location of SDCC's include files so a typical
11020 command line could look like this:
11024 splint\InsetSpace ~
11026 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
11032 \labelwidthstring 00.00.0000
11039 \begin_layout Standard
11051 \begin_inset LatexCommand \index{-\/-short-is-8bits}
11056 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
11060 Treat short as 8-bit (for backward compatibility with older versions of
11061 compiler - see section
11062 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
11069 \begin_layout Standard
11070 \begin_inset VSpace bigskip
11076 \begin_layout Subsection
11077 Intermediate Dump Options
11078 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
11083 \begin_inset LatexCommand \index{Options intermediate dump}
11088 \begin_inset LatexCommand \index{Intermediate dump options}
11095 \begin_layout Standard
11096 The following options are provided for the purpose of retargetting and debugging
11098 They provide a means to dump the intermediate code (iCode
11099 \begin_inset LatexCommand \index{iCode}
11103 ) generated by the compiler in human readable form at various stages of
11104 the compilation process.
11105 More on iCodes see chapter
11106 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
11111 \begin_inset Quotes srd
11114 The anatomy of the compiler
11115 \begin_inset Quotes srd
11122 \labelwidthstring 00.00.0000
11129 \begin_layout Standard
11139 \begin_inset LatexCommand \index{-\/-dumpraw}
11145 This option will cause the compiler to dump the intermediate code into
11148 <source filename>.dumpraw
11150 just after the intermediate code has been generated for a function, i.e.
11151 before any optimizations are done.
11153 \begin_inset LatexCommand \index{Basic blocks}
11157 at this stage ordered in the depth first number, so they may not be in
11158 sequence of execution.
11162 \labelwidthstring 00.00.0000
11169 \begin_layout Standard
11179 \begin_inset LatexCommand \index{-\/-dumpgcse}
11185 Will create a dump of iCodes, after global subexpression elimination
11186 \begin_inset LatexCommand \index{Global subexpression elimination}
11190 , into a file named
11192 <source filename>.dumpgcse.
11196 \labelwidthstring 00.00.0000
11203 \begin_layout Standard
11213 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
11219 Will create a dump of iCodes, after deadcode elimination
11220 \begin_inset LatexCommand \index{Dead-code elimination}
11224 , into a file named
11226 <source filename>.dumpdeadcode.
11230 \labelwidthstring 00.00.0000
11237 \begin_layout Standard
11247 \begin_inset LatexCommand \index{-\/-dumploop}
11256 Will create a dump of iCodes, after loop optimizations
11257 \begin_inset LatexCommand \index{Loop optimization}
11261 , into a file named
11263 <source filename>.dumploop.
11267 \labelwidthstring 00.00.0000
11274 \begin_layout Standard
11284 \begin_inset LatexCommand \index{-\/-dumprange}
11293 Will create a dump of iCodes, after live range analysis
11294 \begin_inset LatexCommand \index{Live range analysis}
11298 , into a file named
11300 <source filename>.dumprange.
11304 \labelwidthstring 00.00.0000
11311 \begin_layout Standard
11321 \begin_inset LatexCommand \index{-\/-dumlrange}
11327 Will dump the life ranges
11328 \begin_inset LatexCommand \index{Live range analysis}
11336 \labelwidthstring 00.00.0000
11343 \begin_layout Standard
11353 \begin_inset LatexCommand \index{-\/-dumpregassign}
11362 Will create a dump of iCodes, after register assignment
11363 \begin_inset LatexCommand \index{Register assignment}
11367 , into a file named
11369 <source filename>.dumprassgn.
11373 \labelwidthstring 00.00.0000
11380 \begin_layout Standard
11390 \begin_inset LatexCommand \index{-\/-dumplrange}
11396 Will create a dump of the live ranges of iTemp's
11400 \labelwidthstring 00.00.0000
11407 \begin_layout Standard
11417 \begin_inset LatexCommand \index{-\/-dumpall}
11428 Will cause all the above mentioned dumps to be created.
11431 \begin_layout Standard
11432 \begin_inset VSpace bigskip
11438 \begin_layout Subsection
11439 Redirecting output on Windows Shells
11442 \begin_layout Standard
11443 By default SDCC writes its error messages to
11444 \begin_inset Quotes sld
11448 \begin_inset Quotes srd
11452 To force all messages to
11453 \begin_inset Quotes sld
11457 \begin_inset Quotes srd
11469 \begin_layout Standard
11484 \begin_inset LatexCommand \index{-\/-use-stdout}
11489 Additionally, if you happen to have visual studio installed in your windows
11490 machine, you can use it to compile your sources using a custom build and
11497 \begin_layout Standard
11509 \begin_inset LatexCommand \index{-\/-vc}
11514 Something like this should work:
11533 \begin_layout Standard
11552 \begin_layout Standard
11564 -model-large -c $(InputPath)
11567 \begin_inset VSpace bigskip
11573 \begin_layout Section
11574 Environment variables
11575 \begin_inset LatexCommand \index{Environment variables}
11582 \begin_layout Standard
11583 SDCC recognizes the following environment variables:
11587 \labelwidthstring 00.00.0000
11591 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11597 SDCC installs a signal handler
11598 \begin_inset LatexCommand \index{signal handler}
11602 to be able to delete temporary files after an user break (^C) or an exception.
11603 If this environment variable is set, SDCC won't install the signal handler
11604 in order to be able to debug SDCC.
11608 \labelwidthstring 00.00.0000
11614 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11620 Path, where temporary files will be created.
11621 The order of the variables is the search order.
11622 In a standard *nix environment these variables are not set, and there's
11623 no need to set them.
11624 On Windows it's recommended to set one of them.
11628 \labelwidthstring 00.00.0000
11632 \begin_inset LatexCommand \index{SDCC\_HOME}
11639 \begin_inset LatexCommand \ref{sub:Install-paths}
11645 \begin_inset Quotes sld
11649 \begin_inset Quotes srd
11656 \labelwidthstring 00.00.0000
11660 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11667 \begin_inset LatexCommand \ref{sub:Search-Paths}
11673 \begin_inset Quotes sld
11677 \begin_inset Quotes srd
11684 \labelwidthstring 00.00.0000
11688 \begin_inset LatexCommand \index{SDCC\_LIB}
11695 \begin_inset LatexCommand \ref{sub:Search-Paths}
11701 \begin_inset Quotes sld
11705 \begin_inset Quotes srd
11711 \begin_layout Standard
11712 There are some more environment variables recognized by SDCC, but these
11713 are solely used for debugging purposes.
11714 They can change or disappear very quickly, and will never be documented.
11715 \begin_inset VSpace bigskip
11721 \begin_layout Section
11722 Storage Class Language Extensions
11725 \begin_layout Subsection
11726 MCS51/DS390 Storage Class
11727 \begin_inset LatexCommand \index{Storage class}
11731 Language Extensions
11734 \begin_layout Standard
11735 In addition to the ANSI storage classes SDCC allows the following MCS51
11736 specific storage classes:
11739 \begin_layout Subsubsection
11741 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11746 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11751 \begin_inset LatexCommand \index{near (storage class)}
11756 \begin_inset LatexCommand \index{\_\_near (storage class)}
11763 \begin_layout Standard
11768 storage class for the Small Memory model (
11776 or the more ANSI-C compliant forms
11784 can be used synonymously).
11785 Variables declared with this storage class will be allocated in the directly
11786 addressable portion of the internal RAM of a 8051, e.g.:
11789 \begin_layout Verse
11792 __data unsigned char test_data;
11795 \begin_layout Standard
11796 Writing 0x01 to this variable generates the assembly code:
11799 \begin_layout Verse
11802 75*00 01\InsetSpace ~
11810 \begin_layout Subsubsection
11812 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11817 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11822 \begin_inset LatexCommand \index{far (storage class)}
11827 \begin_inset LatexCommand \index{\_\_far (storage class)}
11834 \begin_layout Standard
11835 Variables declared with this storage class will be placed in the external
11841 storage class for the Large Memory model, e.g.:
11844 \begin_layout Verse
11847 __xdata unsigned char test_xdata;
11850 \begin_layout Standard
11851 Writing 0x01 to this variable generates the assembly code:
11854 \begin_layout Verse
11857 90s00r00\InsetSpace ~
11888 \begin_layout Subsubsection
11890 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11895 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11902 \begin_layout Standard
11903 Variables declared with this storage class will be allocated into the indirectly
11904 addressable portion of the internal ram of a 8051, e.g.:
11907 \begin_layout Verse
11910 __idata unsigned char test_idata;
11913 \begin_layout Standard
11914 Writing 0x01 to this variable generates the assembly code:
11917 \begin_layout Verse
11944 \begin_layout Standard
11945 Please note, the first 128 byte of idata physically access the same RAM
11946 as the data memory.
11947 The original 8051 had 128 byte idata memory, nowadays most devices have
11948 256 byte idata memory.
11950 \begin_inset LatexCommand \index{stack}
11954 is located in idata memory.
11957 \begin_layout Subsubsection
11959 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11964 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11971 \begin_layout Standard
11972 Paged xdata access is just as straightforward as using the other addressing
11974 It is typically located at the start of xdata and has a maximum size of
11976 The following example writes 0x01 to the pdata variable.
11977 Please note, pdata access physically accesses xdata memory.
11978 The high byte of the address is determined by port P2
11979 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11983 (or in case of some 8051 variants by a separate Special Function Register,
11985 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11994 storage class for the Medium Memory model, e.g.:
11997 \begin_layout Verse
12000 __pdata unsigned char test_pdata;
12003 \begin_layout Standard
12004 Writing 0x01 to this variable generates the assembly code:
12007 \begin_layout Verse
12016 mov r0,#_test_pdata
12038 \begin_layout Standard
12043 \begin_layout Standard
12053 \begin_inset LatexCommand \index{-\/-xstack}
12057 option is used the pdata memory area is followed by the xstack memory area
12058 and the sum of their sizes is limited to 256 bytes.
12061 \begin_layout Subsubsection
12063 \begin_inset LatexCommand \index{code}
12068 \begin_inset LatexCommand \index{\_\_code}
12075 \begin_layout Standard
12076 'Variables' declared with this storage class will be placed in the code
12080 \begin_layout Verse
12083 __code unsigned char test_code;
12086 \begin_layout Standard
12087 Read access to this variable generates the assembly code:
12090 \begin_layout Verse
12093 90s00r6F\InsetSpace ~
12096 mov dptr,#_test_code
12121 \begin_layout Standard
12126 indexed arrays of characters in code memory can be accessed efficiently:
12129 \begin_layout Verse
12132 __code char test_array[] = {'c','h','e','a','p'};
12135 \begin_layout Standard
12136 Read access to this array using an 8-bit unsigned index generates the assembly
12140 \begin_layout Verse
12152 \begin_layout Verse
12155 90s00r41\InsetSpace ~
12158 mov dptr,#_test_array
12161 \begin_layout Verse
12176 \begin_layout Subsubsection
12178 \begin_inset LatexCommand \index{bit}
12183 \begin_inset LatexCommand \index{\_\_bit}
12190 \begin_layout Standard
12191 This is a data-type and a storage class specifier.
12192 When a variable is declared as a bit, it is allocated into the bit addressable
12193 memory of 8051, e.g.:
12196 \begin_layout Verse
12202 \begin_layout Standard
12203 Writing 1 to this variable generates the assembly code:
12206 \begin_layout Verse
12220 \begin_layout Standard
12221 The bit addressable memory consists of 128 bits which are located from 0x20
12222 to 0x2f in data memory.
12225 Apart from this 8051 specific storage class most architectures support
12227 \begin_inset LatexCommand \index{bitfields}
12235 \begin_layout Standard
12236 Not really meant as examples, but nevertheless showing what bitfields are
12237 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12243 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12244 signed modifier are implemented as unsigned.
12247 \begin_layout Subsubsection
12249 \begin_inset LatexCommand \index{sfr}
12254 \begin_inset LatexCommand \index{\_\_sfr}
12259 \begin_inset LatexCommand \index{sfr16}
12264 \begin_inset LatexCommand \index{\_\_sfr16}
12269 \begin_inset LatexCommand \index{sfr32}
12274 \begin_inset LatexCommand \index{\_\_sfr32}
12279 \begin_inset LatexCommand \index{\_\_sbit}
12284 \begin_inset LatexCommand \index{sbit}
12291 \begin_layout Standard
12292 Like the bit keyword,
12294 sfr / sfr16 / sfr32 / sbit
12296 signify both a data-type and storage class, they are used to describe the
12317 variables of a 8051, eg:
12320 \begin_layout Verse
12324 \begin_inset LatexCommand \index{at}
12329 \begin_inset LatexCommand \index{\_\_at}
12333 (0x80) P0;\InsetSpace ~
12334 /* special function register P0 at location 0x80 */
12339 special function register combination for timer 0
12343 with the high byte at
12344 location 0x8C and the low byte at location 0x8A */
12346 __sfr16 __at (0x8C8A)
12352 \begin_inset LatexCommand \index{at}
12357 \begin_inset LatexCommand \index{\_\_at}
12361 (0xd7) CY;\InsetSpace ~
12363 \begin_inset LatexCommand \index{Flags}
12368 \begin_inset LatexCommand \index{Carry flag}
12375 \begin_layout Standard
12376 Special function registers which are located on an address dividable by
12377 8 are bit-addressable, an
12381 addresses a specific bit within these sfr.
12383 16 Bit and 32 bit special function
12384 register combinations which require a certain access order are better not
12394 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12395 this is not guaranteed.
12400 \begin_layout Standard
12401 Please note, if you use a header file which was written for another compiler
12402 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
12408 Specifically the syntax
12411 sfr P0 = 0x80;\InsetSpace ~
12418 by SDCC to an assignment of 0x80 to a variable called P0
12421 \begin_inset Marginal
12424 \begin_layout Standard
12436 Nevertheless it is possible to write header files
12437 \begin_inset LatexCommand \index{Header files}
12442 \begin_inset LatexCommand \index{Include files}
12446 which can be shared among different compilers (see section
12447 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
12455 \begin_layout Subsubsection
12457 \begin_inset LatexCommand \index{Pointer}
12461 to MCS51/DS390 specific memory spaces
12464 \begin_layout Standard
12465 SDCC allows (via language extensions) pointers to explicitly point to any
12466 of the memory spaces
12467 \begin_inset LatexCommand \index{Memory model}
12472 In addition to the explicit pointers, the compiler uses (by default) generic
12473 pointers which can be used to point to any of the memory spaces.
12478 declaration examples:
12481 \begin_layout Verse
12484 /* pointer physically in internal ram pointing to object in external ram
12487 __xdata unsigned char * __data p;
12491 /* pointer physically in external ram
12492 pointing to object in internal ram */
12494 __data unsigned char * __xdata p;
12499 pointer physically in code rom pointing to data in xdata space */
12502 unsigned char * __code p;
12506 /* pointer physically in code space pointing to
12507 data in code space */
12509 __code unsigned char * __code p;
12514 physically located in xdata space */
12516 unsigned char * __xdata p;
12521 pointer physically located in default memory space */
12528 the following is a function pointer
12529 \begin_inset LatexCommand \index{function pointer}
12533 physically located in data space */
12535 char (* __data fp)(void);
12538 \begin_layout Standard
12539 Well you get the idea.
12544 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
12557 The highest order byte of the
12561 pointers contains the data space information.
12562 Assembler support routines are called whenever data is stored or retrieved
12568 These are useful for developing reusable library
12569 \begin_inset LatexCommand \index{Libraries}
12574 Explicitly specifying the pointer
12575 \begin_inset LatexCommand \index{pointer}
12579 type will generate the most efficient code.
12582 \begin_layout Subsubsection
12583 Notes on MCS51 memory
12584 \begin_inset LatexCommand \index{MCS51 memory}
12591 \begin_layout Standard
12592 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12593 RAM memory which is structured as follows:
12597 - Bytes 00-1F - 32 bytes to hold
12598 up to 4 banks of the registers R0 to R7,
12600 - Bytes 20-2F - 16 bytes to hold
12602 \begin_inset LatexCommand \index{bit}
12608 - Bytes 30-7F - 80 bytes for general purpose use.
12613 \begin_layout Standard
12614 Additionally some members of the MCS51 family may have up to 128 bytes of
12615 additional, indirectly addressable, internal RAM memory (
12620 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12625 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12630 Furthermore, some chips may have some built in external memory (
12635 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12640 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12644 ) which should not be confused with the internal, directly addressable RAM
12650 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12655 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12660 Sometimes this built in
12664 memory has to be activated before using it (you can probably find this
12665 information on the datasheet of the microcontroller your are using, see
12667 \begin_inset LatexCommand \ref{sub:Startup-Code}
12675 \begin_layout Standard
12676 Normally SDCC will only use the first bank
12677 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12681 of registers (register bank 0), but it is possible to specify that other
12682 banks of registers (keyword
12689 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12694 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12700 ) should be used for example in interrupt
12701 \begin_inset LatexCommand \index{interrupt}
12706 \begin_inset LatexCommand \index{\_\_interrupt}
12711 By default, the compiler will place the stack after the last byte of allocated
12712 memory for variables.
12713 For example, if the first 2 banks of registers are used, and only four
12718 variables, it will position the base of the internal stack at address 20
12720 This implies that as the stack
12721 \begin_inset LatexCommand \index{stack}
12725 grows, it will use up the remaining register banks, and the 16 bytes used
12726 by the 128 bit variables, and 80 bytes for general purpose use.
12727 If any bit variables are used, the data variables will be placed in unused
12728 register banks and after the byte holding the last bit variable.
12729 For example, if register banks 0 and 1 are used, and there are 9 bit variables
12734 variables will be placed starting from address 0x10 to 0x20 and continue
12740 \begin_layout Standard
12750 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12754 to specify the start address of the
12762 \begin_layout Standard
12772 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12776 to specify the size of the total internal RAM (
12790 \begin_layout Standard
12791 By default the 8051 linker will place the stack after the last byte of (i)data
12797 \begin_layout Standard
12807 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12811 allows you to specify the start of the stack, i.e.
12812 you could start it after any data in the general purpose area.
12813 If your microcontroller has additional indirectly addressable internal
12818 ) you can place the stack on it.
12819 You may also need to use -
12823 \begin_layout Standard
12833 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12837 to set the start address of the external RAM (
12845 \begin_layout Standard
12855 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12859 to specify its size.
12860 Same goes for the code memory, using -
12864 \begin_layout Standard
12874 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12882 \begin_layout Standard
12892 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12897 If in doubt, don't specify any options and see if the resulting memory
12898 layout is appropriate, then you can adjust it.
12901 \begin_layout Standard
12902 The linker generates two files with memory allocation information.
12903 The first, with extension .map
12904 \begin_inset LatexCommand \index{<file>.map}
12908 shows all the variables and segments.
12909 The second with extension .mem
12910 \begin_inset LatexCommand \index{<file>.mem}
12914 shows the final memory layout.
12915 The linker will complain either if memory segments overlap, there is not
12916 enough memory, or there is not enough space for stack.
12917 If you get any linking warnings and/or errors related to stack or segments
12918 allocation, take a look at either the .map or .mem files to find out what
12920 The .mem file may even suggest a solution to the problem.
12921 \begin_inset VSpace bigskip
12927 \begin_layout Subsection
12928 Z80/Z180 Storage Class
12929 \begin_inset LatexCommand \index{Z80!Storage class}
12933 Language Extensions
12936 \begin_layout Subsubsection
12938 \begin_inset LatexCommand \index{sfr}
12943 \begin_inset LatexCommand \index{\_\_sfr}
12947 (in/out to 8-bit addresses)
12950 \begin_layout Standard
12952 \begin_inset LatexCommand \index{Z80}
12956 family has separate address spaces for memory and
12966 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12971 \begin_inset LatexCommand \index{Z80!I/O memory}
12976 \begin_inset LatexCommand \index{Z180!I/O memory}
12980 is accessed with special instructions, e.g.:
12983 \begin_layout Verse
12986 sfr at 0x78 IoPort;\InsetSpace ~
12988 /* define a var in I/O space at 78h called IoPort */
12992 \begin_layout Standard
12993 Writing 0x01 to this variable generates the assembly code:
12996 \begin_layout Verse
13016 \begin_layout Subsubsection
13018 \begin_inset LatexCommand \index{sfr}
13023 \begin_inset LatexCommand \index{\_\_sfr}
13027 (in/out to 16-bit addresses)
13030 \begin_layout Standard
13035 is used to support 16 bit addresses in I/O memory e.g.:
13038 \begin_layout Verse
13042 \begin_inset LatexCommand \index{at}
13047 \begin_inset LatexCommand \index{\_\_at}
13054 \begin_layout Standard
13055 Writing 0x01 to this variable generates the assembly code:
13058 \begin_layout Verse
13061 01 23 01\InsetSpace ~
13083 \begin_layout Subsubsection
13085 \begin_inset LatexCommand \index{sfr}
13090 \begin_inset LatexCommand \index{\_\_sfr}
13094 (in0/out0 to 8 bit addresses on Z180
13095 \begin_inset LatexCommand \index{Z180}
13100 \begin_inset LatexCommand \index{HD64180 (see Z180)}
13107 \begin_layout Standard
13108 The compiler option -
13112 \begin_layout Standard
13122 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
13126 =180 (80) and a compiler #pragma\InsetSpace ~
13128 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
13132 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
13142 If you include the file z180.h this will be set automatically.
13143 \begin_inset VSpace bigskip
13149 \begin_layout Subsection
13151 \begin_inset LatexCommand \index{HC08!Storage class}
13155 Language Extensions
13158 \begin_layout Subsubsection
13160 \begin_inset LatexCommand \index{data (hc08 storage class)}
13165 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
13172 \begin_layout Standard
13173 The data storage class declares a variable that resides in the first 256
13174 bytes of memory (the direct page).
13176 \begin_inset LatexCommand \index{HC08}
13180 is most efficient at accessing variables (especially pointers) stored here.
13183 \begin_layout Subsubsection
13185 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
13190 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
13197 \begin_layout Standard
13198 The xdata storage class declares a variable that can reside anywhere in
13200 This is the default if no storage class is specified.
13202 \begin_inset VSpace bigskip
13208 \begin_layout Section
13209 Absolute Addressing
13210 \begin_inset LatexCommand \index{Absolute addressing}
13217 \begin_layout Standard
13218 Data items can be assigned an absolute address with the
13221 \begin_inset LatexCommand \index{at}
13226 \begin_inset LatexCommand \index{\_\_at}
13232 keyword, in addition to a storage class, e.g.:
13235 \begin_layout Verse
13239 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13244 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
13249 \begin_inset LatexCommand \index{at}
13254 \begin_inset LatexCommand \index{\_\_at}
13258 0x7ffe unsigned int chksum;
13261 \begin_layout Standard
13262 or, better conforming to ISO/IEC 9899 C:
13265 \begin_layout Verse
13268 __xdata __at (0x7ffe) unsigned int chksum;
13271 \begin_layout Standard
13272 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
13273 of the external ram.
13278 reserve any space for variables declared in this way
13279 \begin_inset Marginal
13282 \begin_layout Standard
13291 (they are implemented with an equate in the assembler).
13292 Thus it is left to the programmer to make sure there are no overlaps with
13293 other variables that are declared without the absolute address.
13294 The assembler listing file (.lst
13295 \begin_inset LatexCommand \index{<file>.lst}
13299 ) and the linker output files (.rst
13300 \begin_inset LatexCommand \index{<file>.rst}
13305 \begin_inset LatexCommand \index{<file>.map}
13309 ) are good places to look for such overlaps.
13312 \begin_layout Standard
13313 If however you provide an initializer
13314 \begin_inset LatexCommand \index{Variable initialization}
13318 actual memory allocation will take place and overlaps will be detected
13323 \begin_layout Verse
13326 __code __at (0x7ff0) char Id[5] =
13327 \begin_inset Quotes sld
13331 \begin_inset Quotes srd
13337 \begin_layout Standard
13338 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
13342 \begin_layout Standard
13343 In case of memory mapped I/O devices the keyword
13347 has to be used to tell the compiler that accesses might not be removed:
13350 \begin_layout Verse
13354 \begin_inset LatexCommand \index{volatile}
13359 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13364 \begin_inset LatexCommand \index{at}
13368 (0x8000) unsigned char PORTA_8255;
13371 \begin_layout Standard
13372 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
13377 \begin_inset LatexCommand \index{Aligned array}
13384 starts at a block (256 byte) boundary
13385 \begin_inset LatexCommand \index{block boundary}
13390 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13396 Absolute addresses can be specified for variables in all
13397 storage classes, e.g.:
13400 \begin_layout Verse
13404 \begin_inset LatexCommand \index{bit}
13409 \begin_inset LatexCommand \index{at}
13416 \begin_layout Standard
13417 The above example will allocate the variable at offset 0x02 in the bit-addressab
13419 There is no real advantage to assigning absolute addresses to variables
13420 in this manner, unless you want strict control over all the variables allocated.
13421 One possible use would be to write hardware portable code.
13422 For example, if you have a routine that uses one or more of the microcontroller
13423 I/O pins, and such pins are different for two different hardwares, you
13424 can declare the I/O pins in your routine using:
13427 \begin_layout Verse
13431 \begin_inset LatexCommand \index{volatile}
13435 __bit MOSI;\InsetSpace ~
13439 /* master out, slave in */
13441 extern volatile __bit MISO;\InsetSpace ~
13448 extern volatile __bit MCLK;\InsetSpace ~
13457 Output of a byte on a 3-wire serial bus.
13462 If needed adapt polarity of clock,
13463 polarity of data and bit order
13468 unsigned char spi_io(unsigned char out_byte)
13493 MOSI = out_byte & 0x80;
13524 /* _asm nop _endasm; */\InsetSpace ~
13532 /* for slow peripherals */
13584 \begin_layout Standard
13585 Then, someplace in the code for the first hardware you would use
13588 \begin_layout Verse
13592 \begin_inset LatexCommand \index{at}
13597 \begin_inset LatexCommand \index{\_\_at}
13601 (0x80) MOSI;\InsetSpace ~
13605 /* I/O port 0, bit 0 */
13607 __bit __at (0x81) MISO;\InsetSpace ~
13614 __bit __at (0x82) MCLK;\InsetSpace ~
13618 /* I/O port 0, bit 2 */
13621 \begin_layout Standard
13622 Similarly, for the second hardware you would use
13625 \begin_layout Verse
13628 __bit __at (0x83) MOSI;\InsetSpace ~
13632 /* I/O port 0, bit 3 */
13634 __bit __at (0x91) MISO;\InsetSpace ~
13639 I/O port 1, bit 1 */
13642 \begin_inset LatexCommand \index{bit}
13646 __at (0x92) MCLK;\InsetSpace ~
13650 /* I/O port 1, bit 2 */
13653 \begin_layout Standard
13654 and you can use the same hardware dependent routine without changes, as
13655 for example in a library.
13656 This is somehow similar to sbit, but only one absolute address has to be
13657 specified in the whole project.
13658 \begin_inset VSpace bigskip
13664 \begin_layout Section
13666 \begin_inset LatexCommand \index{Parameters}
13671 \begin_inset LatexCommand \index{function parameter}
13676 \begin_inset LatexCommand \index{local variables}
13681 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13688 \begin_layout Standard
13689 Automatic (local) variables and parameters to functions can either be placed
13690 on the stack or in data-space.
13691 The default action of the compiler is to place these variables in the internal
13692 RAM (for small model) or external RAM (for medium or large model).
13693 This in fact makes them similar to
13696 \begin_inset LatexCommand \index{static}
13702 so by default functions are non-reentrant
13703 \begin_inset LatexCommand \index{reentrant}
13712 They can be placed on the stack
13713 \begin_inset LatexCommand \index{stack}
13723 \begin_layout Standard
13733 \begin_inset LatexCommand \index{-\/-stack-auto}
13741 #pragma\InsetSpace ~
13745 \begin_inset LatexCommand \index{\#pragma stackauto}
13752 \begin_inset LatexCommand \index{reentrant}
13758 keyword in the function declaration, e.g.:
13761 \begin_layout Verse
13764 unsigned char foo(char i) __reentrant
13778 \begin_layout Standard
13779 Since stack space on 8051 is limited, the
13789 \begin_layout Standard
13800 option should be used sparingly.
13801 Note that the reentrant keyword just means that the parameters & local
13802 variables will be allocated to the stack, it
13806 mean that the function is register bank
13807 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13816 \begin_inset LatexCommand \index{local variables}
13820 can be assigned storage classes and absolute
13821 \begin_inset LatexCommand \index{Absolute addressing}
13828 \begin_layout Verse
13831 unsigned char foo()
13839 __xdata unsigned char i;
13852 \begin_inset LatexCommand \index{at}
13856 (0x31) unsigned char j;
13868 \begin_layout Standard
13869 In the above example the variable
13873 will be allocated in the external ram,
13877 in bit addressable space and
13888 \begin_layout Standard
13899 or when a function is declared as
13903 this should only be done for static variables.
13906 \begin_layout Standard
13908 \begin_inset LatexCommand \index{function parameter}
13912 however are not allowed any storage class
13913 \begin_inset LatexCommand \index{Storage class}
13917 , (storage classes for parameters will be ignored), their allocation is
13918 governed by the memory model in use, and the reentrancy options.
13921 \begin_layout Standard
13922 It is however allowed to use bit parameters in reentrant functions and also
13923 non-static local bit variables are supported.
13924 Efficient use is limited to 8 semi-bitregisters in bit space.
13925 They are pushed and popped to stack
13926 \begin_inset LatexCommand \index{stack}
13930 as a single byte just like the normal registers.
13933 \begin_layout Section
13935 \begin_inset LatexCommand \label{sub:Overlaying}
13940 \begin_inset LatexCommand \index{Overlaying}
13947 \begin_layout Standard
13949 \begin_inset LatexCommand \index{reentrant}
13953 functions SDCC will try to reduce internal ram space usage by overlaying
13954 parameters and local variables of a function (if possible).
13955 Parameters and local variables
13956 \begin_inset LatexCommand \index{local variables}
13960 of a function will be allocated to an overlayable segment if the function
13963 no other function calls and the function is non-reentrant and the memory
13965 \begin_inset LatexCommand \index{Memory model}
13972 If an explicit storage class
13973 \begin_inset LatexCommand \index{Storage class}
13977 is specified for a local variable, it will NOT be overlayed.
13980 \begin_layout Standard
13981 Note that the compiler (not the linkage editor) makes the decision for overlayin
13983 Functions that are called from an interrupt service routine
13984 \begin_inset Marginal
13987 \begin_layout Standard
13995 should be preceded by a #pragma\InsetSpace ~
13997 \begin_inset LatexCommand \index{\#pragma nooverlay}
14001 if they are not reentrant.
14004 \begin_layout Standard
14005 Also note that the compiler does not do any processing of inline assembler
14006 code, so the compiler might incorrectly assign local variables and parameters
14007 of a function into the overlay segment if the inline assembler code calls
14008 other c-functions that might use the overlay.
14009 In that case the #pragma\InsetSpace ~
14010 nooverlay should be used.
14013 \begin_layout Standard
14014 Parameters and local variables of functions that contain 16 or 32 bit multiplica
14016 \begin_inset LatexCommand \index{Multiplication}
14021 \begin_inset LatexCommand \index{Division}
14025 will NOT be overlayed since these are implemented using external functions,
14029 \begin_layout Verse
14035 \begin_inset LatexCommand \index{\#pragma nooverlay}
14041 void set_error(unsigned char errcd)
14058 some_isr () __interrupt
14059 \begin_inset LatexCommand \index{interrupt}
14089 \begin_layout Standard
14090 In the above example the parameter
14098 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
14100 not present, this could cause unpredictable runtime behavior when called
14101 from an interrupt service routine.
14102 The #pragma\InsetSpace ~
14103 nooverlay ensures that the parameters and local variables for
14104 the function are NOT overlayed.
14105 \begin_inset VSpace bigskip
14111 \begin_layout Section
14112 Interrupt Service Routines
14113 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
14120 \begin_layout Subsection
14121 General Information
14124 \begin_layout Standard
14137 outines to be coded in C, with some extended keywords.
14140 \begin_layout Verse
14143 void timer_isr (void) __interrupt (1) __using (1)
14157 \begin_layout Standard
14158 The optional number following the
14161 \begin_inset LatexCommand \index{interrupt}
14166 \begin_inset LatexCommand \index{\_\_interrupt}
14172 keyword is the interrupt number this routine will service.
14173 When present, the compiler will insert a call to this routine in the interrupt
14175 \begin_inset LatexCommand \index{interrupt vector table}
14179 for the interrupt number specified.
14180 If you have multiple source files in your project, interrupt service routines
14181 can be present in any of them, but a prototype of the isr MUST be present
14182 or included in the file that contains the function
14187 The optional (8051 specific) keyword
14190 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14195 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14201 can be used to tell the compiler to use the specified register bank when
14202 generating code for this function.
14205 Interrupt service routines open the door for some very interesting bugs:
14208 \begin_layout Subsubsection
14209 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
14213 Common interrupt pitfall: variable not declared
14218 \begin_layout Standard
14219 If an interrupt service routine changes variables which are accessed by
14220 other functions these variables have to be declared
14225 \begin_inset LatexCommand \index{volatile}
14231 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
14238 \begin_layout Subsubsection
14239 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
14243 Common interrupt pitfall:
14248 \begin_layout Standard
14249 If the access to these variables is not
14252 \begin_inset LatexCommand \index{atomic}
14259 the processor needs more than one instruction for the access and could
14260 be interrupted while accessing the variable) the interrupt must be disabled
14261 during the access to avoid inconsistent data.
14264 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
14265 and should be protected by disabling interrupts.
14266 You're not automatically on the safe side if you use 8 bit variables though.
14267 We need an example here: f.e.
14268 on the 8051 the harmless looking
14269 \begin_inset Quotes srd
14279 \begin_inset Quotes sld
14288 \begin_inset Quotes srd
14298 \begin_inset Quotes sld
14301 from within an interrupt routine might get lost if the interrupt occurs
14304 \begin_inset Quotes sld
14309 counter\InsetSpace ~
14314 \begin_inset Quotes srd
14317 is not atomic on the 8051 even if
14321 is located in data memory.
14323 Bugs like these are hard to reproduce and can
14324 cause a lot of trouble.
14328 \begin_layout Subsubsection
14329 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
14333 Common interrupt pitfall:
14338 \begin_layout Standard
14339 The return address and the registers used in the interrupt service routine
14340 are saved on the stack
14341 \begin_inset LatexCommand \index{stack}
14345 so there must be sufficient stack space.
14346 If there isn't variables or registers (or even the return address itself)
14353 \begin_inset LatexCommand \index{stack overflow}
14357 is most likely to happen if the interrupt occurs during the
14358 \begin_inset Quotes sld
14362 \begin_inset Quotes srd
14365 subroutine when the stack is already in use for f.e.
14366 many return addresses.
14369 \begin_layout Subsubsection
14370 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
14374 Common interrupt pitfall:
14376 use of non-reentrant functions
14379 \begin_layout Standard
14380 A special note here, int (16 bit) and long (32 bit) integer division
14381 \begin_inset LatexCommand \index{Division}
14386 \begin_inset LatexCommand \index{Multiplication}
14391 \begin_inset LatexCommand \index{Modulus}
14396 \begin_inset LatexCommand \index{Floating point support}
14400 operations are implemented using external support routines.
14401 If an interrupt service routine needs to do any of these operations then
14402 the support routines (as mentioned in a following section) will have to
14403 be recompiled using the
14409 \begin_layout Standard
14419 \begin_inset LatexCommand \index{-\/-stack-auto}
14425 option and the source file will need to be compiled using the
14431 \begin_layout Standard
14443 \begin_inset LatexCommand \index{-\/-int-long-reent}
14450 Note, the type promotion
14451 \begin_inset LatexCommand \index{type promotion}
14455 required by ANSI C can cause 16 bit routines to be used
14456 \begin_inset Marginal
14459 \begin_layout Standard
14468 without the programmer being aware of it.
14472 (unsigned char)(tail-1)
14474 within the if clause in section
14475 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
14482 \begin_layout Standard
14483 Calling other functions from an interrupt service routine is not recommended,
14484 avoid it if possible.
14485 Note that when some function is called from an interrupt service routine
14486 it should be preceded by a #pragma\InsetSpace ~
14488 \begin_inset LatexCommand \index{\#pragma nooverlay}
14492 if it is not reentrant.
14493 Furthermore nonreentrant functions should not be called from the main program
14494 while the interrupt service routine might be active.
14495 They also must not be called from low priority interrupt service routines
14496 while a high priority interrupt service routine might be active.
14497 You could use semaphores or make the function
14501 if all parameters are passed in registers.
14504 \begin_inset LatexCommand \ref{sub:Overlaying}
14509 about Overlaying and section
14510 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14515 about Functions using private register banks.
14516 \begin_inset VSpace bigskip
14522 \begin_layout Subsection
14523 MCS51/DS390 Interrupt Service Routines
14526 \begin_layout Standard
14528 \begin_inset LatexCommand \index{interrupt}
14532 numbers and the corresponding address & descriptions for the Standard 8051/8052
14534 SDCC will automatically adjust the
14535 \begin_inset LatexCommand \index{interrupt vector table}
14539 to the maximum interrupt number specified.
14544 \begin_layout Standard
14546 \begin_inset Tabular
14547 <lyxtabular version="3" rows="9" columns="3">
14549 <column alignment="center" valignment="top" leftline="true" width="0in">
14550 <column alignment="left" valignment="top" leftline="true" width="0in">
14551 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14552 <row topline="true" bottomline="true">
14553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14556 \begin_layout Standard
14562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14565 \begin_layout Standard
14571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14574 \begin_layout Standard
14581 <row topline="true">
14582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14585 \begin_layout Standard
14591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14594 \begin_layout Standard
14600 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14603 \begin_layout Standard
14610 <row topline="true">
14611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14614 \begin_layout Standard
14620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14623 \begin_layout Standard
14629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14632 \begin_layout Standard
14639 <row topline="true">
14640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14643 \begin_layout Standard
14649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14652 \begin_layout Standard
14658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14661 \begin_layout Standard
14668 <row topline="true">
14669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14672 \begin_layout Standard
14678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14681 \begin_layout Standard
14687 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14690 \begin_layout Standard
14697 <row topline="true">
14698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14701 \begin_layout Standard
14707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14710 \begin_layout Standard
14716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14719 \begin_layout Standard
14726 <row topline="true">
14727 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14730 \begin_layout Standard
14736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14739 \begin_layout Standard
14745 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14748 \begin_layout Standard
14755 <row topline="true">
14756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14759 \begin_layout Standard
14765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14768 \begin_layout Standard
14774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14777 \begin_layout Standard
14784 <row topline="true" bottomline="true">
14785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14788 \begin_layout Standard
14794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14797 \begin_layout Standard
14803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14806 \begin_layout Standard
14822 \begin_layout Standard
14823 If the interrupt service routine is defined without
14826 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14831 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14837 a register bank or with register bank 0 (
14841 0), the compiler will save the registers used by itself on the stack upon
14842 entry and restore them at exit, however if such an interrupt service routine
14843 calls another function then the entire register bank will be saved on the
14845 This scheme may be advantageous for small interrupt service routines which
14846 have low register usage.
14849 \begin_layout Standard
14850 If the interrupt service routine is defined to be using a specific register
14855 & psw are saved and restored, if such an interrupt service routine calls
14856 another function (using another register bank) then the entire register
14857 bank of the called function will be saved on the stack
14858 \begin_inset LatexCommand \index{stack}
14863 This scheme is recommended for larger interrupt service routines.
14864 \begin_inset VSpace bigskip
14870 \begin_layout Subsection
14872 \begin_inset LatexCommand \index{HC08}
14876 Interrupt Service Routines
14879 \begin_layout Standard
14880 Since the number of interrupts
14881 \begin_inset LatexCommand \index{HC08!interrupt}
14885 available is chip specific and the interrupt vector table always ends at
14886 the last byte of memory, the interrupt numbers corresponds to the interrupt
14887 vectors in reverse order of address.
14888 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14889 2 will use the interrupt vector at 0xfffa, and so on.
14890 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14891 this way; instead see section
14892 \begin_inset LatexCommand \ref{sub:Startup-Code}
14896 for details on customizing startup.
14897 \begin_inset VSpace bigskip
14903 \begin_layout Subsection
14904 Z80 Interrupt Service Routines
14907 \begin_layout Standard
14909 \begin_inset LatexCommand \index{Z80}
14913 uses several different methods for determining the correct interrupt
14914 \begin_inset LatexCommand \index{Z80!interrupt}
14918 vector depending on the hardware implementation.
14919 Therefore, SDCC ignores the optional interrupt number and does not attempt
14920 to generate an interrupt vector table.
14923 \begin_layout Standard
14924 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14925 instruction to return from the interrupt.
14926 To write an interrupt handler for the non-maskable interrupt, which needs
14927 a RETN instruction instead, add the
14934 \begin_layout Verse
14937 void nmi_isr (void) critical interrupt
14951 \begin_layout Standard
14952 However if you need to create a non-interruptable interrupt service routine
14953 you would also require the
14958 To distinguish between this and an nmi_isr you must provide an interrupt
14960 \begin_inset VSpace bigskip
14966 \begin_layout Section
14967 Enabling and Disabling Interrupts
14970 \begin_layout Subsection
14971 Critical Functions and Critical Statements
14974 \begin_layout Standard
14975 A special keyword may be associated with a block or a function declaring
14981 SDCC will generate code to disable all interrupts
14982 \begin_inset LatexCommand \index{interrupt}
14986 upon entry to a critical function and restore the interrupt enable to the
14987 previous state before returning.
14988 Nesting critical functions will need one additional byte on the stack
14989 \begin_inset LatexCommand \index{stack}
14996 \begin_layout Verse
14999 int foo () __critical
15000 \begin_inset LatexCommand \index{critical}
15005 \begin_inset LatexCommand \index{\_\_critical}
15030 \begin_layout Standard
15031 The critical attribute maybe used with other attributes like
15041 may also be used to disable interrupts more locally:
15044 \begin_layout Verse
15050 \begin_layout Standard
15051 More than one statement could have been included in the block.
15054 \begin_layout Subsection
15055 Enabling and Disabling Interrupts directly
15058 \begin_layout Standard
15060 \begin_inset LatexCommand \index{interrupt}
15064 can also be disabled and enabled directly (8051):
15067 \begin_layout Verse
15070 EA = 0;\InsetSpace ~
15096 \begin_layout Verse
15132 \begin_layout Verse
15135 EA = 1;\InsetSpace ~
15164 \begin_layout Verse
15203 \begin_layout Standard
15204 On other architectures which have seperate opcodes for enabling and disabling
15205 interrupts you might want to make use of defines with inline assembly
15206 \begin_inset LatexCommand \index{Assembler routines}
15211 \begin_inset LatexCommand \index{HC08!interrupt}
15218 \begin_layout Verse
15222 \begin_inset LatexCommand \index{\_asm}
15231 \begin_inset LatexCommand \index{\_endasm}
15238 \begin_layout Verse
15241 #define SEI _asm\InsetSpace ~
15248 \begin_layout Verse
15254 \begin_layout Standard
15255 Note: it is sometimes sufficient to disable only a specific interrupt source
15257 a timer or serial interrupt by manipulating an
15260 \begin_inset LatexCommand \index{interrupt mask}
15270 \begin_layout Standard
15271 Usually the time during which interrupts are disabled should be kept as
15273 This minimizes both
15278 \begin_inset LatexCommand \index{interrupt latency}
15282 (the time between the occurrence of the interrupt and the execution of
15283 the first code in the interrupt routine) and
15288 \begin_inset LatexCommand \index{interrupt jitter}
15292 (the difference between the shortest and the longest interrupt latency).
15293 These really are something different, f.e.
15294 a serial interrupt has to be served before its buffer overruns so it cares
15295 for the maximum interrupt latency, whereas it does not care about jitter.
15296 On a loudspeaker driven via a digital to analog converter which is fed
15297 by an interrupt a latency of a few milliseconds might be tolerable, whereas
15298 a much smaller jitter will be very audible.
15301 \begin_layout Standard
15302 You can reenable interrupts within an interrupt routine and on some architecture
15303 s you can make use of two (or more) levels of
15305 interrupt priorities
15308 \begin_inset LatexCommand \index{interrupt priority}
15313 On some architectures which don't support interrupt priorities these can
15314 be implemented by manipulating the interrupt mask and reenabling interrupts
15315 within the interrupt routine.
15316 Check there is sufficient space on the stack
15317 \begin_inset LatexCommand \index{stack}
15321 and don't add complexity unless you have to.
15325 \begin_layout Subsection
15327 \begin_inset LatexCommand \index{semaphore}
15331 locking (mcs51/ds390)
15334 \begin_layout Standard
15335 Some architectures (mcs51/ds390) have an atomic
15336 \begin_inset LatexCommand \index{atomic}
15349 These type of instructions are typically used in preemptive multitasking
15350 systems, where a routine f.e.
15351 claims the use of a data structure ('acquires a lock
15352 \begin_inset LatexCommand \index{lock}
15356 on it'), makes some modifications and then releases the lock when the data
15357 structure is consistent again.
15358 The instruction may also be used if interrupt and non-interrupt code have
15359 to compete for a resource.
15360 With the atomic bit test and clear instruction interrupts
15361 \begin_inset LatexCommand \index{interrupt}
15365 don't have to be disabled for the locking operation.
15369 \begin_layout Standard
15370 SDCC generates this instruction if the source follows this pattern:
15373 \begin_layout Verse
15377 \begin_inset LatexCommand \index{volatile}
15381 bit resource_is_free;
15385 if (resource_is_free)
15395 resource_is_free=0;
15408 resource_is_free=1;
15415 \begin_layout Standard
15416 Note, mcs51 and ds390 support only an atomic
15417 \begin_inset LatexCommand \index{atomic}
15425 instruction (as opposed to atomic bit test and
15430 \begin_layout Section
15431 Functions using private register banks
15432 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
15439 \begin_layout Standard
15440 Some architectures have support for quickly changing register sets.
15441 SDCC supports this feature with the
15444 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
15449 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
15455 attribute (which tells the compiler to use a register bank
15456 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
15460 other than the default bank zero).
15461 It should only be applied to
15464 \begin_inset LatexCommand \index{interrupt}
15470 functions (see footnote below).
15471 This will in most circumstances make the generated ISR code more efficient
15472 since it will not have to save registers on the stack.
15475 \begin_layout Standard
15480 attribute will have no effect on the generated code for a
15484 function (but may occasionally be useful anyway
15488 \begin_layout Standard
15489 possible exception: if a function is called ONLY from 'interrupt' functions
15490 using a particular bank, it can be declared with the same 'using' attribute
15491 as the calling 'interrupt' functions.
15492 For instance, if you have several ISRs using bank one, and all of them
15493 call memcpy(), it might make sense to create a specialized version of memcpy()
15494 'using 1', since this would prevent the ISR from having to save bank zero
15495 to the stack on entry and switch to bank zero before calling the function
15504 (pending: Note, nowadays the
15508 attribute has an effect on
15512 the generated code for a
15523 \begin_layout Standard
15528 function using a non-zero bank will assume that it can trash that register
15529 bank, and will not save it.
15530 Since high-priority interrupts
15531 \begin_inset LatexCommand \index{interrupts}
15536 \begin_inset LatexCommand \index{interrupt priority}
15540 can interrupt low-priority ones on the 8051 and friends, this means that
15541 if a high-priority ISR
15545 a particular bank occurs while processing a low-priority ISR
15549 the same bank, terrible and bad things can happen.
15550 To prevent this, no single register bank should be
15554 by both a high priority and a low priority ISR.
15555 This is probably most easily done by having all high priority ISRs use
15556 one bank and all low priority ISRs use another.
15557 If you have an ISR which can change priority at runtime, you're on your
15558 own: I suggest using the default bank zero and taking the small performance
15562 \begin_layout Standard
15563 It is most efficient if your ISR calls no other functions.
15564 If your ISR must call other functions, it is most efficient if those functions
15565 use the same bank as the ISR (see note 1 below); the next best is if the
15566 called functions use bank zero.
15567 It is very inefficient to call a function using a different, non-zero bank
15570 \begin_inset VSpace bigskip
15576 \begin_layout Section
15578 \begin_inset LatexCommand \label{sub:Startup-Code}
15583 \begin_inset LatexCommand \index{Startup code}
15590 \begin_layout Subsection
15591 MCS51/DS390 Startup Code
15594 \begin_layout Standard
15595 The compiler triggers the linker to link certain initialization modules
15596 from the runtime library
15597 \begin_inset LatexCommand \index{Runtime library}
15601 called crt<something>.
15602 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15603 GSINIT5) is not linked unless the -
15609 \begin_layout Standard
15620 -xstack option is used.
15621 These modules are highly entangled by the use of special segments/areas,
15622 but a common layout is shown below:
15625 \begin_layout Verse
15633 \begin_layout Verse
15657 ljmp __sdcc_gsinit_startup
15660 \begin_layout Verse
15668 \begin_layout Verse
15680 .area GSINIT0 (CODE)
15682 __sdcc_gsinit_startup::
15692 mov sp,#__start__stack - 1
15695 \begin_layout Verse
15703 \begin_layout Verse
15715 .area GSINIT1 (CODE)
15717 __sdcc_init_xstack::
15719 ; Need to initialize in GSINIT1 in
15720 case the user's __sdcc_external_startup uses the xstack.
15730 mov __XPAGE,#(__start__x
15741 mov _spx,#__start__xstack
15744 \begin_layout Verse
15752 \begin_layout Verse
15764 .area GSINIT2 (CODE)
15774 lcall __sdcc_external_startup
15794 jz __sdcc_init_data
15805 __sdcc_program_startup
15810 \begin_layout Verse
15818 \begin_layout Verse
15830 .area GSINIT3 (CODE)
15883 mov r2,#((l_XINIT+255) >> 8)
15914 __XPAGE,#(s_XISEG >> 8)
15916 00001$:\InsetSpace ~
15980 00002$:\InsetSpace ~
16007 \begin_layout Verse
16015 \begin_layout Verse
16027 .area GSINIT4 (CODE)
16029 __mcs51_genRAMCLEAR::
16051 00004$:\InsetSpace ~
16065 ; _mcs51_genRAMCLEAR() end
16068 \begin_layout Verse
16076 \begin_layout Verse
16088 .area GSINIT4 (CODE)
16090 __mcs51_genXRAMCLEAR::
16151 mov __XPAGE,#(s_PSEG >> 8)
16163 00005$:\InsetSpace ~
16238 mov r1,#((l_XSEG + 255) >> 8)
16260 00007$:\InsetSpace ~
16297 \begin_layout Verse
16305 \begin_layout Verse
16317 .area GSINIT5 (CODE)
16319 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
16322 ; and __mcs51_genRAMCLEAR modifies _spx.
16332 mov __XPAGE,#(__start__x
16343 mov _spx,#__start__xstack
16346 \begin_layout Verse
16351 (application modules)
16354 \begin_layout Verse
16366 .area GSINIT (CODE)
16369 \begin_layout Verse
16377 \begin_layout Verse
16389 .area GSFINAL (CODE)
16399 ljmp __sdcc_program_startup
16401 ;---------------------------------
16402 -----------------------
16406 ;--------------------------------------------------
16429 __sdcc_program_startup:
16442 return from main will lock up
16455 \begin_layout Standard
16456 One of these modules (crtstart.asm) contains a call to the C routine
16458 _sdcc_external_startup()
16459 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
16468 at the start of the CODE area.
16469 This routine is also in the runtime library
16470 \begin_inset LatexCommand \index{Runtime library}
16474 and returns 0 by default.
16475 If this routine returns a non-zero value, the static & global variable
16476 initialization will be skipped and the function main will be invoked.
16477 Otherwise static & global variables will be initialized before the function
16481 _sdcc_external_startup()
16483 routine to your program to override the default if you need to setup hardware
16484 or perform some other critical operation prior to static & global variable
16486 \begin_inset LatexCommand \index{Variable initialization}
16491 On some mcs51 variants xdata
16492 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
16496 memory has to be explicitly enabled before it can be accessed or if the
16498 \begin_inset LatexCommand \index{watchdog}
16502 needs to be disabled, this is the place to do it.
16503 The startup code clears all internal data memory, 256 bytes by default,
16504 but from 0 to n-1 if
16510 \begin_layout Standard
16520 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16527 (recommended for Chipcon CC1010).
16530 \begin_layout Standard
16531 See also the compiler options
16537 \begin_layout Standard
16553 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16563 \begin_layout Standard
16575 \begin_inset LatexCommand \index{-\/-main-return}
16580 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16584 about MCS51-variants.
16589 \begin_layout Standard
16590 While these initialization modules are meant as generic startup code there
16591 might be the need for customization.
16592 Let's assume the return value of
16594 _sdcc_external_startup()
16600 should not be checked (or
16602 _sdcc_external_startup()
16604 should not be called at all).
16605 The recommended way would be to copy
16611 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm}
16615 ) into the source directory, adapt it there, then assemble it with
16621 \begin_layout Standard
16622 \begin_inset Quotes sld
16626 \begin_inset Quotes srd
16629 are the assembler options used in
16630 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup }
16641 and when linking your project explicitely specify
16646 As a bonus a listing of the relocated object file
16653 \begin_layout Standard
16654 \begin_inset VSpace bigskip
16660 \begin_layout Subsection
16664 \begin_layout Standard
16666 \begin_inset LatexCommand \index{HC08}
16670 startup code follows the same scheme as the MCS51 startup code.
16671 \begin_inset VSpace bigskip
16677 \begin_layout Subsection
16681 \begin_layout Standard
16683 \begin_inset LatexCommand \index{Z80}
16687 the startup code is inserted by linking with crt0.o which is generated from
16688 sdcc/device/lib/z80/crt0.s.
16689 If you need a different startup code you can use the compiler option
16698 \begin_layout Standard
16713 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16717 and provide your own crt0.o.
16719 \begin_inset VSpace bigskip
16725 \begin_layout Section
16726 Inline Assembler Code
16727 \begin_inset LatexCommand \index{Assembler routines}
16734 \begin_layout Subsection
16735 A Step by Step Introduction
16736 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16743 \begin_layout Standard
16744 Starting from a small snippet of c-code this example shows for the MCS51
16745 how to use inline assembly, access variables, a function parameter and
16746 an array in xdata memory.
16747 The example uses an MCS51 here but is easily adapted for other architectures.
16748 This is a buffer routine which should be optimized:
16751 \begin_layout Verse
16755 unsigned char __far
16756 \begin_inset LatexCommand \index{far (storage class)}
16761 \begin_inset LatexCommand \index{\_\_far (storage class)}
16766 \begin_inset LatexCommand \index{at}
16771 \begin_inset LatexCommand \index{\_\_at}
16775 (0x7f00) buf[0x100];
16776 \begin_inset LatexCommand \index{Aligned array}
16782 unsigned char head, tail;\InsetSpace ~
16800 \begin_inset LatexCommand \index{interrupt}
16852 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16864 void to_buffer( unsigned char c )
16872 if( head != (unsigned char)(tail-1)
16879 \begin_inset LatexCommand \index{promotion to signed int}
16884 \begin_inset LatexCommand \index{type promotion}
16889 \begin_inset Marginal
16892 \begin_layout Standard
16911 buf[ head++ ] = c;\InsetSpace ~
16927 /* access to a 256 byte aligned array */
16932 \begin_layout Standard
16933 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16934 then a corresponding buffer.asm file is generated.
16935 We define a new function
16939 in file buffer.c in which we cut and paste the generated code, removing
16940 unwanted comments and some ':'.
16942 \begin_inset Quotes sld
16950 \begin_inset Quotes srd
16954 \begin_inset Quotes sld
16962 \begin_inset Quotes srd
16969 \begin_layout Standard
16970 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16971 and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16973 The latter is also used in the library functions.
16978 to the beginning and the end of the function body:
16981 \begin_layout Verse
16985 /* With a cut and paste from the .asm file, we have something to start with.
16991 function is not yet OK! (registers aren't saved) */
16993 void to_buffer_asm(
17003 \begin_inset LatexCommand \index{\_asm}
17008 \begin_inset LatexCommand \index{\_\_asm}
17022 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
17028 \begin_inset LatexCommand \index{promotion to signed int}
17033 \begin_inset LatexCommand \index{type promotion}
17086 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
17087 \begin_inset LatexCommand \index{Aligned array}
17153 \begin_inset LatexCommand \index{\_endasm}
17158 \begin_inset LatexCommand \index{\_\_endasm}
17167 \begin_layout Standard
17168 The new file buffer.c should compile with only one warning about the unreferenced
17169 function argument 'c'.
17170 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
17171 (1) and finally have:
17174 \begin_layout Verse
17178 unsigned char __far __at(0x7f00) buf[0x100];
17180 unsigned char head, tail;
17191 void to_buffer( unsigned char c )
17200 head != (unsigned char)(tail-1) )
17229 c; // to avoid warning: unreferenced function argument
17236 \begin_inset LatexCommand \index{\_asm}
17241 \begin_inset LatexCommand \index{\_\_asm}
17255 ; save used registers here.
17266 ; If we were still using r2,r3 we would have to push them here.
17269 ; if( head != (unsigned char)(tail-1) )
17313 could do an ANL a,#0x0f here to use a smaller buffer (see below)
17349 a,dpl \InsetSpace ~
17356 ; dpl holds lower byte of function argument
17368 dpl,_head \InsetSpace ~
17371 ; buf is 0x100 byte aligned so head can be used directly
17414 ; we could do an ANL _head,#0x0f here to use a
17415 smaller buffer (see above)
17427 ; restore used registers here
17434 \begin_inset LatexCommand \index{\_endasm}
17439 \begin_inset LatexCommand \index{\_\_endasm}
17450 \begin_layout Standard
17451 The inline assembler code can contain any valid code understood by the assembler
17452 , this includes any assembler directives and comment lines.
17453 The assembler does not like some characters like ':' or ''' in comments.
17454 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
17455 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
17460 \begin_inset LatexCommand \index{Assembler documentation}
17465 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
17473 \begin_layout Standard
17474 The compiler does not do any validation of the code within the
17477 \begin_inset LatexCommand \index{\_asm}
17482 \begin_inset LatexCommand \index{\_\_asm}
17490 \begin_inset LatexCommand \index{\_endasm}
17495 \begin_inset LatexCommand \index{\_\_endasm}
17504 Specifically it will not know which registers are used and thus register
17506 \begin_inset LatexCommand \index{push/pop}
17510 has to be done manually.
17514 \begin_layout Standard
17515 It is recommended that each assembly instruction (including labels) be placed
17516 in a separate line (as the example shows).
17521 \begin_layout Standard
17533 \begin_inset LatexCommand \index{-\/-peep-asm}
17539 command line option is used, the inline assembler code will be passed through
17540 the peephole optimizer
17541 \begin_inset LatexCommand \index{Peephole optimizer}
17546 There are only a few (if any) cases where this option makes sense, it might
17547 cause some unexpected changes in the inline assembler code.
17548 Please go through the peephole optimizer rules defined in file
17552 before using this option.
17555 \begin_layout Subsection
17557 \begin_inset LatexCommand \label{sub:Naked-Functions}
17562 \begin_inset LatexCommand \index{Naked functions}
17569 \begin_layout Standard
17570 A special keyword may be associated with a function declaring it as
17573 \begin_inset LatexCommand \index{\_naked}
17578 \begin_inset LatexCommand \index{\_\_naked}
17589 function modifier attribute prevents the compiler from generating prologue
17590 \begin_inset LatexCommand \index{function prologue}
17595 \begin_inset LatexCommand \index{function epilogue}
17599 code for that function.
17600 This means that the user is entirely responsible for such things as saving
17601 any registers that may need to be preserved, selecting the proper register
17602 bank, generating the
17606 instruction at the end, etc.
17607 Practically, this means that the contents of the function must be written
17608 in inline assembler.
17609 This is particularly useful for interrupt functions, which can have a large
17610 (and often unnecessary) prologue/epilogue.
17611 For example, compare the code generated by these two functions:
17614 \begin_layout Verse
17618 \begin_inset LatexCommand \index{volatile}
17622 data unsigned char counter;
17626 void simpleInterrupt(void) __interrupt
17627 \begin_inset LatexCommand \index{interrupt}
17632 \begin_inset LatexCommand \index{\_\_interrupt}
17650 void nakedInterrupt(void) __interrupt (2) __naked
17659 \begin_inset LatexCommand \index{\_asm}
17664 \begin_inset LatexCommand \index{\_\_asm}
17681 _counter ; does not change flags, no need to save psw
17694 include ret or reti in _naked function.
17701 \begin_inset LatexCommand \index{\_endasm}
17706 \begin_inset LatexCommand \index{\_\_endasm}
17715 \begin_layout Standard
17716 For an 8051 target, the generated simpleInterrupt looks like:
17719 \begin_layout Verse
17726 example, recent versions of SDCC generate
17732 code for simpleInterrupt() and nakedInterrupt()!
17873 \begin_layout Standard
17874 whereas nakedInterrupt looks like:
17877 \begin_layout Verse
17890 _counter ; does not change flags, no need to save psw
17909 MUST explicitly include ret or reti in _naked function
17912 \begin_layout Standard
17913 The related directive #pragma exclude
17914 \begin_inset LatexCommand \index{\#pragma exclude}
17918 allows a more fine grained control over pushing & popping
17919 \begin_inset LatexCommand \index{push/pop}
17926 \begin_layout Standard
17927 While there is nothing preventing you from writing C code inside a
17931 function, there are many ways to shoot yourself in the foot doing this,
17932 and it is recommended that you stick to inline assembler.
17935 \begin_layout Subsection
17936 Use of Labels within Inline Assembler
17939 \begin_layout Standard
17940 SDCC allows the use of in-line assembler with a few restrictions regarding
17942 All labels defined within inline assembler code have to be of the form
17947 where nnnnn is a number less than 100 (which implies a limit of utmost
17948 100 inline assembler labels
17959 \begin_layout Standard
17960 This is a slightly more stringent rule than absolutely necessary, but stays
17961 always on the safe side.
17962 Labels in the form of nnnnn$ are local labels in the assembler, locality
17963 of which is confined within two labels of the standard form.
17964 The compiler uses the same form for labels within a function (but starting
17965 from nnnnn=00100); and places always a standard label at the beginning
17966 of a function, thus limiting the locality of labels within the scope of
17968 So, if the inline assembler part would be embedded into C-code, an improperly
17969 placed non-local label in the assembler would break up the reference space
17970 for labels created by the compiler for the C-code, leading to an assembling
17974 \begin_layout Standard
17975 The numeric part of local labels does not need to have 5 digits (although
17976 this is the form of labels output by the compiler), any valid integer will
17978 Please refer to the assemblers documentation for further details.
17986 \begin_layout Verse
17990 \begin_inset LatexCommand \index{\_asm}
17995 \begin_inset LatexCommand \index{\_\_asm}
18025 \begin_inset LatexCommand \index{\_endasm}
18030 \begin_inset LatexCommand \index{\_\_endasm}
18037 \begin_layout Standard
18038 Inline assembler code cannot reference any C-labels, however it can reference
18040 \begin_inset LatexCommand \index{Labels}
18044 defined by the inline assembler, e.g.:
18047 \begin_layout Verse
18070 ; some assembler code
18091 /* some more c code */
18093 clabel:\InsetSpace ~
18095 /* inline assembler cannot reference this
18100 \begin_layout Standard
18105 is translated by the compiler into a local label, so the locality of labels
18106 within the function is not broken.
18123 0003$: ;label (can be referenced by inline assembler only)
18130 \begin_inset LatexCommand \index{\_endasm}
18135 \begin_inset LatexCommand \index{\_\_endasm}
18145 /* some more c code */
18150 \begin_layout Standard
18151 In other words inline assembly code can access labels defined in inline
18152 assembly within the scope of the function.
18153 The same goes the other way, i.e.
18154 labels defines in inline assembly can not be accessed by C statements.
18157 \begin_layout Section
18158 Interfacing with Assembler Code
18159 \begin_inset LatexCommand \index{Assembler routines}
18166 \begin_layout Subsection
18167 Global Registers used for Parameter Passing
18168 \begin_inset LatexCommand \index{Parameter passing}
18175 \begin_layout Standard
18176 The compiler always uses the global registers
18179 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18184 \begin_inset LatexCommand \index{DPTR}
18189 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
18198 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
18204 to pass the first (non-bit) parameter to a function, and also to pass the
18206 \begin_inset LatexCommand \index{return value}
18210 of function; according to the following scheme: one byte return value in
18215 , two byte value in
18224 three byte values (generic pointers) in
18236 , and four byte values in
18254 \begin_inset LatexCommand \index{generic pointer}
18258 contain type of accessed memory in
18279 \begin_inset Note Note
18282 \begin_layout Standard
18283 This might not be the case of certain memory models (medium???)
18291 \begin_layout Standard
18292 The second parameter onwards is either allocated on the stack (for reentrant
18297 \begin_layout Standard
18306 -stack-auto is used) or in data/xdata memory (depending on the memory model).
18309 \begin_layout Standard
18310 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
18311 space for reentrant functions or allocated directly in bit memory otherwise.
18314 \begin_layout Standard
18315 Functions (with two or more parameters or bit parameters) that are called
18316 through function pointers
18317 \begin_inset LatexCommand \index{function pointers}
18321 must therefor be reentrant so the compiler knows how to pass the parameters.
18324 \begin_layout Subsection
18328 \begin_layout Standard
18329 Unless the called function is declared as
18334 \begin_inset LatexCommand \index{naked}
18342 \begin_layout Standard
18352 \begin_inset LatexCommand \index{-\/-callee-saves}
18360 \begin_layout Standard
18369 -all-callee-saves command line option or the corresponding callee_saves
18370 pragma are used, the caller will save the registers (
18374 ) around the call, so the called function can destroy they content freely.
18377 \begin_layout Standard
18378 If the called function is not declared as
18382 , the caller will swap register banks around the call, if caller and callee
18383 use different register banks (having them defined by the
18391 \begin_layout Standard
18392 The called function can also use
18408 observing that they are used for parameter/return value passing.
18411 \begin_layout Subsection
18412 Assembler Routine (non-reentrant)
18415 \begin_layout Standard
18416 In the following example
18417 \begin_inset LatexCommand \index{reentrant}
18422 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
18426 the function c_func calls an assembler routine asm_func, which takes two
18428 \begin_inset LatexCommand \index{function parameter}
18435 \begin_layout Verse
18438 extern int asm_func(unsigned char, unsigned char);
18442 int c_func (unsigned char
18443 i, unsigned char j)
18451 return asm_func(i,j);
18465 return c_func(10,9);
18470 \begin_layout Standard
18471 The corresponding assembler function is:
18474 \begin_layout Verse
18477 .globl _asm_func_PARM_2
18579 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18596 \begin_layout Standard
18597 The parameter naming convention is _<function_name>_PARM_<n>, where n is
18598 the parameter number starting from 1, and counting from the left.
18599 The first parameter is passed in
18615 according to the description above.
18616 The variable name for the second parameter will be _<function_name>_PARM_2.
18621 ble the assembler routine with the following command:
18628 asx8051 -losg asmfunc.asm
18635 Then compile and link the assembler routine to the C source file with the
18643 sdcc cfunc.c asmfunc.rel
18646 \begin_layout Subsection
18647 Assembler Routine (reentrant)
18650 \begin_layout Standard
18652 \begin_inset LatexCommand \index{reentrant}
18657 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18661 the second parameter
18662 \begin_inset LatexCommand \index{function parameter}
18666 onwards will be passed on the stack, the parameters are pushed from right
18668 before the call the second leftmost parameter will be on the top of the
18669 stack (the leftmost parameter is passed in registers).
18670 Here is an example:
18673 \begin_layout Verse
18676 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18681 c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
18690 return asm_func(i,j,k);
18704 return c_func(10,9,8);
18709 \begin_layout Standard
18710 The corresponding (unoptimized) assembler routine is:
18713 \begin_layout Verse
18733 _bp,sp\InsetSpace ~
18739 ;stack contains: _bp, return
18740 address, second parameter, third parameter
18764 a,#0xfd\InsetSpace ~
18770 pointer to the second parameter
18794 a,#0xfc\InsetSpace ~
18800 to the rightmost parameter
18841 result (= sum of all three parameters)
18856 ;return value goes into dptr
18890 \begin_layout Standard
18891 The compiling and linking procedure remains the same, however note the extra
18892 entry & exit linkage required for the assembler code, _bp is the stack
18893 frame pointer and is used to compute the offset into the stack for parameters
18894 and local variables.
18895 \begin_inset VSpace bigskip
18901 \begin_layout Section
18903 \begin_inset LatexCommand \index{int (16 bit)}
18908 \begin_inset LatexCommand \index{long (32 bit)}
18915 \begin_layout Standard
18916 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18917 multiplication and modulus operations are implemented by support routines.
18918 These support routines are all developed in ANSI-C to facilitate porting
18919 to other MCUs, although some model specific assembler optimizations are
18921 The following files contain the described routines, all of them can be
18922 found in <installdir>/share/sdcc/lib.
18927 \begin_layout Standard
18929 \begin_inset Tabular
18930 <lyxtabular version="3" rows="11" columns="2">
18932 <column alignment="left" valignment="top" leftline="true" width="0">
18933 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18934 <row topline="true" bottomline="true">
18935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18938 \begin_layout Standard
18946 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18949 \begin_layout Standard
18958 <row topline="true">
18959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18962 \begin_layout Standard
18968 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18971 \begin_layout Standard
18972 16 bit multiplication
18978 <row topline="true">
18979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18982 \begin_layout Standard
18988 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18991 \begin_layout Standard
18992 signed 16 bit division (calls _divuint)
18998 <row topline="true">
18999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19002 \begin_layout Standard
19008 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19011 \begin_layout Standard
19012 unsigned 16 bit division
19018 <row topline="true">
19019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19022 \begin_layout Standard
19028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19031 \begin_layout Standard
19032 signed 16 bit modulus (calls _moduint)
19038 <row topline="true">
19039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19042 \begin_layout Standard
19048 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19051 \begin_layout Standard
19052 unsigned 16 bit modulus
19058 <row topline="true">
19059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19062 \begin_layout Standard
19068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19071 \begin_layout Standard
19072 32 bit multiplication
19078 <row topline="true">
19079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19082 \begin_layout Standard
19088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19091 \begin_layout Standard
19092 signed 32 division (calls _divulong)
19098 <row topline="true">
19099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19102 \begin_layout Standard
19108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19111 \begin_layout Standard
19112 unsigned 32 division
19118 <row topline="true">
19119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19122 \begin_layout Standard
19128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19131 \begin_layout Standard
19132 signed 32 bit modulus (calls _modulong)
19138 <row topline="true" bottomline="true">
19139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19142 \begin_layout Standard
19148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19151 \begin_layout Standard
19152 unsigned 32 bit modulus
19167 \begin_layout Standard
19168 Since they are compiled as
19173 \begin_inset LatexCommand \index{reentrant}
19178 \begin_inset LatexCommand \index{interrupt}
19182 service routines should not do any of the above operations.
19183 If this is unavoidable then the above routines will need to be compiled
19190 \begin_layout Standard
19200 \begin_inset LatexCommand \index{-\/-stack-auto}
19206 option, after which the source program will have to be compiled with
19212 \begin_layout Standard
19222 \begin_inset LatexCommand \index{-\/-int-long-reent}
19229 Notice that you don't have to call these routines directly.
19230 The compiler will use them automatically every time an integer operation
19234 \begin_layout Section
19235 Floating Point Support
19236 \begin_inset LatexCommand \index{Floating point support}
19243 \begin_layout Standard
19244 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
19245 The floating point support routines are derived from gcc's floatlib.c and
19246 consist of the following routines:
19251 \begin_layout Standard
19255 \begin_inset Tabular
19256 <lyxtabular version="3" rows="17" columns="2">
19258 <column alignment="left" valignment="top" leftline="true" width="0">
19259 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19260 <row topline="true" bottomline="true">
19261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19264 \begin_layout Standard
19279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19282 \begin_layout Standard
19289 <row topline="true">
19290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19293 \begin_layout Standard
19308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19311 \begin_layout Standard
19321 add floating point numbers
19327 <row topline="true">
19328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19331 \begin_layout Standard
19346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19349 \begin_layout Standard
19359 subtract floating point numbers
19365 <row topline="true">
19366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19369 \begin_layout Standard
19384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19387 \begin_layout Standard
19397 divide floating point numbers
19403 <row topline="true">
19404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19407 \begin_layout Standard
19422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19425 \begin_layout Standard
19435 multiply floating point numbers
19441 <row topline="true">
19442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19445 \begin_layout Standard
19460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19463 \begin_layout Standard
19473 convert floating point to unsigned char
19479 <row topline="true">
19480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19483 \begin_layout Standard
19498 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19501 \begin_layout Standard
19511 convert floating point to signed char
19517 <row topline="true">
19518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19521 \begin_layout Standard
19536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19539 \begin_layout Standard
19549 convert floating point to unsigned int
19555 <row topline="true">
19556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19559 \begin_layout Standard
19574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19577 \begin_layout Standard
19587 convert floating point to signed int
19593 <row topline="true">
19594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19597 \begin_layout Standard
19620 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19623 \begin_layout Standard
19633 convert floating point to unsigned long
19639 <row topline="true">
19640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19643 \begin_layout Standard
19658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19661 \begin_layout Standard
19671 convert floating point to signed long
19677 <row topline="true">
19678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19681 \begin_layout Standard
19696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19699 \begin_layout Standard
19709 convert unsigned char to floating point
19715 <row topline="true">
19716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19719 \begin_layout Standard
19734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19737 \begin_layout Standard
19747 convert char to floating point number
19753 <row topline="true">
19754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19757 \begin_layout Standard
19772 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19775 \begin_layout Standard
19785 convert unsigned int to floating point
19791 <row topline="true">
19792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19795 \begin_layout Standard
19810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19813 \begin_layout Standard
19823 convert int to floating point numbers
19829 <row topline="true">
19830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19833 \begin_layout Standard
19848 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19851 \begin_layout Standard
19861 convert unsigned long to floating point number
19867 <row topline="true" bottomline="true">
19868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19871 \begin_layout Standard
19886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19889 \begin_layout Standard
19899 convert long to floating point number
19914 \begin_layout Standard
19915 These support routines are developed in ANSI-C so there is room for space
19916 and speed improvement
19920 \begin_layout Standard
19921 These floating point routines (
19925 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19932 Note if all these routines are used simultaneously the data space might
19934 For serious floating point usage the large model might be needed.
19935 Also notice that you don't have to call this routines directly.
19936 The compiler will use them automatically every time a floating point operation
19938 \begin_inset VSpace bigskip
19944 \begin_layout Section
19946 \begin_inset LatexCommand \index{Libraries}
19953 \begin_layout Standard
19956 <pending: this is messy and incomplete - a little more information is in
19957 sdcc/doc/libdoc.txt
19962 \begin_layout Subsection
19963 Compiler support routines (_gptrget, _mulint etc.)
19966 \begin_layout Subsection
19967 Stdclib functions (puts, printf, strcat etc.)
19970 \begin_layout Subsubsection
19974 \begin_layout Paragraph
19975 getchar(), putchar()
19978 \begin_layout Standard
19979 \begin_inset LatexCommand \index{<stdio.h>}
19983 As usual on embedded systems you have to provide your own
19986 \begin_inset LatexCommand \index{getchar()}
19995 \begin_inset LatexCommand \index{putchar()}
20002 SDCC does not know whether the system connects to a serial line with or
20003 without handshake, LCD, keyboard or other device.
20017 You'll find examples for serial routines f.e.
20018 in sdcc/device/lib.
20019 For the mcs51 this minimalistic polling
20023 routine might be a start:
20026 \begin_layout Verse
20029 void putchar (char c) {
20035 while (!TI)\InsetSpace ~
20038 /* assumes UART is initialized */
20066 \begin_layout Paragraph
20070 \begin_layout Standard
20074 \begin_inset LatexCommand \index{printf()}
20084 does not support float (except on ds390).
20085 To enable this recompile it with the option
20091 \begin_layout Standard
20101 \begin_inset LatexCommand \index{USE\_FLOATS}
20107 on the command line.
20114 \begin_layout Standard
20124 \begin_inset LatexCommand \index{-\/-model-large}
20130 for the mcs51 port, since this uses a lot of memory.
20133 \begin_layout Standard
20134 If you're short on code memory you might want to use
20137 \begin_inset LatexCommand \index{printf\_small()}
20152 For the mcs51 there additionally are assembly versions
20155 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
20161 (subset of printf using less than 270 bytes) and
20164 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
20173 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
20179 (floating-point aware version of printf_fast) which should fit the requirements
20180 of many embedded systems (printf_fast() can be customized by unsetting
20185 support long variables and field widths).
20186 Be sure to use only one of these printf options within a project.
20191 \begin_layout Standard
20192 Feature matrix of different
20199 \begin_layout Standard
20200 \begin_inset Tabular
20201 <lyxtabular version="3" rows="14" columns="7">
20202 <features islongtable="true">
20203 <column alignment="left" valignment="middle" leftline="true" width="14col%">
20204 <column alignment="center" valignment="top" leftline="true" width="0">
20205 <column alignment="center" valignment="top" leftline="true" width="12col%">
20206 <column alignment="center" valignment="top" leftline="true" width="10col%">
20207 <column alignment="center" valignment="top" leftline="true" width="0">
20208 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
20209 <column alignment="center" valignment="top" rightline="true" width="0">
20210 <row topline="true" bottomline="true" endhead="true">
20211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20214 \begin_layout Standard
20223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20226 \begin_layout Standard
20228 \begin_inset LatexCommand \index{printf}
20237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20240 \begin_layout Standard
20248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20251 \begin_layout Standard
20257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20260 \begin_layout Standard
20266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20269 \begin_layout Standard
20275 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20278 \begin_layout Standard
20285 <row topline="true" endhead="true">
20286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20289 \begin_layout Standard
20295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20298 \begin_layout Standard
20306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20309 \begin_layout Standard
20317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20320 \begin_layout Standard
20328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20331 \begin_layout Standard
20339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20342 \begin_layout Standard
20350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20353 \begin_layout Standard
20362 <row topline="true" endhead="true">
20363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20366 \begin_layout Standard
20367 \begin_inset Quotes sld
20371 \begin_inset Quotes srd
20377 \begin_layout Standard
20383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20386 \begin_layout Standard
20392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20395 \begin_layout Standard
20401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20404 \begin_layout Standard
20410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20413 \begin_layout Standard
20419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20422 \begin_layout Standard
20428 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20431 \begin_layout Standard
20438 <row topline="true" endhead="true">
20439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20442 \begin_layout Standard
20446 \begin_layout Standard
20452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20455 \begin_layout Standard
20461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20464 \begin_layout Standard
20470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20473 \begin_layout Standard
20474 0.45k / 0.47k (+ _ltoa)
20479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20482 \begin_layout Standard
20488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20491 \begin_layout Standard
20497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20500 \begin_layout Standard
20507 <row topline="true">
20508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20511 \begin_layout Standard
20517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20520 \begin_layout Standard
20530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20533 \begin_layout Standard
20580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20583 \begin_layout Standard
20622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20625 \begin_layout Standard
20631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20634 \begin_layout Standard
20640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20643 \begin_layout Standard
20650 <row topline="true">
20651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20654 \begin_layout Standard
20655 long (32 bit) support
20660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20663 \begin_layout Standard
20669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20672 \begin_layout Standard
20678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20681 \begin_layout Standard
20687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20690 \begin_layout Standard
20696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20699 \begin_layout Standard
20714 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20717 \begin_layout Standard
20724 <row topline="true">
20725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20728 \begin_layout Standard
20729 byte arguments on stack
20734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20737 \begin_layout Standard
20743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20746 \begin_layout Standard
20752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20755 \begin_layout Standard
20761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20764 \begin_layout Standard
20770 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20773 \begin_layout Standard
20779 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20782 \begin_layout Standard
20789 <row topline="true">
20790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20793 \begin_layout Standard
20795 \begin_inset LatexCommand \index{Floating point support}
20804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20807 \begin_layout Standard
20813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20816 \begin_layout Standard
20822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20825 \begin_layout Standard
20831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20834 \begin_layout Standard
20840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20843 \begin_layout Standard
20848 \begin_layout Standard
20849 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20862 \begin_layout Standard
20869 <row topline="true">
20870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20873 \begin_layout Standard
20874 float formats %e %g
20879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20882 \begin_layout Standard
20888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20891 \begin_layout Standard
20897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20900 \begin_layout Standard
20906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20909 \begin_layout Standard
20915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20918 \begin_layout Standard
20924 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20927 \begin_layout Standard
20934 <row topline="true" bottomline="true">
20935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20938 \begin_layout Standard
20944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20947 \begin_layout Standard
20953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20956 \begin_layout Standard
20962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20965 \begin_layout Standard
20971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20974 \begin_layout Standard
20980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20983 \begin_layout Standard
20989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20992 \begin_layout Standard
20999 <row bottomline="true">
21000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21003 \begin_layout Standard
21008 \begin_layout Standard
21009 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
21013 n'); standard 8051 @ 22.1184 MHz, empty putchar()
21021 \begin_layout Standard
21027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21030 \begin_layout Standard
21036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21039 \begin_layout Standard
21045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21048 \begin_layout Standard
21054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21057 \begin_layout Standard
21063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21066 \begin_layout Standard
21072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21075 \begin_layout Standard
21082 <row bottomline="true">
21083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21086 \begin_layout Standard
21091 \begin_layout Standard
21092 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
21101 \begin_layout Standard
21107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21110 \begin_layout Standard
21116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21119 \begin_layout Standard
21125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21128 \begin_layout Standard
21134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21137 \begin_layout Standard
21143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21146 \begin_layout Standard
21152 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21155 \begin_layout Standard
21160 \begin_layout Standard
21161 printf_tiny integer speed is data dependent, worst case is 0.33 ms
21172 <row bottomline="true">
21173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21176 \begin_layout Standard
21181 \begin_layout Standard
21182 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
21191 \begin_layout Standard
21197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21200 \begin_layout Standard
21206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21209 \begin_layout Standard
21215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21218 \begin_layout Standard
21224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21227 \begin_layout Standard
21233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21236 \begin_layout Standard
21242 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21245 \begin_layout Standard
21252 <row bottomline="true">
21253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21256 \begin_layout Standard
21261 \begin_layout Standard
21262 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
21271 \begin_layout Standard
21277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21280 \begin_layout Standard
21286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21289 \begin_layout Standard
21295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21298 \begin_layout Standard
21304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21307 \begin_layout Standard
21313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21316 \begin_layout Standard
21322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21325 \begin_layout Standard
21339 \begin_layout Subsubsection
21341 \begin_inset LatexCommand \index{malloc.h}
21348 \begin_layout Standard
21349 As of SDCC 2.6.2 you no longer need to call an initialization routine before
21350 using dynamic memory allocation
21351 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
21356 \begin_inset LatexCommand \index{heap (malloc)}
21360 space of 1024 bytes is provided for malloc to allocate memory from.
21361 If you need a different heap size you need to recompile _heap.c with the
21362 required size defined in HEAP_SIZE.
21363 It is recommended to make a copy of this file into your project directory
21364 and compile it there with:
21367 \begin_layout Verse
21370 sdcc -c _heap.c -D HEAD_SIZE=2048
21373 \begin_layout Standard
21374 And then link it with:
21377 \begin_layout Verse
21380 sdcc main.rel _heap.rel
21383 \begin_layout Subsection
21384 Math functions (sinf, powf, sqrtf etc.)
21387 \begin_layout Subsubsection
21391 \begin_layout Standard
21392 See definitions in file <math.h>.
21395 \begin_layout Subsection
21399 \begin_layout Standard
21401 \begin_inset LatexCommand \index{Libraries}
21405 included in SDCC should have a license at least as liberal as the GNU Lesser
21406 General Public License
21407 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
21418 \begin_layout Standard
21419 \begin_inset Note Note
21422 \begin_layout Standard
21423 license statements for the libraries are missing.
21424 sdcc/device/lib/ser_ir.c
21427 \begin_layout Standard
21429 come with a GPL (as opposed to LGPL) License - this will not be liberal
21430 enough for many embedded programmers.
21438 \begin_layout Standard
21439 If you have ported some library or want to share experience about some code
21441 falls into any of these categories Busses (I
21442 \begin_inset Formula $^{\textrm{2}}$
21445 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
21446 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
21447 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
21448 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
21453 would certainly like to hear about it.
21456 \begin_layout Standard
21457 Programmers coding for embedded systems are not especially famous for being
21458 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
21459 e these references are very valuable.
21460 Let's help to create a climate where information is shared.
21461 \begin_inset VSpace bigskip
21467 \begin_layout Section
21471 \begin_layout Subsection
21472 MCS51 Memory Models
21473 \begin_inset LatexCommand \index{Memory model}
21478 \begin_inset LatexCommand \index{MCS51 memory model}
21485 \begin_layout Subsubsection
21486 Small, Medium and Large
21489 \begin_layout Standard
21490 SDCC allows three memory models for MCS51 code,
21499 Modules compiled with different memory models should
21503 be combined together or the results would be unpredictable.
21504 The library routines supplied with the compiler are compiled as small,
21506 The compiled library modules are contained in separate directories as small,
21507 medium and large so that you can link to the appropriate set.
21510 \begin_layout Standard
21511 When the medium or large model is used all variables declared without a
21512 storage class will be allocated into the external ram, this includes all
21513 parameters and local variables (for non-reentrant
21514 \begin_inset LatexCommand \index{reentrant}
21519 When the small model is used variables without storage class are allocated
21520 in the internal ram.
21523 \begin_layout Standard
21524 Judicious usage of the processor specific storage classes
21525 \begin_inset LatexCommand \index{Storage class}
21529 and the 'reentrant' function type will yield much more efficient code,
21530 than using the large model.
21531 Several optimizations are disabled when the program is compiled using the
21532 large model, it is therefore recommended that the small model be used unless
21533 absolutely required.
21536 \begin_layout Subsubsection
21538 \begin_inset LatexCommand \label{sub:External-Stack}
21543 \begin_inset LatexCommand \index{stack}
21548 \begin_inset LatexCommand \index{External stack (mcs51)}
21555 \begin_layout Standard
21556 The external stack (-
21560 \begin_layout Standard
21570 \begin_inset LatexCommand \index{-\/-xstack}
21574 ) is located in pdata
21575 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
21579 memory (usually at the start of the external ram segment) and uses all
21580 unused space in pdata (max.
21586 \begin_layout Standard
21595 -xstack option is used to compile the program, the parameters and local
21597 \begin_inset LatexCommand \index{local variables}
21601 of all reentrant functions are allocated in this area.
21602 This option is provided for programs with large stack space requirements.
21603 When used with the -
21607 \begin_layout Standard
21617 \begin_inset LatexCommand \index{-\/-stack-auto}
21621 option, all parameters and local variables are allocated on the external
21622 stack (note: support libraries will need to be recompiled with the same
21624 There is a predefined target in the library makefile).
21627 \begin_layout Standard
21628 The compiler outputs the higher order address byte of the external ram segment
21630 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21635 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21639 ), therefore when using the External Stack option, this port
21643 be used by the application program.
21646 \begin_layout Subsection
21648 \begin_inset LatexCommand \index{Memory model}
21653 \begin_inset LatexCommand \index{DS390 memory model}
21660 \begin_layout Standard
21661 The only model supported is Flat 24
21662 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21667 This generates code for the 24 bit contiguous addressing mode of the Dallas
21669 In this mode, up to four meg of external RAM or code space can be directly
21671 See the data sheets at www.dalsemi.com for further information on this part.
21676 that the compiler does not generate any code to place the processor into
21677 24 bitmode (although
21681 in the ds390 libraries will do that for you).
21687 \begin_inset LatexCommand \index{Tinibios (DS390)}
21691 , the boot loader or similar code must ensure that the processor is in 24
21692 bit contiguous addressing mode before calling the SDCC startup code.
21703 \begin_layout Standard
21714 option, variables will by default be placed into the XDATA segment.
21719 Segments may be placed anywhere in the 4 meg address space using the usual
21724 \begin_layout Standard
21734 Note that if any segments are located above 64K, the -r flag must be passed
21735 to the linker to generate the proper segment relocations, and the Intel
21736 HEX output format must be used.
21737 The -r flag can be passed to the linker by using the option
21741 on the SDCC command line.
21742 However, currently the linker can not handle code segments > 64k.
21745 \begin_layout Section
21747 \begin_inset LatexCommand \label{sec:Pragmas}
21752 \begin_inset LatexCommand \index{Pragmas}
21759 \begin_layout Standard
21760 Pragmas are used to turn on and/or off certain compiler options.
21761 Some of them are closely related to corresponding command-line options
21763 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21769 Pragmas should be placed before and/or after a function, placing pragmas
21770 inside a function body could have unpredictable results.
21775 following #pragma directives:
21778 \begin_layout Itemize
21784 \begin_inset LatexCommand \index{\#pragma save}
21788 - this will save most current options to the save/restore stack.
21789 See #pragma\InsetSpace ~
21793 \begin_layout Itemize
21799 \begin_inset LatexCommand \index{\#pragma restore}
21803 - will restore saved options from the last save.
21804 saves & restores can be nested.
21805 SDCC uses a save/restore stack: save pushes current options to the stack,
21806 restore pulls current options from the stack.
21807 See #pragma\InsetSpace ~
21813 \begin_layout Itemize
21819 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21824 \begin_inset LatexCommand \index{function prologue}
21828 function1[,function2[,function3...]]
21829 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21833 - The compiler by default uses a caller saves convention for register saving
21834 across function calls, however this can cause unnecessary register pushing
21836 \begin_inset LatexCommand \index{push/pop}
21840 when calling small functions from larger functions.
21841 This option can be used to switch off the register saving convention for
21842 the function names specified.
21843 The compiler will not save registers when calling these functions, extra
21844 code need to be manually inserted at the entry and exit for these functions
21845 to save and restore the registers used by these functions, this can SUBSTANTIAL
21846 LY reduce code and improve run time performance of the generated code.
21847 In the future the compiler (with inter procedural analysis) may be able
21848 to determine the appropriate scheme to use for each function call.
21853 \begin_layout Standard
21862 -callee-saves command line option is used (see page
21863 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21867 ), the function names specified in #pragma\InsetSpace ~
21869 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21873 is appended to the list of functions specified in the command line.
21876 \begin_layout Itemize
21882 \begin_inset LatexCommand \index{\#pragma exclude}
21886 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21887 of pairs of push/pop
21888 \begin_inset LatexCommand \index{push/pop}
21897 \begin_inset LatexCommand \index{interrupt}
21910 The directive should be placed immediately before the ISR function definition
21911 and it affects ALL ISR functions following it.
21912 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21913 exclude\InsetSpace ~
21915 \begin_inset LatexCommand \index{\#pragma exclude}
21920 See also the related keyword _naked
21921 \begin_inset LatexCommand \index{\_naked}
21926 \begin_inset LatexCommand \index{\_\_naked}
21933 \begin_layout Itemize
21939 \begin_inset LatexCommand \index{pedantic}
21944 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21949 \begin_inset LatexCommand \label{ite:less_pedantic}
21953 - the compiler will not warn you anymore for obvious mistakes, you're on
21955 See also the command line option -
21959 \begin_layout Standard
21969 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21976 More specifically, the following warnings will be disabled:
21978 comparison is always [true/false] due to limited range of data type
21982 overflow in implicit constant conversion
21984 (158); [the (in)famous]
21986 conditional flow changed by optimizer: so said EVELYN the modified DOG
21990 function '[function name]' must return value
21995 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21996 level) are disabled, too, namely:
21999 \begin_inset Note Note
22002 \begin_layout Standard
22003 dunno what comes here - this warning appears to be unused altogether
22012 [left/right] shifting more than size of object changed to zero
22020 integer overflow in expression
22024 unmatched #pragma save and #pragma restore
22028 comparison of 'signed char' with 'unsigned char' requires promotion to int
22032 ISO C90 does not support flexible array members
22036 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
22040 \begin_inset Note Note
22043 \begin_layout Standard
22044 appears to be always blank - what was supposed to be here?
22053 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
22054 complexity [number]
22059 \begin_layout Itemize
22065 \begin_inset LatexCommand \index{\#pragma disable\_warning}
22069 - the compiler will not warn you anymore about warning number <nnnn>.
22072 \begin_layout Itemize
22078 \begin_inset LatexCommand \index{\#pragma nogcse}
22082 - will stop global common subexpression elimination.
22085 \begin_layout Itemize
22091 \begin_inset LatexCommand \index{\#pragma noinduction}
22095 - will stop loop induction optimizations.
22098 \begin_layout Itemize
22104 \begin_inset LatexCommand \index{\#pragma noinvariant}
22108 - will not do loop invariant optimizations.
22109 For more details see Loop Invariants in section
22110 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
22117 \begin_layout Itemize
22123 \begin_inset LatexCommand \index{\#pragma noiv}
22127 - Do not generate interrupt
22128 \begin_inset LatexCommand \index{interrupt}
22133 \begin_inset LatexCommand \index{interrupt vector table}
22137 entries for all ISR functions defined after the pragma.
22138 This is useful in cases where the interrupt vector table must be defined
22139 manually, or when there is a secondary, manually defined interrupt vector
22141 for the autovector feature of the Cypress EZ-USB FX2).
22142 More elegantly this can be achieved by obmitting the optional interrupt
22143 number after the interrupt keyword, see section
22144 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
22152 \begin_layout Itemize
22158 \begin_inset LatexCommand \index{\#pragma nojtbound}
22162 - will not generate code for boundary value checking, when switch statements
22163 are turned into jump-tables (dangerous).
22164 For more details see section
22165 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
22172 \begin_layout Itemize
22178 \begin_inset LatexCommand \index{\#pragma noloopreverse}
22182 - Will not do loop reversal optimization
22185 \begin_layout Itemize
22191 \begin_inset LatexCommand \index{\#pragma nooverlay}
22195 - the compiler will not overlay the parameters and local variables of a
22199 \begin_layout Itemize
22205 \begin_inset LatexCommand \index{\#pragma stackauto}
22213 \begin_layout Standard
22223 \begin_inset LatexCommand \index{-\/-stack-auto}
22228 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
22232 Parameters and Local Variables.
22235 \begin_layout Itemize
22241 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
22245 - The compiler will optimize code generation towards fast code, possibly
22246 at the expense of code size.
22247 Currently this has little effect.
22250 \begin_layout Itemize
22256 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
22260 - The compiler will optimize code generation towards compact code, possibly
22261 at the expense of code speed.
22262 Currently this has little effect.
22265 \begin_layout Itemize
22271 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
22275 - The compiler will attempt to generate code that is both compact and fast,
22276 as long as meeting one goal is not a detriment to the other (this is the
22281 \begin_layout Itemize
22287 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
22291 - Generally follow the C89 standard, but allow SDCC features that conflict
22292 with the standard (default).
22295 \begin_layout Itemize
22301 \begin_inset LatexCommand \index{\#pragma std\_c89}
22305 - Follow the C89 standard and disable SDCC features that conflict with the
22309 \begin_layout Itemize
22315 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
22319 - Generally follow the C99 standard, but allow SDCC features that conflict
22320 with the standard (incomplete support).
22323 \begin_layout Itemize
22329 \begin_inset LatexCommand \index{\#pragma std\_c99}
22333 - Follow the C99 standard and disable SDCC features that conflict with the
22334 standard (incomplete support).
22337 \begin_layout Itemize
22343 \begin_inset LatexCommand \index{\#pragma codeseg}
22347 - Use this name (max.
22348 8 characters) for the code segment.
22353 \begin_layout Standard
22365 \begin_layout Itemize
22371 \begin_inset LatexCommand \index{\#pragma constseg}
22375 - Use this name (max.
22376 8 characters) for the const segment.
22381 \begin_layout Standard
22393 \begin_layout Standard
22394 The preprocessor SDCPP
22395 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
22399 supports the following #pragma directives:
22402 \begin_layout Itemize
22405 pedantic_parse_number
22408 \begin_inset LatexCommand \index{pedantic}
22413 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22418 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
22422 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
22423 properly and the macro LO_B(3) gets expanded.
22429 \begin_layout Standard
22438 -pedantic-parse-number command line option
22439 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
22446 Below is an example on how to use this pragma.
22449 Note: this functionality is not in conformance with standard!
22452 \begin_layout Verse
22455 #pragma pedantic_parse_number +
22456 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22464 #define LO_B(x) ((x) & 0xff)
22468 unsigned char foo(void)
22475 unsigned char c=0xfe-LO_B(3)
22490 \begin_layout Itemize
22496 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22500 (+ | -) - switch _asm _endasm block preprocessing on / off.
22502 You use this prama to define multilines of assembly code.
22503 This will prevent the preprocessor from changing the formating required
22505 Below is an example on how to use this pragma.
22508 \begin_layout Verse
22511 #pragma preproc_asm -
22512 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22518 #define MYDELAY _asm
22523 nop ;my assembly comment...
22537 #pragma preproc_asm
22568 \begin_layout Itemize
22574 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22578 (+ | -) - Allow "naked" hash in macro definition, for example:
22582 #define DIR_LO(x) #(x & 0xff)
22587 Below is an example on how to use this pragma.
22590 \begin_layout Verse
22593 #pragma preproc_asm +
22595 #pragma sdcc_hash +
22596 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22611 mov R6_B3, #(x & 0xff)
22618 mov R7_B3, #((x >> 8) & 0xff)
22642 \begin_layout Standard
22643 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22644 ons which might cause the compiler to generate extra stack and/or data space
22645 to store compiler generated temporary variables.
22646 This usually happens in large functions.
22647 Pragma directives should be used as shown in the following example, they
22648 are used to control options and optimizations for a given function.
22652 \begin_layout Verse
22656 \begin_inset LatexCommand \index{\#pragma save}
22667 /* save the current settings */
22670 \begin_inset LatexCommand \index{\#pragma nogcse}
22679 /* turnoff global subexpression elimination */
22681 #pragma noinduction
22682 \begin_inset LatexCommand \index{\#pragma noinduction}
22686 /* turn off induction optimizations */
22709 \begin_inset LatexCommand \index{\#pragma restore}
22713 /* turn the optimizations back on */
22716 \begin_layout Standard
22717 The compiler will generate a warning message when extra space is allocated.
22718 It is strongly recommended that the save and restore pragmas be used when
22719 changing options for a function.
22728 \begin_layout Section
22729 Defines Created by the Compiler
22732 \begin_layout Standard
22733 The compiler creates the following #defines
22734 \begin_inset LatexCommand \index{\#defines}
22739 \begin_inset LatexCommand \index{Defines created by the compiler}
22748 \begin_layout Standard
22749 \begin_inset Tabular
22750 <lyxtabular version="3" rows="15" columns="2">
22752 <column alignment="left" valignment="top" leftline="true" width="3in">
22753 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22754 <row topline="true" bottomline="true">
22755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22758 \begin_layout Standard
22766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22769 \begin_layout Standard
22778 <row topline="true">
22779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22782 \begin_layout Standard
22784 \begin_inset LatexCommand \index{SDCC}
22793 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22796 \begin_layout Standard
22798 Since version 2.5.6 the version number as an int (ex.
22805 <row topline="true">
22806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22809 \begin_layout Standard
22811 \begin_inset LatexCommand \index{SDCC\_mcs51}
22816 \begin_inset LatexCommand \index{SDCC\_ds390}
22821 \begin_inset LatexCommand \index{SDCC\_z80}
22830 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22833 \begin_layout Standard
22834 depending on the model used (e.g.: -mds390)
22840 <row topline="true">
22841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22844 \begin_layout Standard
22846 \begin_inset LatexCommand \index{\_\_mcs51}
22851 \begin_inset LatexCommand \index{\_\_ds390}
22856 \begin_inset LatexCommand \index{\_\_hc08}
22861 \begin_inset LatexCommand \index{\_\_z80}
22870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22873 \begin_layout Standard
22874 depending on the model used (e.g.
22881 <row topline="true">
22882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22885 \begin_layout Standard
22887 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22896 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22899 \begin_layout Standard
22906 \begin_layout Standard
22923 <row topline="true">
22924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22927 \begin_layout Standard
22929 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22941 \begin_layout Standard
22948 \begin_layout Standard
22965 <row topline="true">
22966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22969 \begin_layout Standard
22971 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22983 \begin_layout Standard
22990 \begin_layout Standard
23007 <row topline="true">
23008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23011 \begin_layout Standard
23013 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
23022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23025 \begin_layout Standard
23032 \begin_layout Standard
23049 <row topline="true">
23050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23053 \begin_layout Standard
23055 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
23064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23067 \begin_layout Standard
23074 \begin_layout Standard
23091 <row topline="true">
23092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23095 \begin_layout Standard
23097 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
23106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23109 \begin_layout Standard
23120 <row topline="true">
23121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23124 \begin_layout Standard
23126 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23138 \begin_layout Standard
23149 <row topline="true">
23150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23153 \begin_layout Standard
23155 \begin_inset LatexCommand \index{SDCC\_REVISION}
23164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23167 \begin_layout Standard
23169 SDCC svn revision number
23175 <row topline="true">
23176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23179 \begin_layout Standard
23180 SDCC_PARMS_IN_BANK1
23181 \begin_inset LatexCommand \index{SDCC\_PARMS\_IN\_BANK1}
23190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23193 \begin_layout Standard
23200 \begin_layout Standard
23217 <row topline="true">
23218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23221 \begin_layout Standard
23223 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23232 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23235 \begin_layout Standard
23242 \begin_layout Standard
23259 <row topline="true" bottomline="true">
23260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23263 \begin_layout Standard
23264 SDCC_INT_LONG_REENT
23265 \begin_inset LatexCommand \index{SDCC\_INT\_LONG\_REENT}
23274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23277 \begin_layout Standard
23284 \begin_layout Standard
23308 \begin_layout Chapter
23309 Notes on supported Processors
23312 \begin_layout Section
23314 \begin_inset LatexCommand \label{sub:MCS51-variants}
23319 \begin_inset LatexCommand \index{MCS51 variants}
23326 \begin_layout Standard
23327 MCS51 processors are available from many vendors and come in many different
23329 While they might differ considerably in respect to Special Function Registers
23330 the core MCS51 is usually not modified or is kept compatible.
23334 \begin_layout Subsection
23335 pdata access by SFR
23338 \begin_layout Standard
23339 With the upcome of devices with internal xdata and flash memory devices
23341 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
23345 as dedicated I/O port is becoming more popular.
23346 Switching the high byte for pdata
23347 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
23351 access which was formerly done by port P2 is then achieved by a Special
23353 \begin_inset LatexCommand \index{sfr}
23358 In well-established MCS51 tradition the address of this
23362 is where the chip designers decided to put it.
23363 Needless to say that they didn't agree on a common name either.
23364 So that the startup code can correctly initialize xdata variables, you
23365 should define an sfr with the name _XPAGE
23368 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
23374 at the appropriate location if the default, port P2, is not used for this.
23378 \begin_layout Verse
23381 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
23385 \begin_layout Verse
23388 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
23393 \begin_layout Verse
23396 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
23400 \begin_layout Verse
23403 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23407 \begin_layout Verse
23410 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23414 \begin_layout Standard
23415 For more exotic implementations further customizations may be needed.
23417 \begin_inset LatexCommand \ref{sub:Startup-Code}
23421 for other possibilities.
23424 \begin_layout Subsection
23425 Other Features available by SFR
23428 \begin_layout Standard
23429 Some MCS51 variants offer features like Double DPTR
23430 \begin_inset LatexCommand \index{DPTR}
23434 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
23435 These are currently not used for the MCS51 port.
23436 If you absolutely need them you can fall back to inline assembly or submit
23438 \begin_inset VSpace bigskip
23444 \begin_layout Section
23448 \begin_layout Standard
23450 \begin_inset LatexCommand \index{DS80C400}
23455 \begin_inset LatexCommand \index{DS400}
23459 microcontroller has a rich set of peripherals.
23460 In its built-in ROM library it includes functions to access some of the
23461 features, among them is a TCP stack with IP4 and IP6 support.
23462 Library headers (currently in beta status) and other files are provided
23466 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
23472 \begin_inset VSpace bigskip
23478 \begin_layout Section
23479 The Z80 and gbz80 port
23482 \begin_layout Standard
23483 SDCC can target both the Zilog Z80
23484 \begin_inset LatexCommand \index{Z80}
23488 and the Nintendo Gameboy's Z80-like gbz80
23489 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
23494 The Z80 port is passed through the same
23497 \begin_inset LatexCommand \index{Regression test}
23504 \begin_inset LatexCommand \ref{sec:Quality-control}
23508 ) as the MCS51 and DS390 ports, so floating point support, support for long
23509 variables and bitfield support is fine.
23510 See mailing lists and forums about interrupt routines.
23513 \begin_layout Standard
23514 As always, the code is the authoritative reference - see z80/ralloc.c and
23517 \begin_inset LatexCommand \index{Z80!stack}
23521 frame is similar to that generated by the IAR Z80 compiler.
23522 IX is used as the base pointer, HL and IY are used as a temporary registers,
23523 and BC and DE are available for holding variables.
23525 \begin_inset LatexCommand \index{Z80!return value}
23529 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
23531 The gbz80 port use the same set of registers for the return values, but
23532 in a different order of significance: E (one byte), DE (two bytes), or
23534 \begin_inset VSpace bigskip
23540 \begin_layout Section
23544 \begin_layout Standard
23545 The port to the Freescale/Motorola HC08
23546 \begin_inset LatexCommand \index{HC08}
23550 family has been added in October 2003, and is still undergoing some basic
23552 The code generator is complete, but the register allocation is still quite
23554 Some of the SDCC's standard C library functions have embedded non-HC08
23555 inline assembly and so are not yet usable.
23558 \begin_layout Standard
23559 The HC08 port passes the regression test suite (see section
23560 \begin_inset LatexCommand \ref{sec:Quality-control}
23565 \begin_inset VSpace bigskip
23573 \begin_layout Section
23575 \begin_inset LatexCommand \index{PIC14}
23582 \begin_layout Standard
23583 The PIC14 port adds support for Microchip
23584 \begin_inset LatexCommand \index{Microchip}
23589 \begin_inset Formula $^{\text{TM}}$
23593 \begin_inset LatexCommand \index{PIC14}
23598 \begin_inset Formula $^{\text{TM}}$
23601 MCUs with 14 bit wide instructions.
23602 This port is not yet mature and still lacks many features.
23603 However, it can work for simple code.
23606 \begin_layout Standard
23607 Currently supported devices include:
23610 \begin_layout Standard
23611 12F: 629, 635, 675, 683
23614 \begin_layout Standard
23618 \begin_layout Standard
23622 \begin_layout Standard
23623 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
23626 \begin_layout Standard
23627 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
23631 \begin_layout Standard
23635 \begin_layout Standard
23636 16F: 627, 627a, 628, 628a, 630, 636, 639, 648a, 676, 684, 685, 687, 688,
23640 \begin_layout Standard
23641 16F: 716, 72, 73, 737, 74, 76, 767, 77, 777, 785
23644 \begin_layout Standard
23645 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
23649 \begin_layout Standard
23650 16F: 913, 914, 916, 917
23653 \begin_layout Standard
23654 An up-to-date list of currently supported devices can be obtained via
23656 sdcc -mpic14 -phelp foo.c
23658 (foo.c must exist...).
23661 \begin_layout Subsection
23663 \begin_inset LatexCommand \index{code page (pic14)}
23668 \begin_inset LatexCommand \index{Memory bank (pic14)}
23675 \begin_layout Standard
23676 The linker organizes allocation for the code page and RAM banks.
23677 It does not have intimate knowledge of the code flow.
23678 It will put all the code section of a single .asm file into a single code
23680 In order to make use of multiple code pages, separate asm files must be
23682 The compiler assigns all
23686 functions of a single .c file into the same code page.
23690 To get the best results,
23691 follow these guidelines:
23694 \begin_layout Enumerate
23695 Make local functions static, as non static functions require code page selection
23698 Due to the way sdcc handles functions, place called functions prior
23699 to calling functions in the file wherever possible: Otherwise sdcc will
23700 insert unneccessary pagesel directives around the call, believing that
23701 the called function is externally defined.
23704 \begin_layout Enumerate
23705 For devices that have multiple code pages it is more efficient to use the
23706 same number of files as pages: Use up to 4 separate .c files for the 16F877,
23707 but only 2 files for the 16F874.
23708 This way the linker can put the code for each file into different code
23709 pages and there will be less page selection overhead.
23712 \begin_layout Enumerate
23713 And as for any 8 bit micro (especially for PIC14 as they have a very simple
23714 instruction set), use `unsigned char' wherever possible instead of `int'.
23717 \begin_layout Subsection
23718 Adding New Devices to the Port
23721 \begin_layout Standard
23722 Adding support for a new 14
23726 \begin_layout Standard
23735 bit PIC MCU requires the following steps:
23738 \begin_layout Enumerate
23739 Create a new device description.
23741 Each device is described in two files: pic16f*.h
23743 These files primarily define SFRs, structs to access their bits, and symbolic
23744 configuration options.
23745 Both files can be generated from gputils' .inc files using the perl script
23748 support/scripts/inc2h.pl
23751 This file also contains further instructions on how to proceed.
23754 \begin_layout Enumerate
23755 Copy the .h file into SDCC's include path and either add the .c file to your
23756 project or copy it to
23758 device/lib/pic/libdev
23761 Afterwards, rebuild and install the libraries.
23764 \begin_layout Enumerate
23765 Edit pic14devices.txt in SDCC's include path (
23767 device/include/pic/
23769 in the source tree or
23771 /usr/local/share/sdcc/include/pic
23773 after installation).
23775 You need to add a device specification here to make
23776 the memory layout (code banks, RAM, aliased memory regions, ...) known to
23778 Probably you can copy and modify an existing entry.
23779 The file format is documented at the top of the file.
23782 \begin_layout Subsection
23786 \begin_layout Standard
23787 For the interrupt function, use the keyword `__interrupt'
23788 \begin_inset LatexCommand \index{PIC14!interrupt}
23792 with level number of 0 (PIC14 only has 1 interrupt so this number is only
23793 there to avoid a syntax error - it ought to be fixed).
23797 \begin_layout Verse
23800 void Intr(void) __interrupt 0
23806 T0IF = 0; /* Clear timer interrupt */
23811 \begin_layout Subsection
23812 Linking and Assembling
23815 \begin_layout Standard
23816 For assembling you can use either GPUTILS'
23817 \begin_inset LatexCommand \index{gputils (pic tools)}
23821 gpasm.exe or MPLAB's mpasmwin.exe.
23822 GPUTILS are available from
23823 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23828 For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
23829 If you use MPLAB and an interrupt function then the linker script file
23830 vectors section will need to be enlarged to link with mplink.
23841 \begin_layout Verse
23854 sdcc -V -mpic14 -p16f877 -c $<
23858 $(PRJ).hex: $(OBJS)
23868 gplink -m -s $(PRJ).lkr
23869 -o $(PRJ).hex $(OBJS) libsdcc.lib
23872 \begin_layout Standard
23880 \begin_layout Verse
23893 sdcc -S -V -mpic14 -p16f877 $<
23903 mpasmwin /q /o $*.asm
23907 $(PRJ).hex: $(OBJS)
23918 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
23921 \begin_layout Standard
23922 Please note that indentations within a
23926 have to be done with a tabulator character.
23929 \begin_layout Subsection
23930 Command-Line Options
23933 \begin_layout Standard
23934 Besides the switches common to all SDCC backends, the PIC14 port accepts
23935 the following options (for an updated list see sdcc -
23939 \begin_layout Standard
23951 \begin_layout Description
23956 \begin_layout Standard
23966 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
23970 emit debug info in assembly output
23973 \begin_layout Description
23978 \begin_layout Standard
23988 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
23992 disable (slightly faulty) optimization on pCode
23995 \begin_layout Description
24000 \begin_layout Standard
24010 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
24014 sets the lowest address of the argument passing stack (defaults to a suitably
24015 large shared databank to reduce BANKSEL overhead)
24018 \begin_layout Description
24023 \begin_layout Standard
24033 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
24037 sets the size if the argument passing stack (default: 16, minimum: 4)
24040 \begin_layout Subsection
24041 Environment Variables
24044 \begin_layout Standard
24045 The PIC14 port recognizes the following environment variables:
24048 \begin_layout Description
24049 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
24050 register (the ones called r0xNNNN) in a section of its own.
24051 By default (if this variable is unset), sdcc tries to cluster registers
24052 in sections in order to reduce the BANKSEL overhead when accessing them.
24055 \begin_layout Subsection
24059 \begin_layout Standard
24060 The PIC14 library currently only contains support routines required by the
24061 compiler to implement multiplication, division, and floating point support.
24062 No libc-like replacement is available at the moment, though many of the
24063 common sdcc library sources (in
24067 ) should also compile with the PIC14 port.
24070 \begin_layout Subsubsection
24071 error: missing definition for symbol ``__gptrget1''
24074 \begin_layout Standard
24075 The PIC14 port uses library routines to provide more complex operations
24076 like multiplication, division/modulus and (generic) pointer dereferencing.
24077 In order to add these routines to your project, you must link with PIC14's
24083 For single source file projects this is done automatically, more complex
24088 to the linker's arguments.
24089 Make sure you also add an include path for the library (using the -I switch
24093 \begin_layout Subsubsection
24094 Processor mismatch in file ``XXX''.
24097 \begin_layout Standard
24098 This warning can usually be ignored due to the very good compatibility amongst
24103 \begin_layout Standard
24113 \begin_inset LatexCommand \index{PIC14}
24120 \begin_layout Standard
24121 You might also consider recompiling the library for your specific device
24122 by changing the ARCH=p16f877 (default target) entry in
24124 device/lib/pic/Makefile.in
24128 device/lib/pic/Makefile
24130 to reflect your device.
24131 This might even improve performance for smaller devices as unneccesary
24132 BANKSELs might be removed.
24135 \begin_layout Subsection
24139 \begin_layout Subsubsection
24143 \begin_layout Standard
24144 Functions with variable argument lists (like printf) are not yet supported.
24145 Similarly, taking the argument of the first argument passed into a function
24146 does not work: It is currently passed in WREG and has no address...
24149 \begin_layout Subsubsection
24150 Regression tests fail
24153 \begin_layout Standard
24154 Though the small subset of regression tests in src/regression passes, SDCC
24155 regression test suite does not, indicating that there are still major bugs
24157 However, many smaller projects have successfully used SDCC in the past...
24160 \begin_layout Standard
24168 \begin_layout Section
24170 \begin_inset LatexCommand \index{PIC16}
24177 \begin_layout Standard
24178 The PIC16 port adds support for Microchip
24179 \begin_inset LatexCommand \index{Microchip}
24184 \begin_inset Formula $^{\text{TM}}$
24188 \begin_inset LatexCommand \index{PIC}
24193 \begin_inset Formula $^{\text{TM}}$
24196 MCUs with 16 bit wide instructions.
24197 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
24198 ; devices supported by the port include:
24201 \begin_layout Standard
24202 18F: 242, 248, 252, 258, 442, 448, 452, 458
24205 \begin_layout Standard
24209 \begin_layout Standard
24210 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 24j10, 2525, 2550, 25j10,
24214 \begin_layout Standard
24215 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 44j10, 4520, 4525, 4550,
24219 \begin_layout Standard
24220 18F: 6520, 6620, 6680, 6720
24223 \begin_layout Standard
24224 18F: 8520, 8620, 8680, 8720
24227 \begin_layout Subsection
24231 \begin_layout Standard
24232 PIC16 port supports the standard command line arguments as supposed, with
24233 the exception of certain cases that will be mentioned in the following
24237 \begin_layout Description
24242 \begin_layout Standard
24252 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
24260 \begin_layout Standard
24272 \begin_layout Description
24277 \begin_layout Standard
24286 -fommit-frame-pointer
24287 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
24291 Frame pointer will be omitted when the function uses no local variables.
24294 \begin_layout Subsection
24295 Port Specific Options
24296 \begin_inset LatexCommand \index{Options PIC16}
24303 \begin_layout Standard
24304 The port specific options appear after the global options in the sdcc -
24308 \begin_layout Standard
24320 \begin_layout Subsubsection
24321 Code Generation Options
24324 \begin_layout Standard
24325 These options influence the generated assembler code.
24328 \begin_layout Description
24333 \begin_layout Standard
24342 -pstack-model=[model] Used in conjuction with the command above.
24343 Defines the stack model to be used, valid stack models are:
24348 \labelwidthstring 00.00.0000
24353 Selects small stack model.
24354 8 bit stack and frame pointers.
24355 Supports 256 bytes stack size.
24359 \labelwidthstring 00.00.0000
24364 Selects large stack model.
24365 16 bit stack and frame pointers.
24366 Supports 65536 bytes stack size.
24370 \begin_layout Description
24375 \begin_layout Standard
24384 -pno-banksel Do not generate BANKSEL assembler directives.
24387 \begin_layout Description
24392 \begin_layout Standard
24401 -extended Enable extended instruction set/literal offset addressing mode.
24405 \begin_layout Subsubsection
24406 Optimization Options
24409 \begin_layout Description
24414 \begin_layout Standard
24423 -obanksel=n Set optimization level for inserting BANKSELs.
24430 \labelwidthstring 00.00.0000
24435 \labelwidthstring 00.00.0000
24436 1 checks previous used register and if it is the same then does not emit
24437 BANKSEL, accounts only for labels.
24441 \labelwidthstring 00.00.0000
24442 2 tries to check the location of (even different) symbols and removes BANKSELs
24443 if they are in the same bank.
24448 Important: There might be problems if the linker script has data sections
24449 across bank borders!
24453 \begin_layout Description
24458 \begin_layout Standard
24467 -denable-peeps Force the usage of peepholes.
24471 \begin_layout Description
24476 \begin_layout Standard
24485 -optimize-goto Try to use (conditional) BRA instead of GOTO.
24488 \begin_layout Description
24493 \begin_layout Standard
24502 -optimize-cmp Try to optimize some compares.
24505 \begin_layout Description
24510 \begin_layout Standard
24519 -optimize-df Analyze the dataflow of the generated code and improve it.
24522 \begin_layout Subsubsection
24526 \begin_layout Description
24531 \begin_layout Standard
24540 -asm= Sets the full path and name of an external assembler to call.
24543 \begin_layout Description
24548 \begin_layout Standard
24558 \begin_inset LatexCommand \index{PIC16!MPLAB}
24562 compatibility option.
24563 Currently only suppresses special gpasm directives.
24566 \begin_layout Subsubsection
24570 \begin_layout Description
24575 \begin_layout Standard
24584 -link= Sets the full path and name of an external linker to call.
24587 \begin_layout Description
24592 \begin_layout Standard
24601 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
24602 unitialized data variables with [kword].
24603 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
24606 \begin_layout Description
24611 \begin_layout Standard
24620 -ivt-loc=n Place the interrupt vector table at address
24625 Useful for bootloaders.
24628 \begin_layout Description
24633 \begin_layout Standard
24642 -nodefaultlibs Do not link default libraries when linking.
24645 \begin_layout Description
24650 \begin_layout Standard
24659 -use-crt= Use a custom run-time module instead of the defaults.
24662 \begin_layout Description
24667 \begin_layout Standard
24676 -no-crt Don't link the default run-time modules
24679 \begin_layout Subsubsection
24683 \begin_layout Standard
24684 Debugging options enable extra debugging information in the output files.
24687 \begin_layout Description
24692 \begin_layout Standard
24701 -debug-xtra Similar to -
24705 \begin_layout Standard
24715 \begin_inset LatexCommand \index{-\/-debug}
24719 , but dumps more information.
24722 \begin_layout Description
24727 \begin_layout Standard
24736 -debug-ralloc Force register allocator to dump <source>.d file with debugging
24738 <source> is the name of the file being compiled.
24741 \begin_layout Description
24746 \begin_layout Standard
24755 -pcode-verbose Enable pcode debugging information in translation.
24758 \begin_layout Description
24763 \begin_layout Standard
24772 -calltree Dump call tree in .calltree file.
24775 \begin_layout Description
24780 \begin_layout Standard
24789 -gstack Trace push/pops for stack pointer overflow.
24792 \begin_layout Subsection
24793 Enviroment Variables
24796 \begin_layout Standard
24797 There is a number of enviromental variables that can be used when running
24798 SDCC to enable certain optimizations or force a specific program behaviour.
24799 these variables are primarily for debugging purposes so they can be enabled/dis
24803 \begin_layout Standard
24804 Currently there is only two such variables available:
24807 \begin_layout Description
24808 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
24809 bitfields is optimized by directly loading FSR0 with the address of the
24810 bitfield structure.
24811 Normally SDCC will cast the bitfield structure to a bitfield pointer and
24813 This step saves data ram and code space for functions that make heavy use
24815 (i.e., 80 bytes of code space are saved when compiling malloc.c with this
24820 \begin_layout Description
24821 NO_REG_OPT Do not perform pCode registers optimization.
24822 This should be used for debugging purposes.
24823 If bugs in the pcode optimizer are found, users can benefit from temporarily
24824 disabling the optimizer until the bug is fixed.
24827 \begin_layout Subsection
24828 Preprocessor Macros
24831 \begin_layout Standard
24833 \begin_inset LatexCommand \index{PIC16}
24837 port defines the following preprocessor macros while translating a source.
24840 \begin_layout Standard
24842 \begin_inset Tabular
24843 <lyxtabular version="3" rows="6" columns="2">
24845 <column alignment="center" valignment="top" leftline="true" width="0">
24846 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24847 <row topline="true" bottomline="true">
24848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24851 \begin_layout Standard
24857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24860 \begin_layout Standard
24867 <row topline="true">
24868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24871 \begin_layout Standard
24877 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24880 \begin_layout Standard
24881 Port identification
24887 <row topline="true">
24888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24891 \begin_layout Standard
24896 \begin_layout Standard
24910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24913 \begin_layout Standard
24914 Port identification (same as above)
24920 <row topline="true">
24921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24924 \begin_layout Standard
24930 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24933 \begin_layout Standard
24934 MCU Identification.
24939 is the microcontrol identification number, i.e.
24946 <row topline="true">
24947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24950 \begin_layout Standard
24955 \begin_layout Standard
24969 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24972 \begin_layout Standard
24973 MCU Identification (same as above)
24979 <row topline="true" bottomline="true">
24980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24983 \begin_layout Standard
24989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24992 \begin_layout Standard
24993 nnn = SMALL or LARGE respectively according to the stack model used
25006 \begin_layout Standard
25007 In addition the following macros are defined when calling assembler:
25010 \begin_layout Standard
25012 \begin_inset Tabular
25013 <lyxtabular version="3" rows="4" columns="2">
25015 <column alignment="center" valignment="top" leftline="true" width="0">
25016 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25017 <row topline="true" bottomline="true">
25018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25021 \begin_layout Standard
25027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25030 \begin_layout Standard
25037 <row topline="true">
25038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25041 \begin_layout Standard
25047 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25050 \begin_layout Standard
25051 MCU Identification.
25056 is the microcontrol identification number, i.e.
25063 <row topline="true">
25064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25067 \begin_layout Standard
25073 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25076 \begin_layout Standard
25077 nnn = SMALL or LARGE respectively according to the memory model used for
25084 <row topline="true" bottomline="true">
25085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25088 \begin_layout Standard
25094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25097 \begin_layout Standard
25098 nnn = SMALL or LARGE respectively according to the stack model used
25111 \begin_layout Subsection
25115 \begin_layout Standard
25117 \begin_inset LatexCommand \index{PIC16}
25121 port uses the following directories for searching header files and libraries.
25124 \begin_layout Standard
25126 \begin_inset Tabular
25127 <lyxtabular version="3" rows="3" columns="4">
25129 <column alignment="center" valignment="top" leftline="true" width="0">
25130 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25131 <column alignment="center" valignment="top" width="0">
25132 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25133 <row topline="true" bottomline="true">
25134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25137 \begin_layout Standard
25143 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25146 \begin_layout Standard
25152 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25155 \begin_layout Standard
25161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25164 \begin_layout Standard
25171 <row topline="true">
25172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25175 \begin_layout Standard
25176 PREFIX/sdcc/include/pic16
25181 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25184 \begin_layout Standard
25185 PIC16 specific headers
25190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25193 \begin_layout Standard
25199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25202 \begin_layout Standard
25209 <row topline="true" bottomline="true">
25210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25213 \begin_layout Standard
25214 PREFIX/sdcc/lib/pic16
25219 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25222 \begin_layout Standard
25223 PIC16 specific libraries
25228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25231 \begin_layout Standard
25237 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25240 \begin_layout Standard
25254 \begin_layout Subsection
25256 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
25263 \begin_layout Standard
25265 \begin_inset LatexCommand \index{PIC16}
25269 port currently supports the following pragmas:
25272 \begin_layout Description
25274 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
25278 This forces the code generator to initialize the stack & frame pointers
25279 at a specific address.
25280 This is an ad hoc solution for cases where no STACK directive is available
25281 in the linker script or gplink is not instructed to create a stack section.
25284 stack pragma should be used only once in a project.
25285 Multiple pragmas may result in indeterminate behaviour of the program.
25289 \begin_layout Standard
25290 The old format (ie.
25291 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
25292 cross page boundaries (or even exceed the available data RAM) and crash
25294 Make sure that stack does not cross page boundaries when using the SMALL
25302 The format is as follows:
25307 \begin_layout LyX-Code
25308 #pragma stack bottom_address [stack_size]
25313 \begin_layout Standard
25318 is the lower bound of the stack section.
25319 The stack pointer initially will point at address (bottom_address+stack_size-1).
25322 \begin_layout LyX-Code
25326 \begin_layout LyX-Code
25330 \begin_layout LyX-Code
25331 /* initializes stack of 100 bytes at RAM address 0x200 */
25334 \begin_layout LyX-Code
25335 #pragma stack 0x200 100
25338 \begin_layout Standard
25339 If the stack_size field is omitted then a stack is created with the default
25341 This size might be enough for most programs, but its not enough for operations
25342 with deep function nesting or excessive stack usage.
25345 \begin_layout Description
25347 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
25351 Force a function to a static FLASH address.
25354 \begin_layout LyX-Code
25358 \begin_layout LyX-Code
25362 \begin_layout LyX-Code
25363 /* place function test_func at 0x4000 */
25366 \begin_layout LyX-Code
25367 #pragma code test_func 0x4000
25370 \begin_layout LyX-Code
25374 \begin_layout Description
25375 library instructs the linker to use a library module.
25380 \begin_layout LyX-Code
25381 #pragma library module_name
25384 \begin_layout Standard
25389 can be any library or object file (including its path).
25390 Note that there are four reserved keywords which have special meaning.
25394 \begin_layout Standard
25396 \begin_inset Tabular
25397 <lyxtabular version="3" rows="6" columns="3">
25399 <column alignment="center" valignment="top" leftline="true" width="0">
25400 <column alignment="block" valignment="top" leftline="true" width="20page%">
25401 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
25402 <row topline="true" bottomline="true">
25403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25406 \begin_layout Standard
25412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25415 \begin_layout Standard
25421 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25424 \begin_layout Standard
25431 <row topline="true">
25432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25435 \begin_layout Standard
25443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25446 \begin_layout Standard
25447 ignore all library pragmas
25452 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25455 \begin_layout Standard
25464 <row topline="true">
25465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25468 \begin_layout Standard
25476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25479 \begin_layout Standard
25485 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25488 \begin_layout Standard
25499 <row topline="true">
25500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25503 \begin_layout Standard
25511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25514 \begin_layout Standard
25515 link the Math libarary
25520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25523 \begin_layout Standard
25534 <row topline="true">
25535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25538 \begin_layout Standard
25546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25549 \begin_layout Standard
25550 link the I/O library
25555 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25558 \begin_layout Standard
25569 <row topline="true" bottomline="true">
25570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25573 \begin_layout Standard
25581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25584 \begin_layout Standard
25585 link the debug library
25590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25593 \begin_layout Standard
25610 * is the device number, i.e.
25611 452 for PIC18F452 MCU.
25614 \begin_layout Standard
25615 This feature allows for linking with specific libraries withoug having to
25616 explicit name them in the command line.
25621 keyword will reject all modules specified by the library pragma.
25624 \begin_layout Description
25625 udata The pragma udata instructs the compiler to emit code so that linker
25626 will place a variable at a specific memory bank.
25629 \begin_layout LyX-Code
25633 \begin_layout LyX-Code
25637 \begin_layout LyX-Code
25638 /* places variable foo at bank2 */
25641 \begin_layout LyX-Code
25642 #pragma udata bank2 foo
25645 \begin_layout LyX-Code
25649 \begin_layout Standard
25650 In order for this pragma to work extra SECTION directives should be added
25651 in the .lkr script.
25652 In the following example a sample .lkr file is shown:
25655 \begin_layout LyX-Code
25659 \begin_layout LyX-Code
25660 // Sample linker script for the PIC18F452 processor
25663 \begin_layout LyX-Code
25667 \begin_layout LyX-Code
25668 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
25671 \begin_layout LyX-Code
25672 CODEPAGE NAME=page START=0x2A END=0x7FFF
25675 \begin_layout LyX-Code
25676 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
25679 \begin_layout LyX-Code
25680 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
25683 \begin_layout LyX-Code
25684 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
25687 \begin_layout LyX-Code
25688 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
25691 \begin_layout LyX-Code
25692 ACCESSBANK NAME=accessram START=0x0 END=0x7F
25695 \begin_layout LyX-Code
25699 \begin_layout LyX-Code
25700 DATABANK NAME=gpr0 START=0x80 END=0xFF
25703 \begin_layout LyX-Code
25704 DATABANK NAME=gpr1 START=0x100 END=0x1FF
25707 \begin_layout LyX-Code
25708 DATABANK NAME=gpr2 START=0x200 END=0x2FF
25711 \begin_layout LyX-Code
25712 DATABANK NAME=gpr3 START=0x300 END=0x3FF
25715 \begin_layout LyX-Code
25716 DATABANK NAME=gpr4 START=0x400 END=0x4FF
25719 \begin_layout LyX-Code
25720 DATABANK NAME=gpr5 START=0x500 END=0x5FF
25723 \begin_layout LyX-Code
25724 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
25727 \begin_layout LyX-Code
25731 \begin_layout LyX-Code
25732 SECTION NAME=CONFIG ROM=config
25735 \begin_layout LyX-Code
25739 \begin_layout LyX-Code
25740 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
25743 \begin_layout LyX-Code
25744 SECTION NAME=bank1 RAM=gpr1 # should be added to link
25747 \begin_layout LyX-Code
25748 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
25751 \begin_layout LyX-Code
25752 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
25755 \begin_layout LyX-Code
25756 SECTION NAME=bank4 RAM=gpr4
25759 \begin_layout LyX-Code
25760 SECTION NAME=bank5 RAM=gpr5
25763 \begin_layout Standard
25764 The linker will recognise the section name set in the pragma statement and
25765 will position the variable at the memory bank set with the RAM field at
25766 the SECTION line in the linker script file.
25769 \begin_layout Subsection
25771 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
25778 \begin_layout Standard
25779 There is one main header file
25780 \begin_inset LatexCommand \index{PIC16!Header files}
25784 that can be included to the source files using the pic16
25785 \begin_inset LatexCommand \index{PIC16}
25795 This header file contains the definitions for the processor special registers,
25796 so it is necessary if the source accesses them.
25797 It can be included by adding the following line in the beginning of the
25801 \begin_layout LyX-Code
25802 #include <pic18fregs.h>
25805 \begin_layout Standard
25806 The specific microcontroller is selected within the pic18fregs.h automatically,
25807 so the same source can be used with a variety of devices.
25810 \begin_layout Subsection
25814 \begin_layout Standard
25816 \begin_inset LatexCommand \index{PIC16!Libraries}
25821 \begin_inset LatexCommand \index{PIC16}
25825 port depends on are the microcontroller device libraries which contain
25826 the symbol definitions for the microcontroller special function registers.
25827 These libraries have the format pic18fxxxx.lib, where
25831 is the microcontroller identification number.
25832 The specific library is selected automatically by the compiler at link
25833 stage according to the selected device.
25836 \begin_layout Standard
25837 Libraries are created with gplib which is part of the gputils package
25838 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
25845 \begin_layout Subsubsection*
25846 Building the libraries
25849 \begin_layout Standard
25850 Before using SDCC/pic16 there are some libraries that need to be compiled.
25851 This process is not done automatically by SDCC since not all users use
25852 SDCC for pic16 projects.
25853 So each user should compile the libraries separately.
25856 \begin_layout Standard
25857 The steps to compile the pic16 libraries under Linux and Mac OS X are:
25860 \begin_layout LyX-Code
25861 cd device/lib/pic16
25864 \begin_layout LyX-Code
25868 \begin_layout LyX-Code
25872 \begin_layout LyX-Code
25876 \begin_layout LyX-Code
25880 \begin_layout LyX-Code
25881 su -c 'make install' # install the libraries, you need the root password
25884 \begin_layout Standard
25885 If you need to install the headers too, do:
25888 \begin_layout LyX-Code
25892 \begin_layout LyX-Code
25893 su -c 'make install' # install the headers, you need the root password
25896 \begin_layout Standard
25897 There exist a special target to build the I/O libraries.
25898 This target is not automatically build because it will build the I/O library
25904 This way building will take quite a lot of time.
25905 Users are advised to edit the
25907 device/lib/pic16/pics.build
25909 file and then execute:
25912 \begin_layout LyX-Code
25916 \begin_layout Subsection
25917 Adding New Devices to the Port
25920 \begin_layout Standard
25921 Adding support for a new 16
25925 \begin_layout Standard
25934 bit PIC MCU requires the following steps:
25937 \begin_layout Enumerate
25938 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
25942 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
25946 \begin_layout Enumerate
25949 mv picDEVICE.h /path/to/sdcc/device/include/pic16
25952 \begin_layout Enumerate
25955 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
25958 \begin_layout Enumerate
25961 /path/to/sdcc/device/lib/pic16/pics.all
25969 Note: No 18f prefix here!
25972 \begin_layout Enumerate
25975 /path/to/sdcc/device/lib/pic16/libio/*.ignore
25979 Add your DEVICE if it does not compile in
25994 \begin_layout Enumerate
25997 /path/to/sdcc/device/include/pic16/pic18fregs.h
26000 The file format is self-explanatory, just add
26004 #elif defined(picDEVICE)
26006 # include <picDEVICE.h>
26010 at the right place (keep it sorted).
26013 \begin_layout Enumerate
26016 /path/to/sdcc/src/pic16/devices.inc
26019 Copy and modify an existing entry and insert it at the correct place (keep
26021 The file is hardly documented, look at the entries for the 18f2221...
26024 \begin_layout Enumerate
26025 Recompile SDCC, including the pic16 libraries.
26028 \begin_layout Subsection
26032 \begin_layout Standard
26033 The following memory models are supported by the PIC16 port:
26036 \begin_layout Itemize
26040 \begin_layout Itemize
26044 \begin_layout Standard
26045 Memory model affects the default size of pointers within the source.
26046 The sizes are shown in the next table:
26049 \begin_layout Standard
26051 \begin_inset Tabular
26052 <lyxtabular version="3" rows="3" columns="3">
26054 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26055 <column alignment="center" valignment="top" leftline="true" width="0">
26056 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26057 <row topline="true" bottomline="true">
26058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26061 \begin_layout Standard
26062 Pointer sizes according to memory model
26067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26070 \begin_layout Standard
26076 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26079 \begin_layout Standard
26086 <row topline="true" bottomline="true">
26087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26090 \begin_layout Standard
26096 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26099 \begin_layout Standard
26105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26108 \begin_layout Standard
26115 <row topline="true" bottomline="true">
26116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26119 \begin_layout Standard
26125 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
26128 \begin_layout Standard
26134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26137 \begin_layout Standard
26151 \begin_layout Standard
26152 It is advisable that all sources within a project are compiled with the
26154 If one wants to override the default memory model, this can be done by
26155 declaring a pointer as
26164 Far selects large memory model's pointers, while near selects small memory
26168 \begin_layout Standard
26169 The standard device libraries (see
26170 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
26174 ) contain no reference to pointers, so they can be used with both memory
26178 \begin_layout Subsection
26182 \begin_layout Standard
26184 \begin_inset LatexCommand \index{PIC16!stack}
26188 implementation for the PIC16 port uses two indirect registers, FSR1 and
26192 \begin_layout Description
26193 FSR1 is assigned as stack pointer
26196 \begin_layout Description
26197 FSR2 is assigned as frame pointer
26200 \begin_layout Standard
26201 The following stack models are supported by the PIC16 port
26204 \begin_layout Itemize
26212 \begin_layout Itemize
26220 \begin_layout Standard
26225 model means that only the FSRxL byte is used to access stack and frame,
26232 uses both FSRxL and FSRxH registers.
26233 The following table shows the stack/frame pointers sizes according to stack
26234 model and the maximum space they can address:
26237 \begin_layout Standard
26239 \begin_inset Tabular
26240 <lyxtabular version="3" rows="3" columns="3">
26242 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26243 <column alignment="center" valignment="top" leftline="true" width="0">
26244 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26245 <row topline="true" bottomline="true">
26246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26249 \begin_layout Standard
26250 Stack & Frame pointer sizes according to stack model
26255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26258 \begin_layout Standard
26264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26267 \begin_layout Standard
26274 <row topline="true">
26275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26278 \begin_layout Standard
26284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26287 \begin_layout Standard
26293 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26296 \begin_layout Standard
26303 <row topline="true" bottomline="true">
26304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26307 \begin_layout Standard
26313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26316 \begin_layout Standard
26322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26325 \begin_layout Standard
26339 \begin_layout Standard
26344 stack model is currently not working properly throughout the code generator.
26345 So its use is not advised.
26346 Also there are some other points that need special care:
26351 \begin_layout Enumerate
26352 Do not create stack sections with size more than one physical bank (that
26356 \begin_layout Enumerate
26357 Stack sections should no cross physical bank limits (i.e.
26358 #pragma stack 0x50 0x100)
26361 \begin_layout Standard
26362 These limitations are caused by the fact that only FSRxL is modified when
26363 using SMALL stack model, so no more than 256 bytes of stack can be used.
26364 This problem will disappear after LARGE model is fully implemented.
26367 \begin_layout Subsection
26371 \begin_layout Standard
26372 In addition to the standard SDCC function keywords, PIC16
26373 \begin_inset LatexCommand \index{PIC16}
26377 port makes available two more:
26380 \begin_layout Description
26382 \begin_inset LatexCommand \index{PIC16!wparam}
26386 Use the WREG to pass one byte of the first function argument.
26387 This improves speed but you may not use this for functions with arguments
26388 that are called via function pointers, otherwise the first byte of the
26389 first parameter will get lost.
26393 \begin_layout LyX-Code
26394 void func_wparam(int a) wparam
26397 \begin_layout LyX-Code
26401 \begin_layout LyX-Code
26402 /* WREG hold the lower part of a */
26405 \begin_layout LyX-Code
26406 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
26410 \begin_layout LyX-Code
26414 \begin_layout LyX-Code
26418 \begin_layout Description
26420 \begin_inset LatexCommand \index{PIC16!shadowregs}
26424 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
26425 hardware shadow registers which hold the values of WREG, STATUS and BSR
26427 This can be done by adding the keyword
26435 keyword in the function's header.
26438 \begin_layout LyX-Code
26439 void isr_shadow(void) shadowregs interrupt 1
26442 \begin_layout LyX-Code
26446 \begin_layout LyX-Code
26450 \begin_layout LyX-Code
26454 \begin_layout Standard
26459 instructs the code generator not to store/restore WREG, STATUS, BSR when
26460 entering/exiting the ISR.
26463 \begin_layout Subsection
26464 Function return values
26467 \begin_layout Standard
26468 Return values from functions are placed to the appropriate registers following
26469 a modified Microchip policy optimized for SDCC.
26470 The following table shows these registers:
26473 \begin_layout Standard
26475 \begin_inset Tabular
26476 <lyxtabular version="3" rows="6" columns="2">
26478 <column alignment="center" valignment="top" leftline="true" width="0">
26479 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26480 <row topline="true" bottomline="true">
26481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26484 \begin_layout Standard
26490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26493 \begin_layout Standard
26494 destination register
26500 <row topline="true">
26501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26504 \begin_layout Standard
26510 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26513 \begin_layout Standard
26520 <row topline="true">
26521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26524 \begin_layout Standard
26530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26533 \begin_layout Standard
26540 <row topline="true">
26541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26544 \begin_layout Standard
26550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26553 \begin_layout Standard
26560 <row topline="true">
26561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26564 \begin_layout Standard
26570 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26573 \begin_layout Standard
26574 FSR0L:PRODH:PRODL:WREG
26580 <row topline="true" bottomline="true">
26581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26584 \begin_layout Standard
26590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26593 \begin_layout Standard
26594 on stack, FSR0 points to the beginning
26607 \begin_layout Subsection
26611 \begin_layout Standard
26613 \begin_inset LatexCommand \index{PIC16!interrupt}
26617 service routine (ISR) is declared using the
26624 \begin_layout LyX-Code
26625 void isr(void) interrupt
26630 \begin_layout LyX-Code
26634 \begin_layout LyX-Code
26638 \begin_layout LyX-Code
26642 \begin_layout Standard
26647 is the interrupt number, which for PIC18F devices can be:
26650 \begin_layout Standard
26652 \begin_inset Tabular
26653 <lyxtabular version="3" rows="4" columns="3">
26655 <column alignment="center" valignment="top" leftline="true" width="0">
26656 <column alignment="center" valignment="top" leftline="true" width="0">
26657 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26658 <row topline="true" bottomline="true">
26659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26662 \begin_layout Standard
26670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26673 \begin_layout Standard
26679 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26682 \begin_layout Standard
26683 Interrupt Vector Address
26689 <row topline="true">
26690 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26693 \begin_layout Standard
26699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26702 \begin_layout Standard
26708 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26711 \begin_layout Standard
26718 <row topline="true">
26719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26722 \begin_layout Standard
26737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26740 \begin_layout Standard
26750 HIGH priority interrupts
26755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26758 \begin_layout Standard
26765 <row topline="true" bottomline="true">
26766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26769 \begin_layout Standard
26775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26778 \begin_layout Standard
26779 LOW priority interrupts
26784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26787 \begin_layout Standard
26801 \begin_layout Standard
26802 When generating assembly code for ISR the code generator places a
26808 Interrupt Vector Address
26810 which points at the genetated ISR.
26811 This single GOTO instruction is part of an automatically generated
26813 interrupt entry point
26816 The actuall ISR code is placed as normally would in the code space.
26817 Upon interrupt request, the GOTO instruction is executed which jumps to
26819 When declaring interrupt functions as _naked this GOTO instruction is
26824 The whole interrupt functions is therefore placed at the Interrupt Vector
26825 Address of the specific interrupt.
26826 This is not a problem for the LOW priority interrupts, but it is a problem
26827 for the RESET and the HIGH priority interrupts because code may be written
26828 at the next interrupt's vector address and cause undeterminate program
26829 behaviour if that interrupt is raised.
26833 \begin_layout Standard
26834 This is not a problem when
26837 \begin_layout Enumerate
26838 this is a HIGH interrupt ISR and LOW interrupts are
26845 \begin_layout Enumerate
26846 when the ISR is small enough not to reach the next interrupt's vector address.
26854 \begin_layout Standard
26860 This way a function is generated similar to an ISR, but it is not assigned
26864 \begin_layout Standard
26865 When entering an interrupt, currently the PIC16
26866 \begin_inset LatexCommand \index{PIC16}
26870 port automatically saves the following registers:
26873 \begin_layout Itemize
26877 \begin_layout Itemize
26881 \begin_layout Itemize
26885 \begin_layout Itemize
26886 PROD (PRODL and PRODH)
26889 \begin_layout Itemize
26890 FSR0 (FSR0L and FSR0H)
26893 \begin_layout Standard
26894 These registers are restored upon return from the interrupt routine.
26898 \begin_layout Standard
26899 NOTE that when the _naked attribute is specified for an interrupt routine,
26900 then NO registers are stored or restored.
26908 \begin_layout Subsection
26912 \begin_layout Standard
26913 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
26914 There are 3 types of generic pointers currently implemented data, code
26915 and eeprom pointers.
26916 They are differentiated by the value of the 7th and 6th bits of the upper
26920 \begin_layout Standard
26922 \begin_inset Tabular
26923 <lyxtabular version="3" rows="5" columns="5">
26925 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26926 <column alignment="center" valignment="top" width="0">
26927 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26928 <column alignment="center" valignment="top" width="0">
26929 <column alignment="left" valignment="top" rightline="true" width="0">
26930 <row topline="true" bottomline="true">
26931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26934 \begin_layout Standard
26940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26943 \begin_layout Standard
26949 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26952 \begin_layout Standard
26958 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26961 \begin_layout Standard
26962 rest of the pointer
26967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26970 \begin_layout Standard
26977 <row topline="true" bottomline="true">
26978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26981 \begin_layout Standard
26987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26990 \begin_layout Standard
26996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26999 \begin_layout Standard
27005 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27008 \begin_layout Standard
27013 uuuuuu uuuuxxxx xxxxxxxx
27018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27021 \begin_layout Standard
27022 a 12-bit data pointer in data RAM memory
27028 <row bottomline="true">
27029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27032 \begin_layout Standard
27038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27041 \begin_layout Standard
27047 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27050 \begin_layout Standard
27056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27059 \begin_layout Standard
27064 uxxxxx xxxxxxxx xxxxxxxx
27069 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27072 \begin_layout Standard
27073 a 21-bit code pointer in FLASH memory
27079 <row bottomline="true">
27080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27083 \begin_layout Standard
27089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27092 \begin_layout Standard
27098 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27101 \begin_layout Standard
27107 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27110 \begin_layout Standard
27115 uuuuuu uuuuuuxx xxxxxxxx
27120 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27123 \begin_layout Standard
27124 a 10-bit eeprom pointer in EEPROM memory
27130 <row bottomline="true">
27131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27134 \begin_layout Standard
27140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27143 \begin_layout Standard
27149 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27152 \begin_layout Standard
27158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27161 \begin_layout Standard
27166 xxxxxx xxxxxxxx xxxxxxxx
27171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27174 \begin_layout Standard
27175 unimplemented pointer type
27188 \begin_layout Standard
27189 Generic pointer are read and written with a set of library functions which
27190 read/write 1, 2, 3, 4 bytes.
27193 \begin_layout Subsection
27197 \begin_layout Subsubsection
27198 Standard I/O Streams
27201 \begin_layout Standard
27206 the type FILE is defined as:
27209 \begin_layout LyX-Code
27210 typedef char * FILE;
27213 \begin_layout Standard
27214 This type is the stream type implemented I/O in the PIC18F devices.
27215 Also the standard input and output streams are declared in stdio.h:
27218 \begin_layout LyX-Code
27219 extern FILE * stdin;
27222 \begin_layout LyX-Code
27223 extern FILE * stdout;
27226 \begin_layout Standard
27227 The FILE type is actually a generic pointer which defines one more type
27228 of generic pointers, the
27233 This new type has the format:
27236 \begin_layout Standard
27238 \begin_inset Tabular
27239 <lyxtabular version="3" rows="2" columns="7">
27241 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27242 <column alignment="center" valignment="top" width="0">
27243 <column alignment="center" valignment="top" leftline="true" width="0">
27244 <column alignment="center" valignment="top" leftline="true" width="0">
27245 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27246 <column alignment="center" valignment="top" width="0">
27247 <column alignment="left" valignment="top" rightline="true" width="0">
27248 <row topline="true" bottomline="true">
27249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27252 \begin_layout Standard
27258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27261 \begin_layout Standard
27267 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27270 \begin_layout Standard
27276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27279 \begin_layout Standard
27285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27288 \begin_layout Standard
27294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27297 \begin_layout Standard
27298 rest of the pointer
27303 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27306 \begin_layout Standard
27313 <row topline="true" bottomline="true">
27314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27317 \begin_layout Standard
27323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27326 \begin_layout Standard
27332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27335 \begin_layout Standard
27341 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27344 \begin_layout Standard
27350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27353 \begin_layout Standard
27359 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27362 \begin_layout Standard
27372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27375 \begin_layout Standard
27376 upper byte high nubble is 0x2n, the rest are zeroes
27389 \begin_layout Standard
27390 Currently implemented there are 3 types of streams defined:
27393 \begin_layout Standard
27395 \begin_inset Tabular
27396 <lyxtabular version="3" rows="4" columns="4">
27398 <column alignment="center" valignment="top" leftline="true" width="0">
27399 <column alignment="center" valignment="top" leftline="true" width="0">
27400 <column alignment="center" valignment="top" leftline="true" width="0">
27401 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27402 <row topline="true" bottomline="true">
27403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27406 \begin_layout Standard
27412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27415 \begin_layout Standard
27421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27424 \begin_layout Standard
27430 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27433 \begin_layout Standard
27440 <row topline="true">
27441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27444 \begin_layout Standard
27450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27453 \begin_layout Standard
27461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27464 \begin_layout Standard
27470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27473 \begin_layout Standard
27474 Writes/Reads characters via the USART peripheral
27480 <row topline="true">
27481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27484 \begin_layout Standard
27490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27493 \begin_layout Standard
27501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27504 \begin_layout Standard
27510 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27513 \begin_layout Standard
27514 Writes/Reads characters via the MSSP peripheral
27520 <row topline="true" bottomline="true">
27521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27524 \begin_layout Standard
27530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27533 \begin_layout Standard
27541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27544 \begin_layout Standard
27550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27553 \begin_layout Standard
27554 Writes/Reads characters via used defined functions
27567 \begin_layout Standard
27568 The stream identifiers are declared as macros in the stdio.h header.
27571 \begin_layout Standard
27572 In the libc library there exist the functions that are used to write to
27573 each of the above streams.
27577 \begin_layout Description
27582 \begin_layout Standard
27591 _stream_usart_putchar writes a character at the USART stream
27594 \begin_layout Description
27599 \begin_layout Standard
27608 _stream_mssp_putchar writes a character at the MSSP stream
27611 \begin_layout Description
27612 putchar dummy function.
27613 This writes a character to a user specified manner.
27616 \begin_layout Standard
27617 In order to increase performance
27621 is declared in stdio.h as having its parameter in WREG (it has the wparam
27623 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
27624 in a user-friendly way.
27629 is the name of the variable that holds the character to print.
27630 An example follows:
27633 \begin_layout LyX-Code
27634 #include <pic18fregs.h>
27643 \begin_layout LyX-Code
27647 \begin_layout LyX-Code
27648 PORTA = c; /* dump character c to PORTA */
27651 \begin_layout LyX-Code
27659 \begin_layout LyX-Code
27663 \begin_layout LyX-Code
27664 stdout = STREAM_USER; /* this is not necessary, since stdout points
27667 \begin_layout LyX-Code
27668 * by default to STREAM_USER */
27671 \begin_layout LyX-Code
27673 \begin_inset Quotes sld
27676 This is a printf test
27679 \begin_inset Quotes srd
27685 \begin_layout LyX-Code
27689 \begin_layout LyX-Code
27693 \begin_layout Subsubsection
27697 \begin_layout Standard
27698 PIC16 contains an implementation of the printf-family of functions.
27699 There exist the following functions:
27702 \begin_layout LyX-Code
27703 extern unsigned int sprintf(char *buf, char *fmt, ...);
27706 \begin_layout LyX-Code
27707 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
27710 \begin_layout LyX-Code
27714 \begin_layout LyX-Code
27715 extern unsigned int printf(char *fmt, ...);
27718 \begin_layout LyX-Code
27719 extern unsigned int vprintf(char *fmt, va_lista ap);
27722 \begin_layout LyX-Code
27726 \begin_layout LyX-Code
27727 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
27730 \begin_layout LyX-Code
27731 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
27734 \begin_layout Standard
27735 For sprintf and vsprintf
27739 should normally be a data pointer where the resulting string will be placed.
27740 No range checking is done so the user should allocate the necessery buffer.
27741 For fprintf and vfprintf
27745 should be a stream pointer (i.e.
27746 stdout, STREAM_MSSP, etc...).
27749 \begin_layout Subsubsection
27753 \begin_layout Standard
27754 The PIC18F family of microcontrollers supports a number of interrupt sources.
27755 A list of these interrupts is shown in the following table:
27758 \begin_layout Standard
27760 \begin_inset Tabular
27761 <lyxtabular version="3" rows="11" columns="4">
27763 <column alignment="left" valignment="top" leftline="true" width="0">
27764 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27765 <column alignment="left" valignment="top" leftline="true" width="0">
27766 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27767 <row topline="true" bottomline="true">
27768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27771 \begin_layout Standard
27777 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27780 \begin_layout Standard
27786 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27789 \begin_layout Standard
27795 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27798 \begin_layout Standard
27805 <row topline="true">
27806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27809 \begin_layout Standard
27815 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27818 \begin_layout Standard
27819 PORTB change interrupt
27824 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27827 \begin_layout Standard
27833 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27836 \begin_layout Standard
27837 EEPROM/FLASH write complete interrupt
27843 <row topline="true">
27844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27847 \begin_layout Standard
27853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27856 \begin_layout Standard
27857 INT0 external interrupt
27862 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27865 \begin_layout Standard
27871 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27874 \begin_layout Standard
27875 Bus collision interrupt
27881 <row topline="true">
27882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27885 \begin_layout Standard
27891 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27894 \begin_layout Standard
27895 INT1 external interrupt
27900 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27903 \begin_layout Standard
27909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27912 \begin_layout Standard
27913 Low voltage detect interrupt
27919 <row topline="true">
27920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27923 \begin_layout Standard
27929 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27932 \begin_layout Standard
27933 INT2 external interrupt
27938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27941 \begin_layout Standard
27947 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27950 \begin_layout Standard
27951 Parallel slave port interrupt
27957 <row topline="true">
27958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27961 \begin_layout Standard
27967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27970 \begin_layout Standard
27971 CCP1 module interrupt
27976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27979 \begin_layout Standard
27985 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27988 \begin_layout Standard
27989 AD convertion complete interrupt
27995 <row topline="true">
27996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27999 \begin_layout Standard
28005 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28008 \begin_layout Standard
28009 CCP2 module interrupt
28014 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28017 \begin_layout Standard
28023 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28026 \begin_layout Standard
28027 USART receive interrupt
28033 <row topline="true">
28034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28037 \begin_layout Standard
28043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28046 \begin_layout Standard
28047 TMR0 overflow interrupt
28052 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28055 \begin_layout Standard
28061 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28064 \begin_layout Standard
28065 USART transmit interrupt
28071 <row topline="true">
28072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28075 \begin_layout Standard
28081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28084 \begin_layout Standard
28085 TMR1 overflow interrupt
28090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28093 \begin_layout Standard
28099 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28102 \begin_layout Standard
28103 SSP receive/transmit interrupt
28109 <row topline="true">
28110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28113 \begin_layout Standard
28119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28122 \begin_layout Standard
28123 TMR2 matches PR2 interrupt
28128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28131 \begin_layout Standard
28137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28140 \begin_layout Standard
28147 <row topline="true" bottomline="true">
28148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28151 \begin_layout Standard
28157 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28160 \begin_layout Standard
28161 TMR3 overflow interrupt
28166 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28169 \begin_layout Standard
28175 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28178 \begin_layout Standard
28192 \begin_layout Standard
28193 The prototypes for these names are defined in the header file
28200 \begin_layout Standard
28201 In order to simplify signal handling, a number of macros is provided:
28205 \labelwidthstring 00.00.0000
28206 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
28207 high priority interrupts.
28212 is the function name to use.
28216 \labelwidthstring 00.00.0000
28217 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
28218 low priority interrupt.
28223 is the function name to use.
28227 \labelwidthstring 00.00.0000
28228 DEF_HANDLER(sig,handler) define a handler for signal
28234 \labelwidthstring 00.00.0000
28235 END_DEF end the declaration of the dispatch table.
28238 \begin_layout Standard
28239 Additionally there are two more macros to simplify the declaration of the
28244 \labelwidthstring 00.00.0000
28247 SIGHANDLER(handler)
28249 this declares the function prototype for the
28257 \labelwidthstring 00.00.0000
28258 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
28261 \begin_layout Standard
28262 An example of using the macros above is shown below:
28265 \begin_layout LyX-Code
28266 #include <pic18fregs.h>
28269 \begin_layout LyX-Code
28270 #include <signal.h>
28274 DEF_INTHIGH(high_int)
28277 \begin_layout LyX-Code
28278 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
28281 \begin_layout LyX-Code
28282 DEF_HANDLER(SIG_BCOL, _bcol_handler)
28285 \begin_layout LyX-Code
28290 SIGHANDLER(_tmr0_handler)
28293 \begin_layout LyX-Code
28297 \begin_layout LyX-Code
28298 /* action to be taken when timer 0 overflows */
28301 \begin_layout LyX-Code
28306 SIGHANDLERNAKED(_bcol_handler)
28309 \begin_layout LyX-Code
28313 \begin_layout LyX-Code
28317 \begin_layout LyX-Code
28318 /* action to be taken when bus collision occurs */
28321 \begin_layout LyX-Code
28325 \begin_layout LyX-Code
28329 \begin_layout LyX-Code
28333 \begin_layout Standard
28338 Special care should be taken when using the above scheme:
28341 \begin_layout Itemize
28342 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
28345 \begin_layout Itemize
28346 when declaring SIGHANDLERNAKED handler never forget to use
28350 for proper returning.
28353 \begin_layout Subsection
28357 \begin_layout Standard
28358 Here you can find some general tips for compiling programs with SDCC/pic16.
28361 \begin_layout Subsubsection
28365 \begin_layout Standard
28367 \begin_inset LatexCommand \index{PIC16!stack}
28371 size (that is 64 bytes) probably is enough for many programs.
28372 One must take care that when there are many levels of function nesting,
28373 or there is excessive usage of stack, its size should be extended.
28374 An example of such a case is the printf/sprintf family of functions.
28375 If you encounter problems like not being able to print integers, then you
28376 need to set the stack size around the maximum (256 for small stack model).
28377 The following diagram shows what happens when calling printf to print an
28381 \begin_layout LyX-Code
28382 printf () --> ltoa () --> ultoa () --> divschar ()
28385 \begin_layout Standard
28386 It is should be understood that stack is easily consumed when calling complicate
28388 Using command line arguments like -
28392 \begin_layout Standard
28401 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
28403 Other ways to reduce stack usage may exist.
28406 \begin_layout Subsection
28410 \begin_layout Standard
28411 The PIC16 Port currently does not pass SDCC's regression test
28412 \begin_inset LatexCommand \index{Regression test (PIC16)}
28417 \begin_inset LatexCommand \ref{sec:Quality-control}
28421 ) and thus the snapshot build regression tests for the PIC16 target are
28422 currently disabled for all hosts
28427 \begin_layout Chapter
28431 \begin_layout Standard
28432 There are several approaches to debugging your code.
28433 This chapter is meant to show your options and to give detail on some of
28438 When writing your code:
28441 \begin_layout Itemize
28442 write your code with debugging in mind (avoid duplicating code, put conceptually
28443 similar variables into structs, use structured code, have strategic points
28444 within your code where all variables are consistent, ...)
28447 \begin_layout Itemize
28448 run a syntax-checking tool like splint
28449 \begin_inset LatexCommand \index{splint (syntax checking tool)}
28454 \begin_inset LatexCommand \index{lint (syntax checking tool)}
28462 \begin_layout Standard
28472 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28479 \begin_layout Itemize
28480 for the high level code use a C-compiler (like f.e.
28481 GCC) to compile run and debug the code on your host.
28486 \begin_layout Standard
28496 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28500 ) on how to handle syntax extensions like __xdata, __at(), ...
28504 \begin_layout Itemize
28505 use another C-compiler to compile code for your target.
28506 Always an option but not recommended:) And not very likely to help you.
28507 If you seriously consider walking this path you should at least occasionally
28508 check portability of your code.
28509 Most commercial compiler vendors will offer an evaluation version so you
28510 can test compile your code or snippets of your code.
28513 \begin_layout Standard
28514 Debugging on a simulator:
28517 \begin_layout Itemize
28518 there is a separate section about SDCDB (section
28519 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
28526 \begin_layout Itemize
28527 or (8051 specific) use a freeware/commercial simulator which interfaces
28529 \begin_inset LatexCommand \index{AOMF, AOMF51}
28534 \begin_inset LatexCommand \ref{OMF file}
28538 ) optionally generated by SDCC.
28541 \begin_layout Standard
28542 Debugging On-target:
28545 \begin_layout Itemize
28546 use a MCU port pin to serially output debug data to the RS232 port of your
28548 You'll probably want some level shifting device typically involving a MAX232
28550 If the hardware serial port of the MCU is not available search for 'Software
28551 UART' in your favourite search machine.
28554 \begin_layout Itemize
28555 use an on-target monitor.
28556 In this context a monitor is a small program which usually accepts commands
28557 via a serial line and allows to set program counter, to single step through
28558 a program and read/write memory locations.
28559 For the 8051 good examples of monitors are paulmon and cmon51 (see section
28561 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
28568 \begin_layout Itemize
28569 toggle MCU port pins at strategic points within your code and use an oscilloscop
28573 digital oscilloscope
28576 \begin_inset LatexCommand \index{Oscilloscope}
28580 with deep trace memory is really helpful especially if you have to debug
28581 a realtime application.
28582 If you need to monitor more pins than your oscilloscope provides you can
28583 sometimes get away with a small R-2R network.
28584 On a single channel oscilloscope you could f.e.
28585 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
28587 \begin_inset Formula $\Omega$
28590 resistor and the other one by a 5\InsetSpace ~
28592 \begin_inset Formula $\Omega$
28595 resistor to the oscilloscope probe (check output drive capability of the
28596 pins you want to monitor).
28597 If you need to monitor many more pins a
28604 \begin_layout Itemize
28618 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
28623 Usually very expensive.
28624 And very nice to have too.
28625 And usually locks you (for years...) to the devices the ICE can emulate.
28629 \begin_layout Itemize
28630 use a remote debugger.
28631 In most 8-bit systems the symbol information is not available on the target,
28632 and a complete debugger is too bulky for the target system.
28633 Therefore usually a debugger on the host system connects to an on-target
28634 debugging stub which accepts only primitive commands.
28637 Terms to enter into your favourite search engine could be 'remote debugging',
28638 'gdb stub' or 'inferior debugger'.
28642 \begin_layout Itemize
28643 use an on target hardware debugger.
28644 Some of the more modern MCUs include hardware support for setting break
28645 points and monitoring/changing variables by using dedicated hardware pins.
28646 This facility doesn't require additional code to run on the target and
28651 doesn't affect runtime behaviour until a breakpoint is hit.
28652 For the mcs51 most hardware debuggers use the AOMF
28653 \begin_inset LatexCommand \index{AOMF, AOMF51}
28658 \begin_inset LatexCommand \ref{OMF file}
28666 \begin_layout Standard
28670 \begin_layout Itemize
28671 if you are not familiar with any of the following terms you're likely to
28672 run into problems rather sooner than later:
28689 As an embedded programmer you
28693 to know them so why not look them up
28697 you have problems?)
28700 \begin_layout Itemize
28701 tell someone else about your problem (actually this is a surprisingly effective
28702 means to hunt down the bug even if the listener is not familiar with your
28704 As 'failure to communicate' is probably one of the job-induced deformations
28705 of an embedded programmer this is highly encouraged.
28708 \begin_layout Section
28709 Debugging with SDCDB
28710 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
28715 \begin_inset LatexCommand \index{SDCDB (debugger)}
28722 \begin_layout Standard
28723 SDCC is distributed with a source level debugger
28724 \begin_inset LatexCommand \index{Debugger}
28729 The debugger uses a command line interface, the command repertoire of the
28730 debugger has been kept as close to gdb
28731 \begin_inset LatexCommand \index{gdb}
28735 (the GNU debugger) as possible.
28736 The configuration and build process is part of the standard compiler installati
28737 on, which also builds and installs the debugger in the target directory
28738 specified during configuration.
28739 The debugger allows you debug BOTH at the C source and at the ASM source
28743 \begin_layout Subsection
28744 Compiling for Debugging
28747 \begin_layout Standard
28752 \begin_layout Standard
28762 \begin_inset LatexCommand \index{-\/-debug}
28766 option must be specified for all files for which debug information is to
28768 The compiler generates a .adb file for each of these files.
28769 The linker creates the .cdb
28770 \begin_inset LatexCommand \index{<file>.cdb}
28775 \begin_inset LatexCommand \index{<file>.adb}
28779 files and the address information.
28780 This .cdb is used by the debugger.
28783 \begin_layout Subsection
28784 How the Debugger Works
28787 \begin_layout Standard
28792 \begin_layout Standard
28801 -debug option is specified the compiler generates extra symbol information
28802 some of which are put into the assembler source and some are put into the
28804 Then the linker creates the .cdb file from the individual .adb files with
28805 the address information for the symbols.
28806 The debugger reads the symbolic information generated by the compiler &
28807 the address information generated by the linker.
28808 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
28809 execution is controlled by the debugger.
28810 When a command is issued for the debugger, it translates it into appropriate
28811 commands for the simulator.
28812 (Currently SDCDM only connects to the simulator but
28817 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
28821 is an effort to connect directly to the hardware.)
28824 \begin_layout Subsection
28825 Starting the Debugger SDCDB
28828 \begin_layout Standard
28829 The debugger can be started using the following command line.
28830 (Assume the file you are debugging has the file name foo).
28844 The debugger will look for the following files.
28847 \begin_layout Itemize
28848 foo.c - the source file.
28851 \begin_layout Itemize
28852 foo.cdb - the debugger symbol information file.
28855 \begin_layout Itemize
28856 foo.ihx - the Intel hex format
28857 \begin_inset LatexCommand \index{Intel hex format}
28864 \begin_layout Subsection
28865 SDCDB Command Line Options
28868 \begin_layout Itemize
28873 \begin_layout Standard
28882 -directory=<source file directory> this option can used to specify the directory
28884 The debugger will look into the directory list specified for source, cdb
28886 The items in the directory list must be separated by ':', e.g.
28887 if the source files can be in the directories /home/src1 and /home/src2,
28892 \begin_layout Standard
28901 -directory option should be -
28905 \begin_layout Standard
28914 -directory=/home/src1:/home/src2.
28915 Note there can be no spaces in the option.
28919 \begin_layout Itemize
28920 -cd <directory> - change to the <directory>.
28923 \begin_layout Itemize
28924 -fullname - used by GUI front ends.
28927 \begin_layout Itemize
28928 -cpu <cpu-type> - this argument is passed to the simulator please see the
28929 simulator docs for details.
28932 \begin_layout Itemize
28933 -X <Clock frequency > this options is passed to the simulator please see
28934 the simulator docs for details.
28937 \begin_layout Itemize
28938 -s <serial port file> passed to simulator see the simulator docs for details.
28941 \begin_layout Itemize
28942 -S <serial in,out> passed to simulator see the simulator docs for details.
28945 \begin_layout Itemize
28946 -k <port number> passed to simulator see the simulator docs for details.
28949 \begin_layout Subsection
28950 SDCDB Debugger Commands
28953 \begin_layout Standard
28954 As mentioned earlier the command interface for the debugger has been deliberatel
28955 y kept as close the GNU debugger gdb, as possible.
28956 This will help the integration with existing graphical user interfaces
28957 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
28958 If you use a graphical user interface for the debugger you can skip this
28962 \begin_layout Subsubsection*
28963 break [line | file:line | function | file:function]
28966 \begin_layout Standard
28967 Set breakpoint at specified line or function:
28976 sdcdb>break foo.c:100
28978 sdcdb>break funcfoo
28980 sdcdb>break foo.c:funcfoo
28983 \begin_layout Subsubsection*
28984 clear [line | file:line | function | file:function ]
28987 \begin_layout Standard
28988 Clear breakpoint at specified line or function:
28997 sdcdb>clear foo.c:100
28999 sdcdb>clear funcfoo
29001 sdcdb>clear foo.c:funcfoo
29004 \begin_layout Subsubsection*
29008 \begin_layout Standard
29009 Continue program being debugged, after breakpoint.
29012 \begin_layout Subsubsection*
29016 \begin_layout Standard
29017 Execute till the end of the current function.
29020 \begin_layout Subsubsection*
29024 \begin_layout Standard
29025 Delete breakpoint number 'n'.
29026 If used without any option clear ALL user defined break points.
29029 \begin_layout Subsubsection*
29030 info [break | stack | frame | registers ]
29033 \begin_layout Itemize
29034 info break - list all breakpoints
29037 \begin_layout Itemize
29038 info stack - show the function call stack.
29041 \begin_layout Itemize
29042 info frame - show information about the current execution frame.
29045 \begin_layout Itemize
29046 info registers - show content of all registers.
29049 \begin_layout Subsubsection*
29053 \begin_layout Standard
29054 Step program until it reaches a different source line.
29055 Note: pressing <return> repeats the last command.
29058 \begin_layout Subsubsection*
29062 \begin_layout Standard
29063 Step program, proceeding through subroutine calls.
29066 \begin_layout Subsubsection*
29070 \begin_layout Standard
29071 Start debugged program.
29074 \begin_layout Subsubsection*
29078 \begin_layout Standard
29079 Print type information of the variable.
29082 \begin_layout Subsubsection*
29086 \begin_layout Standard
29087 print value of variable.
29090 \begin_layout Subsubsection*
29094 \begin_layout Standard
29095 load the given file name.
29096 Note this is an alternate method of loading file for debugging.
29099 \begin_layout Subsubsection*
29103 \begin_layout Standard
29104 print information about current frame.
29107 \begin_layout Subsubsection*
29111 \begin_layout Standard
29112 Toggle between C source & assembly source.
29115 \begin_layout Subsubsection*
29116 ! simulator command
29119 \begin_layout Standard
29120 Send the string following '!' to the simulator, the simulator response is
29122 Note the debugger does not interpret the command being sent to the simulator,
29123 so if a command like 'go' is sent the debugger can loose its execution
29124 context and may display incorrect values.
29127 \begin_layout Subsubsection*
29131 \begin_layout Standard
29134 My name is Bobby Brown"
29137 \begin_layout Subsection
29138 Interfacing SDCDB with DDD
29141 \begin_layout Standard
29142 \begin_inset Note Note
29145 \begin_layout Standard
29146 The screenshot was converted from png to eps with:
29147 \begin_inset Quotes sld
29150 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
29151 \begin_inset Quotes srd
29154 which produces a pretty compact eps file which is free from compression
29158 \begin_layout Standard
29159 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
29160 as this broke the build system on Sourceforge (pdf-file was broken.
29161 pdflatex does not accept eps files).
29169 \begin_layout Standard
29185 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
29191 shows a screenshot of a debugging session with DDD
29192 \begin_inset LatexCommand \index{DDD (debugger)}
29196 (Unix only) on a simulated 8032.
29197 The debugging session might not run as smoothly as the screenshot suggests.
29198 The debugger allows setting of breakpoints, displaying and changing variables,
29199 single stepping through C and assembler code.
29202 The source was compiled with
29216 \begin_layout Standard
29228 -debug ddd_example.c
29241 and DDD was invoked with
29248 ddd -debugger "sdcdb -cpu 8032 ddd_example"
29251 \begin_layout Standard
29252 \begin_inset Note Note
29255 \begin_layout Standard
29256 Check that the double quotes or an apostroph within the command line survive
29257 the LyX tool chain.
29258 Previously the apostrophs got slanted in the PDF output so a cut and paste
29267 \begin_layout Subsection
29268 Interfacing SDCDB with XEmacs
29269 \begin_inset LatexCommand \index{XEmacs}
29274 \begin_inset LatexCommand \index{Emacs}
29281 \begin_layout Standard
29282 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
29283 sdcdb.el and sdcdbsrc.el.
29284 These two files can be found in the $(prefix)/bin directory after the installat
29286 These files need to be loaded into XEmacs for the interface to work.
29287 This can be done at XEmacs startup time by inserting the following into
29288 your '.xemacs' file (which can be found in your HOME directory):
29294 (load-file sdcdbsrc.el)
29300 .xemacs is a lisp file so the () around the command is REQUIRED.
29301 The files can also be loaded dynamically while XEmacs is running, set the
29302 environment variable 'EMACSLOADPATH' to the installation bin directory
29303 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
29304 To start the interface enter the following command:
29318 You will prompted to enter the file name to be debugged.
29323 The command line options that are passed to the simulator directly are
29324 bound to default values in the file sdcdbsrc.el.
29325 The variables are listed below, these values maybe changed as required.
29328 \begin_layout Itemize
29329 sdcdbsrc-cpu-type '51
29332 \begin_layout Itemize
29333 sdcdbsrc-frequency '11059200
29336 \begin_layout Itemize
29337 sdcdbsrc-serial nil
29340 \begin_layout Standard
29341 The following is a list of key mapping for the debugger interface.
29344 \begin_layout Standard
29367 binding\InsetSpace ~
29405 -------\InsetSpace ~
29476 sdcdb-back-from-src\InsetSpace ~
29505 rom-src\InsetSpace ~
29515 SDCDB continue command
29533 sdcdb-step-from-src\InsetSpace ~
29562 hatis-c-sexp\InsetSpace ~
29572 SDCDB ptypecommand for data at
29639 sdcdbsrc-delete\InsetSpace ~
29654 B Delete all breakpoints if no arg
29703 given or delete arg (C-u arg x)
29722 -frame\InsetSpace ~
29737 SDCDB Display current frame if no arg,
29786 given or display frame arg
29854 sdcdbsrc-goto-sdcdb\InsetSpace ~
29864 Goto the SDCDB output buffer
29883 t-c-sexp\InsetSpace ~
29894 SDCDB print command for data at
29961 sdcdbsrc-goto-sdcdb\InsetSpace ~
29972 o the SDCDB output buffer
29990 sdcdbsrc-mode\InsetSpace ~
30006 Toggles Sdcdbsrc mode (turns it
30022 sdcdb-finish-from-src\InsetSpace ~
30030 SDCDB finish command
30064 Set break for line with point
30079 sdcdbsrc-mode\InsetSpace ~
30095 Toggle Sdcdbsrc mode
30111 dbsrc-srcmode\InsetSpace ~
30135 \begin_layout Chapter
30139 \begin_layout Standard
30140 Here are a few guidelines that will help the compiler generate more efficient
30141 code, some of the tips are specific to this compiler others are generally
30142 good programming practice.
30145 \begin_layout Itemize
30146 Use the smallest data type to represent your data-value.
30147 If it is known in advance that the value is going to be less than 256 then
30148 use an 'unsigned char' instead of a 'short' or 'int'.
30149 Please note, that ANSI C requires both signed and unsigned chars to be
30150 promoted to 'signed int'
30151 \begin_inset LatexCommand \index{promotion to signed int}
30156 \begin_inset Marginal
30159 \begin_layout Standard
30168 before doing any operation.
30170 \begin_inset LatexCommand \index{type promotion}
30175 \begin_inset LatexCommand \label{type promotion}
30179 can be omitted, if the result is the same.
30180 The effect of the promotion rules together with the sign-extension is often
30185 \begin_layout Verse
30188 unsigned char uc = 0xfe;
30190 if (uc * uc < 0) /* this is true! */
30203 \begin_layout Standard
30210 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
30218 \begin_layout Verse
30221 (unsigned char) -12 / (signed char) -3 = ...
30224 \begin_layout Standard
30225 No, the result is not 4:
30228 \begin_layout Verse
30231 (int) (unsigned char) -12 / (int) (signed char) -3 =
30233 (int) (unsigned char)
30234 0xf4 / (int) (signed char) 0xfd =
30236 (int) 0x00f4 / (int) 0xfffd =
30241 (int) 244 / (int) -3 =
30243 (int) -81 = (int) 0xffaf;
30246 \begin_layout Standard
30247 Don't complain, that gcc gives you a different result.
30248 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
30249 Therefore the results are different.
30252 \begin_inset Quotes sld
30256 \begin_inset Quotes srd
30262 \begin_layout Quote
30265 If well-defined overflow characteristics are important and negative values
30266 are not, or if you want to steer clear of sign-extension problems when
30267 manipulating bits or bytes, use one of the corresponding unsigned types.
30268 (Beware when mixing signed and unsigned values in expressions, though.)
30271 character types (especially unsigned char) can be used as "tiny" integers,
30272 doing so is sometimes more trouble than it's worth, due to unpredictable
30273 sign extension and increased code size.
30277 \begin_layout Itemize
30278 Use unsigned when it is known in advance that the value is not going to
30280 This helps especially if you are doing division or multiplication, bit-shifting
30281 or are using an array index.
30284 \begin_layout Itemize
30285 NEVER jump into a LOOP.
30288 \begin_layout Itemize
30289 Declare the variables to be local
30290 \begin_inset LatexCommand \index{local variables}
30294 whenever possible, especially loop control variables (induction).
30297 \begin_layout Itemize
30298 Have a look at the assembly listing to get a
30299 \begin_inset Quotes sld
30303 \begin_inset Quotes srd
30306 for the code generation.
30309 \begin_layout Section
30310 Porting code from or to other compilers
30311 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
30318 \begin_layout Itemize
30319 check whether endianness of the compilers differs and adapt where needed.
30322 \begin_layout Itemize
30323 check the device specific header files
30324 \begin_inset LatexCommand \index{Header files}
30329 \begin_inset LatexCommand \index{Include files}
30333 for compiler specific syntax.
30334 Eventually include the file <compiler.h
30335 \begin_inset LatexCommand \index{compiler.h (include file)}
30340 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
30344 to allow using common header files.
30347 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
30354 \begin_layout Itemize
30355 check whether the startup code contains the correct initialization (watchdog,
30359 \begin_layout Itemize
30360 check whether the sizes of short, int, long match.
30363 \begin_layout Itemize
30364 check if some 16 or 32 bit hardware registers require a specific addressing
30365 order (least significant or most significant byte first) and adapt if needed
30374 relate to time and not to lower/upper memory location here, so this is
30379 the same as endianness).
30382 \begin_layout Itemize
30383 check whether the keyword
30387 is used where needed.
30388 The compilers might differ in their optimization characteristics (as different
30389 versions of the same compiler might also use more clever optimizations
30390 this is good idea anyway).
30392 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
30399 \begin_layout Itemize
30400 check that the compilers are not told to supress warnings.
30403 \begin_layout Itemize
30404 check and convert compiler specific extensions (interrupts, memory areas,
30408 \begin_layout Itemize
30409 check for differences in type promotion.
30410 Especially check for math operations on
30419 For the sake of C99 compatibility SDCC will probably promote these to
30423 more often than other compilers.
30424 Eventually insert explicit casts to
30433 Also check that the ~\InsetSpace ~
30435 \begin_inset LatexCommand \index{\~\/ Operator}
30442 \begin_inset LatexCommand \index{bit}
30448 variables, use the !\InsetSpace ~
30451 \begin_inset LatexCommand \ref{type promotion}
30456 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30463 \begin_layout Itemize
30464 check the assembly code generated for interrupt routines (f.e.
30465 for calls to possibly non-reentrant library functions).
30468 \begin_layout Itemize
30469 check whether timing loops result in proper timing (or preferably consider
30470 a rewrite of the code with timer based delays instead).
30473 \begin_layout Itemize
30474 check for differences in printf parameters (some compilers push (va_arg
30475 \begin_inset LatexCommand \index{vararg, va\_arg}
30479 ) char variables as
30483 others push them as
30489 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30496 \begin_layout Itemize
30497 check the resulting memory map
30498 \begin_inset LatexCommand \index{Memory map}
30503 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
30504 ly idata, pdata, xdata).
30505 Eventually check if unexpected library functions are included.
30508 \begin_layout Section
30510 \begin_inset LatexCommand \index{Tools}
30514 included in the distribution
30517 \begin_layout Standard
30519 \begin_inset Tabular
30520 <lyxtabular version="3" rows="12" columns="3">
30522 <column alignment="left" valignment="top" leftline="true" width="0pt">
30523 <column alignment="left" valignment="top" leftline="true" width="0pt">
30524 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30525 <row topline="true" bottomline="true">
30526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30529 \begin_layout Standard
30537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30540 \begin_layout Standard
30548 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30551 \begin_layout Standard
30560 <row topline="true">
30561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30564 \begin_layout Standard
30566 \begin_inset LatexCommand \index{uCsim}
30575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30578 \begin_layout Standard
30579 Simulator for various architectures
30584 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30587 \begin_layout Standard
30594 <row topline="true">
30595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30598 \begin_layout Standard
30604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30607 \begin_layout Standard
30609 \begin_inset LatexCommand \index{Header files}
30614 \begin_inset LatexCommand \index{Include files}
30623 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30626 \begin_layout Standard
30627 sdcc/support/scripts
30633 <row topline="true">
30634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30637 \begin_layout Standard
30643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30646 \begin_layout Standard
30647 header file conversion
30652 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30655 \begin_layout Standard
30656 sdcc/support/scripts
30662 <row topline="true">
30663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30666 \begin_layout Standard
30672 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30675 \begin_layout Standard
30681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30684 \begin_layout Standard
30700 <row topline="true">
30701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30704 \begin_layout Standard
30710 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30713 \begin_layout Standard
30719 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30722 \begin_layout Standard
30738 <row topline="true">
30739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30742 \begin_layout Standard
30748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30751 \begin_layout Standard
30757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30760 \begin_layout Standard
30776 <row topline="true">
30777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30780 \begin_layout Standard
30786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30789 \begin_layout Standard
30795 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30798 \begin_layout Standard
30814 <row topline="true">
30815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30818 \begin_layout Standard
30824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30827 \begin_layout Standard
30833 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30836 \begin_layout Standard
30852 <row topline="true">
30853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30856 \begin_layout Standard
30862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30865 \begin_layout Standard
30871 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30874 \begin_layout Standard
30890 <row topline="true">
30891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30894 \begin_layout Standard
30900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30903 \begin_layout Standard
30909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30912 \begin_layout Standard
30928 <row topline="true" bottomline="true">
30929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30932 \begin_layout Standard
30938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30941 \begin_layout Standard
30943 \begin_inset LatexCommand \index{packihx (tool)}
30952 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30955 \begin_layout Standard
30980 \begin_layout Section
30982 \begin_inset LatexCommand \index{Documentation}
30986 included in the distribution
30989 \begin_layout Standard
30991 \begin_inset Tabular
30992 <lyxtabular version="3" rows="10" columns="2">
30994 <column alignment="block" valignment="top" leftline="true" width="40col%">
30995 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
30996 <row topline="true" bottomline="true" endhead="true">
30997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31000 \begin_layout Standard
31008 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31011 \begin_layout Standard
31014 Filename / Where to get
31020 <row topline="true">
31021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31024 \begin_layout Standard
31025 SDCC Compiler User Guide
31030 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31033 \begin_layout Standard
31034 You're reading it right now
31046 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
31056 <row topline="true">
31057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31060 \begin_layout Standard
31066 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31069 \begin_layout Standard
31082 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31092 <row topline="true">
31093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31096 \begin_layout Standard
31098 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
31103 \begin_inset LatexCommand \index{Assembler documentation}
31110 \begin_inset LatexCommand \index{aslink}
31115 \begin_inset LatexCommand \index{Linker documentation}
31124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31127 \begin_layout Standard
31128 sdcc/as/doc/asxhtm.html
31140 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
31150 <row topline="true">
31151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31154 \begin_layout Standard
31155 SDCC regression test
31156 \begin_inset LatexCommand \index{Regression test}
31165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31168 \begin_layout Standard
31169 sdcc/doc/test_suite_spec.pdf
31181 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
31191 <row topline="true">
31192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31195 \begin_layout Standard
31201 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31204 \begin_layout Standard
31217 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
31227 <row topline="true">
31228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31231 \begin_layout Standard
31232 Notes on debugging with SDCDB
31233 \begin_inset LatexCommand \index{SDCDB (debugger)}
31242 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31245 \begin_layout Standard
31246 sdcc/debugger/README
31258 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
31268 <row topline="true">
31269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31272 \begin_layout Standard
31274 \begin_inset LatexCommand \index{uCsim}
31278 Software simulator for microcontrollers
31283 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31286 \begin_layout Standard
31316 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
31326 <row topline="true">
31327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31330 \begin_layout Standard
31331 Temporary notes on the pic16
31332 \begin_inset LatexCommand \index{PIC16}
31341 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31344 \begin_layout Standard
31345 sdcc/src/pic16/NOTES
31357 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
31367 <row topline="true" bottomline="true">
31368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31371 \begin_layout Standard
31372 SDCC internal documentation (debugging file format)
31377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31380 \begin_layout Standard
31410 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
31429 \begin_layout Section
31430 Related open source tools
31431 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
31436 \begin_inset LatexCommand \index{Related tools}
31443 \begin_layout Standard
31445 \begin_inset Tabular
31446 <lyxtabular version="3" rows="16" columns="3">
31448 <column alignment="left" valignment="top" leftline="true" width="0pt">
31449 <column alignment="block" valignment="top" leftline="true" width="30line%">
31450 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
31451 <row topline="true" bottomline="true">
31452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31455 \begin_layout Standard
31463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31466 \begin_layout Standard
31474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31477 \begin_layout Standard
31486 <row topline="true">
31487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31490 \begin_layout Standard
31492 \begin_inset LatexCommand \index{gpsim (pic simulator)}
31501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31504 \begin_layout Standard
31510 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31513 \begin_layout Standard
31514 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
31524 <row topline="true">
31525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31528 \begin_layout Standard
31530 \begin_inset LatexCommand \index{gputils (pic tools)}
31539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31542 \begin_layout Standard
31548 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31551 \begin_layout Standard
31552 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
31562 <row topline="true">
31563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31566 \begin_layout Standard
31572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31575 \begin_layout Standard
31581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31584 \begin_layout Standard
31585 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
31595 <row topline="true">
31596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31599 \begin_layout Standard
31605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31608 \begin_layout Standard
31609 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
31615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31618 \begin_layout Standard
31619 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
31629 <row topline="true">
31630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31633 \begin_layout Standard
31635 \begin_inset LatexCommand \index{indent (source formatting tool)}
31644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31647 \begin_layout Standard
31648 Formats C source - Master of the white spaces
31653 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31656 \begin_layout Standard
31657 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
31667 <row topline="true">
31668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31671 \begin_layout Standard
31673 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
31682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31685 \begin_layout Standard
31686 Object file conversion, checksumming, ...
31691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31694 \begin_layout Standard
31695 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
31705 <row topline="true">
31706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31709 \begin_layout Standard
31711 \begin_inset LatexCommand \index{objdump (tool)}
31720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31723 \begin_layout Standard
31724 Object file conversion, ...
31729 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31732 \begin_layout Standard
31733 Part of binutils (should be there anyway)
31739 <row topline="true">
31740 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31743 \begin_layout Standard
31749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31752 \begin_layout Standard
31753 8051 monitor (hex up-/download, single step, disassemble)
31758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31761 \begin_layout Standard
31762 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
31772 <row topline="true">
31773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31776 \begin_layout Standard
31778 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
31787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31790 \begin_layout Standard
31791 Source code documentation system
31796 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31799 \begin_layout Standard
31800 \begin_inset LatexCommand \url{http://www.doxygen.org}
31810 <row topline="true">
31811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31814 \begin_layout Standard
31820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31823 \begin_layout Standard
31824 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
31829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31832 \begin_layout Standard
31833 \begin_inset LatexCommand \url{http://www.kdevelop.org}
31843 <row topline="true">
31844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31847 \begin_layout Standard
31853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31856 \begin_layout Standard
31857 8051 monitor (hex up-/download, single step, disassemble)
31862 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31865 \begin_layout Standard
31866 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
31876 <row topline="true">
31877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31880 \begin_layout Standard
31882 \begin_inset LatexCommand \index{splint (syntax checking tool)}
31891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31894 \begin_layout Standard
31895 Statically checks c sources (see
31896 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
31905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31908 \begin_layout Standard
31909 \begin_inset LatexCommand \url{http://www.splint.org}
31919 <row topline="true" bottomline="true">
31920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31923 \begin_layout Standard
31925 \begin_inset LatexCommand \index{DDD (debugger)}
31934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31937 \begin_layout Standard
31938 Debugger, serves nicely as GUI to SDCDB
31939 \begin_inset LatexCommand \index{SDCDB (debugger)}
31948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31951 \begin_layout Standard
31952 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
31962 <row bottomline="true">
31963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31966 \begin_layout Standard
31968 \begin_inset LatexCommand \index{d52}
31973 \begin_inset LatexCommand \index{d52 (disassembler)}
31982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31985 \begin_layout Standard
31986 Disassembler, can count instruction cycles
31987 \begin_inset LatexCommand \index{instruction cycles (count)}
31991 , use with options -pnd
31996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31999 \begin_layout Standard
32000 \begin_inset LatexCommand \url{http://www.8052.com/users/disasm/}
32010 <row bottomline="true">
32011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32014 \begin_layout Standard
32016 \begin_inset LatexCommand \index{cmake}
32025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32028 \begin_layout Standard
32029 Cross platform build system, generates Makefiles
32030 \begin_inset LatexCommand \index{Makefile}
32034 and project workspaces
32035 \begin_inset LatexCommand \index{project workspace}
32044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32047 \begin_layout Standard
32048 \begin_inset LatexCommand \url{http://www.cmake.org}
32056 and a dedicated wiki entry:
32057 \begin_inset LatexCommand \url{http://www.cmake.org/Wiki/CmakeSdcc}
32076 \begin_layout Section
32077 Related documentation / recommended reading
32080 \begin_layout Standard
32082 \begin_inset Tabular
32083 <lyxtabular version="3" rows="7" columns="3">
32085 <column alignment="left" valignment="top" leftline="true" width="0pt">
32086 <column alignment="left" valignment="top" leftline="true" width="0">
32087 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32088 <row topline="true" bottomline="true">
32089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32092 \begin_layout Standard
32100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32103 \begin_layout Standard
32111 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32114 \begin_layout Standard
32123 <row topline="true">
32124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32127 \begin_layout Standard
32142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32145 \begin_layout Standard
32147 \begin_inset LatexCommand \index{C Reference card}
32156 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32159 \begin_layout Standard
32160 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
32170 <row topline="true">
32171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32174 \begin_layout Standard
32180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32183 \begin_layout Standard
32185 \begin_inset LatexCommand \index{C FAQ}
32194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32197 \begin_layout Standard
32198 \begin_inset LatexCommand \url{http://www.c-faq.com}
32208 <row topline="true">
32209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32212 \begin_layout Standard
32218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32221 \begin_layout Standard
32222 \begin_inset Quotes sld
32226 \begin_inset Quotes srd
32234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32237 \begin_layout Standard
32240 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
32250 <row topline="true">
32251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32254 \begin_layout Standard
32260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32263 \begin_layout Standard
32264 \begin_inset Quotes sld
32267 Extensions for Embedded C
32268 \begin_inset Quotes srd
32276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32279 \begin_layout Standard
32282 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
32292 <row topline="true">
32293 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32296 \begin_layout Standard
32302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32305 \begin_layout Standard
32306 Latest datasheet of target CPU
32311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32314 \begin_layout Standard
32321 <row topline="true" bottomline="true">
32322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32325 \begin_layout Standard
32331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32334 \begin_layout Standard
32335 Revision history of datasheet
32340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32343 \begin_layout Standard
32359 \begin_layout Section
32360 Application notes specifically for SDCC
32363 \begin_layout Standard
32364 SDCC makes no claims about the completeness of this list and about up-to-datenes
32365 s or correctness of the application notes
32366 \begin_inset LatexCommand \index{Application notes}
32373 \begin_layout Standard
32377 \begin_inset Tabular
32378 <lyxtabular version="3" rows="7" columns="3">
32380 <column alignment="block" valignment="top" leftline="true" width="17col%">
32381 <column alignment="block" valignment="top" leftline="true" width="27col%">
32382 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
32383 <row topline="true" bottomline="true">
32384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32387 \begin_layout Standard
32396 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
32399 \begin_layout Standard
32408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32411 \begin_layout Standard
32421 <row topline="true">
32422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32425 \begin_layout Standard
32433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32436 \begin_layout Standard
32439 Using the SDCC Compiler for the DS80C400
32440 \begin_inset LatexCommand \index{DS80C400}
32449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32452 \begin_layout Standard
32455 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
32465 <row topline="true">
32466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32469 \begin_layout Standard
32477 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
32480 \begin_layout Standard
32483 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
32484 \begin_inset LatexCommand \index{DS89C4x0}
32488 Family of Microcontrollers
32493 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32496 \begin_layout Standard
32499 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
32509 <row topline="true">
32510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32513 \begin_layout Standard
32516 Silicon Laboratories / Cygnal
32521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32524 \begin_layout Standard
32527 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
32528 \begin_inset LatexCommand \index{IDE}
32537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32540 \begin_layout Standard
32543 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
32553 <row topline="true">
32554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32557 \begin_layout Standard
32560 Ramtron / Goal Semiconductor
32565 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32568 \begin_layout Standard
32571 Interfacing SDCC to Syn and Textpad
32576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32579 \begin_layout Standard
32582 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32592 <row topline="true">
32593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32596 \begin_layout Standard
32599 Ramtron / Goal Semiconductor
32604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32607 \begin_layout Standard
32610 Installing and Configuring SDCC and Crimson Editor
32615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32618 \begin_layout Standard
32621 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32631 <row topline="true" bottomline="true">
32632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32635 \begin_layout Standard
32643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32646 \begin_layout Standard
32649 MSC12xx Programming with SDCC
32654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32657 \begin_layout Standard
32660 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
32677 \begin_layout Section
32681 \begin_layout Standard
32682 Some questions answered, some pointers given - it might be time to in turn
32690 \begin_layout Itemize
32691 can you solve your project with the selected microcontroller? Would you
32692 find out early or rather late that your target is too small/slow/whatever?
32693 Can you switch to a slightly better device if it doesn't fit?
32696 \begin_layout Itemize
32697 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
32698 and/or another programming language be more adequate? Would an operating
32699 system on the target device help?
32702 \begin_layout Itemize
32703 if you solved the problem, will the marketing department be happy?
32706 \begin_layout Itemize
32707 if the marketing department is happy, will customers be happy?
32710 \begin_layout Itemize
32711 if you're the project manager, marketing department and maybe even the customer
32712 in one person, have you tried to see the project from the outside?
32715 \begin_layout Itemize
32716 is the project done if you think it is done? Or is just that other interface/pro
32717 tocol/feature/configuration/option missing? How about website, manual(s),
32718 internationali(z|s)ation, packaging, labels, 2nd source for components,
32719 electromagnetic compatability/interference, documentation for production,
32720 production test software, update mechanism, patent issues?
32723 \begin_layout Itemize
32724 is your project adequately positioned in that magic triangle: fame, fortune,
32728 \begin_layout Standard
32729 Maybe not all answers to these questions are known and some answers may
32734 , nevertheless knowing these questions may help you to avoid burnout
32738 \begin_layout Standard
32739 burnout is bad for electronic devices, programmers and motorcycle tyres
32745 Chances are you didn't want to hear some of them...
32748 \begin_layout Chapter
32750 \begin_inset LatexCommand \index{Support}
32757 \begin_layout Standard
32758 SDCC has grown to be a large project.
32759 The compiler alone (without the preprocessor, assembler and linker) is
32760 well over 150,000 lines of code (blank stripped).
32761 The open source nature of this project is a key to its continued growth
32763 You gain the benefit and support of many active software developers and
32765 Is SDCC perfect? No, that's why we need your help.
32766 The developers take pride in fixing reported bugs.
32767 You can help by reporting the bugs and helping other SDCC users.
32768 There are lots of ways to contribute, and we encourage you to take part
32769 in making SDCC a great software package.
32773 \begin_layout Standard
32774 The SDCC project is hosted on the SDCC sourceforge site at
32775 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
32780 You'll find the complete set of mailing lists
32781 \begin_inset LatexCommand \index{Mailing list(s)}
32785 , forums, bug reporting system, patch submission
32786 \begin_inset LatexCommand \index{Patch submission}
32791 \begin_inset LatexCommand \index{download}
32795 area and Subversion code repository
32796 \begin_inset LatexCommand \index{Subversion code repository}
32803 \begin_layout Section
32805 \begin_inset LatexCommand \index{Bug reporting}
32810 \begin_inset LatexCommand \index{Reporting bugs}
32817 \begin_layout Standard
32818 The recommended way of reporting bugs is using the infrastructure of the
32820 You can follow the status of bug reports there and have an overview about
32824 \begin_layout Standard
32825 Bug reports are automatically forwarded to the developer mailing list and
32826 will be fixed ASAP.
32827 When reporting a bug, it is very useful to include a small test program
32828 (the smaller the better) which reproduces the problem.
32829 If you can isolate the problem by looking at the generated assembly code,
32830 this can be very helpful.
32831 Compiling your program with the -
32835 \begin_layout Standard
32845 \begin_inset LatexCommand \index{-\/-dumpall}
32849 option can sometimes be useful in locating optimization problems.
32850 When reporting a bug please make sure you:
32853 \begin_layout Enumerate
32854 Attach the code you are compiling with SDCC.
32858 \begin_layout Enumerate
32859 Specify the exact command you use to run SDCC, or attach your Makefile.
32863 \begin_layout Enumerate
32864 Specify the SDCC version (type "
32870 "), your platform, and operating system.
32874 \begin_layout Enumerate
32875 Provide an exact copy of any error message or incorrect output.
32879 \begin_layout Enumerate
32880 Put something meaningful in the subject of your message.
32883 \begin_layout Standard
32884 Please attempt to include these 5 important parts, as applicable, in all
32885 requests for support or when reporting any problems or bugs with SDCC.
32886 Though this will make your message lengthy, it will greatly improve your
32887 chance that SDCC users and developers will be able to help you.
32888 Some SDCC developers are frustrated by bug reports without code provided
32889 that they can use to reproduce and ultimately fix the problem, so please
32890 be sure to provide sample code if you are reporting a bug!
32893 \begin_layout Standard
32894 Please have a short check that you are using a recent version of SDCC and
32895 the bug is not yet known.
32896 This is the link for reporting bugs:
32897 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
32902 With SDCC on average having more than 200 downloads
32903 \begin_inset LatexCommand \index{download}
32907 on sourceforge per day
32911 \begin_layout Standard
32912 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
32913 between 2002 and 2005.
32914 This does not include other methods of distribution.
32919 there must be some users.
32920 So it's not exactly easy to find a new bug.
32921 If you find one we need it:
32923 reporting bugs is good
32928 \begin_layout Section
32929 Requesting Features
32930 \begin_inset LatexCommand \label{sub:Requesting-Features}
32935 \begin_inset LatexCommand \index{Feature request}
32940 \begin_inset LatexCommand \index{Requesting features}
32947 \begin_layout Standard
32948 Like bug reports feature requests are forwarded to the developer mailing
32950 This is the link for requesting features:
32951 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32958 \begin_layout Section
32962 \begin_layout Standard
32963 Like bug reports contributed patches are forwarded to the developer mailing
32965 This is the link for submitting patches
32966 \begin_inset LatexCommand \index{Patch submission}
32971 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
32978 \begin_layout Standard
32979 You need to specify some parameters to the
32983 command for the patches to be useful.
32984 If you modified more than one file a patch created f.e.
32989 \begin_inset Quotes sld
32992 diff -Naur unmodified_directory modified_directory >my_changes.patch
32993 \begin_inset Quotes srd
32999 will be fine, otherwise
33003 \begin_inset Quotes sld
33006 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
33007 \begin_inset Quotes srd
33017 \begin_layout Section
33021 \begin_layout Standard
33022 These links should take you directly to the
33023 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
33031 \begin_layout Standard
33032 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
33033 automated messages (mid 2003)
33039 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
33044 \begin_inset LatexCommand \index{Mailing list(s)}
33048 and forums are archived and searchable so if you are lucky someone already
33049 had a similar problem.
33050 While mails to the lists themselves are delivered promptly their web front
33051 end on sourceforge sometimes shows a severe time lag (up to several weeks),
33052 if you're seriously using SDCC please consider subscribing to the lists.
33055 \begin_layout Section
33059 \begin_layout Standard
33060 You can follow the status of the Subversion version
33061 \begin_inset LatexCommand \index{version}
33065 of SDCC by watching the Changelog
33066 \begin_inset LatexCommand \index{Changelog}
33070 in the Subversion repository
33073 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
33080 \begin_layout Section
33081 Subversion Source Code Repository
33084 \begin_layout Standard
33094 \begin_layout Standard
33108 or the filenames of the snapshot versions of SDCC include date and its
33110 \begin_inset LatexCommand \index{Subversion code repository}
33115 Subversion allows to download the source of recent or previous versions
33117 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
33121 (by number or by date).
33122 An on-line source code browser and detailled instructions are also available
33124 SDCC versions starting from 1999 up to now are available (currently the
33125 versions prior to the conversion from cvs
33126 \begin_inset LatexCommand \index{cvs|see{Subversion}}
33130 to Subversion (April 2006) are either by accessible by Subversion or by
33134 \begin_layout Section
33136 \begin_inset LatexCommand \index{Release policy}
33143 \begin_layout Standard
33144 Historically there often were long delays between official releases and
33145 the sourceforge download area tends to get not updated at all.
33146 Excuses in the past might have referred to problems with live range analysis,
33147 but as this was fixed a while ago, the current problem is that another
33148 excuse has to be found.
33149 Kidding aside, we have to get better there! On the other hand there are
33150 daily snapshots available at
33151 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
33155 , and you can always build the very last version (hopefully with many bugs
33156 fixed, and features added) from the source code available at
33157 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
33163 \begin_inset LatexCommand \index{wiki}
33168 \begin_inset LatexCommand \index{SDCC Wiki}
33173 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/}
33177 also holds some information about past and future releases.
33180 \begin_layout Section
33182 \begin_inset LatexCommand \index{Examples}
33189 \begin_layout Standard
33190 You'll find some small examples in the directory
33192 sdcc/device/examples/.
33195 More examples and libraries are available at
33197 The SDCC Open Knowledge Resource
33198 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
33205 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
33212 \begin_layout Standard
33213 \begin_inset Note Note
33216 \begin_layout Standard
33217 I did insert a reference to Paul's web site here although it seems rather
33218 dedicated to a specific 8032 board (I think it's okay because it f.e.
33219 shows LCD/Harddisc interface and has a free 8051 monitor.
33220 Independent 8032 board vendors face hard competition of heavily subsidized
33221 development boards anyway).
33224 \begin_layout Standard
33225 Maybe we should include some links to real world applications.
33226 Preferably pointer to pointers (one for each architecture) so this stays
33235 \begin_layout Section
33237 \begin_inset LatexCommand \label{sec:Quality-control}
33242 \begin_inset LatexCommand \index{Quality control}
33249 \begin_layout Standard
33250 The compiler is passed through snaphot build compile and build checks.
33256 \begin_inset LatexCommand \index{Regression test}
33260 check that SDCC itself compiles flawlessly on several host platforms (i386,
33261 Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
33262 and checks the quality of the code generated by SDCC by running the code
33263 for several target platforms through simulators.
33264 The regression test suite comprises more than 100 files which expand to
33265 more than 500 test cases which include more than 4500 tests.
33266 The results of these tests are published daily on SDCC's snapshot page
33267 (click on the red or green symbols on the right side of
33268 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
33275 \begin_layout Standard
33276 There is a separate document
33279 \begin_inset LatexCommand \index{Test suite}
33286 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
33290 about the regression test suite.
33293 \begin_layout Standard
33294 You'll find the test code in the directory
33296 sdcc/support/regression
33299 You can run these tests manually by running
33303 in this directory (or f.e.
33308 \begin_inset Quotes sld
33312 \begin_inset Quotes srd
33318 if you don't want to run the complete tests).
33319 The test code might also be interesting if you want to look for examples
33320 \begin_inset LatexCommand \index{Examples}
33324 checking corner cases of SDCC or if you plan to submit patches
33325 \begin_inset LatexCommand \index{Patch submission}
33332 \begin_layout Standard
33333 The PIC14 port uses a different set of regression tests
33334 \begin_inset LatexCommand \index{Regression test (PIC14)}
33338 , you'll find them in the directory
33340 sdcc/src/regression
33345 \begin_layout Section
33346 Use of SDCC in Education
33349 \begin_layout Standard
33358 \begin_layout Standard
33359 the phrase "use in education" might evoke the association "
33363 fit for use in education".
33364 This connotation is not intended but nevertheless risked as the licensing
33365 of SDCC makes it difficult to offer educational discounts
33371 If your rationales are to:
33374 \begin_layout Enumerate
33375 give students a chance to understand the
33379 steps of code generation
33382 \begin_layout Enumerate
33383 have a curriculum that can be extended for years.
33384 Then you could use an fpga board as target and your curriculum will seamlessly
33385 extend from logic synthesis (
33386 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
33391 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
33395 ), over assembly programming, to C to FPGA compilers (
33396 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
33403 \begin_layout Enumerate
33404 be able to insert excursions about skills like using a revision control
33405 system, submitting/applying patches, using a type-setting (as opposed to
33406 word-processing) engine LyX/LaTeX, using
33407 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
33412 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
33416 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
33417 Source Software, CPU simulation, compiler regression tests
33418 \begin_inset LatexCommand \index{Regression test}
33425 And if there should be a shortage of ideas then you can always point students
33426 to the ever-growing feature request list
33427 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33434 \begin_layout Enumerate
33435 not tie students to a specific host platform and instead allow them to use
33440 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
33442 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
33449 \begin_layout Enumerate
33450 not encourage students to use illegal copies of educational software
33453 \begin_layout Enumerate
33454 be immune to licensing/availability/price changes of the chosen tool chain
33457 \begin_layout Enumerate
33458 be able to change to a new target platform without having to adopt a new
33462 \begin_layout Enumerate
33463 have complete control over and insight into the tool chain
33466 \begin_layout Enumerate
33467 make your students aware about the pros and cons of open source software
33471 \begin_layout Enumerate
33472 give back to the public as you are probably at least partially publically
33476 \begin_layout Enumerate
33477 give students a chance to publically prove their skills and to possibly
33478 see a world wide impact
33481 \begin_layout Standard
33482 then SDCC is probably among the first choices.
33483 Well, probably SDCC might be the only choice.
33488 \begin_layout Chapter
33489 SDCC Technical Data
33492 \begin_layout Section
33494 \begin_inset LatexCommand \index{Optimizations}
33501 \begin_layout Standard
33502 SDCC performs a host of standard optimizations in addition to some MCU specific
33507 \begin_layout Subsection
33508 Sub-expression Elimination
33509 \begin_inset LatexCommand \index{Subexpression elimination}
33516 \begin_layout Standard
33517 The compiler does local and
33536 \begin_layout Verse
33544 \begin_layout Standard
33545 will be translated to
33548 \begin_layout Verse
33558 \begin_layout Standard
33559 Some subexpressions are not as obvious as the above example, e.g.:
33562 \begin_layout Verse
33570 \begin_layout Standard
33571 In this case the address arithmetic a->b[i] will be computed only once;
33572 the equivalent code in C would be.
33575 \begin_layout Verse
33585 \begin_layout Standard
33586 The compiler will try to keep these temporary variables in registers.
33589 \begin_layout Subsection
33590 Dead-Code Elimination
33591 \begin_inset LatexCommand \index{Dead-code elimination}
33598 \begin_layout Verse
33613 i = 1; \InsetSpace ~
33622 global = 1;\InsetSpace ~
33636 global = 3;\InsetSpace ~
33642 \begin_layout Standard
33646 \begin_layout Verse
33662 \begin_layout Subsection
33664 \begin_inset LatexCommand \index{Copy propagation}
33671 \begin_layout Verse
33695 \begin_layout Standard
33699 \begin_layout Verse
33723 \begin_layout Standard
33724 Note: the dead stores created by this copy propagation will be eliminated
33725 by dead-code elimination.
33728 \begin_layout Subsection
33730 \begin_inset LatexCommand \index{Loop optimization}
33735 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
33742 \begin_layout Standard
33743 Two types of loop optimizations are done by SDCC
33751 of loop induction variables.
33752 In addition to the strength reduction the optimizer marks the induction
33753 variables and the register allocator tries to keep the induction variables
33754 in registers for the duration of the loop.
33755 Because of this preference of the register allocator
33756 \begin_inset LatexCommand \index{Register allocation}
33760 , loop induction optimization causes an increase in register pressure, which
33761 may cause unwanted spilling of other temporary variables into the stack
33762 \begin_inset LatexCommand \index{stack}
33767 The compiler will generate a warning message when it is forced to allocate
33768 extra space either on the stack or data space.
33769 If this extra space allocation is undesirable then induction optimization
33770 can be eliminated either for the entire source file (with -
33774 \begin_layout Standard
33783 -noinduction option) or for a given function only using #pragma\InsetSpace ~
33785 \begin_inset LatexCommand \index{\#pragma noinduction}
33796 \begin_layout Verse
33799 for (i = 0 ; i < 100 ; i ++)
33808 \begin_layout Standard
33812 \begin_layout Verse
33817 for (i = 0; i < 100; i++)
33826 \begin_layout Standard
33827 As mentioned previously some loop invariants are not as apparent, all static
33828 address computations are also moved out of the loop.
33833 \begin_inset LatexCommand \index{Strength reduction}
33837 , this optimization substitutes an expression by a cheaper expression:
33840 \begin_layout Verse
33843 for (i=0;i < 100; i++)
33852 \begin_layout Standard
33856 \begin_layout Verse
33863 for (i=0;i< 100;i++) {
33869 ar[itemp1] = itemp2;
33887 \begin_layout Standard
33888 The more expensive multiplication
33889 \begin_inset LatexCommand \index{Multiplication}
33893 is changed to a less expensive addition.
33896 \begin_layout Subsection
33898 \begin_inset LatexCommand \index{Loop reversing}
33905 \begin_layout Standard
33906 This optimization is done to reduce the overhead of checking loop boundaries
33907 for every iteration.
33908 Some simple loops can be reversed and implemented using a
33909 \begin_inset Quotes eld
33912 decrement and jump if not zero
33913 \begin_inset Quotes erd
33917 SDCC checks for the following criterion to determine if a loop is reversible
33918 (note: more sophisticated compilers use data-dependency analysis to make
33919 this determination, SDCC uses a more simple minded analysis).
33922 \begin_layout Itemize
33923 The 'for' loop is of the form
33929 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
33939 \begin_layout Itemize
33940 The <for body> does not contain
33941 \begin_inset Quotes eld
33945 \begin_inset Quotes erd
33949 \begin_inset Quotes erd
33955 \begin_layout Itemize
33956 All goto's are contained within the loop.
33959 \begin_layout Itemize
33960 No function calls within the loop.
33963 \begin_layout Itemize
33964 The loop control variable <sym> is not assigned any value within the loop
33967 \begin_layout Itemize
33968 The loop control variable does NOT participate in any arithmetic operation
33972 \begin_layout Itemize
33973 There are NO switch statements in the loop.
33976 \begin_layout Subsection
33977 Algebraic Simplifications
33980 \begin_layout Standard
33981 SDCC does numerous algebraic simplifications, the following is a small sub-set
33982 of these optimizations.
33985 \begin_layout Verse
33988 i = j + 0;\InsetSpace ~
33992 /* changed to: */\InsetSpace ~
33998 i /= 2;\InsetSpace ~
34005 /* changed to: */\InsetSpace ~
34012 = j - j;\InsetSpace ~
34016 /* changed to: */\InsetSpace ~
34022 i = j / 1;\InsetSpace ~
34026 /* changed to: */\InsetSpace ~
34033 \begin_layout Standard
34034 Note the subexpressions
34035 \begin_inset LatexCommand \index{Subexpression}
34039 given above are generally introduced by macro expansions or as a result
34040 of copy/constant propagation.
34043 \begin_layout Subsection
34044 'switch' Statements
34045 \begin_inset LatexCommand \label{sub:'switch'-Statements}
34050 \begin_inset LatexCommand \index{switch statement}
34057 \begin_layout Standard
34058 SDCC can optimize switch statements to jump tables
34059 \begin_inset LatexCommand \index{jump tables}
34064 It makes the decision based on an estimate of the generated code size.
34065 SDCC is quite liberal in the requirements for jump table generation:
34068 \begin_layout Itemize
34069 The labels need not be in order, and the starting number need not be one
34070 or zero, the case labels are in numerical sequence or not too many case
34071 labels are missing.
34075 \begin_layout Verse
34078 switch(i) {\InsetSpace ~
34109 case 4: ...\InsetSpace ~
34141 case 5: ...\InsetSpace ~
34173 case 3: ...\InsetSpace ~
34204 case 6: ...\InsetSpace ~
34236 case 7: ...\InsetSpace ~
34268 case 8: ...\InsetSpace ~
34300 case 9: ...\InsetSpace ~
34332 case 10: ...\InsetSpace ~
34363 case 11: ...\InsetSpace ~
34430 \begin_layout Standard
34431 Both the above switch statements will be implemented using a jump-table.
34432 The example to the right side is slightly more efficient as the check for
34433 the lower boundary of the jump-table is not needed.
34437 \begin_layout Itemize
34438 The number of case labels is not larger than supported by the target architectur
34442 \begin_layout Itemize
34443 If the case labels are not in numerical sequence ('gaps' between cases)
34444 SDCC checks whether a jump table with additionally inserted dummy cases
34445 is still attractive.
34449 \begin_layout Itemize
34450 If the starting number is not zero and a check for the lower boundary of
34451 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
34456 \begin_layout Standard
34457 Switch statements which have large gaps in the numeric sequence or those
34458 that have too many case labels can be split into more than one switch statement
34459 for efficient code generation, e.g.:
34462 \begin_layout Verse
34540 \begin_layout Standard
34541 If the above switch statement is broken down into two switch statements
34544 \begin_layout Verse
34587 \begin_layout Standard
34591 \begin_layout Verse
34634 \begin_layout Standard
34635 then both the switch statements will be implemented using jump-tables whereas
34636 the unmodified switch statement will not be.
34639 \begin_layout Standard
34640 \begin_inset Note Note
34643 \begin_layout Standard
34644 There might be reasons which SDCC cannot know about to either favour or
34645 not favour jump tables.
34646 If the target system has to be as quick for the last switch case as for
34647 the first (pro jump table), or if the switch argument is known to be zero
34648 in the majority of the cases (contra jump table).
34656 \begin_layout Standard
34657 The pragma nojtbound
34658 \begin_inset LatexCommand \index{\#pragma nojtbound}
34662 can be used to turn off checking the
34675 It has no effect if a default label is supplied.
34676 Use of this pragma is dangerous: if the switch
34677 \begin_inset LatexCommand \index{switch statement}
34681 argument is not matched by a case statement the processor will happily
34685 \begin_layout Subsection
34686 Bit-shifting Operations
34687 \begin_inset LatexCommand \index{Bit shifting}
34694 \begin_layout Standard
34695 Bit shifting is one of the most frequently used operation in embedded programmin
34697 SDCC tries to implement bit-shift operations in the most efficient way
34701 \begin_layout Verse
34714 \begin_layout Standard
34715 generates the following code:
34718 \begin_layout Verse
34733 \begin_layout Standard
34734 In general SDCC will never setup a loop if the shift count is known.
34738 \begin_layout Verse
34751 \begin_layout Standard
34755 \begin_layout Verse
34779 \begin_layout Subsection
34781 \begin_inset LatexCommand \index{Bit rotation}
34788 \begin_layout Standard
34789 A special case of the bit-shift operation is bit rotation
34790 \begin_inset LatexCommand \index{rotating bits}
34794 , SDCC recognizes the following expression to be a left bit-rotation:
34797 \begin_layout Verse
34805 char i;\InsetSpace ~
34816 /* unsigned is needed for rotation */
34821 i = ((i << 1) | (i >> 7));
34830 \begin_layout Standard
34831 will generate the following code:
34834 \begin_layout Verse
34851 \begin_layout Standard
34852 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
34853 ns of this case will also be recognized as bit-rotation, i.e.:
34856 \begin_layout Verse
34859 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
34862 \begin_layout Subsection
34863 Nibble and Byte Swapping
34866 \begin_layout Standard
34867 Other special cases of the bit-shift operations are nibble or byte swapping
34868 \begin_inset LatexCommand \index{swapping nibbles/bytes}
34872 , SDCC recognizes the following expressions:
34875 \begin_layout Verse
34896 i = ((i << 4) | (i >> 4));
34902 j = ((j << 8) | (j >> 8));
34905 \begin_layout Standard
34906 and generates a swap instruction for the nibble swapping
34907 \begin_inset LatexCommand \index{Nibble swapping}
34911 or move instructions for the byte swapping
34912 \begin_inset LatexCommand \index{Byte swapping}
34918 \begin_inset Quotes sld
34922 \begin_inset Quotes srd
34925 example can be used to convert from little to big-endian or vice versa.
34926 If you want to change the endianness of a
34930 integer you have to cast to
34937 \begin_layout Standard
34938 Note that SDCC stores numbers in little-endian
34942 \begin_layout Standard
34943 Usually 8-bit processors don't care much about endianness.
34944 This is not the case for the standard 8051 which only has an instruction
34950 \begin_inset LatexCommand \index{DPTR}
34958 so little-endian is the more efficient byte order.
34964 \begin_inset LatexCommand \index{little-endian}
34969 \begin_inset LatexCommand \index{Endianness}
34974 lowest order first).
34977 \begin_layout Subsection
34979 \begin_inset LatexCommand \index{Highest Order Bit}
34984 \begin_inset LatexCommand \index{Any Order Bit}
34991 \begin_layout Standard
34992 It is frequently required to obtain the highest order bit of an integral
34993 type (long, int, short or char types).
34994 Also obtaining any other order bit is not uncommon.
34995 SDCC recognizes the following expressions to yield the highest order bit
34996 and generates optimized code for it, e.g.:
34999 \begin_layout Verse
35010 unsigned char hob1, aob1;
35014 bit hob2, hob3, aob2,
35024 hob1 = (gint >> 15) & 1;
35028 hob2 = (gint >> 15) & 1;
35032 hob3 = gint & 0x8000;
35037 aob1 = (gint >> 9) & 1;
35041 aob2 = (gint >> 8) & 1;
35045 aob3 = gint & 0x0800;
35055 \begin_layout Standard
35056 will generate the following code:
35059 \begin_layout Verse
35090 000A E5*01\InsetSpace ~
35117 000C 23\InsetSpace ~
35148 000D 54 01\InsetSpace ~
35176 000F F5*02\InsetSpace ~
35231 0011 E5*01\InsetSpace ~
35259 0013 33\InsetSpace ~
35289 0014 92*00\InsetSpace ~
35345 0016 E5*01\InsetSpace ~
35372 0018 33\InsetSpace ~
35402 0019 92*01\InsetSpace ~
35458 001B E5*01\InsetSpace ~
35517 001E 54 01\InsetSpace ~
35544 0020 F5*03\InsetSpace ~
35600 0022 E5*01\InsetSpace ~
35627 0024 13\InsetSpace ~
35657 0025 92*02\InsetSpace ~
35713 0027 E5*01\InsetSpace ~
35768 002B 92*03\InsetSpace ~
35796 \begin_layout Standard
35797 Other variations of these cases however will
35802 They are standard C expressions, so I heartily recommend these be the only
35803 way to get the highest order bit, (it is portable).
35804 Of course it will be recognized even if it is embedded in other expressions,
35808 \begin_layout Verse
35811 xyz = gint + ((gint >> 15) & 1);
35814 \begin_layout Standard
35815 will still be recognized.
35818 \begin_layout Subsection
35820 \begin_inset LatexCommand \index{Higher Order Byte}
35824 / Higher Order Word
35825 \begin_inset LatexCommand \index{Higher Order Word}
35832 \begin_layout Standard
35833 It is also frequently required to obtain a higher order byte or word of
35834 a larger integral type (long, int or short types).
35835 SDCC recognizes the following expressions to yield the higher order byte
35836 or word and generates optimized code for it, e.g.:
35839 \begin_layout Verse
35844 unsigned long int glong;
35852 unsigned char hob1,
35857 unsigned int how1, how2;
35866 hob1 = (gint >> 8) & 0xFF;
35870 hob2 = glong >> 24;
35874 how1 = (glong >> 16) & 0xFFFF;
35889 \begin_layout Standard
35890 will generate the following code:
35893 \begin_layout Verse
35924 0037 85*01*06\InsetSpace ~
35946 _foo_hob1_1_1,(_gint + 1)
35977 003A 85*05*07\InsetSpace ~
35999 _foo_hob2_1_1,(_glong + 3)
36029 003D 85*04*08\InsetSpace ~
36052 _foo_how1_1_1,(_glong + 2)
36054 0040 85*05*09\InsetSpace ~
36079 0043 85*03*0A\InsetSpace ~
36101 _foo_how2_1_1,(_glong + 1)
36103 0046 85*04*0B\InsetSpace ~
36126 (_foo_how2_1_1 + 1),(_glong + 2)
36129 \begin_layout Standard
36130 Again, variations of these cases may
36135 They are standard C expressions, so I heartily recommend these be the only
36136 way to get the higher order byte/word, (it is portable).
36137 Of course it will be recognized even if it is embedded in other expressions,
36141 \begin_layout Verse
36144 xyz = gint + ((gint >> 8) & 0xFF);
36147 \begin_layout Standard
36148 will still be recognized.
36151 \begin_layout Subsection
36153 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
36158 \begin_inset LatexCommand \index{Peephole optimizer}
36165 \begin_layout Standard
36166 The compiler uses a rule based, pattern matching and re-writing mechanism
36167 for peep-hole optimization.
36172 a peep-hole optimizer by Christopher W.
36173 Fraser (cwfraser\InsetSpace ~
36176 A default set of rules are compiled into the compiler, additional rules
36177 may be added with the
36183 \begin_layout Standard
36193 \begin_inset LatexCommand \index{-\/-peep-file}
36200 The rule language is best illustrated with examples.
36203 \begin_layout Verse
36225 \begin_layout Standard
36226 The above rule will change the following assembly
36227 \begin_inset LatexCommand \index{Assembler routines}
36234 \begin_layout Verse
36242 \begin_layout Standard
36246 \begin_layout Verse
36252 \begin_layout Standard
36253 Note: All occurrences of a
36257 (pattern variable) must denote the same string.
36258 With the above rule, the assembly sequence:
36261 \begin_layout Verse
36269 \begin_layout Standard
36270 will remain unmodified.
36274 Other special case optimizations may be added by the
36281 \begin_layout Standard
36294 some variants of the 8051 MCU
36295 \begin_inset LatexCommand \index{MCS51 variants}
36308 The following two rules will change all
36325 \begin_layout Verse
36328 replace { lcall %1 } by { acall %1 }
36330 replace { ljmp %1 } by { ajmp %1 }
36333 \begin_layout Standard
36334 (NOTE: from version 2.7.3 on, you can use option -
36340 \begin_layout Standard
36352 \begin_inset LatexCommand \index{-\/-acall-ajmp}
36356 , which also takes care of aligning the interrupt vectors properly.)
36361 \begin_layout Standard
36364 inline-assembler code
36366 is also passed through the peep hole optimizer, thus the peephole optimizer
36367 can also be used as an assembly level macro expander.
36368 The rules themselves are MCU dependent whereas the rule language infra-structur
36369 e is MCU independent.
36370 Peephole optimization rules for other MCU can be easily programmed using
36375 The syntax for a rule is as follows:
36378 \begin_layout Verse
36381 rule := replace [ restart ] '{' <assembly sequence> '
36419 <assembly sequence> '
36437 '}' [if <functionName> ] '
36442 \begin_layout Standard
36443 <assembly sequence> := assembly instruction (each instruction including
36444 labels must be on a separate line).
36448 The optimizer will apply to the rules
36449 one by one from the top in the sequence of their appearance, it will terminate
36450 when all rules are exhausted.
36451 If the 'restart' option is specified, then the optimizer will start matching
36452 the rules again from the top, this option for a rule is expensive (performance)
36453 , it is intended to be used in situations where a transformation will trigger
36454 the same rule again.
36455 An example of this (not a good one, it has side effects) is the following
36459 \begin_layout Verse
36479 \begin_layout Standard
36480 Note that the replace pattern cannot be a blank, but can be a comment line.
36481 Without the 'restart' option only the innermost 'pop' 'push' pair would
36482 be eliminated, i.e.:
36485 \begin_layout Verse
36497 \begin_layout Standard
36501 \begin_layout Verse
36511 \begin_layout Standard
36516 the restart option the rule will be applied again to the resulting code
36517 and then all the pop-push pairs will be eliminated to yield:
36520 \begin_layout Verse
36528 \begin_layout Standard
36529 A conditional function can be attached to a rule.
36530 Attaching rules are somewhat more involved, let me illustrate this with
36534 \begin_layout Verse
36558 \begin_layout Standard
36559 The optimizer does a look-up of a function name table defined in function
36564 in the source file SDCCpeeph.c, with the name
36569 If it finds a corresponding entry the function is called.
36570 Note there can be no parameters specified for these functions, in this
36575 is crucial, since the function
36579 expects to find the label in that particular variable (the hash table containin
36580 g the variable bindings is passed as a parameter).
36581 If you want to code more such functions, take a close look at the function
36582 labelInRange and the calling mechanism in source file SDCCpeeph.c.
36583 Currently implemented are
36585 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
36586 24bitMode, portIsDS390, 24bitModeAndPortDS390
36595 \begin_layout Standard
36596 I know this whole thing is a little kludgey, but maybe some day we will
36597 have some better means.
36598 If you are looking at this file, you will see the default rules that are
36599 compiled into the compiler, you can add your own rules in the default set
36600 there if you get tired of specifying the -
36604 \begin_layout Standard
36616 \begin_layout Section
36618 \begin_inset LatexCommand \index{ANSI-compliance}
36623 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
36630 \begin_layout Standard
36631 The latest publically available version of the standard
36633 ISO/IEC 9899 - Programming languages - C
36635 should be available at:
36636 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
36645 \begin_layout Standard
36646 Deviations from the compliance:
36649 \begin_layout Itemize
36650 functions are not reentrant
36651 \begin_inset LatexCommand \index{reentrant}
36655 unless explicitly declared as such or the
36661 \begin_layout Standard
36671 \begin_inset LatexCommand \index{-\/-stack-auto}
36677 command line option is specified.
36680 \begin_layout Itemize
36682 \begin_inset LatexCommand \index{struct}
36687 \begin_inset LatexCommand \index{union}
36691 cannot be assigned values directly, cannot be passed as function parameters
36692 or assigned to each other and cannot be a return value
36693 \begin_inset LatexCommand \index{return value}
36697 from a function, e.g.:
36701 \begin_layout Verse
36724 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
36743 s parms) /* invalid in SDCC although allowed in ANSI */
36765 return rets; /* is invalid in SDCC although allowed in ANSI */
36771 \begin_layout Itemize
36772 initialization of structure arrays must be fully braced.
36776 \begin_layout Verse
36779 struct s { char x } a[] = {1, 2};\InsetSpace ~
36784 /* invalid in SDCC */
36787 } a[] = {{1}, {2}}; /* OK */
36791 \begin_layout Itemize
36793 \begin_inset LatexCommand \index{long long (not supported)}
36798 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
36805 \begin_layout Itemize
36807 \begin_inset LatexCommand \index{double (not supported)}
36811 ' precision floating point
36812 \begin_inset LatexCommand \index{Floating point support}
36819 \begin_layout Itemize
36821 \begin_inset LatexCommand \index{K\&R style}
36825 function declarations are NOT allowed.
36829 \begin_layout Verse
36832 foo(i,j) /* this old style of function declarations */
36834 int i,j; /* is valid
36835 in ANSI but not valid in SDCC */
36850 \begin_layout Itemize
36851 Most enhancements in C99 are not supported, e.g.:
36855 \begin_layout Verse
36862 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
36866 \begin_layout Itemize
36867 But some have been added recently in SDCC 2.7.0.
36868 They must be considered alpha quality however.
36872 \begin_layout Verse
36877 \begin_inset LatexCommand \index{inline (not supported)}
36883 int increment (int a) { return a+1; } /* inlines the increment without
36884 function call overhead */
36889 \begin_inset LatexCommand \index{inline (not supported)}
36895 p; /* accepted but ignored */
36899 \begin_layout Itemize
36900 Certain words that are valid identifiers in the standard may be reserved
36901 words in SDCC unless the
36907 \begin_layout Standard
36917 \begin_inset LatexCommand \index{-\/-std-c89}
36929 \begin_layout Standard
36939 \begin_inset LatexCommand \index{-\/-std-c99}
36945 command line options are used.
36946 These may include (depending on the selected processor): 'at', 'banked',
36947 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
36948 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
36949 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
36951 Compliant equivalents of these keywords are always available in a form
36952 that begin with two underscores
36953 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
36958 '__data' instead of 'data'.
36961 \begin_layout Itemize
36962 Integer promotion of variable arguments is not performed if the argument
36963 is explicitly taypecasted unless the
36969 \begin_layout Standard
36979 \begin_inset LatexCommand \index{-\/-std-c89}
36991 \begin_layout Standard
37001 \begin_inset LatexCommand \index{-\/-std-c99}
37007 command line options are used.
37011 \begin_layout Verse
37014 void vararg_func (char *str, ...) { str; }
37031 u is promoted to int before
37036 * passing to function */
37040 vararg_func ("%c", c);
37047 argument u is not promoted to int,
37052 * it is passed as char to function
37058 --std-cXX is not defined;
37063 * is promoted to int before passing
37069 if --std-cXX is defined */
37073 vararg_func ("%bc", (char)u);
37079 \begin_layout Section
37080 Cyclomatic Complexity
37081 \begin_inset LatexCommand \index{Cyclomatic complexity}
37088 \begin_layout Standard
37089 Cyclomatic complexity of a function is defined as the number of independent
37090 paths the program can take during execution of the function.
37091 This is an important number since it defines the number test cases you
37092 have to generate to validate the function.
37093 The accepted industry standard for complexity number is 10, if the cyclomatic
37094 complexity reported by SDCC exceeds 10 you should think about simplification
37095 of the function logic.
37096 Note that the complexity level is not related to the number of lines of
37097 code in a function.
37098 Large functions can have low complexity, and small functions can have large
37104 SDCC uses the following formula to compute the complexity:
37109 \begin_layout Standard
37110 complexity = (number of edges in control flow graph) - (number of nodes
37111 in control flow graph) + 2;
37115 Having said that the industry standard is 10,
37116 you should be aware that in some cases it be may unavoidable to have a
37117 complexity level of less than 10.
37118 For example if you have switch statement with more than 10 case labels,
37119 each case label adds one to the complexity level.
37120 The complexity level is by no means an absolute measure of the algorithmic
37121 complexity of the function, it does however provide a good starting point
37122 for which functions you might look at for further optimization.
37125 \begin_layout Section
37126 Retargetting for other Processors
37129 \begin_layout Standard
37130 The issues for retargetting the compiler are far too numerous to be covered
37132 What follows is a brief description of each of the seven phases of the
37133 compiler and its MCU dependency.
37136 \begin_layout Itemize
37137 Parsing the source and building the annotated parse tree.
37138 This phase is largely MCU independent (except for the language extensions).
37139 Syntax & semantic checks are also done in this phase, along with some initial
37140 optimizations like back patching labels and the pattern matching optimizations
37141 like bit-rotation etc.
37144 \begin_layout Itemize
37145 The second phase involves generating an intermediate code which can be easy
37146 manipulated during the later phases.
37147 This phase is entirely MCU independent.
37148 The intermediate code generation assumes the target machine has unlimited
37149 number of registers, and designates them with the name iTemp.
37150 The compiler can be made to dump a human readable form of the code generated
37155 \begin_layout Standard
37167 \begin_layout Itemize
37168 This phase does the bulk of the standard optimizations and is also MCU independe
37170 This phase can be broken down into several sub-phases:
37174 Break down intermediate
37175 code (iCode) into basic blocks.
37177 Do control flow & data flow analysis on the
37180 Do local common subexpression elimination, then global subexpressio
37183 Dead code elimination
37187 If loop optimizations
37188 caused any changes then do 'global subexpression elimination' and 'dead
37189 code elimination' again.
37192 \begin_layout Itemize
37193 This phase determines the live-ranges; by live range I mean those iTemp
37194 variables defined by the compiler that still survive after all the optimization
37196 Live range analysis
37197 \begin_inset LatexCommand \index{Live range analysis}
37201 is essential for register allocation, since these computation determines
37202 which of these iTemps will be assigned to registers, and for how long.
37205 \begin_layout Itemize
37206 Phase five is register allocation.
37207 There are two parts to this process.
37211 The first part I call 'register packing'
37212 (for lack of a better term).
37213 In this case several MCU specific expression folding is done to reduce
37218 The second part is more MCU independent and deals with
37219 allocating registers to the remaining live ranges.
37220 A lot of MCU specific code does creep into this phase because of the limited
37221 number of index registers available in the 8051.
37224 \begin_layout Itemize
37225 The Code generation phase is (unhappily), entirely MCU dependent and very
37226 little (if any at all) of this code can be reused for other MCU.
37227 However the scheme for allocating a homogenized assembler operand for each
37228 iCode operand may be reused.
37231 \begin_layout Itemize
37232 As mentioned in the optimization section the peep-hole optimizer is rule
37233 based system, which can reprogrammed for other MCUs.
37236 \begin_layout Standard
37237 More information is available on SDCC Wiki
37238 \begin_inset LatexCommand \index{wiki}
37243 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting}
37247 ) and in the thread
37248 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
37255 \begin_layout Chapter
37257 \begin_inset LatexCommand \index{Compiler internals}
37264 \begin_layout Section
37265 The anatomy of the compiler
37266 \begin_inset LatexCommand \label{sub:The-anatomy-of}
37273 \begin_layout Standard
37276 This is an excerpt from an article published in Circuit Cellar Magazine
37282 It's a little outdated (the compiler is much more efficient now and user/develo
37283 per friendly), but pretty well exposes the guts of it all.
37289 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
37290 It is fairly easy to retarget for other 8-bit MCU.
37291 Here we take a look at some of the internals of the compiler.
37295 \begin_layout Paragraph*
37297 \begin_inset LatexCommand \index{Parsing}
37304 \begin_layout Standard
37305 Parsing the input source file and creating an AST (Annotated Syntax Tree
37306 \begin_inset LatexCommand \index{Annotated syntax tree}
37311 This phase also involves propagating types (annotating each node of the
37312 parse tree with type information) and semantic analysis.
37313 There are some MCU specific parsing rules.
37314 For example the storage classes, the extended storage classes are MCU specific
37315 while there may be a xdata storage class for 8051 there is no such storage
37316 class for z80 or Atmel AVR.
37317 SDCC allows MCU specific storage class extensions, i.e.
37318 xdata will be treated as a storage class specifier when parsing 8051 C
37319 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
37323 \begin_layout Paragraph*
37325 \begin_inset LatexCommand \index{iCode}
37332 \begin_layout Standard
37333 Intermediate code generation.
37334 In this phase the AST is broken down into three-operand form (iCode).
37335 These three operand forms are represented as doubly linked lists.
37336 ICode is the term given to the intermediate form generated by the compiler.
37337 ICode example section shows some examples of iCode generated for some simple
37338 C source functions.
37341 \begin_layout Paragraph*
37343 \begin_inset LatexCommand \index{Optimizations}
37350 \begin_layout Standard
37351 Bulk of the target independent optimizations is performed in this phase.
37352 The optimizations include constant propagation, common sub-expression eliminati
37353 on, loop invariant code movement, strength reduction of loop induction variables
37354 and dead-code elimination.
37357 \begin_layout Paragraph*
37358 Live range analysis
37359 \begin_inset LatexCommand \index{Live range analysis}
37366 \begin_layout Standard
37367 During intermediate code generation phase, the compiler assumes the target
37368 machine has infinite number of registers and generates a lot of temporary
37370 The live range computation determines the lifetime of each of these compiler-ge
37371 nerated temporaries.
37372 A picture speaks a thousand words.
37373 ICode example sections show the live range annotations for each of the
37375 It is important to note here, each iCode is assigned a number in the order
37376 of its execution in the function.
37377 The live ranges are computed in terms of these numbers.
37378 The from number is the number of the iCode which first defines the operand
37379 and the to number signifies the iCode which uses this operand last.
37382 \begin_layout Paragraph*
37383 Register Allocation
37384 \begin_inset LatexCommand \index{Register allocation}
37391 \begin_layout Standard
37392 The register allocation determines the type and number of registers needed
37394 In most MCUs only a few registers can be used for indirect addressing.
37395 In case of 8051 for example the registers R0 & R1 can be used to indirectly
37396 address the internal ram and DPTR to indirectly address the external ram.
37397 The compiler will try to allocate the appropriate register to pointer variables
37399 ICode example section shows the operands annotated with the registers assigned
37401 The compiler will try to keep operands in registers as much as possible;
37402 there are several schemes the compiler uses to do achieve this.
37403 When the compiler runs out of registers the compiler will check to see
37404 if there are any live operands which is not used or defined in the current
37405 basic block being processed, if there are any found then it will push that
37406 operand and use the registers in this block, the operand will then be popped
37407 at the end of the basic block.
37411 \begin_layout Standard
37412 There are other MCU specific considerations in this phase.
37413 Some MCUs have an accumulator; very short-lived operands could be assigned
37414 to the accumulator instead of a general-purpose register.
37417 \begin_layout Paragraph*
37421 \begin_layout Standard
37422 Figure II gives a table of iCode
37423 \begin_inset LatexCommand \index{iCode}
37427 operations supported by the compiler.
37428 The code generation involves translating these operations into corresponding
37429 assembly code for the processor.
37430 This sounds overly simple but that is the essence of code generation.
37431 Some of the iCode operations are generated on a MCU specific manner for
37432 example, the z80 port does not use registers to pass parameters so the
37433 SEND and RECV iCode operations will not be generated, and it also does
37434 not support JUMPTABLES.
37440 \begin_layout Standard
37444 \begin_inset Tabular
37445 <lyxtabular version="3" rows="39" columns="4">
37446 <features islongtable="true" headBottomDL="true">
37447 <column alignment="block" valignment="top" leftline="true" width="13col%">
37448 <column alignment="left" valignment="top" leftline="true" width="13col%">
37449 <column alignment="block" valignment="top" leftline="true" width="22col%">
37450 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
37451 <row topline="true" bottomline="true" endhead="true">
37452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37455 \begin_layout Standard
37461 \begin_inset LatexCommand \index{iCode}
37470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37473 \begin_layout Standard
37481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37484 \begin_layout Standard
37492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37495 \begin_layout Standard
37504 <row topline="true">
37505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37508 \begin_layout Standard
37516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37519 \begin_layout Standard
37522 IC_LEFT() IC_RESULT()
37527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37530 \begin_layout Standard
37538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37541 \begin_layout Standard
37544 IC_RESULT = ! IC_LEFT;
37550 <row topline="true">
37551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37554 \begin_layout Standard
37562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37565 \begin_layout Standard
37568 IC_LEFT() IC_RESULT()
37573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37576 \begin_layout Standard
37579 Bitwise complement of
37584 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37587 \begin_layout Standard
37590 IC_RESULT = ~IC_LEFT;
37596 <row topline="true">
37597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37600 \begin_layout Standard
37608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37611 \begin_layout Standard
37614 IC_LEFT() IC_RESULT()
37619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37622 \begin_layout Standard
37625 Rotate right with carry
37630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37633 \begin_layout Standard
37636 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
37642 <row topline="true">
37643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37646 \begin_layout Standard
37654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37657 \begin_layout Standard
37660 IC_LEFT() IC_RESULT()
37665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37668 \begin_layout Standard
37671 Rotate left with carry
37676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37679 \begin_layout Standard
37682 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
37688 <row topline="true">
37689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37692 \begin_layout Standard
37700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37703 \begin_layout Standard
37706 IC_LEFT() IC_RESULT()
37711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37714 \begin_layout Standard
37717 Get the highest order bit of IC_LEFT
37722 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37725 \begin_layout Standard
37728 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
37734 <row topline="true">
37735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37738 \begin_layout Standard
37746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37749 \begin_layout Standard
37752 IC_LEFT() IC_RESULT()
37757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37760 \begin_layout Standard
37768 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37771 \begin_layout Standard
37774 IC_RESULT = - IC_LEFT;
37780 <row topline="true">
37781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37784 \begin_layout Standard
37792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37795 \begin_layout Standard
37803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37806 \begin_layout Standard
37809 Push the operand into stack
37814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37817 \begin_layout Standard
37826 <row topline="true">
37827 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37830 \begin_layout Standard
37838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37841 \begin_layout Standard
37849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37852 \begin_layout Standard
37855 Pop the operand from the stack
37860 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37863 \begin_layout Standard
37872 <row topline="true">
37873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37876 \begin_layout Standard
37884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37887 \begin_layout Standard
37890 IC_LEFT() IC_RESULT()
37895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37898 \begin_layout Standard
37901 Call the function represented by IC_LEFT
37906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37909 \begin_layout Standard
37912 IC_RESULT = IC_LEFT();
37918 <row topline="true">
37919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37922 \begin_layout Standard
37930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37933 \begin_layout Standard
37936 IC_LEFT() IC_RESULT()
37941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37944 \begin_layout Standard
37947 Call via function pointer
37952 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37955 \begin_layout Standard
37958 IC_RESULT = (*IC_LEFT)();
37964 <row topline="true">
37965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37968 \begin_layout Standard
37976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37979 \begin_layout Standard
37987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37990 \begin_layout Standard
37993 Return the value in operand IC_LEFT
37998 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38001 \begin_layout Standard
38010 <row topline="true">
38011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38014 \begin_layout Standard
38022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38025 \begin_layout Standard
38033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38036 \begin_layout Standard
38044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38047 \begin_layout Standard
38056 <row topline="true">
38057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38060 \begin_layout Standard
38068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38071 \begin_layout Standard
38079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38082 \begin_layout Standard
38090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38093 \begin_layout Standard
38102 <row topline="true">
38103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38106 \begin_layout Standard
38114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38117 \begin_layout Standard
38120 IC_LEFT() IC_RIGHT() IC_RESULT()
38125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38128 \begin_layout Standard
38136 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38139 \begin_layout Standard
38142 IC_RESULT = IC_LEFT + IC_RIGHT
38148 <row topline="true">
38149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38152 \begin_layout Standard
38160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38163 \begin_layout Standard
38166 IC_LEFT() IC_RIGHT() IC_RESULT()
38171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38174 \begin_layout Standard
38182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38185 \begin_layout Standard
38188 IC_RESULT = IC_LEFT - IC_RIGHT
38194 <row topline="true">
38195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38198 \begin_layout Standard
38206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38209 \begin_layout Standard
38212 IC_LEFT() IC_RIGHT() IC_RESULT()
38217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38220 \begin_layout Standard
38228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38231 \begin_layout Standard
38234 IC_RESULT = IC_LEFT * IC_RIGHT;
38240 <row topline="true">
38241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38244 \begin_layout Standard
38252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38255 \begin_layout Standard
38258 IC_LEFT() IC_RIGHT() IC_RESULT()
38263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38266 \begin_layout Standard
38274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38277 \begin_layout Standard
38280 IC_RESULT = IC_LEFT / IC_RIGHT;
38286 <row topline="true">
38287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38290 \begin_layout Standard
38298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38301 \begin_layout Standard
38304 IC_LEFT() IC_RIGHT() IC_RESULT()
38309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38312 \begin_layout Standard
38320 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38323 \begin_layout Standard
38326 IC_RESULT = IC_LEFT % IC_RIGHT;
38332 <row topline="true">
38333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38336 \begin_layout Standard
38344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38347 \begin_layout Standard
38350 IC_LEFT() IC_RIGHT() IC_RESULT()
38355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38358 \begin_layout Standard
38366 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38369 \begin_layout Standard
38372 IC_RESULT = IC_LEFT < IC_RIGHT;
38378 <row topline="true">
38379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38382 \begin_layout Standard
38390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38393 \begin_layout Standard
38396 IC_LEFT() IC_RIGHT() IC_RESULT()
38401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38404 \begin_layout Standard
38412 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38415 \begin_layout Standard
38418 IC_RESULT = IC_LEFT > IC_RIGHT;
38424 <row topline="true">
38425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38428 \begin_layout Standard
38436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38439 \begin_layout Standard
38442 IC_LEFT() IC_RIGHT() IC_RESULT()
38447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38450 \begin_layout Standard
38458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38461 \begin_layout Standard
38464 IC_RESULT = IC_LEFT == IC_RIGHT;
38470 <row topline="true">
38471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38474 \begin_layout Standard
38482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38485 \begin_layout Standard
38488 IC_LEFT() IC_RIGHT() IC_RESULT()
38493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38496 \begin_layout Standard
38499 Logical and operation
38504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38507 \begin_layout Standard
38510 IC_RESULT = IC_LEFT && IC_RIGHT;
38516 <row topline="true">
38517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38520 \begin_layout Standard
38528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38531 \begin_layout Standard
38534 IC_LEFT() IC_RIGHT() IC_RESULT()
38539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38542 \begin_layout Standard
38545 Logical or operation
38550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38553 \begin_layout Standard
38556 IC_RESULT = IC_LEFT || IC_RIGHT;
38562 <row topline="true">
38563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38566 \begin_layout Standard
38574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38577 \begin_layout Standard
38580 IC_LEFT() IC_RIGHT() IC_RESULT()
38585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38588 \begin_layout Standard
38596 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38599 \begin_layout Standard
38602 IC_RESULT = IC_LEFT ^ IC_RIGHT;
38608 <row topline="true">
38609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38612 \begin_layout Standard
38620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38623 \begin_layout Standard
38626 IC_LEFT() IC_RIGHT() IC_RESULT()
38631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38634 \begin_layout Standard
38642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38645 \begin_layout Standard
38648 IC_RESULT = IC_LEFT | IC_RIGHT;
38654 <row topline="true">
38655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38658 \begin_layout Standard
38666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38669 \begin_layout Standard
38672 IC_LEFT() IC_RIGHT() IC_RESULT()
38677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38680 \begin_layout Standard
38688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38691 \begin_layout Standard
38694 IC_RESULT = IC_LEFT & IC_RIGHT;
38700 <row topline="true">
38701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38704 \begin_layout Standard
38712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38715 \begin_layout Standard
38718 IC_LEFT() IC_RIGHT() IC_RESULT()
38723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38726 \begin_layout Standard
38734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38737 \begin_layout Standard
38740 IC_RESULT = IC_LEFT << IC_RIGHT
38746 <row topline="true">
38747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38750 \begin_layout Standard
38758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38761 \begin_layout Standard
38764 IC_LEFT() IC_RIGHT() IC_RESULT()
38769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38772 \begin_layout Standard
38780 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38783 \begin_layout Standard
38786 IC_RESULT = IC_LEFT >> IC_RIGHT
38792 <row topline="true">
38793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38796 \begin_layout Standard
38806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38809 \begin_layout Standard
38812 IC_LEFT() IC_RESULT()
38817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38820 \begin_layout Standard
38828 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38831 \begin_layout Standard
38834 IC_RESULT = (*IC_LEFT);
38840 <row topline="true">
38841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38844 \begin_layout Standard
38852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38855 \begin_layout Standard
38858 IC_RIGHT() IC_RESULT()
38863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38866 \begin_layout Standard
38874 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38877 \begin_layout Standard
38880 (*IC_RESULT) = IC_RIGHT;
38886 <row topline="true">
38887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38890 \begin_layout Standard
38898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38901 \begin_layout Standard
38904 IC_RIGHT() IC_RESULT()
38909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38912 \begin_layout Standard
38920 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38923 \begin_layout Standard
38926 IC_RESULT = IC_RIGHT;
38932 <row topline="true">
38933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38936 \begin_layout Standard
38944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38947 \begin_layout Standard
38950 IC_COND IC_TRUE IC_LABEL
38955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38958 \begin_layout Standard
38962 If true label is present then jump to true label if condition is true else
38963 jump to false label if condition is false
38968 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38971 \begin_layout Standard
38974 if (IC_COND) goto IC_TRUE;
38980 If (!IC_COND) goto IC_FALSE;
38986 <row topline="true">
38987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38990 \begin_layout Standard
38998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39001 \begin_layout Standard
39004 IC_LEFT() IC_RESULT()
39009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39012 \begin_layout Standard
39020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39023 \begin_layout Standard
39026 IC_RESULT = &IC_LEFT();
39032 <row topline="true">
39033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39036 \begin_layout Standard
39044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39047 \begin_layout Standard
39050 IC_JTCOND IC_JTLABELS
39055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39058 \begin_layout Standard
39061 Jump to list of labels depending on the value of JTCOND
39066 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39069 \begin_layout Standard
39078 <row topline="true">
39079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39082 \begin_layout Standard
39090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39093 \begin_layout Standard
39096 IC_RIGHT() IC_LEFT() IC_RESULT()
39101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39104 \begin_layout Standard
39112 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39115 \begin_layout Standard
39118 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
39124 <row topline="true">
39125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39128 \begin_layout Standard
39136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39139 \begin_layout Standard
39147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39150 \begin_layout Standard
39153 This is used for passing parameters in registers;
39155 move IC_LEFT to the next
39156 available parameter register.
39161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39164 \begin_layout Standard
39173 <row topline="true">
39174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39177 \begin_layout Standard
39185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39188 \begin_layout Standard
39196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39199 \begin_layout Standard
39202 This is used for receiving parameters passed in registers;
39205 in the next parameter register to IC_RESULT
39210 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39213 \begin_layout Standard
39222 <row topline="true" bottomline="true">
39223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39226 \begin_layout Standard
39230 (some more have been added)
39235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39238 \begin_layout Standard
39244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39247 \begin_layout Standard
39253 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39256 \begin_layout Standard
39280 \begin_layout Standard
39281 \begin_inset Note Note
39284 \begin_layout Standard
39285 In the original article Figure II was announced to be downloadable on
39290 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
39298 \begin_layout Paragraph*
39300 \begin_inset LatexCommand \index{iCode}
39307 \begin_layout Standard
39308 This section shows some details of iCode.
39309 The example C code does not do anything useful; it is used as an example
39310 to illustrate the intermediate code generated by the compiler.
39313 \begin_layout Verse
39323 /* This function does nothing useful.
39330 for the purpose of explaining iCode */
39333 short function (data
39342 short i=10; \InsetSpace ~
39344 /* dead initialization eliminated */
39350 /* dead initialization eliminated */
39378 /* compiler detects i,j to be induction
39383 for (i = 0, j = 10 ; i < 10 ; i++, j
39389 \begin_layout Standard
39412 mul += i * 3; \InsetSpace ~
39414 /* this multiplication remains */
39421 j * 3;\InsetSpace ~
39423 /* this multiplication changed to addition */
39437 \begin_layout Standard
39438 In addition to the operands each iCode contains information about the filename
39439 and line it corresponds to in the source file.
39440 The first field in the listing should be interpreted as follows:
39445 Filename(linenumber: iCode Execution sequence number : ICode hash table
39446 key : loop depth of the iCode).
39451 Then follows the human readable form of the ICode operation.
39452 Each operand of this triplet form can be of three basic types a) compiler
39453 generated temporary b) user defined variable c) a constant value.
39454 Note that local variables and parameters are replaced by compiler generated
39457 \begin_inset LatexCommand \index{Live range analysis}
39461 are computed only for temporaries (i.e.
39462 live ranges are not computed for global variables).
39464 \begin_inset LatexCommand \index{Register allocation}
39468 are allocated for temporaries only.
39469 Operands are formatted in the following manner:
39474 Operand Name [lr live-from : live-to ] { type information } [ registers
39480 As mentioned earlier the live ranges are computed in terms of the execution
39481 sequence number of the iCodes, for example
39483 the iTemp0 is live from (i.e.
39484 first defined in iCode with execution sequence number 3, and is last used
39485 in the iCode with sequence number 5).
39486 For induction variables such as iTemp21 the live range computation extends
39487 the lifetime from the start to the end of the loop.
39489 The register allocator
39490 used the live range information to allocate registers, the same registers
39491 may be used for different temporaries if their live ranges do not overlap,
39492 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
39493 ranges do not overlap.
39494 In addition the allocator also takes into consideration the type and usage
39495 of a temporary, for example itemp6 is a pointer to near space and is used
39496 as to fetch data from (i.e.
39497 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
39498 Some short lived temporaries are allocated to special registers which have
39499 meaning to the code generator e.g.
39500 iTemp13 is allocated to a pseudo register CC which tells the back end that
39501 the temporary is used only for a conditional jump the code generation makes
39502 use of this information to optimize a compare and jump ICode.
39506 \begin_inset LatexCommand \index{Loop optimization}
39510 performed by the compiler.
39511 It can detect induction variables iTemp21(i) and iTemp23(j).
39512 Also note the compiler does selective strength reduction
39513 \begin_inset LatexCommand \index{Strength reduction}
39518 the multiplication of an induction variable in line 18 (gint = j * 3) is
39519 changed to addition, a new temporary iTemp17 is allocated and assigned
39520 a initial value, a constant 3 is then added for each iteration of the loop.
39521 The compiler does not change the multiplication
39522 \begin_inset LatexCommand \index{Multiplication}
39526 in line 17 however since the processor does support an 8 * 8 bit multiplication.
39529 Note the dead code elimination
39530 \begin_inset LatexCommand \index{Dead-code elimination}
39534 optimization eliminated the dead assignments in line 7 & 8 to I and sum
39540 \begin_layout Standard
39543 Sample.c (5:1:0:0) _entry($9) :
39546 \begin_layout Standard
39549 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
39552 \begin_layout Standard
39555 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
39558 \begin_layout Standard
39561 Sample.c(11:4:53:0) preHeaderLbl0($11) :
39564 \begin_layout Standard
39567 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
39571 \begin_layout Standard
39574 Sample.c(11:6:5:1) _whilecontinue_0($1) :
39577 \begin_layout Standard
39580 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
39584 \begin_layout Standard
39587 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39590 \begin_layout Standard
39593 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
39597 \begin_layout Standard
39600 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
39604 \begin_layout Standard
39607 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
39611 \begin_layout Standard
39614 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
39618 \begin_layout Standard
39621 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
39622 * int}[r0] + 0x2 {short}
39625 \begin_layout Standard
39628 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
39631 \begin_layout Standard
39634 Sample.c(11:17:21:0)_whilebreak_0($3) :
39637 \begin_layout Standard
39640 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39643 \begin_layout Standard
39646 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39649 \begin_layout Standard
39652 Sample.c(15:20:54:0)preHeaderLbl1($13) :
39655 \begin_layout Standard
39658 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39661 \begin_layout Standard
39664 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39667 \begin_layout Standard
39670 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39673 \begin_layout Standard
39676 Sample.c(15:24:26:1)_forcond_0($4) :
39679 \begin_layout Standard
39682 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
39686 \begin_layout Standard
39689 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39692 \begin_layout Standard
39695 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
39696 + ITemp21 [lr21:38]{short}[r4]
39699 \begin_layout Standard
39702 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
39706 \begin_layout Standard
39709 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
39710 + iTemp15 [lr29:30]{short}[r1]
39713 \begin_layout Standard
39716 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
39720 \begin_layout Standard
39723 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
39727 \begin_layout Standard
39730 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
39734 \begin_layout Standard
39737 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
39741 \begin_layout Standard
39744 Sample.c(19:38:47:1) goto _forcond_0($4)
39747 \begin_layout Standard
39750 Sample.c(19:39:48:0)_forbreak_0($7) :
39753 \begin_layout Standard
39756 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
39757 + ITemp11 [lr19:40]{short}[r3]
39760 \begin_layout Standard
39763 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
39766 \begin_layout Standard
39769 Sample.c(20:42:51:0)_return($8) :
39772 \begin_layout Standard
39775 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
39781 Finally the code generated for this function:
39786 \begin_layout Standard
39792 \begin_layout Standard
39798 \begin_layout Standard
39806 \begin_layout Standard
39812 \begin_layout Standard
39820 \begin_layout Standard
39826 \begin_layout Standard
39829 ; ----------------------------------------------
39832 \begin_layout Standard
39835 ; function function
39838 \begin_layout Standard
39841 ; ----------------------------------------------
39844 \begin_layout Standard
39850 \begin_layout Standard
39853 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
39856 \begin_layout Standard
39864 \begin_layout Standard
39867 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
39870 \begin_layout Standard
39878 \begin_layout Standard
39881 ;_whilecontinue_0($1) :
39884 \begin_layout Standard
39890 \begin_layout Standard
39893 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
39896 \begin_layout Standard
39899 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39902 \begin_layout Standard
39910 \begin_layout Standard
39918 \begin_layout Standard
39926 \begin_layout Standard
39934 \begin_layout Standard
39942 \begin_layout Standard
39950 \begin_layout Standard
39958 \begin_layout Standard
39964 \begin_layout Standard
39967 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
39970 \begin_layout Standard
39978 \begin_layout Standard
39986 \begin_layout Standard
39989 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
39992 \begin_layout Standard
40000 \begin_layout Standard
40008 \begin_layout Standard
40016 \begin_layout Standard
40024 \begin_layout Standard
40032 \begin_layout Standard
40040 \begin_layout Standard
40043 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
40046 \begin_layout Standard
40054 \begin_layout Standard
40062 \begin_layout Standard
40070 \begin_layout Standard
40078 \begin_layout Standard
40086 \begin_layout Standard
40089 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
40092 \begin_layout Standard
40100 \begin_layout Standard
40108 \begin_layout Standard
40116 \begin_layout Standard
40119 ; iTemp6 [lr5:16]{_near * int}[r0] =
40122 \begin_layout Standard
40125 ; iTemp6 [lr5:16]{_near * int}[r0] +
40128 \begin_layout Standard
40134 \begin_layout Standard
40142 \begin_layout Standard
40145 ; goto _whilecontinue_0($1)
40148 \begin_layout Standard
40156 \begin_layout Standard
40159 ; _whilebreak_0($3) :
40162 \begin_layout Standard
40168 \begin_layout Standard
40171 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
40174 \begin_layout Standard
40182 \begin_layout Standard
40185 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
40188 \begin_layout Standard
40196 \begin_layout Standard
40199 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
40202 \begin_layout Standard
40210 \begin_layout Standard
40213 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
40216 \begin_layout Standard
40224 \begin_layout Standard
40232 \begin_layout Standard
40235 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
40238 \begin_layout Standard
40246 \begin_layout Standard
40254 \begin_layout Standard
40260 \begin_layout Standard
40266 \begin_layout Standard
40269 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
40272 \begin_layout Standard
40275 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
40278 \begin_layout Standard
40286 \begin_layout Standard
40294 \begin_layout Standard
40302 \begin_layout Standard
40310 \begin_layout Standard
40318 \begin_layout Standard
40324 \begin_layout Standard
40327 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
40330 \begin_layout Standard
40333 ; iTemp21 [lr21:38]{short}[r4]
40336 \begin_layout Standard
40344 \begin_layout Standard
40352 \begin_layout Standard
40360 \begin_layout Standard
40363 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
40366 \begin_layout Standard
40374 \begin_layout Standard
40382 \begin_layout Standard
40390 \begin_layout Standard
40398 \begin_layout Standard
40401 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
40404 \begin_layout Standard
40407 ; iTemp15 [lr29:30]{short}[r1]
40410 \begin_layout Standard
40418 \begin_layout Standard
40426 \begin_layout Standard
40429 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
40432 \begin_layout Standard
40440 \begin_layout Standard
40448 \begin_layout Standard
40456 \begin_layout Standard
40464 \begin_layout Standard
40472 \begin_layout Standard
40480 \begin_layout Standard
40483 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
40486 \begin_layout Standard
40494 \begin_layout Standard
40502 \begin_layout Standard
40510 \begin_layout Standard
40518 \begin_layout Standard
40526 \begin_layout Standard
40534 \begin_layout Standard
40537 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
40540 \begin_layout Standard
40548 \begin_layout Standard
40551 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
40554 \begin_layout Standard
40562 \begin_layout Standard
40567 cjne r5,#0xff,00104$
40570 \begin_layout Standard
40578 \begin_layout Standard
40581 ; goto _forcond_0($4)
40584 \begin_layout Standard
40592 \begin_layout Standard
40595 ; _forbreak_0($7) :
40598 \begin_layout Standard
40604 \begin_layout Standard
40607 ; ret iTemp24 [lr40:41]{short}
40610 \begin_layout Standard
40618 \begin_layout Standard
40626 \begin_layout Standard
40634 \begin_layout Standard
40640 \begin_layout Standard
40646 \begin_layout Standard
40656 \begin_layout Section
40657 A few words about basic block successors, predecessors and dominators
40660 \begin_layout Standard
40661 Successors are basic blocks
40662 \begin_inset LatexCommand \index{Basic blocks}
40666 that might execute after this basic block.
40668 Predecessors are basic blocks
40669 that might execute before reaching this basic block.
40671 Dominators are basic
40672 blocks that WILL execute before reaching this basic block.
40677 \begin_layout Standard
40681 \begin_layout Standard
40685 \begin_layout Standard
40693 \begin_layout Standard
40697 \begin_layout Standard
40705 \begin_layout Standard
40711 \begin_layout Standard
40712 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
40715 \begin_layout Standard
40716 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
40719 \begin_layout Standard
40720 c) domVect of [BB4] = BB1 ...
40721 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
40725 \begin_layout Chapter
40729 \begin_layout Standard
40730 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/#Who}
40740 Thanks to all the other volunteer developers who have helped with coding,
40741 testing, web-page creation, distribution sets, etc.
40742 You know who you are :-)
40750 Thanks to Sourceforge
40751 \begin_inset LatexCommand \url{http://www.sf.net}
40755 which has hosted the project since 1999 and donates significant download
40764 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
40765 cycles and bandwidth for snapshot builds.
40770 \begin_layout Standard
40771 This document was initially written by Sandeep Dutta
40774 \begin_layout Standard
40775 All product names mentioned herein may be trademarks
40776 \begin_inset LatexCommand \index{Trademarks}
40780 of their respective companies.
40784 \begin_layout Section*
40788 \begin_layout Standard
40789 To avoid confusion, the installation and building options for SDCC itself
40790 (chapter 2) are not part of the index.
40793 \begin_layout Standard
40794 \begin_inset LatexCommand \printindex{}