1 #LyX 1.4.5 created this file. For more info see http://www.lyx.org/
7 \pdfoptionpdfminorversion=3
9 pdftitle={SDCC Compiler User Guide},
10 pdfauthor={SDCC development team},
11 pdfsubject={installation, user manual},
12 pdfkeywords={68hc08 8032 8051 ansi c compiler assembler CPU DS390 embedded development free Floating Point Arithmetic Freescale GPL HC08 inline Intel ISO/IEC 9899:1990 Linux MAC OS X manual Maxim mcs51 Microchip microcontroller open source PIC Unix Windows Z80 Zilog},
13 pdfpagemode=UseOutlines,
15 linkcolor=blue] {hyperref}
19 \emergencystretch=30pt
24 \inputencoding default
27 \paperfontsize default
29 \papersize letterpaper
34 \paperorientation portrait
41 \paragraph_separation indent
43 \quotes_language swedish
47 \tracking_changes false
53 \begin_layout Standard
54 \begin_inset Note Note
57 \begin_layout Standard
58 Please note: double dashed longoptions (e.g.
59 --version) are written this way: -
63 \begin_layout Standard
75 \begin_layout Standard
77 three consecutive dashes would otherwise result in a long resp.
81 \begin_layout Standard
82 Architecture specific stuff (like memory models, code examples) should maybe
86 \begin_layout Standard
87 into seperate sections/chapters/appendices (it is hard to document PIC or
91 \begin_layout Standard
92 a 8051 centered document) - for now simply add.
101 SDCC Compiler User Guide
116 \begin_layout Standard
117 \begin_inset Note Note
120 \begin_layout Standard
121 The above strings enclosed in $ are automatically updated by Subversion
129 \begin_layout Standard
130 \begin_inset LatexCommand \tableofcontents{}
137 \begin_layout Chapter
141 \begin_layout Section
145 \begin_layout Standard
166 ompiler) is free open source, retargettable, optimizing ANSI-C compiler
171 designed for 8 bit Microprocessors.
172 The current version targets Intel MCS51 based Microprocessors (8031, 8032,
174 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
178 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
179 Zilog Z80 based MCUs.
180 It can be retargeted for other microprocessors, support for Microchip PIC,
181 Atmel AVR is under development.
182 The entire source code for the compiler is distributed under GPL.
184 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
189 \begin_inset LatexCommand \index{aslink}
193 , an open source retargetable assembler & linker.
194 SDCC has extensive language extensions suitable for utilizing various microcont
195 rollers and underlying hardware effectively.
200 In addition to the MCU specific optimizations SDCC also does a host of
201 standard optimizations like:
204 \begin_layout Itemize
205 global sub expression elimination,
208 \begin_layout Itemize
209 loop optimizations (loop invariant, strength reduction of induction variables
213 \begin_layout Itemize
214 constant folding & propagation,
217 \begin_layout Itemize
221 \begin_layout Itemize
222 dead code elimination
225 \begin_layout Itemize
233 \begin_layout Standard
234 For the back-end SDCC uses a global register allocation scheme which should
235 be well suited for other 8 bit MCUs.
240 The peep hole optimizer uses a rule based substitution mechanism which
246 Supported data-types are:
249 \begin_layout Standard
251 <lyxtabular version="3" rows="8" columns="5">
253 <column alignment="center" valignment="top" leftline="true" width="0">
254 <column alignment="center" valignment="top" leftline="true" width="0">
255 <column alignment="center" valignment="top" leftline="true" width="0">
256 <column alignment="center" valignment="top" leftline="true" width="0">
257 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
258 <row topline="true" bottomline="true">
259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
262 \begin_layout Standard
268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
271 \begin_layout Standard
277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
280 \begin_layout Standard
286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
289 \begin_layout Standard
295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
298 \begin_layout Standard
306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
309 \begin_layout Standard
315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
318 \begin_layout Standard
324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
327 \begin_layout Standard
333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
336 \begin_layout Standard
342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
345 \begin_layout Standard
353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
356 \begin_layout Standard
362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
365 \begin_layout Standard
371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
374 \begin_layout Standard
380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
383 \begin_layout Standard
389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
392 \begin_layout Standard
400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
403 \begin_layout Standard
409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
412 \begin_layout Standard
418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
421 \begin_layout Standard
427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
430 \begin_layout Standard
436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
439 \begin_layout Standard
447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
450 \begin_layout Standard
456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
459 \begin_layout Standard
465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
468 \begin_layout Standard
474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
477 \begin_layout Standard
483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
486 \begin_layout Standard
493 <row topline="true" bottomline="true">
494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
497 \begin_layout Standard
503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
506 \begin_layout Standard
512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
515 \begin_layout Standard
521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
524 \begin_layout Standard
525 -2.147.483.648, +2.147.483.647
530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
533 \begin_layout Standard
540 <row topline="true" bottomline="true">
541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
544 \begin_layout Standard
550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
553 \begin_layout Standard
559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
562 \begin_layout Standard
568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
571 \begin_layout Standard
577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
580 \begin_layout Standard
596 <row topline="true" bottomline="true">
597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
600 \begin_layout Standard
606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
609 \begin_layout Standard
615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
618 \begin_layout Standard
624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
627 \begin_layout Standard
633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
636 \begin_layout Standard
649 The compiler also allows
651 inline assembler code
653 to be embedded anywhere in a function.
654 In addition, routines developed in assembly can also be called.
659 provides an option (-
663 \begin_layout Standard
672 -cyclomatic) to report the relative complexity of a function.
673 These functions can then be further optimized, or hand coded in assembly
679 SDCC also comes with a companion source level debugger SDCDB.
680 The debugger currently uses ucSim, a free open source simulator for 8051
681 and other micro-controllers.
685 The latest SDCC version can be downloaded from
687 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
697 Please note: the compiler will probably always be some steps ahead of this
702 \begin_inset LatexCommand \index{Status of documentation}
710 \begin_layout Standard
711 Obviously this has pros and cons
719 \begin_layout Section
723 \begin_layout Standard
724 All packages used in this compiler system are
732 ; source code for all the sub-packages (pre-processor, assemblers, linkers
733 etc.) is distributed with the package.
734 This documentation is maintained using a free open source word processor
737 This program is free software; you can redistribute it and/or modify
738 it under the terms of the GNU General Public License
739 \begin_inset LatexCommand \index{GNU General Public License, GPL}
743 as published by the Free Software Foundation; either version 2, or (at
744 your option) any later version.
745 This program is distributed in the hope that it will be useful, but WITHOUT
746 ANY WARRANTY; without even the implied warranty
747 \begin_inset LatexCommand \index{warranty}
751 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
752 See the GNU General Public License for more details.
753 You should have received a copy of the GNU General Public License along
754 with this program; if not, write to the Free Software Foundation, 59 Temple
755 Place - Suite 330, Boston, MA 02111-1307, USA.
756 In other words, you are welcome to use, share and improve this program.
757 You are forbidden to forbid anyone else to use, share and improve what
759 Help stamp out software-hoarding!
762 \begin_layout Section
763 Typographic conventions
764 \begin_inset LatexCommand \index{Typographic conventions}
771 \begin_layout Standard
772 Throughout this manual, we will use the following convention.
773 Commands you have to type in are printed in
781 Code samples are printed in
786 Interesting items and new terms are printed in
791 \begin_layout Section
793 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
797 with previous versions
798 \begin_inset LatexCommand \index{Compatibility with previous versions}
805 \begin_layout Standard
806 Newer versions have usually numerous bug fixes compared with the previous
808 But we also sometimes introduce some incompatibilities with older versions.
809 Not just for the fun of it, but to make the compiler more stable, efficient
811 \begin_inset LatexCommand \index{ANSI-compliance}
816 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
820 for ANSI-Compliance).
822 \begin_inset Note Note
825 \begin_layout Standard
826 It would be fine to add to each item, in which version was it changed.
836 \begin_layout Itemize
837 short is now equivalent to int (16 bits), it used to be equivalent to char
838 (8 bits) which is not ANSI compliant.
839 To maintain compatibility, old programs may be compiled using the -
843 \begin_layout Standard
852 -short-is-8bits commandline option (see
853 \begin_inset LatexCommand \vref{lyx:--short-is-8bits}
860 \begin_layout Itemize
861 the default directory for gcc-builds where include, library and documentation
862 files are stored is now in /usr/local/share.
865 \begin_layout Itemize
866 char type parameters to vararg
867 \begin_inset LatexCommand \index{vararg, va\_arg}
871 functions are casted to int unless explicitly casted and
877 \begin_layout Standard
887 \begin_inset LatexCommand \index{-\/-std-c89}
899 \begin_layout Standard
909 \begin_inset LatexCommand \index{-\/-std-c99}
915 command line option are not defined
916 \begin_inset Marginal
919 \begin_layout Standard
944 will push a as an int and as a char resp if
950 \begin_layout Standard
960 \begin_inset LatexCommand \index{-\/-std-c89}
972 \begin_layout Standard
982 \begin_inset LatexCommand \index{-\/-std-c99}
988 command line options are not defined,
990 will push a as two ints if
996 \begin_layout Standard
1006 \begin_inset LatexCommand \index{-\/-std-c89}
1018 \begin_layout Standard
1028 \begin_inset LatexCommand \index{-\/-std-c99}
1034 command line option is defined.
1037 \begin_layout Itemize
1042 \begin_layout Standard
1051 -regextend has been removed.
1054 \begin_layout Itemize
1059 \begin_layout Standard
1068 -noregparms has been removed.
1071 \begin_layout Itemize
1076 \begin_layout Standard
1085 -stack-after-data has been removed.
1088 \begin_layout Itemize
1090 \begin_inset LatexCommand \index{bit}
1095 \begin_inset LatexCommand \index{sbit}
1100 \begin_inset LatexCommand \index{\_\_sbit}
1104 types now consistently behave like the C99 _Bool type with respect to type
1106 \begin_inset LatexCommand \index{type conversion}
1111 \begin_inset LatexCommand \index{type promotion}
1116 The most common incompatibility resulting from this change is related to
1118 \begin_inset LatexCommand \index{Bit toggling}
1133 \begin_inset LatexCommand \index{\~\/ Operator}
1137 b; /* equivalent to b=1 instead of toggling b */
1138 \begin_inset Marginal
1141 \begin_layout Standard
1154 b = !b; /* toggles b */
1158 In previous versions, both forms would have toggled the bit.
1161 \begin_layout Itemize
1162 in older versions, the preprocessor was always called with -std=c99 regardless
1163 of the --std-xxx setting.
1164 This is no longer true, and can cause compilation failures on code built
1165 with --std-c89 but using c99 preprocessor features, such as one-line (//)
1169 \begin_layout Itemize
1170 in versions older then 2.8.4 the pic16 *printf() and printf_tiny() library
1171 functions supported undocumented and not standard compliant 'b' binary
1172 format specifier ("%b", "%hb" and "%lb").
1173 The 'b' specifier is now disabled by default.
1174 It can be enabled by defining BINARY_SPECIFIER macro in files device/lib/pic16/
1175 libc/stdio/vfprintf.c and device/lib/pic16/libc/stdio/printf_tiny.c and recompilin
1179 \begin_layout Section
1183 \begin_layout Standard
1184 What do you need before you start installation of SDCC? A computer, and
1185 a desire to compute.
1186 The preferred method of installation is to compile SDCC from source using
1188 For Windows some pre-compiled binary distributions are available for your
1190 You should have some experience with command line tools and compiler use.
1193 \begin_layout Section
1197 \begin_layout Standard
1198 The SDCC home page at
1199 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1203 is a great place to find distribution sets.
1204 You can also find links to the user mailing lists that offer help or discuss
1205 SDCC with other SDCC users.
1206 Web links to other SDCC related sites can also be found here.
1207 This document can be found in the DOC directory of the source package as
1208 a text or HTML file.
1209 A pdf version of this document is available at
1210 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1215 Some of the other tools (simulator and assembler) included with SDCC contain
1216 their own documentation and can be found in the source distribution.
1217 If you want the latest unreleased software, the complete source package
1218 is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1222 \begin_layout Section
1223 Wishes for the future
1226 \begin_layout Standard
1227 There are (and always will be) some things that could be done.
1228 Here are some I can think of:
1233 \begin_layout Standard
1236 char KernelFunction3(char p) at 0x340;
1241 \begin_layout Standard
1245 \begin_inset LatexCommand \index{code banking (limited support)}
1255 If you can think of some more, please see the section
1256 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1260 about filing feature requests
1261 \begin_inset LatexCommand \index{Requesting features}
1266 \begin_inset LatexCommand \index{Feature request}
1275 \begin_layout Chapter
1277 \begin_inset LatexCommand \index{Installation}
1284 \begin_layout Standard
1285 For most users it is sufficient to skip to either section
1286 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1291 \begin_inset LatexCommand \ref{sub:Windows-Install}
1296 More detailed instructions follow below.
1299 \begin_layout Section
1301 \begin_inset LatexCommand \index{Options SDCC configuration}
1308 \begin_layout Standard
1309 The install paths, search paths and other options are defined when running
1311 The defaults can be overridden by:
1315 \labelwidthstring 00.00.0000
1320 \begin_layout Standard
1329 -prefix see table below
1333 \labelwidthstring 00.00.0000
1338 \begin_layout Standard
1347 -exec_prefix see table below
1351 \labelwidthstring 00.00.0000
1356 \begin_layout Standard
1365 -bindir see table below
1369 \labelwidthstring 00.00.0000
1374 \begin_layout Standard
1383 -datadir see table below
1387 \labelwidthstring 00.00.0000
1392 \begin_layout Standard
1401 -datarootdir see table below
1407 \labelwidthstring 00.00.0000
1410 docdir environment variable, see table below
1414 \labelwidthstring 00.00.0000
1417 include_dir_suffix environment variable, see table below
1421 \labelwidthstring 00.00.0000
1424 lib_dir_suffix environment variable, see table below
1428 \labelwidthstring 00.00.0000
1431 sdccconf_h_dir_separator environment variable, either / or
1436 This character will only be used in sdccconf.h; don't forget it's a C-header,
1437 therefore a double-backslash is needed there.
1443 \labelwidthstring 00.00.0000
1448 \begin_layout Standard
1457 -disable-mcs51-port Excludes the Intel mcs51 port
1461 \labelwidthstring 00.00.0000
1466 \begin_layout Standard
1475 -disable-gbz80-port Excludes the Gameboy gbz80 port
1479 \labelwidthstring 00.00.0000
1484 \begin_layout Standard
1493 -disable-z80-port Excludes the z80 port
1497 \labelwidthstring 00.00.0000
1502 \begin_layout Standard
1511 -disable-avr-port Excludes the AVR port
1515 \labelwidthstring 00.00.0000
1520 \begin_layout Standard
1529 -disable-ds390-port Excludes the DS390 port
1533 \labelwidthstring 00.00.0000
1538 \begin_layout Standard
1547 -disable-hc08-port Excludes the HC08 port
1551 \labelwidthstring 00.00.0000
1556 \begin_layout Standard
1565 -disable-pic-port Excludes the PIC14 port
1569 \labelwidthstring 00.00.0000
1574 \begin_layout Standard
1583 -disable-pic16-port Excludes the PIC16 port
1587 \labelwidthstring 00.00.0000
1592 \begin_layout Standard
1601 -disable-xa51-port Excludes the XA51 port
1605 \labelwidthstring 00.00.0000
1610 \begin_layout Standard
1619 -disable-ucsim Disables configuring and building of ucsim
1623 \labelwidthstring 00.00.0000
1628 \begin_layout Standard
1637 -disable-device-lib Disables automatically building device libraries
1641 \labelwidthstring 00.00.0000
1646 \begin_layout Standard
1655 -disable-packihx Disables building packihx
1661 \labelwidthstring 00.00.0000
1666 \begin_layout Standard
1675 -enable-doc Build pdf, html and txt files from the lyx sources
1679 \labelwidthstring 00.00.0000
1684 \begin_layout Standard
1693 -enable-libgc Use the Bohem memory allocator.
1694 Lower runtime footprint.
1698 \labelwidthstring 00.00.0000
1703 \begin_layout Standard
1712 -without-ccache Do not use ccache even if available
1715 \begin_layout Standard
1716 Furthermore the environment variables CC, CFLAGS, ...
1717 the tools and their arguments can be influenced.
1718 Please see `configure -
1722 \begin_layout Standard
1731 -help' and the man/info pages of `configure' for details.
1736 standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1737 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1738 SDCC_LIB_NAME are defined by `configure' too.
1739 At the moment it's not possible to change the default settings (it was
1740 simply never required).
1744 These configure options are compiled into the binaries,
1745 and can only be changed by rerunning 'configure' and recompiling SDCC.
1746 The configure options are written in
1750 to distinguish them from run time environment variables (see section search
1756 \begin_inset Quotes sld
1760 \begin_inset Quotes srd
1763 are used by the SDCC team to build the official Win32 binaries.
1764 The SDCC team uses Mingw32 to build the official Windows binaries, because
1768 \begin_layout Enumerate
1772 \begin_layout Enumerate
1773 a gcc compiler and last but not least
1776 \begin_layout Enumerate
1777 the binaries can be built by cross compiling on SDCC Distributed Compile
1781 \begin_layout Standard
1782 See the examples, how to pass the Win32 settings to 'configure'.
1783 The other Win32 builds using Borland, VC or whatever don't use 'configure',
1784 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1794 \begin_layout Standard
1796 \begin_inset Tabular
1797 <lyxtabular version="3" rows="9" columns="3">
1799 <column alignment="block" valignment="top" leftline="true" width="0in">
1800 <column alignment="block" valignment="top" leftline="true" width="0in">
1801 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1802 <row topline="true" bottomline="true">
1803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1806 \begin_layout Standard
1812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1815 \begin_layout Standard
1821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1824 \begin_layout Standard
1831 <row topline="true">
1832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1835 \begin_layout Standard
1843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1846 \begin_layout Standard
1852 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1855 \begin_layout Standard
1864 <row topline="true">
1865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1868 \begin_layout Standard
1876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1879 \begin_layout Standard
1887 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1890 \begin_layout Standard
1899 <row topline="true">
1900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1903 \begin_layout Standard
1911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1914 \begin_layout Standard
1924 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1927 \begin_layout Standard
1940 <row topline="true">
1941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1944 \begin_layout Standard
1952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1955 \begin_layout Standard
1963 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1966 \begin_layout Standard
1975 <row topline="true">
1976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1979 \begin_layout Standard
1987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1990 \begin_layout Standard
2000 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2003 \begin_layout Standard
2012 <row topline="true">
2013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2016 \begin_layout Standard
2024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2027 \begin_layout Standard
2037 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2040 \begin_layout Standard
2053 <row topline="true">
2054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2057 \begin_layout Standard
2065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2068 \begin_layout Standard
2074 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2077 \begin_layout Standard
2084 <row topline="true" bottomline="true">
2085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2088 \begin_layout Standard
2096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2099 \begin_layout Standard
2105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2108 \begin_layout Standard
2124 \begin_layout Standard
2126 'configure' also computes relative paths.
2127 This is needed for full relocatability of a binary package and to complete
2128 search paths (see section search paths below):
2133 \begin_layout Standard
2135 \begin_inset Tabular
2136 <lyxtabular version="3" rows="4" columns="3">
2138 <column alignment="block" valignment="top" leftline="true" width="0in">
2139 <column alignment="block" valignment="top" leftline="true" width="0in">
2140 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2141 <row topline="true" bottomline="true">
2142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2145 \begin_layout Standard
2151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2154 \begin_layout Standard
2160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2163 \begin_layout Standard
2170 <row topline="true" bottomline="true">
2171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2174 \begin_layout Standard
2182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2185 \begin_layout Standard
2191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2194 \begin_layout Standard
2201 <row bottomline="true">
2202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2205 \begin_layout Standard
2213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2216 \begin_layout Standard
2222 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2225 \begin_layout Standard
2232 <row bottomline="true">
2233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2236 \begin_layout Standard
2244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2247 \begin_layout Standard
2253 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2256 \begin_layout Standard
2272 \begin_layout Standard
2277 \begin_layout LyX-Code
2284 \begin_layout Standard
2294 \begin_inset Quotes srd
2298 \begin_inset Quotes srd
2305 \begin_layout Standard
2315 \begin_inset Quotes srd
2319 \begin_inset Quotes srd
2328 \begin_layout Standard
2341 \begin_layout Standard
2353 \begin_layout Standard
2354 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2358 \begin_layout LyX-Code
2364 \begin_inset Quotes srd
2367 i586-mingw32msvc-gcc
2368 \begin_inset Quotes srd
2372 \begin_inset Quotes srd
2375 i586-mingw32msvc-g++
2376 \begin_inset Quotes srd
2384 \begin_inset Quotes srd
2387 i586-mingw32msvc-ranlib
2388 \begin_inset Quotes srd
2396 \begin_inset Quotes srd
2399 i586-mingw32msvc-strip
2400 \begin_inset Quotes srd
2411 \begin_layout Standard
2421 \begin_inset Quotes srd
2425 \begin_inset Quotes srd
2436 \begin_layout Standard
2446 \begin_inset Quotes srd
2450 \begin_inset Quotes srd
2458 \begin_inset Quotes srd
2464 \begin_inset Quotes srd
2472 \begin_inset Quotes srd
2476 \begin_inset Quotes srd
2484 \begin_inset Quotes srd
2488 \begin_inset Quotes srd
2495 sdccconf_h_dir_separator=
2496 \begin_inset Quotes srd
2508 \begin_inset Quotes srd
2519 \begin_layout Standard
2536 \begin_layout Standard
2545 -host=i586-mingw32msvc
2553 \begin_layout Standard
2562 -build=unknown-unknown-linux-gnu
2565 \begin_layout Standard
2567 \begin_inset Quotes sld
2571 \begin_inset Quotes srd
2574 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2578 \begin_layout LyX-Code
2587 \begin_layout Standard
2597 \begin_inset Quotes srd
2601 \begin_inset Quotes srd
2612 \begin_layout Standard
2622 \begin_inset Quotes srd
2626 \begin_inset Quotes srd
2634 \begin_inset Quotes srd
2640 \begin_inset Quotes srd
2648 \begin_inset Quotes srd
2652 \begin_inset Quotes srd
2660 \begin_inset Quotes srd
2664 \begin_inset Quotes srd
2671 sdccconf_h_dir_separator=
2672 \begin_inset Quotes srd
2684 \begin_inset Quotes srd
2692 \begin_inset Quotes srd
2696 \begin_inset Quotes srd
2704 \begin_inset Quotes srd
2708 \begin_inset Quotes srd
2714 \begin_layout Standard
2715 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2720 \begin_layout Standard
2729 -C' turns on caching, which gives a little bit extra speed.
2730 However if options are changed, it can be necessary to delete the config.cache
2734 \begin_layout Section
2736 \begin_inset LatexCommand \label{sub:Install-paths}
2741 \begin_inset LatexCommand \index{Install paths}
2748 \begin_layout Standard
2749 \begin_inset VSpace medskip
2755 \begin_layout Standard
2757 \begin_inset Tabular
2758 <lyxtabular version="3" rows="5" columns="4">
2760 <column alignment="left" valignment="top" leftline="true" width="0">
2761 <column alignment="left" valignment="top" leftline="true" width="0">
2762 <column alignment="left" valignment="top" leftline="true" width="0">
2763 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2764 <row topline="true" bottomline="true">
2765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2768 \begin_layout Standard
2776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2779 \begin_layout Standard
2787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2790 \begin_layout Standard
2798 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2801 \begin_layout Standard
2810 <row topline="true">
2811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2814 \begin_layout Standard
2820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2823 \begin_layout Standard
2831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2834 \begin_layout Standard
2840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2843 \begin_layout Standard
2854 <row topline="true">
2855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2858 \begin_layout Standard
2864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2867 \begin_layout Standard
2870 $DATADIR/ $INCLUDE_DIR_SUFFIX
2875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2878 \begin_layout Standard
2879 /usr/local/share/sdcc/include
2884 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2887 \begin_layout Standard
2898 <row topline="true">
2899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2902 \begin_layout Standard
2908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2911 \begin_layout Standard
2914 $DATADIR/$LIB_DIR_SUFFIX
2919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2922 \begin_layout Standard
2923 /usr/local/share/sdcc/lib
2928 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2931 \begin_layout Standard
2942 <row topline="true" bottomline="true">
2943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2946 \begin_layout Standard
2952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2955 \begin_layout Standard
2963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2966 \begin_layout Standard
2967 /usr/local/share/sdcc/doc
2972 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2975 \begin_layout Standard
2996 *compiler, preprocessor, assembler, and linker
3002 is auto-appended by the compiler, e.g.
3003 small, large, z80, ds390 etc
3006 \begin_layout Standard
3008 The install paths can still be changed during `make install' with e.g.:
3011 \begin_layout LyX-Code
3012 make install prefix=$(HOME)/local/sdcc
3015 \begin_layout Standard
3016 Of course this doesn't change the search paths compiled into the binaries.
3021 r the install path can be changed by defining DESTDIR
3022 \begin_inset LatexCommand \index{DESTDIR}
3029 \begin_layout LyX-Code
3030 make install DESTDIR=$(HOME)/sdcc.rpm/
3033 \begin_layout Standard
3034 Please note that DESTDIR must have a trailing slash!
3037 \begin_layout Section
3039 \begin_inset LatexCommand \label{sub:Search-Paths}
3044 \begin_inset LatexCommand \index{Search path}
3051 \begin_layout Standard
3052 Some search paths or parts of them are determined by configure variables
3057 , see section above).
3058 Further search paths are determined by environment variables during runtime.
3061 The paths searched when running the compiler are as follows (the first
3067 Binary files (preprocessor, assembler and linker)
3072 \begin_layout Standard
3074 \begin_inset Tabular
3075 <lyxtabular version="3" rows="4" columns="3">
3077 <column alignment="block" valignment="top" leftline="true" width="0in">
3078 <column alignment="block" valignment="top" leftline="true" width="0in">
3079 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3080 <row topline="true" bottomline="true">
3081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3084 \begin_layout Standard
3090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3093 \begin_layout Standard
3099 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3102 \begin_layout Standard
3109 <row topline="true">
3110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3113 \begin_layout Standard
3121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3124 \begin_layout Standard
3130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3133 \begin_layout Standard
3142 <row topline="true">
3143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3146 \begin_layout Standard
3147 Path of argv[0] (if available)
3152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3155 \begin_layout Standard
3161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3164 \begin_layout Standard
3171 <row topline="true" bottomline="true">
3172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3175 \begin_layout Standard
3181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3184 \begin_layout Standard
3190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3193 \begin_layout Standard
3209 \begin_layout Standard
3217 \begin_layout Standard
3219 \begin_inset Tabular
3220 <lyxtabular version="3" rows="6" columns="3">
3222 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3223 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3224 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3225 <row topline="true" bottomline="true">
3226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3229 \begin_layout Standard
3235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3238 \begin_layout Standard
3244 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3247 \begin_layout Standard
3254 <row topline="true">
3255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3258 \begin_layout Standard
3263 \begin_layout Standard
3277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3280 \begin_layout Standard
3285 \begin_layout Standard
3299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3302 \begin_layout Standard
3307 \begin_layout Standard
3322 <row topline="true">
3323 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3326 \begin_layout Standard
3332 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3335 \begin_layout Standard
3341 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3344 \begin_layout Standard
3351 <row topline="true">
3352 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3355 \begin_layout Standard
3367 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3370 \begin_layout Standard
3380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3383 \begin_layout Standard
3392 <row topline="true">
3393 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3396 \begin_layout Standard
3412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3415 \begin_layout Standard
3463 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3466 \begin_layout Standard
3477 <row topline="true" bottomline="true">
3478 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3481 \begin_layout Standard
3495 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3498 \begin_layout Standard
3499 /usr/local/share/sdcc/
3506 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3509 \begin_layout Standard
3525 \begin_layout Standard
3531 \begin_layout Standard
3540 -nostdinc disables the last two search paths.
3550 \begin_layout Standard
3551 With the exception of
3552 \begin_inset Quotes sld
3559 \begin_layout Standard
3569 \begin_inset Quotes srd
3576 is auto-appended by the compiler (e.g.
3577 small, large, z80, ds390 etc.).
3583 \begin_layout Standard
3585 \begin_inset Tabular
3586 <lyxtabular version="3" rows="6" columns="3">
3588 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3589 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3590 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3591 <row topline="true" bottomline="true">
3592 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3595 \begin_layout Standard
3601 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3604 \begin_layout Standard
3610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3613 \begin_layout Standard
3620 <row topline="true">
3621 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3624 \begin_layout Standard
3629 \begin_layout Standard
3643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3646 \begin_layout Standard
3651 \begin_layout Standard
3665 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3668 \begin_layout Standard
3673 \begin_layout Standard
3688 <row topline="true">
3689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3692 \begin_layout Standard
3702 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3705 \begin_layout Standard
3715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3718 \begin_layout Standard
3731 <row topline="true">
3732 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3735 \begin_layout Standard
3742 $LIB_DIR_SUFFIX/<model>
3747 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3750 \begin_layout Standard
3762 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3765 \begin_layout Standard
3780 <row topline="true">
3781 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3784 \begin_layout Standard
3795 $LIB_DIR_SUFFIX/<model>
3800 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3803 \begin_layout Standard
3854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3857 \begin_layout Standard
3911 <row topline="true" bottomline="true">
3912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3915 \begin_layout Standard
3920 $LIB_DIR_SUFFIX/<model>
3925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3928 \begin_layout Standard
3929 /usr/local/share/sdcc/
3938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3941 \begin_layout Standard
3957 \begin_layout Standard
3958 \begin_inset Note Note
3961 \begin_layout Standard
3962 Don't delete any of the stray spaces in the table above without checking
3963 the HTML output (last line)!
3971 \begin_layout Standard
3979 \begin_layout Standard
3988 -nostdlib disables the last two search paths.
3991 \begin_layout Section
3993 \begin_inset LatexCommand \index{Building SDCC}
4000 \begin_layout Subsection
4001 Building SDCC on Linux
4002 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
4009 \begin_layout Enumerate
4012 Download the source package
4014 either from the SDCC Subversion repository or from snapshot builds
4016 , it will be named something like sdcc
4027 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
4034 \begin_layout Enumerate
4037 Bring up a command line terminal, such as xterm.
4040 \begin_layout Enumerate
4043 Unpack the file using a command like:
4046 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
4047 \begin_inset Quotes srd
4053 , this will create a sub-directory called sdcc with all of the sources.
4056 \begin_layout Enumerate
4057 Change directory into the main SDCC directory, for example type:
4065 \begin_layout Enumerate
4075 This configures the package for compilation on your system.
4078 \begin_layout Enumerate
4092 All of the source packages will compile, this can take a while.
4095 \begin_layout Enumerate
4109 This copies the binary executables, the include files, the libraries and
4110 the documentation to the install directories.
4111 Proceed with section
4112 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
4119 \begin_layout Subsection
4120 Building SDCC on Mac OS X
4123 \begin_layout Standard
4124 Follow the instruction for Linux.
4128 On Mac OS X 10.2.x it was reported, that the
4129 default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
4130 Fortunately there's also gcc 2.9.x installed, which works fine.
4131 This compiler can be selected by running 'configure' with:
4134 \begin_layout LyX-Code
4135 ./configure CC=gcc2 CXX=g++2
4138 \begin_layout Standard
4139 Universal (ppc and i386) binaries can be produced on Mac OS X 10.4.x with
4141 Run 'configure' with:
4144 \begin_layout LyX-Code
4150 \begin_layout LyX-Code
4151 LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4157 \begin_layout LyX-Code
4158 CXXFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4164 \begin_layout LyX-Code
4165 CFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
4168 \begin_layout Subsection
4169 Cross compiling SDCC on Linux for Windows
4172 \begin_layout Standard
4173 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
4174 See section 'Configure Options'.
4177 \begin_layout Subsection
4178 Building SDCC using Cygwin and Mingw32
4181 \begin_layout Standard
4182 For building and installing a Cygwin executable follow the instructions
4188 \begin_inset Quotes sld
4192 \begin_inset Quotes srd
4195 Win32-binary can be built, which will not need the Cygwin-DLL.
4196 For the necessary 'configure' options see section 'configure options' or
4197 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4202 Cygwin on Windows download setup.exe from
4203 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
4209 \begin_inset Quotes sld
4212 default text file type
4213 \begin_inset Quotes srd
4217 \begin_inset Quotes sld
4221 \begin_inset Quotes srd
4224 and download/install at least the following packages.
4225 Some packages are selected by default, others will be automatically selected
4226 because of dependencies with the manually selected packages.
4227 Never deselect these packages!
4230 \begin_layout Itemize
4234 \begin_layout Itemize
4238 \begin_layout Itemize
4239 gcc ; version 3.x is fine, no need to use the old 2.9x
4242 \begin_layout Itemize
4243 binutils ; selected with gcc
4246 \begin_layout Itemize
4250 \begin_layout Itemize
4251 rxvt ; a nice console, which makes life much easier under windoze (see below)
4254 \begin_layout Itemize
4255 man ; not really needed for building SDCC, but you'll miss it sooner or
4259 \begin_layout Itemize
4260 less ; not really needed for building SDCC, but you'll miss it sooner or
4264 \begin_layout Itemize
4265 svn ; only if you use Subversion access
4268 \begin_layout Standard
4269 If you want to develop something you'll need:
4272 \begin_layout Itemize
4273 python ; for the regression tests
4276 \begin_layout Itemize
4277 gdb ; the gnu debugger, together with the nice GUI
4278 \begin_inset Quotes sld
4282 \begin_inset Quotes srd
4288 \begin_layout Itemize
4289 openssh ; to access the CF or commit changes
4292 \begin_layout Itemize
4293 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4294 use autoconf-stable!
4297 \begin_layout Standard
4298 rxvt is a nice console with history.
4299 Replace in your cygwin.bat the line
4302 \begin_layout LyX-Code
4307 \begin_layout Standard
4319 \begin_layout Standard
4323 \begin_layout LyX-Code
4324 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4327 \begin_layout LyX-Code
4328 -bg black -fg white -geometry 100x65 -e bash -
4332 \begin_layout Standard
4344 \begin_layout Standard
4345 Text selected with the mouse is automatically copied to the clipboard, pasting
4346 works with shift-insert.
4350 The other good tip is to make sure you have no //c/-styl
4351 e paths anywhere, use /cygdrive/c/ instead.
4352 Using // invokes a network lookup which is very slow.
4354 \begin_inset Quotes sld
4358 \begin_inset Quotes srd
4361 is too long, you can change it with e.g.
4364 \begin_layout LyX-Code
4368 \begin_layout Standard
4369 SDCC sources use the unix line ending LF.
4370 Life is much easier, if you store the source tree on a drive which is mounted
4372 And use an editor which can handle LF-only line endings.
4373 Make sure not to commit files with windows line endings.
4374 The tabulator spacing
4375 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4379 used in the project is 8.
4380 Although a tabulator spacing of 8 is a sensible choice for programmers
4381 (it's a power of 2 and allows to display 8/16 bit signed variables without
4382 loosing columns) the plan is to move towards using only spaces in the source.
4385 \begin_layout Subsection
4386 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4389 \begin_layout Standard
4392 Download the source package
4394 either from the SDCC Subversion repository or from the
4395 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4401 , it will be named something like sdcc
4405 -yyyymmdd-rrrr.tar.bz2.
4408 SDCC is distributed with all the projects, workspaces, and files you need
4409 to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4410 The workspace name is 'sdcc.dsw'.
4411 Please note that as it is now, all the executables are created in a folder
4415 Once built you need to copy the executables from sdcc
4419 bin before running SDCC.
4424 WARNING: Visual studio is very picky with line terminations; it expects
4425 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4426 When using the Subversion repository it's easiest to configure the svn
4427 client to convert automatically for you.
4428 If however you are getting a message such as "This makefile was not generated
4429 by Developer Studio etc.
4431 \begin_inset Quotes srd
4434 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4435 need to convert the Unix style line endings to DOS style line endings.
4436 To do so you can use the
4437 \begin_inset Quotes sld
4441 \begin_inset Quotes srd
4444 utility freely available on the internet.
4445 Doug Hawkins reported in the sdcc-user list that this works:
4453 SDCC> unix2dos sdcc.dsw
4459 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4463 In order to build SDCC with MSVC
4464 you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4465 One good place to get them is
4466 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4474 Download the file UnxUtils
4475 \begin_inset LatexCommand \index{UnxUtils}
4480 Now you have to install the utilities and setup MSVC so it can locate the
4482 Here there are two alternatives (choose one!):
4485 \begin_layout Enumerate
4490 a) Extract UnxUtils.zip to your C:
4492 hard disk PRESERVING the original paths, otherwise bison won't work.
4493 (If you are using WinZip make certain that 'Use folder names' is selected)
4498 In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4499 'Show directories for:' select 'Executable files', and in the directories
4500 window add a new path: 'C:
4510 (As a side effect, you get a bunch of Unix utilities that
4511 could be useful, such as diff and patch.)
4514 \begin_layout Enumerate
4519 This one avoids extracting a bunch of files you may not
4520 use, but requires some extra work:
4524 a) Create a directory were to put the
4525 tools needed, or use a directory already present.
4532 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4533 gawk.exe to such directory WITHOUT preserving the original paths.
4534 (If you are using WinZip make certain that 'Use folder names' is not selected)
4539 ) Rename bison.exe to '_bison.exe'.
4543 d) Create a batch file 'bison.bat' in 'C:
4547 ' and add these lines:
4567 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4571 Steps 'c' and 'd' are needed
4572 because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4573 reside in some weird Unix directory, '/usr/local/share/' I think.
4574 So it is necessary to tell bison where those files are located if they
4575 are not in such directory.
4576 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4581 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4582 in 'Show directories for:' select 'Executable files', and in the directories
4583 window add a new path: 'c:
4586 Note that you can use any other path instead of 'c:
4588 util', even the path where the Visual C++ tools are, probably: 'C:
4592 Microsoft Visual Studio
4597 So you don't have to execute step 'e' :)
4600 \begin_layout Standard
4602 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4603 the executables from sdcc
4607 bin, and you can compile using SDCC.
4610 \begin_layout Subsection
4611 Building SDCC Using Borland
4614 \begin_layout Enumerate
4615 From the sdcc directory, run the command "make -f Makefile.bcc".
4616 This should regenerate all the .exe files in the bin directory except for
4620 \begin_layout Enumerate
4621 If you modify any source files and need to rebuild, be aware that the dependenci
4622 es may not be correctly calculated.
4623 The safest option is to delete all .obj files and run the build again.
4624 From a Cygwin BASH prompt, this can easily be done with the command (be
4625 sure you are in the sdcc directory):
4635 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
4637 ) -print -exec rm {}
4646 or on Windows NT/2000/XP from the command prompt with the command:
4653 del /s *.obj *.lib *.rul
4656 from the sdcc directory.
4659 \begin_layout Subsection
4660 Windows Install Using a ZIP Package
4663 \begin_layout Enumerate
4664 Download the binary zip package from
4665 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4669 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4670 This should unpack to a group of sub-directories.
4671 An example directory structure after unpacking the mingw32 package is:
4676 bin for the executables, c:
4684 lib for the include and libraries.
4687 \begin_layout Enumerate
4688 Adjust your environment variable PATH to include the location of the bin
4689 directory or start sdcc using the full path.
4692 \begin_layout Subsection
4693 Windows Install Using the Setup Program
4694 \begin_inset LatexCommand \label{sub:Windows-Install}
4701 \begin_layout Standard
4702 Download the setup program
4704 sdcc-x.y.z-setup.exe
4706 for an official release from
4709 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4713 or a setup program for one of the snapshots
4715 sdcc-yyyymmdd-xxxx-setup.exe
4718 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4723 A windows typical installer will guide you through the installation process.
4726 \begin_layout Subsection
4728 \begin_inset LatexCommand \index{VPATH}
4735 \begin_layout Standard
4736 SDCC supports the VPATH feature provided by configure and make.
4737 It allows to separate the source and build trees.
4741 \begin_layout Standard
4768 \begin_layout Standard
4771 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4772 # extract source to directory sdcc
4775 \begin_layout Standard
4778 mkdir sdcc.build\InsetSpace ~
4787 # put output in sdcc.build
4790 \begin_layout Standard
4796 \begin_layout Standard
4799 ../sdcc/configure\InsetSpace ~
4807 # configure is doing all the magic!
4810 \begin_layout Standard
4816 \begin_layout Standard
4822 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4823 It automagically computes the variables srcdir, top_srcdir and top_buildir
4829 the generated files will be in ~/sdcc.build, while the source files stay
4832 This is not only usefull for building different binaries, e.g.
4833 when cross compiling.
4834 It also gives you a much better overview in the source tree when all the
4835 generated files are not scattered between the source files.
4836 And the best thing is: if you want to change a file you can leave the original
4837 file untouched in the source directory.
4838 Simply copy it to the build directory, edit it, enter `make clean', `rm
4839 Makefile.dep' and `make'.
4844 will do the rest for you!
4847 \begin_layout Section
4848 Building the Documentation
4851 \begin_layout Standard
4856 \begin_layout Standard
4865 -enable-doc to the configure arguments to build the documentation together
4866 with all the other stuff.
4867 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4868 dvips and makeindex) to get the job done.
4869 Another possibility is to change to the doc directory and to type
4873 \begin_inset Quotes srd
4877 \begin_inset Quotes srd
4884 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4887 \begin_inset LatexCommand \url{http://www.lyx.org}
4891 as editor is straightforward.
4892 Prebuilt documentation in html and pdf format is available from
4893 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4900 \begin_layout Section
4901 Reading the Documentation
4902 \begin_inset LatexCommand \index{Documentation}
4909 \begin_layout Standard
4910 Currently reading the document in pdf format is recommended, as for unknown
4911 reason the hyperlinks are working there whereas in the html version they
4916 \begin_layout Standard
4917 If you should know why please drop us a note
4925 You'll find the pdf version
4926 \begin_inset LatexCommand \index{PDF version of this document}
4931 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4939 \begin_inset LatexCommand \index{HTML version of this document}
4944 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4950 This documentation is in some aspects different from a commercial documentation:
4954 \begin_layout Itemize
4955 It tries to document SDCC for several processor architectures in one document
4956 (commercially these probably would be separate documents/products).
4958 \begin_inset LatexCommand \index{Status of documentation}
4962 currently matches SDCC for mcs51 and DS390 best and does give too few informati
4964 Z80, PIC14, PIC16 and HC08.
4967 \begin_layout Itemize
4968 There are many references pointing away from this documentation.
4969 Don't let this distract you.
4971 was a reference like
4972 \begin_inset LatexCommand \url{http://www.opencores.org}
4976 together with a statement
4977 \begin_inset Quotes sld
4980 some processors which are targetted by SDCC can be implemented in a
4997 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
5002 \begin_inset Quotes srd
5006 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
5011 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
5016 \begin_inset Quotes sld
5019 have you ever heard of an open source compiler that compiles a subset of
5021 \begin_inset Quotes srd
5024 we expect you to have a quick look there and come back.
5025 If you read this you are on the right track.
5028 \begin_layout Itemize
5029 Some sections attribute more space to problems, restrictions and warnings
5030 than to the solution.
5033 \begin_layout Itemize
5034 The installation section and the section about the debugger is intimidating.
5037 \begin_layout Itemize
5038 There are still lots of typos and there are more different writing styles
5042 \begin_layout Section
5043 Testing the SDCC Compiler
5044 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
5051 \begin_layout Standard
5052 The first thing you should do after installing your SDCC compiler is to
5061 \begin_layout Standard
5071 \begin_inset LatexCommand \index{version}
5078 at the prompt, and the program should run and output its version like:
5083 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
5087 \begin_layout Standard
5088 If it doesn't run, or gives a message about not finding sdcc program, then
5089 you need to check over your installation.
5090 Make sure that the sdcc bin directory is in your executable search path
5091 defined by the PATH environment setting (
5096 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5103 Install trouble-shooting for suggestions
5106 Make sure that the sdcc program is in the bin folder, if not perhaps something
5107 did not install correctly.
5115 is commonly installed as described in section
5116 \begin_inset Quotes sld
5119 Install and search paths
5120 \begin_inset Quotes srd
5129 Make sure the compiler works on a very simple example.
5130 Type in the following test.c program using your favorite
5155 \begin_layout Standard
5158 Compile this using the following command:
5167 If all goes well, the compiler will generate a test.asm and test.rel file.
5168 Congratulations, you've just compiled your first program with SDCC.
5169 We used the -c option to tell SDCC not to link the generated code, just
5170 to keep things simple for this step.
5178 The next step is to try it with the linker.
5188 If all goes well the compiler will link with the libraries and produce
5189 a test.ihx output file.
5194 (no test.ihx, and the linker generates warnings), then the problem is most
5203 usr/local/share/sdcc/lib directory
5210 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5217 Install trouble-shooting for suggestions).
5225 The final test is to ensure
5233 header files and libraries.
5234 Edit test.c and change it to the following:
5252 strcpy(str1, "testing");
5257 \begin_layout Standard
5260 Compile this by typing
5267 This should generate a test.ihx output file, and it should give no warnings
5268 such as not finding the string.h file.
5269 If it cannot find the string.h file, then the problem is that
5273 cannot find the /usr/local/share/sdcc/include directory
5280 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5287 Install trouble-shooting section for suggestions).
5296 \begin_layout Standard
5308 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5312 to find exactly where SDCC is looking for the include and lib files.
5315 \begin_layout Section
5316 Install Trouble-shooting
5317 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5322 \begin_inset LatexCommand \index{Install trouble-shooting}
5329 \begin_layout Subsection
5330 If SDCC does not build correctly
5333 \begin_layout Standard
5334 A thing to try is starting from scratch by unpacking the .tgz source package
5335 again in an empty directory.
5343 ./configure 2>&1 | tee configure.log
5357 make 2>&1 | tee make.log
5364 If anything goes wrong, you can review the log files to locate the problem.
5365 Or a relevant part of this can be attached to an email that could be helpful
5366 when requesting help from the mailing list.
5369 \begin_layout Subsection
5371 \begin_inset Quotes sld
5375 \begin_inset Quotes srd
5381 \begin_layout Standard
5383 \begin_inset Quotes sld
5387 \begin_inset Quotes srd
5390 command is a script that analyzes your system and performs some configuration
5391 to ensure the source package compiles on your system.
5392 It will take a few minutes to run, and will compile a few tests to determine
5393 what compiler features are installed.
5396 \begin_layout Subsection
5398 \begin_inset Quotes sld
5402 \begin_inset Quotes srd
5408 \begin_layout Standard
5409 This runs the GNU make tool, which automatically compiles all the source
5410 packages into the final installed binary executables.
5413 \begin_layout Subsection
5415 \begin_inset Quotes sld
5419 \begin_inset Quotes erd
5425 \begin_layout Standard
5426 This will install the compiler, other executables libraries and include
5427 files into the appropriate directories.
5429 \begin_inset LatexCommand \ref{sub:Install-paths}
5435 \begin_inset LatexCommand \ref{sub:Search-Paths}
5440 about install and search paths.
5442 On most systems you will need super-user privilege
5446 \begin_layout Section
5450 \begin_layout Standard
5451 SDCC is not just a compiler, but a collection of tools by various developers.
5452 These include linkers, assemblers, simulators and other components.
5453 Here is a summary of some of the components.
5454 Note that the included simulator and assembler have separate documentation
5455 which you can find in the source package in their respective directories.
5456 As SDCC grows to include support for other processors, other packages from
5457 various developers are included and may have their own sets of documentation.
5462 might want to look at the files which are installed in <installdir>.
5463 At the time of this writing, we find the following programs for gcc-builds:
5468 In <installdir>/bin:
5471 \begin_layout Itemize
5472 sdcc - The compiler.
5475 \begin_layout Itemize
5476 sdcpp - The C preprocessor.
5479 \begin_layout Itemize
5480 asx8051 - The assembler for 8051 type processors.
5483 \begin_layout Itemize
5488 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5491 \begin_layout Itemize
5492 aslink -The linker for 8051 type processors.
5495 \begin_layout Itemize
5500 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5503 \begin_layout Itemize
5504 s51 - The ucSim 8051 simulator.
5507 \begin_layout Itemize
5508 sdcdb - The source debugger.
5511 \begin_layout Itemize
5512 packihx - A tool to pack (compress) Intel hex files.
5515 \begin_layout Standard
5516 In <installdir>/share/sdcc/include
5519 \begin_layout Itemize
5523 \begin_layout Standard
5524 In <installdir>/share/sdcc/lib
5527 \begin_layout Itemize
5528 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5532 \begin_layout Standard
5533 In <installdir>/share/sdcc/doc
5536 \begin_layout Itemize
5540 \begin_layout Standard
5541 As development for other processors proceeds, this list will expand to include
5542 executables to support processors like AVR, PIC, etc.
5545 \begin_layout Subsection
5549 \begin_layout Standard
5550 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5551 the assembler and linkage editor.
5554 \begin_layout Subsection
5555 sdcpp - The C-Preprocessor
5558 \begin_layout Standard
5560 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5564 is a modified version of the GNU cpp
5565 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5570 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5575 The C preprocessor is used to pull in #include sources, process #ifdef
5576 statements, #defines and so on.
5579 \begin_layout Subsection
5588 - The Assemblers and Linkage Editors
5591 \begin_layout Standard
5592 This is retargettable assembler & linkage editor, it was developed by Alan
5594 John Hartman created the version for 8051, and I (Sandeep) have made some
5595 enhancements and bug fixes for it to work properly with SDCC.
5598 \begin_layout Subsection
5602 \begin_layout Standard
5604 \begin_inset LatexCommand \index{s51}
5608 is a free open source simulator developed by Daniel Drotos.
5609 The simulator is built as part of the build process.
5610 For more information visit Daniel's web site at:
5611 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5616 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5620 \begin_layout Subsection
5621 sdcdb - Source Level Debugger
5624 \begin_layout Standard
5626 \begin_inset LatexCommand \index{SDCDB (debugger)}
5630 is the companion source level debugger.
5631 More about SDCDB in section
5632 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5637 The current version of the debugger uses Daniel's Simulator S51
5638 \begin_inset LatexCommand \index{s51}
5642 , but can be easily changed to use other simulators.
5645 \begin_layout Chapter
5649 \begin_layout Section
5653 \begin_layout Subsection
5654 Single Source File Projects
5657 \begin_layout Standard
5658 For single source file 8051 projects the process is very simple.
5659 Compile your programs with the following command
5662 "sdcc sourcefile.c".
5666 This will compile, assemble and link your source file.
5667 Output files are as follows:
5670 \begin_layout Itemize
5672 \begin_inset LatexCommand \index{<file>.asm}
5677 \begin_inset LatexCommand \index{Assembler source}
5681 file created by the compiler
5684 \begin_layout Itemize
5686 \begin_inset LatexCommand \index{<file>.lst}
5691 \begin_inset LatexCommand \index{Assembler listing}
5695 file created by the Assembler
5698 \begin_layout Itemize
5700 \begin_inset LatexCommand \index{<file>.rst}
5705 \begin_inset LatexCommand \index{Assembler listing}
5709 file updated with linkedit information, created by linkage editor
5712 \begin_layout Itemize
5714 \begin_inset LatexCommand \index{<file>.sym}
5719 \begin_inset LatexCommand \index{Symbol listing}
5723 for the sourcefile, created by the assembler
5726 \begin_layout Itemize
5728 \begin_inset LatexCommand \index{<file>.rel}
5733 \begin_inset LatexCommand \index{<file>.o}
5738 \begin_inset LatexCommand \index{Object file}
5742 created by the assembler, input to Linkage editor
5745 \begin_layout Itemize
5747 \begin_inset LatexCommand \index{<file>.map}
5752 \begin_inset LatexCommand \index{Memory map}
5756 for the load module, created by the Linker
5759 \begin_layout Itemize
5761 \begin_inset LatexCommand \index{<file>.mem}
5765 - A file with a summary of the memory usage
5768 \begin_layout Itemize
5770 \begin_inset LatexCommand \index{<file>.ihx}
5774 - The load module in Intel hex format
5775 \begin_inset LatexCommand \index{Intel hex format}
5779 (you can select the Motorola S19 format
5780 \begin_inset LatexCommand \index{Motorola S19 format}
5788 \begin_layout Standard
5798 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5803 If you need another format you might want to use
5810 \begin_inset LatexCommand \index{objdump (tool)}
5821 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5826 \begin_inset Note Note
5829 \begin_layout Standard
5836 \begin_inset LatexCommand \vref{sub:Postprocessing-the-Intel}
5841 Both formats are documented in the documentation of srecord
5842 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5849 \begin_layout Itemize
5851 \begin_inset LatexCommand \index{<file>.adb}
5855 - An intermediate file containing debug information needed to create the
5860 \begin_layout Standard
5870 \begin_inset LatexCommand \index{-\/-debug}
5877 \begin_layout Itemize
5879 \begin_inset LatexCommand \index{<file>.cdb}
5883 - An optional file (with -
5887 \begin_layout Standard
5896 -debug) containing debug information.
5897 The format is documented in cdbfileformat.pdf
5900 \begin_layout Itemize
5903 \begin_inset LatexCommand \index{<file> (no extension)}
5907 An optional AOMF or AOMF51
5908 \begin_inset LatexCommand \index{AOMF, AOMF51}
5913 \begin_inset LatexCommand \label{OMF file}
5917 file containing debug information (generated with option -
5921 \begin_layout Standard
5947 ormat is a subformat of the OMF51 format and is commonly used by third party
5949 \begin_inset LatexCommand \index{Debugger}
5953 , simulators, emulators).
5956 \begin_layout Itemize
5958 \begin_inset LatexCommand \index{<file>.dump*}
5962 - Dump file to debug the compiler it self (generated with option -
5966 \begin_layout Standard
5975 -dumpall) (see section
5976 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5982 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5988 \begin_inset Quotes sld
5991 Anatomy of the compiler
5992 \begin_inset Quotes srd
5998 \begin_layout Subsection
5999 Postprocessing the Intel Hex
6000 \begin_inset LatexCommand \index{Intel hex format}
6005 \begin_inset LatexCommand \label{sub:Postprocessing-the-Intel}
6012 \begin_layout Standard
6013 In most cases this won't be needed but the Intel Hex file
6014 \begin_inset LatexCommand \index{<file>.ihx}
6018 which is generated by SDCC might include lines of varying length and the
6019 addresses within the file are not guaranteed to be strictly ascending.
6020 If your toolchain or a bootloader does not like this you can use the tool
6026 \begin_inset LatexCommand \index{packihx (tool)}
6030 which is part of the SDCC distribution:
6037 packihx sourcefile.ihx >sourcefile.hex
6044 The separately available
6049 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6053 package additionally allows to set undefined locations to a predefined
6054 value, to insert checksums
6055 \begin_inset LatexCommand \index{checksum}
6059 of various flavours (crc, add, xor) and to perform other manipulations
6060 (convert, split, crop, offset, ...).
6068 srec_cat\InsetSpace ~
6070 sourcefile.ihx -intel\InsetSpace ~
6072 -o sourcefile.hex -intel
6079 An example for a more complex command line
6083 \begin_layout Standard
6084 the command backfills
6085 \begin_inset LatexCommand \index{backfill unused memory}
6089 unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
6091 If the program counter on an mcs51 runs wild the backfill pattern 0x12
6092 will be interpreted as an
6100 (where an emergency routine could sit).
6113 srec_cat\InsetSpace ~
6114 sourcefile.ihx -intel\InsetSpace ~
6116 -fill 0x12 0x0000 0xfffe\InsetSpace ~
6117 -little-endian-checksum-nega
6118 tive 0xfffe 0x02 0x02\InsetSpace ~
6120 -o sourcefile.hex -intel
6129 The srecord package is available at
6130 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
6137 \begin_layout Subsection
6138 Projects with Multiple Source Files
6141 \begin_layout Standard
6142 SDCC can compile only ONE file at a time.
6143 Let us for example assume that you have a project containing the following
6148 foo1.c (contains some functions)
6150 foo2.c (contains some more functions)
6153 n.c (contains more functions and the function main)
6161 The first two files will need to be compiled separately with the commands:
6193 Then compile the source file containing the
6198 \begin_inset LatexCommand \index{Linker}
6202 the files together with the following command:
6210 foomain.c\InsetSpace ~
6211 foo1.rel\InsetSpace ~
6216 \begin_inset LatexCommand \index{<file>.rel}
6228 can be separately compiled as well:
6239 sdcc foomain.rel foo1.rel foo2.rel
6246 The file containing the
6261 file specified in the command line, since the linkage editor processes
6262 file in the order they are presented to it.
6263 The linker is invoked from SDCC using a script file with extension .lnk
6264 \begin_inset LatexCommand \index{<file>.lnk}
6269 You can view this file to troubleshoot linking problems such as those arising
6270 from missing libraries.
6273 \begin_layout Subsection
6274 Projects with Additional Libraries
6275 \begin_inset LatexCommand \index{Libraries}
6282 \begin_layout Standard
6283 Some reusable routines may be compiled into a library, see the documentation
6284 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6288 \begin_inset LatexCommand \index{<file>.lib}
6295 Libraries created in this manner can be included in the command line.
6296 Make sure you include the -L <library-path> option to tell the linker where
6297 to look for these files if they are not in the current directory.
6298 Here is an example, assuming you have the source file
6310 (if that is not the same as your current project):
6317 sdcc foomain.c foolib.lib -L mylib
6328 must be an absolute path name.
6332 The most efficient way to use libraries is
6333 to keep separate modules in separate source files.
6334 The lib file now should name all the modules.rel
6335 \begin_inset LatexCommand \index{<file>.rel}
6340 For an example see the standard library file
6344 in the directory <installdir>/share/lib/small.
6347 \begin_layout Subsection
6348 Using sdcclib to Create and Manage Libraries
6349 \begin_inset LatexCommand \index{sdcclib}
6356 \begin_layout Standard
6357 Alternatively, instead of having a .rel file for each entry on the library
6358 file as described in the preceding section, sdcclib can be used to embed
6359 all the modules belonging to such library in the library file itself.
6360 This results in a larger library file, but it greatly reduces the number
6361 of disk files accessed by the linker.
6362 Additionally, the packed library file contains an index of all include
6363 modules and symbols that significantly speeds up the linking process.
6364 To display a list of options supported by sdcclib type:
6369 \begin_layout Standard
6374 \begin_inset LatexCommand \index{sdcclib}
6385 To create a new library file, start by compiling all the required modules.
6391 \begin_layout Standard
6398 \begin_layout Standard
6405 \begin_layout Standard
6412 \begin_layout Standard
6419 \begin_layout Standard
6428 \begin_layout Standard
6429 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6431 The next step is to add the .rel files to the library file:
6436 \begin_layout Standard
6440 sdcclib libint.lib _divsint.rel
6443 \begin_inset LatexCommand \index{sdcclib}
6450 \begin_layout Standard
6454 sdcclib libint.lib _divuint.rel
6457 \begin_layout Standard
6461 sdcclib libint.lib _modsint.rel
6464 \begin_layout Standard
6468 sdcclib libint.lib _moduint.rel
6471 \begin_layout Standard
6475 sdcclib libint.lib _mulint.rel
6483 \begin_layout Standard
6492 \begin_layout Standard
6496 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6504 \begin_layout Standard
6505 If the file already exists in the library, it will be replaced.
6506 If a list of .rel files is available, you can tell sdcclib to add those
6508 For example, if the file 'myliblist.txt' contains
6516 \begin_layout Standard
6523 \begin_layout Standard
6530 \begin_layout Standard
6537 \begin_layout Standard
6544 \begin_layout Standard
6556 \begin_layout Standard
6565 \begin_layout Standard
6569 sdcclib -l libint.lib myliblist.txt
6577 \begin_layout Standard
6578 Additionally, you can instruct sdcclib to compiles the files before adding
6579 them to the library.
6580 This is achieved using the environment variables SDCCLIB_CC and/or SDCCLIB_AS.
6589 \begin_layout Standard
6593 set SDCCLIB_CC=sdcc -c
6596 \begin_layout Standard
6600 sdcclib -l libint.lib myliblist.txt
6608 \begin_layout Standard
6609 To see what modules and symbols are included in the library, options -s
6610 and -m are available.
6618 sdcclib -s libint.lib
6621 \begin_inset LatexCommand \index{sdcclib}
6633 \begin_layout Standard
6639 \begin_layout Standard
6645 \begin_layout Standard
6653 \begin_layout Standard
6659 \begin_layout Standard
6665 \begin_layout Standard
6671 \begin_layout Standard
6677 \begin_layout Standard
6685 \begin_layout Standard
6691 \begin_layout Standard
6697 \begin_layout Standard
6705 \begin_layout Standard
6711 \begin_layout Standard
6717 \begin_layout Standard
6723 \begin_layout Standard
6731 \begin_layout Standard
6737 \begin_layout Standard
6748 \begin_layout Standard
6749 If the source files are compiled using -
6753 \begin_layout Standard
6763 \begin_inset LatexCommand \index{-\/-debug}
6767 , the corresponding debug information file .adb will be include in the library
6769 The library files created with sdcclib are plain text files, so they can
6770 be viewed with a text editor.
6771 It is not recomended to modify a library file created with sdcclib using
6772 a text editor, as there are file indexes numbers located accross the file
6773 used by the linker to quickly locate the required module to link.
6774 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6775 it can be safely deleted, since all the information required for linking
6776 is embedded in the library file itself.
6777 Library files created using sdcclib are used as described in the preceding
6779 \begin_inset VSpace bigskip
6785 \begin_layout Section
6786 Command Line Options
6787 \begin_inset LatexCommand \index{Command Line Options}
6792 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6799 \begin_layout Subsection
6800 Processor Selection Options
6801 \begin_inset LatexCommand \index{Options processor selection}
6806 \begin_inset LatexCommand \index{Processor selection options}
6814 \labelwidthstring 00.00.0000
6818 \begin_inset LatexCommand \index{-mmcs51}
6824 Generate code for the Intel MCS51
6825 \begin_inset LatexCommand \index{MCS51}
6829 family of processors.
6830 This is the default processor target.
6834 \labelwidthstring 00.00.0000
6838 \begin_inset LatexCommand \index{-mds390}
6844 Generate code for the Dallas DS80C390
6845 \begin_inset LatexCommand \index{DS80C390}
6853 \labelwidthstring 00.00.0000
6857 \begin_inset LatexCommand \index{-mds400}
6863 Generate code for the Dallas DS80C400
6864 \begin_inset LatexCommand \index{DS80C400}
6872 \labelwidthstring 00.00.0000
6876 \begin_inset LatexCommand \index{-mhc08}
6882 Generate code for the Freescale/Motorola HC08
6883 \begin_inset LatexCommand \index{HC08}
6887 family of processors.
6891 \labelwidthstring 00.00.0000
6895 \begin_inset LatexCommand \index{-mz80}
6901 Generate code for the Zilog Z80
6902 \begin_inset LatexCommand \index{Z80}
6906 family of processors.
6910 \labelwidthstring 00.00.0000
6914 \begin_inset LatexCommand \index{-mgbz80}
6920 Generate code for the GameBoy Z80
6921 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6925 processor (Not actively maintained).
6929 \labelwidthstring 00.00.0000
6933 \begin_inset LatexCommand \index{-mavr}
6939 Generate code for the Atmel AVR
6940 \begin_inset LatexCommand \index{AVR}
6944 processor (Not maintained, not complete).
6945 AVR users should probably have a look at winavr
6946 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6951 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6955 , which is based on AVR-port of the gcc compiler.
6958 \begin_layout Standard
6959 \begin_inset Note Note
6962 \begin_layout Standard
6963 I think it is fair to direct users there for now.
6964 Open source is also about avoiding unnecessary work .
6965 But I didn't find the 'official' link.
6974 \labelwidthstring 00.00.0000
6978 \begin_inset LatexCommand \index{-mpic14}
6984 Generate code for the Microchip PIC 14
6985 \begin_inset LatexCommand \index{PIC14}
6989 -bit processors (p16f84 and variants.
6990 In development, not complete).
6993 \begin_layout Standard
6994 \begin_inset Note Note
6997 \begin_layout Standard
6998 p16f627 p16f628 p16f84 p16f873 p16f877?
7007 \labelwidthstring 00.00.0000
7011 \begin_inset LatexCommand \index{-mpic16}
7017 Generate code for the Microchip PIC 16
7018 \begin_inset LatexCommand \index{PIC16}
7022 -bit processors (p18f452 and variants.
7023 In development, not complete).
7027 \labelwidthstring 00.00.0000
7032 Generate code for the Toshiba TLCS-900H
7033 \begin_inset LatexCommand \index{TLCS-900H}
7037 processor (Not maintained, not complete).
7041 \labelwidthstring 00.00.0000
7045 \begin_inset LatexCommand \index{-mxa51}
7051 Generate code for the Phillips XA51
7052 \begin_inset LatexCommand \index{XA51}
7056 processor (Not maintained, not complete).
7059 \begin_layout Standard
7060 \begin_inset VSpace bigskip
7066 \begin_layout Subsection
7067 Preprocessor Options
7068 \begin_inset LatexCommand \index{Options preprocessor}
7073 \begin_inset LatexCommand \index{Preprocessor options}
7078 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7086 \labelwidthstring 00.00.0000
7090 \begin_inset LatexCommand \index{-I<path>}
7096 The additional location where the preprocessor will look for <..h> or
7097 \begin_inset Quotes eld
7101 \begin_inset Quotes erd
7108 \labelwidthstring 00.00.0000
7112 \begin_inset LatexCommand \index{-D<macro[=value]>}
7118 Command line definition of macros.
7119 Passed to the preprocessor.
7123 \labelwidthstring 00.00.0000
7127 \begin_inset LatexCommand \index{-M}
7133 Tell the preprocessor to output a rule suitable for make describing the
7134 dependencies of each object file.
7135 For each source file, the preprocessor outputs one make-rule whose target
7136 is the object file name for that source file and whose dependencies are
7137 all the files `#include'd in it.
7138 This rule may be a single line or may be continued with `
7140 '-newline if it is long.
7141 The list of rules is printed on standard output instead of the preprocessed
7144 \begin_inset LatexCommand \index{-E}
7152 \labelwidthstring 00.00.0000
7156 \begin_inset LatexCommand \index{-C}
7162 Tell the preprocessor not to discard comments.
7163 Used with the `-E' option.
7167 \labelwidthstring 00.00.0000
7171 \begin_inset LatexCommand \index{-MM}
7182 Like `-M' but the output mentions only the user header files included with
7184 \begin_inset Quotes eld
7188 System header files included with `#include <file>' are omitted.
7192 \labelwidthstring 00.00.0000
7196 \begin_inset LatexCommand \index{-Aquestion(answer)}
7202 Assert the answer answer for question, in case it is tested with a preprocessor
7203 conditional such as `#if #question(answer)'.
7204 `-A-' disables the standard assertions that normally describe the target
7209 \labelwidthstring 00.00.0000
7213 \begin_inset LatexCommand \index{-Umacro}
7219 Undefine macro macro.
7220 `-U' options are evaluated after all `-D' options, but before any `-include'
7221 and `-imacros' options.
7225 \labelwidthstring 00.00.0000
7229 \begin_inset LatexCommand \index{-dM}
7235 Tell the preprocessor to output only a list of the macro definitions that
7236 are in effect at the end of preprocessing.
7237 Used with the `-E' option.
7241 \labelwidthstring 00.00.0000
7245 \begin_inset LatexCommand \index{-dD}
7251 Tell the preprocessor to pass all macro definitions into the output, in
7252 their proper sequence in the rest of the output.
7256 \labelwidthstring 00.00.0000
7260 \begin_inset LatexCommand \index{-dN}
7271 Like `-dD' except that the macro arguments and contents are omitted.
7272 Only `#define name' is included in the output.
7276 \labelwidthstring 00.00.0000
7279 -pedantic-parse-number
7280 \begin_inset LatexCommand \index{pedantic}
7285 \begin_inset LatexCommand \index{-pedantic-parse-number}
7293 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
7301 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7302 and the macro LO_B(3) gets expanded.
7303 See also #pragma pedantic_parse_number
7304 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
7309 \begin_inset LatexCommand \ref{sec:Pragmas}
7315 Note: this functionality is not in conformance with C99 standard!
7319 \labelwidthstring 00.00.0000
7323 preprocessorOption[,preprocessorOption]
7326 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
7331 Pass the preprocessorOption to the preprocessor
7336 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7341 SDCC uses an adapted version of the preprocessor
7345 of the GNU Compiler Collection
7346 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
7355 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7359 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7364 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7371 \begin_layout Standard
7372 \begin_inset VSpace bigskip
7378 \begin_layout Subsection
7380 \begin_inset LatexCommand \index{Options linker}
7385 \begin_inset LatexCommand \index{Linker options}
7393 \labelwidthstring 00.00.0000
7403 \begin_layout Standard
7415 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7420 \begin_inset LatexCommand \index{-L -\/-lib-path}
7427 <absolute path to additional libraries> This option is passed to the linkage
7428 editor's additional libraries
7429 \begin_inset LatexCommand \index{Libraries}
7434 The path name must be absolute.
7435 Additional library files may be specified in the command line.
7436 See section Compiling programs for more details.
7440 \labelwidthstring 00.00.0000
7447 \begin_layout Standard
7459 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7464 <Value> The start location of the external ram
7465 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7469 , default value is 0.
7470 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7474 \begin_layout Standard
7483 -xram-loc 0x8000 or -
7487 \begin_layout Standard
7500 \labelwidthstring 00.00.0000
7507 \begin_layout Standard
7519 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7524 <Value> The start location of the code
7525 \begin_inset LatexCommand \index{code}
7529 segment, default value 0.
7530 Note when this option is used the interrupt vector table
7531 \begin_inset LatexCommand \index{interrupt vector table}
7535 is also relocated to the given address.
7536 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7540 \begin_layout Standard
7549 -code-loc 0x8000 or -
7553 \begin_layout Standard
7566 \labelwidthstring 00.00.0000
7573 \begin_layout Standard
7585 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7590 <Value> By default the stack
7591 \begin_inset LatexCommand \index{stack}
7595 is placed after the data segment.
7596 Using this option the stack can be placed anywhere in the internal memory
7598 The value entered can be in Hexadecimal or Decimal format, e.g.
7603 \begin_layout Standard
7612 -stack-loc 0x20 or -
7616 \begin_layout Standard
7626 Since the sp register is incremented before a push or call, the initial
7627 sp will be set to one byte prior the provided value.
7628 The provided value should not overlap any other memory areas such as used
7629 register banks or the data segment and with enough space for the current
7637 \begin_layout Standard
7650 \begin_inset LatexCommand \index{-\/-pack-iram}
7654 option (which is now a default setting) will override this setting, so
7655 you should also specify the
7661 \begin_layout Standard
7674 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7678 option if you need to manually place the stack.
7682 \labelwidthstring 00.00.0000
7689 \begin_layout Standard
7701 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7706 <Value> By default the external stack
7707 \begin_inset LatexCommand \index{xstack}
7711 is placed after the pdata
7712 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7717 Using this option the xstack can be placed anywhere in the external memory
7719 The value entered can be in Hexadecimal or Decimal format, e.g.
7724 \begin_layout Standard
7733 -xstack-loc 0x8000 or -
7737 \begin_layout Standard
7747 The provided value should not overlap any other memory areas such as the
7748 pdata or xdata segment and with enough space for the current application.
7752 \labelwidthstring 00.00.0000
7759 \begin_layout Standard
7771 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7776 <Value> The start location of the internal ram data
7777 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7782 The value entered can be in Hexadecimal or Decimal format, eg.
7787 \begin_layout Standard
7800 \begin_layout Standard
7810 (By default, the start location of the internal ram data segment is set
7811 as low as possible in memory, taking into account the used register banks
7812 and the bit segment at address 0x20.
7813 For example if register banks 0 and 1 are used without bit variables, the
7814 data segment will be set, if -
7818 \begin_layout Standard
7827 -data-loc is not used, to location 0x10.)
7831 \labelwidthstring 00.00.0000
7838 \begin_layout Standard
7850 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7855 <Value> The start location of the indirectly addressable internal ram
7856 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7860 of the 8051, default value is 0x80.
7861 The value entered can be in Hexadecimal or Decimal format, eg.
7866 \begin_layout Standard
7875 -idata-loc 0x88 or -
7879 \begin_layout Standard
7892 \labelwidthstring 00.00.0000
7899 \begin_layout Standard
7911 <Value> The start location of the bit
7912 \begin_inset LatexCommand \index{bit}
7916 addressable internal ram of the 8051.
7922 Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7927 \labelwidthstring 00.00.0000
7934 \begin_layout Standard
7944 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7953 The linker output (final object code) is in Intel Hex format.
7954 \begin_inset LatexCommand \index{Intel hex format}
7958 This is the default option.
7959 The format itself is documented in the documentation of srecord
7960 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7968 \labelwidthstring 00.00.0000
7975 \begin_layout Standard
7985 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7994 The linker output (final object code) is in Motorola S19 format
7995 \begin_inset LatexCommand \index{Motorola S19 format}
8000 The format itself is documented in the documentation of srecord.
8004 \labelwidthstring 00.00.0000
8011 \begin_layout Standard
8021 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
8026 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
8035 The linker output (final object code) is in ELF format
8036 \begin_inset LatexCommand \index{ELF format}
8041 (Currently only supported for the HC08
8042 \begin_inset LatexCommand \index{HC08}
8050 \labelwidthstring 00.00.0000
8054 linkOption[,linkOption]
8057 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
8062 \begin_inset LatexCommand \label{lyx:-Wl option}
8067 Pass the linkOption to the linker.
8068 If a bootloader is used an option like
8069 \begin_inset Quotes sld
8074 \begin_inset Quotes srd
8077 would be typical to set the start of the code segment.
8078 Either use the double quotes around this option or use no space (e.g.
8080 See also #pragma constseg and #pragma codeseg in section
8081 \begin_inset LatexCommand \ref{sec:Pragmas}
8086 File sdcc/as/doc/asxhtm.html has more on linker options.
8089 \begin_layout Standard
8090 \begin_inset VSpace bigskip
8096 \begin_layout Subsection
8098 \begin_inset LatexCommand \index{Options MCS51}
8103 \begin_inset LatexCommand \index{MCS51 options}
8111 \labelwidthstring 00.00.0000
8118 \begin_layout Standard
8128 \begin_inset LatexCommand \index{-\/-model-small}
8139 Generate code for Small Model programs, see section Memory Models for more
8141 This is the default model.
8145 \labelwidthstring 00.00.0000
8152 \begin_layout Standard
8162 \begin_inset LatexCommand \index{-\/-model-medium}
8168 Generate code for Medium model programs, see section Memory Models for
8170 If this option is used all source files in the project have to be compiled
8172 It must also be used when invoking the linker.
8176 \labelwidthstring 00.00.0000
8183 \begin_layout Standard
8193 \begin_inset LatexCommand \index{-\/-model-large}
8199 Generate code for Large model programs, see section Memory Models for more
8201 If this option is used all source files in the project have to be compiled
8203 It must also be used when invoking the linker.
8207 \labelwidthstring 00.00.0000
8214 \begin_layout Standard
8224 \begin_inset LatexCommand \index{-\/-xstack}
8230 Uses a pseudo stack in the pdata
8231 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8235 area (usually the first 256 bytes in the external ram) for allocating variables
8236 and passing parameters.
8238 \begin_inset LatexCommand \ref{sub:External-Stack}
8243 External Stack for more details.
8247 \labelwidthstring 00.00.0000
8254 \begin_layout Standard
8267 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
8271 Causes the linker to check if the internal ram usage is within limits of
8276 \labelwidthstring 00.00.0000
8283 \begin_layout Standard
8296 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
8300 Causes the linker to check if the external ram usage is within limits of
8305 \labelwidthstring 00.00.0000
8312 \begin_layout Standard
8325 \begin_inset LatexCommand \index{-\/-code-size <Value>}
8329 Causes the linker to check if the code memory usage is within limits of
8334 \labelwidthstring 00.00.0000
8341 \begin_layout Standard
8354 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8358 Causes the linker to check if there is at minimum <Value> bytes for stack.
8362 \labelwidthstring 00.00.0000
8369 \begin_layout Standard
8382 \begin_inset LatexCommand \index{-\/-pack-iram}
8386 Causes the linker to use unused register banks for data variables and pack
8387 data, idata and stack together.
8388 This is the default now.
8392 \labelwidthstring 00.00.0000
8399 \begin_layout Standard
8412 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8416 Causes the linker to use old style for allocating memory areas.
8420 \labelwidthstring 00.00.0000
8427 \begin_layout Standard
8440 \begin_inset LatexCommand \index{-\/-acall-ajmp}
8444 Replaces the three byte instructions lcall/ljmp with the two byte instructions
8446 Only use this option if your code is in the same 2k block of memory.
8447 You may need to use this option for some 8051 derivatives which lack the
8448 lcall/ljmp instructions..
8451 \begin_layout Standard
8452 \begin_inset VSpace bigskip
8458 \begin_layout Subsection
8459 DS390 / DS400 Options
8460 \begin_inset LatexCommand \index{Options DS390}
8465 \begin_inset LatexCommand \index{DS390}
8473 \labelwidthstring 00.00.0000
8480 \begin_layout Standard
8492 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8502 Generate 24-bit flat mode code.
8503 This is the one and only that the ds390 code generator supports right now
8504 and is default when using
8509 See section Memory Models for more details.
8513 \labelwidthstring 00.00.0000
8520 \begin_layout Standard
8530 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8536 disable interrupts during ESP:SP updates.
8540 \labelwidthstring 00.00.0000
8547 \begin_layout Standard
8559 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8563 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8564 This is the one and only that the ds390 code generator supports right now
8565 and is default when using
8570 In this mode, the stack is located in the lower 1K of the internal RAM,
8571 which is mapped to 0x400000.
8572 Note that the support is incomplete, since it still uses a single byte
8573 as the stack pointer.
8574 This means that only the lower 256 bytes of the potential 1K stack space
8575 will actually be used.
8576 However, this does allow you to reclaim the precious 256 bytes of low RAM
8577 for use for the DATA and IDATA segments.
8578 The compiler will not generate any code to put the processor into 10 bit
8580 It is important to ensure that the processor is in this mode before calling
8581 any re-entrant functions compiled with this option.
8582 In principle, this should work with the
8588 \begin_layout Standard
8598 \begin_inset LatexCommand \index{-\/-stack-auto}
8604 option, but that has not been tested.
8605 It is incompatible with the
8611 \begin_layout Standard
8621 \begin_inset LatexCommand \index{-\/-xstack}
8628 It also only makes sense if the processor is in 24 bit contiguous addressing
8635 \begin_layout Standard
8644 -model-flat24 option
8649 \begin_inset Note Note
8653 \labelwidthstring 00.00.0000
8660 \begin_layout Standard
8669 -stack-8-bit - switches off the 10-bit mode
8678 \labelwidthstring 00.00.0000
8685 \begin_layout Standard
8695 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8701 insert call to function __stack_probe at each function prologue.
8705 \labelwidthstring 00.00.0000
8712 \begin_layout Standard
8722 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8728 <nnnn> LibraryID used in -mTININative.
8733 \labelwidthstring 00.00.0000
8740 \begin_layout Standard
8750 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8756 generate code for DS390 Arithmetic Accelerator.
8760 \begin_layout Standard
8761 \begin_inset VSpace bigskip
8767 \begin_layout Subsection
8769 \begin_inset LatexCommand \index{Options Z80}
8774 \begin_inset LatexCommand \index{Z80}
8782 \labelwidthstring 00.00.0000
8789 \begin_layout Standard
8801 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8811 Force a called function to always save BC.
8815 \labelwidthstring 00.00.0000
8822 \begin_layout Standard
8834 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8838 When linking, skip the standard crt0.o object file.
8839 You must provide your own crt0.o for your system when linking.
8843 \labelwidthstring 00.00.0000
8850 \begin_layout Standard
8862 \begin_inset LatexCommand \index{Z80!Options!-\/-portmode=<Value>}
8866 Determinate PORT I/O mode (<Value> is z80 or z180).
8870 \labelwidthstring 00.00.0000
8877 \begin_layout Standard
8889 \begin_inset LatexCommand \index{Z80!Options!-\/-asm=<Value>}
8893 Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
8897 \labelwidthstring 00.00.0000
8904 \begin_layout Standard
8917 \begin_inset LatexCommand \index{Z80!Options!-\/-codeseg <Value>}
8921 Use <Value> for the code segment name.
8925 \labelwidthstring 00.00.0000
8932 \begin_layout Standard
8945 \begin_inset LatexCommand \index{Z80!Options!-\/-constseg <Value>}
8949 Use <Value> for the const segment name.
8953 \labelwidthstring 00.00.0000
8954 \begin_inset VSpace bigskip
8960 \begin_layout Subsection
8962 \begin_inset LatexCommand \index{Options GBZ80}
8967 \begin_inset LatexCommand \index{GBZ80}
8975 \labelwidthstring 00.00.0000
8982 \begin_layout Standard
8994 \begin_inset LatexCommand \index{GBZ80!Options!-\/-callee-saves-bc}
9004 Force a called function to always save BC.
9008 \labelwidthstring 00.00.0000
9015 \begin_layout Standard
9027 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
9031 When linking, skip the standard crt0.o object file.
9032 You must provide your own crt0.o for your system when linking.
9036 \labelwidthstring 00.00.0000
9043 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
9047 Use code bank <Num>.
9051 \labelwidthstring 00.00.0000
9058 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
9062 Use data bank <Num>.
9066 \labelwidthstring 00.00.0000
9073 \begin_layout Standard
9086 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
9090 Use <Value> for the code segment name.
9094 \labelwidthstring 00.00.0000
9101 \begin_layout Standard
9114 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
9118 Use <Value> for the const segment name.
9121 \begin_layout Standard
9122 \begin_inset VSpace bigskip
9128 \begin_layout Subsection
9129 Optimization Options
9130 \begin_inset LatexCommand \index{Options optimization}
9135 \begin_inset LatexCommand \index{Optimization options}
9143 \labelwidthstring 00.00.0000
9150 \begin_layout Standard
9160 \begin_inset LatexCommand \index{-\/-nogcse}
9166 Will not do global subexpression elimination, this option may be used when
9167 the compiler creates undesirably large stack/data spaces to store compiler
9177 \begin_inset LatexCommand \index{sloc (spill location)}
9182 A warning message will be generated when this happens and the compiler
9183 will indicate the number of extra bytes it allocated.
9184 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9186 \begin_inset LatexCommand \index{\#pragma nogcse}
9190 can be used to turn off global subexpression elimination
9191 \begin_inset LatexCommand \index{Subexpression elimination}
9195 for a given function only.
9199 \labelwidthstring 00.00.0000
9206 \begin_layout Standard
9216 \begin_inset LatexCommand \index{-\/-noinvariant}
9222 Will not do loop invariant optimizations, this may be turned off for reasons
9223 explained for the previous option.
9224 For more details of loop optimizations performed see Loop Invariants in
9226 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
9231 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9233 \begin_inset LatexCommand \index{\#pragma noinvariant}
9237 can be used to turn off invariant optimizations for a given function only.
9241 \labelwidthstring 00.00.0000
9248 \begin_layout Standard
9258 \begin_inset LatexCommand \index{-\/-noinduction}
9264 Will not do loop induction optimizations, see section strength reduction
9266 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9268 \begin_inset LatexCommand \index{\#pragma noinduction}
9272 can be used to turn off induction optimizations for a given function only.
9276 \labelwidthstring 00.00.0000
9283 \begin_layout Standard
9293 \begin_inset LatexCommand \index{-\/-nojtbound}
9304 Will not generate boundary condition check when switch statements
9305 \begin_inset LatexCommand \index{switch statement}
9309 are implemented using jump-tables.
9311 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
9316 Switch Statements for more details.
9317 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9319 \begin_inset LatexCommand \index{\#pragma nojtbound}
9323 can be used to turn off boundary checking for jump tables for a given function
9328 \labelwidthstring 00.00.0000
9335 \begin_layout Standard
9345 \begin_inset LatexCommand \index{-\/-noloopreverse}
9354 Will not do loop reversal
9355 \begin_inset LatexCommand \index{Loop reversing}
9363 \labelwidthstring 00.00.0000
9368 \begin_layout Standard
9382 \begin_inset LatexCommand \index{-\/-nolabelopt }
9386 Will not optimize labels (makes the dumpfiles more readable).
9390 \labelwidthstring 00.00.0000
9397 \begin_layout Standard
9407 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9413 Will not memcpy initialized data from code space into xdata space.
9414 This saves a few bytes in code space if you don't have initialized data
9415 \begin_inset LatexCommand \index{Variable initialization}
9423 \labelwidthstring 00.00.0000
9430 \begin_layout Standard
9440 \begin_inset LatexCommand \index{-\/-nooverlay}
9446 The compiler will not overlay parameters and local variables of any function,
9447 see section Parameters and local variables for more details.
9451 \labelwidthstring 00.00.0000
9458 \begin_layout Standard
9468 \begin_inset LatexCommand \index{-\/-no-peep}
9474 Disable peep-hole optimization with built-in rules.
9478 \labelwidthstring 00.00.0000
9485 \begin_layout Standard
9497 \begin_inset LatexCommand \index{-\/-peep-file}
9502 <filename> This option can be used to use additional rules to be used by
9503 the peep hole optimizer.
9505 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9510 Peep Hole optimizations for details on how to write these rules.
9514 \labelwidthstring 00.00.0000
9521 \begin_layout Standard
9531 \begin_inset LatexCommand \index{-\/-peep-asm}
9537 Pass the inline assembler code through the peep hole optimizer.
9538 This can cause unexpected changes to inline assembler code, please go through
9539 the peephole optimizer
9540 \begin_inset LatexCommand \index{Peephole optimizer}
9544 rules defined in the source file tree '<target>/peeph.def' before using
9549 \labelwidthstring 00.00.0000
9556 \begin_layout Standard
9566 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9572 The compiler will optimize code generation towards fast code, possibly
9573 at the expense of code size.
9577 \labelwidthstring 00.00.0000
9584 \begin_layout Standard
9594 \begin_inset LatexCommand \index{-\/-opt-code-size}
9600 The compiler will optimize code generation towards compact code, possibly
9601 at the expense of code speed.
9604 \begin_layout Standard
9605 \begin_inset VSpace bigskip
9611 \begin_layout Subsection
9613 \begin_inset LatexCommand \index{Options other}
9621 \labelwidthstring 00.00.0000
9629 \begin_layout Standard
9639 \begin_inset LatexCommand \index{-\/-compile-only}
9644 \begin_inset LatexCommand \index{-c -\/-compile-only}
9650 will compile and assemble the source, but will not call the linkage editor.
9654 \labelwidthstring 00.00.0000
9663 \begin_layout Standard
9675 \begin_inset LatexCommand \index{-\/-c1mode}
9681 reads the preprocessed source from standard input and compiles it.
9682 The file name for the assembler output must be specified using the -o option.
9686 \labelwidthstring 00.00.0000
9690 \begin_inset LatexCommand \index{-E}
9696 Run only the C preprocessor.
9697 Preprocess all the C source files specified and output the results to standard
9702 \labelwidthstring 00.00.0000
9707 \begin_inset LatexCommand \index{-o <path/file>}
9713 The output path where everything will be placed or the file name used for
9714 all generated output files.
9715 If the parameter is a path, it must have a trailing slash (or backslash
9716 for the Windows binaries) to be recognized as a path.
9721 Note for Windows users: if the path contains spaces, it should be surrounded
9723 The trailing backslash should be doubled in order to prevent escaping the
9724 final quote, for example:
9727 \begin_inset Quotes sld
9741 \begin_inset Quotes srd
9746 or put after the final quote, for example:
9749 \begin_inset Quotes sld
9759 \begin_inset Quotes srd
9767 The path using slashes for directory delimiters can be used too, for example:
9771 \begin_inset Quotes sld
9774 F:/Projects/test3/output 1/
9775 \begin_inset Quotes srd
9784 \labelwidthstring 00.00.0000
9791 \begin_layout Standard
9801 \begin_inset LatexCommand \index{-\/-stack-auto}
9812 All functions in the source file will be compiled as
9817 \begin_inset LatexCommand \index{reentrant}
9822 the parameters and local variables will be allocated on the stack
9823 \begin_inset LatexCommand \index{stack}
9829 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9833 Parameters and Local Variables for more details.
9834 If this option is used all source files in the project should be compiled
9836 It automatically implies -
9842 \begin_layout Standard
9853 -int-long-reent and -
9859 \begin_layout Standard
9875 \labelwidthstring 00.00.0000
9882 \begin_layout Standard
9892 \begin_inset LatexCommand \index{-\/-callee-saves}
9897 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9901 function1[,function2][,function3]....
9904 The compiler by default uses a caller saves convention for register saving
9905 across function calls, however this can cause unnecessary register pushing
9906 and popping when calling small functions from larger functions.
9907 This option can be used to switch the register saving convention for the
9908 function names specified.
9909 The compiler will not save registers when calling these functions, no extra
9910 code will be generated at the entry and exit (function prologue
9913 \begin_inset LatexCommand \index{function prologue}
9922 \begin_inset LatexCommand \index{function epilogue}
9928 ) for these functions to save and restore the registers used by these functions,
9929 this can SUBSTANTIALLY reduce code and improve run time performance of
9931 In the future the compiler (with inter procedural analysis) will be able
9932 to determine the appropriate scheme to use for each function call.
9933 DO NOT use this option for built-in functions such as _mulint..., if this
9934 option is used for a library function the appropriate library function
9935 needs to be recompiled with the same option.
9936 If the project consists of multiple source files then all the source file
9937 should be compiled with the same -
9941 \begin_layout Standard
9950 -callee-saves option string.
9951 Also see #pragma\InsetSpace ~
9953 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9958 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9966 \labelwidthstring 00.00.0000
9973 \begin_layout Standard
9983 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9997 \begin_layout Standard
10006 -callee-saves will be applied to all functions by default.
10010 \labelwidthstring 00.00.0000
10017 \begin_layout Standard
10027 \begin_inset LatexCommand \index{-\/-debug}
10036 When this option is used the compiler will generate debug information.
10037 The debug information collected in a file with .cdb extension can be used
10039 For more information see documentation for SDCDB.
10040 Another file with no extension contains debug information in AOMF or AOMF51
10041 \begin_inset LatexCommand \index{AOMF, AOMF51}
10045 format which is commonly used by third party tools.
10049 \labelwidthstring 00.00.0000
10053 \begin_inset LatexCommand \index{-S}
10064 Stop after the stage of compilation proper; do not assemble.
10065 The output is an assembler code file for the input file specified.
10069 \labelwidthstring 00.00.0000
10076 \begin_layout Standard
10086 \begin_inset LatexCommand \index{-\/-int-long-reent}
10092 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
10093 Note by default these libraries are compiled as non-reentrant.
10094 See section Installation for more details.
10098 \labelwidthstring 00.00.0000
10105 \begin_layout Standard
10115 \begin_inset LatexCommand \index{-\/-cyclomatic}
10124 This option will cause the compiler to generate an information message for
10125 each function in the source file.
10126 The message contains some
10130 information about the function.
10131 The number of edges and nodes the compiler detected in the control flow
10132 graph of the function, and most importantly the
10134 cyclomatic complexity
10135 \begin_inset LatexCommand \index{Cyclomatic complexity}
10141 see section on Cyclomatic Complexity for more details.
10145 \labelwidthstring 00.00.0000
10152 \begin_layout Standard
10162 \begin_inset LatexCommand \index{-\/-float-reent}
10168 Floating point library is compiled as reentrant
10169 \begin_inset LatexCommand \index{reentrant}
10174 See section Installation for more details.
10178 \labelwidthstring 00.00.0000
10185 \begin_layout Standard
10195 \begin_inset LatexCommand \index{-\/-funsigned-char}
10201 The default signedness for every type is
10206 In some embedded environments the default signedness of
10215 To set the signess for characters to unsigned, use the option -
10221 \begin_layout Standard
10233 If this option is set and no signedness keyword (unsigned/signed) is given,
10234 a char will be signed.
10235 All other types are unaffected.
10239 \labelwidthstring 00.00.0000
10246 \begin_layout Standard
10256 \begin_inset LatexCommand \index{-\/-main-return}
10262 This option can be used if the code generated is called by a monitor program
10263 or if the main routine includes an endless loop.
10264 This option results in slightly smaller code and saves two bytes of stack
10266 The return from the 'main'
10267 \begin_inset LatexCommand \index{main return}
10271 function will return to the function calling main.
10272 The default setting is to lock up i.e.
10281 \labelwidthstring 00.00.0000
10288 \begin_layout Standard
10298 \begin_inset LatexCommand \index{-\/-nostdinc}
10304 This will prevent the compiler from passing on the default include path
10305 to the preprocessor.
10309 \labelwidthstring 00.00.0000
10316 \begin_layout Standard
10326 \begin_inset LatexCommand \index{-\/-nostdlib}
10332 This will prevent the compiler from passing on the default library
10333 \begin_inset LatexCommand \index{Libraries}
10337 path to the linker.
10341 \labelwidthstring 00.00.0000
10348 \begin_layout Standard
10358 \begin_inset LatexCommand \index{-\/-verbose}
10364 Shows the various actions the compiler is performing.
10368 \labelwidthstring 00.00.0000
10372 \begin_inset LatexCommand \index{-V}
10378 Shows the actual commands the compiler is executing.
10382 \labelwidthstring 00.00.0000
10389 \begin_layout Standard
10399 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
10405 Hides your ugly and inefficient c-code from the asm file, so you can always
10406 blame the compiler :)
10410 \labelwidthstring 00.00.0000
10417 \begin_layout Standard
10427 \begin_inset LatexCommand \index{-\/-no-gen-comments}
10433 Include code generator and peep-hole comments in the generated asm files.
10437 \labelwidthstring 00.00.0000
10444 \begin_layout Standard
10454 \begin_inset LatexCommand \index{-\/-no-peep-comments}
10460 Don't include peep-hole comments in the generated asm files even if -
10466 \begin_layout Standard
10477 -fverbose-asm option is specified.
10481 \labelwidthstring 00.00.0000
10488 \begin_layout Standard
10498 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10504 Include i-codes in the asm file.
10505 Sounds like noise but is most helpful for debugging the compiler itself.
10509 \labelwidthstring 00.00.0000
10516 \begin_layout Standard
10526 \begin_inset LatexCommand \index{pedantic}
10531 \begin_inset LatexCommand \index{-\/-less-pedantic}
10538 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10542 Disable some of the more pedantic warnings
10543 \begin_inset LatexCommand \index{Warnings}
10548 For more details, see the less_pedantic pragma
10549 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10557 \labelwidthstring 00.00.0000
10564 \begin_layout Standard
10573 -disable-warning\InsetSpace ~
10575 \begin_inset LatexCommand \index{-\/-disable-warning}
10581 Disable specific warning with number <nnnn>.
10585 \labelwidthstring 00.00.0000
10592 \begin_layout Standard
10602 \begin_inset LatexCommand \index{-\/-Werror}
10608 Treat all warnings as errors.
10612 \labelwidthstring 00.00.0000
10619 \begin_layout Standard
10629 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10635 Display the directories in the compiler's search path
10639 \labelwidthstring 00.00.0000
10646 \begin_layout Standard
10656 \begin_inset LatexCommand \index{-\/-vc}
10662 Display errors and warnings using MSVC style, so you can use SDCC with
10663 the visual studio IDE
10664 \begin_inset LatexCommand \index{IDE}
10669 With SDCC both offering a GCC-like (the default) and a MSVC-like
10670 \begin_inset LatexCommand \index{MSVC output style}
10674 output style, integration into most programming editors should be straightforwa
10679 \labelwidthstring 00.00.0000
10686 \begin_layout Standard
10696 \begin_inset LatexCommand \index{-\/-use-stdout}
10702 Send errors and warnings to stdout instead of stderr.
10706 \labelwidthstring 00.00.0000
10710 asmOption[,asmOption]
10713 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10718 Pass the asmOption to the assembler
10719 \begin_inset LatexCommand \index{Options assembler}
10724 \begin_inset LatexCommand \index{Assembler options}
10729 See file sdcc/as/doc/asxhtm.html for assembler options.cd
10733 \labelwidthstring 00.00.0000
10740 \begin_layout Standard
10750 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10756 Generally follow the C89 standard, but allow SDCC features that conflict
10757 with the standard (default).
10761 \labelwidthstring 00.00.0000
10768 \begin_layout Standard
10778 \begin_inset LatexCommand \index{-\/-std-c89}
10784 Follow the C89 standard and disable SDCC features that conflict with the
10789 \labelwidthstring 00.00.0000
10796 \begin_layout Standard
10806 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10812 Generally follow the C99 standard, but allow SDCC features that conflict
10813 with the standard (incomplete support).
10817 \labelwidthstring 00.00.0000
10824 \begin_layout Standard
10834 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10840 Follow the C99 standard and disable SDCC features that conflict with the
10841 standard (incomplete support).
10845 \labelwidthstring 00.00.0000
10852 \begin_layout Standard
10864 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10869 \begin_inset LatexCommand \label{lyx:-codeseg}
10874 <Name> The name to be used for the code
10875 \begin_inset LatexCommand \index{code}
10879 segment, default CSEG.
10880 This is useful if you need to tell the compiler to put the code in a special
10881 segment so you can later on tell the linker to put this segment in a special
10883 Can be used for instance when using bank switching to put the code in a
10888 \labelwidthstring 00.00.0000
10895 \begin_layout Standard
10907 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10912 <Name> The name to be used for the const
10913 \begin_inset LatexCommand \index{const}
10917 segment, default CONST.
10918 This is useful if you need to tell the compiler to put the const data in
10919 a special segment so you can later on tell the linker to put this segment
10920 in a special place in memory.
10921 Can be used for instance when using bank switching to put the const data
10926 \labelwidthstring 00.00.0000
10933 \begin_layout Standard
10942 -fdollars-in-identifiers
10943 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10949 Permit '$' as an identifier character.
10953 \labelwidthstring 00.00.0000
10960 \begin_layout Standard
10972 \begin_inset LatexCommand \index{-\/-more-pedantic}
10977 \begin_inset LatexCommand \index{pedantic}
10987 a SDCC compiler option but if you want
10991 warnings you can use a separate tool dedicated to syntax checking like
10993 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10998 \begin_inset LatexCommand \index{lint (syntax checking tool)}
11003 \begin_inset LatexCommand \url{http://www.splint.org}
11008 To make your source files parseable by splint you will have to include
11014 \begin_inset LatexCommand \index{splint (syntax checking tool)}
11018 in your source file and add brackets around extended keywords (like
11021 \begin_inset Quotes sld
11034 \begin_inset Quotes srd
11042 \begin_inset Quotes sld
11045 __interrupt\InsetSpace ~
11047 \begin_inset Quotes srd
11055 Splint has an excellent on line manual at
11056 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
11060 and it's capabilities go beyond pure syntax checking.
11061 You'll need to tell splint the location of SDCC's include files so a typical
11062 command line could look like this:
11066 splint\InsetSpace ~
11068 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
11074 \labelwidthstring 00.00.0000
11081 \begin_layout Standard
11093 \begin_inset LatexCommand \index{-\/-short-is-8bits}
11098 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
11102 Treat short as 8-bit (for backward compatibility with older versions of
11103 compiler - see section
11104 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
11111 \begin_layout Standard
11112 \begin_inset VSpace bigskip
11118 \begin_layout Subsection
11119 Intermediate Dump Options
11120 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
11125 \begin_inset LatexCommand \index{Options intermediate dump}
11130 \begin_inset LatexCommand \index{Intermediate dump options}
11137 \begin_layout Standard
11138 The following options are provided for the purpose of retargetting and debugging
11140 They provide a means to dump the intermediate code (iCode
11141 \begin_inset LatexCommand \index{iCode}
11145 ) generated by the compiler in human readable form at various stages of
11146 the compilation process.
11147 More on iCodes see chapter
11148 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
11153 \begin_inset Quotes srd
11156 The anatomy of the compiler
11157 \begin_inset Quotes srd
11164 \labelwidthstring 00.00.0000
11171 \begin_layout Standard
11181 \begin_inset LatexCommand \index{-\/-dumpraw}
11187 This option will cause the compiler to dump the intermediate code into
11190 <source filename>.dumpraw
11192 just after the intermediate code has been generated for a function, i.e.
11193 before any optimizations are done.
11195 \begin_inset LatexCommand \index{Basic blocks}
11199 at this stage ordered in the depth first number, so they may not be in
11200 sequence of execution.
11204 \labelwidthstring 00.00.0000
11211 \begin_layout Standard
11221 \begin_inset LatexCommand \index{-\/-dumpgcse}
11227 Will create a dump of iCodes, after global subexpression elimination
11228 \begin_inset LatexCommand \index{Global subexpression elimination}
11232 , into a file named
11234 <source filename>.dumpgcse.
11238 \labelwidthstring 00.00.0000
11245 \begin_layout Standard
11255 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
11261 Will create a dump of iCodes, after deadcode elimination
11262 \begin_inset LatexCommand \index{Dead-code elimination}
11266 , into a file named
11268 <source filename>.dumpdeadcode.
11272 \labelwidthstring 00.00.0000
11279 \begin_layout Standard
11289 \begin_inset LatexCommand \index{-\/-dumploop}
11298 Will create a dump of iCodes, after loop optimizations
11299 \begin_inset LatexCommand \index{Loop optimization}
11303 , into a file named
11305 <source filename>.dumploop.
11309 \labelwidthstring 00.00.0000
11316 \begin_layout Standard
11326 \begin_inset LatexCommand \index{-\/-dumprange}
11335 Will create a dump of iCodes, after live range analysis
11336 \begin_inset LatexCommand \index{Live range analysis}
11340 , into a file named
11342 <source filename>.dumprange.
11346 \labelwidthstring 00.00.0000
11353 \begin_layout Standard
11363 \begin_inset LatexCommand \index{-\/-dumlrange}
11369 Will dump the life ranges
11370 \begin_inset LatexCommand \index{Live range analysis}
11378 \labelwidthstring 00.00.0000
11385 \begin_layout Standard
11395 \begin_inset LatexCommand \index{-\/-dumpregassign}
11404 Will create a dump of iCodes, after register assignment
11405 \begin_inset LatexCommand \index{Register assignment}
11409 , into a file named
11411 <source filename>.dumprassgn.
11415 \labelwidthstring 00.00.0000
11422 \begin_layout Standard
11432 \begin_inset LatexCommand \index{-\/-dumplrange}
11438 Will create a dump of the live ranges of iTemp's
11442 \labelwidthstring 00.00.0000
11449 \begin_layout Standard
11459 \begin_inset LatexCommand \index{-\/-dumpall}
11470 Will cause all the above mentioned dumps to be created.
11473 \begin_layout Standard
11474 \begin_inset VSpace bigskip
11480 \begin_layout Subsection
11481 Redirecting output on Windows Shells
11484 \begin_layout Standard
11485 By default SDCC writes its error messages to
11486 \begin_inset Quotes sld
11490 \begin_inset Quotes srd
11494 To force all messages to
11495 \begin_inset Quotes sld
11499 \begin_inset Quotes srd
11511 \begin_layout Standard
11526 \begin_inset LatexCommand \index{-\/-use-stdout}
11531 Additionally, if you happen to have visual studio installed in your windows
11532 machine, you can use it to compile your sources using a custom build and
11539 \begin_layout Standard
11551 \begin_inset LatexCommand \index{-\/-vc}
11556 Something like this should work:
11575 \begin_layout Standard
11594 \begin_layout Standard
11606 -model-large -c $(InputPath)
11609 \begin_inset VSpace bigskip
11615 \begin_layout Section
11616 Environment variables
11617 \begin_inset LatexCommand \index{Environment variables}
11624 \begin_layout Standard
11625 SDCC recognizes the following environment variables:
11629 \labelwidthstring 00.00.0000
11633 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11639 SDCC installs a signal handler
11640 \begin_inset LatexCommand \index{signal handler}
11644 to be able to delete temporary files after an user break (^C) or an exception.
11645 If this environment variable is set, SDCC won't install the signal handler
11646 in order to be able to debug SDCC.
11650 \labelwidthstring 00.00.0000
11656 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11662 Path, where temporary files will be created.
11663 The order of the variables is the search order.
11664 In a standard *nix environment these variables are not set, and there's
11665 no need to set them.
11666 On Windows it's recommended to set one of them.
11670 \labelwidthstring 00.00.0000
11674 \begin_inset LatexCommand \index{SDCC\_HOME}
11681 \begin_inset LatexCommand \ref{sub:Install-paths}
11687 \begin_inset Quotes sld
11691 \begin_inset Quotes srd
11698 \labelwidthstring 00.00.0000
11702 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11709 \begin_inset LatexCommand \ref{sub:Search-Paths}
11715 \begin_inset Quotes sld
11719 \begin_inset Quotes srd
11726 \labelwidthstring 00.00.0000
11730 \begin_inset LatexCommand \index{SDCC\_LIB}
11737 \begin_inset LatexCommand \ref{sub:Search-Paths}
11743 \begin_inset Quotes sld
11747 \begin_inset Quotes srd
11753 \begin_layout Standard
11754 There are some more environment variables recognized by SDCC, but these
11755 are solely used for debugging purposes.
11756 They can change or disappear very quickly, and will never be documented.
11757 \begin_inset VSpace bigskip
11763 \begin_layout Section
11764 Storage Class Language Extensions
11767 \begin_layout Subsection
11768 MCS51/DS390 Storage Class
11769 \begin_inset LatexCommand \index{Storage class}
11773 Language Extensions
11776 \begin_layout Standard
11777 In addition to the ANSI storage classes SDCC allows the following MCS51
11778 specific storage classes:
11781 \begin_layout Subsubsection
11783 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11788 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11793 \begin_inset LatexCommand \index{near (storage class)}
11798 \begin_inset LatexCommand \index{\_\_near (storage class)}
11805 \begin_layout Standard
11810 storage class for the Small Memory model (
11818 or the more ANSI-C compliant forms
11826 can be used synonymously).
11827 Variables declared with this storage class will be allocated in the directly
11828 addressable portion of the internal RAM of a 8051, e.g.:
11831 \begin_layout Verse
11834 __data unsigned char test_data;
11837 \begin_layout Standard
11838 Writing 0x01 to this variable generates the assembly code:
11841 \begin_layout Verse
11844 75*00 01\InsetSpace ~
11852 \begin_layout Subsubsection
11854 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11859 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11864 \begin_inset LatexCommand \index{far (storage class)}
11869 \begin_inset LatexCommand \index{\_\_far (storage class)}
11876 \begin_layout Standard
11877 Variables declared with this storage class will be placed in the external
11883 storage class for the Large Memory model, e.g.:
11886 \begin_layout Verse
11889 __xdata unsigned char test_xdata;
11892 \begin_layout Standard
11893 Writing 0x01 to this variable generates the assembly code:
11896 \begin_layout Verse
11899 90s00r00\InsetSpace ~
11930 \begin_layout Subsubsection
11932 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11937 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11944 \begin_layout Standard
11945 Variables declared with this storage class will be allocated into the indirectly
11946 addressable portion of the internal ram of a 8051, e.g.:
11949 \begin_layout Verse
11952 __idata unsigned char test_idata;
11955 \begin_layout Standard
11956 Writing 0x01 to this variable generates the assembly code:
11959 \begin_layout Verse
11986 \begin_layout Standard
11987 Please note, the first 128 byte of idata physically access the same RAM
11988 as the data memory.
11989 The original 8051 had 128 byte idata memory, nowadays most devices have
11990 256 byte idata memory.
11992 \begin_inset LatexCommand \index{stack}
11996 is located in idata memory.
11999 \begin_layout Subsubsection
12001 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
12006 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
12013 \begin_layout Standard
12014 Paged xdata access is just as straightforward as using the other addressing
12016 It is typically located at the start of xdata and has a maximum size of
12018 The following example writes 0x01 to the pdata variable.
12019 Please note, pdata access physically accesses xdata memory.
12020 The high byte of the address is determined by port P2
12021 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
12025 (or in case of some 8051 variants by a separate Special Function Register,
12027 \begin_inset LatexCommand \ref{sub:MCS51-variants}
12036 storage class for the Medium Memory model, e.g.:
12039 \begin_layout Verse
12042 __pdata unsigned char test_pdata;
12045 \begin_layout Standard
12046 Writing 0x01 to this variable generates the assembly code:
12049 \begin_layout Verse
12058 mov r0,#_test_pdata
12080 \begin_layout Standard
12085 \begin_layout Standard
12095 \begin_inset LatexCommand \index{-\/-xstack}
12099 option is used the pdata memory area is followed by the xstack memory area
12100 and the sum of their sizes is limited to 256 bytes.
12103 \begin_layout Subsubsection
12105 \begin_inset LatexCommand \index{code}
12110 \begin_inset LatexCommand \index{\_\_code}
12117 \begin_layout Standard
12118 'Variables' declared with this storage class will be placed in the code
12122 \begin_layout Verse
12125 __code unsigned char test_code;
12128 \begin_layout Standard
12129 Read access to this variable generates the assembly code:
12132 \begin_layout Verse
12135 90s00r6F\InsetSpace ~
12138 mov dptr,#_test_code
12163 \begin_layout Standard
12168 indexed arrays of characters in code memory can be accessed efficiently:
12171 \begin_layout Verse
12174 __code char test_array[] = {'c','h','e','a','p'};
12177 \begin_layout Standard
12178 Read access to this array using an 8-bit unsigned index generates the assembly
12182 \begin_layout Verse
12194 \begin_layout Verse
12197 90s00r41\InsetSpace ~
12200 mov dptr,#_test_array
12203 \begin_layout Verse
12218 \begin_layout Subsubsection
12220 \begin_inset LatexCommand \index{bit}
12225 \begin_inset LatexCommand \index{\_\_bit}
12232 \begin_layout Standard
12233 This is a data-type and a storage class specifier.
12234 When a variable is declared as a bit, it is allocated into the bit addressable
12235 memory of 8051, e.g.:
12238 \begin_layout Verse
12244 \begin_layout Standard
12245 Writing 1 to this variable generates the assembly code:
12248 \begin_layout Verse
12262 \begin_layout Standard
12263 The bit addressable memory consists of 128 bits which are located from 0x20
12264 to 0x2f in data memory.
12267 Apart from this 8051 specific storage class most architectures support
12269 \begin_inset LatexCommand \index{bitfields}
12277 \begin_layout Standard
12278 Not really meant as examples, but nevertheless showing what bitfields are
12279 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12285 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12286 signed modifier are implemented as unsigned.
12289 \begin_layout Subsubsection
12291 \begin_inset LatexCommand \index{sfr}
12296 \begin_inset LatexCommand \index{\_\_sfr}
12301 \begin_inset LatexCommand \index{sfr16}
12306 \begin_inset LatexCommand \index{\_\_sfr16}
12311 \begin_inset LatexCommand \index{sfr32}
12316 \begin_inset LatexCommand \index{\_\_sfr32}
12321 \begin_inset LatexCommand \index{\_\_sbit}
12326 \begin_inset LatexCommand \index{sbit}
12333 \begin_layout Standard
12334 Like the bit keyword,
12336 sfr / sfr16 / sfr32 / sbit
12338 signify both a data-type and storage class, they are used to describe the
12359 variables of a 8051, eg:
12362 \begin_layout Verse
12366 \begin_inset LatexCommand \index{at}
12371 \begin_inset LatexCommand \index{\_\_at}
12375 (0x80) P0;\InsetSpace ~
12376 /* special function register P0 at location 0x80 */
12381 special function register combination for timer 0
12385 with the high byte at
12386 location 0x8C and the low byte at location 0x8A */
12388 __sfr16 __at (0x8C8A)
12394 \begin_inset LatexCommand \index{at}
12399 \begin_inset LatexCommand \index{\_\_at}
12403 (0xd7) CY;\InsetSpace ~
12405 \begin_inset LatexCommand \index{Flags}
12410 \begin_inset LatexCommand \index{Carry flag}
12417 \begin_layout Standard
12418 Special function registers which are located on an address dividable by
12419 8 are bit-addressable, an
12423 addresses a specific bit within these sfr.
12425 16 Bit and 32 bit special function
12426 register combinations which require a certain access order are better not
12436 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12437 this is not guaranteed.
12442 \begin_layout Standard
12443 Please note, if you use a header file which was written for another compiler
12444 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
12450 Specifically the syntax
12453 sfr P0 = 0x80;\InsetSpace ~
12460 by SDCC to an assignment of 0x80 to a variable called P0
12463 \begin_inset Marginal
12466 \begin_layout Standard
12478 Nevertheless it is possible to write header files
12479 \begin_inset LatexCommand \index{Header files}
12484 \begin_inset LatexCommand \index{Include files}
12488 which can be shared among different compilers (see section
12489 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
12497 \begin_layout Subsubsection
12499 \begin_inset LatexCommand \index{Pointer}
12503 to MCS51/DS390 specific memory spaces
12506 \begin_layout Standard
12507 SDCC allows (via language extensions) pointers to explicitly point to any
12508 of the memory spaces
12509 \begin_inset LatexCommand \index{Memory model}
12514 In addition to the explicit pointers, the compiler uses (by default) generic
12515 pointers which can be used to point to any of the memory spaces.
12520 declaration examples:
12523 \begin_layout Verse
12526 /* pointer physically in internal ram pointing to object in external ram
12529 __xdata unsigned char * __data p;
12533 /* pointer physically in external ram
12534 pointing to object in internal ram */
12536 __data unsigned char * __xdata p;
12541 pointer physically in code rom pointing to data in xdata space */
12544 unsigned char * __code p;
12548 /* pointer physically in code space pointing to
12549 data in code space */
12551 __code unsigned char * __code p;
12556 physically located in xdata space */
12558 unsigned char * __xdata p;
12563 pointer physically located in default memory space */
12570 the following is a function pointer
12571 \begin_inset LatexCommand \index{function pointer}
12575 physically located in data space */
12577 char (* __data fp)(void);
12580 \begin_layout Standard
12581 Well you get the idea.
12586 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
12599 The highest order byte of the
12603 pointers contains the data space information.
12604 Assembler support routines are called whenever data is stored or retrieved
12610 These are useful for developing reusable library
12611 \begin_inset LatexCommand \index{Libraries}
12616 Explicitly specifying the pointer
12617 \begin_inset LatexCommand \index{pointer}
12621 type will generate the most efficient code.
12624 \begin_layout Subsubsection
12625 Notes on MCS51 memory
12626 \begin_inset LatexCommand \index{MCS51 memory}
12633 \begin_layout Standard
12634 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12635 RAM memory which is structured as follows:
12639 - Bytes 00-1F - 32 bytes to hold
12640 up to 4 banks of the registers R0 to R7,
12642 - Bytes 20-2F - 16 bytes to hold
12644 \begin_inset LatexCommand \index{bit}
12650 - Bytes 30-7F - 80 bytes for general purpose use.
12655 \begin_layout Standard
12656 Additionally some members of the MCS51 family may have up to 128 bytes of
12657 additional, indirectly addressable, internal RAM memory (
12662 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12667 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12672 Furthermore, some chips may have some built in external memory (
12677 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12682 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12686 ) which should not be confused with the internal, directly addressable RAM
12692 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12697 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12702 Sometimes this built in
12706 memory has to be activated before using it (you can probably find this
12707 information on the datasheet of the microcontroller your are using, see
12709 \begin_inset LatexCommand \ref{sub:Startup-Code}
12717 \begin_layout Standard
12718 Normally SDCC will only use the first bank
12719 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12723 of registers (register bank 0), but it is possible to specify that other
12724 banks of registers (keyword
12731 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12736 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12742 ) should be used for example in interrupt
12743 \begin_inset LatexCommand \index{interrupt}
12748 \begin_inset LatexCommand \index{\_\_interrupt}
12753 By default, the compiler will place the stack after the last byte of allocated
12754 memory for variables.
12755 For example, if the first 2 banks of registers are used, and only four
12760 variables, it will position the base of the internal stack at address 20
12762 This implies that as the stack
12763 \begin_inset LatexCommand \index{stack}
12767 grows, it will use up the remaining register banks, and the 16 bytes used
12768 by the 128 bit variables, and 80 bytes for general purpose use.
12769 If any bit variables are used, the data variables will be placed in unused
12770 register banks and after the byte holding the last bit variable.
12771 For example, if register banks 0 and 1 are used, and there are 9 bit variables
12776 variables will be placed starting from address 0x10 to 0x20 and continue
12782 \begin_layout Standard
12792 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12796 to specify the start address of the
12804 \begin_layout Standard
12814 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12818 to specify the size of the total internal RAM (
12832 \begin_layout Standard
12833 By default the 8051 linker will place the stack after the last byte of (i)data
12839 \begin_layout Standard
12849 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12853 allows you to specify the start of the stack, i.e.
12854 you could start it after any data in the general purpose area.
12855 If your microcontroller has additional indirectly addressable internal
12860 ) you can place the stack on it.
12861 You may also need to use -
12865 \begin_layout Standard
12875 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12879 to set the start address of the external RAM (
12887 \begin_layout Standard
12897 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12901 to specify its size.
12902 Same goes for the code memory, using -
12906 \begin_layout Standard
12916 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12924 \begin_layout Standard
12934 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12939 If in doubt, don't specify any options and see if the resulting memory
12940 layout is appropriate, then you can adjust it.
12943 \begin_layout Standard
12944 The linker generates two files with memory allocation information.
12945 The first, with extension .map
12946 \begin_inset LatexCommand \index{<file>.map}
12950 shows all the variables and segments.
12951 The second with extension .mem
12952 \begin_inset LatexCommand \index{<file>.mem}
12956 shows the final memory layout.
12957 The linker will complain either if memory segments overlap, there is not
12958 enough memory, or there is not enough space for stack.
12959 If you get any linking warnings and/or errors related to stack or segments
12960 allocation, take a look at either the .map or .mem files to find out what
12962 The .mem file may even suggest a solution to the problem.
12963 \begin_inset VSpace bigskip
12969 \begin_layout Subsection
12970 Z80/Z180 Storage Class
12971 \begin_inset LatexCommand \index{Z80!Storage class}
12975 Language Extensions
12978 \begin_layout Subsubsection
12980 \begin_inset LatexCommand \index{sfr}
12985 \begin_inset LatexCommand \index{\_\_sfr}
12989 (in/out to 8-bit addresses)
12992 \begin_layout Standard
12994 \begin_inset LatexCommand \index{Z80}
12998 family has separate address spaces for memory and
13008 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
13013 \begin_inset LatexCommand \index{Z80!I/O memory}
13018 \begin_inset LatexCommand \index{Z180!I/O memory}
13022 is accessed with special instructions, e.g.:
13025 \begin_layout Verse
13028 sfr at 0x78 IoPort;\InsetSpace ~
13030 /* define a var in I/O space at 78h called IoPort */
13034 \begin_layout Standard
13035 Writing 0x01 to this variable generates the assembly code:
13038 \begin_layout Verse
13058 \begin_layout Subsubsection
13060 \begin_inset LatexCommand \index{sfr}
13065 \begin_inset LatexCommand \index{\_\_sfr}
13069 (in/out to 16-bit addresses)
13072 \begin_layout Standard
13077 is used to support 16 bit addresses in I/O memory e.g.:
13080 \begin_layout Verse
13084 \begin_inset LatexCommand \index{at}
13089 \begin_inset LatexCommand \index{\_\_at}
13096 \begin_layout Standard
13097 Writing 0x01 to this variable generates the assembly code:
13100 \begin_layout Verse
13103 01 23 01\InsetSpace ~
13125 \begin_layout Subsubsection
13127 \begin_inset LatexCommand \index{sfr}
13132 \begin_inset LatexCommand \index{\_\_sfr}
13136 (in0/out0 to 8 bit addresses on Z180
13137 \begin_inset LatexCommand \index{Z180}
13142 \begin_inset LatexCommand \index{HD64180 (see Z180)}
13149 \begin_layout Standard
13150 The compiler option -
13154 \begin_layout Standard
13164 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
13168 =180 (80) and a compiler #pragma\InsetSpace ~
13170 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
13174 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
13184 If you include the file z180.h this will be set automatically.
13185 \begin_inset VSpace bigskip
13191 \begin_layout Subsection
13193 \begin_inset LatexCommand \index{HC08!Storage class}
13197 Language Extensions
13200 \begin_layout Subsubsection
13202 \begin_inset LatexCommand \index{data (hc08 storage class)}
13207 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
13214 \begin_layout Standard
13215 The data storage class declares a variable that resides in the first 256
13216 bytes of memory (the direct page).
13218 \begin_inset LatexCommand \index{HC08}
13222 is most efficient at accessing variables (especially pointers) stored here.
13225 \begin_layout Subsubsection
13227 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
13232 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
13239 \begin_layout Standard
13240 The xdata storage class declares a variable that can reside anywhere in
13242 This is the default if no storage class is specified.
13244 \begin_inset VSpace bigskip
13250 \begin_layout Section
13251 Other SDCC language extensions
13252 \begin_inset LatexCommand \index{Other SDCC language extensions}
13259 \begin_layout Subsection
13263 \begin_layout Standard
13264 SDCC supports the use of binary constants, such as 0b01100010.
13265 This feature is only enabled when the compiler is invoked using --std-sdccxx.
13268 \begin_layout Standard
13269 \begin_inset VSpace bigskip
13275 \begin_layout Section
13276 Absolute Addressing
13277 \begin_inset LatexCommand \index{Absolute addressing}
13284 \begin_layout Standard
13285 Data items can be assigned an absolute address with the
13288 \begin_inset LatexCommand \index{at}
13293 \begin_inset LatexCommand \index{\_\_at}
13299 keyword, in addition to a storage class, e.g.:
13302 \begin_layout Verse
13306 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13311 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
13316 \begin_inset LatexCommand \index{at}
13321 \begin_inset LatexCommand \index{\_\_at}
13325 0x7ffe unsigned int chksum;
13328 \begin_layout Standard
13329 or, better conforming to ISO/IEC 9899 C:
13332 \begin_layout Verse
13335 __xdata __at (0x7ffe) unsigned int chksum;
13338 \begin_layout Standard
13339 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
13340 of the external ram.
13345 reserve any space for variables declared in this way
13346 \begin_inset Marginal
13349 \begin_layout Standard
13358 (they are implemented with an equate in the assembler).
13359 Thus it is left to the programmer to make sure there are no overlaps with
13360 other variables that are declared without the absolute address.
13361 The assembler listing file (.lst
13362 \begin_inset LatexCommand \index{<file>.lst}
13366 ) and the linker output files (.rst
13367 \begin_inset LatexCommand \index{<file>.rst}
13372 \begin_inset LatexCommand \index{<file>.map}
13376 ) are good places to look for such overlaps.
13379 \begin_layout Standard
13380 If however you provide an initializer
13381 \begin_inset LatexCommand \index{Variable initialization}
13385 actual memory allocation will take place and overlaps will be detected
13390 \begin_layout Verse
13393 __code __at (0x7ff0) char Id[5] =
13394 \begin_inset Quotes sld
13398 \begin_inset Quotes srd
13404 \begin_layout Standard
13405 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
13409 \begin_layout Standard
13410 In case of memory mapped I/O devices the keyword
13414 has to be used to tell the compiler that accesses might not be removed:
13417 \begin_layout Verse
13421 \begin_inset LatexCommand \index{volatile}
13426 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13431 \begin_inset LatexCommand \index{at}
13435 (0x8000) unsigned char PORTA_8255;
13438 \begin_layout Standard
13439 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
13444 \begin_inset LatexCommand \index{Aligned array}
13451 starts at a block (256 byte) boundary
13452 \begin_inset LatexCommand \index{block boundary}
13457 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13463 Absolute addresses can be specified for variables in all
13464 storage classes, e.g.:
13467 \begin_layout Verse
13471 \begin_inset LatexCommand \index{bit}
13476 \begin_inset LatexCommand \index{at}
13483 \begin_layout Standard
13484 The above example will allocate the variable at offset 0x02 in the bit-addressab
13486 There is no real advantage to assigning absolute addresses to variables
13487 in this manner, unless you want strict control over all the variables allocated.
13488 One possible use would be to write hardware portable code.
13489 For example, if you have a routine that uses one or more of the microcontroller
13490 I/O pins, and such pins are different for two different hardwares, you
13491 can declare the I/O pins in your routine using:
13494 \begin_layout Verse
13498 \begin_inset LatexCommand \index{volatile}
13502 __bit MOSI;\InsetSpace ~
13506 /* master out, slave in */
13508 extern volatile __bit MISO;\InsetSpace ~
13515 extern volatile __bit MCLK;\InsetSpace ~
13524 Output of a byte on a 3-wire serial bus.
13529 If needed adapt polarity of clock,
13530 polarity of data and bit order
13535 unsigned char spi_io(unsigned char out_byte)
13560 MOSI = out_byte & 0x80;
13591 /* _asm nop _endasm; */\InsetSpace ~
13599 /* for slow peripherals */
13651 \begin_layout Standard
13652 Then, someplace in the code for the first hardware you would use
13655 \begin_layout Verse
13659 \begin_inset LatexCommand \index{at}
13664 \begin_inset LatexCommand \index{\_\_at}
13668 (0x80) MOSI;\InsetSpace ~
13672 /* I/O port 0, bit 0 */
13674 __bit __at (0x81) MISO;\InsetSpace ~
13681 __bit __at (0x82) MCLK;\InsetSpace ~
13685 /* I/O port 0, bit 2 */
13688 \begin_layout Standard
13689 Similarly, for the second hardware you would use
13692 \begin_layout Verse
13695 __bit __at (0x83) MOSI;\InsetSpace ~
13699 /* I/O port 0, bit 3 */
13701 __bit __at (0x91) MISO;\InsetSpace ~
13706 I/O port 1, bit 1 */
13709 \begin_inset LatexCommand \index{bit}
13713 __at (0x92) MCLK;\InsetSpace ~
13717 /* I/O port 1, bit 2 */
13720 \begin_layout Standard
13721 and you can use the same hardware dependent routine without changes, as
13722 for example in a library.
13723 This is somehow similar to sbit, but only one absolute address has to be
13724 specified in the whole project.
13725 \begin_inset VSpace bigskip
13731 \begin_layout Section
13733 \begin_inset LatexCommand \index{Parameters}
13738 \begin_inset LatexCommand \index{function parameter}
13743 \begin_inset LatexCommand \index{local variables}
13748 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13755 \begin_layout Standard
13756 Automatic (local) variables and parameters to functions can either be placed
13757 on the stack or in data-space.
13758 The default action of the compiler is to place these variables in the internal
13759 RAM (for small model) or external RAM (for medium or large model).
13760 This in fact makes them similar to
13763 \begin_inset LatexCommand \index{static}
13769 so by default functions are non-reentrant
13770 \begin_inset LatexCommand \index{reentrant}
13779 They can be placed on the stack
13780 \begin_inset LatexCommand \index{stack}
13790 \begin_layout Standard
13800 \begin_inset LatexCommand \index{-\/-stack-auto}
13808 #pragma\InsetSpace ~
13812 \begin_inset LatexCommand \index{\#pragma stackauto}
13819 \begin_inset LatexCommand \index{reentrant}
13825 keyword in the function declaration, e.g.:
13828 \begin_layout Verse
13831 unsigned char foo(char i) __reentrant
13845 \begin_layout Standard
13846 Since stack space on 8051 is limited, the
13856 \begin_layout Standard
13867 option should be used sparingly.
13868 Note that the reentrant keyword just means that the parameters & local
13869 variables will be allocated to the stack, it
13873 mean that the function is register bank
13874 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13883 \begin_inset LatexCommand \index{local variables}
13887 can be assigned storage classes and absolute
13888 \begin_inset LatexCommand \index{Absolute addressing}
13895 \begin_layout Verse
13898 unsigned char foo()
13906 __xdata unsigned char i;
13919 \begin_inset LatexCommand \index{at}
13923 (0x31) unsigned char j;
13935 \begin_layout Standard
13936 In the above example the variable
13940 will be allocated in the external ram,
13944 in bit addressable space and
13955 \begin_layout Standard
13966 or when a function is declared as
13970 this should only be done for static variables.
13973 \begin_layout Standard
13975 \begin_inset LatexCommand \index{function parameter}
13979 however are not allowed any storage class
13980 \begin_inset LatexCommand \index{Storage class}
13984 , (storage classes for parameters will be ignored), their allocation is
13985 governed by the memory model in use, and the reentrancy options.
13988 \begin_layout Standard
13989 It is however allowed to use bit parameters in reentrant functions and also
13990 non-static local bit variables are supported.
13991 Efficient use is limited to 8 semi-bitregisters in bit space.
13992 They are pushed and popped to stack
13993 \begin_inset LatexCommand \index{stack}
13997 as a single byte just like the normal registers.
14000 \begin_layout Section
14002 \begin_inset LatexCommand \label{sub:Overlaying}
14007 \begin_inset LatexCommand \index{Overlaying}
14014 \begin_layout Standard
14016 \begin_inset LatexCommand \index{reentrant}
14020 functions SDCC will try to reduce internal ram space usage by overlaying
14021 parameters and local variables of a function (if possible).
14022 Parameters and local variables
14023 \begin_inset LatexCommand \index{local variables}
14027 of a function will be allocated to an overlayable segment if the function
14030 no other function calls and the function is non-reentrant and the memory
14032 \begin_inset LatexCommand \index{Memory model}
14039 If an explicit storage class
14040 \begin_inset LatexCommand \index{Storage class}
14044 is specified for a local variable, it will NOT be overlayed.
14047 \begin_layout Standard
14048 Note that the compiler (not the linkage editor) makes the decision for overlayin
14050 Functions that are called from an interrupt service routine
14051 \begin_inset Marginal
14054 \begin_layout Standard
14062 should be preceded by a #pragma\InsetSpace ~
14064 \begin_inset LatexCommand \index{\#pragma nooverlay}
14068 if they are not reentrant.
14071 \begin_layout Standard
14072 Also note that the compiler does not do any processing of inline assembler
14073 code, so the compiler might incorrectly assign local variables and parameters
14074 of a function into the overlay segment if the inline assembler code calls
14075 other c-functions that might use the overlay.
14076 In that case the #pragma\InsetSpace ~
14077 nooverlay should be used.
14080 \begin_layout Standard
14081 Parameters and local variables of functions that contain 16 or 32 bit multiplica
14083 \begin_inset LatexCommand \index{Multiplication}
14088 \begin_inset LatexCommand \index{Division}
14092 will NOT be overlayed since these are implemented using external functions,
14096 \begin_layout Verse
14102 \begin_inset LatexCommand \index{\#pragma nooverlay}
14108 void set_error(unsigned char errcd)
14125 some_isr () __interrupt
14126 \begin_inset LatexCommand \index{interrupt}
14156 \begin_layout Standard
14157 In the above example the parameter
14165 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
14167 not present, this could cause unpredictable runtime behavior when called
14168 from an interrupt service routine.
14169 The #pragma\InsetSpace ~
14170 nooverlay ensures that the parameters and local variables for
14171 the function are NOT overlayed.
14172 \begin_inset VSpace bigskip
14178 \begin_layout Section
14179 Interrupt Service Routines
14180 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
14187 \begin_layout Subsection
14188 General Information
14191 \begin_layout Standard
14204 outines to be coded in C, with some extended keywords.
14207 \begin_layout Verse
14210 void timer_isr (void) __interrupt (1) __using (1)
14224 \begin_layout Standard
14225 The optional number following the
14228 \begin_inset LatexCommand \index{interrupt}
14233 \begin_inset LatexCommand \index{\_\_interrupt}
14239 keyword is the interrupt number this routine will service.
14240 When present, the compiler will insert a call to this routine in the interrupt
14242 \begin_inset LatexCommand \index{interrupt vector table}
14246 for the interrupt number specified.
14247 If you have multiple source files in your project, interrupt service routines
14248 can be present in any of them, but a prototype of the isr MUST be present
14249 or included in the file that contains the function
14254 The optional (8051 specific) keyword
14257 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14262 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14268 can be used to tell the compiler to use the specified register bank when
14269 generating code for this function.
14272 Interrupt service routines open the door for some very interesting bugs:
14275 \begin_layout Subsubsection
14276 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
14280 Common interrupt pitfall: variable not declared
14285 \begin_layout Standard
14286 If an interrupt service routine changes variables which are accessed by
14287 other functions these variables have to be declared
14292 \begin_inset LatexCommand \index{volatile}
14298 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
14305 \begin_layout Subsubsection
14306 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
14310 Common interrupt pitfall:
14315 \begin_layout Standard
14316 If the access to these variables is not
14319 \begin_inset LatexCommand \index{atomic}
14326 the processor needs more than one instruction for the access and could
14327 be interrupted while accessing the variable) the interrupt must be disabled
14328 during the access to avoid inconsistent data.
14331 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
14332 and should be protected by disabling interrupts.
14333 You're not automatically on the safe side if you use 8 bit variables though.
14334 We need an example here: f.e.
14335 on the 8051 the harmless looking
14336 \begin_inset Quotes srd
14346 \begin_inset Quotes sld
14355 \begin_inset Quotes srd
14365 \begin_inset Quotes sld
14368 from within an interrupt routine might get lost if the interrupt occurs
14371 \begin_inset Quotes sld
14376 counter\InsetSpace ~
14381 \begin_inset Quotes srd
14384 is not atomic on the 8051 even if
14388 is located in data memory.
14390 Bugs like these are hard to reproduce and can
14391 cause a lot of trouble.
14395 \begin_layout Subsubsection
14396 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
14400 Common interrupt pitfall:
14405 \begin_layout Standard
14406 The return address and the registers used in the interrupt service routine
14407 are saved on the stack
14408 \begin_inset LatexCommand \index{stack}
14412 so there must be sufficient stack space.
14413 If there isn't variables or registers (or even the return address itself)
14420 \begin_inset LatexCommand \index{stack overflow}
14424 is most likely to happen if the interrupt occurs during the
14425 \begin_inset Quotes sld
14429 \begin_inset Quotes srd
14432 subroutine when the stack is already in use for f.e.
14433 many return addresses.
14436 \begin_layout Subsubsection
14437 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
14441 Common interrupt pitfall:
14443 use of non-reentrant functions
14446 \begin_layout Standard
14447 A special note here, int (16 bit) and long (32 bit) integer division
14448 \begin_inset LatexCommand \index{Division}
14453 \begin_inset LatexCommand \index{Multiplication}
14458 \begin_inset LatexCommand \index{Modulus}
14463 \begin_inset LatexCommand \index{Floating point support}
14467 operations are implemented using external support routines.
14468 If an interrupt service routine needs to do any of these operations then
14469 the support routines (as mentioned in a following section) will have to
14470 be recompiled using the
14476 \begin_layout Standard
14486 \begin_inset LatexCommand \index{-\/-stack-auto}
14492 option and the source file will need to be compiled using the
14498 \begin_layout Standard
14510 \begin_inset LatexCommand \index{-\/-int-long-reent}
14517 Note, the type promotion
14518 \begin_inset LatexCommand \index{type promotion}
14522 required by ANSI C can cause 16 bit routines to be used
14523 \begin_inset Marginal
14526 \begin_layout Standard
14535 without the programmer being aware of it.
14539 (unsigned char)(tail-1)
14541 within the if clause in section
14542 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
14549 \begin_layout Standard
14550 Calling other functions from an interrupt service routine is not recommended,
14551 avoid it if possible.
14552 Note that when some function is called from an interrupt service routine
14553 it should be preceded by a #pragma\InsetSpace ~
14555 \begin_inset LatexCommand \index{\#pragma nooverlay}
14559 if it is not reentrant.
14560 Furthermore nonreentrant functions should not be called from the main program
14561 while the interrupt service routine might be active.
14562 They also must not be called from low priority interrupt service routines
14563 while a high priority interrupt service routine might be active.
14564 You could use semaphores or make the function
14568 if all parameters are passed in registers.
14571 \begin_inset LatexCommand \ref{sub:Overlaying}
14576 about Overlaying and section
14577 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14582 about Functions using private register banks.
14583 \begin_inset VSpace bigskip
14589 \begin_layout Subsection
14590 MCS51/DS390 Interrupt Service Routines
14593 \begin_layout Standard
14595 \begin_inset LatexCommand \index{interrupt}
14599 numbers and the corresponding address & descriptions for the Standard 8051/8052
14601 SDCC will automatically adjust the
14602 \begin_inset LatexCommand \index{interrupt vector table}
14606 to the maximum interrupt number specified.
14611 \begin_layout Standard
14613 \begin_inset Tabular
14614 <lyxtabular version="3" rows="9" columns="3">
14616 <column alignment="center" valignment="top" leftline="true" width="0in">
14617 <column alignment="left" valignment="top" leftline="true" width="0in">
14618 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14619 <row topline="true" bottomline="true">
14620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14623 \begin_layout Standard
14629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14632 \begin_layout Standard
14638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14641 \begin_layout Standard
14648 <row topline="true">
14649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14652 \begin_layout Standard
14658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14661 \begin_layout Standard
14667 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14670 \begin_layout Standard
14677 <row topline="true">
14678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14681 \begin_layout Standard
14687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14690 \begin_layout Standard
14696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14699 \begin_layout Standard
14706 <row topline="true">
14707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14710 \begin_layout Standard
14716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14719 \begin_layout Standard
14725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14728 \begin_layout Standard
14735 <row topline="true">
14736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14739 \begin_layout Standard
14745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14748 \begin_layout Standard
14754 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14757 \begin_layout Standard
14764 <row topline="true">
14765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14768 \begin_layout Standard
14774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14777 \begin_layout Standard
14783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14786 \begin_layout Standard
14793 <row topline="true">
14794 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14797 \begin_layout Standard
14803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14806 \begin_layout Standard
14812 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14815 \begin_layout Standard
14822 <row topline="true">
14823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14826 \begin_layout Standard
14832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14835 \begin_layout Standard
14841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14844 \begin_layout Standard
14851 <row topline="true" bottomline="true">
14852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14855 \begin_layout Standard
14861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14864 \begin_layout Standard
14870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14873 \begin_layout Standard
14889 \begin_layout Standard
14890 If the interrupt service routine is defined without
14893 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14898 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14904 a register bank or with register bank 0 (
14908 0), the compiler will save the registers used by itself on the stack upon
14909 entry and restore them at exit, however if such an interrupt service routine
14910 calls another function then the entire register bank will be saved on the
14912 This scheme may be advantageous for small interrupt service routines which
14913 have low register usage.
14916 \begin_layout Standard
14917 If the interrupt service routine is defined to be using a specific register
14922 & psw are saved and restored, if such an interrupt service routine calls
14923 another function (using another register bank) then the entire register
14924 bank of the called function will be saved on the stack
14925 \begin_inset LatexCommand \index{stack}
14930 This scheme is recommended for larger interrupt service routines.
14931 \begin_inset VSpace bigskip
14937 \begin_layout Subsection
14939 \begin_inset LatexCommand \index{HC08}
14943 Interrupt Service Routines
14946 \begin_layout Standard
14947 Since the number of interrupts
14948 \begin_inset LatexCommand \index{HC08!interrupt}
14952 available is chip specific and the interrupt vector table always ends at
14953 the last byte of memory, the interrupt numbers corresponds to the interrupt
14954 vectors in reverse order of address.
14955 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14956 2 will use the interrupt vector at 0xfffa, and so on.
14957 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14958 this way; instead see section
14959 \begin_inset LatexCommand \ref{sub:Startup-Code}
14963 for details on customizing startup.
14964 \begin_inset VSpace bigskip
14970 \begin_layout Subsection
14971 Z80 Interrupt Service Routines
14974 \begin_layout Standard
14976 \begin_inset LatexCommand \index{Z80}
14980 uses several different methods for determining the correct interrupt
14981 \begin_inset LatexCommand \index{Z80!interrupt}
14985 vector depending on the hardware implementation.
14986 Therefore, SDCC ignores the optional interrupt number and does not attempt
14987 to generate an interrupt vector table.
14990 \begin_layout Standard
14991 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14992 instruction to return from the interrupt.
14993 To write an interrupt handler for the non-maskable interrupt, which needs
14994 a RETN instruction instead, add the
15001 \begin_layout Verse
15004 void nmi_isr (void) critical interrupt
15018 \begin_layout Standard
15019 However if you need to create a non-interruptable interrupt service routine
15020 you would also require the
15025 To distinguish between this and an nmi_isr you must provide an interrupt
15027 \begin_inset VSpace bigskip
15033 \begin_layout Section
15034 Enabling and Disabling Interrupts
15037 \begin_layout Subsection
15038 Critical Functions and Critical Statements
15041 \begin_layout Standard
15042 A special keyword may be associated with a block or a function declaring
15048 SDCC will generate code to disable all interrupts
15049 \begin_inset LatexCommand \index{interrupt}
15053 upon entry to a critical function and restore the interrupt enable to the
15054 previous state before returning.
15055 Nesting critical functions will need one additional byte on the stack
15056 \begin_inset LatexCommand \index{stack}
15063 \begin_layout Verse
15066 int foo () __critical
15067 \begin_inset LatexCommand \index{critical}
15072 \begin_inset LatexCommand \index{\_\_critical}
15097 \begin_layout Standard
15098 The critical attribute maybe used with other attributes like
15108 may also be used to disable interrupts more locally:
15111 \begin_layout Verse
15117 \begin_layout Standard
15118 More than one statement could have been included in the block.
15121 \begin_layout Subsection
15122 Enabling and Disabling Interrupts directly
15125 \begin_layout Standard
15127 \begin_inset LatexCommand \index{interrupt}
15131 can also be disabled and enabled directly (8051):
15134 \begin_layout Verse
15137 EA = 0;\InsetSpace ~
15163 \begin_layout Verse
15199 \begin_layout Verse
15202 EA = 1;\InsetSpace ~
15231 \begin_layout Verse
15270 \begin_layout Standard
15271 On other architectures which have seperate opcodes for enabling and disabling
15272 interrupts you might want to make use of defines with inline assembly
15273 \begin_inset LatexCommand \index{Assembler routines}
15278 \begin_inset LatexCommand \index{HC08!interrupt}
15285 \begin_layout Verse
15289 \begin_inset LatexCommand \index{\_asm}
15298 \begin_inset LatexCommand \index{\_endasm}
15305 \begin_layout Verse
15308 #define SEI _asm\InsetSpace ~
15315 \begin_layout Verse
15321 \begin_layout Standard
15322 Note: it is sometimes sufficient to disable only a specific interrupt source
15324 a timer or serial interrupt by manipulating an
15327 \begin_inset LatexCommand \index{interrupt mask}
15337 \begin_layout Standard
15338 Usually the time during which interrupts are disabled should be kept as
15340 This minimizes both
15345 \begin_inset LatexCommand \index{interrupt latency}
15349 (the time between the occurrence of the interrupt and the execution of
15350 the first code in the interrupt routine) and
15355 \begin_inset LatexCommand \index{interrupt jitter}
15359 (the difference between the shortest and the longest interrupt latency).
15360 These really are something different, f.e.
15361 a serial interrupt has to be served before its buffer overruns so it cares
15362 for the maximum interrupt latency, whereas it does not care about jitter.
15363 On a loudspeaker driven via a digital to analog converter which is fed
15364 by an interrupt a latency of a few milliseconds might be tolerable, whereas
15365 a much smaller jitter will be very audible.
15368 \begin_layout Standard
15369 You can reenable interrupts within an interrupt routine and on some architecture
15370 s you can make use of two (or more) levels of
15372 interrupt priorities
15375 \begin_inset LatexCommand \index{interrupt priority}
15380 On some architectures which don't support interrupt priorities these can
15381 be implemented by manipulating the interrupt mask and reenabling interrupts
15382 within the interrupt routine.
15383 Check there is sufficient space on the stack
15384 \begin_inset LatexCommand \index{stack}
15388 and don't add complexity unless you have to.
15392 \begin_layout Subsection
15394 \begin_inset LatexCommand \index{semaphore}
15398 locking (mcs51/ds390)
15401 \begin_layout Standard
15402 Some architectures (mcs51/ds390) have an atomic
15403 \begin_inset LatexCommand \index{atomic}
15416 These type of instructions are typically used in preemptive multitasking
15417 systems, where a routine f.e.
15418 claims the use of a data structure ('acquires a lock
15419 \begin_inset LatexCommand \index{lock}
15423 on it'), makes some modifications and then releases the lock when the data
15424 structure is consistent again.
15425 The instruction may also be used if interrupt and non-interrupt code have
15426 to compete for a resource.
15427 With the atomic bit test and clear instruction interrupts
15428 \begin_inset LatexCommand \index{interrupt}
15432 don't have to be disabled for the locking operation.
15436 \begin_layout Standard
15437 SDCC generates this instruction if the source follows this pattern:
15440 \begin_layout Verse
15444 \begin_inset LatexCommand \index{volatile}
15448 bit resource_is_free;
15452 if (resource_is_free)
15462 resource_is_free=0;
15475 resource_is_free=1;
15482 \begin_layout Standard
15483 Note, mcs51 and ds390 support only an atomic
15484 \begin_inset LatexCommand \index{atomic}
15492 instruction (as opposed to atomic bit test and
15497 \begin_layout Section
15498 Functions using private register banks
15499 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
15506 \begin_layout Standard
15507 Some architectures have support for quickly changing register sets.
15508 SDCC supports this feature with the
15511 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
15516 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
15522 attribute (which tells the compiler to use a register bank
15523 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
15527 other than the default bank zero).
15528 It should only be applied to
15531 \begin_inset LatexCommand \index{interrupt}
15537 functions (see footnote below).
15538 This will in most circumstances make the generated ISR code more efficient
15539 since it will not have to save registers on the stack.
15542 \begin_layout Standard
15547 attribute will have no effect on the generated code for a
15551 function (but may occasionally be useful anyway
15555 \begin_layout Standard
15556 possible exception: if a function is called ONLY from 'interrupt' functions
15557 using a particular bank, it can be declared with the same 'using' attribute
15558 as the calling 'interrupt' functions.
15559 For instance, if you have several ISRs using bank one, and all of them
15560 call memcpy(), it might make sense to create a specialized version of memcpy()
15561 'using 1', since this would prevent the ISR from having to save bank zero
15562 to the stack on entry and switch to bank zero before calling the function
15571 (pending: Note, nowadays the
15575 attribute has an effect on
15579 the generated code for a
15590 \begin_layout Standard
15595 function using a non-zero bank will assume that it can trash that register
15596 bank, and will not save it.
15597 Since high-priority interrupts
15598 \begin_inset LatexCommand \index{interrupts}
15603 \begin_inset LatexCommand \index{interrupt priority}
15607 can interrupt low-priority ones on the 8051 and friends, this means that
15608 if a high-priority ISR
15612 a particular bank occurs while processing a low-priority ISR
15616 the same bank, terrible and bad things can happen.
15617 To prevent this, no single register bank should be
15621 by both a high priority and a low priority ISR.
15622 This is probably most easily done by having all high priority ISRs use
15623 one bank and all low priority ISRs use another.
15624 If you have an ISR which can change priority at runtime, you're on your
15625 own: I suggest using the default bank zero and taking the small performance
15629 \begin_layout Standard
15630 It is most efficient if your ISR calls no other functions.
15631 If your ISR must call other functions, it is most efficient if those functions
15632 use the same bank as the ISR (see note 1 below); the next best is if the
15633 called functions use bank zero.
15634 It is very inefficient to call a function using a different, non-zero bank
15637 \begin_inset VSpace bigskip
15643 \begin_layout Section
15645 \begin_inset LatexCommand \label{sub:Startup-Code}
15650 \begin_inset LatexCommand \index{Startup code}
15657 \begin_layout Subsection
15658 MCS51/DS390 Startup Code
15661 \begin_layout Standard
15662 The compiler triggers the linker to link certain initialization modules
15663 from the runtime library
15664 \begin_inset LatexCommand \index{Runtime library}
15668 called crt<something>.
15669 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15670 GSINIT5) is not linked unless the -
15676 \begin_layout Standard
15687 -xstack option is used.
15688 These modules are highly entangled by the use of special segments/areas,
15689 but a common layout is shown below:
15692 \begin_layout Verse
15700 \begin_layout Verse
15724 ljmp __sdcc_gsinit_startup
15727 \begin_layout Verse
15735 \begin_layout Verse
15747 .area GSINIT0 (CODE)
15749 __sdcc_gsinit_startup::
15759 mov sp,#__start__stack - 1
15762 \begin_layout Verse
15770 \begin_layout Verse
15782 .area GSINIT1 (CODE)
15784 __sdcc_init_xstack::
15786 ; Need to initialize in GSINIT1 in
15787 case the user's __sdcc_external_startup uses the xstack.
15797 mov __XPAGE,#(__start__x
15808 mov _spx,#__start__xstack
15811 \begin_layout Verse
15819 \begin_layout Verse
15831 .area GSINIT2 (CODE)
15841 lcall __sdcc_external_startup
15861 jz __sdcc_init_data
15872 __sdcc_program_startup
15877 \begin_layout Verse
15885 \begin_layout Verse
15897 .area GSINIT3 (CODE)
15950 mov r2,#((l_XINIT+255) >> 8)
15981 __XPAGE,#(s_XISEG >> 8)
15983 00001$:\InsetSpace ~
16047 00002$:\InsetSpace ~
16074 \begin_layout Verse
16082 \begin_layout Verse
16094 .area GSINIT4 (CODE)
16096 __mcs51_genRAMCLEAR::
16118 00004$:\InsetSpace ~
16132 ; _mcs51_genRAMCLEAR() end
16135 \begin_layout Verse
16143 \begin_layout Verse
16155 .area GSINIT4 (CODE)
16157 __mcs51_genXRAMCLEAR::
16218 mov __XPAGE,#(s_PSEG >> 8)
16230 00005$:\InsetSpace ~
16305 mov r1,#((l_XSEG + 255) >> 8)
16327 00007$:\InsetSpace ~
16364 \begin_layout Verse
16372 \begin_layout Verse
16384 .area GSINIT5 (CODE)
16386 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
16389 ; and __mcs51_genRAMCLEAR modifies _spx.
16399 mov __XPAGE,#(__start__x
16410 mov _spx,#__start__xstack
16413 \begin_layout Verse
16418 (application modules)
16421 \begin_layout Verse
16433 .area GSINIT (CODE)
16436 \begin_layout Verse
16444 \begin_layout Verse
16456 .area GSFINAL (CODE)
16466 ljmp __sdcc_program_startup
16468 ;---------------------------------
16469 -----------------------
16473 ;--------------------------------------------------
16496 __sdcc_program_startup:
16509 return from main will lock up
16522 \begin_layout Standard
16523 One of these modules (crtstart.asm) contains a call to the C routine
16525 _sdcc_external_startup()
16526 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
16535 at the start of the CODE area.
16536 This routine is also in the runtime library
16537 \begin_inset LatexCommand \index{Runtime library}
16541 and returns 0 by default.
16542 If this routine returns a non-zero value, the static & global variable
16543 initialization will be skipped and the function main will be invoked.
16544 Otherwise static & global variables will be initialized before the function
16548 _sdcc_external_startup()
16550 routine to your program to override the default if you need to setup hardware
16551 or perform some other critical operation prior to static & global variable
16553 \begin_inset LatexCommand \index{Variable initialization}
16558 On some mcs51 variants xdata
16559 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
16563 memory has to be explicitly enabled before it can be accessed or if the
16565 \begin_inset LatexCommand \index{watchdog}
16569 needs to be disabled, this is the place to do it.
16570 The startup code clears all internal data memory, 256 bytes by default,
16571 but from 0 to n-1 if
16577 \begin_layout Standard
16587 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16594 (recommended for Chipcon CC1010).
16597 \begin_layout Standard
16598 See also the compiler options
16604 \begin_layout Standard
16620 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16630 \begin_layout Standard
16642 \begin_inset LatexCommand \index{-\/-main-return}
16647 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16651 about MCS51-variants.
16656 \begin_layout Standard
16657 While these initialization modules are meant as generic startup code there
16658 might be the need for customization.
16659 Let's assume the return value of
16661 _sdcc_external_startup()
16667 should not be checked (or
16669 _sdcc_external_startup()
16671 should not be called at all).
16672 The recommended way would be to copy
16678 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm}
16682 ) into the source directory, adapt it there, then assemble it with
16688 \begin_layout Standard
16689 \begin_inset Quotes sld
16693 \begin_inset Quotes srd
16696 are the assembler options used in
16697 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup }
16708 and when linking your project explicitely specify
16713 As a bonus a listing of the relocated object file
16720 \begin_layout Standard
16721 \begin_inset VSpace bigskip
16727 \begin_layout Subsection
16731 \begin_layout Standard
16733 \begin_inset LatexCommand \index{HC08}
16737 startup code follows the same scheme as the MCS51 startup code.
16738 \begin_inset VSpace bigskip
16744 \begin_layout Subsection
16748 \begin_layout Standard
16750 \begin_inset LatexCommand \index{Z80}
16754 the startup code is inserted by linking with crt0.o which is generated from
16755 sdcc/device/lib/z80/crt0.s.
16756 If you need a different startup code you can use the compiler option
16765 \begin_layout Standard
16780 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16784 and provide your own crt0.o.
16786 \begin_inset VSpace bigskip
16792 \begin_layout Section
16793 Inline Assembler Code
16794 \begin_inset LatexCommand \index{Assembler routines}
16801 \begin_layout Subsection
16802 A Step by Step Introduction
16803 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16810 \begin_layout Standard
16811 Starting from a small snippet of c-code this example shows for the MCS51
16812 how to use inline assembly, access variables, a function parameter and
16813 an array in xdata memory.
16814 The example uses an MCS51 here but is easily adapted for other architectures.
16815 This is a buffer routine which should be optimized:
16818 \begin_layout Verse
16822 unsigned char __far
16823 \begin_inset LatexCommand \index{far (storage class)}
16828 \begin_inset LatexCommand \index{\_\_far (storage class)}
16833 \begin_inset LatexCommand \index{at}
16838 \begin_inset LatexCommand \index{\_\_at}
16842 (0x7f00) buf[0x100];
16843 \begin_inset LatexCommand \index{Aligned array}
16849 unsigned char head, tail;\InsetSpace ~
16867 \begin_inset LatexCommand \index{interrupt}
16919 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16931 void to_buffer( unsigned char c )
16939 if( head != (unsigned char)(tail-1)
16946 \begin_inset LatexCommand \index{promotion to signed int}
16951 \begin_inset LatexCommand \index{type promotion}
16956 \begin_inset Marginal
16959 \begin_layout Standard
16978 buf[ head++ ] = c;\InsetSpace ~
16994 /* access to a 256 byte aligned array */
16999 \begin_layout Standard
17000 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
17001 then a corresponding buffer.asm file is generated.
17002 We define a new function
17006 in file buffer.c in which we cut and paste the generated code, removing
17007 unwanted comments and some ':'.
17009 \begin_inset Quotes sld
17017 \begin_inset Quotes srd
17021 \begin_inset Quotes sld
17029 \begin_inset Quotes srd
17036 \begin_layout Standard
17037 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
17038 and for C-99 compatibility, the double-underscore form (__asm and __endasm)
17040 The latter is also used in the library functions.
17045 to the beginning and the end of the function body:
17048 \begin_layout Verse
17052 /* With a cut and paste from the .asm file, we have something to start with.
17058 function is not yet OK! (registers aren't saved) */
17060 void to_buffer_asm(
17070 \begin_inset LatexCommand \index{\_asm}
17075 \begin_inset LatexCommand \index{\_\_asm}
17089 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
17095 \begin_inset LatexCommand \index{promotion to signed int}
17100 \begin_inset LatexCommand \index{type promotion}
17153 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
17154 \begin_inset LatexCommand \index{Aligned array}
17220 \begin_inset LatexCommand \index{\_endasm}
17225 \begin_inset LatexCommand \index{\_\_endasm}
17234 \begin_layout Standard
17235 The new file buffer.c should compile with only one warning about the unreferenced
17236 function argument 'c'.
17237 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
17238 (1) and finally have:
17241 \begin_layout Verse
17245 unsigned char __far __at(0x7f00) buf[0x100];
17247 unsigned char head, tail;
17258 void to_buffer( unsigned char c )
17267 head != (unsigned char)(tail-1) )
17296 c; // to avoid warning: unreferenced function argument
17303 \begin_inset LatexCommand \index{\_asm}
17308 \begin_inset LatexCommand \index{\_\_asm}
17322 ; save used registers here.
17333 ; If we were still using r2,r3 we would have to push them here.
17336 ; if( head != (unsigned char)(tail-1) )
17380 could do an ANL a,#0x0f here to use a smaller buffer (see below)
17416 a,dpl \InsetSpace ~
17423 ; dpl holds lower byte of function argument
17435 dpl,_head \InsetSpace ~
17438 ; buf is 0x100 byte aligned so head can be used directly
17481 ; we could do an ANL _head,#0x0f here to use a
17482 smaller buffer (see above)
17494 ; restore used registers here
17501 \begin_inset LatexCommand \index{\_endasm}
17506 \begin_inset LatexCommand \index{\_\_endasm}
17517 \begin_layout Standard
17518 The inline assembler code can contain any valid code understood by the assembler
17519 , this includes any assembler directives and comment lines.
17520 The assembler does not like some characters like ':' or ''' in comments.
17521 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
17522 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
17527 \begin_inset LatexCommand \index{Assembler documentation}
17532 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
17540 \begin_layout Standard
17541 The compiler does not do any validation of the code within the
17544 \begin_inset LatexCommand \index{\_asm}
17549 \begin_inset LatexCommand \index{\_\_asm}
17557 \begin_inset LatexCommand \index{\_endasm}
17562 \begin_inset LatexCommand \index{\_\_endasm}
17571 Specifically it will not know which registers are used and thus register
17573 \begin_inset LatexCommand \index{push/pop}
17577 has to be done manually.
17581 \begin_layout Standard
17582 It is recommended that each assembly instruction (including labels) be placed
17583 in a separate line (as the example shows).
17588 \begin_layout Standard
17600 \begin_inset LatexCommand \index{-\/-peep-asm}
17606 command line option is used, the inline assembler code will be passed through
17607 the peephole optimizer
17608 \begin_inset LatexCommand \index{Peephole optimizer}
17613 There are only a few (if any) cases where this option makes sense, it might
17614 cause some unexpected changes in the inline assembler code.
17615 Please go through the peephole optimizer rules defined in file
17619 before using this option.
17622 \begin_layout Subsection
17624 \begin_inset LatexCommand \label{sub:Naked-Functions}
17629 \begin_inset LatexCommand \index{Naked functions}
17636 \begin_layout Standard
17637 A special keyword may be associated with a function declaring it as
17640 \begin_inset LatexCommand \index{\_naked}
17645 \begin_inset LatexCommand \index{\_\_naked}
17656 function modifier attribute prevents the compiler from generating prologue
17657 \begin_inset LatexCommand \index{function prologue}
17662 \begin_inset LatexCommand \index{function epilogue}
17666 code for that function.
17667 This means that the user is entirely responsible for such things as saving
17668 any registers that may need to be preserved, selecting the proper register
17669 bank, generating the
17673 instruction at the end, etc.
17674 Practically, this means that the contents of the function must be written
17675 in inline assembler.
17676 This is particularly useful for interrupt functions, which can have a large
17677 (and often unnecessary) prologue/epilogue.
17678 For example, compare the code generated by these two functions:
17681 \begin_layout Verse
17685 \begin_inset LatexCommand \index{volatile}
17689 data unsigned char counter;
17693 void simpleInterrupt(void) __interrupt
17694 \begin_inset LatexCommand \index{interrupt}
17699 \begin_inset LatexCommand \index{\_\_interrupt}
17717 void nakedInterrupt(void) __interrupt (2) __naked
17726 \begin_inset LatexCommand \index{\_asm}
17731 \begin_inset LatexCommand \index{\_\_asm}
17748 _counter ; does not change flags, no need to save psw
17761 include ret or reti in _naked function.
17768 \begin_inset LatexCommand \index{\_endasm}
17773 \begin_inset LatexCommand \index{\_\_endasm}
17782 \begin_layout Standard
17783 For an 8051 target, the generated simpleInterrupt looks like:
17786 \begin_layout Verse
17793 example, recent versions of SDCC generate
17799 code for simpleInterrupt() and nakedInterrupt()!
17940 \begin_layout Standard
17941 whereas nakedInterrupt looks like:
17944 \begin_layout Verse
17957 _counter ; does not change flags, no need to save psw
17976 MUST explicitly include ret or reti in _naked function
17979 \begin_layout Standard
17980 The related directive #pragma exclude
17981 \begin_inset LatexCommand \index{\#pragma exclude}
17985 allows a more fine grained control over pushing & popping
17986 \begin_inset LatexCommand \index{push/pop}
17993 \begin_layout Standard
17994 While there is nothing preventing you from writing C code inside a
17998 function, there are many ways to shoot yourself in the foot doing this,
17999 and it is recommended that you stick to inline assembler.
18002 \begin_layout Subsection
18003 Use of Labels within Inline Assembler
18006 \begin_layout Standard
18007 SDCC allows the use of in-line assembler with a few restrictions regarding
18009 All labels defined within inline assembler code have to be of the form
18014 where nnnnn is a number less than 100 (which implies a limit of utmost
18015 100 inline assembler labels
18026 \begin_layout Standard
18027 This is a slightly more stringent rule than absolutely necessary, but stays
18028 always on the safe side.
18029 Labels in the form of nnnnn$ are local labels in the assembler, locality
18030 of which is confined within two labels of the standard form.
18031 The compiler uses the same form for labels within a function (but starting
18032 from nnnnn=00100); and places always a standard label at the beginning
18033 of a function, thus limiting the locality of labels within the scope of
18035 So, if the inline assembler part would be embedded into C-code, an improperly
18036 placed non-local label in the assembler would break up the reference space
18037 for labels created by the compiler for the C-code, leading to an assembling
18041 \begin_layout Standard
18042 The numeric part of local labels does not need to have 5 digits (although
18043 this is the form of labels output by the compiler), any valid integer will
18045 Please refer to the assemblers documentation for further details.
18053 \begin_layout Verse
18057 \begin_inset LatexCommand \index{\_asm}
18062 \begin_inset LatexCommand \index{\_\_asm}
18092 \begin_inset LatexCommand \index{\_endasm}
18097 \begin_inset LatexCommand \index{\_\_endasm}
18104 \begin_layout Standard
18105 Inline assembler code cannot reference any C-labels, however it can reference
18107 \begin_inset LatexCommand \index{Labels}
18111 defined by the inline assembler, e.g.:
18114 \begin_layout Verse
18137 ; some assembler code
18158 /* some more c code */
18160 clabel:\InsetSpace ~
18162 /* inline assembler cannot reference this
18167 \begin_layout Standard
18172 is translated by the compiler into a local label, so the locality of labels
18173 within the function is not broken.
18190 0003$: ;label (can be referenced by inline assembler only)
18197 \begin_inset LatexCommand \index{\_endasm}
18202 \begin_inset LatexCommand \index{\_\_endasm}
18212 /* some more c code */
18217 \begin_layout Standard
18218 In other words inline assembly code can access labels defined in inline
18219 assembly within the scope of the function.
18220 The same goes the other way, i.e.
18221 labels defines in inline assembly can not be accessed by C statements.
18224 \begin_layout Section
18225 Interfacing with Assembler Code
18226 \begin_inset LatexCommand \index{Assembler routines}
18233 \begin_layout Subsection
18234 Global Registers used for Parameter Passing
18235 \begin_inset LatexCommand \index{Parameter passing}
18242 \begin_layout Standard
18243 The compiler always uses the global registers
18246 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18251 \begin_inset LatexCommand \index{DPTR}
18256 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
18265 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
18271 to pass the first (non-bit) parameter to a function, and also to pass the
18273 \begin_inset LatexCommand \index{return value}
18277 of function; according to the following scheme: one byte return value in
18282 , two byte value in
18291 three byte values (generic pointers) in
18303 , and four byte values in
18321 \begin_inset LatexCommand \index{generic pointer}
18325 contain type of accessed memory in
18346 \begin_inset Note Note
18349 \begin_layout Standard
18350 This might not be the case of certain memory models (medium???)
18358 \begin_layout Standard
18359 The second parameter onwards is either allocated on the stack (for reentrant
18364 \begin_layout Standard
18373 -stack-auto is used) or in data/xdata memory (depending on the memory model).
18376 \begin_layout Standard
18377 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
18378 space for reentrant functions or allocated directly in bit memory otherwise.
18381 \begin_layout Standard
18382 Functions (with two or more parameters or bit parameters) that are called
18383 through function pointers
18384 \begin_inset LatexCommand \index{function pointers}
18388 must therefor be reentrant so the compiler knows how to pass the parameters.
18391 \begin_layout Subsection
18395 \begin_layout Standard
18396 Unless the called function is declared as
18401 \begin_inset LatexCommand \index{naked}
18409 \begin_layout Standard
18419 \begin_inset LatexCommand \index{-\/-callee-saves}
18427 \begin_layout Standard
18436 -all-callee-saves command line option or the corresponding callee_saves
18437 pragma are used, the caller will save the registers (
18441 ) around the call, so the called function can destroy they content freely.
18444 \begin_layout Standard
18445 If the called function is not declared as
18449 , the caller will swap register banks around the call, if caller and callee
18450 use different register banks (having them defined by the
18458 \begin_layout Standard
18459 The called function can also use
18475 observing that they are used for parameter/return value passing.
18478 \begin_layout Subsection
18479 Assembler Routine (non-reentrant)
18482 \begin_layout Standard
18483 In the following example
18484 \begin_inset LatexCommand \index{reentrant}
18489 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
18493 the function c_func calls an assembler routine asm_func, which takes two
18495 \begin_inset LatexCommand \index{function parameter}
18502 \begin_layout Verse
18505 extern int asm_func(unsigned char, unsigned char);
18509 int c_func (unsigned char
18510 i, unsigned char j)
18518 return asm_func(i,j);
18532 return c_func(10,9);
18537 \begin_layout Standard
18538 The corresponding assembler function is:
18541 \begin_layout Verse
18544 .globl _asm_func_PARM_2
18646 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18663 \begin_layout Standard
18664 The parameter naming convention is _<function_name>_PARM_<n>, where n is
18665 the parameter number starting from 1, and counting from the left.
18666 The first parameter is passed in
18682 according to the description above.
18683 The variable name for the second parameter will be _<function_name>_PARM_2.
18688 ble the assembler routine with the following command:
18695 asx8051 -losg asmfunc.asm
18702 Then compile and link the assembler routine to the C source file with the
18710 sdcc cfunc.c asmfunc.rel
18713 \begin_layout Subsection
18714 Assembler Routine (reentrant)
18717 \begin_layout Standard
18719 \begin_inset LatexCommand \index{reentrant}
18724 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18728 the second parameter
18729 \begin_inset LatexCommand \index{function parameter}
18733 onwards will be passed on the stack, the parameters are pushed from right
18735 before the call the second leftmost parameter will be on the top of the
18736 stack (the leftmost parameter is passed in registers).
18737 Here is an example:
18740 \begin_layout Verse
18743 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18748 c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
18757 return asm_func(i,j,k);
18771 return c_func(10,9,8);
18776 \begin_layout Standard
18777 The corresponding (unoptimized) assembler routine is:
18780 \begin_layout Verse
18800 _bp,sp\InsetSpace ~
18806 ;stack contains: _bp, return
18807 address, second parameter, third parameter
18831 a,#0xfd\InsetSpace ~
18837 pointer to the second parameter
18861 a,#0xfc\InsetSpace ~
18867 to the rightmost parameter
18908 result (= sum of all three parameters)
18923 ;return value goes into dptr
18957 \begin_layout Standard
18958 The compiling and linking procedure remains the same, however note the extra
18959 entry & exit linkage required for the assembler code, _bp is the stack
18960 frame pointer and is used to compute the offset into the stack for parameters
18961 and local variables.
18962 \begin_inset VSpace bigskip
18968 \begin_layout Section
18970 \begin_inset LatexCommand \index{int (16 bit)}
18975 \begin_inset LatexCommand \index{long (32 bit)}
18982 \begin_layout Standard
18983 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18984 multiplication and modulus operations are implemented by support routines.
18985 These support routines are all developed in ANSI-C to facilitate porting
18986 to other MCUs, although some model specific assembler optimizations are
18988 The following files contain the described routines, all of them can be
18989 found in <installdir>/share/sdcc/lib.
18994 \begin_layout Standard
18996 \begin_inset Tabular
18997 <lyxtabular version="3" rows="11" columns="2">
18999 <column alignment="left" valignment="top" leftline="true" width="0">
19000 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19001 <row topline="true" bottomline="true">
19002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19005 \begin_layout Standard
19013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19016 \begin_layout Standard
19025 <row topline="true">
19026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19029 \begin_layout Standard
19035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19038 \begin_layout Standard
19039 16 bit multiplication
19045 <row topline="true">
19046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19049 \begin_layout Standard
19055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19058 \begin_layout Standard
19059 signed 16 bit division (calls _divuint)
19065 <row topline="true">
19066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19069 \begin_layout Standard
19075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19078 \begin_layout Standard
19079 unsigned 16 bit division
19085 <row topline="true">
19086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19089 \begin_layout Standard
19095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19098 \begin_layout Standard
19099 signed 16 bit modulus (calls _moduint)
19105 <row topline="true">
19106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19109 \begin_layout Standard
19115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19118 \begin_layout Standard
19119 unsigned 16 bit modulus
19125 <row topline="true">
19126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19129 \begin_layout Standard
19135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19138 \begin_layout Standard
19139 32 bit multiplication
19145 <row topline="true">
19146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19149 \begin_layout Standard
19155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19158 \begin_layout Standard
19159 signed 32 division (calls _divulong)
19165 <row topline="true">
19166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19169 \begin_layout Standard
19175 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19178 \begin_layout Standard
19179 unsigned 32 division
19185 <row topline="true">
19186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19189 \begin_layout Standard
19195 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19198 \begin_layout Standard
19199 signed 32 bit modulus (calls _modulong)
19205 <row topline="true" bottomline="true">
19206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19209 \begin_layout Standard
19215 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19218 \begin_layout Standard
19219 unsigned 32 bit modulus
19234 \begin_layout Standard
19235 Since they are compiled as
19240 \begin_inset LatexCommand \index{reentrant}
19245 \begin_inset LatexCommand \index{interrupt}
19249 service routines should not do any of the above operations.
19250 If this is unavoidable then the above routines will need to be compiled
19257 \begin_layout Standard
19267 \begin_inset LatexCommand \index{-\/-stack-auto}
19273 option, after which the source program will have to be compiled with
19279 \begin_layout Standard
19289 \begin_inset LatexCommand \index{-\/-int-long-reent}
19296 Notice that you don't have to call these routines directly.
19297 The compiler will use them automatically every time an integer operation
19301 \begin_layout Section
19302 Floating Point Support
19303 \begin_inset LatexCommand \index{Floating point support}
19310 \begin_layout Standard
19311 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
19312 The floating point support routines are derived from gcc's floatlib.c and
19313 consist of the following routines:
19318 \begin_layout Standard
19322 \begin_inset Tabular
19323 <lyxtabular version="3" rows="17" columns="2">
19325 <column alignment="left" valignment="top" leftline="true" width="0">
19326 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19327 <row topline="true" bottomline="true">
19328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19331 \begin_layout Standard
19346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19349 \begin_layout Standard
19356 <row topline="true">
19357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19360 \begin_layout Standard
19375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19378 \begin_layout Standard
19388 add floating point numbers
19394 <row topline="true">
19395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19398 \begin_layout Standard
19413 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19416 \begin_layout Standard
19426 subtract floating point numbers
19432 <row topline="true">
19433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19436 \begin_layout Standard
19451 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19454 \begin_layout Standard
19464 divide floating point numbers
19470 <row topline="true">
19471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19474 \begin_layout Standard
19489 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19492 \begin_layout Standard
19502 multiply floating point numbers
19508 <row topline="true">
19509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19512 \begin_layout Standard
19527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19530 \begin_layout Standard
19540 convert floating point to unsigned char
19546 <row topline="true">
19547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19550 \begin_layout Standard
19565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19568 \begin_layout Standard
19578 convert floating point to signed char
19584 <row topline="true">
19585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19588 \begin_layout Standard
19603 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19606 \begin_layout Standard
19616 convert floating point to unsigned int
19622 <row topline="true">
19623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19626 \begin_layout Standard
19641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19644 \begin_layout Standard
19654 convert floating point to signed int
19660 <row topline="true">
19661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19664 \begin_layout Standard
19687 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19690 \begin_layout Standard
19700 convert floating point to unsigned long
19706 <row topline="true">
19707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19710 \begin_layout Standard
19725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19728 \begin_layout Standard
19738 convert floating point to signed long
19744 <row topline="true">
19745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19748 \begin_layout Standard
19763 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19766 \begin_layout Standard
19776 convert unsigned char to floating point
19782 <row topline="true">
19783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19786 \begin_layout Standard
19801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19804 \begin_layout Standard
19814 convert char to floating point number
19820 <row topline="true">
19821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19824 \begin_layout Standard
19839 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19842 \begin_layout Standard
19852 convert unsigned int to floating point
19858 <row topline="true">
19859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19862 \begin_layout Standard
19877 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19880 \begin_layout Standard
19890 convert int to floating point numbers
19896 <row topline="true">
19897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19900 \begin_layout Standard
19915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19918 \begin_layout Standard
19928 convert unsigned long to floating point number
19934 <row topline="true" bottomline="true">
19935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19938 \begin_layout Standard
19953 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19956 \begin_layout Standard
19966 convert long to floating point number
19981 \begin_layout Standard
19982 These support routines are developed in ANSI-C so there is room for space
19983 and speed improvement
19987 \begin_layout Standard
19988 These floating point routines (
19992 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19999 Note if all these routines are used simultaneously the data space might
20001 For serious floating point usage the large model might be needed.
20002 Also notice that you don't have to call this routines directly.
20003 The compiler will use them automatically every time a floating point operation
20005 \begin_inset VSpace bigskip
20011 \begin_layout Section
20013 \begin_inset LatexCommand \index{Libraries}
20020 \begin_layout Standard
20023 <pending: this is messy and incomplete - a little more information is in
20024 sdcc/doc/libdoc.txt
20029 \begin_layout Subsection
20030 Compiler support routines (_gptrget, _mulint etc.)
20033 \begin_layout Subsection
20034 Stdclib functions (puts, printf, strcat etc.)
20037 \begin_layout Subsubsection
20041 \begin_layout Paragraph
20042 getchar(), putchar()
20045 \begin_layout Standard
20046 \begin_inset LatexCommand \index{<stdio.h>}
20050 As usual on embedded systems you have to provide your own
20053 \begin_inset LatexCommand \index{getchar()}
20062 \begin_inset LatexCommand \index{putchar()}
20069 SDCC does not know whether the system connects to a serial line with or
20070 without handshake, LCD, keyboard or other device.
20084 You'll find examples for serial routines f.e.
20085 in sdcc/device/lib.
20086 For the mcs51 this minimalistic polling
20090 routine might be a start:
20093 \begin_layout Verse
20096 void putchar (char c) {
20102 while (!TI)\InsetSpace ~
20105 /* assumes UART is initialized */
20133 \begin_layout Paragraph
20137 \begin_layout Standard
20141 \begin_inset LatexCommand \index{printf()}
20151 does not support float (except on ds390).
20152 To enable this recompile it with the option
20158 \begin_layout Standard
20168 \begin_inset LatexCommand \index{USE\_FLOATS}
20174 on the command line.
20181 \begin_layout Standard
20191 \begin_inset LatexCommand \index{-\/-model-large}
20197 for the mcs51 port, since this uses a lot of memory.
20200 \begin_layout Standard
20201 If you're short on code memory you might want to use
20204 \begin_inset LatexCommand \index{printf\_small()}
20219 For the mcs51 there additionally are assembly versions
20222 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
20228 (subset of printf using less than 270 bytes) and
20231 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
20240 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
20246 (floating-point aware version of printf_fast) which should fit the requirements
20247 of many embedded systems (printf_fast() can be customized by unsetting
20252 support long variables and field widths).
20253 Be sure to use only one of these printf options within a project.
20258 \begin_layout Standard
20259 Feature matrix of different
20266 \begin_layout Standard
20267 \begin_inset Tabular
20268 <lyxtabular version="3" rows="14" columns="7">
20269 <features islongtable="true">
20270 <column alignment="left" valignment="middle" leftline="true" width="14col%">
20271 <column alignment="center" valignment="top" leftline="true" width="0">
20272 <column alignment="center" valignment="top" leftline="true" width="12col%">
20273 <column alignment="center" valignment="top" leftline="true" width="10col%">
20274 <column alignment="center" valignment="top" leftline="true" width="0">
20275 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
20276 <column alignment="center" valignment="top" rightline="true" width="0">
20277 <row topline="true" bottomline="true" endhead="true">
20278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20281 \begin_layout Standard
20290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20293 \begin_layout Standard
20295 \begin_inset LatexCommand \index{printf}
20304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20307 \begin_layout Standard
20315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20318 \begin_layout Standard
20324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20327 \begin_layout Standard
20333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20336 \begin_layout Standard
20342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20345 \begin_layout Standard
20352 <row topline="true" endhead="true">
20353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20356 \begin_layout Standard
20362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20365 \begin_layout Standard
20373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20376 \begin_layout Standard
20384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20387 \begin_layout Standard
20395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20398 \begin_layout Standard
20406 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20409 \begin_layout Standard
20417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20420 \begin_layout Standard
20429 <row topline="true" endhead="true">
20430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20433 \begin_layout Standard
20434 \begin_inset Quotes sld
20438 \begin_inset Quotes srd
20444 \begin_layout Standard
20450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20453 \begin_layout Standard
20459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20462 \begin_layout Standard
20468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20471 \begin_layout Standard
20477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20480 \begin_layout Standard
20486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20489 \begin_layout Standard
20495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20498 \begin_layout Standard
20505 <row topline="true" endhead="true">
20506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20509 \begin_layout Standard
20513 \begin_layout Standard
20519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20522 \begin_layout Standard
20528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20531 \begin_layout Standard
20537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20540 \begin_layout Standard
20541 0.45k / 0.47k (+ _ltoa)
20546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20549 \begin_layout Standard
20555 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20558 \begin_layout Standard
20564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20567 \begin_layout Standard
20574 <row topline="true">
20575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20578 \begin_layout Standard
20584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20587 \begin_layout Standard
20597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20600 \begin_layout Standard
20647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20650 \begin_layout Standard
20689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20692 \begin_layout Standard
20698 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20701 \begin_layout Standard
20707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20710 \begin_layout Standard
20717 <row topline="true">
20718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20721 \begin_layout Standard
20722 long (32 bit) support
20727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20730 \begin_layout Standard
20736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20739 \begin_layout Standard
20745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20748 \begin_layout Standard
20754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20757 \begin_layout Standard
20763 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20766 \begin_layout Standard
20781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20784 \begin_layout Standard
20791 <row topline="true">
20792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20795 \begin_layout Standard
20796 byte arguments on stack
20801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20804 \begin_layout Standard
20810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20813 \begin_layout Standard
20819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20822 \begin_layout Standard
20828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20831 \begin_layout Standard
20837 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20840 \begin_layout Standard
20846 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20849 \begin_layout Standard
20856 <row topline="true">
20857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20860 \begin_layout Standard
20862 \begin_inset LatexCommand \index{Floating point support}
20871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20874 \begin_layout Standard
20880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20883 \begin_layout Standard
20889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20892 \begin_layout Standard
20898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20901 \begin_layout Standard
20907 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20910 \begin_layout Standard
20915 \begin_layout Standard
20916 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20926 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20929 \begin_layout Standard
20936 <row topline="true">
20937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20940 \begin_layout Standard
20941 float formats %e %g
20946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20949 \begin_layout Standard
20955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20958 \begin_layout Standard
20964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20967 \begin_layout Standard
20973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20976 \begin_layout Standard
20982 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20985 \begin_layout Standard
20991 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20994 \begin_layout Standard
21001 <row topline="true" bottomline="true">
21002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21005 \begin_layout Standard
21011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21014 \begin_layout Standard
21020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21023 \begin_layout Standard
21029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21032 \begin_layout Standard
21038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21041 \begin_layout Standard
21047 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21050 \begin_layout Standard
21056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21059 \begin_layout Standard
21066 <row bottomline="true">
21067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21070 \begin_layout Standard
21075 \begin_layout Standard
21076 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
21080 n'); standard 8051 @ 22.1184 MHz, empty putchar()
21088 \begin_layout Standard
21094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21097 \begin_layout Standard
21103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21106 \begin_layout Standard
21112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21115 \begin_layout Standard
21121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21124 \begin_layout Standard
21130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21133 \begin_layout Standard
21139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21142 \begin_layout Standard
21149 <row bottomline="true">
21150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21153 \begin_layout Standard
21158 \begin_layout Standard
21159 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
21168 \begin_layout Standard
21174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21177 \begin_layout Standard
21183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21186 \begin_layout Standard
21192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21195 \begin_layout Standard
21201 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21204 \begin_layout Standard
21210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21213 \begin_layout Standard
21219 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21222 \begin_layout Standard
21227 \begin_layout Standard
21228 printf_tiny integer speed is data dependent, worst case is 0.33 ms
21239 <row bottomline="true">
21240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21243 \begin_layout Standard
21248 \begin_layout Standard
21249 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
21258 \begin_layout Standard
21264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21267 \begin_layout Standard
21273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21276 \begin_layout Standard
21282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21285 \begin_layout Standard
21291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21294 \begin_layout Standard
21300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21303 \begin_layout Standard
21309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21312 \begin_layout Standard
21319 <row bottomline="true">
21320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21323 \begin_layout Standard
21328 \begin_layout Standard
21329 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
21338 \begin_layout Standard
21344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21347 \begin_layout Standard
21353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21356 \begin_layout Standard
21362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21365 \begin_layout Standard
21371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21374 \begin_layout Standard
21380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21383 \begin_layout Standard
21389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21392 \begin_layout Standard
21406 \begin_layout Subsubsection
21408 \begin_inset LatexCommand \index{malloc.h}
21415 \begin_layout Standard
21416 As of SDCC 2.6.2 you no longer need to call an initialization routine before
21417 using dynamic memory allocation
21418 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
21423 \begin_inset LatexCommand \index{heap (malloc)}
21427 space of 1024 bytes is provided for malloc to allocate memory from.
21428 If you need a different heap size you need to recompile _heap.c with the
21429 required size defined in HEAP_SIZE.
21430 It is recommended to make a copy of this file into your project directory
21431 and compile it there with:
21434 \begin_layout Verse
21437 sdcc -c _heap.c -D HEAD_SIZE=2048
21440 \begin_layout Standard
21441 And then link it with:
21444 \begin_layout Verse
21447 sdcc main.rel _heap.rel
21450 \begin_layout Subsection
21451 Math functions (sinf, powf, sqrtf etc.)
21454 \begin_layout Subsubsection
21458 \begin_layout Standard
21459 See definitions in file <math.h>.
21462 \begin_layout Subsection
21466 \begin_layout Standard
21468 \begin_inset LatexCommand \index{Libraries}
21472 included in SDCC should have a license at least as liberal as the GNU Lesser
21473 General Public License
21474 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
21485 \begin_layout Standard
21486 \begin_inset Note Note
21489 \begin_layout Standard
21490 license statements for the libraries are missing.
21491 sdcc/device/lib/ser_ir.c
21494 \begin_layout Standard
21496 come with a GPL (as opposed to LGPL) License - this will not be liberal
21497 enough for many embedded programmers.
21505 \begin_layout Standard
21506 If you have ported some library or want to share experience about some code
21508 falls into any of these categories Busses (I
21509 \begin_inset Formula $^{\textrm{2}}$
21512 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
21513 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
21514 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
21515 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
21520 would certainly like to hear about it.
21523 \begin_layout Standard
21524 Programmers coding for embedded systems are not especially famous for being
21525 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
21526 e these references are very valuable.
21527 Let's help to create a climate where information is shared.
21528 \begin_inset VSpace bigskip
21534 \begin_layout Section
21538 \begin_layout Subsection
21539 MCS51 Memory Models
21540 \begin_inset LatexCommand \index{Memory model}
21545 \begin_inset LatexCommand \index{MCS51 memory model}
21552 \begin_layout Subsubsection
21553 Small, Medium and Large
21556 \begin_layout Standard
21557 SDCC allows three memory models for MCS51 code,
21566 Modules compiled with different memory models should
21570 be combined together or the results would be unpredictable.
21571 The library routines supplied with the compiler are compiled as small,
21573 The compiled library modules are contained in separate directories as small,
21574 medium and large so that you can link to the appropriate set.
21577 \begin_layout Standard
21578 When the medium or large model is used all variables declared without a
21579 storage class will be allocated into the external ram, this includes all
21580 parameters and local variables (for non-reentrant
21581 \begin_inset LatexCommand \index{reentrant}
21586 When the small model is used variables without storage class are allocated
21587 in the internal ram.
21590 \begin_layout Standard
21591 Judicious usage of the processor specific storage classes
21592 \begin_inset LatexCommand \index{Storage class}
21596 and the 'reentrant' function type will yield much more efficient code,
21597 than using the large model.
21598 Several optimizations are disabled when the program is compiled using the
21599 large model, it is therefore recommended that the small model be used unless
21600 absolutely required.
21603 \begin_layout Subsubsection
21605 \begin_inset LatexCommand \label{sub:External-Stack}
21610 \begin_inset LatexCommand \index{stack}
21615 \begin_inset LatexCommand \index{External stack (mcs51)}
21622 \begin_layout Standard
21623 The external stack (-
21627 \begin_layout Standard
21637 \begin_inset LatexCommand \index{-\/-xstack}
21641 ) is located in pdata
21642 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
21646 memory (usually at the start of the external ram segment) and uses all
21647 unused space in pdata (max.
21653 \begin_layout Standard
21662 -xstack option is used to compile the program, the parameters and local
21664 \begin_inset LatexCommand \index{local variables}
21668 of all reentrant functions are allocated in this area.
21669 This option is provided for programs with large stack space requirements.
21670 When used with the -
21674 \begin_layout Standard
21684 \begin_inset LatexCommand \index{-\/-stack-auto}
21688 option, all parameters and local variables are allocated on the external
21689 stack (note: support libraries will need to be recompiled with the same
21691 There is a predefined target in the library makefile).
21694 \begin_layout Standard
21695 The compiler outputs the higher order address byte of the external ram segment
21697 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21702 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21706 ), therefore when using the External Stack option, this port
21710 be used by the application program.
21713 \begin_layout Subsection
21715 \begin_inset LatexCommand \index{Memory model}
21720 \begin_inset LatexCommand \index{DS390 memory model}
21727 \begin_layout Standard
21728 The only model supported is Flat 24
21729 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21734 This generates code for the 24 bit contiguous addressing mode of the Dallas
21736 In this mode, up to four meg of external RAM or code space can be directly
21738 See the data sheets at www.dalsemi.com for further information on this part.
21743 that the compiler does not generate any code to place the processor into
21744 24 bitmode (although
21748 in the ds390 libraries will do that for you).
21754 \begin_inset LatexCommand \index{Tinibios (DS390)}
21758 , the boot loader or similar code must ensure that the processor is in 24
21759 bit contiguous addressing mode before calling the SDCC startup code.
21770 \begin_layout Standard
21781 option, variables will by default be placed into the XDATA segment.
21786 Segments may be placed anywhere in the 4 meg address space using the usual
21791 \begin_layout Standard
21801 Note that if any segments are located above 64K, the -r flag must be passed
21802 to the linker to generate the proper segment relocations, and the Intel
21803 HEX output format must be used.
21804 The -r flag can be passed to the linker by using the option
21808 on the SDCC command line.
21809 However, currently the linker can not handle code segments > 64k.
21812 \begin_layout Section
21814 \begin_inset LatexCommand \label{sec:Pragmas}
21819 \begin_inset LatexCommand \index{Pragmas}
21826 \begin_layout Standard
21827 Pragmas are used to turn on and/or off certain compiler options.
21828 Some of them are closely related to corresponding command-line options
21830 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21836 Pragmas should be placed before and/or after a function, placing pragmas
21837 inside a function body could have unpredictable results.
21842 following #pragma directives:
21845 \begin_layout Itemize
21851 \begin_inset LatexCommand \index{\#pragma save}
21855 - this will save most current options to the save/restore stack.
21856 See #pragma\InsetSpace ~
21860 \begin_layout Itemize
21866 \begin_inset LatexCommand \index{\#pragma restore}
21870 - will restore saved options from the last save.
21871 saves & restores can be nested.
21872 SDCC uses a save/restore stack: save pushes current options to the stack,
21873 restore pulls current options from the stack.
21874 See #pragma\InsetSpace ~
21880 \begin_layout Itemize
21886 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21891 \begin_inset LatexCommand \index{function prologue}
21895 function1[,function2[,function3...]]
21896 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21900 - The compiler by default uses a caller saves convention for register saving
21901 across function calls, however this can cause unnecessary register pushing
21903 \begin_inset LatexCommand \index{push/pop}
21907 when calling small functions from larger functions.
21908 This option can be used to switch off the register saving convention for
21909 the function names specified.
21910 The compiler will not save registers when calling these functions, extra
21911 code need to be manually inserted at the entry and exit for these functions
21912 to save and restore the registers used by these functions, this can SUBSTANTIAL
21913 LY reduce code and improve run time performance of the generated code.
21914 In the future the compiler (with inter procedural analysis) may be able
21915 to determine the appropriate scheme to use for each function call.
21920 \begin_layout Standard
21929 -callee-saves command line option is used (see page
21930 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21934 ), the function names specified in #pragma\InsetSpace ~
21936 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21940 is appended to the list of functions specified in the command line.
21943 \begin_layout Itemize
21949 \begin_inset LatexCommand \index{\#pragma exclude}
21953 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21954 of pairs of push/pop
21955 \begin_inset LatexCommand \index{push/pop}
21964 \begin_inset LatexCommand \index{interrupt}
21977 The directive should be placed immediately before the ISR function definition
21978 and it affects ALL ISR functions following it.
21979 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21980 exclude\InsetSpace ~
21982 \begin_inset LatexCommand \index{\#pragma exclude}
21987 See also the related keyword _naked
21988 \begin_inset LatexCommand \index{\_naked}
21993 \begin_inset LatexCommand \index{\_\_naked}
22000 \begin_layout Itemize
22006 \begin_inset LatexCommand \index{pedantic}
22011 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
22016 \begin_inset LatexCommand \label{ite:less_pedantic}
22020 - the compiler will not warn you anymore for obvious mistakes, you're on
22022 See also the command line option -
22026 \begin_layout Standard
22036 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
22043 More specifically, the following warnings will be disabled:
22045 comparison is always [true/false] due to limited range of data type
22049 overflow in implicit constant conversion
22051 (158); [the (in)famous]
22053 conditional flow changed by optimizer: so said EVELYN the modified DOG
22057 function '[function name]' must return value
22062 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
22063 level) are disabled, too, namely:
22066 \begin_inset Note Note
22069 \begin_layout Standard
22070 dunno what comes here - this warning appears to be unused altogether
22079 [left/right] shifting more than size of object changed to zero
22087 integer overflow in expression
22091 unmatched #pragma save and #pragma restore
22095 comparison of 'signed char' with 'unsigned char' requires promotion to int
22099 ISO C90 does not support flexible array members
22103 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
22107 \begin_inset Note Note
22110 \begin_layout Standard
22111 appears to be always blank - what was supposed to be here?
22120 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
22121 complexity [number]
22126 \begin_layout Itemize
22132 \begin_inset LatexCommand \index{\#pragma disable\_warning}
22136 - the compiler will not warn you anymore about warning number <nnnn>.
22139 \begin_layout Itemize
22145 \begin_inset LatexCommand \index{\#pragma nogcse}
22149 - will stop global common subexpression elimination.
22152 \begin_layout Itemize
22158 \begin_inset LatexCommand \index{\#pragma noinduction}
22162 - will stop loop induction optimizations.
22165 \begin_layout Itemize
22171 \begin_inset LatexCommand \index{\#pragma noinvariant}
22175 - will not do loop invariant optimizations.
22176 For more details see Loop Invariants in section
22177 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
22184 \begin_layout Itemize
22190 \begin_inset LatexCommand \index{\#pragma noiv}
22194 - Do not generate interrupt
22195 \begin_inset LatexCommand \index{interrupt}
22200 \begin_inset LatexCommand \index{interrupt vector table}
22204 entries for all ISR functions defined after the pragma.
22205 This is useful in cases where the interrupt vector table must be defined
22206 manually, or when there is a secondary, manually defined interrupt vector
22208 for the autovector feature of the Cypress EZ-USB FX2).
22209 More elegantly this can be achieved by obmitting the optional interrupt
22210 number after the interrupt keyword, see section
22211 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
22219 \begin_layout Itemize
22225 \begin_inset LatexCommand \index{\#pragma nojtbound}
22229 - will not generate code for boundary value checking, when switch statements
22230 are turned into jump-tables (dangerous).
22231 For more details see section
22232 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
22239 \begin_layout Itemize
22245 \begin_inset LatexCommand \index{\#pragma noloopreverse}
22249 - Will not do loop reversal optimization
22252 \begin_layout Itemize
22258 \begin_inset LatexCommand \index{\#pragma nooverlay}
22262 - the compiler will not overlay the parameters and local variables of a
22266 \begin_layout Itemize
22272 \begin_inset LatexCommand \index{\#pragma stackauto}
22280 \begin_layout Standard
22290 \begin_inset LatexCommand \index{-\/-stack-auto}
22295 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
22299 Parameters and Local Variables.
22302 \begin_layout Itemize
22308 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
22312 - The compiler will optimize code generation towards fast code, possibly
22313 at the expense of code size.
22314 Currently this has little effect.
22317 \begin_layout Itemize
22323 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
22327 - The compiler will optimize code generation towards compact code, possibly
22328 at the expense of code speed.
22329 Currently this has little effect.
22332 \begin_layout Itemize
22338 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
22342 - The compiler will attempt to generate code that is both compact and fast,
22343 as long as meeting one goal is not a detriment to the other (this is the
22348 \begin_layout Itemize
22354 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
22358 - Generally follow the C89 standard, but allow SDCC features that conflict
22359 with the standard (default).
22362 \begin_layout Itemize
22368 \begin_inset LatexCommand \index{\#pragma std\_c89}
22372 - Follow the C89 standard and disable SDCC features that conflict with the
22376 \begin_layout Itemize
22382 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
22386 - Generally follow the C99 standard, but allow SDCC features that conflict
22387 with the standard (incomplete support).
22390 \begin_layout Itemize
22396 \begin_inset LatexCommand \index{\#pragma std\_c99}
22400 - Follow the C99 standard and disable SDCC features that conflict with the
22401 standard (incomplete support).
22404 \begin_layout Itemize
22410 \begin_inset LatexCommand \index{\#pragma codeseg}
22414 - Use this name (max.
22415 8 characters) for the code segment.
22420 \begin_layout Standard
22432 \begin_layout Itemize
22438 \begin_inset LatexCommand \index{\#pragma constseg}
22442 - Use this name (max.
22443 8 characters) for the const segment.
22448 \begin_layout Standard
22460 \begin_layout Standard
22461 The preprocessor SDCPP
22462 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
22466 supports the following #pragma directives:
22469 \begin_layout Itemize
22472 pedantic_parse_number
22475 \begin_inset LatexCommand \index{pedantic}
22480 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22485 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
22489 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
22490 properly and the macro LO_B(3) gets expanded.
22496 \begin_layout Standard
22505 -pedantic-parse-number command line option
22506 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
22513 Below is an example on how to use this pragma.
22516 Note: this functionality is not in conformance with standard!
22519 \begin_layout Verse
22522 #pragma pedantic_parse_number +
22523 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22531 #define LO_B(x) ((x) & 0xff)
22535 unsigned char foo(void)
22542 unsigned char c=0xfe-LO_B(3)
22557 \begin_layout Itemize
22563 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22567 (+ | -) - switch _asm _endasm block preprocessing on / off.
22569 You use this prama to define multilines of assembly code.
22570 This will prevent the preprocessor from changing the formating required
22572 Below is an example on how to use this pragma.
22575 \begin_layout Verse
22578 #pragma preproc_asm -
22579 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22585 #define MYDELAY _asm
22590 nop ;my assembly comment...
22604 #pragma preproc_asm
22635 \begin_layout Itemize
22641 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22645 (+ | -) - Allow "naked" hash in macro definition, for example:
22649 #define DIR_LO(x) #(x & 0xff)
22654 Below is an example on how to use this pragma.
22657 \begin_layout Verse
22660 #pragma preproc_asm +
22662 #pragma sdcc_hash +
22663 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22678 mov R6_B3, #(x & 0xff)
22685 mov R7_B3, #((x >> 8) & 0xff)
22709 \begin_layout Standard
22710 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22711 ons which might cause the compiler to generate extra stack and/or data space
22712 to store compiler generated temporary variables.
22713 This usually happens in large functions.
22714 Pragma directives should be used as shown in the following example, they
22715 are used to control options and optimizations for a given function.
22719 \begin_layout Verse
22723 \begin_inset LatexCommand \index{\#pragma save}
22734 /* save the current settings */
22737 \begin_inset LatexCommand \index{\#pragma nogcse}
22746 /* turnoff global subexpression elimination */
22748 #pragma noinduction
22749 \begin_inset LatexCommand \index{\#pragma noinduction}
22753 /* turn off induction optimizations */
22776 \begin_inset LatexCommand \index{\#pragma restore}
22780 /* turn the optimizations back on */
22783 \begin_layout Standard
22784 The compiler will generate a warning message when extra space is allocated.
22785 It is strongly recommended that the save and restore pragmas be used when
22786 changing options for a function.
22795 \begin_layout Section
22796 Defines Created by the Compiler
22799 \begin_layout Standard
22800 The compiler creates the following #defines
22801 \begin_inset LatexCommand \index{\#defines}
22806 \begin_inset LatexCommand \index{Defines created by the compiler}
22815 \begin_layout Standard
22816 \begin_inset Tabular
22817 <lyxtabular version="3" rows="15" columns="2">
22819 <column alignment="left" valignment="top" leftline="true" width="3in">
22820 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22821 <row topline="true" bottomline="true">
22822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22825 \begin_layout Standard
22833 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22836 \begin_layout Standard
22845 <row topline="true">
22846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22849 \begin_layout Standard
22851 \begin_inset LatexCommand \index{SDCC}
22860 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22863 \begin_layout Standard
22865 Since version 2.5.6 the version number as an int (ex.
22872 <row topline="true">
22873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22876 \begin_layout Standard
22878 \begin_inset LatexCommand \index{SDCC\_mcs51}
22883 \begin_inset LatexCommand \index{SDCC\_ds390}
22888 \begin_inset LatexCommand \index{SDCC\_z80}
22897 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22900 \begin_layout Standard
22901 depending on the model used (e.g.: -mds390)
22907 <row topline="true">
22908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22911 \begin_layout Standard
22913 \begin_inset LatexCommand \index{\_\_mcs51}
22918 \begin_inset LatexCommand \index{\_\_ds390}
22923 \begin_inset LatexCommand \index{\_\_hc08}
22928 \begin_inset LatexCommand \index{\_\_z80}
22937 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22940 \begin_layout Standard
22941 depending on the model used (e.g.
22948 <row topline="true">
22949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22952 \begin_layout Standard
22954 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22963 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22966 \begin_layout Standard
22973 \begin_layout Standard
22990 <row topline="true">
22991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22994 \begin_layout Standard
22996 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
23005 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23008 \begin_layout Standard
23015 \begin_layout Standard
23032 <row topline="true">
23033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23036 \begin_layout Standard
23038 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
23047 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23050 \begin_layout Standard
23057 \begin_layout Standard
23074 <row topline="true">
23075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23078 \begin_layout Standard
23080 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
23089 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23092 \begin_layout Standard
23099 \begin_layout Standard
23116 <row topline="true">
23117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23120 \begin_layout Standard
23122 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
23131 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23134 \begin_layout Standard
23141 \begin_layout Standard
23158 <row topline="true">
23159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23162 \begin_layout Standard
23164 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
23173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23176 \begin_layout Standard
23187 <row topline="true">
23188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23191 \begin_layout Standard
23193 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23205 \begin_layout Standard
23216 <row topline="true">
23217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23220 \begin_layout Standard
23222 \begin_inset LatexCommand \index{SDCC\_REVISION}
23231 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23234 \begin_layout Standard
23236 SDCC svn revision number
23242 <row topline="true">
23243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23246 \begin_layout Standard
23247 SDCC_PARMS_IN_BANK1
23248 \begin_inset LatexCommand \index{SDCC\_PARMS\_IN\_BANK1}
23257 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23260 \begin_layout Standard
23267 \begin_layout Standard
23284 <row topline="true">
23285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23288 \begin_layout Standard
23290 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23302 \begin_layout Standard
23309 \begin_layout Standard
23326 <row topline="true" bottomline="true">
23327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23330 \begin_layout Standard
23331 SDCC_INT_LONG_REENT
23332 \begin_inset LatexCommand \index{SDCC\_INT\_LONG\_REENT}
23341 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23344 \begin_layout Standard
23351 \begin_layout Standard
23375 \begin_layout Chapter
23376 Notes on supported Processors
23379 \begin_layout Section
23381 \begin_inset LatexCommand \label{sub:MCS51-variants}
23386 \begin_inset LatexCommand \index{MCS51 variants}
23393 \begin_layout Standard
23394 MCS51 processors are available from many vendors and come in many different
23396 While they might differ considerably in respect to Special Function Registers
23397 the core MCS51 is usually not modified or is kept compatible.
23401 \begin_layout Subsection
23402 pdata access by SFR
23405 \begin_layout Standard
23406 With the upcome of devices with internal xdata and flash memory devices
23408 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
23412 as dedicated I/O port is becoming more popular.
23413 Switching the high byte for pdata
23414 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
23418 access which was formerly done by port P2 is then achieved by a Special
23420 \begin_inset LatexCommand \index{sfr}
23425 In well-established MCS51 tradition the address of this
23429 is where the chip designers decided to put it.
23430 Needless to say that they didn't agree on a common name either.
23431 So that the startup code can correctly initialize xdata variables, you
23432 should define an sfr with the name _XPAGE
23435 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
23441 at the appropriate location if the default, port P2, is not used for this.
23445 \begin_layout Verse
23448 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
23452 \begin_layout Verse
23455 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
23460 \begin_layout Verse
23463 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
23467 \begin_layout Verse
23470 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23474 \begin_layout Verse
23477 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23481 \begin_layout Standard
23482 For more exotic implementations further customizations may be needed.
23484 \begin_inset LatexCommand \ref{sub:Startup-Code}
23488 for other possibilities.
23491 \begin_layout Subsection
23492 Other Features available by SFR
23495 \begin_layout Standard
23496 Some MCS51 variants offer features like Double DPTR
23497 \begin_inset LatexCommand \index{DPTR}
23501 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
23502 These are currently not used for the MCS51 port.
23503 If you absolutely need them you can fall back to inline assembly or submit
23507 \begin_layout Subsection
23511 \begin_layout Standard
23513 \begin_inset LatexCommand \index{Bankswitching}
23519 \begin_inset LatexCommand \index{code banking}
23523 ) is a technique to increase the code space above the 64k limit of the 8051.
23526 \begin_layout Subsubsection
23530 \begin_layout Standard
23531 \begin_inset Tabular
23532 <lyxtabular version="3" rows="3" columns="4">
23534 <column alignment="center" valignment="top" width="0">
23535 <column alignment="center" valignment="top" leftline="true" width="0">
23536 <column alignment="center" valignment="top" leftline="true" width="0">
23537 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23538 <row topline="true" bottomline="true">
23539 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23542 \begin_layout Standard
23548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23551 \begin_layout Standard
23557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23560 \begin_layout Standard
23566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23569 \begin_layout Standard
23576 <row topline="true" bottomline="true">
23577 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23580 \begin_layout Standard
23586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23589 \begin_layout Standard
23595 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23598 \begin_layout Standard
23604 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23607 \begin_layout Standard
23615 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23618 \begin_layout Standard
23619 SiLabs C8051F120 example
23624 <cell multicolumn="2" alignment="center" valignment="top" usebox="none">
23627 \begin_layout Standard
23633 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23636 \begin_layout Standard
23642 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23645 \begin_layout Standard
23660 Usually the hardware uses some sfr (an output port or an internal sfr) to
23661 select a bank and put it in the banked area of the memory map.
23662 The selected bank usually becomes active immediately upon assignment to
23663 this sfr and when running inside a bank it will switch out this code it
23664 is currently running.
23665 Therefor you cannot jump or call directly from one bank to another and
23666 need to use a so-called trampoline in the common area.
23667 For SDCC an example trampoline is in crtbank.asm and you may need to change
23668 it to your 8051 derivative or schematic.
23669 The presented code is written for the C8051F120.
23673 When calling a banked function
23674 SDCC will put the LSB of the functions address in register R0, the MSB
23675 in R1 and the bank in R2 and then call this trampoline
23680 The current selected bank is saved on the stack, the new bank is selected
23681 and an indirect jump is made.
23682 When the banked function returns it jumps to
23686 which restores the previous bank and returns to the caller.
23689 \begin_layout Subsubsection
23693 \begin_layout Standard
23694 When writing banked software using SDCC you need to use some special keywords
23696 You also need to take over a bit of work from the linker.
23700 To create a function
23701 that can be called from another bank it requires the keyword
23706 \begin_inset LatexCommand \index{banked}
23711 The caller must see this in the prototype of the callee and the callee
23712 needs it for a proper return.
23713 Called functions within the same bank as the caller do not need the
23717 keyword nor do functions in the common area.
23718 Beware: SDCC does not know or check if functions are in the same bank.
23719 This is your responsibility!
23723 Normally all functions you write end up in
23725 If you want a function explicitly to reside in the common area put it in
23727 This applies for instance to interrupt service routines as they should
23731 \begin_layout Standard
23732 Functions that need to be in a switched bank must be put in a named segment.
23733 The name can be mostly anything upto eight characters (e.g.
23735 To do this you either use -
23739 \begin_layout Standard
23748 -codeseg BANK1 (See
23749 \begin_inset LatexCommand \ref{lyx:-codeseg}
23753 ) on the command line when compiling or #pragma codeseg BANK1 (See
23754 \begin_inset LatexCommand \ref{sec:Pragmas}
23758 ) at the top of the C source file.
23759 The segment name always applies to the whole source file and generated
23760 object so functions for different banks need to be defined in different
23765 When linking your objects you need to tell the linker where
23766 to put your segments.
23767 To do this you use the following command line option to SDCC: -Wl-b BANK1=0x180
23769 \begin_inset LatexCommand \ref{lyx:-Wl option}
23774 This sets the virtual start address of this segment.
23775 It sets the banknumber to 0x01 and maps the bank to 0x8000 and up.
23776 The linker will not check for overflows, again this is your responsibility.
23779 \begin_layout Standard
23780 \begin_inset VSpace bigskip
23786 \begin_layout Section
23790 \begin_layout Standard
23792 \begin_inset LatexCommand \index{DS80C400}
23797 \begin_inset LatexCommand \index{DS400}
23801 microcontroller has a rich set of peripherals.
23802 In its built-in ROM library it includes functions to access some of the
23803 features, among them is a TCP stack with IP4 and IP6 support.
23804 Library headers (currently in beta status) and other files are provided
23808 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
23814 \begin_inset VSpace bigskip
23820 \begin_layout Section
23821 The Z80 and gbz80 port
23824 \begin_layout Standard
23825 SDCC can target both the Zilog Z80
23826 \begin_inset LatexCommand \index{Z80}
23830 and the Nintendo Gameboy's Z80-like gbz80
23831 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
23836 The Z80 port is passed through the same
23839 \begin_inset LatexCommand \index{Regression test}
23846 \begin_inset LatexCommand \ref{sec:Quality-control}
23850 ) as the MCS51 and DS390 ports, so floating point support, support for long
23851 variables and bitfield support is fine.
23852 See mailing lists and forums about interrupt routines.
23855 \begin_layout Standard
23856 As always, the code is the authoritative reference - see z80/ralloc.c and
23859 \begin_inset LatexCommand \index{Z80!stack}
23863 frame is similar to that generated by the IAR Z80 compiler.
23864 IX is used as the base pointer, HL and IY are used as a temporary registers,
23865 and BC and DE are available for holding variables.
23867 \begin_inset LatexCommand \index{Z80!return value}
23871 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
23873 The gbz80 port use the same set of registers for the return values, but
23874 in a different order of significance: E (one byte), DE (two bytes), or
23876 \begin_inset VSpace bigskip
23882 \begin_layout Section
23886 \begin_layout Standard
23887 The port to the Freescale/Motorola HC08
23888 \begin_inset LatexCommand \index{HC08}
23892 family has been added in October 2003, and is still undergoing some basic
23894 The code generator is complete, but the register allocation is still quite
23896 Some of the SDCC's standard C library functions have embedded non-HC08
23897 inline assembly and so are not yet usable.
23900 \begin_layout Standard
23901 The HC08 port passes the regression test suite (see section
23902 \begin_inset LatexCommand \ref{sec:Quality-control}
23907 \begin_inset VSpace bigskip
23913 \begin_layout Section
23915 \begin_inset LatexCommand \index{PIC14}
23922 \begin_layout Standard
23923 The PIC14 port adds support for Microchip
23924 \begin_inset LatexCommand \index{Microchip}
23929 \begin_inset Formula $^{\text{TM}}$
23933 \begin_inset LatexCommand \index{PIC14}
23938 \begin_inset Formula $^{\text{TM}}$
23941 MCUs with 14 bit wide instructions.
23942 This port is not yet mature and still lacks many features.
23943 However, it can work for simple code.
23946 \begin_layout Standard
23947 Currently supported devices include:
23950 \begin_layout Standard
23951 12F: 629, 635, 675, 683
23954 \begin_layout Standard
23958 \begin_layout Standard
23962 \begin_layout Standard
23963 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
23966 \begin_layout Standard
23967 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
23971 \begin_layout Standard
23975 \begin_layout Standard
23976 16CR: 620a, 73, 74, 76, 77
23979 \begin_layout Standard
23980 16F: 616, 627, 627a, 628, 628a, 630, 636, 639, 648, 648a, 676, 684, 685,
23984 \begin_layout Standard
23985 16F: 716, 72, 73, 737, 74, 747, 76, 767, 77, 777, 785
23988 \begin_layout Standard
23989 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
23990 877, 877a, 88, 886, 887
23993 \begin_layout Standard
23994 16F: 913, 914, 916, 917, 946
23997 \begin_layout Standard
24001 \begin_layout Standard
24002 An up-to-date list of currently supported devices can be obtained via
24004 sdcc -mpic14 -phelp foo.c
24006 (foo.c must exist...).
24009 \begin_layout Subsection
24011 \begin_inset LatexCommand \index{code page (pic14)}
24016 \begin_inset LatexCommand \index{Memory bank (pic14)}
24023 \begin_layout Standard
24024 The linker organizes allocation for the code page and RAM banks.
24025 It does not have intimate knowledge of the code flow.
24026 It will put all the code section of a single .asm file into a single code
24028 In order to make use of multiple code pages, separate asm files must be
24030 The compiler assigns all
24034 functions of a single .c file into the same code page.
24038 To get the best results,
24039 follow these guidelines:
24042 \begin_layout Enumerate
24043 Make local functions static, as non static functions require code page selection
24046 Due to the way sdcc handles functions, place called functions prior
24047 to calling functions in the file wherever possible: Otherwise sdcc will
24048 insert unneccessary pagesel directives around the call, believing that
24049 the called function is externally defined.
24052 \begin_layout Enumerate
24053 For devices that have multiple code pages it is more efficient to use the
24054 same number of files as pages: Use up to 4 separate .c files for the 16F877,
24055 but only 2 files for the 16F874.
24056 This way the linker can put the code for each file into different code
24057 pages and there will be less page selection overhead.
24060 \begin_layout Enumerate
24061 And as for any 8 bit micro (especially for PIC14 as they have a very simple
24062 instruction set), use `unsigned char' wherever possible instead of `int'.
24065 \begin_layout Subsection
24066 Adding New Devices to the Port
24069 \begin_layout Standard
24070 Adding support for a new 14
24074 \begin_layout Standard
24083 bit PIC MCU requires the following steps:
24086 \begin_layout Enumerate
24087 Create a new device description.
24089 Each device is described in two files: pic16f*.h
24091 These files primarily define SFRs, structs to access their bits, and symbolic
24092 configuration options.
24093 Both files can be generated from gputils' .inc files using the perl script
24096 support/scripts/inc2h.pl
24099 This file also contains further instructions on how to proceed.
24102 \begin_layout Enumerate
24103 Copy the .h file into SDCC's include path and either add the .c file to your
24104 project or copy it to
24106 device/lib/pic/libdev
24109 Afterwards, rebuild and install the libraries.
24112 \begin_layout Enumerate
24113 Edit pic14devices.txt in SDCC's include path (
24115 device/include/pic/
24117 in the source tree or
24119 /usr/local/share/sdcc/include/pic
24121 after installation).
24123 You need to add a device specification here to make
24124 the memory layout (code banks, RAM, aliased memory regions, ...) known to
24126 Probably you can copy and modify an existing entry.
24127 The file format is documented at the top of the file.
24130 \begin_layout Subsection
24134 \begin_layout Standard
24135 For the interrupt function, use the keyword `__interrupt'
24136 \begin_inset LatexCommand \index{PIC14!interrupt}
24140 with level number of 0 (PIC14 only has 1 interrupt so this number is only
24141 there to avoid a syntax error - it ought to be fixed).
24145 \begin_layout Verse
24148 void Intr(void) __interrupt 0
24154 T0IF = 0; /* Clear timer interrupt */
24159 \begin_layout Subsection
24160 Linking and Assembling
24163 \begin_layout Standard
24164 For assembling you can use either GPUTILS'
24165 \begin_inset LatexCommand \index{gputils (pic tools)}
24169 gpasm.exe or MPLAB's mpasmwin.exe.
24170 GPUTILS are available from
24171 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24176 For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
24177 If you use MPLAB and an interrupt function then the linker script file
24178 vectors section will need to be enlarged to link with mplink.
24189 \begin_layout Verse
24202 sdcc -V -mpic14 -p16f877 -c $<
24206 $(PRJ).hex: $(OBJS)
24216 gplink -m -s $(PRJ).lkr
24217 -o $(PRJ).hex $(OBJS) libsdcc.lib
24220 \begin_layout Standard
24228 \begin_layout Verse
24241 sdcc -S -V -mpic14 -p16f877 $<
24251 mpasmwin /q /o $*.asm
24255 $(PRJ).hex: $(OBJS)
24266 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
24269 \begin_layout Standard
24270 Please note that indentations within a
24274 have to be done with a tabulator character.
24277 \begin_layout Subsection
24278 Command-Line Options
24281 \begin_layout Standard
24282 Besides the switches common to all SDCC backends, the PIC14 port accepts
24283 the following options (for an updated list see sdcc -
24287 \begin_layout Standard
24299 \begin_layout Description
24304 \begin_layout Standard
24314 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
24318 emit debug info in assembly output
24321 \begin_layout Description
24326 \begin_layout Standard
24336 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
24340 disable (slightly faulty) optimization on pCode
24343 \begin_layout Description
24348 \begin_layout Standard
24358 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
24362 sets the lowest address of the argument passing stack (defaults to a suitably
24363 large shared databank to reduce BANKSEL overhead)
24366 \begin_layout Description
24371 \begin_layout Standard
24381 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
24385 sets the size if the argument passing stack (default: 16, minimum: 4)
24388 \begin_layout Subsection
24389 Environment Variables
24392 \begin_layout Standard
24393 The PIC14 port recognizes the following environment variables:
24396 \begin_layout Description
24397 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
24398 register (the ones called r0xNNNN) in a section of its own.
24399 By default (if this variable is unset), sdcc tries to cluster registers
24400 in sections in order to reduce the BANKSEL overhead when accessing them.
24403 \begin_layout Subsection
24407 \begin_layout Standard
24408 The PIC14 library currently only contains support routines required by the
24409 compiler to implement multiplication, division, and floating point support.
24410 No libc-like replacement is available at the moment, though many of the
24411 common sdcc library sources (in
24415 ) should also compile with the PIC14 port.
24418 \begin_layout Subsubsection
24419 error: missing definition for symbol ``__gptrget1''
24422 \begin_layout Standard
24423 The PIC14 port uses library routines to provide more complex operations
24424 like multiplication, division/modulus and (generic) pointer dereferencing.
24425 In order to add these routines to your project, you must link with PIC14's
24431 For single source file projects this is done automatically, more complex
24436 to the linker's arguments.
24437 Make sure you also add an include path for the library (using the -I switch
24441 \begin_layout Subsubsection
24442 Processor mismatch in file ``XXX''.
24445 \begin_layout Standard
24446 This warning can usually be ignored due to the very good compatibility amongst
24451 \begin_layout Standard
24461 \begin_inset LatexCommand \index{PIC14}
24468 \begin_layout Standard
24469 You might also consider recompiling the library for your specific device
24470 by changing the ARCH=p16f877 (default target) entry in
24472 device/lib/pic/Makefile.in
24476 device/lib/pic/Makefile
24478 to reflect your device.
24479 This might even improve performance for smaller devices as unneccesary
24480 BANKSELs might be removed.
24483 \begin_layout Subsection
24487 \begin_layout Subsubsection
24491 \begin_layout Standard
24492 Functions with variable argument lists (like printf) are not yet supported.
24493 Similarly, taking the address of the first argument passed into a function
24494 does not work: It is currently passed in WREG and has no address...
24497 \begin_layout Subsubsection
24498 Regression tests fail
24501 \begin_layout Standard
24502 Though the small subset of regression tests in src/regression passes, SDCC
24503 regression test suite does not, indicating that there are still major bugs
24505 However, many smaller projects have successfully used SDCC in the past...
24508 \begin_layout Standard
24516 \begin_layout Section
24518 \begin_inset LatexCommand \index{PIC16}
24525 \begin_layout Standard
24526 The PIC16 port adds support for Microchip
24527 \begin_inset LatexCommand \index{Microchip}
24532 \begin_inset Formula $^{\text{TM}}$
24536 \begin_inset LatexCommand \index{PIC}
24541 \begin_inset Formula $^{\text{TM}}$
24544 MCUs with 16 bit wide instructions.
24545 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
24546 ; devices supported by the port include:
24549 \begin_layout Standard
24550 18F: 242, 248, 252, 258, 442, 448, 452, 458
24553 \begin_layout Standard
24557 \begin_layout Standard
24558 18F: 2220, 2221, 2320, 2321, 2331, 2410, 2420, 2423, 2431, 2450, 2455, 2480, 24j10
24561 \begin_layout Standard
24562 18F: (2510,) 2515, 2520, 2523, 2525, 2550, 2580, 2585, 25j10, 2610, 2620, 2680, 2682, 2685
24565 \begin_layout Standard
24566 18F: 4220, 4221, 4320, 4321, 4331, 4410, 4420, 4423, 4431, 4450, 4455, 4480, 44j10
24569 \begin_layout Standard
24570 18F: 4510, 4515, 4520, 4523, 4525, 4550, 4580, 4585, 45j10, 4610, 4620, 4680, 4682, 4685
24573 \begin_layout Standard
24574 18F: 6520, 6585, 6620, 6680, 66j60, 66j65, 6720, 67j60
24577 \begin_layout Standard
24578 18F: 8520, 8585, 8620, 8680, 86j60, 86j65, 8720, 87j60
24581 \begin_layout Standard
24582 18F: 96j60, 96j65, 97j60
24585 \begin_layout Standard
24586 A list of supported devices is also available via '
24588 sdcc -mpic16 -plist
24593 \begin_layout Subsection
24597 \begin_layout Standard
24598 PIC16 port supports the standard command line arguments as supposed, with
24599 the exception of certain cases that will be mentioned in the following
24603 \begin_layout Description
24608 \begin_layout Standard
24618 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
24626 \begin_layout Standard
24638 \begin_layout Description
24643 \begin_layout Standard
24652 -fommit-frame-pointer
24653 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
24657 Frame pointer will be omitted when the function uses no local variables.
24660 \begin_layout Subsection
24661 Port Specific Options
24662 \begin_inset LatexCommand \index{Options PIC16}
24669 \begin_layout Standard
24670 The port specific options appear after the global options in the sdcc -
24674 \begin_layout Standard
24686 \begin_layout Subsubsection
24687 Code Generation Options
24690 \begin_layout Standard
24691 These options influence the generated assembler code.
24694 \begin_layout Description
24699 \begin_layout Standard
24708 -pstack-model=[model] Used in conjuction with the command above.
24709 Defines the stack model to be used, valid stack models are:
24714 \labelwidthstring 00.00.0000
24719 Selects small stack model.
24720 8 bit stack and frame pointers.
24721 Supports 256 bytes stack size.
24725 \labelwidthstring 00.00.0000
24730 Selects large stack model.
24731 16 bit stack and frame pointers.
24732 Supports 65536 bytes stack size.
24736 \begin_layout Description
24741 \begin_layout Standard
24750 -pno-banksel Do not generate BANKSEL assembler directives.
24753 \begin_layout Description
24758 \begin_layout Standard
24767 -extended Enable extended instruction set/literal offset addressing mode.
24771 \begin_layout Subsubsection
24772 Optimization Options
24775 \begin_layout Description
24780 \begin_layout Standard
24789 -obanksel=n Set optimization level for inserting BANKSELs.
24796 \labelwidthstring 00.00.0000
24801 \labelwidthstring 00.00.0000
24802 1 checks previous used register and if it is the same then does not emit
24803 BANKSEL, accounts only for labels.
24807 \labelwidthstring 00.00.0000
24808 2 tries to check the location of (even different) symbols and removes BANKSELs
24809 if they are in the same bank.
24814 Important: There might be problems if the linker script has data sections
24815 across bank borders!
24819 \begin_layout Description
24824 \begin_layout Standard
24833 -denable-peeps Force the usage of peepholes.
24837 \begin_layout Description
24842 \begin_layout Standard
24851 -no-optimize-goto Do not use (conditional) BRA instead of GOTO.
24854 \begin_layout Description
24859 \begin_layout Standard
24868 -optimize-cmp Try to optimize some compares.
24871 \begin_layout Description
24876 \begin_layout Standard
24885 -optimize-df Analyze the dataflow of the generated code and improve it.
24888 \begin_layout Subsubsection
24892 \begin_layout Description
24897 \begin_layout Standard
24906 -asm= Sets the full path and name of an external assembler to call.
24909 \begin_layout Description
24914 \begin_layout Standard
24924 \begin_inset LatexCommand \index{PIC16!MPLAB}
24928 compatibility option.
24929 Currently only suppresses special gpasm directives.
24932 \begin_layout Subsubsection
24936 \begin_layout Description
24941 \begin_layout Standard
24950 -link= Sets the full path and name of an external linker to call.
24953 \begin_layout Description
24958 \begin_layout Standard
24967 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
24968 unitialized data variables with [kword].
24969 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
24972 \begin_layout Description
24977 \begin_layout Standard
24986 -ivt-loc=n Place the interrupt vector table at address
24991 Useful for bootloaders.
24994 \begin_layout Description
24999 \begin_layout Standard
25008 -nodefaultlibs Do not link default libraries when linking.
25011 \begin_layout Description
25016 \begin_layout Standard
25025 -use-crt= Use a custom run-time module instead of the defaults.
25028 \begin_layout Description
25033 \begin_layout Standard
25042 -no-crt Don't link the default run-time modules
25045 \begin_layout Subsubsection
25049 \begin_layout Standard
25050 Debugging options enable extra debugging information in the output files.
25053 \begin_layout Description
25058 \begin_layout Standard
25067 -debug-xtra Similar to -
25071 \begin_layout Standard
25081 \begin_inset LatexCommand \index{-\/-debug}
25085 , but dumps more information.
25088 \begin_layout Description
25093 \begin_layout Standard
25102 -debug-ralloc Force register allocator to dump <source>.d file with debugging
25104 <source> is the name of the file being compiled.
25107 \begin_layout Description
25112 \begin_layout Standard
25121 -pcode-verbose Enable pcode debugging information in translation.
25124 \begin_layout Description
25129 \begin_layout Standard
25138 -calltree Dump call tree in .calltree file.
25141 \begin_layout Description
25146 \begin_layout Standard
25155 -gstack Trace push/pops for stack pointer overflow.
25158 \begin_layout Subsection
25159 Enviroment Variables
25162 \begin_layout Standard
25163 There is a number of enviromental variables that can be used when running
25164 SDCC to enable certain optimizations or force a specific program behaviour.
25165 these variables are primarily for debugging purposes so they can be enabled/dis
25169 \begin_layout Standard
25170 Currently there is only two such variables available:
25173 \begin_layout Description
25174 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
25175 bitfields is optimized by directly loading FSR0 with the address of the
25176 bitfield structure.
25177 Normally SDCC will cast the bitfield structure to a bitfield pointer and
25179 This step saves data ram and code space for functions that make heavy use
25181 (i.e., 80 bytes of code space are saved when compiling malloc.c with this
25186 \begin_layout Description
25187 NO_REG_OPT Do not perform pCode registers optimization.
25188 This should be used for debugging purposes.
25189 If bugs in the pcode optimizer are found, users can benefit from temporarily
25190 disabling the optimizer until the bug is fixed.
25193 \begin_layout Subsection
25194 Preprocessor Macros
25197 \begin_layout Standard
25199 \begin_inset LatexCommand \index{PIC16}
25203 port defines the following preprocessor macros while translating a source.
25206 \begin_layout Standard
25208 \begin_inset Tabular
25209 <lyxtabular version="3" rows="6" columns="2">
25211 <column alignment="center" valignment="top" leftline="true" width="0">
25212 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25213 <row topline="true" bottomline="true">
25214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25217 \begin_layout Standard
25223 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25226 \begin_layout Standard
25233 <row topline="true">
25234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25237 \begin_layout Standard
25243 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25246 \begin_layout Standard
25247 Port identification
25253 <row topline="true">
25254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25257 \begin_layout Standard
25262 \begin_layout Standard
25276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25279 \begin_layout Standard
25280 Port identification (same as above)
25286 <row topline="true">
25287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25290 \begin_layout Standard
25296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25299 \begin_layout Standard
25300 MCU Identification.
25305 is the microcontrol identification number, i.e.
25312 <row topline="true">
25313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25316 \begin_layout Standard
25321 \begin_layout Standard
25335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25338 \begin_layout Standard
25339 MCU Identification (same as above)
25345 <row topline="true" bottomline="true">
25346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25349 \begin_layout Standard
25355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25358 \begin_layout Standard
25359 nnn = SMALL or LARGE respectively according to the stack model used
25372 \begin_layout Standard
25373 In addition the following macros are defined when calling assembler:
25376 \begin_layout Standard
25378 \begin_inset Tabular
25379 <lyxtabular version="3" rows="4" columns="2">
25381 <column alignment="center" valignment="top" leftline="true" width="0">
25382 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25383 <row topline="true" bottomline="true">
25384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25387 \begin_layout Standard
25393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25396 \begin_layout Standard
25403 <row topline="true">
25404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25407 \begin_layout Standard
25413 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25416 \begin_layout Standard
25417 MCU Identification.
25422 is the microcontrol identification number, i.e.
25429 <row topline="true">
25430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25433 \begin_layout Standard
25439 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25442 \begin_layout Standard
25443 nnn = SMALL or LARGE respectively according to the memory model used for
25450 <row topline="true" bottomline="true">
25451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25454 \begin_layout Standard
25460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25463 \begin_layout Standard
25464 nnn = SMALL or LARGE respectively according to the stack model used
25477 \begin_layout Subsection
25481 \begin_layout Standard
25483 \begin_inset LatexCommand \index{PIC16}
25487 port uses the following directories for searching header files and libraries.
25490 \begin_layout Standard
25492 \begin_inset Tabular
25493 <lyxtabular version="3" rows="3" columns="4">
25495 <column alignment="center" valignment="top" leftline="true" width="0">
25496 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25497 <column alignment="center" valignment="top" width="0">
25498 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25499 <row topline="true" bottomline="true">
25500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25503 \begin_layout Standard
25509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25512 \begin_layout Standard
25518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25521 \begin_layout Standard
25527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25530 \begin_layout Standard
25537 <row topline="true">
25538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25541 \begin_layout Standard
25542 PREFIX/sdcc/include/pic16
25547 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25550 \begin_layout Standard
25551 PIC16 specific headers
25556 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25559 \begin_layout Standard
25565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25568 \begin_layout Standard
25575 <row topline="true" bottomline="true">
25576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25579 \begin_layout Standard
25580 PREFIX/sdcc/lib/pic16
25585 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25588 \begin_layout Standard
25589 PIC16 specific libraries
25594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25597 \begin_layout Standard
25603 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25606 \begin_layout Standard
25620 \begin_layout Subsection
25622 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
25629 \begin_layout Standard
25631 \begin_inset LatexCommand \index{PIC16}
25635 port currently supports the following pragmas:
25638 \begin_layout Description
25640 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
25644 This forces the code generator to initialize the stack & frame pointers
25645 at a specific address.
25646 This is an ad hoc solution for cases where no STACK directive is available
25647 in the linker script or gplink is not instructed to create a stack section.
25650 stack pragma should be used only once in a project.
25651 Multiple pragmas may result in indeterminate behaviour of the program.
25655 \begin_layout Standard
25656 The old format (ie.
25657 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
25658 cross page boundaries (or even exceed the available data RAM) and crash
25660 Make sure that stack does not cross page boundaries when using the SMALL
25668 The format is as follows:
25673 \begin_layout LyX-Code
25674 #pragma stack bottom_address [stack_size]
25679 \begin_layout Standard
25684 is the lower bound of the stack section.
25685 The stack pointer initially will point at address (bottom_address+stack_size-1).
25688 \begin_layout LyX-Code
25692 \begin_layout LyX-Code
25696 \begin_layout LyX-Code
25697 /* initializes stack of 100 bytes at RAM address 0x200 */
25700 \begin_layout LyX-Code
25701 #pragma stack 0x200 100
25704 \begin_layout Standard
25705 If the stack_size field is omitted then a stack is created with the default
25707 This size might be enough for most programs, but its not enough for operations
25708 with deep function nesting or excessive stack usage.
25711 \begin_layout Description
25713 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
25717 Force a function to a static FLASH address.
25720 \begin_layout LyX-Code
25724 \begin_layout LyX-Code
25728 \begin_layout LyX-Code
25729 /* place function test_func at 0x4000 */
25732 \begin_layout LyX-Code
25733 #pragma code test_func 0x4000
25736 \begin_layout LyX-Code
25740 \begin_layout Description
25741 library instructs the linker to use a library module.
25746 \begin_layout LyX-Code
25747 #pragma library module_name
25750 \begin_layout Standard
25755 can be any library or object file (including its path).
25756 Note that there are four reserved keywords which have special meaning.
25760 \begin_layout Standard
25762 \begin_inset Tabular
25763 <lyxtabular version="3" rows="6" columns="3">
25765 <column alignment="center" valignment="top" leftline="true" width="0">
25766 <column alignment="block" valignment="top" leftline="true" width="20page%">
25767 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
25768 <row topline="true" bottomline="true">
25769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25772 \begin_layout Standard
25778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25781 \begin_layout Standard
25787 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25790 \begin_layout Standard
25797 <row topline="true">
25798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25801 \begin_layout Standard
25809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25812 \begin_layout Standard
25813 ignore all library pragmas
25818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25821 \begin_layout Standard
25830 <row topline="true">
25831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25834 \begin_layout Standard
25842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25845 \begin_layout Standard
25851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25854 \begin_layout Standard
25865 <row topline="true">
25866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25869 \begin_layout Standard
25877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25880 \begin_layout Standard
25881 link the Math libarary
25886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25889 \begin_layout Standard
25900 <row topline="true">
25901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25904 \begin_layout Standard
25912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25915 \begin_layout Standard
25916 link the I/O library
25921 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25924 \begin_layout Standard
25935 <row topline="true" bottomline="true">
25936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25939 \begin_layout Standard
25947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25950 \begin_layout Standard
25951 link the debug library
25956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25959 \begin_layout Standard
25976 * is the device number, i.e.
25977 452 for PIC18F452 MCU.
25980 \begin_layout Standard
25981 This feature allows for linking with specific libraries withoug having to
25982 explicit name them in the command line.
25987 keyword will reject all modules specified by the library pragma.
25990 \begin_layout Description
25991 udata The pragma udata instructs the compiler to emit code so that linker
25992 will place a variable at a specific memory bank.
25995 \begin_layout LyX-Code
25999 \begin_layout LyX-Code
26003 \begin_layout LyX-Code
26004 /* places variable foo at bank2 */
26007 \begin_layout LyX-Code
26008 #pragma udata bank2 foo
26011 \begin_layout LyX-Code
26015 \begin_layout Standard
26016 In order for this pragma to work extra SECTION directives should be added
26017 in the .lkr script.
26018 In the following example a sample .lkr file is shown:
26021 \begin_layout LyX-Code
26025 \begin_layout LyX-Code
26026 // Sample linker script for the PIC18F452 processor
26029 \begin_layout LyX-Code
26033 \begin_layout LyX-Code
26034 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
26037 \begin_layout LyX-Code
26038 CODEPAGE NAME=page START=0x2A END=0x7FFF
26041 \begin_layout LyX-Code
26042 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
26045 \begin_layout LyX-Code
26046 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
26049 \begin_layout LyX-Code
26050 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
26053 \begin_layout LyX-Code
26054 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
26057 \begin_layout LyX-Code
26058 ACCESSBANK NAME=accessram START=0x0 END=0x7F
26061 \begin_layout LyX-Code
26065 \begin_layout LyX-Code
26066 DATABANK NAME=gpr0 START=0x80 END=0xFF
26069 \begin_layout LyX-Code
26070 DATABANK NAME=gpr1 START=0x100 END=0x1FF
26073 \begin_layout LyX-Code
26074 DATABANK NAME=gpr2 START=0x200 END=0x2FF
26077 \begin_layout LyX-Code
26078 DATABANK NAME=gpr3 START=0x300 END=0x3FF
26081 \begin_layout LyX-Code
26082 DATABANK NAME=gpr4 START=0x400 END=0x4FF
26085 \begin_layout LyX-Code
26086 DATABANK NAME=gpr5 START=0x500 END=0x5FF
26089 \begin_layout LyX-Code
26090 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
26093 \begin_layout LyX-Code
26097 \begin_layout LyX-Code
26098 SECTION NAME=CONFIG ROM=config
26101 \begin_layout LyX-Code
26105 \begin_layout LyX-Code
26106 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
26109 \begin_layout LyX-Code
26110 SECTION NAME=bank1 RAM=gpr1 # should be added to link
26113 \begin_layout LyX-Code
26114 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
26117 \begin_layout LyX-Code
26118 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
26121 \begin_layout LyX-Code
26122 SECTION NAME=bank4 RAM=gpr4
26125 \begin_layout LyX-Code
26126 SECTION NAME=bank5 RAM=gpr5
26129 \begin_layout Standard
26130 The linker will recognise the section name set in the pragma statement and
26131 will position the variable at the memory bank set with the RAM field at
26132 the SECTION line in the linker script file.
26135 \begin_layout Subsection
26137 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
26144 \begin_layout Standard
26145 There is one main header file
26146 \begin_inset LatexCommand \index{PIC16!Header files}
26150 that can be included to the source files using the pic16
26151 \begin_inset LatexCommand \index{PIC16}
26161 This header file contains the definitions for the processor special registers,
26162 so it is necessary if the source accesses them.
26163 It can be included by adding the following line in the beginning of the
26167 \begin_layout LyX-Code
26168 #include <pic18fregs.h>
26171 \begin_layout Standard
26172 The specific microcontroller is selected within the pic18fregs.h automatically,
26173 so the same source can be used with a variety of devices.
26176 \begin_layout Subsection
26180 \begin_layout Standard
26182 \begin_inset LatexCommand \index{PIC16!Libraries}
26187 \begin_inset LatexCommand \index{PIC16}
26191 port depends on are the microcontroller device libraries which contain
26192 the symbol definitions for the microcontroller special function registers.
26193 These libraries have the format pic18fxxxx.lib, where
26197 is the microcontroller identification number.
26198 The specific library is selected automatically by the compiler at link
26199 stage according to the selected device.
26202 \begin_layout Standard
26203 Libraries are created with gplib which is part of the gputils package
26204 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
26211 \begin_layout Subsubsection*
26212 Building the libraries
26215 \begin_layout Standard
26216 Before using SDCC/pic16 there are some libraries that need to be compiled.
26217 This process is not done automatically by SDCC since not all users use
26218 SDCC for pic16 projects.
26219 So each user should compile the libraries separately.
26222 \begin_layout Standard
26223 The steps to compile the pic16 libraries under Linux and Mac OS X are:
26226 \begin_layout LyX-Code
26227 cd device/lib/pic16
26230 \begin_layout LyX-Code
26234 \begin_layout LyX-Code
26238 \begin_layout LyX-Code
26242 \begin_layout LyX-Code
26246 \begin_layout LyX-Code
26247 su -c 'make install' # install the libraries, you need the root password
26250 \begin_layout Standard
26251 If you need to install the headers too, do:
26254 \begin_layout LyX-Code
26258 \begin_layout LyX-Code
26259 su -c 'make install' # install the headers, you need the root password
26262 \begin_layout Standard
26263 There exist a special target to build the I/O libraries.
26264 This target is not automatically build because it will build the I/O library
26270 This way building will take quite a lot of time.
26271 Users are advised to edit the
26273 device/lib/pic16/pics.build
26275 file and then execute:
26278 \begin_layout LyX-Code
26282 \begin_layout Subsection
26283 Adding New Devices to the Port
26286 \begin_layout Standard
26287 Adding support for a new 16
26291 \begin_layout Standard
26300 bit PIC MCU requires the following steps:
26303 \begin_layout Enumerate
26304 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
26308 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
26312 \begin_layout Enumerate
26315 mv picDEVICE.h /path/to/sdcc/device/include/pic16
26318 \begin_layout Enumerate
26321 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
26324 \begin_layout Enumerate
26327 /path/to/sdcc/device/lib/pic16/pics.all
26335 Note: No 18f prefix here!
26338 \begin_layout Enumerate
26339 Set up the I/O library by doing
26347 \begin_layout Enumerate
26350 /path/to/sdcc/device/lib/pic16/libio/*.ignore
26354 Add your DEVICE if it does not compile in
26369 \begin_layout Enumerate
26372 /path/to/sdcc/device/include/pic16/adc.h
26376 Add the new devices to the correct ADC style class.
26380 \begin_layout Enumerate
26383 /path/to/sdcc/device/include/pic16/pic18fregs.h
26387 The file format is self-explanatory, just add
26391 #elif defined(picDEVICE)
26393 # include <picDEVICE.h>
26397 at the right place (keep it sorted).
26400 \begin_layout Enumerate
26403 /path/to/sdcc/device/include/pic16devices.txt
26407 Copy and modify an existing entry or create a new one and insert it at the
26408 correct place (keep the file sorted).
26411 \begin_layout Enumerate
26412 Recompile the pic16 libraries.
26415 \begin_layout Subsection
26419 \begin_layout Standard
26420 The following memory models are supported by the PIC16 port:
26423 \begin_layout Itemize
26427 \begin_layout Itemize
26431 \begin_layout Standard
26432 Memory model affects the default size of pointers within the source.
26433 The sizes are shown in the next table:
26436 \begin_layout Standard
26438 \begin_inset Tabular
26439 <lyxtabular version="3" rows="3" columns="3">
26441 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26442 <column alignment="center" valignment="top" leftline="true" width="0">
26443 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26444 <row topline="true" bottomline="true">
26445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26448 \begin_layout Standard
26449 Pointer sizes according to memory model
26454 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26457 \begin_layout Standard
26463 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26466 \begin_layout Standard
26473 <row topline="true" bottomline="true">
26474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26477 \begin_layout Standard
26483 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26486 \begin_layout Standard
26492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26495 \begin_layout Standard
26502 <row topline="true" bottomline="true">
26503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26506 \begin_layout Standard
26512 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
26515 \begin_layout Standard
26521 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26524 \begin_layout Standard
26538 \begin_layout Standard
26539 It is advisable that all sources within a project are compiled with the
26541 If one wants to override the default memory model, this can be done by
26542 declaring a pointer as
26551 Far selects large memory model's pointers, while near selects small memory
26555 \begin_layout Standard
26556 The standard device libraries (see
26557 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
26561 ) contain no reference to pointers, so they can be used with both memory
26565 \begin_layout Subsection
26569 \begin_layout Standard
26571 \begin_inset LatexCommand \index{PIC16!stack}
26575 implementation for the PIC16 port uses two indirect registers, FSR1 and
26579 \begin_layout Description
26580 FSR1 is assigned as stack pointer
26583 \begin_layout Description
26584 FSR2 is assigned as frame pointer
26587 \begin_layout Standard
26588 The following stack models are supported by the PIC16 port
26591 \begin_layout Itemize
26599 \begin_layout Itemize
26607 \begin_layout Standard
26612 model means that only the FSRxL byte is used to access stack and frame,
26619 uses both FSRxL and FSRxH registers.
26620 The following table shows the stack/frame pointers sizes according to stack
26621 model and the maximum space they can address:
26624 \begin_layout Standard
26626 \begin_inset Tabular
26627 <lyxtabular version="3" rows="3" columns="3">
26629 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26630 <column alignment="center" valignment="top" leftline="true" width="0">
26631 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26632 <row topline="true" bottomline="true">
26633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26636 \begin_layout Standard
26637 Stack & Frame pointer sizes according to stack model
26642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26645 \begin_layout Standard
26651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26654 \begin_layout Standard
26661 <row topline="true">
26662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26665 \begin_layout Standard
26671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26674 \begin_layout Standard
26680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26683 \begin_layout Standard
26690 <row topline="true" bottomline="true">
26691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26694 \begin_layout Standard
26700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26703 \begin_layout Standard
26709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26712 \begin_layout Standard
26726 \begin_layout Standard
26731 stack model is currently not working properly throughout the code generator.
26732 So its use is not advised.
26733 Also there are some other points that need special care:
26738 \begin_layout Enumerate
26739 Do not create stack sections with size more than one physical bank (that
26743 \begin_layout Enumerate
26744 Stack sections should no cross physical bank limits (i.e.
26745 #pragma stack 0x50 0x100)
26748 \begin_layout Standard
26749 These limitations are caused by the fact that only FSRxL is modified when
26750 using SMALL stack model, so no more than 256 bytes of stack can be used.
26751 This problem will disappear after LARGE model is fully implemented.
26754 \begin_layout Subsection
26758 \begin_layout Standard
26759 In addition to the standard SDCC function keywords, PIC16
26760 \begin_inset LatexCommand \index{PIC16}
26764 port makes available two more:
26767 \begin_layout Description
26769 \begin_inset LatexCommand \index{PIC16!wparam}
26773 Use the WREG to pass one byte of the first function argument.
26774 This improves speed but you may not use this for functions with arguments
26775 that are called via function pointers, otherwise the first byte of the
26776 first parameter will get lost.
26780 \begin_layout LyX-Code
26781 void func_wparam(int a) wparam
26784 \begin_layout LyX-Code
26788 \begin_layout LyX-Code
26789 /* WREG hold the lower part of a */
26792 \begin_layout LyX-Code
26793 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
26797 \begin_layout LyX-Code
26801 \begin_layout LyX-Code
26805 \begin_layout Description
26807 \begin_inset LatexCommand \index{PIC16!shadowregs}
26811 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
26812 hardware shadow registers which hold the values of WREG, STATUS and BSR
26814 This can be done by adding the keyword
26822 keyword in the function's header.
26825 \begin_layout LyX-Code
26826 void isr_shadow(void) shadowregs interrupt 1
26829 \begin_layout LyX-Code
26833 \begin_layout LyX-Code
26837 \begin_layout LyX-Code
26841 \begin_layout Standard
26846 instructs the code generator not to store/restore WREG, STATUS, BSR when
26847 entering/exiting the ISR.
26850 \begin_layout Subsection
26851 Function return values
26854 \begin_layout Standard
26855 Return values from functions are placed to the appropriate registers following
26856 a modified Microchip policy optimized for SDCC.
26857 The following table shows these registers:
26860 \begin_layout Standard
26862 \begin_inset Tabular
26863 <lyxtabular version="3" rows="6" columns="2">
26865 <column alignment="center" valignment="top" leftline="true" width="0">
26866 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26867 <row topline="true" bottomline="true">
26868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26871 \begin_layout Standard
26877 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26880 \begin_layout Standard
26881 destination register
26887 <row topline="true">
26888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26891 \begin_layout Standard
26897 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26900 \begin_layout Standard
26907 <row topline="true">
26908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26911 \begin_layout Standard
26917 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26920 \begin_layout Standard
26927 <row topline="true">
26928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26931 \begin_layout Standard
26937 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26940 \begin_layout Standard
26947 <row topline="true">
26948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26951 \begin_layout Standard
26957 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26960 \begin_layout Standard
26961 FSR0L:PRODH:PRODL:WREG
26967 <row topline="true" bottomline="true">
26968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26971 \begin_layout Standard
26977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26980 \begin_layout Standard
26981 on stack, FSR0 points to the beginning
26994 \begin_layout Subsection
26998 \begin_layout Standard
27000 \begin_inset LatexCommand \index{PIC16!interrupt}
27004 service routine (ISR) is declared using the
27011 \begin_layout LyX-Code
27012 void isr(void) interrupt
27017 \begin_layout LyX-Code
27021 \begin_layout LyX-Code
27025 \begin_layout LyX-Code
27029 \begin_layout Standard
27034 is the interrupt number, which for PIC18F devices can be:
27037 \begin_layout Standard
27039 \begin_inset Tabular
27040 <lyxtabular version="3" rows="4" columns="3">
27042 <column alignment="center" valignment="top" leftline="true" width="0">
27043 <column alignment="center" valignment="top" leftline="true" width="0">
27044 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27045 <row topline="true" bottomline="true">
27046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27049 \begin_layout Standard
27057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27060 \begin_layout Standard
27066 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27069 \begin_layout Standard
27070 Interrupt Vector Address
27076 <row topline="true">
27077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27080 \begin_layout Standard
27086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27089 \begin_layout Standard
27095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27098 \begin_layout Standard
27105 <row topline="true">
27106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27109 \begin_layout Standard
27124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27127 \begin_layout Standard
27137 HIGH priority interrupts
27142 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27145 \begin_layout Standard
27152 <row topline="true" bottomline="true">
27153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27156 \begin_layout Standard
27162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27165 \begin_layout Standard
27166 LOW priority interrupts
27171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27174 \begin_layout Standard
27188 \begin_layout Standard
27189 When generating assembly code for ISR the code generator places a
27195 Interrupt Vector Address
27197 which points at the genetated ISR.
27198 This single GOTO instruction is part of an automatically generated
27200 interrupt entry point
27203 The actuall ISR code is placed as normally would in the code space.
27204 Upon interrupt request, the GOTO instruction is executed which jumps to
27206 When declaring interrupt functions as _naked this GOTO instruction is
27211 The whole interrupt functions is therefore placed at the Interrupt Vector
27212 Address of the specific interrupt.
27213 This is not a problem for the LOW priority interrupts, but it is a problem
27214 for the RESET and the HIGH priority interrupts because code may be written
27215 at the next interrupt's vector address and cause undeterminate program
27216 behaviour if that interrupt is raised.
27220 \begin_layout Standard
27221 This is not a problem when
27224 \begin_layout Enumerate
27225 this is a HIGH interrupt ISR and LOW interrupts are
27232 \begin_layout Enumerate
27233 when the ISR is small enough not to reach the next interrupt's vector address.
27241 \begin_layout Standard
27247 This way a function is generated similar to an ISR, but it is not assigned
27251 \begin_layout Standard
27252 When entering an interrupt, currently the PIC16
27253 \begin_inset LatexCommand \index{PIC16}
27257 port automatically saves the following registers:
27260 \begin_layout Itemize
27264 \begin_layout Itemize
27268 \begin_layout Itemize
27272 \begin_layout Itemize
27273 PROD (PRODL and PRODH)
27276 \begin_layout Itemize
27277 FSR0 (FSR0L and FSR0H)
27280 \begin_layout Standard
27281 These registers are restored upon return from the interrupt routine.
27285 \begin_layout Standard
27286 NOTE that when the _naked attribute is specified for an interrupt routine,
27287 then NO registers are stored or restored.
27295 \begin_layout Subsection
27299 \begin_layout Standard
27300 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
27301 There are 3 types of generic pointers currently implemented data, code
27302 and eeprom pointers.
27303 They are differentiated by the value of the 7th and 6th bits of the upper
27307 \begin_layout Standard
27309 \begin_inset Tabular
27310 <lyxtabular version="3" rows="5" columns="5">
27312 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27313 <column alignment="center" valignment="top" width="0">
27314 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27315 <column alignment="center" valignment="top" width="0">
27316 <column alignment="left" valignment="top" rightline="true" width="0">
27317 <row topline="true" bottomline="true">
27318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27321 \begin_layout Standard
27327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27330 \begin_layout Standard
27336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27339 \begin_layout Standard
27345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27348 \begin_layout Standard
27349 rest of the pointer
27354 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27357 \begin_layout Standard
27364 <row topline="true" bottomline="true">
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" usebox="none">
27377 \begin_layout Standard
27383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27386 \begin_layout Standard
27392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27395 \begin_layout Standard
27400 uuuuuu uuuuxxxx xxxxxxxx
27405 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27408 \begin_layout Standard
27409 a 12-bit data pointer in data RAM memory
27415 <row bottomline="true">
27416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27419 \begin_layout Standard
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" rightline="true" usebox="none">
27437 \begin_layout Standard
27443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27446 \begin_layout Standard
27451 uxxxxx xxxxxxxx xxxxxxxx
27456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27459 \begin_layout Standard
27460 a 21-bit code pointer in FLASH memory
27466 <row bottomline="true">
27467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27470 \begin_layout Standard
27476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27479 \begin_layout Standard
27485 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="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
27502 uuuuuu uuuuuuxx xxxxxxxx
27507 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27510 \begin_layout Standard
27511 a 10-bit eeprom pointer in EEPROM memory
27517 <row bottomline="true">
27518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27521 \begin_layout Standard
27527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27530 \begin_layout Standard
27536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27539 \begin_layout Standard
27545 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27548 \begin_layout Standard
27553 xxxxxx xxxxxxxx xxxxxxxx
27558 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27561 \begin_layout Standard
27562 unimplemented pointer type
27575 \begin_layout Standard
27576 Generic pointer are read and written with a set of library functions which
27577 read/write 1, 2, 3, 4 bytes.
27580 \begin_layout Subsection
27584 \begin_layout Subsubsection
27585 Standard I/O Streams
27588 \begin_layout Standard
27593 the type FILE is defined as:
27596 \begin_layout LyX-Code
27597 typedef char * FILE;
27600 \begin_layout Standard
27601 This type is the stream type implemented I/O in the PIC18F devices.
27602 Also the standard input and output streams are declared in stdio.h:
27605 \begin_layout LyX-Code
27606 extern FILE * stdin;
27609 \begin_layout LyX-Code
27610 extern FILE * stdout;
27613 \begin_layout Standard
27614 The FILE type is actually a generic pointer which defines one more type
27615 of generic pointers, the
27620 This new type has the format:
27623 \begin_layout Standard
27625 \begin_inset Tabular
27626 <lyxtabular version="3" rows="2" columns="7">
27628 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27629 <column alignment="center" valignment="top" width="0">
27630 <column alignment="center" valignment="top" leftline="true" width="0">
27631 <column alignment="center" valignment="top" leftline="true" width="0">
27632 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27633 <column alignment="center" valignment="top" width="0">
27634 <column alignment="left" valignment="top" rightline="true" width="0">
27635 <row topline="true" bottomline="true">
27636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27639 \begin_layout Standard
27645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27648 \begin_layout Standard
27654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27657 \begin_layout Standard
27663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27666 \begin_layout Standard
27672 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27675 \begin_layout Standard
27681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27684 \begin_layout Standard
27685 rest of the pointer
27690 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27693 \begin_layout Standard
27700 <row topline="true" bottomline="true">
27701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27704 \begin_layout Standard
27710 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27713 \begin_layout Standard
27719 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27722 \begin_layout Standard
27728 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27731 \begin_layout Standard
27737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27740 \begin_layout Standard
27746 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27749 \begin_layout Standard
27759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27762 \begin_layout Standard
27763 upper byte high nubble is 0x2n, the rest are zeroes
27776 \begin_layout Standard
27777 Currently implemented there are 3 types of streams defined:
27780 \begin_layout Standard
27782 \begin_inset Tabular
27783 <lyxtabular version="3" rows="4" columns="4">
27785 <column alignment="center" valignment="top" leftline="true" width="0">
27786 <column alignment="center" valignment="top" leftline="true" width="0">
27787 <column alignment="center" valignment="top" leftline="true" width="0">
27788 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27789 <row topline="true" bottomline="true">
27790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27793 \begin_layout Standard
27799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27802 \begin_layout Standard
27808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27811 \begin_layout Standard
27817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27820 \begin_layout Standard
27827 <row topline="true">
27828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27831 \begin_layout Standard
27837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27840 \begin_layout Standard
27848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27851 \begin_layout Standard
27857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27860 \begin_layout Standard
27861 Writes/Reads characters via the USART peripheral
27867 <row topline="true">
27868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27871 \begin_layout Standard
27877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27880 \begin_layout Standard
27888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27891 \begin_layout Standard
27897 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27900 \begin_layout Standard
27901 Writes/Reads characters via the MSSP peripheral
27907 <row topline="true" bottomline="true">
27908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27911 \begin_layout Standard
27917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27920 \begin_layout Standard
27928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27931 \begin_layout Standard
27937 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27940 \begin_layout Standard
27941 Writes/Reads characters via used defined functions
27954 \begin_layout Standard
27955 The stream identifiers are declared as macros in the stdio.h header.
27958 \begin_layout Standard
27959 In the libc library there exist the functions that are used to write to
27960 each of the above streams.
27964 \begin_layout Description
27969 \begin_layout Standard
27978 _stream_usart_putchar writes a character at the USART stream
27981 \begin_layout Description
27986 \begin_layout Standard
27995 _stream_mssp_putchar writes a character at the MSSP stream
27998 \begin_layout Description
27999 putchar dummy function.
28000 This writes a character to a user specified manner.
28003 \begin_layout Standard
28004 In order to increase performance
28008 is declared in stdio.h as having its parameter in WREG (it has the wparam
28010 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
28011 in a user-friendly way.
28016 is the name of the variable that holds the character to print.
28017 An example follows:
28020 \begin_layout LyX-Code
28021 #include <pic18fregs.h>
28030 \begin_layout LyX-Code
28034 \begin_layout LyX-Code
28035 PORTA = c; /* dump character c to PORTA */
28038 \begin_layout LyX-Code
28046 \begin_layout LyX-Code
28050 \begin_layout LyX-Code
28051 stdout = STREAM_USER; /* this is not necessary, since stdout points
28054 \begin_layout LyX-Code
28055 * by default to STREAM_USER */
28058 \begin_layout LyX-Code
28060 \begin_inset Quotes sld
28063 This is a printf test
28066 \begin_inset Quotes srd
28072 \begin_layout LyX-Code
28076 \begin_layout LyX-Code
28080 \begin_layout Subsubsection
28084 \begin_layout Standard
28085 PIC16 contains an implementation of the printf-family of functions.
28086 There exist the following functions:
28089 \begin_layout LyX-Code
28090 extern unsigned int sprintf(char *buf, char *fmt, ...);
28093 \begin_layout LyX-Code
28094 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
28097 \begin_layout LyX-Code
28101 \begin_layout LyX-Code
28102 extern unsigned int printf(char *fmt, ...);
28105 \begin_layout LyX-Code
28106 extern unsigned int vprintf(char *fmt, va_lista ap);
28109 \begin_layout LyX-Code
28113 \begin_layout LyX-Code
28114 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
28117 \begin_layout LyX-Code
28118 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
28121 \begin_layout Standard
28122 For sprintf and vsprintf
28126 should normally be a data pointer where the resulting string will be placed.
28127 No range checking is done so the user should allocate the necessery buffer.
28128 For fprintf and vfprintf
28132 should be a stream pointer (i.e.
28133 stdout, STREAM_MSSP, etc...).
28136 \begin_layout Subsubsection
28140 \begin_layout Standard
28141 The PIC18F family of microcontrollers supports a number of interrupt sources.
28142 A list of these interrupts is shown in the following table:
28145 \begin_layout Standard
28147 \begin_inset Tabular
28148 <lyxtabular version="3" rows="11" columns="4">
28150 <column alignment="left" valignment="top" leftline="true" width="0">
28151 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28152 <column alignment="left" valignment="top" leftline="true" width="0">
28153 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28154 <row topline="true" bottomline="true">
28155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28158 \begin_layout Standard
28164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28167 \begin_layout Standard
28173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28176 \begin_layout Standard
28182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28185 \begin_layout Standard
28192 <row topline="true">
28193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28196 \begin_layout Standard
28202 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28205 \begin_layout Standard
28206 PORTB change interrupt
28211 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28214 \begin_layout Standard
28220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28223 \begin_layout Standard
28224 EEPROM/FLASH write complete interrupt
28230 <row topline="true">
28231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28234 \begin_layout Standard
28240 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28243 \begin_layout Standard
28244 INT0 external interrupt
28249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28252 \begin_layout Standard
28258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28261 \begin_layout Standard
28262 Bus collision interrupt
28268 <row topline="true">
28269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28272 \begin_layout Standard
28278 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28281 \begin_layout Standard
28282 INT1 external interrupt
28287 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28290 \begin_layout Standard
28296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28299 \begin_layout Standard
28300 Low voltage detect interrupt
28306 <row topline="true">
28307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28310 \begin_layout Standard
28316 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28319 \begin_layout Standard
28320 INT2 external interrupt
28325 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28328 \begin_layout Standard
28334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28337 \begin_layout Standard
28338 Parallel slave port interrupt
28344 <row topline="true">
28345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28348 \begin_layout Standard
28354 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28357 \begin_layout Standard
28358 CCP1 module interrupt
28363 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28366 \begin_layout Standard
28372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28375 \begin_layout Standard
28376 AD convertion complete interrupt
28382 <row topline="true">
28383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28386 \begin_layout Standard
28392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28395 \begin_layout Standard
28396 CCP2 module interrupt
28401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28404 \begin_layout Standard
28410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28413 \begin_layout Standard
28414 USART receive interrupt
28420 <row topline="true">
28421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28424 \begin_layout Standard
28430 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28433 \begin_layout Standard
28434 TMR0 overflow interrupt
28439 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28442 \begin_layout Standard
28448 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28451 \begin_layout Standard
28452 USART transmit interrupt
28458 <row topline="true">
28459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28462 \begin_layout Standard
28468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28471 \begin_layout Standard
28472 TMR1 overflow interrupt
28477 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28480 \begin_layout Standard
28486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28489 \begin_layout Standard
28490 SSP receive/transmit interrupt
28496 <row topline="true">
28497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28500 \begin_layout Standard
28506 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28509 \begin_layout Standard
28510 TMR2 matches PR2 interrupt
28515 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28518 \begin_layout Standard
28524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28527 \begin_layout Standard
28534 <row topline="true" bottomline="true">
28535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28538 \begin_layout Standard
28544 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28547 \begin_layout Standard
28548 TMR3 overflow interrupt
28553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28556 \begin_layout Standard
28562 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28565 \begin_layout Standard
28579 \begin_layout Standard
28580 The prototypes for these names are defined in the header file
28587 \begin_layout Standard
28588 In order to simplify signal handling, a number of macros is provided:
28592 \labelwidthstring 00.00.0000
28593 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
28594 high priority interrupts.
28599 is the function name to use.
28603 \labelwidthstring 00.00.0000
28604 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
28605 low priority interrupt.
28610 is the function name to use.
28614 \labelwidthstring 00.00.0000
28615 DEF_HANDLER(sig,handler) define a handler for signal
28621 \labelwidthstring 00.00.0000
28622 END_DEF end the declaration of the dispatch table.
28625 \begin_layout Standard
28626 Additionally there are two more macros to simplify the declaration of the
28631 \labelwidthstring 00.00.0000
28634 SIGHANDLER(handler)
28636 this declares the function prototype for the
28644 \labelwidthstring 00.00.0000
28645 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
28648 \begin_layout Standard
28649 An example of using the macros above is shown below:
28652 \begin_layout LyX-Code
28653 #include <pic18fregs.h>
28656 \begin_layout LyX-Code
28657 #include <signal.h>
28661 DEF_INTHIGH(high_int)
28664 \begin_layout LyX-Code
28665 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
28668 \begin_layout LyX-Code
28669 DEF_HANDLER(SIG_BCOL, _bcol_handler)
28672 \begin_layout LyX-Code
28677 SIGHANDLER(_tmr0_handler)
28680 \begin_layout LyX-Code
28684 \begin_layout LyX-Code
28685 /* action to be taken when timer 0 overflows */
28688 \begin_layout LyX-Code
28693 SIGHANDLERNAKED(_bcol_handler)
28696 \begin_layout LyX-Code
28700 \begin_layout LyX-Code
28704 \begin_layout LyX-Code
28705 /* action to be taken when bus collision occurs */
28708 \begin_layout LyX-Code
28712 \begin_layout LyX-Code
28716 \begin_layout LyX-Code
28720 \begin_layout Standard
28725 Special care should be taken when using the above scheme:
28728 \begin_layout Itemize
28729 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
28732 \begin_layout Itemize
28733 when declaring SIGHANDLERNAKED handler never forget to use
28737 for proper returning.
28740 \begin_layout Subsection
28744 \begin_layout Standard
28745 Here you can find some general tips for compiling programs with SDCC/pic16.
28748 \begin_layout Subsubsection
28752 \begin_layout Standard
28754 \begin_inset LatexCommand \index{PIC16!stack}
28758 size (that is 64 bytes) probably is enough for many programs.
28759 One must take care that when there are many levels of function nesting,
28760 or there is excessive usage of stack, its size should be extended.
28761 An example of such a case is the printf/sprintf family of functions.
28762 If you encounter problems like not being able to print integers, then you
28763 need to set the stack size around the maximum (256 for small stack model).
28764 The following diagram shows what happens when calling printf to print an
28768 \begin_layout LyX-Code
28769 printf () --> ltoa () --> ultoa () --> divschar ()
28772 \begin_layout Standard
28773 It is should be understood that stack is easily consumed when calling complicate
28775 Using command line arguments like -
28779 \begin_layout Standard
28788 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
28790 Other ways to reduce stack usage may exist.
28793 \begin_layout Subsection
28797 \begin_layout Standard
28798 The PIC16 Port currently does not pass SDCC's regression test
28799 \begin_inset LatexCommand \index{Regression test (PIC16)}
28804 \begin_inset LatexCommand \ref{sec:Quality-control}
28808 ) and thus the snapshot build regression tests for the PIC16 target are
28809 currently disabled for all hosts
28814 \begin_layout Chapter
28818 \begin_layout Standard
28819 There are several approaches to debugging your code.
28820 This chapter is meant to show your options and to give detail on some of
28825 When writing your code:
28828 \begin_layout Itemize
28829 write your code with debugging in mind (avoid duplicating code, put conceptually
28830 similar variables into structs, use structured code, have strategic points
28831 within your code where all variables are consistent, ...)
28834 \begin_layout Itemize
28835 run a syntax-checking tool like splint
28836 \begin_inset LatexCommand \index{splint (syntax checking tool)}
28841 \begin_inset LatexCommand \index{lint (syntax checking tool)}
28849 \begin_layout Standard
28859 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28866 \begin_layout Itemize
28867 for the high level code use a C-compiler (like f.e.
28868 GCC) to compile run and debug the code on your host.
28873 \begin_layout Standard
28883 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28887 ) on how to handle syntax extensions like __xdata, __at(), ...
28891 \begin_layout Itemize
28892 use another C-compiler to compile code for your target.
28893 Always an option but not recommended:) And not very likely to help you.
28894 If you seriously consider walking this path you should at least occasionally
28895 check portability of your code.
28896 Most commercial compiler vendors will offer an evaluation version so you
28897 can test compile your code or snippets of your code.
28900 \begin_layout Standard
28901 Debugging on a simulator:
28904 \begin_layout Itemize
28905 there is a separate section about SDCDB (section
28906 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
28913 \begin_layout Itemize
28914 or (8051 specific) use a freeware/commercial simulator which interfaces
28916 \begin_inset LatexCommand \index{AOMF, AOMF51}
28921 \begin_inset LatexCommand \ref{OMF file}
28925 ) optionally generated by SDCC.
28928 \begin_layout Standard
28929 Debugging On-target:
28932 \begin_layout Itemize
28933 use a MCU port pin to serially output debug data to the RS232 port of your
28935 You'll probably want some level shifting device typically involving a MAX232
28937 If the hardware serial port of the MCU is not available search for 'Software
28938 UART' in your favourite search machine.
28941 \begin_layout Itemize
28942 use an on-target monitor.
28943 In this context a monitor is a small program which usually accepts commands
28944 via a serial line and allows to set program counter, to single step through
28945 a program and read/write memory locations.
28946 For the 8051 good examples of monitors are paulmon and cmon51 (see section
28948 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
28955 \begin_layout Itemize
28956 toggle MCU port pins at strategic points within your code and use an oscilloscop
28960 digital oscilloscope
28963 \begin_inset LatexCommand \index{Oscilloscope}
28967 with deep trace memory is really helpful especially if you have to debug
28968 a realtime application.
28969 If you need to monitor more pins than your oscilloscope provides you can
28970 sometimes get away with a small R-2R network.
28971 On a single channel oscilloscope you could f.e.
28972 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
28974 \begin_inset Formula $\Omega$
28977 resistor and the other one by a 5\InsetSpace ~
28979 \begin_inset Formula $\Omega$
28982 resistor to the oscilloscope probe (check output drive capability of the
28983 pins you want to monitor).
28984 If you need to monitor many more pins a
28991 \begin_layout Itemize
29005 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
29010 Usually very expensive.
29011 And very nice to have too.
29012 And usually locks you (for years...) to the devices the ICE can emulate.
29016 \begin_layout Itemize
29017 use a remote debugger.
29018 In most 8-bit systems the symbol information is not available on the target,
29019 and a complete debugger is too bulky for the target system.
29020 Therefore usually a debugger on the host system connects to an on-target
29021 debugging stub which accepts only primitive commands.
29024 Terms to enter into your favourite search engine could be 'remote debugging',
29025 'gdb stub' or 'inferior debugger'.
29029 \begin_layout Itemize
29030 use an on target hardware debugger.
29031 Some of the more modern MCUs include hardware support for setting break
29032 points and monitoring/changing variables by using dedicated hardware pins.
29033 This facility doesn't require additional code to run on the target and
29038 doesn't affect runtime behaviour until a breakpoint is hit.
29039 For the mcs51 most hardware debuggers use the AOMF
29040 \begin_inset LatexCommand \index{AOMF, AOMF51}
29045 \begin_inset LatexCommand \ref{OMF file}
29053 \begin_layout Standard
29057 \begin_layout Itemize
29058 if you are not familiar with any of the following terms you're likely to
29059 run into problems rather sooner than later:
29076 As an embedded programmer you
29080 to know them so why not look them up
29084 you have problems?)
29087 \begin_layout Itemize
29088 tell someone else about your problem (actually this is a surprisingly effective
29089 means to hunt down the bug even if the listener is not familiar with your
29091 As 'failure to communicate' is probably one of the job-induced deformations
29092 of an embedded programmer this is highly encouraged.
29095 \begin_layout Section
29096 Debugging with SDCDB
29097 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
29102 \begin_inset LatexCommand \index{SDCDB (debugger)}
29109 \begin_layout Standard
29110 SDCC is distributed with a source level debugger
29111 \begin_inset LatexCommand \index{Debugger}
29116 The debugger uses a command line interface, the command repertoire of the
29117 debugger has been kept as close to gdb
29118 \begin_inset LatexCommand \index{gdb}
29122 (the GNU debugger) as possible.
29123 The configuration and build process is part of the standard compiler installati
29124 on, which also builds and installs the debugger in the target directory
29125 specified during configuration.
29126 The debugger allows you debug BOTH at the C source and at the ASM source
29130 \begin_layout Subsection
29131 Compiling for Debugging
29134 \begin_layout Standard
29139 \begin_layout Standard
29149 \begin_inset LatexCommand \index{-\/-debug}
29153 option must be specified for all files for which debug information is to
29155 The compiler generates a .adb file for each of these files.
29156 The linker creates the .cdb
29157 \begin_inset LatexCommand \index{<file>.cdb}
29162 \begin_inset LatexCommand \index{<file>.adb}
29166 files and the address information.
29167 This .cdb is used by the debugger.
29170 \begin_layout Subsection
29171 How the Debugger Works
29174 \begin_layout Standard
29179 \begin_layout Standard
29188 -debug option is specified the compiler generates extra symbol information
29189 some of which are put into the assembler source and some are put into the
29191 Then the linker creates the .cdb file from the individual .adb files with
29192 the address information for the symbols.
29193 The debugger reads the symbolic information generated by the compiler &
29194 the address information generated by the linker.
29195 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
29196 execution is controlled by the debugger.
29197 When a command is issued for the debugger, it translates it into appropriate
29198 commands for the simulator.
29199 (Currently SDCDM only connects to the simulator but
29204 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
29208 is an effort to connect directly to the hardware.)
29211 \begin_layout Subsection
29212 Starting the Debugger SDCDB
29215 \begin_layout Standard
29216 The debugger can be started using the following command line.
29217 (Assume the file you are debugging has the file name foo).
29231 The debugger will look for the following files.
29234 \begin_layout Itemize
29235 foo.c - the source file.
29238 \begin_layout Itemize
29239 foo.cdb - the debugger symbol information file.
29242 \begin_layout Itemize
29243 foo.ihx - the Intel hex format
29244 \begin_inset LatexCommand \index{Intel hex format}
29251 \begin_layout Subsection
29252 SDCDB Command Line Options
29255 \begin_layout Itemize
29260 \begin_layout Standard
29269 -directory=<source file directory> this option can used to specify the directory
29271 The debugger will look into the directory list specified for source, cdb
29273 The items in the directory list must be separated by ':', e.g.
29274 if the source files can be in the directories /home/src1 and /home/src2,
29279 \begin_layout Standard
29288 -directory option should be -
29292 \begin_layout Standard
29301 -directory=/home/src1:/home/src2.
29302 Note there can be no spaces in the option.
29306 \begin_layout Itemize
29307 -cd <directory> - change to the <directory>.
29310 \begin_layout Itemize
29311 -fullname - used by GUI front ends.
29314 \begin_layout Itemize
29315 -cpu <cpu-type> - this argument is passed to the simulator please see the
29316 simulator docs for details.
29319 \begin_layout Itemize
29320 -X <Clock frequency > this options is passed to the simulator please see
29321 the simulator docs for details.
29324 \begin_layout Itemize
29325 -s <serial port file> passed to simulator see the simulator docs for details.
29328 \begin_layout Itemize
29329 -S <serial in,out> passed to simulator see the simulator docs for details.
29332 \begin_layout Itemize
29333 -k <port number> passed to simulator see the simulator docs for details.
29336 \begin_layout Subsection
29337 SDCDB Debugger Commands
29340 \begin_layout Standard
29341 As mentioned earlier the command interface for the debugger has been deliberatel
29342 y kept as close the GNU debugger gdb, as possible.
29343 This will help the integration with existing graphical user interfaces
29344 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
29345 If you use a graphical user interface for the debugger you can skip this
29349 \begin_layout Subsubsection*
29350 break [line | file:line | function | file:function]
29353 \begin_layout Standard
29354 Set breakpoint at specified line or function:
29363 sdcdb>break foo.c:100
29365 sdcdb>break funcfoo
29367 sdcdb>break foo.c:funcfoo
29370 \begin_layout Subsubsection*
29371 clear [line | file:line | function | file:function ]
29374 \begin_layout Standard
29375 Clear breakpoint at specified line or function:
29384 sdcdb>clear foo.c:100
29386 sdcdb>clear funcfoo
29388 sdcdb>clear foo.c:funcfoo
29391 \begin_layout Subsubsection*
29395 \begin_layout Standard
29396 Continue program being debugged, after breakpoint.
29399 \begin_layout Subsubsection*
29403 \begin_layout Standard
29404 Execute till the end of the current function.
29407 \begin_layout Subsubsection*
29411 \begin_layout Standard
29412 Delete breakpoint number 'n'.
29413 If used without any option clear ALL user defined break points.
29416 \begin_layout Subsubsection*
29417 info [break | stack | frame | registers ]
29420 \begin_layout Itemize
29421 info break - list all breakpoints
29424 \begin_layout Itemize
29425 info stack - show the function call stack.
29428 \begin_layout Itemize
29429 info frame - show information about the current execution frame.
29432 \begin_layout Itemize
29433 info registers - show content of all registers.
29436 \begin_layout Subsubsection*
29440 \begin_layout Standard
29441 Step program until it reaches a different source line.
29442 Note: pressing <return> repeats the last command.
29445 \begin_layout Subsubsection*
29449 \begin_layout Standard
29450 Step program, proceeding through subroutine calls.
29453 \begin_layout Subsubsection*
29457 \begin_layout Standard
29458 Start debugged program.
29461 \begin_layout Subsubsection*
29465 \begin_layout Standard
29466 Print type information of the variable.
29469 \begin_layout Subsubsection*
29473 \begin_layout Standard
29474 print value of variable.
29477 \begin_layout Subsubsection*
29481 \begin_layout Standard
29482 load the given file name.
29483 Note this is an alternate method of loading file for debugging.
29486 \begin_layout Subsubsection*
29490 \begin_layout Standard
29491 print information about current frame.
29494 \begin_layout Subsubsection*
29498 \begin_layout Standard
29499 Toggle between C source & assembly source.
29502 \begin_layout Subsubsection*
29503 ! simulator command
29506 \begin_layout Standard
29507 Send the string following '!' to the simulator, the simulator response is
29509 Note the debugger does not interpret the command being sent to the simulator,
29510 so if a command like 'go' is sent the debugger can loose its execution
29511 context and may display incorrect values.
29514 \begin_layout Subsubsection*
29518 \begin_layout Standard
29521 My name is Bobby Brown"
29524 \begin_layout Subsection
29525 Interfacing SDCDB with DDD
29528 \begin_layout Standard
29529 \begin_inset Note Note
29532 \begin_layout Standard
29533 The screenshot was converted from png to eps with:
29534 \begin_inset Quotes sld
29537 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
29538 \begin_inset Quotes srd
29541 which produces a pretty compact eps file which is free from compression
29545 \begin_layout Standard
29546 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
29547 as this broke the build system on Sourceforge (pdf-file was broken.
29548 pdflatex does not accept eps files).
29556 \begin_layout Standard
29572 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
29578 shows a screenshot of a debugging session with DDD
29579 \begin_inset LatexCommand \index{DDD (debugger)}
29583 (Unix only) on a simulated 8032.
29584 The debugging session might not run as smoothly as the screenshot suggests.
29585 The debugger allows setting of breakpoints, displaying and changing variables,
29586 single stepping through C and assembler code.
29589 The source was compiled with
29603 \begin_layout Standard
29615 -debug ddd_example.c
29628 and DDD was invoked with
29635 ddd -debugger "sdcdb -cpu 8032 ddd_example"
29638 \begin_layout Standard
29639 \begin_inset Note Note
29642 \begin_layout Standard
29643 Check that the double quotes or an apostroph within the command line survive
29644 the LyX tool chain.
29645 Previously the apostrophs got slanted in the PDF output so a cut and paste
29654 \begin_layout Subsection
29655 Interfacing SDCDB with XEmacs
29656 \begin_inset LatexCommand \index{XEmacs}
29661 \begin_inset LatexCommand \index{Emacs}
29668 \begin_layout Standard
29669 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
29670 sdcdb.el and sdcdbsrc.el.
29671 These two files can be found in the $(prefix)/bin directory after the installat
29673 These files need to be loaded into XEmacs for the interface to work.
29674 This can be done at XEmacs startup time by inserting the following into
29675 your '.xemacs' file (which can be found in your HOME directory):
29681 (load-file sdcdbsrc.el)
29687 .xemacs is a lisp file so the () around the command is REQUIRED.
29688 The files can also be loaded dynamically while XEmacs is running, set the
29689 environment variable 'EMACSLOADPATH' to the installation bin directory
29690 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
29691 To start the interface enter the following command:
29705 You will prompted to enter the file name to be debugged.
29710 The command line options that are passed to the simulator directly are
29711 bound to default values in the file sdcdbsrc.el.
29712 The variables are listed below, these values maybe changed as required.
29715 \begin_layout Itemize
29716 sdcdbsrc-cpu-type '51
29719 \begin_layout Itemize
29720 sdcdbsrc-frequency '11059200
29723 \begin_layout Itemize
29724 sdcdbsrc-serial nil
29727 \begin_layout Standard
29728 The following is a list of key mapping for the debugger interface.
29731 \begin_layout Standard
29754 binding\InsetSpace ~
29792 -------\InsetSpace ~
29863 sdcdb-back-from-src\InsetSpace ~
29892 rom-src\InsetSpace ~
29902 SDCDB continue command
29920 sdcdb-step-from-src\InsetSpace ~
29949 hatis-c-sexp\InsetSpace ~
29959 SDCDB ptypecommand for data at
30026 sdcdbsrc-delete\InsetSpace ~
30041 B Delete all breakpoints if no arg
30090 given or delete arg (C-u arg x)
30109 -frame\InsetSpace ~
30124 SDCDB Display current frame if no arg,
30173 given or display frame arg
30241 sdcdbsrc-goto-sdcdb\InsetSpace ~
30251 Goto the SDCDB output buffer
30270 t-c-sexp\InsetSpace ~
30281 SDCDB print command for data at
30348 sdcdbsrc-goto-sdcdb\InsetSpace ~
30359 o the SDCDB output buffer
30377 sdcdbsrc-mode\InsetSpace ~
30393 Toggles Sdcdbsrc mode (turns it
30409 sdcdb-finish-from-src\InsetSpace ~
30417 SDCDB finish command
30451 Set break for line with point
30466 sdcdbsrc-mode\InsetSpace ~
30482 Toggle Sdcdbsrc mode
30498 dbsrc-srcmode\InsetSpace ~
30522 \begin_layout Chapter
30526 \begin_layout Standard
30527 Here are a few guidelines that will help the compiler generate more efficient
30528 code, some of the tips are specific to this compiler others are generally
30529 good programming practice.
30532 \begin_layout Itemize
30533 Use the smallest data type to represent your data-value.
30534 If it is known in advance that the value is going to be less than 256 then
30535 use an 'unsigned char' instead of a 'short' or 'int'.
30536 Please note, that ANSI C requires both signed and unsigned chars to be
30537 promoted to 'signed int'
30538 \begin_inset LatexCommand \index{promotion to signed int}
30543 \begin_inset Marginal
30546 \begin_layout Standard
30555 before doing any operation.
30557 \begin_inset LatexCommand \index{type promotion}
30562 \begin_inset LatexCommand \label{type promotion}
30566 can be omitted, if the result is the same.
30567 The effect of the promotion rules together with the sign-extension is often
30572 \begin_layout Verse
30575 unsigned char uc = 0xfe;
30577 if (uc * uc < 0) /* this is true! */
30590 \begin_layout Standard
30597 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
30605 \begin_layout Verse
30608 (unsigned char) -12 / (signed char) -3 = ...
30611 \begin_layout Standard
30612 No, the result is not 4:
30615 \begin_layout Verse
30618 (int) (unsigned char) -12 / (int) (signed char) -3 =
30620 (int) (unsigned char)
30621 0xf4 / (int) (signed char) 0xfd =
30623 (int) 0x00f4 / (int) 0xfffd =
30628 (int) 244 / (int) -3 =
30630 (int) -81 = (int) 0xffaf;
30633 \begin_layout Standard
30634 Don't complain, that gcc gives you a different result.
30635 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
30636 Therefore the results are different.
30639 \begin_inset Quotes sld
30643 \begin_inset Quotes srd
30649 \begin_layout Quote
30652 If well-defined overflow characteristics are important and negative values
30653 are not, or if you want to steer clear of sign-extension problems when
30654 manipulating bits or bytes, use one of the corresponding unsigned types.
30655 (Beware when mixing signed and unsigned values in expressions, though.)
30658 character types (especially unsigned char) can be used as "tiny" integers,
30659 doing so is sometimes more trouble than it's worth, due to unpredictable
30660 sign extension and increased code size.
30664 \begin_layout Itemize
30665 Use unsigned when it is known in advance that the value is not going to
30667 This helps especially if you are doing division or multiplication, bit-shifting
30668 or are using an array index.
30671 \begin_layout Itemize
30672 NEVER jump into a LOOP.
30675 \begin_layout Itemize
30676 Declare the variables to be local
30677 \begin_inset LatexCommand \index{local variables}
30681 whenever possible, especially loop control variables (induction).
30684 \begin_layout Itemize
30685 Have a look at the assembly listing to get a
30686 \begin_inset Quotes sld
30690 \begin_inset Quotes srd
30693 for the code generation.
30696 \begin_layout Section
30697 Porting code from or to other compilers
30698 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
30705 \begin_layout Itemize
30706 check whether endianness of the compilers differs and adapt where needed.
30709 \begin_layout Itemize
30710 check the device specific header files
30711 \begin_inset LatexCommand \index{Header files}
30716 \begin_inset LatexCommand \index{Include files}
30720 for compiler specific syntax.
30721 Eventually include the file <compiler.h
30722 \begin_inset LatexCommand \index{compiler.h (include file)}
30727 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
30731 to allow using common header files.
30734 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
30741 \begin_layout Itemize
30742 check whether the startup code contains the correct initialization (watchdog,
30746 \begin_layout Itemize
30747 check whether the sizes of short, int, long match.
30750 \begin_layout Itemize
30751 check if some 16 or 32 bit hardware registers require a specific addressing
30752 order (least significant or most significant byte first) and adapt if needed
30761 relate to time and not to lower/upper memory location here, so this is
30766 the same as endianness).
30769 \begin_layout Itemize
30770 check whether the keyword
30774 is used where needed.
30775 The compilers might differ in their optimization characteristics (as different
30776 versions of the same compiler might also use more clever optimizations
30777 this is good idea anyway).
30779 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
30786 \begin_layout Itemize
30787 check that the compilers are not told to supress warnings.
30790 \begin_layout Itemize
30791 check and convert compiler specific extensions (interrupts, memory areas,
30795 \begin_layout Itemize
30796 check for differences in type promotion.
30797 Especially check for math operations on
30806 For the sake of C99 compatibility SDCC will probably promote these to
30810 more often than other compilers.
30811 Eventually insert explicit casts to
30820 Also check that the ~\InsetSpace ~
30822 \begin_inset LatexCommand \index{\~\/ Operator}
30829 \begin_inset LatexCommand \index{bit}
30835 variables, use the !\InsetSpace ~
30838 \begin_inset LatexCommand \ref{type promotion}
30843 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30850 \begin_layout Itemize
30851 check the assembly code generated for interrupt routines (f.e.
30852 for calls to possibly non-reentrant library functions).
30855 \begin_layout Itemize
30856 check whether timing loops result in proper timing (or preferably consider
30857 a rewrite of the code with timer based delays instead).
30860 \begin_layout Itemize
30861 check for differences in printf parameters (some compilers push (va_arg
30862 \begin_inset LatexCommand \index{vararg, va\_arg}
30866 ) char variables as
30870 others push them as
30876 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30883 \begin_layout Itemize
30884 check the resulting memory map
30885 \begin_inset LatexCommand \index{Memory map}
30890 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
30891 ly idata, pdata, xdata).
30892 Eventually check if unexpected library functions are included.
30895 \begin_layout Section
30897 \begin_inset LatexCommand \index{Tools}
30901 included in the distribution
30904 \begin_layout Standard
30906 \begin_inset Tabular
30907 <lyxtabular version="3" rows="12" columns="3">
30909 <column alignment="left" valignment="top" leftline="true" width="0pt">
30910 <column alignment="left" valignment="top" leftline="true" width="0pt">
30911 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30912 <row topline="true" bottomline="true">
30913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30916 \begin_layout Standard
30924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30927 \begin_layout Standard
30935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30938 \begin_layout Standard
30947 <row topline="true">
30948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30951 \begin_layout Standard
30953 \begin_inset LatexCommand \index{uCsim}
30962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30965 \begin_layout Standard
30966 Simulator for various architectures
30971 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30974 \begin_layout Standard
30981 <row topline="true">
30982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30985 \begin_layout Standard
30991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30994 \begin_layout Standard
30996 \begin_inset LatexCommand \index{Header files}
31001 \begin_inset LatexCommand \index{Include files}
31010 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31013 \begin_layout Standard
31014 sdcc/support/scripts
31020 <row topline="true">
31021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31024 \begin_layout Standard
31030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31033 \begin_layout Standard
31034 header file conversion
31039 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31042 \begin_layout Standard
31043 sdcc/support/scripts
31049 <row topline="true">
31050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31053 \begin_layout Standard
31059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31062 \begin_layout Standard
31068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31071 \begin_layout Standard
31087 <row topline="true">
31088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31091 \begin_layout Standard
31097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31100 \begin_layout Standard
31106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31109 \begin_layout Standard
31125 <row topline="true">
31126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31129 \begin_layout Standard
31135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31138 \begin_layout Standard
31144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31147 \begin_layout Standard
31163 <row topline="true">
31164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31167 \begin_layout Standard
31173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31176 \begin_layout Standard
31182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31185 \begin_layout Standard
31201 <row topline="true">
31202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31205 \begin_layout Standard
31211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31214 \begin_layout Standard
31220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31223 \begin_layout Standard
31239 <row topline="true">
31240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31243 \begin_layout Standard
31249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31252 \begin_layout Standard
31258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31261 \begin_layout Standard
31277 <row topline="true">
31278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31281 \begin_layout Standard
31287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31290 \begin_layout Standard
31296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31299 \begin_layout Standard
31315 <row topline="true" bottomline="true">
31316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31319 \begin_layout Standard
31325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31328 \begin_layout Standard
31330 \begin_inset LatexCommand \index{packihx (tool)}
31339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31342 \begin_layout Standard
31367 \begin_layout Section
31369 \begin_inset LatexCommand \index{Documentation}
31373 included in the distribution
31376 \begin_layout Standard
31378 \begin_inset Tabular
31379 <lyxtabular version="3" rows="10" columns="2">
31381 <column alignment="block" valignment="top" leftline="true" width="40col%">
31382 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
31383 <row topline="true" bottomline="true" endhead="true">
31384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31387 \begin_layout Standard
31395 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31398 \begin_layout Standard
31401 Filename / Where to get
31407 <row topline="true">
31408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31411 \begin_layout Standard
31412 SDCC Compiler User Guide
31417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31420 \begin_layout Standard
31421 You're reading it right now
31433 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
31443 <row topline="true">
31444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31447 \begin_layout Standard
31453 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31456 \begin_layout Standard
31469 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31479 <row topline="true">
31480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31483 \begin_layout Standard
31485 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
31490 \begin_inset LatexCommand \index{Assembler documentation}
31497 \begin_inset LatexCommand \index{aslink}
31502 \begin_inset LatexCommand \index{Linker documentation}
31511 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31514 \begin_layout Standard
31515 sdcc/as/doc/asxhtm.html
31527 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
31537 <row topline="true">
31538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31541 \begin_layout Standard
31542 SDCC regression test
31543 \begin_inset LatexCommand \index{Regression test}
31552 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31555 \begin_layout Standard
31556 sdcc/doc/test_suite_spec.pdf
31568 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
31578 <row topline="true">
31579 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31582 \begin_layout Standard
31588 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31591 \begin_layout Standard
31604 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
31614 <row topline="true">
31615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31618 \begin_layout Standard
31619 Notes on debugging with SDCDB
31620 \begin_inset LatexCommand \index{SDCDB (debugger)}
31629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31632 \begin_layout Standard
31633 sdcc/debugger/README
31645 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
31655 <row topline="true">
31656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31659 \begin_layout Standard
31661 \begin_inset LatexCommand \index{uCsim}
31665 Software simulator for microcontrollers
31670 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31673 \begin_layout Standard
31703 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
31713 <row topline="true">
31714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31717 \begin_layout Standard
31718 Temporary notes on the pic16
31719 \begin_inset LatexCommand \index{PIC16}
31728 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31731 \begin_layout Standard
31732 sdcc/src/pic16/NOTES
31744 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
31754 <row topline="true" bottomline="true">
31755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31758 \begin_layout Standard
31759 SDCC internal documentation (debugging file format)
31764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31767 \begin_layout Standard
31797 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
31816 \begin_layout Section
31817 Related open source tools
31818 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
31823 \begin_inset LatexCommand \index{Related tools}
31830 \begin_layout Standard
31832 \begin_inset Tabular
31833 <lyxtabular version="3" rows="16" columns="3">
31835 <column alignment="left" valignment="top" leftline="true" width="0pt">
31836 <column alignment="block" valignment="top" leftline="true" width="30line%">
31837 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
31838 <row topline="true" bottomline="true">
31839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31842 \begin_layout Standard
31850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31853 \begin_layout Standard
31861 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31864 \begin_layout Standard
31873 <row topline="true">
31874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31877 \begin_layout Standard
31879 \begin_inset LatexCommand \index{gpsim (pic simulator)}
31888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31891 \begin_layout Standard
31897 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31900 \begin_layout Standard
31901 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
31911 <row topline="true">
31912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31915 \begin_layout Standard
31917 \begin_inset LatexCommand \index{gputils (pic tools)}
31926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31929 \begin_layout Standard
31935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31938 \begin_layout Standard
31939 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
31949 <row topline="true">
31950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31953 \begin_layout Standard
31959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31962 \begin_layout Standard
31968 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31971 \begin_layout Standard
31972 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
31982 <row topline="true">
31983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31986 \begin_layout Standard
31992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31995 \begin_layout Standard
31996 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
32002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32005 \begin_layout Standard
32006 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
32016 <row topline="true">
32017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32020 \begin_layout Standard
32022 \begin_inset LatexCommand \index{indent (source formatting tool)}
32031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32034 \begin_layout Standard
32035 Formats C source - Master of the white spaces
32040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32043 \begin_layout Standard
32044 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
32054 <row topline="true">
32055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32058 \begin_layout Standard
32060 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
32069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32072 \begin_layout Standard
32073 Object file conversion, checksumming, ...
32078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32081 \begin_layout Standard
32082 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
32092 <row topline="true">
32093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32096 \begin_layout Standard
32098 \begin_inset LatexCommand \index{objdump (tool)}
32107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32110 \begin_layout Standard
32111 Object file conversion, ...
32116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32119 \begin_layout Standard
32120 Part of binutils (should be there anyway)
32126 <row topline="true">
32127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32130 \begin_layout Standard
32136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32139 \begin_layout Standard
32140 8051 monitor (hex up-/download, single step, disassemble)
32145 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32148 \begin_layout Standard
32149 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
32159 <row topline="true">
32160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32163 \begin_layout Standard
32165 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
32174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32177 \begin_layout Standard
32178 Source code documentation system
32183 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32186 \begin_layout Standard
32187 \begin_inset LatexCommand \url{http://www.doxygen.org}
32197 <row topline="true">
32198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32201 \begin_layout Standard
32207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32210 \begin_layout Standard
32211 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
32216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32219 \begin_layout Standard
32220 \begin_inset LatexCommand \url{http://www.kdevelop.org}
32230 <row topline="true">
32231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32234 \begin_layout Standard
32240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32243 \begin_layout Standard
32244 8051 monitor (hex up-/download, single step, disassemble)
32249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32252 \begin_layout Standard
32253 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
32263 <row topline="true">
32264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32267 \begin_layout Standard
32269 \begin_inset LatexCommand \index{splint (syntax checking tool)}
32278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32281 \begin_layout Standard
32282 Statically checks c sources (see
32283 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
32292 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32295 \begin_layout Standard
32296 \begin_inset LatexCommand \url{http://www.splint.org}
32306 <row topline="true" bottomline="true">
32307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32310 \begin_layout Standard
32312 \begin_inset LatexCommand \index{DDD (debugger)}
32321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32324 \begin_layout Standard
32325 Debugger, serves nicely as GUI to SDCDB
32326 \begin_inset LatexCommand \index{SDCDB (debugger)}
32335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32338 \begin_layout Standard
32339 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
32349 <row bottomline="true">
32350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32353 \begin_layout Standard
32355 \begin_inset LatexCommand \index{d52}
32360 \begin_inset LatexCommand \index{d52 (disassembler)}
32369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32372 \begin_layout Standard
32373 Disassembler, can count instruction cycles
32374 \begin_inset LatexCommand \index{instruction cycles (count)}
32378 , use with options -pnd
32383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32386 \begin_layout Standard
32387 \begin_inset LatexCommand \url{http://www.8052.com/users/disasm/}
32397 <row bottomline="true">
32398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32401 \begin_layout Standard
32403 \begin_inset LatexCommand \index{cmake}
32412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32415 \begin_layout Standard
32416 Cross platform build system, generates Makefiles
32417 \begin_inset LatexCommand \index{Makefile}
32421 and project workspaces
32422 \begin_inset LatexCommand \index{project workspace}
32431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32434 \begin_layout Standard
32435 \begin_inset LatexCommand \url{http://www.cmake.org}
32443 and a dedicated wiki entry:
32444 \begin_inset LatexCommand \url{http://www.cmake.org/Wiki/CmakeSdcc}
32463 \begin_layout Section
32464 Related documentation / recommended reading
32467 \begin_layout Standard
32469 \begin_inset Tabular
32470 <lyxtabular version="3" rows="7" columns="3">
32472 <column alignment="left" valignment="top" leftline="true" width="0pt">
32473 <column alignment="left" valignment="top" leftline="true" width="0">
32474 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32475 <row topline="true" bottomline="true">
32476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32479 \begin_layout Standard
32487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32490 \begin_layout Standard
32498 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32501 \begin_layout Standard
32510 <row topline="true">
32511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32514 \begin_layout Standard
32529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32532 \begin_layout Standard
32534 \begin_inset LatexCommand \index{C Reference card}
32543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32546 \begin_layout Standard
32547 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
32557 <row topline="true">
32558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32561 \begin_layout Standard
32567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32570 \begin_layout Standard
32572 \begin_inset LatexCommand \index{C FAQ}
32581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32584 \begin_layout Standard
32585 \begin_inset LatexCommand \url{http://www.c-faq.com}
32595 <row topline="true">
32596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32599 \begin_layout Standard
32605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32608 \begin_layout Standard
32609 \begin_inset Quotes sld
32613 \begin_inset Quotes srd
32621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32624 \begin_layout Standard
32627 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
32637 <row topline="true">
32638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32641 \begin_layout Standard
32647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32650 \begin_layout Standard
32651 \begin_inset Quotes sld
32654 Extensions for Embedded C
32655 \begin_inset Quotes srd
32663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32666 \begin_layout Standard
32669 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
32679 <row topline="true">
32680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32683 \begin_layout Standard
32689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32692 \begin_layout Standard
32693 Latest datasheet of target CPU
32698 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32701 \begin_layout Standard
32708 <row topline="true" bottomline="true">
32709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32712 \begin_layout Standard
32718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32721 \begin_layout Standard
32722 Revision history of datasheet
32727 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32730 \begin_layout Standard
32746 \begin_layout Section
32747 Application notes specifically for SDCC
32750 \begin_layout Standard
32751 SDCC makes no claims about the completeness of this list and about up-to-datenes
32752 s or correctness of the application notes
32753 \begin_inset LatexCommand \index{Application notes}
32760 \begin_layout Standard
32764 \begin_inset Tabular
32765 <lyxtabular version="3" rows="7" columns="3">
32767 <column alignment="block" valignment="top" leftline="true" width="17col%">
32768 <column alignment="block" valignment="top" leftline="true" width="27col%">
32769 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
32770 <row topline="true" bottomline="true">
32771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32774 \begin_layout Standard
32783 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
32786 \begin_layout Standard
32795 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32798 \begin_layout Standard
32808 <row topline="true">
32809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32812 \begin_layout Standard
32820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32823 \begin_layout Standard
32826 Using the SDCC Compiler for the DS80C400
32827 \begin_inset LatexCommand \index{DS80C400}
32836 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32839 \begin_layout Standard
32842 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
32852 <row topline="true">
32853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32856 \begin_layout Standard
32864 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
32867 \begin_layout Standard
32870 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
32871 \begin_inset LatexCommand \index{DS89C4x0}
32875 Family of Microcontrollers
32880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32883 \begin_layout Standard
32886 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
32896 <row topline="true">
32897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32900 \begin_layout Standard
32903 Silicon Laboratories / Cygnal
32908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32911 \begin_layout Standard
32914 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
32915 \begin_inset LatexCommand \index{IDE}
32924 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32927 \begin_layout Standard
32930 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
32940 <row topline="true">
32941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32944 \begin_layout Standard
32947 Ramtron / Goal Semiconductor
32952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32955 \begin_layout Standard
32958 Interfacing SDCC to Syn and Textpad
32963 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32966 \begin_layout Standard
32969 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32979 <row topline="true">
32980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32983 \begin_layout Standard
32986 Ramtron / Goal Semiconductor
32991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32994 \begin_layout Standard
32997 Installing and Configuring SDCC and Crimson Editor
33002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33005 \begin_layout Standard
33008 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
33018 <row topline="true" bottomline="true">
33019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33022 \begin_layout Standard
33030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33033 \begin_layout Standard
33036 MSC12xx Programming with SDCC
33041 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33044 \begin_layout Standard
33047 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
33064 \begin_layout Section
33068 \begin_layout Standard
33069 Some questions answered, some pointers given - it might be time to in turn
33077 \begin_layout Itemize
33078 can you solve your project with the selected microcontroller? Would you
33079 find out early or rather late that your target is too small/slow/whatever?
33080 Can you switch to a slightly better device if it doesn't fit?
33083 \begin_layout Itemize
33084 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
33085 and/or another programming language be more adequate? Would an operating
33086 system on the target device help?
33089 \begin_layout Itemize
33090 if you solved the problem, will the marketing department be happy?
33093 \begin_layout Itemize
33094 if the marketing department is happy, will customers be happy?
33097 \begin_layout Itemize
33098 if you're the project manager, marketing department and maybe even the customer
33099 in one person, have you tried to see the project from the outside?
33102 \begin_layout Itemize
33103 is the project done if you think it is done? Or is just that other interface/pro
33104 tocol/feature/configuration/option missing? How about website, manual(s),
33105 internationali(z|s)ation, packaging, labels, 2nd source for components,
33106 electromagnetic compatability/interference, documentation for production,
33107 production test software, update mechanism, patent issues?
33110 \begin_layout Itemize
33111 is your project adequately positioned in that magic triangle: fame, fortune,
33115 \begin_layout Standard
33116 Maybe not all answers to these questions are known and some answers may
33121 , nevertheless knowing these questions may help you to avoid burnout
33125 \begin_layout Standard
33126 burnout is bad for electronic devices, programmers and motorcycle tyres
33132 Chances are you didn't want to hear some of them...
33135 \begin_layout Chapter
33137 \begin_inset LatexCommand \index{Support}
33144 \begin_layout Standard
33145 SDCC has grown to be a large project.
33146 The compiler alone (without the preprocessor, assembler and linker) is
33147 well over 150,000 lines of code (blank stripped).
33148 The open source nature of this project is a key to its continued growth
33150 You gain the benefit and support of many active software developers and
33152 Is SDCC perfect? No, that's why we need your help.
33153 The developers take pride in fixing reported bugs.
33154 You can help by reporting the bugs and helping other SDCC users.
33155 There are lots of ways to contribute, and we encourage you to take part
33156 in making SDCC a great software package.
33160 \begin_layout Standard
33161 The SDCC project is hosted on the SDCC sourceforge site at
33162 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
33167 You'll find the complete set of mailing lists
33168 \begin_inset LatexCommand \index{Mailing list(s)}
33172 , forums, bug reporting system, patch submission
33173 \begin_inset LatexCommand \index{Patch submission}
33178 \begin_inset LatexCommand \index{download}
33182 area and Subversion code repository
33183 \begin_inset LatexCommand \index{Subversion code repository}
33190 \begin_layout Section
33192 \begin_inset LatexCommand \index{Bug reporting}
33197 \begin_inset LatexCommand \index{Reporting bugs}
33204 \begin_layout Standard
33205 The recommended way of reporting bugs is using the infrastructure of the
33207 You can follow the status of bug reports there and have an overview about
33211 \begin_layout Standard
33212 Bug reports are automatically forwarded to the developer mailing list and
33213 will be fixed ASAP.
33214 When reporting a bug, it is very useful to include a small test program
33215 (the smaller the better) which reproduces the problem.
33216 If you can isolate the problem by looking at the generated assembly code,
33217 this can be very helpful.
33218 Compiling your program with the -
33222 \begin_layout Standard
33232 \begin_inset LatexCommand \index{-\/-dumpall}
33236 option can sometimes be useful in locating optimization problems.
33237 When reporting a bug please make sure you:
33240 \begin_layout Enumerate
33241 Attach the code you are compiling with SDCC.
33245 \begin_layout Enumerate
33246 Specify the exact command you use to run SDCC, or attach your Makefile.
33250 \begin_layout Enumerate
33251 Specify the SDCC version (type "
33257 "), your platform, and operating system.
33261 \begin_layout Enumerate
33262 Provide an exact copy of any error message or incorrect output.
33266 \begin_layout Enumerate
33267 Put something meaningful in the subject of your message.
33270 \begin_layout Standard
33271 Please attempt to include these 5 important parts, as applicable, in all
33272 requests for support or when reporting any problems or bugs with SDCC.
33273 Though this will make your message lengthy, it will greatly improve your
33274 chance that SDCC users and developers will be able to help you.
33275 Some SDCC developers are frustrated by bug reports without code provided
33276 that they can use to reproduce and ultimately fix the problem, so please
33277 be sure to provide sample code if you are reporting a bug!
33280 \begin_layout Standard
33281 Please have a short check that you are using a recent version of SDCC and
33282 the bug is not yet known.
33283 This is the link for reporting bugs:
33284 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
33289 With SDCC on average having more than 200 downloads
33290 \begin_inset LatexCommand \index{download}
33294 on sourceforge per day
33298 \begin_layout Standard
33299 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
33300 between 2002 and 2005.
33301 This does not include other methods of distribution.
33306 there must be some users.
33307 So it's not exactly easy to find a new bug.
33308 If you find one we need it:
33310 reporting bugs is good
33315 \begin_layout Section
33316 Requesting Features
33317 \begin_inset LatexCommand \label{sub:Requesting-Features}
33322 \begin_inset LatexCommand \index{Feature request}
33327 \begin_inset LatexCommand \index{Requesting features}
33334 \begin_layout Standard
33335 Like bug reports feature requests are forwarded to the developer mailing
33337 This is the link for requesting features:
33338 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33345 \begin_layout Section
33349 \begin_layout Standard
33350 Like bug reports contributed patches are forwarded to the developer mailing
33352 This is the link for submitting patches
33353 \begin_inset LatexCommand \index{Patch submission}
33358 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
33365 \begin_layout Standard
33366 You need to specify some parameters to the
33370 command for the patches to be useful.
33371 If you modified more than one file a patch created f.e.
33376 \begin_inset Quotes sld
33379 diff -Naur unmodified_directory modified_directory >my_changes.patch
33380 \begin_inset Quotes srd
33386 will be fine, otherwise
33390 \begin_inset Quotes sld
33393 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
33394 \begin_inset Quotes srd
33404 \begin_layout Section
33408 \begin_layout Standard
33409 These links should take you directly to the
33410 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
33418 \begin_layout Standard
33419 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
33420 automated messages (mid 2003)
33426 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
33431 \begin_inset LatexCommand \index{Mailing list(s)}
33435 and forums are archived and searchable so if you are lucky someone already
33436 had a similar problem.
33437 While mails to the lists themselves are delivered promptly their web front
33438 end on sourceforge sometimes shows a severe time lag (up to several weeks),
33439 if you're seriously using SDCC please consider subscribing to the lists.
33442 \begin_layout Section
33446 \begin_layout Standard
33447 You can follow the status of the Subversion version
33448 \begin_inset LatexCommand \index{version}
33452 of SDCC by watching the Changelog
33453 \begin_inset LatexCommand \index{Changelog}
33457 in the Subversion repository
33460 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
33467 \begin_layout Section
33468 Subversion Source Code Repository
33471 \begin_layout Standard
33481 \begin_layout Standard
33495 or the filenames of the snapshot versions of SDCC include date and its
33497 \begin_inset LatexCommand \index{Subversion code repository}
33502 Subversion allows to download the source of recent or previous versions
33504 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
33508 (by number or by date).
33509 An on-line source code browser and detailled instructions are also available
33511 SDCC versions starting from 1999 up to now are available (currently the
33512 versions prior to the conversion from cvs
33513 \begin_inset LatexCommand \index{cvs|see{Subversion}}
33517 to Subversion (April 2006) are either by accessible by Subversion or by
33521 \begin_layout Section
33523 \begin_inset LatexCommand \index{Release policy}
33530 \begin_layout Standard
33531 Historically there often were long delays between official releases and
33532 the sourceforge download area tends to get not updated at all.
33533 Excuses in the past might have referred to problems with live range analysis,
33534 but as this was fixed a while ago, the current problem is that another
33535 excuse has to be found.
33536 Kidding aside, we have to get better there! On the other hand there are
33537 daily snapshots available at
33538 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
33542 , and you can always build the very last version (hopefully with many bugs
33543 fixed, and features added) from the source code available at
33544 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
33550 \begin_inset LatexCommand \index{wiki}
33555 \begin_inset LatexCommand \index{SDCC Wiki}
33560 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/}
33564 also holds some information about past and future releases.
33567 \begin_layout Section
33569 \begin_inset LatexCommand \index{Examples}
33576 \begin_layout Standard
33577 You'll find some small examples in the directory
33579 sdcc/device/examples/.
33582 More examples and libraries are available at
33584 The SDCC Open Knowledge Resource
33585 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
33592 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
33599 \begin_layout Standard
33600 \begin_inset Note Note
33603 \begin_layout Standard
33604 I did insert a reference to Paul's web site here although it seems rather
33605 dedicated to a specific 8032 board (I think it's okay because it f.e.
33606 shows LCD/Harddisc interface and has a free 8051 monitor.
33607 Independent 8032 board vendors face hard competition of heavily subsidized
33608 development boards anyway).
33611 \begin_layout Standard
33612 Maybe we should include some links to real world applications.
33613 Preferably pointer to pointers (one for each architecture) so this stays
33622 \begin_layout Section
33624 \begin_inset LatexCommand \label{sec:Quality-control}
33629 \begin_inset LatexCommand \index{Quality control}
33636 \begin_layout Standard
33637 The compiler is passed through snaphot build compile and build checks.
33643 \begin_inset LatexCommand \index{Regression test}
33647 check that SDCC itself compiles flawlessly on several host platforms (i386,
33648 Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
33649 and checks the quality of the code generated by SDCC by running the code
33650 for several target platforms through simulators.
33651 The regression test suite comprises more than 100 files which expand to
33652 more than 500 test cases which include more than 4500 tests.
33653 The results of these tests are published daily on SDCC's snapshot page
33654 (click on the red or green symbols on the right side of
33655 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
33662 \begin_layout Standard
33663 There is a separate document
33666 \begin_inset LatexCommand \index{Test suite}
33673 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
33677 about the regression test suite.
33680 \begin_layout Standard
33681 You'll find the test code in the directory
33683 sdcc/support/regression
33686 You can run these tests manually by running
33690 in this directory (or f.e.
33695 \begin_inset Quotes sld
33699 \begin_inset Quotes srd
33705 if you don't want to run the complete tests).
33706 The test code might also be interesting if you want to look for examples
33707 \begin_inset LatexCommand \index{Examples}
33711 checking corner cases of SDCC or if you plan to submit patches
33712 \begin_inset LatexCommand \index{Patch submission}
33719 \begin_layout Standard
33720 The PIC14 port uses a different set of regression tests
33721 \begin_inset LatexCommand \index{Regression test (PIC14)}
33725 , you'll find them in the directory
33727 sdcc/src/regression
33732 \begin_layout Section
33733 Use of SDCC in Education
33736 \begin_layout Standard
33745 \begin_layout Standard
33746 the phrase "use in education" might evoke the association "
33750 fit for use in education".
33751 This connotation is not intended but nevertheless risked as the licensing
33752 of SDCC makes it difficult to offer educational discounts
33758 If your rationales are to:
33761 \begin_layout Enumerate
33762 give students a chance to understand the
33766 steps of code generation
33769 \begin_layout Enumerate
33770 have a curriculum that can be extended for years.
33771 Then you could use an fpga board as target and your curriculum will seamlessly
33772 extend from logic synthesis (
33773 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
33778 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
33782 ), over assembly programming, to C to FPGA compilers (
33783 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
33790 \begin_layout Enumerate
33791 be able to insert excursions about skills like using a revision control
33792 system, submitting/applying patches, using a type-setting (as opposed to
33793 word-processing) engine LyX/LaTeX, using
33794 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
33799 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
33803 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
33804 Source Software, CPU simulation, compiler regression tests
33805 \begin_inset LatexCommand \index{Regression test}
33812 And if there should be a shortage of ideas then you can always point students
33813 to the ever-growing feature request list
33814 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33821 \begin_layout Enumerate
33822 not tie students to a specific host platform and instead allow them to use
33827 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
33829 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
33836 \begin_layout Enumerate
33837 not encourage students to use illegal copies of educational software
33840 \begin_layout Enumerate
33841 be immune to licensing/availability/price changes of the chosen tool chain
33844 \begin_layout Enumerate
33845 be able to change to a new target platform without having to adopt a new
33849 \begin_layout Enumerate
33850 have complete control over and insight into the tool chain
33853 \begin_layout Enumerate
33854 make your students aware about the pros and cons of open source software
33858 \begin_layout Enumerate
33859 give back to the public as you are probably at least partially publically
33863 \begin_layout Enumerate
33864 give students a chance to publically prove their skills and to possibly
33865 see a world wide impact
33868 \begin_layout Standard
33869 then SDCC is probably among the first choices.
33870 Well, probably SDCC might be the only choice.
33875 \begin_layout Chapter
33876 SDCC Technical Data
33879 \begin_layout Section
33881 \begin_inset LatexCommand \index{Optimizations}
33888 \begin_layout Standard
33889 SDCC performs a host of standard optimizations in addition to some MCU specific
33894 \begin_layout Subsection
33895 Sub-expression Elimination
33896 \begin_inset LatexCommand \index{Subexpression elimination}
33903 \begin_layout Standard
33904 The compiler does local and
33923 \begin_layout Verse
33931 \begin_layout Standard
33932 will be translated to
33935 \begin_layout Verse
33945 \begin_layout Standard
33946 Some subexpressions are not as obvious as the above example, e.g.:
33949 \begin_layout Verse
33957 \begin_layout Standard
33958 In this case the address arithmetic a->b[i] will be computed only once;
33959 the equivalent code in C would be.
33962 \begin_layout Verse
33972 \begin_layout Standard
33973 The compiler will try to keep these temporary variables in registers.
33976 \begin_layout Subsection
33977 Dead-Code Elimination
33978 \begin_inset LatexCommand \index{Dead-code elimination}
33985 \begin_layout Verse
34000 i = 1; \InsetSpace ~
34009 global = 1;\InsetSpace ~
34023 global = 3;\InsetSpace ~
34029 \begin_layout Standard
34033 \begin_layout Verse
34049 \begin_layout Subsection
34051 \begin_inset LatexCommand \index{Copy propagation}
34058 \begin_layout Verse
34082 \begin_layout Standard
34086 \begin_layout Verse
34110 \begin_layout Standard
34111 Note: the dead stores created by this copy propagation will be eliminated
34112 by dead-code elimination.
34115 \begin_layout Subsection
34117 \begin_inset LatexCommand \index{Loop optimization}
34122 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
34129 \begin_layout Standard
34130 Two types of loop optimizations are done by SDCC
34138 of loop induction variables.
34139 In addition to the strength reduction the optimizer marks the induction
34140 variables and the register allocator tries to keep the induction variables
34141 in registers for the duration of the loop.
34142 Because of this preference of the register allocator
34143 \begin_inset LatexCommand \index{Register allocation}
34147 , loop induction optimization causes an increase in register pressure, which
34148 may cause unwanted spilling of other temporary variables into the stack
34149 \begin_inset LatexCommand \index{stack}
34154 The compiler will generate a warning message when it is forced to allocate
34155 extra space either on the stack or data space.
34156 If this extra space allocation is undesirable then induction optimization
34157 can be eliminated either for the entire source file (with -
34161 \begin_layout Standard
34170 -noinduction option) or for a given function only using #pragma\InsetSpace ~
34172 \begin_inset LatexCommand \index{\#pragma noinduction}
34183 \begin_layout Verse
34186 for (i = 0 ; i < 100 ; i ++)
34195 \begin_layout Standard
34199 \begin_layout Verse
34204 for (i = 0; i < 100; i++)
34213 \begin_layout Standard
34214 As mentioned previously some loop invariants are not as apparent, all static
34215 address computations are also moved out of the loop.
34220 \begin_inset LatexCommand \index{Strength reduction}
34224 , this optimization substitutes an expression by a cheaper expression:
34227 \begin_layout Verse
34230 for (i=0;i < 100; i++)
34239 \begin_layout Standard
34243 \begin_layout Verse
34250 for (i=0;i< 100;i++) {
34256 ar[itemp1] = itemp2;
34274 \begin_layout Standard
34275 The more expensive multiplication
34276 \begin_inset LatexCommand \index{Multiplication}
34280 is changed to a less expensive addition.
34283 \begin_layout Subsection
34285 \begin_inset LatexCommand \index{Loop reversing}
34292 \begin_layout Standard
34293 This optimization is done to reduce the overhead of checking loop boundaries
34294 for every iteration.
34295 Some simple loops can be reversed and implemented using a
34296 \begin_inset Quotes eld
34299 decrement and jump if not zero
34300 \begin_inset Quotes erd
34304 SDCC checks for the following criterion to determine if a loop is reversible
34305 (note: more sophisticated compilers use data-dependency analysis to make
34306 this determination, SDCC uses a more simple minded analysis).
34309 \begin_layout Itemize
34310 The 'for' loop is of the form
34316 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
34326 \begin_layout Itemize
34327 The <for body> does not contain
34328 \begin_inset Quotes eld
34332 \begin_inset Quotes erd
34336 \begin_inset Quotes erd
34342 \begin_layout Itemize
34343 All goto's are contained within the loop.
34346 \begin_layout Itemize
34347 No function calls within the loop.
34350 \begin_layout Itemize
34351 The loop control variable <sym> is not assigned any value within the loop
34354 \begin_layout Itemize
34355 The loop control variable does NOT participate in any arithmetic operation
34359 \begin_layout Itemize
34360 There are NO switch statements in the loop.
34363 \begin_layout Subsection
34364 Algebraic Simplifications
34367 \begin_layout Standard
34368 SDCC does numerous algebraic simplifications, the following is a small sub-set
34369 of these optimizations.
34372 \begin_layout Verse
34375 i = j + 0;\InsetSpace ~
34379 /* changed to: */\InsetSpace ~
34385 i /= 2;\InsetSpace ~
34392 /* changed to: */\InsetSpace ~
34399 = j - j;\InsetSpace ~
34403 /* changed to: */\InsetSpace ~
34409 i = j / 1;\InsetSpace ~
34413 /* changed to: */\InsetSpace ~
34420 \begin_layout Standard
34421 Note the subexpressions
34422 \begin_inset LatexCommand \index{Subexpression}
34426 given above are generally introduced by macro expansions or as a result
34427 of copy/constant propagation.
34430 \begin_layout Subsection
34431 'switch' Statements
34432 \begin_inset LatexCommand \label{sub:'switch'-Statements}
34437 \begin_inset LatexCommand \index{switch statement}
34444 \begin_layout Standard
34445 SDCC can optimize switch statements to jump tables
34446 \begin_inset LatexCommand \index{jump tables}
34451 It makes the decision based on an estimate of the generated code size.
34452 SDCC is quite liberal in the requirements for jump table generation:
34455 \begin_layout Itemize
34456 The labels need not be in order, and the starting number need not be one
34457 or zero, the case labels are in numerical sequence or not too many case
34458 labels are missing.
34462 \begin_layout Verse
34465 switch(i) {\InsetSpace ~
34496 case 4: ...\InsetSpace ~
34528 case 5: ...\InsetSpace ~
34560 case 3: ...\InsetSpace ~
34591 case 6: ...\InsetSpace ~
34623 case 7: ...\InsetSpace ~
34655 case 8: ...\InsetSpace ~
34687 case 9: ...\InsetSpace ~
34719 case 10: ...\InsetSpace ~
34750 case 11: ...\InsetSpace ~
34817 \begin_layout Standard
34818 Both the above switch statements will be implemented using a jump-table.
34819 The example to the right side is slightly more efficient as the check for
34820 the lower boundary of the jump-table is not needed.
34824 \begin_layout Itemize
34825 The number of case labels is not larger than supported by the target architectur
34829 \begin_layout Itemize
34830 If the case labels are not in numerical sequence ('gaps' between cases)
34831 SDCC checks whether a jump table with additionally inserted dummy cases
34832 is still attractive.
34836 \begin_layout Itemize
34837 If the starting number is not zero and a check for the lower boundary of
34838 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
34843 \begin_layout Standard
34844 Switch statements which have large gaps in the numeric sequence or those
34845 that have too many case labels can be split into more than one switch statement
34846 for efficient code generation, e.g.:
34849 \begin_layout Verse
34927 \begin_layout Standard
34928 If the above switch statement is broken down into two switch statements
34931 \begin_layout Verse
34974 \begin_layout Standard
34978 \begin_layout Verse
35021 \begin_layout Standard
35022 then both the switch statements will be implemented using jump-tables whereas
35023 the unmodified switch statement will not be.
35026 \begin_layout Standard
35027 \begin_inset Note Note
35030 \begin_layout Standard
35031 There might be reasons which SDCC cannot know about to either favour or
35032 not favour jump tables.
35033 If the target system has to be as quick for the last switch case as for
35034 the first (pro jump table), or if the switch argument is known to be zero
35035 in the majority of the cases (contra jump table).
35043 \begin_layout Standard
35044 The pragma nojtbound
35045 \begin_inset LatexCommand \index{\#pragma nojtbound}
35049 can be used to turn off checking the
35062 It has no effect if a default label is supplied.
35063 Use of this pragma is dangerous: if the switch
35064 \begin_inset LatexCommand \index{switch statement}
35068 argument is not matched by a case statement the processor will happily
35072 \begin_layout Subsection
35073 Bit-shifting Operations
35074 \begin_inset LatexCommand \index{Bit shifting}
35081 \begin_layout Standard
35082 Bit shifting is one of the most frequently used operation in embedded programmin
35084 SDCC tries to implement bit-shift operations in the most efficient way
35088 \begin_layout Verse
35101 \begin_layout Standard
35102 generates the following code:
35105 \begin_layout Verse
35120 \begin_layout Standard
35121 In general SDCC will never setup a loop if the shift count is known.
35125 \begin_layout Verse
35138 \begin_layout Standard
35142 \begin_layout Verse
35166 \begin_layout Subsection
35168 \begin_inset LatexCommand \index{Bit rotation}
35175 \begin_layout Standard
35176 A special case of the bit-shift operation is bit rotation
35177 \begin_inset LatexCommand \index{rotating bits}
35181 , SDCC recognizes the following expression to be a left bit-rotation:
35184 \begin_layout Verse
35192 char i;\InsetSpace ~
35203 /* unsigned is needed for rotation */
35208 i = ((i << 1) | (i >> 7));
35217 \begin_layout Standard
35218 will generate the following code:
35221 \begin_layout Verse
35238 \begin_layout Standard
35239 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
35240 ns of this case will also be recognized as bit-rotation, i.e.:
35243 \begin_layout Verse
35246 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
35249 \begin_layout Subsection
35250 Nibble and Byte Swapping
35253 \begin_layout Standard
35254 Other special cases of the bit-shift operations are nibble or byte swapping
35255 \begin_inset LatexCommand \index{swapping nibbles/bytes}
35259 , SDCC recognizes the following expressions:
35262 \begin_layout Verse
35283 i = ((i << 4) | (i >> 4));
35289 j = ((j << 8) | (j >> 8));
35292 \begin_layout Standard
35293 and generates a swap instruction for the nibble swapping
35294 \begin_inset LatexCommand \index{Nibble swapping}
35298 or move instructions for the byte swapping
35299 \begin_inset LatexCommand \index{Byte swapping}
35305 \begin_inset Quotes sld
35309 \begin_inset Quotes srd
35312 example can be used to convert from little to big-endian or vice versa.
35313 If you want to change the endianness of a
35317 integer you have to cast to
35324 \begin_layout Standard
35325 Note that SDCC stores numbers in little-endian
35329 \begin_layout Standard
35330 Usually 8-bit processors don't care much about endianness.
35331 This is not the case for the standard 8051 which only has an instruction
35337 \begin_inset LatexCommand \index{DPTR}
35345 so little-endian is the more efficient byte order.
35351 \begin_inset LatexCommand \index{little-endian}
35356 \begin_inset LatexCommand \index{Endianness}
35361 lowest order first).
35364 \begin_layout Subsection
35366 \begin_inset LatexCommand \index{Highest Order Bit}
35371 \begin_inset LatexCommand \index{Any Order Bit}
35378 \begin_layout Standard
35379 It is frequently required to obtain the highest order bit of an integral
35380 type (long, int, short or char types).
35381 Also obtaining any other order bit is not uncommon.
35382 SDCC recognizes the following expressions to yield the highest order bit
35383 and generates optimized code for it, e.g.:
35386 \begin_layout Verse
35397 unsigned char hob1, aob1;
35401 bit hob2, hob3, aob2,
35411 hob1 = (gint >> 15) & 1;
35415 hob2 = (gint >> 15) & 1;
35419 hob3 = gint & 0x8000;
35424 aob1 = (gint >> 9) & 1;
35428 aob2 = (gint >> 8) & 1;
35432 aob3 = gint & 0x0800;
35442 \begin_layout Standard
35443 will generate the following code:
35446 \begin_layout Verse
35477 000A E5*01\InsetSpace ~
35504 000C 23\InsetSpace ~
35535 000D 54 01\InsetSpace ~
35563 000F F5*02\InsetSpace ~
35618 0011 E5*01\InsetSpace ~
35646 0013 33\InsetSpace ~
35676 0014 92*00\InsetSpace ~
35732 0016 E5*01\InsetSpace ~
35759 0018 33\InsetSpace ~
35789 0019 92*01\InsetSpace ~
35845 001B E5*01\InsetSpace ~
35904 001E 54 01\InsetSpace ~
35931 0020 F5*03\InsetSpace ~
35987 0022 E5*01\InsetSpace ~
36014 0024 13\InsetSpace ~
36044 0025 92*02\InsetSpace ~
36100 0027 E5*01\InsetSpace ~
36155 002B 92*03\InsetSpace ~
36183 \begin_layout Standard
36184 Other variations of these cases however will
36189 They are standard C expressions, so I heartily recommend these be the only
36190 way to get the highest order bit, (it is portable).
36191 Of course it will be recognized even if it is embedded in other expressions,
36195 \begin_layout Verse
36198 xyz = gint + ((gint >> 15) & 1);
36201 \begin_layout Standard
36202 will still be recognized.
36205 \begin_layout Subsection
36207 \begin_inset LatexCommand \index{Higher Order Byte}
36211 / Higher Order Word
36212 \begin_inset LatexCommand \index{Higher Order Word}
36219 \begin_layout Standard
36220 It is also frequently required to obtain a higher order byte or word of
36221 a larger integral type (long, int or short types).
36222 SDCC recognizes the following expressions to yield the higher order byte
36223 or word and generates optimized code for it, e.g.:
36226 \begin_layout Verse
36231 unsigned long int glong;
36239 unsigned char hob1,
36244 unsigned int how1, how2;
36253 hob1 = (gint >> 8) & 0xFF;
36257 hob2 = glong >> 24;
36261 how1 = (glong >> 16) & 0xFFFF;
36276 \begin_layout Standard
36277 will generate the following code:
36280 \begin_layout Verse
36311 0037 85*01*06\InsetSpace ~
36333 _foo_hob1_1_1,(_gint + 1)
36364 003A 85*05*07\InsetSpace ~
36386 _foo_hob2_1_1,(_glong + 3)
36416 003D 85*04*08\InsetSpace ~
36439 _foo_how1_1_1,(_glong + 2)
36441 0040 85*05*09\InsetSpace ~
36466 0043 85*03*0A\InsetSpace ~
36488 _foo_how2_1_1,(_glong + 1)
36490 0046 85*04*0B\InsetSpace ~
36513 (_foo_how2_1_1 + 1),(_glong + 2)
36516 \begin_layout Standard
36517 Again, variations of these cases may
36522 They are standard C expressions, so I heartily recommend these be the only
36523 way to get the higher order byte/word, (it is portable).
36524 Of course it will be recognized even if it is embedded in other expressions,
36528 \begin_layout Verse
36531 xyz = gint + ((gint >> 8) & 0xFF);
36534 \begin_layout Standard
36535 will still be recognized.
36538 \begin_layout Subsection
36540 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
36545 \begin_inset LatexCommand \index{Peephole optimizer}
36552 \begin_layout Standard
36553 The compiler uses a rule based, pattern matching and re-writing mechanism
36554 for peep-hole optimization.
36559 a peep-hole optimizer by Christopher W.
36560 Fraser (cwfraser\InsetSpace ~
36563 A default set of rules are compiled into the compiler, additional rules
36564 may be added with the
36570 \begin_layout Standard
36580 \begin_inset LatexCommand \index{-\/-peep-file}
36587 The rule language is best illustrated with examples.
36590 \begin_layout Verse
36612 \begin_layout Standard
36613 The above rule will change the following assembly
36614 \begin_inset LatexCommand \index{Assembler routines}
36621 \begin_layout Verse
36629 \begin_layout Standard
36633 \begin_layout Verse
36639 \begin_layout Standard
36640 Note: All occurrences of a
36644 (pattern variable) must denote the same string.
36645 With the above rule, the assembly sequence:
36648 \begin_layout Verse
36656 \begin_layout Standard
36657 will remain unmodified.
36661 Other special case optimizations may be added by the
36668 \begin_layout Standard
36681 some variants of the 8051 MCU
36682 \begin_inset LatexCommand \index{MCS51 variants}
36695 The following two rules will change all
36712 \begin_layout Verse
36715 replace { lcall %1 } by { acall %1 }
36717 replace { ljmp %1 } by { ajmp %1 }
36720 \begin_layout Standard
36721 (NOTE: from version 2.7.3 on, you can use option -
36727 \begin_layout Standard
36739 \begin_inset LatexCommand \index{-\/-acall-ajmp}
36743 , which also takes care of aligning the interrupt vectors properly.)
36748 \begin_layout Standard
36751 inline-assembler code
36753 is also passed through the peep hole optimizer, thus the peephole optimizer
36754 can also be used as an assembly level macro expander.
36755 The rules themselves are MCU dependent whereas the rule language infra-structur
36756 e is MCU independent.
36757 Peephole optimization rules for other MCU can be easily programmed using
36762 The syntax for a rule is as follows:
36765 \begin_layout Verse
36768 rule := replace [ restart ] '{' <assembly sequence> '
36806 <assembly sequence> '
36824 '}' [if <functionName> ] '
36829 \begin_layout Standard
36830 <assembly sequence> := assembly instruction (each instruction including
36831 labels must be on a separate line).
36835 The optimizer will apply to the rules
36836 one by one from the top in the sequence of their appearance, it will terminate
36837 when all rules are exhausted.
36838 If the 'restart' option is specified, then the optimizer will start matching
36839 the rules again from the top, this option for a rule is expensive (performance)
36840 , it is intended to be used in situations where a transformation will trigger
36841 the same rule again.
36842 An example of this (not a good one, it has side effects) is the following
36846 \begin_layout Verse
36866 \begin_layout Standard
36867 Note that the replace pattern cannot be a blank, but can be a comment line.
36868 Without the 'restart' option only the innermost 'pop' 'push' pair would
36869 be eliminated, i.e.:
36872 \begin_layout Verse
36884 \begin_layout Standard
36888 \begin_layout Verse
36898 \begin_layout Standard
36903 the restart option the rule will be applied again to the resulting code
36904 and then all the pop-push pairs will be eliminated to yield:
36907 \begin_layout Verse
36915 \begin_layout Standard
36916 A conditional function can be attached to a rule.
36917 Attaching rules are somewhat more involved, let me illustrate this with
36921 \begin_layout Verse
36945 \begin_layout Standard
36946 The optimizer does a look-up of a function name table defined in function
36951 in the source file SDCCpeeph.c, with the name
36956 If it finds a corresponding entry the function is called.
36957 Note there can be no parameters specified for these functions, in this
36962 is crucial, since the function
36966 expects to find the label in that particular variable (the hash table containin
36967 g the variable bindings is passed as a parameter).
36968 If you want to code more such functions, take a close look at the function
36969 labelInRange and the calling mechanism in source file SDCCpeeph.c.
36970 Currently implemented are
36972 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
36973 24bitMode, portIsDS390, 24bitModeAndPortDS390
36982 \begin_layout Standard
36983 I know this whole thing is a little kludgey, but maybe some day we will
36984 have some better means.
36985 If you are looking at this file, you will see the default rules that are
36986 compiled into the compiler, you can add your own rules in the default set
36987 there if you get tired of specifying the -
36991 \begin_layout Standard
37003 \begin_layout Section
37005 \begin_inset LatexCommand \index{ANSI-compliance}
37010 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
37017 \begin_layout Standard
37018 The latest publically available version of the standard
37020 ISO/IEC 9899 - Programming languages - C
37022 should be available at:
37023 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
37032 \begin_layout Standard
37033 Deviations from the compliance:
37036 \begin_layout Itemize
37037 functions are not reentrant
37038 \begin_inset LatexCommand \index{reentrant}
37042 unless explicitly declared as such or the
37048 \begin_layout Standard
37058 \begin_inset LatexCommand \index{-\/-stack-auto}
37064 command line option is specified.
37067 \begin_layout Itemize
37069 \begin_inset LatexCommand \index{struct}
37074 \begin_inset LatexCommand \index{union}
37078 cannot be assigned values directly, cannot be passed as function parameters
37079 or assigned to each other and cannot be a return value
37080 \begin_inset LatexCommand \index{return value}
37084 from a function, e.g.:
37088 \begin_layout Verse
37111 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
37130 s parms) /* invalid in SDCC although allowed in ANSI */
37152 return rets; /* is invalid in SDCC although allowed in ANSI */
37158 \begin_layout Itemize
37159 initialization of structure arrays must be fully braced.
37163 \begin_layout Verse
37166 struct s { char x } a[] = {1, 2};\InsetSpace ~
37171 /* invalid in SDCC */
37174 } a[] = {{1}, {2}}; /* OK */
37178 \begin_layout Itemize
37180 \begin_inset LatexCommand \index{long long (not supported)}
37185 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
37192 \begin_layout Itemize
37194 \begin_inset LatexCommand \index{double (not supported)}
37198 ' precision floating point
37199 \begin_inset LatexCommand \index{Floating point support}
37206 \begin_layout Itemize
37208 \begin_inset LatexCommand \index{K\&R style}
37212 function declarations are NOT allowed.
37216 \begin_layout Verse
37219 foo(i,j) /* this old style of function declarations */
37221 int i,j; /* is valid
37222 in ANSI but not valid in SDCC */
37237 \begin_layout Itemize
37238 Most enhancements in C99 are not supported, e.g.:
37242 \begin_layout Verse
37249 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
37253 \begin_layout Itemize
37254 But some have been added recently in SDCC 2.7.0.
37255 They must be considered alpha quality however.
37259 \begin_layout Verse
37264 \begin_inset LatexCommand \index{inline (not supported)}
37270 int increment (int a) { return a+1; } /* inlines the increment without
37271 function call overhead */
37276 \begin_inset LatexCommand \index{inline (not supported)}
37282 p; /* accepted but ignored */
37286 \begin_layout Itemize
37287 Certain words that are valid identifiers in the standard may be reserved
37288 words in SDCC unless the
37294 \begin_layout Standard
37304 \begin_inset LatexCommand \index{-\/-std-c89}
37316 \begin_layout Standard
37326 \begin_inset LatexCommand \index{-\/-std-c99}
37332 command line options are used.
37333 These may include (depending on the selected processor): 'at', 'banked',
37334 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
37335 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
37336 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
37338 Compliant equivalents of these keywords are always available in a form
37339 that begin with two underscores
37340 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
37345 '__data' instead of 'data'.
37348 \begin_layout Itemize
37349 Integer promotion of variable arguments is not performed if the argument
37350 is explicitly taypecasted unless the
37356 \begin_layout Standard
37366 \begin_inset LatexCommand \index{-\/-std-c89}
37378 \begin_layout Standard
37388 \begin_inset LatexCommand \index{-\/-std-c99}
37394 command line options are used.
37398 \begin_layout Verse
37401 void vararg_func (char *str, ...) { str; }
37418 u is promoted to int before
37423 * passing to function */
37427 vararg_func ("%c", c);
37434 argument u is not promoted to int,
37439 * it is passed as char to function
37445 --std-cXX is not defined;
37450 * is promoted to int before passing
37456 if --std-cXX is defined */
37460 vararg_func ("%bc", (char)u);
37466 \begin_layout Section
37467 Cyclomatic Complexity
37468 \begin_inset LatexCommand \index{Cyclomatic complexity}
37475 \begin_layout Standard
37476 Cyclomatic complexity of a function is defined as the number of independent
37477 paths the program can take during execution of the function.
37478 This is an important number since it defines the number test cases you
37479 have to generate to validate the function.
37480 The accepted industry standard for complexity number is 10, if the cyclomatic
37481 complexity reported by SDCC exceeds 10 you should think about simplification
37482 of the function logic.
37483 Note that the complexity level is not related to the number of lines of
37484 code in a function.
37485 Large functions can have low complexity, and small functions can have large
37491 SDCC uses the following formula to compute the complexity:
37496 \begin_layout Standard
37497 complexity = (number of edges in control flow graph) - (number of nodes
37498 in control flow graph) + 2;
37502 Having said that the industry standard is 10,
37503 you should be aware that in some cases it be may unavoidable to have a
37504 complexity level of less than 10.
37505 For example if you have switch statement with more than 10 case labels,
37506 each case label adds one to the complexity level.
37507 The complexity level is by no means an absolute measure of the algorithmic
37508 complexity of the function, it does however provide a good starting point
37509 for which functions you might look at for further optimization.
37512 \begin_layout Section
37513 Retargetting for other Processors
37516 \begin_layout Standard
37517 The issues for retargetting the compiler are far too numerous to be covered
37519 What follows is a brief description of each of the seven phases of the
37520 compiler and its MCU dependency.
37523 \begin_layout Itemize
37524 Parsing the source and building the annotated parse tree.
37525 This phase is largely MCU independent (except for the language extensions).
37526 Syntax & semantic checks are also done in this phase, along with some initial
37527 optimizations like back patching labels and the pattern matching optimizations
37528 like bit-rotation etc.
37531 \begin_layout Itemize
37532 The second phase involves generating an intermediate code which can be easy
37533 manipulated during the later phases.
37534 This phase is entirely MCU independent.
37535 The intermediate code generation assumes the target machine has unlimited
37536 number of registers, and designates them with the name iTemp.
37537 The compiler can be made to dump a human readable form of the code generated
37542 \begin_layout Standard
37554 \begin_layout Itemize
37555 This phase does the bulk of the standard optimizations and is also MCU independe
37557 This phase can be broken down into several sub-phases:
37561 Break down intermediate
37562 code (iCode) into basic blocks.
37564 Do control flow & data flow analysis on the
37567 Do local common subexpression elimination, then global subexpressio
37570 Dead code elimination
37574 If loop optimizations
37575 caused any changes then do 'global subexpression elimination' and 'dead
37576 code elimination' again.
37579 \begin_layout Itemize
37580 This phase determines the live-ranges; by live range I mean those iTemp
37581 variables defined by the compiler that still survive after all the optimization
37583 Live range analysis
37584 \begin_inset LatexCommand \index{Live range analysis}
37588 is essential for register allocation, since these computation determines
37589 which of these iTemps will be assigned to registers, and for how long.
37592 \begin_layout Itemize
37593 Phase five is register allocation.
37594 There are two parts to this process.
37598 The first part I call 'register packing'
37599 (for lack of a better term).
37600 In this case several MCU specific expression folding is done to reduce
37605 The second part is more MCU independent and deals with
37606 allocating registers to the remaining live ranges.
37607 A lot of MCU specific code does creep into this phase because of the limited
37608 number of index registers available in the 8051.
37611 \begin_layout Itemize
37612 The Code generation phase is (unhappily), entirely MCU dependent and very
37613 little (if any at all) of this code can be reused for other MCU.
37614 However the scheme for allocating a homogenized assembler operand for each
37615 iCode operand may be reused.
37618 \begin_layout Itemize
37619 As mentioned in the optimization section the peep-hole optimizer is rule
37620 based system, which can reprogrammed for other MCUs.
37623 \begin_layout Standard
37624 More information is available on SDCC Wiki
37625 \begin_inset LatexCommand \index{wiki}
37630 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting}
37634 ) and in the thread
37635 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
37642 \begin_layout Chapter
37644 \begin_inset LatexCommand \index{Compiler internals}
37651 \begin_layout Section
37652 The anatomy of the compiler
37653 \begin_inset LatexCommand \label{sub:The-anatomy-of}
37660 \begin_layout Standard
37663 This is an excerpt from an article published in Circuit Cellar Magazine
37669 It's a little outdated (the compiler is much more efficient now and user/develo
37670 per friendly), but pretty well exposes the guts of it all.
37676 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
37677 It is fairly easy to retarget for other 8-bit MCU.
37678 Here we take a look at some of the internals of the compiler.
37682 \begin_layout Paragraph*
37684 \begin_inset LatexCommand \index{Parsing}
37691 \begin_layout Standard
37692 Parsing the input source file and creating an AST (Annotated Syntax Tree
37693 \begin_inset LatexCommand \index{Annotated syntax tree}
37698 This phase also involves propagating types (annotating each node of the
37699 parse tree with type information) and semantic analysis.
37700 There are some MCU specific parsing rules.
37701 For example the storage classes, the extended storage classes are MCU specific
37702 while there may be a xdata storage class for 8051 there is no such storage
37703 class for z80 or Atmel AVR.
37704 SDCC allows MCU specific storage class extensions, i.e.
37705 xdata will be treated as a storage class specifier when parsing 8051 C
37706 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
37710 \begin_layout Paragraph*
37712 \begin_inset LatexCommand \index{iCode}
37719 \begin_layout Standard
37720 Intermediate code generation.
37721 In this phase the AST is broken down into three-operand form (iCode).
37722 These three operand forms are represented as doubly linked lists.
37723 ICode is the term given to the intermediate form generated by the compiler.
37724 ICode example section shows some examples of iCode generated for some simple
37725 C source functions.
37728 \begin_layout Paragraph*
37730 \begin_inset LatexCommand \index{Optimizations}
37737 \begin_layout Standard
37738 Bulk of the target independent optimizations is performed in this phase.
37739 The optimizations include constant propagation, common sub-expression eliminati
37740 on, loop invariant code movement, strength reduction of loop induction variables
37741 and dead-code elimination.
37744 \begin_layout Paragraph*
37745 Live range analysis
37746 \begin_inset LatexCommand \index{Live range analysis}
37753 \begin_layout Standard
37754 During intermediate code generation phase, the compiler assumes the target
37755 machine has infinite number of registers and generates a lot of temporary
37757 The live range computation determines the lifetime of each of these compiler-ge
37758 nerated temporaries.
37759 A picture speaks a thousand words.
37760 ICode example sections show the live range annotations for each of the
37762 It is important to note here, each iCode is assigned a number in the order
37763 of its execution in the function.
37764 The live ranges are computed in terms of these numbers.
37765 The from number is the number of the iCode which first defines the operand
37766 and the to number signifies the iCode which uses this operand last.
37769 \begin_layout Paragraph*
37770 Register Allocation
37771 \begin_inset LatexCommand \index{Register allocation}
37778 \begin_layout Standard
37779 The register allocation determines the type and number of registers needed
37781 In most MCUs only a few registers can be used for indirect addressing.
37782 In case of 8051 for example the registers R0 & R1 can be used to indirectly
37783 address the internal ram and DPTR to indirectly address the external ram.
37784 The compiler will try to allocate the appropriate register to pointer variables
37786 ICode example section shows the operands annotated with the registers assigned
37788 The compiler will try to keep operands in registers as much as possible;
37789 there are several schemes the compiler uses to do achieve this.
37790 When the compiler runs out of registers the compiler will check to see
37791 if there are any live operands which is not used or defined in the current
37792 basic block being processed, if there are any found then it will push that
37793 operand and use the registers in this block, the operand will then be popped
37794 at the end of the basic block.
37798 \begin_layout Standard
37799 There are other MCU specific considerations in this phase.
37800 Some MCUs have an accumulator; very short-lived operands could be assigned
37801 to the accumulator instead of a general-purpose register.
37804 \begin_layout Paragraph*
37808 \begin_layout Standard
37809 Figure II gives a table of iCode
37810 \begin_inset LatexCommand \index{iCode}
37814 operations supported by the compiler.
37815 The code generation involves translating these operations into corresponding
37816 assembly code for the processor.
37817 This sounds overly simple but that is the essence of code generation.
37818 Some of the iCode operations are generated on a MCU specific manner for
37819 example, the z80 port does not use registers to pass parameters so the
37820 SEND and RECV iCode operations will not be generated, and it also does
37821 not support JUMPTABLES.
37827 \begin_layout Standard
37831 \begin_inset Tabular
37832 <lyxtabular version="3" rows="39" columns="4">
37833 <features islongtable="true" headBottomDL="true">
37834 <column alignment="block" valignment="top" leftline="true" width="13col%">
37835 <column alignment="left" valignment="top" leftline="true" width="13col%">
37836 <column alignment="block" valignment="top" leftline="true" width="22col%">
37837 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
37838 <row topline="true" bottomline="true" endhead="true">
37839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37842 \begin_layout Standard
37848 \begin_inset LatexCommand \index{iCode}
37857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37860 \begin_layout Standard
37868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37871 \begin_layout Standard
37879 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37882 \begin_layout Standard
37891 <row topline="true">
37892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37895 \begin_layout Standard
37903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37906 \begin_layout Standard
37909 IC_LEFT() IC_RESULT()
37914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37917 \begin_layout Standard
37925 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37928 \begin_layout Standard
37931 IC_RESULT = ! IC_LEFT;
37937 <row topline="true">
37938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37941 \begin_layout Standard
37949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37952 \begin_layout Standard
37955 IC_LEFT() IC_RESULT()
37960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37963 \begin_layout Standard
37966 Bitwise complement of
37971 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37974 \begin_layout Standard
37977 IC_RESULT = ~IC_LEFT;
37983 <row topline="true">
37984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37987 \begin_layout Standard
37995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37998 \begin_layout Standard
38001 IC_LEFT() IC_RESULT()
38006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38009 \begin_layout Standard
38012 Rotate right with carry
38017 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38020 \begin_layout Standard
38023 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
38029 <row topline="true">
38030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38033 \begin_layout Standard
38041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38044 \begin_layout Standard
38047 IC_LEFT() IC_RESULT()
38052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38055 \begin_layout Standard
38058 Rotate left with carry
38063 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38066 \begin_layout Standard
38069 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
38075 <row topline="true">
38076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38079 \begin_layout Standard
38087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38090 \begin_layout Standard
38093 IC_LEFT() IC_RESULT()
38098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38101 \begin_layout Standard
38104 Get the highest order bit of IC_LEFT
38109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38112 \begin_layout Standard
38115 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
38121 <row topline="true">
38122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38125 \begin_layout Standard
38133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38136 \begin_layout Standard
38139 IC_LEFT() IC_RESULT()
38144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38147 \begin_layout Standard
38155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38158 \begin_layout Standard
38161 IC_RESULT = - IC_LEFT;
38167 <row topline="true">
38168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38171 \begin_layout Standard
38179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38182 \begin_layout Standard
38190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38193 \begin_layout Standard
38196 Push the operand into stack
38201 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38204 \begin_layout Standard
38213 <row topline="true">
38214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38217 \begin_layout Standard
38225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38228 \begin_layout Standard
38236 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38239 \begin_layout Standard
38242 Pop the operand from the stack
38247 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38250 \begin_layout Standard
38259 <row topline="true">
38260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38263 \begin_layout Standard
38271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38274 \begin_layout Standard
38277 IC_LEFT() IC_RESULT()
38282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38285 \begin_layout Standard
38288 Call the function represented by IC_LEFT
38293 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38296 \begin_layout Standard
38299 IC_RESULT = IC_LEFT();
38305 <row topline="true">
38306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38309 \begin_layout Standard
38317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38320 \begin_layout Standard
38323 IC_LEFT() IC_RESULT()
38328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38331 \begin_layout Standard
38334 Call via function pointer
38339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38342 \begin_layout Standard
38345 IC_RESULT = (*IC_LEFT)();
38351 <row topline="true">
38352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38355 \begin_layout Standard
38363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38366 \begin_layout Standard
38374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38377 \begin_layout Standard
38380 Return the value in operand IC_LEFT
38385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38388 \begin_layout Standard
38397 <row topline="true">
38398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38401 \begin_layout Standard
38409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38412 \begin_layout Standard
38420 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38423 \begin_layout Standard
38431 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38434 \begin_layout Standard
38443 <row topline="true">
38444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38447 \begin_layout Standard
38455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38458 \begin_layout Standard
38466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38469 \begin_layout Standard
38477 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38480 \begin_layout Standard
38489 <row topline="true">
38490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38493 \begin_layout Standard
38501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38504 \begin_layout Standard
38507 IC_LEFT() IC_RIGHT() IC_RESULT()
38512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38515 \begin_layout Standard
38523 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38526 \begin_layout Standard
38529 IC_RESULT = IC_LEFT + IC_RIGHT
38535 <row topline="true">
38536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38539 \begin_layout Standard
38547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38550 \begin_layout Standard
38553 IC_LEFT() IC_RIGHT() IC_RESULT()
38558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38561 \begin_layout Standard
38569 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38572 \begin_layout Standard
38575 IC_RESULT = IC_LEFT - IC_RIGHT
38581 <row topline="true">
38582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38585 \begin_layout Standard
38593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38596 \begin_layout Standard
38599 IC_LEFT() IC_RIGHT() IC_RESULT()
38604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38607 \begin_layout Standard
38615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38618 \begin_layout Standard
38621 IC_RESULT = IC_LEFT * IC_RIGHT;
38627 <row topline="true">
38628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38631 \begin_layout Standard
38639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38642 \begin_layout Standard
38645 IC_LEFT() IC_RIGHT() IC_RESULT()
38650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38653 \begin_layout Standard
38661 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38664 \begin_layout Standard
38667 IC_RESULT = IC_LEFT / IC_RIGHT;
38673 <row topline="true">
38674 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38677 \begin_layout Standard
38685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38688 \begin_layout Standard
38691 IC_LEFT() IC_RIGHT() IC_RESULT()
38696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38699 \begin_layout Standard
38707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38710 \begin_layout Standard
38713 IC_RESULT = IC_LEFT % IC_RIGHT;
38719 <row topline="true">
38720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38723 \begin_layout Standard
38731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38734 \begin_layout Standard
38737 IC_LEFT() IC_RIGHT() IC_RESULT()
38742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38745 \begin_layout Standard
38753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38756 \begin_layout Standard
38759 IC_RESULT = IC_LEFT < IC_RIGHT;
38765 <row topline="true">
38766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38769 \begin_layout Standard
38777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38780 \begin_layout Standard
38783 IC_LEFT() IC_RIGHT() IC_RESULT()
38788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38791 \begin_layout Standard
38799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38802 \begin_layout Standard
38805 IC_RESULT = IC_LEFT > IC_RIGHT;
38811 <row topline="true">
38812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38815 \begin_layout Standard
38823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38826 \begin_layout Standard
38829 IC_LEFT() IC_RIGHT() IC_RESULT()
38834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38837 \begin_layout Standard
38845 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38848 \begin_layout Standard
38851 IC_RESULT = IC_LEFT == IC_RIGHT;
38857 <row topline="true">
38858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38861 \begin_layout Standard
38869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38872 \begin_layout Standard
38875 IC_LEFT() IC_RIGHT() IC_RESULT()
38880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38883 \begin_layout Standard
38886 Logical and operation
38891 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38894 \begin_layout Standard
38897 IC_RESULT = IC_LEFT && IC_RIGHT;
38903 <row topline="true">
38904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38907 \begin_layout Standard
38915 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38918 \begin_layout Standard
38921 IC_LEFT() IC_RIGHT() IC_RESULT()
38926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38929 \begin_layout Standard
38932 Logical or operation
38937 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38940 \begin_layout Standard
38943 IC_RESULT = IC_LEFT || IC_RIGHT;
38949 <row topline="true">
38950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38953 \begin_layout Standard
38961 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38964 \begin_layout Standard
38967 IC_LEFT() IC_RIGHT() IC_RESULT()
38972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38975 \begin_layout Standard
38983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38986 \begin_layout Standard
38989 IC_RESULT = IC_LEFT ^ IC_RIGHT;
38995 <row topline="true">
38996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38999 \begin_layout Standard
39007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39010 \begin_layout Standard
39013 IC_LEFT() IC_RIGHT() IC_RESULT()
39018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39021 \begin_layout Standard
39029 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39032 \begin_layout Standard
39035 IC_RESULT = IC_LEFT | IC_RIGHT;
39041 <row topline="true">
39042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39045 \begin_layout Standard
39053 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39056 \begin_layout Standard
39059 IC_LEFT() IC_RIGHT() IC_RESULT()
39064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39067 \begin_layout Standard
39075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39078 \begin_layout Standard
39081 IC_RESULT = IC_LEFT & IC_RIGHT;
39087 <row topline="true">
39088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39091 \begin_layout Standard
39099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39102 \begin_layout Standard
39105 IC_LEFT() IC_RIGHT() IC_RESULT()
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" rightline="true" usebox="none">
39124 \begin_layout Standard
39127 IC_RESULT = IC_LEFT << IC_RIGHT
39133 <row topline="true">
39134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39137 \begin_layout Standard
39145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39148 \begin_layout Standard
39151 IC_LEFT() IC_RIGHT() IC_RESULT()
39156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39159 \begin_layout Standard
39167 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39170 \begin_layout Standard
39173 IC_RESULT = IC_LEFT >> IC_RIGHT
39179 <row topline="true">
39180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39183 \begin_layout Standard
39193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39196 \begin_layout Standard
39199 IC_LEFT() IC_RESULT()
39204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39207 \begin_layout Standard
39215 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39218 \begin_layout Standard
39221 IC_RESULT = (*IC_LEFT);
39227 <row topline="true">
39228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39231 \begin_layout Standard
39239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39242 \begin_layout Standard
39245 IC_RIGHT() IC_RESULT()
39250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39253 \begin_layout Standard
39261 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39264 \begin_layout Standard
39267 (*IC_RESULT) = IC_RIGHT;
39273 <row topline="true">
39274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39277 \begin_layout Standard
39285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39288 \begin_layout Standard
39291 IC_RIGHT() IC_RESULT()
39296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39299 \begin_layout Standard
39307 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39310 \begin_layout Standard
39313 IC_RESULT = IC_RIGHT;
39319 <row topline="true">
39320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39323 \begin_layout Standard
39331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39334 \begin_layout Standard
39337 IC_COND IC_TRUE IC_LABEL
39342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39345 \begin_layout Standard
39349 If true label is present then jump to true label if condition is true else
39350 jump to false label if condition is false
39355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39358 \begin_layout Standard
39361 if (IC_COND) goto IC_TRUE;
39367 If (!IC_COND) goto IC_FALSE;
39373 <row topline="true">
39374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39377 \begin_layout Standard
39385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39388 \begin_layout Standard
39391 IC_LEFT() IC_RESULT()
39396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39399 \begin_layout Standard
39407 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39410 \begin_layout Standard
39413 IC_RESULT = &IC_LEFT();
39419 <row topline="true">
39420 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39423 \begin_layout Standard
39431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39434 \begin_layout Standard
39437 IC_JTCOND IC_JTLABELS
39442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39445 \begin_layout Standard
39448 Jump to list of labels depending on the value of JTCOND
39453 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39456 \begin_layout Standard
39465 <row topline="true">
39466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39469 \begin_layout Standard
39477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39480 \begin_layout Standard
39483 IC_RIGHT() IC_LEFT() IC_RESULT()
39488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39491 \begin_layout Standard
39499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39502 \begin_layout Standard
39505 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
39511 <row topline="true">
39512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39515 \begin_layout Standard
39523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39526 \begin_layout Standard
39534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39537 \begin_layout Standard
39540 This is used for passing parameters in registers;
39542 move IC_LEFT to the next
39543 available parameter register.
39548 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39551 \begin_layout Standard
39560 <row topline="true">
39561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39564 \begin_layout Standard
39572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39575 \begin_layout Standard
39583 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39586 \begin_layout Standard
39589 This is used for receiving parameters passed in registers;
39592 in the next parameter register to IC_RESULT
39597 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39600 \begin_layout Standard
39609 <row topline="true" bottomline="true">
39610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39613 \begin_layout Standard
39617 (some more have been added)
39622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39625 \begin_layout Standard
39631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39634 \begin_layout Standard
39640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39643 \begin_layout Standard
39667 \begin_layout Standard
39668 \begin_inset Note Note
39671 \begin_layout Standard
39672 In the original article Figure II was announced to be downloadable on
39677 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
39685 \begin_layout Paragraph*
39687 \begin_inset LatexCommand \index{iCode}
39694 \begin_layout Standard
39695 This section shows some details of iCode.
39696 The example C code does not do anything useful; it is used as an example
39697 to illustrate the intermediate code generated by the compiler.
39700 \begin_layout Verse
39710 /* This function does nothing useful.
39717 for the purpose of explaining iCode */
39720 short function (data
39729 short i=10; \InsetSpace ~
39731 /* dead initialization eliminated */
39737 /* dead initialization eliminated */
39765 /* compiler detects i,j to be induction
39770 for (i = 0, j = 10 ; i < 10 ; i++, j
39776 \begin_layout Standard
39799 mul += i * 3; \InsetSpace ~
39801 /* this multiplication remains */
39808 j * 3;\InsetSpace ~
39810 /* this multiplication changed to addition */
39824 \begin_layout Standard
39825 In addition to the operands each iCode contains information about the filename
39826 and line it corresponds to in the source file.
39827 The first field in the listing should be interpreted as follows:
39832 Filename(linenumber: iCode Execution sequence number : ICode hash table
39833 key : loop depth of the iCode).
39838 Then follows the human readable form of the ICode operation.
39839 Each operand of this triplet form can be of three basic types a) compiler
39840 generated temporary b) user defined variable c) a constant value.
39841 Note that local variables and parameters are replaced by compiler generated
39844 \begin_inset LatexCommand \index{Live range analysis}
39848 are computed only for temporaries (i.e.
39849 live ranges are not computed for global variables).
39851 \begin_inset LatexCommand \index{Register allocation}
39855 are allocated for temporaries only.
39856 Operands are formatted in the following manner:
39861 Operand Name [lr live-from : live-to ] { type information } [ registers
39867 As mentioned earlier the live ranges are computed in terms of the execution
39868 sequence number of the iCodes, for example
39870 the iTemp0 is live from (i.e.
39871 first defined in iCode with execution sequence number 3, and is last used
39872 in the iCode with sequence number 5).
39873 For induction variables such as iTemp21 the live range computation extends
39874 the lifetime from the start to the end of the loop.
39876 The register allocator
39877 used the live range information to allocate registers, the same registers
39878 may be used for different temporaries if their live ranges do not overlap,
39879 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
39880 ranges do not overlap.
39881 In addition the allocator also takes into consideration the type and usage
39882 of a temporary, for example itemp6 is a pointer to near space and is used
39883 as to fetch data from (i.e.
39884 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
39885 Some short lived temporaries are allocated to special registers which have
39886 meaning to the code generator e.g.
39887 iTemp13 is allocated to a pseudo register CC which tells the back end that
39888 the temporary is used only for a conditional jump the code generation makes
39889 use of this information to optimize a compare and jump ICode.
39893 \begin_inset LatexCommand \index{Loop optimization}
39897 performed by the compiler.
39898 It can detect induction variables iTemp21(i) and iTemp23(j).
39899 Also note the compiler does selective strength reduction
39900 \begin_inset LatexCommand \index{Strength reduction}
39905 the multiplication of an induction variable in line 18 (gint = j * 3) is
39906 changed to addition, a new temporary iTemp17 is allocated and assigned
39907 a initial value, a constant 3 is then added for each iteration of the loop.
39908 The compiler does not change the multiplication
39909 \begin_inset LatexCommand \index{Multiplication}
39913 in line 17 however since the processor does support an 8 * 8 bit multiplication.
39916 Note the dead code elimination
39917 \begin_inset LatexCommand \index{Dead-code elimination}
39921 optimization eliminated the dead assignments in line 7 & 8 to I and sum
39927 \begin_layout Standard
39930 Sample.c (5:1:0:0) _entry($9) :
39933 \begin_layout Standard
39936 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
39939 \begin_layout Standard
39942 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
39945 \begin_layout Standard
39948 Sample.c(11:4:53:0) preHeaderLbl0($11) :
39951 \begin_layout Standard
39954 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
39958 \begin_layout Standard
39961 Sample.c(11:6:5:1) _whilecontinue_0($1) :
39964 \begin_layout Standard
39967 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
39971 \begin_layout Standard
39974 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39977 \begin_layout Standard
39980 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
39984 \begin_layout Standard
39987 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
39991 \begin_layout Standard
39994 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
39998 \begin_layout Standard
40001 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
40005 \begin_layout Standard
40008 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
40009 * int}[r0] + 0x2 {short}
40012 \begin_layout Standard
40015 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
40018 \begin_layout Standard
40021 Sample.c(11:17:21:0)_whilebreak_0($3) :
40024 \begin_layout Standard
40027 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
40030 \begin_layout Standard
40033 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
40036 \begin_layout Standard
40039 Sample.c(15:20:54:0)preHeaderLbl1($13) :
40042 \begin_layout Standard
40045 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
40048 \begin_layout Standard
40051 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
40054 \begin_layout Standard
40057 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
40060 \begin_layout Standard
40063 Sample.c(15:24:26:1)_forcond_0($4) :
40066 \begin_layout Standard
40069 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
40073 \begin_layout Standard
40076 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
40079 \begin_layout Standard
40082 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
40083 + ITemp21 [lr21:38]{short}[r4]
40086 \begin_layout Standard
40089 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
40093 \begin_layout Standard
40096 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
40097 + iTemp15 [lr29:30]{short}[r1]
40100 \begin_layout Standard
40103 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
40107 \begin_layout Standard
40110 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
40114 \begin_layout Standard
40117 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
40121 \begin_layout Standard
40124 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
40128 \begin_layout Standard
40131 Sample.c(19:38:47:1) goto _forcond_0($4)
40134 \begin_layout Standard
40137 Sample.c(19:39:48:0)_forbreak_0($7) :
40140 \begin_layout Standard
40143 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
40144 + ITemp11 [lr19:40]{short}[r3]
40147 \begin_layout Standard
40150 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
40153 \begin_layout Standard
40156 Sample.c(20:42:51:0)_return($8) :
40159 \begin_layout Standard
40162 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
40168 Finally the code generated for this function:
40173 \begin_layout Standard
40179 \begin_layout Standard
40185 \begin_layout Standard
40193 \begin_layout Standard
40199 \begin_layout Standard
40207 \begin_layout Standard
40213 \begin_layout Standard
40216 ; ----------------------------------------------
40219 \begin_layout Standard
40222 ; function function
40225 \begin_layout Standard
40228 ; ----------------------------------------------
40231 \begin_layout Standard
40237 \begin_layout Standard
40240 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
40243 \begin_layout Standard
40251 \begin_layout Standard
40254 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
40257 \begin_layout Standard
40265 \begin_layout Standard
40268 ;_whilecontinue_0($1) :
40271 \begin_layout Standard
40277 \begin_layout Standard
40280 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
40283 \begin_layout Standard
40286 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
40289 \begin_layout Standard
40297 \begin_layout Standard
40305 \begin_layout Standard
40313 \begin_layout Standard
40321 \begin_layout Standard
40329 \begin_layout Standard
40337 \begin_layout Standard
40345 \begin_layout Standard
40351 \begin_layout Standard
40354 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
40357 \begin_layout Standard
40365 \begin_layout Standard
40373 \begin_layout Standard
40376 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
40379 \begin_layout Standard
40387 \begin_layout Standard
40395 \begin_layout Standard
40403 \begin_layout Standard
40411 \begin_layout Standard
40419 \begin_layout Standard
40427 \begin_layout Standard
40430 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
40433 \begin_layout Standard
40441 \begin_layout Standard
40449 \begin_layout Standard
40457 \begin_layout Standard
40465 \begin_layout Standard
40473 \begin_layout Standard
40476 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
40479 \begin_layout Standard
40487 \begin_layout Standard
40495 \begin_layout Standard
40503 \begin_layout Standard
40506 ; iTemp6 [lr5:16]{_near * int}[r0] =
40509 \begin_layout Standard
40512 ; iTemp6 [lr5:16]{_near * int}[r0] +
40515 \begin_layout Standard
40521 \begin_layout Standard
40529 \begin_layout Standard
40532 ; goto _whilecontinue_0($1)
40535 \begin_layout Standard
40543 \begin_layout Standard
40546 ; _whilebreak_0($3) :
40549 \begin_layout Standard
40555 \begin_layout Standard
40558 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
40561 \begin_layout Standard
40569 \begin_layout Standard
40572 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
40575 \begin_layout Standard
40583 \begin_layout Standard
40586 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
40589 \begin_layout Standard
40597 \begin_layout Standard
40600 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
40603 \begin_layout Standard
40611 \begin_layout Standard
40619 \begin_layout Standard
40622 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
40625 \begin_layout Standard
40633 \begin_layout Standard
40641 \begin_layout Standard
40647 \begin_layout Standard
40653 \begin_layout Standard
40656 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
40659 \begin_layout Standard
40662 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
40665 \begin_layout Standard
40673 \begin_layout Standard
40681 \begin_layout Standard
40689 \begin_layout Standard
40697 \begin_layout Standard
40705 \begin_layout Standard
40711 \begin_layout Standard
40714 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
40717 \begin_layout Standard
40720 ; iTemp21 [lr21:38]{short}[r4]
40723 \begin_layout Standard
40731 \begin_layout Standard
40739 \begin_layout Standard
40747 \begin_layout Standard
40750 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
40753 \begin_layout Standard
40761 \begin_layout Standard
40769 \begin_layout Standard
40777 \begin_layout Standard
40785 \begin_layout Standard
40788 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
40791 \begin_layout Standard
40794 ; iTemp15 [lr29:30]{short}[r1]
40797 \begin_layout Standard
40805 \begin_layout Standard
40813 \begin_layout Standard
40816 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
40819 \begin_layout Standard
40827 \begin_layout Standard
40835 \begin_layout Standard
40843 \begin_layout Standard
40851 \begin_layout Standard
40859 \begin_layout Standard
40867 \begin_layout Standard
40870 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
40873 \begin_layout Standard
40881 \begin_layout Standard
40889 \begin_layout Standard
40897 \begin_layout Standard
40905 \begin_layout Standard
40913 \begin_layout Standard
40921 \begin_layout Standard
40924 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
40927 \begin_layout Standard
40935 \begin_layout Standard
40938 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
40941 \begin_layout Standard
40949 \begin_layout Standard
40954 cjne r5,#0xff,00104$
40957 \begin_layout Standard
40965 \begin_layout Standard
40968 ; goto _forcond_0($4)
40971 \begin_layout Standard
40979 \begin_layout Standard
40982 ; _forbreak_0($7) :
40985 \begin_layout Standard
40991 \begin_layout Standard
40994 ; ret iTemp24 [lr40:41]{short}
40997 \begin_layout Standard
41005 \begin_layout Standard
41013 \begin_layout Standard
41021 \begin_layout Standard
41027 \begin_layout Standard
41033 \begin_layout Standard
41043 \begin_layout Section
41044 A few words about basic block successors, predecessors and dominators
41047 \begin_layout Standard
41048 Successors are basic blocks
41049 \begin_inset LatexCommand \index{Basic blocks}
41053 that might execute after this basic block.
41055 Predecessors are basic blocks
41056 that might execute before reaching this basic block.
41058 Dominators are basic
41059 blocks that WILL execute before reaching this basic block.
41064 \begin_layout Standard
41068 \begin_layout Standard
41072 \begin_layout Standard
41080 \begin_layout Standard
41084 \begin_layout Standard
41092 \begin_layout Standard
41098 \begin_layout Standard
41099 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
41102 \begin_layout Standard
41103 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
41106 \begin_layout Standard
41107 c) domVect of [BB4] = BB1 ...
41108 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
41112 \begin_layout Chapter
41116 \begin_layout Standard
41117 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/#Who}
41127 Thanks to all the other volunteer developers who have helped with coding,
41128 testing, web-page creation, distribution sets, etc.
41129 You know who you are :-)
41137 Thanks to Sourceforge
41138 \begin_inset LatexCommand \url{http://www.sf.net}
41142 which has hosted the project since 1999 and donates significant download
41151 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
41152 cycles and bandwidth for snapshot builds.
41157 \begin_layout Standard
41158 This document was initially written by Sandeep Dutta
41161 \begin_layout Standard
41162 All product names mentioned herein may be trademarks
41163 \begin_inset LatexCommand \index{Trademarks}
41167 of their respective companies.
41171 \begin_layout Section*
41175 \begin_layout Standard
41176 To avoid confusion, the installation and building options for SDCC itself
41177 (chapter 2) are not part of the index.
41180 \begin_layout Standard
41181 \begin_inset LatexCommand \printindex{}