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
1168 \begin_layout Standard
1178 \begin_inset LatexCommand \index{-\/-std-c99}
1190 \begin_layout Standard
1202 This is no longer true, and can cause compilation failures on code built
1209 \begin_layout Standard
1219 \begin_inset LatexCommand \index{-\/-std-c89}
1225 but using c99 preprocessor features, such as one-line (//) comments
1228 \begin_layout Itemize
1229 in versions older then 2.8.4 the pic16 *printf() and printf_tiny() library
1230 functions supported undocumented and not standard compliant 'b' binary
1231 format specifier ("%b", "%hb" and "%lb").
1232 The 'b' specifier is now disabled by default.
1233 It can be enabled by defining BINARY_SPECIFIER macro in files device/lib/pic16/
1234 libc/stdio/vfprintf.c and device/lib/pic16/libc/stdio/printf_tiny.c and recompilin
1238 \begin_layout Itemize
1239 in versions older then 2.8.5 the unnamed bitfield structure members participated
1240 in initialization, which is not conforming with ISO/IEC 9899:1999 standard
1241 (see section Section 6.7.8 Initialization, clause 9)
1245 Old behavior, before
1281 /* s.a = 1, s.b = 3 */
1322 /* s.a = 1, s.b = 2 */
1325 \begin_layout Section
1329 \begin_layout Standard
1330 What do you need before you start installation of SDCC? A computer, and
1331 a desire to compute.
1332 The preferred method of installation is to compile SDCC from source using
1334 For Windows some pre-compiled binary distributions are available for your
1336 You should have some experience with command line tools and compiler use.
1339 \begin_layout Section
1343 \begin_layout Standard
1344 The SDCC home page at
1345 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1349 is a great place to find distribution sets.
1350 You can also find links to the user mailing lists that offer help or discuss
1351 SDCC with other SDCC users.
1352 Web links to other SDCC related sites can also be found here.
1353 This document can be found in the DOC directory of the source package as
1354 a text or HTML file.
1355 A pdf version of this document is available at
1356 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1361 Some of the other tools (simulator and assembler) included with SDCC contain
1362 their own documentation and can be found in the source distribution.
1363 If you want the latest unreleased software, the complete source package
1364 is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1368 \begin_layout Section
1369 Wishes for the future
1372 \begin_layout Standard
1373 There are (and always will be) some things that could be done.
1374 Here are some I can think of:
1379 \begin_layout Standard
1382 char KernelFunction3(char p) at 0x340;
1387 \begin_layout Standard
1391 \begin_inset LatexCommand \index{code banking (limited support)}
1401 If you can think of some more, please see the section
1402 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1406 about filing feature requests
1407 \begin_inset LatexCommand \index{Requesting features}
1412 \begin_inset LatexCommand \index{Feature request}
1421 \begin_layout Chapter
1423 \begin_inset LatexCommand \index{Installation}
1430 \begin_layout Standard
1431 For most users it is sufficient to skip to either section
1432 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1437 \begin_inset LatexCommand \ref{sub:Windows-Install}
1442 More detailed instructions follow below.
1445 \begin_layout Section
1447 \begin_inset LatexCommand \index{Options SDCC configuration}
1454 \begin_layout Standard
1455 The install paths, search paths and other options are defined when running
1457 The defaults can be overridden by:
1461 \labelwidthstring 00.00.0000
1466 \begin_layout Standard
1475 -prefix see table below
1479 \labelwidthstring 00.00.0000
1484 \begin_layout Standard
1493 -exec_prefix see table below
1497 \labelwidthstring 00.00.0000
1502 \begin_layout Standard
1511 -bindir see table below
1515 \labelwidthstring 00.00.0000
1520 \begin_layout Standard
1529 -datadir see table below
1533 \labelwidthstring 00.00.0000
1538 \begin_layout Standard
1547 -datarootdir see table below
1553 \labelwidthstring 00.00.0000
1556 docdir environment variable, see table below
1560 \labelwidthstring 00.00.0000
1563 include_dir_suffix environment variable, see table below
1567 \labelwidthstring 00.00.0000
1570 lib_dir_suffix environment variable, see table below
1574 \labelwidthstring 00.00.0000
1577 sdccconf_h_dir_separator environment variable, either / or
1582 This character will only be used in sdccconf.h; don't forget it's a C-header,
1583 therefore a double-backslash is needed there.
1589 \labelwidthstring 00.00.0000
1594 \begin_layout Standard
1603 -disable-mcs51-port Excludes the Intel mcs51 port
1607 \labelwidthstring 00.00.0000
1612 \begin_layout Standard
1621 -disable-gbz80-port Excludes the Gameboy gbz80 port
1625 \labelwidthstring 00.00.0000
1630 \begin_layout Standard
1639 -disable-z80-port Excludes the z80 port
1643 \labelwidthstring 00.00.0000
1648 \begin_layout Standard
1657 -disable-avr-port Excludes the AVR port
1661 \labelwidthstring 00.00.0000
1666 \begin_layout Standard
1675 -disable-ds390-port Excludes the DS390 port
1679 \labelwidthstring 00.00.0000
1684 \begin_layout Standard
1693 -disable-hc08-port Excludes the HC08 port
1697 \labelwidthstring 00.00.0000
1702 \begin_layout Standard
1711 -disable-pic-port Excludes the PIC14 port
1715 \labelwidthstring 00.00.0000
1720 \begin_layout Standard
1729 -disable-pic16-port Excludes the PIC16 port
1733 \labelwidthstring 00.00.0000
1738 \begin_layout Standard
1747 -disable-xa51-port Excludes the XA51 port
1751 \labelwidthstring 00.00.0000
1756 \begin_layout Standard
1765 -disable-ucsim Disables configuring and building of ucsim
1769 \labelwidthstring 00.00.0000
1774 \begin_layout Standard
1783 -disable-device-lib Disables automatically building device libraries
1787 \labelwidthstring 00.00.0000
1792 \begin_layout Standard
1801 -disable-packihx Disables building packihx
1807 \labelwidthstring 00.00.0000
1812 \begin_layout Standard
1821 -enable-doc Build pdf, html and txt files from the lyx sources
1825 \labelwidthstring 00.00.0000
1830 \begin_layout Standard
1839 -enable-libgc Use the Bohem memory allocator.
1840 Lower runtime footprint.
1844 \labelwidthstring 00.00.0000
1849 \begin_layout Standard
1858 -without-ccache Do not use ccache even if available
1861 \begin_layout Standard
1862 Furthermore the environment variables CC, CFLAGS, ...
1863 the tools and their arguments can be influenced.
1864 Please see `configure -
1868 \begin_layout Standard
1877 -help' and the man/info pages of `configure' for details.
1882 standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1883 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1884 SDCC_LIB_NAME are defined by `configure' too.
1885 At the moment it's not possible to change the default settings (it was
1886 simply never required).
1890 These configure options are compiled into the binaries,
1891 and can only be changed by rerunning 'configure' and recompiling SDCC.
1892 The configure options are written in
1896 to distinguish them from run time environment variables (see section search
1902 \begin_inset Quotes sld
1906 \begin_inset Quotes srd
1909 are used by the SDCC team to build the official Win32 binaries.
1910 The SDCC team uses Mingw32 to build the official Windows binaries, because
1914 \begin_layout Enumerate
1918 \begin_layout Enumerate
1919 a gcc compiler and last but not least
1922 \begin_layout Enumerate
1923 the binaries can be built by cross compiling on SDCC Distributed Compile
1927 \begin_layout Standard
1928 See the examples, how to pass the Win32 settings to 'configure'.
1929 The other Win32 builds using Borland, VC or whatever don't use 'configure',
1930 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1940 \begin_layout Standard
1942 \begin_inset Tabular
1943 <lyxtabular version="3" rows="9" columns="3">
1945 <column alignment="block" valignment="top" leftline="true" width="0in">
1946 <column alignment="block" valignment="top" leftline="true" width="0in">
1947 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1948 <row topline="true" bottomline="true">
1949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1952 \begin_layout Standard
1958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1961 \begin_layout Standard
1967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1970 \begin_layout Standard
1977 <row topline="true">
1978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1981 \begin_layout Standard
1989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1992 \begin_layout Standard
1998 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2001 \begin_layout Standard
2010 <row topline="true">
2011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2014 \begin_layout Standard
2022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2025 \begin_layout Standard
2033 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2036 \begin_layout Standard
2045 <row topline="true">
2046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2049 \begin_layout Standard
2057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2060 \begin_layout Standard
2070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2073 \begin_layout Standard
2086 <row topline="true">
2087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2090 \begin_layout Standard
2098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2101 \begin_layout Standard
2109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2112 \begin_layout Standard
2121 <row topline="true">
2122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2125 \begin_layout Standard
2133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2136 \begin_layout Standard
2146 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2149 \begin_layout Standard
2158 <row topline="true">
2159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2162 \begin_layout Standard
2170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2173 \begin_layout Standard
2183 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2186 \begin_layout Standard
2199 <row topline="true">
2200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2203 \begin_layout Standard
2211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2214 \begin_layout Standard
2220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2223 \begin_layout Standard
2230 <row topline="true" bottomline="true">
2231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2234 \begin_layout Standard
2242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2245 \begin_layout Standard
2251 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2254 \begin_layout Standard
2270 \begin_layout Standard
2272 'configure' also computes relative paths.
2273 This is needed for full relocatability of a binary package and to complete
2274 search paths (see section search paths below):
2279 \begin_layout Standard
2281 \begin_inset Tabular
2282 <lyxtabular version="3" rows="4" columns="3">
2284 <column alignment="block" valignment="top" leftline="true" width="0in">
2285 <column alignment="block" valignment="top" leftline="true" width="0in">
2286 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2287 <row topline="true" bottomline="true">
2288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2291 \begin_layout Standard
2297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2300 \begin_layout Standard
2306 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2309 \begin_layout Standard
2316 <row topline="true" bottomline="true">
2317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2320 \begin_layout Standard
2328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2331 \begin_layout Standard
2337 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2340 \begin_layout Standard
2347 <row bottomline="true">
2348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2351 \begin_layout Standard
2359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2362 \begin_layout Standard
2368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2371 \begin_layout Standard
2378 <row bottomline="true">
2379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2382 \begin_layout Standard
2390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2393 \begin_layout Standard
2399 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2402 \begin_layout Standard
2418 \begin_layout Standard
2423 \begin_layout LyX-Code
2430 \begin_layout Standard
2440 \begin_inset Quotes srd
2444 \begin_inset Quotes srd
2451 \begin_layout Standard
2461 \begin_inset Quotes srd
2465 \begin_inset Quotes srd
2474 \begin_layout Standard
2487 \begin_layout Standard
2499 \begin_layout Standard
2500 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2504 \begin_layout LyX-Code
2510 \begin_inset Quotes srd
2513 i586-mingw32msvc-gcc
2514 \begin_inset Quotes srd
2518 \begin_inset Quotes srd
2521 i586-mingw32msvc-g++
2522 \begin_inset Quotes srd
2530 \begin_inset Quotes srd
2533 i586-mingw32msvc-ranlib
2534 \begin_inset Quotes srd
2542 \begin_inset Quotes srd
2545 i586-mingw32msvc-strip
2546 \begin_inset Quotes srd
2557 \begin_layout Standard
2567 \begin_inset Quotes srd
2571 \begin_inset Quotes srd
2582 \begin_layout Standard
2592 \begin_inset Quotes srd
2596 \begin_inset Quotes srd
2604 \begin_inset Quotes srd
2610 \begin_inset Quotes srd
2618 \begin_inset Quotes srd
2622 \begin_inset Quotes srd
2630 \begin_inset Quotes srd
2634 \begin_inset Quotes srd
2641 sdccconf_h_dir_separator=
2642 \begin_inset Quotes srd
2654 \begin_inset Quotes srd
2665 \begin_layout Standard
2682 \begin_layout Standard
2691 -host=i586-mingw32msvc
2699 \begin_layout Standard
2708 -build=unknown-unknown-linux-gnu
2711 \begin_layout Standard
2713 \begin_inset Quotes sld
2717 \begin_inset Quotes srd
2720 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2724 \begin_layout LyX-Code
2733 \begin_layout Standard
2743 \begin_inset Quotes srd
2747 \begin_inset Quotes srd
2758 \begin_layout Standard
2768 \begin_inset Quotes srd
2772 \begin_inset Quotes srd
2780 \begin_inset Quotes srd
2786 \begin_inset Quotes srd
2794 \begin_inset Quotes srd
2798 \begin_inset Quotes srd
2806 \begin_inset Quotes srd
2810 \begin_inset Quotes srd
2817 sdccconf_h_dir_separator=
2818 \begin_inset Quotes srd
2830 \begin_inset Quotes srd
2838 \begin_inset Quotes srd
2842 \begin_inset Quotes srd
2850 \begin_inset Quotes srd
2854 \begin_inset Quotes srd
2860 \begin_layout Standard
2861 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2866 \begin_layout Standard
2875 -C' turns on caching, which gives a little bit extra speed.
2876 However if options are changed, it can be necessary to delete the config.cache
2880 \begin_layout Section
2882 \begin_inset LatexCommand \label{sub:Install-paths}
2887 \begin_inset LatexCommand \index{Install paths}
2894 \begin_layout Standard
2895 \begin_inset VSpace medskip
2901 \begin_layout Standard
2903 \begin_inset Tabular
2904 <lyxtabular version="3" rows="5" columns="4">
2906 <column alignment="left" valignment="top" leftline="true" width="0">
2907 <column alignment="left" valignment="top" leftline="true" width="0">
2908 <column alignment="left" valignment="top" leftline="true" width="0">
2909 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2910 <row topline="true" bottomline="true">
2911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2914 \begin_layout Standard
2922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2925 \begin_layout Standard
2933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2936 \begin_layout Standard
2944 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2947 \begin_layout Standard
2956 <row topline="true">
2957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2960 \begin_layout Standard
2966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2969 \begin_layout Standard
2977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2980 \begin_layout Standard
2986 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2989 \begin_layout Standard
3000 <row topline="true">
3001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3004 \begin_layout Standard
3010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3013 \begin_layout Standard
3016 $DATADIR/ $INCLUDE_DIR_SUFFIX
3021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3024 \begin_layout Standard
3025 /usr/local/share/sdcc/include
3030 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3033 \begin_layout Standard
3044 <row topline="true">
3045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3048 \begin_layout Standard
3054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3057 \begin_layout Standard
3060 $DATADIR/$LIB_DIR_SUFFIX
3065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3068 \begin_layout Standard
3069 /usr/local/share/sdcc/lib
3074 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3077 \begin_layout Standard
3088 <row topline="true" bottomline="true">
3089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3092 \begin_layout Standard
3098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3101 \begin_layout Standard
3109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3112 \begin_layout Standard
3113 /usr/local/share/sdcc/doc
3118 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3121 \begin_layout Standard
3142 *compiler, preprocessor, assembler, and linker
3148 is auto-appended by the compiler, e.g.
3149 small, large, z80, ds390 etc
3152 \begin_layout Standard
3154 The install paths can still be changed during `make install' with e.g.:
3157 \begin_layout LyX-Code
3158 make install prefix=$(HOME)/local/sdcc
3161 \begin_layout Standard
3162 Of course this doesn't change the search paths compiled into the binaries.
3167 r the install path can be changed by defining DESTDIR
3168 \begin_inset LatexCommand \index{DESTDIR}
3175 \begin_layout LyX-Code
3176 make install DESTDIR=$(HOME)/sdcc.rpm/
3179 \begin_layout Standard
3180 Please note that DESTDIR must have a trailing slash!
3183 \begin_layout Section
3185 \begin_inset LatexCommand \label{sub:Search-Paths}
3190 \begin_inset LatexCommand \index{Search path}
3197 \begin_layout Standard
3198 Some search paths or parts of them are determined by configure variables
3203 , see section above).
3204 Further search paths are determined by environment variables during runtime.
3207 The paths searched when running the compiler are as follows (the first
3213 Binary files (preprocessor, assembler and linker)
3218 \begin_layout Standard
3220 \begin_inset Tabular
3221 <lyxtabular version="3" rows="4" columns="3">
3223 <column alignment="block" valignment="top" leftline="true" width="0in">
3224 <column alignment="block" valignment="top" leftline="true" width="0in">
3225 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3226 <row topline="true" bottomline="true">
3227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3230 \begin_layout Standard
3236 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3239 \begin_layout Standard
3245 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3248 \begin_layout Standard
3255 <row topline="true">
3256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3259 \begin_layout Standard
3267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3270 \begin_layout Standard
3276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3279 \begin_layout Standard
3288 <row topline="true">
3289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3292 \begin_layout Standard
3293 Path of argv[0] (if available)
3298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3301 \begin_layout Standard
3307 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3310 \begin_layout Standard
3317 <row topline="true" bottomline="true">
3318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3321 \begin_layout Standard
3327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3330 \begin_layout Standard
3336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3339 \begin_layout Standard
3355 \begin_layout Standard
3363 \begin_layout Standard
3365 \begin_inset Tabular
3366 <lyxtabular version="3" rows="6" columns="3">
3368 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3369 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3370 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3371 <row topline="true" bottomline="true">
3372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3375 \begin_layout Standard
3381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3384 \begin_layout Standard
3390 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3393 \begin_layout Standard
3400 <row topline="true">
3401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3404 \begin_layout Standard
3409 \begin_layout Standard
3423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3426 \begin_layout Standard
3431 \begin_layout Standard
3445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3448 \begin_layout Standard
3453 \begin_layout Standard
3468 <row topline="true">
3469 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3472 \begin_layout Standard
3478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3481 \begin_layout Standard
3487 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3490 \begin_layout Standard
3497 <row topline="true">
3498 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3501 \begin_layout Standard
3513 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3516 \begin_layout Standard
3526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3529 \begin_layout Standard
3538 <row topline="true">
3539 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3542 \begin_layout Standard
3558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3561 \begin_layout Standard
3609 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3612 \begin_layout Standard
3623 <row topline="true" bottomline="true">
3624 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3627 \begin_layout Standard
3641 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3644 \begin_layout Standard
3645 /usr/local/share/sdcc/
3652 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3655 \begin_layout Standard
3671 \begin_layout Standard
3677 \begin_layout Standard
3686 -nostdinc disables the last two search paths.
3696 \begin_layout Standard
3697 With the exception of
3698 \begin_inset Quotes sld
3705 \begin_layout Standard
3715 \begin_inset Quotes srd
3722 is auto-appended by the compiler (e.g.
3723 small, large, z80, ds390 etc.).
3729 \begin_layout Standard
3731 \begin_inset Tabular
3732 <lyxtabular version="3" rows="6" columns="3">
3734 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3735 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3736 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3737 <row topline="true" bottomline="true">
3738 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3741 \begin_layout Standard
3747 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3750 \begin_layout Standard
3756 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3759 \begin_layout Standard
3766 <row topline="true">
3767 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3770 \begin_layout Standard
3775 \begin_layout Standard
3789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3792 \begin_layout Standard
3797 \begin_layout Standard
3811 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3814 \begin_layout Standard
3819 \begin_layout Standard
3834 <row topline="true">
3835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3838 \begin_layout Standard
3848 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3851 \begin_layout Standard
3861 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3864 \begin_layout Standard
3877 <row topline="true">
3878 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3881 \begin_layout Standard
3888 $LIB_DIR_SUFFIX/<model>
3893 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3896 \begin_layout Standard
3908 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3911 \begin_layout Standard
3926 <row topline="true">
3927 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3930 \begin_layout Standard
3941 $LIB_DIR_SUFFIX/<model>
3946 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3949 \begin_layout Standard
4000 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4003 \begin_layout Standard
4057 <row topline="true" bottomline="true">
4058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4061 \begin_layout Standard
4066 $LIB_DIR_SUFFIX/<model>
4071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4074 \begin_layout Standard
4075 /usr/local/share/sdcc/
4084 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4087 \begin_layout Standard
4103 \begin_layout Standard
4104 \begin_inset Note Note
4107 \begin_layout Standard
4108 Don't delete any of the stray spaces in the table above without checking
4109 the HTML output (last line)!
4117 \begin_layout Standard
4125 \begin_layout Standard
4134 -nostdlib disables the last two search paths.
4137 \begin_layout Section
4139 \begin_inset LatexCommand \index{Building SDCC}
4146 \begin_layout Subsection
4147 Building SDCC on Linux
4148 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
4155 \begin_layout Enumerate
4158 Download the source package
4160 either from the SDCC Subversion repository or from snapshot builds
4162 , it will be named something like sdcc
4173 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
4180 \begin_layout Enumerate
4183 Bring up a command line terminal, such as xterm.
4186 \begin_layout Enumerate
4189 Unpack the file using a command like:
4192 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
4193 \begin_inset Quotes srd
4199 , this will create a sub-directory called sdcc with all of the sources.
4202 \begin_layout Enumerate
4203 Change directory into the main SDCC directory, for example type:
4211 \begin_layout Enumerate
4221 This configures the package for compilation on your system.
4224 \begin_layout Enumerate
4238 All of the source packages will compile, this can take a while.
4241 \begin_layout Enumerate
4255 This copies the binary executables, the include files, the libraries and
4256 the documentation to the install directories.
4257 Proceed with section
4258 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
4265 \begin_layout Subsection
4266 Building SDCC on Mac OS X
4269 \begin_layout Standard
4270 Follow the instruction for Linux.
4274 On Mac OS X 10.2.x it was reported, that the
4275 default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
4276 Fortunately there's also gcc 2.9.x installed, which works fine.
4277 This compiler can be selected by running 'configure' with:
4280 \begin_layout LyX-Code
4281 ./configure CC=gcc2 CXX=g++2
4284 \begin_layout Standard
4285 Universal (ppc and i386) binaries can be produced on Mac OS X 10.4.x with
4287 Run 'configure' with:
4290 \begin_layout LyX-Code
4296 \begin_layout LyX-Code
4297 LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4303 \begin_layout LyX-Code
4304 CXXFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4310 \begin_layout LyX-Code
4311 CFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
4314 \begin_layout Subsection
4315 Cross compiling SDCC on Linux for Windows
4318 \begin_layout Standard
4319 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
4320 See section 'Configure Options'.
4323 \begin_layout Subsection
4324 Building SDCC using Cygwin and Mingw32
4327 \begin_layout Standard
4328 For building and installing a Cygwin executable follow the instructions
4334 \begin_inset Quotes sld
4338 \begin_inset Quotes srd
4341 Win32-binary can be built, which will not need the Cygwin-DLL.
4342 For the necessary 'configure' options see section 'configure options' or
4343 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4348 Cygwin on Windows download setup.exe from
4349 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
4355 \begin_inset Quotes sld
4358 default text file type
4359 \begin_inset Quotes srd
4363 \begin_inset Quotes sld
4367 \begin_inset Quotes srd
4370 and download/install at least the following packages.
4371 Some packages are selected by default, others will be automatically selected
4372 because of dependencies with the manually selected packages.
4373 Never deselect these packages!
4376 \begin_layout Itemize
4380 \begin_layout Itemize
4384 \begin_layout Itemize
4385 gcc ; version 3.x is fine, no need to use the old 2.9x
4388 \begin_layout Itemize
4389 binutils ; selected with gcc
4392 \begin_layout Itemize
4396 \begin_layout Itemize
4397 rxvt ; a nice console, which makes life much easier under windoze (see below)
4400 \begin_layout Itemize
4401 man ; not really needed for building SDCC, but you'll miss it sooner or
4405 \begin_layout Itemize
4406 less ; not really needed for building SDCC, but you'll miss it sooner or
4410 \begin_layout Itemize
4411 svn ; only if you use Subversion access
4414 \begin_layout Standard
4415 If you want to develop something you'll need:
4418 \begin_layout Itemize
4419 python ; for the regression tests
4422 \begin_layout Itemize
4423 gdb ; the gnu debugger, together with the nice GUI
4424 \begin_inset Quotes sld
4428 \begin_inset Quotes srd
4434 \begin_layout Itemize
4435 openssh ; to access the CF or commit changes
4438 \begin_layout Itemize
4439 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4440 use autoconf-stable!
4443 \begin_layout Standard
4444 rxvt is a nice console with history.
4445 Replace in your cygwin.bat the line
4448 \begin_layout LyX-Code
4453 \begin_layout Standard
4465 \begin_layout Standard
4469 \begin_layout LyX-Code
4470 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4473 \begin_layout LyX-Code
4474 -bg black -fg white -geometry 100x65 -e bash -
4478 \begin_layout Standard
4490 \begin_layout Standard
4491 Text selected with the mouse is automatically copied to the clipboard, pasting
4492 works with shift-insert.
4496 The other good tip is to make sure you have no //c/-styl
4497 e paths anywhere, use /cygdrive/c/ instead.
4498 Using // invokes a network lookup which is very slow.
4500 \begin_inset Quotes sld
4504 \begin_inset Quotes srd
4507 is too long, you can change it with e.g.
4510 \begin_layout LyX-Code
4514 \begin_layout Standard
4515 SDCC sources use the unix line ending LF.
4516 Life is much easier, if you store the source tree on a drive which is mounted
4518 And use an editor which can handle LF-only line endings.
4519 Make sure not to commit files with windows line endings.
4520 The tabulator spacing
4521 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4525 used in the project is 8.
4526 Although a tabulator spacing of 8 is a sensible choice for programmers
4527 (it's a power of 2 and allows to display 8/16 bit signed variables without
4528 loosing columns) the plan is to move towards using only spaces in the source.
4531 \begin_layout Subsection
4532 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4535 \begin_layout Standard
4538 Download the source package
4540 either from the SDCC Subversion repository or from the
4541 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4547 , it will be named something like sdcc
4551 -yyyymmdd-rrrr.tar.bz2.
4554 SDCC is distributed with all the projects, workspaces, and files you need
4555 to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4556 The workspace name is 'sdcc.dsw'.
4557 Please note that as it is now, all the executables are created in a folder
4561 Once built you need to copy the executables from sdcc
4565 bin before running SDCC.
4570 WARNING: Visual studio is very picky with line terminations; it expects
4571 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4572 When using the Subversion repository it's easiest to configure the svn
4573 client to convert automatically for you.
4574 If however you are getting a message such as "This makefile was not generated
4575 by Developer Studio etc.
4577 \begin_inset Quotes srd
4580 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4581 need to convert the Unix style line endings to DOS style line endings.
4582 To do so you can use the
4583 \begin_inset Quotes sld
4587 \begin_inset Quotes srd
4590 utility freely available on the internet.
4591 Doug Hawkins reported in the sdcc-user list that this works:
4599 SDCC> unix2dos sdcc.dsw
4605 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4609 In order to build SDCC with MSVC
4610 you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4611 One good place to get them is
4612 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4620 Download the file UnxUtils
4621 \begin_inset LatexCommand \index{UnxUtils}
4626 Now you have to install the utilities and setup MSVC so it can locate the
4628 Here there are two alternatives (choose one!):
4631 \begin_layout Enumerate
4636 a) Extract UnxUtils.zip to your C:
4638 hard disk PRESERVING the original paths, otherwise bison won't work.
4639 (If you are using WinZip make certain that 'Use folder names' is selected)
4644 In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4645 'Show directories for:' select 'Executable files', and in the directories
4646 window add a new path: 'C:
4656 (As a side effect, you get a bunch of Unix utilities that
4657 could be useful, such as diff and patch.)
4660 \begin_layout Enumerate
4665 This one avoids extracting a bunch of files you may not
4666 use, but requires some extra work:
4670 a) Create a directory were to put the
4671 tools needed, or use a directory already present.
4678 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4679 gawk.exe to such directory WITHOUT preserving the original paths.
4680 (If you are using WinZip make certain that 'Use folder names' is not selected)
4685 ) Rename bison.exe to '_bison.exe'.
4689 d) Create a batch file 'bison.bat' in 'C:
4693 ' and add these lines:
4713 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4717 Steps 'c' and 'd' are needed
4718 because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4719 reside in some weird Unix directory, '/usr/local/share/' I think.
4720 So it is necessary to tell bison where those files are located if they
4721 are not in such directory.
4722 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4727 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4728 in 'Show directories for:' select 'Executable files', and in the directories
4729 window add a new path: 'c:
4732 Note that you can use any other path instead of 'c:
4734 util', even the path where the Visual C++ tools are, probably: 'C:
4738 Microsoft Visual Studio
4743 So you don't have to execute step 'e' :)
4746 \begin_layout Standard
4748 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4749 the executables from sdcc
4753 bin, and you can compile using SDCC.
4756 \begin_layout Subsection
4757 Building SDCC Using Borland
4760 \begin_layout Enumerate
4761 From the sdcc directory, run the command "make -f Makefile.bcc".
4762 This should regenerate all the .exe files in the bin directory except for
4766 \begin_layout Enumerate
4767 If you modify any source files and need to rebuild, be aware that the dependenci
4768 es may not be correctly calculated.
4769 The safest option is to delete all .obj files and run the build again.
4770 From a Cygwin BASH prompt, this can easily be done with the command (be
4771 sure you are in the sdcc directory):
4781 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
4783 ) -print -exec rm {}
4792 or on Windows NT/2000/XP from the command prompt with the command:
4799 del /s *.obj *.lib *.rul
4802 from the sdcc directory.
4805 \begin_layout Subsection
4806 Windows Install Using a ZIP Package
4809 \begin_layout Enumerate
4810 Download the binary zip package from
4811 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4815 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4816 This should unpack to a group of sub-directories.
4817 An example directory structure after unpacking the mingw32 package is:
4822 bin for the executables, c:
4830 lib for the include and libraries.
4833 \begin_layout Enumerate
4834 Adjust your environment variable PATH to include the location of the bin
4835 directory or start sdcc using the full path.
4838 \begin_layout Subsection
4839 Windows Install Using the Setup Program
4840 \begin_inset LatexCommand \label{sub:Windows-Install}
4847 \begin_layout Standard
4848 Download the setup program
4850 sdcc-x.y.z-setup.exe
4852 for an official release from
4855 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4859 or a setup program for one of the snapshots
4861 sdcc-yyyymmdd-xxxx-setup.exe
4864 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4869 A windows typical installer will guide you through the installation process.
4872 \begin_layout Subsection
4874 \begin_inset LatexCommand \index{VPATH}
4881 \begin_layout Standard
4882 SDCC supports the VPATH feature provided by configure and make.
4883 It allows to separate the source and build trees.
4887 \begin_layout Standard
4914 \begin_layout Standard
4917 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4918 # extract source to directory sdcc
4921 \begin_layout Standard
4924 mkdir sdcc.build\InsetSpace ~
4933 # put output in sdcc.build
4936 \begin_layout Standard
4942 \begin_layout Standard
4945 ../sdcc/configure\InsetSpace ~
4953 # configure is doing all the magic!
4956 \begin_layout Standard
4962 \begin_layout Standard
4968 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4969 It automagically computes the variables srcdir, top_srcdir and top_buildir
4975 the generated files will be in ~/sdcc.build, while the source files stay
4978 This is not only usefull for building different binaries, e.g.
4979 when cross compiling.
4980 It also gives you a much better overview in the source tree when all the
4981 generated files are not scattered between the source files.
4982 And the best thing is: if you want to change a file you can leave the original
4983 file untouched in the source directory.
4984 Simply copy it to the build directory, edit it, enter `make clean', `rm
4985 Makefile.dep' and `make'.
4990 will do the rest for you!
4993 \begin_layout Section
4994 Building the Documentation
4997 \begin_layout Standard
5002 \begin_layout Standard
5011 -enable-doc to the configure arguments to build the documentation together
5012 with all the other stuff.
5013 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
5014 dvips and makeindex) to get the job done.
5015 Another possibility is to change to the doc directory and to type
5019 \begin_inset Quotes srd
5023 \begin_inset Quotes srd
5030 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
5033 \begin_inset LatexCommand \url{http://www.lyx.org}
5037 as editor is straightforward.
5038 Prebuilt documentation in html and pdf format is available from
5039 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
5046 \begin_layout Section
5047 Reading the Documentation
5048 \begin_inset LatexCommand \index{Documentation}
5055 \begin_layout Standard
5056 Currently reading the document in pdf format is recommended, as for unknown
5057 reason the hyperlinks are working there whereas in the html version they
5062 \begin_layout Standard
5063 If you should know why please drop us a note
5071 You'll find the pdf version
5072 \begin_inset LatexCommand \index{PDF version of this document}
5077 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
5085 \begin_inset LatexCommand \index{HTML version of this document}
5090 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
5096 This documentation is in some aspects different from a commercial documentation:
5100 \begin_layout Itemize
5101 It tries to document SDCC for several processor architectures in one document
5102 (commercially these probably would be separate documents/products).
5104 \begin_inset LatexCommand \index{Status of documentation}
5108 currently matches SDCC for mcs51 and DS390 best and does give too few informati
5110 Z80, PIC14, PIC16 and HC08.
5113 \begin_layout Itemize
5114 There are many references pointing away from this documentation.
5115 Don't let this distract you.
5117 was a reference like
5118 \begin_inset LatexCommand \url{http://www.opencores.org}
5122 together with a statement
5123 \begin_inset Quotes sld
5126 some processors which are targetted by SDCC can be implemented in a
5143 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
5148 \begin_inset Quotes srd
5152 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
5157 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
5162 \begin_inset Quotes sld
5165 have you ever heard of an open source compiler that compiles a subset of
5167 \begin_inset Quotes srd
5170 we expect you to have a quick look there and come back.
5171 If you read this you are on the right track.
5174 \begin_layout Itemize
5175 Some sections attribute more space to problems, restrictions and warnings
5176 than to the solution.
5179 \begin_layout Itemize
5180 The installation section and the section about the debugger is intimidating.
5183 \begin_layout Itemize
5184 There are still lots of typos and there are more different writing styles
5188 \begin_layout Section
5189 Testing the SDCC Compiler
5190 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
5197 \begin_layout Standard
5198 The first thing you should do after installing your SDCC compiler is to
5207 \begin_layout Standard
5217 \begin_inset LatexCommand \index{version}
5224 at the prompt, and the program should run and output its version like:
5229 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
5233 \begin_layout Standard
5234 If it doesn't run, or gives a message about not finding sdcc program, then
5235 you need to check over your installation.
5236 Make sure that the sdcc bin directory is in your executable search path
5237 defined by the PATH environment setting (
5242 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5249 Install trouble-shooting for suggestions
5252 Make sure that the sdcc program is in the bin folder, if not perhaps something
5253 did not install correctly.
5261 is commonly installed as described in section
5262 \begin_inset Quotes sld
5265 Install and search paths
5266 \begin_inset Quotes srd
5275 Make sure the compiler works on a very simple example.
5276 Type in the following test.c program using your favorite
5301 \begin_layout Standard
5304 Compile this using the following command:
5313 If all goes well, the compiler will generate a test.asm and test.rel file.
5314 Congratulations, you've just compiled your first program with SDCC.
5315 We used the -c option to tell SDCC not to link the generated code, just
5316 to keep things simple for this step.
5324 The next step is to try it with the linker.
5334 If all goes well the compiler will link with the libraries and produce
5335 a test.ihx output file.
5340 (no test.ihx, and the linker generates warnings), then the problem is most
5349 usr/local/share/sdcc/lib directory
5356 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5363 Install trouble-shooting for suggestions).
5371 The final test is to ensure
5379 header files and libraries.
5380 Edit test.c and change it to the following:
5398 strcpy(str1, "testing");
5403 \begin_layout Standard
5406 Compile this by typing
5413 This should generate a test.ihx output file, and it should give no warnings
5414 such as not finding the string.h file.
5415 If it cannot find the string.h file, then the problem is that
5419 cannot find the /usr/local/share/sdcc/include directory
5426 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5433 Install trouble-shooting section for suggestions).
5442 \begin_layout Standard
5454 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5458 to find exactly where SDCC is looking for the include and lib files.
5461 \begin_layout Section
5462 Install Trouble-shooting
5463 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5468 \begin_inset LatexCommand \index{Install trouble-shooting}
5475 \begin_layout Subsection
5476 If SDCC does not build correctly
5479 \begin_layout Standard
5480 A thing to try is starting from scratch by unpacking the .tgz source package
5481 again in an empty directory.
5489 ./configure 2>&1 | tee configure.log
5503 make 2>&1 | tee make.log
5510 If anything goes wrong, you can review the log files to locate the problem.
5511 Or a relevant part of this can be attached to an email that could be helpful
5512 when requesting help from the mailing list.
5515 \begin_layout Subsection
5517 \begin_inset Quotes sld
5521 \begin_inset Quotes srd
5527 \begin_layout Standard
5529 \begin_inset Quotes sld
5533 \begin_inset Quotes srd
5536 command is a script that analyzes your system and performs some configuration
5537 to ensure the source package compiles on your system.
5538 It will take a few minutes to run, and will compile a few tests to determine
5539 what compiler features are installed.
5542 \begin_layout Subsection
5544 \begin_inset Quotes sld
5548 \begin_inset Quotes srd
5554 \begin_layout Standard
5555 This runs the GNU make tool, which automatically compiles all the source
5556 packages into the final installed binary executables.
5559 \begin_layout Subsection
5561 \begin_inset Quotes sld
5565 \begin_inset Quotes erd
5571 \begin_layout Standard
5572 This will install the compiler, other executables libraries and include
5573 files into the appropriate directories.
5575 \begin_inset LatexCommand \ref{sub:Install-paths}
5581 \begin_inset LatexCommand \ref{sub:Search-Paths}
5586 about install and search paths.
5588 On most systems you will need super-user privilege
5592 \begin_layout Section
5596 \begin_layout Standard
5597 SDCC is not just a compiler, but a collection of tools by various developers.
5598 These include linkers, assemblers, simulators and other components.
5599 Here is a summary of some of the components.
5600 Note that the included simulator and assembler have separate documentation
5601 which you can find in the source package in their respective directories.
5602 As SDCC grows to include support for other processors, other packages from
5603 various developers are included and may have their own sets of documentation.
5608 might want to look at the files which are installed in <installdir>.
5609 At the time of this writing, we find the following programs for gcc-builds:
5614 In <installdir>/bin:
5617 \begin_layout Itemize
5618 sdcc - The compiler.
5621 \begin_layout Itemize
5622 sdcpp - The C preprocessor.
5625 \begin_layout Itemize
5626 asx8051 - The assembler for 8051 type processors.
5629 \begin_layout Itemize
5634 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5637 \begin_layout Itemize
5638 aslink -The linker for 8051 type processors.
5641 \begin_layout Itemize
5646 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5649 \begin_layout Itemize
5650 s51 - The ucSim 8051 simulator.
5653 \begin_layout Itemize
5654 sdcdb - The source debugger.
5657 \begin_layout Itemize
5658 packihx - A tool to pack (compress) Intel hex files.
5661 \begin_layout Standard
5662 In <installdir>/share/sdcc/include
5665 \begin_layout Itemize
5669 \begin_layout Standard
5670 In <installdir>/share/sdcc/lib
5673 \begin_layout Itemize
5674 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5678 \begin_layout Standard
5679 In <installdir>/share/sdcc/doc
5682 \begin_layout Itemize
5686 \begin_layout Standard
5687 As development for other processors proceeds, this list will expand to include
5688 executables to support processors like AVR, PIC, etc.
5691 \begin_layout Subsection
5695 \begin_layout Standard
5696 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5697 the assembler and linkage editor.
5700 \begin_layout Subsection
5701 sdcpp - The C-Preprocessor
5704 \begin_layout Standard
5706 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5710 is a modified version of the GNU cpp
5711 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5716 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5721 The C preprocessor is used to pull in #include sources, process #ifdef
5722 statements, #defines and so on.
5725 \begin_layout Subsection
5734 - The Assemblers and Linkage Editors
5737 \begin_layout Standard
5738 This is retargettable assembler & linkage editor, it was developed by Alan
5740 John Hartman created the version for 8051, and I (Sandeep) have made some
5741 enhancements and bug fixes for it to work properly with SDCC.
5744 \begin_layout Subsection
5748 \begin_layout Standard
5750 \begin_inset LatexCommand \index{s51}
5754 is a free open source simulator developed by Daniel Drotos.
5755 The simulator is built as part of the build process.
5756 For more information visit Daniel's web site at:
5757 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5762 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5766 \begin_layout Subsection
5767 sdcdb - Source Level Debugger
5770 \begin_layout Standard
5772 \begin_inset LatexCommand \index{SDCDB (debugger)}
5776 is the companion source level debugger.
5777 More about SDCDB in section
5778 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5783 The current version of the debugger uses Daniel's Simulator S51
5784 \begin_inset LatexCommand \index{s51}
5788 , but can be easily changed to use other simulators.
5791 \begin_layout Chapter
5795 \begin_layout Section
5799 \begin_layout Subsection
5800 Single Source File Projects
5803 \begin_layout Standard
5804 For single source file 8051 projects the process is very simple.
5805 Compile your programs with the following command
5808 "sdcc sourcefile.c".
5812 This will compile, assemble and link your source file.
5813 Output files are as follows:
5816 \begin_layout Itemize
5818 \begin_inset LatexCommand \index{<file>.asm}
5823 \begin_inset LatexCommand \index{Assembler source}
5827 file created by the compiler
5830 \begin_layout Itemize
5832 \begin_inset LatexCommand \index{<file>.lst}
5837 \begin_inset LatexCommand \index{Assembler listing}
5841 file created by the Assembler
5844 \begin_layout Itemize
5846 \begin_inset LatexCommand \index{<file>.rst}
5851 \begin_inset LatexCommand \index{Assembler listing}
5855 file updated with linkedit information, created by linkage editor
5858 \begin_layout Itemize
5860 \begin_inset LatexCommand \index{<file>.sym}
5865 \begin_inset LatexCommand \index{Symbol listing}
5869 for the sourcefile, created by the assembler
5872 \begin_layout Itemize
5874 \begin_inset LatexCommand \index{<file>.rel}
5879 \begin_inset LatexCommand \index{<file>.o}
5884 \begin_inset LatexCommand \index{Object file}
5888 created by the assembler, input to Linkage editor
5891 \begin_layout Itemize
5893 \begin_inset LatexCommand \index{<file>.map}
5898 \begin_inset LatexCommand \index{Memory map}
5902 for the load module, created by the Linker
5905 \begin_layout Itemize
5907 \begin_inset LatexCommand \index{<file>.mem}
5911 - A file with a summary of the memory usage
5914 \begin_layout Itemize
5916 \begin_inset LatexCommand \index{<file>.ihx}
5920 - The load module in Intel hex format
5921 \begin_inset LatexCommand \index{Intel hex format}
5925 (you can select the Motorola S19 format
5926 \begin_inset LatexCommand \index{Motorola S19 format}
5934 \begin_layout Standard
5944 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5949 If you need another format you might want to use
5956 \begin_inset LatexCommand \index{objdump (tool)}
5967 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5972 \begin_inset Note Note
5975 \begin_layout Standard
5982 \begin_inset LatexCommand \vref{sub:Postprocessing-the-Intel}
5987 Both formats are documented in the documentation of srecord
5988 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5995 \begin_layout Itemize
5997 \begin_inset LatexCommand \index{<file>.adb}
6001 - An intermediate file containing debug information needed to create the
6006 \begin_layout Standard
6016 \begin_inset LatexCommand \index{-\/-debug}
6023 \begin_layout Itemize
6025 \begin_inset LatexCommand \index{<file>.cdb}
6029 - An optional file (with -
6033 \begin_layout Standard
6042 -debug) containing debug information.
6043 The format is documented in cdbfileformat.pdf
6046 \begin_layout Itemize
6049 \begin_inset LatexCommand \index{<file> (no extension)}
6053 An optional AOMF or AOMF51
6054 \begin_inset LatexCommand \index{AOMF, AOMF51}
6059 \begin_inset LatexCommand \label{OMF file}
6063 file containing debug information (generated with option -
6067 \begin_layout Standard
6093 ormat is a subformat of the OMF51 format and is commonly used by third party
6095 \begin_inset LatexCommand \index{Debugger}
6099 , simulators, emulators).
6102 \begin_layout Itemize
6104 \begin_inset LatexCommand \index{<file>.dump*}
6108 - Dump file to debug the compiler it self (generated with option -
6112 \begin_layout Standard
6121 -dumpall) (see section
6122 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
6128 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
6134 \begin_inset Quotes sld
6137 Anatomy of the compiler
6138 \begin_inset Quotes srd
6144 \begin_layout Subsection
6145 Postprocessing the Intel Hex
6146 \begin_inset LatexCommand \index{Intel hex format}
6151 \begin_inset LatexCommand \label{sub:Postprocessing-the-Intel}
6158 \begin_layout Standard
6159 In most cases this won't be needed but the Intel Hex file
6160 \begin_inset LatexCommand \index{<file>.ihx}
6164 which is generated by SDCC might include lines of varying length and the
6165 addresses within the file are not guaranteed to be strictly ascending.
6166 If your toolchain or a bootloader does not like this you can use the tool
6172 \begin_inset LatexCommand \index{packihx (tool)}
6176 which is part of the SDCC distribution:
6183 packihx sourcefile.ihx >sourcefile.hex
6190 The separately available
6195 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6199 package additionally allows to set undefined locations to a predefined
6200 value, to insert checksums
6201 \begin_inset LatexCommand \index{checksum}
6205 of various flavours (crc, add, xor) and to perform other manipulations
6206 (convert, split, crop, offset, ...).
6214 srec_cat\InsetSpace ~
6216 sourcefile.ihx -intel\InsetSpace ~
6218 -o sourcefile.hex -intel
6225 An example for a more complex command line
6229 \begin_layout Standard
6230 the command backfills
6231 \begin_inset LatexCommand \index{backfill unused memory}
6235 unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
6237 If the program counter on an mcs51 runs wild the backfill pattern 0x12
6238 will be interpreted as an
6246 (where an emergency routine could sit).
6259 srec_cat\InsetSpace ~
6260 sourcefile.ihx -intel\InsetSpace ~
6262 -fill 0x12 0x0000 0xfffe\InsetSpace ~
6263 -little-endian-checksum-nega
6264 tive 0xfffe 0x02 0x02\InsetSpace ~
6266 -o sourcefile.hex -intel
6275 The srecord package is available at
6276 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
6283 \begin_layout Subsection
6284 Projects with Multiple Source Files
6287 \begin_layout Standard
6288 SDCC can compile only ONE file at a time.
6289 Let us for example assume that you have a project containing the following
6294 foo1.c (contains some functions)
6296 foo2.c (contains some more functions)
6299 n.c (contains more functions and the function main)
6307 The first two files will need to be compiled separately with the commands:
6339 Then compile the source file containing the
6344 \begin_inset LatexCommand \index{Linker}
6348 the files together with the following command:
6356 foomain.c\InsetSpace ~
6357 foo1.rel\InsetSpace ~
6362 \begin_inset LatexCommand \index{<file>.rel}
6374 can be separately compiled as well:
6385 sdcc foomain.rel foo1.rel foo2.rel
6392 The file containing the
6407 file specified in the command line, since the linkage editor processes
6408 file in the order they are presented to it.
6409 The linker is invoked from SDCC using a script file with extension .lnk
6410 \begin_inset LatexCommand \index{<file>.lnk}
6415 You can view this file to troubleshoot linking problems such as those arising
6416 from missing libraries.
6419 \begin_layout Subsection
6420 Projects with Additional Libraries
6421 \begin_inset LatexCommand \index{Libraries}
6428 \begin_layout Standard
6429 Some reusable routines may be compiled into a library, see the documentation
6430 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6434 \begin_inset LatexCommand \index{<file>.lib}
6441 Libraries created in this manner can be included in the command line.
6442 Make sure you include the -L <library-path> option to tell the linker where
6443 to look for these files if they are not in the current directory.
6444 Here is an example, assuming you have the source file
6456 (if that is not the same as your current project):
6463 sdcc foomain.c foolib.lib -L mylib
6474 must be an absolute path name.
6478 The most efficient way to use libraries is
6479 to keep separate modules in separate source files.
6480 The lib file now should name all the modules.rel
6481 \begin_inset LatexCommand \index{<file>.rel}
6486 For an example see the standard library file
6490 in the directory <installdir>/share/lib/small.
6493 \begin_layout Subsection
6494 Using sdcclib to Create and Manage Libraries
6495 \begin_inset LatexCommand \index{sdcclib}
6502 \begin_layout Standard
6503 Alternatively, instead of having a .rel file for each entry on the library
6504 file as described in the preceding section, sdcclib can be used to embed
6505 all the modules belonging to such library in the library file itself.
6506 This results in a larger library file, but it greatly reduces the number
6507 of disk files accessed by the linker.
6508 Additionally, the packed library file contains an index of all include
6509 modules and symbols that significantly speeds up the linking process.
6510 To display a list of options supported by sdcclib type:
6515 \begin_layout Standard
6520 \begin_inset LatexCommand \index{sdcclib}
6531 To create a new library file, start by compiling all the required modules.
6537 \begin_layout Standard
6544 \begin_layout Standard
6551 \begin_layout Standard
6558 \begin_layout Standard
6565 \begin_layout Standard
6574 \begin_layout Standard
6575 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6577 The next step is to add the .rel files to the library file:
6582 \begin_layout Standard
6586 sdcclib libint.lib _divsint.rel
6589 \begin_inset LatexCommand \index{sdcclib}
6596 \begin_layout Standard
6600 sdcclib libint.lib _divuint.rel
6603 \begin_layout Standard
6607 sdcclib libint.lib _modsint.rel
6610 \begin_layout Standard
6614 sdcclib libint.lib _moduint.rel
6617 \begin_layout Standard
6621 sdcclib libint.lib _mulint.rel
6629 \begin_layout Standard
6638 \begin_layout Standard
6642 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6650 \begin_layout Standard
6651 If the file already exists in the library, it will be replaced.
6652 If a list of .rel files is available, you can tell sdcclib to add those
6654 For example, if the file 'myliblist.txt' contains
6662 \begin_layout Standard
6669 \begin_layout Standard
6676 \begin_layout Standard
6683 \begin_layout Standard
6690 \begin_layout Standard
6702 \begin_layout Standard
6711 \begin_layout Standard
6715 sdcclib -l libint.lib myliblist.txt
6723 \begin_layout Standard
6724 Additionally, you can instruct sdcclib to compiles the files before adding
6725 them to the library.
6726 This is achieved using the environment variables SDCCLIB_CC and/or SDCCLIB_AS.
6735 \begin_layout Standard
6739 set SDCCLIB_CC=sdcc -c
6742 \begin_layout Standard
6746 sdcclib -l libint.lib myliblist.txt
6754 \begin_layout Standard
6755 To see what modules and symbols are included in the library, options -s
6756 and -m are available.
6764 sdcclib -s libint.lib
6767 \begin_inset LatexCommand \index{sdcclib}
6779 \begin_layout Standard
6785 \begin_layout Standard
6791 \begin_layout Standard
6799 \begin_layout Standard
6805 \begin_layout Standard
6811 \begin_layout Standard
6817 \begin_layout Standard
6823 \begin_layout Standard
6831 \begin_layout Standard
6837 \begin_layout Standard
6843 \begin_layout Standard
6851 \begin_layout Standard
6857 \begin_layout Standard
6863 \begin_layout Standard
6869 \begin_layout Standard
6877 \begin_layout Standard
6883 \begin_layout Standard
6894 \begin_layout Standard
6895 If the source files are compiled using -
6899 \begin_layout Standard
6909 \begin_inset LatexCommand \index{-\/-debug}
6913 , the corresponding debug information file .adb will be include in the library
6915 The library files created with sdcclib are plain text files, so they can
6916 be viewed with a text editor.
6917 It is not recomended to modify a library file created with sdcclib using
6918 a text editor, as there are file indexes numbers located accross the file
6919 used by the linker to quickly locate the required module to link.
6920 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6921 it can be safely deleted, since all the information required for linking
6922 is embedded in the library file itself.
6923 Library files created using sdcclib are used as described in the preceding
6925 \begin_inset VSpace bigskip
6931 \begin_layout Section
6932 Command Line Options
6933 \begin_inset LatexCommand \index{Command Line Options}
6938 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6945 \begin_layout Subsection
6946 Processor Selection Options
6947 \begin_inset LatexCommand \index{Options processor selection}
6952 \begin_inset LatexCommand \index{Processor selection options}
6960 \labelwidthstring 00.00.0000
6964 \begin_inset LatexCommand \index{-mmcs51}
6970 Generate code for the Intel MCS51
6971 \begin_inset LatexCommand \index{MCS51}
6975 family of processors.
6976 This is the default processor target.
6980 \labelwidthstring 00.00.0000
6984 \begin_inset LatexCommand \index{-mds390}
6990 Generate code for the Dallas DS80C390
6991 \begin_inset LatexCommand \index{DS80C390}
6999 \labelwidthstring 00.00.0000
7003 \begin_inset LatexCommand \index{-mds400}
7009 Generate code for the Dallas DS80C400
7010 \begin_inset LatexCommand \index{DS80C400}
7018 \labelwidthstring 00.00.0000
7022 \begin_inset LatexCommand \index{-mhc08}
7028 Generate code for the Freescale/Motorola HC08
7029 \begin_inset LatexCommand \index{HC08}
7033 family of processors.
7037 \labelwidthstring 00.00.0000
7041 \begin_inset LatexCommand \index{-mz80}
7047 Generate code for the Zilog Z80
7048 \begin_inset LatexCommand \index{Z80}
7052 family of processors.
7056 \labelwidthstring 00.00.0000
7060 \begin_inset LatexCommand \index{-mgbz80}
7066 Generate code for the GameBoy Z80
7067 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
7071 processor (Not actively maintained).
7075 \labelwidthstring 00.00.0000
7079 \begin_inset LatexCommand \index{-mavr}
7085 Generate code for the Atmel AVR
7086 \begin_inset LatexCommand \index{AVR}
7090 processor (Not maintained, not complete).
7091 AVR users should probably have a look at winavr
7092 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
7097 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
7101 , which is based on AVR-port of the gcc compiler.
7104 \begin_layout Standard
7105 \begin_inset Note Note
7108 \begin_layout Standard
7109 I think it is fair to direct users there for now.
7110 Open source is also about avoiding unnecessary work .
7111 But I didn't find the 'official' link.
7120 \labelwidthstring 00.00.0000
7124 \begin_inset LatexCommand \index{-mpic14}
7130 Generate code for the Microchip PIC 14
7131 \begin_inset LatexCommand \index{PIC14}
7135 -bit processors (p16f84 and variants.
7136 In development, not complete).
7139 \begin_layout Standard
7140 \begin_inset Note Note
7143 \begin_layout Standard
7144 p16f627 p16f628 p16f84 p16f873 p16f877?
7153 \labelwidthstring 00.00.0000
7157 \begin_inset LatexCommand \index{-mpic16}
7163 Generate code for the Microchip PIC 16
7164 \begin_inset LatexCommand \index{PIC16}
7168 -bit processors (p18f452 and variants.
7169 In development, not complete).
7173 \labelwidthstring 00.00.0000
7178 Generate code for the Toshiba TLCS-900H
7179 \begin_inset LatexCommand \index{TLCS-900H}
7183 processor (Not maintained, not complete).
7187 \labelwidthstring 00.00.0000
7191 \begin_inset LatexCommand \index{-mxa51}
7197 Generate code for the Phillips XA51
7198 \begin_inset LatexCommand \index{XA51}
7202 processor (Not maintained, not complete).
7205 \begin_layout Standard
7206 \begin_inset VSpace bigskip
7212 \begin_layout Subsection
7213 Preprocessor Options
7214 \begin_inset LatexCommand \index{Options preprocessor}
7219 \begin_inset LatexCommand \index{Preprocessor options}
7224 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7232 \labelwidthstring 00.00.0000
7236 \begin_inset LatexCommand \index{-I<path>}
7242 The additional location where the preprocessor will look for <..h> or
7243 \begin_inset Quotes eld
7247 \begin_inset Quotes erd
7254 \labelwidthstring 00.00.0000
7258 \begin_inset LatexCommand \index{-D<macro[=value]>}
7264 Command line definition of macros.
7265 Passed to the preprocessor.
7269 \labelwidthstring 00.00.0000
7273 \begin_inset LatexCommand \index{-M}
7279 Tell the preprocessor to output a rule suitable for make describing the
7280 dependencies of each object file.
7281 For each source file, the preprocessor outputs one make-rule whose target
7282 is the object file name for that source file and whose dependencies are
7283 all the files `#include'd in it.
7284 This rule may be a single line or may be continued with `
7286 '-newline if it is long.
7287 The list of rules is printed on standard output instead of the preprocessed
7290 \begin_inset LatexCommand \index{-E}
7298 \labelwidthstring 00.00.0000
7302 \begin_inset LatexCommand \index{-C}
7308 Tell the preprocessor not to discard comments.
7309 Used with the `-E' option.
7313 \labelwidthstring 00.00.0000
7317 \begin_inset LatexCommand \index{-MM}
7328 Like `-M' but the output mentions only the user header files included with
7330 \begin_inset Quotes eld
7334 System header files included with `#include <file>' are omitted.
7338 \labelwidthstring 00.00.0000
7342 \begin_inset LatexCommand \index{-Aquestion(answer)}
7348 Assert the answer answer for question, in case it is tested with a preprocessor
7349 conditional such as `#if #question(answer)'.
7350 `-A-' disables the standard assertions that normally describe the target
7355 \labelwidthstring 00.00.0000
7359 \begin_inset LatexCommand \index{-Umacro}
7365 Undefine macro macro.
7366 `-U' options are evaluated after all `-D' options, but before any `-include'
7367 and `-imacros' options.
7371 \labelwidthstring 00.00.0000
7375 \begin_inset LatexCommand \index{-dM}
7381 Tell the preprocessor to output only a list of the macro definitions that
7382 are in effect at the end of preprocessing.
7383 Used with the `-E' option.
7387 \labelwidthstring 00.00.0000
7391 \begin_inset LatexCommand \index{-dD}
7397 Tell the preprocessor to pass all macro definitions into the output, in
7398 their proper sequence in the rest of the output.
7402 \labelwidthstring 00.00.0000
7406 \begin_inset LatexCommand \index{-dN}
7417 Like `-dD' except that the macro arguments and contents are omitted.
7418 Only `#define name' is included in the output.
7422 \labelwidthstring 00.00.0000
7425 -pedantic-parse-number
7426 \begin_inset LatexCommand \index{pedantic}
7431 \begin_inset LatexCommand \index{-pedantic-parse-number}
7439 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
7447 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7448 and the macro LO_B(3) gets expanded.
7449 See also #pragma pedantic_parse_number
7450 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
7455 \begin_inset LatexCommand \ref{sec:Pragmas}
7461 Note: this functionality is not in conformance with C99 standard!
7465 \labelwidthstring 00.00.0000
7469 preprocessorOption[,preprocessorOption]
7472 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
7477 Pass the preprocessorOption to the preprocessor
7482 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7487 SDCC uses an adapted version of the preprocessor
7491 of the GNU Compiler Collection
7492 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
7501 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7505 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7510 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7517 \begin_layout Standard
7518 \begin_inset VSpace bigskip
7524 \begin_layout Subsection
7526 \begin_inset LatexCommand \index{Options linker}
7531 \begin_inset LatexCommand \index{Linker options}
7539 \labelwidthstring 00.00.0000
7549 \begin_layout Standard
7561 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7566 \begin_inset LatexCommand \index{-L -\/-lib-path}
7573 <absolute path to additional libraries> This option is passed to the linkage
7574 editor's additional libraries
7575 \begin_inset LatexCommand \index{Libraries}
7580 The path name must be absolute.
7581 Additional library files may be specified in the command line.
7582 See section Compiling programs for more details.
7586 \labelwidthstring 00.00.0000
7593 \begin_layout Standard
7605 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7610 <Value> The start location of the external ram
7611 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7615 , default value is 0.
7616 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7620 \begin_layout Standard
7629 -xram-loc 0x8000 or -
7633 \begin_layout Standard
7646 \labelwidthstring 00.00.0000
7653 \begin_layout Standard
7665 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7670 <Value> The start location of the code
7671 \begin_inset LatexCommand \index{code}
7675 segment, default value 0.
7676 Note when this option is used the interrupt vector table
7677 \begin_inset LatexCommand \index{interrupt vector table}
7681 is also relocated to the given address.
7682 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7686 \begin_layout Standard
7695 -code-loc 0x8000 or -
7699 \begin_layout Standard
7712 \labelwidthstring 00.00.0000
7719 \begin_layout Standard
7731 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7736 <Value> By default the stack
7737 \begin_inset LatexCommand \index{stack}
7741 is placed after the data segment.
7742 Using this option the stack can be placed anywhere in the internal memory
7744 The value entered can be in Hexadecimal or Decimal format, e.g.
7749 \begin_layout Standard
7758 -stack-loc 0x20 or -
7762 \begin_layout Standard
7772 Since the sp register is incremented before a push or call, the initial
7773 sp will be set to one byte prior the provided value.
7774 The provided value should not overlap any other memory areas such as used
7775 register banks or the data segment and with enough space for the current
7783 \begin_layout Standard
7796 \begin_inset LatexCommand \index{-\/-pack-iram}
7800 option (which is now a default setting) will override this setting, so
7801 you should also specify the
7807 \begin_layout Standard
7820 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7824 option if you need to manually place the stack.
7828 \labelwidthstring 00.00.0000
7835 \begin_layout Standard
7847 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7852 <Value> By default the external stack
7853 \begin_inset LatexCommand \index{xstack}
7857 is placed after the pdata
7858 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7863 Using this option the xstack can be placed anywhere in the external memory
7865 The value entered can be in Hexadecimal or Decimal format, e.g.
7870 \begin_layout Standard
7879 -xstack-loc 0x8000 or -
7883 \begin_layout Standard
7893 The provided value should not overlap any other memory areas such as the
7894 pdata or xdata segment and with enough space for the current application.
7898 \labelwidthstring 00.00.0000
7905 \begin_layout Standard
7917 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7922 <Value> The start location of the internal ram data
7923 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7928 The value entered can be in Hexadecimal or Decimal format, eg.
7933 \begin_layout Standard
7946 \begin_layout Standard
7956 (By default, the start location of the internal ram data segment is set
7957 as low as possible in memory, taking into account the used register banks
7958 and the bit segment at address 0x20.
7959 For example if register banks 0 and 1 are used without bit variables, the
7960 data segment will be set, if -
7964 \begin_layout Standard
7973 -data-loc is not used, to location 0x10.)
7977 \labelwidthstring 00.00.0000
7984 \begin_layout Standard
7996 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
8001 <Value> The start location of the indirectly addressable internal ram
8002 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
8006 of the 8051, default value is 0x80.
8007 The value entered can be in Hexadecimal or Decimal format, eg.
8012 \begin_layout Standard
8021 -idata-loc 0x88 or -
8025 \begin_layout Standard
8038 \labelwidthstring 00.00.0000
8045 \begin_layout Standard
8057 <Value> The start location of the bit
8058 \begin_inset LatexCommand \index{bit}
8062 addressable internal ram of the 8051.
8068 Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
8073 \labelwidthstring 00.00.0000
8080 \begin_layout Standard
8090 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
8099 The linker output (final object code) is in Intel Hex format.
8100 \begin_inset LatexCommand \index{Intel hex format}
8104 This is the default option.
8105 The format itself is documented in the documentation of srecord
8106 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
8114 \labelwidthstring 00.00.0000
8121 \begin_layout Standard
8131 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
8140 The linker output (final object code) is in Motorola S19 format
8141 \begin_inset LatexCommand \index{Motorola S19 format}
8146 The format itself is documented in the documentation of srecord.
8150 \labelwidthstring 00.00.0000
8157 \begin_layout Standard
8167 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
8172 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
8181 The linker output (final object code) is in ELF format
8182 \begin_inset LatexCommand \index{ELF format}
8187 (Currently only supported for the HC08
8188 \begin_inset LatexCommand \index{HC08}
8196 \labelwidthstring 00.00.0000
8200 linkOption[,linkOption]
8203 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
8208 \begin_inset LatexCommand \label{lyx:-Wl option}
8213 Pass the linkOption to the linker.
8214 If a bootloader is used an option like
8215 \begin_inset Quotes sld
8220 \begin_inset Quotes srd
8223 would be typical to set the start of the code segment.
8224 Either use the double quotes around this option or use no space (e.g.
8226 See also #pragma constseg and #pragma codeseg in section
8227 \begin_inset LatexCommand \ref{sec:Pragmas}
8232 File sdcc/as/doc/asxhtm.html has more on linker options.
8235 \begin_layout Standard
8236 \begin_inset VSpace bigskip
8242 \begin_layout Subsection
8244 \begin_inset LatexCommand \index{Options MCS51}
8249 \begin_inset LatexCommand \index{MCS51 options}
8257 \labelwidthstring 00.00.0000
8264 \begin_layout Standard
8274 \begin_inset LatexCommand \index{-\/-model-small}
8285 Generate code for Small Model programs, see section Memory Models for more
8287 This is the default model.
8291 \labelwidthstring 00.00.0000
8298 \begin_layout Standard
8308 \begin_inset LatexCommand \index{-\/-model-medium}
8314 Generate code for Medium model programs, see section Memory Models for
8316 If this option is used all source files in the project have to be compiled
8318 It must also be used when invoking the linker.
8322 \labelwidthstring 00.00.0000
8329 \begin_layout Standard
8339 \begin_inset LatexCommand \index{-\/-model-large}
8345 Generate code for Large model programs, see section Memory Models for more
8347 If this option is used all source files in the project have to be compiled
8349 It must also be used when invoking the linker.
8353 \labelwidthstring 00.00.0000
8360 \begin_layout Standard
8370 \begin_inset LatexCommand \index{-\/-xstack}
8376 Uses a pseudo stack in the pdata
8377 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8381 area (usually the first 256 bytes in the external ram) for allocating variables
8382 and passing parameters.
8384 \begin_inset LatexCommand \ref{sub:External-Stack}
8389 External Stack for more details.
8393 \labelwidthstring 00.00.0000
8400 \begin_layout Standard
8413 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
8417 Causes the linker to check if the internal ram usage is within limits of
8422 \labelwidthstring 00.00.0000
8429 \begin_layout Standard
8442 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
8446 Causes the linker to check if the external ram usage is within limits of
8451 \labelwidthstring 00.00.0000
8458 \begin_layout Standard
8471 \begin_inset LatexCommand \index{-\/-code-size <Value>}
8475 Causes the linker to check if the code memory usage is within limits of
8480 \labelwidthstring 00.00.0000
8487 \begin_layout Standard
8500 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8504 Causes the linker to check if there is at minimum <Value> bytes for stack.
8508 \labelwidthstring 00.00.0000
8515 \begin_layout Standard
8528 \begin_inset LatexCommand \index{-\/-pack-iram}
8532 Causes the linker to use unused register banks for data variables and pack
8533 data, idata and stack together.
8534 This is the default now.
8538 \labelwidthstring 00.00.0000
8545 \begin_layout Standard
8558 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8562 Causes the linker to use old style for allocating memory areas.
8566 \labelwidthstring 00.00.0000
8573 \begin_layout Standard
8586 \begin_inset LatexCommand \index{-\/-acall-ajmp}
8590 Replaces the three byte instructions lcall/ljmp with the two byte instructions
8592 Only use this option if your code is in the same 2k block of memory.
8593 You may need to use this option for some 8051 derivatives which lack the
8594 lcall/ljmp instructions..
8597 \begin_layout Standard
8598 \begin_inset VSpace bigskip
8604 \begin_layout Subsection
8605 DS390 / DS400 Options
8606 \begin_inset LatexCommand \index{Options DS390}
8611 \begin_inset LatexCommand \index{DS390}
8619 \labelwidthstring 00.00.0000
8626 \begin_layout Standard
8638 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8648 Generate 24-bit flat mode code.
8649 This is the one and only that the ds390 code generator supports right now
8650 and is default when using
8655 See section Memory Models for more details.
8659 \labelwidthstring 00.00.0000
8666 \begin_layout Standard
8676 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8682 disable interrupts during ESP:SP updates.
8686 \labelwidthstring 00.00.0000
8693 \begin_layout Standard
8705 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8709 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8710 This is the one and only that the ds390 code generator supports right now
8711 and is default when using
8716 In this mode, the stack is located in the lower 1K of the internal RAM,
8717 which is mapped to 0x400000.
8718 Note that the support is incomplete, since it still uses a single byte
8719 as the stack pointer.
8720 This means that only the lower 256 bytes of the potential 1K stack space
8721 will actually be used.
8722 However, this does allow you to reclaim the precious 256 bytes of low RAM
8723 for use for the DATA and IDATA segments.
8724 The compiler will not generate any code to put the processor into 10 bit
8726 It is important to ensure that the processor is in this mode before calling
8727 any re-entrant functions compiled with this option.
8728 In principle, this should work with the
8734 \begin_layout Standard
8744 \begin_inset LatexCommand \index{-\/-stack-auto}
8750 option, but that has not been tested.
8751 It is incompatible with the
8757 \begin_layout Standard
8767 \begin_inset LatexCommand \index{-\/-xstack}
8774 It also only makes sense if the processor is in 24 bit contiguous addressing
8781 \begin_layout Standard
8790 -model-flat24 option
8795 \begin_inset Note Note
8799 \labelwidthstring 00.00.0000
8806 \begin_layout Standard
8815 -stack-8-bit - switches off the 10-bit mode
8824 \labelwidthstring 00.00.0000
8831 \begin_layout Standard
8841 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8847 insert call to function __stack_probe at each function prologue.
8851 \labelwidthstring 00.00.0000
8858 \begin_layout Standard
8868 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8874 <nnnn> LibraryID used in -mTININative.
8879 \labelwidthstring 00.00.0000
8886 \begin_layout Standard
8896 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8902 generate code for DS390 Arithmetic Accelerator.
8906 \begin_layout Standard
8907 \begin_inset VSpace bigskip
8913 \begin_layout Subsection
8915 \begin_inset LatexCommand \index{Options Z80}
8920 \begin_inset LatexCommand \index{Z80}
8928 \labelwidthstring 00.00.0000
8935 \begin_layout Standard
8947 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8957 Force a called function to always save BC.
8961 \labelwidthstring 00.00.0000
8968 \begin_layout Standard
8980 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8984 When linking, skip the standard crt0.o object file.
8985 You must provide your own crt0.o for your system when linking.
8989 \labelwidthstring 00.00.0000
8996 \begin_layout Standard
9008 \begin_inset LatexCommand \index{Z80!Options!-\/-portmode=<Value>}
9012 Determinate PORT I/O mode (<Value> is z80 or z180).
9016 \labelwidthstring 00.00.0000
9023 \begin_layout Standard
9035 \begin_inset LatexCommand \index{Z80!Options!-\/-asm=<Value>}
9039 Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
9043 \labelwidthstring 00.00.0000
9050 \begin_layout Standard
9063 \begin_inset LatexCommand \index{Z80!Options!-\/-codeseg <Value>}
9067 Use <Value> for the code segment name.
9071 \labelwidthstring 00.00.0000
9078 \begin_layout Standard
9091 \begin_inset LatexCommand \index{Z80!Options!-\/-constseg <Value>}
9095 Use <Value> for the const segment name.
9099 \labelwidthstring 00.00.0000
9100 \begin_inset VSpace bigskip
9106 \begin_layout Subsection
9108 \begin_inset LatexCommand \index{Options GBZ80}
9113 \begin_inset LatexCommand \index{GBZ80}
9121 \labelwidthstring 00.00.0000
9128 \begin_layout Standard
9140 \begin_inset LatexCommand \index{GBZ80!Options!-\/-callee-saves-bc}
9150 Force a called function to always save BC.
9154 \labelwidthstring 00.00.0000
9161 \begin_layout Standard
9173 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
9177 When linking, skip the standard crt0.o object file.
9178 You must provide your own crt0.o for your system when linking.
9182 \labelwidthstring 00.00.0000
9189 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
9193 Use code bank <Num>.
9197 \labelwidthstring 00.00.0000
9204 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
9208 Use data bank <Num>.
9212 \labelwidthstring 00.00.0000
9219 \begin_layout Standard
9232 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
9236 Use <Value> for the code segment name.
9240 \labelwidthstring 00.00.0000
9247 \begin_layout Standard
9260 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
9264 Use <Value> for the const segment name.
9267 \begin_layout Standard
9268 \begin_inset VSpace bigskip
9274 \begin_layout Subsection
9275 Optimization Options
9276 \begin_inset LatexCommand \index{Options optimization}
9281 \begin_inset LatexCommand \index{Optimization options}
9289 \labelwidthstring 00.00.0000
9296 \begin_layout Standard
9306 \begin_inset LatexCommand \index{-\/-nogcse}
9312 Will not do global subexpression elimination, this option may be used when
9313 the compiler creates undesirably large stack/data spaces to store compiler
9323 \begin_inset LatexCommand \index{sloc (spill location)}
9328 A warning message will be generated when this happens and the compiler
9329 will indicate the number of extra bytes it allocated.
9330 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9332 \begin_inset LatexCommand \index{\#pragma nogcse}
9336 can be used to turn off global subexpression elimination
9337 \begin_inset LatexCommand \index{Subexpression elimination}
9341 for a given function only.
9345 \labelwidthstring 00.00.0000
9352 \begin_layout Standard
9362 \begin_inset LatexCommand \index{-\/-noinvariant}
9368 Will not do loop invariant optimizations, this may be turned off for reasons
9369 explained for the previous option.
9370 For more details of loop optimizations performed see Loop Invariants in
9372 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
9377 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9379 \begin_inset LatexCommand \index{\#pragma noinvariant}
9383 can be used to turn off invariant optimizations for a given function only.
9387 \labelwidthstring 00.00.0000
9394 \begin_layout Standard
9404 \begin_inset LatexCommand \index{-\/-noinduction}
9410 Will not do loop induction optimizations, see section strength reduction
9412 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9414 \begin_inset LatexCommand \index{\#pragma noinduction}
9418 can be used to turn off induction optimizations for a given function only.
9422 \labelwidthstring 00.00.0000
9429 \begin_layout Standard
9439 \begin_inset LatexCommand \index{-\/-nojtbound}
9450 Will not generate boundary condition check when switch statements
9451 \begin_inset LatexCommand \index{switch statement}
9455 are implemented using jump-tables.
9457 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
9462 Switch Statements for more details.
9463 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9465 \begin_inset LatexCommand \index{\#pragma nojtbound}
9469 can be used to turn off boundary checking for jump tables for a given function
9474 \labelwidthstring 00.00.0000
9481 \begin_layout Standard
9491 \begin_inset LatexCommand \index{-\/-noloopreverse}
9500 Will not do loop reversal
9501 \begin_inset LatexCommand \index{Loop reversing}
9509 \labelwidthstring 00.00.0000
9514 \begin_layout Standard
9528 \begin_inset LatexCommand \index{-\/-nolabelopt }
9532 Will not optimize labels (makes the dumpfiles more readable).
9536 \labelwidthstring 00.00.0000
9543 \begin_layout Standard
9553 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9559 Will not memcpy initialized data from code space into xdata space.
9560 This saves a few bytes in code space if you don't have initialized data
9561 \begin_inset LatexCommand \index{Variable initialization}
9569 \labelwidthstring 00.00.0000
9576 \begin_layout Standard
9586 \begin_inset LatexCommand \index{-\/-nooverlay}
9592 The compiler will not overlay parameters and local variables of any function,
9593 see section Parameters and local variables for more details.
9597 \labelwidthstring 00.00.0000
9604 \begin_layout Standard
9614 \begin_inset LatexCommand \index{-\/-no-peep}
9620 Disable peep-hole optimization with built-in rules.
9624 \labelwidthstring 00.00.0000
9631 \begin_layout Standard
9643 \begin_inset LatexCommand \index{-\/-peep-file}
9648 <filename> This option can be used to use additional rules to be used by
9649 the peep hole optimizer.
9651 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9656 Peep Hole optimizations for details on how to write these rules.
9660 \labelwidthstring 00.00.0000
9667 \begin_layout Standard
9677 \begin_inset LatexCommand \index{-\/-peep-asm}
9683 Pass the inline assembler code through the peep hole optimizer.
9684 This can cause unexpected changes to inline assembler code, please go through
9685 the peephole optimizer
9686 \begin_inset LatexCommand \index{Peephole optimizer}
9690 rules defined in the source file tree '<target>/peeph.def' before using
9695 \labelwidthstring 00.00.0000
9702 \begin_layout Standard
9712 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9718 The compiler will optimize code generation towards fast code, possibly
9719 at the expense of code size.
9723 \labelwidthstring 00.00.0000
9730 \begin_layout Standard
9740 \begin_inset LatexCommand \index{-\/-opt-code-size}
9746 The compiler will optimize code generation towards compact code, possibly
9747 at the expense of code speed.
9750 \begin_layout Standard
9751 \begin_inset VSpace bigskip
9757 \begin_layout Subsection
9759 \begin_inset LatexCommand \index{Options other}
9767 \labelwidthstring 00.00.0000
9775 \begin_layout Standard
9785 \begin_inset LatexCommand \index{-\/-compile-only}
9790 \begin_inset LatexCommand \index{-c -\/-compile-only}
9796 will compile and assemble the source, but will not call the linkage editor.
9800 \labelwidthstring 00.00.0000
9809 \begin_layout Standard
9821 \begin_inset LatexCommand \index{-\/-c1mode}
9827 reads the preprocessed source from standard input and compiles it.
9828 The file name for the assembler output must be specified using the -o option.
9832 \labelwidthstring 00.00.0000
9836 \begin_inset LatexCommand \index{-E}
9842 Run only the C preprocessor.
9843 Preprocess all the C source files specified and output the results to standard
9848 \labelwidthstring 00.00.0000
9853 \begin_inset LatexCommand \index{-o <path/file>}
9859 The output path where everything will be placed or the file name used for
9860 all generated output files.
9861 If the parameter is a path, it must have a trailing slash (or backslash
9862 for the Windows binaries) to be recognized as a path.
9867 Note for Windows users: if the path contains spaces, it should be surrounded
9869 The trailing backslash should be doubled in order to prevent escaping the
9870 final quote, for example:
9873 \begin_inset Quotes sld
9887 \begin_inset Quotes srd
9892 or put after the final quote, for example:
9895 \begin_inset Quotes sld
9905 \begin_inset Quotes srd
9913 The path using slashes for directory delimiters can be used too, for example:
9917 \begin_inset Quotes sld
9920 F:/Projects/test3/output 1/
9921 \begin_inset Quotes srd
9930 \labelwidthstring 00.00.0000
9937 \begin_layout Standard
9947 \begin_inset LatexCommand \index{-\/-stack-auto}
9958 All functions in the source file will be compiled as
9963 \begin_inset LatexCommand \index{reentrant}
9968 the parameters and local variables will be allocated on the stack
9969 \begin_inset LatexCommand \index{stack}
9975 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9979 Parameters and Local Variables for more details.
9980 If this option is used all source files in the project should be compiled
9982 It automatically implies -
9988 \begin_layout Standard
9999 -int-long-reent and -
10005 \begin_layout Standard
10021 \labelwidthstring 00.00.0000
10028 \begin_layout Standard
10038 \begin_inset LatexCommand \index{-\/-callee-saves}
10043 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
10047 function1[,function2][,function3]....
10050 The compiler by default uses a caller saves convention for register saving
10051 across function calls, however this can cause unnecessary register pushing
10052 and popping when calling small functions from larger functions.
10053 This option can be used to switch the register saving convention for the
10054 function names specified.
10055 The compiler will not save registers when calling these functions, no extra
10056 code will be generated at the entry and exit (function prologue
10059 \begin_inset LatexCommand \index{function prologue}
10068 \begin_inset LatexCommand \index{function epilogue}
10074 ) for these functions to save and restore the registers used by these functions,
10075 this can SUBSTANTIALLY reduce code and improve run time performance of
10076 the generated code.
10077 In the future the compiler (with inter procedural analysis) will be able
10078 to determine the appropriate scheme to use for each function call.
10079 DO NOT use this option for built-in functions such as _mulint..., if this
10080 option is used for a library function the appropriate library function
10081 needs to be recompiled with the same option.
10082 If the project consists of multiple source files then all the source file
10083 should be compiled with the same -
10087 \begin_layout Standard
10096 -callee-saves option string.
10097 Also see #pragma\InsetSpace ~
10099 \begin_inset LatexCommand \index{\#pragma callee\_saves}
10104 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
10112 \labelwidthstring 00.00.0000
10119 \begin_layout Standard
10129 \begin_inset LatexCommand \index{-\/-all-callee-saves}
10143 \begin_layout Standard
10152 -callee-saves will be applied to all functions by default.
10156 \labelwidthstring 00.00.0000
10163 \begin_layout Standard
10173 \begin_inset LatexCommand \index{-\/-debug}
10182 When this option is used the compiler will generate debug information.
10183 The debug information collected in a file with .cdb extension can be used
10185 For more information see documentation for SDCDB.
10186 Another file with no extension contains debug information in AOMF or AOMF51
10187 \begin_inset LatexCommand \index{AOMF, AOMF51}
10191 format which is commonly used by third party tools.
10195 \labelwidthstring 00.00.0000
10199 \begin_inset LatexCommand \index{-S}
10210 Stop after the stage of compilation proper; do not assemble.
10211 The output is an assembler code file for the input file specified.
10215 \labelwidthstring 00.00.0000
10222 \begin_layout Standard
10232 \begin_inset LatexCommand \index{-\/-int-long-reent}
10238 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
10239 Note by default these libraries are compiled as non-reentrant.
10240 See section Installation for more details.
10244 \labelwidthstring 00.00.0000
10251 \begin_layout Standard
10261 \begin_inset LatexCommand \index{-\/-cyclomatic}
10270 This option will cause the compiler to generate an information message for
10271 each function in the source file.
10272 The message contains some
10276 information about the function.
10277 The number of edges and nodes the compiler detected in the control flow
10278 graph of the function, and most importantly the
10280 cyclomatic complexity
10281 \begin_inset LatexCommand \index{Cyclomatic complexity}
10287 see section on Cyclomatic Complexity for more details.
10291 \labelwidthstring 00.00.0000
10298 \begin_layout Standard
10308 \begin_inset LatexCommand \index{-\/-float-reent}
10314 Floating point library is compiled as reentrant
10315 \begin_inset LatexCommand \index{reentrant}
10320 See section Installation for more details.
10324 \labelwidthstring 00.00.0000
10331 \begin_layout Standard
10341 \begin_inset LatexCommand \index{-\/-funsigned-char}
10347 The default signedness for every type is
10352 In some embedded environments the default signedness of
10361 To set the signess for characters to unsigned, use the option -
10367 \begin_layout Standard
10379 If this option is set and no signedness keyword (unsigned/signed) is given,
10380 a char will be signed.
10381 All other types are unaffected.
10385 \labelwidthstring 00.00.0000
10392 \begin_layout Standard
10402 \begin_inset LatexCommand \index{-\/-main-return}
10408 This option can be used if the code generated is called by a monitor program
10409 or if the main routine includes an endless loop.
10410 This option results in slightly smaller code and saves two bytes of stack
10412 The return from the 'main'
10413 \begin_inset LatexCommand \index{main return}
10417 function will return to the function calling main.
10418 The default setting is to lock up i.e.
10427 \labelwidthstring 00.00.0000
10434 \begin_layout Standard
10444 \begin_inset LatexCommand \index{-\/-nostdinc}
10450 This will prevent the compiler from passing on the default include path
10451 to the preprocessor.
10455 \labelwidthstring 00.00.0000
10462 \begin_layout Standard
10472 \begin_inset LatexCommand \index{-\/-nostdlib}
10478 This will prevent the compiler from passing on the default library
10479 \begin_inset LatexCommand \index{Libraries}
10483 path to the linker.
10487 \labelwidthstring 00.00.0000
10494 \begin_layout Standard
10504 \begin_inset LatexCommand \index{-\/-verbose}
10510 Shows the various actions the compiler is performing.
10514 \labelwidthstring 00.00.0000
10518 \begin_inset LatexCommand \index{-V}
10524 Shows the actual commands the compiler is executing.
10528 \labelwidthstring 00.00.0000
10535 \begin_layout Standard
10545 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
10551 Hides your ugly and inefficient c-code from the asm file, so you can always
10552 blame the compiler :)
10556 \labelwidthstring 00.00.0000
10563 \begin_layout Standard
10573 \begin_inset LatexCommand \index{-\/-no-gen-comments}
10579 Include code generator and peep-hole comments in the generated asm files.
10583 \labelwidthstring 00.00.0000
10590 \begin_layout Standard
10600 \begin_inset LatexCommand \index{-\/-no-peep-comments}
10606 Don't include peep-hole comments in the generated asm files even if -
10612 \begin_layout Standard
10623 -fverbose-asm option is specified.
10627 \labelwidthstring 00.00.0000
10634 \begin_layout Standard
10644 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10650 Include i-codes in the asm file.
10651 Sounds like noise but is most helpful for debugging the compiler itself.
10655 \labelwidthstring 00.00.0000
10662 \begin_layout Standard
10672 \begin_inset LatexCommand \index{pedantic}
10677 \begin_inset LatexCommand \index{-\/-less-pedantic}
10684 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10688 Disable some of the more pedantic warnings
10689 \begin_inset LatexCommand \index{Warnings}
10694 For more details, see the less_pedantic pragma
10695 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10703 \labelwidthstring 00.00.0000
10710 \begin_layout Standard
10719 -disable-warning\InsetSpace ~
10721 \begin_inset LatexCommand \index{-\/-disable-warning}
10727 Disable specific warning with number <nnnn>.
10731 \labelwidthstring 00.00.0000
10738 \begin_layout Standard
10748 \begin_inset LatexCommand \index{-\/-Werror}
10754 Treat all warnings as errors.
10758 \labelwidthstring 00.00.0000
10765 \begin_layout Standard
10775 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10781 Display the directories in the compiler's search path
10785 \labelwidthstring 00.00.0000
10792 \begin_layout Standard
10802 \begin_inset LatexCommand \index{-\/-vc}
10808 Display errors and warnings using MSVC style, so you can use SDCC with
10809 the visual studio IDE
10810 \begin_inset LatexCommand \index{IDE}
10815 With SDCC both offering a GCC-like (the default) and a MSVC-like
10816 \begin_inset LatexCommand \index{MSVC output style}
10820 output style, integration into most programming editors should be straightforwa
10825 \labelwidthstring 00.00.0000
10832 \begin_layout Standard
10842 \begin_inset LatexCommand \index{-\/-use-stdout}
10848 Send errors and warnings to stdout instead of stderr.
10852 \labelwidthstring 00.00.0000
10856 asmOption[,asmOption]
10859 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10864 Pass the asmOption to the assembler
10865 \begin_inset LatexCommand \index{Options assembler}
10870 \begin_inset LatexCommand \index{Assembler options}
10875 See file sdcc/as/doc/asxhtm.html for assembler options.cd
10879 \labelwidthstring 00.00.0000
10886 \begin_layout Standard
10896 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10902 Generally follow the C89 standard, but allow SDCC features that conflict
10903 with the standard (default).
10907 \labelwidthstring 00.00.0000
10914 \begin_layout Standard
10924 \begin_inset LatexCommand \index{-\/-std-c89}
10930 Follow the C89 standard and disable SDCC features that conflict with the
10935 \labelwidthstring 00.00.0000
10942 \begin_layout Standard
10952 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10958 Generally follow the C99 standard, but allow SDCC features that conflict
10959 with the standard (incomplete support).
10963 \labelwidthstring 00.00.0000
10970 \begin_layout Standard
10980 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10986 Follow the C99 standard and disable SDCC features that conflict with the
10987 standard (incomplete support).
10991 \labelwidthstring 00.00.0000
10998 \begin_layout Standard
11010 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
11015 \begin_inset LatexCommand \label{lyx:-codeseg}
11020 <Name> The name to be used for the code
11021 \begin_inset LatexCommand \index{code}
11025 segment, default CSEG.
11026 This is useful if you need to tell the compiler to put the code in a special
11027 segment so you can later on tell the linker to put this segment in a special
11029 Can be used for instance when using bank switching to put the code in a
11034 \labelwidthstring 00.00.0000
11041 \begin_layout Standard
11053 \begin_inset LatexCommand \index{-\/-constseg <Value>}
11058 <Name> The name to be used for the const
11059 \begin_inset LatexCommand \index{const}
11063 segment, default CONST.
11064 This is useful if you need to tell the compiler to put the const data in
11065 a special segment so you can later on tell the linker to put this segment
11066 in a special place in memory.
11067 Can be used for instance when using bank switching to put the const data
11072 \labelwidthstring 00.00.0000
11079 \begin_layout Standard
11088 -fdollars-in-identifiers
11089 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
11095 Permit '$' as an identifier character.
11099 \labelwidthstring 00.00.0000
11106 \begin_layout Standard
11118 \begin_inset LatexCommand \index{-\/-more-pedantic}
11123 \begin_inset LatexCommand \index{pedantic}
11133 a SDCC compiler option but if you want
11137 warnings you can use a separate tool dedicated to syntax checking like
11139 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
11144 \begin_inset LatexCommand \index{lint (syntax checking tool)}
11149 \begin_inset LatexCommand \url{http://www.splint.org}
11154 To make your source files parseable by splint you will have to include
11160 \begin_inset LatexCommand \index{splint (syntax checking tool)}
11164 in your source file and add brackets around extended keywords (like
11167 \begin_inset Quotes sld
11180 \begin_inset Quotes srd
11188 \begin_inset Quotes sld
11191 __interrupt\InsetSpace ~
11193 \begin_inset Quotes srd
11201 Splint has an excellent on line manual at
11202 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
11206 and it's capabilities go beyond pure syntax checking.
11207 You'll need to tell splint the location of SDCC's include files so a typical
11208 command line could look like this:
11212 splint\InsetSpace ~
11214 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
11220 \labelwidthstring 00.00.0000
11227 \begin_layout Standard
11239 \begin_inset LatexCommand \index{-\/-short-is-8bits}
11244 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
11248 Treat short as 8-bit (for backward compatibility with older versions of
11249 compiler - see section
11250 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
11257 \begin_layout Standard
11258 \begin_inset VSpace bigskip
11264 \begin_layout Subsection
11265 Intermediate Dump Options
11266 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
11271 \begin_inset LatexCommand \index{Options intermediate dump}
11276 \begin_inset LatexCommand \index{Intermediate dump options}
11283 \begin_layout Standard
11284 The following options are provided for the purpose of retargetting and debugging
11286 They provide a means to dump the intermediate code (iCode
11287 \begin_inset LatexCommand \index{iCode}
11291 ) generated by the compiler in human readable form at various stages of
11292 the compilation process.
11293 More on iCodes see chapter
11294 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
11299 \begin_inset Quotes srd
11302 The anatomy of the compiler
11303 \begin_inset Quotes srd
11310 \labelwidthstring 00.00.0000
11317 \begin_layout Standard
11327 \begin_inset LatexCommand \index{-\/-dumpraw}
11333 This option will cause the compiler to dump the intermediate code into
11336 <source filename>.dumpraw
11338 just after the intermediate code has been generated for a function, i.e.
11339 before any optimizations are done.
11341 \begin_inset LatexCommand \index{Basic blocks}
11345 at this stage ordered in the depth first number, so they may not be in
11346 sequence of execution.
11350 \labelwidthstring 00.00.0000
11357 \begin_layout Standard
11367 \begin_inset LatexCommand \index{-\/-dumpgcse}
11373 Will create a dump of iCodes, after global subexpression elimination
11374 \begin_inset LatexCommand \index{Global subexpression elimination}
11378 , into a file named
11380 <source filename>.dumpgcse.
11384 \labelwidthstring 00.00.0000
11391 \begin_layout Standard
11401 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
11407 Will create a dump of iCodes, after deadcode elimination
11408 \begin_inset LatexCommand \index{Dead-code elimination}
11412 , into a file named
11414 <source filename>.dumpdeadcode.
11418 \labelwidthstring 00.00.0000
11425 \begin_layout Standard
11435 \begin_inset LatexCommand \index{-\/-dumploop}
11444 Will create a dump of iCodes, after loop optimizations
11445 \begin_inset LatexCommand \index{Loop optimization}
11449 , into a file named
11451 <source filename>.dumploop.
11455 \labelwidthstring 00.00.0000
11462 \begin_layout Standard
11472 \begin_inset LatexCommand \index{-\/-dumprange}
11481 Will create a dump of iCodes, after live range analysis
11482 \begin_inset LatexCommand \index{Live range analysis}
11486 , into a file named
11488 <source filename>.dumprange.
11492 \labelwidthstring 00.00.0000
11499 \begin_layout Standard
11509 \begin_inset LatexCommand \index{-\/-dumlrange}
11515 Will dump the life ranges
11516 \begin_inset LatexCommand \index{Live range analysis}
11524 \labelwidthstring 00.00.0000
11531 \begin_layout Standard
11541 \begin_inset LatexCommand \index{-\/-dumpregassign}
11550 Will create a dump of iCodes, after register assignment
11551 \begin_inset LatexCommand \index{Register assignment}
11555 , into a file named
11557 <source filename>.dumprassgn.
11561 \labelwidthstring 00.00.0000
11568 \begin_layout Standard
11578 \begin_inset LatexCommand \index{-\/-dumplrange}
11584 Will create a dump of the live ranges of iTemp's
11588 \labelwidthstring 00.00.0000
11595 \begin_layout Standard
11605 \begin_inset LatexCommand \index{-\/-dumpall}
11616 Will cause all the above mentioned dumps to be created.
11619 \begin_layout Standard
11620 \begin_inset VSpace bigskip
11626 \begin_layout Subsection
11627 Redirecting output on Windows Shells
11630 \begin_layout Standard
11631 By default SDCC writes its error messages to
11632 \begin_inset Quotes sld
11636 \begin_inset Quotes srd
11640 To force all messages to
11641 \begin_inset Quotes sld
11645 \begin_inset Quotes srd
11657 \begin_layout Standard
11672 \begin_inset LatexCommand \index{-\/-use-stdout}
11677 Additionally, if you happen to have visual studio installed in your windows
11678 machine, you can use it to compile your sources using a custom build and
11685 \begin_layout Standard
11697 \begin_inset LatexCommand \index{-\/-vc}
11702 Something like this should work:
11721 \begin_layout Standard
11740 \begin_layout Standard
11752 -model-large -c $(InputPath)
11755 \begin_inset VSpace bigskip
11761 \begin_layout Section
11762 Environment variables
11763 \begin_inset LatexCommand \index{Environment variables}
11770 \begin_layout Standard
11771 SDCC recognizes the following environment variables:
11775 \labelwidthstring 00.00.0000
11779 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11785 SDCC installs a signal handler
11786 \begin_inset LatexCommand \index{signal handler}
11790 to be able to delete temporary files after an user break (^C) or an exception.
11791 If this environment variable is set, SDCC won't install the signal handler
11792 in order to be able to debug SDCC.
11796 \labelwidthstring 00.00.0000
11802 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11808 Path, where temporary files will be created.
11809 The order of the variables is the search order.
11810 In a standard *nix environment these variables are not set, and there's
11811 no need to set them.
11812 On Windows it's recommended to set one of them.
11816 \labelwidthstring 00.00.0000
11820 \begin_inset LatexCommand \index{SDCC\_HOME}
11827 \begin_inset LatexCommand \ref{sub:Install-paths}
11833 \begin_inset Quotes sld
11837 \begin_inset Quotes srd
11844 \labelwidthstring 00.00.0000
11848 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11855 \begin_inset LatexCommand \ref{sub:Search-Paths}
11861 \begin_inset Quotes sld
11865 \begin_inset Quotes srd
11872 \labelwidthstring 00.00.0000
11876 \begin_inset LatexCommand \index{SDCC\_LIB}
11883 \begin_inset LatexCommand \ref{sub:Search-Paths}
11889 \begin_inset Quotes sld
11893 \begin_inset Quotes srd
11899 \begin_layout Standard
11900 There are some more environment variables recognized by SDCC, but these
11901 are solely used for debugging purposes.
11902 They can change or disappear very quickly, and will never be documented.
11903 \begin_inset VSpace bigskip
11909 \begin_layout Section
11910 Storage Class Language Extensions
11913 \begin_layout Subsection
11914 MCS51/DS390 Storage Class
11915 \begin_inset LatexCommand \index{Storage class}
11919 Language Extensions
11922 \begin_layout Standard
11923 In addition to the ANSI storage classes SDCC allows the following MCS51
11924 specific storage classes:
11927 \begin_layout Subsubsection
11929 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11934 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11939 \begin_inset LatexCommand \index{near (storage class)}
11944 \begin_inset LatexCommand \index{\_\_near (storage class)}
11951 \begin_layout Standard
11956 storage class for the Small Memory model (
11964 or the more ANSI-C compliant forms
11972 can be used synonymously).
11973 Variables declared with this storage class will be allocated in the directly
11974 addressable portion of the internal RAM of a 8051, e.g.:
11977 \begin_layout Verse
11980 __data unsigned char test_data;
11983 \begin_layout Standard
11984 Writing 0x01 to this variable generates the assembly code:
11987 \begin_layout Verse
11990 75*00 01\InsetSpace ~
11998 \begin_layout Subsubsection
12000 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12005 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12010 \begin_inset LatexCommand \index{far (storage class)}
12015 \begin_inset LatexCommand \index{\_\_far (storage class)}
12022 \begin_layout Standard
12023 Variables declared with this storage class will be placed in the external
12029 storage class for the Large Memory model, e.g.:
12032 \begin_layout Verse
12035 __xdata unsigned char test_xdata;
12038 \begin_layout Standard
12039 Writing 0x01 to this variable generates the assembly code:
12042 \begin_layout Verse
12045 90s00r00\InsetSpace ~
12076 \begin_layout Subsubsection
12078 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12083 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12090 \begin_layout Standard
12091 Variables declared with this storage class will be allocated into the indirectly
12092 addressable portion of the internal ram of a 8051, e.g.:
12095 \begin_layout Verse
12098 __idata unsigned char test_idata;
12101 \begin_layout Standard
12102 Writing 0x01 to this variable generates the assembly code:
12105 \begin_layout Verse
12132 \begin_layout Standard
12133 Please note, the first 128 byte of idata physically access the same RAM
12134 as the data memory.
12135 The original 8051 had 128 byte idata memory, nowadays most devices have
12136 256 byte idata memory.
12138 \begin_inset LatexCommand \index{stack}
12142 is located in idata memory.
12145 \begin_layout Subsubsection
12147 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
12152 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
12159 \begin_layout Standard
12160 Paged xdata access is just as straightforward as using the other addressing
12162 It is typically located at the start of xdata and has a maximum size of
12164 The following example writes 0x01 to the pdata variable.
12165 Please note, pdata access physically accesses xdata memory.
12166 The high byte of the address is determined by port P2
12167 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
12171 (or in case of some 8051 variants by a separate Special Function Register,
12173 \begin_inset LatexCommand \ref{sub:MCS51-variants}
12182 storage class for the Medium Memory model, e.g.:
12185 \begin_layout Verse
12188 __pdata unsigned char test_pdata;
12191 \begin_layout Standard
12192 Writing 0x01 to this variable generates the assembly code:
12195 \begin_layout Verse
12204 mov r0,#_test_pdata
12226 \begin_layout Standard
12231 \begin_layout Standard
12241 \begin_inset LatexCommand \index{-\/-xstack}
12245 option is used the pdata memory area is followed by the xstack memory area
12246 and the sum of their sizes is limited to 256 bytes.
12249 \begin_layout Subsubsection
12251 \begin_inset LatexCommand \index{code}
12256 \begin_inset LatexCommand \index{\_\_code}
12263 \begin_layout Standard
12264 'Variables' declared with this storage class will be placed in the code
12268 \begin_layout Verse
12271 __code unsigned char test_code;
12274 \begin_layout Standard
12275 Read access to this variable generates the assembly code:
12278 \begin_layout Verse
12281 90s00r6F\InsetSpace ~
12284 mov dptr,#_test_code
12309 \begin_layout Standard
12314 indexed arrays of characters in code memory can be accessed efficiently:
12317 \begin_layout Verse
12320 __code char test_array[] = {'c','h','e','a','p'};
12323 \begin_layout Standard
12324 Read access to this array using an 8-bit unsigned index generates the assembly
12328 \begin_layout Verse
12340 \begin_layout Verse
12343 90s00r41\InsetSpace ~
12346 mov dptr,#_test_array
12349 \begin_layout Verse
12364 \begin_layout Subsubsection
12366 \begin_inset LatexCommand \index{bit}
12371 \begin_inset LatexCommand \index{\_\_bit}
12378 \begin_layout Standard
12379 This is a data-type and a storage class specifier.
12380 When a variable is declared as a bit, it is allocated into the bit addressable
12381 memory of 8051, e.g.:
12384 \begin_layout Verse
12390 \begin_layout Standard
12391 Writing 1 to this variable generates the assembly code:
12394 \begin_layout Verse
12408 \begin_layout Standard
12409 The bit addressable memory consists of 128 bits which are located from 0x20
12410 to 0x2f in data memory.
12413 Apart from this 8051 specific storage class most architectures support
12415 \begin_inset LatexCommand \index{bitfields}
12423 \begin_layout Standard
12424 Not really meant as examples, but nevertheless showing what bitfields are
12425 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12431 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12432 signed modifier are implemented as unsigned.
12435 \begin_layout Subsubsection
12437 \begin_inset LatexCommand \index{sfr}
12442 \begin_inset LatexCommand \index{\_\_sfr}
12447 \begin_inset LatexCommand \index{sfr16}
12452 \begin_inset LatexCommand \index{\_\_sfr16}
12457 \begin_inset LatexCommand \index{sfr32}
12462 \begin_inset LatexCommand \index{\_\_sfr32}
12467 \begin_inset LatexCommand \index{\_\_sbit}
12472 \begin_inset LatexCommand \index{sbit}
12479 \begin_layout Standard
12480 Like the bit keyword,
12482 sfr / sfr16 / sfr32 / sbit
12484 signify both a data-type and storage class, they are used to describe the
12505 variables of a 8051, eg:
12508 \begin_layout Verse
12512 \begin_inset LatexCommand \index{at}
12517 \begin_inset LatexCommand \index{\_\_at}
12521 (0x80) P0;\InsetSpace ~
12522 /* special function register P0 at location 0x80 */
12527 special function register combination for timer 0
12531 with the high byte at
12532 location 0x8C and the low byte at location 0x8A */
12534 __sfr16 __at (0x8C8A)
12540 \begin_inset LatexCommand \index{at}
12545 \begin_inset LatexCommand \index{\_\_at}
12549 (0xd7) CY;\InsetSpace ~
12551 \begin_inset LatexCommand \index{Flags}
12556 \begin_inset LatexCommand \index{Carry flag}
12563 \begin_layout Standard
12564 Special function registers which are located on an address dividable by
12565 8 are bit-addressable, an
12569 addresses a specific bit within these sfr.
12571 16 Bit and 32 bit special function
12572 register combinations which require a certain access order are better not
12582 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12583 this is not guaranteed.
12588 \begin_layout Standard
12589 Please note, if you use a header file which was written for another compiler
12590 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
12596 Specifically the syntax
12599 sfr P0 = 0x80;\InsetSpace ~
12606 by SDCC to an assignment of 0x80 to a variable called P0
12609 \begin_inset Marginal
12612 \begin_layout Standard
12624 Nevertheless it is possible to write header files
12625 \begin_inset LatexCommand \index{Header files}
12630 \begin_inset LatexCommand \index{Include files}
12634 which can be shared among different compilers (see section
12635 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
12643 \begin_layout Subsubsection
12645 \begin_inset LatexCommand \index{Pointer}
12649 to MCS51/DS390 specific memory spaces
12652 \begin_layout Standard
12653 SDCC allows (via language extensions) pointers to explicitly point to any
12654 of the memory spaces
12655 \begin_inset LatexCommand \index{Memory model}
12660 In addition to the explicit pointers, the compiler uses (by default) generic
12661 pointers which can be used to point to any of the memory spaces.
12666 declaration examples:
12669 \begin_layout Verse
12672 /* pointer physically in internal ram pointing to object in external ram
12675 __xdata unsigned char * __data p;
12679 /* pointer physically in external ram
12680 pointing to object in internal ram */
12682 __data unsigned char * __xdata p;
12687 pointer physically in code rom pointing to data in xdata space */
12690 unsigned char * __code p;
12694 /* pointer physically in code space pointing to
12695 data in code space */
12697 __code unsigned char * __code p;
12702 physically located in xdata space */
12704 unsigned char * __xdata p;
12709 pointer physically located in default memory space */
12716 the following is a function pointer
12717 \begin_inset LatexCommand \index{function pointer}
12721 physically located in data space */
12723 char (* __data fp)(void);
12726 \begin_layout Standard
12727 Well you get the idea.
12732 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
12745 The highest order byte of the
12749 pointers contains the data space information.
12750 Assembler support routines are called whenever data is stored or retrieved
12756 These are useful for developing reusable library
12757 \begin_inset LatexCommand \index{Libraries}
12762 Explicitly specifying the pointer
12763 \begin_inset LatexCommand \index{pointer}
12767 type will generate the most efficient code.
12770 \begin_layout Subsubsection
12771 Notes on MCS51 memory
12772 \begin_inset LatexCommand \index{MCS51 memory}
12779 \begin_layout Standard
12780 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12781 RAM memory which is structured as follows:
12785 - Bytes 00-1F - 32 bytes to hold
12786 up to 4 banks of the registers R0 to R7,
12788 - Bytes 20-2F - 16 bytes to hold
12790 \begin_inset LatexCommand \index{bit}
12796 - Bytes 30-7F - 80 bytes for general purpose use.
12801 \begin_layout Standard
12802 Additionally some members of the MCS51 family may have up to 128 bytes of
12803 additional, indirectly addressable, internal RAM memory (
12808 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12813 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12818 Furthermore, some chips may have some built in external memory (
12823 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12828 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12832 ) which should not be confused with the internal, directly addressable RAM
12838 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12843 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12848 Sometimes this built in
12852 memory has to be activated before using it (you can probably find this
12853 information on the datasheet of the microcontroller your are using, see
12855 \begin_inset LatexCommand \ref{sub:Startup-Code}
12863 \begin_layout Standard
12864 Normally SDCC will only use the first bank
12865 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12869 of registers (register bank 0), but it is possible to specify that other
12870 banks of registers (keyword
12877 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12882 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12888 ) should be used for example in interrupt
12889 \begin_inset LatexCommand \index{interrupt}
12894 \begin_inset LatexCommand \index{\_\_interrupt}
12899 By default, the compiler will place the stack after the last byte of allocated
12900 memory for variables.
12901 For example, if the first 2 banks of registers are used, and only four
12906 variables, it will position the base of the internal stack at address 20
12908 This implies that as the stack
12909 \begin_inset LatexCommand \index{stack}
12913 grows, it will use up the remaining register banks, and the 16 bytes used
12914 by the 128 bit variables, and 80 bytes for general purpose use.
12915 If any bit variables are used, the data variables will be placed in unused
12916 register banks and after the byte holding the last bit variable.
12917 For example, if register banks 0 and 1 are used, and there are 9 bit variables
12922 variables will be placed starting from address 0x10 to 0x20 and continue
12928 \begin_layout Standard
12938 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12942 to specify the start address of the
12950 \begin_layout Standard
12960 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12964 to specify the size of the total internal RAM (
12978 \begin_layout Standard
12979 By default the 8051 linker will place the stack after the last byte of (i)data
12985 \begin_layout Standard
12995 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12999 allows you to specify the start of the stack, i.e.
13000 you could start it after any data in the general purpose area.
13001 If your microcontroller has additional indirectly addressable internal
13006 ) you can place the stack on it.
13007 You may also need to use -
13011 \begin_layout Standard
13021 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
13025 to set the start address of the external RAM (
13033 \begin_layout Standard
13043 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
13047 to specify its size.
13048 Same goes for the code memory, using -
13052 \begin_layout Standard
13062 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
13070 \begin_layout Standard
13080 \begin_inset LatexCommand \index{-\/-code-size <Value>}
13085 If in doubt, don't specify any options and see if the resulting memory
13086 layout is appropriate, then you can adjust it.
13089 \begin_layout Standard
13090 The linker generates two files with memory allocation information.
13091 The first, with extension .map
13092 \begin_inset LatexCommand \index{<file>.map}
13096 shows all the variables and segments.
13097 The second with extension .mem
13098 \begin_inset LatexCommand \index{<file>.mem}
13102 shows the final memory layout.
13103 The linker will complain either if memory segments overlap, there is not
13104 enough memory, or there is not enough space for stack.
13105 If you get any linking warnings and/or errors related to stack or segments
13106 allocation, take a look at either the .map or .mem files to find out what
13108 The .mem file may even suggest a solution to the problem.
13109 \begin_inset VSpace bigskip
13115 \begin_layout Subsection
13116 Z80/Z180 Storage Class
13117 \begin_inset LatexCommand \index{Z80!Storage class}
13121 Language Extensions
13124 \begin_layout Subsubsection
13126 \begin_inset LatexCommand \index{sfr}
13131 \begin_inset LatexCommand \index{\_\_sfr}
13135 (in/out to 8-bit addresses)
13138 \begin_layout Standard
13140 \begin_inset LatexCommand \index{Z80}
13144 family has separate address spaces for memory and
13154 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
13159 \begin_inset LatexCommand \index{Z80!I/O memory}
13164 \begin_inset LatexCommand \index{Z180!I/O memory}
13168 is accessed with special instructions, e.g.:
13171 \begin_layout Verse
13174 sfr at 0x78 IoPort;\InsetSpace ~
13176 /* define a var in I/O space at 78h called IoPort */
13180 \begin_layout Standard
13181 Writing 0x01 to this variable generates the assembly code:
13184 \begin_layout Verse
13204 \begin_layout Subsubsection
13206 \begin_inset LatexCommand \index{sfr}
13211 \begin_inset LatexCommand \index{\_\_sfr}
13215 (in/out to 16-bit addresses)
13218 \begin_layout Standard
13223 is used to support 16 bit addresses in I/O memory e.g.:
13226 \begin_layout Verse
13230 \begin_inset LatexCommand \index{at}
13235 \begin_inset LatexCommand \index{\_\_at}
13242 \begin_layout Standard
13243 Writing 0x01 to this variable generates the assembly code:
13246 \begin_layout Verse
13249 01 23 01\InsetSpace ~
13271 \begin_layout Subsubsection
13273 \begin_inset LatexCommand \index{sfr}
13278 \begin_inset LatexCommand \index{\_\_sfr}
13282 (in0/out0 to 8 bit addresses on Z180
13283 \begin_inset LatexCommand \index{Z180}
13288 \begin_inset LatexCommand \index{HD64180 (see Z180)}
13295 \begin_layout Standard
13296 The compiler option -
13300 \begin_layout Standard
13310 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
13314 =180 (80) and a compiler #pragma\InsetSpace ~
13316 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
13320 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
13330 If you include the file z180.h this will be set automatically.
13331 \begin_inset VSpace bigskip
13337 \begin_layout Subsection
13339 \begin_inset LatexCommand \index{HC08!Storage class}
13343 Language Extensions
13346 \begin_layout Subsubsection
13348 \begin_inset LatexCommand \index{data (hc08 storage class)}
13353 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
13360 \begin_layout Standard
13361 The data storage class declares a variable that resides in the first 256
13362 bytes of memory (the direct page).
13364 \begin_inset LatexCommand \index{HC08}
13368 is most efficient at accessing variables (especially pointers) stored here.
13371 \begin_layout Subsubsection
13373 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
13378 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
13385 \begin_layout Standard
13386 The xdata storage class declares a variable that can reside anywhere in
13388 This is the default if no storage class is specified.
13390 \begin_inset VSpace bigskip
13396 \begin_layout Section
13397 Other SDCC language extensions
13398 \begin_inset LatexCommand \index{Other SDCC language extensions}
13405 \begin_layout Subsection
13409 \begin_layout Standard
13410 SDCC supports the use of binary constants, such as 0b01100010.
13411 This feature is only enabled when the compiler is invoked using --std-sdccxx.
13414 \begin_layout Standard
13415 \begin_inset VSpace bigskip
13421 \begin_layout Section
13422 Absolute Addressing
13423 \begin_inset LatexCommand \index{Absolute addressing}
13430 \begin_layout Standard
13431 Data items can be assigned an absolute address with the
13434 \begin_inset LatexCommand \index{at}
13439 \begin_inset LatexCommand \index{\_\_at}
13445 keyword, in addition to a storage class, e.g.:
13448 \begin_layout Verse
13452 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13457 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
13462 \begin_inset LatexCommand \index{at}
13467 \begin_inset LatexCommand \index{\_\_at}
13471 0x7ffe unsigned int chksum;
13474 \begin_layout Standard
13475 or, better conforming to ISO/IEC 9899 C:
13478 \begin_layout Verse
13481 __xdata __at (0x7ffe) unsigned int chksum;
13484 \begin_layout Standard
13485 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
13486 of the external ram.
13491 reserve any space for variables declared in this way
13492 \begin_inset Marginal
13495 \begin_layout Standard
13504 (they are implemented with an equate in the assembler).
13505 Thus it is left to the programmer to make sure there are no overlaps with
13506 other variables that are declared without the absolute address.
13507 The assembler listing file (.lst
13508 \begin_inset LatexCommand \index{<file>.lst}
13512 ) and the linker output files (.rst
13513 \begin_inset LatexCommand \index{<file>.rst}
13518 \begin_inset LatexCommand \index{<file>.map}
13522 ) are good places to look for such overlaps.
13525 \begin_layout Standard
13526 If however you provide an initializer
13527 \begin_inset LatexCommand \index{Variable initialization}
13531 actual memory allocation will take place and overlaps will be detected
13536 \begin_layout Verse
13539 __code __at (0x7ff0) char Id[5] =
13540 \begin_inset Quotes sld
13544 \begin_inset Quotes srd
13550 \begin_layout Standard
13551 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
13555 \begin_layout Standard
13556 In case of memory mapped I/O devices the keyword
13560 has to be used to tell the compiler that accesses might not be removed:
13563 \begin_layout Verse
13567 \begin_inset LatexCommand \index{volatile}
13572 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13577 \begin_inset LatexCommand \index{at}
13581 (0x8000) unsigned char PORTA_8255;
13584 \begin_layout Standard
13585 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
13590 \begin_inset LatexCommand \index{Aligned array}
13597 starts at a block (256 byte) boundary
13598 \begin_inset LatexCommand \index{block boundary}
13603 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13609 Absolute addresses can be specified for variables in all
13610 storage classes, e.g.:
13613 \begin_layout Verse
13617 \begin_inset LatexCommand \index{bit}
13622 \begin_inset LatexCommand \index{at}
13629 \begin_layout Standard
13630 The above example will allocate the variable at offset 0x02 in the bit-addressab
13632 There is no real advantage to assigning absolute addresses to variables
13633 in this manner, unless you want strict control over all the variables allocated.
13634 One possible use would be to write hardware portable code.
13635 For example, if you have a routine that uses one or more of the microcontroller
13636 I/O pins, and such pins are different for two different hardwares, you
13637 can declare the I/O pins in your routine using:
13640 \begin_layout Verse
13644 \begin_inset LatexCommand \index{volatile}
13648 __bit MOSI;\InsetSpace ~
13652 /* master out, slave in */
13654 extern volatile __bit MISO;\InsetSpace ~
13661 extern volatile __bit MCLK;\InsetSpace ~
13670 Output of a byte on a 3-wire serial bus.
13675 If needed adapt polarity of clock,
13676 polarity of data and bit order
13681 unsigned char spi_io(unsigned char out_byte)
13706 MOSI = out_byte & 0x80;
13737 /* _asm nop _endasm; */\InsetSpace ~
13745 /* for slow peripherals */
13797 \begin_layout Standard
13798 Then, someplace in the code for the first hardware you would use
13801 \begin_layout Verse
13805 \begin_inset LatexCommand \index{at}
13810 \begin_inset LatexCommand \index{\_\_at}
13814 (0x80) MOSI;\InsetSpace ~
13818 /* I/O port 0, bit 0 */
13820 __bit __at (0x81) MISO;\InsetSpace ~
13827 __bit __at (0x82) MCLK;\InsetSpace ~
13831 /* I/O port 0, bit 2 */
13834 \begin_layout Standard
13835 Similarly, for the second hardware you would use
13838 \begin_layout Verse
13841 __bit __at (0x83) MOSI;\InsetSpace ~
13845 /* I/O port 0, bit 3 */
13847 __bit __at (0x91) MISO;\InsetSpace ~
13852 I/O port 1, bit 1 */
13855 \begin_inset LatexCommand \index{bit}
13859 __at (0x92) MCLK;\InsetSpace ~
13863 /* I/O port 1, bit 2 */
13866 \begin_layout Standard
13867 and you can use the same hardware dependent routine without changes, as
13868 for example in a library.
13869 This is somehow similar to sbit, but only one absolute address has to be
13870 specified in the whole project.
13871 \begin_inset VSpace bigskip
13877 \begin_layout Section
13879 \begin_inset LatexCommand \index{Parameters}
13884 \begin_inset LatexCommand \index{function parameter}
13889 \begin_inset LatexCommand \index{local variables}
13894 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13901 \begin_layout Standard
13902 Automatic (local) variables and parameters to functions can either be placed
13903 on the stack or in data-space.
13904 The default action of the compiler is to place these variables in the internal
13905 RAM (for small model) or external RAM (for medium or large model).
13906 This in fact makes them similar to
13909 \begin_inset LatexCommand \index{static}
13915 so by default functions are non-reentrant
13916 \begin_inset LatexCommand \index{reentrant}
13925 They can be placed on the stack
13926 \begin_inset LatexCommand \index{stack}
13936 \begin_layout Standard
13946 \begin_inset LatexCommand \index{-\/-stack-auto}
13954 #pragma\InsetSpace ~
13958 \begin_inset LatexCommand \index{\#pragma stackauto}
13965 \begin_inset LatexCommand \index{reentrant}
13971 keyword in the function declaration, e.g.:
13974 \begin_layout Verse
13977 unsigned char foo(char i) __reentrant
13991 \begin_layout Standard
13992 Since stack space on 8051 is limited, the
14002 \begin_layout Standard
14013 option should be used sparingly.
14014 Note that the reentrant keyword just means that the parameters & local
14015 variables will be allocated to the stack, it
14019 mean that the function is register bank
14020 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
14029 \begin_inset LatexCommand \index{local variables}
14033 can be assigned storage classes and absolute
14034 \begin_inset LatexCommand \index{Absolute addressing}
14041 \begin_layout Verse
14044 unsigned char foo()
14052 __xdata unsigned char i;
14065 \begin_inset LatexCommand \index{at}
14069 (0x31) unsigned char j;
14081 \begin_layout Standard
14082 In the above example the variable
14086 will be allocated in the external ram,
14090 in bit addressable space and
14101 \begin_layout Standard
14112 or when a function is declared as
14116 this should only be done for static variables.
14119 \begin_layout Standard
14121 \begin_inset LatexCommand \index{function parameter}
14125 however are not allowed any storage class
14126 \begin_inset LatexCommand \index{Storage class}
14130 , (storage classes for parameters will be ignored), their allocation is
14131 governed by the memory model in use, and the reentrancy options.
14134 \begin_layout Standard
14135 It is however allowed to use bit parameters in reentrant functions and also
14136 non-static local bit variables are supported.
14137 Efficient use is limited to 8 semi-bitregisters in bit space.
14138 They are pushed and popped to stack
14139 \begin_inset LatexCommand \index{stack}
14143 as a single byte just like the normal registers.
14146 \begin_layout Section
14148 \begin_inset LatexCommand \label{sub:Overlaying}
14153 \begin_inset LatexCommand \index{Overlaying}
14160 \begin_layout Standard
14162 \begin_inset LatexCommand \index{reentrant}
14166 functions SDCC will try to reduce internal ram space usage by overlaying
14167 parameters and local variables of a function (if possible).
14168 Parameters and local variables
14169 \begin_inset LatexCommand \index{local variables}
14173 of a function will be allocated to an overlayable segment if the function
14176 no other function calls and the function is non-reentrant and the memory
14178 \begin_inset LatexCommand \index{Memory model}
14185 If an explicit storage class
14186 \begin_inset LatexCommand \index{Storage class}
14190 is specified for a local variable, it will NOT be overlayed.
14193 \begin_layout Standard
14194 Note that the compiler (not the linkage editor) makes the decision for overlayin
14196 Functions that are called from an interrupt service routine
14197 \begin_inset Marginal
14200 \begin_layout Standard
14208 should be preceded by a #pragma\InsetSpace ~
14210 \begin_inset LatexCommand \index{\#pragma nooverlay}
14214 if they are not reentrant.
14217 \begin_layout Standard
14218 Also note that the compiler does not do any processing of inline assembler
14219 code, so the compiler might incorrectly assign local variables and parameters
14220 of a function into the overlay segment if the inline assembler code calls
14221 other c-functions that might use the overlay.
14222 In that case the #pragma\InsetSpace ~
14223 nooverlay should be used.
14226 \begin_layout Standard
14227 Parameters and local variables of functions that contain 16 or 32 bit multiplica
14229 \begin_inset LatexCommand \index{Multiplication}
14234 \begin_inset LatexCommand \index{Division}
14238 will NOT be overlayed since these are implemented using external functions,
14242 \begin_layout Verse
14248 \begin_inset LatexCommand \index{\#pragma nooverlay}
14254 void set_error(unsigned char errcd)
14271 some_isr () __interrupt
14272 \begin_inset LatexCommand \index{interrupt}
14302 \begin_layout Standard
14303 In the above example the parameter
14311 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
14313 not present, this could cause unpredictable runtime behavior when called
14314 from an interrupt service routine.
14315 The #pragma\InsetSpace ~
14316 nooverlay ensures that the parameters and local variables for
14317 the function are NOT overlayed.
14318 \begin_inset VSpace bigskip
14324 \begin_layout Section
14325 Interrupt Service Routines
14326 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
14333 \begin_layout Subsection
14334 General Information
14337 \begin_layout Standard
14350 outines to be coded in C, with some extended keywords.
14353 \begin_layout Verse
14356 void timer_isr (void) __interrupt (1) __using (1)
14370 \begin_layout Standard
14371 The optional number following the
14374 \begin_inset LatexCommand \index{interrupt}
14379 \begin_inset LatexCommand \index{\_\_interrupt}
14385 keyword is the interrupt number this routine will service.
14386 When present, the compiler will insert a call to this routine in the interrupt
14388 \begin_inset LatexCommand \index{interrupt vector table}
14392 for the interrupt number specified.
14393 If you have multiple source files in your project, interrupt service routines
14394 can be present in any of them, but a prototype of the isr MUST be present
14395 or included in the file that contains the function
14400 The optional (8051 specific) keyword
14403 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14408 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14414 can be used to tell the compiler to use the specified register bank when
14415 generating code for this function.
14418 Interrupt service routines open the door for some very interesting bugs:
14421 \begin_layout Subsubsection
14422 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
14426 Common interrupt pitfall: variable not declared
14431 \begin_layout Standard
14432 If an interrupt service routine changes variables which are accessed by
14433 other functions these variables have to be declared
14438 \begin_inset LatexCommand \index{volatile}
14444 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
14451 \begin_layout Subsubsection
14452 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
14456 Common interrupt pitfall:
14461 \begin_layout Standard
14462 If the access to these variables is not
14465 \begin_inset LatexCommand \index{atomic}
14472 the processor needs more than one instruction for the access and could
14473 be interrupted while accessing the variable) the interrupt must be disabled
14474 during the access to avoid inconsistent data.
14477 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
14478 and should be protected by disabling interrupts.
14479 You're not automatically on the safe side if you use 8 bit variables though.
14480 We need an example here: f.e.
14481 on the 8051 the harmless looking
14482 \begin_inset Quotes srd
14492 \begin_inset Quotes sld
14501 \begin_inset Quotes srd
14511 \begin_inset Quotes sld
14514 from within an interrupt routine might get lost if the interrupt occurs
14517 \begin_inset Quotes sld
14522 counter\InsetSpace ~
14527 \begin_inset Quotes srd
14530 is not atomic on the 8051 even if
14534 is located in data memory.
14536 Bugs like these are hard to reproduce and can
14537 cause a lot of trouble.
14541 \begin_layout Subsubsection
14542 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
14546 Common interrupt pitfall:
14551 \begin_layout Standard
14552 The return address and the registers used in the interrupt service routine
14553 are saved on the stack
14554 \begin_inset LatexCommand \index{stack}
14558 so there must be sufficient stack space.
14559 If there isn't variables or registers (or even the return address itself)
14566 \begin_inset LatexCommand \index{stack overflow}
14570 is most likely to happen if the interrupt occurs during the
14571 \begin_inset Quotes sld
14575 \begin_inset Quotes srd
14578 subroutine when the stack is already in use for f.e.
14579 many return addresses.
14582 \begin_layout Subsubsection
14583 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
14587 Common interrupt pitfall:
14589 use of non-reentrant functions
14592 \begin_layout Standard
14593 A special note here, int (16 bit) and long (32 bit) integer division
14594 \begin_inset LatexCommand \index{Division}
14599 \begin_inset LatexCommand \index{Multiplication}
14604 \begin_inset LatexCommand \index{Modulus}
14609 \begin_inset LatexCommand \index{Floating point support}
14613 operations are implemented using external support routines.
14614 If an interrupt service routine needs to do any of these operations then
14615 the support routines (as mentioned in a following section) will have to
14616 be recompiled using the
14622 \begin_layout Standard
14632 \begin_inset LatexCommand \index{-\/-stack-auto}
14638 option and the source file will need to be compiled using the
14644 \begin_layout Standard
14656 \begin_inset LatexCommand \index{-\/-int-long-reent}
14663 Note, the type promotion
14664 \begin_inset LatexCommand \index{type promotion}
14668 required by ANSI C can cause 16 bit routines to be used
14669 \begin_inset Marginal
14672 \begin_layout Standard
14681 without the programmer being aware of it.
14685 (unsigned char)(tail-1)
14687 within the if clause in section
14688 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
14695 \begin_layout Standard
14696 Calling other functions from an interrupt service routine is not recommended,
14697 avoid it if possible.
14698 Note that when some function is called from an interrupt service routine
14699 it should be preceded by a #pragma\InsetSpace ~
14701 \begin_inset LatexCommand \index{\#pragma nooverlay}
14705 if it is not reentrant.
14706 Furthermore nonreentrant functions should not be called from the main program
14707 while the interrupt service routine might be active.
14708 They also must not be called from low priority interrupt service routines
14709 while a high priority interrupt service routine might be active.
14710 You could use semaphores or make the function
14714 if all parameters are passed in registers.
14717 \begin_inset LatexCommand \ref{sub:Overlaying}
14722 about Overlaying and section
14723 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14728 about Functions using private register banks.
14729 \begin_inset VSpace bigskip
14735 \begin_layout Subsection
14736 MCS51/DS390 Interrupt Service Routines
14739 \begin_layout Standard
14741 \begin_inset LatexCommand \index{interrupt}
14745 numbers and the corresponding address & descriptions for the Standard 8051/8052
14747 SDCC will automatically adjust the
14748 \begin_inset LatexCommand \index{interrupt vector table}
14752 to the maximum interrupt number specified.
14757 \begin_layout Standard
14759 \begin_inset Tabular
14760 <lyxtabular version="3" rows="9" columns="3">
14762 <column alignment="center" valignment="top" leftline="true" width="0in">
14763 <column alignment="left" valignment="top" leftline="true" width="0in">
14764 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14765 <row topline="true" bottomline="true">
14766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14769 \begin_layout Standard
14775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14778 \begin_layout Standard
14784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14787 \begin_layout Standard
14794 <row topline="true">
14795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14798 \begin_layout Standard
14804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14807 \begin_layout Standard
14813 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14816 \begin_layout Standard
14823 <row topline="true">
14824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14827 \begin_layout Standard
14833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14836 \begin_layout Standard
14842 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14845 \begin_layout Standard
14852 <row topline="true">
14853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14856 \begin_layout Standard
14862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14865 \begin_layout Standard
14871 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14874 \begin_layout Standard
14881 <row topline="true">
14882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14885 \begin_layout Standard
14891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14894 \begin_layout Standard
14900 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14903 \begin_layout Standard
14910 <row topline="true">
14911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14914 \begin_layout Standard
14920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14923 \begin_layout Standard
14929 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14932 \begin_layout Standard
14939 <row topline="true">
14940 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14943 \begin_layout Standard
14949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14952 \begin_layout Standard
14958 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14961 \begin_layout Standard
14968 <row topline="true">
14969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14972 \begin_layout Standard
14978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14981 \begin_layout Standard
14987 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14990 \begin_layout Standard
14997 <row topline="true" bottomline="true">
14998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15001 \begin_layout Standard
15007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15010 \begin_layout Standard
15016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15019 \begin_layout Standard
15035 \begin_layout Standard
15036 If the interrupt service routine is defined without
15039 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
15044 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
15050 a register bank or with register bank 0 (
15054 0), the compiler will save the registers used by itself on the stack upon
15055 entry and restore them at exit, however if such an interrupt service routine
15056 calls another function then the entire register bank will be saved on the
15058 This scheme may be advantageous for small interrupt service routines which
15059 have low register usage.
15062 \begin_layout Standard
15063 If the interrupt service routine is defined to be using a specific register
15068 & psw are saved and restored, if such an interrupt service routine calls
15069 another function (using another register bank) then the entire register
15070 bank of the called function will be saved on the stack
15071 \begin_inset LatexCommand \index{stack}
15076 This scheme is recommended for larger interrupt service routines.
15077 \begin_inset VSpace bigskip
15083 \begin_layout Subsection
15085 \begin_inset LatexCommand \index{HC08}
15089 Interrupt Service Routines
15092 \begin_layout Standard
15093 Since the number of interrupts
15094 \begin_inset LatexCommand \index{HC08!interrupt}
15098 available is chip specific and the interrupt vector table always ends at
15099 the last byte of memory, the interrupt numbers corresponds to the interrupt
15100 vectors in reverse order of address.
15101 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
15102 2 will use the interrupt vector at 0xfffa, and so on.
15103 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
15104 this way; instead see section
15105 \begin_inset LatexCommand \ref{sub:Startup-Code}
15109 for details on customizing startup.
15110 \begin_inset VSpace bigskip
15116 \begin_layout Subsection
15117 Z80 Interrupt Service Routines
15120 \begin_layout Standard
15122 \begin_inset LatexCommand \index{Z80}
15126 uses several different methods for determining the correct interrupt
15127 \begin_inset LatexCommand \index{Z80!interrupt}
15131 vector depending on the hardware implementation.
15132 Therefore, SDCC ignores the optional interrupt number and does not attempt
15133 to generate an interrupt vector table.
15136 \begin_layout Standard
15137 By default, SDCC generates code for a maskable interrupt, which uses a RETI
15138 instruction to return from the interrupt.
15139 To write an interrupt handler for the non-maskable interrupt, which needs
15140 a RETN instruction instead, add the
15147 \begin_layout Verse
15150 void nmi_isr (void) critical interrupt
15164 \begin_layout Standard
15165 However if you need to create a non-interruptable interrupt service routine
15166 you would also require the
15171 To distinguish between this and an nmi_isr you must provide an interrupt
15173 \begin_inset VSpace bigskip
15179 \begin_layout Section
15180 Enabling and Disabling Interrupts
15183 \begin_layout Subsection
15184 Critical Functions and Critical Statements
15187 \begin_layout Standard
15188 A special keyword may be associated with a block or a function declaring
15194 SDCC will generate code to disable all interrupts
15195 \begin_inset LatexCommand \index{interrupt}
15199 upon entry to a critical function and restore the interrupt enable to the
15200 previous state before returning.
15201 Nesting critical functions will need one additional byte on the stack
15202 \begin_inset LatexCommand \index{stack}
15209 \begin_layout Verse
15212 int foo () __critical
15213 \begin_inset LatexCommand \index{critical}
15218 \begin_inset LatexCommand \index{\_\_critical}
15243 \begin_layout Standard
15244 The critical attribute maybe used with other attributes like
15254 may also be used to disable interrupts more locally:
15257 \begin_layout Verse
15263 \begin_layout Standard
15264 More than one statement could have been included in the block.
15267 \begin_layout Subsection
15268 Enabling and Disabling Interrupts directly
15271 \begin_layout Standard
15273 \begin_inset LatexCommand \index{interrupt}
15277 can also be disabled and enabled directly (8051):
15280 \begin_layout Verse
15283 EA = 0;\InsetSpace ~
15309 \begin_layout Verse
15345 \begin_layout Verse
15348 EA = 1;\InsetSpace ~
15377 \begin_layout Verse
15416 \begin_layout Standard
15417 On other architectures which have seperate opcodes for enabling and disabling
15418 interrupts you might want to make use of defines with inline assembly
15419 \begin_inset LatexCommand \index{Assembler routines}
15424 \begin_inset LatexCommand \index{HC08!interrupt}
15431 \begin_layout Verse
15435 \begin_inset LatexCommand \index{\_asm}
15444 \begin_inset LatexCommand \index{\_endasm}
15451 \begin_layout Verse
15454 #define SEI _asm\InsetSpace ~
15461 \begin_layout Verse
15467 \begin_layout Standard
15468 Note: it is sometimes sufficient to disable only a specific interrupt source
15470 a timer or serial interrupt by manipulating an
15473 \begin_inset LatexCommand \index{interrupt mask}
15483 \begin_layout Standard
15484 Usually the time during which interrupts are disabled should be kept as
15486 This minimizes both
15491 \begin_inset LatexCommand \index{interrupt latency}
15495 (the time between the occurrence of the interrupt and the execution of
15496 the first code in the interrupt routine) and
15501 \begin_inset LatexCommand \index{interrupt jitter}
15505 (the difference between the shortest and the longest interrupt latency).
15506 These really are something different, f.e.
15507 a serial interrupt has to be served before its buffer overruns so it cares
15508 for the maximum interrupt latency, whereas it does not care about jitter.
15509 On a loudspeaker driven via a digital to analog converter which is fed
15510 by an interrupt a latency of a few milliseconds might be tolerable, whereas
15511 a much smaller jitter will be very audible.
15514 \begin_layout Standard
15515 You can reenable interrupts within an interrupt routine and on some architecture
15516 s you can make use of two (or more) levels of
15518 interrupt priorities
15521 \begin_inset LatexCommand \index{interrupt priority}
15526 On some architectures which don't support interrupt priorities these can
15527 be implemented by manipulating the interrupt mask and reenabling interrupts
15528 within the interrupt routine.
15529 Check there is sufficient space on the stack
15530 \begin_inset LatexCommand \index{stack}
15534 and don't add complexity unless you have to.
15538 \begin_layout Subsection
15540 \begin_inset LatexCommand \index{semaphore}
15544 locking (mcs51/ds390)
15547 \begin_layout Standard
15548 Some architectures (mcs51/ds390) have an atomic
15549 \begin_inset LatexCommand \index{atomic}
15562 These type of instructions are typically used in preemptive multitasking
15563 systems, where a routine f.e.
15564 claims the use of a data structure ('acquires a lock
15565 \begin_inset LatexCommand \index{lock}
15569 on it'), makes some modifications and then releases the lock when the data
15570 structure is consistent again.
15571 The instruction may also be used if interrupt and non-interrupt code have
15572 to compete for a resource.
15573 With the atomic bit test and clear instruction interrupts
15574 \begin_inset LatexCommand \index{interrupt}
15578 don't have to be disabled for the locking operation.
15582 \begin_layout Standard
15583 SDCC generates this instruction if the source follows this pattern:
15586 \begin_layout Verse
15590 \begin_inset LatexCommand \index{volatile}
15594 bit resource_is_free;
15598 if (resource_is_free)
15608 resource_is_free=0;
15621 resource_is_free=1;
15628 \begin_layout Standard
15629 Note, mcs51 and ds390 support only an atomic
15630 \begin_inset LatexCommand \index{atomic}
15638 instruction (as opposed to atomic bit test and
15643 \begin_layout Section
15644 Functions using private register banks
15645 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
15652 \begin_layout Standard
15653 Some architectures have support for quickly changing register sets.
15654 SDCC supports this feature with the
15657 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
15662 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
15668 attribute (which tells the compiler to use a register bank
15669 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
15673 other than the default bank zero).
15674 It should only be applied to
15677 \begin_inset LatexCommand \index{interrupt}
15683 functions (see footnote below).
15684 This will in most circumstances make the generated ISR code more efficient
15685 since it will not have to save registers on the stack.
15688 \begin_layout Standard
15693 attribute will have no effect on the generated code for a
15697 function (but may occasionally be useful anyway
15701 \begin_layout Standard
15702 possible exception: if a function is called ONLY from 'interrupt' functions
15703 using a particular bank, it can be declared with the same 'using' attribute
15704 as the calling 'interrupt' functions.
15705 For instance, if you have several ISRs using bank one, and all of them
15706 call memcpy(), it might make sense to create a specialized version of memcpy()
15707 'using 1', since this would prevent the ISR from having to save bank zero
15708 to the stack on entry and switch to bank zero before calling the function
15717 (pending: Note, nowadays the
15721 attribute has an effect on
15725 the generated code for a
15736 \begin_layout Standard
15741 function using a non-zero bank will assume that it can trash that register
15742 bank, and will not save it.
15743 Since high-priority interrupts
15744 \begin_inset LatexCommand \index{interrupts}
15749 \begin_inset LatexCommand \index{interrupt priority}
15753 can interrupt low-priority ones on the 8051 and friends, this means that
15754 if a high-priority ISR
15758 a particular bank occurs while processing a low-priority ISR
15762 the same bank, terrible and bad things can happen.
15763 To prevent this, no single register bank should be
15767 by both a high priority and a low priority ISR.
15768 This is probably most easily done by having all high priority ISRs use
15769 one bank and all low priority ISRs use another.
15770 If you have an ISR which can change priority at runtime, you're on your
15771 own: I suggest using the default bank zero and taking the small performance
15775 \begin_layout Standard
15776 It is most efficient if your ISR calls no other functions.
15777 If your ISR must call other functions, it is most efficient if those functions
15778 use the same bank as the ISR (see note 1 below); the next best is if the
15779 called functions use bank zero.
15780 It is very inefficient to call a function using a different, non-zero bank
15783 \begin_inset VSpace bigskip
15789 \begin_layout Section
15791 \begin_inset LatexCommand \label{sub:Startup-Code}
15796 \begin_inset LatexCommand \index{Startup code}
15803 \begin_layout Subsection
15804 MCS51/DS390 Startup Code
15807 \begin_layout Standard
15808 The compiler triggers the linker to link certain initialization modules
15809 from the runtime library
15810 \begin_inset LatexCommand \index{Runtime library}
15814 called crt<something>.
15815 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15816 GSINIT5) is not linked unless the -
15822 \begin_layout Standard
15833 -xstack option is used.
15834 These modules are highly entangled by the use of special segments/areas,
15835 but a common layout is shown below:
15838 \begin_layout Verse
15846 \begin_layout Verse
15870 ljmp __sdcc_gsinit_startup
15873 \begin_layout Verse
15881 \begin_layout Verse
15893 .area GSINIT0 (CODE)
15895 __sdcc_gsinit_startup::
15905 mov sp,#__start__stack - 1
15908 \begin_layout Verse
15916 \begin_layout Verse
15928 .area GSINIT1 (CODE)
15930 __sdcc_init_xstack::
15932 ; Need to initialize in GSINIT1 in
15933 case the user's __sdcc_external_startup uses the xstack.
15943 mov __XPAGE,#(__start__x
15954 mov _spx,#__start__xstack
15957 \begin_layout Verse
15965 \begin_layout Verse
15977 .area GSINIT2 (CODE)
15987 lcall __sdcc_external_startup
16007 jz __sdcc_init_data
16018 __sdcc_program_startup
16023 \begin_layout Verse
16031 \begin_layout Verse
16043 .area GSINIT3 (CODE)
16096 mov r2,#((l_XINIT+255) >> 8)
16127 __XPAGE,#(s_XISEG >> 8)
16129 00001$:\InsetSpace ~
16193 00002$:\InsetSpace ~
16220 \begin_layout Verse
16228 \begin_layout Verse
16240 .area GSINIT4 (CODE)
16242 __mcs51_genRAMCLEAR::
16264 00004$:\InsetSpace ~
16278 ; _mcs51_genRAMCLEAR() end
16281 \begin_layout Verse
16289 \begin_layout Verse
16301 .area GSINIT4 (CODE)
16303 __mcs51_genXRAMCLEAR::
16364 mov __XPAGE,#(s_PSEG >> 8)
16376 00005$:\InsetSpace ~
16451 mov r1,#((l_XSEG + 255) >> 8)
16473 00007$:\InsetSpace ~
16510 \begin_layout Verse
16518 \begin_layout Verse
16530 .area GSINIT5 (CODE)
16532 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
16535 ; and __mcs51_genRAMCLEAR modifies _spx.
16545 mov __XPAGE,#(__start__x
16556 mov _spx,#__start__xstack
16559 \begin_layout Verse
16564 (application modules)
16567 \begin_layout Verse
16579 .area GSINIT (CODE)
16582 \begin_layout Verse
16590 \begin_layout Verse
16602 .area GSFINAL (CODE)
16612 ljmp __sdcc_program_startup
16614 ;---------------------------------
16615 -----------------------
16619 ;--------------------------------------------------
16642 __sdcc_program_startup:
16655 return from main will lock up
16668 \begin_layout Standard
16669 One of these modules (crtstart.asm) contains a call to the C routine
16671 _sdcc_external_startup()
16672 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
16681 at the start of the CODE area.
16682 This routine is also in the runtime library
16683 \begin_inset LatexCommand \index{Runtime library}
16687 and returns 0 by default.
16688 If this routine returns a non-zero value, the static & global variable
16689 initialization will be skipped and the function main will be invoked.
16690 Otherwise static & global variables will be initialized before the function
16694 _sdcc_external_startup()
16696 routine to your program to override the default if you need to setup hardware
16697 or perform some other critical operation prior to static & global variable
16699 \begin_inset LatexCommand \index{Variable initialization}
16704 On some mcs51 variants xdata
16705 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
16709 memory has to be explicitly enabled before it can be accessed or if the
16711 \begin_inset LatexCommand \index{watchdog}
16715 needs to be disabled, this is the place to do it.
16716 The startup code clears all internal data memory, 256 bytes by default,
16717 but from 0 to n-1 if
16723 \begin_layout Standard
16733 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16740 (recommended for Chipcon CC1010).
16743 \begin_layout Standard
16744 See also the compiler options
16750 \begin_layout Standard
16766 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16776 \begin_layout Standard
16788 \begin_inset LatexCommand \index{-\/-main-return}
16793 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16797 about MCS51-variants.
16802 \begin_layout Standard
16803 While these initialization modules are meant as generic startup code there
16804 might be the need for customization.
16805 Let's assume the return value of
16807 _sdcc_external_startup()
16813 should not be checked (or
16815 _sdcc_external_startup()
16817 should not be called at all).
16818 The recommended way would be to copy
16824 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm}
16828 ) into the source directory, adapt it there, then assemble it with
16834 \begin_layout Standard
16835 \begin_inset Quotes sld
16839 \begin_inset Quotes srd
16842 are the assembler options used in
16843 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup }
16854 and when linking your project explicitely specify
16859 As a bonus a listing of the relocated object file
16866 \begin_layout Standard
16867 \begin_inset VSpace bigskip
16873 \begin_layout Subsection
16877 \begin_layout Standard
16879 \begin_inset LatexCommand \index{HC08}
16883 startup code follows the same scheme as the MCS51 startup code.
16884 \begin_inset VSpace bigskip
16890 \begin_layout Subsection
16894 \begin_layout Standard
16896 \begin_inset LatexCommand \index{Z80}
16900 the startup code is inserted by linking with crt0.o which is generated from
16901 sdcc/device/lib/z80/crt0.s.
16902 If you need a different startup code you can use the compiler option
16911 \begin_layout Standard
16926 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16930 and provide your own crt0.o.
16932 \begin_inset VSpace bigskip
16938 \begin_layout Section
16939 Inline Assembler Code
16940 \begin_inset LatexCommand \index{Assembler routines}
16947 \begin_layout Subsection
16948 A Step by Step Introduction
16949 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16956 \begin_layout Standard
16957 Starting from a small snippet of c-code this example shows for the MCS51
16958 how to use inline assembly, access variables, a function parameter and
16959 an array in xdata memory.
16960 The example uses an MCS51 here but is easily adapted for other architectures.
16961 This is a buffer routine which should be optimized:
16964 \begin_layout Verse
16968 unsigned char __far
16969 \begin_inset LatexCommand \index{far (storage class)}
16974 \begin_inset LatexCommand \index{\_\_far (storage class)}
16979 \begin_inset LatexCommand \index{at}
16984 \begin_inset LatexCommand \index{\_\_at}
16988 (0x7f00) buf[0x100];
16989 \begin_inset LatexCommand \index{Aligned array}
16995 unsigned char head, tail;\InsetSpace ~
17013 \begin_inset LatexCommand \index{interrupt}
17065 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
17077 void to_buffer( unsigned char c )
17085 if( head != (unsigned char)(tail-1)
17092 \begin_inset LatexCommand \index{promotion to signed int}
17097 \begin_inset LatexCommand \index{type promotion}
17102 \begin_inset Marginal
17105 \begin_layout Standard
17124 buf[ head++ ] = c;\InsetSpace ~
17140 /* access to a 256 byte aligned array */
17145 \begin_layout Standard
17146 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
17147 then a corresponding buffer.asm file is generated.
17148 We define a new function
17152 in file buffer.c in which we cut and paste the generated code, removing
17153 unwanted comments and some ':'.
17155 \begin_inset Quotes sld
17163 \begin_inset Quotes srd
17167 \begin_inset Quotes sld
17175 \begin_inset Quotes srd
17182 \begin_layout Standard
17183 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
17184 and for C-99 compatibility, the double-underscore form (__asm and __endasm)
17186 The latter is also used in the library functions.
17191 to the beginning and the end of the function body:
17194 \begin_layout Verse
17198 /* With a cut and paste from the .asm file, we have something to start with.
17204 function is not yet OK! (registers aren't saved) */
17206 void to_buffer_asm(
17216 \begin_inset LatexCommand \index{\_asm}
17221 \begin_inset LatexCommand \index{\_\_asm}
17235 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
17241 \begin_inset LatexCommand \index{promotion to signed int}
17246 \begin_inset LatexCommand \index{type promotion}
17299 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
17300 \begin_inset LatexCommand \index{Aligned array}
17366 \begin_inset LatexCommand \index{\_endasm}
17371 \begin_inset LatexCommand \index{\_\_endasm}
17380 \begin_layout Standard
17381 The new file buffer.c should compile with only one warning about the unreferenced
17382 function argument 'c'.
17383 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
17384 (1) and finally have:
17387 \begin_layout Verse
17391 unsigned char __far __at(0x7f00) buf[0x100];
17393 unsigned char head, tail;
17404 void to_buffer( unsigned char c )
17413 head != (unsigned char)(tail-1) )
17442 c; // to avoid warning: unreferenced function argument
17449 \begin_inset LatexCommand \index{\_asm}
17454 \begin_inset LatexCommand \index{\_\_asm}
17468 ; save used registers here.
17479 ; If we were still using r2,r3 we would have to push them here.
17482 ; if( head != (unsigned char)(tail-1) )
17526 could do an ANL a,#0x0f here to use a smaller buffer (see below)
17562 a,dpl \InsetSpace ~
17569 ; dpl holds lower byte of function argument
17581 dpl,_head \InsetSpace ~
17584 ; buf is 0x100 byte aligned so head can be used directly
17627 ; we could do an ANL _head,#0x0f here to use a
17628 smaller buffer (see above)
17640 ; restore used registers here
17647 \begin_inset LatexCommand \index{\_endasm}
17652 \begin_inset LatexCommand \index{\_\_endasm}
17663 \begin_layout Standard
17664 The inline assembler code can contain any valid code understood by the assembler
17665 , this includes any assembler directives and comment lines.
17666 The assembler does not like some characters like ':' or ''' in comments.
17667 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
17668 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
17673 \begin_inset LatexCommand \index{Assembler documentation}
17678 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
17686 \begin_layout Standard
17687 The compiler does not do any validation of the code within the
17690 \begin_inset LatexCommand \index{\_asm}
17695 \begin_inset LatexCommand \index{\_\_asm}
17703 \begin_inset LatexCommand \index{\_endasm}
17708 \begin_inset LatexCommand \index{\_\_endasm}
17717 Specifically it will not know which registers are used and thus register
17719 \begin_inset LatexCommand \index{push/pop}
17723 has to be done manually.
17727 \begin_layout Standard
17728 It is recommended that each assembly instruction (including labels) be placed
17729 in a separate line (as the example shows).
17734 \begin_layout Standard
17746 \begin_inset LatexCommand \index{-\/-peep-asm}
17752 command line option is used, the inline assembler code will be passed through
17753 the peephole optimizer
17754 \begin_inset LatexCommand \index{Peephole optimizer}
17759 There are only a few (if any) cases where this option makes sense, it might
17760 cause some unexpected changes in the inline assembler code.
17761 Please go through the peephole optimizer rules defined in file
17765 before using this option.
17768 \begin_layout Subsection
17770 \begin_inset LatexCommand \label{sub:Naked-Functions}
17775 \begin_inset LatexCommand \index{Naked functions}
17782 \begin_layout Standard
17783 A special keyword may be associated with a function declaring it as
17786 \begin_inset LatexCommand \index{\_naked}
17791 \begin_inset LatexCommand \index{\_\_naked}
17802 function modifier attribute prevents the compiler from generating prologue
17803 \begin_inset LatexCommand \index{function prologue}
17808 \begin_inset LatexCommand \index{function epilogue}
17812 code for that function.
17813 This means that the user is entirely responsible for such things as saving
17814 any registers that may need to be preserved, selecting the proper register
17815 bank, generating the
17819 instruction at the end, etc.
17820 Practically, this means that the contents of the function must be written
17821 in inline assembler.
17822 This is particularly useful for interrupt functions, which can have a large
17823 (and often unnecessary) prologue/epilogue.
17824 For example, compare the code generated by these two functions:
17827 \begin_layout Verse
17831 \begin_inset LatexCommand \index{volatile}
17835 data unsigned char counter;
17839 void simpleInterrupt(void) __interrupt
17840 \begin_inset LatexCommand \index{interrupt}
17845 \begin_inset LatexCommand \index{\_\_interrupt}
17863 void nakedInterrupt(void) __interrupt (2) __naked
17872 \begin_inset LatexCommand \index{\_asm}
17877 \begin_inset LatexCommand \index{\_\_asm}
17894 _counter ; does not change flags, no need to save psw
17907 include ret or reti in _naked function.
17914 \begin_inset LatexCommand \index{\_endasm}
17919 \begin_inset LatexCommand \index{\_\_endasm}
17928 \begin_layout Standard
17929 For an 8051 target, the generated simpleInterrupt looks like:
17932 \begin_layout Verse
17939 example, recent versions of SDCC generate
17945 code for simpleInterrupt() and nakedInterrupt()!
18086 \begin_layout Standard
18087 whereas nakedInterrupt looks like:
18090 \begin_layout Verse
18103 _counter ; does not change flags, no need to save psw
18122 MUST explicitly include ret or reti in _naked function
18125 \begin_layout Standard
18126 The related directive #pragma exclude
18127 \begin_inset LatexCommand \index{\#pragma exclude}
18131 allows a more fine grained control over pushing & popping
18132 \begin_inset LatexCommand \index{push/pop}
18139 \begin_layout Standard
18140 While there is nothing preventing you from writing C code inside a
18144 function, there are many ways to shoot yourself in the foot doing this,
18145 and it is recommended that you stick to inline assembler.
18148 \begin_layout Subsection
18149 Use of Labels within Inline Assembler
18152 \begin_layout Standard
18153 SDCC allows the use of in-line assembler with a few restrictions regarding
18155 All labels defined within inline assembler code have to be of the form
18160 where nnnnn is a number less than 100 (which implies a limit of utmost
18161 100 inline assembler labels
18172 \begin_layout Standard
18173 This is a slightly more stringent rule than absolutely necessary, but stays
18174 always on the safe side.
18175 Labels in the form of nnnnn$ are local labels in the assembler, locality
18176 of which is confined within two labels of the standard form.
18177 The compiler uses the same form for labels within a function (but starting
18178 from nnnnn=00100); and places always a standard label at the beginning
18179 of a function, thus limiting the locality of labels within the scope of
18181 So, if the inline assembler part would be embedded into C-code, an improperly
18182 placed non-local label in the assembler would break up the reference space
18183 for labels created by the compiler for the C-code, leading to an assembling
18187 \begin_layout Standard
18188 The numeric part of local labels does not need to have 5 digits (although
18189 this is the form of labels output by the compiler), any valid integer will
18191 Please refer to the assemblers documentation for further details.
18199 \begin_layout Verse
18203 \begin_inset LatexCommand \index{\_asm}
18208 \begin_inset LatexCommand \index{\_\_asm}
18238 \begin_inset LatexCommand \index{\_endasm}
18243 \begin_inset LatexCommand \index{\_\_endasm}
18250 \begin_layout Standard
18251 Inline assembler code cannot reference any C-labels, however it can reference
18253 \begin_inset LatexCommand \index{Labels}
18257 defined by the inline assembler, e.g.:
18260 \begin_layout Verse
18283 ; some assembler code
18304 /* some more c code */
18306 clabel:\InsetSpace ~
18308 /* inline assembler cannot reference this
18313 \begin_layout Standard
18318 is translated by the compiler into a local label, so the locality of labels
18319 within the function is not broken.
18336 0003$: ;label (can be referenced by inline assembler only)
18343 \begin_inset LatexCommand \index{\_endasm}
18348 \begin_inset LatexCommand \index{\_\_endasm}
18358 /* some more c code */
18363 \begin_layout Standard
18364 In other words inline assembly code can access labels defined in inline
18365 assembly within the scope of the function.
18366 The same goes the other way, i.e.
18367 labels defines in inline assembly can not be accessed by C statements.
18370 \begin_layout Section
18371 Interfacing with Assembler Code
18372 \begin_inset LatexCommand \index{Assembler routines}
18379 \begin_layout Subsection
18380 Global Registers used for Parameter Passing
18381 \begin_inset LatexCommand \index{Parameter passing}
18388 \begin_layout Standard
18389 The compiler always uses the global registers
18392 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18397 \begin_inset LatexCommand \index{DPTR}
18402 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
18411 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
18417 to pass the first (non-bit) parameter to a function, and also to pass the
18419 \begin_inset LatexCommand \index{return value}
18423 of function; according to the following scheme: one byte return value in
18428 , two byte value in
18437 three byte values (generic pointers) in
18449 , and four byte values in
18467 \begin_inset LatexCommand \index{generic pointer}
18471 contain type of accessed memory in
18492 \begin_inset Note Note
18495 \begin_layout Standard
18496 This might not be the case of certain memory models (medium???)
18504 \begin_layout Standard
18505 The second parameter onwards is either allocated on the stack (for reentrant
18510 \begin_layout Standard
18519 -stack-auto is used) or in data/xdata memory (depending on the memory model).
18522 \begin_layout Standard
18523 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
18524 space for reentrant functions or allocated directly in bit memory otherwise.
18527 \begin_layout Standard
18528 Functions (with two or more parameters or bit parameters) that are called
18529 through function pointers
18530 \begin_inset LatexCommand \index{function pointers}
18534 must therefor be reentrant so the compiler knows how to pass the parameters.
18537 \begin_layout Subsection
18541 \begin_layout Standard
18542 Unless the called function is declared as
18547 \begin_inset LatexCommand \index{naked}
18555 \begin_layout Standard
18565 \begin_inset LatexCommand \index{-\/-callee-saves}
18573 \begin_layout Standard
18582 -all-callee-saves command line option or the corresponding callee_saves
18583 pragma are used, the caller will save the registers (
18587 ) around the call, so the called function can destroy they content freely.
18590 \begin_layout Standard
18591 If the called function is not declared as
18595 , the caller will swap register banks around the call, if caller and callee
18596 use different register banks (having them defined by the
18604 \begin_layout Standard
18605 The called function can also use
18621 observing that they are used for parameter/return value passing.
18624 \begin_layout Subsection
18625 Assembler Routine (non-reentrant)
18628 \begin_layout Standard
18629 In the following example
18630 \begin_inset LatexCommand \index{reentrant}
18635 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
18639 the function c_func calls an assembler routine asm_func, which takes two
18641 \begin_inset LatexCommand \index{function parameter}
18648 \begin_layout Verse
18651 extern int asm_func(unsigned char, unsigned char);
18655 int c_func (unsigned char
18656 i, unsigned char j)
18664 return asm_func(i,j);
18678 return c_func(10,9);
18683 \begin_layout Standard
18684 The corresponding assembler function is:
18687 \begin_layout Verse
18690 .globl _asm_func_PARM_2
18792 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18809 \begin_layout Standard
18810 The parameter naming convention is _<function_name>_PARM_<n>, where n is
18811 the parameter number starting from 1, and counting from the left.
18812 The first parameter is passed in
18828 according to the description above.
18829 The variable name for the second parameter will be _<function_name>_PARM_2.
18834 ble the assembler routine with the following command:
18841 asx8051 -losg asmfunc.asm
18848 Then compile and link the assembler routine to the C source file with the
18856 sdcc cfunc.c asmfunc.rel
18859 \begin_layout Subsection
18860 Assembler Routine (reentrant)
18863 \begin_layout Standard
18865 \begin_inset LatexCommand \index{reentrant}
18870 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18874 the second parameter
18875 \begin_inset LatexCommand \index{function parameter}
18879 onwards will be passed on the stack, the parameters are pushed from right
18881 before the call the second leftmost parameter will be on the top of the
18882 stack (the leftmost parameter is passed in registers).
18883 Here is an example:
18886 \begin_layout Verse
18889 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18894 c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
18903 return asm_func(i,j,k);
18917 return c_func(10,9,8);
18922 \begin_layout Standard
18923 The corresponding (unoptimized) assembler routine is:
18926 \begin_layout Verse
18946 _bp,sp\InsetSpace ~
18952 ;stack contains: _bp, return
18953 address, second parameter, third parameter
18977 a,#0xfd\InsetSpace ~
18983 pointer to the second parameter
19007 a,#0xfc\InsetSpace ~
19013 to the rightmost parameter
19054 result (= sum of all three parameters)
19069 ;return value goes into dptr
19103 \begin_layout Standard
19104 The compiling and linking procedure remains the same, however note the extra
19105 entry & exit linkage required for the assembler code, _bp is the stack
19106 frame pointer and is used to compute the offset into the stack for parameters
19107 and local variables.
19108 \begin_inset VSpace bigskip
19114 \begin_layout Section
19116 \begin_inset LatexCommand \index{int (16 bit)}
19121 \begin_inset LatexCommand \index{long (32 bit)}
19128 \begin_layout Standard
19129 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
19130 multiplication and modulus operations are implemented by support routines.
19131 These support routines are all developed in ANSI-C to facilitate porting
19132 to other MCUs, although some model specific assembler optimizations are
19134 The following files contain the described routines, all of them can be
19135 found in <installdir>/share/sdcc/lib.
19140 \begin_layout Standard
19142 \begin_inset Tabular
19143 <lyxtabular version="3" rows="11" columns="2">
19145 <column alignment="left" valignment="top" leftline="true" width="0">
19146 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19147 <row topline="true" bottomline="true">
19148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19151 \begin_layout Standard
19159 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19162 \begin_layout Standard
19171 <row topline="true">
19172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19175 \begin_layout Standard
19181 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19184 \begin_layout Standard
19185 16 bit multiplication
19191 <row topline="true">
19192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19195 \begin_layout Standard
19201 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19204 \begin_layout Standard
19205 signed 16 bit division (calls _divuint)
19211 <row topline="true">
19212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19215 \begin_layout Standard
19221 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19224 \begin_layout Standard
19225 unsigned 16 bit division
19231 <row topline="true">
19232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19235 \begin_layout Standard
19241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19244 \begin_layout Standard
19245 signed 16 bit modulus (calls _moduint)
19251 <row topline="true">
19252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19255 \begin_layout Standard
19261 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19264 \begin_layout Standard
19265 unsigned 16 bit modulus
19271 <row topline="true">
19272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19275 \begin_layout Standard
19281 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19284 \begin_layout Standard
19285 32 bit multiplication
19291 <row topline="true">
19292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19295 \begin_layout Standard
19301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19304 \begin_layout Standard
19305 signed 32 division (calls _divulong)
19311 <row topline="true">
19312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19315 \begin_layout Standard
19321 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19324 \begin_layout Standard
19325 unsigned 32 division
19331 <row topline="true">
19332 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19335 \begin_layout Standard
19341 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19344 \begin_layout Standard
19345 signed 32 bit modulus (calls _modulong)
19351 <row topline="true" bottomline="true">
19352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19355 \begin_layout Standard
19361 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19364 \begin_layout Standard
19365 unsigned 32 bit modulus
19380 \begin_layout Standard
19381 Since they are compiled as
19386 \begin_inset LatexCommand \index{reentrant}
19391 \begin_inset LatexCommand \index{interrupt}
19395 service routines should not do any of the above operations.
19396 If this is unavoidable then the above routines will need to be compiled
19403 \begin_layout Standard
19413 \begin_inset LatexCommand \index{-\/-stack-auto}
19419 option, after which the source program will have to be compiled with
19425 \begin_layout Standard
19435 \begin_inset LatexCommand \index{-\/-int-long-reent}
19442 Notice that you don't have to call these routines directly.
19443 The compiler will use them automatically every time an integer operation
19447 \begin_layout Section
19448 Floating Point Support
19449 \begin_inset LatexCommand \index{Floating point support}
19456 \begin_layout Standard
19457 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
19458 The floating point support routines are derived from gcc's floatlib.c and
19459 consist of the following routines:
19464 \begin_layout Standard
19468 \begin_inset Tabular
19469 <lyxtabular version="3" rows="17" columns="2">
19471 <column alignment="left" valignment="top" leftline="true" width="0">
19472 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19473 <row topline="true" bottomline="true">
19474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19477 \begin_layout Standard
19492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19495 \begin_layout Standard
19502 <row topline="true">
19503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19506 \begin_layout Standard
19521 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19524 \begin_layout Standard
19534 add floating point numbers
19540 <row topline="true">
19541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19544 \begin_layout Standard
19559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19562 \begin_layout Standard
19572 subtract floating point numbers
19578 <row topline="true">
19579 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19582 \begin_layout Standard
19597 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19600 \begin_layout Standard
19610 divide floating point numbers
19616 <row topline="true">
19617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19620 \begin_layout Standard
19635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19638 \begin_layout Standard
19648 multiply floating point numbers
19654 <row topline="true">
19655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19658 \begin_layout Standard
19673 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19676 \begin_layout Standard
19686 convert floating point to unsigned char
19692 <row topline="true">
19693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19696 \begin_layout Standard
19711 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19714 \begin_layout Standard
19724 convert floating point to signed char
19730 <row topline="true">
19731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19734 \begin_layout Standard
19749 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19752 \begin_layout Standard
19762 convert floating point to unsigned int
19768 <row topline="true">
19769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19772 \begin_layout Standard
19787 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19790 \begin_layout Standard
19800 convert floating point to signed int
19806 <row topline="true">
19807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19810 \begin_layout Standard
19833 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19836 \begin_layout Standard
19846 convert floating point to unsigned long
19852 <row topline="true">
19853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19856 \begin_layout Standard
19871 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19874 \begin_layout Standard
19884 convert floating point to signed long
19890 <row topline="true">
19891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19894 \begin_layout Standard
19909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19912 \begin_layout Standard
19922 convert unsigned char to floating point
19928 <row topline="true">
19929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19932 \begin_layout Standard
19947 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19950 \begin_layout Standard
19960 convert char to floating point number
19966 <row topline="true">
19967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19970 \begin_layout Standard
19985 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19988 \begin_layout Standard
19998 convert unsigned int to floating point
20004 <row topline="true">
20005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20008 \begin_layout Standard
20023 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20026 \begin_layout Standard
20036 convert int to floating point numbers
20042 <row topline="true">
20043 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20046 \begin_layout Standard
20061 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20064 \begin_layout Standard
20074 convert unsigned long to floating point number
20080 <row topline="true" bottomline="true">
20081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20084 \begin_layout Standard
20099 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20102 \begin_layout Standard
20112 convert long to floating point number
20127 \begin_layout Standard
20128 These support routines are developed in ANSI-C so there is room for space
20129 and speed improvement
20133 \begin_layout Standard
20134 These floating point routines (
20138 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
20145 Note if all these routines are used simultaneously the data space might
20147 For serious floating point usage the large model might be needed.
20148 Also notice that you don't have to call this routines directly.
20149 The compiler will use them automatically every time a floating point operation
20151 \begin_inset VSpace bigskip
20157 \begin_layout Section
20159 \begin_inset LatexCommand \index{Libraries}
20166 \begin_layout Standard
20169 <pending: this is messy and incomplete - a little more information is in
20170 sdcc/doc/libdoc.txt
20175 \begin_layout Subsection
20176 Compiler support routines (_gptrget, _mulint etc.)
20179 \begin_layout Subsection
20180 Stdclib functions (puts, printf, strcat etc.)
20183 \begin_layout Subsubsection
20187 \begin_layout Paragraph
20188 getchar(), putchar()
20191 \begin_layout Standard
20192 \begin_inset LatexCommand \index{<stdio.h>}
20196 As usual on embedded systems you have to provide your own
20199 \begin_inset LatexCommand \index{getchar()}
20208 \begin_inset LatexCommand \index{putchar()}
20215 SDCC does not know whether the system connects to a serial line with or
20216 without handshake, LCD, keyboard or other device.
20230 You'll find examples for serial routines f.e.
20231 in sdcc/device/lib.
20232 For the mcs51 this minimalistic polling
20236 routine might be a start:
20239 \begin_layout Verse
20242 void putchar (char c) {
20248 while (!TI)\InsetSpace ~
20251 /* assumes UART is initialized */
20279 \begin_layout Paragraph
20283 \begin_layout Standard
20287 \begin_inset LatexCommand \index{printf()}
20297 does not support float (except on ds390).
20298 To enable this recompile it with the option
20304 \begin_layout Standard
20314 \begin_inset LatexCommand \index{USE\_FLOATS}
20320 on the command line.
20327 \begin_layout Standard
20337 \begin_inset LatexCommand \index{-\/-model-large}
20343 for the mcs51 port, since this uses a lot of memory.
20346 \begin_layout Standard
20347 If you're short on code memory you might want to use
20350 \begin_inset LatexCommand \index{printf\_small()}
20365 For the mcs51 there additionally are assembly versions
20368 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
20374 (subset of printf using less than 270 bytes) and
20377 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
20386 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
20392 (floating-point aware version of printf_fast) which should fit the requirements
20393 of many embedded systems (printf_fast() can be customized by unsetting
20398 support long variables and field widths).
20399 Be sure to use only one of these printf options within a project.
20404 \begin_layout Standard
20405 Feature matrix of different
20412 \begin_layout Standard
20413 \begin_inset Tabular
20414 <lyxtabular version="3" rows="14" columns="7">
20415 <features islongtable="true">
20416 <column alignment="left" valignment="middle" leftline="true" width="14col%">
20417 <column alignment="center" valignment="top" leftline="true" width="0">
20418 <column alignment="center" valignment="top" leftline="true" width="12col%">
20419 <column alignment="center" valignment="top" leftline="true" width="10col%">
20420 <column alignment="center" valignment="top" leftline="true" width="0">
20421 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
20422 <column alignment="center" valignment="top" rightline="true" width="0">
20423 <row topline="true" bottomline="true" endhead="true">
20424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20427 \begin_layout Standard
20436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20439 \begin_layout Standard
20441 \begin_inset LatexCommand \index{printf}
20450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20453 \begin_layout Standard
20461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20464 \begin_layout Standard
20470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20473 \begin_layout Standard
20479 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20482 \begin_layout Standard
20488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20491 \begin_layout Standard
20498 <row topline="true" endhead="true">
20499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20502 \begin_layout Standard
20508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20511 \begin_layout Standard
20519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20522 \begin_layout Standard
20530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20533 \begin_layout Standard
20541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20544 \begin_layout Standard
20552 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20555 \begin_layout Standard
20563 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20566 \begin_layout Standard
20575 <row topline="true" endhead="true">
20576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20579 \begin_layout Standard
20580 \begin_inset Quotes sld
20584 \begin_inset Quotes srd
20590 \begin_layout Standard
20596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20599 \begin_layout Standard
20605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20608 \begin_layout Standard
20614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20617 \begin_layout Standard
20623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20626 \begin_layout Standard
20632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20635 \begin_layout Standard
20641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20644 \begin_layout Standard
20651 <row topline="true" endhead="true">
20652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20655 \begin_layout Standard
20659 \begin_layout Standard
20665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20668 \begin_layout Standard
20674 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20677 \begin_layout Standard
20683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20686 \begin_layout Standard
20687 0.45k / 0.47k (+ _ltoa)
20692 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20695 \begin_layout Standard
20701 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20704 \begin_layout Standard
20710 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20713 \begin_layout Standard
20720 <row topline="true">
20721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20724 \begin_layout Standard
20730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20733 \begin_layout Standard
20743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20746 \begin_layout Standard
20793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20796 \begin_layout Standard
20835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20838 \begin_layout Standard
20844 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20847 \begin_layout Standard
20853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20856 \begin_layout Standard
20863 <row topline="true">
20864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20867 \begin_layout Standard
20868 long (32 bit) support
20873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20876 \begin_layout Standard
20882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20885 \begin_layout Standard
20891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20894 \begin_layout Standard
20900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20903 \begin_layout Standard
20909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20912 \begin_layout Standard
20927 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20930 \begin_layout Standard
20937 <row topline="true">
20938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20941 \begin_layout Standard
20942 byte arguments on stack
20947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20950 \begin_layout Standard
20956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20959 \begin_layout Standard
20965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20968 \begin_layout Standard
20974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20977 \begin_layout Standard
20983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20986 \begin_layout Standard
20992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20995 \begin_layout Standard
21002 <row topline="true">
21003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21006 \begin_layout Standard
21008 \begin_inset LatexCommand \index{Floating point support}
21017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21020 \begin_layout Standard
21026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21029 \begin_layout Standard
21035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21038 \begin_layout Standard
21044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21047 \begin_layout Standard
21053 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21056 \begin_layout Standard
21061 \begin_layout Standard
21062 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
21072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21075 \begin_layout Standard
21082 <row topline="true">
21083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21086 \begin_layout Standard
21087 float formats %e %g
21092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21095 \begin_layout Standard
21101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21104 \begin_layout Standard
21110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21113 \begin_layout Standard
21119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21122 \begin_layout Standard
21128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21131 \begin_layout Standard
21137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21140 \begin_layout Standard
21147 <row topline="true" bottomline="true">
21148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21151 \begin_layout Standard
21157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21160 \begin_layout Standard
21166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21169 \begin_layout Standard
21175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21178 \begin_layout Standard
21184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21187 \begin_layout Standard
21193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21196 \begin_layout Standard
21202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21205 \begin_layout Standard
21212 <row bottomline="true">
21213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21216 \begin_layout Standard
21221 \begin_layout Standard
21222 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
21226 n'); standard 8051 @ 22.1184 MHz, empty putchar()
21234 \begin_layout Standard
21240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21243 \begin_layout Standard
21249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21252 \begin_layout Standard
21258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21261 \begin_layout Standard
21267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21270 \begin_layout Standard
21276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21279 \begin_layout Standard
21285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21288 \begin_layout Standard
21295 <row bottomline="true">
21296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21299 \begin_layout Standard
21304 \begin_layout Standard
21305 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
21314 \begin_layout Standard
21320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21323 \begin_layout Standard
21329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21332 \begin_layout Standard
21338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21341 \begin_layout Standard
21347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21350 \begin_layout Standard
21356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21359 \begin_layout Standard
21365 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21368 \begin_layout Standard
21373 \begin_layout Standard
21374 printf_tiny integer speed is data dependent, worst case is 0.33 ms
21385 <row bottomline="true">
21386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21389 \begin_layout Standard
21394 \begin_layout Standard
21395 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
21404 \begin_layout Standard
21410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21413 \begin_layout Standard
21419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21422 \begin_layout Standard
21428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21431 \begin_layout Standard
21437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21440 \begin_layout Standard
21446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21449 \begin_layout Standard
21455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21458 \begin_layout Standard
21465 <row bottomline="true">
21466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21469 \begin_layout Standard
21474 \begin_layout Standard
21475 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
21484 \begin_layout Standard
21490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21493 \begin_layout Standard
21499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21502 \begin_layout Standard
21508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21511 \begin_layout Standard
21517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21520 \begin_layout Standard
21526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21529 \begin_layout Standard
21535 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21538 \begin_layout Standard
21552 \begin_layout Subsubsection
21554 \begin_inset LatexCommand \index{malloc.h}
21561 \begin_layout Standard
21562 As of SDCC 2.6.2 you no longer need to call an initialization routine before
21563 using dynamic memory allocation
21564 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
21569 \begin_inset LatexCommand \index{heap (malloc)}
21573 space of 1024 bytes is provided for malloc to allocate memory from.
21574 If you need a different heap size you need to recompile _heap.c with the
21575 required size defined in HEAP_SIZE.
21576 It is recommended to make a copy of this file into your project directory
21577 and compile it there with:
21580 \begin_layout Verse
21583 sdcc -c _heap.c -D HEAD_SIZE=2048
21586 \begin_layout Standard
21587 And then link it with:
21590 \begin_layout Verse
21593 sdcc main.rel _heap.rel
21596 \begin_layout Subsection
21597 Math functions (sinf, powf, sqrtf etc.)
21600 \begin_layout Subsubsection
21604 \begin_layout Standard
21605 See definitions in file <math.h>.
21608 \begin_layout Subsection
21612 \begin_layout Standard
21614 \begin_inset LatexCommand \index{Libraries}
21618 included in SDCC should have a license at least as liberal as the GNU Lesser
21619 General Public License
21620 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
21631 \begin_layout Standard
21632 \begin_inset Note Note
21635 \begin_layout Standard
21636 license statements for the libraries are missing.
21637 sdcc/device/lib/ser_ir.c
21640 \begin_layout Standard
21642 come with a GPL (as opposed to LGPL) License - this will not be liberal
21643 enough for many embedded programmers.
21651 \begin_layout Standard
21652 If you have ported some library or want to share experience about some code
21654 falls into any of these categories Busses (I
21655 \begin_inset Formula $^{\textrm{2}}$
21658 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
21659 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
21660 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
21661 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
21666 would certainly like to hear about it.
21669 \begin_layout Standard
21670 Programmers coding for embedded systems are not especially famous for being
21671 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
21672 e these references are very valuable.
21673 Let's help to create a climate where information is shared.
21674 \begin_inset VSpace bigskip
21680 \begin_layout Section
21684 \begin_layout Subsection
21685 MCS51 Memory Models
21686 \begin_inset LatexCommand \index{Memory model}
21691 \begin_inset LatexCommand \index{MCS51 memory model}
21698 \begin_layout Subsubsection
21699 Small, Medium and Large
21702 \begin_layout Standard
21703 SDCC allows three memory models for MCS51 code,
21712 Modules compiled with different memory models should
21716 be combined together or the results would be unpredictable.
21717 The library routines supplied with the compiler are compiled as small,
21719 The compiled library modules are contained in separate directories as small,
21720 medium and large so that you can link to the appropriate set.
21723 \begin_layout Standard
21724 When the medium or large model is used all variables declared without a
21725 storage class will be allocated into the external ram, this includes all
21726 parameters and local variables (for non-reentrant
21727 \begin_inset LatexCommand \index{reentrant}
21732 When the small model is used variables without storage class are allocated
21733 in the internal ram.
21736 \begin_layout Standard
21737 Judicious usage of the processor specific storage classes
21738 \begin_inset LatexCommand \index{Storage class}
21742 and the 'reentrant' function type will yield much more efficient code,
21743 than using the large model.
21744 Several optimizations are disabled when the program is compiled using the
21745 large model, it is therefore recommended that the small model be used unless
21746 absolutely required.
21749 \begin_layout Subsubsection
21751 \begin_inset LatexCommand \label{sub:External-Stack}
21756 \begin_inset LatexCommand \index{stack}
21761 \begin_inset LatexCommand \index{External stack (mcs51)}
21768 \begin_layout Standard
21769 The external stack (-
21773 \begin_layout Standard
21783 \begin_inset LatexCommand \index{-\/-xstack}
21787 ) is located in pdata
21788 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
21792 memory (usually at the start of the external ram segment) and uses all
21793 unused space in pdata (max.
21799 \begin_layout Standard
21808 -xstack option is used to compile the program, the parameters and local
21810 \begin_inset LatexCommand \index{local variables}
21814 of all reentrant functions are allocated in this area.
21815 This option is provided for programs with large stack space requirements.
21816 When used with the -
21820 \begin_layout Standard
21830 \begin_inset LatexCommand \index{-\/-stack-auto}
21834 option, all parameters and local variables are allocated on the external
21835 stack (note: support libraries will need to be recompiled with the same
21837 There is a predefined target in the library makefile).
21840 \begin_layout Standard
21841 The compiler outputs the higher order address byte of the external ram segment
21843 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21848 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21852 ), therefore when using the External Stack option, this port
21856 be used by the application program.
21859 \begin_layout Subsection
21861 \begin_inset LatexCommand \index{Memory model}
21866 \begin_inset LatexCommand \index{DS390 memory model}
21873 \begin_layout Standard
21874 The only model supported is Flat 24
21875 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21880 This generates code for the 24 bit contiguous addressing mode of the Dallas
21882 In this mode, up to four meg of external RAM or code space can be directly
21884 See the data sheets at www.dalsemi.com for further information on this part.
21889 that the compiler does not generate any code to place the processor into
21890 24 bitmode (although
21894 in the ds390 libraries will do that for you).
21900 \begin_inset LatexCommand \index{Tinibios (DS390)}
21904 , the boot loader or similar code must ensure that the processor is in 24
21905 bit contiguous addressing mode before calling the SDCC startup code.
21916 \begin_layout Standard
21927 option, variables will by default be placed into the XDATA segment.
21932 Segments may be placed anywhere in the 4 meg address space using the usual
21937 \begin_layout Standard
21947 Note that if any segments are located above 64K, the -r flag must be passed
21948 to the linker to generate the proper segment relocations, and the Intel
21949 HEX output format must be used.
21950 The -r flag can be passed to the linker by using the option
21954 on the SDCC command line.
21955 However, currently the linker can not handle code segments > 64k.
21958 \begin_layout Section
21960 \begin_inset LatexCommand \label{sec:Pragmas}
21965 \begin_inset LatexCommand \index{Pragmas}
21972 \begin_layout Standard
21973 Pragmas are used to turn on and/or off certain compiler options.
21974 Some of them are closely related to corresponding command-line options
21976 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21982 Pragmas should be placed before and/or after a function, placing pragmas
21983 inside a function body could have unpredictable results.
21988 following #pragma directives:
21991 \begin_layout Itemize
21997 \begin_inset LatexCommand \index{\#pragma save}
22001 - this will save most current options to the save/restore stack.
22002 See #pragma\InsetSpace ~
22006 \begin_layout Itemize
22012 \begin_inset LatexCommand \index{\#pragma restore}
22016 - will restore saved options from the last save.
22017 saves & restores can be nested.
22018 SDCC uses a save/restore stack: save pushes current options to the stack,
22019 restore pulls current options from the stack.
22020 See #pragma\InsetSpace ~
22026 \begin_layout Itemize
22032 \begin_inset LatexCommand \index{\#pragma callee\_saves}
22037 \begin_inset LatexCommand \index{function prologue}
22041 function1[,function2[,function3...]]
22042 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
22046 - The compiler by default uses a caller saves convention for register saving
22047 across function calls, however this can cause unnecessary register pushing
22049 \begin_inset LatexCommand \index{push/pop}
22053 when calling small functions from larger functions.
22054 This option can be used to switch off the register saving convention for
22055 the function names specified.
22056 The compiler will not save registers when calling these functions, extra
22057 code need to be manually inserted at the entry and exit for these functions
22058 to save and restore the registers used by these functions, this can SUBSTANTIAL
22059 LY reduce code and improve run time performance of the generated code.
22060 In the future the compiler (with inter procedural analysis) may be able
22061 to determine the appropriate scheme to use for each function call.
22066 \begin_layout Standard
22075 -callee-saves command line option is used (see page
22076 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
22080 ), the function names specified in #pragma\InsetSpace ~
22082 \begin_inset LatexCommand \index{\#pragma callee\_saves}
22086 is appended to the list of functions specified in the command line.
22089 \begin_layout Itemize
22095 \begin_inset LatexCommand \index{\#pragma exclude}
22099 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
22100 of pairs of push/pop
22101 \begin_inset LatexCommand \index{push/pop}
22110 \begin_inset LatexCommand \index{interrupt}
22123 The directive should be placed immediately before the ISR function definition
22124 and it affects ALL ISR functions following it.
22125 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
22126 exclude\InsetSpace ~
22128 \begin_inset LatexCommand \index{\#pragma exclude}
22133 See also the related keyword _naked
22134 \begin_inset LatexCommand \index{\_naked}
22139 \begin_inset LatexCommand \index{\_\_naked}
22146 \begin_layout Itemize
22152 \begin_inset LatexCommand \index{pedantic}
22157 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
22162 \begin_inset LatexCommand \label{ite:less_pedantic}
22166 - the compiler will not warn you anymore for obvious mistakes, you're on
22168 See also the command line option -
22172 \begin_layout Standard
22182 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
22189 More specifically, the following warnings will be disabled:
22191 comparison is always [true/false] due to limited range of data type
22195 overflow in implicit constant conversion
22197 (158); [the (in)famous]
22199 conditional flow changed by optimizer: so said EVELYN the modified DOG
22203 function '[function name]' must return value
22208 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
22209 level) are disabled, too, namely:
22212 \begin_inset Note Note
22215 \begin_layout Standard
22216 dunno what comes here - this warning appears to be unused altogether
22225 [left/right] shifting more than size of object changed to zero
22233 integer overflow in expression
22237 unmatched #pragma save and #pragma restore
22241 comparison of 'signed char' with 'unsigned char' requires promotion to int
22245 ISO C90 does not support flexible array members
22249 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
22253 \begin_inset Note Note
22256 \begin_layout Standard
22257 appears to be always blank - what was supposed to be here?
22266 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
22267 complexity [number]
22272 \begin_layout Itemize
22278 \begin_inset LatexCommand \index{\#pragma disable\_warning}
22282 - the compiler will not warn you anymore about warning number <nnnn>.
22285 \begin_layout Itemize
22291 \begin_inset LatexCommand \index{\#pragma nogcse}
22295 - will stop global common subexpression elimination.
22298 \begin_layout Itemize
22304 \begin_inset LatexCommand \index{\#pragma noinduction}
22308 - will stop loop induction optimizations.
22311 \begin_layout Itemize
22317 \begin_inset LatexCommand \index{\#pragma noinvariant}
22321 - will not do loop invariant optimizations.
22322 For more details see Loop Invariants in section
22323 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
22330 \begin_layout Itemize
22336 \begin_inset LatexCommand \index{\#pragma noiv}
22340 - Do not generate interrupt
22341 \begin_inset LatexCommand \index{interrupt}
22346 \begin_inset LatexCommand \index{interrupt vector table}
22350 entries for all ISR functions defined after the pragma.
22351 This is useful in cases where the interrupt vector table must be defined
22352 manually, or when there is a secondary, manually defined interrupt vector
22354 for the autovector feature of the Cypress EZ-USB FX2).
22355 More elegantly this can be achieved by obmitting the optional interrupt
22356 number after the interrupt keyword, see section
22357 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
22365 \begin_layout Itemize
22371 \begin_inset LatexCommand \index{\#pragma nojtbound}
22375 - will not generate code for boundary value checking, when switch statements
22376 are turned into jump-tables (dangerous).
22377 For more details see section
22378 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
22385 \begin_layout Itemize
22391 \begin_inset LatexCommand \index{\#pragma noloopreverse}
22395 - Will not do loop reversal optimization
22398 \begin_layout Itemize
22404 \begin_inset LatexCommand \index{\#pragma nooverlay}
22408 - the compiler will not overlay the parameters and local variables of a
22412 \begin_layout Itemize
22418 \begin_inset LatexCommand \index{\#pragma stackauto}
22426 \begin_layout Standard
22436 \begin_inset LatexCommand \index{-\/-stack-auto}
22441 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
22445 Parameters and Local Variables.
22448 \begin_layout Itemize
22454 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
22458 - The compiler will optimize code generation towards fast code, possibly
22459 at the expense of code size.
22460 Currently this has little effect.
22463 \begin_layout Itemize
22469 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
22473 - The compiler will optimize code generation towards compact code, possibly
22474 at the expense of code speed.
22475 Currently this has little effect.
22478 \begin_layout Itemize
22484 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
22488 - The compiler will attempt to generate code that is both compact and fast,
22489 as long as meeting one goal is not a detriment to the other (this is the
22494 \begin_layout Itemize
22500 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
22504 - Generally follow the C89 standard, but allow SDCC features that conflict
22505 with the standard (default).
22508 \begin_layout Itemize
22514 \begin_inset LatexCommand \index{\#pragma std\_c89}
22518 - Follow the C89 standard and disable SDCC features that conflict with the
22522 \begin_layout Itemize
22528 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
22532 - Generally follow the C99 standard, but allow SDCC features that conflict
22533 with the standard (incomplete support).
22536 \begin_layout Itemize
22542 \begin_inset LatexCommand \index{\#pragma std\_c99}
22546 - Follow the C99 standard and disable SDCC features that conflict with the
22547 standard (incomplete support).
22550 \begin_layout Itemize
22556 \begin_inset LatexCommand \index{\#pragma codeseg}
22560 - Use this name (max.
22561 8 characters) for the code segment.
22566 \begin_layout Standard
22578 \begin_layout Itemize
22584 \begin_inset LatexCommand \index{\#pragma constseg}
22588 - Use this name (max.
22589 8 characters) for the const segment.
22594 \begin_layout Standard
22606 \begin_layout Standard
22607 The preprocessor SDCPP
22608 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
22612 supports the following #pragma directives:
22615 \begin_layout Itemize
22618 pedantic_parse_number
22621 \begin_inset LatexCommand \index{pedantic}
22626 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22631 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
22635 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
22636 properly and the macro LO_B(3) gets expanded.
22642 \begin_layout Standard
22651 -pedantic-parse-number command line option
22652 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
22659 Below is an example on how to use this pragma.
22662 Note: this functionality is not in conformance with standard!
22665 \begin_layout Verse
22668 #pragma pedantic_parse_number +
22669 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22677 #define LO_B(x) ((x) & 0xff)
22681 unsigned char foo(void)
22688 unsigned char c=0xfe-LO_B(3)
22703 \begin_layout Itemize
22709 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22713 (+ | -) - switch _asm _endasm block preprocessing on / off.
22715 You use this prama to define multilines of assembly code.
22716 This will prevent the preprocessor from changing the formating required
22718 Below is an example on how to use this pragma.
22721 \begin_layout Verse
22724 #pragma preproc_asm -
22725 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22731 #define MYDELAY _asm
22736 nop ;my assembly comment...
22750 #pragma preproc_asm
22781 \begin_layout Itemize
22787 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22791 (+ | -) - Allow "naked" hash in macro definition, for example:
22795 #define DIR_LO(x) #(x & 0xff)
22800 Below is an example on how to use this pragma.
22803 \begin_layout Verse
22806 #pragma preproc_asm +
22808 #pragma sdcc_hash +
22809 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22824 mov R6_B3, #(x & 0xff)
22831 mov R7_B3, #((x >> 8) & 0xff)
22855 \begin_layout Standard
22856 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22857 ons which might cause the compiler to generate extra stack and/or data space
22858 to store compiler generated temporary variables.
22859 This usually happens in large functions.
22860 Pragma directives should be used as shown in the following example, they
22861 are used to control options and optimizations for a given function.
22865 \begin_layout Verse
22869 \begin_inset LatexCommand \index{\#pragma save}
22880 /* save the current settings */
22883 \begin_inset LatexCommand \index{\#pragma nogcse}
22892 /* turnoff global subexpression elimination */
22894 #pragma noinduction
22895 \begin_inset LatexCommand \index{\#pragma noinduction}
22899 /* turn off induction optimizations */
22922 \begin_inset LatexCommand \index{\#pragma restore}
22926 /* turn the optimizations back on */
22929 \begin_layout Standard
22930 The compiler will generate a warning message when extra space is allocated.
22931 It is strongly recommended that the save and restore pragmas be used when
22932 changing options for a function.
22941 \begin_layout Section
22942 Defines Created by the Compiler
22945 \begin_layout Standard
22946 The compiler creates the following #defines
22947 \begin_inset LatexCommand \index{\#defines}
22952 \begin_inset LatexCommand \index{Defines created by the compiler}
22961 \begin_layout Standard
22962 \begin_inset Tabular
22963 <lyxtabular version="3" rows="15" columns="2">
22965 <column alignment="left" valignment="top" leftline="true" width="3in">
22966 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22967 <row topline="true" bottomline="true">
22968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22971 \begin_layout Standard
22979 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22982 \begin_layout Standard
22991 <row topline="true">
22992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22995 \begin_layout Standard
22997 \begin_inset LatexCommand \index{SDCC}
23006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23009 \begin_layout Standard
23011 Since version 2.5.6 the version number as an int (ex.
23018 <row topline="true">
23019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23022 \begin_layout Standard
23024 \begin_inset LatexCommand \index{SDCC\_mcs51}
23029 \begin_inset LatexCommand \index{SDCC\_ds390}
23034 \begin_inset LatexCommand \index{SDCC\_z80}
23043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23046 \begin_layout Standard
23047 depending on the model used (e.g.: -mds390)
23053 <row topline="true">
23054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23057 \begin_layout Standard
23059 \begin_inset LatexCommand \index{\_\_mcs51}
23064 \begin_inset LatexCommand \index{\_\_ds390}
23069 \begin_inset LatexCommand \index{\_\_hc08}
23074 \begin_inset LatexCommand \index{\_\_z80}
23083 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23086 \begin_layout Standard
23087 depending on the model used (e.g.
23094 <row topline="true">
23095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23098 \begin_layout Standard
23100 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
23109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23112 \begin_layout Standard
23119 \begin_layout Standard
23136 <row topline="true">
23137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23140 \begin_layout Standard
23142 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
23151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23154 \begin_layout Standard
23161 \begin_layout Standard
23178 <row topline="true">
23179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23182 \begin_layout Standard
23184 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
23193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23196 \begin_layout Standard
23203 \begin_layout Standard
23220 <row topline="true">
23221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23224 \begin_layout Standard
23226 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
23235 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23238 \begin_layout Standard
23245 \begin_layout Standard
23262 <row topline="true">
23263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23266 \begin_layout Standard
23268 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
23277 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23280 \begin_layout Standard
23287 \begin_layout Standard
23304 <row topline="true">
23305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23308 \begin_layout Standard
23310 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
23319 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23322 \begin_layout Standard
23333 <row topline="true">
23334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23337 \begin_layout Standard
23339 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23351 \begin_layout Standard
23362 <row topline="true">
23363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23366 \begin_layout Standard
23368 \begin_inset LatexCommand \index{SDCC\_REVISION}
23377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23380 \begin_layout Standard
23382 SDCC svn revision number
23388 <row topline="true">
23389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23392 \begin_layout Standard
23393 SDCC_PARMS_IN_BANK1
23394 \begin_inset LatexCommand \index{SDCC\_PARMS\_IN\_BANK1}
23403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23406 \begin_layout Standard
23413 \begin_layout Standard
23430 <row topline="true">
23431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23434 \begin_layout Standard
23436 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23448 \begin_layout Standard
23455 \begin_layout Standard
23472 <row topline="true" bottomline="true">
23473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23476 \begin_layout Standard
23477 SDCC_INT_LONG_REENT
23478 \begin_inset LatexCommand \index{SDCC\_INT\_LONG\_REENT}
23487 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23490 \begin_layout Standard
23497 \begin_layout Standard
23521 \begin_layout Chapter
23522 Notes on supported Processors
23525 \begin_layout Section
23527 \begin_inset LatexCommand \label{sub:MCS51-variants}
23532 \begin_inset LatexCommand \index{MCS51 variants}
23539 \begin_layout Standard
23540 MCS51 processors are available from many vendors and come in many different
23542 While they might differ considerably in respect to Special Function Registers
23543 the core MCS51 is usually not modified or is kept compatible.
23547 \begin_layout Subsection
23548 pdata access by SFR
23551 \begin_layout Standard
23552 With the upcome of devices with internal xdata and flash memory devices
23554 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
23558 as dedicated I/O port is becoming more popular.
23559 Switching the high byte for pdata
23560 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
23564 access which was formerly done by port P2 is then achieved by a Special
23566 \begin_inset LatexCommand \index{sfr}
23571 In well-established MCS51 tradition the address of this
23575 is where the chip designers decided to put it.
23576 Needless to say that they didn't agree on a common name either.
23577 So that the startup code can correctly initialize xdata variables, you
23578 should define an sfr with the name _XPAGE
23581 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
23587 at the appropriate location if the default, port P2, is not used for this.
23591 \begin_layout Verse
23594 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
23598 \begin_layout Verse
23601 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
23606 \begin_layout Verse
23609 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
23613 \begin_layout Verse
23616 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23620 \begin_layout Verse
23623 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23627 \begin_layout Standard
23628 For more exotic implementations further customizations may be needed.
23630 \begin_inset LatexCommand \ref{sub:Startup-Code}
23634 for other possibilities.
23637 \begin_layout Subsection
23638 Other Features available by SFR
23641 \begin_layout Standard
23642 Some MCS51 variants offer features like Double DPTR
23643 \begin_inset LatexCommand \index{DPTR}
23647 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
23648 These are currently not used for the MCS51 port.
23649 If you absolutely need them you can fall back to inline assembly or submit
23653 \begin_layout Subsection
23657 \begin_layout Standard
23659 \begin_inset LatexCommand \index{Bankswitching}
23665 \begin_inset LatexCommand \index{code banking}
23669 ) is a technique to increase the code space above the 64k limit of the 8051.
23672 \begin_layout Subsubsection
23676 \begin_layout Standard
23677 \begin_inset Tabular
23678 <lyxtabular version="3" rows="3" columns="4">
23680 <column alignment="center" valignment="top" width="0">
23681 <column alignment="center" valignment="top" leftline="true" width="0">
23682 <column alignment="center" valignment="top" leftline="true" width="0">
23683 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23684 <row topline="true" bottomline="true">
23685 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23688 \begin_layout Standard
23694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23697 \begin_layout Standard
23703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23706 \begin_layout Standard
23712 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23715 \begin_layout Standard
23722 <row topline="true" bottomline="true">
23723 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23726 \begin_layout Standard
23732 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23735 \begin_layout Standard
23741 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23744 \begin_layout Standard
23750 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23753 \begin_layout Standard
23761 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23764 \begin_layout Standard
23765 SiLabs C8051F120 example
23770 <cell multicolumn="2" alignment="center" valignment="top" usebox="none">
23773 \begin_layout Standard
23779 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23782 \begin_layout Standard
23788 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23791 \begin_layout Standard
23806 Usually the hardware uses some sfr (an output port or an internal sfr) to
23807 select a bank and put it in the banked area of the memory map.
23808 The selected bank usually becomes active immediately upon assignment to
23809 this sfr and when running inside a bank it will switch out this code it
23810 is currently running.
23811 Therefor you cannot jump or call directly from one bank to another and
23812 need to use a so-called trampoline in the common area.
23813 For SDCC an example trampoline is in crtbank.asm and you may need to change
23814 it to your 8051 derivative or schematic.
23815 The presented code is written for the C8051F120.
23819 When calling a banked function
23820 SDCC will put the LSB of the functions address in register R0, the MSB
23821 in R1 and the bank in R2 and then call this trampoline
23826 The current selected bank is saved on the stack, the new bank is selected
23827 and an indirect jump is made.
23828 When the banked function returns it jumps to
23832 which restores the previous bank and returns to the caller.
23835 \begin_layout Subsubsection
23839 \begin_layout Standard
23840 When writing banked software using SDCC you need to use some special keywords
23842 You also need to take over a bit of work from the linker.
23846 To create a function
23847 that can be called from another bank it requires the keyword
23852 \begin_inset LatexCommand \index{banked}
23857 The caller must see this in the prototype of the callee and the callee
23858 needs it for a proper return.
23859 Called functions within the same bank as the caller do not need the
23863 keyword nor do functions in the common area.
23864 Beware: SDCC does not know or check if functions are in the same bank.
23865 This is your responsibility!
23869 Normally all functions you write end up in
23871 If you want a function explicitly to reside in the common area put it in
23873 This applies for instance to interrupt service routines as they should
23877 \begin_layout Standard
23878 Functions that need to be in a switched bank must be put in a named segment.
23879 The name can be mostly anything upto eight characters (e.g.
23881 To do this you either use -
23885 \begin_layout Standard
23894 -codeseg BANK1 (See
23895 \begin_inset LatexCommand \ref{lyx:-codeseg}
23899 ) on the command line when compiling or #pragma codeseg BANK1 (See
23900 \begin_inset LatexCommand \ref{sec:Pragmas}
23904 ) at the top of the C source file.
23905 The segment name always applies to the whole source file and generated
23906 object so functions for different banks need to be defined in different
23911 When linking your objects you need to tell the linker where
23912 to put your segments.
23913 To do this you use the following command line option to SDCC: -Wl-b BANK1=0x180
23915 \begin_inset LatexCommand \ref{lyx:-Wl option}
23920 This sets the virtual start address of this segment.
23921 It sets the banknumber to 0x01 and maps the bank to 0x8000 and up.
23922 The linker will not check for overflows, again this is your responsibility.
23925 \begin_layout Standard
23926 \begin_inset VSpace bigskip
23932 \begin_layout Section
23936 \begin_layout Standard
23938 \begin_inset LatexCommand \index{DS80C400}
23943 \begin_inset LatexCommand \index{DS400}
23947 microcontroller has a rich set of peripherals.
23948 In its built-in ROM library it includes functions to access some of the
23949 features, among them is a TCP stack with IP4 and IP6 support.
23950 Library headers (currently in beta status) and other files are provided
23954 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
23960 \begin_inset VSpace bigskip
23966 \begin_layout Section
23967 The Z80 and gbz80 port
23970 \begin_layout Standard
23971 SDCC can target both the Zilog Z80
23972 \begin_inset LatexCommand \index{Z80}
23976 and the Nintendo Gameboy's Z80-like gbz80
23977 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
23982 The Z80 port is passed through the same
23985 \begin_inset LatexCommand \index{Regression test}
23992 \begin_inset LatexCommand \ref{sec:Quality-control}
23996 ) as the MCS51 and DS390 ports, so floating point support, support for long
23997 variables and bitfield support is fine.
23998 See mailing lists and forums about interrupt routines.
24001 \begin_layout Standard
24002 As always, the code is the authoritative reference - see z80/ralloc.c and
24005 \begin_inset LatexCommand \index{Z80!stack}
24009 frame is similar to that generated by the IAR Z80 compiler.
24010 IX is used as the base pointer, HL and IY are used as a temporary registers,
24011 and BC and DE are available for holding variables.
24013 \begin_inset LatexCommand \index{Z80!return value}
24017 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
24019 The gbz80 port use the same set of registers for the return values, but
24020 in a different order of significance: E (one byte), DE (two bytes), or
24022 \begin_inset VSpace bigskip
24028 \begin_layout Section
24032 \begin_layout Standard
24033 The port to the Freescale/Motorola HC08
24034 \begin_inset LatexCommand \index{HC08}
24038 family has been added in October 2003, and is still undergoing some basic
24040 The code generator is complete, but the register allocation is still quite
24042 Some of the SDCC's standard C library functions have embedded non-HC08
24043 inline assembly and so are not yet usable.
24046 \begin_layout Standard
24047 The HC08 port passes the regression test suite (see section
24048 \begin_inset LatexCommand \ref{sec:Quality-control}
24053 \begin_inset VSpace bigskip
24059 \begin_layout Section
24061 \begin_inset LatexCommand \index{PIC14}
24068 \begin_layout Standard
24069 The PIC14 port adds support for Microchip
24070 \begin_inset LatexCommand \index{Microchip}
24075 \begin_inset Formula $^{\text{TM}}$
24079 \begin_inset LatexCommand \index{PIC14}
24084 \begin_inset Formula $^{\text{TM}}$
24087 MCUs with 14 bit wide instructions.
24088 This port is not yet mature and still lacks many features.
24089 However, it can work for simple code.
24092 \begin_layout Standard
24094 Currently supported devices include:
24097 \begin_layout Standard
24098 12F: 629, 635, 675, 683
24101 \begin_layout Standard
24105 \begin_layout Standard
24109 \begin_layout Standard
24110 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
24113 \begin_layout Standard
24114 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
24118 \begin_layout Standard
24122 \begin_layout Standard
24123 16CR: 620a, 73, 74, 76, 77
24126 \begin_layout Standard
24127 16F: 616, 627, 627a, 628, 628a, 630, 636, 639, 648, 648a, 676, 684, 685,
24131 \begin_layout Standard
24132 16F: 716, 72, 73, 737, 74, 747, 76, 767, 77, 777, 785
24135 \begin_layout Standard
24136 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
24137 877, 877a, 88, 886, 887
24140 \begin_layout Standard
24141 16F: 913, 914, 916, 917, 946
24144 \begin_layout Standard
24148 \begin_layout Standard
24150 An up-to-date list of currently supported devices can be obtained via
24152 sdcc -mpic14 -phelp foo.c
24154 (foo.c must exist...).
24157 \begin_layout Subsection
24159 \begin_inset LatexCommand \index{code page (pic14)}
24164 \begin_inset LatexCommand \index{Memory bank (pic14)}
24171 \begin_layout Standard
24172 The linker organizes allocation for the code page and RAM banks.
24173 It does not have intimate knowledge of the code flow.
24174 It will put all the code section of a single .asm file into a single code
24176 In order to make use of multiple code pages, separate asm files must be
24178 The compiler assigns all
24182 functions of a single .c file into the same code page.
24186 To get the best results,
24187 follow these guidelines:
24190 \begin_layout Enumerate
24191 Make local functions static, as non static functions require code page selection
24194 Due to the way sdcc handles functions, place called functions prior
24195 to calling functions in the file wherever possible: Otherwise sdcc will
24196 insert unneccessary pagesel directives around the call, believing that
24197 the called function is externally defined.
24200 \begin_layout Enumerate
24201 For devices that have multiple code pages it is more efficient to use the
24202 same number of files as pages: Use up to 4 separate .c files for the 16F877,
24203 but only 2 files for the 16F874.
24204 This way the linker can put the code for each file into different code
24205 pages and there will be less page selection overhead.
24208 \begin_layout Enumerate
24209 And as for any 8 bit micro (especially for PIC14 as they have a very simple
24210 instruction set), use `unsigned char' wherever possible instead of `int'.
24213 \begin_layout Subsection
24214 Adding New Devices to the Port
24217 \begin_layout Standard
24218 Adding support for a new 14
24222 \begin_layout Standard
24231 bit PIC MCU requires the following steps:
24234 \begin_layout Enumerate
24235 Create a new device description.
24237 Each device is described in two files: pic16f*.h
24239 These files primarily define SFRs, structs to access their bits, and symbolic
24240 configuration options.
24241 Both files can be generated from gputils' .inc files using the perl script
24244 support/scripts/inc2h.pl
24247 This file also contains further instructions on how to proceed.
24250 \begin_layout Enumerate
24251 Copy the .h file into SDCC's include path and either add the .c file to your
24252 project or copy it to
24254 device/lib/pic/libdev
24257 Afterwards, rebuild and install the libraries.
24260 \begin_layout Enumerate
24261 Edit pic14devices.txt in SDCC's include path (
24263 device/include/pic/
24265 in the source tree or
24267 /usr/local/share/sdcc/include/pic
24269 after installation).
24271 You need to add a device specification here to make
24272 the memory layout (code banks, RAM, aliased memory regions, ...) known to
24274 Probably you can copy and modify an existing entry.
24275 The file format is documented at the top of the file.
24278 \begin_layout Subsection
24282 \begin_layout Standard
24283 For the interrupt function, use the keyword `__interrupt'
24284 \begin_inset LatexCommand \index{PIC14!interrupt}
24288 with level number of 0 (PIC14 only has 1 interrupt so this number is only
24289 there to avoid a syntax error - it ought to be fixed).
24293 \begin_layout Verse
24296 void Intr(void) __interrupt 0
24302 T0IF = 0; /* Clear timer interrupt */
24307 \begin_layout Subsection
24308 Linking and Assembling
24311 \begin_layout Standard
24312 For assembling you can use either GPUTILS'
24313 \begin_inset LatexCommand \index{gputils (pic tools)}
24317 gpasm.exe or MPLAB's mpasmwin.exe.
24318 GPUTILS are available from
24319 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24324 For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
24325 If you use MPLAB and an interrupt function then the linker script file
24326 vectors section will need to be enlarged to link with mplink.
24337 \begin_layout Verse
24350 sdcc -V -mpic14 -p16f877 -c $<
24354 $(PRJ).hex: $(OBJS)
24364 gplink -m -s $(PRJ).lkr
24365 -o $(PRJ).hex $(OBJS) libsdcc.lib
24368 \begin_layout Standard
24376 \begin_layout Verse
24389 sdcc -S -V -mpic14 -p16f877 $<
24399 mpasmwin /q /o $*.asm
24403 $(PRJ).hex: $(OBJS)
24414 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
24417 \begin_layout Standard
24418 Please note that indentations within a
24422 have to be done with a tabulator character.
24425 \begin_layout Subsection
24426 Command-Line Options
24429 \begin_layout Standard
24430 Besides the switches common to all SDCC backends, the PIC14 port accepts
24431 the following options (for an updated list see sdcc -
24435 \begin_layout Standard
24447 \begin_layout Description
24452 \begin_layout Standard
24462 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
24466 emit debug info in assembly output
24469 \begin_layout Description
24474 \begin_layout Standard
24484 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
24488 disable (slightly faulty) optimization on pCode
24491 \begin_layout Description
24496 \begin_layout Standard
24506 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
24510 sets the lowest address of the argument passing stack (defaults to a suitably
24511 large shared databank to reduce BANKSEL overhead)
24514 \begin_layout Description
24519 \begin_layout Standard
24529 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
24533 sets the size if the argument passing stack (default: 16, minimum: 4)
24536 \begin_layout Subsection
24537 Environment Variables
24540 \begin_layout Standard
24541 The PIC14 port recognizes the following environment variables:
24544 \begin_layout Description
24545 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
24546 register (the ones called r0xNNNN) in a section of its own.
24547 By default (if this variable is unset), sdcc tries to cluster registers
24548 in sections in order to reduce the BANKSEL overhead when accessing them.
24551 \begin_layout Subsection
24555 \begin_layout Standard
24556 The PIC14 library currently only contains support routines required by the
24557 compiler to implement multiplication, division, and floating point support.
24558 No libc-like replacement is available at the moment, though many of the
24559 common sdcc library sources (in
24563 ) should also compile with the PIC14 port.
24566 \begin_layout Subsubsection
24567 error: missing definition for symbol ``__gptrget1''
24570 \begin_layout Standard
24571 The PIC14 port uses library routines to provide more complex operations
24572 like multiplication, division/modulus and (generic) pointer dereferencing.
24573 In order to add these routines to your project, you must link with PIC14's
24579 For single source file projects this is done automatically, more complex
24584 to the linker's arguments.
24585 Make sure you also add an include path for the library (using the -I switch
24589 \begin_layout Subsubsection
24590 Processor mismatch in file ``XXX''.
24593 \begin_layout Standard
24594 This warning can usually be ignored due to the very good compatibility amongst
24599 \begin_layout Standard
24609 \begin_inset LatexCommand \index{PIC14}
24616 \begin_layout Standard
24617 You might also consider recompiling the library for your specific device
24618 by changing the ARCH=p16f877 (default target) entry in
24620 device/lib/pic/Makefile.in
24624 device/lib/pic/Makefile
24626 to reflect your device.
24627 This might even improve performance for smaller devices as unneccesary
24628 BANKSELs might be removed.
24631 \begin_layout Subsection
24635 \begin_layout Subsubsection
24639 \begin_layout Standard
24640 Functions with variable argument lists (like printf) are not yet supported.
24641 Similarly, taking the address of the first argument passed into a function
24642 does not work: It is currently passed in WREG and has no address...
24645 \begin_layout Subsubsection
24646 Regression tests fail
24649 \begin_layout Standard
24650 Though the small subset of regression tests in src/regression passes, SDCC
24651 regression test suite does not, indicating that there are still major bugs
24653 However, many smaller projects have successfully used SDCC in the past...
24656 \begin_layout Standard
24664 \begin_layout Section
24666 \begin_inset LatexCommand \index{PIC16}
24673 \begin_layout Standard
24674 The PIC16 port adds support for Microchip
24675 \begin_inset LatexCommand \index{Microchip}
24680 \begin_inset Formula $^{\text{TM}}$
24684 \begin_inset LatexCommand \index{PIC}
24689 \begin_inset Formula $^{\text{TM}}$
24692 MCUs with 16 bit wide instructions.
24693 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
24694 ; devices supported by the port include:
24697 \begin_layout Standard
24698 18F: 242, 248, 252, 258, 442, 448, 452, 458
24701 \begin_layout Standard
24705 \begin_layout Standard
24706 18F: 2220, 2221, 2320, 2321, 2331, 2410, 2420, 2423, 2431, 2450, 2455, 2480,
24710 \begin_layout Standard
24711 18F: (2510,) 2515, 2520, 2523, 2525, 2550, 2580, 2585, 25j10, 2610, 2620,
24715 \begin_layout Standard
24716 18F: 4220, 4221, 4320, 4321, 4331, 4410, 4420, 4423, 4431, 4450, 4455, 4480,
24720 \begin_layout Standard
24721 18F: 4510, 4515, 4520, 4523, 4525, 4550, 4580, 4585, 45j10, 4610, 4620,
24725 \begin_layout Standard
24726 18F: 6520, 6585, 6620, 6680, 66j60, 66j65, 6720, 67j60
24729 \begin_layout Standard
24730 18F: 8520, 8585, 8620, 8680, 86j60, 86j65, 8720, 87j60
24733 \begin_layout Standard
24734 18F: 96j60, 96j65, 97j60
24737 \begin_layout Standard
24739 An up-to-date list of supported devices is also available via '
24741 sdcc -mpic16 -plist
24746 \begin_layout Subsection
24750 \begin_layout Standard
24751 PIC16 port supports the standard command line arguments as supposed, with
24752 the exception of certain cases that will be mentioned in the following
24756 \begin_layout Description
24761 \begin_layout Standard
24771 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
24779 \begin_layout Standard
24791 \begin_layout Description
24796 \begin_layout Standard
24805 -fommit-frame-pointer
24806 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
24810 Frame pointer will be omitted when the function uses no local variables.
24813 \begin_layout Subsection
24814 Port Specific Options
24815 \begin_inset LatexCommand \index{Options PIC16}
24822 \begin_layout Standard
24823 The port specific options appear after the global options in the sdcc -
24827 \begin_layout Standard
24839 \begin_layout Subsubsection
24840 Code Generation Options
24843 \begin_layout Standard
24844 These options influence the generated assembler code.
24847 \begin_layout Description
24852 \begin_layout Standard
24861 -pstack-model=[model] Used in conjuction with the command above.
24862 Defines the stack model to be used, valid stack models are:
24867 \labelwidthstring 00.00.0000
24872 Selects small stack model.
24873 8 bit stack and frame pointers.
24874 Supports 256 bytes stack size.
24878 \labelwidthstring 00.00.0000
24883 Selects large stack model.
24884 16 bit stack and frame pointers.
24885 Supports 65536 bytes stack size.
24889 \begin_layout Description
24894 \begin_layout Standard
24903 -pno-banksel Do not generate BANKSEL assembler directives.
24906 \begin_layout Description
24911 \begin_layout Standard
24920 -extended Enable extended instruction set/literal offset addressing mode.
24924 \begin_layout Subsubsection
24925 Optimization Options
24928 \begin_layout Description
24933 \begin_layout Standard
24942 -obanksel=n Set optimization level for inserting BANKSELs.
24949 \labelwidthstring 00.00.0000
24954 \labelwidthstring 00.00.0000
24955 1 checks previous used register and if it is the same then does not emit
24956 BANKSEL, accounts only for labels.
24960 \labelwidthstring 00.00.0000
24961 2 tries to check the location of (even different) symbols and removes BANKSELs
24962 if they are in the same bank.
24967 Important: There might be problems if the linker script has data sections
24968 across bank borders!
24972 \begin_layout Description
24977 \begin_layout Standard
24986 -denable-peeps Force the usage of peepholes.
24990 \begin_layout Description
24995 \begin_layout Standard
25004 -no-optimize-goto Do not use (conditional) BRA instead of GOTO.
25007 \begin_layout Description
25012 \begin_layout Standard
25021 -optimize-cmp Try to optimize some compares.
25024 \begin_layout Description
25029 \begin_layout Standard
25038 -optimize-df Analyze the dataflow of the generated code and improve it.
25041 \begin_layout Subsubsection
25045 \begin_layout Description
25050 \begin_layout Standard
25059 -asm= Sets the full path and name of an external assembler to call.
25062 \begin_layout Description
25067 \begin_layout Standard
25077 \begin_inset LatexCommand \index{PIC16!MPLAB}
25081 compatibility option.
25082 Currently only suppresses special gpasm directives.
25085 \begin_layout Subsubsection
25089 \begin_layout Description
25094 \begin_layout Standard
25103 -link= Sets the full path and name of an external linker to call.
25106 \begin_layout Description
25111 \begin_layout Standard
25120 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
25121 unitialized data variables with [kword].
25122 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
25125 \begin_layout Description
25130 \begin_layout Standard
25139 -ivt-loc=n Place the interrupt vector table at address
25144 Useful for bootloaders.
25147 \begin_layout Description
25152 \begin_layout Standard
25161 -nodefaultlibs Do not link default libraries when linking.
25164 \begin_layout Description
25169 \begin_layout Standard
25178 -use-crt= Use a custom run-time module instead of the defaults.
25181 \begin_layout Description
25186 \begin_layout Standard
25195 -no-crt Don't link the default run-time modules
25198 \begin_layout Subsubsection
25202 \begin_layout Standard
25203 Debugging options enable extra debugging information in the output files.
25206 \begin_layout Description
25211 \begin_layout Standard
25220 -debug-xtra Similar to -
25224 \begin_layout Standard
25234 \begin_inset LatexCommand \index{-\/-debug}
25238 , but dumps more information.
25241 \begin_layout Description
25246 \begin_layout Standard
25255 -debug-ralloc Force register allocator to dump <source>.d file with debugging
25257 <source> is the name of the file being compiled.
25260 \begin_layout Description
25265 \begin_layout Standard
25274 -pcode-verbose Enable pcode debugging information in translation.
25277 \begin_layout Description
25282 \begin_layout Standard
25291 -calltree Dump call tree in .calltree file.
25294 \begin_layout Description
25299 \begin_layout Standard
25308 -gstack Trace push/pops for stack pointer overflow.
25311 \begin_layout Subsection
25312 Enviroment Variables
25315 \begin_layout Standard
25316 There is a number of enviromental variables that can be used when running
25317 SDCC to enable certain optimizations or force a specific program behaviour.
25318 these variables are primarily for debugging purposes so they can be enabled/dis
25322 \begin_layout Standard
25323 Currently there is only two such variables available:
25326 \begin_layout Description
25327 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
25328 bitfields is optimized by directly loading FSR0 with the address of the
25329 bitfield structure.
25330 Normally SDCC will cast the bitfield structure to a bitfield pointer and
25332 This step saves data ram and code space for functions that make heavy use
25334 (i.e., 80 bytes of code space are saved when compiling malloc.c with this
25339 \begin_layout Description
25340 NO_REG_OPT Do not perform pCode registers optimization.
25341 This should be used for debugging purposes.
25342 If bugs in the pcode optimizer are found, users can benefit from temporarily
25343 disabling the optimizer until the bug is fixed.
25346 \begin_layout Subsection
25347 Preprocessor Macros
25350 \begin_layout Standard
25352 \begin_inset LatexCommand \index{PIC16}
25356 port defines the following preprocessor macros while translating a source.
25359 \begin_layout Standard
25361 \begin_inset Tabular
25362 <lyxtabular version="3" rows="6" columns="2">
25364 <column alignment="center" valignment="top" leftline="true" width="0">
25365 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25366 <row topline="true" bottomline="true">
25367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25370 \begin_layout Standard
25376 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25379 \begin_layout Standard
25386 <row topline="true">
25387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25390 \begin_layout Standard
25396 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25399 \begin_layout Standard
25400 Port identification
25406 <row topline="true">
25407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25410 \begin_layout Standard
25415 \begin_layout Standard
25429 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25432 \begin_layout Standard
25433 Port identification (same as above)
25439 <row topline="true">
25440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25443 \begin_layout Standard
25449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25452 \begin_layout Standard
25453 MCU Identification.
25458 is the microcontrol identification number, i.e.
25465 <row topline="true">
25466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25469 \begin_layout Standard
25474 \begin_layout Standard
25488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25491 \begin_layout Standard
25492 MCU Identification (same as above)
25498 <row topline="true" bottomline="true">
25499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25502 \begin_layout Standard
25508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25511 \begin_layout Standard
25512 nnn = SMALL or LARGE respectively according to the stack model used
25525 \begin_layout Standard
25527 In addition the following macros are defined when calling assembler:
25530 \begin_layout Standard
25532 \begin_inset Tabular
25533 <lyxtabular version="3" rows="4" columns="2">
25535 <column alignment="center" valignment="top" leftline="true" width="0">
25536 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25537 <row topline="true" bottomline="true">
25538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25541 \begin_layout Standard
25547 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25550 \begin_layout Standard
25557 <row topline="true">
25558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25561 \begin_layout Standard
25567 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25570 \begin_layout Standard
25571 MCU Identification.
25576 is the microcontrol identification number, i.e.
25583 <row topline="true">
25584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25587 \begin_layout Standard
25593 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25596 \begin_layout Standard
25597 nnn = SMALL or LARGE respectively according to the memory model used for
25604 <row topline="true" bottomline="true">
25605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25608 \begin_layout Standard
25614 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25617 \begin_layout Standard
25618 nnn = SMALL or LARGE respectively according to the stack model used
25631 \begin_layout Subsection
25635 \begin_layout Standard
25637 \begin_inset LatexCommand \index{PIC16}
25641 port uses the following directories for searching header files and libraries.
25644 \begin_layout Standard
25646 \begin_inset Tabular
25647 <lyxtabular version="3" rows="3" columns="4">
25649 <column alignment="center" valignment="top" leftline="true" width="0">
25650 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25651 <column alignment="center" valignment="top" width="0">
25652 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25653 <row topline="true" bottomline="true">
25654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25657 \begin_layout Standard
25663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25666 \begin_layout Standard
25672 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25675 \begin_layout Standard
25681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25684 \begin_layout Standard
25691 <row topline="true">
25692 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25695 \begin_layout Standard
25696 PREFIX/sdcc/include/pic16
25701 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25704 \begin_layout Standard
25705 PIC16 specific headers
25710 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25713 \begin_layout Standard
25719 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25722 \begin_layout Standard
25729 <row topline="true" bottomline="true">
25730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25733 \begin_layout Standard
25734 PREFIX/sdcc/lib/pic16
25739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25742 \begin_layout Standard
25743 PIC16 specific libraries
25748 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25751 \begin_layout Standard
25757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25760 \begin_layout Standard
25774 \begin_layout Subsection
25776 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
25783 \begin_layout Standard
25785 \begin_inset LatexCommand \index{PIC16}
25789 port currently supports the following pragmas:
25792 \begin_layout Description
25794 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
25798 This forces the code generator to initialize the stack & frame pointers
25799 at a specific address.
25800 This is an ad hoc solution for cases where no STACK directive is available
25801 in the linker script or gplink is not instructed to create a stack section.
25804 stack pragma should be used only once in a project.
25805 Multiple pragmas may result in indeterminate behaviour of the program.
25809 \begin_layout Standard
25810 The old format (ie.
25811 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
25812 cross page boundaries (or even exceed the available data RAM) and crash
25814 Make sure that stack does not cross page boundaries when using the SMALL
25822 The format is as follows:
25827 \begin_layout LyX-Code
25828 #pragma stack bottom_address [stack_size]
25833 \begin_layout Standard
25838 is the lower bound of the stack section.
25839 The stack pointer initially will point at address (bottom_address+stack_size-1).
25842 \begin_layout LyX-Code
25846 \begin_layout LyX-Code
25850 \begin_layout LyX-Code
25851 /* initializes stack of 100 bytes at RAM address 0x200 */
25854 \begin_layout LyX-Code
25855 #pragma stack 0x200 100
25858 \begin_layout Standard
25859 If the stack_size field is omitted then a stack is created with the default
25861 This size might be enough for most programs, but its not enough for operations
25862 with deep function nesting or excessive stack usage.
25865 \begin_layout Description
25867 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
25871 Force a function to a static FLASH address.
25874 \begin_layout LyX-Code
25878 \begin_layout LyX-Code
25882 \begin_layout LyX-Code
25883 /* place function test_func at 0x4000 */
25886 \begin_layout LyX-Code
25887 #pragma code test_func 0x4000
25890 \begin_layout LyX-Code
25894 \begin_layout Description
25895 library instructs the linker to use a library module.
25900 \begin_layout LyX-Code
25901 #pragma library module_name
25904 \begin_layout Standard
25909 can be any library or object file (including its path).
25910 Note that there are four reserved keywords which have special meaning.
25914 \begin_layout Standard
25916 \begin_inset Tabular
25917 <lyxtabular version="3" rows="6" columns="3">
25919 <column alignment="center" valignment="top" leftline="true" width="0">
25920 <column alignment="block" valignment="top" leftline="true" width="20page%">
25921 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
25922 <row topline="true" bottomline="true">
25923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25926 \begin_layout Standard
25932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25935 \begin_layout Standard
25941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25944 \begin_layout Standard
25951 <row topline="true">
25952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25955 \begin_layout Standard
25963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25966 \begin_layout Standard
25967 ignore all library pragmas
25972 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25975 \begin_layout Standard
25984 <row topline="true">
25985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25988 \begin_layout Standard
25996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25999 \begin_layout Standard
26005 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26008 \begin_layout Standard
26019 <row topline="true">
26020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26023 \begin_layout Standard
26031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26034 \begin_layout Standard
26035 link the Math libarary
26040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26043 \begin_layout Standard
26054 <row topline="true">
26055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26058 \begin_layout Standard
26066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26069 \begin_layout Standard
26070 link the I/O library
26075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26078 \begin_layout Standard
26089 <row topline="true" bottomline="true">
26090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26093 \begin_layout Standard
26101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26104 \begin_layout Standard
26105 link the debug library
26110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26113 \begin_layout Standard
26130 * is the device number, i.e.
26131 452 for PIC18F452 MCU.
26134 \begin_layout Standard
26136 This feature allows for linking with specific libraries withoug having to
26137 explicit name them in the command line.
26142 keyword will reject all modules specified by the library pragma.
26145 \begin_layout Description
26146 udata The pragma udata instructs the compiler to emit code so that linker
26147 will place a variable at a specific memory bank.
26150 \begin_layout LyX-Code
26154 \begin_layout LyX-Code
26158 \begin_layout LyX-Code
26159 /* places variable foo at bank2 */
26162 \begin_layout LyX-Code
26163 #pragma udata bank2 foo
26166 \begin_layout LyX-Code
26170 \begin_layout Standard
26171 In order for this pragma to work extra SECTION directives should be added
26172 in the .lkr script.
26173 In the following example a sample .lkr file is shown:
26176 \begin_layout LyX-Code
26180 \begin_layout LyX-Code
26181 // Sample linker script for the PIC18F452 processor
26184 \begin_layout LyX-Code
26188 \begin_layout LyX-Code
26189 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
26192 \begin_layout LyX-Code
26193 CODEPAGE NAME=page START=0x2A END=0x7FFF
26196 \begin_layout LyX-Code
26197 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
26200 \begin_layout LyX-Code
26201 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
26204 \begin_layout LyX-Code
26205 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
26208 \begin_layout LyX-Code
26209 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
26212 \begin_layout LyX-Code
26213 ACCESSBANK NAME=accessram START=0x0 END=0x7F
26216 \begin_layout LyX-Code
26220 \begin_layout LyX-Code
26221 DATABANK NAME=gpr0 START=0x80 END=0xFF
26224 \begin_layout LyX-Code
26225 DATABANK NAME=gpr1 START=0x100 END=0x1FF
26228 \begin_layout LyX-Code
26229 DATABANK NAME=gpr2 START=0x200 END=0x2FF
26232 \begin_layout LyX-Code
26233 DATABANK NAME=gpr3 START=0x300 END=0x3FF
26236 \begin_layout LyX-Code
26237 DATABANK NAME=gpr4 START=0x400 END=0x4FF
26240 \begin_layout LyX-Code
26241 DATABANK NAME=gpr5 START=0x500 END=0x5FF
26244 \begin_layout LyX-Code
26245 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
26248 \begin_layout LyX-Code
26252 \begin_layout LyX-Code
26253 SECTION NAME=CONFIG ROM=config
26256 \begin_layout LyX-Code
26260 \begin_layout LyX-Code
26261 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
26264 \begin_layout LyX-Code
26265 SECTION NAME=bank1 RAM=gpr1 # should be added to link
26268 \begin_layout LyX-Code
26269 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
26272 \begin_layout LyX-Code
26273 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
26276 \begin_layout LyX-Code
26277 SECTION NAME=bank4 RAM=gpr4
26280 \begin_layout LyX-Code
26281 SECTION NAME=bank5 RAM=gpr5
26284 \begin_layout Standard
26285 The linker will recognise the section name set in the pragma statement and
26286 will position the variable at the memory bank set with the RAM field at
26287 the SECTION line in the linker script file.
26290 \begin_layout Subsection
26292 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
26299 \begin_layout Standard
26300 There is one main header file
26301 \begin_inset LatexCommand \index{PIC16!Header files}
26305 that can be included to the source files using the pic16
26306 \begin_inset LatexCommand \index{PIC16}
26316 This header file contains the definitions for the processor special registers,
26317 so it is necessary if the source accesses them.
26318 It can be included by adding the following line in the beginning of the
26322 \begin_layout LyX-Code
26323 #include <pic18fregs.h>
26326 \begin_layout Standard
26327 The specific microcontroller is selected within the pic18fregs.h automatically,
26328 so the same source can be used with a variety of devices.
26331 \begin_layout Subsection
26333 \begin_inset LatexCommand \label{sub:pic16Libraries}
26340 \begin_layout Standard
26342 \begin_inset LatexCommand \index{PIC16!Libraries}
26347 \begin_inset LatexCommand \index{PIC16}
26351 port depends on are the microcontroller device libraries which contain
26352 the symbol definitions for the microcontroller special function registers.
26353 These libraries have the format pic18fxxxx.lib, where
26357 is the microcontroller identification number.
26358 The specific library is selected automatically by the compiler at link
26359 stage according to the selected device.
26362 \begin_layout Standard
26364 Libraries are created with gplib which is part of the gputils package
26365 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
26372 \begin_layout Subsubsection*
26373 Building the libraries
26376 \begin_layout Standard
26377 Before using SDCC/pic16 there are some libraries that need to be compiled.
26378 This process is done automatically if gputils are found at SDCC's compile
26380 Should you require to rebuild the pic16 libraries manually, these are the
26381 steps required to do so under Linux or Mac OS X (cygwin might work as well,
26385 \begin_layout LyX-Code
26386 cd device/lib/pic16
26389 \begin_layout LyX-Code
26393 \begin_layout LyX-Code
26397 \begin_layout LyX-Code
26401 \begin_layout LyX-Code
26402 su -c 'make install' # install the libraries, you need the root password
26405 \begin_layout LyX-Code
26409 \begin_layout Standard
26410 If you need to install the headers too, do:
26413 \begin_layout LyX-Code
26417 \begin_layout LyX-Code
26418 su -c 'make install' # install the headers, you need the root password
26421 \begin_layout Subsection
26422 Adding New Devices to the Port
26425 \begin_layout Standard
26426 Adding support for a new 16
26430 \begin_layout Standard
26439 bit PIC MCU requires the following steps:
26442 \begin_layout Enumerate
26443 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
26447 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
26451 \begin_layout Enumerate
26454 mv picDEVICE.h /path/to/sdcc/device/include/pic16
26457 \begin_layout Enumerate
26460 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
26463 \begin_layout Enumerate
26466 /path/to/sdcc/device/lib/pic16/pics.all
26470 Note: No 18f prefix here!
26473 \begin_layout Enumerate
26476 /path/to/sdcc/device/include/pic16/adc.h
26480 Add the new devices to the correct ADC style class (depending on the number
26487 if the device does not offer any ADC at all.
26490 \begin_layout Enumerate
26493 /path/to/sdcc/device/include/pic16/pic18fregs.h
26497 The file format is self-explanatory, just add
26501 #elif defined(picDEVICE)
26507 \begin_layout Standard
26518 include <picDEVICE.h>
26522 at the right place (keep the file sorted, please).
26525 \begin_layout Enumerate
26528 /path/to/sdcc/device/include/pic16devices.txt
26532 Copy and modify an existing entry or create a new one and insert it at the
26533 correct place (keep the file sorted, please).
26536 \begin_layout Enumerate
26539 /path/to/sdcc/device/lib/pic16/libdev/Makefile.am
26543 Copy an existing entry and adjust the device name.
26546 \begin_layout Enumerate
26549 /path/to/sdcc/device/lib/pic16/libio/Makefile.am
26553 Copy the record from the 18f2220 and adjust the device name.
26556 does not offer ADC, I
26557 \begin_inset Formula $^{\text{2}}$
26560 C, and/or (E)USART functionality as assumed by the library, remove the lines
26576 \begin_layout Enumerate
26595 /path/to/sdcc/device/lib/pic16
26600 \begin_layout Enumerate
26601 Recompile the pic16 libraries as described in
26602 \begin_inset LatexCommand \ref{sub:pic16Libraries}
26609 \begin_layout Subsection
26613 \begin_layout Standard
26614 The following memory models are supported by the PIC16 port:
26617 \begin_layout Itemize
26621 \begin_layout Itemize
26625 \begin_layout Standard
26626 Memory model affects the default size of pointers within the source.
26627 The sizes are shown in the next table:
26630 \begin_layout Standard
26632 \begin_inset Tabular
26633 <lyxtabular version="3" rows="3" columns="3">
26635 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26636 <column alignment="center" valignment="top" leftline="true" width="0">
26637 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26638 <row topline="true" bottomline="true">
26639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26642 \begin_layout Standard
26643 Pointer sizes according to memory model
26648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26651 \begin_layout Standard
26657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26660 \begin_layout Standard
26667 <row topline="true" bottomline="true">
26668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26671 \begin_layout Standard
26677 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26680 \begin_layout Standard
26686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26689 \begin_layout Standard
26696 <row topline="true" bottomline="true">
26697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26700 \begin_layout Standard
26706 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
26709 \begin_layout Standard
26715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26718 \begin_layout Standard
26732 \begin_layout Standard
26733 It is advisable that all sources within a project are compiled with the
26735 If one wants to override the default memory model, this can be done by
26736 declaring a pointer as
26745 Far selects large memory model's pointers, while near selects small memory
26749 \begin_layout Standard
26750 The standard device libraries (see
26751 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
26755 ) contain no reference to pointers, so they can be used with both memory
26759 \begin_layout Subsection
26763 \begin_layout Standard
26765 \begin_inset LatexCommand \index{PIC16!stack}
26769 implementation for the PIC16 port uses two indirect registers, FSR1 and
26773 \begin_layout Description
26774 FSR1 is assigned as stack pointer
26777 \begin_layout Description
26778 FSR2 is assigned as frame pointer
26781 \begin_layout Standard
26782 The following stack models are supported by the PIC16 port
26785 \begin_layout Itemize
26793 \begin_layout Itemize
26801 \begin_layout Standard
26806 model means that only the FSRxL byte is used to access stack and frame,
26813 uses both FSRxL and FSRxH registers.
26814 The following table shows the stack/frame pointers sizes according to stack
26815 model and the maximum space they can address:
26818 \begin_layout Standard
26820 \begin_inset Tabular
26821 <lyxtabular version="3" rows="3" columns="3">
26823 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26824 <column alignment="center" valignment="top" leftline="true" width="0">
26825 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26826 <row topline="true" bottomline="true">
26827 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26830 \begin_layout Standard
26831 Stack & Frame pointer sizes according to stack model
26836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26839 \begin_layout Standard
26845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26848 \begin_layout Standard
26855 <row topline="true">
26856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26859 \begin_layout Standard
26865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26868 \begin_layout Standard
26874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26877 \begin_layout Standard
26884 <row topline="true" bottomline="true">
26885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26888 \begin_layout Standard
26894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26897 \begin_layout Standard
26903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26906 \begin_layout Standard
26920 \begin_layout Standard
26926 stack model is currently not working properly throughout the code generator.
26927 So its use is not advised.
26928 Also there are some other points that need special care:
26933 \begin_layout Enumerate
26934 Do not create stack sections with size more than one physical bank (that
26938 \begin_layout Enumerate
26939 Stack sections should no cross physical bank limits (i.e.
26940 #pragma stack 0x50 0x100)
26943 \begin_layout Standard
26944 These limitations are caused by the fact that only FSRxL is modified when
26945 using SMALL stack model, so no more than 256 bytes of stack can be used.
26946 This problem will disappear after LARGE model is fully implemented.
26949 \begin_layout Subsection
26953 \begin_layout Standard
26954 In addition to the standard SDCC function keywords, PIC16
26955 \begin_inset LatexCommand \index{PIC16}
26959 port makes available two more:
26962 \begin_layout Description
26964 \begin_inset LatexCommand \index{PIC16!wparam}
26968 Use the WREG to pass one byte of the first function argument.
26969 This improves speed but you may not use this for functions with arguments
26970 that are called via function pointers, otherwise the first byte of the
26971 first parameter will get lost.
26975 \begin_layout LyX-Code
26976 void func_wparam(int a) wparam
26979 \begin_layout LyX-Code
26983 \begin_layout LyX-Code
26984 /* WREG hold the lower part of a */
26987 \begin_layout LyX-Code
26988 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
26992 \begin_layout LyX-Code
26996 \begin_layout LyX-Code
27000 \begin_layout Description
27002 \begin_inset LatexCommand \index{PIC16!shadowregs}
27006 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
27007 hardware shadow registers which hold the values of WREG, STATUS and BSR
27009 This can be done by adding the keyword
27017 keyword in the function's header.
27020 \begin_layout LyX-Code
27021 void isr_shadow(void) shadowregs interrupt 1
27024 \begin_layout LyX-Code
27028 \begin_layout LyX-Code
27032 \begin_layout LyX-Code
27036 \begin_layout Standard
27041 instructs the code generator not to store/restore WREG, STATUS, BSR when
27042 entering/exiting the ISR.
27045 \begin_layout Subsection
27046 Function return values
27049 \begin_layout Standard
27050 Return values from functions are placed to the appropriate registers following
27051 a modified Microchip policy optimized for SDCC.
27052 The following table shows these registers:
27055 \begin_layout Standard
27057 \begin_inset Tabular
27058 <lyxtabular version="3" rows="6" columns="2">
27060 <column alignment="center" valignment="top" leftline="true" width="0">
27061 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27062 <row topline="true" bottomline="true">
27063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27066 \begin_layout Standard
27072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27075 \begin_layout Standard
27076 destination register
27082 <row topline="true">
27083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27086 \begin_layout Standard
27092 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27095 \begin_layout Standard
27102 <row topline="true">
27103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27106 \begin_layout Standard
27112 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27115 \begin_layout Standard
27122 <row topline="true">
27123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27126 \begin_layout Standard
27132 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27135 \begin_layout Standard
27142 <row topline="true">
27143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27146 \begin_layout Standard
27152 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27155 \begin_layout Standard
27156 FSR0L:PRODH:PRODL:WREG
27162 <row topline="true" bottomline="true">
27163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27166 \begin_layout Standard
27172 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27175 \begin_layout Standard
27176 on stack, FSR0 points to the beginning
27189 \begin_layout Subsection
27193 \begin_layout Standard
27195 \begin_inset LatexCommand \index{PIC16!interrupt}
27199 service routine (ISR) is declared using the
27206 \begin_layout LyX-Code
27207 void isr(void) interrupt
27212 \begin_layout LyX-Code
27216 \begin_layout LyX-Code
27220 \begin_layout LyX-Code
27224 \begin_layout Standard
27229 is the interrupt number, which for PIC18F devices can be:
27232 \begin_layout Standard
27234 \begin_inset Tabular
27235 <lyxtabular version="3" rows="4" columns="3">
27237 <column alignment="center" valignment="top" leftline="true" width="0">
27238 <column alignment="center" valignment="top" leftline="true" width="0">
27239 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27240 <row topline="true" bottomline="true">
27241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27244 \begin_layout Standard
27252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27255 \begin_layout Standard
27261 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27264 \begin_layout Standard
27265 Interrupt Vector Address
27271 <row topline="true">
27272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27275 \begin_layout Standard
27281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27284 \begin_layout Standard
27290 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27293 \begin_layout Standard
27300 <row topline="true">
27301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27304 \begin_layout Standard
27319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27322 \begin_layout Standard
27332 HIGH priority interrupts
27337 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27340 \begin_layout Standard
27347 <row topline="true" bottomline="true">
27348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27351 \begin_layout Standard
27357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27360 \begin_layout Standard
27361 LOW priority interrupts
27366 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27369 \begin_layout Standard
27383 \begin_layout Standard
27384 When generating assembly code for ISR the code generator places a
27390 Interrupt Vector Address
27392 which points at the genetated ISR.
27393 This single GOTO instruction is part of an automatically generated
27395 interrupt entry point
27398 The actuall ISR code is placed as normally would in the code space.
27399 Upon interrupt request, the GOTO instruction is executed which jumps to
27401 When declaring interrupt functions as _naked this GOTO instruction is
27406 The whole interrupt functions is therefore placed at the Interrupt Vector
27407 Address of the specific interrupt.
27408 This is not a problem for the LOW priority interrupts, but it is a problem
27409 for the RESET and the HIGH priority interrupts because code may be written
27410 at the next interrupt's vector address and cause undeterminate program
27411 behaviour if that interrupt is raised.
27415 \begin_layout Standard
27416 This is not a problem when
27419 \begin_layout Enumerate
27420 this is a HIGH interrupt ISR and LOW interrupts are
27427 \begin_layout Enumerate
27428 when the ISR is small enough not to reach the next interrupt's vector address.
27436 \begin_layout Standard
27442 This way a function is generated similar to an ISR, but it is not assigned
27446 \begin_layout Standard
27447 When entering an interrupt, currently the PIC16
27448 \begin_inset LatexCommand \index{PIC16}
27452 port automatically saves the following registers:
27455 \begin_layout Itemize
27459 \begin_layout Itemize
27463 \begin_layout Itemize
27467 \begin_layout Itemize
27468 PROD (PRODL and PRODH)
27471 \begin_layout Itemize
27472 FSR0 (FSR0L and FSR0H)
27475 \begin_layout Standard
27476 These registers are restored upon return from the interrupt routine.
27480 \begin_layout Standard
27481 NOTE that when the _naked attribute is specified for an interrupt routine,
27482 then NO registers are stored or restored.
27490 \begin_layout Subsection
27494 \begin_layout Standard
27495 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
27496 There are 3 types of generic pointers currently implemented data, code
27497 and eeprom pointers.
27498 They are differentiated by the value of the 7th and 6th bits of the upper
27502 \begin_layout Standard
27504 \begin_inset Tabular
27505 <lyxtabular version="3" rows="5" columns="5">
27507 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27508 <column alignment="center" valignment="top" width="0">
27509 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27510 <column alignment="center" valignment="top" width="0">
27511 <column alignment="left" valignment="top" rightline="true" width="0">
27512 <row topline="true" bottomline="true">
27513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27516 \begin_layout Standard
27522 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27525 \begin_layout Standard
27531 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27534 \begin_layout Standard
27540 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27543 \begin_layout Standard
27544 rest of the pointer
27549 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27552 \begin_layout Standard
27559 <row topline="true" bottomline="true">
27560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27563 \begin_layout Standard
27569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27572 \begin_layout Standard
27578 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27581 \begin_layout Standard
27587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27590 \begin_layout Standard
27595 uuuuuu uuuuxxxx xxxxxxxx
27600 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27603 \begin_layout Standard
27604 a 12-bit data pointer in data RAM memory
27610 <row bottomline="true">
27611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27614 \begin_layout Standard
27620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27623 \begin_layout Standard
27629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27632 \begin_layout Standard
27638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27641 \begin_layout Standard
27646 uxxxxx xxxxxxxx xxxxxxxx
27651 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27654 \begin_layout Standard
27655 a 21-bit code pointer in FLASH memory
27661 <row bottomline="true">
27662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27665 \begin_layout Standard
27671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27674 \begin_layout Standard
27680 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27683 \begin_layout Standard
27689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27692 \begin_layout Standard
27697 uuuuuu uuuuuuxx xxxxxxxx
27702 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27705 \begin_layout Standard
27706 a 10-bit eeprom pointer in EEPROM memory
27712 <row bottomline="true">
27713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27716 \begin_layout Standard
27722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27725 \begin_layout Standard
27731 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27734 \begin_layout Standard
27740 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27743 \begin_layout Standard
27748 xxxxxx xxxxxxxx xxxxxxxx
27753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27756 \begin_layout Standard
27757 unimplemented pointer type
27770 \begin_layout Standard
27772 Generic pointer are read and written with a set of library functions which
27773 read/write 1, 2, 3, 4 bytes.
27776 \begin_layout Subsection
27780 \begin_layout Subsubsection
27781 Standard I/O Streams
27784 \begin_layout Standard
27789 the type FILE is defined as:
27792 \begin_layout LyX-Code
27793 typedef char * FILE;
27796 \begin_layout Standard
27797 This type is the stream type implemented I/O in the PIC18F devices.
27798 Also the standard input and output streams are declared in stdio.h:
27801 \begin_layout LyX-Code
27802 extern FILE * stdin;
27805 \begin_layout LyX-Code
27806 extern FILE * stdout;
27809 \begin_layout Standard
27810 The FILE type is actually a generic pointer which defines one more type
27811 of generic pointers, the
27816 This new type has the format:
27819 \begin_layout Standard
27822 \begin_inset Tabular
27823 <lyxtabular version="3" rows="2" columns="7">
27825 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27826 <column alignment="center" valignment="top" width="0">
27827 <column alignment="center" valignment="top" leftline="true" width="0">
27828 <column alignment="center" valignment="top" leftline="true" width="0">
27829 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27830 <column alignment="center" valignment="top" width="0">
27831 <column alignment="left" valignment="top" rightline="true" width="0">
27832 <row topline="true" bottomline="true">
27833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27836 \begin_layout Standard
27842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27845 \begin_layout Standard
27851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27854 \begin_layout Standard
27860 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27863 \begin_layout Standard
27869 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27872 \begin_layout Standard
27878 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27881 \begin_layout Standard
27882 rest of the pointer
27887 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27890 \begin_layout Standard
27897 <row topline="true" bottomline="true">
27898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27901 \begin_layout Standard
27907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27910 \begin_layout Standard
27916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27919 \begin_layout Standard
27925 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27928 \begin_layout Standard
27934 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27937 \begin_layout Standard
27943 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27946 \begin_layout Standard
27956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27959 \begin_layout Standard
27960 upper byte high nubble is 0x2n, the rest are zeroes
27973 \begin_layout Standard
27975 Currently implemented there are 3 types of streams defined:
27978 \begin_layout Standard
27981 \begin_inset Tabular
27982 <lyxtabular version="3" rows="4" columns="4">
27984 <column alignment="center" valignment="top" leftline="true" width="0">
27985 <column alignment="center" valignment="top" leftline="true" width="0">
27986 <column alignment="center" valignment="top" leftline="true" width="0">
27987 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27988 <row topline="true" bottomline="true">
27989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27992 \begin_layout Standard
27998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28001 \begin_layout Standard
28007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28010 \begin_layout Standard
28016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28019 \begin_layout Standard
28026 <row topline="true">
28027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28030 \begin_layout Standard
28036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28039 \begin_layout Standard
28047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28050 \begin_layout Standard
28056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28059 \begin_layout Standard
28060 Writes/Reads characters via the USART peripheral
28066 <row topline="true">
28067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28070 \begin_layout Standard
28076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28079 \begin_layout Standard
28087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28090 \begin_layout Standard
28096 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28099 \begin_layout Standard
28100 Writes/Reads characters via the MSSP peripheral
28106 <row topline="true" bottomline="true">
28107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28110 \begin_layout Standard
28116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28119 \begin_layout Standard
28127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28130 \begin_layout Standard
28136 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28139 \begin_layout Standard
28140 Writes/Reads characters via used defined functions
28153 \begin_layout Standard
28155 The stream identifiers are declared as macros in the stdio.h header.
28158 \begin_layout Standard
28160 In the libc library there exist the functions that are used to write to
28161 each of the above streams.
28165 \begin_layout Description
28170 \begin_layout Standard
28179 _stream_usart_putchar writes a character at the USART stream
28182 \begin_layout Description
28187 \begin_layout Standard
28196 _stream_mssp_putchar writes a character at the MSSP stream
28199 \begin_layout Description
28200 putchar dummy function.
28201 This writes a character to a user specified manner.
28204 \begin_layout Standard
28205 In order to increase performance
28209 is declared in stdio.h as having its parameter in WREG (it has the wparam
28211 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
28212 in a user-friendly way.
28217 is the name of the variable that holds the character to print.
28218 An example follows:
28221 \begin_layout LyX-Code
28222 #include <pic18fregs.h>
28231 \begin_layout LyX-Code
28235 \begin_layout LyX-Code
28236 PORTA = c; /* dump character c to PORTA */
28239 \begin_layout LyX-Code
28247 \begin_layout LyX-Code
28251 \begin_layout LyX-Code
28252 stdout = STREAM_USER; /* this is not necessary, since stdout points
28255 \begin_layout LyX-Code
28256 * by default to STREAM_USER */
28259 \begin_layout LyX-Code
28261 \begin_inset Quotes sld
28264 This is a printf test
28267 \begin_inset Quotes srd
28273 \begin_layout LyX-Code
28277 \begin_layout LyX-Code
28281 \begin_layout Subsubsection
28285 \begin_layout Standard
28286 PIC16 contains an implementation of the printf-family of functions.
28287 There exist the following functions:
28290 \begin_layout LyX-Code
28291 extern unsigned int sprintf(char *buf, char *fmt, ...);
28294 \begin_layout LyX-Code
28295 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
28298 \begin_layout LyX-Code
28302 \begin_layout LyX-Code
28303 extern unsigned int printf(char *fmt, ...);
28306 \begin_layout LyX-Code
28307 extern unsigned int vprintf(char *fmt, va_lista ap);
28310 \begin_layout LyX-Code
28314 \begin_layout LyX-Code
28315 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
28318 \begin_layout LyX-Code
28319 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
28322 \begin_layout Standard
28323 For sprintf and vsprintf
28327 should normally be a data pointer where the resulting string will be placed.
28328 No range checking is done so the user should allocate the necessery buffer.
28329 For fprintf and vfprintf
28333 should be a stream pointer (i.e.
28334 stdout, STREAM_MSSP, etc...).
28337 \begin_layout Subsubsection
28341 \begin_layout Standard
28342 The PIC18F family of microcontrollers supports a number of interrupt sources.
28343 A list of these interrupts is shown in the following table:
28346 \begin_layout Standard
28348 \begin_inset Tabular
28349 <lyxtabular version="3" rows="11" columns="4">
28351 <column alignment="left" valignment="top" leftline="true" width="0">
28352 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28353 <column alignment="left" valignment="top" leftline="true" width="0">
28354 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28355 <row topline="true" bottomline="true">
28356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28359 \begin_layout Standard
28365 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28368 \begin_layout Standard
28374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28377 \begin_layout Standard
28383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28386 \begin_layout Standard
28393 <row topline="true">
28394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28397 \begin_layout Standard
28403 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28406 \begin_layout Standard
28407 PORTB change interrupt
28412 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28415 \begin_layout Standard
28421 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28424 \begin_layout Standard
28425 EEPROM/FLASH write complete interrupt
28431 <row topline="true">
28432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28435 \begin_layout Standard
28441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28444 \begin_layout Standard
28445 INT0 external interrupt
28450 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28453 \begin_layout Standard
28459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28462 \begin_layout Standard
28463 Bus collision interrupt
28469 <row topline="true">
28470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28473 \begin_layout Standard
28479 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28482 \begin_layout Standard
28483 INT1 external interrupt
28488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28491 \begin_layout Standard
28497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28500 \begin_layout Standard
28501 Low voltage detect interrupt
28507 <row topline="true">
28508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28511 \begin_layout Standard
28517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28520 \begin_layout Standard
28521 INT2 external interrupt
28526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28529 \begin_layout Standard
28535 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28538 \begin_layout Standard
28539 Parallel slave port interrupt
28545 <row topline="true">
28546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28549 \begin_layout Standard
28555 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28558 \begin_layout Standard
28559 CCP1 module interrupt
28564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28567 \begin_layout Standard
28573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28576 \begin_layout Standard
28577 AD convertion complete interrupt
28583 <row topline="true">
28584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28587 \begin_layout Standard
28593 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28596 \begin_layout Standard
28597 CCP2 module interrupt
28602 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28605 \begin_layout Standard
28611 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28614 \begin_layout Standard
28615 USART receive interrupt
28621 <row topline="true">
28622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28625 \begin_layout Standard
28631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28634 \begin_layout Standard
28635 TMR0 overflow interrupt
28640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28643 \begin_layout Standard
28649 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28652 \begin_layout Standard
28653 USART transmit interrupt
28659 <row topline="true">
28660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28663 \begin_layout Standard
28669 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28672 \begin_layout Standard
28673 TMR1 overflow interrupt
28678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28681 \begin_layout Standard
28687 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28690 \begin_layout Standard
28691 SSP receive/transmit interrupt
28697 <row topline="true">
28698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28701 \begin_layout Standard
28707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28710 \begin_layout Standard
28711 TMR2 matches PR2 interrupt
28716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28719 \begin_layout Standard
28725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28728 \begin_layout Standard
28735 <row topline="true" bottomline="true">
28736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28739 \begin_layout Standard
28745 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28748 \begin_layout Standard
28749 TMR3 overflow interrupt
28754 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28757 \begin_layout Standard
28763 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28766 \begin_layout Standard
28780 \begin_layout Standard
28782 The prototypes for these names are defined in the header file
28789 \begin_layout Standard
28791 In order to simplify signal handling, a number of macros is provided:
28795 \labelwidthstring 00.00.0000
28796 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
28797 high priority interrupts.
28802 is the function name to use.
28806 \labelwidthstring 00.00.0000
28807 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
28808 low priority interrupt.
28813 is the function name to use.
28817 \labelwidthstring 00.00.0000
28818 DEF_HANDLER(sig,handler) define a handler for signal
28824 \labelwidthstring 00.00.0000
28825 END_DEF end the declaration of the dispatch table.
28828 \begin_layout Standard
28829 Additionally there are two more macros to simplify the declaration of the
28834 \labelwidthstring 00.00.0000
28837 SIGHANDLER(handler)
28839 this declares the function prototype for the
28847 \labelwidthstring 00.00.0000
28848 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
28851 \begin_layout Standard
28852 An example of using the macros above is shown below:
28855 \begin_layout LyX-Code
28856 #include <pic18fregs.h>
28859 \begin_layout LyX-Code
28860 #include <signal.h>
28864 DEF_INTHIGH(high_int)
28867 \begin_layout LyX-Code
28868 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
28871 \begin_layout LyX-Code
28872 DEF_HANDLER(SIG_BCOL, _bcol_handler)
28875 \begin_layout LyX-Code
28880 SIGHANDLER(_tmr0_handler)
28883 \begin_layout LyX-Code
28887 \begin_layout LyX-Code
28888 /* action to be taken when timer 0 overflows */
28891 \begin_layout LyX-Code
28896 SIGHANDLERNAKED(_bcol_handler)
28899 \begin_layout LyX-Code
28903 \begin_layout LyX-Code
28907 \begin_layout LyX-Code
28908 /* action to be taken when bus collision occurs */
28911 \begin_layout LyX-Code
28915 \begin_layout LyX-Code
28919 \begin_layout LyX-Code
28923 \begin_layout Standard
28928 Special care should be taken when using the above scheme:
28931 \begin_layout Itemize
28932 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
28935 \begin_layout Itemize
28936 when declaring SIGHANDLERNAKED handler never forget to use
28940 for proper returning.
28943 \begin_layout Subsection
28947 \begin_layout Standard
28948 Here you can find some general tips for compiling programs with SDCC/pic16.
28951 \begin_layout Subsubsection
28955 \begin_layout Standard
28957 \begin_inset LatexCommand \index{PIC16!stack}
28961 size (that is 64 bytes) probably is enough for many programs.
28962 One must take care that when there are many levels of function nesting,
28963 or there is excessive usage of stack, its size should be extended.
28964 An example of such a case is the printf/sprintf family of functions.
28965 If you encounter problems like not being able to print integers, then you
28966 need to set the stack size around the maximum (256 for small stack model).
28967 The following diagram shows what happens when calling printf to print an
28971 \begin_layout LyX-Code
28972 printf () --> ltoa () --> ultoa () --> divschar ()
28975 \begin_layout Standard
28976 It is should be understood that stack is easily consumed when calling complicate
28978 Using command line arguments like -
28982 \begin_layout Standard
28991 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
28993 Other ways to reduce stack usage may exist.
28996 \begin_layout Subsection
29000 \begin_layout Subsubsection
29001 Extended Instruction Set
29004 \begin_layout Standard
29005 The PIC16 port emits code which is incompatible with the extended instruction
29006 set available with many newer devices.
29007 Make sure to always explicitly disable it, usually using
29010 \begin_layout Standard
29013 static __code char __at(__CONFIG4L) conf4l = /* more flags & */ _XINST_OFF_4L;
29016 \begin_layout Standard
29018 Some devices (namely 18f2455, 18f2550, 18f4455, and 18f4550) use _ENHCPU_OFF_4L
29019 instead of _XINST_OFF_4L.
29022 \begin_layout Subsubsection
29026 \begin_layout Standard
29027 The PIC16 port currently passes most but not all of the tests in SDCC's
29029 \begin_inset LatexCommand \index{Regression test (PIC16)}
29034 \begin_inset LatexCommand \ref{sec:Quality-control}
29038 ), thus no automatic regression tests are currently performed for the PIC16
29042 \begin_layout Chapter
29046 \begin_layout Standard
29047 There are several approaches to debugging your code.
29048 This chapter is meant to show your options and to give detail on some of
29053 When writing your code:
29056 \begin_layout Itemize
29057 write your code with debugging in mind (avoid duplicating code, put conceptually
29058 similar variables into structs, use structured code, have strategic points
29059 within your code where all variables are consistent, ...)
29062 \begin_layout Itemize
29063 run a syntax-checking tool like splint
29064 \begin_inset LatexCommand \index{splint (syntax checking tool)}
29069 \begin_inset LatexCommand \index{lint (syntax checking tool)}
29077 \begin_layout Standard
29087 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
29094 \begin_layout Itemize
29095 for the high level code use a C-compiler (like f.e.
29096 GCC) to compile run and debug the code on your host.
29101 \begin_layout Standard
29111 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
29115 ) on how to handle syntax extensions like __xdata, __at(), ...
29119 \begin_layout Itemize
29120 use another C-compiler to compile code for your target.
29121 Always an option but not recommended:) And not very likely to help you.
29122 If you seriously consider walking this path you should at least occasionally
29123 check portability of your code.
29124 Most commercial compiler vendors will offer an evaluation version so you
29125 can test compile your code or snippets of your code.
29128 \begin_layout Standard
29129 Debugging on a simulator:
29132 \begin_layout Itemize
29133 there is a separate section about SDCDB (section
29134 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
29141 \begin_layout Itemize
29142 or (8051 specific) use a freeware/commercial simulator which interfaces
29144 \begin_inset LatexCommand \index{AOMF, AOMF51}
29149 \begin_inset LatexCommand \ref{OMF file}
29153 ) optionally generated by SDCC.
29156 \begin_layout Standard
29157 Debugging On-target:
29160 \begin_layout Itemize
29161 use a MCU port pin to serially output debug data to the RS232 port of your
29163 You'll probably want some level shifting device typically involving a MAX232
29165 If the hardware serial port of the MCU is not available search for 'Software
29166 UART' in your favourite search machine.
29169 \begin_layout Itemize
29170 use an on-target monitor.
29171 In this context a monitor is a small program which usually accepts commands
29172 via a serial line and allows to set program counter, to single step through
29173 a program and read/write memory locations.
29174 For the 8051 good examples of monitors are paulmon and cmon51 (see section
29176 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
29183 \begin_layout Itemize
29184 toggle MCU port pins at strategic points within your code and use an oscilloscop
29188 digital oscilloscope
29191 \begin_inset LatexCommand \index{Oscilloscope}
29195 with deep trace memory is really helpful especially if you have to debug
29196 a realtime application.
29197 If you need to monitor more pins than your oscilloscope provides you can
29198 sometimes get away with a small R-2R network.
29199 On a single channel oscilloscope you could f.e.
29200 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
29202 \begin_inset Formula $\Omega$
29205 resistor and the other one by a 5\InsetSpace ~
29207 \begin_inset Formula $\Omega$
29210 resistor to the oscilloscope probe (check output drive capability of the
29211 pins you want to monitor).
29212 If you need to monitor many more pins a
29219 \begin_layout Itemize
29233 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
29238 Usually very expensive.
29239 And very nice to have too.
29240 And usually locks you (for years...) to the devices the ICE can emulate.
29244 \begin_layout Itemize
29245 use a remote debugger.
29246 In most 8-bit systems the symbol information is not available on the target,
29247 and a complete debugger is too bulky for the target system.
29248 Therefore usually a debugger on the host system connects to an on-target
29249 debugging stub which accepts only primitive commands.
29252 Terms to enter into your favourite search engine could be 'remote debugging',
29253 'gdb stub' or 'inferior debugger'.
29257 \begin_layout Itemize
29258 use an on target hardware debugger.
29259 Some of the more modern MCUs include hardware support for setting break
29260 points and monitoring/changing variables by using dedicated hardware pins.
29261 This facility doesn't require additional code to run on the target and
29266 doesn't affect runtime behaviour until a breakpoint is hit.
29267 For the mcs51 most hardware debuggers use the AOMF
29268 \begin_inset LatexCommand \index{AOMF, AOMF51}
29273 \begin_inset LatexCommand \ref{OMF file}
29281 \begin_layout Standard
29285 \begin_layout Itemize
29286 if you are not familiar with any of the following terms you're likely to
29287 run into problems rather sooner than later:
29304 As an embedded programmer you
29308 to know them so why not look them up
29312 you have problems?)
29315 \begin_layout Itemize
29316 tell someone else about your problem (actually this is a surprisingly effective
29317 means to hunt down the bug even if the listener is not familiar with your
29319 As 'failure to communicate' is probably one of the job-induced deformations
29320 of an embedded programmer this is highly encouraged.
29323 \begin_layout Section
29324 Debugging with SDCDB
29325 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
29330 \begin_inset LatexCommand \index{SDCDB (debugger)}
29337 \begin_layout Standard
29338 SDCC is distributed with a source level debugger
29339 \begin_inset LatexCommand \index{Debugger}
29344 The debugger uses a command line interface, the command repertoire of the
29345 debugger has been kept as close to gdb
29346 \begin_inset LatexCommand \index{gdb}
29350 (the GNU debugger) as possible.
29351 The configuration and build process is part of the standard compiler installati
29352 on, which also builds and installs the debugger in the target directory
29353 specified during configuration.
29354 The debugger allows you debug BOTH at the C source and at the ASM source
29358 \begin_layout Subsection
29359 Compiling for Debugging
29362 \begin_layout Standard
29367 \begin_layout Standard
29377 \begin_inset LatexCommand \index{-\/-debug}
29381 option must be specified for all files for which debug information is to
29383 The compiler generates a .adb file for each of these files.
29384 The linker creates the .cdb
29385 \begin_inset LatexCommand \index{<file>.cdb}
29390 \begin_inset LatexCommand \index{<file>.adb}
29394 files and the address information.
29395 This .cdb is used by the debugger.
29398 \begin_layout Subsection
29399 How the Debugger Works
29402 \begin_layout Standard
29407 \begin_layout Standard
29416 -debug option is specified the compiler generates extra symbol information
29417 some of which are put into the assembler source and some are put into the
29419 Then the linker creates the .cdb file from the individual .adb files with
29420 the address information for the symbols.
29421 The debugger reads the symbolic information generated by the compiler &
29422 the address information generated by the linker.
29423 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
29424 execution is controlled by the debugger.
29425 When a command is issued for the debugger, it translates it into appropriate
29426 commands for the simulator.
29427 (Currently SDCDM only connects to the simulator but
29432 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
29436 is an effort to connect directly to the hardware.)
29439 \begin_layout Subsection
29440 Starting the Debugger SDCDB
29443 \begin_layout Standard
29444 The debugger can be started using the following command line.
29445 (Assume the file you are debugging has the file name foo).
29459 The debugger will look for the following files.
29462 \begin_layout Itemize
29463 foo.c - the source file.
29466 \begin_layout Itemize
29467 foo.cdb - the debugger symbol information file.
29470 \begin_layout Itemize
29471 foo.ihx - the Intel hex format
29472 \begin_inset LatexCommand \index{Intel hex format}
29479 \begin_layout Subsection
29480 SDCDB Command Line Options
29483 \begin_layout Itemize
29488 \begin_layout Standard
29497 -directory=<source file directory> this option can used to specify the directory
29499 The debugger will look into the directory list specified for source, cdb
29501 The items in the directory list must be separated by ':', e.g.
29502 if the source files can be in the directories /home/src1 and /home/src2,
29507 \begin_layout Standard
29516 -directory option should be -
29520 \begin_layout Standard
29529 -directory=/home/src1:/home/src2.
29530 Note there can be no spaces in the option.
29534 \begin_layout Itemize
29535 -cd <directory> - change to the <directory>.
29538 \begin_layout Itemize
29539 -fullname - used by GUI front ends.
29542 \begin_layout Itemize
29543 -cpu <cpu-type> - this argument is passed to the simulator please see the
29544 simulator docs for details.
29547 \begin_layout Itemize
29548 -X <Clock frequency > this options is passed to the simulator please see
29549 the simulator docs for details.
29552 \begin_layout Itemize
29553 -s <serial port file> passed to simulator see the simulator docs for details.
29556 \begin_layout Itemize
29557 -S <serial in,out> passed to simulator see the simulator docs for details.
29560 \begin_layout Itemize
29561 -k <port number> passed to simulator see the simulator docs for details.
29564 \begin_layout Subsection
29565 SDCDB Debugger Commands
29568 \begin_layout Standard
29569 As mentioned earlier the command interface for the debugger has been deliberatel
29570 y kept as close the GNU debugger gdb, as possible.
29571 This will help the integration with existing graphical user interfaces
29572 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
29573 If you use a graphical user interface for the debugger you can skip this
29577 \begin_layout Subsubsection*
29578 break [line | file:line | function | file:function]
29581 \begin_layout Standard
29582 Set breakpoint at specified line or function:
29591 sdcdb>break foo.c:100
29593 sdcdb>break funcfoo
29595 sdcdb>break foo.c:funcfoo
29598 \begin_layout Subsubsection*
29599 clear [line | file:line | function | file:function ]
29602 \begin_layout Standard
29603 Clear breakpoint at specified line or function:
29612 sdcdb>clear foo.c:100
29614 sdcdb>clear funcfoo
29616 sdcdb>clear foo.c:funcfoo
29619 \begin_layout Subsubsection*
29623 \begin_layout Standard
29624 Continue program being debugged, after breakpoint.
29627 \begin_layout Subsubsection*
29631 \begin_layout Standard
29632 Execute till the end of the current function.
29635 \begin_layout Subsubsection*
29639 \begin_layout Standard
29640 Delete breakpoint number 'n'.
29641 If used without any option clear ALL user defined break points.
29644 \begin_layout Subsubsection*
29645 info [break | stack | frame | registers ]
29648 \begin_layout Itemize
29649 info break - list all breakpoints
29652 \begin_layout Itemize
29653 info stack - show the function call stack.
29656 \begin_layout Itemize
29657 info frame - show information about the current execution frame.
29660 \begin_layout Itemize
29661 info registers - show content of all registers.
29664 \begin_layout Subsubsection*
29668 \begin_layout Standard
29669 Step program until it reaches a different source line.
29670 Note: pressing <return> repeats the last command.
29673 \begin_layout Subsubsection*
29677 \begin_layout Standard
29678 Step program, proceeding through subroutine calls.
29681 \begin_layout Subsubsection*
29685 \begin_layout Standard
29686 Start debugged program.
29689 \begin_layout Subsubsection*
29693 \begin_layout Standard
29694 Print type information of the variable.
29697 \begin_layout Subsubsection*
29701 \begin_layout Standard
29702 print value of variable.
29705 \begin_layout Subsubsection*
29709 \begin_layout Standard
29710 load the given file name.
29711 Note this is an alternate method of loading file for debugging.
29714 \begin_layout Subsubsection*
29718 \begin_layout Standard
29719 print information about current frame.
29722 \begin_layout Subsubsection*
29726 \begin_layout Standard
29727 Toggle between C source & assembly source.
29730 \begin_layout Subsubsection*
29731 ! simulator command
29734 \begin_layout Standard
29735 Send the string following '!' to the simulator, the simulator response is
29737 Note the debugger does not interpret the command being sent to the simulator,
29738 so if a command like 'go' is sent the debugger can loose its execution
29739 context and may display incorrect values.
29742 \begin_layout Subsubsection*
29746 \begin_layout Standard
29749 My name is Bobby Brown"
29752 \begin_layout Subsection
29753 Interfacing SDCDB with DDD
29756 \begin_layout Standard
29757 \begin_inset Note Note
29760 \begin_layout Standard
29761 The screenshot was converted from png to eps with:
29762 \begin_inset Quotes sld
29765 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
29766 \begin_inset Quotes srd
29769 which produces a pretty compact eps file which is free from compression
29773 \begin_layout Standard
29774 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
29775 as this broke the build system on Sourceforge (pdf-file was broken.
29776 pdflatex does not accept eps files).
29784 \begin_layout Standard
29800 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
29806 shows a screenshot of a debugging session with DDD
29807 \begin_inset LatexCommand \index{DDD (debugger)}
29811 (Unix only) on a simulated 8032.
29812 The debugging session might not run as smoothly as the screenshot suggests.
29813 The debugger allows setting of breakpoints, displaying and changing variables,
29814 single stepping through C and assembler code.
29817 The source was compiled with
29831 \begin_layout Standard
29843 -debug ddd_example.c
29856 and DDD was invoked with
29863 ddd -debugger "sdcdb -cpu 8032 ddd_example"
29866 \begin_layout Standard
29867 \begin_inset Note Note
29870 \begin_layout Standard
29871 Check that the double quotes or an apostroph within the command line survive
29872 the LyX tool chain.
29873 Previously the apostrophs got slanted in the PDF output so a cut and paste
29882 \begin_layout Subsection
29883 Interfacing SDCDB with XEmacs
29884 \begin_inset LatexCommand \index{XEmacs}
29889 \begin_inset LatexCommand \index{Emacs}
29896 \begin_layout Standard
29897 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
29898 sdcdb.el and sdcdbsrc.el.
29899 These two files can be found in the $(prefix)/bin directory after the installat
29901 These files need to be loaded into XEmacs for the interface to work.
29902 This can be done at XEmacs startup time by inserting the following into
29903 your '.xemacs' file (which can be found in your HOME directory):
29909 (load-file sdcdbsrc.el)
29915 .xemacs is a lisp file so the () around the command is REQUIRED.
29916 The files can also be loaded dynamically while XEmacs is running, set the
29917 environment variable 'EMACSLOADPATH' to the installation bin directory
29918 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
29919 To start the interface enter the following command:
29933 You will prompted to enter the file name to be debugged.
29938 The command line options that are passed to the simulator directly are
29939 bound to default values in the file sdcdbsrc.el.
29940 The variables are listed below, these values maybe changed as required.
29943 \begin_layout Itemize
29944 sdcdbsrc-cpu-type '51
29947 \begin_layout Itemize
29948 sdcdbsrc-frequency '11059200
29951 \begin_layout Itemize
29952 sdcdbsrc-serial nil
29955 \begin_layout Standard
29956 The following is a list of key mapping for the debugger interface.
29959 \begin_layout Standard
29982 binding\InsetSpace ~
30020 -------\InsetSpace ~
30091 sdcdb-back-from-src\InsetSpace ~
30120 rom-src\InsetSpace ~
30130 SDCDB continue command
30148 sdcdb-step-from-src\InsetSpace ~
30177 hatis-c-sexp\InsetSpace ~
30187 SDCDB ptypecommand for data at
30254 sdcdbsrc-delete\InsetSpace ~
30269 B Delete all breakpoints if no arg
30318 given or delete arg (C-u arg x)
30337 -frame\InsetSpace ~
30352 SDCDB Display current frame if no arg,
30401 given or display frame arg
30469 sdcdbsrc-goto-sdcdb\InsetSpace ~
30479 Goto the SDCDB output buffer
30498 t-c-sexp\InsetSpace ~
30509 SDCDB print command for data at
30576 sdcdbsrc-goto-sdcdb\InsetSpace ~
30587 o the SDCDB output buffer
30605 sdcdbsrc-mode\InsetSpace ~
30621 Toggles Sdcdbsrc mode (turns it
30637 sdcdb-finish-from-src\InsetSpace ~
30645 SDCDB finish command
30679 Set break for line with point
30694 sdcdbsrc-mode\InsetSpace ~
30710 Toggle Sdcdbsrc mode
30726 dbsrc-srcmode\InsetSpace ~
30750 \begin_layout Chapter
30754 \begin_layout Standard
30755 Here are a few guidelines that will help the compiler generate more efficient
30756 code, some of the tips are specific to this compiler others are generally
30757 good programming practice.
30760 \begin_layout Itemize
30761 Use the smallest data type to represent your data-value.
30762 If it is known in advance that the value is going to be less than 256 then
30763 use an 'unsigned char' instead of a 'short' or 'int'.
30764 Please note, that ANSI C requires both signed and unsigned chars to be
30765 promoted to 'signed int'
30766 \begin_inset LatexCommand \index{promotion to signed int}
30771 \begin_inset Marginal
30774 \begin_layout Standard
30783 before doing any operation.
30785 \begin_inset LatexCommand \index{type promotion}
30790 \begin_inset LatexCommand \label{type promotion}
30794 can be omitted, if the result is the same.
30795 The effect of the promotion rules together with the sign-extension is often
30800 \begin_layout Verse
30803 unsigned char uc = 0xfe;
30805 if (uc * uc < 0) /* this is true! */
30818 \begin_layout Standard
30825 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
30833 \begin_layout Verse
30836 (unsigned char) -12 / (signed char) -3 = ...
30839 \begin_layout Standard
30840 No, the result is not 4:
30843 \begin_layout Verse
30846 (int) (unsigned char) -12 / (int) (signed char) -3 =
30848 (int) (unsigned char)
30849 0xf4 / (int) (signed char) 0xfd =
30851 (int) 0x00f4 / (int) 0xfffd =
30856 (int) 244 / (int) -3 =
30858 (int) -81 = (int) 0xffaf;
30861 \begin_layout Standard
30862 Don't complain, that gcc gives you a different result.
30863 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
30864 Therefore the results are different.
30867 \begin_inset Quotes sld
30871 \begin_inset Quotes srd
30877 \begin_layout Quote
30880 If well-defined overflow characteristics are important and negative values
30881 are not, or if you want to steer clear of sign-extension problems when
30882 manipulating bits or bytes, use one of the corresponding unsigned types.
30883 (Beware when mixing signed and unsigned values in expressions, though.)
30886 character types (especially unsigned char) can be used as "tiny" integers,
30887 doing so is sometimes more trouble than it's worth, due to unpredictable
30888 sign extension and increased code size.
30892 \begin_layout Itemize
30893 Use unsigned when it is known in advance that the value is not going to
30895 This helps especially if you are doing division or multiplication, bit-shifting
30896 or are using an array index.
30899 \begin_layout Itemize
30900 NEVER jump into a LOOP.
30903 \begin_layout Itemize
30904 Declare the variables to be local
30905 \begin_inset LatexCommand \index{local variables}
30909 whenever possible, especially loop control variables (induction).
30912 \begin_layout Itemize
30913 Have a look at the assembly listing to get a
30914 \begin_inset Quotes sld
30918 \begin_inset Quotes srd
30921 for the code generation.
30924 \begin_layout Section
30925 Porting code from or to other compilers
30926 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
30933 \begin_layout Itemize
30934 check whether endianness of the compilers differs and adapt where needed.
30937 \begin_layout Itemize
30938 check the device specific header files
30939 \begin_inset LatexCommand \index{Header files}
30944 \begin_inset LatexCommand \index{Include files}
30948 for compiler specific syntax.
30949 Eventually include the file <compiler.h
30950 \begin_inset LatexCommand \index{compiler.h (include file)}
30955 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
30959 to allow using common header files.
30962 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
30969 \begin_layout Itemize
30970 check whether the startup code contains the correct initialization (watchdog,
30974 \begin_layout Itemize
30975 check whether the sizes of short, int, long match.
30978 \begin_layout Itemize
30979 check if some 16 or 32 bit hardware registers require a specific addressing
30980 order (least significant or most significant byte first) and adapt if needed
30989 relate to time and not to lower/upper memory location here, so this is
30994 the same as endianness).
30997 \begin_layout Itemize
30998 check whether the keyword
31002 is used where needed.
31003 The compilers might differ in their optimization characteristics (as different
31004 versions of the same compiler might also use more clever optimizations
31005 this is good idea anyway).
31007 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
31014 \begin_layout Itemize
31015 check that the compilers are not told to supress warnings.
31018 \begin_layout Itemize
31019 check and convert compiler specific extensions (interrupts, memory areas,
31023 \begin_layout Itemize
31024 check for differences in type promotion.
31025 Especially check for math operations on
31034 For the sake of C99 compatibility SDCC will probably promote these to
31038 more often than other compilers.
31039 Eventually insert explicit casts to
31048 Also check that the ~\InsetSpace ~
31050 \begin_inset LatexCommand \index{\~\/ Operator}
31057 \begin_inset LatexCommand \index{bit}
31063 variables, use the !\InsetSpace ~
31066 \begin_inset LatexCommand \ref{type promotion}
31071 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
31078 \begin_layout Itemize
31079 check the assembly code generated for interrupt routines (f.e.
31080 for calls to possibly non-reentrant library functions).
31083 \begin_layout Itemize
31084 check whether timing loops result in proper timing (or preferably consider
31085 a rewrite of the code with timer based delays instead).
31088 \begin_layout Itemize
31089 check for differences in printf parameters (some compilers push (va_arg
31090 \begin_inset LatexCommand \index{vararg, va\_arg}
31094 ) char variables as
31098 others push them as
31104 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
31111 \begin_layout Itemize
31112 check the resulting memory map
31113 \begin_inset LatexCommand \index{Memory map}
31118 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
31119 ly idata, pdata, xdata).
31120 Eventually check if unexpected library functions are included.
31123 \begin_layout Section
31125 \begin_inset LatexCommand \index{Tools}
31129 included in the distribution
31132 \begin_layout Standard
31134 \begin_inset Tabular
31135 <lyxtabular version="3" rows="12" columns="3">
31137 <column alignment="left" valignment="top" leftline="true" width="0pt">
31138 <column alignment="left" valignment="top" leftline="true" width="0pt">
31139 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
31140 <row topline="true" bottomline="true">
31141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31144 \begin_layout Standard
31152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31155 \begin_layout Standard
31163 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31166 \begin_layout Standard
31175 <row topline="true">
31176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31179 \begin_layout Standard
31181 \begin_inset LatexCommand \index{uCsim}
31190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31193 \begin_layout Standard
31194 Simulator for various architectures
31199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31202 \begin_layout Standard
31209 <row topline="true">
31210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31213 \begin_layout Standard
31219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31222 \begin_layout Standard
31224 \begin_inset LatexCommand \index{Header files}
31229 \begin_inset LatexCommand \index{Include files}
31238 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31241 \begin_layout Standard
31242 sdcc/support/scripts
31248 <row topline="true">
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" usebox="none">
31261 \begin_layout Standard
31262 header file conversion
31267 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31270 \begin_layout Standard
31271 sdcc/support/scripts
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">
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
31334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31337 \begin_layout Standard
31353 <row topline="true">
31354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31357 \begin_layout Standard
31363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31366 \begin_layout Standard
31372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31375 \begin_layout Standard
31391 <row topline="true">
31392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31395 \begin_layout Standard
31401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31404 \begin_layout Standard
31410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31413 \begin_layout Standard
31429 <row topline="true">
31430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31433 \begin_layout Standard
31439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31442 \begin_layout Standard
31448 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31451 \begin_layout Standard
31467 <row topline="true">
31468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31471 \begin_layout Standard
31477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31480 \begin_layout Standard
31486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31489 \begin_layout Standard
31505 <row topline="true">
31506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31509 \begin_layout Standard
31515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31518 \begin_layout Standard
31524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31527 \begin_layout Standard
31543 <row topline="true" bottomline="true">
31544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31547 \begin_layout Standard
31553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31556 \begin_layout Standard
31558 \begin_inset LatexCommand \index{packihx (tool)}
31567 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31570 \begin_layout Standard
31595 \begin_layout Section
31597 \begin_inset LatexCommand \index{Documentation}
31601 included in the distribution
31604 \begin_layout Standard
31606 \begin_inset Tabular
31607 <lyxtabular version="3" rows="10" columns="2">
31609 <column alignment="block" valignment="top" leftline="true" width="40col%">
31610 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
31611 <row topline="true" bottomline="true" endhead="true">
31612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31615 \begin_layout Standard
31623 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31626 \begin_layout Standard
31629 Filename / Where to get
31635 <row topline="true">
31636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31639 \begin_layout Standard
31640 SDCC Compiler User Guide
31645 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31648 \begin_layout Standard
31649 You're reading it right now
31661 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
31671 <row topline="true">
31672 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31675 \begin_layout Standard
31681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31684 \begin_layout Standard
31697 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31707 <row topline="true">
31708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31711 \begin_layout Standard
31713 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
31718 \begin_inset LatexCommand \index{Assembler documentation}
31725 \begin_inset LatexCommand \index{aslink}
31730 \begin_inset LatexCommand \index{Linker documentation}
31739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31742 \begin_layout Standard
31743 sdcc/as/doc/asxhtm.html
31755 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
31765 <row topline="true">
31766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31769 \begin_layout Standard
31770 SDCC regression test
31771 \begin_inset LatexCommand \index{Regression test}
31780 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31783 \begin_layout Standard
31784 sdcc/doc/test_suite_spec.pdf
31796 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
31806 <row topline="true">
31807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31810 \begin_layout Standard
31816 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31819 \begin_layout Standard
31832 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
31842 <row topline="true">
31843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31846 \begin_layout Standard
31847 Notes on debugging with SDCDB
31848 \begin_inset LatexCommand \index{SDCDB (debugger)}
31857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31860 \begin_layout Standard
31861 sdcc/debugger/README
31873 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
31883 <row topline="true">
31884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31887 \begin_layout Standard
31889 \begin_inset LatexCommand \index{uCsim}
31893 Software simulator for microcontrollers
31898 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31901 \begin_layout Standard
31931 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
31941 <row topline="true">
31942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31945 \begin_layout Standard
31946 Temporary notes on the pic16
31947 \begin_inset LatexCommand \index{PIC16}
31956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31959 \begin_layout Standard
31960 sdcc/src/pic16/NOTES
31972 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
31982 <row topline="true" bottomline="true">
31983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31986 \begin_layout Standard
31987 SDCC internal documentation (debugging file format)
31992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31995 \begin_layout Standard
32025 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
32044 \begin_layout Section
32045 Related open source tools
32046 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
32051 \begin_inset LatexCommand \index{Related tools}
32058 \begin_layout Standard
32060 \begin_inset Tabular
32061 <lyxtabular version="3" rows="16" columns="3">
32063 <column alignment="left" valignment="top" leftline="true" width="0pt">
32064 <column alignment="block" valignment="top" leftline="true" width="30line%">
32065 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
32066 <row topline="true" bottomline="true">
32067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32070 \begin_layout Standard
32078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32081 \begin_layout Standard
32089 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32092 \begin_layout Standard
32101 <row topline="true">
32102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32105 \begin_layout Standard
32107 \begin_inset LatexCommand \index{gpsim (pic simulator)}
32116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32119 \begin_layout Standard
32125 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32128 \begin_layout Standard
32129 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
32139 <row topline="true">
32140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32143 \begin_layout Standard
32145 \begin_inset LatexCommand \index{gputils (pic tools)}
32154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32157 \begin_layout Standard
32163 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32166 \begin_layout Standard
32167 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
32177 <row topline="true">
32178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32181 \begin_layout Standard
32187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32190 \begin_layout Standard
32196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32199 \begin_layout Standard
32200 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
32210 <row topline="true">
32211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32214 \begin_layout Standard
32220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32223 \begin_layout Standard
32224 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
32230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32233 \begin_layout Standard
32234 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
32244 <row topline="true">
32245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32248 \begin_layout Standard
32250 \begin_inset LatexCommand \index{indent (source formatting tool)}
32259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32262 \begin_layout Standard
32263 Formats C source - Master of the white spaces
32268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32271 \begin_layout Standard
32272 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
32282 <row topline="true">
32283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32286 \begin_layout Standard
32288 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
32297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32300 \begin_layout Standard
32301 Object file conversion, checksumming, ...
32306 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32309 \begin_layout Standard
32310 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
32320 <row topline="true">
32321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32324 \begin_layout Standard
32326 \begin_inset LatexCommand \index{objdump (tool)}
32335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32338 \begin_layout Standard
32339 Object file conversion, ...
32344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32347 \begin_layout Standard
32348 Part of binutils (should be there anyway)
32354 <row topline="true">
32355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32358 \begin_layout Standard
32364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32367 \begin_layout Standard
32368 8051 monitor (hex up-/download, single step, disassemble)
32373 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32376 \begin_layout Standard
32377 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
32387 <row topline="true">
32388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32391 \begin_layout Standard
32393 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
32402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32405 \begin_layout Standard
32406 Source code documentation system
32411 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32414 \begin_layout Standard
32415 \begin_inset LatexCommand \url{http://www.doxygen.org}
32425 <row topline="true">
32426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32429 \begin_layout Standard
32435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32438 \begin_layout Standard
32439 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
32444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32447 \begin_layout Standard
32448 \begin_inset LatexCommand \url{http://www.kdevelop.org}
32458 <row topline="true">
32459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32462 \begin_layout Standard
32468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32471 \begin_layout Standard
32472 8051 monitor (hex up-/download, single step, disassemble)
32477 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32480 \begin_layout Standard
32481 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
32491 <row topline="true">
32492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32495 \begin_layout Standard
32497 \begin_inset LatexCommand \index{splint (syntax checking tool)}
32506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32509 \begin_layout Standard
32510 Statically checks c sources (see
32511 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
32520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32523 \begin_layout Standard
32524 \begin_inset LatexCommand \url{http://www.splint.org}
32534 <row topline="true" bottomline="true">
32535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32538 \begin_layout Standard
32540 \begin_inset LatexCommand \index{DDD (debugger)}
32549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32552 \begin_layout Standard
32553 Debugger, serves nicely as GUI to SDCDB
32554 \begin_inset LatexCommand \index{SDCDB (debugger)}
32563 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32566 \begin_layout Standard
32567 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
32577 <row bottomline="true">
32578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32581 \begin_layout Standard
32583 \begin_inset LatexCommand \index{d52}
32588 \begin_inset LatexCommand \index{d52 (disassembler)}
32597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32600 \begin_layout Standard
32601 Disassembler, can count instruction cycles
32602 \begin_inset LatexCommand \index{instruction cycles (count)}
32606 , use with options -pnd
32611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32614 \begin_layout Standard
32615 \begin_inset LatexCommand \url{http://www.8052.com/users/disasm/}
32625 <row bottomline="true">
32626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32629 \begin_layout Standard
32631 \begin_inset LatexCommand \index{cmake}
32640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32643 \begin_layout Standard
32644 Cross platform build system, generates Makefiles
32645 \begin_inset LatexCommand \index{Makefile}
32649 and project workspaces
32650 \begin_inset LatexCommand \index{project workspace}
32659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32662 \begin_layout Standard
32663 \begin_inset LatexCommand \url{http://www.cmake.org}
32671 and a dedicated wiki entry:
32672 \begin_inset LatexCommand \url{http://www.cmake.org/Wiki/CmakeSdcc}
32691 \begin_layout Section
32692 Related documentation / recommended reading
32695 \begin_layout Standard
32697 \begin_inset Tabular
32698 <lyxtabular version="3" rows="7" columns="3">
32700 <column alignment="left" valignment="top" leftline="true" width="0pt">
32701 <column alignment="left" valignment="top" leftline="true" width="0">
32702 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32703 <row topline="true" bottomline="true">
32704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32707 \begin_layout Standard
32715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32718 \begin_layout Standard
32726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32729 \begin_layout Standard
32738 <row topline="true">
32739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32742 \begin_layout Standard
32757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32760 \begin_layout Standard
32762 \begin_inset LatexCommand \index{C Reference card}
32771 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32774 \begin_layout Standard
32775 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
32785 <row topline="true">
32786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32789 \begin_layout Standard
32795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32798 \begin_layout Standard
32800 \begin_inset LatexCommand \index{C FAQ}
32809 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32812 \begin_layout Standard
32813 \begin_inset LatexCommand \url{http://www.c-faq.com}
32823 <row topline="true">
32824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32827 \begin_layout Standard
32833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32836 \begin_layout Standard
32837 \begin_inset Quotes sld
32841 \begin_inset Quotes srd
32849 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32852 \begin_layout Standard
32855 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
32865 <row topline="true">
32866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32869 \begin_layout Standard
32875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32878 \begin_layout Standard
32879 \begin_inset Quotes sld
32882 Extensions for Embedded C
32883 \begin_inset Quotes srd
32891 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32894 \begin_layout Standard
32897 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
32907 <row topline="true">
32908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32911 \begin_layout Standard
32917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32920 \begin_layout Standard
32921 Latest datasheet of target CPU
32926 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32929 \begin_layout Standard
32936 <row topline="true" bottomline="true">
32937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32940 \begin_layout Standard
32946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32949 \begin_layout Standard
32950 Revision history of datasheet
32955 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32958 \begin_layout Standard
32974 \begin_layout Section
32975 Application notes specifically for SDCC
32978 \begin_layout Standard
32979 SDCC makes no claims about the completeness of this list and about up-to-datenes
32980 s or correctness of the application notes
32981 \begin_inset LatexCommand \index{Application notes}
32988 \begin_layout Standard
32992 \begin_inset Tabular
32993 <lyxtabular version="3" rows="7" columns="3">
32995 <column alignment="block" valignment="top" leftline="true" width="17col%">
32996 <column alignment="block" valignment="top" leftline="true" width="27col%">
32997 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
32998 <row topline="true" bottomline="true">
32999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33002 \begin_layout Standard
33011 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
33014 \begin_layout Standard
33023 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33026 \begin_layout Standard
33036 <row topline="true">
33037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33040 \begin_layout Standard
33048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33051 \begin_layout Standard
33054 Using the SDCC Compiler for the DS80C400
33055 \begin_inset LatexCommand \index{DS80C400}
33064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33067 \begin_layout Standard
33070 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
33080 <row topline="true">
33081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33084 \begin_layout Standard
33092 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
33095 \begin_layout Standard
33098 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
33099 \begin_inset LatexCommand \index{DS89C4x0}
33103 Family of Microcontrollers
33108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33111 \begin_layout Standard
33114 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
33124 <row topline="true">
33125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33128 \begin_layout Standard
33131 Silicon Laboratories / Cygnal
33136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33139 \begin_layout Standard
33142 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
33143 \begin_inset LatexCommand \index{IDE}
33152 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33155 \begin_layout Standard
33158 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
33168 <row topline="true">
33169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33172 \begin_layout Standard
33175 Ramtron / Goal Semiconductor
33180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33183 \begin_layout Standard
33186 Interfacing SDCC to Syn and Textpad
33191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33194 \begin_layout Standard
33197 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
33207 <row topline="true">
33208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33211 \begin_layout Standard
33214 Ramtron / Goal Semiconductor
33219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33222 \begin_layout Standard
33225 Installing and Configuring SDCC and Crimson Editor
33230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33233 \begin_layout Standard
33236 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
33246 <row topline="true" bottomline="true">
33247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33250 \begin_layout Standard
33258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33261 \begin_layout Standard
33264 MSC12xx Programming with SDCC
33269 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33272 \begin_layout Standard
33275 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
33292 \begin_layout Section
33296 \begin_layout Standard
33297 Some questions answered, some pointers given - it might be time to in turn
33305 \begin_layout Itemize
33306 can you solve your project with the selected microcontroller? Would you
33307 find out early or rather late that your target is too small/slow/whatever?
33308 Can you switch to a slightly better device if it doesn't fit?
33311 \begin_layout Itemize
33312 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
33313 and/or another programming language be more adequate? Would an operating
33314 system on the target device help?
33317 \begin_layout Itemize
33318 if you solved the problem, will the marketing department be happy?
33321 \begin_layout Itemize
33322 if the marketing department is happy, will customers be happy?
33325 \begin_layout Itemize
33326 if you're the project manager, marketing department and maybe even the customer
33327 in one person, have you tried to see the project from the outside?
33330 \begin_layout Itemize
33331 is the project done if you think it is done? Or is just that other interface/pro
33332 tocol/feature/configuration/option missing? How about website, manual(s),
33333 internationali(z|s)ation, packaging, labels, 2nd source for components,
33334 electromagnetic compatability/interference, documentation for production,
33335 production test software, update mechanism, patent issues?
33338 \begin_layout Itemize
33339 is your project adequately positioned in that magic triangle: fame, fortune,
33343 \begin_layout Standard
33344 Maybe not all answers to these questions are known and some answers may
33349 , nevertheless knowing these questions may help you to avoid burnout
33353 \begin_layout Standard
33354 burnout is bad for electronic devices, programmers and motorcycle tyres
33360 Chances are you didn't want to hear some of them...
33363 \begin_layout Chapter
33365 \begin_inset LatexCommand \index{Support}
33372 \begin_layout Standard
33373 SDCC has grown to be a large project.
33374 The compiler alone (without the preprocessor, assembler and linker) is
33375 well over 150,000 lines of code (blank stripped).
33376 The open source nature of this project is a key to its continued growth
33378 You gain the benefit and support of many active software developers and
33380 Is SDCC perfect? No, that's why we need your help.
33381 The developers take pride in fixing reported bugs.
33382 You can help by reporting the bugs and helping other SDCC users.
33383 There are lots of ways to contribute, and we encourage you to take part
33384 in making SDCC a great software package.
33388 \begin_layout Standard
33389 The SDCC project is hosted on the SDCC sourceforge site at
33390 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
33395 You'll find the complete set of mailing lists
33396 \begin_inset LatexCommand \index{Mailing list(s)}
33400 , forums, bug reporting system, patch submission
33401 \begin_inset LatexCommand \index{Patch submission}
33406 \begin_inset LatexCommand \index{download}
33410 area and Subversion code repository
33411 \begin_inset LatexCommand \index{Subversion code repository}
33418 \begin_layout Section
33420 \begin_inset LatexCommand \index{Bug reporting}
33425 \begin_inset LatexCommand \index{Reporting bugs}
33432 \begin_layout Standard
33433 The recommended way of reporting bugs is using the infrastructure of the
33435 You can follow the status of bug reports there and have an overview about
33439 \begin_layout Standard
33440 Bug reports are automatically forwarded to the developer mailing list and
33441 will be fixed ASAP.
33442 When reporting a bug, it is very useful to include a small test program
33443 (the smaller the better) which reproduces the problem.
33444 If you can isolate the problem by looking at the generated assembly code,
33445 this can be very helpful.
33446 Compiling your program with the -
33450 \begin_layout Standard
33460 \begin_inset LatexCommand \index{-\/-dumpall}
33464 option can sometimes be useful in locating optimization problems.
33465 When reporting a bug please make sure you:
33468 \begin_layout Enumerate
33469 Attach the code you are compiling with SDCC.
33473 \begin_layout Enumerate
33474 Specify the exact command you use to run SDCC, or attach your Makefile.
33478 \begin_layout Enumerate
33479 Specify the SDCC version (type "
33485 "), your platform, and operating system.
33489 \begin_layout Enumerate
33490 Provide an exact copy of any error message or incorrect output.
33494 \begin_layout Enumerate
33495 Put something meaningful in the subject of your message.
33498 \begin_layout Standard
33499 Please attempt to include these 5 important parts, as applicable, in all
33500 requests for support or when reporting any problems or bugs with SDCC.
33501 Though this will make your message lengthy, it will greatly improve your
33502 chance that SDCC users and developers will be able to help you.
33503 Some SDCC developers are frustrated by bug reports without code provided
33504 that they can use to reproduce and ultimately fix the problem, so please
33505 be sure to provide sample code if you are reporting a bug!
33508 \begin_layout Standard
33509 Please have a short check that you are using a recent version of SDCC and
33510 the bug is not yet known.
33511 This is the link for reporting bugs:
33512 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
33517 With SDCC on average having more than 200 downloads
33518 \begin_inset LatexCommand \index{download}
33522 on sourceforge per day
33526 \begin_layout Standard
33527 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
33528 between 2002 and 2005.
33529 This does not include other methods of distribution.
33534 there must be some users.
33535 So it's not exactly easy to find a new bug.
33536 If you find one we need it:
33538 reporting bugs is good
33543 \begin_layout Section
33544 Requesting Features
33545 \begin_inset LatexCommand \label{sub:Requesting-Features}
33550 \begin_inset LatexCommand \index{Feature request}
33555 \begin_inset LatexCommand \index{Requesting features}
33562 \begin_layout Standard
33563 Like bug reports feature requests are forwarded to the developer mailing
33565 This is the link for requesting features:
33566 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33573 \begin_layout Section
33577 \begin_layout Standard
33578 Like bug reports contributed patches are forwarded to the developer mailing
33580 This is the link for submitting patches
33581 \begin_inset LatexCommand \index{Patch submission}
33586 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
33593 \begin_layout Standard
33594 You need to specify some parameters to the
33598 command for the patches to be useful.
33599 If you modified more than one file a patch created f.e.
33604 \begin_inset Quotes sld
33607 diff -Naur unmodified_directory modified_directory >my_changes.patch
33608 \begin_inset Quotes srd
33614 will be fine, otherwise
33618 \begin_inset Quotes sld
33621 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
33622 \begin_inset Quotes srd
33632 \begin_layout Section
33636 \begin_layout Standard
33637 These links should take you directly to the
33638 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
33646 \begin_layout Standard
33647 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
33648 automated messages (mid 2003)
33654 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
33659 \begin_inset LatexCommand \index{Mailing list(s)}
33663 and forums are archived and searchable so if you are lucky someone already
33664 had a similar problem.
33665 While mails to the lists themselves are delivered promptly their web front
33666 end on sourceforge sometimes shows a severe time lag (up to several weeks),
33667 if you're seriously using SDCC please consider subscribing to the lists.
33670 \begin_layout Section
33674 \begin_layout Standard
33675 You can follow the status of the Subversion version
33676 \begin_inset LatexCommand \index{version}
33680 of SDCC by watching the Changelog
33681 \begin_inset LatexCommand \index{Changelog}
33685 in the Subversion repository
33688 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
33695 \begin_layout Section
33696 Subversion Source Code Repository
33699 \begin_layout Standard
33709 \begin_layout Standard
33723 or the filenames of the snapshot versions of SDCC include date and its
33725 \begin_inset LatexCommand \index{Subversion code repository}
33730 Subversion allows to download the source of recent or previous versions
33732 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
33736 (by number or by date).
33737 An on-line source code browser and detailled instructions are also available
33739 SDCC versions starting from 1999 up to now are available (currently the
33740 versions prior to the conversion from cvs
33741 \begin_inset LatexCommand \index{cvs|see{Subversion}}
33745 to Subversion (April 2006) are either by accessible by Subversion or by
33749 \begin_layout Section
33751 \begin_inset LatexCommand \index{Release policy}
33758 \begin_layout Standard
33759 Historically there often were long delays between official releases and
33760 the sourceforge download area tends to get not updated at all.
33761 Excuses in the past might have referred to problems with live range analysis,
33762 but as this was fixed a while ago, the current problem is that another
33763 excuse has to be found.
33764 Kidding aside, we have to get better there! On the other hand there are
33765 daily snapshots available at
33766 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
33770 , and you can always build the very last version (hopefully with many bugs
33771 fixed, and features added) from the source code available at
33772 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
33778 \begin_inset LatexCommand \index{wiki}
33783 \begin_inset LatexCommand \index{SDCC Wiki}
33788 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/}
33792 also holds some information about past and future releases.
33795 \begin_layout Section
33797 \begin_inset LatexCommand \index{Examples}
33804 \begin_layout Standard
33805 You'll find some small examples in the directory
33807 sdcc/device/examples/.
33810 More examples and libraries are available at
33812 The SDCC Open Knowledge Resource
33813 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
33820 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
33827 \begin_layout Standard
33828 \begin_inset Note Note
33831 \begin_layout Standard
33832 I did insert a reference to Paul's web site here although it seems rather
33833 dedicated to a specific 8032 board (I think it's okay because it f.e.
33834 shows LCD/Harddisc interface and has a free 8051 monitor.
33835 Independent 8032 board vendors face hard competition of heavily subsidized
33836 development boards anyway).
33839 \begin_layout Standard
33840 Maybe we should include some links to real world applications.
33841 Preferably pointer to pointers (one for each architecture) so this stays
33850 \begin_layout Section
33852 \begin_inset LatexCommand \label{sec:Quality-control}
33857 \begin_inset LatexCommand \index{Quality control}
33864 \begin_layout Standard
33865 The compiler is passed through snaphot build compile and build checks.
33871 \begin_inset LatexCommand \index{Regression test}
33875 check that SDCC itself compiles flawlessly on several host platforms (i386,
33876 Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
33877 and checks the quality of the code generated by SDCC by running the code
33878 for several target platforms through simulators.
33879 The regression test suite comprises more than 100 files which expand to
33880 more than 500 test cases which include more than 4500 tests.
33881 The results of these tests are published daily on SDCC's snapshot page
33882 (click on the red or green symbols on the right side of
33883 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
33890 \begin_layout Standard
33891 There is a separate document
33894 \begin_inset LatexCommand \index{Test suite}
33901 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
33905 about the regression test suite.
33908 \begin_layout Standard
33909 You'll find the test code in the directory
33911 sdcc/support/regression
33914 You can run these tests manually by running
33918 in this directory (or f.e.
33923 \begin_inset Quotes sld
33927 \begin_inset Quotes srd
33933 if you don't want to run the complete tests).
33934 The test code might also be interesting if you want to look for examples
33935 \begin_inset LatexCommand \index{Examples}
33939 checking corner cases of SDCC or if you plan to submit patches
33940 \begin_inset LatexCommand \index{Patch submission}
33947 \begin_layout Standard
33948 The PIC14 port uses a different set of regression tests
33949 \begin_inset LatexCommand \index{Regression test (PIC14)}
33953 , you'll find them in the directory
33955 sdcc/src/regression
33960 \begin_layout Section
33961 Use of SDCC in Education
33964 \begin_layout Standard
33973 \begin_layout Standard
33974 the phrase "use in education" might evoke the association "
33978 fit for use in education".
33979 This connotation is not intended but nevertheless risked as the licensing
33980 of SDCC makes it difficult to offer educational discounts
33986 If your rationales are to:
33989 \begin_layout Enumerate
33990 give students a chance to understand the
33994 steps of code generation
33997 \begin_layout Enumerate
33998 have a curriculum that can be extended for years.
33999 Then you could use an fpga board as target and your curriculum will seamlessly
34000 extend from logic synthesis (
34001 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
34006 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
34010 ), over assembly programming, to C to FPGA compilers (
34011 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
34018 \begin_layout Enumerate
34019 be able to insert excursions about skills like using a revision control
34020 system, submitting/applying patches, using a type-setting (as opposed to
34021 word-processing) engine LyX/LaTeX, using
34022 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
34027 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
34031 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
34032 Source Software, CPU simulation, compiler regression tests
34033 \begin_inset LatexCommand \index{Regression test}
34040 And if there should be a shortage of ideas then you can always point students
34041 to the ever-growing feature request list
34042 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
34049 \begin_layout Enumerate
34050 not tie students to a specific host platform and instead allow them to use
34055 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
34057 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
34064 \begin_layout Enumerate
34065 not encourage students to use illegal copies of educational software
34068 \begin_layout Enumerate
34069 be immune to licensing/availability/price changes of the chosen tool chain
34072 \begin_layout Enumerate
34073 be able to change to a new target platform without having to adopt a new
34077 \begin_layout Enumerate
34078 have complete control over and insight into the tool chain
34081 \begin_layout Enumerate
34082 make your students aware about the pros and cons of open source software
34086 \begin_layout Enumerate
34087 give back to the public as you are probably at least partially publically
34091 \begin_layout Enumerate
34092 give students a chance to publically prove their skills and to possibly
34093 see a world wide impact
34096 \begin_layout Standard
34097 then SDCC is probably among the first choices.
34098 Well, probably SDCC might be the only choice.
34103 \begin_layout Chapter
34104 SDCC Technical Data
34107 \begin_layout Section
34109 \begin_inset LatexCommand \index{Optimizations}
34116 \begin_layout Standard
34117 SDCC performs a host of standard optimizations in addition to some MCU specific
34122 \begin_layout Subsection
34123 Sub-expression Elimination
34124 \begin_inset LatexCommand \index{Subexpression elimination}
34131 \begin_layout Standard
34132 The compiler does local and
34151 \begin_layout Verse
34159 \begin_layout Standard
34160 will be translated to
34163 \begin_layout Verse
34173 \begin_layout Standard
34174 Some subexpressions are not as obvious as the above example, e.g.:
34177 \begin_layout Verse
34185 \begin_layout Standard
34186 In this case the address arithmetic a->b[i] will be computed only once;
34187 the equivalent code in C would be.
34190 \begin_layout Verse
34200 \begin_layout Standard
34201 The compiler will try to keep these temporary variables in registers.
34204 \begin_layout Subsection
34205 Dead-Code Elimination
34206 \begin_inset LatexCommand \index{Dead-code elimination}
34213 \begin_layout Verse
34228 i = 1; \InsetSpace ~
34237 global = 1;\InsetSpace ~
34251 global = 3;\InsetSpace ~
34257 \begin_layout Standard
34261 \begin_layout Verse
34277 \begin_layout Subsection
34279 \begin_inset LatexCommand \index{Copy propagation}
34286 \begin_layout Verse
34310 \begin_layout Standard
34314 \begin_layout Verse
34338 \begin_layout Standard
34339 Note: the dead stores created by this copy propagation will be eliminated
34340 by dead-code elimination.
34343 \begin_layout Subsection
34345 \begin_inset LatexCommand \index{Loop optimization}
34350 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
34357 \begin_layout Standard
34358 Two types of loop optimizations are done by SDCC
34366 of loop induction variables.
34367 In addition to the strength reduction the optimizer marks the induction
34368 variables and the register allocator tries to keep the induction variables
34369 in registers for the duration of the loop.
34370 Because of this preference of the register allocator
34371 \begin_inset LatexCommand \index{Register allocation}
34375 , loop induction optimization causes an increase in register pressure, which
34376 may cause unwanted spilling of other temporary variables into the stack
34377 \begin_inset LatexCommand \index{stack}
34382 The compiler will generate a warning message when it is forced to allocate
34383 extra space either on the stack or data space.
34384 If this extra space allocation is undesirable then induction optimization
34385 can be eliminated either for the entire source file (with -
34389 \begin_layout Standard
34398 -noinduction option) or for a given function only using #pragma\InsetSpace ~
34400 \begin_inset LatexCommand \index{\#pragma noinduction}
34411 \begin_layout Verse
34414 for (i = 0 ; i < 100 ; i ++)
34423 \begin_layout Standard
34427 \begin_layout Verse
34432 for (i = 0; i < 100; i++)
34441 \begin_layout Standard
34442 As mentioned previously some loop invariants are not as apparent, all static
34443 address computations are also moved out of the loop.
34448 \begin_inset LatexCommand \index{Strength reduction}
34452 , this optimization substitutes an expression by a cheaper expression:
34455 \begin_layout Verse
34458 for (i=0;i < 100; i++)
34467 \begin_layout Standard
34471 \begin_layout Verse
34478 for (i=0;i< 100;i++) {
34484 ar[itemp1] = itemp2;
34502 \begin_layout Standard
34503 The more expensive multiplication
34504 \begin_inset LatexCommand \index{Multiplication}
34508 is changed to a less expensive addition.
34511 \begin_layout Subsection
34513 \begin_inset LatexCommand \index{Loop reversing}
34520 \begin_layout Standard
34521 This optimization is done to reduce the overhead of checking loop boundaries
34522 for every iteration.
34523 Some simple loops can be reversed and implemented using a
34524 \begin_inset Quotes eld
34527 decrement and jump if not zero
34528 \begin_inset Quotes erd
34532 SDCC checks for the following criterion to determine if a loop is reversible
34533 (note: more sophisticated compilers use data-dependency analysis to make
34534 this determination, SDCC uses a more simple minded analysis).
34537 \begin_layout Itemize
34538 The 'for' loop is of the form
34544 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
34554 \begin_layout Itemize
34555 The <for body> does not contain
34556 \begin_inset Quotes eld
34560 \begin_inset Quotes erd
34564 \begin_inset Quotes erd
34570 \begin_layout Itemize
34571 All goto's are contained within the loop.
34574 \begin_layout Itemize
34575 No function calls within the loop.
34578 \begin_layout Itemize
34579 The loop control variable <sym> is not assigned any value within the loop
34582 \begin_layout Itemize
34583 The loop control variable does NOT participate in any arithmetic operation
34587 \begin_layout Itemize
34588 There are NO switch statements in the loop.
34591 \begin_layout Subsection
34592 Algebraic Simplifications
34595 \begin_layout Standard
34596 SDCC does numerous algebraic simplifications, the following is a small sub-set
34597 of these optimizations.
34600 \begin_layout Verse
34603 i = j + 0;\InsetSpace ~
34607 /* changed to: */\InsetSpace ~
34613 i /= 2;\InsetSpace ~
34620 /* changed to: */\InsetSpace ~
34627 = j - j;\InsetSpace ~
34631 /* changed to: */\InsetSpace ~
34637 i = j / 1;\InsetSpace ~
34641 /* changed to: */\InsetSpace ~
34648 \begin_layout Standard
34649 Note the subexpressions
34650 \begin_inset LatexCommand \index{Subexpression}
34654 given above are generally introduced by macro expansions or as a result
34655 of copy/constant propagation.
34658 \begin_layout Subsection
34659 'switch' Statements
34660 \begin_inset LatexCommand \label{sub:'switch'-Statements}
34665 \begin_inset LatexCommand \index{switch statement}
34672 \begin_layout Standard
34673 SDCC can optimize switch statements to jump tables
34674 \begin_inset LatexCommand \index{jump tables}
34679 It makes the decision based on an estimate of the generated code size.
34680 SDCC is quite liberal in the requirements for jump table generation:
34683 \begin_layout Itemize
34684 The labels need not be in order, and the starting number need not be one
34685 or zero, the case labels are in numerical sequence or not too many case
34686 labels are missing.
34690 \begin_layout Verse
34693 switch(i) {\InsetSpace ~
34724 case 4: ...\InsetSpace ~
34756 case 5: ...\InsetSpace ~
34788 case 3: ...\InsetSpace ~
34819 case 6: ...\InsetSpace ~
34851 case 7: ...\InsetSpace ~
34883 case 8: ...\InsetSpace ~
34915 case 9: ...\InsetSpace ~
34947 case 10: ...\InsetSpace ~
34978 case 11: ...\InsetSpace ~
35045 \begin_layout Standard
35046 Both the above switch statements will be implemented using a jump-table.
35047 The example to the right side is slightly more efficient as the check for
35048 the lower boundary of the jump-table is not needed.
35052 \begin_layout Itemize
35053 The number of case labels is not larger than supported by the target architectur
35057 \begin_layout Itemize
35058 If the case labels are not in numerical sequence ('gaps' between cases)
35059 SDCC checks whether a jump table with additionally inserted dummy cases
35060 is still attractive.
35064 \begin_layout Itemize
35065 If the starting number is not zero and a check for the lower boundary of
35066 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
35071 \begin_layout Standard
35072 Switch statements which have large gaps in the numeric sequence or those
35073 that have too many case labels can be split into more than one switch statement
35074 for efficient code generation, e.g.:
35077 \begin_layout Verse
35155 \begin_layout Standard
35156 If the above switch statement is broken down into two switch statements
35159 \begin_layout Verse
35202 \begin_layout Standard
35206 \begin_layout Verse
35249 \begin_layout Standard
35250 then both the switch statements will be implemented using jump-tables whereas
35251 the unmodified switch statement will not be.
35254 \begin_layout Standard
35255 \begin_inset Note Note
35258 \begin_layout Standard
35259 There might be reasons which SDCC cannot know about to either favour or
35260 not favour jump tables.
35261 If the target system has to be as quick for the last switch case as for
35262 the first (pro jump table), or if the switch argument is known to be zero
35263 in the majority of the cases (contra jump table).
35271 \begin_layout Standard
35272 The pragma nojtbound
35273 \begin_inset LatexCommand \index{\#pragma nojtbound}
35277 can be used to turn off checking the
35290 It has no effect if a default label is supplied.
35291 Use of this pragma is dangerous: if the switch
35292 \begin_inset LatexCommand \index{switch statement}
35296 argument is not matched by a case statement the processor will happily
35300 \begin_layout Subsection
35301 Bit-shifting Operations
35302 \begin_inset LatexCommand \index{Bit shifting}
35309 \begin_layout Standard
35310 Bit shifting is one of the most frequently used operation in embedded programmin
35312 SDCC tries to implement bit-shift operations in the most efficient way
35316 \begin_layout Verse
35329 \begin_layout Standard
35330 generates the following code:
35333 \begin_layout Verse
35348 \begin_layout Standard
35349 In general SDCC will never setup a loop if the shift count is known.
35353 \begin_layout Verse
35366 \begin_layout Standard
35370 \begin_layout Verse
35394 \begin_layout Subsection
35396 \begin_inset LatexCommand \index{Bit rotation}
35403 \begin_layout Standard
35404 A special case of the bit-shift operation is bit rotation
35405 \begin_inset LatexCommand \index{rotating bits}
35409 , SDCC recognizes the following expression to be a left bit-rotation:
35412 \begin_layout Verse
35420 char i;\InsetSpace ~
35431 /* unsigned is needed for rotation */
35436 i = ((i << 1) | (i >> 7));
35445 \begin_layout Standard
35446 will generate the following code:
35449 \begin_layout Verse
35466 \begin_layout Standard
35467 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
35468 ns of this case will also be recognized as bit-rotation, i.e.:
35471 \begin_layout Verse
35474 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
35477 \begin_layout Subsection
35478 Nibble and Byte Swapping
35481 \begin_layout Standard
35482 Other special cases of the bit-shift operations are nibble or byte swapping
35483 \begin_inset LatexCommand \index{swapping nibbles/bytes}
35487 , SDCC recognizes the following expressions:
35490 \begin_layout Verse
35511 i = ((i << 4) | (i >> 4));
35517 j = ((j << 8) | (j >> 8));
35520 \begin_layout Standard
35521 and generates a swap instruction for the nibble swapping
35522 \begin_inset LatexCommand \index{Nibble swapping}
35526 or move instructions for the byte swapping
35527 \begin_inset LatexCommand \index{Byte swapping}
35533 \begin_inset Quotes sld
35537 \begin_inset Quotes srd
35540 example can be used to convert from little to big-endian or vice versa.
35541 If you want to change the endianness of a
35545 integer you have to cast to
35552 \begin_layout Standard
35553 Note that SDCC stores numbers in little-endian
35557 \begin_layout Standard
35558 Usually 8-bit processors don't care much about endianness.
35559 This is not the case for the standard 8051 which only has an instruction
35565 \begin_inset LatexCommand \index{DPTR}
35573 so little-endian is the more efficient byte order.
35579 \begin_inset LatexCommand \index{little-endian}
35584 \begin_inset LatexCommand \index{Endianness}
35589 lowest order first).
35592 \begin_layout Subsection
35594 \begin_inset LatexCommand \index{Highest Order Bit}
35599 \begin_inset LatexCommand \index{Any Order Bit}
35606 \begin_layout Standard
35607 It is frequently required to obtain the highest order bit of an integral
35608 type (long, int, short or char types).
35609 Also obtaining any other order bit is not uncommon.
35610 SDCC recognizes the following expressions to yield the highest order bit
35611 and generates optimized code for it, e.g.:
35614 \begin_layout Verse
35625 unsigned char hob1, aob1;
35629 bit hob2, hob3, aob2,
35639 hob1 = (gint >> 15) & 1;
35643 hob2 = (gint >> 15) & 1;
35647 hob3 = gint & 0x8000;
35652 aob1 = (gint >> 9) & 1;
35656 aob2 = (gint >> 8) & 1;
35660 aob3 = gint & 0x0800;
35670 \begin_layout Standard
35671 will generate the following code:
35674 \begin_layout Verse
35705 000A E5*01\InsetSpace ~
35732 000C 23\InsetSpace ~
35763 000D 54 01\InsetSpace ~
35791 000F F5*02\InsetSpace ~
35846 0011 E5*01\InsetSpace ~
35874 0013 33\InsetSpace ~
35904 0014 92*00\InsetSpace ~
35960 0016 E5*01\InsetSpace ~
35987 0018 33\InsetSpace ~
36017 0019 92*01\InsetSpace ~
36073 001B E5*01\InsetSpace ~
36132 001E 54 01\InsetSpace ~
36159 0020 F5*03\InsetSpace ~
36215 0022 E5*01\InsetSpace ~
36242 0024 13\InsetSpace ~
36272 0025 92*02\InsetSpace ~
36328 0027 E5*01\InsetSpace ~
36383 002B 92*03\InsetSpace ~
36411 \begin_layout Standard
36412 Other variations of these cases however will
36417 They are standard C expressions, so I heartily recommend these be the only
36418 way to get the highest order bit, (it is portable).
36419 Of course it will be recognized even if it is embedded in other expressions,
36423 \begin_layout Verse
36426 xyz = gint + ((gint >> 15) & 1);
36429 \begin_layout Standard
36430 will still be recognized.
36433 \begin_layout Subsection
36435 \begin_inset LatexCommand \index{Higher Order Byte}
36439 / Higher Order Word
36440 \begin_inset LatexCommand \index{Higher Order Word}
36447 \begin_layout Standard
36448 It is also frequently required to obtain a higher order byte or word of
36449 a larger integral type (long, int or short types).
36450 SDCC recognizes the following expressions to yield the higher order byte
36451 or word and generates optimized code for it, e.g.:
36454 \begin_layout Verse
36459 unsigned long int glong;
36467 unsigned char hob1,
36472 unsigned int how1, how2;
36481 hob1 = (gint >> 8) & 0xFF;
36485 hob2 = glong >> 24;
36489 how1 = (glong >> 16) & 0xFFFF;
36504 \begin_layout Standard
36505 will generate the following code:
36508 \begin_layout Verse
36539 0037 85*01*06\InsetSpace ~
36561 _foo_hob1_1_1,(_gint + 1)
36592 003A 85*05*07\InsetSpace ~
36614 _foo_hob2_1_1,(_glong + 3)
36644 003D 85*04*08\InsetSpace ~
36667 _foo_how1_1_1,(_glong + 2)
36669 0040 85*05*09\InsetSpace ~
36694 0043 85*03*0A\InsetSpace ~
36716 _foo_how2_1_1,(_glong + 1)
36718 0046 85*04*0B\InsetSpace ~
36741 (_foo_how2_1_1 + 1),(_glong + 2)
36744 \begin_layout Standard
36745 Again, variations of these cases may
36750 They are standard C expressions, so I heartily recommend these be the only
36751 way to get the higher order byte/word, (it is portable).
36752 Of course it will be recognized even if it is embedded in other expressions,
36756 \begin_layout Verse
36759 xyz = gint + ((gint >> 8) & 0xFF);
36762 \begin_layout Standard
36763 will still be recognized.
36766 \begin_layout Subsection
36768 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
36773 \begin_inset LatexCommand \index{Peephole optimizer}
36780 \begin_layout Standard
36781 The compiler uses a rule based, pattern matching and re-writing mechanism
36782 for peep-hole optimization.
36787 a peep-hole optimizer by Christopher W.
36788 Fraser (cwfraser\InsetSpace ~
36791 A default set of rules are compiled into the compiler, additional rules
36792 may be added with the
36798 \begin_layout Standard
36808 \begin_inset LatexCommand \index{-\/-peep-file}
36815 The rule language is best illustrated with examples.
36818 \begin_layout Verse
36840 \begin_layout Standard
36841 The above rule will change the following assembly
36842 \begin_inset LatexCommand \index{Assembler routines}
36849 \begin_layout Verse
36857 \begin_layout Standard
36861 \begin_layout Verse
36867 \begin_layout Standard
36868 Note: All occurrences of a
36872 (pattern variable) must denote the same string.
36873 With the above rule, the assembly sequence:
36876 \begin_layout Verse
36884 \begin_layout Standard
36885 will remain unmodified.
36889 Other special case optimizations may be added by the
36896 \begin_layout Standard
36909 some variants of the 8051 MCU
36910 \begin_inset LatexCommand \index{MCS51 variants}
36923 The following two rules will change all
36940 \begin_layout Verse
36943 replace { lcall %1 } by { acall %1 }
36945 replace { ljmp %1 } by { ajmp %1 }
36948 \begin_layout Standard
36949 (NOTE: from version 2.7.3 on, you can use option -
36955 \begin_layout Standard
36967 \begin_inset LatexCommand \index{-\/-acall-ajmp}
36971 , which also takes care of aligning the interrupt vectors properly.)
36976 \begin_layout Standard
36979 inline-assembler code
36981 is also passed through the peep hole optimizer, thus the peephole optimizer
36982 can also be used as an assembly level macro expander.
36983 The rules themselves are MCU dependent whereas the rule language infra-structur
36984 e is MCU independent.
36985 Peephole optimization rules for other MCU can be easily programmed using
36990 The syntax for a rule is as follows:
36993 \begin_layout Verse
36996 rule := replace [ restart ] '{' <assembly sequence> '
37034 <assembly sequence> '
37052 '}' [if <functionName> ] '
37057 \begin_layout Standard
37058 <assembly sequence> := assembly instruction (each instruction including
37059 labels must be on a separate line).
37063 The optimizer will apply to the rules
37064 one by one from the top in the sequence of their appearance, it will terminate
37065 when all rules are exhausted.
37066 If the 'restart' option is specified, then the optimizer will start matching
37067 the rules again from the top, this option for a rule is expensive (performance)
37068 , it is intended to be used in situations where a transformation will trigger
37069 the same rule again.
37070 An example of this (not a good one, it has side effects) is the following
37074 \begin_layout Verse
37094 \begin_layout Standard
37095 Note that the replace pattern cannot be a blank, but can be a comment line.
37096 Without the 'restart' option only the innermost 'pop' 'push' pair would
37097 be eliminated, i.e.:
37100 \begin_layout Verse
37112 \begin_layout Standard
37116 \begin_layout Verse
37126 \begin_layout Standard
37131 the restart option the rule will be applied again to the resulting code
37132 and then all the pop-push pairs will be eliminated to yield:
37135 \begin_layout Verse
37143 \begin_layout Standard
37144 A conditional function can be attached to a rule.
37145 Attaching rules are somewhat more involved, let me illustrate this with
37149 \begin_layout Verse
37173 \begin_layout Standard
37174 The optimizer does a look-up of a function name table defined in function
37179 in the source file SDCCpeeph.c, with the name
37184 If it finds a corresponding entry the function is called.
37185 Note there can be no parameters specified for these functions, in this
37190 is crucial, since the function
37194 expects to find the label in that particular variable (the hash table containin
37195 g the variable bindings is passed as a parameter).
37196 If you want to code more such functions, take a close look at the function
37197 labelInRange and the calling mechanism in source file SDCCpeeph.c.
37198 Currently implemented are
37200 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
37201 24bitMode, portIsDS390, 24bitModeAndPortDS390
37210 \begin_layout Standard
37211 I know this whole thing is a little kludgey, but maybe some day we will
37212 have some better means.
37213 If you are looking at this file, you will see the default rules that are
37214 compiled into the compiler, you can add your own rules in the default set
37215 there if you get tired of specifying the -
37219 \begin_layout Standard
37231 \begin_layout Section
37233 \begin_inset LatexCommand \index{ANSI-compliance}
37238 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
37245 \begin_layout Standard
37246 The latest publically available version of the standard
37248 ISO/IEC 9899 - Programming languages - C
37250 should be available at:
37251 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
37260 \begin_layout Standard
37261 Deviations from the compliance:
37264 \begin_layout Itemize
37265 functions are not reentrant
37266 \begin_inset LatexCommand \index{reentrant}
37270 unless explicitly declared as such or the
37276 \begin_layout Standard
37286 \begin_inset LatexCommand \index{-\/-stack-auto}
37292 command line option is specified.
37295 \begin_layout Itemize
37297 \begin_inset LatexCommand \index{struct}
37302 \begin_inset LatexCommand \index{union}
37306 cannot be assigned values directly, cannot be passed as function parameters
37307 or assigned to each other and cannot be a return value
37308 \begin_inset LatexCommand \index{return value}
37312 from a function, e.g.:
37316 \begin_layout Verse
37339 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
37358 s parms) /* invalid in SDCC although allowed in ANSI */
37380 return rets; /* is invalid in SDCC although allowed in ANSI */
37386 \begin_layout Itemize
37387 initialization of structure arrays must be fully braced.
37391 \begin_layout Verse
37394 struct s { char x } a[] = {1, 2};\InsetSpace ~
37399 /* invalid in SDCC */
37402 } a[] = {{1}, {2}}; /* OK */
37406 \begin_layout Itemize
37408 \begin_inset LatexCommand \index{long long (not supported)}
37413 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
37420 \begin_layout Itemize
37422 \begin_inset LatexCommand \index{double (not supported)}
37426 ' precision floating point
37427 \begin_inset LatexCommand \index{Floating point support}
37434 \begin_layout Itemize
37436 \begin_inset LatexCommand \index{K\&R style}
37440 function declarations are NOT allowed.
37444 \begin_layout Verse
37447 foo(i,j) /* this old style of function declarations */
37449 int i,j; /* is valid
37450 in ANSI but not valid in SDCC */
37465 \begin_layout Itemize
37466 Most enhancements in C99 are not supported, e.g.:
37470 \begin_layout Verse
37477 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
37481 \begin_layout Itemize
37482 But some have been added recently in SDCC 2.7.0.
37483 They must be considered alpha quality however.
37487 \begin_layout Verse
37492 \begin_inset LatexCommand \index{inline (not supported)}
37498 int increment (int a) { return a+1; } /* inlines the increment without
37499 function call overhead */
37504 \begin_inset LatexCommand \index{inline (not supported)}
37510 p; /* accepted but ignored */
37514 \begin_layout Itemize
37515 Certain words that are valid identifiers in the standard may be reserved
37516 words in SDCC unless the
37522 \begin_layout Standard
37532 \begin_inset LatexCommand \index{-\/-std-c89}
37544 \begin_layout Standard
37554 \begin_inset LatexCommand \index{-\/-std-c99}
37560 command line options are used.
37561 These may include (depending on the selected processor): 'at', 'banked',
37562 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
37563 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
37564 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
37566 Compliant equivalents of these keywords are always available in a form
37567 that begin with two underscores
37568 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
37573 '__data' instead of 'data'.
37576 \begin_layout Itemize
37577 Integer promotion of variable arguments is not performed if the argument
37578 is explicitly taypecasted unless the
37584 \begin_layout Standard
37594 \begin_inset LatexCommand \index{-\/-std-c89}
37606 \begin_layout Standard
37616 \begin_inset LatexCommand \index{-\/-std-c99}
37622 command line options are used.
37626 \begin_layout Verse
37629 void vararg_func (char *str, ...) { str; }
37646 u is promoted to int before
37651 * passing to function */
37655 vararg_func ("%c", c);
37662 argument u is not promoted to int,
37667 * it is passed as char to function
37673 --std-cXX is not defined;
37678 * is promoted to int before passing
37684 if --std-cXX is defined */
37688 vararg_func ("%bc", (char)u);
37694 \begin_layout Section
37695 Cyclomatic Complexity
37696 \begin_inset LatexCommand \index{Cyclomatic complexity}
37703 \begin_layout Standard
37704 Cyclomatic complexity of a function is defined as the number of independent
37705 paths the program can take during execution of the function.
37706 This is an important number since it defines the number test cases you
37707 have to generate to validate the function.
37708 The accepted industry standard for complexity number is 10, if the cyclomatic
37709 complexity reported by SDCC exceeds 10 you should think about simplification
37710 of the function logic.
37711 Note that the complexity level is not related to the number of lines of
37712 code in a function.
37713 Large functions can have low complexity, and small functions can have large
37719 SDCC uses the following formula to compute the complexity:
37724 \begin_layout Standard
37725 complexity = (number of edges in control flow graph) - (number of nodes
37726 in control flow graph) + 2;
37730 Having said that the industry standard is 10,
37731 you should be aware that in some cases it be may unavoidable to have a
37732 complexity level of less than 10.
37733 For example if you have switch statement with more than 10 case labels,
37734 each case label adds one to the complexity level.
37735 The complexity level is by no means an absolute measure of the algorithmic
37736 complexity of the function, it does however provide a good starting point
37737 for which functions you might look at for further optimization.
37740 \begin_layout Section
37741 Retargetting for other Processors
37744 \begin_layout Standard
37745 The issues for retargetting the compiler are far too numerous to be covered
37747 What follows is a brief description of each of the seven phases of the
37748 compiler and its MCU dependency.
37751 \begin_layout Itemize
37752 Parsing the source and building the annotated parse tree.
37753 This phase is largely MCU independent (except for the language extensions).
37754 Syntax & semantic checks are also done in this phase, along with some initial
37755 optimizations like back patching labels and the pattern matching optimizations
37756 like bit-rotation etc.
37759 \begin_layout Itemize
37760 The second phase involves generating an intermediate code which can be easy
37761 manipulated during the later phases.
37762 This phase is entirely MCU independent.
37763 The intermediate code generation assumes the target machine has unlimited
37764 number of registers, and designates them with the name iTemp.
37765 The compiler can be made to dump a human readable form of the code generated
37770 \begin_layout Standard
37782 \begin_layout Itemize
37783 This phase does the bulk of the standard optimizations and is also MCU independe
37785 This phase can be broken down into several sub-phases:
37789 Break down intermediate
37790 code (iCode) into basic blocks.
37792 Do control flow & data flow analysis on the
37795 Do local common subexpression elimination, then global subexpressio
37798 Dead code elimination
37802 If loop optimizations
37803 caused any changes then do 'global subexpression elimination' and 'dead
37804 code elimination' again.
37807 \begin_layout Itemize
37808 This phase determines the live-ranges; by live range I mean those iTemp
37809 variables defined by the compiler that still survive after all the optimization
37811 Live range analysis
37812 \begin_inset LatexCommand \index{Live range analysis}
37816 is essential for register allocation, since these computation determines
37817 which of these iTemps will be assigned to registers, and for how long.
37820 \begin_layout Itemize
37821 Phase five is register allocation.
37822 There are two parts to this process.
37826 The first part I call 'register packing'
37827 (for lack of a better term).
37828 In this case several MCU specific expression folding is done to reduce
37833 The second part is more MCU independent and deals with
37834 allocating registers to the remaining live ranges.
37835 A lot of MCU specific code does creep into this phase because of the limited
37836 number of index registers available in the 8051.
37839 \begin_layout Itemize
37840 The Code generation phase is (unhappily), entirely MCU dependent and very
37841 little (if any at all) of this code can be reused for other MCU.
37842 However the scheme for allocating a homogenized assembler operand for each
37843 iCode operand may be reused.
37846 \begin_layout Itemize
37847 As mentioned in the optimization section the peep-hole optimizer is rule
37848 based system, which can reprogrammed for other MCUs.
37851 \begin_layout Standard
37852 More information is available on SDCC Wiki
37853 \begin_inset LatexCommand \index{wiki}
37858 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting}
37862 ) and in the thread
37863 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
37870 \begin_layout Chapter
37872 \begin_inset LatexCommand \index{Compiler internals}
37879 \begin_layout Section
37880 The anatomy of the compiler
37881 \begin_inset LatexCommand \label{sub:The-anatomy-of}
37888 \begin_layout Standard
37891 This is an excerpt from an article published in Circuit Cellar Magazine
37897 It's a little outdated (the compiler is much more efficient now and user/develo
37898 per friendly), but pretty well exposes the guts of it all.
37904 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
37905 It is fairly easy to retarget for other 8-bit MCU.
37906 Here we take a look at some of the internals of the compiler.
37910 \begin_layout Paragraph*
37912 \begin_inset LatexCommand \index{Parsing}
37919 \begin_layout Standard
37920 Parsing the input source file and creating an AST (Annotated Syntax Tree
37921 \begin_inset LatexCommand \index{Annotated syntax tree}
37926 This phase also involves propagating types (annotating each node of the
37927 parse tree with type information) and semantic analysis.
37928 There are some MCU specific parsing rules.
37929 For example the storage classes, the extended storage classes are MCU specific
37930 while there may be a xdata storage class for 8051 there is no such storage
37931 class for z80 or Atmel AVR.
37932 SDCC allows MCU specific storage class extensions, i.e.
37933 xdata will be treated as a storage class specifier when parsing 8051 C
37934 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
37938 \begin_layout Paragraph*
37940 \begin_inset LatexCommand \index{iCode}
37947 \begin_layout Standard
37948 Intermediate code generation.
37949 In this phase the AST is broken down into three-operand form (iCode).
37950 These three operand forms are represented as doubly linked lists.
37951 ICode is the term given to the intermediate form generated by the compiler.
37952 ICode example section shows some examples of iCode generated for some simple
37953 C source functions.
37956 \begin_layout Paragraph*
37958 \begin_inset LatexCommand \index{Optimizations}
37965 \begin_layout Standard
37966 Bulk of the target independent optimizations is performed in this phase.
37967 The optimizations include constant propagation, common sub-expression eliminati
37968 on, loop invariant code movement, strength reduction of loop induction variables
37969 and dead-code elimination.
37972 \begin_layout Paragraph*
37973 Live range analysis
37974 \begin_inset LatexCommand \index{Live range analysis}
37981 \begin_layout Standard
37982 During intermediate code generation phase, the compiler assumes the target
37983 machine has infinite number of registers and generates a lot of temporary
37985 The live range computation determines the lifetime of each of these compiler-ge
37986 nerated temporaries.
37987 A picture speaks a thousand words.
37988 ICode example sections show the live range annotations for each of the
37990 It is important to note here, each iCode is assigned a number in the order
37991 of its execution in the function.
37992 The live ranges are computed in terms of these numbers.
37993 The from number is the number of the iCode which first defines the operand
37994 and the to number signifies the iCode which uses this operand last.
37997 \begin_layout Paragraph*
37998 Register Allocation
37999 \begin_inset LatexCommand \index{Register allocation}
38006 \begin_layout Standard
38007 The register allocation determines the type and number of registers needed
38009 In most MCUs only a few registers can be used for indirect addressing.
38010 In case of 8051 for example the registers R0 & R1 can be used to indirectly
38011 address the internal ram and DPTR to indirectly address the external ram.
38012 The compiler will try to allocate the appropriate register to pointer variables
38014 ICode example section shows the operands annotated with the registers assigned
38016 The compiler will try to keep operands in registers as much as possible;
38017 there are several schemes the compiler uses to do achieve this.
38018 When the compiler runs out of registers the compiler will check to see
38019 if there are any live operands which is not used or defined in the current
38020 basic block being processed, if there are any found then it will push that
38021 operand and use the registers in this block, the operand will then be popped
38022 at the end of the basic block.
38026 \begin_layout Standard
38027 There are other MCU specific considerations in this phase.
38028 Some MCUs have an accumulator; very short-lived operands could be assigned
38029 to the accumulator instead of a general-purpose register.
38032 \begin_layout Paragraph*
38036 \begin_layout Standard
38037 Figure II gives a table of iCode
38038 \begin_inset LatexCommand \index{iCode}
38042 operations supported by the compiler.
38043 The code generation involves translating these operations into corresponding
38044 assembly code for the processor.
38045 This sounds overly simple but that is the essence of code generation.
38046 Some of the iCode operations are generated on a MCU specific manner for
38047 example, the z80 port does not use registers to pass parameters so the
38048 SEND and RECV iCode operations will not be generated, and it also does
38049 not support JUMPTABLES.
38055 \begin_layout Standard
38059 \begin_inset Tabular
38060 <lyxtabular version="3" rows="39" columns="4">
38061 <features islongtable="true" headBottomDL="true">
38062 <column alignment="block" valignment="top" leftline="true" width="13col%">
38063 <column alignment="left" valignment="top" leftline="true" width="13col%">
38064 <column alignment="block" valignment="top" leftline="true" width="22col%">
38065 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
38066 <row topline="true" bottomline="true" endhead="true">
38067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38070 \begin_layout Standard
38076 \begin_inset LatexCommand \index{iCode}
38085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38088 \begin_layout Standard
38096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38099 \begin_layout Standard
38107 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38110 \begin_layout Standard
38119 <row topline="true">
38120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38123 \begin_layout Standard
38131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38134 \begin_layout Standard
38137 IC_LEFT() IC_RESULT()
38142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38145 \begin_layout Standard
38153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38156 \begin_layout Standard
38159 IC_RESULT = ! IC_LEFT;
38165 <row topline="true">
38166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38169 \begin_layout Standard
38177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38180 \begin_layout Standard
38183 IC_LEFT() IC_RESULT()
38188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38191 \begin_layout Standard
38194 Bitwise complement of
38199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38202 \begin_layout Standard
38205 IC_RESULT = ~IC_LEFT;
38211 <row topline="true">
38212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38215 \begin_layout Standard
38223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38226 \begin_layout Standard
38229 IC_LEFT() IC_RESULT()
38234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38237 \begin_layout Standard
38240 Rotate right with carry
38245 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38248 \begin_layout Standard
38251 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
38257 <row topline="true">
38258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38261 \begin_layout Standard
38269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38272 \begin_layout Standard
38275 IC_LEFT() IC_RESULT()
38280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38283 \begin_layout Standard
38286 Rotate left with carry
38291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38294 \begin_layout Standard
38297 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
38303 <row topline="true">
38304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38307 \begin_layout Standard
38315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38318 \begin_layout Standard
38321 IC_LEFT() IC_RESULT()
38326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38329 \begin_layout Standard
38332 Get the highest order bit of IC_LEFT
38337 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38340 \begin_layout Standard
38343 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
38349 <row topline="true">
38350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38353 \begin_layout Standard
38361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38364 \begin_layout Standard
38367 IC_LEFT() IC_RESULT()
38372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38375 \begin_layout Standard
38383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38386 \begin_layout Standard
38389 IC_RESULT = - IC_LEFT;
38395 <row topline="true">
38396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38399 \begin_layout Standard
38407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38410 \begin_layout Standard
38418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38421 \begin_layout Standard
38424 Push the operand into stack
38429 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38432 \begin_layout Standard
38441 <row topline="true">
38442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38445 \begin_layout Standard
38453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38456 \begin_layout Standard
38464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38467 \begin_layout Standard
38470 Pop the operand from the stack
38475 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38478 \begin_layout Standard
38487 <row topline="true">
38488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38491 \begin_layout Standard
38499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38502 \begin_layout Standard
38505 IC_LEFT() IC_RESULT()
38510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38513 \begin_layout Standard
38516 Call the function represented by IC_LEFT
38521 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38524 \begin_layout Standard
38527 IC_RESULT = IC_LEFT();
38533 <row topline="true">
38534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38537 \begin_layout Standard
38545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38548 \begin_layout Standard
38551 IC_LEFT() IC_RESULT()
38556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38559 \begin_layout Standard
38562 Call via function pointer
38567 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38570 \begin_layout Standard
38573 IC_RESULT = (*IC_LEFT)();
38579 <row topline="true">
38580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38583 \begin_layout Standard
38591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38594 \begin_layout Standard
38602 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38605 \begin_layout Standard
38608 Return the value in operand IC_LEFT
38613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38616 \begin_layout Standard
38625 <row topline="true">
38626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38629 \begin_layout Standard
38637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38640 \begin_layout Standard
38648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38651 \begin_layout Standard
38659 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38662 \begin_layout Standard
38671 <row topline="true">
38672 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38675 \begin_layout Standard
38683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38686 \begin_layout Standard
38694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38697 \begin_layout Standard
38705 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38708 \begin_layout Standard
38717 <row topline="true">
38718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38721 \begin_layout Standard
38729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38732 \begin_layout Standard
38735 IC_LEFT() IC_RIGHT() IC_RESULT()
38740 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38743 \begin_layout Standard
38751 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38754 \begin_layout Standard
38757 IC_RESULT = IC_LEFT + IC_RIGHT
38763 <row topline="true">
38764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38767 \begin_layout Standard
38775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38778 \begin_layout Standard
38781 IC_LEFT() IC_RIGHT() IC_RESULT()
38786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38789 \begin_layout Standard
38797 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38800 \begin_layout Standard
38803 IC_RESULT = IC_LEFT - IC_RIGHT
38809 <row topline="true">
38810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38813 \begin_layout Standard
38821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38824 \begin_layout Standard
38827 IC_LEFT() IC_RIGHT() IC_RESULT()
38832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38835 \begin_layout Standard
38843 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38846 \begin_layout Standard
38849 IC_RESULT = IC_LEFT * IC_RIGHT;
38855 <row topline="true">
38856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38859 \begin_layout Standard
38867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38870 \begin_layout Standard
38873 IC_LEFT() IC_RIGHT() IC_RESULT()
38878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38881 \begin_layout Standard
38889 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38892 \begin_layout Standard
38895 IC_RESULT = IC_LEFT / IC_RIGHT;
38901 <row topline="true">
38902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38905 \begin_layout Standard
38913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38916 \begin_layout Standard
38919 IC_LEFT() IC_RIGHT() IC_RESULT()
38924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38927 \begin_layout Standard
38935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38938 \begin_layout Standard
38941 IC_RESULT = IC_LEFT % IC_RIGHT;
38947 <row topline="true">
38948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38951 \begin_layout Standard
38959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38962 \begin_layout Standard
38965 IC_LEFT() IC_RIGHT() IC_RESULT()
38970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38973 \begin_layout Standard
38981 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38984 \begin_layout Standard
38987 IC_RESULT = IC_LEFT < IC_RIGHT;
38993 <row topline="true">
38994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38997 \begin_layout Standard
39005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39008 \begin_layout Standard
39011 IC_LEFT() IC_RIGHT() IC_RESULT()
39016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39019 \begin_layout Standard
39027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39030 \begin_layout Standard
39033 IC_RESULT = IC_LEFT > IC_RIGHT;
39039 <row topline="true">
39040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39043 \begin_layout Standard
39051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39054 \begin_layout Standard
39057 IC_LEFT() IC_RIGHT() IC_RESULT()
39062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39065 \begin_layout Standard
39073 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39076 \begin_layout Standard
39079 IC_RESULT = IC_LEFT == IC_RIGHT;
39085 <row topline="true">
39086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39089 \begin_layout Standard
39097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39100 \begin_layout Standard
39103 IC_LEFT() IC_RIGHT() IC_RESULT()
39108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39111 \begin_layout Standard
39114 Logical and operation
39119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39122 \begin_layout Standard
39125 IC_RESULT = IC_LEFT && IC_RIGHT;
39131 <row topline="true">
39132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39135 \begin_layout Standard
39143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39146 \begin_layout Standard
39149 IC_LEFT() IC_RIGHT() IC_RESULT()
39154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39157 \begin_layout Standard
39160 Logical or operation
39165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39168 \begin_layout Standard
39171 IC_RESULT = IC_LEFT || IC_RIGHT;
39177 <row topline="true">
39178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39181 \begin_layout Standard
39189 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39192 \begin_layout Standard
39195 IC_LEFT() IC_RIGHT() IC_RESULT()
39200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39203 \begin_layout Standard
39211 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39214 \begin_layout Standard
39217 IC_RESULT = IC_LEFT ^ IC_RIGHT;
39223 <row topline="true">
39224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39227 \begin_layout Standard
39235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39238 \begin_layout Standard
39241 IC_LEFT() IC_RIGHT() IC_RESULT()
39246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39249 \begin_layout Standard
39257 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39260 \begin_layout Standard
39263 IC_RESULT = IC_LEFT | IC_RIGHT;
39269 <row topline="true">
39270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39273 \begin_layout Standard
39281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39284 \begin_layout Standard
39287 IC_LEFT() IC_RIGHT() IC_RESULT()
39292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39295 \begin_layout Standard
39303 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39306 \begin_layout Standard
39309 IC_RESULT = IC_LEFT & IC_RIGHT;
39315 <row topline="true">
39316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39319 \begin_layout Standard
39327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39330 \begin_layout Standard
39333 IC_LEFT() IC_RIGHT() IC_RESULT()
39338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39341 \begin_layout Standard
39349 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39352 \begin_layout Standard
39355 IC_RESULT = IC_LEFT << IC_RIGHT
39361 <row topline="true">
39362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39365 \begin_layout Standard
39373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39376 \begin_layout Standard
39379 IC_LEFT() IC_RIGHT() IC_RESULT()
39384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39387 \begin_layout Standard
39395 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39398 \begin_layout Standard
39401 IC_RESULT = IC_LEFT >> IC_RIGHT
39407 <row topline="true">
39408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39411 \begin_layout Standard
39421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39424 \begin_layout Standard
39427 IC_LEFT() IC_RESULT()
39432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39435 \begin_layout Standard
39443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39446 \begin_layout Standard
39449 IC_RESULT = (*IC_LEFT);
39455 <row topline="true">
39456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39459 \begin_layout Standard
39467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39470 \begin_layout Standard
39473 IC_RIGHT() IC_RESULT()
39478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39481 \begin_layout Standard
39489 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39492 \begin_layout Standard
39495 (*IC_RESULT) = IC_RIGHT;
39501 <row topline="true">
39502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39505 \begin_layout Standard
39513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39516 \begin_layout Standard
39519 IC_RIGHT() IC_RESULT()
39524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39527 \begin_layout Standard
39535 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39538 \begin_layout Standard
39541 IC_RESULT = IC_RIGHT;
39547 <row topline="true">
39548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39551 \begin_layout Standard
39559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39562 \begin_layout Standard
39565 IC_COND IC_TRUE IC_LABEL
39570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39573 \begin_layout Standard
39577 If true label is present then jump to true label if condition is true else
39578 jump to false label if condition is false
39583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39586 \begin_layout Standard
39589 if (IC_COND) goto IC_TRUE;
39595 If (!IC_COND) goto IC_FALSE;
39601 <row topline="true">
39602 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39605 \begin_layout Standard
39613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39616 \begin_layout Standard
39619 IC_LEFT() IC_RESULT()
39624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39627 \begin_layout Standard
39635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39638 \begin_layout Standard
39641 IC_RESULT = &IC_LEFT();
39647 <row topline="true">
39648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39651 \begin_layout Standard
39659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39662 \begin_layout Standard
39665 IC_JTCOND IC_JTLABELS
39670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39673 \begin_layout Standard
39676 Jump to list of labels depending on the value of JTCOND
39681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39684 \begin_layout Standard
39693 <row topline="true">
39694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39697 \begin_layout Standard
39705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39708 \begin_layout Standard
39711 IC_RIGHT() IC_LEFT() IC_RESULT()
39716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39719 \begin_layout Standard
39727 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39730 \begin_layout Standard
39733 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
39739 <row topline="true">
39740 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39743 \begin_layout Standard
39751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39754 \begin_layout Standard
39762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39765 \begin_layout Standard
39768 This is used for passing parameters in registers;
39770 move IC_LEFT to the next
39771 available parameter register.
39776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39779 \begin_layout Standard
39788 <row topline="true">
39789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39792 \begin_layout Standard
39800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39803 \begin_layout Standard
39811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39814 \begin_layout Standard
39817 This is used for receiving parameters passed in registers;
39820 in the next parameter register to IC_RESULT
39825 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39828 \begin_layout Standard
39837 <row topline="true" bottomline="true">
39838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39841 \begin_layout Standard
39845 (some more have been added)
39850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39853 \begin_layout Standard
39859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39862 \begin_layout Standard
39868 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39871 \begin_layout Standard
39895 \begin_layout Standard
39896 \begin_inset Note Note
39899 \begin_layout Standard
39900 In the original article Figure II was announced to be downloadable on
39905 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
39913 \begin_layout Paragraph*
39915 \begin_inset LatexCommand \index{iCode}
39922 \begin_layout Standard
39923 This section shows some details of iCode.
39924 The example C code does not do anything useful; it is used as an example
39925 to illustrate the intermediate code generated by the compiler.
39928 \begin_layout Verse
39938 /* This function does nothing useful.
39945 for the purpose of explaining iCode */
39948 short function (data
39957 short i=10; \InsetSpace ~
39959 /* dead initialization eliminated */
39965 /* dead initialization eliminated */
39993 /* compiler detects i,j to be induction
39998 for (i = 0, j = 10 ; i < 10 ; i++, j
40004 \begin_layout Standard
40027 mul += i * 3; \InsetSpace ~
40029 /* this multiplication remains */
40036 j * 3;\InsetSpace ~
40038 /* this multiplication changed to addition */
40052 \begin_layout Standard
40053 In addition to the operands each iCode contains information about the filename
40054 and line it corresponds to in the source file.
40055 The first field in the listing should be interpreted as follows:
40060 Filename(linenumber: iCode Execution sequence number : ICode hash table
40061 key : loop depth of the iCode).
40066 Then follows the human readable form of the ICode operation.
40067 Each operand of this triplet form can be of three basic types a) compiler
40068 generated temporary b) user defined variable c) a constant value.
40069 Note that local variables and parameters are replaced by compiler generated
40072 \begin_inset LatexCommand \index{Live range analysis}
40076 are computed only for temporaries (i.e.
40077 live ranges are not computed for global variables).
40079 \begin_inset LatexCommand \index{Register allocation}
40083 are allocated for temporaries only.
40084 Operands are formatted in the following manner:
40089 Operand Name [lr live-from : live-to ] { type information } [ registers
40095 As mentioned earlier the live ranges are computed in terms of the execution
40096 sequence number of the iCodes, for example
40098 the iTemp0 is live from (i.e.
40099 first defined in iCode with execution sequence number 3, and is last used
40100 in the iCode with sequence number 5).
40101 For induction variables such as iTemp21 the live range computation extends
40102 the lifetime from the start to the end of the loop.
40104 The register allocator
40105 used the live range information to allocate registers, the same registers
40106 may be used for different temporaries if their live ranges do not overlap,
40107 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
40108 ranges do not overlap.
40109 In addition the allocator also takes into consideration the type and usage
40110 of a temporary, for example itemp6 is a pointer to near space and is used
40111 as to fetch data from (i.e.
40112 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
40113 Some short lived temporaries are allocated to special registers which have
40114 meaning to the code generator e.g.
40115 iTemp13 is allocated to a pseudo register CC which tells the back end that
40116 the temporary is used only for a conditional jump the code generation makes
40117 use of this information to optimize a compare and jump ICode.
40121 \begin_inset LatexCommand \index{Loop optimization}
40125 performed by the compiler.
40126 It can detect induction variables iTemp21(i) and iTemp23(j).
40127 Also note the compiler does selective strength reduction
40128 \begin_inset LatexCommand \index{Strength reduction}
40133 the multiplication of an induction variable in line 18 (gint = j * 3) is
40134 changed to addition, a new temporary iTemp17 is allocated and assigned
40135 a initial value, a constant 3 is then added for each iteration of the loop.
40136 The compiler does not change the multiplication
40137 \begin_inset LatexCommand \index{Multiplication}
40141 in line 17 however since the processor does support an 8 * 8 bit multiplication.
40144 Note the dead code elimination
40145 \begin_inset LatexCommand \index{Dead-code elimination}
40149 optimization eliminated the dead assignments in line 7 & 8 to I and sum
40155 \begin_layout Standard
40158 Sample.c (5:1:0:0) _entry($9) :
40161 \begin_layout Standard
40164 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
40167 \begin_layout Standard
40170 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
40173 \begin_layout Standard
40176 Sample.c(11:4:53:0) preHeaderLbl0($11) :
40179 \begin_layout Standard
40182 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
40186 \begin_layout Standard
40189 Sample.c(11:6:5:1) _whilecontinue_0($1) :
40192 \begin_layout Standard
40195 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
40199 \begin_layout Standard
40202 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
40205 \begin_layout Standard
40208 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
40212 \begin_layout Standard
40215 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
40219 \begin_layout Standard
40222 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
40226 \begin_layout Standard
40229 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
40233 \begin_layout Standard
40236 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
40237 * int}[r0] + 0x2 {short}
40240 \begin_layout Standard
40243 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
40246 \begin_layout Standard
40249 Sample.c(11:17:21:0)_whilebreak_0($3) :
40252 \begin_layout Standard
40255 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
40258 \begin_layout Standard
40261 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
40264 \begin_layout Standard
40267 Sample.c(15:20:54:0)preHeaderLbl1($13) :
40270 \begin_layout Standard
40273 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
40276 \begin_layout Standard
40279 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
40282 \begin_layout Standard
40285 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
40288 \begin_layout Standard
40291 Sample.c(15:24:26:1)_forcond_0($4) :
40294 \begin_layout Standard
40297 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
40301 \begin_layout Standard
40304 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
40307 \begin_layout Standard
40310 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
40311 + ITemp21 [lr21:38]{short}[r4]
40314 \begin_layout Standard
40317 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
40321 \begin_layout Standard
40324 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
40325 + iTemp15 [lr29:30]{short}[r1]
40328 \begin_layout Standard
40331 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
40335 \begin_layout Standard
40338 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
40342 \begin_layout Standard
40345 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
40349 \begin_layout Standard
40352 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
40356 \begin_layout Standard
40359 Sample.c(19:38:47:1) goto _forcond_0($4)
40362 \begin_layout Standard
40365 Sample.c(19:39:48:0)_forbreak_0($7) :
40368 \begin_layout Standard
40371 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
40372 + ITemp11 [lr19:40]{short}[r3]
40375 \begin_layout Standard
40378 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
40381 \begin_layout Standard
40384 Sample.c(20:42:51:0)_return($8) :
40387 \begin_layout Standard
40390 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
40396 Finally the code generated for this function:
40401 \begin_layout Standard
40407 \begin_layout Standard
40413 \begin_layout Standard
40421 \begin_layout Standard
40427 \begin_layout Standard
40435 \begin_layout Standard
40441 \begin_layout Standard
40444 ; ----------------------------------------------
40447 \begin_layout Standard
40450 ; function function
40453 \begin_layout Standard
40456 ; ----------------------------------------------
40459 \begin_layout Standard
40465 \begin_layout Standard
40468 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
40471 \begin_layout Standard
40479 \begin_layout Standard
40482 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
40485 \begin_layout Standard
40493 \begin_layout Standard
40496 ;_whilecontinue_0($1) :
40499 \begin_layout Standard
40505 \begin_layout Standard
40508 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
40511 \begin_layout Standard
40514 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
40517 \begin_layout Standard
40525 \begin_layout Standard
40533 \begin_layout Standard
40541 \begin_layout Standard
40549 \begin_layout Standard
40557 \begin_layout Standard
40565 \begin_layout Standard
40573 \begin_layout Standard
40579 \begin_layout Standard
40582 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
40585 \begin_layout Standard
40593 \begin_layout Standard
40601 \begin_layout Standard
40604 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
40607 \begin_layout Standard
40615 \begin_layout Standard
40623 \begin_layout Standard
40631 \begin_layout Standard
40639 \begin_layout Standard
40647 \begin_layout Standard
40655 \begin_layout Standard
40658 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
40661 \begin_layout Standard
40669 \begin_layout Standard
40677 \begin_layout Standard
40685 \begin_layout Standard
40693 \begin_layout Standard
40701 \begin_layout Standard
40704 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
40707 \begin_layout Standard
40715 \begin_layout Standard
40723 \begin_layout Standard
40731 \begin_layout Standard
40734 ; iTemp6 [lr5:16]{_near * int}[r0] =
40737 \begin_layout Standard
40740 ; iTemp6 [lr5:16]{_near * int}[r0] +
40743 \begin_layout Standard
40749 \begin_layout Standard
40757 \begin_layout Standard
40760 ; goto _whilecontinue_0($1)
40763 \begin_layout Standard
40771 \begin_layout Standard
40774 ; _whilebreak_0($3) :
40777 \begin_layout Standard
40783 \begin_layout Standard
40786 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
40789 \begin_layout Standard
40797 \begin_layout Standard
40800 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
40803 \begin_layout Standard
40811 \begin_layout Standard
40814 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
40817 \begin_layout Standard
40825 \begin_layout Standard
40828 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
40831 \begin_layout Standard
40839 \begin_layout Standard
40847 \begin_layout Standard
40850 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
40853 \begin_layout Standard
40861 \begin_layout Standard
40869 \begin_layout Standard
40875 \begin_layout Standard
40881 \begin_layout Standard
40884 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
40887 \begin_layout Standard
40890 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
40893 \begin_layout Standard
40901 \begin_layout Standard
40909 \begin_layout Standard
40917 \begin_layout Standard
40925 \begin_layout Standard
40933 \begin_layout Standard
40939 \begin_layout Standard
40942 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
40945 \begin_layout Standard
40948 ; iTemp21 [lr21:38]{short}[r4]
40951 \begin_layout Standard
40959 \begin_layout Standard
40967 \begin_layout Standard
40975 \begin_layout Standard
40978 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
40981 \begin_layout Standard
40989 \begin_layout Standard
40997 \begin_layout Standard
41005 \begin_layout Standard
41013 \begin_layout Standard
41016 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
41019 \begin_layout Standard
41022 ; iTemp15 [lr29:30]{short}[r1]
41025 \begin_layout Standard
41033 \begin_layout Standard
41041 \begin_layout Standard
41044 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
41047 \begin_layout Standard
41055 \begin_layout Standard
41063 \begin_layout Standard
41071 \begin_layout Standard
41079 \begin_layout Standard
41087 \begin_layout Standard
41095 \begin_layout Standard
41098 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
41101 \begin_layout Standard
41109 \begin_layout Standard
41117 \begin_layout Standard
41125 \begin_layout Standard
41133 \begin_layout Standard
41141 \begin_layout Standard
41149 \begin_layout Standard
41152 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
41155 \begin_layout Standard
41163 \begin_layout Standard
41166 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
41169 \begin_layout Standard
41177 \begin_layout Standard
41182 cjne r5,#0xff,00104$
41185 \begin_layout Standard
41193 \begin_layout Standard
41196 ; goto _forcond_0($4)
41199 \begin_layout Standard
41207 \begin_layout Standard
41210 ; _forbreak_0($7) :
41213 \begin_layout Standard
41219 \begin_layout Standard
41222 ; ret iTemp24 [lr40:41]{short}
41225 \begin_layout Standard
41233 \begin_layout Standard
41241 \begin_layout Standard
41249 \begin_layout Standard
41255 \begin_layout Standard
41261 \begin_layout Standard
41271 \begin_layout Section
41272 A few words about basic block successors, predecessors and dominators
41275 \begin_layout Standard
41276 Successors are basic blocks
41277 \begin_inset LatexCommand \index{Basic blocks}
41281 that might execute after this basic block.
41283 Predecessors are basic blocks
41284 that might execute before reaching this basic block.
41286 Dominators are basic
41287 blocks that WILL execute before reaching this basic block.
41292 \begin_layout Standard
41296 \begin_layout Standard
41300 \begin_layout Standard
41308 \begin_layout Standard
41312 \begin_layout Standard
41320 \begin_layout Standard
41326 \begin_layout Standard
41327 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
41330 \begin_layout Standard
41331 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
41334 \begin_layout Standard
41335 c) domVect of [BB4] = BB1 ...
41336 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
41340 \begin_layout Chapter
41344 \begin_layout Standard
41345 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/#Who}
41355 Thanks to all the other volunteer developers who have helped with coding,
41356 testing, web-page creation, distribution sets, etc.
41357 You know who you are :-)
41365 Thanks to Sourceforge
41366 \begin_inset LatexCommand \url{http://www.sf.net}
41370 which has hosted the project since 1999 and donates significant download
41379 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
41380 cycles and bandwidth for snapshot builds.
41385 \begin_layout Standard
41386 This document was initially written by Sandeep Dutta
41389 \begin_layout Standard
41390 All product names mentioned herein may be trademarks
41391 \begin_inset LatexCommand \index{Trademarks}
41395 of their respective companies.
41399 \begin_layout Section*
41403 \begin_layout Standard
41404 To avoid confusion, the installation and building options for SDCC itself
41405 (chapter 2) are not part of the index.
41408 \begin_layout Standard
41409 \begin_inset LatexCommand \printindex{}