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.
962 will push a as two ints if
968 \begin_layout Standard
978 \begin_inset LatexCommand \index{-\/-std-c89}
990 \begin_layout Standard
1000 \begin_inset LatexCommand \index{-\/-std-c99}
1006 command line option is defined.
1009 \begin_layout Itemize
1014 \begin_layout Standard
1023 -regextend has been removed.
1026 \begin_layout Itemize
1031 \begin_layout Standard
1040 -noregparms has been removed.
1043 \begin_layout Itemize
1048 \begin_layout Standard
1057 -stack-after-data has been removed.
1060 \begin_layout Itemize
1062 \begin_inset LatexCommand \index{bit}
1067 \begin_inset LatexCommand \index{sbit}
1072 \begin_inset LatexCommand \index{\_\_sbit}
1076 types now consistently behave like the C99 _Bool type with respect to type
1078 \begin_inset LatexCommand \index{type conversion}
1083 \begin_inset LatexCommand \index{type promotion}
1088 The most common incompatibility resulting from this change is related to
1090 \begin_inset LatexCommand \index{Bit toggling}
1105 \begin_inset LatexCommand \index{\~\/ Operator}
1109 b; /* equivalent to b=1 instead of toggling b */
1110 \begin_inset Marginal
1113 \begin_layout Standard
1126 b = !b; /* toggles b */
1130 In previous versions, both forms would have toggled the bit.
1133 \begin_layout Standard
1136 <pending: more incompatibilities?>
1139 \begin_layout Section
1143 \begin_layout Standard
1144 What do you need before you start installation of SDCC? A computer, and
1145 a desire to compute.
1146 The preferred method of installation is to compile SDCC from source using
1148 For Windows some pre-compiled binary distributions are available for your
1150 You should have some experience with command line tools and compiler use.
1153 \begin_layout Section
1157 \begin_layout Standard
1158 The SDCC home page at
1159 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1163 is a great place to find distribution sets.
1164 You can also find links to the user mailing lists that offer help or discuss
1165 SDCC with other SDCC users.
1166 Web links to other SDCC related sites can also be found here.
1167 This document can be found in the DOC directory of the source package as
1168 a text or HTML file.
1169 A pdf version of this document is available at
1170 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1175 Some of the other tools (simulator and assembler) included with SDCC contain
1176 their own documentation and can be found in the source distribution.
1177 If you want the latest unreleased software, the complete source package
1178 is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1182 \begin_layout Section
1183 Wishes for the future
1186 \begin_layout Standard
1187 There are (and always will be) some things that could be done.
1188 Here are some I can think of:
1193 \begin_layout Standard
1196 char KernelFunction3(char p) at 0x340;
1201 \begin_layout Standard
1205 \begin_inset LatexCommand \index{code banking (limited support)}
1215 If you can think of some more, please see the section
1216 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1220 about filing feature requests
1221 \begin_inset LatexCommand \index{Requesting features}
1226 \begin_inset LatexCommand \index{Feature request}
1235 \begin_layout Chapter
1237 \begin_inset LatexCommand \index{Installation}
1244 \begin_layout Standard
1245 For most users it is sufficient to skip to either section
1246 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1251 \begin_inset LatexCommand \ref{sub:Windows-Install}
1256 More detailed instructions follow below.
1259 \begin_layout Section
1261 \begin_inset LatexCommand \index{Options SDCC configuration}
1268 \begin_layout Standard
1269 The install paths, search paths and other options are defined when running
1271 The defaults can be overridden by:
1275 \labelwidthstring 00.00.0000
1280 \begin_layout Standard
1289 -prefix see table below
1293 \labelwidthstring 00.00.0000
1298 \begin_layout Standard
1307 -exec_prefix see table below
1311 \labelwidthstring 00.00.0000
1316 \begin_layout Standard
1325 -bindir see table below
1329 \labelwidthstring 00.00.0000
1334 \begin_layout Standard
1343 -datadir see table below
1347 \labelwidthstring 00.00.0000
1352 \begin_layout Standard
1361 -datarootdir see table below
1367 \labelwidthstring 00.00.0000
1370 docdir environment variable, see table below
1374 \labelwidthstring 00.00.0000
1377 include_dir_suffix environment variable, see table below
1381 \labelwidthstring 00.00.0000
1384 lib_dir_suffix environment variable, see table below
1388 \labelwidthstring 00.00.0000
1391 sdccconf_h_dir_separator environment variable, either / or
1396 This character will only be used in sdccconf.h; don't forget it's a C-header,
1397 therefore a double-backslash is needed there.
1403 \labelwidthstring 00.00.0000
1408 \begin_layout Standard
1417 -disable-mcs51-port Excludes the Intel mcs51 port
1421 \labelwidthstring 00.00.0000
1426 \begin_layout Standard
1435 -disable-gbz80-port Excludes the Gameboy gbz80 port
1439 \labelwidthstring 00.00.0000
1444 \begin_layout Standard
1453 -disable-z80-port Excludes the z80 port
1457 \labelwidthstring 00.00.0000
1462 \begin_layout Standard
1471 -disable-avr-port Excludes the AVR port
1475 \labelwidthstring 00.00.0000
1480 \begin_layout Standard
1489 -disable-ds390-port Excludes the DS390 port
1493 \labelwidthstring 00.00.0000
1498 \begin_layout Standard
1507 -disable-hc08-port Excludes the HC08 port
1511 \labelwidthstring 00.00.0000
1516 \begin_layout Standard
1525 -disable-pic-port Excludes the PIC14 port
1529 \labelwidthstring 00.00.0000
1534 \begin_layout Standard
1543 -disable-pic16-port Excludes the PIC16 port
1547 \labelwidthstring 00.00.0000
1552 \begin_layout Standard
1561 -disable-xa51-port Excludes the XA51 port
1565 \labelwidthstring 00.00.0000
1570 \begin_layout Standard
1579 -disable-ucsim Disables configuring and building of ucsim
1583 \labelwidthstring 00.00.0000
1588 \begin_layout Standard
1597 -disable-device-lib Disables automatically building device libraries
1601 \labelwidthstring 00.00.0000
1606 \begin_layout Standard
1615 -disable-packihx Disables building packihx
1621 \labelwidthstring 00.00.0000
1626 \begin_layout Standard
1635 -enable-doc Build pdf, html and txt files from the lyx sources
1639 \labelwidthstring 00.00.0000
1644 \begin_layout Standard
1653 -enable-libgc Use the Bohem memory allocator.
1654 Lower runtime footprint.
1657 \begin_layout Standard
1658 Furthermore the environment variables CC, CFLAGS, ...
1659 the tools and their arguments can be influenced.
1660 Please see `configure -
1664 \begin_layout Standard
1673 -help' and the man/info pages of `configure' for details.
1678 standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1679 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1680 SDCC_LIB_NAME are defined by `configure' too.
1681 At the moment it's not possible to change the default settings (it was
1682 simply never required).
1686 These configure options are compiled into the binaries,
1687 and can only be changed by rerunning 'configure' and recompiling SDCC.
1688 The configure options are written in
1692 to distinguish them from run time environment variables (see section search
1698 \begin_inset Quotes sld
1702 \begin_inset Quotes srd
1705 are used by the SDCC team to build the official Win32 binaries.
1706 The SDCC team uses Mingw32 to build the official Windows binaries, because
1710 \begin_layout Enumerate
1714 \begin_layout Enumerate
1715 a gcc compiler and last but not least
1718 \begin_layout Enumerate
1719 the binaries can be built by cross compiling on SDCC Distributed Compile
1723 \begin_layout Standard
1724 See the examples, how to pass the Win32 settings to 'configure'.
1725 The other Win32 builds using Borland, VC or whatever don't use 'configure',
1726 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1736 \begin_layout Standard
1738 \begin_inset Tabular
1739 <lyxtabular version="3" rows="9" columns="3">
1741 <column alignment="block" valignment="top" leftline="true" width="0in">
1742 <column alignment="block" valignment="top" leftline="true" width="0in">
1743 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1744 <row topline="true" bottomline="true">
1745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1748 \begin_layout Standard
1754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1757 \begin_layout Standard
1763 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1766 \begin_layout Standard
1773 <row topline="true">
1774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1777 \begin_layout Standard
1785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1788 \begin_layout Standard
1794 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1797 \begin_layout Standard
1806 <row topline="true">
1807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1810 \begin_layout Standard
1818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1821 \begin_layout Standard
1829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1832 \begin_layout Standard
1841 <row topline="true">
1842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1845 \begin_layout Standard
1853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1856 \begin_layout Standard
1866 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1869 \begin_layout Standard
1882 <row topline="true">
1883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1886 \begin_layout Standard
1894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1897 \begin_layout Standard
1905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1908 \begin_layout Standard
1917 <row topline="true">
1918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1921 \begin_layout Standard
1929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1932 \begin_layout Standard
1942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1945 \begin_layout Standard
1954 <row topline="true">
1955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1958 \begin_layout Standard
1966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1969 \begin_layout Standard
1979 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1982 \begin_layout Standard
1995 <row topline="true">
1996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1999 \begin_layout Standard
2007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2010 \begin_layout Standard
2016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2019 \begin_layout Standard
2026 <row topline="true" bottomline="true">
2027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2030 \begin_layout Standard
2038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2041 \begin_layout Standard
2047 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2050 \begin_layout Standard
2066 \begin_layout Standard
2068 'configure' also computes relative paths.
2069 This is needed for full relocatability of a binary package and to complete
2070 search paths (see section search paths below):
2075 \begin_layout Standard
2077 \begin_inset Tabular
2078 <lyxtabular version="3" rows="4" columns="3">
2080 <column alignment="block" valignment="top" leftline="true" width="0in">
2081 <column alignment="block" valignment="top" leftline="true" width="0in">
2082 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2083 <row topline="true" bottomline="true">
2084 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2087 \begin_layout Standard
2093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2096 \begin_layout Standard
2102 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2105 \begin_layout Standard
2112 <row topline="true" bottomline="true">
2113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2116 \begin_layout Standard
2124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2127 \begin_layout Standard
2133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2136 \begin_layout Standard
2143 <row bottomline="true">
2144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2147 \begin_layout Standard
2155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2158 \begin_layout Standard
2164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2167 \begin_layout Standard
2174 <row bottomline="true">
2175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2178 \begin_layout Standard
2186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2189 \begin_layout Standard
2195 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2198 \begin_layout Standard
2214 \begin_layout Standard
2219 \begin_layout LyX-Code
2226 \begin_layout Standard
2236 \begin_inset Quotes srd
2240 \begin_inset Quotes srd
2247 \begin_layout Standard
2257 \begin_inset Quotes srd
2261 \begin_inset Quotes srd
2270 \begin_layout Standard
2283 \begin_layout Standard
2295 \begin_layout Standard
2296 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2300 \begin_layout LyX-Code
2306 \begin_inset Quotes srd
2309 i586-mingw32msvc-gcc
2310 \begin_inset Quotes srd
2314 \begin_inset Quotes srd
2317 i586-mingw32msvc-g++
2318 \begin_inset Quotes srd
2326 \begin_inset Quotes srd
2329 i586-mingw32msvc-ranlib
2330 \begin_inset Quotes srd
2338 \begin_inset Quotes srd
2341 i586-mingw32msvc-strip
2342 \begin_inset Quotes srd
2353 \begin_layout Standard
2363 \begin_inset Quotes srd
2367 \begin_inset Quotes srd
2378 \begin_layout Standard
2388 \begin_inset Quotes srd
2392 \begin_inset Quotes srd
2400 \begin_inset Quotes srd
2406 \begin_inset Quotes srd
2414 \begin_inset Quotes srd
2418 \begin_inset Quotes srd
2426 \begin_inset Quotes srd
2430 \begin_inset Quotes srd
2437 sdccconf_h_dir_separator=
2438 \begin_inset Quotes srd
2450 \begin_inset Quotes srd
2461 \begin_layout Standard
2478 \begin_layout Standard
2487 -host=i586-mingw32msvc
2495 \begin_layout Standard
2504 -build=unknown-unknown-linux-gnu
2507 \begin_layout Standard
2509 \begin_inset Quotes sld
2513 \begin_inset Quotes srd
2516 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2520 \begin_layout LyX-Code
2529 \begin_layout Standard
2539 \begin_inset Quotes srd
2543 \begin_inset Quotes srd
2554 \begin_layout Standard
2564 \begin_inset Quotes srd
2568 \begin_inset Quotes srd
2576 \begin_inset Quotes srd
2582 \begin_inset Quotes srd
2590 \begin_inset Quotes srd
2594 \begin_inset Quotes srd
2602 \begin_inset Quotes srd
2606 \begin_inset Quotes srd
2613 sdccconf_h_dir_separator=
2614 \begin_inset Quotes srd
2626 \begin_inset Quotes srd
2634 \begin_inset Quotes srd
2638 \begin_inset Quotes srd
2646 \begin_inset Quotes srd
2650 \begin_inset Quotes srd
2656 \begin_layout Standard
2657 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2662 \begin_layout Standard
2671 -C' turns on caching, which gives a little bit extra speed.
2672 However if options are changed, it can be necessary to delete the config.cache
2676 \begin_layout Section
2678 \begin_inset LatexCommand \label{sub:Install-paths}
2683 \begin_inset LatexCommand \index{Install paths}
2690 \begin_layout Standard
2691 \begin_inset VSpace medskip
2697 \begin_layout Standard
2699 \begin_inset Tabular
2700 <lyxtabular version="3" rows="5" columns="4">
2702 <column alignment="left" valignment="top" leftline="true" width="0">
2703 <column alignment="left" valignment="top" leftline="true" width="0">
2704 <column alignment="left" valignment="top" leftline="true" width="0">
2705 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2706 <row topline="true" bottomline="true">
2707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2710 \begin_layout Standard
2718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2721 \begin_layout Standard
2729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2732 \begin_layout Standard
2740 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2743 \begin_layout Standard
2752 <row topline="true">
2753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2756 \begin_layout Standard
2762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2765 \begin_layout Standard
2773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2776 \begin_layout Standard
2782 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2785 \begin_layout Standard
2796 <row topline="true">
2797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2800 \begin_layout Standard
2806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2809 \begin_layout Standard
2812 $DATADIR/ $INCLUDE_DIR_SUFFIX
2817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2820 \begin_layout Standard
2821 /usr/local/share/sdcc/include
2826 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2829 \begin_layout Standard
2840 <row topline="true">
2841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2844 \begin_layout Standard
2850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2853 \begin_layout Standard
2856 $DATADIR/$LIB_DIR_SUFFIX
2861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2864 \begin_layout Standard
2865 /usr/local/share/sdcc/lib
2870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2873 \begin_layout Standard
2884 <row topline="true" bottomline="true">
2885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2888 \begin_layout Standard
2894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2897 \begin_layout Standard
2905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2908 \begin_layout Standard
2909 /usr/local/share/sdcc/doc
2914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2917 \begin_layout Standard
2938 *compiler, preprocessor, assembler, and linker
2944 is auto-appended by the compiler, e.g.
2945 small, large, z80, ds390 etc
2948 \begin_layout Standard
2950 The install paths can still be changed during `make install' with e.g.:
2953 \begin_layout LyX-Code
2954 make install prefix=$(HOME)/local/sdcc
2957 \begin_layout Standard
2958 Of course this doesn't change the search paths compiled into the binaries.
2963 r the install path can be changed by defining DESTDIR
2964 \begin_inset LatexCommand \index{DESTDIR}
2971 \begin_layout LyX-Code
2972 make install DESTDIR=$(HOME)/sdcc.rpm/
2975 \begin_layout Standard
2976 Please note that DESTDIR must have a trailing slash!
2979 \begin_layout Section
2981 \begin_inset LatexCommand \label{sub:Search-Paths}
2986 \begin_inset LatexCommand \index{Search path}
2993 \begin_layout Standard
2994 Some search paths or parts of them are determined by configure variables
2999 , see section above).
3000 Further search paths are determined by environment variables during runtime.
3003 The paths searched when running the compiler are as follows (the first
3009 Binary files (preprocessor, assembler and linker)
3014 \begin_layout Standard
3016 \begin_inset Tabular
3017 <lyxtabular version="3" rows="4" columns="3">
3019 <column alignment="block" valignment="top" leftline="true" width="0in">
3020 <column alignment="block" valignment="top" leftline="true" width="0in">
3021 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3022 <row topline="true" bottomline="true">
3023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3026 \begin_layout Standard
3032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3035 \begin_layout Standard
3041 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3044 \begin_layout Standard
3051 <row topline="true">
3052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3055 \begin_layout Standard
3063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3066 \begin_layout Standard
3072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3075 \begin_layout Standard
3084 <row topline="true">
3085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3088 \begin_layout Standard
3089 Path of argv[0] (if available)
3094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3097 \begin_layout Standard
3103 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3106 \begin_layout Standard
3113 <row topline="true" bottomline="true">
3114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3117 \begin_layout Standard
3123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3126 \begin_layout Standard
3132 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3135 \begin_layout Standard
3151 \begin_layout Standard
3159 \begin_layout Standard
3161 \begin_inset Tabular
3162 <lyxtabular version="3" rows="6" columns="3">
3164 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3165 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3166 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3167 <row topline="true" bottomline="true">
3168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3171 \begin_layout Standard
3177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3180 \begin_layout Standard
3186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3189 \begin_layout Standard
3196 <row topline="true">
3197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3200 \begin_layout Standard
3205 \begin_layout Standard
3219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3222 \begin_layout Standard
3227 \begin_layout Standard
3241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3244 \begin_layout Standard
3249 \begin_layout Standard
3264 <row topline="true">
3265 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3268 \begin_layout Standard
3274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3277 \begin_layout Standard
3283 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3286 \begin_layout Standard
3293 <row topline="true">
3294 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3297 \begin_layout Standard
3309 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3312 \begin_layout Standard
3322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3325 \begin_layout Standard
3334 <row topline="true">
3335 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3338 \begin_layout Standard
3354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3357 \begin_layout Standard
3405 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3408 \begin_layout Standard
3419 <row topline="true" bottomline="true">
3420 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3423 \begin_layout Standard
3437 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3440 \begin_layout Standard
3441 /usr/local/share/sdcc/
3448 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3451 \begin_layout Standard
3467 \begin_layout Standard
3473 \begin_layout Standard
3482 -nostdinc disables the last two search paths.
3492 \begin_layout Standard
3493 With the exception of
3494 \begin_inset Quotes sld
3501 \begin_layout Standard
3511 \begin_inset Quotes srd
3518 is auto-appended by the compiler (e.g.
3519 small, large, z80, ds390 etc.).
3525 \begin_layout Standard
3527 \begin_inset Tabular
3528 <lyxtabular version="3" rows="6" columns="3">
3530 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3531 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3532 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3533 <row topline="true" bottomline="true">
3534 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3537 \begin_layout Standard
3543 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3546 \begin_layout Standard
3552 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3555 \begin_layout Standard
3562 <row topline="true">
3563 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3566 \begin_layout Standard
3571 \begin_layout Standard
3585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3588 \begin_layout Standard
3593 \begin_layout Standard
3607 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3610 \begin_layout Standard
3615 \begin_layout Standard
3630 <row topline="true">
3631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3634 \begin_layout Standard
3644 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3647 \begin_layout Standard
3657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3660 \begin_layout Standard
3673 <row topline="true">
3674 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3677 \begin_layout Standard
3684 $LIB_DIR_SUFFIX/<model>
3689 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3692 \begin_layout Standard
3704 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3707 \begin_layout Standard
3722 <row topline="true">
3723 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3726 \begin_layout Standard
3737 $LIB_DIR_SUFFIX/<model>
3742 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3745 \begin_layout Standard
3796 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3799 \begin_layout Standard
3853 <row topline="true" bottomline="true">
3854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3857 \begin_layout Standard
3862 $LIB_DIR_SUFFIX/<model>
3867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3870 \begin_layout Standard
3871 /usr/local/share/sdcc/
3880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3883 \begin_layout Standard
3899 \begin_layout Standard
3900 \begin_inset Note Note
3903 \begin_layout Standard
3904 Don't delete any of the stray spaces in the table above without checking
3905 the HTML output (last line)!
3913 \begin_layout Standard
3921 \begin_layout Standard
3930 -nostdlib disables the last two search paths.
3933 \begin_layout Section
3935 \begin_inset LatexCommand \index{Building SDCC}
3942 \begin_layout Subsection
3943 Building SDCC on Linux
3944 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3951 \begin_layout Enumerate
3954 Download the source package
3956 either from the SDCC Subversion repository or from snapshot builds
3958 , it will be named something like sdcc
3969 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3976 \begin_layout Enumerate
3979 Bring up a command line terminal, such as xterm.
3982 \begin_layout Enumerate
3985 Unpack the file using a command like:
3988 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
3989 \begin_inset Quotes srd
3995 , this will create a sub-directory called sdcc with all of the sources.
3998 \begin_layout Enumerate
3999 Change directory into the main SDCC directory, for example type:
4007 \begin_layout Enumerate
4017 This configures the package for compilation on your system.
4020 \begin_layout Enumerate
4034 All of the source packages will compile, this can take a while.
4037 \begin_layout Enumerate
4051 This copies the binary executables, the include files, the libraries and
4052 the documentation to the install directories.
4053 Proceed with section
4054 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
4061 \begin_layout Subsection
4062 Building SDCC on Mac OS X
4065 \begin_layout Standard
4066 Follow the instruction for Linux.
4070 On Mac OS X 10.2.x it was reported, that the
4071 default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
4072 Fortunately there's also gcc 2.9.x installed, which works fine.
4073 This compiler can be selected by running 'configure' with:
4076 \begin_layout LyX-Code
4077 ./configure CC=gcc2 CXX=g++2
4080 \begin_layout Standard
4081 Universal (ppc and i386) binaries can be produced on Mac OS X 10.4.x with
4083 Run 'configure' with:
4086 \begin_layout LyX-Code
4092 \begin_layout LyX-Code
4093 LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4099 \begin_layout LyX-Code
4100 CXXFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4106 \begin_layout LyX-Code
4107 CFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
4110 \begin_layout Subsection
4111 Cross compiling SDCC on Linux for Windows
4114 \begin_layout Standard
4115 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
4116 See section 'Configure Options'.
4119 \begin_layout Subsection
4120 Building SDCC using Cygwin and Mingw32
4123 \begin_layout Standard
4124 For building and installing a Cygwin executable follow the instructions
4130 \begin_inset Quotes sld
4134 \begin_inset Quotes srd
4137 Win32-binary can be built, which will not need the Cygwin-DLL.
4138 For the necessary 'configure' options see section 'configure options' or
4139 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4144 Cygwin on Windows download setup.exe from
4145 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
4151 \begin_inset Quotes sld
4154 default text file type
4155 \begin_inset Quotes srd
4159 \begin_inset Quotes sld
4163 \begin_inset Quotes srd
4166 and download/install at least the following packages.
4167 Some packages are selected by default, others will be automatically selected
4168 because of dependencies with the manually selected packages.
4169 Never deselect these packages!
4172 \begin_layout Itemize
4176 \begin_layout Itemize
4180 \begin_layout Itemize
4181 gcc ; version 3.x is fine, no need to use the old 2.9x
4184 \begin_layout Itemize
4185 binutils ; selected with gcc
4188 \begin_layout Itemize
4192 \begin_layout Itemize
4193 rxvt ; a nice console, which makes life much easier under windoze (see below)
4196 \begin_layout Itemize
4197 man ; not really needed for building SDCC, but you'll miss it sooner or
4201 \begin_layout Itemize
4202 less ; not really needed for building SDCC, but you'll miss it sooner or
4206 \begin_layout Itemize
4207 svn ; only if you use Subversion access
4210 \begin_layout Standard
4211 If you want to develop something you'll need:
4214 \begin_layout Itemize
4215 python ; for the regression tests
4218 \begin_layout Itemize
4219 gdb ; the gnu debugger, together with the nice GUI
4220 \begin_inset Quotes sld
4224 \begin_inset Quotes srd
4230 \begin_layout Itemize
4231 openssh ; to access the CF or commit changes
4234 \begin_layout Itemize
4235 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4236 use autoconf-stable!
4239 \begin_layout Standard
4240 rxvt is a nice console with history.
4241 Replace in your cygwin.bat the line
4244 \begin_layout LyX-Code
4249 \begin_layout Standard
4261 \begin_layout Standard
4265 \begin_layout LyX-Code
4266 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4269 \begin_layout LyX-Code
4270 -bg black -fg white -geometry 100x65 -e bash -
4274 \begin_layout Standard
4286 \begin_layout Standard
4287 Text selected with the mouse is automatically copied to the clipboard, pasting
4288 works with shift-insert.
4292 The other good tip is to make sure you have no //c/-styl
4293 e paths anywhere, use /cygdrive/c/ instead.
4294 Using // invokes a network lookup which is very slow.
4296 \begin_inset Quotes sld
4300 \begin_inset Quotes srd
4303 is too long, you can change it with e.g.
4306 \begin_layout LyX-Code
4310 \begin_layout Standard
4311 SDCC sources use the unix line ending LF.
4312 Life is much easier, if you store the source tree on a drive which is mounted
4314 And use an editor which can handle LF-only line endings.
4315 Make sure not to commit files with windows line endings.
4316 The tabulator spacing
4317 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4321 used in the project is 8.
4322 Although a tabulator spacing of 8 is a sensible choice for programmers
4323 (it's a power of 2 and allows to display 8/16 bit signed variables without
4324 loosing columns) the plan is to move towards using only spaces in the source.
4327 \begin_layout Subsection
4328 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4331 \begin_layout Standard
4334 Download the source package
4336 either from the SDCC Subversion repository or from the
4337 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4343 , it will be named something like sdcc
4347 -yyyymmdd-rrrr.tar.bz2.
4350 SDCC is distributed with all the projects, workspaces, and files you need
4351 to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4352 The workspace name is 'sdcc.dsw'.
4353 Please note that as it is now, all the executables are created in a folder
4357 Once built you need to copy the executables from sdcc
4361 bin before running SDCC.
4366 WARNING: Visual studio is very picky with line terminations; it expects
4367 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4368 When using the Subversion repository it's easiest to configure the svn
4369 client to convert automatically for you.
4370 If however you are getting a message such as "This makefile was not generated
4371 by Developer Studio etc.
4373 \begin_inset Quotes srd
4376 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4377 need to convert the Unix style line endings to DOS style line endings.
4378 To do so you can use the
4379 \begin_inset Quotes sld
4383 \begin_inset Quotes srd
4386 utility freely available on the internet.
4387 Doug Hawkins reported in the sdcc-user list that this works:
4395 SDCC> unix2dos sdcc.dsw
4401 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4405 In order to build SDCC with MSVC
4406 you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4407 One good place to get them is
4408 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4416 Download the file UnxUtils
4417 \begin_inset LatexCommand \index{UnxUtils}
4422 Now you have to install the utilities and setup MSVC so it can locate the
4424 Here there are two alternatives (choose one!):
4427 \begin_layout Enumerate
4432 a) Extract UnxUtils.zip to your C:
4434 hard disk PRESERVING the original paths, otherwise bison won't work.
4435 (If you are using WinZip make certain that 'Use folder names' is selected)
4440 In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4441 'Show directories for:' select 'Executable files', and in the directories
4442 window add a new path: 'C:
4452 (As a side effect, you get a bunch of Unix utilities that
4453 could be useful, such as diff and patch.)
4456 \begin_layout Enumerate
4461 This one avoids extracting a bunch of files you may not
4462 use, but requires some extra work:
4466 a) Create a directory were to put the
4467 tools needed, or use a directory already present.
4474 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4475 gawk.exe to such directory WITHOUT preserving the original paths.
4476 (If you are using WinZip make certain that 'Use folder names' is not selected)
4481 ) Rename bison.exe to '_bison.exe'.
4485 d) Create a batch file 'bison.bat' in 'C:
4489 ' and add these lines:
4509 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4513 Steps 'c' and 'd' are needed
4514 because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4515 reside in some weird Unix directory, '/usr/local/share/' I think.
4516 So it is necessary to tell bison where those files are located if they
4517 are not in such directory.
4518 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4523 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4524 in 'Show directories for:' select 'Executable files', and in the directories
4525 window add a new path: 'c:
4528 Note that you can use any other path instead of 'c:
4530 util', even the path where the Visual C++ tools are, probably: 'C:
4534 Microsoft Visual Studio
4539 So you don't have to execute step 'e' :)
4542 \begin_layout Standard
4544 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4545 the executables from sdcc
4549 bin, and you can compile using SDCC.
4552 \begin_layout Subsection
4553 Building SDCC Using Borland
4556 \begin_layout Enumerate
4557 From the sdcc directory, run the command "make -f Makefile.bcc".
4558 This should regenerate all the .exe files in the bin directory except for
4562 \begin_layout Enumerate
4563 If you modify any source files and need to rebuild, be aware that the dependenci
4564 es may not be correctly calculated.
4565 The safest option is to delete all .obj files and run the build again.
4566 From a Cygwin BASH prompt, this can easily be done with the command (be
4567 sure you are in the sdcc directory):
4577 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
4579 ) -print -exec rm {}
4588 or on Windows NT/2000/XP from the command prompt with the command:
4595 del /s *.obj *.lib *.rul
4598 from the sdcc directory.
4601 \begin_layout Subsection
4602 Windows Install Using a ZIP Package
4605 \begin_layout Enumerate
4606 Download the binary zip package from
4607 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4611 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4612 This should unpack to a group of sub-directories.
4613 An example directory structure after unpacking the mingw32 package is:
4618 bin for the executables, c:
4626 lib for the include and libraries.
4629 \begin_layout Enumerate
4630 Adjust your environment variable PATH to include the location of the bin
4631 directory or start sdcc using the full path.
4634 \begin_layout Subsection
4635 Windows Install Using the Setup Program
4636 \begin_inset LatexCommand \label{sub:Windows-Install}
4643 \begin_layout Standard
4644 Download the setup program
4646 sdcc-x.y.z-setup.exe
4648 for an official release from
4651 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4655 or a setup program for one of the snapshots
4657 sdcc-yyyymmdd-xxxx-setup.exe
4660 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4665 A windows typical installer will guide you through the installation process.
4668 \begin_layout Subsection
4670 \begin_inset LatexCommand \index{VPATH}
4677 \begin_layout Standard
4678 SDCC supports the VPATH feature provided by configure and make.
4679 It allows to separate the source and build trees.
4683 \begin_layout Standard
4710 \begin_layout Standard
4713 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4714 # extract source to directory sdcc
4717 \begin_layout Standard
4720 mkdir sdcc.build\InsetSpace ~
4729 # put output in sdcc.build
4732 \begin_layout Standard
4738 \begin_layout Standard
4741 ../sdcc/configure\InsetSpace ~
4749 # configure is doing all the magic!
4752 \begin_layout Standard
4758 \begin_layout Standard
4764 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4765 It automagically computes the variables srcdir, top_srcdir and top_buildir
4771 the generated files will be in ~/sdcc.build, while the source files stay
4774 This is not only usefull for building different binaries, e.g.
4775 when cross compiling.
4776 It also gives you a much better overview in the source tree when all the
4777 generated files are not scattered between the source files.
4778 And the best thing is: if you want to change a file you can leave the original
4779 file untouched in the source directory.
4780 Simply copy it to the build directory, edit it, enter `make clean', `rm
4781 Makefile.dep' and `make'.
4786 will do the rest for you!
4789 \begin_layout Section
4790 Building the Documentation
4793 \begin_layout Standard
4798 \begin_layout Standard
4807 -enable-doc to the configure arguments to build the documentation together
4808 with all the other stuff.
4809 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4810 dvips and makeindex) to get the job done.
4811 Another possibility is to change to the doc directory and to type
4815 \begin_inset Quotes srd
4819 \begin_inset Quotes srd
4826 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4829 \begin_inset LatexCommand \url{http://www.lyx.org}
4833 as editor is straightforward.
4834 Prebuilt documentation in html and pdf format is available from
4835 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4842 \begin_layout Section
4843 Reading the Documentation
4844 \begin_inset LatexCommand \index{Documentation}
4851 \begin_layout Standard
4852 Currently reading the document in pdf format is recommended, as for unknown
4853 reason the hyperlinks are working there whereas in the html version they
4858 \begin_layout Standard
4859 If you should know why please drop us a note
4867 You'll find the pdf version
4868 \begin_inset LatexCommand \index{PDF version of this document}
4873 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4881 \begin_inset LatexCommand \index{HTML version of this document}
4886 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4892 This documentation is in some aspects different from a commercial documentation:
4896 \begin_layout Itemize
4897 It tries to document SDCC for several processor architectures in one document
4898 (commercially these probably would be separate documents/products).
4900 \begin_inset LatexCommand \index{Status of documentation}
4904 currently matches SDCC for mcs51 and DS390 best and does give too few informati
4906 Z80, PIC14, PIC16 and HC08.
4909 \begin_layout Itemize
4910 There are many references pointing away from this documentation.
4911 Don't let this distract you.
4913 was a reference like
4914 \begin_inset LatexCommand \url{http://www.opencores.org}
4918 together with a statement
4919 \begin_inset Quotes sld
4922 some processors which are targetted by SDCC can be implemented in a
4939 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4944 \begin_inset Quotes srd
4948 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4953 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4958 \begin_inset Quotes sld
4961 have you ever heard of an open source compiler that compiles a subset of
4963 \begin_inset Quotes srd
4966 we expect you to have a quick look there and come back.
4967 If you read this you are on the right track.
4970 \begin_layout Itemize
4971 Some sections attribute more space to problems, restrictions and warnings
4972 than to the solution.
4975 \begin_layout Itemize
4976 The installation section and the section about the debugger is intimidating.
4979 \begin_layout Itemize
4980 There are still lots of typos and there are more different writing styles
4984 \begin_layout Section
4985 Testing the SDCC Compiler
4986 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4993 \begin_layout Standard
4994 The first thing you should do after installing your SDCC compiler is to
5003 \begin_layout Standard
5013 \begin_inset LatexCommand \index{version}
5020 at the prompt, and the program should run and output its version like:
5025 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
5029 \begin_layout Standard
5030 If it doesn't run, or gives a message about not finding sdcc program, then
5031 you need to check over your installation.
5032 Make sure that the sdcc bin directory is in your executable search path
5033 defined by the PATH environment setting (
5038 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5045 Install trouble-shooting for suggestions
5048 Make sure that the sdcc program is in the bin folder, if not perhaps something
5049 did not install correctly.
5057 is commonly installed as described in section
5058 \begin_inset Quotes sld
5061 Install and search paths
5062 \begin_inset Quotes srd
5071 Make sure the compiler works on a very simple example.
5072 Type in the following test.c program using your favorite
5097 \begin_layout Standard
5100 Compile this using the following command:
5109 If all goes well, the compiler will generate a test.asm and test.rel file.
5110 Congratulations, you've just compiled your first program with SDCC.
5111 We used the -c option to tell SDCC not to link the generated code, just
5112 to keep things simple for this step.
5120 The next step is to try it with the linker.
5130 If all goes well the compiler will link with the libraries and produce
5131 a test.ihx output file.
5136 (no test.ihx, and the linker generates warnings), then the problem is most
5145 usr/local/share/sdcc/lib directory
5152 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5159 Install trouble-shooting for suggestions).
5167 The final test is to ensure
5175 header files and libraries.
5176 Edit test.c and change it to the following:
5194 strcpy(str1, "testing");
5199 \begin_layout Standard
5202 Compile this by typing
5209 This should generate a test.ihx output file, and it should give no warnings
5210 such as not finding the string.h file.
5211 If it cannot find the string.h file, then the problem is that
5215 cannot find the /usr/local/share/sdcc/include directory
5222 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5229 Install trouble-shooting section for suggestions).
5238 \begin_layout Standard
5250 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5254 to find exactly where SDCC is looking for the include and lib files.
5257 \begin_layout Section
5258 Install Trouble-shooting
5259 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5264 \begin_inset LatexCommand \index{Install trouble-shooting}
5271 \begin_layout Subsection
5272 If SDCC does not build correctly
5275 \begin_layout Standard
5276 A thing to try is starting from scratch by unpacking the .tgz source package
5277 again in an empty directory.
5285 ./configure 2>&1 | tee configure.log
5299 make 2>&1 | tee make.log
5306 If anything goes wrong, you can review the log files to locate the problem.
5307 Or a relevant part of this can be attached to an email that could be helpful
5308 when requesting help from the mailing list.
5311 \begin_layout Subsection
5313 \begin_inset Quotes sld
5317 \begin_inset Quotes srd
5323 \begin_layout Standard
5325 \begin_inset Quotes sld
5329 \begin_inset Quotes srd
5332 command is a script that analyzes your system and performs some configuration
5333 to ensure the source package compiles on your system.
5334 It will take a few minutes to run, and will compile a few tests to determine
5335 what compiler features are installed.
5338 \begin_layout Subsection
5340 \begin_inset Quotes sld
5344 \begin_inset Quotes srd
5350 \begin_layout Standard
5351 This runs the GNU make tool, which automatically compiles all the source
5352 packages into the final installed binary executables.
5355 \begin_layout Subsection
5357 \begin_inset Quotes sld
5361 \begin_inset Quotes erd
5367 \begin_layout Standard
5368 This will install the compiler, other executables libraries and include
5369 files into the appropriate directories.
5371 \begin_inset LatexCommand \ref{sub:Install-paths}
5377 \begin_inset LatexCommand \ref{sub:Search-Paths}
5382 about install and search paths.
5384 On most systems you will need super-user privilege
5388 \begin_layout Section
5392 \begin_layout Standard
5393 SDCC is not just a compiler, but a collection of tools by various developers.
5394 These include linkers, assemblers, simulators and other components.
5395 Here is a summary of some of the components.
5396 Note that the included simulator and assembler have separate documentation
5397 which you can find in the source package in their respective directories.
5398 As SDCC grows to include support for other processors, other packages from
5399 various developers are included and may have their own sets of documentation.
5404 might want to look at the files which are installed in <installdir>.
5405 At the time of this writing, we find the following programs for gcc-builds:
5410 In <installdir>/bin:
5413 \begin_layout Itemize
5414 sdcc - The compiler.
5417 \begin_layout Itemize
5418 sdcpp - The C preprocessor.
5421 \begin_layout Itemize
5422 asx8051 - The assembler for 8051 type processors.
5425 \begin_layout Itemize
5430 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5433 \begin_layout Itemize
5434 aslink -The linker for 8051 type processors.
5437 \begin_layout Itemize
5442 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5445 \begin_layout Itemize
5446 s51 - The ucSim 8051 simulator.
5449 \begin_layout Itemize
5450 sdcdb - The source debugger.
5453 \begin_layout Itemize
5454 packihx - A tool to pack (compress) Intel hex files.
5457 \begin_layout Standard
5458 In <installdir>/share/sdcc/include
5461 \begin_layout Itemize
5465 \begin_layout Standard
5466 In <installdir>/share/sdcc/lib
5469 \begin_layout Itemize
5470 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5474 \begin_layout Standard
5475 In <installdir>/share/sdcc/doc
5478 \begin_layout Itemize
5482 \begin_layout Standard
5483 As development for other processors proceeds, this list will expand to include
5484 executables to support processors like AVR, PIC, etc.
5487 \begin_layout Subsection
5491 \begin_layout Standard
5492 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5493 the assembler and linkage editor.
5496 \begin_layout Subsection
5497 sdcpp - The C-Preprocessor
5500 \begin_layout Standard
5502 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5506 is a modified version of the GNU cpp
5507 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5512 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5517 The C preprocessor is used to pull in #include sources, process #ifdef
5518 statements, #defines and so on.
5521 \begin_layout Subsection
5530 - The Assemblers and Linkage Editors
5533 \begin_layout Standard
5534 This is retargettable assembler & linkage editor, it was developed by Alan
5536 John Hartman created the version for 8051, and I (Sandeep) have made some
5537 enhancements and bug fixes for it to work properly with SDCC.
5540 \begin_layout Subsection
5544 \begin_layout Standard
5546 \begin_inset LatexCommand \index{s51}
5550 is a free open source simulator developed by Daniel Drotos.
5551 The simulator is built as part of the build process.
5552 For more information visit Daniel's web site at:
5553 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5558 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5562 \begin_layout Subsection
5563 sdcdb - Source Level Debugger
5566 \begin_layout Standard
5568 \begin_inset LatexCommand \index{SDCDB (debugger)}
5572 is the companion source level debugger.
5573 More about SDCDB in section
5574 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5579 The current version of the debugger uses Daniel's Simulator S51
5580 \begin_inset LatexCommand \index{s51}
5584 , but can be easily changed to use other simulators.
5587 \begin_layout Chapter
5591 \begin_layout Section
5595 \begin_layout Subsection
5596 Single Source File Projects
5599 \begin_layout Standard
5600 For single source file 8051 projects the process is very simple.
5601 Compile your programs with the following command
5604 "sdcc sourcefile.c".
5608 This will compile, assemble and link your source file.
5609 Output files are as follows:
5612 \begin_layout Itemize
5614 \begin_inset LatexCommand \index{<file>.asm}
5619 \begin_inset LatexCommand \index{Assembler source}
5623 file created by the compiler
5626 \begin_layout Itemize
5628 \begin_inset LatexCommand \index{<file>.lst}
5633 \begin_inset LatexCommand \index{Assembler listing}
5637 file created by the Assembler
5640 \begin_layout Itemize
5642 \begin_inset LatexCommand \index{<file>.rst}
5647 \begin_inset LatexCommand \index{Assembler listing}
5651 file updated with linkedit information, created by linkage editor
5654 \begin_layout Itemize
5656 \begin_inset LatexCommand \index{<file>.sym}
5661 \begin_inset LatexCommand \index{Symbol listing}
5665 for the sourcefile, created by the assembler
5668 \begin_layout Itemize
5670 \begin_inset LatexCommand \index{<file>.rel}
5675 \begin_inset LatexCommand \index{<file>.o}
5680 \begin_inset LatexCommand \index{Object file}
5684 created by the assembler, input to Linkage editor
5687 \begin_layout Itemize
5689 \begin_inset LatexCommand \index{<file>.map}
5694 \begin_inset LatexCommand \index{Memory map}
5698 for the load module, created by the Linker
5701 \begin_layout Itemize
5703 \begin_inset LatexCommand \index{<file>.mem}
5707 - A file with a summary of the memory usage
5710 \begin_layout Itemize
5712 \begin_inset LatexCommand \index{<file>.ihx}
5716 - The load module in Intel hex format
5717 \begin_inset LatexCommand \index{Intel hex format}
5721 (you can select the Motorola S19 format
5722 \begin_inset LatexCommand \index{Motorola S19 format}
5730 \begin_layout Standard
5740 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5745 If you need another format you might want to use
5752 \begin_inset LatexCommand \index{objdump (tool)}
5763 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5768 \begin_inset Note Note
5771 \begin_layout Standard
5778 \begin_inset LatexCommand \vref{sub:Postprocessing-the-Intel}
5783 Both formats are documented in the documentation of srecord
5784 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5791 \begin_layout Itemize
5793 \begin_inset LatexCommand \index{<file>.adb}
5797 - An intermediate file containing debug information needed to create the
5802 \begin_layout Standard
5812 \begin_inset LatexCommand \index{-\/-debug}
5819 \begin_layout Itemize
5821 \begin_inset LatexCommand \index{<file>.cdb}
5825 - An optional file (with -
5829 \begin_layout Standard
5838 -debug) containing debug information.
5839 The format is documented in cdbfileformat.pdf
5842 \begin_layout Itemize
5845 \begin_inset LatexCommand \index{<file> (no extension)}
5849 An optional AOMF or AOMF51
5850 \begin_inset LatexCommand \index{AOMF, AOMF51}
5855 \begin_inset LatexCommand \label{OMF file}
5859 file containing debug information (generated with option -
5863 \begin_layout Standard
5889 ormat is a subformat of the OMF51 format and is commonly used by third party
5891 \begin_inset LatexCommand \index{Debugger}
5895 , simulators, emulators).
5898 \begin_layout Itemize
5900 \begin_inset LatexCommand \index{<file>.dump*}
5904 - Dump file to debug the compiler it self (generated with option -
5908 \begin_layout Standard
5917 -dumpall) (see section
5918 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5924 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5930 \begin_inset Quotes sld
5933 Anatomy of the compiler
5934 \begin_inset Quotes srd
5940 \begin_layout Subsection
5941 Postprocessing the Intel Hex
5942 \begin_inset LatexCommand \index{Intel hex format}
5947 \begin_inset LatexCommand \label{sub:Postprocessing-the-Intel}
5954 \begin_layout Standard
5955 In most cases this won't be needed but the Intel Hex file
5956 \begin_inset LatexCommand \index{<file>.ihx}
5960 which is generated by SDCC might include lines of varying length and the
5961 addresses within the file are not guaranteed to be strictly ascending.
5962 If your toolchain or a bootloader does not like this you can use the tool
5968 \begin_inset LatexCommand \index{packihx (tool)}
5972 which is part of the SDCC distribution:
5979 packihx sourcefile.ihx >sourcefile.hex
5986 The separately available
5991 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5995 package additionally allows to set undefined locations to a predefined
5996 value, to insert checksums
5997 \begin_inset LatexCommand \index{checksum}
6001 of various flavours (crc, add, xor) and to perform other manipulations
6002 (convert, split, crop, offset, ...).
6010 srec_cat\InsetSpace ~
6012 sourcefile.ihx -intel\InsetSpace ~
6014 -o sourcefile.hex -intel
6021 An example for a more complex command line
6025 \begin_layout Standard
6026 the command backfills
6027 \begin_inset LatexCommand \index{backfill unused memory}
6031 unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
6033 If the program counter on an mcs51 runs wild the backfill pattern 0x12
6034 will be interpreted as an
6042 (where an emergency routine could sit).
6055 srec_cat\InsetSpace ~
6056 sourcefile.ihx -intel\InsetSpace ~
6058 -fill 0x12 0x0000 0xfffe\InsetSpace ~
6059 -little-endian-checksum-nega
6060 tive 0xfffe 0x02 0x02\InsetSpace ~
6062 -o sourcefile.hex -intel
6071 The srecord package is available at
6072 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
6079 \begin_layout Subsection
6080 Projects with Multiple Source Files
6083 \begin_layout Standard
6084 SDCC can compile only ONE file at a time.
6085 Let us for example assume that you have a project containing the following
6090 foo1.c (contains some functions)
6092 foo2.c (contains some more functions)
6095 n.c (contains more functions and the function main)
6103 The first two files will need to be compiled separately with the commands:
6135 Then compile the source file containing the
6140 \begin_inset LatexCommand \index{Linker}
6144 the files together with the following command:
6152 foomain.c\InsetSpace ~
6153 foo1.rel\InsetSpace ~
6158 \begin_inset LatexCommand \index{<file>.rel}
6170 can be separately compiled as well:
6181 sdcc foomain.rel foo1.rel foo2.rel
6188 The file containing the
6203 file specified in the command line, since the linkage editor processes
6204 file in the order they are presented to it.
6205 The linker is invoked from SDCC using a script file with extension .lnk
6206 \begin_inset LatexCommand \index{<file>.lnk}
6211 You can view this file to troubleshoot linking problems such as those arising
6212 from missing libraries.
6215 \begin_layout Subsection
6216 Projects with Additional Libraries
6217 \begin_inset LatexCommand \index{Libraries}
6224 \begin_layout Standard
6225 Some reusable routines may be compiled into a library, see the documentation
6226 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6230 \begin_inset LatexCommand \index{<file>.lib}
6237 Libraries created in this manner can be included in the command line.
6238 Make sure you include the -L <library-path> option to tell the linker where
6239 to look for these files if they are not in the current directory.
6240 Here is an example, assuming you have the source file
6252 (if that is not the same as your current project):
6259 sdcc foomain.c foolib.lib -L mylib
6270 must be an absolute path name.
6274 The most efficient way to use libraries is
6275 to keep separate modules in separate source files.
6276 The lib file now should name all the modules.rel
6277 \begin_inset LatexCommand \index{<file>.rel}
6282 For an example see the standard library file
6286 in the directory <installdir>/share/lib/small.
6289 \begin_layout Subsection
6290 Using sdcclib to Create and Manage Libraries
6291 \begin_inset LatexCommand \index{sdcclib}
6298 \begin_layout Standard
6299 Alternatively, instead of having a .rel file for each entry on the library
6300 file as described in the preceding section, sdcclib can be used to embed
6301 all the modules belonging to such library in the library file itself.
6302 This results in a larger library file, but it greatly reduces the number
6303 of disk files accessed by the linker.
6304 Additionally, the packed library file contains an index of all include
6305 modules and symbols that significantly speeds up the linking process.
6306 To display a list of options supported by sdcclib type:
6311 \begin_layout Standard
6316 \begin_inset LatexCommand \index{sdcclib}
6327 To create a new library file, start by compiling all the required modules.
6333 \begin_layout Standard
6340 \begin_layout Standard
6347 \begin_layout Standard
6354 \begin_layout Standard
6361 \begin_layout Standard
6370 \begin_layout Standard
6371 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6373 The next step is to add the .rel files to the library file:
6378 \begin_layout Standard
6382 sdcclib libint.lib _divsint.rel
6385 \begin_inset LatexCommand \index{sdcclib}
6392 \begin_layout Standard
6396 sdcclib libint.lib _divuint.rel
6399 \begin_layout Standard
6403 sdcclib libint.lib _modsint.rel
6406 \begin_layout Standard
6410 sdcclib libint.lib _moduint.rel
6413 \begin_layout Standard
6417 sdcclib libint.lib _mulint.rel
6425 \begin_layout Standard
6434 \begin_layout Standard
6438 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6446 \begin_layout Standard
6447 If the file already exists in the library, it will be replaced.
6448 If a list of .rel files is available, you can tell sdcclib to add those
6450 For example, if the file 'myliblist.txt' contains
6458 \begin_layout Standard
6465 \begin_layout Standard
6472 \begin_layout Standard
6479 \begin_layout Standard
6486 \begin_layout Standard
6498 \begin_layout Standard
6507 \begin_layout Standard
6511 sdcclib -l libint.lib myliblist.txt
6519 \begin_layout Standard
6520 Additionally, you can instruct sdcclib to compiles the files before adding
6521 them to the library.
6522 This is achieved using the environment variables SDCCLIB_CC and/or SDCCLIB_AS.
6531 \begin_layout Standard
6535 set SDCCLIB_CC=sdcc -c
6538 \begin_layout Standard
6542 sdcclib -l libint.lib myliblist.txt
6550 \begin_layout Standard
6551 To see what modules and symbols are included in the library, options -s
6552 and -m are available.
6560 sdcclib -s libint.lib
6563 \begin_inset LatexCommand \index{sdcclib}
6575 \begin_layout Standard
6581 \begin_layout Standard
6587 \begin_layout Standard
6595 \begin_layout Standard
6601 \begin_layout Standard
6607 \begin_layout Standard
6613 \begin_layout Standard
6619 \begin_layout Standard
6627 \begin_layout Standard
6633 \begin_layout Standard
6639 \begin_layout Standard
6647 \begin_layout Standard
6653 \begin_layout Standard
6659 \begin_layout Standard
6665 \begin_layout Standard
6673 \begin_layout Standard
6679 \begin_layout Standard
6690 \begin_layout Standard
6691 If the source files are compiled using -
6695 \begin_layout Standard
6705 \begin_inset LatexCommand \index{-\/-debug}
6709 , the corresponding debug information file .adb will be include in the library
6711 The library files created with sdcclib are plain text files, so they can
6712 be viewed with a text editor.
6713 It is not recomended to modify a library file created with sdcclib using
6714 a text editor, as there are file indexes numbers located accross the file
6715 used by the linker to quickly locate the required module to link.
6716 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6717 it can be safely deleted, since all the information required for linking
6718 is embedded in the library file itself.
6719 Library files created using sdcclib are used as described in the preceding
6721 \begin_inset VSpace bigskip
6727 \begin_layout Section
6728 Command Line Options
6729 \begin_inset LatexCommand \index{Command Line Options}
6734 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6741 \begin_layout Subsection
6742 Processor Selection Options
6743 \begin_inset LatexCommand \index{Options processor selection}
6748 \begin_inset LatexCommand \index{Processor selection options}
6756 \labelwidthstring 00.00.0000
6760 \begin_inset LatexCommand \index{-mmcs51}
6766 Generate code for the Intel MCS51
6767 \begin_inset LatexCommand \index{MCS51}
6771 family of processors.
6772 This is the default processor target.
6776 \labelwidthstring 00.00.0000
6780 \begin_inset LatexCommand \index{-mds390}
6786 Generate code for the Dallas DS80C390
6787 \begin_inset LatexCommand \index{DS80C390}
6795 \labelwidthstring 00.00.0000
6799 \begin_inset LatexCommand \index{-mds400}
6805 Generate code for the Dallas DS80C400
6806 \begin_inset LatexCommand \index{DS80C400}
6814 \labelwidthstring 00.00.0000
6818 \begin_inset LatexCommand \index{-mhc08}
6824 Generate code for the Freescale/Motorola HC08
6825 \begin_inset LatexCommand \index{HC08}
6829 family of processors.
6833 \labelwidthstring 00.00.0000
6837 \begin_inset LatexCommand \index{-mz80}
6843 Generate code for the Zilog Z80
6844 \begin_inset LatexCommand \index{Z80}
6848 family of processors.
6852 \labelwidthstring 00.00.0000
6856 \begin_inset LatexCommand \index{-mgbz80}
6862 Generate code for the GameBoy Z80
6863 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6867 processor (Not actively maintained).
6871 \labelwidthstring 00.00.0000
6875 \begin_inset LatexCommand \index{-mavr}
6881 Generate code for the Atmel AVR
6882 \begin_inset LatexCommand \index{AVR}
6886 processor (Not maintained, not complete).
6887 AVR users should probably have a look at winavr
6888 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6893 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6897 , which is based on AVR-port of the gcc compiler.
6900 \begin_layout Standard
6901 \begin_inset Note Note
6904 \begin_layout Standard
6905 I think it is fair to direct users there for now.
6906 Open source is also about avoiding unnecessary work .
6907 But I didn't find the 'official' link.
6916 \labelwidthstring 00.00.0000
6920 \begin_inset LatexCommand \index{-mpic14}
6926 Generate code for the Microchip PIC 14
6927 \begin_inset LatexCommand \index{PIC14}
6931 -bit processors (p16f84 and variants.
6932 In development, not complete).
6935 \begin_layout Standard
6936 \begin_inset Note Note
6939 \begin_layout Standard
6940 p16f627 p16f628 p16f84 p16f873 p16f877?
6949 \labelwidthstring 00.00.0000
6953 \begin_inset LatexCommand \index{-mpic16}
6959 Generate code for the Microchip PIC 16
6960 \begin_inset LatexCommand \index{PIC16}
6964 -bit processors (p18f452 and variants.
6965 In development, not complete).
6969 \labelwidthstring 00.00.0000
6974 Generate code for the Toshiba TLCS-900H
6975 \begin_inset LatexCommand \index{TLCS-900H}
6979 processor (Not maintained, not complete).
6983 \labelwidthstring 00.00.0000
6987 \begin_inset LatexCommand \index{-mxa51}
6993 Generate code for the Phillips XA51
6994 \begin_inset LatexCommand \index{XA51}
6998 processor (Not maintained, not complete).
7001 \begin_layout Standard
7002 \begin_inset VSpace bigskip
7008 \begin_layout Subsection
7009 Preprocessor Options
7010 \begin_inset LatexCommand \index{Options preprocessor}
7015 \begin_inset LatexCommand \index{Preprocessor options}
7020 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7028 \labelwidthstring 00.00.0000
7032 \begin_inset LatexCommand \index{-I<path>}
7038 The additional location where the preprocessor will look for <..h> or
7039 \begin_inset Quotes eld
7043 \begin_inset Quotes erd
7050 \labelwidthstring 00.00.0000
7054 \begin_inset LatexCommand \index{-D<macro[=value]>}
7060 Command line definition of macros.
7061 Passed to the preprocessor.
7065 \labelwidthstring 00.00.0000
7069 \begin_inset LatexCommand \index{-M}
7075 Tell the preprocessor to output a rule suitable for make describing the
7076 dependencies of each object file.
7077 For each source file, the preprocessor outputs one make-rule whose target
7078 is the object file name for that source file and whose dependencies are
7079 all the files `#include'd in it.
7080 This rule may be a single line or may be continued with `
7082 '-newline if it is long.
7083 The list of rules is printed on standard output instead of the preprocessed
7086 \begin_inset LatexCommand \index{-E}
7094 \labelwidthstring 00.00.0000
7098 \begin_inset LatexCommand \index{-C}
7104 Tell the preprocessor not to discard comments.
7105 Used with the `-E' option.
7109 \labelwidthstring 00.00.0000
7113 \begin_inset LatexCommand \index{-MM}
7124 Like `-M' but the output mentions only the user header files included with
7126 \begin_inset Quotes eld
7130 System header files included with `#include <file>' are omitted.
7134 \labelwidthstring 00.00.0000
7138 \begin_inset LatexCommand \index{-Aquestion(answer)}
7144 Assert the answer answer for question, in case it is tested with a preprocessor
7145 conditional such as `#if #question(answer)'.
7146 `-A-' disables the standard assertions that normally describe the target
7151 \labelwidthstring 00.00.0000
7155 \begin_inset LatexCommand \index{-Umacro}
7161 Undefine macro macro.
7162 `-U' options are evaluated after all `-D' options, but before any `-include'
7163 and `-imacros' options.
7167 \labelwidthstring 00.00.0000
7171 \begin_inset LatexCommand \index{-dM}
7177 Tell the preprocessor to output only a list of the macro definitions that
7178 are in effect at the end of preprocessing.
7179 Used with the `-E' option.
7183 \labelwidthstring 00.00.0000
7187 \begin_inset LatexCommand \index{-dD}
7193 Tell the preprocessor to pass all macro definitions into the output, in
7194 their proper sequence in the rest of the output.
7198 \labelwidthstring 00.00.0000
7202 \begin_inset LatexCommand \index{-dN}
7213 Like `-dD' except that the macro arguments and contents are omitted.
7214 Only `#define name' is included in the output.
7218 \labelwidthstring 00.00.0000
7221 -pedantic-parse-number
7222 \begin_inset LatexCommand \index{pedantic}
7227 \begin_inset LatexCommand \index{-pedantic-parse-number}
7235 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
7243 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7244 and the macro LO_B(3) gets expanded.
7245 See also #pragma pedantic_parse_number
7246 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
7251 \begin_inset LatexCommand \ref{sec:Pragmas}
7257 Note: this functionality is not in conformance with C99 standard!
7261 \labelwidthstring 00.00.0000
7265 preprocessorOption[,preprocessorOption]
7268 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
7273 Pass the preprocessorOption to the preprocessor
7278 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7283 SDCC uses an adapted version of the preprocessor
7287 of the GNU Compiler Collection
7288 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
7297 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7301 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7306 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7313 \begin_layout Standard
7314 \begin_inset VSpace bigskip
7320 \begin_layout Subsection
7322 \begin_inset LatexCommand \index{Options linker}
7327 \begin_inset LatexCommand \index{Linker options}
7335 \labelwidthstring 00.00.0000
7345 \begin_layout Standard
7357 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7362 \begin_inset LatexCommand \index{-L -\/-lib-path}
7369 <absolute path to additional libraries> This option is passed to the linkage
7370 editor's additional libraries
7371 \begin_inset LatexCommand \index{Libraries}
7376 The path name must be absolute.
7377 Additional library files may be specified in the command line.
7378 See section Compiling programs for more details.
7382 \labelwidthstring 00.00.0000
7389 \begin_layout Standard
7401 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7406 <Value> The start location of the external ram
7407 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7411 , default value is 0.
7412 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7416 \begin_layout Standard
7425 -xram-loc 0x8000 or -
7429 \begin_layout Standard
7442 \labelwidthstring 00.00.0000
7449 \begin_layout Standard
7461 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7466 <Value> The start location of the code
7467 \begin_inset LatexCommand \index{code}
7471 segment, default value 0.
7472 Note when this option is used the interrupt vector table
7473 \begin_inset LatexCommand \index{interrupt vector table}
7477 is also relocated to the given address.
7478 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7482 \begin_layout Standard
7491 -code-loc 0x8000 or -
7495 \begin_layout Standard
7508 \labelwidthstring 00.00.0000
7515 \begin_layout Standard
7527 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7532 <Value> By default the stack
7533 \begin_inset LatexCommand \index{stack}
7537 is placed after the data segment.
7538 Using this option the stack can be placed anywhere in the internal memory
7540 The value entered can be in Hexadecimal or Decimal format, e.g.
7545 \begin_layout Standard
7554 -stack-loc 0x20 or -
7558 \begin_layout Standard
7568 Since the sp register is incremented before a push or call, the initial
7569 sp will be set to one byte prior the provided value.
7570 The provided value should not overlap any other memory areas such as used
7571 register banks or the data segment and with enough space for the current
7579 \begin_layout Standard
7592 \begin_inset LatexCommand \index{-\/-pack-iram}
7596 option (which is now a default setting) will override this setting, so
7597 you should also specify the
7603 \begin_layout Standard
7616 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7620 option if you need to manually place the stack.
7624 \labelwidthstring 00.00.0000
7631 \begin_layout Standard
7643 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7648 <Value> By default the external stack
7649 \begin_inset LatexCommand \index{xstack}
7653 is placed after the pdata
7654 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7659 Using this option the xstack can be placed anywhere in the external memory
7661 The value entered can be in Hexadecimal or Decimal format, e.g.
7666 \begin_layout Standard
7675 -xstack-loc 0x8000 or -
7679 \begin_layout Standard
7689 The provided value should not overlap any other memory areas such as the
7690 pdata or xdata segment and with enough space for the current application.
7694 \labelwidthstring 00.00.0000
7701 \begin_layout Standard
7713 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7718 <Value> The start location of the internal ram data
7719 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7724 The value entered can be in Hexadecimal or Decimal format, eg.
7729 \begin_layout Standard
7742 \begin_layout Standard
7752 (By default, the start location of the internal ram data segment is set
7753 as low as possible in memory, taking into account the used register banks
7754 and the bit segment at address 0x20.
7755 For example if register banks 0 and 1 are used without bit variables, the
7756 data segment will be set, if -
7760 \begin_layout Standard
7769 -data-loc is not used, to location 0x10.)
7773 \labelwidthstring 00.00.0000
7780 \begin_layout Standard
7792 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7797 <Value> The start location of the indirectly addressable internal ram
7798 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7802 of the 8051, default value is 0x80.
7803 The value entered can be in Hexadecimal or Decimal format, eg.
7808 \begin_layout Standard
7817 -idata-loc 0x88 or -
7821 \begin_layout Standard
7834 \labelwidthstring 00.00.0000
7841 \begin_layout Standard
7853 <Value> The start location of the bit
7854 \begin_inset LatexCommand \index{bit}
7858 addressable internal ram of the 8051.
7864 Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7869 \labelwidthstring 00.00.0000
7876 \begin_layout Standard
7886 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7895 The linker output (final object code) is in Intel Hex format.
7896 \begin_inset LatexCommand \index{Intel hex format}
7900 This is the default option.
7901 The format itself is documented in the documentation of srecord
7902 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7910 \labelwidthstring 00.00.0000
7917 \begin_layout Standard
7927 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7936 The linker output (final object code) is in Motorola S19 format
7937 \begin_inset LatexCommand \index{Motorola S19 format}
7942 The format itself is documented in the documentation of srecord.
7946 \labelwidthstring 00.00.0000
7953 \begin_layout Standard
7963 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7968 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7977 The linker output (final object code) is in ELF format
7978 \begin_inset LatexCommand \index{ELF format}
7983 (Currently only supported for the HC08
7984 \begin_inset LatexCommand \index{HC08}
7992 \labelwidthstring 00.00.0000
7996 linkOption[,linkOption]
7999 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
8004 Pass the linkOption to the linker.
8005 If a bootloader is used an option like
8006 \begin_inset Quotes sld
8011 \begin_inset Quotes srd
8014 would be typical to set the start of the code segment.
8015 See also #pragma constseg and #pragma codeseg in section
8016 \begin_inset LatexCommand \ref{sec:Pragmas}
8021 File sdcc/as/doc/asxhtm.html has more on linker options.
8024 \begin_layout Standard
8025 \begin_inset VSpace bigskip
8031 \begin_layout Subsection
8033 \begin_inset LatexCommand \index{Options MCS51}
8038 \begin_inset LatexCommand \index{MCS51 options}
8046 \labelwidthstring 00.00.0000
8053 \begin_layout Standard
8063 \begin_inset LatexCommand \index{-\/-model-small}
8074 Generate code for Small Model programs, see section Memory Models for more
8076 This is the default model.
8080 \labelwidthstring 00.00.0000
8087 \begin_layout Standard
8097 \begin_inset LatexCommand \index{-\/-model-medium}
8103 Generate code for Medium model programs, see section Memory Models for
8105 If this option is used all source files in the project have to be compiled
8107 It must also be used when invoking the linker.
8111 \labelwidthstring 00.00.0000
8118 \begin_layout Standard
8128 \begin_inset LatexCommand \index{-\/-model-large}
8134 Generate code for Large model programs, see section Memory Models for more
8136 If this option is used all source files in the project have to be compiled
8138 It must also be used when invoking the linker.
8142 \labelwidthstring 00.00.0000
8149 \begin_layout Standard
8159 \begin_inset LatexCommand \index{-\/-xstack}
8165 Uses a pseudo stack in the pdata
8166 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8170 area (usually the first 256 bytes in the external ram) for allocating variables
8171 and passing parameters.
8173 \begin_inset LatexCommand \ref{sub:External-Stack}
8178 External Stack for more details.
8182 \labelwidthstring 00.00.0000
8189 \begin_layout Standard
8202 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
8206 Causes the linker to check if the internal ram usage is within limits of
8211 \labelwidthstring 00.00.0000
8218 \begin_layout Standard
8231 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
8235 Causes the linker to check if the external ram usage is within limits of
8240 \labelwidthstring 00.00.0000
8247 \begin_layout Standard
8260 \begin_inset LatexCommand \index{-\/-code-size <Value>}
8264 Causes the linker to check if the code memory usage is within limits of
8269 \labelwidthstring 00.00.0000
8276 \begin_layout Standard
8289 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8293 Causes the linker to check if there is at minimum <Value> bytes for stack.
8297 \labelwidthstring 00.00.0000
8304 \begin_layout Standard
8317 \begin_inset LatexCommand \index{-\/-pack-iram}
8321 Causes the linker to use unused register banks for data variables and pack
8322 data, idata and stack together.
8323 This is the default now.
8327 \labelwidthstring 00.00.0000
8334 \begin_layout Standard
8347 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8351 Causes the linker to use old style for allocating memory areas.
8355 \labelwidthstring 00.00.0000
8362 \begin_layout Standard
8375 \begin_inset LatexCommand \index{-\/-acall-ajmp}
8379 Replaces the three byte instructions lcall/ljmp with the two byte instructions
8381 Only use this option if your code is in the same 2k block of memory.
8382 You may need to use this option for some 8051 derivatives which lack the
8383 lcall/ljmp instructions..
8386 \begin_layout Standard
8387 \begin_inset VSpace bigskip
8393 \begin_layout Subsection
8394 DS390 / DS400 Options
8395 \begin_inset LatexCommand \index{Options DS390}
8400 \begin_inset LatexCommand \index{DS390}
8408 \labelwidthstring 00.00.0000
8415 \begin_layout Standard
8427 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8437 Generate 24-bit flat mode code.
8438 This is the one and only that the ds390 code generator supports right now
8439 and is default when using
8444 See section Memory Models for more details.
8448 \labelwidthstring 00.00.0000
8455 \begin_layout Standard
8465 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8471 disable interrupts during ESP:SP updates.
8475 \labelwidthstring 00.00.0000
8482 \begin_layout Standard
8494 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8498 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8499 This is the one and only that the ds390 code generator supports right now
8500 and is default when using
8505 In this mode, the stack is located in the lower 1K of the internal RAM,
8506 which is mapped to 0x400000.
8507 Note that the support is incomplete, since it still uses a single byte
8508 as the stack pointer.
8509 This means that only the lower 256 bytes of the potential 1K stack space
8510 will actually be used.
8511 However, this does allow you to reclaim the precious 256 bytes of low RAM
8512 for use for the DATA and IDATA segments.
8513 The compiler will not generate any code to put the processor into 10 bit
8515 It is important to ensure that the processor is in this mode before calling
8516 any re-entrant functions compiled with this option.
8517 In principle, this should work with the
8523 \begin_layout Standard
8533 \begin_inset LatexCommand \index{-\/-stack-auto}
8539 option, but that has not been tested.
8540 It is incompatible with the
8546 \begin_layout Standard
8556 \begin_inset LatexCommand \index{-\/-xstack}
8563 It also only makes sense if the processor is in 24 bit contiguous addressing
8570 \begin_layout Standard
8579 -model-flat24 option
8584 \begin_inset Note Note
8588 \labelwidthstring 00.00.0000
8595 \begin_layout Standard
8604 -stack-8-bit - switches off the 10-bit mode
8613 \labelwidthstring 00.00.0000
8620 \begin_layout Standard
8630 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8636 insert call to function __stack_probe at each function prologue.
8640 \labelwidthstring 00.00.0000
8647 \begin_layout Standard
8657 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8663 <nnnn> LibraryID used in -mTININative.
8668 \labelwidthstring 00.00.0000
8675 \begin_layout Standard
8685 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8691 generate code for DS390 Arithmetic Accelerator.
8695 \begin_layout Standard
8696 \begin_inset VSpace bigskip
8702 \begin_layout Subsection
8704 \begin_inset LatexCommand \index{Options Z80}
8709 \begin_inset LatexCommand \index{Z80}
8717 \labelwidthstring 00.00.0000
8724 \begin_layout Standard
8736 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8746 Force a called function to always save BC.
8750 \labelwidthstring 00.00.0000
8757 \begin_layout Standard
8769 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8773 When linking, skip the standard crt0.o object file.
8774 You must provide your own crt0.o for your system when linking.
8778 \labelwidthstring 00.00.0000
8785 \begin_layout Standard
8797 \begin_inset LatexCommand \index{Z80!Options!-\/-portmode=<Value>}
8801 Determinate PORT I/O mode (<Value> is z80 or z180).
8805 \labelwidthstring 00.00.0000
8812 \begin_layout Standard
8824 \begin_inset LatexCommand \index{Z80!Options!-\/-asm=<Value>}
8828 Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
8832 \labelwidthstring 00.00.0000
8839 \begin_layout Standard
8852 \begin_inset LatexCommand \index{Z80!Options!-\/-codeseg <Value>}
8856 Use <Value> for the code segment name.
8860 \labelwidthstring 00.00.0000
8867 \begin_layout Standard
8880 \begin_inset LatexCommand \index{Z80!Options!-\/-constseg <Value>}
8884 Use <Value> for the const segment name.
8888 \labelwidthstring 00.00.0000
8889 \begin_inset VSpace bigskip
8895 \begin_layout Subsection
8897 \begin_inset LatexCommand \index{Options GBZ80}
8902 \begin_inset LatexCommand \index{GBZ80}
8910 \labelwidthstring 00.00.0000
8917 \begin_layout Standard
8929 \begin_inset LatexCommand \index{GBZ80!Options!-\/-callee-saves-bc}
8939 Force a called function to always save BC.
8943 \labelwidthstring 00.00.0000
8950 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
8954 Use code bank <Num>.
8958 \labelwidthstring 00.00.0000
8965 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
8969 Use data bank <Num>.
8973 \labelwidthstring 00.00.0000
8980 \begin_layout Standard
8993 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
8997 Use <Value> for the code segment name.
9001 \labelwidthstring 00.00.0000
9008 \begin_layout Standard
9021 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
9025 Use <Value> for the const segment name.
9028 \begin_layout Standard
9029 \begin_inset VSpace bigskip
9035 \begin_layout Subsection
9036 Optimization Options
9037 \begin_inset LatexCommand \index{Options optimization}
9042 \begin_inset LatexCommand \index{Optimization options}
9050 \labelwidthstring 00.00.0000
9057 \begin_layout Standard
9067 \begin_inset LatexCommand \index{-\/-nogcse}
9073 Will not do global subexpression elimination, this option may be used when
9074 the compiler creates undesirably large stack/data spaces to store compiler
9084 \begin_inset LatexCommand \index{sloc (spill location)}
9089 A warning message will be generated when this happens and the compiler
9090 will indicate the number of extra bytes it allocated.
9091 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9093 \begin_inset LatexCommand \index{\#pragma nogcse}
9097 can be used to turn off global subexpression elimination
9098 \begin_inset LatexCommand \index{Subexpression elimination}
9102 for a given function only.
9106 \labelwidthstring 00.00.0000
9113 \begin_layout Standard
9123 \begin_inset LatexCommand \index{-\/-noinvariant}
9129 Will not do loop invariant optimizations, this may be turned off for reasons
9130 explained for the previous option.
9131 For more details of loop optimizations performed see Loop Invariants in
9133 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
9138 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9140 \begin_inset LatexCommand \index{\#pragma noinvariant}
9144 can be used to turn off invariant optimizations for a given function only.
9148 \labelwidthstring 00.00.0000
9155 \begin_layout Standard
9165 \begin_inset LatexCommand \index{-\/-noinduction}
9171 Will not do loop induction optimizations, see section strength reduction
9173 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9175 \begin_inset LatexCommand \index{\#pragma noinduction}
9179 can be used to turn off induction optimizations for a given function only.
9183 \labelwidthstring 00.00.0000
9190 \begin_layout Standard
9200 \begin_inset LatexCommand \index{-\/-nojtbound}
9211 Will not generate boundary condition check when switch statements
9212 \begin_inset LatexCommand \index{switch statement}
9216 are implemented using jump-tables.
9218 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
9223 Switch Statements for more details.
9224 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9226 \begin_inset LatexCommand \index{\#pragma nojtbound}
9230 can be used to turn off boundary checking for jump tables for a given function
9235 \labelwidthstring 00.00.0000
9242 \begin_layout Standard
9252 \begin_inset LatexCommand \index{-\/-noloopreverse}
9261 Will not do loop reversal
9262 \begin_inset LatexCommand \index{Loop reversing}
9270 \labelwidthstring 00.00.0000
9275 \begin_layout Standard
9289 \begin_inset LatexCommand \index{-\/-nolabelopt }
9293 Will not optimize labels (makes the dumpfiles more readable).
9297 \labelwidthstring 00.00.0000
9304 \begin_layout Standard
9314 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9320 Will not memcpy initialized data from code space into xdata space.
9321 This saves a few bytes in code space if you don't have initialized data
9322 \begin_inset LatexCommand \index{Variable initialization}
9330 \labelwidthstring 00.00.0000
9337 \begin_layout Standard
9347 \begin_inset LatexCommand \index{-\/-nooverlay}
9353 The compiler will not overlay parameters and local variables of any function,
9354 see section Parameters and local variables for more details.
9358 \labelwidthstring 00.00.0000
9365 \begin_layout Standard
9375 \begin_inset LatexCommand \index{-\/-no-peep}
9381 Disable peep-hole optimization with built-in rules.
9385 \labelwidthstring 00.00.0000
9392 \begin_layout Standard
9404 \begin_inset LatexCommand \index{-\/-peep-file}
9409 <filename> This option can be used to use additional rules to be used by
9410 the peep hole optimizer.
9412 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9417 Peep Hole optimizations for details on how to write these rules.
9421 \labelwidthstring 00.00.0000
9428 \begin_layout Standard
9438 \begin_inset LatexCommand \index{-\/-peep-asm}
9444 Pass the inline assembler code through the peep hole optimizer.
9445 This can cause unexpected changes to inline assembler code, please go through
9446 the peephole optimizer
9447 \begin_inset LatexCommand \index{Peephole optimizer}
9451 rules defined in the source file tree '<target>/peeph.def' before using
9456 \labelwidthstring 00.00.0000
9463 \begin_layout Standard
9473 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9479 The compiler will optimize code generation towards fast code, possibly
9480 at the expense of code size.
9484 \labelwidthstring 00.00.0000
9491 \begin_layout Standard
9501 \begin_inset LatexCommand \index{-\/-opt-code-size}
9507 The compiler will optimize code generation towards compact code, possibly
9508 at the expense of code speed.
9511 \begin_layout Standard
9512 \begin_inset VSpace bigskip
9518 \begin_layout Subsection
9520 \begin_inset LatexCommand \index{Options other}
9528 \labelwidthstring 00.00.0000
9536 \begin_layout Standard
9546 \begin_inset LatexCommand \index{-\/-compile-only}
9551 \begin_inset LatexCommand \index{-c -\/-compile-only}
9557 will compile and assemble the source, but will not call the linkage editor.
9561 \labelwidthstring 00.00.0000
9570 \begin_layout Standard
9582 \begin_inset LatexCommand \index{-\/-c1mode}
9588 reads the preprocessed source from standard input and compiles it.
9589 The file name for the assembler output must be specified using the -o option.
9593 \labelwidthstring 00.00.0000
9597 \begin_inset LatexCommand \index{-E}
9603 Run only the C preprocessor.
9604 Preprocess all the C source files specified and output the results to standard
9609 \labelwidthstring 00.00.0000
9614 \begin_inset LatexCommand \index{-o <path/file>}
9620 The output path where everything will be placed or the file name used for
9621 all generated output files.
9622 If the parameter is a path, it must have a trailing slash (or backslash
9623 for the Windows binaries) to be recognized as a path.
9628 Note for Windows users: if the path contains spaces, it should be surrounded
9630 The trailing backslash should be doubled in order to prevent escaping the
9631 final quote, for example:
9634 \begin_inset Quotes sld
9648 \begin_inset Quotes srd
9653 or put after the final quote, for example:
9656 \begin_inset Quotes sld
9666 \begin_inset Quotes srd
9674 The path using slashes for directory delimiters can be used too, for example:
9678 \begin_inset Quotes sld
9681 F:/Projects/test3/output 1/
9682 \begin_inset Quotes srd
9691 \labelwidthstring 00.00.0000
9698 \begin_layout Standard
9708 \begin_inset LatexCommand \index{-\/-stack-auto}
9719 All functions in the source file will be compiled as
9724 \begin_inset LatexCommand \index{reentrant}
9729 the parameters and local variables will be allocated on the stack
9730 \begin_inset LatexCommand \index{stack}
9736 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9740 Parameters and Local Variables for more details.
9741 If this option is used all source files in the project should be compiled
9743 It automatically implies -
9749 \begin_layout Standard
9760 -int-long-reent and -
9766 \begin_layout Standard
9782 \labelwidthstring 00.00.0000
9789 \begin_layout Standard
9799 \begin_inset LatexCommand \index{-\/-callee-saves}
9804 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9808 function1[,function2][,function3]....
9811 The compiler by default uses a caller saves convention for register saving
9812 across function calls, however this can cause unnecessary register pushing
9813 and popping when calling small functions from larger functions.
9814 This option can be used to switch the register saving convention for the
9815 function names specified.
9816 The compiler will not save registers when calling these functions, no extra
9817 code will be generated at the entry and exit (function prologue
9820 \begin_inset LatexCommand \index{function prologue}
9829 \begin_inset LatexCommand \index{function epilogue}
9835 ) for these functions to save and restore the registers used by these functions,
9836 this can SUBSTANTIALLY reduce code and improve run time performance of
9838 In the future the compiler (with inter procedural analysis) will be able
9839 to determine the appropriate scheme to use for each function call.
9840 DO NOT use this option for built-in functions such as _mulint..., if this
9841 option is used for a library function the appropriate library function
9842 needs to be recompiled with the same option.
9843 If the project consists of multiple source files then all the source file
9844 should be compiled with the same -
9848 \begin_layout Standard
9857 -callee-saves option string.
9858 Also see #pragma\InsetSpace ~
9860 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9865 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9873 \labelwidthstring 00.00.0000
9880 \begin_layout Standard
9890 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9904 \begin_layout Standard
9913 -callee-saves will be applied to all functions by default.
9917 \labelwidthstring 00.00.0000
9924 \begin_layout Standard
9934 \begin_inset LatexCommand \index{-\/-debug}
9943 When this option is used the compiler will generate debug information.
9944 The debug information collected in a file with .cdb extension can be used
9946 For more information see documentation for SDCDB.
9947 Another file with no extension contains debug information in AOMF or AOMF51
9948 \begin_inset LatexCommand \index{AOMF, AOMF51}
9952 format which is commonly used by third party tools.
9956 \labelwidthstring 00.00.0000
9960 \begin_inset LatexCommand \index{-S}
9971 Stop after the stage of compilation proper; do not assemble.
9972 The output is an assembler code file for the input file specified.
9976 \labelwidthstring 00.00.0000
9983 \begin_layout Standard
9993 \begin_inset LatexCommand \index{-\/-int-long-reent}
9999 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
10000 Note by default these libraries are compiled as non-reentrant.
10001 See section Installation for more details.
10005 \labelwidthstring 00.00.0000
10012 \begin_layout Standard
10022 \begin_inset LatexCommand \index{-\/-cyclomatic}
10031 This option will cause the compiler to generate an information message for
10032 each function in the source file.
10033 The message contains some
10037 information about the function.
10038 The number of edges and nodes the compiler detected in the control flow
10039 graph of the function, and most importantly the
10041 cyclomatic complexity
10042 \begin_inset LatexCommand \index{Cyclomatic complexity}
10048 see section on Cyclomatic Complexity for more details.
10052 \labelwidthstring 00.00.0000
10059 \begin_layout Standard
10069 \begin_inset LatexCommand \index{-\/-float-reent}
10075 Floating point library is compiled as reentrant
10076 \begin_inset LatexCommand \index{reentrant}
10081 See section Installation for more details.
10085 \labelwidthstring 00.00.0000
10092 \begin_layout Standard
10102 \begin_inset LatexCommand \index{-\/-funsigned-char}
10108 The default signedness for every type is
10113 In some embedded environments the default signedness of
10122 To set the signess for characters to unsigned, use the option -
10128 \begin_layout Standard
10140 If this option is set and no signedness keyword (unsigned/signed) is given,
10141 a char will be signed.
10142 All other types are unaffected.
10146 \labelwidthstring 00.00.0000
10153 \begin_layout Standard
10163 \begin_inset LatexCommand \index{-\/-main-return}
10169 This option can be used if the code generated is called by a monitor program
10170 or if the main routine includes an endless loop.
10171 This option results in slightly smaller code and saves two bytes of stack
10173 The return from the 'main'
10174 \begin_inset LatexCommand \index{main return}
10178 function will return to the function calling main.
10179 The default setting is to lock up i.e.
10188 \labelwidthstring 00.00.0000
10195 \begin_layout Standard
10205 \begin_inset LatexCommand \index{-\/-nostdinc}
10211 This will prevent the compiler from passing on the default include path
10212 to the preprocessor.
10216 \labelwidthstring 00.00.0000
10223 \begin_layout Standard
10233 \begin_inset LatexCommand \index{-\/-nostdlib}
10239 This will prevent the compiler from passing on the default library
10240 \begin_inset LatexCommand \index{Libraries}
10244 path to the linker.
10248 \labelwidthstring 00.00.0000
10255 \begin_layout Standard
10265 \begin_inset LatexCommand \index{-\/-verbose}
10271 Shows the various actions the compiler is performing.
10275 \labelwidthstring 00.00.0000
10279 \begin_inset LatexCommand \index{-V}
10285 Shows the actual commands the compiler is executing.
10289 \labelwidthstring 00.00.0000
10296 \begin_layout Standard
10306 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
10312 Hides your ugly and inefficient c-code from the asm file, so you can always
10313 blame the compiler :)
10317 \labelwidthstring 00.00.0000
10324 \begin_layout Standard
10334 \begin_inset LatexCommand \index{-\/-no-gen-comments}
10340 Include code generator and peep-hole comments in the generated asm files.
10344 \labelwidthstring 00.00.0000
10351 \begin_layout Standard
10361 \begin_inset LatexCommand \index{-\/-no-peep-comments}
10367 Don't include peep-hole comments in the generated asm files even if -
10373 \begin_layout Standard
10384 -fverbose-asm option is specified.
10388 \labelwidthstring 00.00.0000
10395 \begin_layout Standard
10405 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10411 Include i-codes in the asm file.
10412 Sounds like noise but is most helpful for debugging the compiler itself.
10416 \labelwidthstring 00.00.0000
10423 \begin_layout Standard
10433 \begin_inset LatexCommand \index{pedantic}
10438 \begin_inset LatexCommand \index{-\/-less-pedantic}
10445 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10449 Disable some of the more pedantic warnings
10450 \begin_inset LatexCommand \index{Warnings}
10455 For more details, see the less_pedantic pragma
10456 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10464 \labelwidthstring 00.00.0000
10471 \begin_layout Standard
10480 -disable-warning\InsetSpace ~
10482 \begin_inset LatexCommand \index{-\/-disable-warning}
10488 Disable specific warning with number <nnnn>.
10492 \labelwidthstring 00.00.0000
10499 \begin_layout Standard
10509 \begin_inset LatexCommand \index{-\/-Werror}
10515 Treat all warnings as errors.
10519 \labelwidthstring 00.00.0000
10526 \begin_layout Standard
10536 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10542 Display the directories in the compiler's search path
10546 \labelwidthstring 00.00.0000
10553 \begin_layout Standard
10563 \begin_inset LatexCommand \index{-\/-vc}
10569 Display errors and warnings using MSVC style, so you can use SDCC with
10570 the visual studio IDE
10571 \begin_inset LatexCommand \index{IDE}
10576 With SDCC both offering a GCC-like (the default) and a MSVC-like
10577 \begin_inset LatexCommand \index{MSVC output style}
10581 output style, integration into most programming editors should be straightforwa
10586 \labelwidthstring 00.00.0000
10593 \begin_layout Standard
10603 \begin_inset LatexCommand \index{-\/-use-stdout}
10609 Send errors and warnings to stdout instead of stderr.
10613 \labelwidthstring 00.00.0000
10617 asmOption[,asmOption]
10620 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10625 Pass the asmOption to the assembler
10626 \begin_inset LatexCommand \index{Options assembler}
10631 \begin_inset LatexCommand \index{Assembler options}
10636 See file sdcc/as/doc/asxhtm.html for assembler options.cd
10640 \labelwidthstring 00.00.0000
10647 \begin_layout Standard
10657 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10663 Generally follow the C89 standard, but allow SDCC features that conflict
10664 with the standard (default).
10668 \labelwidthstring 00.00.0000
10675 \begin_layout Standard
10685 \begin_inset LatexCommand \index{-\/-std-c89}
10691 Follow the C89 standard and disable SDCC features that conflict with the
10696 \labelwidthstring 00.00.0000
10703 \begin_layout Standard
10713 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10719 Generally follow the C99 standard, but allow SDCC features that conflict
10720 with the standard (incomplete support).
10724 \labelwidthstring 00.00.0000
10731 \begin_layout Standard
10741 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10747 Follow the C99 standard and disable SDCC features that conflict with the
10748 standard (incomplete support).
10752 \labelwidthstring 00.00.0000
10759 \begin_layout Standard
10771 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10776 <Name> The name to be used for the code
10777 \begin_inset LatexCommand \index{code}
10781 segment, default CSEG.
10782 This is useful if you need to tell the compiler to put the code in a special
10783 segment so you can later on tell the linker to put this segment in a special
10785 Can be used for instance when using bank switching to put the code in a
10790 \labelwidthstring 00.00.0000
10797 \begin_layout Standard
10809 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10814 <Name> The name to be used for the const
10815 \begin_inset LatexCommand \index{const}
10819 segment, default CONST.
10820 This is useful if you need to tell the compiler to put the const data in
10821 a special segment so you can later on tell the linker to put this segment
10822 in a special place in memory.
10823 Can be used for instance when using bank switching to put the const data
10828 \labelwidthstring 00.00.0000
10835 \begin_layout Standard
10844 -fdollars-in-identifiers
10845 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10851 Permit '$' as an identifier character.
10855 \labelwidthstring 00.00.0000
10862 \begin_layout Standard
10874 \begin_inset LatexCommand \index{-\/-more-pedantic}
10879 \begin_inset LatexCommand \index{pedantic}
10889 a SDCC compiler option but if you want
10893 warnings you can use a separate tool dedicated to syntax checking like
10895 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10900 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10905 \begin_inset LatexCommand \url{http://www.splint.org}
10910 To make your source files parseable by splint you will have to include
10916 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10920 in your source file and add brackets around extended keywords (like
10923 \begin_inset Quotes sld
10936 \begin_inset Quotes srd
10944 \begin_inset Quotes sld
10947 __interrupt\InsetSpace ~
10949 \begin_inset Quotes srd
10957 Splint has an excellent on line manual at
10958 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10962 and it's capabilities go beyond pure syntax checking.
10963 You'll need to tell splint the location of SDCC's include files so a typical
10964 command line could look like this:
10968 splint\InsetSpace ~
10970 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10976 \labelwidthstring 00.00.0000
10983 \begin_layout Standard
10995 \begin_inset LatexCommand \index{-\/-short-is-8bits}
11000 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
11004 Treat short as 8-bit (for backward compatibility with older versions of
11005 compiler - see section
11006 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
11013 \begin_layout Standard
11014 \begin_inset VSpace bigskip
11020 \begin_layout Subsection
11021 Intermediate Dump Options
11022 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
11027 \begin_inset LatexCommand \index{Options intermediate dump}
11032 \begin_inset LatexCommand \index{Intermediate dump options}
11039 \begin_layout Standard
11040 The following options are provided for the purpose of retargetting and debugging
11042 They provide a means to dump the intermediate code (iCode
11043 \begin_inset LatexCommand \index{iCode}
11047 ) generated by the compiler in human readable form at various stages of
11048 the compilation process.
11049 More on iCodes see chapter
11050 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
11055 \begin_inset Quotes srd
11058 The anatomy of the compiler
11059 \begin_inset Quotes srd
11066 \labelwidthstring 00.00.0000
11073 \begin_layout Standard
11083 \begin_inset LatexCommand \index{-\/-dumpraw}
11089 This option will cause the compiler to dump the intermediate code into
11092 <source filename>.dumpraw
11094 just after the intermediate code has been generated for a function, i.e.
11095 before any optimizations are done.
11097 \begin_inset LatexCommand \index{Basic blocks}
11101 at this stage ordered in the depth first number, so they may not be in
11102 sequence of execution.
11106 \labelwidthstring 00.00.0000
11113 \begin_layout Standard
11123 \begin_inset LatexCommand \index{-\/-dumpgcse}
11129 Will create a dump of iCodes, after global subexpression elimination
11130 \begin_inset LatexCommand \index{Global subexpression elimination}
11134 , into a file named
11136 <source filename>.dumpgcse.
11140 \labelwidthstring 00.00.0000
11147 \begin_layout Standard
11157 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
11163 Will create a dump of iCodes, after deadcode elimination
11164 \begin_inset LatexCommand \index{Dead-code elimination}
11168 , into a file named
11170 <source filename>.dumpdeadcode.
11174 \labelwidthstring 00.00.0000
11181 \begin_layout Standard
11191 \begin_inset LatexCommand \index{-\/-dumploop}
11200 Will create a dump of iCodes, after loop optimizations
11201 \begin_inset LatexCommand \index{Loop optimization}
11205 , into a file named
11207 <source filename>.dumploop.
11211 \labelwidthstring 00.00.0000
11218 \begin_layout Standard
11228 \begin_inset LatexCommand \index{-\/-dumprange}
11237 Will create a dump of iCodes, after live range analysis
11238 \begin_inset LatexCommand \index{Live range analysis}
11242 , into a file named
11244 <source filename>.dumprange.
11248 \labelwidthstring 00.00.0000
11255 \begin_layout Standard
11265 \begin_inset LatexCommand \index{-\/-dumlrange}
11271 Will dump the life ranges
11272 \begin_inset LatexCommand \index{Live range analysis}
11280 \labelwidthstring 00.00.0000
11287 \begin_layout Standard
11297 \begin_inset LatexCommand \index{-\/-dumpregassign}
11306 Will create a dump of iCodes, after register assignment
11307 \begin_inset LatexCommand \index{Register assignment}
11311 , into a file named
11313 <source filename>.dumprassgn.
11317 \labelwidthstring 00.00.0000
11324 \begin_layout Standard
11334 \begin_inset LatexCommand \index{-\/-dumplrange}
11340 Will create a dump of the live ranges of iTemp's
11344 \labelwidthstring 00.00.0000
11351 \begin_layout Standard
11361 \begin_inset LatexCommand \index{-\/-dumpall}
11372 Will cause all the above mentioned dumps to be created.
11375 \begin_layout Standard
11376 \begin_inset VSpace bigskip
11382 \begin_layout Subsection
11383 Redirecting output on Windows Shells
11386 \begin_layout Standard
11387 By default SDCC writes its error messages to
11388 \begin_inset Quotes sld
11392 \begin_inset Quotes srd
11396 To force all messages to
11397 \begin_inset Quotes sld
11401 \begin_inset Quotes srd
11413 \begin_layout Standard
11428 \begin_inset LatexCommand \index{-\/-use-stdout}
11433 Additionally, if you happen to have visual studio installed in your windows
11434 machine, you can use it to compile your sources using a custom build and
11441 \begin_layout Standard
11453 \begin_inset LatexCommand \index{-\/-vc}
11458 Something like this should work:
11477 \begin_layout Standard
11496 \begin_layout Standard
11508 -model-large -c $(InputPath)
11511 \begin_inset VSpace bigskip
11517 \begin_layout Section
11518 Environment variables
11519 \begin_inset LatexCommand \index{Environment variables}
11526 \begin_layout Standard
11527 SDCC recognizes the following environment variables:
11531 \labelwidthstring 00.00.0000
11535 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11541 SDCC installs a signal handler
11542 \begin_inset LatexCommand \index{signal handler}
11546 to be able to delete temporary files after an user break (^C) or an exception.
11547 If this environment variable is set, SDCC won't install the signal handler
11548 in order to be able to debug SDCC.
11552 \labelwidthstring 00.00.0000
11558 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11564 Path, where temporary files will be created.
11565 The order of the variables is the search order.
11566 In a standard *nix environment these variables are not set, and there's
11567 no need to set them.
11568 On Windows it's recommended to set one of them.
11572 \labelwidthstring 00.00.0000
11576 \begin_inset LatexCommand \index{SDCC\_HOME}
11583 \begin_inset LatexCommand \ref{sub:Install-paths}
11589 \begin_inset Quotes sld
11593 \begin_inset Quotes srd
11600 \labelwidthstring 00.00.0000
11604 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11611 \begin_inset LatexCommand \ref{sub:Search-Paths}
11617 \begin_inset Quotes sld
11621 \begin_inset Quotes srd
11628 \labelwidthstring 00.00.0000
11632 \begin_inset LatexCommand \index{SDCC\_LIB}
11639 \begin_inset LatexCommand \ref{sub:Search-Paths}
11645 \begin_inset Quotes sld
11649 \begin_inset Quotes srd
11655 \begin_layout Standard
11656 There are some more environment variables recognized by SDCC, but these
11657 are solely used for debugging purposes.
11658 They can change or disappear very quickly, and will never be documented.
11659 \begin_inset VSpace bigskip
11665 \begin_layout Section
11666 Storage Class Language Extensions
11669 \begin_layout Subsection
11670 MCS51/DS390 Storage Class
11671 \begin_inset LatexCommand \index{Storage class}
11675 Language Extensions
11678 \begin_layout Standard
11679 In addition to the ANSI storage classes SDCC allows the following MCS51
11680 specific storage classes:
11683 \begin_layout Subsubsection
11685 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11690 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11695 \begin_inset LatexCommand \index{near (storage class)}
11700 \begin_inset LatexCommand \index{\_\_near (storage class)}
11707 \begin_layout Standard
11712 storage class for the Small Memory model (
11720 or the more ANSI-C compliant forms
11728 can be used synonymously).
11729 Variables declared with this storage class will be allocated in the directly
11730 addressable portion of the internal RAM of a 8051, e.g.:
11733 \begin_layout Verse
11736 __data unsigned char test_data;
11739 \begin_layout Standard
11740 Writing 0x01 to this variable generates the assembly code:
11743 \begin_layout Verse
11746 75*00 01\InsetSpace ~
11754 \begin_layout Subsubsection
11756 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11761 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11766 \begin_inset LatexCommand \index{far (storage class)}
11771 \begin_inset LatexCommand \index{\_\_far (storage class)}
11778 \begin_layout Standard
11779 Variables declared with this storage class will be placed in the external
11785 storage class for the Large Memory model, e.g.:
11788 \begin_layout Verse
11791 __xdata unsigned char test_xdata;
11794 \begin_layout Standard
11795 Writing 0x01 to this variable generates the assembly code:
11798 \begin_layout Verse
11801 90s00r00\InsetSpace ~
11832 \begin_layout Subsubsection
11834 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11839 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11846 \begin_layout Standard
11847 Variables declared with this storage class will be allocated into the indirectly
11848 addressable portion of the internal ram of a 8051, e.g.:
11851 \begin_layout Verse
11854 __idata unsigned char test_idata;
11857 \begin_layout Standard
11858 Writing 0x01 to this variable generates the assembly code:
11861 \begin_layout Verse
11888 \begin_layout Standard
11889 Please note, the first 128 byte of idata physically access the same RAM
11890 as the data memory.
11891 The original 8051 had 128 byte idata memory, nowadays most devices have
11892 256 byte idata memory.
11894 \begin_inset LatexCommand \index{stack}
11898 is located in idata memory.
11901 \begin_layout Subsubsection
11903 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11908 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11915 \begin_layout Standard
11916 Paged xdata access is just as straightforward as using the other addressing
11918 It is typically located at the start of xdata and has a maximum size of
11920 The following example writes 0x01 to the pdata variable.
11921 Please note, pdata access physically accesses xdata memory.
11922 The high byte of the address is determined by port P2
11923 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11927 (or in case of some 8051 variants by a separate Special Function Register,
11929 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11938 storage class for the Medium Memory model, e.g.:
11941 \begin_layout Verse
11944 __pdata unsigned char test_pdata;
11947 \begin_layout Standard
11948 Writing 0x01 to this variable generates the assembly code:
11951 \begin_layout Verse
11960 mov r0,#_test_pdata
11982 \begin_layout Standard
11987 \begin_layout Standard
11997 \begin_inset LatexCommand \index{-\/-xstack}
12001 option is used the pdata memory area is followed by the xstack memory area
12002 and the sum of their sizes is limited to 256 bytes.
12005 \begin_layout Subsubsection
12007 \begin_inset LatexCommand \index{code}
12012 \begin_inset LatexCommand \index{\_\_code}
12019 \begin_layout Standard
12020 'Variables' declared with this storage class will be placed in the code
12024 \begin_layout Verse
12027 __code unsigned char test_code;
12030 \begin_layout Standard
12031 Read access to this variable generates the assembly code:
12034 \begin_layout Verse
12037 90s00r6F\InsetSpace ~
12040 mov dptr,#_test_code
12065 \begin_layout Standard
12070 indexed arrays of characters in code memory can be accessed efficiently:
12073 \begin_layout Verse
12076 __code char test_array[] = {'c','h','e','a','p'};
12079 \begin_layout Standard
12080 Read access to this array using an 8-bit unsigned index generates the assembly
12084 \begin_layout Verse
12096 \begin_layout Verse
12099 90s00r41\InsetSpace ~
12102 mov dptr,#_test_array
12105 \begin_layout Verse
12120 \begin_layout Subsubsection
12122 \begin_inset LatexCommand \index{bit}
12127 \begin_inset LatexCommand \index{\_\_bit}
12134 \begin_layout Standard
12135 This is a data-type and a storage class specifier.
12136 When a variable is declared as a bit, it is allocated into the bit addressable
12137 memory of 8051, e.g.:
12140 \begin_layout Verse
12146 \begin_layout Standard
12147 Writing 1 to this variable generates the assembly code:
12150 \begin_layout Verse
12164 \begin_layout Standard
12165 The bit addressable memory consists of 128 bits which are located from 0x20
12166 to 0x2f in data memory.
12169 Apart from this 8051 specific storage class most architectures support
12171 \begin_inset LatexCommand \index{bitfields}
12179 \begin_layout Standard
12180 Not really meant as examples, but nevertheless showing what bitfields are
12181 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12187 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12188 signed modifier are implemented as unsigned.
12191 \begin_layout Subsubsection
12193 \begin_inset LatexCommand \index{sfr}
12198 \begin_inset LatexCommand \index{\_\_sfr}
12203 \begin_inset LatexCommand \index{sfr16}
12208 \begin_inset LatexCommand \index{\_\_sfr16}
12213 \begin_inset LatexCommand \index{sfr32}
12218 \begin_inset LatexCommand \index{\_\_sfr32}
12223 \begin_inset LatexCommand \index{\_\_sbit}
12228 \begin_inset LatexCommand \index{sbit}
12235 \begin_layout Standard
12236 Like the bit keyword,
12238 sfr / sfr16 / sfr32 / sbit
12240 signify both a data-type and storage class, they are used to describe the
12261 variables of a 8051, eg:
12264 \begin_layout Verse
12268 \begin_inset LatexCommand \index{at}
12273 \begin_inset LatexCommand \index{\_\_at}
12277 (0x80) P0;\InsetSpace ~
12278 /* special function register P0 at location 0x80 */
12283 special function register combination for timer 0
12287 with the high byte at
12288 location 0x8C and the low byte at location 0x8A */
12290 __sfr16 __at (0x8C8A)
12296 \begin_inset LatexCommand \index{at}
12301 \begin_inset LatexCommand \index{\_\_at}
12305 (0xd7) CY;\InsetSpace ~
12307 \begin_inset LatexCommand \index{Flags}
12312 \begin_inset LatexCommand \index{Carry flag}
12319 \begin_layout Standard
12320 Special function registers which are located on an address dividable by
12321 8 are bit-addressable, an
12325 addresses a specific bit within these sfr.
12327 16 Bit and 32 bit special function
12328 register combinations which require a certain access order are better not
12338 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12339 this is not guaranteed.
12344 \begin_layout Standard
12345 Please note, if you use a header file which was written for another compiler
12346 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
12352 Specifically the syntax
12355 sfr P0 = 0x80;\InsetSpace ~
12362 by SDCC to an assignment of 0x80 to a variable called P0
12365 \begin_inset Marginal
12368 \begin_layout Standard
12380 Nevertheless it is possible to write header files
12381 \begin_inset LatexCommand \index{Header files}
12386 \begin_inset LatexCommand \index{Include files}
12390 which can be shared among different compilers (see section
12391 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
12399 \begin_layout Subsubsection
12401 \begin_inset LatexCommand \index{Pointer}
12405 to MCS51/DS390 specific memory spaces
12408 \begin_layout Standard
12409 SDCC allows (via language extensions) pointers to explicitly point to any
12410 of the memory spaces
12411 \begin_inset LatexCommand \index{Memory model}
12416 In addition to the explicit pointers, the compiler uses (by default) generic
12417 pointers which can be used to point to any of the memory spaces.
12422 declaration examples:
12425 \begin_layout Verse
12428 /* pointer physically in internal ram pointing to object in external ram
12431 __xdata unsigned char * __data p;
12435 /* pointer physically in external ram
12436 pointing to object in internal ram */
12438 __data unsigned char * __xdata p;
12443 pointer physically in code rom pointing to data in xdata space */
12446 unsigned char * __code p;
12450 /* pointer physically in code space pointing to
12451 data in code space */
12453 __code unsigned char * __code p;
12458 physically located in xdata space */
12460 unsigned char * __xdata p;
12465 pointer physically located in default memory space */
12472 the following is a function pointer
12473 \begin_inset LatexCommand \index{function pointer}
12477 physically located in data space */
12479 char (* __data fp)(void);
12482 \begin_layout Standard
12483 Well you get the idea.
12488 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
12501 The highest order byte of the
12505 pointers contains the data space information.
12506 Assembler support routines are called whenever data is stored or retrieved
12512 These are useful for developing reusable library
12513 \begin_inset LatexCommand \index{Libraries}
12518 Explicitly specifying the pointer
12519 \begin_inset LatexCommand \index{pointer}
12523 type will generate the most efficient code.
12526 \begin_layout Subsubsection
12527 Notes on MCS51 memory
12528 \begin_inset LatexCommand \index{MCS51 memory}
12535 \begin_layout Standard
12536 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12537 RAM memory which is structured as follows:
12541 - Bytes 00-1F - 32 bytes to hold
12542 up to 4 banks of the registers R0 to R7,
12544 - Bytes 20-2F - 16 bytes to hold
12546 \begin_inset LatexCommand \index{bit}
12552 - Bytes 30-7F - 80 bytes for general purpose use.
12557 \begin_layout Standard
12558 Additionally some members of the MCS51 family may have up to 128 bytes of
12559 additional, indirectly addressable, internal RAM memory (
12564 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12569 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12574 Furthermore, some chips may have some built in external memory (
12579 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12584 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12588 ) which should not be confused with the internal, directly addressable RAM
12594 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12599 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12604 Sometimes this built in
12608 memory has to be activated before using it (you can probably find this
12609 information on the datasheet of the microcontroller your are using, see
12611 \begin_inset LatexCommand \ref{sub:Startup-Code}
12619 \begin_layout Standard
12620 Normally SDCC will only use the first bank
12621 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12625 of registers (register bank 0), but it is possible to specify that other
12626 banks of registers (keyword
12633 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12638 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12644 ) should be used for example in interrupt
12645 \begin_inset LatexCommand \index{interrupt}
12650 \begin_inset LatexCommand \index{\_\_interrupt}
12655 By default, the compiler will place the stack after the last byte of allocated
12656 memory for variables.
12657 For example, if the first 2 banks of registers are used, and only four
12662 variables, it will position the base of the internal stack at address 20
12664 This implies that as the stack
12665 \begin_inset LatexCommand \index{stack}
12669 grows, it will use up the remaining register banks, and the 16 bytes used
12670 by the 128 bit variables, and 80 bytes for general purpose use.
12671 If any bit variables are used, the data variables will be placed in unused
12672 register banks and after the byte holding the last bit variable.
12673 For example, if register banks 0 and 1 are used, and there are 9 bit variables
12678 variables will be placed starting from address 0x10 to 0x20 and continue
12684 \begin_layout Standard
12694 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12698 to specify the start address of the
12706 \begin_layout Standard
12716 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12720 to specify the size of the total internal RAM (
12734 \begin_layout Standard
12735 By default the 8051 linker will place the stack after the last byte of (i)data
12741 \begin_layout Standard
12751 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12755 allows you to specify the start of the stack, i.e.
12756 you could start it after any data in the general purpose area.
12757 If your microcontroller has additional indirectly addressable internal
12762 ) you can place the stack on it.
12763 You may also need to use -
12767 \begin_layout Standard
12777 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12781 to set the start address of the external RAM (
12789 \begin_layout Standard
12799 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12803 to specify its size.
12804 Same goes for the code memory, using -
12808 \begin_layout Standard
12818 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12826 \begin_layout Standard
12836 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12841 If in doubt, don't specify any options and see if the resulting memory
12842 layout is appropriate, then you can adjust it.
12845 \begin_layout Standard
12846 The linker generates two files with memory allocation information.
12847 The first, with extension .map
12848 \begin_inset LatexCommand \index{<file>.map}
12852 shows all the variables and segments.
12853 The second with extension .mem
12854 \begin_inset LatexCommand \index{<file>.mem}
12858 shows the final memory layout.
12859 The linker will complain either if memory segments overlap, there is not
12860 enough memory, or there is not enough space for stack.
12861 If you get any linking warnings and/or errors related to stack or segments
12862 allocation, take a look at either the .map or .mem files to find out what
12864 The .mem file may even suggest a solution to the problem.
12865 \begin_inset VSpace bigskip
12871 \begin_layout Subsection
12872 Z80/Z180 Storage Class
12873 \begin_inset LatexCommand \index{Z80!Storage class}
12877 Language Extensions
12880 \begin_layout Subsubsection
12882 \begin_inset LatexCommand \index{sfr}
12887 \begin_inset LatexCommand \index{\_\_sfr}
12891 (in/out to 8-bit addresses)
12894 \begin_layout Standard
12896 \begin_inset LatexCommand \index{Z80}
12900 family has separate address spaces for memory and
12910 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12915 \begin_inset LatexCommand \index{Z80!I/O memory}
12920 \begin_inset LatexCommand \index{Z180!I/O memory}
12924 is accessed with special instructions, e.g.:
12927 \begin_layout Verse
12930 sfr at 0x78 IoPort;\InsetSpace ~
12932 /* define a var in I/O space at 78h called IoPort */
12936 \begin_layout Standard
12937 Writing 0x01 to this variable generates the assembly code:
12940 \begin_layout Verse
12960 \begin_layout Subsubsection
12962 \begin_inset LatexCommand \index{sfr}
12967 \begin_inset LatexCommand \index{\_\_sfr}
12971 (in/out to 16-bit addresses)
12974 \begin_layout Standard
12979 is used to support 16 bit addresses in I/O memory e.g.:
12982 \begin_layout Verse
12986 \begin_inset LatexCommand \index{at}
12991 \begin_inset LatexCommand \index{\_\_at}
12998 \begin_layout Standard
12999 Writing 0x01 to this variable generates the assembly code:
13002 \begin_layout Verse
13005 01 23 01\InsetSpace ~
13027 \begin_layout Subsubsection
13029 \begin_inset LatexCommand \index{sfr}
13034 \begin_inset LatexCommand \index{\_\_sfr}
13038 (in0/out0 to 8 bit addresses on Z180
13039 \begin_inset LatexCommand \index{Z180}
13044 \begin_inset LatexCommand \index{HD64180 (see Z180)}
13051 \begin_layout Standard
13052 The compiler option -
13056 \begin_layout Standard
13066 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
13070 =180 (80) and a compiler #pragma\InsetSpace ~
13072 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
13076 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
13086 If you include the file z180.h this will be set automatically.
13087 \begin_inset VSpace bigskip
13093 \begin_layout Subsection
13095 \begin_inset LatexCommand \index{HC08!Storage class}
13099 Language Extensions
13102 \begin_layout Subsubsection
13104 \begin_inset LatexCommand \index{data (hc08 storage class)}
13109 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
13116 \begin_layout Standard
13117 The data storage class declares a variable that resides in the first 256
13118 bytes of memory (the direct page).
13120 \begin_inset LatexCommand \index{HC08}
13124 is most efficient at accessing variables (especially pointers) stored here.
13127 \begin_layout Subsubsection
13129 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
13134 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
13141 \begin_layout Standard
13142 The xdata storage class declares a variable that can reside anywhere in
13144 This is the default if no storage class is specified.
13146 \begin_inset VSpace bigskip
13152 \begin_layout Section
13153 Absolute Addressing
13154 \begin_inset LatexCommand \index{Absolute addressing}
13161 \begin_layout Standard
13162 Data items can be assigned an absolute address with the
13165 \begin_inset LatexCommand \index{at}
13170 \begin_inset LatexCommand \index{\_\_at}
13176 keyword, in addition to a storage class, e.g.:
13179 \begin_layout Verse
13183 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13188 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
13193 \begin_inset LatexCommand \index{at}
13198 \begin_inset LatexCommand \index{\_\_at}
13202 0x7ffe unsigned int chksum;
13205 \begin_layout Standard
13206 or, better conforming to ISO/IEC 9899 C:
13209 \begin_layout Verse
13212 __xdata __at (0x7ffe) unsigned int chksum;
13215 \begin_layout Standard
13216 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
13217 of the external ram.
13222 reserve any space for variables declared in this way
13223 \begin_inset Marginal
13226 \begin_layout Standard
13235 (they are implemented with an equate in the assembler).
13236 Thus it is left to the programmer to make sure there are no overlaps with
13237 other variables that are declared without the absolute address.
13238 The assembler listing file (.lst
13239 \begin_inset LatexCommand \index{<file>.lst}
13243 ) and the linker output files (.rst
13244 \begin_inset LatexCommand \index{<file>.rst}
13249 \begin_inset LatexCommand \index{<file>.map}
13253 ) are good places to look for such overlaps.
13256 \begin_layout Standard
13257 If however you provide an initializer
13258 \begin_inset LatexCommand \index{Variable initialization}
13262 actual memory allocation will take place and overlaps will be detected
13267 \begin_layout Verse
13270 __code __at (0x7ff0) char Id[5] =
13271 \begin_inset Quotes sld
13275 \begin_inset Quotes srd
13281 \begin_layout Standard
13282 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
13286 \begin_layout Standard
13287 In case of memory mapped I/O devices the keyword
13291 has to be used to tell the compiler that accesses might not be removed:
13294 \begin_layout Verse
13298 \begin_inset LatexCommand \index{volatile}
13303 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13308 \begin_inset LatexCommand \index{at}
13312 (0x8000) unsigned char PORTA_8255;
13315 \begin_layout Standard
13316 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
13321 \begin_inset LatexCommand \index{Aligned array}
13328 starts at a block (256 byte) boundary
13329 \begin_inset LatexCommand \index{block boundary}
13334 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13340 Absolute addresses can be specified for variables in all
13341 storage classes, e.g.:
13344 \begin_layout Verse
13348 \begin_inset LatexCommand \index{bit}
13353 \begin_inset LatexCommand \index{at}
13360 \begin_layout Standard
13361 The above example will allocate the variable at offset 0x02 in the bit-addressab
13363 There is no real advantage to assigning absolute addresses to variables
13364 in this manner, unless you want strict control over all the variables allocated.
13365 One possible use would be to write hardware portable code.
13366 For example, if you have a routine that uses one or more of the microcontroller
13367 I/O pins, and such pins are different for two different hardwares, you
13368 can declare the I/O pins in your routine using:
13371 \begin_layout Verse
13375 \begin_inset LatexCommand \index{volatile}
13379 __bit MOSI;\InsetSpace ~
13383 /* master out, slave in */
13385 extern volatile __bit MISO;\InsetSpace ~
13392 extern volatile __bit MCLK;\InsetSpace ~
13401 Output of a byte on a 3-wire serial bus.
13406 If needed adapt polarity of clock,
13407 polarity of data and bit order
13412 unsigned char spi_io(unsigned char out_byte)
13437 MOSI = out_byte & 0x80;
13468 /* _asm nop _endasm; */\InsetSpace ~
13476 /* for slow peripherals */
13528 \begin_layout Standard
13529 Then, someplace in the code for the first hardware you would use
13532 \begin_layout Verse
13536 \begin_inset LatexCommand \index{at}
13541 \begin_inset LatexCommand \index{\_\_at}
13545 (0x80) MOSI;\InsetSpace ~
13549 /* I/O port 0, bit 0 */
13551 __bit __at (0x81) MISO;\InsetSpace ~
13558 __bit __at (0x82) MCLK;\InsetSpace ~
13562 /* I/O port 0, bit 2 */
13565 \begin_layout Standard
13566 Similarly, for the second hardware you would use
13569 \begin_layout Verse
13572 __bit __at (0x83) MOSI;\InsetSpace ~
13576 /* I/O port 0, bit 3 */
13578 __bit __at (0x91) MISO;\InsetSpace ~
13583 I/O port 1, bit 1 */
13586 \begin_inset LatexCommand \index{bit}
13590 __at (0x92) MCLK;\InsetSpace ~
13594 /* I/O port 1, bit 2 */
13597 \begin_layout Standard
13598 and you can use the same hardware dependent routine without changes, as
13599 for example in a library.
13600 This is somehow similar to sbit, but only one absolute address has to be
13601 specified in the whole project.
13602 \begin_inset VSpace bigskip
13608 \begin_layout Section
13610 \begin_inset LatexCommand \index{Parameters}
13615 \begin_inset LatexCommand \index{function parameter}
13620 \begin_inset LatexCommand \index{local variables}
13625 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13632 \begin_layout Standard
13633 Automatic (local) variables and parameters to functions can either be placed
13634 on the stack or in data-space.
13635 The default action of the compiler is to place these variables in the internal
13636 RAM (for small model) or external RAM (for medium or large model).
13637 This in fact makes them similar to
13640 \begin_inset LatexCommand \index{static}
13646 so by default functions are non-reentrant
13647 \begin_inset LatexCommand \index{reentrant}
13656 They can be placed on the stack
13657 \begin_inset LatexCommand \index{stack}
13667 \begin_layout Standard
13677 \begin_inset LatexCommand \index{-\/-stack-auto}
13685 #pragma\InsetSpace ~
13689 \begin_inset LatexCommand \index{\#pragma stackauto}
13696 \begin_inset LatexCommand \index{reentrant}
13702 keyword in the function declaration, e.g.:
13705 \begin_layout Verse
13708 unsigned char foo(char i) __reentrant
13722 \begin_layout Standard
13723 Since stack space on 8051 is limited, the
13733 \begin_layout Standard
13744 option should be used sparingly.
13745 Note that the reentrant keyword just means that the parameters & local
13746 variables will be allocated to the stack, it
13750 mean that the function is register bank
13751 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13760 \begin_inset LatexCommand \index{local variables}
13764 can be assigned storage classes and absolute
13765 \begin_inset LatexCommand \index{Absolute addressing}
13772 \begin_layout Verse
13775 unsigned char foo()
13783 __xdata unsigned char i;
13796 \begin_inset LatexCommand \index{at}
13800 (0x31) unsigned char j;
13812 \begin_layout Standard
13813 In the above example the variable
13817 will be allocated in the external ram,
13821 in bit addressable space and
13832 \begin_layout Standard
13843 or when a function is declared as
13847 this should only be done for static variables.
13850 \begin_layout Standard
13852 \begin_inset LatexCommand \index{function parameter}
13856 however are not allowed any storage class
13857 \begin_inset LatexCommand \index{Storage class}
13861 , (storage classes for parameters will be ignored), their allocation is
13862 governed by the memory model in use, and the reentrancy options.
13865 \begin_layout Standard
13866 It is however allowed to use bit parameters in reentrant functions and also
13867 non-static local bit variables are supported.
13868 Efficient use is limited to 8 semi-bitregisters in bit space.
13869 They are pushed and popped to stack
13870 \begin_inset LatexCommand \index{stack}
13874 as a single byte just like the normal registers.
13877 \begin_layout Section
13879 \begin_inset LatexCommand \label{sub:Overlaying}
13884 \begin_inset LatexCommand \index{Overlaying}
13891 \begin_layout Standard
13893 \begin_inset LatexCommand \index{reentrant}
13897 functions SDCC will try to reduce internal ram space usage by overlaying
13898 parameters and local variables of a function (if possible).
13899 Parameters and local variables
13900 \begin_inset LatexCommand \index{local variables}
13904 of a function will be allocated to an overlayable segment if the function
13907 no other function calls and the function is non-reentrant and the memory
13909 \begin_inset LatexCommand \index{Memory model}
13916 If an explicit storage class
13917 \begin_inset LatexCommand \index{Storage class}
13921 is specified for a local variable, it will NOT be overlayed.
13924 \begin_layout Standard
13925 Note that the compiler (not the linkage editor) makes the decision for overlayin
13927 Functions that are called from an interrupt service routine
13928 \begin_inset Marginal
13931 \begin_layout Standard
13939 should be preceded by a #pragma\InsetSpace ~
13941 \begin_inset LatexCommand \index{\#pragma nooverlay}
13945 if they are not reentrant.
13948 \begin_layout Standard
13949 Also note that the compiler does not do any processing of inline assembler
13950 code, so the compiler might incorrectly assign local variables and parameters
13951 of a function into the overlay segment if the inline assembler code calls
13952 other c-functions that might use the overlay.
13953 In that case the #pragma\InsetSpace ~
13954 nooverlay should be used.
13957 \begin_layout Standard
13958 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13960 \begin_inset LatexCommand \index{Multiplication}
13965 \begin_inset LatexCommand \index{Division}
13969 will NOT be overlayed since these are implemented using external functions,
13973 \begin_layout Verse
13979 \begin_inset LatexCommand \index{\#pragma nooverlay}
13985 void set_error(unsigned char errcd)
14002 some_isr () __interrupt
14003 \begin_inset LatexCommand \index{interrupt}
14033 \begin_layout Standard
14034 In the above example the parameter
14042 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
14044 not present, this could cause unpredictable runtime behavior when called
14045 from an interrupt service routine.
14046 The #pragma\InsetSpace ~
14047 nooverlay ensures that the parameters and local variables for
14048 the function are NOT overlayed.
14049 \begin_inset VSpace bigskip
14055 \begin_layout Section
14056 Interrupt Service Routines
14057 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
14064 \begin_layout Subsection
14065 General Information
14068 \begin_layout Standard
14081 outines to be coded in C, with some extended keywords.
14084 \begin_layout Verse
14087 void timer_isr (void) __interrupt (1) __using (1)
14101 \begin_layout Standard
14102 The optional number following the
14105 \begin_inset LatexCommand \index{interrupt}
14110 \begin_inset LatexCommand \index{\_\_interrupt}
14116 keyword is the interrupt number this routine will service.
14117 When present, the compiler will insert a call to this routine in the interrupt
14119 \begin_inset LatexCommand \index{interrupt vector table}
14123 for the interrupt number specified.
14124 If you have multiple source files in your project, interrupt service routines
14125 can be present in any of them, but a prototype of the isr MUST be present
14126 or included in the file that contains the function
14131 The optional (8051 specific) keyword
14134 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14139 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14145 can be used to tell the compiler to use the specified register bank when
14146 generating code for this function.
14149 Interrupt service routines open the door for some very interesting bugs:
14152 \begin_layout Subsubsection
14153 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
14157 Common interrupt pitfall: variable not declared
14162 \begin_layout Standard
14163 If an interrupt service routine changes variables which are accessed by
14164 other functions these variables have to be declared
14169 \begin_inset LatexCommand \index{volatile}
14175 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
14182 \begin_layout Subsubsection
14183 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
14187 Common interrupt pitfall:
14192 \begin_layout Standard
14193 If the access to these variables is not
14196 \begin_inset LatexCommand \index{atomic}
14203 the processor needs more than one instruction for the access and could
14204 be interrupted while accessing the variable) the interrupt must be disabled
14205 during the access to avoid inconsistent data.
14208 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
14209 and should be protected by disabling interrupts.
14210 You're not automatically on the safe side if you use 8 bit variables though.
14211 We need an example here: f.e.
14212 on the 8051 the harmless looking
14213 \begin_inset Quotes srd
14223 \begin_inset Quotes sld
14232 \begin_inset Quotes srd
14242 \begin_inset Quotes sld
14245 from within an interrupt routine might get lost if the interrupt occurs
14248 \begin_inset Quotes sld
14253 counter\InsetSpace ~
14258 \begin_inset Quotes srd
14261 is not atomic on the 8051 even if
14265 is located in data memory.
14267 Bugs like these are hard to reproduce and can
14268 cause a lot of trouble.
14272 \begin_layout Subsubsection
14273 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
14277 Common interrupt pitfall:
14282 \begin_layout Standard
14283 The return address and the registers used in the interrupt service routine
14284 are saved on the stack
14285 \begin_inset LatexCommand \index{stack}
14289 so there must be sufficient stack space.
14290 If there isn't variables or registers (or even the return address itself)
14297 \begin_inset LatexCommand \index{stack overflow}
14301 is most likely to happen if the interrupt occurs during the
14302 \begin_inset Quotes sld
14306 \begin_inset Quotes srd
14309 subroutine when the stack is already in use for f.e.
14310 many return addresses.
14313 \begin_layout Subsubsection
14314 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
14318 Common interrupt pitfall:
14320 use of non-reentrant functions
14323 \begin_layout Standard
14324 A special note here, int (16 bit) and long (32 bit) integer division
14325 \begin_inset LatexCommand \index{Division}
14330 \begin_inset LatexCommand \index{Multiplication}
14335 \begin_inset LatexCommand \index{Modulus}
14340 \begin_inset LatexCommand \index{Floating point support}
14344 operations are implemented using external support routines.
14345 If an interrupt service routine needs to do any of these operations then
14346 the support routines (as mentioned in a following section) will have to
14347 be recompiled using the
14353 \begin_layout Standard
14363 \begin_inset LatexCommand \index{-\/-stack-auto}
14369 option and the source file will need to be compiled using the
14375 \begin_layout Standard
14387 \begin_inset LatexCommand \index{-\/-int-long-reent}
14394 Note, the type promotion
14395 \begin_inset LatexCommand \index{type promotion}
14399 required by ANSI C can cause 16 bit routines to be used
14400 \begin_inset Marginal
14403 \begin_layout Standard
14412 without the programmer being aware of it.
14416 (unsigned char)(tail-1)
14418 within the if clause in section
14419 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
14426 \begin_layout Standard
14427 Calling other functions from an interrupt service routine is not recommended,
14428 avoid it if possible.
14429 Note that when some function is called from an interrupt service routine
14430 it should be preceded by a #pragma\InsetSpace ~
14432 \begin_inset LatexCommand \index{\#pragma nooverlay}
14436 if it is not reentrant.
14437 Furthermore nonreentrant functions should not be called from the main program
14438 while the interrupt service routine might be active.
14439 They also must not be called from low priority interrupt service routines
14440 while a high priority interrupt service routine might be active.
14441 You could use semaphores or make the function
14445 if all parameters are passed in registers.
14448 \begin_inset LatexCommand \ref{sub:Overlaying}
14453 about Overlaying and section
14454 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14459 about Functions using private register banks.
14460 \begin_inset VSpace bigskip
14466 \begin_layout Subsection
14467 MCS51/DS390 Interrupt Service Routines
14470 \begin_layout Standard
14472 \begin_inset LatexCommand \index{interrupt}
14476 numbers and the corresponding address & descriptions for the Standard 8051/8052
14478 SDCC will automatically adjust the
14479 \begin_inset LatexCommand \index{interrupt vector table}
14483 to the maximum interrupt number specified.
14488 \begin_layout Standard
14490 \begin_inset Tabular
14491 <lyxtabular version="3" rows="9" columns="3">
14493 <column alignment="center" valignment="top" leftline="true" width="0in">
14494 <column alignment="left" valignment="top" leftline="true" width="0in">
14495 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14496 <row topline="true" bottomline="true">
14497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14500 \begin_layout Standard
14506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14509 \begin_layout Standard
14515 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14518 \begin_layout Standard
14525 <row topline="true">
14526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14529 \begin_layout Standard
14535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14538 \begin_layout Standard
14544 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14547 \begin_layout Standard
14554 <row topline="true">
14555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14558 \begin_layout Standard
14564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14567 \begin_layout Standard
14573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14576 \begin_layout Standard
14583 <row topline="true">
14584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14587 \begin_layout Standard
14593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14596 \begin_layout Standard
14602 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14605 \begin_layout Standard
14612 <row topline="true">
14613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14616 \begin_layout Standard
14622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14625 \begin_layout Standard
14631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14634 \begin_layout Standard
14641 <row topline="true">
14642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14645 \begin_layout Standard
14651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14654 \begin_layout Standard
14660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14663 \begin_layout Standard
14670 <row topline="true">
14671 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14674 \begin_layout Standard
14680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14683 \begin_layout Standard
14689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14692 \begin_layout Standard
14699 <row topline="true">
14700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14703 \begin_layout Standard
14709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14712 \begin_layout Standard
14718 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14721 \begin_layout Standard
14728 <row topline="true" bottomline="true">
14729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14732 \begin_layout Standard
14738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14741 \begin_layout Standard
14747 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14750 \begin_layout Standard
14766 \begin_layout Standard
14767 If the interrupt service routine is defined without
14770 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14775 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14781 a register bank or with register bank 0 (
14785 0), the compiler will save the registers used by itself on the stack upon
14786 entry and restore them at exit, however if such an interrupt service routine
14787 calls another function then the entire register bank will be saved on the
14789 This scheme may be advantageous for small interrupt service routines which
14790 have low register usage.
14793 \begin_layout Standard
14794 If the interrupt service routine is defined to be using a specific register
14799 & psw are saved and restored, if such an interrupt service routine calls
14800 another function (using another register bank) then the entire register
14801 bank of the called function will be saved on the stack
14802 \begin_inset LatexCommand \index{stack}
14807 This scheme is recommended for larger interrupt service routines.
14808 \begin_inset VSpace bigskip
14814 \begin_layout Subsection
14816 \begin_inset LatexCommand \index{HC08}
14820 Interrupt Service Routines
14823 \begin_layout Standard
14824 Since the number of interrupts
14825 \begin_inset LatexCommand \index{HC08!interrupt}
14829 available is chip specific and the interrupt vector table always ends at
14830 the last byte of memory, the interrupt numbers corresponds to the interrupt
14831 vectors in reverse order of address.
14832 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14833 2 will use the interrupt vector at 0xfffa, and so on.
14834 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14835 this way; instead see section
14836 \begin_inset LatexCommand \ref{sub:Startup-Code}
14840 for details on customizing startup.
14841 \begin_inset VSpace bigskip
14847 \begin_layout Subsection
14848 Z80 Interrupt Service Routines
14851 \begin_layout Standard
14853 \begin_inset LatexCommand \index{Z80}
14857 uses several different methods for determining the correct interrupt
14858 \begin_inset LatexCommand \index{Z80!interrupt}
14862 vector depending on the hardware implementation.
14863 Therefore, SDCC ignores the optional interrupt number and does not attempt
14864 to generate an interrupt vector table.
14867 \begin_layout Standard
14868 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14869 instruction to return from the interrupt.
14870 To write an interrupt handler for the non-maskable interrupt, which needs
14871 a RETN instruction instead, add the
14878 \begin_layout Verse
14881 void nmi_isr (void) critical interrupt
14895 \begin_layout Standard
14896 However if you need to create a non-interruptable interrupt service routine
14897 you would also require the
14902 To distinguish between this and an nmi_isr you must provide an interrupt
14904 \begin_inset VSpace bigskip
14910 \begin_layout Section
14911 Enabling and Disabling Interrupts
14914 \begin_layout Subsection
14915 Critical Functions and Critical Statements
14918 \begin_layout Standard
14919 A special keyword may be associated with a block or a function declaring
14925 SDCC will generate code to disable all interrupts
14926 \begin_inset LatexCommand \index{interrupt}
14930 upon entry to a critical function and restore the interrupt enable to the
14931 previous state before returning.
14932 Nesting critical functions will need one additional byte on the stack
14933 \begin_inset LatexCommand \index{stack}
14940 \begin_layout Verse
14943 int foo () __critical
14944 \begin_inset LatexCommand \index{critical}
14949 \begin_inset LatexCommand \index{\_\_critical}
14974 \begin_layout Standard
14975 The critical attribute maybe used with other attributes like
14985 may also be used to disable interrupts more locally:
14988 \begin_layout Verse
14994 \begin_layout Standard
14995 More than one statement could have been included in the block.
14998 \begin_layout Subsection
14999 Enabling and Disabling Interrupts directly
15002 \begin_layout Standard
15004 \begin_inset LatexCommand \index{interrupt}
15008 can also be disabled and enabled directly (8051):
15011 \begin_layout Verse
15014 EA = 0;\InsetSpace ~
15040 \begin_layout Verse
15076 \begin_layout Verse
15079 EA = 1;\InsetSpace ~
15108 \begin_layout Verse
15147 \begin_layout Standard
15148 On other architectures which have seperate opcodes for enabling and disabling
15149 interrupts you might want to make use of defines with inline assembly
15150 \begin_inset LatexCommand \index{Assembler routines}
15155 \begin_inset LatexCommand \index{HC08!interrupt}
15162 \begin_layout Verse
15166 \begin_inset LatexCommand \index{\_asm}
15175 \begin_inset LatexCommand \index{\_endasm}
15182 \begin_layout Verse
15185 #define SEI _asm\InsetSpace ~
15192 \begin_layout Verse
15198 \begin_layout Standard
15199 Note: it is sometimes sufficient to disable only a specific interrupt source
15201 a timer or serial interrupt by manipulating an
15204 \begin_inset LatexCommand \index{interrupt mask}
15214 \begin_layout Standard
15215 Usually the time during which interrupts are disabled should be kept as
15217 This minimizes both
15222 \begin_inset LatexCommand \index{interrupt latency}
15226 (the time between the occurrence of the interrupt and the execution of
15227 the first code in the interrupt routine) and
15232 \begin_inset LatexCommand \index{interrupt jitter}
15236 (the difference between the shortest and the longest interrupt latency).
15237 These really are something different, f.e.
15238 a serial interrupt has to be served before its buffer overruns so it cares
15239 for the maximum interrupt latency, whereas it does not care about jitter.
15240 On a loudspeaker driven via a digital to analog converter which is fed
15241 by an interrupt a latency of a few milliseconds might be tolerable, whereas
15242 a much smaller jitter will be very audible.
15245 \begin_layout Standard
15246 You can reenable interrupts within an interrupt routine and on some architecture
15247 s you can make use of two (or more) levels of
15249 interrupt priorities
15252 \begin_inset LatexCommand \index{interrupt priority}
15257 On some architectures which don't support interrupt priorities these can
15258 be implemented by manipulating the interrupt mask and reenabling interrupts
15259 within the interrupt routine.
15260 Check there is sufficient space on the stack
15261 \begin_inset LatexCommand \index{stack}
15265 and don't add complexity unless you have to.
15269 \begin_layout Subsection
15271 \begin_inset LatexCommand \index{semaphore}
15275 locking (mcs51/ds390)
15278 \begin_layout Standard
15279 Some architectures (mcs51/ds390) have an atomic
15280 \begin_inset LatexCommand \index{atomic}
15293 These type of instructions are typically used in preemptive multitasking
15294 systems, where a routine f.e.
15295 claims the use of a data structure ('acquires a lock
15296 \begin_inset LatexCommand \index{lock}
15300 on it'), makes some modifications and then releases the lock when the data
15301 structure is consistent again.
15302 The instruction may also be used if interrupt and non-interrupt code have
15303 to compete for a resource.
15304 With the atomic bit test and clear instruction interrupts
15305 \begin_inset LatexCommand \index{interrupt}
15309 don't have to be disabled for the locking operation.
15313 \begin_layout Standard
15314 SDCC generates this instruction if the source follows this pattern:
15317 \begin_layout Verse
15321 \begin_inset LatexCommand \index{volatile}
15325 bit resource_is_free;
15329 if (resource_is_free)
15339 resource_is_free=0;
15352 resource_is_free=1;
15359 \begin_layout Standard
15360 Note, mcs51 and ds390 support only an atomic
15361 \begin_inset LatexCommand \index{atomic}
15369 instruction (as opposed to atomic bit test and
15374 \begin_layout Section
15375 Functions using private register banks
15376 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
15383 \begin_layout Standard
15384 Some architectures have support for quickly changing register sets.
15385 SDCC supports this feature with the
15388 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
15393 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
15399 attribute (which tells the compiler to use a register bank
15400 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
15404 other than the default bank zero).
15405 It should only be applied to
15408 \begin_inset LatexCommand \index{interrupt}
15414 functions (see footnote below).
15415 This will in most circumstances make the generated ISR code more efficient
15416 since it will not have to save registers on the stack.
15419 \begin_layout Standard
15424 attribute will have no effect on the generated code for a
15428 function (but may occasionally be useful anyway
15432 \begin_layout Standard
15433 possible exception: if a function is called ONLY from 'interrupt' functions
15434 using a particular bank, it can be declared with the same 'using' attribute
15435 as the calling 'interrupt' functions.
15436 For instance, if you have several ISRs using bank one, and all of them
15437 call memcpy(), it might make sense to create a specialized version of memcpy()
15438 'using 1', since this would prevent the ISR from having to save bank zero
15439 to the stack on entry and switch to bank zero before calling the function
15448 (pending: Note, nowadays the
15452 attribute has an effect on
15456 the generated code for a
15467 \begin_layout Standard
15472 function using a non-zero bank will assume that it can trash that register
15473 bank, and will not save it.
15474 Since high-priority interrupts
15475 \begin_inset LatexCommand \index{interrupts}
15480 \begin_inset LatexCommand \index{interrupt priority}
15484 can interrupt low-priority ones on the 8051 and friends, this means that
15485 if a high-priority ISR
15489 a particular bank occurs while processing a low-priority ISR
15493 the same bank, terrible and bad things can happen.
15494 To prevent this, no single register bank should be
15498 by both a high priority and a low priority ISR.
15499 This is probably most easily done by having all high priority ISRs use
15500 one bank and all low priority ISRs use another.
15501 If you have an ISR which can change priority at runtime, you're on your
15502 own: I suggest using the default bank zero and taking the small performance
15506 \begin_layout Standard
15507 It is most efficient if your ISR calls no other functions.
15508 If your ISR must call other functions, it is most efficient if those functions
15509 use the same bank as the ISR (see note 1 below); the next best is if the
15510 called functions use bank zero.
15511 It is very inefficient to call a function using a different, non-zero bank
15514 \begin_inset VSpace bigskip
15520 \begin_layout Section
15522 \begin_inset LatexCommand \label{sub:Startup-Code}
15527 \begin_inset LatexCommand \index{Startup code}
15534 \begin_layout Subsection
15535 MCS51/DS390 Startup Code
15538 \begin_layout Standard
15539 The compiler triggers the linker to link certain initialization modules
15540 from the runtime library
15541 \begin_inset LatexCommand \index{Runtime library}
15545 called crt<something>.
15546 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15547 GSINIT5) is not linked unless the -
15553 \begin_layout Standard
15564 -xstack option is used.
15565 These modules are highly entangled by the use of special segments/areas,
15566 but a common layout is shown below:
15569 \begin_layout Verse
15577 \begin_layout Verse
15601 ljmp __sdcc_gsinit_startup
15604 \begin_layout Verse
15612 \begin_layout Verse
15624 .area GSINIT0 (CODE)
15626 __sdcc_gsinit_startup::
15636 mov sp,#__start__stack - 1
15639 \begin_layout Verse
15647 \begin_layout Verse
15659 .area GSINIT1 (CODE)
15661 __sdcc_init_xstack::
15663 ; Need to initialize in GSINIT1 in
15664 case the user's __sdcc_external_startup uses the xstack.
15674 mov __XPAGE,#(__start__x
15685 mov _spx,#__start__xstack
15688 \begin_layout Verse
15696 \begin_layout Verse
15708 .area GSINIT2 (CODE)
15718 lcall __sdcc_external_startup
15738 jz __sdcc_init_data
15749 __sdcc_program_startup
15754 \begin_layout Verse
15762 \begin_layout Verse
15774 .area GSINIT3 (CODE)
15827 mov r2,#((l_XINIT+255) >> 8)
15858 __XPAGE,#(s_XISEG >> 8)
15860 00001$:\InsetSpace ~
15924 00002$:\InsetSpace ~
15951 \begin_layout Verse
15959 \begin_layout Verse
15971 .area GSINIT4 (CODE)
15973 __mcs51_genRAMCLEAR::
15995 00004$:\InsetSpace ~
16009 ; _mcs51_genRAMCLEAR() end
16012 \begin_layout Verse
16020 \begin_layout Verse
16032 .area GSINIT4 (CODE)
16034 __mcs51_genXRAMCLEAR::
16095 mov __XPAGE,#(s_PSEG >> 8)
16107 00005$:\InsetSpace ~
16182 mov r1,#((l_XSEG + 255) >> 8)
16204 00007$:\InsetSpace ~
16241 \begin_layout Verse
16249 \begin_layout Verse
16261 .area GSINIT5 (CODE)
16263 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
16266 ; and __mcs51_genRAMCLEAR modifies _spx.
16276 mov __XPAGE,#(__start__x
16287 mov _spx,#__start__xstack
16290 \begin_layout Verse
16295 (application modules)
16298 \begin_layout Verse
16310 .area GSINIT (CODE)
16313 \begin_layout Verse
16321 \begin_layout Verse
16333 .area GSFINAL (CODE)
16343 ljmp __sdcc_program_startup
16345 ;---------------------------------
16346 -----------------------
16350 ;--------------------------------------------------
16373 __sdcc_program_startup:
16386 return from main will lock up
16399 \begin_layout Standard
16400 One of these modules (crtstart.asm) contains a call to the C routine
16402 _sdcc_external_startup()
16403 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
16412 at the start of the CODE area.
16413 This routine is also in the runtime library
16414 \begin_inset LatexCommand \index{Runtime library}
16418 and returns 0 by default.
16419 If this routine returns a non-zero value, the static & global variable
16420 initialization will be skipped and the function main will be invoked.
16421 Otherwise static & global variables will be initialized before the function
16425 _sdcc_external_startup()
16427 routine to your program to override the default if you need to setup hardware
16428 or perform some other critical operation prior to static & global variable
16430 \begin_inset LatexCommand \index{Variable initialization}
16435 On some mcs51 variants xdata
16436 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
16440 memory has to be explicitly enabled before it can be accessed or if the
16442 \begin_inset LatexCommand \index{watchdog}
16446 needs to be disabled, this is the place to do it.
16447 The startup code clears all internal data memory, 256 bytes by default,
16448 but from 0 to n-1 if
16454 \begin_layout Standard
16464 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16471 (recommended for Chipcon CC1010).
16474 \begin_layout Standard
16475 See also the compiler options
16481 \begin_layout Standard
16497 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16507 \begin_layout Standard
16519 \begin_inset LatexCommand \index{-\/-main-return}
16524 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16528 about MCS51-variants.
16533 \begin_layout Standard
16534 While these initialization modules are meant as generic startup code there
16535 might be the need for customization.
16536 Let's assume the return value of
16538 _sdcc_external_startup()
16544 should not be checked (or
16546 _sdcc_external_startup()
16548 should not be called at all).
16549 The recommended way would be to copy
16555 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm}
16559 ) into the source directory, adapt it there, then assemble it with
16565 \begin_layout Standard
16566 \begin_inset Quotes sld
16570 \begin_inset Quotes srd
16573 are the assembler options used in
16574 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup }
16585 and when linking your project explicitely specify
16590 As a bonus a listing of the relocated object file
16597 \begin_layout Standard
16598 \begin_inset VSpace bigskip
16604 \begin_layout Subsection
16608 \begin_layout Standard
16610 \begin_inset LatexCommand \index{HC08}
16614 startup code follows the same scheme as the MCS51 startup code.
16615 \begin_inset VSpace bigskip
16621 \begin_layout Subsection
16625 \begin_layout Standard
16627 \begin_inset LatexCommand \index{Z80}
16631 the startup code is inserted by linking with crt0.o which is generated from
16632 sdcc/device/lib/z80/crt0.s.
16633 If you need a different startup code you can use the compiler option
16642 \begin_layout Standard
16657 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16661 and provide your own crt0.o.
16663 \begin_inset VSpace bigskip
16669 \begin_layout Section
16670 Inline Assembler Code
16671 \begin_inset LatexCommand \index{Assembler routines}
16678 \begin_layout Subsection
16679 A Step by Step Introduction
16680 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16687 \begin_layout Standard
16688 Starting from a small snippet of c-code this example shows for the MCS51
16689 how to use inline assembly, access variables, a function parameter and
16690 an array in xdata memory.
16691 The example uses an MCS51 here but is easily adapted for other architectures.
16692 This is a buffer routine which should be optimized:
16695 \begin_layout Verse
16699 unsigned char __far
16700 \begin_inset LatexCommand \index{far (storage class)}
16705 \begin_inset LatexCommand \index{\_\_far (storage class)}
16710 \begin_inset LatexCommand \index{at}
16715 \begin_inset LatexCommand \index{\_\_at}
16719 (0x7f00) buf[0x100];
16720 \begin_inset LatexCommand \index{Aligned array}
16726 unsigned char head, tail;\InsetSpace ~
16744 \begin_inset LatexCommand \index{interrupt}
16796 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16808 void to_buffer( unsigned char c )
16816 if( head != (unsigned char)(tail-1)
16823 \begin_inset LatexCommand \index{promotion to signed int}
16828 \begin_inset LatexCommand \index{type promotion}
16833 \begin_inset Marginal
16836 \begin_layout Standard
16855 buf[ head++ ] = c;\InsetSpace ~
16871 /* access to a 256 byte aligned array */
16876 \begin_layout Standard
16877 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16878 then a corresponding buffer.asm file is generated.
16879 We define a new function
16883 in file buffer.c in which we cut and paste the generated code, removing
16884 unwanted comments and some ':'.
16886 \begin_inset Quotes sld
16894 \begin_inset Quotes srd
16898 \begin_inset Quotes sld
16906 \begin_inset Quotes srd
16913 \begin_layout Standard
16914 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16915 and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16917 The latter is also used in the library functions.
16922 to the beginning and the end of the function body:
16925 \begin_layout Verse
16929 /* With a cut and paste from the .asm file, we have something to start with.
16935 function is not yet OK! (registers aren't saved) */
16937 void to_buffer_asm(
16947 \begin_inset LatexCommand \index{\_asm}
16952 \begin_inset LatexCommand \index{\_\_asm}
16966 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16972 \begin_inset LatexCommand \index{promotion to signed int}
16977 \begin_inset LatexCommand \index{type promotion}
17030 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
17031 \begin_inset LatexCommand \index{Aligned array}
17097 \begin_inset LatexCommand \index{\_endasm}
17102 \begin_inset LatexCommand \index{\_\_endasm}
17111 \begin_layout Standard
17112 The new file buffer.c should compile with only one warning about the unreferenced
17113 function argument 'c'.
17114 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
17115 (1) and finally have:
17118 \begin_layout Verse
17122 unsigned char __far __at(0x7f00) buf[0x100];
17124 unsigned char head, tail;
17135 void to_buffer( unsigned char c )
17144 head != (unsigned char)(tail-1) )
17173 c; // to avoid warning: unreferenced function argument
17180 \begin_inset LatexCommand \index{\_asm}
17185 \begin_inset LatexCommand \index{\_\_asm}
17199 ; save used registers here.
17210 ; If we were still using r2,r3 we would have to push them here.
17213 ; if( head != (unsigned char)(tail-1) )
17257 could do an ANL a,#0x0f here to use a smaller buffer (see below)
17293 a,dpl \InsetSpace ~
17300 ; dpl holds lower byte of function argument
17312 dpl,_head \InsetSpace ~
17315 ; buf is 0x100 byte aligned so head can be used directly
17358 ; we could do an ANL _head,#0x0f here to use a
17359 smaller buffer (see above)
17371 ; restore used registers here
17378 \begin_inset LatexCommand \index{\_endasm}
17383 \begin_inset LatexCommand \index{\_\_endasm}
17394 \begin_layout Standard
17395 The inline assembler code can contain any valid code understood by the assembler
17396 , this includes any assembler directives and comment lines.
17397 The assembler does not like some characters like ':' or ''' in comments.
17398 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
17399 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
17404 \begin_inset LatexCommand \index{Assembler documentation}
17409 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
17417 \begin_layout Standard
17418 The compiler does not do any validation of the code within the
17421 \begin_inset LatexCommand \index{\_asm}
17426 \begin_inset LatexCommand \index{\_\_asm}
17434 \begin_inset LatexCommand \index{\_endasm}
17439 \begin_inset LatexCommand \index{\_\_endasm}
17448 Specifically it will not know which registers are used and thus register
17450 \begin_inset LatexCommand \index{push/pop}
17454 has to be done manually.
17458 \begin_layout Standard
17459 It is recommended that each assembly instruction (including labels) be placed
17460 in a separate line (as the example shows).
17465 \begin_layout Standard
17477 \begin_inset LatexCommand \index{-\/-peep-asm}
17483 command line option is used, the inline assembler code will be passed through
17484 the peephole optimizer
17485 \begin_inset LatexCommand \index{Peephole optimizer}
17490 There are only a few (if any) cases where this option makes sense, it might
17491 cause some unexpected changes in the inline assembler code.
17492 Please go through the peephole optimizer rules defined in file
17496 before using this option.
17499 \begin_layout Subsection
17501 \begin_inset LatexCommand \label{sub:Naked-Functions}
17506 \begin_inset LatexCommand \index{Naked functions}
17513 \begin_layout Standard
17514 A special keyword may be associated with a function declaring it as
17517 \begin_inset LatexCommand \index{\_naked}
17522 \begin_inset LatexCommand \index{\_\_naked}
17533 function modifier attribute prevents the compiler from generating prologue
17534 \begin_inset LatexCommand \index{function prologue}
17539 \begin_inset LatexCommand \index{function epilogue}
17543 code for that function.
17544 This means that the user is entirely responsible for such things as saving
17545 any registers that may need to be preserved, selecting the proper register
17546 bank, generating the
17550 instruction at the end, etc.
17551 Practically, this means that the contents of the function must be written
17552 in inline assembler.
17553 This is particularly useful for interrupt functions, which can have a large
17554 (and often unnecessary) prologue/epilogue.
17555 For example, compare the code generated by these two functions:
17558 \begin_layout Verse
17562 \begin_inset LatexCommand \index{volatile}
17566 data unsigned char counter;
17570 void simpleInterrupt(void) __interrupt
17571 \begin_inset LatexCommand \index{interrupt}
17576 \begin_inset LatexCommand \index{\_\_interrupt}
17594 void nakedInterrupt(void) __interrupt (2) __naked
17603 \begin_inset LatexCommand \index{\_asm}
17608 \begin_inset LatexCommand \index{\_\_asm}
17625 _counter ; does not change flags, no need to save psw
17638 include ret or reti in _naked function.
17645 \begin_inset LatexCommand \index{\_endasm}
17650 \begin_inset LatexCommand \index{\_\_endasm}
17659 \begin_layout Standard
17660 For an 8051 target, the generated simpleInterrupt looks like:
17663 \begin_layout Verse
17670 example, recent versions of SDCC generate
17676 code for simpleInterrupt() and nakedInterrupt()!
17817 \begin_layout Standard
17818 whereas nakedInterrupt looks like:
17821 \begin_layout Verse
17834 _counter ; does not change flags, no need to save psw
17853 MUST explicitly include ret or reti in _naked function
17856 \begin_layout Standard
17857 The related directive #pragma exclude
17858 \begin_inset LatexCommand \index{\#pragma exclude}
17862 allows a more fine grained control over pushing & popping
17863 \begin_inset LatexCommand \index{push/pop}
17870 \begin_layout Standard
17871 While there is nothing preventing you from writing C code inside a
17875 function, there are many ways to shoot yourself in the foot doing this,
17876 and it is recommended that you stick to inline assembler.
17879 \begin_layout Subsection
17880 Use of Labels within Inline Assembler
17883 \begin_layout Standard
17884 SDCC allows the use of in-line assembler with a few restrictions regarding
17886 All labels defined within inline assembler code have to be of the form
17891 where nnnnn is a number less than 100 (which implies a limit of utmost
17892 100 inline assembler labels
17903 \begin_layout Standard
17904 This is a slightly more stringent rule than absolutely necessary, but stays
17905 always on the safe side.
17906 Labels in the form of nnnnn$ are local labels in the assembler, locality
17907 of which is confined within two labels of the standard form.
17908 The compiler uses the same form for labels within a function (but starting
17909 from nnnnn=00100); and places always a standard label at the beginning
17910 of a function, thus limiting the locality of labels within the scope of
17912 So, if the inline assembler part would be embedded into C-code, an improperly
17913 placed non-local label in the assembler would break up the reference space
17914 for labels created by the compiler for the C-code, leading to an assembling
17918 \begin_layout Standard
17919 The numeric part of local labels does not need to have 5 digits (although
17920 this is the form of labels output by the compiler), any valid integer will
17922 Please refer to the assemblers documentation for further details.
17930 \begin_layout Verse
17934 \begin_inset LatexCommand \index{\_asm}
17939 \begin_inset LatexCommand \index{\_\_asm}
17969 \begin_inset LatexCommand \index{\_endasm}
17974 \begin_inset LatexCommand \index{\_\_endasm}
17981 \begin_layout Standard
17982 Inline assembler code cannot reference any C-labels, however it can reference
17984 \begin_inset LatexCommand \index{Labels}
17988 defined by the inline assembler, e.g.:
17991 \begin_layout Verse
18014 ; some assembler code
18035 /* some more c code */
18037 clabel:\InsetSpace ~
18039 /* inline assembler cannot reference this
18044 \begin_layout Standard
18049 is translated by the compiler into a local label, so the locality of labels
18050 within the function is not broken.
18067 0003$: ;label (can be referenced by inline assembler only)
18074 \begin_inset LatexCommand \index{\_endasm}
18079 \begin_inset LatexCommand \index{\_\_endasm}
18089 /* some more c code */
18094 \begin_layout Standard
18095 In other words inline assembly code can access labels defined in inline
18096 assembly within the scope of the function.
18097 The same goes the other way, i.e.
18098 labels defines in inline assembly can not be accessed by C statements.
18101 \begin_layout Section
18102 Interfacing with Assembler Code
18103 \begin_inset LatexCommand \index{Assembler routines}
18110 \begin_layout Subsection
18111 Global Registers used for Parameter Passing
18112 \begin_inset LatexCommand \index{Parameter passing}
18119 \begin_layout Standard
18120 The compiler always uses the global registers
18123 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18128 \begin_inset LatexCommand \index{DPTR}
18133 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
18142 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
18148 to pass the first (non-bit) parameter to a function, and also to pass the
18150 \begin_inset LatexCommand \index{return value}
18154 of function; according to the following scheme: one byte return value in
18159 , two byte value in
18168 three byte values (generic pointers) in
18180 , and four byte values in
18198 \begin_inset LatexCommand \index{generic pointer}
18202 contain type of accessed memory in
18223 \begin_inset Note Note
18226 \begin_layout Standard
18227 This might not be the case of certain memory models (medium???)
18235 \begin_layout Standard
18236 The second parameter onwards is either allocated on the stack (for reentrant
18241 \begin_layout Standard
18250 -stack-auto is used) or in data/xdata memory (depending on the memory model).
18253 \begin_layout Standard
18254 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
18255 space for reentrant functions or allocated directly in bit memory otherwise.
18258 \begin_layout Standard
18259 Functions (with two or more parameters or bit parameters) that are called
18260 through function pointers
18261 \begin_inset LatexCommand \index{function pointers}
18265 must therefor be reentrant so the compiler knows how to pass the parameters.
18268 \begin_layout Subsection
18272 \begin_layout Standard
18273 Unless the called function is declared as
18278 \begin_inset LatexCommand \index{naked}
18286 \begin_layout Standard
18296 \begin_inset LatexCommand \index{-\/-callee-saves}
18304 \begin_layout Standard
18313 -all-callee-saves command line option or the corresponding callee_saves
18314 pragma are used, the caller will save the registers (
18318 ) around the call, so the called function can destroy they content freely.
18321 \begin_layout Standard
18322 If the called function is not declared as
18326 , the caller will swap register banks around the call, if caller and callee
18327 use different register banks (having them defined by the
18335 \begin_layout Standard
18336 The called function can also use
18352 observing that they are used for parameter/return value passing.
18355 \begin_layout Subsection
18356 Assembler Routine (non-reentrant)
18359 \begin_layout Standard
18360 In the following example
18361 \begin_inset LatexCommand \index{reentrant}
18366 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
18370 the function c_func calls an assembler routine asm_func, which takes two
18372 \begin_inset LatexCommand \index{function parameter}
18379 \begin_layout Verse
18382 extern int asm_func(unsigned char, unsigned char);
18386 int c_func (unsigned char
18387 i, unsigned char j)
18395 return asm_func(i,j);
18409 return c_func(10,9);
18414 \begin_layout Standard
18415 The corresponding assembler function is:
18418 \begin_layout Verse
18421 .globl _asm_func_PARM_2
18523 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18540 \begin_layout Standard
18541 The parameter naming convention is _<function_name>_PARM_<n>, where n is
18542 the parameter number starting from 1, and counting from the left.
18543 The first parameter is passed in
18559 according to the description above.
18560 The variable name for the second parameter will be _<function_name>_PARM_2.
18565 ble the assembler routine with the following command:
18572 asx8051 -losg asmfunc.asm
18579 Then compile and link the assembler routine to the C source file with the
18587 sdcc cfunc.c asmfunc.rel
18590 \begin_layout Subsection
18591 Assembler Routine (reentrant)
18594 \begin_layout Standard
18596 \begin_inset LatexCommand \index{reentrant}
18601 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18605 the second parameter
18606 \begin_inset LatexCommand \index{function parameter}
18610 onwards will be passed on the stack, the parameters are pushed from right
18612 before the call the second leftmost parameter will be on the top of the
18613 stack (the leftmost parameter is passed in registers).
18614 Here is an example:
18617 \begin_layout Verse
18620 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18625 c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
18634 return asm_func(i,j,k);
18648 return c_func(10,9,8);
18653 \begin_layout Standard
18654 The corresponding (unoptimized) assembler routine is:
18657 \begin_layout Verse
18677 _bp,sp\InsetSpace ~
18683 ;stack contains: _bp, return
18684 address, second parameter, third parameter
18708 a,#0xfd\InsetSpace ~
18714 pointer to the second parameter
18738 a,#0xfc\InsetSpace ~
18744 to the rightmost parameter
18785 result (= sum of all three parameters)
18800 ;return value goes into dptr
18834 \begin_layout Standard
18835 The compiling and linking procedure remains the same, however note the extra
18836 entry & exit linkage required for the assembler code, _bp is the stack
18837 frame pointer and is used to compute the offset into the stack for parameters
18838 and local variables.
18839 \begin_inset VSpace bigskip
18845 \begin_layout Section
18847 \begin_inset LatexCommand \index{int (16 bit)}
18852 \begin_inset LatexCommand \index{long (32 bit)}
18859 \begin_layout Standard
18860 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18861 multiplication and modulus operations are implemented by support routines.
18862 These support routines are all developed in ANSI-C to facilitate porting
18863 to other MCUs, although some model specific assembler optimizations are
18865 The following files contain the described routines, all of them can be
18866 found in <installdir>/share/sdcc/lib.
18871 \begin_layout Standard
18873 \begin_inset Tabular
18874 <lyxtabular version="3" rows="11" columns="2">
18876 <column alignment="left" valignment="top" leftline="true" width="0">
18877 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18878 <row topline="true" bottomline="true">
18879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18882 \begin_layout Standard
18890 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18893 \begin_layout Standard
18902 <row topline="true">
18903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18906 \begin_layout Standard
18912 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18915 \begin_layout Standard
18916 16 bit multiplication
18922 <row topline="true">
18923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18926 \begin_layout Standard
18932 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18935 \begin_layout Standard
18936 signed 16 bit division (calls _divuint)
18942 <row topline="true">
18943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18946 \begin_layout Standard
18952 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18955 \begin_layout Standard
18956 unsigned 16 bit division
18962 <row topline="true">
18963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18966 \begin_layout Standard
18972 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18975 \begin_layout Standard
18976 signed 16 bit modulus (calls _moduint)
18982 <row topline="true">
18983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18986 \begin_layout Standard
18992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18995 \begin_layout Standard
18996 unsigned 16 bit modulus
19002 <row topline="true">
19003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19006 \begin_layout Standard
19012 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19015 \begin_layout Standard
19016 32 bit multiplication
19022 <row topline="true">
19023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19026 \begin_layout Standard
19032 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19035 \begin_layout Standard
19036 signed 32 division (calls _divulong)
19042 <row topline="true">
19043 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19046 \begin_layout Standard
19052 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19055 \begin_layout Standard
19056 unsigned 32 division
19062 <row topline="true">
19063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19066 \begin_layout Standard
19072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19075 \begin_layout Standard
19076 signed 32 bit modulus (calls _modulong)
19082 <row topline="true" bottomline="true">
19083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19086 \begin_layout Standard
19092 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19095 \begin_layout Standard
19096 unsigned 32 bit modulus
19111 \begin_layout Standard
19112 Since they are compiled as
19117 \begin_inset LatexCommand \index{reentrant}
19122 \begin_inset LatexCommand \index{interrupt}
19126 service routines should not do any of the above operations.
19127 If this is unavoidable then the above routines will need to be compiled
19134 \begin_layout Standard
19144 \begin_inset LatexCommand \index{-\/-stack-auto}
19150 option, after which the source program will have to be compiled with
19156 \begin_layout Standard
19166 \begin_inset LatexCommand \index{-\/-int-long-reent}
19173 Notice that you don't have to call these routines directly.
19174 The compiler will use them automatically every time an integer operation
19178 \begin_layout Section
19179 Floating Point Support
19180 \begin_inset LatexCommand \index{Floating point support}
19187 \begin_layout Standard
19188 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
19189 The floating point support routines are derived from gcc's floatlib.c and
19190 consist of the following routines:
19195 \begin_layout Standard
19199 \begin_inset Tabular
19200 <lyxtabular version="3" rows="17" columns="2">
19202 <column alignment="left" valignment="top" leftline="true" width="0">
19203 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19204 <row topline="true" bottomline="true">
19205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19208 \begin_layout Standard
19223 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19226 \begin_layout Standard
19233 <row topline="true">
19234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19237 \begin_layout Standard
19252 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19255 \begin_layout Standard
19265 add floating point numbers
19271 <row topline="true">
19272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19275 \begin_layout Standard
19290 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19293 \begin_layout Standard
19303 subtract floating point numbers
19309 <row topline="true">
19310 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19313 \begin_layout Standard
19328 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19331 \begin_layout Standard
19341 divide floating point numbers
19347 <row topline="true">
19348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19351 \begin_layout Standard
19366 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19369 \begin_layout Standard
19379 multiply floating point numbers
19385 <row topline="true">
19386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19389 \begin_layout Standard
19404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19407 \begin_layout Standard
19417 convert floating point to unsigned char
19423 <row topline="true">
19424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19427 \begin_layout Standard
19442 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19445 \begin_layout Standard
19455 convert floating point to signed char
19461 <row topline="true">
19462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19465 \begin_layout Standard
19480 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19483 \begin_layout Standard
19493 convert floating point to unsigned int
19499 <row topline="true">
19500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19503 \begin_layout Standard
19518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19521 \begin_layout Standard
19531 convert floating point to signed int
19537 <row topline="true">
19538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19541 \begin_layout Standard
19564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19567 \begin_layout Standard
19577 convert floating point to unsigned long
19583 <row topline="true">
19584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19587 \begin_layout Standard
19602 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19605 \begin_layout Standard
19615 convert floating point to signed long
19621 <row topline="true">
19622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19625 \begin_layout Standard
19640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19643 \begin_layout Standard
19653 convert unsigned char to floating point
19659 <row topline="true">
19660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19663 \begin_layout Standard
19678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19681 \begin_layout Standard
19691 convert char to floating point number
19697 <row topline="true">
19698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19701 \begin_layout Standard
19716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19719 \begin_layout Standard
19729 convert unsigned int to floating point
19735 <row topline="true">
19736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19739 \begin_layout Standard
19754 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19757 \begin_layout Standard
19767 convert int to floating point numbers
19773 <row topline="true">
19774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19777 \begin_layout Standard
19792 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19795 \begin_layout Standard
19805 convert unsigned long to floating point number
19811 <row topline="true" bottomline="true">
19812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19815 \begin_layout Standard
19830 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19833 \begin_layout Standard
19843 convert long to floating point number
19858 \begin_layout Standard
19859 These support routines are developed in ANSI-C so there is room for space
19860 and speed improvement
19864 \begin_layout Standard
19865 These floating point routines (
19869 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19876 Note if all these routines are used simultaneously the data space might
19878 For serious floating point usage the large model might be needed.
19879 Also notice that you don't have to call this routines directly.
19880 The compiler will use them automatically every time a floating point operation
19882 \begin_inset VSpace bigskip
19888 \begin_layout Section
19890 \begin_inset LatexCommand \index{Libraries}
19897 \begin_layout Standard
19900 <pending: this is messy and incomplete - a little more information is in
19901 sdcc/doc/libdoc.txt
19906 \begin_layout Subsection
19907 Compiler support routines (_gptrget, _mulint etc.)
19910 \begin_layout Subsection
19911 Stdclib functions (puts, printf, strcat etc.)
19914 \begin_layout Subsubsection
19918 \begin_layout Paragraph
19919 getchar(), putchar()
19922 \begin_layout Standard
19923 \begin_inset LatexCommand \index{<stdio.h>}
19927 As usual on embedded systems you have to provide your own
19930 \begin_inset LatexCommand \index{getchar()}
19939 \begin_inset LatexCommand \index{putchar()}
19946 SDCC does not know whether the system connects to a serial line with or
19947 without handshake, LCD, keyboard or other device.
19961 You'll find examples for serial routines f.e.
19962 in sdcc/device/lib.
19963 For the mcs51 this minimalistic polling
19967 routine might be a start:
19970 \begin_layout Verse
19973 void putchar (char c) {
19979 while (!TI)\InsetSpace ~
19982 /* assumes UART is initialized */
20010 \begin_layout Paragraph
20014 \begin_layout Standard
20018 \begin_inset LatexCommand \index{printf()}
20028 does not support float (except on ds390).
20029 To enable this recompile it with the option
20035 \begin_layout Standard
20045 \begin_inset LatexCommand \index{USE\_FLOATS}
20051 on the command line.
20058 \begin_layout Standard
20068 \begin_inset LatexCommand \index{-\/-model-large}
20074 for the mcs51 port, since this uses a lot of memory.
20077 \begin_layout Standard
20078 If you're short on code memory you might want to use
20081 \begin_inset LatexCommand \index{printf\_small()}
20096 For the mcs51 there additionally are assembly versions
20099 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
20105 (subset of printf using less than 270 bytes) and
20108 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
20117 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
20123 (floating-point aware version of printf_fast) which should fit the requirements
20124 of many embedded systems (printf_fast() can be customized by unsetting
20129 support long variables and field widths).
20130 Be sure to use only one of these printf options within a project.
20135 \begin_layout Standard
20136 Feature matrix of different
20143 \begin_layout Standard
20144 \begin_inset Tabular
20145 <lyxtabular version="3" rows="14" columns="7">
20146 <features islongtable="true">
20147 <column alignment="left" valignment="middle" leftline="true" width="14col%">
20148 <column alignment="center" valignment="top" leftline="true" width="0">
20149 <column alignment="center" valignment="top" leftline="true" width="12col%">
20150 <column alignment="center" valignment="top" leftline="true" width="10col%">
20151 <column alignment="center" valignment="top" leftline="true" width="0">
20152 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
20153 <column alignment="center" valignment="top" rightline="true" width="0">
20154 <row topline="true" bottomline="true" endhead="true">
20155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20158 \begin_layout Standard
20167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20170 \begin_layout Standard
20172 \begin_inset LatexCommand \index{printf}
20181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20184 \begin_layout Standard
20192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20195 \begin_layout Standard
20201 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20204 \begin_layout Standard
20210 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20213 \begin_layout Standard
20219 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20222 \begin_layout Standard
20229 <row topline="true" endhead="true">
20230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20233 \begin_layout Standard
20239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20242 \begin_layout Standard
20250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20253 \begin_layout Standard
20261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20264 \begin_layout Standard
20272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20275 \begin_layout Standard
20283 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20286 \begin_layout Standard
20294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20297 \begin_layout Standard
20306 <row topline="true" endhead="true">
20307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20310 \begin_layout Standard
20311 \begin_inset Quotes sld
20315 \begin_inset Quotes srd
20321 \begin_layout Standard
20327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20330 \begin_layout Standard
20336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20339 \begin_layout Standard
20345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20348 \begin_layout Standard
20354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20357 \begin_layout Standard
20363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20366 \begin_layout Standard
20372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20375 \begin_layout Standard
20382 <row topline="true" endhead="true">
20383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20386 \begin_layout Standard
20390 \begin_layout Standard
20396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20399 \begin_layout Standard
20405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20408 \begin_layout Standard
20414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20417 \begin_layout Standard
20418 0.45k / 0.47k (+ _ltoa)
20423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20426 \begin_layout Standard
20432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20435 \begin_layout Standard
20441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20444 \begin_layout Standard
20451 <row topline="true">
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
20474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20477 \begin_layout Standard
20524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20527 \begin_layout Standard
20566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20569 \begin_layout Standard
20575 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20578 \begin_layout Standard
20584 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20587 \begin_layout Standard
20594 <row topline="true">
20595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20598 \begin_layout Standard
20599 long (32 bit) support
20604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20607 \begin_layout Standard
20613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20616 \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" usebox="none">
20634 \begin_layout Standard
20640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20643 \begin_layout Standard
20658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20661 \begin_layout Standard
20668 <row topline="true">
20669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20672 \begin_layout Standard
20673 byte arguments on stack
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" usebox="none">
20699 \begin_layout Standard
20705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20708 \begin_layout Standard
20714 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20717 \begin_layout Standard
20723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20726 \begin_layout Standard
20733 <row topline="true">
20734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20737 \begin_layout Standard
20739 \begin_inset LatexCommand \index{Floating point support}
20748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20751 \begin_layout Standard
20757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20760 \begin_layout Standard
20766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20769 \begin_layout Standard
20775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20778 \begin_layout Standard
20784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20787 \begin_layout Standard
20792 \begin_layout Standard
20793 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20806 \begin_layout Standard
20813 <row topline="true">
20814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20817 \begin_layout Standard
20818 float formats %e %g
20823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20826 \begin_layout Standard
20832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20835 \begin_layout Standard
20841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20844 \begin_layout Standard
20850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20853 \begin_layout Standard
20859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20862 \begin_layout Standard
20868 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20871 \begin_layout Standard
20878 <row topline="true" bottomline="true">
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" usebox="none">
20918 \begin_layout Standard
20924 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20927 \begin_layout Standard
20933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20936 \begin_layout Standard
20943 <row bottomline="true">
20944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20947 \begin_layout Standard
20952 \begin_layout Standard
20953 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20957 n'); standard 8051 @ 22.1184 MHz, empty putchar()
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" usebox="none">
20983 \begin_layout Standard
20989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20992 \begin_layout Standard
20998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21001 \begin_layout Standard
21007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21010 \begin_layout Standard
21016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21019 \begin_layout Standard
21026 <row bottomline="true">
21027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21030 \begin_layout Standard
21035 \begin_layout Standard
21036 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
21045 \begin_layout Standard
21051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21054 \begin_layout Standard
21060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21063 \begin_layout Standard
21069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21072 \begin_layout Standard
21078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21081 \begin_layout Standard
21087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21090 \begin_layout Standard
21096 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21099 \begin_layout Standard
21104 \begin_layout Standard
21105 printf_tiny integer speed is data dependent, worst case is 0.33 ms
21116 <row bottomline="true">
21117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21120 \begin_layout Standard
21125 \begin_layout Standard
21126 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
21135 \begin_layout Standard
21141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21144 \begin_layout Standard
21150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21153 \begin_layout Standard
21159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21162 \begin_layout Standard
21168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21171 \begin_layout Standard
21177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21180 \begin_layout Standard
21186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21189 \begin_layout Standard
21196 <row bottomline="true">
21197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21200 \begin_layout Standard
21205 \begin_layout Standard
21206 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
21215 \begin_layout Standard
21221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21224 \begin_layout Standard
21230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21233 \begin_layout Standard
21239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21242 \begin_layout Standard
21248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21251 \begin_layout Standard
21257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21260 \begin_layout Standard
21266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21269 \begin_layout Standard
21283 \begin_layout Subsubsection
21285 \begin_inset LatexCommand \index{malloc.h}
21292 \begin_layout Standard
21293 As of SDCC 2.6.2 you no longer need to call an initialization routine before
21294 using dynamic memory allocation
21295 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
21300 \begin_inset LatexCommand \index{heap (malloc)}
21304 space of 1024 bytes is provided for malloc to allocate memory from.
21305 If you need a different heap size you need to recompile _heap.c with the
21306 required size defined in HEAP_SIZE.
21307 It is recommended to make a copy of this file into your project directory
21308 and compile it there with:
21311 \begin_layout Verse
21314 sdcc -c _heap.c -D HEAD_SIZE=2048
21317 \begin_layout Standard
21318 And then link it with:
21321 \begin_layout Verse
21324 sdcc main.rel _heap.rel
21327 \begin_layout Subsection
21328 Math functions (sinf, powf, sqrtf etc.)
21331 \begin_layout Subsubsection
21335 \begin_layout Standard
21336 See definitions in file <math.h>.
21339 \begin_layout Subsection
21343 \begin_layout Standard
21345 \begin_inset LatexCommand \index{Libraries}
21349 included in SDCC should have a license at least as liberal as the GNU Lesser
21350 General Public License
21351 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
21362 \begin_layout Standard
21363 \begin_inset Note Note
21366 \begin_layout Standard
21367 license statements for the libraries are missing.
21368 sdcc/device/lib/ser_ir.c
21371 \begin_layout Standard
21373 come with a GPL (as opposed to LGPL) License - this will not be liberal
21374 enough for many embedded programmers.
21382 \begin_layout Standard
21383 If you have ported some library or want to share experience about some code
21385 falls into any of these categories Busses (I
21386 \begin_inset Formula $^{\textrm{2}}$
21389 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
21390 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
21391 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
21392 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
21397 would certainly like to hear about it.
21400 \begin_layout Standard
21401 Programmers coding for embedded systems are not especially famous for being
21402 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
21403 e these references are very valuable.
21404 Let's help to create a climate where information is shared.
21405 \begin_inset VSpace bigskip
21411 \begin_layout Section
21415 \begin_layout Subsection
21416 MCS51 Memory Models
21417 \begin_inset LatexCommand \index{Memory model}
21422 \begin_inset LatexCommand \index{MCS51 memory model}
21429 \begin_layout Subsubsection
21430 Small, Medium and Large
21433 \begin_layout Standard
21434 SDCC allows three memory models for MCS51 code,
21443 Modules compiled with different memory models should
21447 be combined together or the results would be unpredictable.
21448 The library routines supplied with the compiler are compiled as small,
21450 The compiled library modules are contained in separate directories as small,
21451 medium and large so that you can link to the appropriate set.
21454 \begin_layout Standard
21455 When the medium or large model is used all variables declared without a
21456 storage class will be allocated into the external ram, this includes all
21457 parameters and local variables (for non-reentrant
21458 \begin_inset LatexCommand \index{reentrant}
21463 When the small model is used variables without storage class are allocated
21464 in the internal ram.
21467 \begin_layout Standard
21468 Judicious usage of the processor specific storage classes
21469 \begin_inset LatexCommand \index{Storage class}
21473 and the 'reentrant' function type will yield much more efficient code,
21474 than using the large model.
21475 Several optimizations are disabled when the program is compiled using the
21476 large model, it is therefore recommended that the small model be used unless
21477 absolutely required.
21480 \begin_layout Subsubsection
21482 \begin_inset LatexCommand \label{sub:External-Stack}
21487 \begin_inset LatexCommand \index{stack}
21492 \begin_inset LatexCommand \index{External stack (mcs51)}
21499 \begin_layout Standard
21500 The external stack (-
21504 \begin_layout Standard
21514 \begin_inset LatexCommand \index{-\/-xstack}
21518 ) is located in pdata
21519 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
21523 memory (usually at the start of the external ram segment) and uses all
21524 unused space in pdata (max.
21530 \begin_layout Standard
21539 -xstack option is used to compile the program, the parameters and local
21541 \begin_inset LatexCommand \index{local variables}
21545 of all reentrant functions are allocated in this area.
21546 This option is provided for programs with large stack space requirements.
21547 When used with the -
21551 \begin_layout Standard
21561 \begin_inset LatexCommand \index{-\/-stack-auto}
21565 option, all parameters and local variables are allocated on the external
21566 stack (note: support libraries will need to be recompiled with the same
21568 There is a predefined target in the library makefile).
21571 \begin_layout Standard
21572 The compiler outputs the higher order address byte of the external ram segment
21574 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21579 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21583 ), therefore when using the External Stack option, this port
21587 be used by the application program.
21590 \begin_layout Subsection
21592 \begin_inset LatexCommand \index{Memory model}
21597 \begin_inset LatexCommand \index{DS390 memory model}
21604 \begin_layout Standard
21605 The only model supported is Flat 24
21606 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21611 This generates code for the 24 bit contiguous addressing mode of the Dallas
21613 In this mode, up to four meg of external RAM or code space can be directly
21615 See the data sheets at www.dalsemi.com for further information on this part.
21620 that the compiler does not generate any code to place the processor into
21621 24 bitmode (although
21625 in the ds390 libraries will do that for you).
21631 \begin_inset LatexCommand \index{Tinibios (DS390)}
21635 , the boot loader or similar code must ensure that the processor is in 24
21636 bit contiguous addressing mode before calling the SDCC startup code.
21647 \begin_layout Standard
21658 option, variables will by default be placed into the XDATA segment.
21663 Segments may be placed anywhere in the 4 meg address space using the usual
21668 \begin_layout Standard
21678 Note that if any segments are located above 64K, the -r flag must be passed
21679 to the linker to generate the proper segment relocations, and the Intel
21680 HEX output format must be used.
21681 The -r flag can be passed to the linker by using the option
21685 on the SDCC command line.
21686 However, currently the linker can not handle code segments > 64k.
21689 \begin_layout Section
21691 \begin_inset LatexCommand \label{sec:Pragmas}
21696 \begin_inset LatexCommand \index{Pragmas}
21703 \begin_layout Standard
21704 Pragmas are used to turn on and/or off certain compiler options.
21705 Some of them are closely related to corresponding command-line options
21707 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21713 Pragmas should be placed before and/or after a function, placing pragmas
21714 inside a function body could have unpredictable results.
21719 following #pragma directives:
21722 \begin_layout Itemize
21728 \begin_inset LatexCommand \index{\#pragma save}
21732 - this will save most current options to the save/restore stack.
21733 See #pragma\InsetSpace ~
21737 \begin_layout Itemize
21743 \begin_inset LatexCommand \index{\#pragma restore}
21747 - will restore saved options from the last save.
21748 saves & restores can be nested.
21749 SDCC uses a save/restore stack: save pushes current options to the stack,
21750 restore pulls current options from the stack.
21751 See #pragma\InsetSpace ~
21757 \begin_layout Itemize
21763 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21768 \begin_inset LatexCommand \index{function prologue}
21772 function1[,function2[,function3...]]
21773 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21777 - The compiler by default uses a caller saves convention for register saving
21778 across function calls, however this can cause unnecessary register pushing
21780 \begin_inset LatexCommand \index{push/pop}
21784 when calling small functions from larger functions.
21785 This option can be used to switch off the register saving convention for
21786 the function names specified.
21787 The compiler will not save registers when calling these functions, extra
21788 code need to be manually inserted at the entry and exit for these functions
21789 to save and restore the registers used by these functions, this can SUBSTANTIAL
21790 LY reduce code and improve run time performance of the generated code.
21791 In the future the compiler (with inter procedural analysis) may be able
21792 to determine the appropriate scheme to use for each function call.
21797 \begin_layout Standard
21806 -callee-saves command line option is used (see page
21807 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21811 ), the function names specified in #pragma\InsetSpace ~
21813 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21817 is appended to the list of functions specified in the command line.
21820 \begin_layout Itemize
21826 \begin_inset LatexCommand \index{\#pragma exclude}
21830 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21831 of pairs of push/pop
21832 \begin_inset LatexCommand \index{push/pop}
21841 \begin_inset LatexCommand \index{interrupt}
21854 The directive should be placed immediately before the ISR function definition
21855 and it affects ALL ISR functions following it.
21856 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21857 exclude\InsetSpace ~
21859 \begin_inset LatexCommand \index{\#pragma exclude}
21864 See also the related keyword _naked
21865 \begin_inset LatexCommand \index{\_naked}
21870 \begin_inset LatexCommand \index{\_\_naked}
21877 \begin_layout Itemize
21883 \begin_inset LatexCommand \index{pedantic}
21888 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21893 \begin_inset LatexCommand \label{ite:less_pedantic}
21897 - the compiler will not warn you anymore for obvious mistakes, you're on
21899 See also the command line option -
21903 \begin_layout Standard
21913 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21920 More specifically, the following warnings will be disabled:
21922 comparison is always [true/false] due to limited range of data type
21926 overflow in implicit constant conversion
21928 (158); [the (in)famous]
21930 conditional flow changed by optimizer: so said EVELYN the modified DOG
21934 function '[function name]' must return value
21939 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21940 level) are disabled, too, namely:
21943 \begin_inset Note Note
21946 \begin_layout Standard
21947 dunno what comes here - this warning appears to be unused altogether
21956 [left/right] shifting more than size of object changed to zero
21964 integer overflow in expression
21968 unmatched #pragma save and #pragma restore
21972 comparison of 'signed char' with 'unsigned char' requires promotion to int
21976 ISO C90 does not support flexible array members
21980 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21984 \begin_inset Note Note
21987 \begin_layout Standard
21988 appears to be always blank - what was supposed to be here?
21997 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21998 complexity [number]
22003 \begin_layout Itemize
22009 \begin_inset LatexCommand \index{\#pragma disable\_warning}
22013 - the compiler will not warn you anymore about warning number <nnnn>.
22016 \begin_layout Itemize
22022 \begin_inset LatexCommand \index{\#pragma nogcse}
22026 - will stop global common subexpression elimination.
22029 \begin_layout Itemize
22035 \begin_inset LatexCommand \index{\#pragma noinduction}
22039 - will stop loop induction optimizations.
22042 \begin_layout Itemize
22048 \begin_inset LatexCommand \index{\#pragma noinvariant}
22052 - will not do loop invariant optimizations.
22053 For more details see Loop Invariants in section
22054 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
22061 \begin_layout Itemize
22067 \begin_inset LatexCommand \index{\#pragma noiv}
22071 - Do not generate interrupt
22072 \begin_inset LatexCommand \index{interrupt}
22077 \begin_inset LatexCommand \index{interrupt vector table}
22081 entries for all ISR functions defined after the pragma.
22082 This is useful in cases where the interrupt vector table must be defined
22083 manually, or when there is a secondary, manually defined interrupt vector
22085 for the autovector feature of the Cypress EZ-USB FX2).
22086 More elegantly this can be achieved by obmitting the optional interrupt
22087 number after the interrupt keyword, see section
22088 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
22096 \begin_layout Itemize
22102 \begin_inset LatexCommand \index{\#pragma nojtbound}
22106 - will not generate code for boundary value checking, when switch statements
22107 are turned into jump-tables (dangerous).
22108 For more details see section
22109 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
22116 \begin_layout Itemize
22122 \begin_inset LatexCommand \index{\#pragma noloopreverse}
22126 - Will not do loop reversal optimization
22129 \begin_layout Itemize
22135 \begin_inset LatexCommand \index{\#pragma nooverlay}
22139 - the compiler will not overlay the parameters and local variables of a
22143 \begin_layout Itemize
22149 \begin_inset LatexCommand \index{\#pragma stackauto}
22157 \begin_layout Standard
22167 \begin_inset LatexCommand \index{-\/-stack-auto}
22172 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
22176 Parameters and Local Variables.
22179 \begin_layout Itemize
22185 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
22189 - The compiler will optimize code generation towards fast code, possibly
22190 at the expense of code size.
22191 Currently this has little effect.
22194 \begin_layout Itemize
22200 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
22204 - The compiler will optimize code generation towards compact code, possibly
22205 at the expense of code speed.
22206 Currently this has little effect.
22209 \begin_layout Itemize
22215 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
22219 - The compiler will attempt to generate code that is both compact and fast,
22220 as long as meeting one goal is not a detriment to the other (this is the
22225 \begin_layout Itemize
22231 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
22235 - Generally follow the C89 standard, but allow SDCC features that conflict
22236 with the standard (default).
22239 \begin_layout Itemize
22245 \begin_inset LatexCommand \index{\#pragma std\_c89}
22249 - Follow the C89 standard and disable SDCC features that conflict with the
22253 \begin_layout Itemize
22259 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
22263 - Generally follow the C99 standard, but allow SDCC features that conflict
22264 with the standard (incomplete support).
22267 \begin_layout Itemize
22273 \begin_inset LatexCommand \index{\#pragma std\_c99}
22277 - Follow the C99 standard and disable SDCC features that conflict with the
22278 standard (incomplete support).
22281 \begin_layout Itemize
22287 \begin_inset LatexCommand \index{\#pragma codeseg}
22291 - Use this name (max.
22292 8 characters) for the code segment.
22297 \begin_layout Standard
22309 \begin_layout Itemize
22315 \begin_inset LatexCommand \index{\#pragma constseg}
22319 - Use this name (max.
22320 8 characters) for the const segment.
22325 \begin_layout Standard
22337 \begin_layout Standard
22338 The preprocessor SDCPP
22339 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
22343 supports the following #pragma directives:
22346 \begin_layout Itemize
22349 pedantic_parse_number
22352 \begin_inset LatexCommand \index{pedantic}
22357 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22362 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
22366 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
22367 properly and the macro LO_B(3) gets expanded.
22373 \begin_layout Standard
22382 -pedantic-parse-number command line option
22383 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
22390 Below is an example on how to use this pragma.
22393 Note: this functionality is not in conformance with standard!
22396 \begin_layout Verse
22399 #pragma pedantic_parse_number +
22400 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22408 #define LO_B(x) ((x) & 0xff)
22412 unsigned char foo(void)
22419 unsigned char c=0xfe-LO_B(3)
22434 \begin_layout Itemize
22440 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22444 (+ | -) - switch _asm _endasm block preprocessing on / off.
22446 You use this prama to define multilines of assembly code.
22447 This will prevent the preprocessor from changing the formating required
22449 Below is an example on how to use this pragma.
22452 \begin_layout Verse
22455 #pragma preproc_asm -
22456 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22462 #define MYDELAY _asm
22467 nop ;my assembly comment...
22481 #pragma preproc_asm
22512 \begin_layout Itemize
22518 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22522 (+ | -) - Allow "naked" hash in macro definition, for example:
22526 #define DIR_LO(x) #(x & 0xff)
22531 Below is an example on how to use this pragma.
22534 \begin_layout Verse
22537 #pragma preproc_asm +
22539 #pragma sdcc_hash +
22540 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22555 mov R6_B3, #(x & 0xff)
22562 mov R7_B3, #((x >> 8) & 0xff)
22586 \begin_layout Standard
22587 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22588 ons which might cause the compiler to generate extra stack and/or data space
22589 to store compiler generated temporary variables.
22590 This usually happens in large functions.
22591 Pragma directives should be used as shown in the following example, they
22592 are used to control options and optimizations for a given function.
22596 \begin_layout Verse
22600 \begin_inset LatexCommand \index{\#pragma save}
22611 /* save the current settings */
22614 \begin_inset LatexCommand \index{\#pragma nogcse}
22623 /* turnoff global subexpression elimination */
22625 #pragma noinduction
22626 \begin_inset LatexCommand \index{\#pragma noinduction}
22630 /* turn off induction optimizations */
22653 \begin_inset LatexCommand \index{\#pragma restore}
22657 /* turn the optimizations back on */
22660 \begin_layout Standard
22661 The compiler will generate a warning message when extra space is allocated.
22662 It is strongly recommended that the save and restore pragmas be used when
22663 changing options for a function.
22672 \begin_layout Section
22673 Defines Created by the Compiler
22676 \begin_layout Standard
22677 The compiler creates the following #defines
22678 \begin_inset LatexCommand \index{\#defines}
22683 \begin_inset LatexCommand \index{Defines created by the compiler}
22692 \begin_layout Standard
22693 \begin_inset Tabular
22694 <lyxtabular version="3" rows="15" columns="2">
22696 <column alignment="left" valignment="top" leftline="true" width="3in">
22697 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22698 <row topline="true" bottomline="true">
22699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22702 \begin_layout Standard
22710 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22713 \begin_layout Standard
22722 <row topline="true">
22723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22726 \begin_layout Standard
22728 \begin_inset LatexCommand \index{SDCC}
22737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22740 \begin_layout Standard
22742 Since version 2.5.6 the version number as an int (ex.
22749 <row topline="true">
22750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22753 \begin_layout Standard
22755 \begin_inset LatexCommand \index{SDCC\_mcs51}
22760 \begin_inset LatexCommand \index{SDCC\_ds390}
22765 \begin_inset LatexCommand \index{SDCC\_z80}
22774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22777 \begin_layout Standard
22778 depending on the model used (e.g.: -mds390)
22784 <row topline="true">
22785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22788 \begin_layout Standard
22790 \begin_inset LatexCommand \index{\_\_mcs51}
22795 \begin_inset LatexCommand \index{\_\_ds390}
22800 \begin_inset LatexCommand \index{\_\_hc08}
22805 \begin_inset LatexCommand \index{\_\_z80}
22814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22817 \begin_layout Standard
22818 depending on the model used (e.g.
22825 <row topline="true">
22826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22829 \begin_layout Standard
22831 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22843 \begin_layout Standard
22850 \begin_layout Standard
22867 <row topline="true">
22868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22871 \begin_layout Standard
22873 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22885 \begin_layout Standard
22892 \begin_layout Standard
22909 <row topline="true">
22910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22913 \begin_layout Standard
22915 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22924 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22927 \begin_layout Standard
22934 \begin_layout Standard
22951 <row topline="true">
22952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22955 \begin_layout Standard
22957 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22969 \begin_layout Standard
22976 \begin_layout Standard
22993 <row topline="true">
22994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22997 \begin_layout Standard
22999 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
23008 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23011 \begin_layout Standard
23018 \begin_layout Standard
23035 <row topline="true">
23036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23039 \begin_layout Standard
23041 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
23050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23053 \begin_layout Standard
23064 <row topline="true">
23065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23068 \begin_layout Standard
23070 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23079 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23082 \begin_layout Standard
23093 <row topline="true">
23094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23097 \begin_layout Standard
23099 \begin_inset LatexCommand \index{SDCC\_REVISION}
23108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23111 \begin_layout Standard
23113 SDCC revision number
23119 <row topline="true">
23120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23123 \begin_layout Standard
23124 SDCC_PARMS_IN_BANK1
23125 \begin_inset LatexCommand \index{SDCC\_PARMS\_IN\_BANK1}
23134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23137 \begin_layout Standard
23144 \begin_layout Standard
23161 <row topline="true">
23162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23165 \begin_layout Standard
23167 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23176 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23179 \begin_layout Standard
23186 \begin_layout Standard
23203 <row topline="true" bottomline="true">
23204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23207 \begin_layout Standard
23208 SDCC_INT_LONG_REENT
23209 \begin_inset LatexCommand \index{SDCC\_INT\_LONG\_REENT}
23218 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23221 \begin_layout Standard
23228 \begin_layout Standard
23252 \begin_layout Chapter
23253 Notes on supported Processors
23256 \begin_layout Section
23258 \begin_inset LatexCommand \label{sub:MCS51-variants}
23263 \begin_inset LatexCommand \index{MCS51 variants}
23270 \begin_layout Standard
23271 MCS51 processors are available from many vendors and come in many different
23273 While they might differ considerably in respect to Special Function Registers
23274 the core MCS51 is usually not modified or is kept compatible.
23278 \begin_layout Subsection
23279 pdata access by SFR
23282 \begin_layout Standard
23283 With the upcome of devices with internal xdata and flash memory devices
23285 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
23289 as dedicated I/O port is becoming more popular.
23290 Switching the high byte for pdata
23291 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
23295 access which was formerly done by port P2 is then achieved by a Special
23297 \begin_inset LatexCommand \index{sfr}
23302 In well-established MCS51 tradition the address of this
23306 is where the chip designers decided to put it.
23307 Needless to say that they didn't agree on a common name either.
23308 So that the startup code can correctly initialize xdata variables, you
23309 should define an sfr with the name _XPAGE
23312 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
23318 at the appropriate location if the default, port P2, is not used for this.
23322 \begin_layout Verse
23325 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
23329 \begin_layout Verse
23332 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
23337 \begin_layout Verse
23340 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
23344 \begin_layout Verse
23347 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23351 \begin_layout Verse
23354 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23358 \begin_layout Standard
23359 For more exotic implementations further customizations may be needed.
23361 \begin_inset LatexCommand \ref{sub:Startup-Code}
23365 for other possibilities.
23368 \begin_layout Subsection
23369 Other Features available by SFR
23372 \begin_layout Standard
23373 Some MCS51 variants offer features like Double DPTR
23374 \begin_inset LatexCommand \index{DPTR}
23378 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
23379 These are currently not used for the MCS51 port.
23380 If you absolutely need them you can fall back to inline assembly or submit
23382 \begin_inset VSpace bigskip
23388 \begin_layout Section
23392 \begin_layout Standard
23394 \begin_inset LatexCommand \index{DS80C400}
23399 \begin_inset LatexCommand \index{DS400}
23403 microcontroller has a rich set of peripherals.
23404 In its built-in ROM library it includes functions to access some of the
23405 features, among them is a TCP stack with IP4 and IP6 support.
23406 Library headers (currently in beta status) and other files are provided
23410 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
23416 \begin_inset VSpace bigskip
23422 \begin_layout Section
23423 The Z80 and gbz80 port
23426 \begin_layout Standard
23427 SDCC can target both the Zilog Z80
23428 \begin_inset LatexCommand \index{Z80}
23432 and the Nintendo Gameboy's Z80-like gbz80
23433 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
23438 The Z80 port is passed through the same
23441 \begin_inset LatexCommand \index{Regression test}
23448 \begin_inset LatexCommand \ref{sec:Quality-control}
23452 ) as the MCS51 and DS390 ports, so floating point support, support for long
23453 variables and bitfield support is fine.
23454 See mailing lists and forums about interrupt routines.
23457 \begin_layout Standard
23458 As always, the code is the authoritative reference - see z80/ralloc.c and
23461 \begin_inset LatexCommand \index{Z80!stack}
23465 frame is similar to that generated by the IAR Z80 compiler.
23466 IX is used as the base pointer, HL and IY are used as a temporary registers,
23467 and BC and DE are available for holding variables.
23469 \begin_inset LatexCommand \index{Z80!return value}
23473 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
23475 The gbz80 port use the same set of registers for the return values, but
23476 in a different order of significance: E (one byte), DE (two bytes), or
23478 \begin_inset VSpace bigskip
23484 \begin_layout Section
23488 \begin_layout Standard
23489 The port to the Freescale/Motorola HC08
23490 \begin_inset LatexCommand \index{HC08}
23494 family has been added in October 2003, and is still undergoing some basic
23496 The code generator is complete, but the register allocation is still quite
23498 Some of the SDCC's standard C library functions have embedded non-HC08
23499 inline assembly and so are not yet usable.
23502 \begin_layout Standard
23503 The HC08 port passes the regression test suite (see section
23504 \begin_inset LatexCommand \ref{sec:Quality-control}
23509 \begin_inset VSpace bigskip
23517 \begin_layout Section
23519 \begin_inset LatexCommand \index{PIC14}
23526 \begin_layout Standard
23527 The PIC14 port adds support for Microchip
23528 \begin_inset LatexCommand \index{Microchip}
23533 \begin_inset Formula $^{\text{TM}}$
23537 \begin_inset LatexCommand \index{PIC14}
23542 \begin_inset Formula $^{\text{TM}}$
23545 MCUs with 14 bit wide instructions.
23546 This port is not yet mature and still lacks many features.
23547 However, it can work for simple code.
23550 \begin_layout Standard
23551 Currently supported devices include:
23554 \begin_layout Standard
23555 12F: 629, 635, 675, 683
23558 \begin_layout Standard
23562 \begin_layout Standard
23566 \begin_layout Standard
23567 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
23570 \begin_layout Standard
23571 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
23575 \begin_layout Standard
23579 \begin_layout Standard
23580 16F: 627, 627a, 628, 628a, 630, 636, 639, 648a, 676, 684, 685, 687, 688,
23584 \begin_layout Standard
23585 16F: 716, 72, 73, 737, 74, 76, 767, 77, 777, 785
23588 \begin_layout Standard
23589 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
23593 \begin_layout Standard
23594 16F: 913, 914, 916, 917
23597 \begin_layout Standard
23598 An up-to-date list of currently supported devices can be obtained via
23600 sdcc -mpic14 -phelp foo.c
23602 (foo.c must exist...).
23605 \begin_layout Subsection
23607 \begin_inset LatexCommand \index{code page (pic14)}
23612 \begin_inset LatexCommand \index{Memory bank (pic14)}
23619 \begin_layout Standard
23620 The linker organizes allocation for the code page and RAM banks.
23621 It does not have intimate knowledge of the code flow.
23622 It will put all the code section of a single .asm file into a single code
23624 In order to make use of multiple code pages, separate asm files must be
23626 The compiler assigns all
23630 functions of a single .c file into the same code page.
23634 To get the best results,
23635 follow these guidelines:
23638 \begin_layout Enumerate
23639 Make local functions static, as non static functions require code page selection
23642 Due to the way sdcc handles functions, place called functions prior
23643 to calling functions in the file wherever possible: Otherwise sdcc will
23644 insert unneccessary pagesel directives around the call, believing that
23645 the called function is externally defined.
23648 \begin_layout Enumerate
23649 For devices that have multiple code pages it is more efficient to use the
23650 same number of files as pages: Use up to 4 separate .c files for the 16F877,
23651 but only 2 files for the 16F874.
23652 This way the linker can put the code for each file into different code
23653 pages and there will be less page selection overhead.
23656 \begin_layout Enumerate
23657 And as for any 8 bit micro (especially for PIC14 as they have a very simple
23658 instruction set), use `unsigned char' wherever possible instead of `int'.
23661 \begin_layout Subsection
23662 Adding New Devices to the Port
23665 \begin_layout Standard
23666 Adding support for a new 14
23670 \begin_layout Standard
23679 bit PIC MCU requires the following steps:
23682 \begin_layout Enumerate
23683 Create a new device description.
23685 Each device is described in two files: pic16f*.h
23687 These files primarily define SFRs, structs to access their bits, and symbolic
23688 configuration options.
23689 Both files can be generated from gputils' .inc files using the perl script
23692 support/scripts/inc2h.pl
23695 This file also contains further instructions on how to proceed.
23698 \begin_layout Enumerate
23699 Copy the .h file into SDCC's include path and either add the .c file to your
23700 project or copy it to
23702 device/lib/pic/libdev
23705 Afterwards, rebuild and install the libraries.
23708 \begin_layout Enumerate
23709 Edit pic14devices.txt in SDCC's include path (
23711 device/include/pic/
23713 in the source tree or
23715 /usr/local/share/sdcc/include/pic
23717 after installation).
23719 You need to add a device specification here to make
23720 the memory layout (code banks, RAM, aliased memory regions, ...) known to
23722 Probably you can copy and modify an existing entry.
23723 The file format is documented at the top of the file.
23726 \begin_layout Subsection
23730 \begin_layout Standard
23731 For the interrupt function, use the keyword `__interrupt'
23732 \begin_inset LatexCommand \index{PIC14!interrupt}
23736 with level number of 0 (PIC14 only has 1 interrupt so this number is only
23737 there to avoid a syntax error - it ought to be fixed).
23741 \begin_layout Verse
23744 void Intr(void) __interrupt 0
23750 T0IF = 0; /* Clear timer interrupt */
23755 \begin_layout Subsection
23756 Linking and Assembling
23759 \begin_layout Standard
23760 For assembling you can use either GPUTILS'
23761 \begin_inset LatexCommand \index{gputils (pic tools)}
23765 gpasm.exe or MPLAB's mpasmwin.exe.
23766 GPUTILS are available from
23767 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23772 For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
23773 If you use MPLAB and an interrupt function then the linker script file
23774 vectors section will need to be enlarged to link with mplink.
23785 \begin_layout Verse
23798 sdcc -V -mpic14 -p16f877 -c $<
23802 $(PRJ).hex: $(OBJS)
23812 gplink -m -s $(PRJ).lkr
23813 -o $(PRJ).hex $(OBJS) libsdcc.lib
23816 \begin_layout Standard
23824 \begin_layout Verse
23837 sdcc -S -V -mpic14 -p16f877 $<
23847 mpasmwin /q /o $*.asm
23851 $(PRJ).hex: $(OBJS)
23862 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
23865 \begin_layout Standard
23866 Please note that indentations within a
23870 have to be done with a tabulator character.
23873 \begin_layout Subsection
23874 Command-Line Options
23877 \begin_layout Standard
23878 Besides the switches common to all SDCC backends, the PIC14 port accepts
23879 the following options (for an updated list see sdcc -
23883 \begin_layout Standard
23895 \begin_layout Description
23900 \begin_layout Standard
23910 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
23914 emit debug info in assembly output
23917 \begin_layout Description
23922 \begin_layout Standard
23932 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
23936 disable (slightly faulty) optimization on pCode
23939 \begin_layout Description
23944 \begin_layout Standard
23954 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
23958 sets the lowest address of the argument passing stack (defaults to a suitably
23959 large shared databank to reduce BANKSEL overhead)
23962 \begin_layout Description
23967 \begin_layout Standard
23977 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
23981 sets the size if the argument passing stack (default: 16, minimum: 4)
23984 \begin_layout Subsection
23985 Environment Variables
23988 \begin_layout Standard
23989 The PIC14 port recognizes the following environment variables:
23992 \begin_layout Description
23993 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
23994 register (the ones called r0xNNNN) in a section of its own.
23995 By default (if this variable is unset), sdcc tries to cluster registers
23996 in sections in order to reduce the BANKSEL overhead when accessing them.
23999 \begin_layout Subsection
24003 \begin_layout Standard
24004 The PIC14 library currently only contains support routines required by the
24005 compiler to implement multiplication, division, and floating point support.
24006 No libc-like replacement is available at the moment, though many of the
24007 common sdcc library sources (in
24011 ) should also compile with the PIC14 port.
24014 \begin_layout Subsubsection
24015 error: missing definition for symbol ``__gptrget1''
24018 \begin_layout Standard
24019 The PIC14 port uses library routines to provide more complex operations
24020 like multiplication, division/modulus and (generic) pointer dereferencing.
24021 In order to add these routines to your project, you must link with PIC14's
24027 For single source file projects this is done automatically, more complex
24032 to the linker's arguments.
24033 Make sure you also add an include path for the library (using the -I switch
24037 \begin_layout Subsubsection
24038 Processor mismatch in file ``XXX''.
24041 \begin_layout Standard
24042 This warning can usually be ignored due to the very good compatibility amongst
24047 \begin_layout Standard
24057 \begin_inset LatexCommand \index{PIC14}
24064 \begin_layout Standard
24065 You might also consider recompiling the library for your specific device
24066 by changing the ARCH=p16f877 (default target) entry in
24068 device/lib/pic/Makefile.in
24072 device/lib/pic/Makefile
24074 to reflect your device.
24075 This might even improve performance for smaller devices as unneccesary
24076 BANKSELs might be removed.
24079 \begin_layout Subsection
24083 \begin_layout Subsubsection
24087 \begin_layout Standard
24088 Functions with variable argument lists (like printf) are not yet supported.
24089 Similarly, taking the argument of the first argument passed into a function
24090 does not work: It is currently passed in WREG and has no address...
24093 \begin_layout Subsubsection
24094 Regression tests fail
24097 \begin_layout Standard
24098 Though the small subset of regression tests in src/regression passes, SDCC
24099 regression test suite does not, indicating that there are still major bugs
24101 However, many smaller projects have successfully used SDCC in the past...
24104 \begin_layout Standard
24112 \begin_layout Section
24114 \begin_inset LatexCommand \index{PIC16}
24121 \begin_layout Standard
24122 The PIC16 port adds support for Microchip
24123 \begin_inset LatexCommand \index{Microchip}
24128 \begin_inset Formula $^{\text{TM}}$
24132 \begin_inset LatexCommand \index{PIC}
24137 \begin_inset Formula $^{\text{TM}}$
24140 MCUs with 16 bit wide instructions.
24141 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
24142 ; devices supported by the port include:
24145 \begin_layout Standard
24146 18F: 242, 248, 252, 258, 442, 448, 452, 458
24149 \begin_layout Standard
24153 \begin_layout Standard
24154 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 24j10, 2525, 2550, 25j10,
24158 \begin_layout Standard
24159 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 44j10, 4520, 4525, 4550,
24163 \begin_layout Standard
24164 18F: 6520, 6620, 6680, 6720
24167 \begin_layout Standard
24168 18F: 8520, 8620, 8680, 8720
24171 \begin_layout Subsection
24175 \begin_layout Standard
24176 PIC16 port supports the standard command line arguments as supposed, with
24177 the exception of certain cases that will be mentioned in the following
24181 \begin_layout Description
24186 \begin_layout Standard
24196 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
24204 \begin_layout Standard
24216 \begin_layout Description
24221 \begin_layout Standard
24230 -fommit-frame-pointer
24231 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
24235 Frame pointer will be omitted when the function uses no local variables.
24238 \begin_layout Subsection
24239 Port Specific Options
24240 \begin_inset LatexCommand \index{Options PIC16}
24247 \begin_layout Standard
24248 The port specific options appear after the global options in the sdcc -
24252 \begin_layout Standard
24264 \begin_layout Subsubsection
24265 Code Generation Options
24268 \begin_layout Standard
24269 These options influence the generated assembler code.
24272 \begin_layout Description
24277 \begin_layout Standard
24286 -pstack-model=[model] Used in conjuction with the command above.
24287 Defines the stack model to be used, valid stack models are:
24292 \labelwidthstring 00.00.0000
24297 Selects small stack model.
24298 8 bit stack and frame pointers.
24299 Supports 256 bytes stack size.
24303 \labelwidthstring 00.00.0000
24308 Selects large stack model.
24309 16 bit stack and frame pointers.
24310 Supports 65536 bytes stack size.
24314 \begin_layout Description
24319 \begin_layout Standard
24328 -pno-banksel Do not generate BANKSEL assembler directives.
24331 \begin_layout Description
24336 \begin_layout Standard
24345 -extended Enable extended instruction set/literal offset addressing mode.
24349 \begin_layout Subsubsection
24350 Optimization Options
24353 \begin_layout Description
24358 \begin_layout Standard
24367 -obanksel=n Set optimization level for inserting BANKSELs.
24374 \labelwidthstring 00.00.0000
24379 \labelwidthstring 00.00.0000
24380 1 checks previous used register and if it is the same then does not emit
24381 BANKSEL, accounts only for labels.
24385 \labelwidthstring 00.00.0000
24386 2 tries to check the location of (even different) symbols and removes BANKSELs
24387 if they are in the same bank.
24392 Important: There might be problems if the linker script has data sections
24393 across bank borders!
24397 \begin_layout Description
24402 \begin_layout Standard
24411 -denable-peeps Force the usage of peepholes.
24415 \begin_layout Description
24420 \begin_layout Standard
24429 -optimize-goto Try to use (conditional) BRA instead of GOTO.
24432 \begin_layout Description
24437 \begin_layout Standard
24446 -optimize-cmp Try to optimize some compares.
24449 \begin_layout Description
24454 \begin_layout Standard
24463 -optimize-df Analyze the dataflow of the generated code and improve it.
24466 \begin_layout Subsubsection
24470 \begin_layout Description
24475 \begin_layout Standard
24484 -asm= Sets the full path and name of an external assembler to call.
24487 \begin_layout Description
24492 \begin_layout Standard
24502 \begin_inset LatexCommand \index{PIC16!MPLAB}
24506 compatibility option.
24507 Currently only suppresses special gpasm directives.
24510 \begin_layout Subsubsection
24514 \begin_layout Description
24519 \begin_layout Standard
24528 -link= Sets the full path and name of an external linker to call.
24531 \begin_layout Description
24536 \begin_layout Standard
24545 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
24546 unitialized data variables with [kword].
24547 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
24550 \begin_layout Description
24555 \begin_layout Standard
24564 -ivt-loc=n Place the interrupt vector table at address
24569 Useful for bootloaders.
24572 \begin_layout Description
24577 \begin_layout Standard
24586 -nodefaultlibs Do not link default libraries when linking.
24589 \begin_layout Description
24594 \begin_layout Standard
24603 -use-crt= Use a custom run-time module instead of the defaults.
24606 \begin_layout Description
24611 \begin_layout Standard
24620 -no-crt Don't link the default run-time modules
24623 \begin_layout Subsubsection
24627 \begin_layout Standard
24628 Debugging options enable extra debugging information in the output files.
24631 \begin_layout Description
24636 \begin_layout Standard
24645 -debug-xtra Similar to -
24649 \begin_layout Standard
24659 \begin_inset LatexCommand \index{-\/-debug}
24663 , but dumps more information.
24666 \begin_layout Description
24671 \begin_layout Standard
24680 -debug-ralloc Force register allocator to dump <source>.d file with debugging
24682 <source> is the name of the file being compiled.
24685 \begin_layout Description
24690 \begin_layout Standard
24699 -pcode-verbose Enable pcode debugging information in translation.
24702 \begin_layout Description
24707 \begin_layout Standard
24716 -calltree Dump call tree in .calltree file.
24719 \begin_layout Description
24724 \begin_layout Standard
24733 -gstack Trace push/pops for stack pointer overflow.
24736 \begin_layout Subsection
24737 Enviroment Variables
24740 \begin_layout Standard
24741 There is a number of enviromental variables that can be used when running
24742 SDCC to enable certain optimizations or force a specific program behaviour.
24743 these variables are primarily for debugging purposes so they can be enabled/dis
24747 \begin_layout Standard
24748 Currently there is only two such variables available:
24751 \begin_layout Description
24752 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
24753 bitfields is optimized by directly loading FSR0 with the address of the
24754 bitfield structure.
24755 Normally SDCC will cast the bitfield structure to a bitfield pointer and
24757 This step saves data ram and code space for functions that make heavy use
24759 (i.e., 80 bytes of code space are saved when compiling malloc.c with this
24764 \begin_layout Description
24765 NO_REG_OPT Do not perform pCode registers optimization.
24766 This should be used for debugging purposes.
24767 If bugs in the pcode optimizer are found, users can benefit from temporarily
24768 disabling the optimizer until the bug is fixed.
24771 \begin_layout Subsection
24772 Preprocessor Macros
24775 \begin_layout Standard
24777 \begin_inset LatexCommand \index{PIC16}
24781 port defines the following preprocessor macros while translating a source.
24784 \begin_layout Standard
24786 \begin_inset Tabular
24787 <lyxtabular version="3" rows="6" columns="2">
24789 <column alignment="center" valignment="top" leftline="true" width="0">
24790 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24791 <row topline="true" bottomline="true">
24792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24795 \begin_layout Standard
24801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24804 \begin_layout Standard
24811 <row topline="true">
24812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24815 \begin_layout Standard
24821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24824 \begin_layout Standard
24825 Port identification
24831 <row topline="true">
24832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24835 \begin_layout Standard
24840 \begin_layout Standard
24854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24857 \begin_layout Standard
24858 Port identification (same as above)
24864 <row topline="true">
24865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24868 \begin_layout Standard
24874 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24877 \begin_layout Standard
24878 MCU Identification.
24883 is the microcontrol identification number, i.e.
24890 <row topline="true">
24891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24894 \begin_layout Standard
24899 \begin_layout Standard
24913 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24916 \begin_layout Standard
24917 MCU Identification (same as above)
24923 <row topline="true" bottomline="true">
24924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24927 \begin_layout Standard
24933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24936 \begin_layout Standard
24937 nnn = SMALL or LARGE respectively according to the stack model used
24950 \begin_layout Standard
24951 In addition the following macros are defined when calling assembler:
24954 \begin_layout Standard
24956 \begin_inset Tabular
24957 <lyxtabular version="3" rows="4" columns="2">
24959 <column alignment="center" valignment="top" leftline="true" width="0">
24960 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24961 <row topline="true" bottomline="true">
24962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24965 \begin_layout Standard
24971 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24974 \begin_layout Standard
24981 <row topline="true">
24982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24985 \begin_layout Standard
24991 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24994 \begin_layout Standard
24995 MCU Identification.
25000 is the microcontrol identification number, i.e.
25007 <row topline="true">
25008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25011 \begin_layout Standard
25017 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25020 \begin_layout Standard
25021 nnn = SMALL or LARGE respectively according to the memory model used for
25028 <row topline="true" bottomline="true">
25029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25032 \begin_layout Standard
25038 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25041 \begin_layout Standard
25042 nnn = SMALL or LARGE respectively according to the stack model used
25055 \begin_layout Subsection
25059 \begin_layout Standard
25061 \begin_inset LatexCommand \index{PIC16}
25065 port uses the following directories for searching header files and libraries.
25068 \begin_layout Standard
25070 \begin_inset Tabular
25071 <lyxtabular version="3" rows="3" columns="4">
25073 <column alignment="center" valignment="top" leftline="true" width="0">
25074 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25075 <column alignment="center" valignment="top" width="0">
25076 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25077 <row topline="true" bottomline="true">
25078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25081 \begin_layout Standard
25087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25090 \begin_layout Standard
25096 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25099 \begin_layout Standard
25105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25108 \begin_layout Standard
25115 <row topline="true">
25116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25119 \begin_layout Standard
25120 PREFIX/sdcc/include/pic16
25125 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25128 \begin_layout Standard
25129 PIC16 specific headers
25134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="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
25153 <row topline="true" bottomline="true">
25154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25157 \begin_layout Standard
25158 PREFIX/sdcc/lib/pic16
25163 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25166 \begin_layout Standard
25167 PIC16 specific libraries
25172 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25175 \begin_layout Standard
25181 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25184 \begin_layout Standard
25198 \begin_layout Subsection
25200 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
25207 \begin_layout Standard
25209 \begin_inset LatexCommand \index{PIC16}
25213 port currently supports the following pragmas:
25216 \begin_layout Description
25218 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
25222 This forces the code generator to initialize the stack & frame pointers
25223 at a specific address.
25224 This is an ad hoc solution for cases where no STACK directive is available
25225 in the linker script or gplink is not instructed to create a stack section.
25228 stack pragma should be used only once in a project.
25229 Multiple pragmas may result in indeterminate behaviour of the program.
25233 \begin_layout Standard
25234 The old format (ie.
25235 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
25236 cross page boundaries (or even exceed the available data RAM) and crash
25238 Make sure that stack does not cross page boundaries when using the SMALL
25246 The format is as follows:
25251 \begin_layout LyX-Code
25252 #pragma stack bottom_address [stack_size]
25257 \begin_layout Standard
25262 is the lower bound of the stack section.
25263 The stack pointer initially will point at address (bottom_address+stack_size-1).
25266 \begin_layout LyX-Code
25270 \begin_layout LyX-Code
25274 \begin_layout LyX-Code
25275 /* initializes stack of 100 bytes at RAM address 0x200 */
25278 \begin_layout LyX-Code
25279 #pragma stack 0x200 100
25282 \begin_layout Standard
25283 If the stack_size field is omitted then a stack is created with the default
25285 This size might be enough for most programs, but its not enough for operations
25286 with deep function nesting or excessive stack usage.
25289 \begin_layout Description
25291 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
25295 Force a function to a static FLASH address.
25298 \begin_layout LyX-Code
25302 \begin_layout LyX-Code
25306 \begin_layout LyX-Code
25307 /* place function test_func at 0x4000 */
25310 \begin_layout LyX-Code
25311 #pragma code test_func 0x4000
25314 \begin_layout LyX-Code
25318 \begin_layout Description
25319 library instructs the linker to use a library module.
25324 \begin_layout LyX-Code
25325 #pragma library module_name
25328 \begin_layout Standard
25333 can be any library or object file (including its path).
25334 Note that there are four reserved keywords which have special meaning.
25338 \begin_layout Standard
25340 \begin_inset Tabular
25341 <lyxtabular version="3" rows="6" columns="3">
25343 <column alignment="center" valignment="top" leftline="true" width="0">
25344 <column alignment="block" valignment="top" leftline="true" width="20page%">
25345 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
25346 <row topline="true" bottomline="true">
25347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25350 \begin_layout Standard
25356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25359 \begin_layout Standard
25365 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25368 \begin_layout Standard
25375 <row topline="true">
25376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25379 \begin_layout Standard
25387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25390 \begin_layout Standard
25391 ignore all library pragmas
25396 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25399 \begin_layout Standard
25408 <row topline="true">
25409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25412 \begin_layout Standard
25420 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25423 \begin_layout Standard
25429 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25432 \begin_layout Standard
25443 <row topline="true">
25444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25447 \begin_layout Standard
25455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25458 \begin_layout Standard
25459 link the Math libarary
25464 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25467 \begin_layout Standard
25478 <row topline="true">
25479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25482 \begin_layout Standard
25490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25493 \begin_layout Standard
25494 link the I/O library
25499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25502 \begin_layout Standard
25513 <row topline="true" bottomline="true">
25514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25517 \begin_layout Standard
25525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25528 \begin_layout Standard
25529 link the debug library
25534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25537 \begin_layout Standard
25554 * is the device number, i.e.
25555 452 for PIC18F452 MCU.
25558 \begin_layout Standard
25559 This feature allows for linking with specific libraries withoug having to
25560 explicit name them in the command line.
25565 keyword will reject all modules specified by the library pragma.
25568 \begin_layout Description
25569 udata The pragma udata instructs the compiler to emit code so that linker
25570 will place a variable at a specific memory bank.
25573 \begin_layout LyX-Code
25577 \begin_layout LyX-Code
25581 \begin_layout LyX-Code
25582 /* places variable foo at bank2 */
25585 \begin_layout LyX-Code
25586 #pragma udata bank2 foo
25589 \begin_layout LyX-Code
25593 \begin_layout Standard
25594 In order for this pragma to work extra SECTION directives should be added
25595 in the .lkr script.
25596 In the following example a sample .lkr file is shown:
25599 \begin_layout LyX-Code
25603 \begin_layout LyX-Code
25604 // Sample linker script for the PIC18F452 processor
25607 \begin_layout LyX-Code
25611 \begin_layout LyX-Code
25612 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
25615 \begin_layout LyX-Code
25616 CODEPAGE NAME=page START=0x2A END=0x7FFF
25619 \begin_layout LyX-Code
25620 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
25623 \begin_layout LyX-Code
25624 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
25627 \begin_layout LyX-Code
25628 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
25631 \begin_layout LyX-Code
25632 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
25635 \begin_layout LyX-Code
25636 ACCESSBANK NAME=accessram START=0x0 END=0x7F
25639 \begin_layout LyX-Code
25643 \begin_layout LyX-Code
25644 DATABANK NAME=gpr0 START=0x80 END=0xFF
25647 \begin_layout LyX-Code
25648 DATABANK NAME=gpr1 START=0x100 END=0x1FF
25651 \begin_layout LyX-Code
25652 DATABANK NAME=gpr2 START=0x200 END=0x2FF
25655 \begin_layout LyX-Code
25656 DATABANK NAME=gpr3 START=0x300 END=0x3FF
25659 \begin_layout LyX-Code
25660 DATABANK NAME=gpr4 START=0x400 END=0x4FF
25663 \begin_layout LyX-Code
25664 DATABANK NAME=gpr5 START=0x500 END=0x5FF
25667 \begin_layout LyX-Code
25668 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
25671 \begin_layout LyX-Code
25675 \begin_layout LyX-Code
25676 SECTION NAME=CONFIG ROM=config
25679 \begin_layout LyX-Code
25683 \begin_layout LyX-Code
25684 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
25687 \begin_layout LyX-Code
25688 SECTION NAME=bank1 RAM=gpr1 # should be added to link
25691 \begin_layout LyX-Code
25692 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
25695 \begin_layout LyX-Code
25696 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
25699 \begin_layout LyX-Code
25700 SECTION NAME=bank4 RAM=gpr4
25703 \begin_layout LyX-Code
25704 SECTION NAME=bank5 RAM=gpr5
25707 \begin_layout Standard
25708 The linker will recognise the section name set in the pragma statement and
25709 will position the variable at the memory bank set with the RAM field at
25710 the SECTION line in the linker script file.
25713 \begin_layout Subsection
25715 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
25722 \begin_layout Standard
25723 There is one main header file
25724 \begin_inset LatexCommand \index{PIC16!Header files}
25728 that can be included to the source files using the pic16
25729 \begin_inset LatexCommand \index{PIC16}
25739 This header file contains the definitions for the processor special registers,
25740 so it is necessary if the source accesses them.
25741 It can be included by adding the following line in the beginning of the
25745 \begin_layout LyX-Code
25746 #include <pic18fregs.h>
25749 \begin_layout Standard
25750 The specific microcontroller is selected within the pic18fregs.h automatically,
25751 so the same source can be used with a variety of devices.
25754 \begin_layout Subsection
25758 \begin_layout Standard
25760 \begin_inset LatexCommand \index{PIC16!Libraries}
25765 \begin_inset LatexCommand \index{PIC16}
25769 port depends on are the microcontroller device libraries which contain
25770 the symbol definitions for the microcontroller special function registers.
25771 These libraries have the format pic18fxxxx.lib, where
25775 is the microcontroller identification number.
25776 The specific library is selected automatically by the compiler at link
25777 stage according to the selected device.
25780 \begin_layout Standard
25781 Libraries are created with gplib which is part of the gputils package
25782 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
25789 \begin_layout Subsubsection*
25790 Building the libraries
25793 \begin_layout Standard
25794 Before using SDCC/pic16 there are some libraries that need to be compiled.
25795 This process is not done automatically by SDCC since not all users use
25796 SDCC for pic16 projects.
25797 So each user should compile the libraries separately.
25800 \begin_layout Standard
25801 The steps to compile the pic16 libraries under Linux and Mac OS X are:
25804 \begin_layout LyX-Code
25805 cd device/lib/pic16
25808 \begin_layout LyX-Code
25812 \begin_layout LyX-Code
25816 \begin_layout LyX-Code
25820 \begin_layout LyX-Code
25824 \begin_layout LyX-Code
25825 su -c 'make install' # install the libraries, you need the root password
25828 \begin_layout Standard
25829 If you need to install the headers too, do:
25832 \begin_layout LyX-Code
25836 \begin_layout LyX-Code
25837 su -c 'make install' # install the headers, you need the root password
25840 \begin_layout Standard
25841 There exist a special target to build the I/O libraries.
25842 This target is not automatically build because it will build the I/O library
25848 This way building will take quite a lot of time.
25849 Users are advised to edit the
25851 device/lib/pic16/pics.build
25853 file and then execute:
25856 \begin_layout LyX-Code
25860 \begin_layout Subsection
25861 Adding New Devices to the Port
25864 \begin_layout Standard
25865 Adding support for a new 16
25869 \begin_layout Standard
25878 bit PIC MCU requires the following steps:
25881 \begin_layout Enumerate
25882 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
25886 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
25890 \begin_layout Enumerate
25893 mv picDEVICE.h /path/to/sdcc/device/include/pic16
25896 \begin_layout Enumerate
25899 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
25902 \begin_layout Enumerate
25905 /path/to/sdcc/device/lib/pic16/pics.all
25913 Note: No 18f prefix here!
25916 \begin_layout Enumerate
25919 /path/to/sdcc/device/lib/pic16/libio/*.ignore
25923 Add your DEVICE if it does not compile in
25938 \begin_layout Enumerate
25941 /path/to/sdcc/device/include/pic16/pic18fregs.h
25944 The file format is self-explanatory, just add
25948 #elif defined(picDEVICE)
25950 # include <picDEVICE.h>
25954 at the right place (keep it sorted).
25957 \begin_layout Enumerate
25960 /path/to/sdcc/src/pic16/devices.inc
25963 Copy and modify an existing entry and insert it at the correct place (keep
25965 The file is hardly documented, look at the entries for the 18f2221...
25968 \begin_layout Enumerate
25969 Recompile SDCC, including the pic16 libraries.
25972 \begin_layout Subsection
25976 \begin_layout Standard
25977 The following memory models are supported by the PIC16 port:
25980 \begin_layout Itemize
25984 \begin_layout Itemize
25988 \begin_layout Standard
25989 Memory model affects the default size of pointers within the source.
25990 The sizes are shown in the next table:
25993 \begin_layout Standard
25995 \begin_inset Tabular
25996 <lyxtabular version="3" rows="3" columns="3">
25998 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25999 <column alignment="center" valignment="top" leftline="true" width="0">
26000 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26001 <row topline="true" bottomline="true">
26002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26005 \begin_layout Standard
26006 Pointer sizes according to memory model
26011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26014 \begin_layout Standard
26020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26023 \begin_layout Standard
26030 <row topline="true" bottomline="true">
26031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26034 \begin_layout Standard
26040 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26043 \begin_layout Standard
26049 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26052 \begin_layout Standard
26059 <row topline="true" bottomline="true">
26060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26063 \begin_layout Standard
26069 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
26072 \begin_layout Standard
26078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26081 \begin_layout Standard
26095 \begin_layout Standard
26096 It is advisable that all sources within a project are compiled with the
26098 If one wants to override the default memory model, this can be done by
26099 declaring a pointer as
26108 Far selects large memory model's pointers, while near selects small memory
26112 \begin_layout Standard
26113 The standard device libraries (see
26114 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
26118 ) contain no reference to pointers, so they can be used with both memory
26122 \begin_layout Subsection
26126 \begin_layout Standard
26128 \begin_inset LatexCommand \index{PIC16!stack}
26132 implementation for the PIC16 port uses two indirect registers, FSR1 and
26136 \begin_layout Description
26137 FSR1 is assigned as stack pointer
26140 \begin_layout Description
26141 FSR2 is assigned as frame pointer
26144 \begin_layout Standard
26145 The following stack models are supported by the PIC16 port
26148 \begin_layout Itemize
26156 \begin_layout Itemize
26164 \begin_layout Standard
26169 model means that only the FSRxL byte is used to access stack and frame,
26176 uses both FSRxL and FSRxH registers.
26177 The following table shows the stack/frame pointers sizes according to stack
26178 model and the maximum space they can address:
26181 \begin_layout Standard
26183 \begin_inset Tabular
26184 <lyxtabular version="3" rows="3" columns="3">
26186 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26187 <column alignment="center" valignment="top" leftline="true" width="0">
26188 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26189 <row topline="true" bottomline="true">
26190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26193 \begin_layout Standard
26194 Stack & Frame pointer sizes according to stack model
26199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26202 \begin_layout Standard
26208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26211 \begin_layout Standard
26218 <row topline="true">
26219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26222 \begin_layout Standard
26228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26231 \begin_layout Standard
26237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26240 \begin_layout Standard
26247 <row topline="true" bottomline="true">
26248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26251 \begin_layout Standard
26257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26260 \begin_layout Standard
26266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26269 \begin_layout Standard
26283 \begin_layout Standard
26288 stack model is currently not working properly throughout the code generator.
26289 So its use is not advised.
26290 Also there are some other points that need special care:
26295 \begin_layout Enumerate
26296 Do not create stack sections with size more than one physical bank (that
26300 \begin_layout Enumerate
26301 Stack sections should no cross physical bank limits (i.e.
26302 #pragma stack 0x50 0x100)
26305 \begin_layout Standard
26306 These limitations are caused by the fact that only FSRxL is modified when
26307 using SMALL stack model, so no more than 256 bytes of stack can be used.
26308 This problem will disappear after LARGE model is fully implemented.
26311 \begin_layout Subsection
26315 \begin_layout Standard
26316 In addition to the standard SDCC function keywords, PIC16
26317 \begin_inset LatexCommand \index{PIC16}
26321 port makes available two more:
26324 \begin_layout Description
26326 \begin_inset LatexCommand \index{PIC16!wparam}
26330 Use the WREG to pass one byte of the first function argument.
26331 This improves speed but you may not use this for functions with arguments
26332 that are called via function pointers, otherwise the first byte of the
26333 first parameter will get lost.
26337 \begin_layout LyX-Code
26338 void func_wparam(int a) wparam
26341 \begin_layout LyX-Code
26345 \begin_layout LyX-Code
26346 /* WREG hold the lower part of a */
26349 \begin_layout LyX-Code
26350 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
26354 \begin_layout LyX-Code
26358 \begin_layout LyX-Code
26362 \begin_layout Description
26364 \begin_inset LatexCommand \index{PIC16!shadowregs}
26368 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
26369 hardware shadow registers which hold the values of WREG, STATUS and BSR
26371 This can be done by adding the keyword
26379 keyword in the function's header.
26382 \begin_layout LyX-Code
26383 void isr_shadow(void) shadowregs interrupt 1
26386 \begin_layout LyX-Code
26390 \begin_layout LyX-Code
26394 \begin_layout LyX-Code
26398 \begin_layout Standard
26403 instructs the code generator not to store/restore WREG, STATUS, BSR when
26404 entering/exiting the ISR.
26407 \begin_layout Subsection
26408 Function return values
26411 \begin_layout Standard
26412 Return values from functions are placed to the appropriate registers following
26413 a modified Microchip policy optimized for SDCC.
26414 The following table shows these registers:
26417 \begin_layout Standard
26419 \begin_inset Tabular
26420 <lyxtabular version="3" rows="6" columns="2">
26422 <column alignment="center" valignment="top" leftline="true" width="0">
26423 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26424 <row topline="true" bottomline="true">
26425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26428 \begin_layout Standard
26434 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26437 \begin_layout Standard
26438 destination register
26444 <row topline="true">
26445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26448 \begin_layout Standard
26454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26457 \begin_layout Standard
26464 <row topline="true">
26465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26468 \begin_layout Standard
26474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26477 \begin_layout Standard
26484 <row topline="true">
26485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26488 \begin_layout Standard
26494 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26497 \begin_layout Standard
26504 <row topline="true">
26505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26508 \begin_layout Standard
26514 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26517 \begin_layout Standard
26518 FSR0L:PRODH:PRODL:WREG
26524 <row topline="true" bottomline="true">
26525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26528 \begin_layout Standard
26534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26537 \begin_layout Standard
26538 on stack, FSR0 points to the beginning
26551 \begin_layout Subsection
26555 \begin_layout Standard
26557 \begin_inset LatexCommand \index{PIC16!interrupt}
26561 service routine (ISR) is declared using the
26568 \begin_layout LyX-Code
26569 void isr(void) interrupt
26574 \begin_layout LyX-Code
26578 \begin_layout LyX-Code
26582 \begin_layout LyX-Code
26586 \begin_layout Standard
26591 is the interrupt number, which for PIC18F devices can be:
26594 \begin_layout Standard
26596 \begin_inset Tabular
26597 <lyxtabular version="3" rows="4" columns="3">
26599 <column alignment="center" valignment="top" leftline="true" width="0">
26600 <column alignment="center" valignment="top" leftline="true" width="0">
26601 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26602 <row topline="true" bottomline="true">
26603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26606 \begin_layout Standard
26614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26617 \begin_layout Standard
26623 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26626 \begin_layout Standard
26627 Interrupt Vector Address
26633 <row topline="true">
26634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26637 \begin_layout Standard
26643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26646 \begin_layout Standard
26652 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26655 \begin_layout Standard
26662 <row topline="true">
26663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26666 \begin_layout Standard
26681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26684 \begin_layout Standard
26694 HIGH priority interrupts
26699 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26702 \begin_layout Standard
26709 <row topline="true" bottomline="true">
26710 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26713 \begin_layout Standard
26719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26722 \begin_layout Standard
26723 LOW priority interrupts
26728 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26731 \begin_layout Standard
26745 \begin_layout Standard
26746 When generating assembly code for ISR the code generator places a
26752 Interrupt Vector Address
26754 which points at the genetated ISR.
26755 This single GOTO instruction is part of an automatically generated
26757 interrupt entry point
26760 The actuall ISR code is placed as normally would in the code space.
26761 Upon interrupt request, the GOTO instruction is executed which jumps to
26763 When declaring interrupt functions as _naked this GOTO instruction is
26768 The whole interrupt functions is therefore placed at the Interrupt Vector
26769 Address of the specific interrupt.
26770 This is not a problem for the LOW priority interrupts, but it is a problem
26771 for the RESET and the HIGH priority interrupts because code may be written
26772 at the next interrupt's vector address and cause undeterminate program
26773 behaviour if that interrupt is raised.
26777 \begin_layout Standard
26778 This is not a problem when
26781 \begin_layout Enumerate
26782 this is a HIGH interrupt ISR and LOW interrupts are
26789 \begin_layout Enumerate
26790 when the ISR is small enough not to reach the next interrupt's vector address.
26798 \begin_layout Standard
26804 This way a function is generated similar to an ISR, but it is not assigned
26808 \begin_layout Standard
26809 When entering an interrupt, currently the PIC16
26810 \begin_inset LatexCommand \index{PIC16}
26814 port automatically saves the following registers:
26817 \begin_layout Itemize
26821 \begin_layout Itemize
26825 \begin_layout Itemize
26829 \begin_layout Itemize
26830 PROD (PRODL and PRODH)
26833 \begin_layout Itemize
26834 FSR0 (FSR0L and FSR0H)
26837 \begin_layout Standard
26838 These registers are restored upon return from the interrupt routine.
26842 \begin_layout Standard
26843 NOTE that when the _naked attribute is specified for an interrupt routine,
26844 then NO registers are stored or restored.
26852 \begin_layout Subsection
26856 \begin_layout Standard
26857 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
26858 There are 3 types of generic pointers currently implemented data, code
26859 and eeprom pointers.
26860 They are differentiated by the value of the 7th and 6th bits of the upper
26864 \begin_layout Standard
26866 \begin_inset Tabular
26867 <lyxtabular version="3" rows="5" columns="5">
26869 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26870 <column alignment="center" valignment="top" width="0">
26871 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26872 <column alignment="center" valignment="top" width="0">
26873 <column alignment="left" valignment="top" rightline="true" width="0">
26874 <row topline="true" bottomline="true">
26875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26878 \begin_layout Standard
26884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26887 \begin_layout Standard
26893 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26896 \begin_layout Standard
26902 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26905 \begin_layout Standard
26906 rest of the pointer
26911 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26914 \begin_layout Standard
26921 <row topline="true" bottomline="true">
26922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26925 \begin_layout Standard
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" rightline="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
26957 uuuuuu uuuuxxxx xxxxxxxx
26962 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26965 \begin_layout Standard
26966 a 12-bit data pointer in data RAM memory
26972 <row bottomline="true">
26973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26976 \begin_layout Standard
26982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26985 \begin_layout Standard
26991 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26994 \begin_layout Standard
27000 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27003 \begin_layout Standard
27008 uxxxxx xxxxxxxx xxxxxxxx
27013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27016 \begin_layout Standard
27017 a 21-bit code pointer in FLASH memory
27023 <row bottomline="true">
27024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27027 \begin_layout Standard
27033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27036 \begin_layout Standard
27042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27045 \begin_layout Standard
27051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27054 \begin_layout Standard
27059 uuuuuu uuuuuuxx xxxxxxxx
27064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27067 \begin_layout Standard
27068 a 10-bit eeprom pointer in EEPROM memory
27074 <row bottomline="true">
27075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27078 \begin_layout Standard
27084 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27087 \begin_layout Standard
27093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27096 \begin_layout Standard
27102 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27105 \begin_layout Standard
27110 xxxxxx xxxxxxxx xxxxxxxx
27115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27118 \begin_layout Standard
27119 unimplemented pointer type
27132 \begin_layout Standard
27133 Generic pointer are read and written with a set of library functions which
27134 read/write 1, 2, 3, 4 bytes.
27137 \begin_layout Subsection
27141 \begin_layout Subsubsection
27142 Standard I/O Streams
27145 \begin_layout Standard
27150 the type FILE is defined as:
27153 \begin_layout LyX-Code
27154 typedef char * FILE;
27157 \begin_layout Standard
27158 This type is the stream type implemented I/O in the PIC18F devices.
27159 Also the standard input and output streams are declared in stdio.h:
27162 \begin_layout LyX-Code
27163 extern FILE * stdin;
27166 \begin_layout LyX-Code
27167 extern FILE * stdout;
27170 \begin_layout Standard
27171 The FILE type is actually a generic pointer which defines one more type
27172 of generic pointers, the
27177 This new type has the format:
27180 \begin_layout Standard
27182 \begin_inset Tabular
27183 <lyxtabular version="3" rows="2" columns="7">
27185 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27186 <column alignment="center" valignment="top" width="0">
27187 <column alignment="center" valignment="top" leftline="true" width="0">
27188 <column alignment="center" valignment="top" leftline="true" width="0">
27189 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27190 <column alignment="center" valignment="top" width="0">
27191 <column alignment="left" valignment="top" rightline="true" width="0">
27192 <row topline="true" bottomline="true">
27193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27196 \begin_layout Standard
27202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27205 \begin_layout Standard
27211 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27214 \begin_layout Standard
27220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27223 \begin_layout Standard
27229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27232 \begin_layout Standard
27238 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27241 \begin_layout Standard
27242 rest of the pointer
27247 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27250 \begin_layout Standard
27257 <row topline="true" bottomline="true">
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" 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
27303 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27306 \begin_layout Standard
27316 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27319 \begin_layout Standard
27320 upper byte high nubble is 0x2n, the rest are zeroes
27333 \begin_layout Standard
27334 Currently implemented there are 3 types of streams defined:
27337 \begin_layout Standard
27339 \begin_inset Tabular
27340 <lyxtabular version="3" rows="4" columns="4">
27342 <column alignment="center" valignment="top" leftline="true" width="0">
27343 <column alignment="center" valignment="top" leftline="true" width="0">
27344 <column alignment="center" valignment="top" leftline="true" width="0">
27345 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27346 <row topline="true" bottomline="true">
27347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27350 \begin_layout Standard
27356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27359 \begin_layout Standard
27365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27368 \begin_layout Standard
27374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27377 \begin_layout Standard
27384 <row topline="true">
27385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27388 \begin_layout Standard
27394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27397 \begin_layout Standard
27405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27408 \begin_layout Standard
27414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27417 \begin_layout Standard
27418 Writes/Reads characters via the USART peripheral
27424 <row topline="true">
27425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27428 \begin_layout Standard
27434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27437 \begin_layout Standard
27445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27448 \begin_layout Standard
27454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27457 \begin_layout Standard
27458 Writes/Reads characters via the MSSP peripheral
27464 <row topline="true" bottomline="true">
27465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27468 \begin_layout Standard
27474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27477 \begin_layout Standard
27485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27488 \begin_layout Standard
27494 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27497 \begin_layout Standard
27498 Writes/Reads characters via used defined functions
27511 \begin_layout Standard
27512 The stream identifiers are declared as macros in the stdio.h header.
27515 \begin_layout Standard
27516 In the libc library there exist the functions that are used to write to
27517 each of the above streams.
27521 \begin_layout Description
27526 \begin_layout Standard
27535 _stream_usart_putchar writes a character at the USART stream
27538 \begin_layout Description
27543 \begin_layout Standard
27552 _stream_mssp_putchar writes a character at the MSSP stream
27555 \begin_layout Description
27556 putchar dummy function.
27557 This writes a character to a user specified manner.
27560 \begin_layout Standard
27561 In order to increase performance
27565 is declared in stdio.h as having its parameter in WREG (it has the wparam
27567 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
27568 in a user-friendly way.
27573 is the name of the variable that holds the character to print.
27574 An example follows:
27577 \begin_layout LyX-Code
27578 #include <pic18fregs.h>
27587 \begin_layout LyX-Code
27591 \begin_layout LyX-Code
27592 PORTA = c; /* dump character c to PORTA */
27595 \begin_layout LyX-Code
27603 \begin_layout LyX-Code
27607 \begin_layout LyX-Code
27608 stdout = STREAM_USER; /* this is not necessary, since stdout points
27611 \begin_layout LyX-Code
27612 * by default to STREAM_USER */
27615 \begin_layout LyX-Code
27617 \begin_inset Quotes sld
27620 This is a printf test
27623 \begin_inset Quotes srd
27629 \begin_layout LyX-Code
27633 \begin_layout LyX-Code
27637 \begin_layout Subsubsection
27641 \begin_layout Standard
27642 PIC16 contains an implementation of the printf-family of functions.
27643 There exist the following functions:
27646 \begin_layout LyX-Code
27647 extern unsigned int sprintf(char *buf, char *fmt, ...);
27650 \begin_layout LyX-Code
27651 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
27654 \begin_layout LyX-Code
27658 \begin_layout LyX-Code
27659 extern unsigned int printf(char *fmt, ...);
27662 \begin_layout LyX-Code
27663 extern unsigned int vprintf(char *fmt, va_lista ap);
27666 \begin_layout LyX-Code
27670 \begin_layout LyX-Code
27671 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
27674 \begin_layout LyX-Code
27675 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
27678 \begin_layout Standard
27679 For sprintf and vsprintf
27683 should normally be a data pointer where the resulting string will be placed.
27684 No range checking is done so the user should allocate the necessery buffer.
27685 For fprintf and vfprintf
27689 should be a stream pointer (i.e.
27690 stdout, STREAM_MSSP, etc...).
27693 \begin_layout Subsubsection
27697 \begin_layout Standard
27698 The PIC18F family of microcontrollers supports a number of interrupt sources.
27699 A list of these interrupts is shown in the following table:
27702 \begin_layout Standard
27704 \begin_inset Tabular
27705 <lyxtabular version="3" rows="11" columns="4">
27707 <column alignment="left" valignment="top" leftline="true" width="0">
27708 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27709 <column alignment="left" valignment="top" leftline="true" width="0">
27710 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27711 <row topline="true" bottomline="true">
27712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27715 \begin_layout Standard
27721 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27724 \begin_layout Standard
27730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27733 \begin_layout Standard
27739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27742 \begin_layout Standard
27749 <row topline="true">
27750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27753 \begin_layout Standard
27759 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27762 \begin_layout Standard
27763 PORTB change interrupt
27768 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="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
27781 EEPROM/FLASH write complete interrupt
27787 <row topline="true">
27788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27791 \begin_layout Standard
27797 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27800 \begin_layout Standard
27801 INT0 external interrupt
27806 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27809 \begin_layout Standard
27815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27818 \begin_layout Standard
27819 Bus collision interrupt
27825 <row topline="true">
27826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27829 \begin_layout Standard
27835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27838 \begin_layout Standard
27839 INT1 external interrupt
27844 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="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 Low voltage detect interrupt
27863 <row topline="true">
27864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27867 \begin_layout Standard
27873 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27876 \begin_layout Standard
27877 INT2 external interrupt
27882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="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 Parallel slave port interrupt
27901 <row topline="true">
27902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27905 \begin_layout Standard
27911 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27914 \begin_layout Standard
27915 CCP1 module interrupt
27920 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="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 AD convertion complete interrupt
27939 <row topline="true">
27940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27943 \begin_layout Standard
27949 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27952 \begin_layout Standard
27953 CCP2 module interrupt
27958 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="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 USART receive interrupt
27977 <row topline="true">
27978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27981 \begin_layout Standard
27987 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27990 \begin_layout Standard
27991 TMR0 overflow interrupt
27996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="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 USART transmit interrupt
28015 <row topline="true">
28016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28019 \begin_layout Standard
28025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28028 \begin_layout Standard
28029 TMR1 overflow interrupt
28034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="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 SSP receive/transmit interrupt
28053 <row topline="true">
28054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28057 \begin_layout Standard
28063 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28066 \begin_layout Standard
28067 TMR2 matches PR2 interrupt
28072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="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
28091 <row topline="true" bottomline="true">
28092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28095 \begin_layout Standard
28101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28104 \begin_layout Standard
28105 TMR3 overflow interrupt
28110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="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
28136 \begin_layout Standard
28137 The prototypes for these names are defined in the header file
28144 \begin_layout Standard
28145 In order to simplify signal handling, a number of macros is provided:
28149 \labelwidthstring 00.00.0000
28150 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
28151 high priority interrupts.
28156 is the function name to use.
28160 \labelwidthstring 00.00.0000
28161 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
28162 low priority interrupt.
28167 is the function name to use.
28171 \labelwidthstring 00.00.0000
28172 DEF_HANDLER(sig,handler) define a handler for signal
28178 \labelwidthstring 00.00.0000
28179 END_DEF end the declaration of the dispatch table.
28182 \begin_layout Standard
28183 Additionally there are two more macros to simplify the declaration of the
28188 \labelwidthstring 00.00.0000
28191 SIGHANDLER(handler)
28193 this declares the function prototype for the
28201 \labelwidthstring 00.00.0000
28202 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
28205 \begin_layout Standard
28206 An example of using the macros above is shown below:
28209 \begin_layout LyX-Code
28210 #include <pic18fregs.h>
28213 \begin_layout LyX-Code
28214 #include <signal.h>
28218 DEF_INTHIGH(high_int)
28221 \begin_layout LyX-Code
28222 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
28225 \begin_layout LyX-Code
28226 DEF_HANDLER(SIG_BCOL, _bcol_handler)
28229 \begin_layout LyX-Code
28234 SIGHANDLER(_tmr0_handler)
28237 \begin_layout LyX-Code
28241 \begin_layout LyX-Code
28242 /* action to be taken when timer 0 overflows */
28245 \begin_layout LyX-Code
28250 SIGHANDLERNAKED(_bcol_handler)
28253 \begin_layout LyX-Code
28257 \begin_layout LyX-Code
28261 \begin_layout LyX-Code
28262 /* action to be taken when bus collision occurs */
28265 \begin_layout LyX-Code
28269 \begin_layout LyX-Code
28273 \begin_layout LyX-Code
28277 \begin_layout Standard
28282 Special care should be taken when using the above scheme:
28285 \begin_layout Itemize
28286 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
28289 \begin_layout Itemize
28290 when declaring SIGHANDLERNAKED handler never forget to use
28294 for proper returning.
28297 \begin_layout Subsection
28301 \begin_layout Standard
28302 Here you can find some general tips for compiling programs with SDCC/pic16.
28305 \begin_layout Subsubsection
28309 \begin_layout Standard
28311 \begin_inset LatexCommand \index{PIC16!stack}
28315 size (that is 64 bytes) probably is enough for many programs.
28316 One must take care that when there are many levels of function nesting,
28317 or there is excessive usage of stack, its size should be extended.
28318 An example of such a case is the printf/sprintf family of functions.
28319 If you encounter problems like not being able to print integers, then you
28320 need to set the stack size around the maximum (256 for small stack model).
28321 The following diagram shows what happens when calling printf to print an
28325 \begin_layout LyX-Code
28326 printf () --> ltoa () --> ultoa () --> divschar ()
28329 \begin_layout Standard
28330 It is should be understood that stack is easily consumed when calling complicate
28332 Using command line arguments like -
28336 \begin_layout Standard
28345 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
28347 Other ways to reduce stack usage may exist.
28350 \begin_layout Subsection
28354 \begin_layout Standard
28355 The PIC16 Port currently does not pass SDCC's regression test
28356 \begin_inset LatexCommand \index{Regression test (PIC16)}
28361 \begin_inset LatexCommand \ref{sec:Quality-control}
28365 ) and thus the snapshot build regression tests for the PIC16 target are
28366 currently disabled for all hosts
28371 \begin_layout Chapter
28375 \begin_layout Standard
28376 There are several approaches to debugging your code.
28377 This chapter is meant to show your options and to give detail on some of
28382 When writing your code:
28385 \begin_layout Itemize
28386 write your code with debugging in mind (avoid duplicating code, put conceptually
28387 similar variables into structs, use structured code, have strategic points
28388 within your code where all variables are consistent, ...)
28391 \begin_layout Itemize
28392 run a syntax-checking tool like splint
28393 \begin_inset LatexCommand \index{splint (syntax checking tool)}
28398 \begin_inset LatexCommand \index{lint (syntax checking tool)}
28406 \begin_layout Standard
28416 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28423 \begin_layout Itemize
28424 for the high level code use a C-compiler (like f.e.
28425 GCC) to compile run and debug the code on your host.
28430 \begin_layout Standard
28440 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28444 ) on how to handle syntax extensions like __xdata, __at(), ...
28448 \begin_layout Itemize
28449 use another C-compiler to compile code for your target.
28450 Always an option but not recommended:) And not very likely to help you.
28451 If you seriously consider walking this path you should at least occasionally
28452 check portability of your code.
28453 Most commercial compiler vendors will offer an evaluation version so you
28454 can test compile your code or snippets of your code.
28457 \begin_layout Standard
28458 Debugging on a simulator:
28461 \begin_layout Itemize
28462 there is a separate section about SDCDB (section
28463 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
28470 \begin_layout Itemize
28471 or (8051 specific) use a freeware/commercial simulator which interfaces
28473 \begin_inset LatexCommand \index{AOMF, AOMF51}
28478 \begin_inset LatexCommand \ref{OMF file}
28482 ) optionally generated by SDCC.
28485 \begin_layout Standard
28486 Debugging On-target:
28489 \begin_layout Itemize
28490 use a MCU port pin to serially output debug data to the RS232 port of your
28492 You'll probably want some level shifting device typically involving a MAX232
28494 If the hardware serial port of the MCU is not available search for 'Software
28495 UART' in your favourite search machine.
28498 \begin_layout Itemize
28499 use an on-target monitor.
28500 In this context a monitor is a small program which usually accepts commands
28501 via a serial line and allows to set program counter, to single step through
28502 a program and read/write memory locations.
28503 For the 8051 good examples of monitors are paulmon and cmon51 (see section
28505 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
28512 \begin_layout Itemize
28513 toggle MCU port pins at strategic points within your code and use an oscilloscop
28517 digital oscilloscope
28520 \begin_inset LatexCommand \index{Oscilloscope}
28524 with deep trace memory is really helpful especially if you have to debug
28525 a realtime application.
28526 If you need to monitor more pins than your oscilloscope provides you can
28527 sometimes get away with a small R-2R network.
28528 On a single channel oscilloscope you could f.e.
28529 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
28531 \begin_inset Formula $\Omega$
28534 resistor and the other one by a 5\InsetSpace ~
28536 \begin_inset Formula $\Omega$
28539 resistor to the oscilloscope probe (check output drive capability of the
28540 pins you want to monitor).
28541 If you need to monitor many more pins a
28548 \begin_layout Itemize
28562 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
28567 Usually very expensive.
28568 And very nice to have too.
28569 And usually locks you (for years...) to the devices the ICE can emulate.
28573 \begin_layout Itemize
28574 use a remote debugger.
28575 In most 8-bit systems the symbol information is not available on the target,
28576 and a complete debugger is too bulky for the target system.
28577 Therefore usually a debugger on the host system connects to an on-target
28578 debugging stub which accepts only primitive commands.
28581 Terms to enter into your favourite search engine could be 'remote debugging',
28582 'gdb stub' or 'inferior debugger'.
28586 \begin_layout Itemize
28587 use an on target hardware debugger.
28588 Some of the more modern MCUs include hardware support for setting break
28589 points and monitoring/changing variables by using dedicated hardware pins.
28590 This facility doesn't require additional code to run on the target and
28595 doesn't affect runtime behaviour until a breakpoint is hit.
28596 For the mcs51 most hardware debuggers use the AOMF
28597 \begin_inset LatexCommand \index{AOMF, AOMF51}
28602 \begin_inset LatexCommand \ref{OMF file}
28610 \begin_layout Standard
28614 \begin_layout Itemize
28615 if you are not familiar with any of the following terms you're likely to
28616 run into problems rather sooner than later:
28633 As an embedded programmer you
28637 to know them so why not look them up
28641 you have problems?)
28644 \begin_layout Itemize
28645 tell someone else about your problem (actually this is a surprisingly effective
28646 means to hunt down the bug even if the listener is not familiar with your
28648 As 'failure to communicate' is probably one of the job-induced deformations
28649 of an embedded programmer this is highly encouraged.
28652 \begin_layout Section
28653 Debugging with SDCDB
28654 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
28659 \begin_inset LatexCommand \index{SDCDB (debugger)}
28666 \begin_layout Standard
28667 SDCC is distributed with a source level debugger
28668 \begin_inset LatexCommand \index{Debugger}
28673 The debugger uses a command line interface, the command repertoire of the
28674 debugger has been kept as close to gdb
28675 \begin_inset LatexCommand \index{gdb}
28679 (the GNU debugger) as possible.
28680 The configuration and build process is part of the standard compiler installati
28681 on, which also builds and installs the debugger in the target directory
28682 specified during configuration.
28683 The debugger allows you debug BOTH at the C source and at the ASM source
28687 \begin_layout Subsection
28688 Compiling for Debugging
28691 \begin_layout Standard
28696 \begin_layout Standard
28706 \begin_inset LatexCommand \index{-\/-debug}
28710 option must be specified for all files for which debug information is to
28712 The compiler generates a .adb file for each of these files.
28713 The linker creates the .cdb
28714 \begin_inset LatexCommand \index{<file>.cdb}
28719 \begin_inset LatexCommand \index{<file>.adb}
28723 files and the address information.
28724 This .cdb is used by the debugger.
28727 \begin_layout Subsection
28728 How the Debugger Works
28731 \begin_layout Standard
28736 \begin_layout Standard
28745 -debug option is specified the compiler generates extra symbol information
28746 some of which are put into the assembler source and some are put into the
28748 Then the linker creates the .cdb file from the individual .adb files with
28749 the address information for the symbols.
28750 The debugger reads the symbolic information generated by the compiler &
28751 the address information generated by the linker.
28752 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
28753 execution is controlled by the debugger.
28754 When a command is issued for the debugger, it translates it into appropriate
28755 commands for the simulator.
28756 (Currently SDCDM only connects to the simulator but
28761 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
28765 is an effort to connect directly to the hardware.)
28768 \begin_layout Subsection
28769 Starting the Debugger SDCDB
28772 \begin_layout Standard
28773 The debugger can be started using the following command line.
28774 (Assume the file you are debugging has the file name foo).
28788 The debugger will look for the following files.
28791 \begin_layout Itemize
28792 foo.c - the source file.
28795 \begin_layout Itemize
28796 foo.cdb - the debugger symbol information file.
28799 \begin_layout Itemize
28800 foo.ihx - the Intel hex format
28801 \begin_inset LatexCommand \index{Intel hex format}
28808 \begin_layout Subsection
28809 SDCDB Command Line Options
28812 \begin_layout Itemize
28817 \begin_layout Standard
28826 -directory=<source file directory> this option can used to specify the directory
28828 The debugger will look into the directory list specified for source, cdb
28830 The items in the directory list must be separated by ':', e.g.
28831 if the source files can be in the directories /home/src1 and /home/src2,
28836 \begin_layout Standard
28845 -directory option should be -
28849 \begin_layout Standard
28858 -directory=/home/src1:/home/src2.
28859 Note there can be no spaces in the option.
28863 \begin_layout Itemize
28864 -cd <directory> - change to the <directory>.
28867 \begin_layout Itemize
28868 -fullname - used by GUI front ends.
28871 \begin_layout Itemize
28872 -cpu <cpu-type> - this argument is passed to the simulator please see the
28873 simulator docs for details.
28876 \begin_layout Itemize
28877 -X <Clock frequency > this options is passed to the simulator please see
28878 the simulator docs for details.
28881 \begin_layout Itemize
28882 -s <serial port file> passed to simulator see the simulator docs for details.
28885 \begin_layout Itemize
28886 -S <serial in,out> passed to simulator see the simulator docs for details.
28889 \begin_layout Itemize
28890 -k <port number> passed to simulator see the simulator docs for details.
28893 \begin_layout Subsection
28894 SDCDB Debugger Commands
28897 \begin_layout Standard
28898 As mentioned earlier the command interface for the debugger has been deliberatel
28899 y kept as close the GNU debugger gdb, as possible.
28900 This will help the integration with existing graphical user interfaces
28901 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
28902 If you use a graphical user interface for the debugger you can skip this
28906 \begin_layout Subsubsection*
28907 break [line | file:line | function | file:function]
28910 \begin_layout Standard
28911 Set breakpoint at specified line or function:
28920 sdcdb>break foo.c:100
28922 sdcdb>break funcfoo
28924 sdcdb>break foo.c:funcfoo
28927 \begin_layout Subsubsection*
28928 clear [line | file:line | function | file:function ]
28931 \begin_layout Standard
28932 Clear breakpoint at specified line or function:
28941 sdcdb>clear foo.c:100
28943 sdcdb>clear funcfoo
28945 sdcdb>clear foo.c:funcfoo
28948 \begin_layout Subsubsection*
28952 \begin_layout Standard
28953 Continue program being debugged, after breakpoint.
28956 \begin_layout Subsubsection*
28960 \begin_layout Standard
28961 Execute till the end of the current function.
28964 \begin_layout Subsubsection*
28968 \begin_layout Standard
28969 Delete breakpoint number 'n'.
28970 If used without any option clear ALL user defined break points.
28973 \begin_layout Subsubsection*
28974 info [break | stack | frame | registers ]
28977 \begin_layout Itemize
28978 info break - list all breakpoints
28981 \begin_layout Itemize
28982 info stack - show the function call stack.
28985 \begin_layout Itemize
28986 info frame - show information about the current execution frame.
28989 \begin_layout Itemize
28990 info registers - show content of all registers.
28993 \begin_layout Subsubsection*
28997 \begin_layout Standard
28998 Step program until it reaches a different source line.
28999 Note: pressing <return> repeats the last command.
29002 \begin_layout Subsubsection*
29006 \begin_layout Standard
29007 Step program, proceeding through subroutine calls.
29010 \begin_layout Subsubsection*
29014 \begin_layout Standard
29015 Start debugged program.
29018 \begin_layout Subsubsection*
29022 \begin_layout Standard
29023 Print type information of the variable.
29026 \begin_layout Subsubsection*
29030 \begin_layout Standard
29031 print value of variable.
29034 \begin_layout Subsubsection*
29038 \begin_layout Standard
29039 load the given file name.
29040 Note this is an alternate method of loading file for debugging.
29043 \begin_layout Subsubsection*
29047 \begin_layout Standard
29048 print information about current frame.
29051 \begin_layout Subsubsection*
29055 \begin_layout Standard
29056 Toggle between C source & assembly source.
29059 \begin_layout Subsubsection*
29060 ! simulator command
29063 \begin_layout Standard
29064 Send the string following '!' to the simulator, the simulator response is
29066 Note the debugger does not interpret the command being sent to the simulator,
29067 so if a command like 'go' is sent the debugger can loose its execution
29068 context and may display incorrect values.
29071 \begin_layout Subsubsection*
29075 \begin_layout Standard
29078 My name is Bobby Brown"
29081 \begin_layout Subsection
29082 Interfacing SDCDB with DDD
29085 \begin_layout Standard
29086 \begin_inset Note Note
29089 \begin_layout Standard
29090 The screenshot was converted from png to eps with:
29091 \begin_inset Quotes sld
29094 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
29095 \begin_inset Quotes srd
29098 which produces a pretty compact eps file which is free from compression
29102 \begin_layout Standard
29103 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
29104 as this broke the build system on Sourceforge (pdf-file was broken.
29105 pdflatex does not accept eps files).
29113 \begin_layout Standard
29129 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
29135 shows a screenshot of a debugging session with DDD
29136 \begin_inset LatexCommand \index{DDD (debugger)}
29140 (Unix only) on a simulated 8032.
29141 The debugging session might not run as smoothly as the screenshot suggests.
29142 The debugger allows setting of breakpoints, displaying and changing variables,
29143 single stepping through C and assembler code.
29146 The source was compiled with
29160 \begin_layout Standard
29172 -debug ddd_example.c
29185 and DDD was invoked with
29192 ddd -debugger "sdcdb -cpu 8032 ddd_example"
29195 \begin_layout Standard
29196 \begin_inset Note Note
29199 \begin_layout Standard
29200 Check that the double quotes or an apostroph within the command line survive
29201 the LyX tool chain.
29202 Previously the apostrophs got slanted in the PDF output so a cut and paste
29211 \begin_layout Subsection
29212 Interfacing SDCDB with XEmacs
29213 \begin_inset LatexCommand \index{XEmacs}
29218 \begin_inset LatexCommand \index{Emacs}
29225 \begin_layout Standard
29226 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
29227 sdcdb.el and sdcdbsrc.el.
29228 These two files can be found in the $(prefix)/bin directory after the installat
29230 These files need to be loaded into XEmacs for the interface to work.
29231 This can be done at XEmacs startup time by inserting the following into
29232 your '.xemacs' file (which can be found in your HOME directory):
29238 (load-file sdcdbsrc.el)
29244 .xemacs is a lisp file so the () around the command is REQUIRED.
29245 The files can also be loaded dynamically while XEmacs is running, set the
29246 environment variable 'EMACSLOADPATH' to the installation bin directory
29247 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
29248 To start the interface enter the following command:
29262 You will prompted to enter the file name to be debugged.
29267 The command line options that are passed to the simulator directly are
29268 bound to default values in the file sdcdbsrc.el.
29269 The variables are listed below, these values maybe changed as required.
29272 \begin_layout Itemize
29273 sdcdbsrc-cpu-type '51
29276 \begin_layout Itemize
29277 sdcdbsrc-frequency '11059200
29280 \begin_layout Itemize
29281 sdcdbsrc-serial nil
29284 \begin_layout Standard
29285 The following is a list of key mapping for the debugger interface.
29288 \begin_layout Standard
29311 binding\InsetSpace ~
29349 -------\InsetSpace ~
29420 sdcdb-back-from-src\InsetSpace ~
29449 rom-src\InsetSpace ~
29459 SDCDB continue command
29477 sdcdb-step-from-src\InsetSpace ~
29506 hatis-c-sexp\InsetSpace ~
29516 SDCDB ptypecommand for data at
29583 sdcdbsrc-delete\InsetSpace ~
29598 B Delete all breakpoints if no arg
29647 given or delete arg (C-u arg x)
29666 -frame\InsetSpace ~
29681 SDCDB Display current frame if no arg,
29730 given or display frame arg
29798 sdcdbsrc-goto-sdcdb\InsetSpace ~
29808 Goto the SDCDB output buffer
29827 t-c-sexp\InsetSpace ~
29838 SDCDB print command for data at
29905 sdcdbsrc-goto-sdcdb\InsetSpace ~
29916 o the SDCDB output buffer
29934 sdcdbsrc-mode\InsetSpace ~
29950 Toggles Sdcdbsrc mode (turns it
29966 sdcdb-finish-from-src\InsetSpace ~
29974 SDCDB finish command
30008 Set break for line with point
30023 sdcdbsrc-mode\InsetSpace ~
30039 Toggle Sdcdbsrc mode
30055 dbsrc-srcmode\InsetSpace ~
30079 \begin_layout Chapter
30083 \begin_layout Standard
30084 Here are a few guidelines that will help the compiler generate more efficient
30085 code, some of the tips are specific to this compiler others are generally
30086 good programming practice.
30089 \begin_layout Itemize
30090 Use the smallest data type to represent your data-value.
30091 If it is known in advance that the value is going to be less than 256 then
30092 use an 'unsigned char' instead of a 'short' or 'int'.
30093 Please note, that ANSI C requires both signed and unsigned chars to be
30094 promoted to 'signed int'
30095 \begin_inset LatexCommand \index{promotion to signed int}
30100 \begin_inset Marginal
30103 \begin_layout Standard
30112 before doing any operation.
30114 \begin_inset LatexCommand \index{type promotion}
30119 \begin_inset LatexCommand \label{type promotion}
30123 can be omitted, if the result is the same.
30124 The effect of the promotion rules together with the sign-extension is often
30129 \begin_layout Verse
30132 unsigned char uc = 0xfe;
30134 if (uc * uc < 0) /* this is true! */
30147 \begin_layout Standard
30154 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
30162 \begin_layout Verse
30165 (unsigned char) -12 / (signed char) -3 = ...
30168 \begin_layout Standard
30169 No, the result is not 4:
30172 \begin_layout Verse
30175 (int) (unsigned char) -12 / (int) (signed char) -3 =
30177 (int) (unsigned char)
30178 0xf4 / (int) (signed char) 0xfd =
30180 (int) 0x00f4 / (int) 0xfffd =
30185 (int) 244 / (int) -3 =
30187 (int) -81 = (int) 0xffaf;
30190 \begin_layout Standard
30191 Don't complain, that gcc gives you a different result.
30192 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
30193 Therefore the results are different.
30196 \begin_inset Quotes sld
30200 \begin_inset Quotes srd
30206 \begin_layout Quote
30209 If well-defined overflow characteristics are important and negative values
30210 are not, or if you want to steer clear of sign-extension problems when
30211 manipulating bits or bytes, use one of the corresponding unsigned types.
30212 (Beware when mixing signed and unsigned values in expressions, though.)
30215 character types (especially unsigned char) can be used as "tiny" integers,
30216 doing so is sometimes more trouble than it's worth, due to unpredictable
30217 sign extension and increased code size.
30221 \begin_layout Itemize
30222 Use unsigned when it is known in advance that the value is not going to
30224 This helps especially if you are doing division or multiplication, bit-shifting
30225 or are using an array index.
30228 \begin_layout Itemize
30229 NEVER jump into a LOOP.
30232 \begin_layout Itemize
30233 Declare the variables to be local
30234 \begin_inset LatexCommand \index{local variables}
30238 whenever possible, especially loop control variables (induction).
30241 \begin_layout Itemize
30242 Have a look at the assembly listing to get a
30243 \begin_inset Quotes sld
30247 \begin_inset Quotes srd
30250 for the code generation.
30253 \begin_layout Section
30254 Porting code from or to other compilers
30255 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
30262 \begin_layout Itemize
30263 check whether endianness of the compilers differs and adapt where needed.
30266 \begin_layout Itemize
30267 check the device specific header files
30268 \begin_inset LatexCommand \index{Header files}
30273 \begin_inset LatexCommand \index{Include files}
30277 for compiler specific syntax.
30278 Eventually include the file <compiler.h
30279 \begin_inset LatexCommand \index{compiler.h (include file)}
30284 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
30288 to allow using common header files.
30291 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
30298 \begin_layout Itemize
30299 check whether the startup code contains the correct initialization (watchdog,
30303 \begin_layout Itemize
30304 check whether the sizes of short, int, long match.
30307 \begin_layout Itemize
30308 check if some 16 or 32 bit hardware registers require a specific addressing
30309 order (least significant or most significant byte first) and adapt if needed
30318 relate to time and not to lower/upper memory location here, so this is
30323 the same as endianness).
30326 \begin_layout Itemize
30327 check whether the keyword
30331 is used where needed.
30332 The compilers might differ in their optimization characteristics (as different
30333 versions of the same compiler might also use more clever optimizations
30334 this is good idea anyway).
30336 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
30343 \begin_layout Itemize
30344 check that the compilers are not told to supress warnings.
30347 \begin_layout Itemize
30348 check and convert compiler specific extensions (interrupts, memory areas,
30352 \begin_layout Itemize
30353 check for differences in type promotion.
30354 Especially check for math operations on
30363 For the sake of C99 compatibility SDCC will probably promote these to
30367 more often than other compilers.
30368 Eventually insert explicit casts to
30377 Also check that the ~\InsetSpace ~
30379 \begin_inset LatexCommand \index{\~\/ Operator}
30386 \begin_inset LatexCommand \index{bit}
30392 variables, use the !\InsetSpace ~
30395 \begin_inset LatexCommand \ref{type promotion}
30400 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30407 \begin_layout Itemize
30408 check the assembly code generated for interrupt routines (f.e.
30409 for calls to possibly non-reentrant library functions).
30412 \begin_layout Itemize
30413 check whether timing loops result in proper timing (or preferably consider
30414 a rewrite of the code with timer based delays instead).
30417 \begin_layout Itemize
30418 check for differences in printf parameters (some compilers push (va_arg
30419 \begin_inset LatexCommand \index{vararg, va\_arg}
30423 ) char variables as
30427 others push them as
30433 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30440 \begin_layout Itemize
30441 check the resulting memory map
30442 \begin_inset LatexCommand \index{Memory map}
30447 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
30448 ly idata, pdata, xdata).
30449 Eventually check if unexpected library functions are included.
30452 \begin_layout Section
30454 \begin_inset LatexCommand \index{Tools}
30458 included in the distribution
30461 \begin_layout Standard
30463 \begin_inset Tabular
30464 <lyxtabular version="3" rows="12" columns="3">
30466 <column alignment="left" valignment="top" leftline="true" width="0pt">
30467 <column alignment="left" valignment="top" leftline="true" width="0pt">
30468 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30469 <row topline="true" bottomline="true">
30470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30473 \begin_layout Standard
30481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30484 \begin_layout Standard
30492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30495 \begin_layout Standard
30504 <row topline="true">
30505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30508 \begin_layout Standard
30510 \begin_inset LatexCommand \index{uCsim}
30519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30522 \begin_layout Standard
30523 Simulator for various architectures
30528 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30531 \begin_layout Standard
30538 <row topline="true">
30539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30542 \begin_layout Standard
30548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30551 \begin_layout Standard
30553 \begin_inset LatexCommand \index{Header files}
30558 \begin_inset LatexCommand \index{Include files}
30567 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30570 \begin_layout Standard
30571 sdcc/support/scripts
30577 <row topline="true">
30578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30581 \begin_layout Standard
30587 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30590 \begin_layout Standard
30591 header file conversion
30596 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30599 \begin_layout Standard
30600 sdcc/support/scripts
30606 <row topline="true">
30607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30610 \begin_layout Standard
30616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30619 \begin_layout Standard
30625 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30628 \begin_layout Standard
30644 <row topline="true">
30645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30648 \begin_layout Standard
30654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30657 \begin_layout Standard
30663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30666 \begin_layout Standard
30682 <row topline="true">
30683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30686 \begin_layout Standard
30692 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30695 \begin_layout Standard
30701 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30704 \begin_layout Standard
30720 <row topline="true">
30721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30724 \begin_layout Standard
30730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30733 \begin_layout Standard
30739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30742 \begin_layout Standard
30758 <row topline="true">
30759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30762 \begin_layout Standard
30768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30771 \begin_layout Standard
30777 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30780 \begin_layout Standard
30796 <row topline="true">
30797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30800 \begin_layout Standard
30806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30809 \begin_layout Standard
30815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30818 \begin_layout Standard
30834 <row topline="true">
30835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30838 \begin_layout Standard
30844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30847 \begin_layout Standard
30853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30856 \begin_layout Standard
30872 <row topline="true" bottomline="true">
30873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30876 \begin_layout Standard
30882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30885 \begin_layout Standard
30887 \begin_inset LatexCommand \index{packihx (tool)}
30896 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30899 \begin_layout Standard
30924 \begin_layout Section
30926 \begin_inset LatexCommand \index{Documentation}
30930 included in the distribution
30933 \begin_layout Standard
30935 \begin_inset Tabular
30936 <lyxtabular version="3" rows="10" columns="2">
30938 <column alignment="block" valignment="top" leftline="true" width="40col%">
30939 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
30940 <row topline="true" bottomline="true" endhead="true">
30941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30944 \begin_layout Standard
30952 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30955 \begin_layout Standard
30958 Filename / Where to get
30964 <row topline="true">
30965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30968 \begin_layout Standard
30969 SDCC Compiler User Guide
30974 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30977 \begin_layout Standard
30978 You're reading it right now
30990 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
31000 <row topline="true">
31001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31004 \begin_layout Standard
31010 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31013 \begin_layout Standard
31026 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31036 <row topline="true">
31037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31040 \begin_layout Standard
31042 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
31047 \begin_inset LatexCommand \index{Assembler documentation}
31054 \begin_inset LatexCommand \index{aslink}
31059 \begin_inset LatexCommand \index{Linker documentation}
31068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31071 \begin_layout Standard
31072 sdcc/as/doc/asxhtm.html
31084 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
31094 <row topline="true">
31095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31098 \begin_layout Standard
31099 SDCC regression test
31100 \begin_inset LatexCommand \index{Regression test}
31109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31112 \begin_layout Standard
31113 sdcc/doc/test_suite_spec.pdf
31125 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
31135 <row topline="true">
31136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31139 \begin_layout Standard
31145 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31148 \begin_layout Standard
31161 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
31171 <row topline="true">
31172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31175 \begin_layout Standard
31176 Notes on debugging with SDCDB
31177 \begin_inset LatexCommand \index{SDCDB (debugger)}
31186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31189 \begin_layout Standard
31190 sdcc/debugger/README
31202 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
31212 <row topline="true">
31213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31216 \begin_layout Standard
31218 \begin_inset LatexCommand \index{uCsim}
31222 Software simulator for microcontrollers
31227 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31230 \begin_layout Standard
31260 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
31270 <row topline="true">
31271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31274 \begin_layout Standard
31275 Temporary notes on the pic16
31276 \begin_inset LatexCommand \index{PIC16}
31285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31288 \begin_layout Standard
31289 sdcc/src/pic16/NOTES
31301 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
31311 <row topline="true" bottomline="true">
31312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31315 \begin_layout Standard
31316 SDCC internal documentation (debugging file format)
31321 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31324 \begin_layout Standard
31354 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
31373 \begin_layout Section
31374 Related open source tools
31375 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
31380 \begin_inset LatexCommand \index{Related tools}
31387 \begin_layout Standard
31389 \begin_inset Tabular
31390 <lyxtabular version="3" rows="16" columns="3">
31392 <column alignment="left" valignment="top" leftline="true" width="0pt">
31393 <column alignment="block" valignment="top" leftline="true" width="30line%">
31394 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
31395 <row topline="true" bottomline="true">
31396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31399 \begin_layout Standard
31407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31410 \begin_layout Standard
31418 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31421 \begin_layout Standard
31430 <row topline="true">
31431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31434 \begin_layout Standard
31436 \begin_inset LatexCommand \index{gpsim (pic simulator)}
31445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31448 \begin_layout Standard
31454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31457 \begin_layout Standard
31458 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
31468 <row topline="true">
31469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31472 \begin_layout Standard
31474 \begin_inset LatexCommand \index{gputils (pic tools)}
31483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31486 \begin_layout Standard
31492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31495 \begin_layout Standard
31496 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
31506 <row topline="true">
31507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31510 \begin_layout Standard
31516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31519 \begin_layout Standard
31525 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31528 \begin_layout Standard
31529 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
31539 <row topline="true">
31540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31543 \begin_layout Standard
31549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31552 \begin_layout Standard
31553 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
31559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31562 \begin_layout Standard
31563 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
31573 <row topline="true">
31574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31577 \begin_layout Standard
31579 \begin_inset LatexCommand \index{indent (source formatting tool)}
31588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31591 \begin_layout Standard
31592 Formats C source - Master of the white spaces
31597 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31600 \begin_layout Standard
31601 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
31611 <row topline="true">
31612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31615 \begin_layout Standard
31617 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
31626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31629 \begin_layout Standard
31630 Object file conversion, checksumming, ...
31635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31638 \begin_layout Standard
31639 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
31649 <row topline="true">
31650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31653 \begin_layout Standard
31655 \begin_inset LatexCommand \index{objdump (tool)}
31664 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31667 \begin_layout Standard
31668 Object file conversion, ...
31673 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31676 \begin_layout Standard
31677 Part of binutils (should be there anyway)
31683 <row topline="true">
31684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31687 \begin_layout Standard
31693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31696 \begin_layout Standard
31697 8051 monitor (hex up-/download, single step, disassemble)
31702 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31705 \begin_layout Standard
31706 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
31716 <row topline="true">
31717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31720 \begin_layout Standard
31722 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
31731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31734 \begin_layout Standard
31735 Source code documentation system
31740 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31743 \begin_layout Standard
31744 \begin_inset LatexCommand \url{http://www.doxygen.org}
31754 <row topline="true">
31755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31758 \begin_layout Standard
31764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31767 \begin_layout Standard
31768 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
31773 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31776 \begin_layout Standard
31777 \begin_inset LatexCommand \url{http://www.kdevelop.org}
31787 <row topline="true">
31788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31791 \begin_layout Standard
31797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31800 \begin_layout Standard
31801 8051 monitor (hex up-/download, single step, disassemble)
31806 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31809 \begin_layout Standard
31810 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
31820 <row topline="true">
31821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31824 \begin_layout Standard
31826 \begin_inset LatexCommand \index{splint (syntax checking tool)}
31835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31838 \begin_layout Standard
31839 Statically checks c sources (see
31840 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
31849 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31852 \begin_layout Standard
31853 \begin_inset LatexCommand \url{http://www.splint.org}
31863 <row topline="true" bottomline="true">
31864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31867 \begin_layout Standard
31869 \begin_inset LatexCommand \index{DDD (debugger)}
31878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31881 \begin_layout Standard
31882 Debugger, serves nicely as GUI to SDCDB
31883 \begin_inset LatexCommand \index{SDCDB (debugger)}
31892 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31895 \begin_layout Standard
31896 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
31906 <row bottomline="true">
31907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31910 \begin_layout Standard
31912 \begin_inset LatexCommand \index{d52}
31917 \begin_inset LatexCommand \index{d52 (disassembler)}
31926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31929 \begin_layout Standard
31930 Disassembler, can count instruction cycles
31931 \begin_inset LatexCommand \index{instruction cycles (count)}
31935 , use with options -pnd
31940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31943 \begin_layout Standard
31944 \begin_inset LatexCommand \url{http://www.8052.com/users/disasm/}
31954 <row bottomline="true">
31955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31958 \begin_layout Standard
31960 \begin_inset LatexCommand \index{cmake}
31969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31972 \begin_layout Standard
31973 Cross platform build system, generates Makefiles
31974 \begin_inset LatexCommand \index{Makefile}
31978 and project workspaces
31979 \begin_inset LatexCommand \index{project workspace}
31988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31991 \begin_layout Standard
31992 \begin_inset LatexCommand \url{http://www.cmake.org}
32000 and a dedicated wiki entry:
32001 \begin_inset LatexCommand \url{http://www.cmake.org/Wiki/CmakeSdcc}
32020 \begin_layout Section
32021 Related documentation / recommended reading
32024 \begin_layout Standard
32026 \begin_inset Tabular
32027 <lyxtabular version="3" rows="7" columns="3">
32029 <column alignment="left" valignment="top" leftline="true" width="0pt">
32030 <column alignment="left" valignment="top" leftline="true" width="0">
32031 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32032 <row topline="true" bottomline="true">
32033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32036 \begin_layout Standard
32044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32047 \begin_layout Standard
32055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32058 \begin_layout Standard
32067 <row topline="true">
32068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32071 \begin_layout Standard
32086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32089 \begin_layout Standard
32091 \begin_inset LatexCommand \index{C Reference card}
32100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32103 \begin_layout Standard
32104 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
32114 <row topline="true">
32115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32118 \begin_layout Standard
32124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32127 \begin_layout Standard
32129 \begin_inset LatexCommand \index{C FAQ}
32138 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32141 \begin_layout Standard
32142 \begin_inset LatexCommand \url{http://www.c-faq.com}
32152 <row topline="true">
32153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32156 \begin_layout Standard
32162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32165 \begin_layout Standard
32166 \begin_inset Quotes sld
32170 \begin_inset Quotes srd
32178 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32181 \begin_layout Standard
32184 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
32194 <row topline="true">
32195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32198 \begin_layout Standard
32204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32207 \begin_layout Standard
32208 \begin_inset Quotes sld
32211 Extensions for Embedded C
32212 \begin_inset Quotes srd
32220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32223 \begin_layout Standard
32226 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
32236 <row topline="true">
32237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32240 \begin_layout Standard
32246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32249 \begin_layout Standard
32250 Latest datasheet of target CPU
32255 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32258 \begin_layout Standard
32265 <row topline="true" bottomline="true">
32266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32269 \begin_layout Standard
32275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32278 \begin_layout Standard
32279 Revision history of datasheet
32284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32287 \begin_layout Standard
32303 \begin_layout Section
32304 Application notes specifically for SDCC
32307 \begin_layout Standard
32308 SDCC makes no claims about the completeness of this list and about up-to-datenes
32309 s or correctness of the application notes
32310 \begin_inset LatexCommand \index{Application notes}
32317 \begin_layout Standard
32321 \begin_inset Tabular
32322 <lyxtabular version="3" rows="7" columns="3">
32324 <column alignment="block" valignment="top" leftline="true" width="17col%">
32325 <column alignment="block" valignment="top" leftline="true" width="27col%">
32326 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
32327 <row topline="true" bottomline="true">
32328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32331 \begin_layout Standard
32340 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
32343 \begin_layout Standard
32352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32355 \begin_layout Standard
32365 <row topline="true">
32366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32369 \begin_layout Standard
32377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32380 \begin_layout Standard
32383 Using the SDCC Compiler for the DS80C400
32384 \begin_inset LatexCommand \index{DS80C400}
32393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32396 \begin_layout Standard
32399 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
32409 <row topline="true">
32410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32413 \begin_layout Standard
32421 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
32424 \begin_layout Standard
32427 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
32428 \begin_inset LatexCommand \index{DS89C4x0}
32432 Family of Microcontrollers
32437 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32440 \begin_layout Standard
32443 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
32453 <row topline="true">
32454 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32457 \begin_layout Standard
32460 Silicon Laboratories / Cygnal
32465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32468 \begin_layout Standard
32471 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
32472 \begin_inset LatexCommand \index{IDE}
32481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32484 \begin_layout Standard
32487 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
32497 <row topline="true">
32498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32501 \begin_layout Standard
32504 Ramtron / Goal Semiconductor
32509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32512 \begin_layout Standard
32515 Interfacing SDCC to Syn and Textpad
32520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32523 \begin_layout Standard
32526 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32536 <row topline="true">
32537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32540 \begin_layout Standard
32543 Ramtron / Goal Semiconductor
32548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32551 \begin_layout Standard
32554 Installing and Configuring SDCC and Crimson Editor
32559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32562 \begin_layout Standard
32565 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32575 <row topline="true" bottomline="true">
32576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32579 \begin_layout Standard
32587 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32590 \begin_layout Standard
32593 MSC12xx Programming with SDCC
32598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32601 \begin_layout Standard
32604 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
32621 \begin_layout Section
32625 \begin_layout Standard
32626 Some questions answered, some pointers given - it might be time to in turn
32634 \begin_layout Itemize
32635 can you solve your project with the selected microcontroller? Would you
32636 find out early or rather late that your target is too small/slow/whatever?
32637 Can you switch to a slightly better device if it doesn't fit?
32640 \begin_layout Itemize
32641 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
32642 and/or another programming language be more adequate? Would an operating
32643 system on the target device help?
32646 \begin_layout Itemize
32647 if you solved the problem, will the marketing department be happy?
32650 \begin_layout Itemize
32651 if the marketing department is happy, will customers be happy?
32654 \begin_layout Itemize
32655 if you're the project manager, marketing department and maybe even the customer
32656 in one person, have you tried to see the project from the outside?
32659 \begin_layout Itemize
32660 is the project done if you think it is done? Or is just that other interface/pro
32661 tocol/feature/configuration/option missing? How about website, manual(s),
32662 internationali(z|s)ation, packaging, labels, 2nd source for components,
32663 electromagnetic compatability/interference, documentation for production,
32664 production test software, update mechanism, patent issues?
32667 \begin_layout Itemize
32668 is your project adequately positioned in that magic triangle: fame, fortune,
32672 \begin_layout Standard
32673 Maybe not all answers to these questions are known and some answers may
32678 , nevertheless knowing these questions may help you to avoid burnout
32682 \begin_layout Standard
32683 burnout is bad for electronic devices, programmers and motorcycle tyres
32689 Chances are you didn't want to hear some of them...
32692 \begin_layout Chapter
32694 \begin_inset LatexCommand \index{Support}
32701 \begin_layout Standard
32702 SDCC has grown to be a large project.
32703 The compiler alone (without the preprocessor, assembler and linker) is
32704 well over 150,000 lines of code (blank stripped).
32705 The open source nature of this project is a key to its continued growth
32707 You gain the benefit and support of many active software developers and
32709 Is SDCC perfect? No, that's why we need your help.
32710 The developers take pride in fixing reported bugs.
32711 You can help by reporting the bugs and helping other SDCC users.
32712 There are lots of ways to contribute, and we encourage you to take part
32713 in making SDCC a great software package.
32717 \begin_layout Standard
32718 The SDCC project is hosted on the SDCC sourceforge site at
32719 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
32724 You'll find the complete set of mailing lists
32725 \begin_inset LatexCommand \index{Mailing list(s)}
32729 , forums, bug reporting system, patch submission
32730 \begin_inset LatexCommand \index{Patch submission}
32735 \begin_inset LatexCommand \index{download}
32739 area and Subversion code repository
32740 \begin_inset LatexCommand \index{Subversion code repository}
32747 \begin_layout Section
32749 \begin_inset LatexCommand \index{Bug reporting}
32754 \begin_inset LatexCommand \index{Reporting bugs}
32761 \begin_layout Standard
32762 The recommended way of reporting bugs is using the infrastructure of the
32764 You can follow the status of bug reports there and have an overview about
32768 \begin_layout Standard
32769 Bug reports are automatically forwarded to the developer mailing list and
32770 will be fixed ASAP.
32771 When reporting a bug, it is very useful to include a small test program
32772 (the smaller the better) which reproduces the problem.
32773 If you can isolate the problem by looking at the generated assembly code,
32774 this can be very helpful.
32775 Compiling your program with the -
32779 \begin_layout Standard
32789 \begin_inset LatexCommand \index{-\/-dumpall}
32793 option can sometimes be useful in locating optimization problems.
32794 When reporting a bug please make sure you:
32797 \begin_layout Enumerate
32798 Attach the code you are compiling with SDCC.
32802 \begin_layout Enumerate
32803 Specify the exact command you use to run SDCC, or attach your Makefile.
32807 \begin_layout Enumerate
32808 Specify the SDCC version (type "
32814 "), your platform, and operating system.
32818 \begin_layout Enumerate
32819 Provide an exact copy of any error message or incorrect output.
32823 \begin_layout Enumerate
32824 Put something meaningful in the subject of your message.
32827 \begin_layout Standard
32828 Please attempt to include these 5 important parts, as applicable, in all
32829 requests for support or when reporting any problems or bugs with SDCC.
32830 Though this will make your message lengthy, it will greatly improve your
32831 chance that SDCC users and developers will be able to help you.
32832 Some SDCC developers are frustrated by bug reports without code provided
32833 that they can use to reproduce and ultimately fix the problem, so please
32834 be sure to provide sample code if you are reporting a bug!
32837 \begin_layout Standard
32838 Please have a short check that you are using a recent version of SDCC and
32839 the bug is not yet known.
32840 This is the link for reporting bugs:
32841 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
32846 With SDCC on average having more than 200 downloads
32847 \begin_inset LatexCommand \index{download}
32851 on sourceforge per day
32855 \begin_layout Standard
32856 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
32857 between 2002 and 2005.
32858 This does not include other methods of distribution.
32863 there must be some users.
32864 So it's not exactly easy to find a new bug.
32865 If you find one we need it:
32867 reporting bugs is good
32872 \begin_layout Section
32873 Requesting Features
32874 \begin_inset LatexCommand \label{sub:Requesting-Features}
32879 \begin_inset LatexCommand \index{Feature request}
32884 \begin_inset LatexCommand \index{Requesting features}
32891 \begin_layout Standard
32892 Like bug reports feature requests are forwarded to the developer mailing
32894 This is the link for requesting features:
32895 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32902 \begin_layout Section
32906 \begin_layout Standard
32907 Like bug reports contributed patches are forwarded to the developer mailing
32909 This is the link for submitting patches
32910 \begin_inset LatexCommand \index{Patch submission}
32915 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
32922 \begin_layout Standard
32923 You need to specify some parameters to the
32927 command for the patches to be useful.
32928 If you modified more than one file a patch created f.e.
32933 \begin_inset Quotes sld
32936 diff -Naur unmodified_directory modified_directory >my_changes.patch
32937 \begin_inset Quotes srd
32943 will be fine, otherwise
32947 \begin_inset Quotes sld
32950 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
32951 \begin_inset Quotes srd
32961 \begin_layout Section
32965 \begin_layout Standard
32966 These links should take you directly to the
32967 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
32975 \begin_layout Standard
32976 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
32977 automated messages (mid 2003)
32983 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
32988 \begin_inset LatexCommand \index{Mailing list(s)}
32992 and forums are archived and searchable so if you are lucky someone already
32993 had a similar problem.
32994 While mails to the lists themselves are delivered promptly their web front
32995 end on sourceforge sometimes shows a severe time lag (up to several weeks),
32996 if you're seriously using SDCC please consider subscribing to the lists.
32999 \begin_layout Section
33003 \begin_layout Standard
33004 You can follow the status of the Subversion version
33005 \begin_inset LatexCommand \index{version}
33009 of SDCC by watching the Changelog
33010 \begin_inset LatexCommand \index{Changelog}
33014 in the Subversion repository
33017 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
33024 \begin_layout Section
33025 Subversion Source Code Repository
33028 \begin_layout Standard
33038 \begin_layout Standard
33052 or the filenames of the snapshot versions of SDCC include date and its
33054 \begin_inset LatexCommand \index{Subversion code repository}
33059 Subversion allows to download the source of recent or previous versions
33061 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
33065 (by number or by date).
33066 An on-line source code browser and detailled instructions are also available
33068 SDCC versions starting from 1999 up to now are available (currently the
33069 versions prior to the conversion from cvs
33070 \begin_inset LatexCommand \index{cvs|see{Subversion}}
33074 to Subversion (April 2006) are either by accessible by Subversion or by
33078 \begin_layout Section
33080 \begin_inset LatexCommand \index{Release policy}
33087 \begin_layout Standard
33088 Historically there often were long delays between official releases and
33089 the sourceforge download area tends to get not updated at all.
33090 Excuses in the past might have referred to problems with live range analysis,
33091 but as this was fixed a while ago, the current problem is that another
33092 excuse has to be found.
33093 Kidding aside, we have to get better there! On the other hand there are
33094 daily snapshots available at
33095 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
33099 , and you can always build the very last version (hopefully with many bugs
33100 fixed, and features added) from the source code available at
33101 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
33107 \begin_inset LatexCommand \index{wiki}
33112 \begin_inset LatexCommand \index{SDCC Wiki}
33117 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/}
33121 also holds some information about past and future releases.
33124 \begin_layout Section
33126 \begin_inset LatexCommand \index{Examples}
33133 \begin_layout Standard
33134 You'll find some small examples in the directory
33136 sdcc/device/examples/.
33139 More examples and libraries are available at
33141 The SDCC Open Knowledge Resource
33142 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
33149 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
33156 \begin_layout Standard
33157 \begin_inset Note Note
33160 \begin_layout Standard
33161 I did insert a reference to Paul's web site here although it seems rather
33162 dedicated to a specific 8032 board (I think it's okay because it f.e.
33163 shows LCD/Harddisc interface and has a free 8051 monitor.
33164 Independent 8032 board vendors face hard competition of heavily subsidized
33165 development boards anyway).
33168 \begin_layout Standard
33169 Maybe we should include some links to real world applications.
33170 Preferably pointer to pointers (one for each architecture) so this stays
33179 \begin_layout Section
33181 \begin_inset LatexCommand \label{sec:Quality-control}
33186 \begin_inset LatexCommand \index{Quality control}
33193 \begin_layout Standard
33194 The compiler is passed through snaphot build compile and build checks.
33200 \begin_inset LatexCommand \index{Regression test}
33204 check that SDCC itself compiles flawlessly on several host platforms (i386,
33205 Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
33206 and checks the quality of the code generated by SDCC by running the code
33207 for several target platforms through simulators.
33208 The regression test suite comprises more than 100 files which expand to
33209 more than 500 test cases which include more than 4500 tests.
33210 The results of these tests are published daily on SDCC's snapshot page
33211 (click on the red or green symbols on the right side of
33212 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
33219 \begin_layout Standard
33220 There is a separate document
33223 \begin_inset LatexCommand \index{Test suite}
33230 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
33234 about the regression test suite.
33237 \begin_layout Standard
33238 You'll find the test code in the directory
33240 sdcc/support/regression
33243 You can run these tests manually by running
33247 in this directory (or f.e.
33252 \begin_inset Quotes sld
33256 \begin_inset Quotes srd
33262 if you don't want to run the complete tests).
33263 The test code might also be interesting if you want to look for examples
33264 \begin_inset LatexCommand \index{Examples}
33268 checking corner cases of SDCC or if you plan to submit patches
33269 \begin_inset LatexCommand \index{Patch submission}
33276 \begin_layout Standard
33277 The PIC14 port uses a different set of regression tests
33278 \begin_inset LatexCommand \index{Regression test (PIC14)}
33282 , you'll find them in the directory
33284 sdcc/src/regression
33289 \begin_layout Section
33290 Use of SDCC in Education
33293 \begin_layout Standard
33302 \begin_layout Standard
33303 the phrase "use in education" might evoke the association "
33307 fit for use in education".
33308 This connotation is not intended but nevertheless risked as the licensing
33309 of SDCC makes it difficult to offer educational discounts
33315 If your rationales are to:
33318 \begin_layout Enumerate
33319 give students a chance to understand the
33323 steps of code generation
33326 \begin_layout Enumerate
33327 have a curriculum that can be extended for years.
33328 Then you could use an fpga board as target and your curriculum will seamlessly
33329 extend from logic synthesis (
33330 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
33335 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
33339 ), over assembly programming, to C to FPGA compilers (
33340 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
33347 \begin_layout Enumerate
33348 be able to insert excursions about skills like using a revision control
33349 system, submitting/applying patches, using a type-setting (as opposed to
33350 word-processing) engine LyX/LaTeX, using
33351 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
33356 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
33360 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
33361 Source Software, CPU simulation, compiler regression tests
33362 \begin_inset LatexCommand \index{Regression test}
33369 And if there should be a shortage of ideas then you can always point students
33370 to the ever-growing feature request list
33371 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33378 \begin_layout Enumerate
33379 not tie students to a specific host platform and instead allow them to use
33384 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
33386 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
33393 \begin_layout Enumerate
33394 not encourage students to use illegal copies of educational software
33397 \begin_layout Enumerate
33398 be immune to licensing/availability/price changes of the chosen tool chain
33401 \begin_layout Enumerate
33402 be able to change to a new target platform without having to adopt a new
33406 \begin_layout Enumerate
33407 have complete control over and insight into the tool chain
33410 \begin_layout Enumerate
33411 make your students aware about the pros and cons of open source software
33415 \begin_layout Enumerate
33416 give back to the public as you are probably at least partially publically
33420 \begin_layout Enumerate
33421 give students a chance to publically prove their skills and to possibly
33422 see a world wide impact
33425 \begin_layout Standard
33426 then SDCC is probably among the first choices.
33427 Well, probably SDCC might be the only choice.
33432 \begin_layout Chapter
33433 SDCC Technical Data
33436 \begin_layout Section
33438 \begin_inset LatexCommand \index{Optimizations}
33445 \begin_layout Standard
33446 SDCC performs a host of standard optimizations in addition to some MCU specific
33451 \begin_layout Subsection
33452 Sub-expression Elimination
33453 \begin_inset LatexCommand \index{Subexpression elimination}
33460 \begin_layout Standard
33461 The compiler does local and
33480 \begin_layout Verse
33488 \begin_layout Standard
33489 will be translated to
33492 \begin_layout Verse
33502 \begin_layout Standard
33503 Some subexpressions are not as obvious as the above example, e.g.:
33506 \begin_layout Verse
33514 \begin_layout Standard
33515 In this case the address arithmetic a->b[i] will be computed only once;
33516 the equivalent code in C would be.
33519 \begin_layout Verse
33529 \begin_layout Standard
33530 The compiler will try to keep these temporary variables in registers.
33533 \begin_layout Subsection
33534 Dead-Code Elimination
33535 \begin_inset LatexCommand \index{Dead-code elimination}
33542 \begin_layout Verse
33557 i = 1; \InsetSpace ~
33566 global = 1;\InsetSpace ~
33580 global = 3;\InsetSpace ~
33586 \begin_layout Standard
33590 \begin_layout Verse
33606 \begin_layout Subsection
33608 \begin_inset LatexCommand \index{Copy propagation}
33615 \begin_layout Verse
33639 \begin_layout Standard
33643 \begin_layout Verse
33667 \begin_layout Standard
33668 Note: the dead stores created by this copy propagation will be eliminated
33669 by dead-code elimination.
33672 \begin_layout Subsection
33674 \begin_inset LatexCommand \index{Loop optimization}
33679 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
33686 \begin_layout Standard
33687 Two types of loop optimizations are done by SDCC
33695 of loop induction variables.
33696 In addition to the strength reduction the optimizer marks the induction
33697 variables and the register allocator tries to keep the induction variables
33698 in registers for the duration of the loop.
33699 Because of this preference of the register allocator
33700 \begin_inset LatexCommand \index{Register allocation}
33704 , loop induction optimization causes an increase in register pressure, which
33705 may cause unwanted spilling of other temporary variables into the stack
33706 \begin_inset LatexCommand \index{stack}
33711 The compiler will generate a warning message when it is forced to allocate
33712 extra space either on the stack or data space.
33713 If this extra space allocation is undesirable then induction optimization
33714 can be eliminated either for the entire source file (with -
33718 \begin_layout Standard
33727 -noinduction option) or for a given function only using #pragma\InsetSpace ~
33729 \begin_inset LatexCommand \index{\#pragma noinduction}
33740 \begin_layout Verse
33743 for (i = 0 ; i < 100 ; i ++)
33752 \begin_layout Standard
33756 \begin_layout Verse
33761 for (i = 0; i < 100; i++)
33770 \begin_layout Standard
33771 As mentioned previously some loop invariants are not as apparent, all static
33772 address computations are also moved out of the loop.
33777 \begin_inset LatexCommand \index{Strength reduction}
33781 , this optimization substitutes an expression by a cheaper expression:
33784 \begin_layout Verse
33787 for (i=0;i < 100; i++)
33796 \begin_layout Standard
33800 \begin_layout Verse
33807 for (i=0;i< 100;i++) {
33813 ar[itemp1] = itemp2;
33831 \begin_layout Standard
33832 The more expensive multiplication
33833 \begin_inset LatexCommand \index{Multiplication}
33837 is changed to a less expensive addition.
33840 \begin_layout Subsection
33842 \begin_inset LatexCommand \index{Loop reversing}
33849 \begin_layout Standard
33850 This optimization is done to reduce the overhead of checking loop boundaries
33851 for every iteration.
33852 Some simple loops can be reversed and implemented using a
33853 \begin_inset Quotes eld
33856 decrement and jump if not zero
33857 \begin_inset Quotes erd
33861 SDCC checks for the following criterion to determine if a loop is reversible
33862 (note: more sophisticated compilers use data-dependency analysis to make
33863 this determination, SDCC uses a more simple minded analysis).
33866 \begin_layout Itemize
33867 The 'for' loop is of the form
33873 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
33883 \begin_layout Itemize
33884 The <for body> does not contain
33885 \begin_inset Quotes eld
33889 \begin_inset Quotes erd
33893 \begin_inset Quotes erd
33899 \begin_layout Itemize
33900 All goto's are contained within the loop.
33903 \begin_layout Itemize
33904 No function calls within the loop.
33907 \begin_layout Itemize
33908 The loop control variable <sym> is not assigned any value within the loop
33911 \begin_layout Itemize
33912 The loop control variable does NOT participate in any arithmetic operation
33916 \begin_layout Itemize
33917 There are NO switch statements in the loop.
33920 \begin_layout Subsection
33921 Algebraic Simplifications
33924 \begin_layout Standard
33925 SDCC does numerous algebraic simplifications, the following is a small sub-set
33926 of these optimizations.
33929 \begin_layout Verse
33932 i = j + 0;\InsetSpace ~
33936 /* changed to: */\InsetSpace ~
33942 i /= 2;\InsetSpace ~
33949 /* changed to: */\InsetSpace ~
33956 = j - j;\InsetSpace ~
33960 /* changed to: */\InsetSpace ~
33966 i = j / 1;\InsetSpace ~
33970 /* changed to: */\InsetSpace ~
33977 \begin_layout Standard
33978 Note the subexpressions
33979 \begin_inset LatexCommand \index{Subexpression}
33983 given above are generally introduced by macro expansions or as a result
33984 of copy/constant propagation.
33987 \begin_layout Subsection
33988 'switch' Statements
33989 \begin_inset LatexCommand \label{sub:'switch'-Statements}
33994 \begin_inset LatexCommand \index{switch statement}
34001 \begin_layout Standard
34002 SDCC can optimize switch statements to jump tables
34003 \begin_inset LatexCommand \index{jump tables}
34008 It makes the decision based on an estimate of the generated code size.
34009 SDCC is quite liberal in the requirements for jump table generation:
34012 \begin_layout Itemize
34013 The labels need not be in order, and the starting number need not be one
34014 or zero, the case labels are in numerical sequence or not too many case
34015 labels are missing.
34019 \begin_layout Verse
34022 switch(i) {\InsetSpace ~
34053 case 4: ...\InsetSpace ~
34085 case 5: ...\InsetSpace ~
34117 case 3: ...\InsetSpace ~
34148 case 6: ...\InsetSpace ~
34180 case 7: ...\InsetSpace ~
34212 case 8: ...\InsetSpace ~
34244 case 9: ...\InsetSpace ~
34276 case 10: ...\InsetSpace ~
34307 case 11: ...\InsetSpace ~
34374 \begin_layout Standard
34375 Both the above switch statements will be implemented using a jump-table.
34376 The example to the right side is slightly more efficient as the check for
34377 the lower boundary of the jump-table is not needed.
34381 \begin_layout Itemize
34382 The number of case labels is not larger than supported by the target architectur
34386 \begin_layout Itemize
34387 If the case labels are not in numerical sequence ('gaps' between cases)
34388 SDCC checks whether a jump table with additionally inserted dummy cases
34389 is still attractive.
34393 \begin_layout Itemize
34394 If the starting number is not zero and a check for the lower boundary of
34395 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
34400 \begin_layout Standard
34401 Switch statements which have large gaps in the numeric sequence or those
34402 that have too many case labels can be split into more than one switch statement
34403 for efficient code generation, e.g.:
34406 \begin_layout Verse
34484 \begin_layout Standard
34485 If the above switch statement is broken down into two switch statements
34488 \begin_layout Verse
34531 \begin_layout Standard
34535 \begin_layout Verse
34578 \begin_layout Standard
34579 then both the switch statements will be implemented using jump-tables whereas
34580 the unmodified switch statement will not be.
34583 \begin_layout Standard
34584 \begin_inset Note Note
34587 \begin_layout Standard
34588 There might be reasons which SDCC cannot know about to either favour or
34589 not favour jump tables.
34590 If the target system has to be as quick for the last switch case as for
34591 the first (pro jump table), or if the switch argument is known to be zero
34592 in the majority of the cases (contra jump table).
34600 \begin_layout Standard
34601 The pragma nojtbound
34602 \begin_inset LatexCommand \index{\#pragma nojtbound}
34606 can be used to turn off checking the
34619 It has no effect if a default label is supplied.
34620 Use of this pragma is dangerous: if the switch
34621 \begin_inset LatexCommand \index{switch statement}
34625 argument is not matched by a case statement the processor will happily
34629 \begin_layout Subsection
34630 Bit-shifting Operations
34631 \begin_inset LatexCommand \index{Bit shifting}
34638 \begin_layout Standard
34639 Bit shifting is one of the most frequently used operation in embedded programmin
34641 SDCC tries to implement bit-shift operations in the most efficient way
34645 \begin_layout Verse
34658 \begin_layout Standard
34659 generates the following code:
34662 \begin_layout Verse
34677 \begin_layout Standard
34678 In general SDCC will never setup a loop if the shift count is known.
34682 \begin_layout Verse
34695 \begin_layout Standard
34699 \begin_layout Verse
34723 \begin_layout Subsection
34725 \begin_inset LatexCommand \index{Bit rotation}
34732 \begin_layout Standard
34733 A special case of the bit-shift operation is bit rotation
34734 \begin_inset LatexCommand \index{rotating bits}
34738 , SDCC recognizes the following expression to be a left bit-rotation:
34741 \begin_layout Verse
34749 char i;\InsetSpace ~
34760 /* unsigned is needed for rotation */
34765 i = ((i << 1) | (i >> 7));
34774 \begin_layout Standard
34775 will generate the following code:
34778 \begin_layout Verse
34795 \begin_layout Standard
34796 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
34797 ns of this case will also be recognized as bit-rotation, i.e.:
34800 \begin_layout Verse
34803 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
34806 \begin_layout Subsection
34807 Nibble and Byte Swapping
34810 \begin_layout Standard
34811 Other special cases of the bit-shift operations are nibble or byte swapping
34812 \begin_inset LatexCommand \index{swapping nibbles/bytes}
34816 , SDCC recognizes the following expressions:
34819 \begin_layout Verse
34840 i = ((i << 4) | (i >> 4));
34846 j = ((j << 8) | (j >> 8));
34849 \begin_layout Standard
34850 and generates a swap instruction for the nibble swapping
34851 \begin_inset LatexCommand \index{Nibble swapping}
34855 or move instructions for the byte swapping
34856 \begin_inset LatexCommand \index{Byte swapping}
34862 \begin_inset Quotes sld
34866 \begin_inset Quotes srd
34869 example can be used to convert from little to big-endian or vice versa.
34870 If you want to change the endianness of a
34874 integer you have to cast to
34881 \begin_layout Standard
34882 Note that SDCC stores numbers in little-endian
34886 \begin_layout Standard
34887 Usually 8-bit processors don't care much about endianness.
34888 This is not the case for the standard 8051 which only has an instruction
34894 \begin_inset LatexCommand \index{DPTR}
34902 so little-endian is the more efficient byte order.
34908 \begin_inset LatexCommand \index{little-endian}
34913 \begin_inset LatexCommand \index{Endianness}
34918 lowest order first).
34921 \begin_layout Subsection
34923 \begin_inset LatexCommand \index{Highest Order Bit}
34928 \begin_inset LatexCommand \index{Any Order Bit}
34935 \begin_layout Standard
34936 It is frequently required to obtain the highest order bit of an integral
34937 type (long, int, short or char types).
34938 Also obtaining any other order bit is not uncommon.
34939 SDCC recognizes the following expressions to yield the highest order bit
34940 and generates optimized code for it, e.g.:
34943 \begin_layout Verse
34954 unsigned char hob1, aob1;
34958 bit hob2, hob3, aob2,
34968 hob1 = (gint >> 15) & 1;
34972 hob2 = (gint >> 15) & 1;
34976 hob3 = gint & 0x8000;
34981 aob1 = (gint >> 9) & 1;
34985 aob2 = (gint >> 8) & 1;
34989 aob3 = gint & 0x0800;
34999 \begin_layout Standard
35000 will generate the following code:
35003 \begin_layout Verse
35034 000A E5*01\InsetSpace ~
35061 000C 23\InsetSpace ~
35092 000D 54 01\InsetSpace ~
35120 000F F5*02\InsetSpace ~
35175 0011 E5*01\InsetSpace ~
35203 0013 33\InsetSpace ~
35233 0014 92*00\InsetSpace ~
35289 0016 E5*01\InsetSpace ~
35316 0018 33\InsetSpace ~
35346 0019 92*01\InsetSpace ~
35402 001B E5*01\InsetSpace ~
35461 001E 54 01\InsetSpace ~
35488 0020 F5*03\InsetSpace ~
35544 0022 E5*01\InsetSpace ~
35571 0024 13\InsetSpace ~
35601 0025 92*02\InsetSpace ~
35657 0027 E5*01\InsetSpace ~
35712 002B 92*03\InsetSpace ~
35740 \begin_layout Standard
35741 Other variations of these cases however will
35746 They are standard C expressions, so I heartily recommend these be the only
35747 way to get the highest order bit, (it is portable).
35748 Of course it will be recognized even if it is embedded in other expressions,
35752 \begin_layout Verse
35755 xyz = gint + ((gint >> 15) & 1);
35758 \begin_layout Standard
35759 will still be recognized.
35762 \begin_layout Subsection
35764 \begin_inset LatexCommand \index{Higher Order Byte}
35768 / Higher Order Word
35769 \begin_inset LatexCommand \index{Higher Order Word}
35776 \begin_layout Standard
35777 It is also frequently required to obtain a higher order byte or word of
35778 a larger integral type (long, int or short types).
35779 SDCC recognizes the following expressions to yield the higher order byte
35780 or word and generates optimized code for it, e.g.:
35783 \begin_layout Verse
35788 unsigned long int glong;
35796 unsigned char hob1,
35801 unsigned int how1, how2;
35810 hob1 = (gint >> 8) & 0xFF;
35814 hob2 = glong >> 24;
35818 how1 = (glong >> 16) & 0xFFFF;
35833 \begin_layout Standard
35834 will generate the following code:
35837 \begin_layout Verse
35868 0037 85*01*06\InsetSpace ~
35890 _foo_hob1_1_1,(_gint + 1)
35921 003A 85*05*07\InsetSpace ~
35943 _foo_hob2_1_1,(_glong + 3)
35973 003D 85*04*08\InsetSpace ~
35996 _foo_how1_1_1,(_glong + 2)
35998 0040 85*05*09\InsetSpace ~
36023 0043 85*03*0A\InsetSpace ~
36045 _foo_how2_1_1,(_glong + 1)
36047 0046 85*04*0B\InsetSpace ~
36070 (_foo_how2_1_1 + 1),(_glong + 2)
36073 \begin_layout Standard
36074 Again, variations of these cases may
36079 They are standard C expressions, so I heartily recommend these be the only
36080 way to get the higher order byte/word, (it is portable).
36081 Of course it will be recognized even if it is embedded in other expressions,
36085 \begin_layout Verse
36088 xyz = gint + ((gint >> 8) & 0xFF);
36091 \begin_layout Standard
36092 will still be recognized.
36095 \begin_layout Subsection
36097 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
36102 \begin_inset LatexCommand \index{Peephole optimizer}
36109 \begin_layout Standard
36110 The compiler uses a rule based, pattern matching and re-writing mechanism
36111 for peep-hole optimization.
36116 a peep-hole optimizer by Christopher W.
36117 Fraser (cwfraser\InsetSpace ~
36120 A default set of rules are compiled into the compiler, additional rules
36121 may be added with the
36127 \begin_layout Standard
36137 \begin_inset LatexCommand \index{-\/-peep-file}
36144 The rule language is best illustrated with examples.
36147 \begin_layout Verse
36169 \begin_layout Standard
36170 The above rule will change the following assembly
36171 \begin_inset LatexCommand \index{Assembler routines}
36178 \begin_layout Verse
36186 \begin_layout Standard
36190 \begin_layout Verse
36196 \begin_layout Standard
36197 Note: All occurrences of a
36201 (pattern variable) must denote the same string.
36202 With the above rule, the assembly sequence:
36205 \begin_layout Verse
36213 \begin_layout Standard
36214 will remain unmodified.
36218 Other special case optimizations may be added by the
36225 \begin_layout Standard
36238 some variants of the 8051 MCU
36239 \begin_inset LatexCommand \index{MCS51 variants}
36252 The following two rules will change all
36269 \begin_layout Verse
36272 replace { lcall %1 } by { acall %1 }
36274 replace { ljmp %1 } by { ajmp %1 }
36277 \begin_layout Standard
36278 (NOTE: from version 2.7.3 on, you can use option -
36284 \begin_layout Standard
36296 \begin_inset LatexCommand \index{-\/-acall-ajmp}
36300 , which also takes care of aligning the interrupt vectors properly.)
36305 \begin_layout Standard
36308 inline-assembler code
36310 is also passed through the peep hole optimizer, thus the peephole optimizer
36311 can also be used as an assembly level macro expander.
36312 The rules themselves are MCU dependent whereas the rule language infra-structur
36313 e is MCU independent.
36314 Peephole optimization rules for other MCU can be easily programmed using
36319 The syntax for a rule is as follows:
36322 \begin_layout Verse
36325 rule := replace [ restart ] '{' <assembly sequence> '
36363 <assembly sequence> '
36381 '}' [if <functionName> ] '
36386 \begin_layout Standard
36387 <assembly sequence> := assembly instruction (each instruction including
36388 labels must be on a separate line).
36392 The optimizer will apply to the rules
36393 one by one from the top in the sequence of their appearance, it will terminate
36394 when all rules are exhausted.
36395 If the 'restart' option is specified, then the optimizer will start matching
36396 the rules again from the top, this option for a rule is expensive (performance)
36397 , it is intended to be used in situations where a transformation will trigger
36398 the same rule again.
36399 An example of this (not a good one, it has side effects) is the following
36403 \begin_layout Verse
36423 \begin_layout Standard
36424 Note that the replace pattern cannot be a blank, but can be a comment line.
36425 Without the 'restart' option only the innermost 'pop' 'push' pair would
36426 be eliminated, i.e.:
36429 \begin_layout Verse
36441 \begin_layout Standard
36445 \begin_layout Verse
36455 \begin_layout Standard
36460 the restart option the rule will be applied again to the resulting code
36461 and then all the pop-push pairs will be eliminated to yield:
36464 \begin_layout Verse
36472 \begin_layout Standard
36473 A conditional function can be attached to a rule.
36474 Attaching rules are somewhat more involved, let me illustrate this with
36478 \begin_layout Verse
36502 \begin_layout Standard
36503 The optimizer does a look-up of a function name table defined in function
36508 in the source file SDCCpeeph.c, with the name
36513 If it finds a corresponding entry the function is called.
36514 Note there can be no parameters specified for these functions, in this
36519 is crucial, since the function
36523 expects to find the label in that particular variable (the hash table containin
36524 g the variable bindings is passed as a parameter).
36525 If you want to code more such functions, take a close look at the function
36526 labelInRange and the calling mechanism in source file SDCCpeeph.c.
36527 Currently implemented are
36529 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
36530 24bitMode, portIsDS390, 24bitModeAndPortDS390
36539 \begin_layout Standard
36540 I know this whole thing is a little kludgey, but maybe some day we will
36541 have some better means.
36542 If you are looking at this file, you will see the default rules that are
36543 compiled into the compiler, you can add your own rules in the default set
36544 there if you get tired of specifying the -
36548 \begin_layout Standard
36560 \begin_layout Section
36562 \begin_inset LatexCommand \index{ANSI-compliance}
36567 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
36574 \begin_layout Standard
36575 The latest publically available version of the standard
36577 ISO/IEC 9899 - Programming languages - C
36579 should be available at:
36580 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
36589 \begin_layout Standard
36590 Deviations from the compliance:
36593 \begin_layout Itemize
36594 functions are not reentrant
36595 \begin_inset LatexCommand \index{reentrant}
36599 unless explicitly declared as such or the
36605 \begin_layout Standard
36615 \begin_inset LatexCommand \index{-\/-stack-auto}
36621 command line option is specified.
36624 \begin_layout Itemize
36626 \begin_inset LatexCommand \index{struct}
36631 \begin_inset LatexCommand \index{union}
36635 cannot be assigned values directly, cannot be passed as function parameters
36636 or assigned to each other and cannot be a return value
36637 \begin_inset LatexCommand \index{return value}
36641 from a function, e.g.:
36645 \begin_layout Verse
36668 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
36687 s parms) /* invalid in SDCC although allowed in ANSI */
36709 return rets; /* is invalid in SDCC although allowed in ANSI */
36715 \begin_layout Itemize
36716 initialization of structure arrays must be fully braced.
36720 \begin_layout Verse
36723 struct s { char x } a[] = {1, 2};\InsetSpace ~
36728 /* invalid in SDCC */
36731 } a[] = {{1}, {2}}; /* OK */
36735 \begin_layout Itemize
36737 \begin_inset LatexCommand \index{long long (not supported)}
36742 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
36749 \begin_layout Itemize
36751 \begin_inset LatexCommand \index{double (not supported)}
36755 ' precision floating point
36756 \begin_inset LatexCommand \index{Floating point support}
36763 \begin_layout Itemize
36765 \begin_inset LatexCommand \index{K\&R style}
36769 function declarations are NOT allowed.
36773 \begin_layout Verse
36776 foo(i,j) /* this old style of function declarations */
36778 int i,j; /* is valid
36779 in ANSI but not valid in SDCC */
36794 \begin_layout Itemize
36795 Most enhancements in C99 are not supported, e.g.:
36799 \begin_layout Verse
36806 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
36810 \begin_layout Itemize
36811 But some have been added recently in SDCC 2.7.0.
36812 They must be considered alpha quality however.
36816 \begin_layout Verse
36821 \begin_inset LatexCommand \index{inline (not supported)}
36827 int increment (int a) { return a+1; } /* inlines the increment without
36828 function call overhead */
36833 \begin_inset LatexCommand \index{inline (not supported)}
36839 p; /* accepted but ignored */
36843 \begin_layout Itemize
36844 Certain words that are valid identifiers in the standard may be reserved
36845 words in SDCC unless the
36851 \begin_layout Standard
36861 \begin_inset LatexCommand \index{-\/-std-c89}
36869 \begin_layout Standard
36879 \begin_inset LatexCommand \index{-\/-std-c99}
36885 command line options are used.
36886 These may include (depending on the selected processor): 'at', 'banked',
36887 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
36888 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
36889 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
36891 Compliant equivalents of these keywords are always available in a form
36892 that begin with two underscores
36893 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
36898 '__data' instead of 'data'.
36901 \begin_layout Itemize
36902 Integer promotion of variable arguments is not performed if the argument
36903 is explicitly taypecasted unless the
36909 \begin_layout Standard
36919 \begin_inset LatexCommand \index{-\/-std-c89}
36927 \begin_layout Standard
36937 \begin_inset LatexCommand \index{-\/-std-c99}
36943 command line options are used.
36947 \begin_layout Verse
36950 void vararg_func (char *str, ...) { str; }
36967 u is promoted to int before
36972 * passing to function */
36976 vararg_func ("%c", c);
36983 argument u is not promoted to int,
36988 * it is passed as char to function
36994 --std-cXX is not defined;
36999 * is promoted to int before passing
37005 if --std-cXX is defined */
37009 vararg_func ("%bc", (char)u);
37015 \begin_layout Section
37016 Cyclomatic Complexity
37017 \begin_inset LatexCommand \index{Cyclomatic complexity}
37024 \begin_layout Standard
37025 Cyclomatic complexity of a function is defined as the number of independent
37026 paths the program can take during execution of the function.
37027 This is an important number since it defines the number test cases you
37028 have to generate to validate the function.
37029 The accepted industry standard for complexity number is 10, if the cyclomatic
37030 complexity reported by SDCC exceeds 10 you should think about simplification
37031 of the function logic.
37032 Note that the complexity level is not related to the number of lines of
37033 code in a function.
37034 Large functions can have low complexity, and small functions can have large
37040 SDCC uses the following formula to compute the complexity:
37045 \begin_layout Standard
37046 complexity = (number of edges in control flow graph) - (number of nodes
37047 in control flow graph) + 2;
37051 Having said that the industry standard is 10,
37052 you should be aware that in some cases it be may unavoidable to have a
37053 complexity level of less than 10.
37054 For example if you have switch statement with more than 10 case labels,
37055 each case label adds one to the complexity level.
37056 The complexity level is by no means an absolute measure of the algorithmic
37057 complexity of the function, it does however provide a good starting point
37058 for which functions you might look at for further optimization.
37061 \begin_layout Section
37062 Retargetting for other Processors
37065 \begin_layout Standard
37066 The issues for retargetting the compiler are far too numerous to be covered
37068 What follows is a brief description of each of the seven phases of the
37069 compiler and its MCU dependency.
37072 \begin_layout Itemize
37073 Parsing the source and building the annotated parse tree.
37074 This phase is largely MCU independent (except for the language extensions).
37075 Syntax & semantic checks are also done in this phase, along with some initial
37076 optimizations like back patching labels and the pattern matching optimizations
37077 like bit-rotation etc.
37080 \begin_layout Itemize
37081 The second phase involves generating an intermediate code which can be easy
37082 manipulated during the later phases.
37083 This phase is entirely MCU independent.
37084 The intermediate code generation assumes the target machine has unlimited
37085 number of registers, and designates them with the name iTemp.
37086 The compiler can be made to dump a human readable form of the code generated
37091 \begin_layout Standard
37103 \begin_layout Itemize
37104 This phase does the bulk of the standard optimizations and is also MCU independe
37106 This phase can be broken down into several sub-phases:
37110 Break down intermediate
37111 code (iCode) into basic blocks.
37113 Do control flow & data flow analysis on the
37116 Do local common subexpression elimination, then global subexpressio
37119 Dead code elimination
37123 If loop optimizations
37124 caused any changes then do 'global subexpression elimination' and 'dead
37125 code elimination' again.
37128 \begin_layout Itemize
37129 This phase determines the live-ranges; by live range I mean those iTemp
37130 variables defined by the compiler that still survive after all the optimization
37132 Live range analysis
37133 \begin_inset LatexCommand \index{Live range analysis}
37137 is essential for register allocation, since these computation determines
37138 which of these iTemps will be assigned to registers, and for how long.
37141 \begin_layout Itemize
37142 Phase five is register allocation.
37143 There are two parts to this process.
37147 The first part I call 'register packing'
37148 (for lack of a better term).
37149 In this case several MCU specific expression folding is done to reduce
37154 The second part is more MCU independent and deals with
37155 allocating registers to the remaining live ranges.
37156 A lot of MCU specific code does creep into this phase because of the limited
37157 number of index registers available in the 8051.
37160 \begin_layout Itemize
37161 The Code generation phase is (unhappily), entirely MCU dependent and very
37162 little (if any at all) of this code can be reused for other MCU.
37163 However the scheme for allocating a homogenized assembler operand for each
37164 iCode operand may be reused.
37167 \begin_layout Itemize
37168 As mentioned in the optimization section the peep-hole optimizer is rule
37169 based system, which can reprogrammed for other MCUs.
37172 \begin_layout Standard
37173 More information is available on SDCC Wiki
37174 \begin_inset LatexCommand \index{wiki}
37179 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting}
37183 ) and in the thread
37184 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
37191 \begin_layout Chapter
37193 \begin_inset LatexCommand \index{Compiler internals}
37200 \begin_layout Section
37201 The anatomy of the compiler
37202 \begin_inset LatexCommand \label{sub:The-anatomy-of}
37209 \begin_layout Standard
37212 This is an excerpt from an article published in Circuit Cellar Magazine
37218 It's a little outdated (the compiler is much more efficient now and user/develo
37219 per friendly), but pretty well exposes the guts of it all.
37225 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
37226 It is fairly easy to retarget for other 8-bit MCU.
37227 Here we take a look at some of the internals of the compiler.
37231 \begin_layout Paragraph*
37233 \begin_inset LatexCommand \index{Parsing}
37240 \begin_layout Standard
37241 Parsing the input source file and creating an AST (Annotated Syntax Tree
37242 \begin_inset LatexCommand \index{Annotated syntax tree}
37247 This phase also involves propagating types (annotating each node of the
37248 parse tree with type information) and semantic analysis.
37249 There are some MCU specific parsing rules.
37250 For example the storage classes, the extended storage classes are MCU specific
37251 while there may be a xdata storage class for 8051 there is no such storage
37252 class for z80 or Atmel AVR.
37253 SDCC allows MCU specific storage class extensions, i.e.
37254 xdata will be treated as a storage class specifier when parsing 8051 C
37255 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
37259 \begin_layout Paragraph*
37261 \begin_inset LatexCommand \index{iCode}
37268 \begin_layout Standard
37269 Intermediate code generation.
37270 In this phase the AST is broken down into three-operand form (iCode).
37271 These three operand forms are represented as doubly linked lists.
37272 ICode is the term given to the intermediate form generated by the compiler.
37273 ICode example section shows some examples of iCode generated for some simple
37274 C source functions.
37277 \begin_layout Paragraph*
37279 \begin_inset LatexCommand \index{Optimizations}
37286 \begin_layout Standard
37287 Bulk of the target independent optimizations is performed in this phase.
37288 The optimizations include constant propagation, common sub-expression eliminati
37289 on, loop invariant code movement, strength reduction of loop induction variables
37290 and dead-code elimination.
37293 \begin_layout Paragraph*
37294 Live range analysis
37295 \begin_inset LatexCommand \index{Live range analysis}
37302 \begin_layout Standard
37303 During intermediate code generation phase, the compiler assumes the target
37304 machine has infinite number of registers and generates a lot of temporary
37306 The live range computation determines the lifetime of each of these compiler-ge
37307 nerated temporaries.
37308 A picture speaks a thousand words.
37309 ICode example sections show the live range annotations for each of the
37311 It is important to note here, each iCode is assigned a number in the order
37312 of its execution in the function.
37313 The live ranges are computed in terms of these numbers.
37314 The from number is the number of the iCode which first defines the operand
37315 and the to number signifies the iCode which uses this operand last.
37318 \begin_layout Paragraph*
37319 Register Allocation
37320 \begin_inset LatexCommand \index{Register allocation}
37327 \begin_layout Standard
37328 The register allocation determines the type and number of registers needed
37330 In most MCUs only a few registers can be used for indirect addressing.
37331 In case of 8051 for example the registers R0 & R1 can be used to indirectly
37332 address the internal ram and DPTR to indirectly address the external ram.
37333 The compiler will try to allocate the appropriate register to pointer variables
37335 ICode example section shows the operands annotated with the registers assigned
37337 The compiler will try to keep operands in registers as much as possible;
37338 there are several schemes the compiler uses to do achieve this.
37339 When the compiler runs out of registers the compiler will check to see
37340 if there are any live operands which is not used or defined in the current
37341 basic block being processed, if there are any found then it will push that
37342 operand and use the registers in this block, the operand will then be popped
37343 at the end of the basic block.
37347 \begin_layout Standard
37348 There are other MCU specific considerations in this phase.
37349 Some MCUs have an accumulator; very short-lived operands could be assigned
37350 to the accumulator instead of a general-purpose register.
37353 \begin_layout Paragraph*
37357 \begin_layout Standard
37358 Figure II gives a table of iCode
37359 \begin_inset LatexCommand \index{iCode}
37363 operations supported by the compiler.
37364 The code generation involves translating these operations into corresponding
37365 assembly code for the processor.
37366 This sounds overly simple but that is the essence of code generation.
37367 Some of the iCode operations are generated on a MCU specific manner for
37368 example, the z80 port does not use registers to pass parameters so the
37369 SEND and RECV iCode operations will not be generated, and it also does
37370 not support JUMPTABLES.
37376 \begin_layout Standard
37380 \begin_inset Tabular
37381 <lyxtabular version="3" rows="39" columns="4">
37382 <features islongtable="true" headBottomDL="true">
37383 <column alignment="block" valignment="top" leftline="true" width="13col%">
37384 <column alignment="left" valignment="top" leftline="true" width="13col%">
37385 <column alignment="block" valignment="top" leftline="true" width="22col%">
37386 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
37387 <row topline="true" bottomline="true" endhead="true">
37388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37391 \begin_layout Standard
37397 \begin_inset LatexCommand \index{iCode}
37406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37409 \begin_layout Standard
37417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37420 \begin_layout Standard
37428 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37431 \begin_layout Standard
37440 <row topline="true">
37441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37444 \begin_layout Standard
37452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37455 \begin_layout Standard
37458 IC_LEFT() IC_RESULT()
37463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37466 \begin_layout Standard
37474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37477 \begin_layout Standard
37480 IC_RESULT = ! IC_LEFT;
37486 <row topline="true">
37487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37490 \begin_layout Standard
37498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37501 \begin_layout Standard
37504 IC_LEFT() IC_RESULT()
37509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37512 \begin_layout Standard
37515 Bitwise complement of
37520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37523 \begin_layout Standard
37526 IC_RESULT = ~IC_LEFT;
37532 <row topline="true">
37533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37536 \begin_layout Standard
37544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37547 \begin_layout Standard
37550 IC_LEFT() IC_RESULT()
37555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37558 \begin_layout Standard
37561 Rotate right with carry
37566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37569 \begin_layout Standard
37572 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
37578 <row topline="true">
37579 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37582 \begin_layout Standard
37590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37593 \begin_layout Standard
37596 IC_LEFT() IC_RESULT()
37601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37604 \begin_layout Standard
37607 Rotate left with carry
37612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37615 \begin_layout Standard
37618 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
37624 <row topline="true">
37625 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37628 \begin_layout Standard
37636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37639 \begin_layout Standard
37642 IC_LEFT() IC_RESULT()
37647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37650 \begin_layout Standard
37653 Get the highest order bit of IC_LEFT
37658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37661 \begin_layout Standard
37664 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
37670 <row topline="true">
37671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37674 \begin_layout Standard
37682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37685 \begin_layout Standard
37688 IC_LEFT() IC_RESULT()
37693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37696 \begin_layout Standard
37704 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37707 \begin_layout Standard
37710 IC_RESULT = - IC_LEFT;
37716 <row topline="true">
37717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37720 \begin_layout Standard
37728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37731 \begin_layout Standard
37739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37742 \begin_layout Standard
37745 Push the operand into stack
37750 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37753 \begin_layout Standard
37762 <row topline="true">
37763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37766 \begin_layout Standard
37774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37777 \begin_layout Standard
37785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37788 \begin_layout Standard
37791 Pop the operand from the stack
37796 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37799 \begin_layout Standard
37808 <row topline="true">
37809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37812 \begin_layout Standard
37820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37823 \begin_layout Standard
37826 IC_LEFT() IC_RESULT()
37831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37834 \begin_layout Standard
37837 Call the function represented by IC_LEFT
37842 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37845 \begin_layout Standard
37848 IC_RESULT = IC_LEFT();
37854 <row topline="true">
37855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37858 \begin_layout Standard
37866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37869 \begin_layout Standard
37872 IC_LEFT() IC_RESULT()
37877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37880 \begin_layout Standard
37883 Call via function pointer
37888 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37891 \begin_layout Standard
37894 IC_RESULT = (*IC_LEFT)();
37900 <row topline="true">
37901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37904 \begin_layout Standard
37912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37915 \begin_layout Standard
37923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37926 \begin_layout Standard
37929 Return the value in operand IC_LEFT
37934 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37937 \begin_layout Standard
37946 <row topline="true">
37947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37950 \begin_layout Standard
37958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37961 \begin_layout Standard
37969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37972 \begin_layout Standard
37980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37983 \begin_layout Standard
37992 <row topline="true">
37993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37996 \begin_layout Standard
38004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38007 \begin_layout Standard
38015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38018 \begin_layout Standard
38026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38029 \begin_layout Standard
38038 <row topline="true">
38039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38042 \begin_layout Standard
38050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38053 \begin_layout Standard
38056 IC_LEFT() IC_RIGHT() IC_RESULT()
38061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38064 \begin_layout Standard
38072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38075 \begin_layout Standard
38078 IC_RESULT = IC_LEFT + IC_RIGHT
38084 <row topline="true">
38085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38088 \begin_layout Standard
38096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38099 \begin_layout Standard
38102 IC_LEFT() IC_RIGHT() IC_RESULT()
38107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38110 \begin_layout Standard
38118 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38121 \begin_layout Standard
38124 IC_RESULT = IC_LEFT - IC_RIGHT
38130 <row topline="true">
38131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38134 \begin_layout Standard
38142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38145 \begin_layout Standard
38148 IC_LEFT() IC_RIGHT() IC_RESULT()
38153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38156 \begin_layout Standard
38164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38167 \begin_layout Standard
38170 IC_RESULT = IC_LEFT * IC_RIGHT;
38176 <row topline="true">
38177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38180 \begin_layout Standard
38188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38191 \begin_layout Standard
38194 IC_LEFT() IC_RIGHT() IC_RESULT()
38199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38202 \begin_layout Standard
38210 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38213 \begin_layout Standard
38216 IC_RESULT = IC_LEFT / IC_RIGHT;
38222 <row topline="true">
38223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38226 \begin_layout Standard
38234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38237 \begin_layout Standard
38240 IC_LEFT() IC_RIGHT() IC_RESULT()
38245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38248 \begin_layout Standard
38256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38259 \begin_layout Standard
38262 IC_RESULT = IC_LEFT % IC_RIGHT;
38268 <row topline="true">
38269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38272 \begin_layout Standard
38280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38283 \begin_layout Standard
38286 IC_LEFT() IC_RIGHT() IC_RESULT()
38291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38294 \begin_layout Standard
38302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38305 \begin_layout Standard
38308 IC_RESULT = IC_LEFT < IC_RIGHT;
38314 <row topline="true">
38315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38318 \begin_layout Standard
38326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38329 \begin_layout Standard
38332 IC_LEFT() IC_RIGHT() IC_RESULT()
38337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38340 \begin_layout Standard
38348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38351 \begin_layout Standard
38354 IC_RESULT = IC_LEFT > IC_RIGHT;
38360 <row topline="true">
38361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38364 \begin_layout Standard
38372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38375 \begin_layout Standard
38378 IC_LEFT() IC_RIGHT() IC_RESULT()
38383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38386 \begin_layout Standard
38394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38397 \begin_layout Standard
38400 IC_RESULT = IC_LEFT == IC_RIGHT;
38406 <row topline="true">
38407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38410 \begin_layout Standard
38418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38421 \begin_layout Standard
38424 IC_LEFT() IC_RIGHT() IC_RESULT()
38429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38432 \begin_layout Standard
38435 Logical and operation
38440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38443 \begin_layout Standard
38446 IC_RESULT = IC_LEFT && IC_RIGHT;
38452 <row topline="true">
38453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38456 \begin_layout Standard
38464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38467 \begin_layout Standard
38470 IC_LEFT() IC_RIGHT() IC_RESULT()
38475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38478 \begin_layout Standard
38481 Logical or operation
38486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38489 \begin_layout Standard
38492 IC_RESULT = IC_LEFT || IC_RIGHT;
38498 <row topline="true">
38499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38502 \begin_layout Standard
38510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38513 \begin_layout Standard
38516 IC_LEFT() IC_RIGHT() IC_RESULT()
38521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38524 \begin_layout Standard
38532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38535 \begin_layout Standard
38538 IC_RESULT = IC_LEFT ^ IC_RIGHT;
38544 <row topline="true">
38545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38548 \begin_layout Standard
38556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38559 \begin_layout Standard
38562 IC_LEFT() IC_RIGHT() IC_RESULT()
38567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38570 \begin_layout Standard
38578 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38581 \begin_layout Standard
38584 IC_RESULT = IC_LEFT | IC_RIGHT;
38590 <row topline="true">
38591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38594 \begin_layout Standard
38602 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38605 \begin_layout Standard
38608 IC_LEFT() IC_RIGHT() IC_RESULT()
38613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38616 \begin_layout Standard
38624 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38627 \begin_layout Standard
38630 IC_RESULT = IC_LEFT & IC_RIGHT;
38636 <row topline="true">
38637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38640 \begin_layout Standard
38648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38651 \begin_layout Standard
38654 IC_LEFT() IC_RIGHT() IC_RESULT()
38659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38662 \begin_layout Standard
38670 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38673 \begin_layout Standard
38676 IC_RESULT = IC_LEFT << IC_RIGHT
38682 <row topline="true">
38683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38686 \begin_layout Standard
38694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38697 \begin_layout Standard
38700 IC_LEFT() IC_RIGHT() IC_RESULT()
38705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38708 \begin_layout Standard
38716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38719 \begin_layout Standard
38722 IC_RESULT = IC_LEFT >> IC_RIGHT
38728 <row topline="true">
38729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38732 \begin_layout Standard
38742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38745 \begin_layout Standard
38748 IC_LEFT() IC_RESULT()
38753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38756 \begin_layout Standard
38764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38767 \begin_layout Standard
38770 IC_RESULT = (*IC_LEFT);
38776 <row topline="true">
38777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38780 \begin_layout Standard
38788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38791 \begin_layout Standard
38794 IC_RIGHT() IC_RESULT()
38799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38802 \begin_layout Standard
38810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38813 \begin_layout Standard
38816 (*IC_RESULT) = IC_RIGHT;
38822 <row topline="true">
38823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38826 \begin_layout Standard
38834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38837 \begin_layout Standard
38840 IC_RIGHT() IC_RESULT()
38845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38848 \begin_layout Standard
38856 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38859 \begin_layout Standard
38862 IC_RESULT = IC_RIGHT;
38868 <row topline="true">
38869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38872 \begin_layout Standard
38880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38883 \begin_layout Standard
38886 IC_COND IC_TRUE IC_LABEL
38891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38894 \begin_layout Standard
38898 If true label is present then jump to true label if condition is true else
38899 jump to false label if condition is false
38904 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38907 \begin_layout Standard
38910 if (IC_COND) goto IC_TRUE;
38916 If (!IC_COND) goto IC_FALSE;
38922 <row topline="true">
38923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38926 \begin_layout Standard
38934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38937 \begin_layout Standard
38940 IC_LEFT() IC_RESULT()
38945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38948 \begin_layout Standard
38956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38959 \begin_layout Standard
38962 IC_RESULT = &IC_LEFT();
38968 <row topline="true">
38969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38972 \begin_layout Standard
38980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38983 \begin_layout Standard
38986 IC_JTCOND IC_JTLABELS
38991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38994 \begin_layout Standard
38997 Jump to list of labels depending on the value of JTCOND
39002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39005 \begin_layout Standard
39014 <row topline="true">
39015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39018 \begin_layout Standard
39026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39029 \begin_layout Standard
39032 IC_RIGHT() IC_LEFT() IC_RESULT()
39037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39040 \begin_layout Standard
39048 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39051 \begin_layout Standard
39054 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
39060 <row topline="true">
39061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39064 \begin_layout Standard
39072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39075 \begin_layout Standard
39083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39086 \begin_layout Standard
39089 This is used for passing parameters in registers;
39091 move IC_LEFT to the next
39092 available parameter register.
39097 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39100 \begin_layout Standard
39109 <row topline="true">
39110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39113 \begin_layout Standard
39121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39124 \begin_layout Standard
39132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39135 \begin_layout Standard
39138 This is used for receiving parameters passed in registers;
39141 in the next parameter register to IC_RESULT
39146 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39149 \begin_layout Standard
39158 <row topline="true" bottomline="true">
39159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39162 \begin_layout Standard
39166 (some more have been added)
39171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39174 \begin_layout Standard
39180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39183 \begin_layout Standard
39189 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39192 \begin_layout Standard
39216 \begin_layout Standard
39217 \begin_inset Note Note
39220 \begin_layout Standard
39221 In the original article Figure II was announced to be downloadable on
39226 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
39234 \begin_layout Paragraph*
39236 \begin_inset LatexCommand \index{iCode}
39243 \begin_layout Standard
39244 This section shows some details of iCode.
39245 The example C code does not do anything useful; it is used as an example
39246 to illustrate the intermediate code generated by the compiler.
39249 \begin_layout Verse
39259 /* This function does nothing useful.
39266 for the purpose of explaining iCode */
39269 short function (data
39278 short i=10; \InsetSpace ~
39280 /* dead initialization eliminated */
39286 /* dead initialization eliminated */
39314 /* compiler detects i,j to be induction
39319 for (i = 0, j = 10 ; i < 10 ; i++, j
39325 \begin_layout Standard
39348 mul += i * 3; \InsetSpace ~
39350 /* this multiplication remains */
39357 j * 3;\InsetSpace ~
39359 /* this multiplication changed to addition */
39373 \begin_layout Standard
39374 In addition to the operands each iCode contains information about the filename
39375 and line it corresponds to in the source file.
39376 The first field in the listing should be interpreted as follows:
39381 Filename(linenumber: iCode Execution sequence number : ICode hash table
39382 key : loop depth of the iCode).
39387 Then follows the human readable form of the ICode operation.
39388 Each operand of this triplet form can be of three basic types a) compiler
39389 generated temporary b) user defined variable c) a constant value.
39390 Note that local variables and parameters are replaced by compiler generated
39393 \begin_inset LatexCommand \index{Live range analysis}
39397 are computed only for temporaries (i.e.
39398 live ranges are not computed for global variables).
39400 \begin_inset LatexCommand \index{Register allocation}
39404 are allocated for temporaries only.
39405 Operands are formatted in the following manner:
39410 Operand Name [lr live-from : live-to ] { type information } [ registers
39416 As mentioned earlier the live ranges are computed in terms of the execution
39417 sequence number of the iCodes, for example
39419 the iTemp0 is live from (i.e.
39420 first defined in iCode with execution sequence number 3, and is last used
39421 in the iCode with sequence number 5).
39422 For induction variables such as iTemp21 the live range computation extends
39423 the lifetime from the start to the end of the loop.
39425 The register allocator
39426 used the live range information to allocate registers, the same registers
39427 may be used for different temporaries if their live ranges do not overlap,
39428 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
39429 ranges do not overlap.
39430 In addition the allocator also takes into consideration the type and usage
39431 of a temporary, for example itemp6 is a pointer to near space and is used
39432 as to fetch data from (i.e.
39433 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
39434 Some short lived temporaries are allocated to special registers which have
39435 meaning to the code generator e.g.
39436 iTemp13 is allocated to a pseudo register CC which tells the back end that
39437 the temporary is used only for a conditional jump the code generation makes
39438 use of this information to optimize a compare and jump ICode.
39442 \begin_inset LatexCommand \index{Loop optimization}
39446 performed by the compiler.
39447 It can detect induction variables iTemp21(i) and iTemp23(j).
39448 Also note the compiler does selective strength reduction
39449 \begin_inset LatexCommand \index{Strength reduction}
39454 the multiplication of an induction variable in line 18 (gint = j * 3) is
39455 changed to addition, a new temporary iTemp17 is allocated and assigned
39456 a initial value, a constant 3 is then added for each iteration of the loop.
39457 The compiler does not change the multiplication
39458 \begin_inset LatexCommand \index{Multiplication}
39462 in line 17 however since the processor does support an 8 * 8 bit multiplication.
39465 Note the dead code elimination
39466 \begin_inset LatexCommand \index{Dead-code elimination}
39470 optimization eliminated the dead assignments in line 7 & 8 to I and sum
39476 \begin_layout Standard
39479 Sample.c (5:1:0:0) _entry($9) :
39482 \begin_layout Standard
39485 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
39488 \begin_layout Standard
39491 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
39494 \begin_layout Standard
39497 Sample.c(11:4:53:0) preHeaderLbl0($11) :
39500 \begin_layout Standard
39503 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
39507 \begin_layout Standard
39510 Sample.c(11:6:5:1) _whilecontinue_0($1) :
39513 \begin_layout Standard
39516 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
39520 \begin_layout Standard
39523 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39526 \begin_layout Standard
39529 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
39533 \begin_layout Standard
39536 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
39540 \begin_layout Standard
39543 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
39547 \begin_layout Standard
39550 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
39554 \begin_layout Standard
39557 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
39558 * int}[r0] + 0x2 {short}
39561 \begin_layout Standard
39564 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
39567 \begin_layout Standard
39570 Sample.c(11:17:21:0)_whilebreak_0($3) :
39573 \begin_layout Standard
39576 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39579 \begin_layout Standard
39582 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39585 \begin_layout Standard
39588 Sample.c(15:20:54:0)preHeaderLbl1($13) :
39591 \begin_layout Standard
39594 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39597 \begin_layout Standard
39600 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39603 \begin_layout Standard
39606 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39609 \begin_layout Standard
39612 Sample.c(15:24:26:1)_forcond_0($4) :
39615 \begin_layout Standard
39618 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
39622 \begin_layout Standard
39625 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39628 \begin_layout Standard
39631 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
39632 + ITemp21 [lr21:38]{short}[r4]
39635 \begin_layout Standard
39638 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
39642 \begin_layout Standard
39645 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
39646 + iTemp15 [lr29:30]{short}[r1]
39649 \begin_layout Standard
39652 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
39656 \begin_layout Standard
39659 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
39663 \begin_layout Standard
39666 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
39670 \begin_layout Standard
39673 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
39677 \begin_layout Standard
39680 Sample.c(19:38:47:1) goto _forcond_0($4)
39683 \begin_layout Standard
39686 Sample.c(19:39:48:0)_forbreak_0($7) :
39689 \begin_layout Standard
39692 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
39693 + ITemp11 [lr19:40]{short}[r3]
39696 \begin_layout Standard
39699 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
39702 \begin_layout Standard
39705 Sample.c(20:42:51:0)_return($8) :
39708 \begin_layout Standard
39711 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
39717 Finally the code generated for this function:
39722 \begin_layout Standard
39728 \begin_layout Standard
39734 \begin_layout Standard
39742 \begin_layout Standard
39748 \begin_layout Standard
39756 \begin_layout Standard
39762 \begin_layout Standard
39765 ; ----------------------------------------------
39768 \begin_layout Standard
39771 ; function function
39774 \begin_layout Standard
39777 ; ----------------------------------------------
39780 \begin_layout Standard
39786 \begin_layout Standard
39789 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
39792 \begin_layout Standard
39800 \begin_layout Standard
39803 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
39806 \begin_layout Standard
39814 \begin_layout Standard
39817 ;_whilecontinue_0($1) :
39820 \begin_layout Standard
39826 \begin_layout Standard
39829 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
39832 \begin_layout Standard
39835 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39838 \begin_layout Standard
39846 \begin_layout Standard
39854 \begin_layout Standard
39862 \begin_layout Standard
39870 \begin_layout Standard
39878 \begin_layout Standard
39886 \begin_layout Standard
39894 \begin_layout Standard
39900 \begin_layout Standard
39903 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
39906 \begin_layout Standard
39914 \begin_layout Standard
39922 \begin_layout Standard
39925 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
39928 \begin_layout Standard
39936 \begin_layout Standard
39944 \begin_layout Standard
39952 \begin_layout Standard
39960 \begin_layout Standard
39968 \begin_layout Standard
39976 \begin_layout Standard
39979 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
39982 \begin_layout Standard
39990 \begin_layout Standard
39998 \begin_layout Standard
40006 \begin_layout Standard
40014 \begin_layout Standard
40022 \begin_layout Standard
40025 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
40028 \begin_layout Standard
40036 \begin_layout Standard
40044 \begin_layout Standard
40052 \begin_layout Standard
40055 ; iTemp6 [lr5:16]{_near * int}[r0] =
40058 \begin_layout Standard
40061 ; iTemp6 [lr5:16]{_near * int}[r0] +
40064 \begin_layout Standard
40070 \begin_layout Standard
40078 \begin_layout Standard
40081 ; goto _whilecontinue_0($1)
40084 \begin_layout Standard
40092 \begin_layout Standard
40095 ; _whilebreak_0($3) :
40098 \begin_layout Standard
40104 \begin_layout Standard
40107 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
40110 \begin_layout Standard
40118 \begin_layout Standard
40121 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
40124 \begin_layout Standard
40132 \begin_layout Standard
40135 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
40138 \begin_layout Standard
40146 \begin_layout Standard
40149 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
40152 \begin_layout Standard
40160 \begin_layout Standard
40168 \begin_layout Standard
40171 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
40174 \begin_layout Standard
40182 \begin_layout Standard
40190 \begin_layout Standard
40196 \begin_layout Standard
40202 \begin_layout Standard
40205 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
40208 \begin_layout Standard
40211 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
40214 \begin_layout Standard
40222 \begin_layout Standard
40230 \begin_layout Standard
40238 \begin_layout Standard
40246 \begin_layout Standard
40254 \begin_layout Standard
40260 \begin_layout Standard
40263 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
40266 \begin_layout Standard
40269 ; iTemp21 [lr21:38]{short}[r4]
40272 \begin_layout Standard
40280 \begin_layout Standard
40288 \begin_layout Standard
40296 \begin_layout Standard
40299 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
40302 \begin_layout Standard
40310 \begin_layout Standard
40318 \begin_layout Standard
40326 \begin_layout Standard
40334 \begin_layout Standard
40337 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
40340 \begin_layout Standard
40343 ; iTemp15 [lr29:30]{short}[r1]
40346 \begin_layout Standard
40354 \begin_layout Standard
40362 \begin_layout Standard
40365 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
40368 \begin_layout Standard
40376 \begin_layout Standard
40384 \begin_layout Standard
40392 \begin_layout Standard
40400 \begin_layout Standard
40408 \begin_layout Standard
40416 \begin_layout Standard
40419 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
40422 \begin_layout Standard
40430 \begin_layout Standard
40438 \begin_layout Standard
40446 \begin_layout Standard
40454 \begin_layout Standard
40462 \begin_layout Standard
40470 \begin_layout Standard
40473 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
40476 \begin_layout Standard
40484 \begin_layout Standard
40487 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
40490 \begin_layout Standard
40498 \begin_layout Standard
40503 cjne r5,#0xff,00104$
40506 \begin_layout Standard
40514 \begin_layout Standard
40517 ; goto _forcond_0($4)
40520 \begin_layout Standard
40528 \begin_layout Standard
40531 ; _forbreak_0($7) :
40534 \begin_layout Standard
40540 \begin_layout Standard
40543 ; ret iTemp24 [lr40:41]{short}
40546 \begin_layout Standard
40554 \begin_layout Standard
40562 \begin_layout Standard
40570 \begin_layout Standard
40576 \begin_layout Standard
40582 \begin_layout Standard
40592 \begin_layout Section
40593 A few words about basic block successors, predecessors and dominators
40596 \begin_layout Standard
40597 Successors are basic blocks
40598 \begin_inset LatexCommand \index{Basic blocks}
40602 that might execute after this basic block.
40604 Predecessors are basic blocks
40605 that might execute before reaching this basic block.
40607 Dominators are basic
40608 blocks that WILL execute before reaching this basic block.
40613 \begin_layout Standard
40617 \begin_layout Standard
40621 \begin_layout Standard
40629 \begin_layout Standard
40633 \begin_layout Standard
40641 \begin_layout Standard
40647 \begin_layout Standard
40648 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
40651 \begin_layout Standard
40652 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
40655 \begin_layout Standard
40656 c) domVect of [BB4] = BB1 ...
40657 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
40661 \begin_layout Chapter
40665 \begin_layout Standard
40666 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
40676 Thanks to all the other volunteer developers who have helped with coding,
40677 testing, web-page creation, distribution sets, etc.
40678 You know who you are :-)
40686 Thanks to Sourceforge
40687 \begin_inset LatexCommand \url{http://www.sf.net}
40691 which has hosted the project since 1999 and donates significant download
40700 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
40701 cycles and bandwidth for snapshot builds.
40706 \begin_layout Standard
40707 This document was initially written by Sandeep Dutta
40710 \begin_layout Standard
40711 All product names mentioned herein may be trademarks
40712 \begin_inset LatexCommand \index{Trademarks}
40716 of their respective companies.
40720 \begin_layout Section*
40724 \begin_layout Standard
40725 To avoid confusion, the installation and building options for SDCC itself
40726 (chapter 2) are not part of the index.
40729 \begin_layout Standard
40730 \begin_inset LatexCommand \printindex{}