1 #LyX 1.4.4 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
872 \begin_inset Marginal
875 \begin_layout Standard
900 will push a as an int and as a char resp.
903 \begin_layout Itemize
908 \begin_layout Standard
917 -regextend has been removed.
920 \begin_layout Itemize
925 \begin_layout Standard
934 -noregparms has been removed.
937 \begin_layout Itemize
942 \begin_layout Standard
951 -stack-after-data has been removed.
954 \begin_layout Itemize
956 \begin_inset LatexCommand \index{bit}
961 \begin_inset LatexCommand \index{sbit}
966 \begin_inset LatexCommand \index{\_\_sbit}
970 types now consistently behave like the C99 _Bool type with respect to type
972 \begin_inset LatexCommand \index{type conversion}
977 \begin_inset LatexCommand \index{type promotion}
982 The most common incompatibility resulting from this change is related to
984 \begin_inset LatexCommand \index{Bit toggling}
999 \begin_inset LatexCommand \index{\~\/ Operator}
1003 b; /* equivalent to b=1 instead of toggling b */
1004 \begin_inset Marginal
1007 \begin_layout Standard
1020 b = !b; /* toggles b */
1024 In previous versions, both forms would have toggled the bit.
1027 \begin_layout Standard
1030 <pending: more incompatibilities?>
1033 \begin_layout Section
1037 \begin_layout Standard
1038 What do you need before you start installation of SDCC? A computer, and
1039 a desire to compute.
1040 The preferred method of installation is to compile SDCC from source using
1042 For Windows some pre-compiled binary distributions are available for your
1044 You should have some experience with command line tools and compiler use.
1047 \begin_layout Section
1051 \begin_layout Standard
1052 The SDCC home page at
1053 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1057 is a great place to find distribution sets.
1058 You can also find links to the user mailing lists that offer help or discuss
1059 SDCC with other SDCC users.
1060 Web links to other SDCC related sites can also be found here.
1061 This document can be found in the DOC directory of the source package as
1062 a text or HTML file.
1063 A pdf version of this document is available at
1064 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1069 Some of the other tools (simulator and assembler) included with SDCC contain
1070 their own documentation and can be found in the source distribution.
1071 If you want the latest unreleased software, the complete source package
1072 is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1076 \begin_layout Section
1077 Wishes for the future
1080 \begin_layout Standard
1081 There are (and always will be) some things that could be done.
1082 Here are some I can think of:
1087 \begin_layout Standard
1090 char KernelFunction3(char p) at 0x340;
1095 \begin_layout Standard
1099 \begin_inset LatexCommand \index{code banking (limited support)}
1109 If you can think of some more, please see the section
1110 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1114 about filing feature requests
1115 \begin_inset LatexCommand \index{Requesting features}
1120 \begin_inset LatexCommand \index{Feature request}
1129 \begin_layout Chapter
1131 \begin_inset LatexCommand \index{Installation}
1138 \begin_layout Standard
1139 For most users it is sufficient to skip to either section
1140 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1145 \begin_inset LatexCommand \ref{sub:Windows-Install}
1150 More detailed instructions follow below.
1153 \begin_layout Section
1155 \begin_inset LatexCommand \index{Options SDCC configuration}
1162 \begin_layout Standard
1163 The install paths, search paths and other options are defined when running
1165 The defaults can be overridden by:
1169 \labelwidthstring 00.00.0000
1174 \begin_layout Standard
1183 -prefix see table below
1187 \labelwidthstring 00.00.0000
1192 \begin_layout Standard
1201 -exec_prefix see table below
1205 \labelwidthstring 00.00.0000
1210 \begin_layout Standard
1219 -bindir see table below
1223 \labelwidthstring 00.00.0000
1228 \begin_layout Standard
1237 -datadir see table below
1241 \labelwidthstring 00.00.0000
1246 \begin_layout Standard
1255 -datarootdir see table below
1261 \labelwidthstring 00.00.0000
1264 docdir environment variable, see table below
1268 \labelwidthstring 00.00.0000
1271 include_dir_suffix environment variable, see table below
1275 \labelwidthstring 00.00.0000
1278 lib_dir_suffix environment variable, see table below
1282 \labelwidthstring 00.00.0000
1285 sdccconf_h_dir_separator environment variable, either / or
1290 This character will only be used in sdccconf.h; don't forget it's a C-header,
1291 therefore a double-backslash is needed there.
1297 \labelwidthstring 00.00.0000
1302 \begin_layout Standard
1311 -disable-mcs51-port Excludes the Intel mcs51 port
1315 \labelwidthstring 00.00.0000
1320 \begin_layout Standard
1329 -disable-gbz80-port Excludes the Gameboy gbz80 port
1333 \labelwidthstring 00.00.0000
1338 \begin_layout Standard
1347 -disable-z80-port Excludes the z80 port
1351 \labelwidthstring 00.00.0000
1356 \begin_layout Standard
1365 -disable-avr-port Excludes the AVR port
1369 \labelwidthstring 00.00.0000
1374 \begin_layout Standard
1383 -disable-ds390-port Excludes the DS390 port
1387 \labelwidthstring 00.00.0000
1392 \begin_layout Standard
1401 -disable-hc08-port Excludes the HC08 port
1405 \labelwidthstring 00.00.0000
1410 \begin_layout Standard
1419 -disable-pic-port Excludes the PIC14 port
1423 \labelwidthstring 00.00.0000
1428 \begin_layout Standard
1437 -disable-pic16-port Excludes the PIC16 port
1441 \labelwidthstring 00.00.0000
1446 \begin_layout Standard
1455 -disable-xa51-port Excludes the XA51 port
1459 \labelwidthstring 00.00.0000
1464 \begin_layout Standard
1473 -disable-ucsim Disables configuring and building of ucsim
1477 \labelwidthstring 00.00.0000
1482 \begin_layout Standard
1491 -disable-device-lib Disables automatically building device libraries
1495 \labelwidthstring 00.00.0000
1500 \begin_layout Standard
1509 -disable-packihx Disables building packihx
1515 \labelwidthstring 00.00.0000
1520 \begin_layout Standard
1529 -enable-doc Build pdf, html and txt files from the lyx sources
1533 \labelwidthstring 00.00.0000
1538 \begin_layout Standard
1547 -enable-libgc Use the Bohem memory allocator.
1548 Lower runtime footprint.
1551 \begin_layout Standard
1552 Furthermore the environment variables CC, CFLAGS, ...
1553 the tools and their arguments can be influenced.
1554 Please see `configure -
1558 \begin_layout Standard
1567 -help' and the man/info pages of `configure' for details.
1572 standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1573 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1574 SDCC_LIB_NAME are defined by `configure' too.
1575 At the moment it's not possible to change the default settings (it was
1576 simply never required).
1580 These configure options are compiled into the binaries,
1581 and can only be changed by rerunning 'configure' and recompiling SDCC.
1582 The configure options are written in
1586 to distinguish them from run time environment variables (see section search
1592 \begin_inset Quotes sld
1596 \begin_inset Quotes srd
1599 are used by the SDCC team to build the official Win32 binaries.
1600 The SDCC team uses Mingw32 to build the official Windows binaries, because
1604 \begin_layout Enumerate
1608 \begin_layout Enumerate
1609 a gcc compiler and last but not least
1612 \begin_layout Enumerate
1613 the binaries can be built by cross compiling on SDCC Distributed Compile
1617 \begin_layout Standard
1618 See the examples, how to pass the Win32 settings to 'configure'.
1619 The other Win32 builds using Borland, VC or whatever don't use 'configure',
1620 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1630 \begin_layout Standard
1632 \begin_inset Tabular
1633 <lyxtabular version="3" rows="9" columns="3">
1635 <column alignment="block" valignment="top" leftline="true" width="0in">
1636 <column alignment="block" valignment="top" leftline="true" width="0in">
1637 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1638 <row topline="true" bottomline="true">
1639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1642 \begin_layout Standard
1648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1651 \begin_layout Standard
1657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1660 \begin_layout Standard
1667 <row topline="true">
1668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1671 \begin_layout Standard
1679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1682 \begin_layout Standard
1688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1691 \begin_layout Standard
1700 <row topline="true">
1701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1704 \begin_layout Standard
1712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1715 \begin_layout Standard
1723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1726 \begin_layout Standard
1735 <row topline="true">
1736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1739 \begin_layout Standard
1747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1750 \begin_layout Standard
1760 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1763 \begin_layout Standard
1776 <row topline="true">
1777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1780 \begin_layout Standard
1788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1791 \begin_layout Standard
1799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1802 \begin_layout Standard
1811 <row topline="true">
1812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1815 \begin_layout Standard
1823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1826 \begin_layout Standard
1836 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1839 \begin_layout Standard
1848 <row topline="true">
1849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1852 \begin_layout Standard
1860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1863 \begin_layout Standard
1873 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1876 \begin_layout Standard
1889 <row topline="true">
1890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1893 \begin_layout Standard
1901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1904 \begin_layout Standard
1910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1913 \begin_layout Standard
1920 <row topline="true" bottomline="true">
1921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1924 \begin_layout Standard
1932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1935 \begin_layout Standard
1941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1944 \begin_layout Standard
1960 \begin_layout Standard
1962 'configure' also computes relative paths.
1963 This is needed for full relocatability of a binary package and to complete
1964 search paths (see section search paths below):
1969 \begin_layout Standard
1971 \begin_inset Tabular
1972 <lyxtabular version="3" rows="4" columns="3">
1974 <column alignment="block" valignment="top" leftline="true" width="0in">
1975 <column alignment="block" valignment="top" leftline="true" width="0in">
1976 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1977 <row topline="true" bottomline="true">
1978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1981 \begin_layout Standard
1987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1990 \begin_layout Standard
1996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1999 \begin_layout Standard
2006 <row topline="true" bottomline="true">
2007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2010 \begin_layout Standard
2018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2021 \begin_layout Standard
2027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2030 \begin_layout Standard
2037 <row bottomline="true">
2038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2041 \begin_layout Standard
2049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2052 \begin_layout Standard
2058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2061 \begin_layout Standard
2068 <row bottomline="true">
2069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2072 \begin_layout Standard
2080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2083 \begin_layout Standard
2089 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2092 \begin_layout Standard
2108 \begin_layout Standard
2113 \begin_layout LyX-Code
2120 \begin_layout Standard
2130 \begin_inset Quotes srd
2134 \begin_inset Quotes srd
2141 \begin_layout Standard
2151 \begin_inset Quotes srd
2155 \begin_inset Quotes srd
2164 \begin_layout Standard
2177 \begin_layout Standard
2189 \begin_layout Standard
2190 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2194 \begin_layout LyX-Code
2200 \begin_inset Quotes srd
2203 i586-mingw32msvc-gcc
2204 \begin_inset Quotes srd
2208 \begin_inset Quotes srd
2211 i586-mingw32msvc-g++
2212 \begin_inset Quotes srd
2220 \begin_inset Quotes srd
2223 i586-mingw32msvc-ranlib
2224 \begin_inset Quotes srd
2232 \begin_inset Quotes srd
2235 i586-mingw32msvc-strip
2236 \begin_inset Quotes srd
2247 \begin_layout Standard
2257 \begin_inset Quotes srd
2261 \begin_inset Quotes srd
2272 \begin_layout Standard
2282 \begin_inset Quotes srd
2286 \begin_inset Quotes srd
2294 \begin_inset Quotes srd
2300 \begin_inset Quotes srd
2308 \begin_inset Quotes srd
2312 \begin_inset Quotes srd
2320 \begin_inset Quotes srd
2324 \begin_inset Quotes srd
2331 sdccconf_h_dir_separator=
2332 \begin_inset Quotes srd
2344 \begin_inset Quotes srd
2355 \begin_layout Standard
2372 \begin_layout Standard
2381 -host=i586-mingw32msvc
2389 \begin_layout Standard
2398 -build=unknown-unknown-linux-gnu
2401 \begin_layout Standard
2403 \begin_inset Quotes sld
2407 \begin_inset Quotes srd
2410 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2414 \begin_layout LyX-Code
2423 \begin_layout Standard
2433 \begin_inset Quotes srd
2437 \begin_inset Quotes srd
2448 \begin_layout Standard
2458 \begin_inset Quotes srd
2462 \begin_inset Quotes srd
2470 \begin_inset Quotes srd
2476 \begin_inset Quotes srd
2484 \begin_inset Quotes srd
2488 \begin_inset Quotes srd
2496 \begin_inset Quotes srd
2500 \begin_inset Quotes srd
2507 sdccconf_h_dir_separator=
2508 \begin_inset Quotes srd
2520 \begin_inset Quotes srd
2528 \begin_inset Quotes srd
2532 \begin_inset Quotes srd
2540 \begin_inset Quotes srd
2544 \begin_inset Quotes srd
2550 \begin_layout Standard
2551 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2556 \begin_layout Standard
2565 -C' turns on caching, which gives a little bit extra speed.
2566 However if options are changed, it can be necessary to delete the config.cache
2570 \begin_layout Section
2572 \begin_inset LatexCommand \label{sub:Install-paths}
2577 \begin_inset LatexCommand \index{Install paths}
2584 \begin_layout Standard
2585 \begin_inset VSpace medskip
2591 \begin_layout Standard
2593 \begin_inset Tabular
2594 <lyxtabular version="3" rows="5" columns="4">
2596 <column alignment="left" valignment="top" leftline="true" width="0">
2597 <column alignment="left" valignment="top" leftline="true" width="0">
2598 <column alignment="left" valignment="top" leftline="true" width="0">
2599 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2600 <row topline="true" bottomline="true">
2601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2604 \begin_layout Standard
2612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2615 \begin_layout Standard
2623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2626 \begin_layout Standard
2634 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2637 \begin_layout Standard
2646 <row topline="true">
2647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2650 \begin_layout Standard
2656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2659 \begin_layout Standard
2667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2670 \begin_layout Standard
2676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2679 \begin_layout Standard
2690 <row topline="true">
2691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2694 \begin_layout Standard
2700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2703 \begin_layout Standard
2706 $DATADIR/ $INCLUDE_DIR_SUFFIX
2711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2714 \begin_layout Standard
2715 /usr/local/share/sdcc/include
2720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2723 \begin_layout Standard
2734 <row topline="true">
2735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2738 \begin_layout Standard
2744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2747 \begin_layout Standard
2750 $DATADIR/$LIB_DIR_SUFFIX
2755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2758 \begin_layout Standard
2759 /usr/local/share/sdcc/lib
2764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2767 \begin_layout Standard
2778 <row topline="true" bottomline="true">
2779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2782 \begin_layout Standard
2788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2791 \begin_layout Standard
2799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2802 \begin_layout Standard
2803 /usr/local/share/sdcc/doc
2808 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2811 \begin_layout Standard
2832 *compiler, preprocessor, assembler, and linker
2838 is auto-appended by the compiler, e.g.
2839 small, large, z80, ds390 etc
2842 \begin_layout Standard
2844 The install paths can still be changed during `make install' with e.g.:
2847 \begin_layout LyX-Code
2848 make install prefix=$(HOME)/local/sdcc
2851 \begin_layout Standard
2852 Of course this doesn't change the search paths compiled into the binaries.
2857 r the install path can be changed by defining DESTDIR
2858 \begin_inset LatexCommand \index{DESTDIR}
2865 \begin_layout LyX-Code
2866 make install DESTDIR=$(HOME)/sdcc.rpm/
2869 \begin_layout Standard
2870 Please note that DESTDIR must have a trailing slash!
2873 \begin_layout Section
2875 \begin_inset LatexCommand \label{sub:Search-Paths}
2880 \begin_inset LatexCommand \index{Search path}
2887 \begin_layout Standard
2888 Some search paths or parts of them are determined by configure variables
2893 , see section above).
2894 Further search paths are determined by environment variables during runtime.
2897 The paths searched when running the compiler are as follows (the first
2903 Binary files (preprocessor, assembler and linker)
2908 \begin_layout Standard
2910 \begin_inset Tabular
2911 <lyxtabular version="3" rows="4" columns="3">
2913 <column alignment="block" valignment="top" leftline="true" width="0in">
2914 <column alignment="block" valignment="top" leftline="true" width="0in">
2915 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2916 <row topline="true" bottomline="true">
2917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2920 \begin_layout Standard
2926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2929 \begin_layout Standard
2935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2938 \begin_layout Standard
2945 <row topline="true">
2946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2949 \begin_layout Standard
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" rightline="true" usebox="none">
2969 \begin_layout Standard
2978 <row topline="true">
2979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2982 \begin_layout Standard
2983 Path of argv[0] (if available)
2988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2991 \begin_layout Standard
2997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3000 \begin_layout Standard
3007 <row topline="true" bottomline="true">
3008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3011 \begin_layout Standard
3017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3020 \begin_layout Standard
3026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3029 \begin_layout Standard
3045 \begin_layout Standard
3053 \begin_layout Standard
3055 \begin_inset Tabular
3056 <lyxtabular version="3" rows="6" columns="3">
3058 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3059 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3060 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3061 <row topline="true" bottomline="true">
3062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3065 \begin_layout Standard
3071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3074 \begin_layout Standard
3080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3083 \begin_layout Standard
3090 <row topline="true">
3091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3094 \begin_layout Standard
3099 \begin_layout Standard
3113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3116 \begin_layout Standard
3121 \begin_layout Standard
3135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3138 \begin_layout Standard
3143 \begin_layout Standard
3158 <row topline="true">
3159 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3162 \begin_layout Standard
3168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3171 \begin_layout Standard
3177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3180 \begin_layout Standard
3187 <row topline="true">
3188 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3191 \begin_layout Standard
3203 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3206 \begin_layout Standard
3216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3219 \begin_layout Standard
3228 <row topline="true">
3229 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3232 \begin_layout Standard
3248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3251 \begin_layout Standard
3299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3302 \begin_layout Standard
3313 <row topline="true" bottomline="true">
3314 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3317 \begin_layout Standard
3331 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3334 \begin_layout Standard
3335 /usr/local/share/sdcc/
3342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3345 \begin_layout Standard
3361 \begin_layout Standard
3367 \begin_layout Standard
3376 -nostdinc disables the last two search paths.
3386 \begin_layout Standard
3387 With the exception of
3388 \begin_inset Quotes sld
3395 \begin_layout Standard
3405 \begin_inset Quotes srd
3412 is auto-appended by the compiler (e.g.
3413 small, large, z80, ds390 etc.).
3419 \begin_layout Standard
3421 \begin_inset Tabular
3422 <lyxtabular version="3" rows="6" columns="3">
3424 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3425 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3426 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3427 <row topline="true" bottomline="true">
3428 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3431 \begin_layout Standard
3437 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3440 \begin_layout Standard
3446 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3449 \begin_layout Standard
3456 <row topline="true">
3457 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3460 \begin_layout Standard
3465 \begin_layout Standard
3479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3482 \begin_layout Standard
3487 \begin_layout Standard
3501 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3504 \begin_layout Standard
3509 \begin_layout Standard
3524 <row topline="true">
3525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3528 \begin_layout Standard
3538 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3541 \begin_layout Standard
3551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3554 \begin_layout Standard
3567 <row topline="true">
3568 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3571 \begin_layout Standard
3578 $LIB_DIR_SUFFIX/<model>
3583 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3586 \begin_layout Standard
3598 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3601 \begin_layout Standard
3616 <row topline="true">
3617 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3620 \begin_layout Standard
3631 $LIB_DIR_SUFFIX/<model>
3636 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3639 \begin_layout Standard
3690 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3693 \begin_layout Standard
3747 <row topline="true" bottomline="true">
3748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3751 \begin_layout Standard
3756 $LIB_DIR_SUFFIX/<model>
3761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3764 \begin_layout Standard
3765 /usr/local/share/sdcc/
3774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3777 \begin_layout Standard
3793 \begin_layout Standard
3794 \begin_inset Note Note
3797 \begin_layout Standard
3798 Don't delete any of the stray spaces in the table above without checking
3799 the HTML output (last line)!
3807 \begin_layout Standard
3815 \begin_layout Standard
3824 -nostdlib disables the last two search paths.
3827 \begin_layout Section
3829 \begin_inset LatexCommand \index{Building SDCC}
3836 \begin_layout Subsection
3837 Building SDCC on Linux
3838 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3845 \begin_layout Enumerate
3848 Download the source package
3850 either from the SDCC Subversion repository or from snapshot builds
3852 , it will be named something like sdcc
3863 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3870 \begin_layout Enumerate
3873 Bring up a command line terminal, such as xterm.
3876 \begin_layout Enumerate
3879 Unpack the file using a command like:
3882 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
3883 \begin_inset Quotes srd
3889 , this will create a sub-directory called sdcc with all of the sources.
3892 \begin_layout Enumerate
3893 Change directory into the main SDCC directory, for example type:
3901 \begin_layout Enumerate
3911 This configures the package for compilation on your system.
3914 \begin_layout Enumerate
3928 All of the source packages will compile, this can take a while.
3931 \begin_layout Enumerate
3945 This copies the binary executables, the include files, the libraries and
3946 the documentation to the install directories.
3947 Proceed with section
3948 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3955 \begin_layout Subsection
3956 Building SDCC on Mac OS X
3959 \begin_layout Standard
3960 Follow the instruction for Linux.
3964 On Mac OS X 10.2.x it was reported, that the
3965 default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
3966 Fortunately there's also gcc 2.9.x installed, which works fine.
3967 This compiler can be selected by running 'configure' with:
3970 \begin_layout LyX-Code
3971 ./configure CC=gcc2 CXX=g++2
3974 \begin_layout Subsection
3975 Cross compiling SDCC on Linux for Windows
3978 \begin_layout Standard
3979 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3980 See section 'Configure Options'.
3983 \begin_layout Subsection
3984 Building SDCC using Cygwin and Mingw32
3987 \begin_layout Standard
3988 For building and installing a Cygwin executable follow the instructions
3994 \begin_inset Quotes sld
3998 \begin_inset Quotes srd
4001 Win32-binary can be built, which will not need the Cygwin-DLL.
4002 For the necessary 'configure' options see section 'configure options' or
4003 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4008 Cygwin on Windows download setup.exe from
4009 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
4015 \begin_inset Quotes sld
4018 default text file type
4019 \begin_inset Quotes srd
4023 \begin_inset Quotes sld
4027 \begin_inset Quotes srd
4030 and download/install at least the following packages.
4031 Some packages are selected by default, others will be automatically selected
4032 because of dependencies with the manually selected packages.
4033 Never deselect these packages!
4036 \begin_layout Itemize
4040 \begin_layout Itemize
4044 \begin_layout Itemize
4045 gcc ; version 3.x is fine, no need to use the old 2.9x
4048 \begin_layout Itemize
4049 binutils ; selected with gcc
4052 \begin_layout Itemize
4056 \begin_layout Itemize
4057 rxvt ; a nice console, which makes life much easier under windoze (see below)
4060 \begin_layout Itemize
4061 man ; not really needed for building SDCC, but you'll miss it sooner or
4065 \begin_layout Itemize
4066 less ; not really needed for building SDCC, but you'll miss it sooner or
4070 \begin_layout Itemize
4071 svn ; only if you use Subversion access
4074 \begin_layout Standard
4075 If you want to develop something you'll need:
4078 \begin_layout Itemize
4079 python ; for the regression tests
4082 \begin_layout Itemize
4083 gdb ; the gnu debugger, together with the nice GUI
4084 \begin_inset Quotes sld
4088 \begin_inset Quotes srd
4094 \begin_layout Itemize
4095 openssh ; to access the CF or commit changes
4098 \begin_layout Itemize
4099 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4100 use autoconf-stable!
4103 \begin_layout Standard
4104 rxvt is a nice console with history.
4105 Replace in your cygwin.bat the line
4108 \begin_layout LyX-Code
4113 \begin_layout Standard
4125 \begin_layout Standard
4129 \begin_layout LyX-Code
4130 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4133 \begin_layout LyX-Code
4134 -bg black -fg white -geometry 100x65 -e bash -
4138 \begin_layout Standard
4150 \begin_layout Standard
4151 Text selected with the mouse is automatically copied to the clipboard, pasting
4152 works with shift-insert.
4156 The other good tip is to make sure you have no //c/-styl
4157 e paths anywhere, use /cygdrive/c/ instead.
4158 Using // invokes a network lookup which is very slow.
4160 \begin_inset Quotes sld
4164 \begin_inset Quotes srd
4167 is too long, you can change it with e.g.
4170 \begin_layout LyX-Code
4174 \begin_layout Standard
4175 SDCC sources use the unix line ending LF.
4176 Life is much easier, if you store the source tree on a drive which is mounted
4178 And use an editor which can handle LF-only line endings.
4179 Make sure not to commit files with windows line endings.
4180 The tabulator spacing
4181 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4185 used in the project is 8.
4186 Although a tabulator spacing of 8 is a sensible choice for programmers
4187 (it's a power of 2 and allows to display 8/16 bit signed variables without
4188 loosing columns) the plan is to move towards using only spaces in the source.
4191 \begin_layout Subsection
4192 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4195 \begin_layout Standard
4198 Download the source package
4200 either from the SDCC Subversion repository or from the
4201 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4207 , it will be named something like sdcc
4211 -yyyymmdd-rrrr.tar.bz2.
4214 SDCC is distributed with all the projects, workspaces, and files you need
4215 to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4216 The workspace name is 'sdcc.dsw'.
4217 Please note that as it is now, all the executables are created in a folder
4221 Once built you need to copy the executables from sdcc
4225 bin before running SDCC.
4230 WARNING: Visual studio is very picky with line terminations; it expects
4231 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4232 When using the Subversion repository it's easiest to configure the svn
4233 client to convert automatically for you.
4234 If however you are getting a message such as "This makefile was not generated
4235 by Developer Studio etc.
4237 \begin_inset Quotes srd
4240 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4241 need to convert the Unix style line endings to DOS style line endings.
4242 To do so you can use the
4243 \begin_inset Quotes sld
4247 \begin_inset Quotes srd
4250 utility freely available on the internet.
4251 Doug Hawkins reported in the sdcc-user list that this works:
4259 SDCC> unix2dos sdcc.dsw
4265 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4269 In order to build SDCC with MSVC
4270 you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4271 One good place to get them is
4272 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4280 Download the file UnxUtils
4281 \begin_inset LatexCommand \index{UnxUtils}
4286 Now you have to install the utilities and setup MSVC so it can locate the
4288 Here there are two alternatives (choose one!):
4291 \begin_layout Enumerate
4296 a) Extract UnxUtils.zip to your C:
4298 hard disk PRESERVING the original paths, otherwise bison won't work.
4299 (If you are using WinZip make certain that 'Use folder names' is selected)
4304 In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4305 'Show directories for:' select 'Executable files', and in the directories
4306 window add a new path: 'C:
4316 (As a side effect, you get a bunch of Unix utilities that
4317 could be useful, such as diff and patch.)
4320 \begin_layout Enumerate
4325 This one avoids extracting a bunch of files you may not
4326 use, but requires some extra work:
4330 a) Create a directory were to put the
4331 tools needed, or use a directory already present.
4338 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4339 gawk.exe to such directory WITHOUT preserving the original paths.
4340 (If you are using WinZip make certain that 'Use folder names' is not selected)
4345 ) Rename bison.exe to '_bison.exe'.
4349 d) Create a batch file 'bison.bat' in 'C:
4353 ' and add these lines:
4373 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4377 Steps 'c' and 'd' are needed
4378 because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4379 reside in some weird Unix directory, '/usr/local/share/' I think.
4380 So it is necessary to tell bison where those files are located if they
4381 are not in such directory.
4382 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4387 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4388 in 'Show directories for:' select 'Executable files', and in the directories
4389 window add a new path: 'c:
4392 Note that you can use any other path instead of 'c:
4394 util', even the path where the Visual C++ tools are, probably: 'C:
4398 Microsoft Visual Studio
4403 So you don't have to execute step 'e' :)
4406 \begin_layout Standard
4408 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4409 the executables from sdcc
4413 bin, and you can compile using SDCC.
4416 \begin_layout Subsection
4417 Building SDCC Using Borland
4420 \begin_layout Enumerate
4421 From the sdcc directory, run the command "make -f Makefile.bcc".
4422 This should regenerate all the .exe files in the bin directory except for
4426 \begin_layout Enumerate
4427 If you modify any source files and need to rebuild, be aware that the dependenci
4428 es may not be correctly calculated.
4429 The safest option is to delete all .obj files and run the build again.
4430 From a Cygwin BASH prompt, this can easily be done with the command (be
4431 sure you are in the sdcc directory):
4441 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
4443 ) -print -exec rm {}
4452 or on Windows NT/2000/XP from the command prompt with the command:
4459 del /s *.obj *.lib *.rul
4462 from the sdcc directory.
4465 \begin_layout Subsection
4466 Windows Install Using a ZIP Package
4469 \begin_layout Enumerate
4470 Download the binary zip package from
4471 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4475 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4476 This should unpack to a group of sub-directories.
4477 An example directory structure after unpacking the mingw32 package is:
4482 bin for the executables, c:
4490 lib for the include and libraries.
4493 \begin_layout Enumerate
4494 Adjust your environment variable PATH to include the location of the bin
4495 directory or start sdcc using the full path.
4498 \begin_layout Subsection
4499 Windows Install Using the Setup Program
4500 \begin_inset LatexCommand \label{sub:Windows-Install}
4507 \begin_layout Standard
4508 Download the setup program
4510 sdcc-x.y.z-setup.exe
4512 for an official release from
4515 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4519 or a setup program for one of the snapshots
4521 sdcc-yyyymmdd-xxxx-setup.exe
4524 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4529 A windows typical installer will guide you through the installation process.
4532 \begin_layout Subsection
4534 \begin_inset LatexCommand \index{VPATH}
4541 \begin_layout Standard
4542 SDCC supports the VPATH feature provided by configure and make.
4543 It allows to separate the source and build trees.
4547 \begin_layout Standard
4574 \begin_layout Standard
4577 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4578 # extract source to directory sdcc
4581 \begin_layout Standard
4584 mkdir sdcc.build\InsetSpace ~
4593 # put output in sdcc.build
4596 \begin_layout Standard
4602 \begin_layout Standard
4605 ../sdcc/configure\InsetSpace ~
4613 # configure is doing all the magic!
4616 \begin_layout Standard
4622 \begin_layout Standard
4628 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4629 It automagically computes the variables srcdir, top_srcdir and top_buildir
4635 the generated files will be in ~/sdcc.build, while the source files stay
4638 This is not only usefull for building different binaries, e.g.
4639 when cross compiling.
4640 It also gives you a much better overview in the source tree when all the
4641 generated files are not scattered between the source files.
4642 And the best thing is: if you want to change a file you can leave the original
4643 file untouched in the source directory.
4644 Simply copy it to the build directory, edit it, enter `make clean', `rm
4645 Makefile.dep' and `make'.
4650 will do the rest for you!
4653 \begin_layout Section
4654 Building the Documentation
4657 \begin_layout Standard
4662 \begin_layout Standard
4671 -enable-doc to the configure arguments to build the documentation together
4672 with all the other stuff.
4673 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4674 dvips and makeindex) to get the job done.
4675 Another possibility is to change to the doc directory and to type
4679 \begin_inset Quotes srd
4683 \begin_inset Quotes srd
4690 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4693 \begin_inset LatexCommand \url{http://www.lyx.org}
4697 as editor is straightforward.
4698 Prebuilt documentation in html and pdf format is available from
4699 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4706 \begin_layout Section
4707 Reading the Documentation
4708 \begin_inset LatexCommand \index{Documentation}
4715 \begin_layout Standard
4716 Currently reading the document in pdf format is recommended, as for unknown
4717 reason the hyperlinks are working there whereas in the html version they
4722 \begin_layout Standard
4723 If you should know why please drop us a note
4731 You'll find the pdf version
4732 \begin_inset LatexCommand \index{PDF version of this document}
4737 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4745 \begin_inset LatexCommand \index{HTML version of this document}
4750 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4756 This documentation is in some aspects different from a commercial documentation:
4760 \begin_layout Itemize
4761 It tries to document SDCC for several processor architectures in one document
4762 (commercially these probably would be separate documents/products).
4764 \begin_inset LatexCommand \index{Status of documentation}
4768 currently matches SDCC for mcs51 and DS390 best and does give too few informati
4770 Z80, PIC14, PIC16 and HC08.
4773 \begin_layout Itemize
4774 There are many references pointing away from this documentation.
4775 Don't let this distract you.
4777 was a reference like
4778 \begin_inset LatexCommand \url{http://www.opencores.org}
4782 together with a statement
4783 \begin_inset Quotes sld
4786 some processors which are targetted by SDCC can be implemented in a
4803 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4808 \begin_inset Quotes srd
4812 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4817 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4822 \begin_inset Quotes sld
4825 have you ever heard of an open source compiler that compiles a subset of
4827 \begin_inset Quotes srd
4830 we expect you to have a quick look there and come back.
4831 If you read this you are on the right track.
4834 \begin_layout Itemize
4835 Some sections attribute more space to problems, restrictions and warnings
4836 than to the solution.
4839 \begin_layout Itemize
4840 The installation section and the section about the debugger is intimidating.
4843 \begin_layout Itemize
4844 There are still lots of typos and there are more different writing styles
4848 \begin_layout Section
4849 Testing the SDCC Compiler
4850 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4857 \begin_layout Standard
4858 The first thing you should do after installing your SDCC compiler is to
4867 \begin_layout Standard
4877 \begin_inset LatexCommand \index{version}
4884 at the prompt, and the program should run and output its version like:
4889 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4893 \begin_layout Standard
4894 If it doesn't run, or gives a message about not finding sdcc program, then
4895 you need to check over your installation.
4896 Make sure that the sdcc bin directory is in your executable search path
4897 defined by the PATH environment setting (
4902 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4909 Install trouble-shooting for suggestions
4912 Make sure that the sdcc program is in the bin folder, if not perhaps something
4913 did not install correctly.
4921 is commonly installed as described in section
4922 \begin_inset Quotes sld
4925 Install and search paths
4926 \begin_inset Quotes srd
4935 Make sure the compiler works on a very simple example.
4936 Type in the following test.c program using your favorite
4961 \begin_layout Standard
4964 Compile this using the following command:
4973 If all goes well, the compiler will generate a test.asm and test.rel file.
4974 Congratulations, you've just compiled your first program with SDCC.
4975 We used the -c option to tell SDCC not to link the generated code, just
4976 to keep things simple for this step.
4984 The next step is to try it with the linker.
4994 If all goes well the compiler will link with the libraries and produce
4995 a test.ihx output file.
5000 (no test.ihx, and the linker generates warnings), then the problem is most
5009 usr/local/share/sdcc/lib directory
5016 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5023 Install trouble-shooting for suggestions).
5031 The final test is to ensure
5039 header files and libraries.
5040 Edit test.c and change it to the following:
5058 strcpy(str1, "testing");
5063 \begin_layout Standard
5066 Compile this by typing
5073 This should generate a test.ihx output file, and it should give no warnings
5074 such as not finding the string.h file.
5075 If it cannot find the string.h file, then the problem is that
5079 cannot find the /usr/local/share/sdcc/include directory
5086 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5093 Install trouble-shooting section for suggestions).
5102 \begin_layout Standard
5114 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5118 to find exactly where SDCC is looking for the include and lib files.
5121 \begin_layout Section
5122 Install Trouble-shooting
5123 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5128 \begin_inset LatexCommand \index{Install trouble-shooting}
5135 \begin_layout Subsection
5136 If SDCC does not build correctly
5139 \begin_layout Standard
5140 A thing to try is starting from scratch by unpacking the .tgz source package
5141 again in an empty directory.
5149 ./configure 2>&1 | tee configure.log
5163 make 2>&1 | tee make.log
5170 If anything goes wrong, you can review the log files to locate the problem.
5171 Or a relevant part of this can be attached to an email that could be helpful
5172 when requesting help from the mailing list.
5175 \begin_layout Subsection
5177 \begin_inset Quotes sld
5181 \begin_inset Quotes srd
5187 \begin_layout Standard
5189 \begin_inset Quotes sld
5193 \begin_inset Quotes srd
5196 command is a script that analyzes your system and performs some configuration
5197 to ensure the source package compiles on your system.
5198 It will take a few minutes to run, and will compile a few tests to determine
5199 what compiler features are installed.
5202 \begin_layout Subsection
5204 \begin_inset Quotes sld
5208 \begin_inset Quotes srd
5214 \begin_layout Standard
5215 This runs the GNU make tool, which automatically compiles all the source
5216 packages into the final installed binary executables.
5219 \begin_layout Subsection
5221 \begin_inset Quotes sld
5225 \begin_inset Quotes erd
5231 \begin_layout Standard
5232 This will install the compiler, other executables libraries and include
5233 files into the appropriate directories.
5235 \begin_inset LatexCommand \ref{sub:Install-paths}
5241 \begin_inset LatexCommand \ref{sub:Search-Paths}
5246 about install and search paths.
5248 On most systems you will need super-user privilege
5252 \begin_layout Section
5256 \begin_layout Standard
5257 SDCC is not just a compiler, but a collection of tools by various developers.
5258 These include linkers, assemblers, simulators and other components.
5259 Here is a summary of some of the components.
5260 Note that the included simulator and assembler have separate documentation
5261 which you can find in the source package in their respective directories.
5262 As SDCC grows to include support for other processors, other packages from
5263 various developers are included and may have their own sets of documentation.
5268 might want to look at the files which are installed in <installdir>.
5269 At the time of this writing, we find the following programs for gcc-builds:
5274 In <installdir>/bin:
5277 \begin_layout Itemize
5278 sdcc - The compiler.
5281 \begin_layout Itemize
5282 sdcpp - The C preprocessor.
5285 \begin_layout Itemize
5286 asx8051 - The assembler for 8051 type processors.
5289 \begin_layout Itemize
5294 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5297 \begin_layout Itemize
5298 aslink -The linker for 8051 type processors.
5301 \begin_layout Itemize
5306 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5309 \begin_layout Itemize
5310 s51 - The ucSim 8051 simulator.
5313 \begin_layout Itemize
5314 sdcdb - The source debugger.
5317 \begin_layout Itemize
5318 packihx - A tool to pack (compress) Intel hex files.
5321 \begin_layout Standard
5322 In <installdir>/share/sdcc/include
5325 \begin_layout Itemize
5329 \begin_layout Standard
5330 In <installdir>/share/sdcc/lib
5333 \begin_layout Itemize
5334 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5338 \begin_layout Standard
5339 In <installdir>/share/sdcc/doc
5342 \begin_layout Itemize
5346 \begin_layout Standard
5347 As development for other processors proceeds, this list will expand to include
5348 executables to support processors like AVR, PIC, etc.
5351 \begin_layout Subsection
5355 \begin_layout Standard
5356 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5357 the assembler and linkage editor.
5360 \begin_layout Subsection
5361 sdcpp - The C-Preprocessor
5364 \begin_layout Standard
5366 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5370 is a modified version of the GNU cpp
5371 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5376 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5381 The C preprocessor is used to pull in #include sources, process #ifdef
5382 statements, #defines and so on.
5385 \begin_layout Subsection
5394 - The Assemblers and Linkage Editors
5397 \begin_layout Standard
5398 This is retargettable assembler & linkage editor, it was developed by Alan
5400 John Hartman created the version for 8051, and I (Sandeep) have made some
5401 enhancements and bug fixes for it to work properly with SDCC.
5404 \begin_layout Subsection
5408 \begin_layout Standard
5410 \begin_inset LatexCommand \index{s51}
5414 is a free open source simulator developed by Daniel Drotos.
5415 The simulator is built as part of the build process.
5416 For more information visit Daniel's web site at:
5417 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5422 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5426 \begin_layout Subsection
5427 sdcdb - Source Level Debugger
5430 \begin_layout Standard
5432 \begin_inset LatexCommand \index{SDCDB (debugger)}
5436 is the companion source level debugger.
5437 More about SDCDB in section
5438 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5443 The current version of the debugger uses Daniel's Simulator S51
5444 \begin_inset LatexCommand \index{s51}
5448 , but can be easily changed to use other simulators.
5451 \begin_layout Chapter
5455 \begin_layout Section
5459 \begin_layout Subsection
5460 Single Source File Projects
5463 \begin_layout Standard
5464 For single source file 8051 projects the process is very simple.
5465 Compile your programs with the following command
5468 "sdcc sourcefile.c".
5472 This will compile, assemble and link your source file.
5473 Output files are as follows:
5476 \begin_layout Itemize
5478 \begin_inset LatexCommand \index{<file>.asm}
5483 \begin_inset LatexCommand \index{Assembler source}
5487 file created by the compiler
5490 \begin_layout Itemize
5492 \begin_inset LatexCommand \index{<file>.lst}
5497 \begin_inset LatexCommand \index{Assembler listing}
5501 file created by the Assembler
5504 \begin_layout Itemize
5506 \begin_inset LatexCommand \index{<file>.rst}
5511 \begin_inset LatexCommand \index{Assembler listing}
5515 file updated with linkedit information, created by linkage editor
5518 \begin_layout Itemize
5520 \begin_inset LatexCommand \index{<file>.sym}
5525 \begin_inset LatexCommand \index{Symbol listing}
5529 for the sourcefile, created by the assembler
5532 \begin_layout Itemize
5534 \begin_inset LatexCommand \index{<file>.rel}
5539 \begin_inset LatexCommand \index{<file>.o}
5544 \begin_inset LatexCommand \index{Object file}
5548 created by the assembler, input to Linkage editor
5551 \begin_layout Itemize
5553 \begin_inset LatexCommand \index{<file>.map}
5558 \begin_inset LatexCommand \index{Memory map}
5562 for the load module, created by the Linker
5565 \begin_layout Itemize
5567 \begin_inset LatexCommand \index{<file>.mem}
5571 - A file with a summary of the memory usage
5574 \begin_layout Itemize
5576 \begin_inset LatexCommand \index{<file>.ihx}
5580 - The load module in Intel hex format
5581 \begin_inset LatexCommand \index{Intel hex format}
5585 (you can select the Motorola S19 format
5586 \begin_inset LatexCommand \index{Motorola S19 format}
5594 \begin_layout Standard
5604 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5609 If you need another format you might want to use
5616 \begin_inset LatexCommand \index{objdump (tool)}
5627 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5632 \begin_inset Note Note
5635 \begin_layout Standard
5642 \begin_inset LatexCommand \vref{sub:Postprocessing-the-Intel}
5647 Both formats are documented in the documentation of srecord
5648 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5655 \begin_layout Itemize
5657 \begin_inset LatexCommand \index{<file>.adb}
5661 - An intermediate file containing debug information needed to create the
5666 \begin_layout Standard
5676 \begin_inset LatexCommand \index{-\/-debug}
5683 \begin_layout Itemize
5685 \begin_inset LatexCommand \index{<file>.cdb}
5689 - An optional file (with -
5693 \begin_layout Standard
5702 -debug) containing debug information.
5703 The format is documented in cdbfileformat.pdf
5706 \begin_layout Itemize
5709 \begin_inset LatexCommand \index{<file> (no extension)}
5713 An optional AOMF or AOMF51
5714 \begin_inset LatexCommand \index{AOMF, AOMF51}
5719 \begin_inset LatexCommand \label{OMF file}
5723 file containing debug information (generated with option -
5727 \begin_layout Standard
5753 ormat is a subformat of the OMF51 format and is commonly used by third party
5755 \begin_inset LatexCommand \index{Debugger}
5759 , simulators, emulators).
5762 \begin_layout Itemize
5764 \begin_inset LatexCommand \index{<file>.dump*}
5768 - Dump file to debug the compiler it self (generated with option -
5772 \begin_layout Standard
5781 -dumpall) (see section
5782 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5788 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5794 \begin_inset Quotes sld
5797 Anatomy of the compiler
5798 \begin_inset Quotes srd
5804 \begin_layout Subsection
5805 Postprocessing the Intel Hex
5806 \begin_inset LatexCommand \index{Intel hex format}
5811 \begin_inset LatexCommand \label{sub:Postprocessing-the-Intel}
5818 \begin_layout Standard
5819 In most cases this won't be needed but the Intel Hex file
5820 \begin_inset LatexCommand \index{<file>.ihx}
5824 which is generated by SDCC might include lines of varying length and the
5825 addresses within the file are not guaranteed to be strictly ascending.
5826 If your toolchain or a bootloader does not like this you can use the tool
5832 \begin_inset LatexCommand \index{packihx (tool)}
5836 which is part of the SDCC distribution:
5843 packihx sourcefile.ihx >sourcefile.hex
5850 The separately available
5855 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5859 package additionally allows to set undefined locations to a predefined
5860 value, to insert checksums
5861 \begin_inset LatexCommand \index{checksum}
5865 of various flavours (crc, add, xor) and to perform other manipulations
5866 (convert, split, crop, offset, ...).
5874 srec_cat\InsetSpace ~
5876 sourcefile.ihx -intel\InsetSpace ~
5878 -o sourcefile.hex -intel
5885 An example for a more complex command line
5889 \begin_layout Standard
5890 the command backfills
5891 \begin_inset LatexCommand \index{backfill unused memory}
5895 unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5897 If the program counter on an mcs51 runs wild the backfill pattern 0x12
5898 will be interpreted as an
5906 (where an emergency routine could sit).
5919 srec_cat\InsetSpace ~
5920 sourcefile.ihx -intel\InsetSpace ~
5922 -fill 0x12 0x0000 0xfffe\InsetSpace ~
5923 -little-endian-checksum-nega
5924 tive 0xfffe 0x02 0x02\InsetSpace ~
5926 -o sourcefile.hex -intel
5935 The srecord package is available at
5936 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5943 \begin_layout Subsection
5944 Projects with Multiple Source Files
5947 \begin_layout Standard
5948 SDCC can compile only ONE file at a time.
5949 Let us for example assume that you have a project containing the following
5954 foo1.c (contains some functions)
5956 foo2.c (contains some more functions)
5959 n.c (contains more functions and the function main)
5967 The first two files will need to be compiled separately with the commands:
5999 Then compile the source file containing the
6004 \begin_inset LatexCommand \index{Linker}
6008 the files together with the following command:
6016 foomain.c\InsetSpace ~
6017 foo1.rel\InsetSpace ~
6022 \begin_inset LatexCommand \index{<file>.rel}
6034 can be separately compiled as well:
6045 sdcc foomain.rel foo1.rel foo2.rel
6052 The file containing the
6067 file specified in the command line, since the linkage editor processes
6068 file in the order they are presented to it.
6069 The linker is invoked from SDCC using a script file with extension .lnk
6070 \begin_inset LatexCommand \index{<file>.lnk}
6075 You can view this file to troubleshoot linking problems such as those arising
6076 from missing libraries.
6079 \begin_layout Subsection
6080 Projects with Additional Libraries
6081 \begin_inset LatexCommand \index{Libraries}
6088 \begin_layout Standard
6089 Some reusable routines may be compiled into a library, see the documentation
6090 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6094 \begin_inset LatexCommand \index{<file>.lib}
6101 Libraries created in this manner can be included in the command line.
6102 Make sure you include the -L <library-path> option to tell the linker where
6103 to look for these files if they are not in the current directory.
6104 Here is an example, assuming you have the source file
6116 (if that is not the same as your current project):
6123 sdcc foomain.c foolib.lib -L mylib
6134 must be an absolute path name.
6138 The most efficient way to use libraries is
6139 to keep separate modules in separate source files.
6140 The lib file now should name all the modules.rel
6141 \begin_inset LatexCommand \index{<file>.rel}
6146 For an example see the standard library file
6150 in the directory <installdir>/share/lib/small.
6153 \begin_layout Subsection
6154 Using sdcclib to Create and Manage Libraries
6155 \begin_inset LatexCommand \index{sdcclib}
6162 \begin_layout Standard
6163 Alternatively, instead of having a .rel file for each entry on the library
6164 file as described in the preceding section, sdcclib can be used to embed
6165 all the modules belonging to such library in the library file itself.
6166 This results in a larger library file, but it greatly reduces the number
6167 of disk files accessed by the linker.
6168 Additionally, the packed library file contains an index of all include
6169 modules and symbols that significantly speeds up the linking process.
6170 To display a list of options supported by sdcclib type:
6175 \begin_layout Standard
6180 \begin_inset LatexCommand \index{sdcclib}
6191 To create a new library file, start by compiling all the required modules.
6197 \begin_layout Standard
6204 \begin_layout Standard
6211 \begin_layout Standard
6218 \begin_layout Standard
6225 \begin_layout Standard
6234 \begin_layout Standard
6235 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6237 The next step is to add the .rel files to the library file:
6242 \begin_layout Standard
6246 sdcclib libint.lib _divsint.rel
6249 \begin_inset LatexCommand \index{sdcclib}
6256 \begin_layout Standard
6260 sdcclib libint.lib _divuint.rel
6263 \begin_layout Standard
6267 sdcclib libint.lib _modsint.rel
6270 \begin_layout Standard
6274 sdcclib libint.lib _moduint.rel
6277 \begin_layout Standard
6281 sdcclib libint.lib _mulint.rel
6289 \begin_layout Standard
6298 \begin_layout Standard
6302 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6310 \begin_layout Standard
6311 If the file already exists in the library, it will be replaced.
6312 If a list of .rel files is available, you can tell sdcclib to add those
6314 For example, if the file 'myliblist.txt' contains
6322 \begin_layout Standard
6329 \begin_layout Standard
6336 \begin_layout Standard
6343 \begin_layout Standard
6350 \begin_layout Standard
6362 \begin_layout Standard
6371 \begin_layout Standard
6375 sdcclib -l libint.lib myliblist.txt
6383 \begin_layout Standard
6384 Additionally, you can instruct sdcclib to compiles the files before adding
6385 them to the library.
6386 This is achieved using the environment variables SDCCLIB_CC and/or SDCCLIB_AS.
6395 \begin_layout Standard
6399 set SDCCLIB_CC=sdcc -c
6402 \begin_layout Standard
6406 sdcclib -l libint.lib myliblist.txt
6414 \begin_layout Standard
6415 To see what modules and symbols are included in the library, options -s
6416 and -m are available.
6424 sdcclib -s libint.lib
6427 \begin_inset LatexCommand \index{sdcclib}
6439 \begin_layout Standard
6445 \begin_layout Standard
6451 \begin_layout Standard
6459 \begin_layout Standard
6465 \begin_layout Standard
6471 \begin_layout Standard
6477 \begin_layout Standard
6483 \begin_layout Standard
6491 \begin_layout Standard
6497 \begin_layout Standard
6503 \begin_layout Standard
6511 \begin_layout Standard
6517 \begin_layout Standard
6523 \begin_layout Standard
6529 \begin_layout Standard
6537 \begin_layout Standard
6543 \begin_layout Standard
6554 \begin_layout Standard
6555 If the source files are compiled using -
6559 \begin_layout Standard
6569 \begin_inset LatexCommand \index{-\/-debug}
6573 , the corresponding debug information file .adb will be include in the library
6575 The library files created with sdcclib are plain text files, so they can
6576 be viewed with a text editor.
6577 It is not recomended to modify a library file created with sdcclib using
6578 a text editor, as there are file indexes numbers located accross the file
6579 used by the linker to quickly locate the required module to link.
6580 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6581 it can be safely deleted, since all the information required for linking
6582 is embedded in the library file itself.
6583 Library files created using sdcclib are used as described in the preceding
6585 \begin_inset VSpace bigskip
6591 \begin_layout Section
6592 Command Line Options
6593 \begin_inset LatexCommand \index{Command Line Options}
6598 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6605 \begin_layout Subsection
6606 Processor Selection Options
6607 \begin_inset LatexCommand \index{Options processor selection}
6612 \begin_inset LatexCommand \index{Processor selection options}
6620 \labelwidthstring 00.00.0000
6624 \begin_inset LatexCommand \index{-mmcs51}
6630 Generate code for the Intel MCS51
6631 \begin_inset LatexCommand \index{MCS51}
6635 family of processors.
6636 This is the default processor target.
6640 \labelwidthstring 00.00.0000
6644 \begin_inset LatexCommand \index{-mds390}
6650 Generate code for the Dallas DS80C390
6651 \begin_inset LatexCommand \index{DS80C390}
6659 \labelwidthstring 00.00.0000
6663 \begin_inset LatexCommand \index{-mds400}
6669 Generate code for the Dallas DS80C400
6670 \begin_inset LatexCommand \index{DS80C400}
6678 \labelwidthstring 00.00.0000
6682 \begin_inset LatexCommand \index{-mhc08}
6688 Generate code for the Freescale/Motorola HC08
6689 \begin_inset LatexCommand \index{HC08}
6693 family of processors.
6697 \labelwidthstring 00.00.0000
6701 \begin_inset LatexCommand \index{-mz80}
6707 Generate code for the Zilog Z80
6708 \begin_inset LatexCommand \index{Z80}
6712 family of processors.
6716 \labelwidthstring 00.00.0000
6720 \begin_inset LatexCommand \index{-mgbz80}
6726 Generate code for the GameBoy Z80
6727 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6731 processor (Not actively maintained).
6735 \labelwidthstring 00.00.0000
6739 \begin_inset LatexCommand \index{-mavr}
6745 Generate code for the Atmel AVR
6746 \begin_inset LatexCommand \index{AVR}
6750 processor (Not maintained, not complete).
6751 AVR users should probably have a look at winavr
6752 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6757 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6761 , which is based on AVR-port of the gcc compiler.
6764 \begin_layout Standard
6765 \begin_inset Note Note
6768 \begin_layout Standard
6769 I think it is fair to direct users there for now.
6770 Open source is also about avoiding unnecessary work .
6771 But I didn't find the 'official' link.
6780 \labelwidthstring 00.00.0000
6784 \begin_inset LatexCommand \index{-mpic14}
6790 Generate code for the Microchip PIC 14
6791 \begin_inset LatexCommand \index{PIC14}
6795 -bit processors (p16f84 and variants.
6796 In development, not complete).
6799 \begin_layout Standard
6800 \begin_inset Note Note
6803 \begin_layout Standard
6804 p16f627 p16f628 p16f84 p16f873 p16f877?
6813 \labelwidthstring 00.00.0000
6817 \begin_inset LatexCommand \index{-mpic16}
6823 Generate code for the Microchip PIC 16
6824 \begin_inset LatexCommand \index{PIC16}
6828 -bit processors (p18f452 and variants.
6829 In development, not complete).
6833 \labelwidthstring 00.00.0000
6838 Generate code for the Toshiba TLCS-900H
6839 \begin_inset LatexCommand \index{TLCS-900H}
6843 processor (Not maintained, not complete).
6847 \labelwidthstring 00.00.0000
6851 \begin_inset LatexCommand \index{-mxa51}
6857 Generate code for the Phillips XA51
6858 \begin_inset LatexCommand \index{XA51}
6862 processor (Not maintained, not complete).
6865 \begin_layout Standard
6866 \begin_inset VSpace bigskip
6872 \begin_layout Subsection
6873 Preprocessor Options
6874 \begin_inset LatexCommand \index{Options preprocessor}
6879 \begin_inset LatexCommand \index{Preprocessor options}
6884 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6892 \labelwidthstring 00.00.0000
6896 \begin_inset LatexCommand \index{-I<path>}
6902 The additional location where the preprocessor will look for <..h> or
6903 \begin_inset Quotes eld
6907 \begin_inset Quotes erd
6914 \labelwidthstring 00.00.0000
6918 \begin_inset LatexCommand \index{-D<macro[=value]>}
6924 Command line definition of macros.
6925 Passed to the preprocessor.
6929 \labelwidthstring 00.00.0000
6933 \begin_inset LatexCommand \index{-M}
6939 Tell the preprocessor to output a rule suitable for make describing the
6940 dependencies of each object file.
6941 For each source file, the preprocessor outputs one make-rule whose target
6942 is the object file name for that source file and whose dependencies are
6943 all the files `#include'd in it.
6944 This rule may be a single line or may be continued with `
6946 '-newline if it is long.
6947 The list of rules is printed on standard output instead of the preprocessed
6950 \begin_inset LatexCommand \index{-E}
6958 \labelwidthstring 00.00.0000
6962 \begin_inset LatexCommand \index{-C}
6968 Tell the preprocessor not to discard comments.
6969 Used with the `-E' option.
6973 \labelwidthstring 00.00.0000
6977 \begin_inset LatexCommand \index{-MM}
6988 Like `-M' but the output mentions only the user header files included with
6990 \begin_inset Quotes eld
6994 System header files included with `#include <file>' are omitted.
6998 \labelwidthstring 00.00.0000
7002 \begin_inset LatexCommand \index{-Aquestion(answer)}
7008 Assert the answer answer for question, in case it is tested with a preprocessor
7009 conditional such as `#if #question(answer)'.
7010 `-A-' disables the standard assertions that normally describe the target
7015 \labelwidthstring 00.00.0000
7019 \begin_inset LatexCommand \index{-Umacro}
7025 Undefine macro macro.
7026 `-U' options are evaluated after all `-D' options, but before any `-include'
7027 and `-imacros' options.
7031 \labelwidthstring 00.00.0000
7035 \begin_inset LatexCommand \index{-dM}
7041 Tell the preprocessor to output only a list of the macro definitions that
7042 are in effect at the end of preprocessing.
7043 Used with the `-E' option.
7047 \labelwidthstring 00.00.0000
7051 \begin_inset LatexCommand \index{-dD}
7057 Tell the preprocessor to pass all macro definitions into the output, in
7058 their proper sequence in the rest of the output.
7062 \labelwidthstring 00.00.0000
7066 \begin_inset LatexCommand \index{-dN}
7077 Like `-dD' except that the macro arguments and contents are omitted.
7078 Only `#define name' is included in the output.
7082 \labelwidthstring 00.00.0000
7085 -pedantic-parse-number
7086 \begin_inset LatexCommand \index{pedantic}
7091 \begin_inset LatexCommand \index{-pedantic-parse-number}
7099 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
7107 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7108 and the macro LO_B(3) gets expanded.
7109 See also #pragma pedantic_parse_number
7110 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
7115 \begin_inset LatexCommand \ref{sec:Pragmas}
7121 Note: this functionality is not in conformance with C99 standard!
7125 \labelwidthstring 00.00.0000
7129 preprocessorOption[,preprocessorOption]
7132 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
7137 Pass the preprocessorOption to the preprocessor
7142 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7147 SDCC uses an adapted version of the preprocessor
7151 of the GNU Compiler Collection
7152 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
7161 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7165 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7170 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7177 \begin_layout Standard
7178 \begin_inset VSpace bigskip
7184 \begin_layout Subsection
7186 \begin_inset LatexCommand \index{Options linker}
7191 \begin_inset LatexCommand \index{Linker options}
7199 \labelwidthstring 00.00.0000
7209 \begin_layout Standard
7221 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7226 \begin_inset LatexCommand \index{-L -\/-lib-path}
7233 <absolute path to additional libraries> This option is passed to the linkage
7234 editor's additional libraries
7235 \begin_inset LatexCommand \index{Libraries}
7240 The path name must be absolute.
7241 Additional library files may be specified in the command line.
7242 See section Compiling programs for more details.
7246 \labelwidthstring 00.00.0000
7253 \begin_layout Standard
7265 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7270 <Value> The start location of the external ram
7271 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7275 , default value is 0.
7276 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7280 \begin_layout Standard
7289 -xram-loc 0x8000 or -
7293 \begin_layout Standard
7306 \labelwidthstring 00.00.0000
7313 \begin_layout Standard
7325 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7330 <Value> The start location of the code
7331 \begin_inset LatexCommand \index{code}
7335 segment, default value 0.
7336 Note when this option is used the interrupt vector table
7337 \begin_inset LatexCommand \index{interrupt vector table}
7341 is also relocated to the given address.
7342 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7346 \begin_layout Standard
7355 -code-loc 0x8000 or -
7359 \begin_layout Standard
7372 \labelwidthstring 00.00.0000
7379 \begin_layout Standard
7391 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7396 <Value> By default the stack
7397 \begin_inset LatexCommand \index{stack}
7401 is placed after the data segment.
7402 Using this option the stack can be placed anywhere in the internal memory
7404 The value entered can be in Hexadecimal or Decimal format, e.g.
7409 \begin_layout Standard
7418 -stack-loc 0x20 or -
7422 \begin_layout Standard
7432 Since the sp register is incremented before a push or call, the initial
7433 sp will be set to one byte prior the provided value.
7434 The provided value should not overlap any other memory areas such as used
7435 register banks or the data segment and with enough space for the current
7443 \begin_layout Standard
7456 \begin_inset LatexCommand \index{-\/-pack-iram}
7460 option (which is now a default setting) will override this setting, so
7461 you should also specify the
7467 \begin_layout Standard
7480 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7484 option if you need to manually place the stack.
7488 \labelwidthstring 00.00.0000
7495 \begin_layout Standard
7507 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7512 <Value> By default the external stack
7513 \begin_inset LatexCommand \index{xstack}
7517 is placed after the pdata
7518 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7523 Using this option the xstack can be placed anywhere in the external memory
7525 The value entered can be in Hexadecimal or Decimal format, e.g.
7530 \begin_layout Standard
7539 -xstack-loc 0x8000 or -
7543 \begin_layout Standard
7553 The provided value should not overlap any other memory areas such as the
7554 pdata or xdata segment and with enough space for the current application.
7558 \labelwidthstring 00.00.0000
7565 \begin_layout Standard
7577 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7582 <Value> The start location of the internal ram data
7583 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7588 The value entered can be in Hexadecimal or Decimal format, eg.
7593 \begin_layout Standard
7606 \begin_layout Standard
7616 (By default, the start location of the internal ram data segment is set
7617 as low as possible in memory, taking into account the used register banks
7618 and the bit segment at address 0x20.
7619 For example if register banks 0 and 1 are used without bit variables, the
7620 data segment will be set, if -
7624 \begin_layout Standard
7633 -data-loc is not used, to location 0x10.)
7637 \labelwidthstring 00.00.0000
7644 \begin_layout Standard
7656 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7661 <Value> The start location of the indirectly addressable internal ram
7662 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7666 of the 8051, default value is 0x80.
7667 The value entered can be in Hexadecimal or Decimal format, eg.
7672 \begin_layout Standard
7681 -idata-loc 0x88 or -
7685 \begin_layout Standard
7698 \labelwidthstring 00.00.0000
7705 \begin_layout Standard
7717 <Value> The start location of the bit
7718 \begin_inset LatexCommand \index{bit}
7722 addressable internal ram of the 8051.
7728 Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7733 \labelwidthstring 00.00.0000
7740 \begin_layout Standard
7750 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7759 The linker output (final object code) is in Intel Hex format.
7760 \begin_inset LatexCommand \index{Intel hex format}
7764 This is the default option.
7765 The format itself is documented in the documentation of srecord
7766 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7774 \labelwidthstring 00.00.0000
7781 \begin_layout Standard
7791 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7800 The linker output (final object code) is in Motorola S19 format
7801 \begin_inset LatexCommand \index{Motorola S19 format}
7806 The format itself is documented in the documentation of srecord.
7810 \labelwidthstring 00.00.0000
7817 \begin_layout Standard
7827 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7832 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7841 The linker output (final object code) is in ELF format
7842 \begin_inset LatexCommand \index{ELF format}
7847 (Currently only supported for the HC08
7848 \begin_inset LatexCommand \index{HC08}
7856 \labelwidthstring 00.00.0000
7860 linkOption[,linkOption]
7863 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7868 Pass the linkOption to the linker.
7869 If a bootloader is used an option like
7870 \begin_inset Quotes sld
7875 \begin_inset Quotes srd
7878 would be typical to set the start of the code segment.
7879 See also #pragma constseg and #pragma codeseg in section
7880 \begin_inset LatexCommand \ref{sec:Pragmas}
7885 File sdcc/as/doc/asxhtm.html has more on linker options.
7888 \begin_layout Standard
7889 \begin_inset VSpace bigskip
7895 \begin_layout Subsection
7897 \begin_inset LatexCommand \index{Options MCS51}
7902 \begin_inset LatexCommand \index{MCS51 options}
7910 \labelwidthstring 00.00.0000
7917 \begin_layout Standard
7927 \begin_inset LatexCommand \index{-\/-model-small}
7938 Generate code for Small Model programs, see section Memory Models for more
7940 This is the default model.
7944 \labelwidthstring 00.00.0000
7951 \begin_layout Standard
7961 \begin_inset LatexCommand \index{-\/-model-medium}
7967 Generate code for Medium model programs, see section Memory Models for
7969 If this option is used all source files in the project have to be compiled
7971 It must also be used when invoking the linker.
7975 \labelwidthstring 00.00.0000
7982 \begin_layout Standard
7992 \begin_inset LatexCommand \index{-\/-model-large}
7998 Generate code for Large model programs, see section Memory Models for more
8000 If this option is used all source files in the project have to be compiled
8002 It must also be used when invoking the linker.
8006 \labelwidthstring 00.00.0000
8013 \begin_layout Standard
8023 \begin_inset LatexCommand \index{-\/-xstack}
8029 Uses a pseudo stack in the pdata
8030 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8034 area (usually the first 256 bytes in the external ram) for allocating variables
8035 and passing parameters.
8037 \begin_inset LatexCommand \ref{sub:External-Stack}
8042 External Stack for more details.
8046 \labelwidthstring 00.00.0000
8053 \begin_layout Standard
8066 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
8070 Causes the linker to check if the internal ram usage is within limits of
8075 \labelwidthstring 00.00.0000
8082 \begin_layout Standard
8095 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
8099 Causes the linker to check if the external ram usage is within limits of
8104 \labelwidthstring 00.00.0000
8111 \begin_layout Standard
8124 \begin_inset LatexCommand \index{-\/-code-size <Value>}
8128 Causes the linker to check if the code memory usage is within limits of
8133 \labelwidthstring 00.00.0000
8140 \begin_layout Standard
8153 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8157 Causes the linker to check if there is at minimum <Value> bytes for stack.
8161 \labelwidthstring 00.00.0000
8168 \begin_layout Standard
8181 \begin_inset LatexCommand \index{-\/-pack-iram}
8185 Causes the linker to use unused register banks for data variables and pack
8186 data, idata and stack together.
8187 This is the default now.
8191 \labelwidthstring 00.00.0000
8198 \begin_layout Standard
8211 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8215 Causes the linker to use old style for allocating memory areas.
8219 \labelwidthstring 00.00.0000
8226 \begin_layout Standard
8239 \begin_inset LatexCommand \index{-\/-acall-ajmp}
8243 Replaces the three byte instructions lcall/ljmp with the two byte instructions
8245 Only use this option if your code is in the same 2k block of memory.
8246 You may need to use this option for some 8051 derivatives which lack the
8247 lcall/ljmp instructions..
8250 \begin_layout Standard
8251 \begin_inset VSpace bigskip
8257 \begin_layout Subsection
8258 DS390 / DS400 Options
8259 \begin_inset LatexCommand \index{Options DS390}
8264 \begin_inset LatexCommand \index{DS390}
8272 \labelwidthstring 00.00.0000
8279 \begin_layout Standard
8291 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8301 Generate 24-bit flat mode code.
8302 This is the one and only that the ds390 code generator supports right now
8303 and is default when using
8308 See section Memory Models for more details.
8312 \labelwidthstring 00.00.0000
8319 \begin_layout Standard
8329 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8335 disable interrupts during ESP:SP updates.
8339 \labelwidthstring 00.00.0000
8346 \begin_layout Standard
8358 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8362 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8363 This is the one and only that the ds390 code generator supports right now
8364 and is default when using
8369 In this mode, the stack is located in the lower 1K of the internal RAM,
8370 which is mapped to 0x400000.
8371 Note that the support is incomplete, since it still uses a single byte
8372 as the stack pointer.
8373 This means that only the lower 256 bytes of the potential 1K stack space
8374 will actually be used.
8375 However, this does allow you to reclaim the precious 256 bytes of low RAM
8376 for use for the DATA and IDATA segments.
8377 The compiler will not generate any code to put the processor into 10 bit
8379 It is important to ensure that the processor is in this mode before calling
8380 any re-entrant functions compiled with this option.
8381 In principle, this should work with the
8387 \begin_layout Standard
8397 \begin_inset LatexCommand \index{-\/-stack-auto}
8403 option, but that has not been tested.
8404 It is incompatible with the
8410 \begin_layout Standard
8420 \begin_inset LatexCommand \index{-\/-xstack}
8427 It also only makes sense if the processor is in 24 bit contiguous addressing
8434 \begin_layout Standard
8443 -model-flat24 option
8448 \begin_inset Note Note
8452 \labelwidthstring 00.00.0000
8459 \begin_layout Standard
8468 -stack-8-bit - switches off the 10-bit mode
8477 \labelwidthstring 00.00.0000
8484 \begin_layout Standard
8494 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8500 insert call to function __stack_probe at each function prologue.
8504 \labelwidthstring 00.00.0000
8511 \begin_layout Standard
8521 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8527 <nnnn> LibraryID used in -mTININative.
8532 \labelwidthstring 00.00.0000
8539 \begin_layout Standard
8549 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8555 generate code for DS390 Arithmetic Accelerator.
8559 \begin_layout Standard
8560 \begin_inset VSpace bigskip
8566 \begin_layout Subsection
8568 \begin_inset LatexCommand \index{Options Z80}
8573 \begin_inset LatexCommand \index{Z80}
8581 \labelwidthstring 00.00.0000
8588 \begin_layout Standard
8600 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8610 Force a called function to always save BC.
8614 \labelwidthstring 00.00.0000
8621 \begin_layout Standard
8633 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8637 When linking, skip the standard crt0.o object file.
8638 You must provide your own crt0.o for your system when linking.
8642 \labelwidthstring 00.00.0000
8649 \begin_layout Standard
8661 \begin_inset LatexCommand \index{Z80!Options!-\/-portmode=<Value>}
8665 Determinate PORT I/O mode (<Value> is z80 or z180).
8669 \labelwidthstring 00.00.0000
8676 \begin_layout Standard
8688 \begin_inset LatexCommand \index{Z80!Options!-\/-asm=<Value>}
8692 Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
8696 \labelwidthstring 00.00.0000
8703 \begin_layout Standard
8716 \begin_inset LatexCommand \index{Z80!Options!-\/-codeseg <Value>}
8720 Use <Value> for the code segment name.
8724 \labelwidthstring 00.00.0000
8731 \begin_layout Standard
8744 \begin_inset LatexCommand \index{Z80!Options!-\/-constseg <Value>}
8748 Use <Value> for the const segment name.
8752 \labelwidthstring 00.00.0000
8753 \begin_inset VSpace bigskip
8759 \begin_layout Subsection
8761 \begin_inset LatexCommand \index{Options GBZ80}
8766 \begin_inset LatexCommand \index{GBZ80}
8774 \labelwidthstring 00.00.0000
8781 \begin_layout Standard
8793 \begin_inset LatexCommand \index{GBZ80!Options!-\/-callee-saves-bc}
8803 Force a called function to always save BC.
8807 \labelwidthstring 00.00.0000
8814 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
8818 Use code bank <Num>.
8822 \labelwidthstring 00.00.0000
8829 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
8833 Use data bank <Num>.
8837 \labelwidthstring 00.00.0000
8844 \begin_layout Standard
8857 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
8861 Use <Value> for the code segment name.
8865 \labelwidthstring 00.00.0000
8872 \begin_layout Standard
8885 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
8889 Use <Value> for the const segment name.
8892 \begin_layout Standard
8893 \begin_inset VSpace bigskip
8899 \begin_layout Subsection
8900 Optimization Options
8901 \begin_inset LatexCommand \index{Options optimization}
8906 \begin_inset LatexCommand \index{Optimization options}
8914 \labelwidthstring 00.00.0000
8921 \begin_layout Standard
8931 \begin_inset LatexCommand \index{-\/-nogcse}
8937 Will not do global subexpression elimination, this option may be used when
8938 the compiler creates undesirably large stack/data spaces to store compiler
8948 \begin_inset LatexCommand \index{sloc (spill location)}
8953 A warning message will be generated when this happens and the compiler
8954 will indicate the number of extra bytes it allocated.
8955 It is recommended that this option NOT be used, #pragma\InsetSpace ~
8957 \begin_inset LatexCommand \index{\#pragma nogcse}
8961 can be used to turn off global subexpression elimination
8962 \begin_inset LatexCommand \index{Subexpression elimination}
8966 for a given function only.
8970 \labelwidthstring 00.00.0000
8977 \begin_layout Standard
8987 \begin_inset LatexCommand \index{-\/-noinvariant}
8993 Will not do loop invariant optimizations, this may be turned off for reasons
8994 explained for the previous option.
8995 For more details of loop optimizations performed see Loop Invariants in
8997 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
9002 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9004 \begin_inset LatexCommand \index{\#pragma noinvariant}
9008 can be used to turn off invariant optimizations for a given function only.
9012 \labelwidthstring 00.00.0000
9019 \begin_layout Standard
9029 \begin_inset LatexCommand \index{-\/-noinduction}
9035 Will not do loop induction optimizations, see section strength reduction
9037 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9039 \begin_inset LatexCommand \index{\#pragma noinduction}
9043 can be used to turn off induction optimizations for a given function only.
9047 \labelwidthstring 00.00.0000
9054 \begin_layout Standard
9064 \begin_inset LatexCommand \index{-\/-nojtbound}
9075 Will not generate boundary condition check when switch statements
9076 \begin_inset LatexCommand \index{switch statement}
9080 are implemented using jump-tables.
9082 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
9087 Switch Statements for more details.
9088 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9090 \begin_inset LatexCommand \index{\#pragma nojtbound}
9094 can be used to turn off boundary checking for jump tables for a given function
9099 \labelwidthstring 00.00.0000
9106 \begin_layout Standard
9116 \begin_inset LatexCommand \index{-\/-noloopreverse}
9125 Will not do loop reversal
9126 \begin_inset LatexCommand \index{Loop reversing}
9134 \labelwidthstring 00.00.0000
9139 \begin_layout Standard
9153 \begin_inset LatexCommand \index{-\/-nolabelopt }
9157 Will not optimize labels (makes the dumpfiles more readable).
9161 \labelwidthstring 00.00.0000
9168 \begin_layout Standard
9178 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9184 Will not memcpy initialized data from code space into xdata space.
9185 This saves a few bytes in code space if you don't have initialized data
9186 \begin_inset LatexCommand \index{Variable initialization}
9194 \labelwidthstring 00.00.0000
9201 \begin_layout Standard
9211 \begin_inset LatexCommand \index{-\/-nooverlay}
9217 The compiler will not overlay parameters and local variables of any function,
9218 see section Parameters and local variables for more details.
9222 \labelwidthstring 00.00.0000
9229 \begin_layout Standard
9239 \begin_inset LatexCommand \index{-\/-no-peep}
9245 Disable peep-hole optimization with built-in rules.
9249 \labelwidthstring 00.00.0000
9256 \begin_layout Standard
9268 \begin_inset LatexCommand \index{-\/-peep-file}
9273 <filename> This option can be used to use additional rules to be used by
9274 the peep hole optimizer.
9276 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9281 Peep Hole optimizations for details on how to write these rules.
9285 \labelwidthstring 00.00.0000
9292 \begin_layout Standard
9302 \begin_inset LatexCommand \index{-\/-peep-asm}
9308 Pass the inline assembler code through the peep hole optimizer.
9309 This can cause unexpected changes to inline assembler code, please go through
9310 the peephole optimizer
9311 \begin_inset LatexCommand \index{Peephole optimizer}
9315 rules defined in the source file tree '<target>/peeph.def' before using
9320 \labelwidthstring 00.00.0000
9327 \begin_layout Standard
9337 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9343 The compiler will optimize code generation towards fast code, possibly
9344 at the expense of code size.
9348 \labelwidthstring 00.00.0000
9355 \begin_layout Standard
9365 \begin_inset LatexCommand \index{-\/-opt-code-size}
9371 The compiler will optimize code generation towards compact code, possibly
9372 at the expense of code speed.
9375 \begin_layout Standard
9376 \begin_inset VSpace bigskip
9382 \begin_layout Subsection
9384 \begin_inset LatexCommand \index{Options other}
9392 \labelwidthstring 00.00.0000
9400 \begin_layout Standard
9410 \begin_inset LatexCommand \index{-\/-compile-only}
9415 \begin_inset LatexCommand \index{-c -\/-compile-only}
9421 will compile and assemble the source, but will not call the linkage editor.
9425 \labelwidthstring 00.00.0000
9434 \begin_layout Standard
9446 \begin_inset LatexCommand \index{-\/-c1mode}
9452 reads the preprocessed source from standard input and compiles it.
9453 The file name for the assembler output must be specified using the -o option.
9457 \labelwidthstring 00.00.0000
9461 \begin_inset LatexCommand \index{-E}
9467 Run only the C preprocessor.
9468 Preprocess all the C source files specified and output the results to standard
9473 \labelwidthstring 00.00.0000
9478 \begin_inset LatexCommand \index{-o <path/file>}
9484 The output path where everything will be placed or the file name used for
9485 all generated output files.
9486 If the parameter is a path, it must have a trailing slash (or backslash
9487 for the Windows binaries) to be recognized as a path.
9492 Note for Windows users: if the path contains spaces, it should be surrounded
9494 The trailing backslash should be doubled in order to prevent escaping the
9495 final quote, for example:
9498 \begin_inset Quotes sld
9512 \begin_inset Quotes srd
9517 or put after the final quote, for example:
9520 \begin_inset Quotes sld
9530 \begin_inset Quotes srd
9538 The path using slashes for directory delimiters can be used too, for example:
9542 \begin_inset Quotes sld
9545 F:/Projects/test3/output 1/
9546 \begin_inset Quotes srd
9555 \labelwidthstring 00.00.0000
9562 \begin_layout Standard
9572 \begin_inset LatexCommand \index{-\/-stack-auto}
9583 All functions in the source file will be compiled as
9588 \begin_inset LatexCommand \index{reentrant}
9593 the parameters and local variables will be allocated on the stack
9594 \begin_inset LatexCommand \index{stack}
9600 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9604 Parameters and Local Variables for more details.
9605 If this option is used all source files in the project should be compiled
9607 It automatically implies -
9613 \begin_layout Standard
9624 -int-long-reent and -
9630 \begin_layout Standard
9646 \labelwidthstring 00.00.0000
9653 \begin_layout Standard
9663 \begin_inset LatexCommand \index{-\/-callee-saves}
9668 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9672 function1[,function2][,function3]....
9675 The compiler by default uses a caller saves convention for register saving
9676 across function calls, however this can cause unnecessary register pushing
9677 and popping when calling small functions from larger functions.
9678 This option can be used to switch the register saving convention for the
9679 function names specified.
9680 The compiler will not save registers when calling these functions, no extra
9681 code will be generated at the entry and exit (function prologue
9684 \begin_inset LatexCommand \index{function prologue}
9693 \begin_inset LatexCommand \index{function epilogue}
9699 ) for these functions to save and restore the registers used by these functions,
9700 this can SUBSTANTIALLY reduce code and improve run time performance of
9702 In the future the compiler (with inter procedural analysis) will be able
9703 to determine the appropriate scheme to use for each function call.
9704 DO NOT use this option for built-in functions such as _mulint..., if this
9705 option is used for a library function the appropriate library function
9706 needs to be recompiled with the same option.
9707 If the project consists of multiple source files then all the source file
9708 should be compiled with the same -
9712 \begin_layout Standard
9721 -callee-saves option string.
9722 Also see #pragma\InsetSpace ~
9724 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9729 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9737 \labelwidthstring 00.00.0000
9744 \begin_layout Standard
9754 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9768 \begin_layout Standard
9777 -callee-saves will be applied to all functions by default.
9781 \labelwidthstring 00.00.0000
9788 \begin_layout Standard
9798 \begin_inset LatexCommand \index{-\/-debug}
9807 When this option is used the compiler will generate debug information.
9808 The debug information collected in a file with .cdb extension can be used
9810 For more information see documentation for SDCDB.
9811 Another file with no extension contains debug information in AOMF or AOMF51
9812 \begin_inset LatexCommand \index{AOMF, AOMF51}
9816 format which is commonly used by third party tools.
9820 \labelwidthstring 00.00.0000
9824 \begin_inset LatexCommand \index{-S}
9835 Stop after the stage of compilation proper; do not assemble.
9836 The output is an assembler code file for the input file specified.
9840 \labelwidthstring 00.00.0000
9847 \begin_layout Standard
9857 \begin_inset LatexCommand \index{-\/-int-long-reent}
9863 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
9864 Note by default these libraries are compiled as non-reentrant.
9865 See section Installation for more details.
9869 \labelwidthstring 00.00.0000
9876 \begin_layout Standard
9886 \begin_inset LatexCommand \index{-\/-cyclomatic}
9895 This option will cause the compiler to generate an information message for
9896 each function in the source file.
9897 The message contains some
9901 information about the function.
9902 The number of edges and nodes the compiler detected in the control flow
9903 graph of the function, and most importantly the
9905 cyclomatic complexity
9906 \begin_inset LatexCommand \index{Cyclomatic complexity}
9912 see section on Cyclomatic Complexity for more details.
9916 \labelwidthstring 00.00.0000
9923 \begin_layout Standard
9933 \begin_inset LatexCommand \index{-\/-float-reent}
9939 Floating point library is compiled as reentrant
9940 \begin_inset LatexCommand \index{reentrant}
9945 See section Installation for more details.
9949 \labelwidthstring 00.00.0000
9956 \begin_layout Standard
9966 \begin_inset LatexCommand \index{-\/-funsigned-char}
9972 The default signedness for every type is
9977 In some embedded environments the default signedness of
9986 To set the signess for characters to unsigned, use the option -
9992 \begin_layout Standard
10004 If this option is set and no signedness keyword (unsigned/signed) is given,
10005 a char will be signed.
10006 All other types are unaffected.
10010 \labelwidthstring 00.00.0000
10017 \begin_layout Standard
10027 \begin_inset LatexCommand \index{-\/-main-return}
10033 This option can be used if the code generated is called by a monitor program
10034 or if the main routine includes an endless loop.
10035 This option results in slightly smaller code and saves two bytes of stack
10037 The return from the 'main'
10038 \begin_inset LatexCommand \index{main return}
10042 function will return to the function calling main.
10043 The default setting is to lock up i.e.
10052 \labelwidthstring 00.00.0000
10059 \begin_layout Standard
10069 \begin_inset LatexCommand \index{-\/-nostdinc}
10075 This will prevent the compiler from passing on the default include path
10076 to the preprocessor.
10080 \labelwidthstring 00.00.0000
10087 \begin_layout Standard
10097 \begin_inset LatexCommand \index{-\/-nostdlib}
10103 This will prevent the compiler from passing on the default library
10104 \begin_inset LatexCommand \index{Libraries}
10108 path to the linker.
10112 \labelwidthstring 00.00.0000
10119 \begin_layout Standard
10129 \begin_inset LatexCommand \index{-\/-verbose}
10135 Shows the various actions the compiler is performing.
10139 \labelwidthstring 00.00.0000
10143 \begin_inset LatexCommand \index{-V}
10149 Shows the actual commands the compiler is executing.
10153 \labelwidthstring 00.00.0000
10160 \begin_layout Standard
10170 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
10176 Hides your ugly and inefficient c-code from the asm file, so you can always
10177 blame the compiler :)
10181 \labelwidthstring 00.00.0000
10188 \begin_layout Standard
10198 \begin_inset LatexCommand \index{-\/-no-gen-comments}
10204 Include code generator and peep-hole comments in the generated asm files.
10208 \labelwidthstring 00.00.0000
10215 \begin_layout Standard
10225 \begin_inset LatexCommand \index{-\/-no-peep-comments}
10231 Don't include peep-hole comments in the generated asm files even if -
10237 \begin_layout Standard
10248 -fverbose-asm option is specified.
10252 \labelwidthstring 00.00.0000
10259 \begin_layout Standard
10269 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10275 Include i-codes in the asm file.
10276 Sounds like noise but is most helpful for debugging the compiler itself.
10280 \labelwidthstring 00.00.0000
10287 \begin_layout Standard
10297 \begin_inset LatexCommand \index{pedantic}
10302 \begin_inset LatexCommand \index{-\/-less-pedantic}
10309 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10313 Disable some of the more pedantic warnings
10314 \begin_inset LatexCommand \index{Warnings}
10319 For more details, see the less_pedantic pragma
10320 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10328 \labelwidthstring 00.00.0000
10335 \begin_layout Standard
10344 -disable-warning\InsetSpace ~
10346 \begin_inset LatexCommand \index{-\/-disable-warning}
10352 Disable specific warning with number <nnnn>.
10356 \labelwidthstring 00.00.0000
10363 \begin_layout Standard
10373 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10379 Display the directories in the compiler's search path
10383 \labelwidthstring 00.00.0000
10390 \begin_layout Standard
10400 \begin_inset LatexCommand \index{-\/-vc}
10406 Display errors and warnings using MSVC style, so you can use SDCC with
10407 the visual studio IDE
10408 \begin_inset LatexCommand \index{IDE}
10413 With SDCC both offering a GCC-like (the default) and a MSVC-like
10414 \begin_inset LatexCommand \index{MSVC output style}
10418 output style, integration into most programming editors should be straightforwa
10423 \labelwidthstring 00.00.0000
10430 \begin_layout Standard
10440 \begin_inset LatexCommand \index{-\/-use-stdout}
10446 Send errors and warnings to stdout instead of stderr.
10450 \labelwidthstring 00.00.0000
10454 asmOption[,asmOption]
10457 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10462 Pass the asmOption to the assembler
10463 \begin_inset LatexCommand \index{Options assembler}
10468 \begin_inset LatexCommand \index{Assembler options}
10473 See file sdcc/as/doc/asxhtm.html for assembler options.cd
10477 \labelwidthstring 00.00.0000
10484 \begin_layout Standard
10494 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10500 Generally follow the C89 standard, but allow SDCC features that conflict
10501 with the standard (default).
10505 \labelwidthstring 00.00.0000
10512 \begin_layout Standard
10522 \begin_inset LatexCommand \index{-\/-std-c89}
10528 Follow the C89 standard and disable SDCC features that conflict with the
10533 \labelwidthstring 00.00.0000
10540 \begin_layout Standard
10550 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10556 Generally follow the C99 standard, but allow SDCC features that conflict
10557 with the standard (incomplete support).
10561 \labelwidthstring 00.00.0000
10568 \begin_layout Standard
10578 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10584 Follow the C99 standard and disable SDCC features that conflict with the
10585 standard (incomplete support).
10589 \labelwidthstring 00.00.0000
10596 \begin_layout Standard
10608 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10613 <Name> The name to be used for the code
10614 \begin_inset LatexCommand \index{code}
10618 segment, default CSEG.
10619 This is useful if you need to tell the compiler to put the code in a special
10620 segment so you can later on tell the linker to put this segment in a special
10622 Can be used for instance when using bank switching to put the code in a
10627 \labelwidthstring 00.00.0000
10634 \begin_layout Standard
10646 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10651 <Name> The name to be used for the const
10652 \begin_inset LatexCommand \index{const}
10656 segment, default CONST.
10657 This is useful if you need to tell the compiler to put the const data in
10658 a special segment so you can later on tell the linker to put this segment
10659 in a special place in memory.
10660 Can be used for instance when using bank switching to put the const data
10665 \labelwidthstring 00.00.0000
10672 \begin_layout Standard
10681 -fdollars-in-identifiers
10682 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10688 Permit '$' as an identifier character.
10692 \labelwidthstring 00.00.0000
10699 \begin_layout Standard
10711 \begin_inset LatexCommand \index{-\/-more-pedantic}
10716 \begin_inset LatexCommand \index{pedantic}
10726 a SDCC compiler option but if you want
10730 warnings you can use a separate tool dedicated to syntax checking like
10732 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10737 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10742 \begin_inset LatexCommand \url{http://www.splint.org}
10747 To make your source files parseable by splint you will have to include
10753 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10757 in your source file and add brackets around extended keywords (like
10760 \begin_inset Quotes sld
10773 \begin_inset Quotes srd
10781 \begin_inset Quotes sld
10784 __interrupt\InsetSpace ~
10786 \begin_inset Quotes srd
10794 Splint has an excellent on line manual at
10795 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10799 and it's capabilities go beyond pure syntax checking.
10800 You'll need to tell splint the location of SDCC's include files so a typical
10801 command line could look like this:
10805 splint\InsetSpace ~
10807 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10813 \labelwidthstring 00.00.0000
10820 \begin_layout Standard
10832 \begin_inset LatexCommand \index{-\/-short-is-8bits}
10837 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
10841 Treat short as 8-bit (for backward compatibility with older versions of
10842 compiler - see section
10843 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
10850 \begin_layout Standard
10851 \begin_inset VSpace bigskip
10857 \begin_layout Subsection
10858 Intermediate Dump Options
10859 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
10864 \begin_inset LatexCommand \index{Options intermediate dump}
10869 \begin_inset LatexCommand \index{Intermediate dump options}
10876 \begin_layout Standard
10877 The following options are provided for the purpose of retargetting and debugging
10879 They provide a means to dump the intermediate code (iCode
10880 \begin_inset LatexCommand \index{iCode}
10884 ) generated by the compiler in human readable form at various stages of
10885 the compilation process.
10886 More on iCodes see chapter
10887 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10892 \begin_inset Quotes srd
10895 The anatomy of the compiler
10896 \begin_inset Quotes srd
10903 \labelwidthstring 00.00.0000
10910 \begin_layout Standard
10920 \begin_inset LatexCommand \index{-\/-dumpraw}
10926 This option will cause the compiler to dump the intermediate code into
10929 <source filename>.dumpraw
10931 just after the intermediate code has been generated for a function, i.e.
10932 before any optimizations are done.
10934 \begin_inset LatexCommand \index{Basic blocks}
10938 at this stage ordered in the depth first number, so they may not be in
10939 sequence of execution.
10943 \labelwidthstring 00.00.0000
10950 \begin_layout Standard
10960 \begin_inset LatexCommand \index{-\/-dumpgcse}
10966 Will create a dump of iCodes, after global subexpression elimination
10967 \begin_inset LatexCommand \index{Global subexpression elimination}
10971 , into a file named
10973 <source filename>.dumpgcse.
10977 \labelwidthstring 00.00.0000
10984 \begin_layout Standard
10994 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
11000 Will create a dump of iCodes, after deadcode elimination
11001 \begin_inset LatexCommand \index{Dead-code elimination}
11005 , into a file named
11007 <source filename>.dumpdeadcode.
11011 \labelwidthstring 00.00.0000
11018 \begin_layout Standard
11028 \begin_inset LatexCommand \index{-\/-dumploop}
11037 Will create a dump of iCodes, after loop optimizations
11038 \begin_inset LatexCommand \index{Loop optimization}
11042 , into a file named
11044 <source filename>.dumploop.
11048 \labelwidthstring 00.00.0000
11055 \begin_layout Standard
11065 \begin_inset LatexCommand \index{-\/-dumprange}
11074 Will create a dump of iCodes, after live range analysis
11075 \begin_inset LatexCommand \index{Live range analysis}
11079 , into a file named
11081 <source filename>.dumprange.
11085 \labelwidthstring 00.00.0000
11092 \begin_layout Standard
11102 \begin_inset LatexCommand \index{-\/-dumlrange}
11108 Will dump the life ranges
11109 \begin_inset LatexCommand \index{Live range analysis}
11117 \labelwidthstring 00.00.0000
11124 \begin_layout Standard
11134 \begin_inset LatexCommand \index{-\/-dumpregassign}
11143 Will create a dump of iCodes, after register assignment
11144 \begin_inset LatexCommand \index{Register assignment}
11148 , into a file named
11150 <source filename>.dumprassgn.
11154 \labelwidthstring 00.00.0000
11161 \begin_layout Standard
11171 \begin_inset LatexCommand \index{-\/-dumplrange}
11177 Will create a dump of the live ranges of iTemp's
11181 \labelwidthstring 00.00.0000
11188 \begin_layout Standard
11198 \begin_inset LatexCommand \index{-\/-dumpall}
11209 Will cause all the above mentioned dumps to be created.
11212 \begin_layout Standard
11213 \begin_inset VSpace bigskip
11219 \begin_layout Subsection
11220 Redirecting output on Windows Shells
11223 \begin_layout Standard
11224 By default SDCC writes its error messages to
11225 \begin_inset Quotes sld
11229 \begin_inset Quotes srd
11233 To force all messages to
11234 \begin_inset Quotes sld
11238 \begin_inset Quotes srd
11250 \begin_layout Standard
11265 \begin_inset LatexCommand \index{-\/-use-stdout}
11270 Additionally, if you happen to have visual studio installed in your windows
11271 machine, you can use it to compile your sources using a custom build and
11278 \begin_layout Standard
11290 \begin_inset LatexCommand \index{-\/-vc}
11295 Something like this should work:
11314 \begin_layout Standard
11333 \begin_layout Standard
11345 -model-large -c $(InputPath)
11348 \begin_inset VSpace bigskip
11354 \begin_layout Section
11355 Environment variables
11356 \begin_inset LatexCommand \index{Environment variables}
11363 \begin_layout Standard
11364 SDCC recognizes the following environment variables:
11368 \labelwidthstring 00.00.0000
11372 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11378 SDCC installs a signal handler
11379 \begin_inset LatexCommand \index{signal handler}
11383 to be able to delete temporary files after an user break (^C) or an exception.
11384 If this environment variable is set, SDCC won't install the signal handler
11385 in order to be able to debug SDCC.
11389 \labelwidthstring 00.00.0000
11395 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11401 Path, where temporary files will be created.
11402 The order of the variables is the search order.
11403 In a standard *nix environment these variables are not set, and there's
11404 no need to set them.
11405 On Windows it's recommended to set one of them.
11409 \labelwidthstring 00.00.0000
11413 \begin_inset LatexCommand \index{SDCC\_HOME}
11420 \begin_inset LatexCommand \ref{sub:Install-paths}
11426 \begin_inset Quotes sld
11430 \begin_inset Quotes srd
11437 \labelwidthstring 00.00.0000
11441 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11448 \begin_inset LatexCommand \ref{sub:Search-Paths}
11454 \begin_inset Quotes sld
11458 \begin_inset Quotes srd
11465 \labelwidthstring 00.00.0000
11469 \begin_inset LatexCommand \index{SDCC\_LIB}
11476 \begin_inset LatexCommand \ref{sub:Search-Paths}
11482 \begin_inset Quotes sld
11486 \begin_inset Quotes srd
11492 \begin_layout Standard
11493 There are some more environment variables recognized by SDCC, but these
11494 are solely used for debugging purposes.
11495 They can change or disappear very quickly, and will never be documented.
11496 \begin_inset VSpace bigskip
11502 \begin_layout Section
11503 Storage Class Language Extensions
11506 \begin_layout Subsection
11507 MCS51/DS390 Storage Class
11508 \begin_inset LatexCommand \index{Storage class}
11512 Language Extensions
11515 \begin_layout Standard
11516 In addition to the ANSI storage classes SDCC allows the following MCS51
11517 specific storage classes:
11520 \begin_layout Subsubsection
11522 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11527 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11532 \begin_inset LatexCommand \index{near (storage class)}
11537 \begin_inset LatexCommand \index{\_\_near (storage class)}
11544 \begin_layout Standard
11549 storage class for the Small Memory model (
11557 or the more ANSI-C compliant forms
11565 can be used synonymously).
11566 Variables declared with this storage class will be allocated in the directly
11567 addressable portion of the internal RAM of a 8051, e.g.:
11570 \begin_layout Verse
11573 __data unsigned char test_data;
11576 \begin_layout Standard
11577 Writing 0x01 to this variable generates the assembly code:
11580 \begin_layout Verse
11583 75*00 01\InsetSpace ~
11591 \begin_layout Subsubsection
11593 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11598 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11603 \begin_inset LatexCommand \index{far (storage class)}
11608 \begin_inset LatexCommand \index{\_\_far (storage class)}
11615 \begin_layout Standard
11616 Variables declared with this storage class will be placed in the external
11622 storage class for the Large Memory model, e.g.:
11625 \begin_layout Verse
11628 __xdata unsigned char test_xdata;
11631 \begin_layout Standard
11632 Writing 0x01 to this variable generates the assembly code:
11635 \begin_layout Verse
11638 90s00r00\InsetSpace ~
11669 \begin_layout Subsubsection
11671 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11676 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11683 \begin_layout Standard
11684 Variables declared with this storage class will be allocated into the indirectly
11685 addressable portion of the internal ram of a 8051, e.g.:
11688 \begin_layout Verse
11691 __idata unsigned char test_idata;
11694 \begin_layout Standard
11695 Writing 0x01 to this variable generates the assembly code:
11698 \begin_layout Verse
11725 \begin_layout Standard
11726 Please note, the first 128 byte of idata physically access the same RAM
11727 as the data memory.
11728 The original 8051 had 128 byte idata memory, nowadays most devices have
11729 256 byte idata memory.
11731 \begin_inset LatexCommand \index{stack}
11735 is located in idata memory.
11738 \begin_layout Subsubsection
11740 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11745 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11752 \begin_layout Standard
11753 Paged xdata access is just as straightforward as using the other addressing
11755 It is typically located at the start of xdata and has a maximum size of
11757 The following example writes 0x01 to the pdata variable.
11758 Please note, pdata access physically accesses xdata memory.
11759 The high byte of the address is determined by port P2
11760 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11764 (or in case of some 8051 variants by a separate Special Function Register,
11766 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11775 storage class for the Medium Memory model, e.g.:
11778 \begin_layout Verse
11781 __pdata unsigned char test_pdata;
11784 \begin_layout Standard
11785 Writing 0x01 to this variable generates the assembly code:
11788 \begin_layout Verse
11797 mov r0,#_test_pdata
11819 \begin_layout Standard
11824 \begin_layout Standard
11834 \begin_inset LatexCommand \index{-\/-xstack}
11838 option is used the pdata memory area is followed by the xstack memory area
11839 and the sum of their sizes is limited to 256 bytes.
11842 \begin_layout Subsubsection
11844 \begin_inset LatexCommand \index{code}
11849 \begin_inset LatexCommand \index{\_\_code}
11856 \begin_layout Standard
11857 'Variables' declared with this storage class will be placed in the code
11861 \begin_layout Verse
11864 __code unsigned char test_code;
11867 \begin_layout Standard
11868 Read access to this variable generates the assembly code:
11871 \begin_layout Verse
11874 90s00r6F\InsetSpace ~
11877 mov dptr,#_test_code
11902 \begin_layout Standard
11907 indexed arrays of characters in code memory can be accessed efficiently:
11910 \begin_layout Verse
11913 __code char test_array[] = {'c','h','e','a','p'};
11916 \begin_layout Standard
11917 Read access to this array using an 8-bit unsigned index generates the assembly
11921 \begin_layout Verse
11933 \begin_layout Verse
11936 90s00r41\InsetSpace ~
11939 mov dptr,#_test_array
11942 \begin_layout Verse
11957 \begin_layout Subsubsection
11959 \begin_inset LatexCommand \index{bit}
11964 \begin_inset LatexCommand \index{\_\_bit}
11971 \begin_layout Standard
11972 This is a data-type and a storage class specifier.
11973 When a variable is declared as a bit, it is allocated into the bit addressable
11974 memory of 8051, e.g.:
11977 \begin_layout Verse
11983 \begin_layout Standard
11984 Writing 1 to this variable generates the assembly code:
11987 \begin_layout Verse
12001 \begin_layout Standard
12002 The bit addressable memory consists of 128 bits which are located from 0x20
12003 to 0x2f in data memory.
12006 Apart from this 8051 specific storage class most architectures support
12008 \begin_inset LatexCommand \index{bitfields}
12016 \begin_layout Standard
12017 Not really meant as examples, but nevertheless showing what bitfields are
12018 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12024 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12025 signed modifier are implemented as unsigned.
12028 \begin_layout Subsubsection
12030 \begin_inset LatexCommand \index{sfr}
12035 \begin_inset LatexCommand \index{\_\_sfr}
12040 \begin_inset LatexCommand \index{sfr16}
12045 \begin_inset LatexCommand \index{\_\_sfr16}
12050 \begin_inset LatexCommand \index{sfr32}
12055 \begin_inset LatexCommand \index{\_\_sfr32}
12060 \begin_inset LatexCommand \index{\_\_sbit}
12065 \begin_inset LatexCommand \index{sbit}
12072 \begin_layout Standard
12073 Like the bit keyword,
12075 sfr / sfr16 / sfr32 / sbit
12077 signify both a data-type and storage class, they are used to describe the
12098 variables of a 8051, eg:
12101 \begin_layout Verse
12105 \begin_inset LatexCommand \index{at}
12110 \begin_inset LatexCommand \index{\_\_at}
12114 (0x80) P0;\InsetSpace ~
12115 /* special function register P0 at location 0x80 */
12120 special function register combination for timer 0
12124 with the high byte at
12125 location 0x8C and the low byte at location 0x8A */
12127 __sfr16 __at (0x8C8A)
12133 \begin_inset LatexCommand \index{at}
12138 \begin_inset LatexCommand \index{\_\_at}
12142 (0xd7) CY;\InsetSpace ~
12144 \begin_inset LatexCommand \index{Flags}
12149 \begin_inset LatexCommand \index{Carry flag}
12156 \begin_layout Standard
12157 Special function registers which are located on an address dividable by
12158 8 are bit-addressable, an
12162 addresses a specific bit within these sfr.
12164 16 Bit and 32 bit special function
12165 register combinations which require a certain access order are better not
12175 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12176 this is not guaranteed.
12181 \begin_layout Standard
12182 Please note, if you use a header file which was written for another compiler
12183 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
12189 Specifically the syntax
12192 sfr P0 = 0x80;\InsetSpace ~
12199 by SDCC to an assignment of 0x80 to a variable called P0
12202 \begin_inset Marginal
12205 \begin_layout Standard
12217 Nevertheless it is possible to write header files
12218 \begin_inset LatexCommand \index{Header files}
12223 \begin_inset LatexCommand \index{Include files}
12227 which can be shared among different compilers (see section
12228 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
12236 \begin_layout Subsubsection
12238 \begin_inset LatexCommand \index{Pointer}
12242 to MCS51/DS390 specific memory spaces
12245 \begin_layout Standard
12246 SDCC allows (via language extensions) pointers to explicitly point to any
12247 of the memory spaces
12248 \begin_inset LatexCommand \index{Memory model}
12253 In addition to the explicit pointers, the compiler uses (by default) generic
12254 pointers which can be used to point to any of the memory spaces.
12259 declaration examples:
12262 \begin_layout Verse
12265 /* pointer physically in internal ram pointing to object in external ram
12268 __xdata unsigned char * __data p;
12272 /* pointer physically in external ram
12273 pointing to object in internal ram */
12275 __data unsigned char * __xdata p;
12280 pointer physically in code rom pointing to data in xdata space */
12283 unsigned char * __code p;
12287 /* pointer physically in code space pointing to
12288 data in code space */
12290 __code unsigned char * __code p;
12295 physically located in xdata space */
12297 unsigned char * __xdata p;
12302 pointer physically located in default memory space */
12309 the following is a function pointer
12310 \begin_inset LatexCommand \index{function pointer}
12314 physically located in data space */
12316 char (* __data fp)(void);
12319 \begin_layout Standard
12320 Well you get the idea.
12325 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
12338 The highest order byte of the
12342 pointers contains the data space information.
12343 Assembler support routines are called whenever data is stored or retrieved
12349 These are useful for developing reusable library
12350 \begin_inset LatexCommand \index{Libraries}
12355 Explicitly specifying the pointer
12356 \begin_inset LatexCommand \index{pointer}
12360 type will generate the most efficient code.
12363 \begin_layout Subsubsection
12364 Notes on MCS51 memory
12365 \begin_inset LatexCommand \index{MCS51 memory}
12372 \begin_layout Standard
12373 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12374 RAM memory which is structured as follows:
12378 - Bytes 00-1F - 32 bytes to hold
12379 up to 4 banks of the registers R0 to R7,
12381 - Bytes 20-2F - 16 bytes to hold
12383 \begin_inset LatexCommand \index{bit}
12389 - Bytes 30-7F - 80 bytes for general purpose use.
12394 \begin_layout Standard
12395 Additionally some members of the MCS51 family may have up to 128 bytes of
12396 additional, indirectly addressable, internal RAM memory (
12401 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12406 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12411 Furthermore, some chips may have some built in external memory (
12416 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12421 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12425 ) which should not be confused with the internal, directly addressable RAM
12431 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12436 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12441 Sometimes this built in
12445 memory has to be activated before using it (you can probably find this
12446 information on the datasheet of the microcontroller your are using, see
12448 \begin_inset LatexCommand \ref{sub:Startup-Code}
12456 \begin_layout Standard
12457 Normally SDCC will only use the first bank
12458 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12462 of registers (register bank 0), but it is possible to specify that other
12463 banks of registers (keyword
12470 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12475 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12481 ) should be used for example in interrupt
12482 \begin_inset LatexCommand \index{interrupt}
12487 \begin_inset LatexCommand \index{\_\_interrupt}
12492 By default, the compiler will place the stack after the last byte of allocated
12493 memory for variables.
12494 For example, if the first 2 banks of registers are used, and only four
12499 variables, it will position the base of the internal stack at address 20
12501 This implies that as the stack
12502 \begin_inset LatexCommand \index{stack}
12506 grows, it will use up the remaining register banks, and the 16 bytes used
12507 by the 128 bit variables, and 80 bytes for general purpose use.
12508 If any bit variables are used, the data variables will be placed in unused
12509 register banks and after the byte holding the last bit variable.
12510 For example, if register banks 0 and 1 are used, and there are 9 bit variables
12515 variables will be placed starting from address 0x10 to 0x20 and continue
12521 \begin_layout Standard
12531 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12535 to specify the start address of the
12543 \begin_layout Standard
12553 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12557 to specify the size of the total internal RAM (
12571 \begin_layout Standard
12572 By default the 8051 linker will place the stack after the last byte of (i)data
12578 \begin_layout Standard
12588 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12592 allows you to specify the start of the stack, i.e.
12593 you could start it after any data in the general purpose area.
12594 If your microcontroller has additional indirectly addressable internal
12599 ) you can place the stack on it.
12600 You may also need to use -
12604 \begin_layout Standard
12614 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12618 to set the start address of the external RAM (
12626 \begin_layout Standard
12636 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12640 to specify its size.
12641 Same goes for the code memory, using -
12645 \begin_layout Standard
12655 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12663 \begin_layout Standard
12673 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12678 If in doubt, don't specify any options and see if the resulting memory
12679 layout is appropriate, then you can adjust it.
12682 \begin_layout Standard
12683 The linker generates two files with memory allocation information.
12684 The first, with extension .map
12685 \begin_inset LatexCommand \index{<file>.map}
12689 shows all the variables and segments.
12690 The second with extension .mem
12691 \begin_inset LatexCommand \index{<file>.mem}
12695 shows the final memory layout.
12696 The linker will complain either if memory segments overlap, there is not
12697 enough memory, or there is not enough space for stack.
12698 If you get any linking warnings and/or errors related to stack or segments
12699 allocation, take a look at either the .map or .mem files to find out what
12701 The .mem file may even suggest a solution to the problem.
12702 \begin_inset VSpace bigskip
12708 \begin_layout Subsection
12709 Z80/Z180 Storage Class
12710 \begin_inset LatexCommand \index{Z80!Storage class}
12714 Language Extensions
12717 \begin_layout Subsubsection
12719 \begin_inset LatexCommand \index{sfr}
12724 \begin_inset LatexCommand \index{\_\_sfr}
12728 (in/out to 8-bit addresses)
12731 \begin_layout Standard
12733 \begin_inset LatexCommand \index{Z80}
12737 family has separate address spaces for memory and
12747 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12752 \begin_inset LatexCommand \index{Z80!I/O memory}
12757 \begin_inset LatexCommand \index{Z180!I/O memory}
12761 is accessed with special instructions, e.g.:
12764 \begin_layout Verse
12767 sfr at 0x78 IoPort;\InsetSpace ~
12769 /* define a var in I/O space at 78h called IoPort */
12773 \begin_layout Standard
12774 Writing 0x01 to this variable generates the assembly code:
12777 \begin_layout Verse
12797 \begin_layout Subsubsection
12799 \begin_inset LatexCommand \index{sfr}
12804 \begin_inset LatexCommand \index{\_\_sfr}
12808 (in/out to 16-bit addresses)
12811 \begin_layout Standard
12816 is used to support 16 bit addresses in I/O memory e.g.:
12819 \begin_layout Verse
12823 \begin_inset LatexCommand \index{at}
12828 \begin_inset LatexCommand \index{\_\_at}
12835 \begin_layout Standard
12836 Writing 0x01 to this variable generates the assembly code:
12839 \begin_layout Verse
12842 01 23 01\InsetSpace ~
12864 \begin_layout Subsubsection
12866 \begin_inset LatexCommand \index{sfr}
12871 \begin_inset LatexCommand \index{\_\_sfr}
12875 (in0/out0 to 8 bit addresses on Z180
12876 \begin_inset LatexCommand \index{Z180}
12881 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12888 \begin_layout Standard
12889 The compiler option -
12893 \begin_layout Standard
12903 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
12907 =180 (80) and a compiler #pragma\InsetSpace ~
12909 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
12913 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12923 If you include the file z180.h this will be set automatically.
12924 \begin_inset VSpace bigskip
12930 \begin_layout Subsection
12932 \begin_inset LatexCommand \index{HC08!Storage class}
12936 Language Extensions
12939 \begin_layout Subsubsection
12941 \begin_inset LatexCommand \index{data (hc08 storage class)}
12946 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
12953 \begin_layout Standard
12954 The data storage class declares a variable that resides in the first 256
12955 bytes of memory (the direct page).
12957 \begin_inset LatexCommand \index{HC08}
12961 is most efficient at accessing variables (especially pointers) stored here.
12964 \begin_layout Subsubsection
12966 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
12971 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
12978 \begin_layout Standard
12979 The xdata storage class declares a variable that can reside anywhere in
12981 This is the default if no storage class is specified.
12983 \begin_inset VSpace bigskip
12989 \begin_layout Section
12990 Absolute Addressing
12991 \begin_inset LatexCommand \index{Absolute addressing}
12998 \begin_layout Standard
12999 Data items can be assigned an absolute address with the
13002 \begin_inset LatexCommand \index{at}
13007 \begin_inset LatexCommand \index{\_\_at}
13013 keyword, in addition to a storage class, e.g.:
13016 \begin_layout Verse
13020 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13025 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
13030 \begin_inset LatexCommand \index{at}
13035 \begin_inset LatexCommand \index{\_\_at}
13039 0x7ffe unsigned int chksum;
13042 \begin_layout Standard
13043 or, better conforming to ISO/IEC 9899 C:
13046 \begin_layout Verse
13049 __xdata __at (0x7ffe) unsigned int chksum;
13052 \begin_layout Standard
13053 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
13054 of the external ram.
13059 reserve any space for variables declared in this way
13060 \begin_inset Marginal
13063 \begin_layout Standard
13072 (they are implemented with an equate in the assembler).
13073 Thus it is left to the programmer to make sure there are no overlaps with
13074 other variables that are declared without the absolute address.
13075 The assembler listing file (.lst
13076 \begin_inset LatexCommand \index{<file>.lst}
13080 ) and the linker output files (.rst
13081 \begin_inset LatexCommand \index{<file>.rst}
13086 \begin_inset LatexCommand \index{<file>.map}
13090 ) are good places to look for such overlaps.
13093 \begin_layout Standard
13094 If however you provide an initializer
13095 \begin_inset LatexCommand \index{Variable initialization}
13099 actual memory allocation will take place and overlaps will be detected
13104 \begin_layout Verse
13107 __code __at (0x7ff0) char Id[5] =
13108 \begin_inset Quotes sld
13112 \begin_inset Quotes srd
13118 \begin_layout Standard
13119 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
13123 \begin_layout Standard
13124 In case of memory mapped I/O devices the keyword
13128 has to be used to tell the compiler that accesses might not be removed:
13131 \begin_layout Verse
13135 \begin_inset LatexCommand \index{volatile}
13140 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13145 \begin_inset LatexCommand \index{at}
13149 (0x8000) unsigned char PORTA_8255;
13152 \begin_layout Standard
13153 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
13158 \begin_inset LatexCommand \index{Aligned array}
13165 starts at a block (256 byte) boundary
13166 \begin_inset LatexCommand \index{block boundary}
13171 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13177 Absolute addresses can be specified for variables in all
13178 storage classes, e.g.:
13181 \begin_layout Verse
13185 \begin_inset LatexCommand \index{bit}
13190 \begin_inset LatexCommand \index{at}
13197 \begin_layout Standard
13198 The above example will allocate the variable at offset 0x02 in the bit-addressab
13200 There is no real advantage to assigning absolute addresses to variables
13201 in this manner, unless you want strict control over all the variables allocated.
13202 One possible use would be to write hardware portable code.
13203 For example, if you have a routine that uses one or more of the microcontroller
13204 I/O pins, and such pins are different for two different hardwares, you
13205 can declare the I/O pins in your routine using:
13208 \begin_layout Verse
13212 \begin_inset LatexCommand \index{volatile}
13216 __bit MOSI;\InsetSpace ~
13220 /* master out, slave in */
13222 extern volatile __bit MISO;\InsetSpace ~
13229 extern volatile __bit MCLK;\InsetSpace ~
13238 Output of a byte on a 3-wire serial bus.
13243 If needed adapt polarity of clock,
13244 polarity of data and bit order
13249 unsigned char spi_io(unsigned char out_byte)
13274 MOSI = out_byte & 0x80;
13305 /* _asm nop _endasm; */\InsetSpace ~
13313 /* for slow peripherals */
13365 \begin_layout Standard
13366 Then, someplace in the code for the first hardware you would use
13369 \begin_layout Verse
13373 \begin_inset LatexCommand \index{at}
13378 \begin_inset LatexCommand \index{\_\_at}
13382 (0x80) MOSI;\InsetSpace ~
13386 /* I/O port 0, bit 0 */
13388 __bit __at (0x81) MISO;\InsetSpace ~
13395 __bit __at (0x82) MCLK;\InsetSpace ~
13399 /* I/O port 0, bit 2 */
13402 \begin_layout Standard
13403 Similarly, for the second hardware you would use
13406 \begin_layout Verse
13409 __bit __at (0x83) MOSI;\InsetSpace ~
13413 /* I/O port 0, bit 3 */
13415 __bit __at (0x91) MISO;\InsetSpace ~
13420 I/O port 1, bit 1 */
13423 \begin_inset LatexCommand \index{bit}
13427 __at (0x92) MCLK;\InsetSpace ~
13431 /* I/O port 1, bit 2 */
13434 \begin_layout Standard
13435 and you can use the same hardware dependent routine without changes, as
13436 for example in a library.
13437 This is somehow similar to sbit, but only one absolute address has to be
13438 specified in the whole project.
13439 \begin_inset VSpace bigskip
13445 \begin_layout Section
13447 \begin_inset LatexCommand \index{Parameters}
13452 \begin_inset LatexCommand \index{function parameter}
13457 \begin_inset LatexCommand \index{local variables}
13462 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13469 \begin_layout Standard
13470 Automatic (local) variables and parameters to functions can either be placed
13471 on the stack or in data-space.
13472 The default action of the compiler is to place these variables in the internal
13473 RAM (for small model) or external RAM (for medium or large model).
13474 This in fact makes them similar to
13477 \begin_inset LatexCommand \index{static}
13483 so by default functions are non-reentrant
13484 \begin_inset LatexCommand \index{reentrant}
13493 They can be placed on the stack
13494 \begin_inset LatexCommand \index{stack}
13504 \begin_layout Standard
13514 \begin_inset LatexCommand \index{-\/-stack-auto}
13522 #pragma\InsetSpace ~
13526 \begin_inset LatexCommand \index{\#pragma stackauto}
13533 \begin_inset LatexCommand \index{reentrant}
13539 keyword in the function declaration, e.g.:
13542 \begin_layout Verse
13545 unsigned char foo(char i) __reentrant
13559 \begin_layout Standard
13560 Since stack space on 8051 is limited, the
13570 \begin_layout Standard
13581 option should be used sparingly.
13582 Note that the reentrant keyword just means that the parameters & local
13583 variables will be allocated to the stack, it
13587 mean that the function is register bank
13588 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13597 \begin_inset LatexCommand \index{local variables}
13601 can be assigned storage classes and absolute
13602 \begin_inset LatexCommand \index{Absolute addressing}
13609 \begin_layout Verse
13612 unsigned char foo()
13620 __xdata unsigned char i;
13633 \begin_inset LatexCommand \index{at}
13637 (0x31) unsigned char j;
13649 \begin_layout Standard
13650 In the above example the variable
13654 will be allocated in the external ram,
13658 in bit addressable space and
13669 \begin_layout Standard
13680 or when a function is declared as
13684 this should only be done for static variables.
13687 \begin_layout Standard
13689 \begin_inset LatexCommand \index{function parameter}
13693 however are not allowed any storage class
13694 \begin_inset LatexCommand \index{Storage class}
13698 , (storage classes for parameters will be ignored), their allocation is
13699 governed by the memory model in use, and the reentrancy options.
13702 \begin_layout Standard
13703 It is however allowed to use bit parameters in reentrant functions and also
13704 non-static local bit variables are supported.
13705 Efficient use is limited to 8 semi-bitregisters in bit space.
13706 They are pushed and popped to stack
13707 \begin_inset LatexCommand \index{stack}
13711 as a single byte just like the normal registers.
13714 \begin_layout Section
13716 \begin_inset LatexCommand \label{sub:Overlaying}
13721 \begin_inset LatexCommand \index{Overlaying}
13728 \begin_layout Standard
13730 \begin_inset LatexCommand \index{reentrant}
13734 functions SDCC will try to reduce internal ram space usage by overlaying
13735 parameters and local variables of a function (if possible).
13736 Parameters and local variables
13737 \begin_inset LatexCommand \index{local variables}
13741 of a function will be allocated to an overlayable segment if the function
13744 no other function calls and the function is non-reentrant and the memory
13746 \begin_inset LatexCommand \index{Memory model}
13753 If an explicit storage class
13754 \begin_inset LatexCommand \index{Storage class}
13758 is specified for a local variable, it will NOT be overlayed.
13761 \begin_layout Standard
13762 Note that the compiler (not the linkage editor) makes the decision for overlayin
13764 Functions that are called from an interrupt service routine
13765 \begin_inset Marginal
13768 \begin_layout Standard
13776 should be preceded by a #pragma\InsetSpace ~
13778 \begin_inset LatexCommand \index{\#pragma nooverlay}
13782 if they are not reentrant.
13785 \begin_layout Standard
13786 Also note that the compiler does not do any processing of inline assembler
13787 code, so the compiler might incorrectly assign local variables and parameters
13788 of a function into the overlay segment if the inline assembler code calls
13789 other c-functions that might use the overlay.
13790 In that case the #pragma\InsetSpace ~
13791 nooverlay should be used.
13794 \begin_layout Standard
13795 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13797 \begin_inset LatexCommand \index{Multiplication}
13802 \begin_inset LatexCommand \index{Division}
13806 will NOT be overlayed since these are implemented using external functions,
13810 \begin_layout Verse
13816 \begin_inset LatexCommand \index{\#pragma nooverlay}
13822 void set_error(unsigned char errcd)
13839 some_isr () __interrupt
13840 \begin_inset LatexCommand \index{interrupt}
13870 \begin_layout Standard
13871 In the above example the parameter
13879 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13881 not present, this could cause unpredictable runtime behavior when called
13882 from an interrupt service routine.
13883 The #pragma\InsetSpace ~
13884 nooverlay ensures that the parameters and local variables for
13885 the function are NOT overlayed.
13886 \begin_inset VSpace bigskip
13892 \begin_layout Section
13893 Interrupt Service Routines
13894 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13901 \begin_layout Subsection
13902 General Information
13905 \begin_layout Standard
13918 outines to be coded in C, with some extended keywords.
13921 \begin_layout Verse
13924 void timer_isr (void) __interrupt (1) __using (1)
13938 \begin_layout Standard
13939 The optional number following the
13942 \begin_inset LatexCommand \index{interrupt}
13947 \begin_inset LatexCommand \index{\_\_interrupt}
13953 keyword is the interrupt number this routine will service.
13954 When present, the compiler will insert a call to this routine in the interrupt
13956 \begin_inset LatexCommand \index{interrupt vector table}
13960 for the interrupt number specified.
13961 If you have multiple source files in your project, interrupt service routines
13962 can be present in any of them, but a prototype of the isr MUST be present
13963 or included in the file that contains the function
13968 The optional (8051 specific) keyword
13971 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13976 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13982 can be used to tell the compiler to use the specified register bank when
13983 generating code for this function.
13986 Interrupt service routines open the door for some very interesting bugs:
13989 \begin_layout Subsubsection
13990 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
13994 Common interrupt pitfall: variable not declared
13999 \begin_layout Standard
14000 If an interrupt service routine changes variables which are accessed by
14001 other functions these variables have to be declared
14006 \begin_inset LatexCommand \index{volatile}
14012 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
14019 \begin_layout Subsubsection
14020 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
14024 Common interrupt pitfall:
14029 \begin_layout Standard
14030 If the access to these variables is not
14033 \begin_inset LatexCommand \index{atomic}
14040 the processor needs more than one instruction for the access and could
14041 be interrupted while accessing the variable) the interrupt must be disabled
14042 during the access to avoid inconsistent data.
14045 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
14046 and should be protected by disabling interrupts.
14047 You're not automatically on the safe side if you use 8 bit variables though.
14048 We need an example here: f.e.
14049 on the 8051 the harmless looking
14050 \begin_inset Quotes srd
14060 \begin_inset Quotes sld
14069 \begin_inset Quotes srd
14079 \begin_inset Quotes sld
14082 from within an interrupt routine might get lost if the interrupt occurs
14085 \begin_inset Quotes sld
14090 counter\InsetSpace ~
14095 \begin_inset Quotes srd
14098 is not atomic on the 8051 even if
14102 is located in data memory.
14104 Bugs like these are hard to reproduce and can
14105 cause a lot of trouble.
14109 \begin_layout Subsubsection
14110 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
14114 Common interrupt pitfall:
14119 \begin_layout Standard
14120 The return address and the registers used in the interrupt service routine
14121 are saved on the stack
14122 \begin_inset LatexCommand \index{stack}
14126 so there must be sufficient stack space.
14127 If there isn't variables or registers (or even the return address itself)
14134 \begin_inset LatexCommand \index{stack overflow}
14138 is most likely to happen if the interrupt occurs during the
14139 \begin_inset Quotes sld
14143 \begin_inset Quotes srd
14146 subroutine when the stack is already in use for f.e.
14147 many return addresses.
14150 \begin_layout Subsubsection
14151 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
14155 Common interrupt pitfall:
14157 use of non-reentrant functions
14160 \begin_layout Standard
14161 A special note here, int (16 bit) and long (32 bit) integer division
14162 \begin_inset LatexCommand \index{Division}
14167 \begin_inset LatexCommand \index{Multiplication}
14172 \begin_inset LatexCommand \index{Modulus}
14177 \begin_inset LatexCommand \index{Floating point support}
14181 operations are implemented using external support routines.
14182 If an interrupt service routine needs to do any of these operations then
14183 the support routines (as mentioned in a following section) will have to
14184 be recompiled using the
14190 \begin_layout Standard
14200 \begin_inset LatexCommand \index{-\/-stack-auto}
14206 option and the source file will need to be compiled using the
14212 \begin_layout Standard
14224 \begin_inset LatexCommand \index{-\/-int-long-reent}
14231 Note, the type promotion
14232 \begin_inset LatexCommand \index{type promotion}
14236 required by ANSI C can cause 16 bit routines to be used
14237 \begin_inset Marginal
14240 \begin_layout Standard
14249 without the programmer being aware of it.
14253 (unsigned char)(tail-1)
14255 within the if clause in section
14256 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
14263 \begin_layout Standard
14264 Calling other functions from an interrupt service routine is not recommended,
14265 avoid it if possible.
14266 Note that when some function is called from an interrupt service routine
14267 it should be preceded by a #pragma\InsetSpace ~
14269 \begin_inset LatexCommand \index{\#pragma nooverlay}
14273 if it is not reentrant.
14274 Furthermore nonreentrant functions should not be called from the main program
14275 while the interrupt service routine might be active.
14276 They also must not be called from low priority interrupt service routines
14277 while a high priority interrupt service routine might be active.
14278 You could use semaphores or make the function
14282 if all parameters are passed in registers.
14285 \begin_inset LatexCommand \ref{sub:Overlaying}
14290 about Overlaying and section
14291 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14296 about Functions using private register banks.
14297 \begin_inset VSpace bigskip
14303 \begin_layout Subsection
14304 MCS51/DS390 Interrupt Service Routines
14307 \begin_layout Standard
14309 \begin_inset LatexCommand \index{interrupt}
14313 numbers and the corresponding address & descriptions for the Standard 8051/8052
14315 SDCC will automatically adjust the
14316 \begin_inset LatexCommand \index{interrupt vector table}
14320 to the maximum interrupt number specified.
14325 \begin_layout Standard
14327 \begin_inset Tabular
14328 <lyxtabular version="3" rows="9" columns="3">
14330 <column alignment="center" valignment="top" leftline="true" width="0in">
14331 <column alignment="left" valignment="top" leftline="true" width="0in">
14332 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14333 <row topline="true" bottomline="true">
14334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14337 \begin_layout Standard
14343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14346 \begin_layout Standard
14352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14355 \begin_layout Standard
14362 <row topline="true">
14363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14366 \begin_layout Standard
14372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14375 \begin_layout Standard
14381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14384 \begin_layout Standard
14391 <row topline="true">
14392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14395 \begin_layout Standard
14401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14404 \begin_layout Standard
14410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14413 \begin_layout Standard
14420 <row topline="true">
14421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14424 \begin_layout Standard
14430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14433 \begin_layout Standard
14439 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14442 \begin_layout Standard
14449 <row topline="true">
14450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14453 \begin_layout Standard
14459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14462 \begin_layout Standard
14468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14471 \begin_layout Standard
14478 <row topline="true">
14479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14482 \begin_layout Standard
14488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14491 \begin_layout Standard
14497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14500 \begin_layout Standard
14507 <row topline="true">
14508 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14511 \begin_layout Standard
14517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14520 \begin_layout Standard
14526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14529 \begin_layout Standard
14536 <row topline="true">
14537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14540 \begin_layout Standard
14546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14549 \begin_layout Standard
14555 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14558 \begin_layout Standard
14565 <row topline="true" bottomline="true">
14566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14569 \begin_layout Standard
14575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14578 \begin_layout Standard
14584 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14587 \begin_layout Standard
14603 \begin_layout Standard
14604 If the interrupt service routine is defined without
14607 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14612 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14618 a register bank or with register bank 0 (
14622 0), the compiler will save the registers used by itself on the stack upon
14623 entry and restore them at exit, however if such an interrupt service routine
14624 calls another function then the entire register bank will be saved on the
14626 This scheme may be advantageous for small interrupt service routines which
14627 have low register usage.
14630 \begin_layout Standard
14631 If the interrupt service routine is defined to be using a specific register
14636 & psw are saved and restored, if such an interrupt service routine calls
14637 another function (using another register bank) then the entire register
14638 bank of the called function will be saved on the stack
14639 \begin_inset LatexCommand \index{stack}
14644 This scheme is recommended for larger interrupt service routines.
14645 \begin_inset VSpace bigskip
14651 \begin_layout Subsection
14653 \begin_inset LatexCommand \index{HC08}
14657 Interrupt Service Routines
14660 \begin_layout Standard
14661 Since the number of interrupts
14662 \begin_inset LatexCommand \index{HC08!interrupt}
14666 available is chip specific and the interrupt vector table always ends at
14667 the last byte of memory, the interrupt numbers corresponds to the interrupt
14668 vectors in reverse order of address.
14669 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14670 2 will use the interrupt vector at 0xfffa, and so on.
14671 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14672 this way; instead see section
14673 \begin_inset LatexCommand \ref{sub:Startup-Code}
14677 for details on customizing startup.
14678 \begin_inset VSpace bigskip
14684 \begin_layout Subsection
14685 Z80 Interrupt Service Routines
14688 \begin_layout Standard
14690 \begin_inset LatexCommand \index{Z80}
14694 uses several different methods for determining the correct interrupt
14695 \begin_inset LatexCommand \index{Z80!interrupt}
14699 vector depending on the hardware implementation.
14700 Therefore, SDCC ignores the optional interrupt number and does not attempt
14701 to generate an interrupt vector table.
14704 \begin_layout Standard
14705 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14706 instruction to return from the interrupt.
14707 To write an interrupt handler for the non-maskable interrupt, which needs
14708 a RETN instruction instead, add the
14715 \begin_layout Verse
14718 void nmi_isr (void) critical interrupt
14732 \begin_layout Standard
14733 However if you need to create a non-interruptable interrupt service routine
14734 you would also require the
14739 To distinguish between this and an nmi_isr you must provide an interrupt
14741 \begin_inset VSpace bigskip
14747 \begin_layout Section
14748 Enabling and Disabling Interrupts
14751 \begin_layout Subsection
14752 Critical Functions and Critical Statements
14755 \begin_layout Standard
14756 A special keyword may be associated with a block or a function declaring
14762 SDCC will generate code to disable all interrupts
14763 \begin_inset LatexCommand \index{interrupt}
14767 upon entry to a critical function and restore the interrupt enable to the
14768 previous state before returning.
14769 Nesting critical functions will need one additional byte on the stack
14770 \begin_inset LatexCommand \index{stack}
14777 \begin_layout Verse
14780 int foo () __critical
14781 \begin_inset LatexCommand \index{critical}
14786 \begin_inset LatexCommand \index{\_\_critical}
14811 \begin_layout Standard
14812 The critical attribute maybe used with other attributes like
14822 may also be used to disable interrupts more locally:
14825 \begin_layout Verse
14831 \begin_layout Standard
14832 More than one statement could have been included in the block.
14835 \begin_layout Subsection
14836 Enabling and Disabling Interrupts directly
14839 \begin_layout Standard
14841 \begin_inset LatexCommand \index{interrupt}
14845 can also be disabled and enabled directly (8051):
14848 \begin_layout Verse
14851 EA = 0;\InsetSpace ~
14877 \begin_layout Verse
14913 \begin_layout Verse
14916 EA = 1;\InsetSpace ~
14945 \begin_layout Verse
14984 \begin_layout Standard
14985 On other architectures which have seperate opcodes for enabling and disabling
14986 interrupts you might want to make use of defines with inline assembly
14987 \begin_inset LatexCommand \index{Assembler routines}
14992 \begin_inset LatexCommand \index{HC08!interrupt}
14999 \begin_layout Verse
15003 \begin_inset LatexCommand \index{\_asm}
15012 \begin_inset LatexCommand \index{\_endasm}
15019 \begin_layout Verse
15022 #define SEI _asm\InsetSpace ~
15029 \begin_layout Verse
15035 \begin_layout Standard
15036 Note: it is sometimes sufficient to disable only a specific interrupt source
15038 a timer or serial interrupt by manipulating an
15041 \begin_inset LatexCommand \index{interrupt mask}
15051 \begin_layout Standard
15052 Usually the time during which interrupts are disabled should be kept as
15054 This minimizes both
15059 \begin_inset LatexCommand \index{interrupt latency}
15063 (the time between the occurrence of the interrupt and the execution of
15064 the first code in the interrupt routine) and
15069 \begin_inset LatexCommand \index{interrupt jitter}
15073 (the difference between the shortest and the longest interrupt latency).
15074 These really are something different, f.e.
15075 a serial interrupt has to be served before its buffer overruns so it cares
15076 for the maximum interrupt latency, whereas it does not care about jitter.
15077 On a loudspeaker driven via a digital to analog converter which is fed
15078 by an interrupt a latency of a few milliseconds might be tolerable, whereas
15079 a much smaller jitter will be very audible.
15082 \begin_layout Standard
15083 You can reenable interrupts within an interrupt routine and on some architecture
15084 s you can make use of two (or more) levels of
15086 interrupt priorities
15089 \begin_inset LatexCommand \index{interrupt priority}
15094 On some architectures which don't support interrupt priorities these can
15095 be implemented by manipulating the interrupt mask and reenabling interrupts
15096 within the interrupt routine.
15097 Check there is sufficient space on the stack
15098 \begin_inset LatexCommand \index{stack}
15102 and don't add complexity unless you have to.
15106 \begin_layout Subsection
15108 \begin_inset LatexCommand \index{semaphore}
15112 locking (mcs51/ds390)
15115 \begin_layout Standard
15116 Some architectures (mcs51/ds390) have an atomic
15117 \begin_inset LatexCommand \index{atomic}
15130 These type of instructions are typically used in preemptive multitasking
15131 systems, where a routine f.e.
15132 claims the use of a data structure ('acquires a lock
15133 \begin_inset LatexCommand \index{lock}
15137 on it'), makes some modifications and then releases the lock when the data
15138 structure is consistent again.
15139 The instruction may also be used if interrupt and non-interrupt code have
15140 to compete for a resource.
15141 With the atomic bit test and clear instruction interrupts
15142 \begin_inset LatexCommand \index{interrupt}
15146 don't have to be disabled for the locking operation.
15150 \begin_layout Standard
15151 SDCC generates this instruction if the source follows this pattern:
15154 \begin_layout Verse
15158 \begin_inset LatexCommand \index{volatile}
15162 bit resource_is_free;
15166 if (resource_is_free)
15176 resource_is_free=0;
15189 resource_is_free=1;
15196 \begin_layout Standard
15197 Note, mcs51 and ds390 support only an atomic
15198 \begin_inset LatexCommand \index{atomic}
15206 instruction (as opposed to atomic bit test and
15211 \begin_layout Section
15212 Functions using private register banks
15213 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
15220 \begin_layout Standard
15221 Some architectures have support for quickly changing register sets.
15222 SDCC supports this feature with the
15225 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
15230 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
15236 attribute (which tells the compiler to use a register bank
15237 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
15241 other than the default bank zero).
15242 It should only be applied to
15245 \begin_inset LatexCommand \index{interrupt}
15251 functions (see footnote below).
15252 This will in most circumstances make the generated ISR code more efficient
15253 since it will not have to save registers on the stack.
15256 \begin_layout Standard
15261 attribute will have no effect on the generated code for a
15265 function (but may occasionally be useful anyway
15269 \begin_layout Standard
15270 possible exception: if a function is called ONLY from 'interrupt' functions
15271 using a particular bank, it can be declared with the same 'using' attribute
15272 as the calling 'interrupt' functions.
15273 For instance, if you have several ISRs using bank one, and all of them
15274 call memcpy(), it might make sense to create a specialized version of memcpy()
15275 'using 1', since this would prevent the ISR from having to save bank zero
15276 to the stack on entry and switch to bank zero before calling the function
15285 (pending: Note, nowadays the
15289 attribute has an effect on
15293 the generated code for a
15304 \begin_layout Standard
15309 function using a non-zero bank will assume that it can trash that register
15310 bank, and will not save it.
15311 Since high-priority interrupts
15312 \begin_inset LatexCommand \index{interrupts}
15317 \begin_inset LatexCommand \index{interrupt priority}
15321 can interrupt low-priority ones on the 8051 and friends, this means that
15322 if a high-priority ISR
15326 a particular bank occurs while processing a low-priority ISR
15330 the same bank, terrible and bad things can happen.
15331 To prevent this, no single register bank should be
15335 by both a high priority and a low priority ISR.
15336 This is probably most easily done by having all high priority ISRs use
15337 one bank and all low priority ISRs use another.
15338 If you have an ISR which can change priority at runtime, you're on your
15339 own: I suggest using the default bank zero and taking the small performance
15343 \begin_layout Standard
15344 It is most efficient if your ISR calls no other functions.
15345 If your ISR must call other functions, it is most efficient if those functions
15346 use the same bank as the ISR (see note 1 below); the next best is if the
15347 called functions use bank zero.
15348 It is very inefficient to call a function using a different, non-zero bank
15351 \begin_inset VSpace bigskip
15357 \begin_layout Section
15359 \begin_inset LatexCommand \label{sub:Startup-Code}
15364 \begin_inset LatexCommand \index{Startup code}
15371 \begin_layout Subsection
15372 MCS51/DS390 Startup Code
15375 \begin_layout Standard
15376 The compiler triggers the linker to link certain initialization modules
15377 from the runtime library
15378 \begin_inset LatexCommand \index{Runtime library}
15382 called crt<something>.
15383 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15384 GSINIT5) is not linked unless the -
15390 \begin_layout Standard
15401 -xstack option is used.
15402 These modules are highly entangled by the use of special segments/areas,
15403 but a common layout is shown below:
15406 \begin_layout Verse
15414 \begin_layout Verse
15438 ljmp __sdcc_gsinit_startup
15441 \begin_layout Verse
15449 \begin_layout Verse
15461 .area GSINIT0 (CODE)
15463 __sdcc_gsinit_startup::
15473 mov sp,#__start__stack - 1
15476 \begin_layout Verse
15484 \begin_layout Verse
15496 .area GSINIT1 (CODE)
15498 __sdcc_init_xstack::
15500 ; Need to initialize in GSINIT1 in
15501 case the user's __sdcc_external_startup uses the xstack.
15511 mov __XPAGE,#(__start__x
15522 mov _spx,#__start__xstack
15525 \begin_layout Verse
15533 \begin_layout Verse
15545 .area GSINIT2 (CODE)
15555 lcall __sdcc_external_startup
15575 jz __sdcc_init_data
15586 __sdcc_program_startup
15591 \begin_layout Verse
15599 \begin_layout Verse
15611 .area GSINIT3 (CODE)
15664 mov r2,#((l_XINIT+255) >> 8)
15695 __XPAGE,#(s_XISEG >> 8)
15697 00001$:\InsetSpace ~
15761 00002$:\InsetSpace ~
15788 \begin_layout Verse
15796 \begin_layout Verse
15808 .area GSINIT4 (CODE)
15810 __mcs51_genRAMCLEAR::
15832 00004$:\InsetSpace ~
15846 ; _mcs51_genRAMCLEAR() end
15849 \begin_layout Verse
15857 \begin_layout Verse
15869 .area GSINIT4 (CODE)
15871 __mcs51_genXRAMCLEAR::
15922 mov __XPAGE,#(s_PSEG >> 8)
15934 00005$:\InsetSpace ~
15988 orl a,#(l_XSEG >> 8)
16031 00007$:\InsetSpace ~
16068 \begin_layout Verse
16076 \begin_layout Verse
16088 .area GSINIT5 (CODE)
16090 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
16093 ; and __mcs51_genRAMCLEAR modifies _spx.
16103 mov __XPAGE,#(__start__x
16114 mov _spx,#__start__xstack
16117 \begin_layout Verse
16122 (application modules)
16125 \begin_layout Verse
16137 .area GSINIT (CODE)
16140 \begin_layout Verse
16148 \begin_layout Verse
16160 .area GSFINAL (CODE)
16170 ljmp __sdcc_program_startup
16172 ;---------------------------------
16173 -----------------------
16177 ;--------------------------------------------------
16200 __sdcc_program_startup:
16213 return from main will lock up
16226 \begin_layout Standard
16227 One of these modules (crtstart.asm) contains a call to the C routine
16229 _sdcc_external_startup()
16230 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
16239 at the start of the CODE area.
16240 This routine is also in the runtime library
16241 \begin_inset LatexCommand \index{Runtime library}
16245 and returns 0 by default.
16246 If this routine returns a non-zero value, the static & global variable
16247 initialization will be skipped and the function main will be invoked.
16248 Otherwise static & global variables will be initialized before the function
16252 _sdcc_external_startup()
16254 routine to your program to override the default if you need to setup hardware
16255 or perform some other critical operation prior to static & global variable
16257 \begin_inset LatexCommand \index{Variable initialization}
16262 On some mcs51 variants xdata
16263 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
16267 memory has to be explicitly enabled before it can be accessed or if the
16269 \begin_inset LatexCommand \index{watchdog}
16273 needs to be disabled, this is the place to do it.
16274 The startup code clears all internal data memory, 256 bytes by default,
16275 but from 0 to n-1 if
16281 \begin_layout Standard
16291 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16298 (recommended for Chipcon CC1010).
16301 \begin_layout Standard
16302 See also the compiler options
16308 \begin_layout Standard
16324 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16334 \begin_layout Standard
16346 \begin_inset LatexCommand \index{-\/-main-return}
16351 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16355 about MCS51-variants.
16356 \begin_inset VSpace bigskip
16362 \begin_layout Subsection
16366 \begin_layout Standard
16368 \begin_inset LatexCommand \index{HC08}
16372 startup code follows the same scheme as the MCS51 startup code.
16373 \begin_inset VSpace bigskip
16379 \begin_layout Subsection
16383 \begin_layout Standard
16385 \begin_inset LatexCommand \index{Z80}
16389 the startup code is inserted by linking with crt0.o which is generated from
16390 sdcc/device/lib/z80/crt0.s.
16391 If you need a different startup code you can use the compiler option
16400 \begin_layout Standard
16415 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16419 and provide your own crt0.o.
16421 \begin_inset VSpace bigskip
16427 \begin_layout Section
16428 Inline Assembler Code
16429 \begin_inset LatexCommand \index{Assembler routines}
16436 \begin_layout Subsection
16437 A Step by Step Introduction
16438 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16445 \begin_layout Standard
16446 Starting from a small snippet of c-code this example shows for the MCS51
16447 how to use inline assembly, access variables, a function parameter and
16448 an array in xdata memory.
16449 The example uses an MCS51 here but is easily adapted for other architectures.
16450 This is a buffer routine which should be optimized:
16453 \begin_layout Verse
16457 unsigned char __far
16458 \begin_inset LatexCommand \index{far (storage class)}
16463 \begin_inset LatexCommand \index{\_\_far (storage class)}
16468 \begin_inset LatexCommand \index{at}
16473 \begin_inset LatexCommand \index{\_\_at}
16477 (0x7f00) buf[0x100];
16478 \begin_inset LatexCommand \index{Aligned array}
16484 unsigned char head, tail;\InsetSpace ~
16502 \begin_inset LatexCommand \index{interrupt}
16554 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16566 void to_buffer( unsigned char c )
16574 if( head != (unsigned char)(tail-1)
16581 \begin_inset LatexCommand \index{promotion to signed int}
16586 \begin_inset LatexCommand \index{type promotion}
16591 \begin_inset Marginal
16594 \begin_layout Standard
16613 buf[ head++ ] = c;\InsetSpace ~
16629 /* access to a 256 byte aligned array */
16634 \begin_layout Standard
16635 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16636 then a corresponding buffer.asm file is generated.
16637 We define a new function
16641 in file buffer.c in which we cut and paste the generated code, removing
16642 unwanted comments and some ':'.
16644 \begin_inset Quotes sld
16652 \begin_inset Quotes srd
16656 \begin_inset Quotes sld
16664 \begin_inset Quotes srd
16671 \begin_layout Standard
16672 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16673 and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16675 The latter is also used in the library functions.
16680 to the beginning and the end of the function body:
16683 \begin_layout Verse
16687 /* With a cut and paste from the .asm file, we have something to start with.
16693 function is not yet OK! (registers aren't saved) */
16695 void to_buffer_asm(
16705 \begin_inset LatexCommand \index{\_asm}
16710 \begin_inset LatexCommand \index{\_\_asm}
16724 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16730 \begin_inset LatexCommand \index{promotion to signed int}
16735 \begin_inset LatexCommand \index{type promotion}
16788 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
16789 \begin_inset LatexCommand \index{Aligned array}
16855 \begin_inset LatexCommand \index{\_endasm}
16860 \begin_inset LatexCommand \index{\_\_endasm}
16869 \begin_layout Standard
16870 The new file buffer.c should compile with only one warning about the unreferenced
16871 function argument 'c'.
16872 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
16873 (1) and finally have:
16876 \begin_layout Verse
16880 unsigned char __far __at(0x7f00) buf[0x100];
16882 unsigned char head, tail;
16893 void to_buffer( unsigned char c )
16902 head != (unsigned char)(tail-1) )
16931 c; // to avoid warning: unreferenced function argument
16938 \begin_inset LatexCommand \index{\_asm}
16943 \begin_inset LatexCommand \index{\_\_asm}
16957 ; save used registers here.
16968 ; If we were still using r2,r3 we would have to push them here.
16971 ; if( head != (unsigned char)(tail-1) )
17015 could do an ANL a,#0x0f here to use a smaller buffer (see below)
17051 a,dpl \InsetSpace ~
17058 ; dpl holds lower byte of function argument
17070 dpl,_head \InsetSpace ~
17073 ; buf is 0x100 byte aligned so head can be used directly
17116 ; we could do an ANL _head,#0x0f here to use a
17117 smaller buffer (see above)
17129 ; restore used registers here
17136 \begin_inset LatexCommand \index{\_endasm}
17141 \begin_inset LatexCommand \index{\_\_endasm}
17152 \begin_layout Standard
17153 The inline assembler code can contain any valid code understood by the assembler
17154 , this includes any assembler directives and comment lines.
17155 The assembler does not like some characters like ':' or ''' in comments.
17156 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
17157 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
17162 \begin_inset LatexCommand \index{Assembler documentation}
17167 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
17175 \begin_layout Standard
17176 The compiler does not do any validation of the code within the
17179 \begin_inset LatexCommand \index{\_asm}
17184 \begin_inset LatexCommand \index{\_\_asm}
17192 \begin_inset LatexCommand \index{\_endasm}
17197 \begin_inset LatexCommand \index{\_\_endasm}
17206 Specifically it will not know which registers are used and thus register
17208 \begin_inset LatexCommand \index{push/pop}
17212 has to be done manually.
17216 \begin_layout Standard
17217 It is recommended that each assembly instruction (including labels) be placed
17218 in a separate line (as the example shows).
17223 \begin_layout Standard
17235 \begin_inset LatexCommand \index{-\/-peep-asm}
17241 command line option is used, the inline assembler code will be passed through
17242 the peephole optimizer
17243 \begin_inset LatexCommand \index{Peephole optimizer}
17248 There are only a few (if any) cases where this option makes sense, it might
17249 cause some unexpected changes in the inline assembler code.
17250 Please go through the peephole optimizer rules defined in file
17254 before using this option.
17257 \begin_layout Subsection
17259 \begin_inset LatexCommand \label{sub:Naked-Functions}
17264 \begin_inset LatexCommand \index{Naked functions}
17271 \begin_layout Standard
17272 A special keyword may be associated with a function declaring it as
17275 \begin_inset LatexCommand \index{\_naked}
17280 \begin_inset LatexCommand \index{\_\_naked}
17291 function modifier attribute prevents the compiler from generating prologue
17292 \begin_inset LatexCommand \index{function prologue}
17297 \begin_inset LatexCommand \index{function epilogue}
17301 code for that function.
17302 This means that the user is entirely responsible for such things as saving
17303 any registers that may need to be preserved, selecting the proper register
17304 bank, generating the
17308 instruction at the end, etc.
17309 Practically, this means that the contents of the function must be written
17310 in inline assembler.
17311 This is particularly useful for interrupt functions, which can have a large
17312 (and often unnecessary) prologue/epilogue.
17313 For example, compare the code generated by these two functions:
17316 \begin_layout Verse
17320 \begin_inset LatexCommand \index{volatile}
17324 data unsigned char counter;
17328 void simpleInterrupt(void) __interrupt
17329 \begin_inset LatexCommand \index{interrupt}
17334 \begin_inset LatexCommand \index{\_\_interrupt}
17352 void nakedInterrupt(void) __interrupt (2) __naked
17361 \begin_inset LatexCommand \index{\_asm}
17366 \begin_inset LatexCommand \index{\_\_asm}
17383 _counter ; does not change flags, no need to save psw
17396 include ret or reti in _naked function.
17403 \begin_inset LatexCommand \index{\_endasm}
17408 \begin_inset LatexCommand \index{\_\_endasm}
17417 \begin_layout Standard
17418 For an 8051 target, the generated simpleInterrupt looks like:
17421 \begin_layout Verse
17428 example, recent versions of SDCC generate
17434 code for simpleInterrupt() and nakedInterrupt()!
17575 \begin_layout Standard
17576 whereas nakedInterrupt looks like:
17579 \begin_layout Verse
17592 _counter ; does not change flags, no need to save psw
17611 MUST explicitly include ret or reti in _naked function
17614 \begin_layout Standard
17615 The related directive #pragma exclude
17616 \begin_inset LatexCommand \index{\#pragma exclude}
17620 allows a more fine grained control over pushing & popping
17621 \begin_inset LatexCommand \index{push/pop}
17628 \begin_layout Standard
17629 While there is nothing preventing you from writing C code inside a
17633 function, there are many ways to shoot yourself in the foot doing this,
17634 and it is recommended that you stick to inline assembler.
17637 \begin_layout Subsection
17638 Use of Labels within Inline Assembler
17641 \begin_layout Standard
17642 SDCC allows the use of in-line assembler with a few restrictions regarding
17644 All labels defined within inline assembler code have to be of the form
17649 where nnnnn is a number less than 100 (which implies a limit of utmost
17650 100 inline assembler labels
17661 \begin_layout Standard
17662 This is a slightly more stringent rule than absolutely necessary, but stays
17663 always on the safe side.
17664 Labels in the form of nnnnn$ are local labels in the assembler, locality
17665 of which is confined within two labels of the standard form.
17666 The compiler uses the same form for labels within a function (but starting
17667 from nnnnn=00100); and places always a standard label at the beginning
17668 of a function, thus limiting the locality of labels within the scope of
17670 So, if the inline assembler part would be embedded into C-code, an improperly
17671 placed non-local label in the assembler would break up the reference space
17672 for labels created by the compiler for the C-code, leading to an assembling
17676 \begin_layout Standard
17677 The numeric part of local labels does not need to have 5 digits (although
17678 this is the form of labels output by the compiler), any valid integer will
17680 Please refer to the assemblers documentation for further details.
17688 \begin_layout Verse
17692 \begin_inset LatexCommand \index{\_asm}
17697 \begin_inset LatexCommand \index{\_\_asm}
17727 \begin_inset LatexCommand \index{\_endasm}
17732 \begin_inset LatexCommand \index{\_\_endasm}
17739 \begin_layout Standard
17740 Inline assembler code cannot reference any C-labels, however it can reference
17742 \begin_inset LatexCommand \index{Labels}
17746 defined by the inline assembler, e.g.:
17749 \begin_layout Verse
17772 ; some assembler code
17793 /* some more c code */
17795 clabel:\InsetSpace ~
17797 /* inline assembler cannot reference this
17802 \begin_layout Standard
17807 is translated by the compiler into a local label, so the locality of labels
17808 within the function is not broken.
17825 0003$: ;label (can be referenced by inline assembler only)
17832 \begin_inset LatexCommand \index{\_endasm}
17837 \begin_inset LatexCommand \index{\_\_endasm}
17847 /* some more c code */
17852 \begin_layout Standard
17853 In other words inline assembly code can access labels defined in inline
17854 assembly within the scope of the function.
17855 The same goes the other way, i.e.
17856 labels defines in inline assembly can not be accessed by C statements.
17859 \begin_layout Section
17860 Interfacing with Assembler Code
17861 \begin_inset LatexCommand \index{Assembler routines}
17868 \begin_layout Subsection
17869 Global Registers used for Parameter Passing
17870 \begin_inset LatexCommand \index{Parameter passing}
17877 \begin_layout Standard
17878 The compiler always uses the global registers
17881 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17886 \begin_inset LatexCommand \index{DPTR}
17891 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
17900 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
17906 to pass the first (non-bit) parameter to a function, and also to pass the
17908 \begin_inset LatexCommand \index{return value}
17912 of function; according to the following scheme: one byte return value in
17917 , two byte value in
17926 three byte values (generic pointers) in
17938 , and four byte values in
17956 \begin_inset LatexCommand \index{generic pointer}
17960 contain type of accessed memory in
17981 \begin_inset Note Note
17984 \begin_layout Standard
17985 This might not be the case of certain memory models (medium???)
17993 \begin_layout Standard
17994 The second parameter onwards is either allocated on the stack (for reentrant
17999 \begin_layout Standard
18008 -stack-auto is used) or in data/xdata memory (depending on the memory model).
18011 \begin_layout Standard
18012 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
18013 space for reentrant functions or allocated directly in bit memory otherwise.
18016 \begin_layout Standard
18017 Functions (with two or more parameters or bit parameters) that are called
18018 through function pointers
18019 \begin_inset LatexCommand \index{function pointers}
18023 must therefor be reentrant so the compiler knows how to pass the parameters.
18026 \begin_layout Subsection
18030 \begin_layout Standard
18031 Unless the called function is declared as
18036 \begin_inset LatexCommand \index{naked}
18044 \begin_layout Standard
18054 \begin_inset LatexCommand \index{-\/-callee-saves}
18062 \begin_layout Standard
18071 -all-callee-saves command line option or the corresponding callee_saves
18072 pragma are used, the caller will save the registers (
18076 ) around the call, so the called function can destroy they content freely.
18079 \begin_layout Standard
18080 If the called function is not declared as
18084 , the caller will swap register banks around the call, if caller and callee
18085 use different register banks (having them defined by the
18093 \begin_layout Standard
18094 The called function can also use
18110 observing that they are used for parameter/return value passing.
18113 \begin_layout Subsection
18114 Assembler Routine (non-reentrant)
18117 \begin_layout Standard
18118 In the following example
18119 \begin_inset LatexCommand \index{reentrant}
18124 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
18128 the function c_func calls an assembler routine asm_func, which takes two
18130 \begin_inset LatexCommand \index{function parameter}
18137 \begin_layout Verse
18140 extern int asm_func(unsigned char, unsigned char);
18144 int c_func (unsigned char
18145 i, unsigned char j)
18153 return asm_func(i,j);
18167 return c_func(10,9);
18172 \begin_layout Standard
18173 The corresponding assembler function is:
18176 \begin_layout Verse
18179 .globl _asm_func_PARM_2
18281 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18298 \begin_layout Standard
18299 The parameter naming convention is _<function_name>_PARM_<n>, where n is
18300 the parameter number starting from 1, and counting from the left.
18301 The first parameter is passed in
18317 according to the description above.
18318 The variable name for the second parameter will be _<function_name>_PARM_2.
18323 ble the assembler routine with the following command:
18330 asx8051 -losg asmfunc.asm
18337 Then compile and link the assembler routine to the C source file with the
18345 sdcc cfunc.c asmfunc.rel
18348 \begin_layout Subsection
18349 Assembler Routine (reentrant)
18352 \begin_layout Standard
18354 \begin_inset LatexCommand \index{reentrant}
18359 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18363 the second parameter
18364 \begin_inset LatexCommand \index{function parameter}
18368 onwards will be passed on the stack, the parameters are pushed from right
18370 before the call the second leftmost parameter will be on the top of the
18371 stack (the leftmost parameter is passed in registers).
18372 Here is an example:
18375 \begin_layout Verse
18378 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18383 c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
18392 return asm_func(i,j,k);
18406 return c_func(10,9,8);
18411 \begin_layout Standard
18412 The corresponding (unoptimized) assembler routine is:
18415 \begin_layout Verse
18435 _bp,sp\InsetSpace ~
18441 ;stack contains: _bp, return
18442 address, second parameter, third parameter
18466 a,#0xfd\InsetSpace ~
18472 pointer to the second parameter
18496 a,#0xfc\InsetSpace ~
18502 to the rightmost parameter
18543 result (= sum of all three parameters)
18558 ;return value goes into dptr
18592 \begin_layout Standard
18593 The compiling and linking procedure remains the same, however note the extra
18594 entry & exit linkage required for the assembler code, _bp is the stack
18595 frame pointer and is used to compute the offset into the stack for parameters
18596 and local variables.
18597 \begin_inset VSpace bigskip
18603 \begin_layout Section
18605 \begin_inset LatexCommand \index{int (16 bit)}
18610 \begin_inset LatexCommand \index{long (32 bit)}
18617 \begin_layout Standard
18618 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18619 multiplication and modulus operations are implemented by support routines.
18620 These support routines are all developed in ANSI-C to facilitate porting
18621 to other MCUs, although some model specific assembler optimizations are
18623 The following files contain the described routines, all of them can be
18624 found in <installdir>/share/sdcc/lib.
18629 \begin_layout Standard
18631 \begin_inset Tabular
18632 <lyxtabular version="3" rows="11" columns="2">
18634 <column alignment="left" valignment="top" leftline="true" width="0">
18635 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18636 <row topline="true" bottomline="true">
18637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18640 \begin_layout Standard
18648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18651 \begin_layout Standard
18660 <row topline="true">
18661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18664 \begin_layout Standard
18670 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18673 \begin_layout Standard
18674 16 bit multiplication
18680 <row topline="true">
18681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18684 \begin_layout Standard
18690 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18693 \begin_layout Standard
18694 signed 16 bit division (calls _divuint)
18700 <row topline="true">
18701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18704 \begin_layout Standard
18710 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18713 \begin_layout Standard
18714 unsigned 16 bit division
18720 <row topline="true">
18721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18724 \begin_layout Standard
18730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18733 \begin_layout Standard
18734 signed 16 bit modulus (calls _moduint)
18740 <row topline="true">
18741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18744 \begin_layout Standard
18750 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18753 \begin_layout Standard
18754 unsigned 16 bit modulus
18760 <row topline="true">
18761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18764 \begin_layout Standard
18770 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18773 \begin_layout Standard
18774 32 bit multiplication
18780 <row topline="true">
18781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18784 \begin_layout Standard
18790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18793 \begin_layout Standard
18794 signed 32 division (calls _divulong)
18800 <row topline="true">
18801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18804 \begin_layout Standard
18810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18813 \begin_layout Standard
18814 unsigned 32 division
18820 <row topline="true">
18821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18824 \begin_layout Standard
18830 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18833 \begin_layout Standard
18834 signed 32 bit modulus (calls _modulong)
18840 <row topline="true" bottomline="true">
18841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18844 \begin_layout Standard
18850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18853 \begin_layout Standard
18854 unsigned 32 bit modulus
18869 \begin_layout Standard
18870 Since they are compiled as
18875 \begin_inset LatexCommand \index{reentrant}
18880 \begin_inset LatexCommand \index{interrupt}
18884 service routines should not do any of the above operations.
18885 If this is unavoidable then the above routines will need to be compiled
18892 \begin_layout Standard
18902 \begin_inset LatexCommand \index{-\/-stack-auto}
18908 option, after which the source program will have to be compiled with
18914 \begin_layout Standard
18924 \begin_inset LatexCommand \index{-\/-int-long-reent}
18931 Notice that you don't have to call these routines directly.
18932 The compiler will use them automatically every time an integer operation
18936 \begin_layout Section
18937 Floating Point Support
18938 \begin_inset LatexCommand \index{Floating point support}
18945 \begin_layout Standard
18946 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
18947 The floating point support routines are derived from gcc's floatlib.c and
18948 consist of the following routines:
18953 \begin_layout Standard
18957 \begin_inset Tabular
18958 <lyxtabular version="3" rows="17" columns="2">
18960 <column alignment="left" valignment="top" leftline="true" width="0">
18961 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18962 <row topline="true" bottomline="true">
18963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18966 \begin_layout Standard
18981 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18984 \begin_layout Standard
18991 <row topline="true">
18992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18995 \begin_layout Standard
19010 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19013 \begin_layout Standard
19023 add floating point numbers
19029 <row topline="true">
19030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19033 \begin_layout Standard
19048 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19051 \begin_layout Standard
19061 subtract floating point numbers
19067 <row topline="true">
19068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19071 \begin_layout Standard
19086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19089 \begin_layout Standard
19099 divide floating point numbers
19105 <row topline="true">
19106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19109 \begin_layout Standard
19124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19127 \begin_layout Standard
19137 multiply floating point numbers
19143 <row topline="true">
19144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19147 \begin_layout Standard
19162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19165 \begin_layout Standard
19175 convert floating point to unsigned char
19181 <row topline="true">
19182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19185 \begin_layout Standard
19200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19203 \begin_layout Standard
19213 convert floating point to signed char
19219 <row topline="true">
19220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19223 \begin_layout Standard
19238 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19241 \begin_layout Standard
19251 convert floating point to unsigned int
19257 <row topline="true">
19258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19261 \begin_layout Standard
19276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19279 \begin_layout Standard
19289 convert floating point to signed int
19295 <row topline="true">
19296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19299 \begin_layout Standard
19322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19325 \begin_layout Standard
19335 convert floating point to unsigned long
19341 <row topline="true">
19342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19345 \begin_layout Standard
19360 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19363 \begin_layout Standard
19373 convert floating point to signed long
19379 <row topline="true">
19380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19383 \begin_layout Standard
19398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19401 \begin_layout Standard
19411 convert unsigned char to floating point
19417 <row topline="true">
19418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19421 \begin_layout Standard
19436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19439 \begin_layout Standard
19449 convert char to floating point number
19455 <row topline="true">
19456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19459 \begin_layout Standard
19474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19477 \begin_layout Standard
19487 convert unsigned int to floating point
19493 <row topline="true">
19494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19497 \begin_layout Standard
19512 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19515 \begin_layout Standard
19525 convert int to floating point numbers
19531 <row topline="true">
19532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19535 \begin_layout Standard
19550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19553 \begin_layout Standard
19563 convert unsigned long to floating point number
19569 <row topline="true" bottomline="true">
19570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19573 \begin_layout Standard
19588 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19591 \begin_layout Standard
19601 convert long to floating point number
19616 \begin_layout Standard
19617 These support routines are developed in ANSI-C so there is room for space
19618 and speed improvement
19622 \begin_layout Standard
19623 These floating point routines (
19627 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19634 Note if all these routines are used simultaneously the data space might
19636 For serious floating point usage the large model might be needed.
19637 Also notice that you don't have to call this routines directly.
19638 The compiler will use them automatically every time a floating point operation
19640 \begin_inset VSpace bigskip
19646 \begin_layout Section
19648 \begin_inset LatexCommand \index{Libraries}
19655 \begin_layout Standard
19658 <pending: this is messy and incomplete - a little more information is in
19659 sdcc/doc/libdoc.txt
19664 \begin_layout Subsection
19665 Compiler support routines (_gptrget, _mulint etc.)
19668 \begin_layout Subsection
19669 Stdclib functions (puts, printf, strcat etc.)
19672 \begin_layout Subsubsection
19676 \begin_layout Paragraph
19677 getchar(), putchar()
19680 \begin_layout Standard
19681 \begin_inset LatexCommand \index{<stdio.h>}
19685 As usual on embedded systems you have to provide your own
19688 \begin_inset LatexCommand \index{getchar()}
19697 \begin_inset LatexCommand \index{putchar()}
19704 SDCC does not know whether the system connects to a serial line with or
19705 without handshake, LCD, keyboard or other device.
19719 You'll find examples for serial routines f.e.
19720 in sdcc/device/lib.
19721 For the mcs51 this minimalistic polling
19725 routine might be a start:
19728 \begin_layout Verse
19731 void putchar (char c) {
19737 while (!TI)\InsetSpace ~
19740 /* assumes UART is initialized */
19768 \begin_layout Paragraph
19772 \begin_layout Standard
19776 \begin_inset LatexCommand \index{printf()}
19786 does not support float (except on ds390).
19787 To enable this recompile it with the option
19793 \begin_layout Standard
19803 \begin_inset LatexCommand \index{USE\_FLOATS}
19809 on the command line.
19816 \begin_layout Standard
19826 \begin_inset LatexCommand \index{-\/-model-large}
19832 for the mcs51 port, since this uses a lot of memory.
19835 \begin_layout Standard
19836 If you're short on code memory you might want to use
19839 \begin_inset LatexCommand \index{printf\_small()}
19854 For the mcs51 there additionally are assembly versions
19857 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
19863 (subset of printf using less than 270 bytes) and
19866 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
19875 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
19881 (floating-point aware version of printf_fast) which should fit the requirements
19882 of many embedded systems (printf_fast() can be customized by unsetting
19887 support long variables and field widths).
19888 Be sure to use only one of these printf options within a project.
19893 \begin_layout Standard
19894 Feature matrix of different
19901 \begin_layout Standard
19902 \begin_inset Tabular
19903 <lyxtabular version="3" rows="14" columns="7">
19904 <features islongtable="true">
19905 <column alignment="left" valignment="middle" leftline="true" width="14col%">
19906 <column alignment="center" valignment="top" leftline="true" width="0">
19907 <column alignment="center" valignment="top" leftline="true" width="12col%">
19908 <column alignment="center" valignment="top" leftline="true" width="10col%">
19909 <column alignment="center" valignment="top" leftline="true" width="0">
19910 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
19911 <column alignment="center" valignment="top" rightline="true" width="0">
19912 <row topline="true" bottomline="true" endhead="true">
19913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19916 \begin_layout Standard
19925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19928 \begin_layout Standard
19930 \begin_inset LatexCommand \index{printf}
19939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19942 \begin_layout Standard
19950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19953 \begin_layout Standard
19959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19962 \begin_layout Standard
19968 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19971 \begin_layout Standard
19977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19980 \begin_layout Standard
19987 <row topline="true" endhead="true">
19988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19991 \begin_layout Standard
19997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20000 \begin_layout Standard
20008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20011 \begin_layout Standard
20019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20022 \begin_layout Standard
20030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20033 \begin_layout Standard
20041 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20044 \begin_layout Standard
20052 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20055 \begin_layout Standard
20064 <row topline="true" endhead="true">
20065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20068 \begin_layout Standard
20069 \begin_inset Quotes sld
20073 \begin_inset Quotes srd
20079 \begin_layout Standard
20085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20088 \begin_layout Standard
20094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20097 \begin_layout Standard
20103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20106 \begin_layout Standard
20112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20115 \begin_layout Standard
20121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20124 \begin_layout Standard
20130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20133 \begin_layout Standard
20140 <row topline="true" endhead="true">
20141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20144 \begin_layout Standard
20148 \begin_layout Standard
20154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20157 \begin_layout Standard
20163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20166 \begin_layout Standard
20172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20175 \begin_layout Standard
20176 0.45k / 0.47k (+ _ltoa)
20181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20184 \begin_layout Standard
20190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20193 \begin_layout Standard
20199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20202 \begin_layout Standard
20209 <row topline="true">
20210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20213 \begin_layout Standard
20219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20222 \begin_layout Standard
20232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20235 \begin_layout Standard
20282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20285 \begin_layout Standard
20324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20327 \begin_layout Standard
20333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20336 \begin_layout Standard
20342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20345 \begin_layout Standard
20352 <row topline="true">
20353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20356 \begin_layout Standard
20357 long (32 bit) support
20362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20365 \begin_layout Standard
20371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20374 \begin_layout Standard
20380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20383 \begin_layout Standard
20389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20392 \begin_layout Standard
20398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20401 \begin_layout Standard
20416 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20419 \begin_layout Standard
20426 <row topline="true">
20427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20430 \begin_layout Standard
20431 byte arguments on stack
20436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20439 \begin_layout Standard
20445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20448 \begin_layout Standard
20454 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20457 \begin_layout Standard
20463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20466 \begin_layout Standard
20472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20475 \begin_layout Standard
20481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20484 \begin_layout Standard
20491 <row topline="true">
20492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20495 \begin_layout Standard
20497 \begin_inset LatexCommand \index{Floating point support}
20506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20509 \begin_layout Standard
20515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20518 \begin_layout Standard
20524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20527 \begin_layout Standard
20533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20536 \begin_layout Standard
20542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20545 \begin_layout Standard
20550 \begin_layout Standard
20551 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20561 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20564 \begin_layout Standard
20571 <row topline="true">
20572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20575 \begin_layout Standard
20576 float formats %e %g
20581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20584 \begin_layout Standard
20590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20593 \begin_layout Standard
20599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20602 \begin_layout Standard
20608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20611 \begin_layout Standard
20617 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20620 \begin_layout Standard
20626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20629 \begin_layout Standard
20636 <row topline="true" bottomline="true">
20637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20640 \begin_layout Standard
20646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20649 \begin_layout Standard
20655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20658 \begin_layout Standard
20664 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20667 \begin_layout Standard
20673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20676 \begin_layout Standard
20682 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20685 \begin_layout Standard
20691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20694 \begin_layout Standard
20701 <row bottomline="true">
20702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20705 \begin_layout Standard
20710 \begin_layout Standard
20711 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20715 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20723 \begin_layout Standard
20729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20732 \begin_layout Standard
20738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20741 \begin_layout Standard
20747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20750 \begin_layout Standard
20756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20759 \begin_layout Standard
20765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20768 \begin_layout Standard
20774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20777 \begin_layout Standard
20784 <row bottomline="true">
20785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20788 \begin_layout Standard
20793 \begin_layout Standard
20794 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
20803 \begin_layout Standard
20809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20812 \begin_layout Standard
20818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20821 \begin_layout Standard
20827 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20830 \begin_layout Standard
20836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20839 \begin_layout Standard
20845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20848 \begin_layout Standard
20854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20857 \begin_layout Standard
20862 \begin_layout Standard
20863 printf_tiny integer speed is data dependent, worst case is 0.33 ms
20874 <row bottomline="true">
20875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20878 \begin_layout Standard
20883 \begin_layout Standard
20884 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
20893 \begin_layout Standard
20899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20902 \begin_layout Standard
20908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20911 \begin_layout Standard
20917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20920 \begin_layout Standard
20926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20929 \begin_layout Standard
20935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20938 \begin_layout Standard
20944 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20947 \begin_layout Standard
20954 <row bottomline="true">
20955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20958 \begin_layout Standard
20963 \begin_layout Standard
20964 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
20973 \begin_layout Standard
20979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20982 \begin_layout Standard
20988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20991 \begin_layout Standard
20997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21000 \begin_layout Standard
21006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21009 \begin_layout Standard
21015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21018 \begin_layout Standard
21024 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21027 \begin_layout Standard
21041 \begin_layout Subsubsection
21043 \begin_inset LatexCommand \index{malloc.h}
21050 \begin_layout Standard
21051 As of SDCC 2.6.2 you no longer need to call an initialization routine before
21052 using dynamic memory allocation
21053 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
21058 \begin_inset LatexCommand \index{heap (malloc)}
21062 space of 1024 bytes is provided for malloc to allocate memory from.
21063 If you need a different heap size you need to recompile _heap.c with the
21064 required size defined in HEAP_SIZE.
21065 It is recommended to make a copy of this file into your project directory
21066 and compile it there with:
21069 \begin_layout Verse
21072 sdcc -c _heap.c -D HEAD_SIZE=2048
21075 \begin_layout Standard
21076 And then link it with:
21079 \begin_layout Verse
21082 sdcc main.rel _heap.rel
21085 \begin_layout Subsection
21086 Math functions (sinf, powf, sqrtf etc.)
21089 \begin_layout Subsubsection
21093 \begin_layout Standard
21094 See definitions in file <math.h>.
21097 \begin_layout Subsection
21101 \begin_layout Standard
21103 \begin_inset LatexCommand \index{Libraries}
21107 included in SDCC should have a license at least as liberal as the GNU Lesser
21108 General Public License
21109 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
21120 \begin_layout Standard
21121 \begin_inset Note Note
21124 \begin_layout Standard
21125 license statements for the libraries are missing.
21126 sdcc/device/lib/ser_ir.c
21129 \begin_layout Standard
21131 come with a GPL (as opposed to LGPL) License - this will not be liberal
21132 enough for many embedded programmers.
21140 \begin_layout Standard
21141 If you have ported some library or want to share experience about some code
21143 falls into any of these categories Busses (I
21144 \begin_inset Formula $^{\textrm{2}}$
21147 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
21148 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
21149 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
21150 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
21155 would certainly like to hear about it.
21158 \begin_layout Standard
21159 Programmers coding for embedded systems are not especially famous for being
21160 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
21161 e these references are very valuable.
21162 Let's help to create a climate where information is shared.
21163 \begin_inset VSpace bigskip
21169 \begin_layout Section
21173 \begin_layout Subsection
21174 MCS51 Memory Models
21175 \begin_inset LatexCommand \index{Memory model}
21180 \begin_inset LatexCommand \index{MCS51 memory model}
21187 \begin_layout Subsubsection
21188 Small, Medium and Large
21191 \begin_layout Standard
21192 SDCC allows three memory models for MCS51 code,
21201 Modules compiled with different memory models should
21205 be combined together or the results would be unpredictable.
21206 The library routines supplied with the compiler are compiled as small,
21208 The compiled library modules are contained in separate directories as small,
21209 medium and large so that you can link to the appropriate set.
21212 \begin_layout Standard
21213 When the medium or large model is used all variables declared without a
21214 storage class will be allocated into the external ram, this includes all
21215 parameters and local variables (for non-reentrant
21216 \begin_inset LatexCommand \index{reentrant}
21221 When the small model is used variables without storage class are allocated
21222 in the internal ram.
21225 \begin_layout Standard
21226 Judicious usage of the processor specific storage classes
21227 \begin_inset LatexCommand \index{Storage class}
21231 and the 'reentrant' function type will yield much more efficient code,
21232 than using the large model.
21233 Several optimizations are disabled when the program is compiled using the
21234 large model, it is therefore recommended that the small model be used unless
21235 absolutely required.
21238 \begin_layout Subsubsection
21240 \begin_inset LatexCommand \label{sub:External-Stack}
21245 \begin_inset LatexCommand \index{stack}
21250 \begin_inset LatexCommand \index{External stack (mcs51)}
21257 \begin_layout Standard
21258 The external stack (-
21262 \begin_layout Standard
21272 \begin_inset LatexCommand \index{-\/-xstack}
21276 ) is located in pdata
21277 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
21281 memory (usually at the start of the external ram segment) and uses all
21282 unused space in pdata (max.
21288 \begin_layout Standard
21297 -xstack option is used to compile the program, the parameters and local
21299 \begin_inset LatexCommand \index{local variables}
21303 of all reentrant functions are allocated in this area.
21304 This option is provided for programs with large stack space requirements.
21305 When used with the -
21309 \begin_layout Standard
21319 \begin_inset LatexCommand \index{-\/-stack-auto}
21323 option, all parameters and local variables are allocated on the external
21324 stack (note: support libraries will need to be recompiled with the same
21326 There is a predefined target in the library makefile).
21329 \begin_layout Standard
21330 The compiler outputs the higher order address byte of the external ram segment
21332 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21337 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21341 ), therefore when using the External Stack option, this port
21345 be used by the application program.
21348 \begin_layout Subsection
21350 \begin_inset LatexCommand \index{Memory model}
21355 \begin_inset LatexCommand \index{DS390 memory model}
21362 \begin_layout Standard
21363 The only model supported is Flat 24
21364 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21369 This generates code for the 24 bit contiguous addressing mode of the Dallas
21371 In this mode, up to four meg of external RAM or code space can be directly
21373 See the data sheets at www.dalsemi.com for further information on this part.
21378 that the compiler does not generate any code to place the processor into
21379 24 bitmode (although
21383 in the ds390 libraries will do that for you).
21389 \begin_inset LatexCommand \index{Tinibios (DS390)}
21393 , the boot loader or similar code must ensure that the processor is in 24
21394 bit contiguous addressing mode before calling the SDCC startup code.
21405 \begin_layout Standard
21416 option, variables will by default be placed into the XDATA segment.
21421 Segments may be placed anywhere in the 4 meg address space using the usual
21426 \begin_layout Standard
21436 Note that if any segments are located above 64K, the -r flag must be passed
21437 to the linker to generate the proper segment relocations, and the Intel
21438 HEX output format must be used.
21439 The -r flag can be passed to the linker by using the option
21443 on the SDCC command line.
21444 However, currently the linker can not handle code segments > 64k.
21447 \begin_layout Section
21449 \begin_inset LatexCommand \label{sec:Pragmas}
21454 \begin_inset LatexCommand \index{Pragmas}
21461 \begin_layout Standard
21462 Pragmas are used to turn on and/or off certain compiler options.
21463 Some of them are closely related to corresponding command-line options
21465 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21471 Pragmas should be placed before and/or after a function, placing pragmas
21472 inside a function body could have unpredictable results.
21477 following #pragma directives:
21480 \begin_layout Itemize
21486 \begin_inset LatexCommand \index{\#pragma save}
21490 - this will save most current options to the save/restore stack.
21491 See #pragma\InsetSpace ~
21495 \begin_layout Itemize
21501 \begin_inset LatexCommand \index{\#pragma restore}
21505 - will restore saved options from the last save.
21506 saves & restores can be nested.
21507 SDCC uses a save/restore stack: save pushes current options to the stack,
21508 restore pulls current options from the stack.
21509 See #pragma\InsetSpace ~
21515 \begin_layout Itemize
21521 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21526 \begin_inset LatexCommand \index{function prologue}
21530 function1[,function2[,function3...]]
21531 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21535 - The compiler by default uses a caller saves convention for register saving
21536 across function calls, however this can cause unnecessary register pushing
21538 \begin_inset LatexCommand \index{push/pop}
21542 when calling small functions from larger functions.
21543 This option can be used to switch off the register saving convention for
21544 the function names specified.
21545 The compiler will not save registers when calling these functions, extra
21546 code need to be manually inserted at the entry and exit for these functions
21547 to save and restore the registers used by these functions, this can SUBSTANTIAL
21548 LY reduce code and improve run time performance of the generated code.
21549 In the future the compiler (with inter procedural analysis) may be able
21550 to determine the appropriate scheme to use for each function call.
21555 \begin_layout Standard
21564 -callee-saves command line option is used (see page
21565 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21569 ), the function names specified in #pragma\InsetSpace ~
21571 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21575 is appended to the list of functions specified in the command line.
21578 \begin_layout Itemize
21584 \begin_inset LatexCommand \index{\#pragma exclude}
21588 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21589 of pairs of push/pop
21590 \begin_inset LatexCommand \index{push/pop}
21599 \begin_inset LatexCommand \index{interrupt}
21612 The directive should be placed immediately before the ISR function definition
21613 and it affects ALL ISR functions following it.
21614 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21615 exclude\InsetSpace ~
21617 \begin_inset LatexCommand \index{\#pragma exclude}
21622 See also the related keyword _naked
21623 \begin_inset LatexCommand \index{\_naked}
21628 \begin_inset LatexCommand \index{\_\_naked}
21635 \begin_layout Itemize
21641 \begin_inset LatexCommand \index{pedantic}
21646 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21651 \begin_inset LatexCommand \label{ite:less_pedantic}
21655 - the compiler will not warn you anymore for obvious mistakes, you're on
21657 See also the command line option -
21661 \begin_layout Standard
21671 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21678 More specifically, the following warnings will be disabled:
21680 comparison is always [true/false] due to limited range of data type
21684 overflow in implicit constant conversion
21686 (158); [the (in)famous]
21688 conditional flow changed by optimizer: so said EVELYN the modified DOG
21692 function '[function name]' must return value
21697 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21698 level) are disabled, too, namely:
21701 \begin_inset Note Note
21704 \begin_layout Standard
21705 dunno what comes here - this warning appears to be unused altogether
21714 [left/right] shifting more than size of object changed to zero
21722 integer overflow in expression
21726 unmatched #pragma save and #pragma restore
21730 comparison of 'signed char' with 'unsigned char' requires promotion to int
21734 ISO C90 does not support flexible array members
21738 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21742 \begin_inset Note Note
21745 \begin_layout Standard
21746 appears to be always blank - what was supposed to be here?
21755 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21756 complexity [number]
21761 \begin_layout Itemize
21767 \begin_inset LatexCommand \index{\#pragma disable\_warning}
21771 - the compiler will not warn you anymore about warning number <nnnn>.
21774 \begin_layout Itemize
21780 \begin_inset LatexCommand \index{\#pragma nogcse}
21784 - will stop global common subexpression elimination.
21787 \begin_layout Itemize
21793 \begin_inset LatexCommand \index{\#pragma noinduction}
21797 - will stop loop induction optimizations.
21800 \begin_layout Itemize
21806 \begin_inset LatexCommand \index{\#pragma noinvariant}
21810 - will not do loop invariant optimizations.
21811 For more details see Loop Invariants in section
21812 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
21819 \begin_layout Itemize
21825 \begin_inset LatexCommand \index{\#pragma noiv}
21829 - Do not generate interrupt
21830 \begin_inset LatexCommand \index{interrupt}
21835 \begin_inset LatexCommand \index{interrupt vector table}
21839 entries for all ISR functions defined after the pragma.
21840 This is useful in cases where the interrupt vector table must be defined
21841 manually, or when there is a secondary, manually defined interrupt vector
21843 for the autovector feature of the Cypress EZ-USB FX2).
21844 More elegantly this can be achieved by obmitting the optional interrupt
21845 number after the interrupt keyword, see section
21846 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
21854 \begin_layout Itemize
21860 \begin_inset LatexCommand \index{\#pragma nojtbound}
21864 - will not generate code for boundary value checking, when switch statements
21865 are turned into jump-tables (dangerous).
21866 For more details see section
21867 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
21874 \begin_layout Itemize
21880 \begin_inset LatexCommand \index{\#pragma noloopreverse}
21884 - Will not do loop reversal optimization
21887 \begin_layout Itemize
21893 \begin_inset LatexCommand \index{\#pragma nooverlay}
21897 - the compiler will not overlay the parameters and local variables of a
21901 \begin_layout Itemize
21907 \begin_inset LatexCommand \index{\#pragma stackauto}
21915 \begin_layout Standard
21925 \begin_inset LatexCommand \index{-\/-stack-auto}
21930 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
21934 Parameters and Local Variables.
21937 \begin_layout Itemize
21943 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
21947 - The compiler will optimize code generation towards fast code, possibly
21948 at the expense of code size.
21949 Currently this has little effect.
21952 \begin_layout Itemize
21958 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
21962 - The compiler will optimize code generation towards compact code, possibly
21963 at the expense of code speed.
21964 Currently this has little effect.
21967 \begin_layout Itemize
21973 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
21977 - The compiler will attempt to generate code that is both compact and fast,
21978 as long as meeting one goal is not a detriment to the other (this is the
21983 \begin_layout Itemize
21989 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
21993 - Generally follow the C89 standard, but allow SDCC features that conflict
21994 with the standard (default).
21997 \begin_layout Itemize
22003 \begin_inset LatexCommand \index{\#pragma std\_c89}
22007 - Follow the C89 standard and disable SDCC features that conflict with the
22011 \begin_layout Itemize
22017 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
22021 - Generally follow the C99 standard, but allow SDCC features that conflict
22022 with the standard (incomplete support).
22025 \begin_layout Itemize
22031 \begin_inset LatexCommand \index{\#pragma std\_c99}
22035 - Follow the C99 standard and disable SDCC features that conflict with the
22036 standard (incomplete support).
22039 \begin_layout Itemize
22045 \begin_inset LatexCommand \index{\#pragma codeseg}
22049 - Use this name (max.
22050 8 characters) for the code segment.
22055 \begin_layout Standard
22067 \begin_layout Itemize
22073 \begin_inset LatexCommand \index{\#pragma constseg}
22077 - Use this name (max.
22078 8 characters) for the const segment.
22083 \begin_layout Standard
22095 \begin_layout Standard
22096 The preprocessor SDCPP
22097 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
22101 supports the following #pragma directives:
22104 \begin_layout Itemize
22107 pedantic_parse_number
22110 \begin_inset LatexCommand \index{pedantic}
22115 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22120 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
22124 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
22125 properly and the macro LO_B(3) gets expanded.
22131 \begin_layout Standard
22140 -pedantic-parse-number command line option
22141 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
22148 Below is an example on how to use this pragma.
22151 Note: this functionality is not in conformance with standard!
22154 \begin_layout Verse
22157 #pragma pedantic_parse_number +
22158 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22166 #define LO_B(x) ((x) & 0xff)
22170 unsigned char foo(void)
22177 unsigned char c=0xfe-LO_B(3)
22192 \begin_layout Itemize
22198 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22202 (+ | -) - switch _asm _endasm block preprocessing on / off.
22204 You use this prama to define multilines of assembly code.
22205 This will prevent the preprocessor from changing the formating required
22207 Below is an example on how to use this pragma.
22210 \begin_layout Verse
22213 #pragma preproc_asm -
22214 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22220 #define MYDELAY _asm
22225 nop ;my assembly comment...
22239 #pragma preproc_asm
22270 \begin_layout Itemize
22276 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22280 (+ | -) - Allow "naked" hash in macro definition, for example:
22284 #define DIR_LO(x) #(x & 0xff)
22289 Below is an example on how to use this pragma.
22292 \begin_layout Verse
22295 #pragma preproc_asm +
22297 #pragma sdcc_hash +
22298 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22313 mov R6_B3, #(x & 0xff)
22320 mov R7_B3, #((x >> 8) & 0xff)
22344 \begin_layout Standard
22345 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22346 ons which might cause the compiler to generate extra stack and/or data space
22347 to store compiler generated temporary variables.
22348 This usually happens in large functions.
22349 Pragma directives should be used as shown in the following example, they
22350 are used to control options and optimizations for a given function.
22354 \begin_layout Verse
22358 \begin_inset LatexCommand \index{\#pragma save}
22369 /* save the current settings */
22372 \begin_inset LatexCommand \index{\#pragma nogcse}
22381 /* turnoff global subexpression elimination */
22383 #pragma noinduction
22384 \begin_inset LatexCommand \index{\#pragma noinduction}
22388 /* turn off induction optimizations */
22411 \begin_inset LatexCommand \index{\#pragma restore}
22415 /* turn the optimizations back on */
22418 \begin_layout Standard
22419 The compiler will generate a warning message when extra space is allocated.
22420 It is strongly recommended that the save and restore pragmas be used when
22421 changing options for a function.
22430 \begin_layout Section
22431 Defines Created by the Compiler
22434 \begin_layout Standard
22435 The compiler creates the following #defines
22436 \begin_inset LatexCommand \index{\#defines}
22441 \begin_inset LatexCommand \index{Defines created by the compiler}
22450 \begin_layout Standard
22451 \begin_inset Tabular
22452 <lyxtabular version="3" rows="11" columns="2">
22454 <column alignment="left" valignment="top" leftline="true" width="3in">
22455 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22456 <row topline="true" bottomline="true">
22457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22460 \begin_layout Standard
22468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22471 \begin_layout Standard
22480 <row topline="true">
22481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22484 \begin_layout Standard
22486 \begin_inset LatexCommand \index{SDCC}
22495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22498 \begin_layout Standard
22500 Since version 2.5.6 the version number as an int (ex.
22507 <row topline="true">
22508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22511 \begin_layout Standard
22513 \begin_inset LatexCommand \index{SDCC\_mcs51}
22518 \begin_inset LatexCommand \index{SDCC\_ds390}
22523 \begin_inset LatexCommand \index{SDCC\_z80}
22532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22535 \begin_layout Standard
22536 depending on the model used (e.g.: -mds390)
22542 <row topline="true">
22543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22546 \begin_layout Standard
22548 \begin_inset LatexCommand \index{\_\_mcs51}
22553 \begin_inset LatexCommand \index{\_\_ds390}
22558 \begin_inset LatexCommand \index{\_\_hc08}
22563 \begin_inset LatexCommand \index{\_\_z80}
22572 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22575 \begin_layout Standard
22576 depending on the model used (e.g.
22583 <row topline="true">
22584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22587 \begin_layout Standard
22589 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22601 \begin_layout Standard
22608 \begin_layout Standard
22625 <row topline="true">
22626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22629 \begin_layout Standard
22631 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22643 \begin_layout Standard
22650 \begin_layout Standard
22667 <row topline="true">
22668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22671 \begin_layout Standard
22673 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22682 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22685 \begin_layout Standard
22692 \begin_layout Standard
22709 <row topline="true">
22710 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22713 \begin_layout Standard
22715 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22727 \begin_layout Standard
22734 \begin_layout Standard
22751 <row topline="true">
22752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22755 \begin_layout Standard
22757 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
22766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22769 \begin_layout Standard
22776 \begin_layout Standard
22793 <row topline="true">
22794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22797 \begin_layout Standard
22799 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
22808 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22811 \begin_layout Standard
22822 <row topline="true" bottomline="true">
22823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22826 \begin_layout Standard
22828 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
22837 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22840 \begin_layout Standard
22858 \begin_layout Chapter
22859 Notes on supported Processors
22862 \begin_layout Section
22864 \begin_inset LatexCommand \label{sub:MCS51-variants}
22869 \begin_inset LatexCommand \index{MCS51 variants}
22876 \begin_layout Standard
22877 MCS51 processors are available from many vendors and come in many different
22879 While they might differ considerably in respect to Special Function Registers
22880 the core MCS51 is usually not modified or is kept compatible.
22884 \begin_layout Subsection
22885 pdata access by SFR
22888 \begin_layout Standard
22889 With the upcome of devices with internal xdata and flash memory devices
22891 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
22895 as dedicated I/O port is becoming more popular.
22896 Switching the high byte for pdata
22897 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
22901 access which was formerly done by port P2 is then achieved by a Special
22903 \begin_inset LatexCommand \index{sfr}
22908 In well-established MCS51 tradition the address of this
22912 is where the chip designers decided to put it.
22913 Needless to say that they didn't agree on a common name either.
22914 So that the startup code can correctly initialize xdata variables, you
22915 should define an sfr with the name _XPAGE
22918 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
22924 at the appropriate location if the default, port P2, is not used for this.
22928 \begin_layout Verse
22931 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
22935 \begin_layout Verse
22938 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
22943 \begin_layout Verse
22946 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
22950 \begin_layout Verse
22953 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22957 \begin_layout Verse
22960 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22964 \begin_layout Standard
22965 For more exotic implementations further customizations may be needed.
22967 \begin_inset LatexCommand \ref{sub:Startup-Code}
22971 for other possibilities.
22974 \begin_layout Subsection
22975 Other Features available by SFR
22978 \begin_layout Standard
22979 Some MCS51 variants offer features like Double DPTR
22980 \begin_inset LatexCommand \index{DPTR}
22984 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
22985 These are currently not used for the MCS51 port.
22986 If you absolutely need them you can fall back to inline assembly or submit
22988 \begin_inset VSpace bigskip
22994 \begin_layout Section
22998 \begin_layout Standard
23000 \begin_inset LatexCommand \index{DS80C400}
23005 \begin_inset LatexCommand \index{DS400}
23009 microcontroller has a rich set of peripherals.
23010 In its built-in ROM library it includes functions to access some of the
23011 features, among them is a TCP stack with IP4 and IP6 support.
23012 Library headers (currently in beta status) and other files are provided
23016 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
23022 \begin_inset VSpace bigskip
23028 \begin_layout Section
23029 The Z80 and gbz80 port
23032 \begin_layout Standard
23033 SDCC can target both the Zilog Z80
23034 \begin_inset LatexCommand \index{Z80}
23038 and the Nintendo Gameboy's Z80-like gbz80
23039 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
23044 The Z80 port is passed through the same
23047 \begin_inset LatexCommand \index{Regression test}
23054 \begin_inset LatexCommand \ref{sec:Quality-control}
23058 ) as the MCS51 and DS390 ports, so floating point support, support for long
23059 variables and bitfield support is fine.
23060 See mailing lists and forums about interrupt routines.
23063 \begin_layout Standard
23064 As always, the code is the authoritative reference - see z80/ralloc.c and
23067 \begin_inset LatexCommand \index{Z80!stack}
23071 frame is similar to that generated by the IAR Z80 compiler.
23072 IX is used as the base pointer, HL and IY are used as a temporary registers,
23073 and BC and DE are available for holding variables.
23075 \begin_inset LatexCommand \index{Z80!return value}
23079 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
23081 The gbz80 port use the same set of registers for the return values, but
23082 in a different order of significance: E (one byte), DE (two bytes), or
23084 \begin_inset VSpace bigskip
23090 \begin_layout Section
23094 \begin_layout Standard
23095 The port to the Freescale/Motorola HC08
23096 \begin_inset LatexCommand \index{HC08}
23100 family has been added in October 2003, and is still undergoing some basic
23102 The code generator is complete, but the register allocation is still quite
23104 Some of the SDCC's standard C library functions have embedded non-HC08
23105 inline assembly and so are not yet usable.
23108 \begin_layout Standard
23109 The HC08 port passes the regression test suite (see section
23110 \begin_inset LatexCommand \ref{sec:Quality-control}
23115 \begin_inset VSpace bigskip
23123 \begin_layout Section
23125 \begin_inset LatexCommand \index{PIC14}
23132 \begin_layout Standard
23133 The PIC14 port adds support for Microchip
23134 \begin_inset LatexCommand \index{Microchip}
23139 \begin_inset Formula $^{\text{TM}}$
23143 \begin_inset LatexCommand \index{PIC14}
23148 \begin_inset Formula $^{\text{TM}}$
23151 MCUs with 14 bit wide instructions.
23152 This port is not yet mature and still lacks many features.
23153 However, it can work for simple code.
23156 \begin_layout Standard
23157 Currently supported devices include:
23160 \begin_layout Standard
23161 12F: 629, 635, 675, 683
23164 \begin_layout Standard
23168 \begin_layout Standard
23172 \begin_layout Standard
23173 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
23176 \begin_layout Standard
23177 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
23181 \begin_layout Standard
23185 \begin_layout Standard
23186 16F: 627, 627a, 628, 628a, 630, 636, 639, 648a, 676, 684, 685, 687, 688,
23190 \begin_layout Standard
23191 16F: 716, 72, 73, 737, 74, 76, 767, 77, 777, 785
23194 \begin_layout Standard
23195 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
23199 \begin_layout Standard
23200 16F: 913, 914, 916, 917
23203 \begin_layout Standard
23204 An up-to-date list of currently supported devices can be obtained via
23206 sdcc -mpic14 -phelp foo.c
23208 (foo.c must exist...).
23211 \begin_layout Subsection
23213 \begin_inset LatexCommand \index{code page (pic14)}
23218 \begin_inset LatexCommand \index{Memory bank (pic14)}
23225 \begin_layout Standard
23226 The linker organizes allocation for the code page and RAM banks.
23227 It does not have intimate knowledge of the code flow.
23228 It will put all the code section of a single .asm file into a single code
23230 In order to make use of multiple code pages, separate asm files must be
23232 The compiler assigns all
23236 functions of a single .c file into the same code page.
23240 To get the best results,
23241 follow these guidelines:
23244 \begin_layout Enumerate
23245 Make local functions static, as non static functions require code page selection
23248 Due to the way sdcc handles functions, place called functions prior
23249 to calling functions in the file wherever possible: Otherwise sdcc will
23250 insert unneccessary pagesel directives around the call, believing that
23251 the called function is externally defined.
23254 \begin_layout Enumerate
23255 For devices that have multiple code pages it is more efficient to use the
23256 same number of files as pages: Use up to 4 separate .c files for the 16F877,
23257 but only 2 files for the 16F874.
23258 This way the linker can put the code for each file into different code
23259 pages and there will be less page selection overhead.
23262 \begin_layout Enumerate
23263 And as for any 8 bit micro (especially for PIC14 as they have a very simple
23264 instruction set), use `unsigned char' wherever possible instead of `int'.
23267 \begin_layout Subsection
23268 Adding New Devices to the Port
23271 \begin_layout Standard
23272 Adding support for a new 14
23276 \begin_layout Standard
23285 bit PIC MCU requires the following steps:
23288 \begin_layout Enumerate
23289 Create a new device description.
23291 Each device is described in two files: pic16f*.h
23293 These files primarily define SFRs, structs to access their bits, and symbolic
23294 configuration options.
23295 Both files can be generated from gputils' .inc files using the perl script
23298 support/scripts/inc2h.pl
23301 This file also contains further instructions on how to proceed.
23304 \begin_layout Enumerate
23305 Copy the .h file into SDCC's include path and either add the .c file to your
23306 project or copy it to
23308 device/lib/pic/libdev
23311 Afterwards, rebuild and install the libraries.
23314 \begin_layout Enumerate
23315 Edit pic14devices.txt in SDCC's include path (
23317 device/include/pic/
23319 in the source tree or
23321 /usr/local/share/sdcc/include/pic
23323 after installation).
23325 You need to add a device specification here to make
23326 the memory layout (code banks, RAM, aliased memory regions, ...) known to
23328 Probably you can copy and modify an existing entry.
23329 The file format is documented at the top of the file.
23332 \begin_layout Subsection
23336 \begin_layout Standard
23337 For the interrupt function, use the keyword `__interrupt'
23338 \begin_inset LatexCommand \index{PIC14!interrupt}
23342 with level number of 0 (PIC14 only has 1 interrupt so this number is only
23343 there to avoid a syntax error - it ought to be fixed).
23347 \begin_layout Verse
23350 void Intr(void) __interrupt 0
23356 T0IF = 0; /* Clear timer interrupt */
23361 \begin_layout Subsection
23362 Linking and Assembling
23365 \begin_layout Standard
23366 For assembling you can use either GPUTILS'
23367 \begin_inset LatexCommand \index{gputils (pic tools)}
23371 gpasm.exe or MPLAB's mpasmwin.exe.
23372 GPUTILS are available from
23373 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23378 For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
23379 If you use MPLAB and an interrupt function then the linker script file
23380 vectors section will need to be enlarged to link with mplink.
23391 \begin_layout Verse
23404 sdcc -V -mpic14 -p16f877 -c $<
23408 $(PRJ).hex: $(OBJS)
23418 gplink -m -s $(PRJ).lkr
23419 -o $(PRJ).hex $(OBJS) libsdcc.lib
23422 \begin_layout Standard
23430 \begin_layout Verse
23443 sdcc -S -V -mpic14 -p16f877 $<
23453 mpasmwin /q /o $*.asm
23457 $(PRJ).hex: $(OBJS)
23468 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
23471 \begin_layout Standard
23472 Please note that indentations within a
23476 have to be done with a tabulator character.
23479 \begin_layout Subsection
23480 Command-Line Options
23483 \begin_layout Standard
23484 Besides the switches common to all SDCC backends, the PIC14 port accepts
23485 the following options (for an updated list see sdcc -
23489 \begin_layout Standard
23501 \begin_layout Description
23506 \begin_layout Standard
23516 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
23520 emit debug info in assembly output
23523 \begin_layout Description
23528 \begin_layout Standard
23538 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
23542 disable (slightly faulty) optimization on pCode
23545 \begin_layout Description
23550 \begin_layout Standard
23560 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
23564 sets the lowest address of the argument passing stack (defaults to a suitably
23565 large shared databank to reduce BANKSEL overhead)
23568 \begin_layout Description
23573 \begin_layout Standard
23583 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
23587 sets the size if the argument passing stack (default: 16, minimum: 4)
23590 \begin_layout Subsection
23591 Environment Variables
23594 \begin_layout Standard
23595 The PIC14 port recognizes the following environment variables:
23598 \begin_layout Description
23599 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
23600 register (the ones called r0xNNNN) in a section of its own.
23601 By default (if this variable is unset), sdcc tries to cluster registers
23602 in sections in order to reduce the BANKSEL overhead when accessing them.
23605 \begin_layout Subsection
23609 \begin_layout Standard
23610 The PIC14 library currently only contains support routines required by the
23611 compiler to implement multiplication, division, and floating point support.
23612 No libc-like replacement is available at the moment, though many of the
23613 common sdcc library sources (in
23617 ) should also compile with the PIC14 port.
23620 \begin_layout Subsubsection
23621 error: missing definition for symbol ``__gptrget1''
23624 \begin_layout Standard
23625 The PIC14 port uses library routines to provide more complex operations
23626 like multiplication, division/modulus and (generic) pointer dereferencing.
23627 In order to add these routines to your project, you must link with PIC14's
23633 For single source file projects this is done automatically, more complex
23638 to the linker's arguments.
23639 Make sure you also add an include path for the library (using the -I switch
23643 \begin_layout Subsubsection
23644 Processor mismatch in file ``XXX''.
23647 \begin_layout Standard
23648 This warning can usually be ignored due to the very good compatibility amongst
23653 \begin_layout Standard
23663 \begin_inset LatexCommand \index{PIC14}
23670 \begin_layout Standard
23671 You might also consider recompiling the library for your specific device
23672 by changing the ARCH=p16f877 (default target) entry in
23674 device/lib/pic/Makefile.in
23678 device/lib/pic/Makefile
23680 to reflect your device.
23681 This might even improve performance for smaller devices as unneccesary
23682 BANKSELs might be removed.
23685 \begin_layout Subsection
23689 \begin_layout Subsubsection
23693 \begin_layout Standard
23694 Functions with variable argument lists (like printf) are not yet supported.
23695 Similarly, taking the argument of the first argument passed into a function
23696 does not work: It is currently passed in WREG and has no address...
23699 \begin_layout Subsubsection
23700 Regression tests fail
23703 \begin_layout Standard
23704 Though the small subset of regression tests in src/regression passes, SDCC
23705 regression test suite does not, indicating that there are still major bugs
23707 However, many smaller projects have successfully used SDCC in the past...
23710 \begin_layout Standard
23718 \begin_layout Section
23720 \begin_inset LatexCommand \index{PIC16}
23727 \begin_layout Standard
23728 The PIC16 port adds support for Microchip
23729 \begin_inset LatexCommand \index{Microchip}
23734 \begin_inset Formula $^{\text{TM}}$
23738 \begin_inset LatexCommand \index{PIC}
23743 \begin_inset Formula $^{\text{TM}}$
23746 MCUs with 16 bit wide instructions.
23747 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
23748 ; devices supported by the port include:
23751 \begin_layout Standard
23752 18F: 242, 248, 252, 258, 442, 448, 452, 458
23755 \begin_layout Standard
23759 \begin_layout Standard
23760 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 24j10, 2525, 2550, 25j10,
23764 \begin_layout Standard
23765 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 44j10, 4520, 4525, 4550,
23769 \begin_layout Standard
23770 18F: 6520, 6620, 6680, 6720
23773 \begin_layout Standard
23774 18F: 8520, 8620, 8680, 8720
23777 \begin_layout Subsection
23781 \begin_layout Standard
23782 PIC16 port supports the standard command line arguments as supposed, with
23783 the exception of certain cases that will be mentioned in the following
23787 \begin_layout Description
23792 \begin_layout Standard
23802 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
23810 \begin_layout Standard
23822 \begin_layout Description
23827 \begin_layout Standard
23836 -fommit-frame-pointer
23837 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
23841 Frame pointer will be omitted when the function uses no local variables.
23844 \begin_layout Subsection
23845 Port Specific Options
23846 \begin_inset LatexCommand \index{Options PIC16}
23853 \begin_layout Standard
23854 The port specific options appear after the global options in the sdcc -
23858 \begin_layout Standard
23870 \begin_layout Subsubsection
23871 Code Generation Options
23874 \begin_layout Standard
23875 These options influence the generated assembler code.
23878 \begin_layout Description
23883 \begin_layout Standard
23892 -pstack-model=[model] Used in conjuction with the command above.
23893 Defines the stack model to be used, valid stack models are:
23898 \labelwidthstring 00.00.0000
23903 Selects small stack model.
23904 8 bit stack and frame pointers.
23905 Supports 256 bytes stack size.
23909 \labelwidthstring 00.00.0000
23914 Selects large stack model.
23915 16 bit stack and frame pointers.
23916 Supports 65536 bytes stack size.
23920 \begin_layout Description
23925 \begin_layout Standard
23934 -pno-banksel Do not generate BANKSEL assembler directives.
23937 \begin_layout Description
23942 \begin_layout Standard
23951 -extended Enable extended instruction set/literal offset addressing mode.
23955 \begin_layout Subsubsection
23956 Optimization Options
23959 \begin_layout Description
23964 \begin_layout Standard
23973 -obanksel=n Set optimization level for inserting BANKSELs.
23980 \labelwidthstring 00.00.0000
23985 \labelwidthstring 00.00.0000
23986 1 checks previous used register and if it is the same then does not emit
23987 BANKSEL, accounts only for labels.
23991 \labelwidthstring 00.00.0000
23992 2 tries to check the location of (even different) symbols and removes BANKSELs
23993 if they are in the same bank.
23998 Important: There might be problems if the linker script has data sections
23999 across bank borders!
24003 \begin_layout Description
24008 \begin_layout Standard
24017 -denable-peeps Force the usage of peepholes.
24021 \begin_layout Description
24026 \begin_layout Standard
24035 -optimize-goto Try to use (conditional) BRA instead of GOTO.
24038 \begin_layout Description
24043 \begin_layout Standard
24052 -optimize-cmp Try to optimize some compares.
24055 \begin_layout Description
24060 \begin_layout Standard
24069 -optimize-df Analyze the dataflow of the generated code and improve it.
24072 \begin_layout Subsubsection
24076 \begin_layout Description
24081 \begin_layout Standard
24090 -asm= Sets the full path and name of an external assembler to call.
24093 \begin_layout Description
24098 \begin_layout Standard
24108 \begin_inset LatexCommand \index{PIC16!MPLAB}
24112 compatibility option.
24113 Currently only suppresses special gpasm directives.
24116 \begin_layout Subsubsection
24120 \begin_layout Description
24125 \begin_layout Standard
24134 -link= Sets the full path and name of an external linker to call.
24137 \begin_layout Description
24142 \begin_layout Standard
24151 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
24152 unitialized data variables with [kword].
24153 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
24156 \begin_layout Description
24161 \begin_layout Standard
24170 -ivt-loc=n Place the interrupt vector table at address
24175 Useful for bootloaders.
24178 \begin_layout Description
24183 \begin_layout Standard
24192 -nodefaultlibs Do not link default libraries when linking.
24195 \begin_layout Description
24200 \begin_layout Standard
24209 -use-crt= Use a custom run-time module instead of the defaults.
24212 \begin_layout Description
24217 \begin_layout Standard
24226 -no-crt Don't link the default run-time modules
24229 \begin_layout Subsubsection
24233 \begin_layout Standard
24234 Debugging options enable extra debugging information in the output files.
24237 \begin_layout Description
24242 \begin_layout Standard
24251 -debug-xtra Similar to -
24255 \begin_layout Standard
24265 \begin_inset LatexCommand \index{-\/-debug}
24269 , but dumps more information.
24272 \begin_layout Description
24277 \begin_layout Standard
24286 -debug-ralloc Force register allocator to dump <source>.d file with debugging
24288 <source> is the name of the file being compiled.
24291 \begin_layout Description
24296 \begin_layout Standard
24305 -pcode-verbose Enable pcode debugging information in translation.
24308 \begin_layout Description
24313 \begin_layout Standard
24322 -calltree Dump call tree in .calltree file.
24325 \begin_layout Description
24330 \begin_layout Standard
24339 -gstack Trace push/pops for stack pointer overflow.
24342 \begin_layout Subsection
24343 Enviroment Variables
24346 \begin_layout Standard
24347 There is a number of enviromental variables that can be used when running
24348 SDCC to enable certain optimizations or force a specific program behaviour.
24349 these variables are primarily for debugging purposes so they can be enabled/dis
24353 \begin_layout Standard
24354 Currently there is only two such variables available:
24357 \begin_layout Description
24358 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
24359 bitfields is optimized by directly loading FSR0 with the address of the
24360 bitfield structure.
24361 Normally SDCC will cast the bitfield structure to a bitfield pointer and
24363 This step saves data ram and code space for functions that make heavy use
24365 (i.e., 80 bytes of code space are saved when compiling malloc.c with this
24370 \begin_layout Description
24371 NO_REG_OPT Do not perform pCode registers optimization.
24372 This should be used for debugging purposes.
24373 If bugs in the pcode optimizer are found, users can benefit from temporarily
24374 disabling the optimizer until the bug is fixed.
24377 \begin_layout Subsection
24378 Preprocessor Macros
24381 \begin_layout Standard
24383 \begin_inset LatexCommand \index{PIC16}
24387 port defines the following preprocessor macros while translating a source.
24390 \begin_layout Standard
24392 \begin_inset Tabular
24393 <lyxtabular version="3" rows="6" columns="2">
24395 <column alignment="center" valignment="top" leftline="true" width="0">
24396 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24397 <row topline="true" bottomline="true">
24398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24401 \begin_layout Standard
24407 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24410 \begin_layout Standard
24417 <row topline="true">
24418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24421 \begin_layout Standard
24427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24430 \begin_layout Standard
24431 Port identification
24437 <row topline="true">
24438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24441 \begin_layout Standard
24446 \begin_layout Standard
24460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24463 \begin_layout Standard
24464 Port identification (same as above)
24470 <row topline="true">
24471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24474 \begin_layout Standard
24480 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24483 \begin_layout Standard
24484 MCU Identification.
24489 is the microcontrol identification number, i.e.
24496 <row topline="true">
24497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24500 \begin_layout Standard
24505 \begin_layout Standard
24519 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24522 \begin_layout Standard
24523 MCU Identification (same as above)
24529 <row topline="true" bottomline="true">
24530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24533 \begin_layout Standard
24539 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24542 \begin_layout Standard
24543 nnn = SMALL or LARGE respectively according to the stack model used
24556 \begin_layout Standard
24557 In addition the following macros are defined when calling assembler:
24560 \begin_layout Standard
24562 \begin_inset Tabular
24563 <lyxtabular version="3" rows="4" columns="2">
24565 <column alignment="center" valignment="top" leftline="true" width="0">
24566 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24567 <row topline="true" bottomline="true">
24568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24571 \begin_layout Standard
24577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24580 \begin_layout Standard
24587 <row topline="true">
24588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24591 \begin_layout Standard
24597 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24600 \begin_layout Standard
24601 MCU Identification.
24606 is the microcontrol identification number, i.e.
24613 <row topline="true">
24614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24617 \begin_layout Standard
24623 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24626 \begin_layout Standard
24627 nnn = SMALL or LARGE respectively according to the memory model used for
24634 <row topline="true" bottomline="true">
24635 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24638 \begin_layout Standard
24644 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24647 \begin_layout Standard
24648 nnn = SMALL or LARGE respectively according to the stack model used
24661 \begin_layout Subsection
24665 \begin_layout Standard
24667 \begin_inset LatexCommand \index{PIC16}
24671 port uses the following directories for searching header files and libraries.
24674 \begin_layout Standard
24676 \begin_inset Tabular
24677 <lyxtabular version="3" rows="3" columns="4">
24679 <column alignment="center" valignment="top" leftline="true" width="0">
24680 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24681 <column alignment="center" valignment="top" width="0">
24682 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24683 <row topline="true" bottomline="true">
24684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24687 \begin_layout Standard
24693 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24696 \begin_layout Standard
24702 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24705 \begin_layout Standard
24711 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24714 \begin_layout Standard
24721 <row topline="true">
24722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24725 \begin_layout Standard
24726 PREFIX/sdcc/include/pic16
24731 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24734 \begin_layout Standard
24735 PIC16 specific headers
24740 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24743 \begin_layout Standard
24749 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24752 \begin_layout Standard
24759 <row topline="true" bottomline="true">
24760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24763 \begin_layout Standard
24764 PREFIX/sdcc/lib/pic16
24769 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24772 \begin_layout Standard
24773 PIC16 specific libraries
24778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24781 \begin_layout Standard
24787 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24790 \begin_layout Standard
24804 \begin_layout Subsection
24806 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
24813 \begin_layout Standard
24815 \begin_inset LatexCommand \index{PIC16}
24819 port currently supports the following pragmas:
24822 \begin_layout Description
24824 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
24828 This forces the code generator to initialize the stack & frame pointers
24829 at a specific address.
24830 This is an ad hoc solution for cases where no STACK directive is available
24831 in the linker script or gplink is not instructed to create a stack section.
24834 stack pragma should be used only once in a project.
24835 Multiple pragmas may result in indeterminate behaviour of the program.
24839 \begin_layout Standard
24840 The old format (ie.
24841 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
24842 cross page boundaries (or even exceed the available data RAM) and crash
24844 Make sure that stack does not cross page boundaries when using the SMALL
24852 The format is as follows:
24857 \begin_layout LyX-Code
24858 #pragma stack bottom_address [stack_size]
24863 \begin_layout Standard
24868 is the lower bound of the stack section.
24869 The stack pointer initially will point at address (bottom_address+stack_size-1).
24872 \begin_layout LyX-Code
24876 \begin_layout LyX-Code
24880 \begin_layout LyX-Code
24881 /* initializes stack of 100 bytes at RAM address 0x200 */
24884 \begin_layout LyX-Code
24885 #pragma stack 0x200 100
24888 \begin_layout Standard
24889 If the stack_size field is omitted then a stack is created with the default
24891 This size might be enough for most programs, but its not enough for operations
24892 with deep function nesting or excessive stack usage.
24895 \begin_layout Description
24897 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
24901 Force a function to a static FLASH address.
24904 \begin_layout LyX-Code
24908 \begin_layout LyX-Code
24912 \begin_layout LyX-Code
24913 /* place function test_func at 0x4000 */
24916 \begin_layout LyX-Code
24917 #pragma code test_func 0x4000
24920 \begin_layout LyX-Code
24924 \begin_layout Description
24925 library instructs the linker to use a library module.
24930 \begin_layout LyX-Code
24931 #pragma library module_name
24934 \begin_layout Standard
24939 can be any library or object file (including its path).
24940 Note that there are four reserved keywords which have special meaning.
24944 \begin_layout Standard
24946 \begin_inset Tabular
24947 <lyxtabular version="3" rows="6" columns="3">
24949 <column alignment="center" valignment="top" leftline="true" width="0">
24950 <column alignment="block" valignment="top" leftline="true" width="20page%">
24951 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
24952 <row topline="true" bottomline="true">
24953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24956 \begin_layout Standard
24962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24965 \begin_layout Standard
24971 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24974 \begin_layout Standard
24981 <row topline="true">
24982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24985 \begin_layout Standard
24993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24996 \begin_layout Standard
24997 ignore all library pragmas
25002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25005 \begin_layout Standard
25014 <row topline="true">
25015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25018 \begin_layout Standard
25026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25029 \begin_layout Standard
25035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25038 \begin_layout Standard
25049 <row topline="true">
25050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25053 \begin_layout Standard
25061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25064 \begin_layout Standard
25065 link the Math libarary
25070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25073 \begin_layout Standard
25084 <row topline="true">
25085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25088 \begin_layout Standard
25096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25099 \begin_layout Standard
25100 link the I/O library
25105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25108 \begin_layout Standard
25119 <row topline="true" bottomline="true">
25120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25123 \begin_layout Standard
25131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25134 \begin_layout Standard
25135 link the debug library
25140 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25143 \begin_layout Standard
25160 * is the device number, i.e.
25161 452 for PIC18F452 MCU.
25164 \begin_layout Standard
25165 This feature allows for linking with specific libraries withoug having to
25166 explicit name them in the command line.
25171 keyword will reject all modules specified by the library pragma.
25174 \begin_layout Description
25175 udata The pragma udata instructs the compiler to emit code so that linker
25176 will place a variable at a specific memory bank.
25179 \begin_layout LyX-Code
25183 \begin_layout LyX-Code
25187 \begin_layout LyX-Code
25188 /* places variable foo at bank2 */
25191 \begin_layout LyX-Code
25192 #pragma udata bank2 foo
25195 \begin_layout LyX-Code
25199 \begin_layout Standard
25200 In order for this pragma to work extra SECTION directives should be added
25201 in the .lkr script.
25202 In the following example a sample .lkr file is shown:
25205 \begin_layout LyX-Code
25209 \begin_layout LyX-Code
25210 // Sample linker script for the PIC18F452 processor
25213 \begin_layout LyX-Code
25217 \begin_layout LyX-Code
25218 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
25221 \begin_layout LyX-Code
25222 CODEPAGE NAME=page START=0x2A END=0x7FFF
25225 \begin_layout LyX-Code
25226 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
25229 \begin_layout LyX-Code
25230 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
25233 \begin_layout LyX-Code
25234 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
25237 \begin_layout LyX-Code
25238 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
25241 \begin_layout LyX-Code
25242 ACCESSBANK NAME=accessram START=0x0 END=0x7F
25245 \begin_layout LyX-Code
25249 \begin_layout LyX-Code
25250 DATABANK NAME=gpr0 START=0x80 END=0xFF
25253 \begin_layout LyX-Code
25254 DATABANK NAME=gpr1 START=0x100 END=0x1FF
25257 \begin_layout LyX-Code
25258 DATABANK NAME=gpr2 START=0x200 END=0x2FF
25261 \begin_layout LyX-Code
25262 DATABANK NAME=gpr3 START=0x300 END=0x3FF
25265 \begin_layout LyX-Code
25266 DATABANK NAME=gpr4 START=0x400 END=0x4FF
25269 \begin_layout LyX-Code
25270 DATABANK NAME=gpr5 START=0x500 END=0x5FF
25273 \begin_layout LyX-Code
25274 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
25277 \begin_layout LyX-Code
25281 \begin_layout LyX-Code
25282 SECTION NAME=CONFIG ROM=config
25285 \begin_layout LyX-Code
25289 \begin_layout LyX-Code
25290 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
25293 \begin_layout LyX-Code
25294 SECTION NAME=bank1 RAM=gpr1 # should be added to link
25297 \begin_layout LyX-Code
25298 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
25301 \begin_layout LyX-Code
25302 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
25305 \begin_layout LyX-Code
25306 SECTION NAME=bank4 RAM=gpr4
25309 \begin_layout LyX-Code
25310 SECTION NAME=bank5 RAM=gpr5
25313 \begin_layout Standard
25314 The linker will recognise the section name set in the pragma statement and
25315 will position the variable at the memory bank set with the RAM field at
25316 the SECTION line in the linker script file.
25319 \begin_layout Subsection
25321 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
25328 \begin_layout Standard
25329 There is one main header file
25330 \begin_inset LatexCommand \index{PIC16!Header files}
25334 that can be included to the source files using the pic16
25335 \begin_inset LatexCommand \index{PIC16}
25345 This header file contains the definitions for the processor special registers,
25346 so it is necessary if the source accesses them.
25347 It can be included by adding the following line in the beginning of the
25351 \begin_layout LyX-Code
25352 #include <pic18fregs.h>
25355 \begin_layout Standard
25356 The specific microcontroller is selected within the pic18fregs.h automatically,
25357 so the same source can be used with a variety of devices.
25360 \begin_layout Subsection
25364 \begin_layout Standard
25366 \begin_inset LatexCommand \index{PIC16!Libraries}
25371 \begin_inset LatexCommand \index{PIC16}
25375 port depends on are the microcontroller device libraries which contain
25376 the symbol definitions for the microcontroller special function registers.
25377 These libraries have the format pic18fxxxx.lib, where
25381 is the microcontroller identification number.
25382 The specific library is selected automatically by the compiler at link
25383 stage according to the selected device.
25386 \begin_layout Standard
25387 Libraries are created with gplib which is part of the gputils package
25388 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
25395 \begin_layout Subsubsection*
25396 Building the libraries
25399 \begin_layout Standard
25400 Before using SDCC/pic16 there are some libraries that need to be compiled.
25401 This process is not done automatically by SDCC since not all users use
25402 SDCC for pic16 projects.
25403 So each user should compile the libraries separately.
25406 \begin_layout Standard
25407 The steps to compile the pic16 libraries under Linux and Mac OS X are:
25410 \begin_layout LyX-Code
25411 cd device/lib/pic16
25414 \begin_layout LyX-Code
25418 \begin_layout LyX-Code
25422 \begin_layout LyX-Code
25426 \begin_layout LyX-Code
25430 \begin_layout LyX-Code
25431 su -c 'make install' # install the libraries, you need the root password
25434 \begin_layout Standard
25435 If you need to install the headers too, do:
25438 \begin_layout LyX-Code
25442 \begin_layout LyX-Code
25443 su -c 'make install' # install the headers, you need the root password
25446 \begin_layout Standard
25447 There exist a special target to build the I/O libraries.
25448 This target is not automatically build because it will build the I/O library
25454 This way building will take quite a lot of time.
25455 Users are advised to edit the
25457 device/lib/pic16/pics.build
25459 file and then execute:
25462 \begin_layout LyX-Code
25466 \begin_layout Subsection
25467 Adding New Devices to the Port
25470 \begin_layout Standard
25471 Adding support for a new 16
25475 \begin_layout Standard
25484 bit PIC MCU requires the following steps:
25487 \begin_layout Enumerate
25488 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
25492 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
25496 \begin_layout Enumerate
25499 mv picDEVICE.h /path/to/sdcc/device/include/pic16
25502 \begin_layout Enumerate
25505 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
25508 \begin_layout Enumerate
25511 /path/to/sdcc/device/lib/pics.all
25519 Note: No 18f prefix here!
25522 \begin_layout Enumerate
25525 /path/to/sdcc/device/lib/pic16/libio/*.ignore
25529 Add your DEVICE if it does not compile in
25544 \begin_layout Enumerate
25547 /path/to/sdcc/device/include/pic16/pic18fregs.h
25550 The file format is self-explanatory, just add
25554 #elif defined(picDEVICE)
25556 # include <picDEVICE.h>
25560 at the right place (keep it sorted).
25563 \begin_layout Enumerate
25566 /path/to/sdcc/src/pic16/devices.inc
25569 Copy and modify an existing entry and insert it at the correct place (keep
25571 The file is hardly documented, look at the entries for the 18f2221...
25574 \begin_layout Enumerate
25575 Recompile SDCC, including the pic16 libraries.
25578 \begin_layout Subsection
25582 \begin_layout Standard
25583 The following memory models are supported by the PIC16 port:
25586 \begin_layout Itemize
25590 \begin_layout Itemize
25594 \begin_layout Standard
25595 Memory model affects the default size of pointers within the source.
25596 The sizes are shown in the next table:
25599 \begin_layout Standard
25601 \begin_inset Tabular
25602 <lyxtabular version="3" rows="3" columns="3">
25604 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25605 <column alignment="center" valignment="top" leftline="true" width="0">
25606 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25607 <row topline="true" bottomline="true">
25608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25611 \begin_layout Standard
25612 Pointer sizes according to memory model
25617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25620 \begin_layout Standard
25626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25629 \begin_layout Standard
25636 <row topline="true" bottomline="true">
25637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25640 \begin_layout Standard
25646 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25649 \begin_layout Standard
25655 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25658 \begin_layout Standard
25665 <row topline="true" bottomline="true">
25666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25669 \begin_layout Standard
25675 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
25678 \begin_layout Standard
25684 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25687 \begin_layout Standard
25701 \begin_layout Standard
25702 It is advisable that all sources within a project are compiled with the
25704 If one wants to override the default memory model, this can be done by
25705 declaring a pointer as
25714 Far selects large memory model's pointers, while near selects small memory
25718 \begin_layout Standard
25719 The standard device libraries (see
25720 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
25724 ) contain no reference to pointers, so they can be used with both memory
25728 \begin_layout Subsection
25732 \begin_layout Standard
25734 \begin_inset LatexCommand \index{PIC16!stack}
25738 implementation for the PIC16 port uses two indirect registers, FSR1 and
25742 \begin_layout Description
25743 FSR1 is assigned as stack pointer
25746 \begin_layout Description
25747 FSR2 is assigned as frame pointer
25750 \begin_layout Standard
25751 The following stack models are supported by the PIC16 port
25754 \begin_layout Itemize
25762 \begin_layout Itemize
25770 \begin_layout Standard
25775 model means that only the FSRxL byte is used to access stack and frame,
25782 uses both FSRxL and FSRxH registers.
25783 The following table shows the stack/frame pointers sizes according to stack
25784 model and the maximum space they can address:
25787 \begin_layout Standard
25789 \begin_inset Tabular
25790 <lyxtabular version="3" rows="3" columns="3">
25792 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25793 <column alignment="center" valignment="top" leftline="true" width="0">
25794 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25795 <row topline="true" bottomline="true">
25796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25799 \begin_layout Standard
25800 Stack & Frame pointer sizes according to stack model
25805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25808 \begin_layout Standard
25814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25817 \begin_layout Standard
25824 <row topline="true">
25825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25828 \begin_layout Standard
25834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25837 \begin_layout Standard
25843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25846 \begin_layout Standard
25853 <row topline="true" bottomline="true">
25854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25857 \begin_layout Standard
25863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25866 \begin_layout Standard
25872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25875 \begin_layout Standard
25889 \begin_layout Standard
25894 stack model is currently not working properly throughout the code generator.
25895 So its use is not advised.
25896 Also there are some other points that need special care:
25901 \begin_layout Enumerate
25902 Do not create stack sections with size more than one physical bank (that
25906 \begin_layout Enumerate
25907 Stack sections should no cross physical bank limits (i.e.
25908 #pragma stack 0x50 0x100)
25911 \begin_layout Standard
25912 These limitations are caused by the fact that only FSRxL is modified when
25913 using SMALL stack model, so no more than 256 bytes of stack can be used.
25914 This problem will disappear after LARGE model is fully implemented.
25917 \begin_layout Subsection
25921 \begin_layout Standard
25922 In addition to the standard SDCC function keywords, PIC16
25923 \begin_inset LatexCommand \index{PIC16}
25927 port makes available two more:
25930 \begin_layout Description
25932 \begin_inset LatexCommand \index{PIC16!wparam}
25936 Use the WREG to pass one byte of the first function argument.
25937 This improves speed but you may not use this for functions with arguments
25938 that are called via function pointers, otherwise the first byte of the
25939 first parameter will get lost.
25943 \begin_layout LyX-Code
25944 void func_wparam(int a) wparam
25947 \begin_layout LyX-Code
25951 \begin_layout LyX-Code
25952 /* WREG hold the lower part of a */
25955 \begin_layout LyX-Code
25956 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
25960 \begin_layout LyX-Code
25964 \begin_layout LyX-Code
25968 \begin_layout Description
25970 \begin_inset LatexCommand \index{PIC16!shadowregs}
25974 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
25975 hardware shadow registers which hold the values of WREG, STATUS and BSR
25977 This can be done by adding the keyword
25985 keyword in the function's header.
25988 \begin_layout LyX-Code
25989 void isr_shadow(void) shadowregs interrupt 1
25992 \begin_layout LyX-Code
25996 \begin_layout LyX-Code
26000 \begin_layout LyX-Code
26004 \begin_layout Standard
26009 instructs the code generator not to store/restore WREG, STATUS, BSR when
26010 entering/exiting the ISR.
26013 \begin_layout Subsection
26014 Function return values
26017 \begin_layout Standard
26018 Return values from functions are placed to the appropriate registers following
26019 a modified Microchip policy optimized for SDCC.
26020 The following table shows these registers:
26023 \begin_layout Standard
26025 \begin_inset Tabular
26026 <lyxtabular version="3" rows="6" columns="2">
26028 <column alignment="center" valignment="top" leftline="true" width="0">
26029 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26030 <row topline="true" bottomline="true">
26031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26034 \begin_layout Standard
26040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26043 \begin_layout Standard
26044 destination register
26050 <row topline="true">
26051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26054 \begin_layout Standard
26060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26063 \begin_layout Standard
26070 <row topline="true">
26071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26074 \begin_layout Standard
26080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26083 \begin_layout Standard
26090 <row topline="true">
26091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26094 \begin_layout Standard
26100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26103 \begin_layout Standard
26110 <row topline="true">
26111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26114 \begin_layout Standard
26120 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26123 \begin_layout Standard
26124 FSR0L:PRODH:PRODL:WREG
26130 <row topline="true" bottomline="true">
26131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26134 \begin_layout Standard
26140 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26143 \begin_layout Standard
26144 on stack, FSR0 points to the beginning
26157 \begin_layout Subsection
26161 \begin_layout Standard
26163 \begin_inset LatexCommand \index{PIC16!interrupt}
26167 service routine (ISR) is declared using the
26174 \begin_layout LyX-Code
26175 void isr(void) interrupt
26180 \begin_layout LyX-Code
26184 \begin_layout LyX-Code
26188 \begin_layout LyX-Code
26192 \begin_layout Standard
26197 is the interrupt number, which for PIC18F devices can be:
26200 \begin_layout Standard
26202 \begin_inset Tabular
26203 <lyxtabular version="3" rows="4" columns="3">
26205 <column alignment="center" valignment="top" leftline="true" width="0">
26206 <column alignment="center" valignment="top" leftline="true" width="0">
26207 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26208 <row topline="true" bottomline="true">
26209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26212 \begin_layout Standard
26220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26223 \begin_layout Standard
26229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26232 \begin_layout Standard
26233 Interrupt Vector Address
26239 <row topline="true">
26240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26243 \begin_layout Standard
26249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26252 \begin_layout Standard
26258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26261 \begin_layout Standard
26268 <row topline="true">
26269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26272 \begin_layout Standard
26287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26290 \begin_layout Standard
26300 HIGH priority interrupts
26305 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26308 \begin_layout Standard
26315 <row topline="true" bottomline="true">
26316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26319 \begin_layout Standard
26325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26328 \begin_layout Standard
26329 LOW priority interrupts
26334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26337 \begin_layout Standard
26351 \begin_layout Standard
26352 When generating assembly code for ISR the code generator places a
26358 Interrupt Vector Address
26360 which points at the genetated ISR.
26361 This single GOTO instruction is part of an automatically generated
26363 interrupt entry point
26366 The actuall ISR code is placed as normally would in the code space.
26367 Upon interrupt request, the GOTO instruction is executed which jumps to
26369 When declaring interrupt functions as _naked this GOTO instruction is
26374 The whole interrupt functions is therefore placed at the Interrupt Vector
26375 Address of the specific interrupt.
26376 This is not a problem for the LOW priority interrupts, but it is a problem
26377 for the RESET and the HIGH priority interrupts because code may be written
26378 at the next interrupt's vector address and cause undeterminate program
26379 behaviour if that interrupt is raised.
26383 \begin_layout Standard
26384 This is not a problem when
26387 \begin_layout Enumerate
26388 this is a HIGH interrupt ISR and LOW interrupts are
26395 \begin_layout Enumerate
26396 when the ISR is small enough not to reach the next interrupt's vector address.
26404 \begin_layout Standard
26410 This way a function is generated similar to an ISR, but it is not assigned
26414 \begin_layout Standard
26415 When entering an interrupt, currently the PIC16
26416 \begin_inset LatexCommand \index{PIC16}
26420 port automatically saves the following registers:
26423 \begin_layout Itemize
26427 \begin_layout Itemize
26431 \begin_layout Itemize
26435 \begin_layout Itemize
26436 PROD (PRODL and PRODH)
26439 \begin_layout Itemize
26440 FSR0 (FSR0L and FSR0H)
26443 \begin_layout Standard
26444 These registers are restored upon return from the interrupt routine.
26448 \begin_layout Standard
26449 NOTE that when the _naked attribute is specified for an interrupt routine,
26450 then NO registers are stored or restored.
26458 \begin_layout Subsection
26462 \begin_layout Standard
26463 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
26464 There are 3 types of generic pointers currently implemented data, code
26465 and eeprom pointers.
26466 They are differentiated by the value of the 7th and 6th bits of the upper
26470 \begin_layout Standard
26472 \begin_inset Tabular
26473 <lyxtabular version="3" rows="5" columns="5">
26475 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26476 <column alignment="center" valignment="top" width="0">
26477 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26478 <column alignment="center" valignment="top" width="0">
26479 <column alignment="left" valignment="top" rightline="true" width="0">
26480 <row topline="true" bottomline="true">
26481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26484 \begin_layout Standard
26490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26493 \begin_layout Standard
26499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26502 \begin_layout Standard
26508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26511 \begin_layout Standard
26512 rest of the pointer
26517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26520 \begin_layout Standard
26527 <row topline="true" bottomline="true">
26528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26531 \begin_layout Standard
26537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26540 \begin_layout Standard
26546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26549 \begin_layout Standard
26555 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26558 \begin_layout Standard
26563 uuuuuu uuuuxxxx xxxxxxxx
26568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26571 \begin_layout Standard
26572 a 12-bit data pointer in data RAM memory
26578 <row bottomline="true">
26579 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26582 \begin_layout Standard
26588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26591 \begin_layout Standard
26597 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26600 \begin_layout Standard
26606 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26609 \begin_layout Standard
26614 uxxxxx xxxxxxxx xxxxxxxx
26619 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26622 \begin_layout Standard
26623 a 21-bit code pointer in FLASH memory
26629 <row bottomline="true">
26630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26633 \begin_layout Standard
26639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26642 \begin_layout Standard
26648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="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
26665 uuuuuu uuuuuuxx xxxxxxxx
26670 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26673 \begin_layout Standard
26674 a 10-bit eeprom pointer in EEPROM memory
26680 <row bottomline="true">
26681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26684 \begin_layout Standard
26690 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26693 \begin_layout Standard
26699 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26702 \begin_layout Standard
26708 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26711 \begin_layout Standard
26716 xxxxxx xxxxxxxx xxxxxxxx
26721 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26724 \begin_layout Standard
26725 unimplemented pointer type
26738 \begin_layout Standard
26739 Generic pointer are read and written with a set of library functions which
26740 read/write 1, 2, 3, 4 bytes.
26743 \begin_layout Subsection
26747 \begin_layout Subsubsection
26748 Standard I/O Streams
26751 \begin_layout Standard
26756 the type FILE is defined as:
26759 \begin_layout LyX-Code
26760 typedef char * FILE;
26763 \begin_layout Standard
26764 This type is the stream type implemented I/O in the PIC18F devices.
26765 Also the standard input and output streams are declared in stdio.h:
26768 \begin_layout LyX-Code
26769 extern FILE * stdin;
26772 \begin_layout LyX-Code
26773 extern FILE * stdout;
26776 \begin_layout Standard
26777 The FILE type is actually a generic pointer which defines one more type
26778 of generic pointers, the
26783 This new type has the format:
26786 \begin_layout Standard
26788 \begin_inset Tabular
26789 <lyxtabular version="3" rows="2" columns="7">
26791 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26792 <column alignment="center" valignment="top" width="0">
26793 <column alignment="center" valignment="top" leftline="true" width="0">
26794 <column alignment="center" valignment="top" leftline="true" width="0">
26795 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26796 <column alignment="center" valignment="top" width="0">
26797 <column alignment="left" valignment="top" rightline="true" width="0">
26798 <row topline="true" bottomline="true">
26799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26802 \begin_layout Standard
26808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26811 \begin_layout Standard
26817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26820 \begin_layout Standard
26826 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26829 \begin_layout Standard
26835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26838 \begin_layout Standard
26844 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26847 \begin_layout Standard
26848 rest of the pointer
26853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26856 \begin_layout Standard
26863 <row topline="true" bottomline="true">
26864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26867 \begin_layout Standard
26873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26876 \begin_layout Standard
26882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26885 \begin_layout Standard
26891 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26894 \begin_layout Standard
26900 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26903 \begin_layout Standard
26909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26912 \begin_layout Standard
26922 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26925 \begin_layout Standard
26926 upper byte high nubble is 0x2n, the rest are zeroes
26939 \begin_layout Standard
26940 Currently implemented there are 3 types of streams defined:
26943 \begin_layout Standard
26945 \begin_inset Tabular
26946 <lyxtabular version="3" rows="4" columns="4">
26948 <column alignment="center" valignment="top" leftline="true" width="0">
26949 <column alignment="center" valignment="top" leftline="true" width="0">
26950 <column alignment="center" valignment="top" leftline="true" width="0">
26951 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26952 <row topline="true" bottomline="true">
26953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26956 \begin_layout Standard
26962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26965 \begin_layout Standard
26971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26974 \begin_layout Standard
26980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26983 \begin_layout Standard
26990 <row topline="true">
26991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26994 \begin_layout Standard
27000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27003 \begin_layout Standard
27011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27014 \begin_layout Standard
27020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27023 \begin_layout Standard
27024 Writes/Reads characters via the USART peripheral
27030 <row topline="true">
27031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27034 \begin_layout Standard
27040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27043 \begin_layout Standard
27051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27054 \begin_layout Standard
27060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27063 \begin_layout Standard
27064 Writes/Reads characters via the MSSP peripheral
27070 <row topline="true" bottomline="true">
27071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27074 \begin_layout Standard
27080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27083 \begin_layout Standard
27091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27094 \begin_layout Standard
27100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27103 \begin_layout Standard
27104 Writes/Reads characters via used defined functions
27117 \begin_layout Standard
27118 The stream identifiers are declared as macros in the stdio.h header.
27121 \begin_layout Standard
27122 In the libc library there exist the functions that are used to write to
27123 each of the above streams.
27127 \begin_layout Description
27132 \begin_layout Standard
27141 _stream_usart_putchar writes a character at the USART stream
27144 \begin_layout Description
27149 \begin_layout Standard
27158 _stream_mssp_putchar writes a character at the MSSP stream
27161 \begin_layout Description
27162 putchar dummy function.
27163 This writes a character to a user specified manner.
27166 \begin_layout Standard
27167 In order to increase performance
27171 is declared in stdio.h as having its parameter in WREG (it has the wparam
27173 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
27174 in a user-friendly way.
27179 is the name of the variable that holds the character to print.
27180 An example follows:
27183 \begin_layout LyX-Code
27184 #include <pic18fregs.h>
27193 \begin_layout LyX-Code
27197 \begin_layout LyX-Code
27198 PORTA = c; /* dump character c to PORTA */
27201 \begin_layout LyX-Code
27209 \begin_layout LyX-Code
27213 \begin_layout LyX-Code
27214 stdout = STREAM_USER; /* this is not necessary, since stdout points
27217 \begin_layout LyX-Code
27218 * by default to STREAM_USER */
27221 \begin_layout LyX-Code
27223 \begin_inset Quotes sld
27226 This is a printf test
27229 \begin_inset Quotes srd
27235 \begin_layout LyX-Code
27239 \begin_layout LyX-Code
27243 \begin_layout Subsubsection
27247 \begin_layout Standard
27248 PIC16 contains an implementation of the printf-family of functions.
27249 There exist the following functions:
27252 \begin_layout LyX-Code
27253 extern unsigned int sprintf(char *buf, char *fmt, ...);
27256 \begin_layout LyX-Code
27257 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
27260 \begin_layout LyX-Code
27264 \begin_layout LyX-Code
27265 extern unsigned int printf(char *fmt, ...);
27268 \begin_layout LyX-Code
27269 extern unsigned int vprintf(char *fmt, va_lista ap);
27272 \begin_layout LyX-Code
27276 \begin_layout LyX-Code
27277 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
27280 \begin_layout LyX-Code
27281 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
27284 \begin_layout Standard
27285 For sprintf and vsprintf
27289 should normally be a data pointer where the resulting string will be placed.
27290 No range checking is done so the user should allocate the necessery buffer.
27291 For fprintf and vfprintf
27295 should be a stream pointer (i.e.
27296 stdout, STREAM_MSSP, etc...).
27299 \begin_layout Subsubsection
27303 \begin_layout Standard
27304 The PIC18F family of microcontrollers supports a number of interrupt sources.
27305 A list of these interrupts is shown in the following table:
27308 \begin_layout Standard
27310 \begin_inset Tabular
27311 <lyxtabular version="3" rows="11" columns="4">
27313 <column alignment="left" valignment="top" leftline="true" width="0">
27314 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27315 <column alignment="left" valignment="top" leftline="true" width="0">
27316 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27317 <row topline="true" bottomline="true">
27318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27321 \begin_layout Standard
27327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27330 \begin_layout Standard
27336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27339 \begin_layout Standard
27345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27348 \begin_layout Standard
27355 <row topline="true">
27356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27359 \begin_layout Standard
27365 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27368 \begin_layout Standard
27369 PORTB change interrupt
27374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27377 \begin_layout Standard
27383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27386 \begin_layout Standard
27387 EEPROM/FLASH write complete interrupt
27393 <row topline="true">
27394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27397 \begin_layout Standard
27403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27406 \begin_layout Standard
27407 INT0 external interrupt
27412 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27415 \begin_layout Standard
27421 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27424 \begin_layout Standard
27425 Bus collision interrupt
27431 <row topline="true">
27432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27435 \begin_layout Standard
27441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27444 \begin_layout Standard
27445 INT1 external interrupt
27450 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27453 \begin_layout Standard
27459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27462 \begin_layout Standard
27463 Low voltage detect interrupt
27469 <row topline="true">
27470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27473 \begin_layout Standard
27479 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27482 \begin_layout Standard
27483 INT2 external interrupt
27488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27491 \begin_layout Standard
27497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27500 \begin_layout Standard
27501 Parallel slave port interrupt
27507 <row topline="true">
27508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27511 \begin_layout Standard
27517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27520 \begin_layout Standard
27521 CCP1 module interrupt
27526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27529 \begin_layout Standard
27535 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27538 \begin_layout Standard
27539 AD convertion complete interrupt
27545 <row topline="true">
27546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27549 \begin_layout Standard
27555 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27558 \begin_layout Standard
27559 CCP2 module interrupt
27564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27567 \begin_layout Standard
27573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27576 \begin_layout Standard
27577 USART receive interrupt
27583 <row topline="true">
27584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27587 \begin_layout Standard
27593 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27596 \begin_layout Standard
27597 TMR0 overflow interrupt
27602 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27605 \begin_layout Standard
27611 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27614 \begin_layout Standard
27615 USART transmit interrupt
27621 <row topline="true">
27622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27625 \begin_layout Standard
27631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27634 \begin_layout Standard
27635 TMR1 overflow interrupt
27640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27643 \begin_layout Standard
27649 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27652 \begin_layout Standard
27653 SSP receive/transmit interrupt
27659 <row topline="true">
27660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27663 \begin_layout Standard
27669 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27672 \begin_layout Standard
27673 TMR2 matches PR2 interrupt
27678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27681 \begin_layout Standard
27687 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27690 \begin_layout Standard
27697 <row topline="true" bottomline="true">
27698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27701 \begin_layout Standard
27707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27710 \begin_layout Standard
27711 TMR3 overflow interrupt
27716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27719 \begin_layout Standard
27725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27728 \begin_layout Standard
27742 \begin_layout Standard
27743 The prototypes for these names are defined in the header file
27750 \begin_layout Standard
27751 In order to simplify signal handling, a number of macros is provided:
27755 \labelwidthstring 00.00.0000
27756 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
27757 high priority interrupts.
27762 is the function name to use.
27766 \labelwidthstring 00.00.0000
27767 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
27768 low priority interrupt.
27773 is the function name to use.
27777 \labelwidthstring 00.00.0000
27778 DEF_HANDLER(sig,handler) define a handler for signal
27784 \labelwidthstring 00.00.0000
27785 END_DEF end the declaration of the dispatch table.
27788 \begin_layout Standard
27789 Additionally there are two more macros to simplify the declaration of the
27794 \labelwidthstring 00.00.0000
27797 SIGHANDLER(handler)
27799 this declares the function prototype for the
27807 \labelwidthstring 00.00.0000
27808 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
27811 \begin_layout Standard
27812 An example of using the macros above is shown below:
27815 \begin_layout LyX-Code
27816 #include <pic18fregs.h>
27819 \begin_layout LyX-Code
27820 #include <signal.h>
27824 DEF_INTHIGH(high_int)
27827 \begin_layout LyX-Code
27828 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
27831 \begin_layout LyX-Code
27832 DEF_HANDLER(SIG_BCOL, _bcol_handler)
27835 \begin_layout LyX-Code
27840 SIGHANDLER(_tmr0_handler)
27843 \begin_layout LyX-Code
27847 \begin_layout LyX-Code
27848 /* action to be taken when timer 0 overflows */
27851 \begin_layout LyX-Code
27856 SIGHANDLERNAKED(_bcol_handler)
27859 \begin_layout LyX-Code
27863 \begin_layout LyX-Code
27867 \begin_layout LyX-Code
27868 /* action to be taken when bus collision occurs */
27871 \begin_layout LyX-Code
27875 \begin_layout LyX-Code
27879 \begin_layout LyX-Code
27883 \begin_layout Standard
27888 Special care should be taken when using the above scheme:
27891 \begin_layout Itemize
27892 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
27895 \begin_layout Itemize
27896 when declaring SIGHANDLERNAKED handler never forget to use
27900 for proper returning.
27903 \begin_layout Subsection
27907 \begin_layout Standard
27908 Here you can find some general tips for compiling programs with SDCC/pic16.
27911 \begin_layout Subsubsection
27915 \begin_layout Standard
27917 \begin_inset LatexCommand \index{PIC16!stack}
27921 size (that is 64 bytes) probably is enough for many programs.
27922 One must take care that when there are many levels of function nesting,
27923 or there is excessive usage of stack, its size should be extended.
27924 An example of such a case is the printf/sprintf family of functions.
27925 If you encounter problems like not being able to print integers, then you
27926 need to set the stack size around the maximum (256 for small stack model).
27927 The following diagram shows what happens when calling printf to print an
27931 \begin_layout LyX-Code
27932 printf () --> ltoa () --> ultoa () --> divschar ()
27935 \begin_layout Standard
27936 It is should be understood that stack is easily consumed when calling complicate
27938 Using command line arguments like -
27942 \begin_layout Standard
27951 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
27953 Other ways to reduce stack usage may exist.
27956 \begin_layout Subsection
27960 \begin_layout Standard
27961 The PIC16 Port currently does not pass SDCC's regression test
27962 \begin_inset LatexCommand \index{Regression test (PIC16)}
27967 \begin_inset LatexCommand \ref{sec:Quality-control}
27971 ) and thus the snapshot build regression tests for the PIC16 target are
27972 currently disabled for all hosts
27977 \begin_layout Chapter
27981 \begin_layout Standard
27982 There are several approaches to debugging your code.
27983 This chapter is meant to show your options and to give detail on some of
27988 When writing your code:
27991 \begin_layout Itemize
27992 write your code with debugging in mind (avoid duplicating code, put conceptually
27993 similar variables into structs, use structured code, have strategic points
27994 within your code where all variables are consistent, ...)
27997 \begin_layout Itemize
27998 run a syntax-checking tool like splint
27999 \begin_inset LatexCommand \index{splint (syntax checking tool)}
28004 \begin_inset LatexCommand \index{lint (syntax checking tool)}
28012 \begin_layout Standard
28022 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28029 \begin_layout Itemize
28030 for the high level code use a C-compiler (like f.e.
28031 GCC) to compile run and debug the code on your host.
28036 \begin_layout Standard
28046 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28050 ) on how to handle syntax extensions like __xdata, __at(), ...
28054 \begin_layout Itemize
28055 use another C-compiler to compile code for your target.
28056 Always an option but not recommended:) And not very likely to help you.
28057 If you seriously consider walking this path you should at least occasionally
28058 check portability of your code.
28059 Most commercial compiler vendors will offer an evaluation version so you
28060 can test compile your code or snippets of your code.
28063 \begin_layout Standard
28064 Debugging on a simulator:
28067 \begin_layout Itemize
28068 there is a separate section about SDCDB (section
28069 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
28076 \begin_layout Itemize
28077 or (8051 specific) use a freeware/commercial simulator which interfaces
28079 \begin_inset LatexCommand \index{AOMF, AOMF51}
28084 \begin_inset LatexCommand \ref{OMF file}
28088 ) optionally generated by SDCC.
28091 \begin_layout Standard
28092 Debugging On-target:
28095 \begin_layout Itemize
28096 use a MCU port pin to serially output debug data to the RS232 port of your
28098 You'll probably want some level shifting device typically involving a MAX232
28100 If the hardware serial port of the MCU is not available search for 'Software
28101 UART' in your favourite search machine.
28104 \begin_layout Itemize
28105 use an on-target monitor.
28106 In this context a monitor is a small program which usually accepts commands
28107 via a serial line and allows to set program counter, to single step through
28108 a program and read/write memory locations.
28109 For the 8051 good examples of monitors are paulmon and cmon51 (see section
28111 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
28118 \begin_layout Itemize
28119 toggle MCU port pins at strategic points within your code and use an oscilloscop
28123 digital oscilloscope
28126 \begin_inset LatexCommand \index{Oscilloscope}
28130 with deep trace memory is really helpful especially if you have to debug
28131 a realtime application.
28132 If you need to monitor more pins than your oscilloscope provides you can
28133 sometimes get away with a small R-2R network.
28134 On a single channel oscilloscope you could f.e.
28135 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
28137 \begin_inset Formula $\Omega$
28140 resistor and the other one by a 5\InsetSpace ~
28142 \begin_inset Formula $\Omega$
28145 resistor to the oscilloscope probe (check output drive capability of the
28146 pins you want to monitor).
28147 If you need to monitor many more pins a
28154 \begin_layout Itemize
28168 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
28173 Usually very expensive.
28174 And very nice to have too.
28175 And usually locks you (for years...) to the devices the ICE can emulate.
28179 \begin_layout Itemize
28180 use a remote debugger.
28181 In most 8-bit systems the symbol information is not available on the target,
28182 and a complete debugger is too bulky for the target system.
28183 Therefore usually a debugger on the host system connects to an on-target
28184 debugging stub which accepts only primitive commands.
28187 Terms to enter into your favourite search engine could be 'remote debugging',
28188 'gdb stub' or 'inferior debugger'.
28192 \begin_layout Itemize
28193 use an on target hardware debugger.
28194 Some of the more modern MCUs include hardware support for setting break
28195 points and monitoring/changing variables by using dedicated hardware pins.
28196 This facility doesn't require additional code to run on the target and
28201 doesn't affect runtime behaviour until a breakpoint is hit.
28202 For the mcs51 most hardware debuggers use the AOMF
28203 \begin_inset LatexCommand \index{AOMF, AOMF51}
28208 \begin_inset LatexCommand \ref{OMF file}
28216 \begin_layout Standard
28220 \begin_layout Itemize
28221 if you are not familiar with any of the following terms you're likely to
28222 run into problems rather sooner than later:
28239 As an embedded programmer you
28243 to know them so why not look them up
28247 you have problems?)
28250 \begin_layout Itemize
28251 tell someone else about your problem (actually this is a surprisingly effective
28252 means to hunt down the bug even if the listener is not familiar with your
28254 As 'failure to communicate' is probably one of the job-induced deformations
28255 of an embedded programmer this is highly encouraged.
28258 \begin_layout Section
28259 Debugging with SDCDB
28260 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
28265 \begin_inset LatexCommand \index{SDCDB (debugger)}
28272 \begin_layout Standard
28273 SDCC is distributed with a source level debugger
28274 \begin_inset LatexCommand \index{Debugger}
28279 The debugger uses a command line interface, the command repertoire of the
28280 debugger has been kept as close to gdb
28281 \begin_inset LatexCommand \index{gdb}
28285 (the GNU debugger) as possible.
28286 The configuration and build process is part of the standard compiler installati
28287 on, which also builds and installs the debugger in the target directory
28288 specified during configuration.
28289 The debugger allows you debug BOTH at the C source and at the ASM source
28293 \begin_layout Subsection
28294 Compiling for Debugging
28297 \begin_layout Standard
28302 \begin_layout Standard
28312 \begin_inset LatexCommand \index{-\/-debug}
28316 option must be specified for all files for which debug information is to
28318 The compiler generates a .adb file for each of these files.
28319 The linker creates the .cdb
28320 \begin_inset LatexCommand \index{<file>.cdb}
28325 \begin_inset LatexCommand \index{<file>.adb}
28329 files and the address information.
28330 This .cdb is used by the debugger.
28333 \begin_layout Subsection
28334 How the Debugger Works
28337 \begin_layout Standard
28342 \begin_layout Standard
28351 -debug option is specified the compiler generates extra symbol information
28352 some of which are put into the assembler source and some are put into the
28354 Then the linker creates the .cdb file from the individual .adb files with
28355 the address information for the symbols.
28356 The debugger reads the symbolic information generated by the compiler &
28357 the address information generated by the linker.
28358 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
28359 execution is controlled by the debugger.
28360 When a command is issued for the debugger, it translates it into appropriate
28361 commands for the simulator.
28362 (Currently SDCDM only connects to the simulator but
28367 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
28371 is an effort to connect directly to the hardware.)
28374 \begin_layout Subsection
28375 Starting the Debugger SDCDB
28378 \begin_layout Standard
28379 The debugger can be started using the following command line.
28380 (Assume the file you are debugging has the file name foo).
28394 The debugger will look for the following files.
28397 \begin_layout Itemize
28398 foo.c - the source file.
28401 \begin_layout Itemize
28402 foo.cdb - the debugger symbol information file.
28405 \begin_layout Itemize
28406 foo.ihx - the Intel hex format
28407 \begin_inset LatexCommand \index{Intel hex format}
28414 \begin_layout Subsection
28415 SDCDB Command Line Options
28418 \begin_layout Itemize
28423 \begin_layout Standard
28432 -directory=<source file directory> this option can used to specify the directory
28434 The debugger will look into the directory list specified for source, cdb
28436 The items in the directory list must be separated by ':', e.g.
28437 if the source files can be in the directories /home/src1 and /home/src2,
28442 \begin_layout Standard
28451 -directory option should be -
28455 \begin_layout Standard
28464 -directory=/home/src1:/home/src2.
28465 Note there can be no spaces in the option.
28469 \begin_layout Itemize
28470 -cd <directory> - change to the <directory>.
28473 \begin_layout Itemize
28474 -fullname - used by GUI front ends.
28477 \begin_layout Itemize
28478 -cpu <cpu-type> - this argument is passed to the simulator please see the
28479 simulator docs for details.
28482 \begin_layout Itemize
28483 -X <Clock frequency > this options is passed to the simulator please see
28484 the simulator docs for details.
28487 \begin_layout Itemize
28488 -s <serial port file> passed to simulator see the simulator docs for details.
28491 \begin_layout Itemize
28492 -S <serial in,out> passed to simulator see the simulator docs for details.
28495 \begin_layout Itemize
28496 -k <port number> passed to simulator see the simulator docs for details.
28499 \begin_layout Subsection
28500 SDCDB Debugger Commands
28503 \begin_layout Standard
28504 As mentioned earlier the command interface for the debugger has been deliberatel
28505 y kept as close the GNU debugger gdb, as possible.
28506 This will help the integration with existing graphical user interfaces
28507 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
28508 If you use a graphical user interface for the debugger you can skip this
28512 \begin_layout Subsubsection*
28513 break [line | file:line | function | file:function]
28516 \begin_layout Standard
28517 Set breakpoint at specified line or function:
28526 sdcdb>break foo.c:100
28528 sdcdb>break funcfoo
28530 sdcdb>break foo.c:funcfoo
28533 \begin_layout Subsubsection*
28534 clear [line | file:line | function | file:function ]
28537 \begin_layout Standard
28538 Clear breakpoint at specified line or function:
28547 sdcdb>clear foo.c:100
28549 sdcdb>clear funcfoo
28551 sdcdb>clear foo.c:funcfoo
28554 \begin_layout Subsubsection*
28558 \begin_layout Standard
28559 Continue program being debugged, after breakpoint.
28562 \begin_layout Subsubsection*
28566 \begin_layout Standard
28567 Execute till the end of the current function.
28570 \begin_layout Subsubsection*
28574 \begin_layout Standard
28575 Delete breakpoint number 'n'.
28576 If used without any option clear ALL user defined break points.
28579 \begin_layout Subsubsection*
28580 info [break | stack | frame | registers ]
28583 \begin_layout Itemize
28584 info break - list all breakpoints
28587 \begin_layout Itemize
28588 info stack - show the function call stack.
28591 \begin_layout Itemize
28592 info frame - show information about the current execution frame.
28595 \begin_layout Itemize
28596 info registers - show content of all registers.
28599 \begin_layout Subsubsection*
28603 \begin_layout Standard
28604 Step program until it reaches a different source line.
28605 Note: pressing <return> repeats the last command.
28608 \begin_layout Subsubsection*
28612 \begin_layout Standard
28613 Step program, proceeding through subroutine calls.
28616 \begin_layout Subsubsection*
28620 \begin_layout Standard
28621 Start debugged program.
28624 \begin_layout Subsubsection*
28628 \begin_layout Standard
28629 Print type information of the variable.
28632 \begin_layout Subsubsection*
28636 \begin_layout Standard
28637 print value of variable.
28640 \begin_layout Subsubsection*
28644 \begin_layout Standard
28645 load the given file name.
28646 Note this is an alternate method of loading file for debugging.
28649 \begin_layout Subsubsection*
28653 \begin_layout Standard
28654 print information about current frame.
28657 \begin_layout Subsubsection*
28661 \begin_layout Standard
28662 Toggle between C source & assembly source.
28665 \begin_layout Subsubsection*
28666 ! simulator command
28669 \begin_layout Standard
28670 Send the string following '!' to the simulator, the simulator response is
28672 Note the debugger does not interpret the command being sent to the simulator,
28673 so if a command like 'go' is sent the debugger can loose its execution
28674 context and may display incorrect values.
28677 \begin_layout Subsubsection*
28681 \begin_layout Standard
28684 My name is Bobby Brown"
28687 \begin_layout Subsection
28688 Interfacing SDCDB with DDD
28691 \begin_layout Standard
28692 \begin_inset Note Note
28695 \begin_layout Standard
28696 The screenshot was converted from png to eps with:
28697 \begin_inset Quotes sld
28700 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
28701 \begin_inset Quotes srd
28704 which produces a pretty compact eps file which is free from compression
28708 \begin_layout Standard
28709 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
28710 as this broke the build system on Sourceforge (pdf-file was broken.
28711 pdflatex does not accept eps files).
28719 \begin_layout Standard
28735 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
28741 shows a screenshot of a debugging session with DDD
28742 \begin_inset LatexCommand \index{DDD (debugger)}
28746 (Unix only) on a simulated 8032.
28747 The debugging session might not run as smoothly as the screenshot suggests.
28748 The debugger allows setting of breakpoints, displaying and changing variables,
28749 single stepping through C and assembler code.
28752 The source was compiled with
28766 \begin_layout Standard
28778 -debug ddd_example.c
28791 and DDD was invoked with
28798 ddd -debugger "sdcdb -cpu 8032 ddd_example"
28801 \begin_layout Standard
28802 \begin_inset Note Note
28805 \begin_layout Standard
28806 Check that the double quotes or an apostroph within the command line survive
28807 the LyX tool chain.
28808 Previously the apostrophs got slanted in the PDF output so a cut and paste
28817 \begin_layout Subsection
28818 Interfacing SDCDB with XEmacs
28819 \begin_inset LatexCommand \index{XEmacs}
28824 \begin_inset LatexCommand \index{Emacs}
28831 \begin_layout Standard
28832 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
28833 sdcdb.el and sdcdbsrc.el.
28834 These two files can be found in the $(prefix)/bin directory after the installat
28836 These files need to be loaded into XEmacs for the interface to work.
28837 This can be done at XEmacs startup time by inserting the following into
28838 your '.xemacs' file (which can be found in your HOME directory):
28844 (load-file sdcdbsrc.el)
28850 .xemacs is a lisp file so the () around the command is REQUIRED.
28851 The files can also be loaded dynamically while XEmacs is running, set the
28852 environment variable 'EMACSLOADPATH' to the installation bin directory
28853 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
28854 To start the interface enter the following command:
28868 You will prompted to enter the file name to be debugged.
28873 The command line options that are passed to the simulator directly are
28874 bound to default values in the file sdcdbsrc.el.
28875 The variables are listed below, these values maybe changed as required.
28878 \begin_layout Itemize
28879 sdcdbsrc-cpu-type '51
28882 \begin_layout Itemize
28883 sdcdbsrc-frequency '11059200
28886 \begin_layout Itemize
28887 sdcdbsrc-serial nil
28890 \begin_layout Standard
28891 The following is a list of key mapping for the debugger interface.
28894 \begin_layout Standard
28917 binding\InsetSpace ~
28955 -------\InsetSpace ~
29026 sdcdb-back-from-src\InsetSpace ~
29055 rom-src\InsetSpace ~
29065 SDCDB continue command
29083 sdcdb-step-from-src\InsetSpace ~
29112 hatis-c-sexp\InsetSpace ~
29122 SDCDB ptypecommand for data at
29189 sdcdbsrc-delete\InsetSpace ~
29204 B Delete all breakpoints if no arg
29253 given or delete arg (C-u arg x)
29272 -frame\InsetSpace ~
29287 SDCDB Display current frame if no arg,
29336 given or display frame arg
29404 sdcdbsrc-goto-sdcdb\InsetSpace ~
29414 Goto the SDCDB output buffer
29433 t-c-sexp\InsetSpace ~
29444 SDCDB print command for data at
29511 sdcdbsrc-goto-sdcdb\InsetSpace ~
29522 o the SDCDB output buffer
29540 sdcdbsrc-mode\InsetSpace ~
29556 Toggles Sdcdbsrc mode (turns it
29572 sdcdb-finish-from-src\InsetSpace ~
29580 SDCDB finish command
29614 Set break for line with point
29629 sdcdbsrc-mode\InsetSpace ~
29645 Toggle Sdcdbsrc mode
29661 dbsrc-srcmode\InsetSpace ~
29685 \begin_layout Chapter
29689 \begin_layout Standard
29690 Here are a few guidelines that will help the compiler generate more efficient
29691 code, some of the tips are specific to this compiler others are generally
29692 good programming practice.
29695 \begin_layout Itemize
29696 Use the smallest data type to represent your data-value.
29697 If it is known in advance that the value is going to be less than 256 then
29698 use an 'unsigned char' instead of a 'short' or 'int'.
29699 Please note, that ANSI C requires both signed and unsigned chars to be
29700 promoted to 'signed int'
29701 \begin_inset LatexCommand \index{promotion to signed int}
29706 \begin_inset Marginal
29709 \begin_layout Standard
29718 before doing any operation.
29720 \begin_inset LatexCommand \index{type promotion}
29725 \begin_inset LatexCommand \label{type promotion}
29729 can be omitted, if the result is the same.
29730 The effect of the promotion rules together with the sign-extension is often
29735 \begin_layout Verse
29738 unsigned char uc = 0xfe;
29740 if (uc * uc < 0) /* this is true! */
29753 \begin_layout Standard
29760 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
29768 \begin_layout Verse
29771 (unsigned char) -12 / (signed char) -3 = ...
29774 \begin_layout Standard
29775 No, the result is not 4:
29778 \begin_layout Verse
29781 (int) (unsigned char) -12 / (int) (signed char) -3 =
29783 (int) (unsigned char)
29784 0xf4 / (int) (signed char) 0xfd =
29786 (int) 0x00f4 / (int) 0xfffd =
29791 (int) 244 / (int) -3 =
29793 (int) -81 = (int) 0xffaf;
29796 \begin_layout Standard
29797 Don't complain, that gcc gives you a different result.
29798 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
29799 Therefore the results are different.
29802 \begin_inset Quotes sld
29806 \begin_inset Quotes srd
29812 \begin_layout Quote
29815 If well-defined overflow characteristics are important and negative values
29816 are not, or if you want to steer clear of sign-extension problems when
29817 manipulating bits or bytes, use one of the corresponding unsigned types.
29818 (Beware when mixing signed and unsigned values in expressions, though.)
29821 character types (especially unsigned char) can be used as "tiny" integers,
29822 doing so is sometimes more trouble than it's worth, due to unpredictable
29823 sign extension and increased code size.
29827 \begin_layout Itemize
29828 Use unsigned when it is known in advance that the value is not going to
29830 This helps especially if you are doing division or multiplication, bit-shifting
29831 or are using an array index.
29834 \begin_layout Itemize
29835 NEVER jump into a LOOP.
29838 \begin_layout Itemize
29839 Declare the variables to be local
29840 \begin_inset LatexCommand \index{local variables}
29844 whenever possible, especially loop control variables (induction).
29847 \begin_layout Itemize
29848 Have a look at the assembly listing to get a
29849 \begin_inset Quotes sld
29853 \begin_inset Quotes srd
29856 for the code generation.
29859 \begin_layout Section
29860 Porting code from or to other compilers
29861 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
29868 \begin_layout Itemize
29869 check whether endianness of the compilers differs and adapt where needed.
29872 \begin_layout Itemize
29873 check the device specific header files
29874 \begin_inset LatexCommand \index{Header files}
29879 \begin_inset LatexCommand \index{Include files}
29883 for compiler specific syntax.
29884 Eventually include the file <compiler.h
29885 \begin_inset LatexCommand \index{compiler.h (include file)}
29890 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
29894 to allow using common header files.
29897 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
29904 \begin_layout Itemize
29905 check whether the startup code contains the correct initialization (watchdog,
29909 \begin_layout Itemize
29910 check whether the sizes of short, int, long match.
29913 \begin_layout Itemize
29914 check if some 16 or 32 bit hardware registers require a specific addressing
29915 order (least significant or most significant byte first) and adapt if needed
29924 relate to time and not to lower/upper memory location here, so this is
29929 the same as endianness).
29932 \begin_layout Itemize
29933 check whether the keyword
29937 is used where needed.
29938 The compilers might differ in their optimization characteristics (as different
29939 versions of the same compiler might also use more clever optimizations
29940 this is good idea anyway).
29942 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
29949 \begin_layout Itemize
29950 check that the compilers are not told to supress warnings.
29953 \begin_layout Itemize
29954 check and convert compiler specific extensions (interrupts, memory areas,
29958 \begin_layout Itemize
29959 check for differences in type promotion.
29960 Especially check for math operations on
29969 For the sake of C99 compatibility SDCC will probably promote these to
29973 more often than other compilers.
29974 Eventually insert explicit casts to
29983 Also check that the ~\InsetSpace ~
29985 \begin_inset LatexCommand \index{\~\/ Operator}
29992 \begin_inset LatexCommand \index{bit}
29998 variables, use the !\InsetSpace ~
30001 \begin_inset LatexCommand \ref{type promotion}
30006 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30013 \begin_layout Itemize
30014 check the assembly code generated for interrupt routines (f.e.
30015 for calls to possibly non-reentrant library functions).
30018 \begin_layout Itemize
30019 check whether timing loops result in proper timing (or preferably consider
30020 a rewrite of the code with timer based delays instead).
30023 \begin_layout Itemize
30024 check for differences in printf parameters (some compilers push (va_arg
30025 \begin_inset LatexCommand \index{vararg, va\_arg}
30029 ) char variables as
30033 others push them as
30039 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30046 \begin_layout Itemize
30047 check the resulting memory map
30048 \begin_inset LatexCommand \index{Memory map}
30053 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
30054 ly idata, pdata, xdata).
30055 Eventually check if unexpected library functions are included.
30058 \begin_layout Section
30060 \begin_inset LatexCommand \index{Tools}
30064 included in the distribution
30067 \begin_layout Standard
30069 \begin_inset Tabular
30070 <lyxtabular version="3" rows="12" columns="3">
30072 <column alignment="left" valignment="top" leftline="true" width="0pt">
30073 <column alignment="left" valignment="top" leftline="true" width="0pt">
30074 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30075 <row topline="true" bottomline="true">
30076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30079 \begin_layout Standard
30087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30090 \begin_layout Standard
30098 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30101 \begin_layout Standard
30110 <row topline="true">
30111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30114 \begin_layout Standard
30116 \begin_inset LatexCommand \index{uCsim}
30125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30128 \begin_layout Standard
30129 Simulator for various architectures
30134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30137 \begin_layout Standard
30144 <row topline="true">
30145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30148 \begin_layout Standard
30154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30157 \begin_layout Standard
30159 \begin_inset LatexCommand \index{Header files}
30164 \begin_inset LatexCommand \index{Include files}
30173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30176 \begin_layout Standard
30177 sdcc/support/scripts
30183 <row topline="true">
30184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30187 \begin_layout Standard
30193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30196 \begin_layout Standard
30197 header file conversion
30202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30205 \begin_layout Standard
30206 sdcc/support/scripts
30212 <row topline="true">
30213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30216 \begin_layout Standard
30222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30225 \begin_layout Standard
30231 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30234 \begin_layout Standard
30250 <row topline="true">
30251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30254 \begin_layout Standard
30260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30263 \begin_layout Standard
30269 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30272 \begin_layout Standard
30288 <row topline="true">
30289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30292 \begin_layout Standard
30298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30301 \begin_layout Standard
30307 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30310 \begin_layout Standard
30326 <row topline="true">
30327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30330 \begin_layout Standard
30336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30339 \begin_layout Standard
30345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30348 \begin_layout Standard
30364 <row topline="true">
30365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30368 \begin_layout Standard
30374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30377 \begin_layout Standard
30383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30386 \begin_layout Standard
30402 <row topline="true">
30403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30406 \begin_layout Standard
30412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30415 \begin_layout Standard
30421 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30424 \begin_layout Standard
30440 <row topline="true">
30441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30444 \begin_layout Standard
30450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30453 \begin_layout Standard
30459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30462 \begin_layout Standard
30478 <row topline="true" bottomline="true">
30479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30482 \begin_layout Standard
30488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30491 \begin_layout Standard
30493 \begin_inset LatexCommand \index{packihx (tool)}
30502 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30505 \begin_layout Standard
30530 \begin_layout Section
30532 \begin_inset LatexCommand \index{Documentation}
30536 included in the distribution
30539 \begin_layout Standard
30541 \begin_inset Tabular
30542 <lyxtabular version="3" rows="10" columns="2">
30544 <column alignment="block" valignment="top" leftline="true" width="40col%">
30545 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
30546 <row topline="true" bottomline="true" endhead="true">
30547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30550 \begin_layout Standard
30558 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30561 \begin_layout Standard
30564 Filename / Where to get
30570 <row topline="true">
30571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30574 \begin_layout Standard
30575 SDCC Compiler User Guide
30580 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30583 \begin_layout Standard
30584 You're reading it right now
30596 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
30606 <row topline="true">
30607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30610 \begin_layout Standard
30616 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30619 \begin_layout Standard
30632 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
30642 <row topline="true">
30643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30646 \begin_layout Standard
30648 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
30653 \begin_inset LatexCommand \index{Assembler documentation}
30660 \begin_inset LatexCommand \index{aslink}
30665 \begin_inset LatexCommand \index{Linker documentation}
30674 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30677 \begin_layout Standard
30678 sdcc/as/doc/asxhtm.html
30690 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
30700 <row topline="true">
30701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30704 \begin_layout Standard
30705 SDCC regression test
30706 \begin_inset LatexCommand \index{Regression test}
30715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30718 \begin_layout Standard
30719 sdcc/doc/test_suite_spec.pdf
30731 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30741 <row topline="true">
30742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30745 \begin_layout Standard
30751 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30754 \begin_layout Standard
30767 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
30777 <row topline="true">
30778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30781 \begin_layout Standard
30782 Notes on debugging with SDCDB
30783 \begin_inset LatexCommand \index{SDCDB (debugger)}
30792 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30795 \begin_layout Standard
30796 sdcc/debugger/README
30808 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
30818 <row topline="true">
30819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30822 \begin_layout Standard
30824 \begin_inset LatexCommand \index{uCsim}
30828 Software simulator for microcontrollers
30833 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30836 \begin_layout Standard
30866 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
30876 <row topline="true">
30877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30880 \begin_layout Standard
30881 Temporary notes on the pic16
30882 \begin_inset LatexCommand \index{PIC16}
30891 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30894 \begin_layout Standard
30895 sdcc/src/pic16/NOTES
30907 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
30917 <row topline="true" bottomline="true">
30918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30921 \begin_layout Standard
30922 SDCC internal documentation (debugging file format)
30927 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30930 \begin_layout Standard
30960 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
30979 \begin_layout Section
30980 Related open source tools
30981 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
30986 \begin_inset LatexCommand \index{Related tools}
30993 \begin_layout Standard
30995 \begin_inset Tabular
30996 <lyxtabular version="3" rows="14" columns="3">
30998 <column alignment="left" valignment="top" leftline="true" width="0pt">
30999 <column alignment="block" valignment="top" leftline="true" width="30line%">
31000 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
31001 <row topline="true" bottomline="true">
31002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31005 \begin_layout Standard
31013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31016 \begin_layout Standard
31024 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31027 \begin_layout Standard
31036 <row topline="true">
31037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31040 \begin_layout Standard
31042 \begin_inset LatexCommand \index{gpsim (pic simulator)}
31051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31054 \begin_layout Standard
31060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31063 \begin_layout Standard
31064 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
31074 <row topline="true">
31075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31078 \begin_layout Standard
31080 \begin_inset LatexCommand \index{gputils (pic tools)}
31089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31092 \begin_layout Standard
31098 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31101 \begin_layout Standard
31102 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
31112 <row topline="true">
31113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31116 \begin_layout Standard
31122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31125 \begin_layout Standard
31131 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31134 \begin_layout Standard
31135 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
31145 <row topline="true">
31146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31149 \begin_layout Standard
31155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31158 \begin_layout Standard
31159 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
31165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31168 \begin_layout Standard
31169 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
31179 <row topline="true">
31180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31183 \begin_layout Standard
31185 \begin_inset LatexCommand \index{indent (source formatting tool)}
31194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31197 \begin_layout Standard
31198 Formats C source - Master of the white spaces
31203 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31206 \begin_layout Standard
31207 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
31217 <row topline="true">
31218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31221 \begin_layout Standard
31223 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
31232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31235 \begin_layout Standard
31236 Object file conversion, checksumming, ...
31241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31244 \begin_layout Standard
31245 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
31255 <row topline="true">
31256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31259 \begin_layout Standard
31261 \begin_inset LatexCommand \index{objdump (tool)}
31270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31273 \begin_layout Standard
31274 Object file conversion, ...
31279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31282 \begin_layout Standard
31283 Part of binutils (should be there anyway)
31289 <row topline="true">
31290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31293 \begin_layout Standard
31299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31302 \begin_layout Standard
31303 8051 monitor (hex up-/download, single step, disassemble)
31308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31311 \begin_layout Standard
31312 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
31322 <row topline="true">
31323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31326 \begin_layout Standard
31328 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
31337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31340 \begin_layout Standard
31341 Source code documentation system
31346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31349 \begin_layout Standard
31350 \begin_inset LatexCommand \url{http://www.doxygen.org}
31360 <row topline="true">
31361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31364 \begin_layout Standard
31370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31373 \begin_layout Standard
31374 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
31379 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31382 \begin_layout Standard
31383 \begin_inset LatexCommand \url{http://www.kdevelop.org}
31393 <row topline="true">
31394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31397 \begin_layout Standard
31403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31406 \begin_layout Standard
31407 8051 monitor (hex up-/download, single step, disassemble)
31412 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31415 \begin_layout Standard
31416 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
31426 <row topline="true">
31427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31430 \begin_layout Standard
31432 \begin_inset LatexCommand \index{splint (syntax checking tool)}
31441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31444 \begin_layout Standard
31445 Statically checks c sources (see
31446 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
31455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31458 \begin_layout Standard
31459 \begin_inset LatexCommand \url{http://www.splint.org}
31469 <row topline="true" bottomline="true">
31470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31473 \begin_layout Standard
31475 \begin_inset LatexCommand \index{DDD (debugger)}
31484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31487 \begin_layout Standard
31488 Debugger, serves nicely as GUI to SDCDB
31489 \begin_inset LatexCommand \index{SDCDB (debugger)}
31498 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31501 \begin_layout Standard
31502 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
31521 \begin_layout Section
31522 Related documentation / recommended reading
31525 \begin_layout Standard
31527 \begin_inset Tabular
31528 <lyxtabular version="3" rows="7" columns="3">
31530 <column alignment="left" valignment="top" leftline="true" width="0pt">
31531 <column alignment="left" valignment="top" leftline="true" width="0">
31532 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
31533 <row topline="true" bottomline="true">
31534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31537 \begin_layout Standard
31545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31548 \begin_layout Standard
31556 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31559 \begin_layout Standard
31568 <row topline="true">
31569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31572 \begin_layout Standard
31587 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31590 \begin_layout Standard
31592 \begin_inset LatexCommand \index{C Reference card}
31601 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31604 \begin_layout Standard
31605 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
31615 <row topline="true">
31616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31619 \begin_layout Standard
31625 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31628 \begin_layout Standard
31630 \begin_inset LatexCommand \index{C FAQ}
31639 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31642 \begin_layout Standard
31643 \begin_inset LatexCommand \url{http://www.c-faq.com}
31653 <row topline="true">
31654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31657 \begin_layout Standard
31663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31666 \begin_layout Standard
31667 \begin_inset Quotes sld
31671 \begin_inset Quotes srd
31679 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31682 \begin_layout Standard
31685 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
31695 <row topline="true">
31696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31699 \begin_layout Standard
31705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31708 \begin_layout Standard
31709 \begin_inset Quotes sld
31712 Extensions for Embedded C
31713 \begin_inset Quotes srd
31721 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31724 \begin_layout Standard
31727 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
31737 <row topline="true">
31738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31741 \begin_layout Standard
31747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31750 \begin_layout Standard
31751 Latest datasheet of target CPU
31756 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31759 \begin_layout Standard
31766 <row topline="true" bottomline="true">
31767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31770 \begin_layout Standard
31776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31779 \begin_layout Standard
31780 Revision history of datasheet
31785 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31788 \begin_layout Standard
31804 \begin_layout Section
31805 Application notes specifically for SDCC
31808 \begin_layout Standard
31809 SDCC makes no claims about the completeness of this list and about up-to-datenes
31810 s or correctness of the application notes
31811 \begin_inset LatexCommand \index{Application notes}
31818 \begin_layout Standard
31822 \begin_inset Tabular
31823 <lyxtabular version="3" rows="7" columns="3">
31825 <column alignment="block" valignment="top" leftline="true" width="17col%">
31826 <column alignment="block" valignment="top" leftline="true" width="27col%">
31827 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
31828 <row topline="true" bottomline="true">
31829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31832 \begin_layout Standard
31841 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
31844 \begin_layout Standard
31853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31856 \begin_layout Standard
31866 <row topline="true">
31867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31870 \begin_layout Standard
31878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31881 \begin_layout Standard
31884 Using the SDCC Compiler for the DS80C400
31885 \begin_inset LatexCommand \index{DS80C400}
31894 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31897 \begin_layout Standard
31900 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
31910 <row topline="true">
31911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31914 \begin_layout Standard
31922 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
31925 \begin_layout Standard
31928 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
31929 \begin_inset LatexCommand \index{DS89C4x0}
31933 Family of Microcontrollers
31938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31941 \begin_layout Standard
31944 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
31954 <row topline="true">
31955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31958 \begin_layout Standard
31961 Silicon Laboratories / Cygnal
31966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31969 \begin_layout Standard
31972 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
31973 \begin_inset LatexCommand \index{IDE}
31982 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31985 \begin_layout Standard
31988 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
31998 <row topline="true">
31999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32002 \begin_layout Standard
32005 Ramtron / Goal Semiconductor
32010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32013 \begin_layout Standard
32016 Interfacing SDCC to Syn and Textpad
32021 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32024 \begin_layout Standard
32027 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32037 <row topline="true">
32038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32041 \begin_layout Standard
32044 Ramtron / Goal Semiconductor
32049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32052 \begin_layout Standard
32055 Installing and Configuring SDCC and Crimson Editor
32060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32063 \begin_layout Standard
32066 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32076 <row topline="true" bottomline="true">
32077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32080 \begin_layout Standard
32088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32091 \begin_layout Standard
32094 MSC12xx Programming with SDCC
32099 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32102 \begin_layout Standard
32105 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
32122 \begin_layout Section
32126 \begin_layout Standard
32127 Some questions answered, some pointers given - it might be time to in turn
32135 \begin_layout Itemize
32136 can you solve your project with the selected microcontroller? Would you
32137 find out early or rather late that your target is too small/slow/whatever?
32138 Can you switch to a slightly better device if it doesn't fit?
32141 \begin_layout Itemize
32142 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
32143 and/or another programming language be more adequate? Would an operating
32144 system on the target device help?
32147 \begin_layout Itemize
32148 if you solved the problem, will the marketing department be happy?
32151 \begin_layout Itemize
32152 if the marketing department is happy, will customers be happy?
32155 \begin_layout Itemize
32156 if you're the project manager, marketing department and maybe even the customer
32157 in one person, have you tried to see the project from the outside?
32160 \begin_layout Itemize
32161 is the project done if you think it is done? Or is just that other interface/pro
32162 tocol/feature/configuration/option missing? How about website, manual(s),
32163 internationali(z|s)ation, packaging, labels, 2nd source for components,
32164 electromagnetic compatability/interference, documentation for production,
32165 production test software, update mechanism, patent issues?
32168 \begin_layout Itemize
32169 is your project adequately positioned in that magic triangle: fame, fortune,
32173 \begin_layout Standard
32174 Maybe not all answers to these questions are known and some answers may
32179 , nevertheless knowing these questions may help you to avoid burnout
32183 \begin_layout Standard
32184 burnout is bad for electronic devices, programmers and motorcycle tyres
32190 Chances are you didn't want to hear some of them...
32193 \begin_layout Chapter
32195 \begin_inset LatexCommand \index{Support}
32202 \begin_layout Standard
32203 SDCC has grown to be a large project.
32204 The compiler alone (without the preprocessor, assembler and linker) is
32205 well over 150,000 lines of code (blank stripped).
32206 The open source nature of this project is a key to its continued growth
32208 You gain the benefit and support of many active software developers and
32210 Is SDCC perfect? No, that's why we need your help.
32211 The developers take pride in fixing reported bugs.
32212 You can help by reporting the bugs and helping other SDCC users.
32213 There are lots of ways to contribute, and we encourage you to take part
32214 in making SDCC a great software package.
32218 \begin_layout Standard
32219 The SDCC project is hosted on the SDCC sourceforge site at
32220 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
32225 You'll find the complete set of mailing lists
32226 \begin_inset LatexCommand \index{Mailing list(s)}
32230 , forums, bug reporting system, patch submission
32231 \begin_inset LatexCommand \index{Patch submission}
32236 \begin_inset LatexCommand \index{download}
32240 area and Subversion code repository
32241 \begin_inset LatexCommand \index{Subversion code repository}
32248 \begin_layout Section
32250 \begin_inset LatexCommand \index{Bug reporting}
32255 \begin_inset LatexCommand \index{Reporting bugs}
32262 \begin_layout Standard
32263 The recommended way of reporting bugs is using the infrastructure of the
32265 You can follow the status of bug reports there and have an overview about
32269 \begin_layout Standard
32270 Bug reports are automatically forwarded to the developer mailing list and
32271 will be fixed ASAP.
32272 When reporting a bug, it is very useful to include a small test program
32273 (the smaller the better) which reproduces the problem.
32274 If you can isolate the problem by looking at the generated assembly code,
32275 this can be very helpful.
32276 Compiling your program with the -
32280 \begin_layout Standard
32290 \begin_inset LatexCommand \index{-\/-dumpall}
32294 option can sometimes be useful in locating optimization problems.
32295 When reporting a bug please make sure you:
32298 \begin_layout Enumerate
32299 Attach the code you are compiling with SDCC.
32303 \begin_layout Enumerate
32304 Specify the exact command you use to run SDCC, or attach your Makefile.
32308 \begin_layout Enumerate
32309 Specify the SDCC version (type "
32315 "), your platform, and operating system.
32319 \begin_layout Enumerate
32320 Provide an exact copy of any error message or incorrect output.
32324 \begin_layout Enumerate
32325 Put something meaningful in the subject of your message.
32328 \begin_layout Standard
32329 Please attempt to include these 5 important parts, as applicable, in all
32330 requests for support or when reporting any problems or bugs with SDCC.
32331 Though this will make your message lengthy, it will greatly improve your
32332 chance that SDCC users and developers will be able to help you.
32333 Some SDCC developers are frustrated by bug reports without code provided
32334 that they can use to reproduce and ultimately fix the problem, so please
32335 be sure to provide sample code if you are reporting a bug!
32338 \begin_layout Standard
32339 Please have a short check that you are using a recent version of SDCC and
32340 the bug is not yet known.
32341 This is the link for reporting bugs:
32342 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
32347 With SDCC on average having more than 200 downloads
32348 \begin_inset LatexCommand \index{download}
32352 on sourceforge per day
32356 \begin_layout Standard
32357 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
32358 between 2002 and 2005.
32359 This does not include other methods of distribution.
32364 there must be some users.
32365 So it's not exactly easy to find a new bug.
32366 If you find one we need it:
32368 reporting bugs is good
32373 \begin_layout Section
32374 Requesting Features
32375 \begin_inset LatexCommand \label{sub:Requesting-Features}
32380 \begin_inset LatexCommand \index{Feature request}
32385 \begin_inset LatexCommand \index{Requesting features}
32392 \begin_layout Standard
32393 Like bug reports feature requests are forwarded to the developer mailing
32395 This is the link for requesting features:
32396 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32403 \begin_layout Section
32407 \begin_layout Standard
32408 Like bug reports contributed patches are forwarded to the developer mailing
32410 This is the link for submitting patches
32411 \begin_inset LatexCommand \index{Patch submission}
32416 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
32423 \begin_layout Standard
32424 You need to specify some parameters to the
32428 command for the patches to be useful.
32429 If you modified more than one file a patch created f.e.
32434 \begin_inset Quotes sld
32437 diff -Naur unmodified_directory modified_directory >my_changes.patch
32438 \begin_inset Quotes srd
32444 will be fine, otherwise
32448 \begin_inset Quotes sld
32451 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
32452 \begin_inset Quotes srd
32462 \begin_layout Section
32466 \begin_layout Standard
32467 These links should take you directly to the
32468 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
32476 \begin_layout Standard
32477 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
32478 automated messages (mid 2003)
32484 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
32489 \begin_inset LatexCommand \index{Mailing list(s)}
32493 and forums are archived and searchable so if you are lucky someone already
32494 had a similar problem.
32495 While mails to the lists themselves are delivered promptly their web front
32496 end on sourceforge sometimes shows a severe time lag (up to several weeks),
32497 if you're seriously using SDCC please consider subscribing to the lists.
32500 \begin_layout Section
32504 \begin_layout Standard
32505 You can follow the status of the Subversion version
32506 \begin_inset LatexCommand \index{version}
32510 of SDCC by watching the Changelog
32511 \begin_inset LatexCommand \index{Changelog}
32515 in the Subversion repository
32518 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
32525 \begin_layout Section
32526 Subversion Source Code Repository
32529 \begin_layout Standard
32539 \begin_layout Standard
32553 or the filenames of the snapshot versions of SDCC include date and its
32555 \begin_inset LatexCommand \index{Subversion code repository}
32560 Subversion allows to download the source of recent or previous versions
32562 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
32566 (by number or by date).
32567 An on-line source code browser and detailled instructions are also available
32569 SDCC versions starting from 1999 up to now are available (currently the
32570 versions prior to the conversion from cvs
32571 \begin_inset LatexCommand \index{cvs|see{Subversion}}
32575 to Subversion (April 2006) are either by accessible by Subversion or by
32579 \begin_layout Section
32581 \begin_inset LatexCommand \index{Release policy}
32588 \begin_layout Standard
32589 Historically there often were long delays between official releases and
32590 the sourceforge download area tends to get not updated at all.
32591 Excuses in the past might have referred to problems with live range analysis,
32592 but as this was fixed a while ago, the current problem is that another
32593 excuse has to be found.
32594 Kidding aside, we have to get better there! On the other hand there are
32595 daily snapshots available at
32596 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
32600 , and you can always build the very last version (hopefully with many bugs
32601 fixed, and features added) from the source code available at
32602 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
32608 \begin_inset LatexCommand \index{wiki}
32613 \begin_inset LatexCommand \index{SDCC Wiki}
32618 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/}
32622 also holds some information about past and future releases.
32625 \begin_layout Section
32627 \begin_inset LatexCommand \index{Examples}
32634 \begin_layout Standard
32635 You'll find some small examples in the directory
32637 sdcc/device/examples/.
32640 More examples and libraries are available at
32642 The SDCC Open Knowledge Resource
32643 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
32650 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
32657 \begin_layout Standard
32658 \begin_inset Note Note
32661 \begin_layout Standard
32662 I did insert a reference to Paul's web site here although it seems rather
32663 dedicated to a specific 8032 board (I think it's okay because it f.e.
32664 shows LCD/Harddisc interface and has a free 8051 monitor.
32665 Independent 8032 board vendors face hard competition of heavily subsidized
32666 development boards anyway).
32669 \begin_layout Standard
32670 Maybe we should include some links to real world applications.
32671 Preferably pointer to pointers (one for each architecture) so this stays
32680 \begin_layout Section
32682 \begin_inset LatexCommand \label{sec:Quality-control}
32687 \begin_inset LatexCommand \index{Quality control}
32694 \begin_layout Standard
32695 The compiler is passed through snaphot build compile and build checks.
32701 \begin_inset LatexCommand \index{Regression test}
32705 check that SDCC itself compiles flawlessly on several host platforms (i386,
32706 Opteron, 64 bit Alpha, ppc64, Mac OS X on PPC, Solaris on Sparc) and checks
32707 the quality of the code generated by SDCC by running the code for several
32708 target platforms through simulators.
32709 The regression test suite comprises more than 100 files which expand to
32710 more than 500 test cases which include more than 4500 tests.
32711 The results of these tests are published daily on SDCC's snapshot page
32712 (click on the red or green symbols on the right side of
32713 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
32720 \begin_layout Standard
32721 There is a separate document
32724 \begin_inset LatexCommand \index{Test suite}
32731 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
32735 about the regression test suite.
32738 \begin_layout Standard
32739 You'll find the test code in the directory
32741 sdcc/support/regression
32744 You can run these tests manually by running
32748 in this directory (or f.e.
32753 \begin_inset Quotes sld
32757 \begin_inset Quotes srd
32763 if you don't want to run the complete tests).
32764 The test code might also be interesting if you want to look for examples
32765 \begin_inset LatexCommand \index{Examples}
32769 checking corner cases of SDCC or if you plan to submit patches
32770 \begin_inset LatexCommand \index{Patch submission}
32777 \begin_layout Standard
32778 The PIC14 port uses a different set of regression tests
32779 \begin_inset LatexCommand \index{Regression test (PIC14)}
32783 , you'll find them in the directory
32785 sdcc/src/regression
32790 \begin_layout Section
32791 Use of SDCC in Education
32794 \begin_layout Standard
32803 \begin_layout Standard
32804 the phrase "use in education" might evoke the association "
32808 fit for use in education".
32809 This connotation is not intended but nevertheless risked as the licensing
32810 of SDCC makes it difficult to offer educational discounts
32816 If your rationales are to:
32819 \begin_layout Enumerate
32820 give students a chance to understand the
32824 steps of code generation
32827 \begin_layout Enumerate
32828 have a curriculum that can be extended for years.
32829 Then you could use an fpga board as target and your curriculum will seamlessly
32830 extend from logic synthesis (
32831 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
32836 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
32840 ), over assembly programming, to C to FPGA compilers (
32841 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
32848 \begin_layout Enumerate
32849 be able to insert excursions about skills like using a revision control
32850 system, submitting/applying patches, using a type-setting (as opposed to
32851 word-processing) engine LyX/LaTeX, using
32852 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
32857 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
32861 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
32862 Source Software, CPU simulation, compiler regression tests
32863 \begin_inset LatexCommand \index{Regression test}
32870 And if there should be a shortage of ideas then you can always point students
32871 to the ever-growing feature request list
32872 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32879 \begin_layout Enumerate
32880 not tie students to a specific host platform and instead allow them to use
32885 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
32887 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
32894 \begin_layout Enumerate
32895 not encourage students to use illegal copies of educational software
32898 \begin_layout Enumerate
32899 be immune to licensing/availability/price changes of the chosen tool chain
32902 \begin_layout Enumerate
32903 be able to change to a new target platform without having to adopt a new
32907 \begin_layout Enumerate
32908 have complete control over and insight into the tool chain
32911 \begin_layout Enumerate
32912 make your students aware about the pros and cons of open source software
32916 \begin_layout Enumerate
32917 give back to the public as you are probably at least partially publically
32921 \begin_layout Enumerate
32922 give students a chance to publically prove their skills and to possibly
32923 see a world wide impact
32926 \begin_layout Standard
32927 then SDCC is probably among the first choices.
32928 Well, probably SDCC might be the only choice.
32933 \begin_layout Chapter
32934 SDCC Technical Data
32937 \begin_layout Section
32939 \begin_inset LatexCommand \index{Optimizations}
32946 \begin_layout Standard
32947 SDCC performs a host of standard optimizations in addition to some MCU specific
32952 \begin_layout Subsection
32953 Sub-expression Elimination
32954 \begin_inset LatexCommand \index{Subexpression elimination}
32961 \begin_layout Standard
32962 The compiler does local and
32981 \begin_layout Verse
32989 \begin_layout Standard
32990 will be translated to
32993 \begin_layout Verse
33003 \begin_layout Standard
33004 Some subexpressions are not as obvious as the above example, e.g.:
33007 \begin_layout Verse
33015 \begin_layout Standard
33016 In this case the address arithmetic a->b[i] will be computed only once;
33017 the equivalent code in C would be.
33020 \begin_layout Verse
33030 \begin_layout Standard
33031 The compiler will try to keep these temporary variables in registers.
33034 \begin_layout Subsection
33035 Dead-Code Elimination
33036 \begin_inset LatexCommand \index{Dead-code elimination}
33043 \begin_layout Verse
33058 i = 1; \InsetSpace ~
33067 global = 1;\InsetSpace ~
33081 global = 3;\InsetSpace ~
33087 \begin_layout Standard
33091 \begin_layout Verse
33107 \begin_layout Subsection
33109 \begin_inset LatexCommand \index{Copy propagation}
33116 \begin_layout Verse
33140 \begin_layout Standard
33144 \begin_layout Verse
33168 \begin_layout Standard
33169 Note: the dead stores created by this copy propagation will be eliminated
33170 by dead-code elimination.
33173 \begin_layout Subsection
33175 \begin_inset LatexCommand \index{Loop optimization}
33180 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
33187 \begin_layout Standard
33188 Two types of loop optimizations are done by SDCC
33196 of loop induction variables.
33197 In addition to the strength reduction the optimizer marks the induction
33198 variables and the register allocator tries to keep the induction variables
33199 in registers for the duration of the loop.
33200 Because of this preference of the register allocator
33201 \begin_inset LatexCommand \index{Register allocation}
33205 , loop induction optimization causes an increase in register pressure, which
33206 may cause unwanted spilling of other temporary variables into the stack
33207 \begin_inset LatexCommand \index{stack}
33212 The compiler will generate a warning message when it is forced to allocate
33213 extra space either on the stack or data space.
33214 If this extra space allocation is undesirable then induction optimization
33215 can be eliminated either for the entire source file (with -
33219 \begin_layout Standard
33228 -noinduction option) or for a given function only using #pragma\InsetSpace ~
33230 \begin_inset LatexCommand \index{\#pragma noinduction}
33241 \begin_layout Verse
33244 for (i = 0 ; i < 100 ; i ++)
33253 \begin_layout Standard
33257 \begin_layout Verse
33262 for (i = 0; i < 100; i++)
33271 \begin_layout Standard
33272 As mentioned previously some loop invariants are not as apparent, all static
33273 address computations are also moved out of the loop.
33278 \begin_inset LatexCommand \index{Strength reduction}
33282 , this optimization substitutes an expression by a cheaper expression:
33285 \begin_layout Verse
33288 for (i=0;i < 100; i++)
33297 \begin_layout Standard
33301 \begin_layout Verse
33308 for (i=0;i< 100;i++) {
33314 ar[itemp1] = itemp2;
33332 \begin_layout Standard
33333 The more expensive multiplication
33334 \begin_inset LatexCommand \index{Multiplication}
33338 is changed to a less expensive addition.
33341 \begin_layout Subsection
33343 \begin_inset LatexCommand \index{Loop reversing}
33350 \begin_layout Standard
33351 This optimization is done to reduce the overhead of checking loop boundaries
33352 for every iteration.
33353 Some simple loops can be reversed and implemented using a
33354 \begin_inset Quotes eld
33357 decrement and jump if not zero
33358 \begin_inset Quotes erd
33362 SDCC checks for the following criterion to determine if a loop is reversible
33363 (note: more sophisticated compilers use data-dependency analysis to make
33364 this determination, SDCC uses a more simple minded analysis).
33367 \begin_layout Itemize
33368 The 'for' loop is of the form
33374 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
33384 \begin_layout Itemize
33385 The <for body> does not contain
33386 \begin_inset Quotes eld
33390 \begin_inset Quotes erd
33394 \begin_inset Quotes erd
33400 \begin_layout Itemize
33401 All goto's are contained within the loop.
33404 \begin_layout Itemize
33405 No function calls within the loop.
33408 \begin_layout Itemize
33409 The loop control variable <sym> is not assigned any value within the loop
33412 \begin_layout Itemize
33413 The loop control variable does NOT participate in any arithmetic operation
33417 \begin_layout Itemize
33418 There are NO switch statements in the loop.
33421 \begin_layout Subsection
33422 Algebraic Simplifications
33425 \begin_layout Standard
33426 SDCC does numerous algebraic simplifications, the following is a small sub-set
33427 of these optimizations.
33430 \begin_layout Verse
33433 i = j + 0;\InsetSpace ~
33437 /* changed to: */\InsetSpace ~
33443 i /= 2;\InsetSpace ~
33450 /* changed to: */\InsetSpace ~
33457 = j - j;\InsetSpace ~
33461 /* changed to: */\InsetSpace ~
33467 i = j / 1;\InsetSpace ~
33471 /* changed to: */\InsetSpace ~
33478 \begin_layout Standard
33479 Note the subexpressions
33480 \begin_inset LatexCommand \index{Subexpression}
33484 given above are generally introduced by macro expansions or as a result
33485 of copy/constant propagation.
33488 \begin_layout Subsection
33489 'switch' Statements
33490 \begin_inset LatexCommand \label{sub:'switch'-Statements}
33495 \begin_inset LatexCommand \index{switch statement}
33502 \begin_layout Standard
33503 SDCC can optimize switch statements to jump tables
33504 \begin_inset LatexCommand \index{jump tables}
33509 It makes the decision based on an estimate of the generated code size.
33510 SDCC is quite liberal in the requirements for jump table generation:
33513 \begin_layout Itemize
33514 The labels need not be in order, and the starting number need not be one
33515 or zero, the case labels are in numerical sequence or not too many case
33516 labels are missing.
33520 \begin_layout Verse
33523 switch(i) {\InsetSpace ~
33554 case 4: ...\InsetSpace ~
33586 case 5: ...\InsetSpace ~
33618 case 3: ...\InsetSpace ~
33649 case 6: ...\InsetSpace ~
33681 case 7: ...\InsetSpace ~
33713 case 8: ...\InsetSpace ~
33745 case 9: ...\InsetSpace ~
33777 case 10: ...\InsetSpace ~
33808 case 11: ...\InsetSpace ~
33875 \begin_layout Standard
33876 Both the above switch statements will be implemented using a jump-table.
33877 The example to the right side is slightly more efficient as the check for
33878 the lower boundary of the jump-table is not needed.
33882 \begin_layout Itemize
33883 The number of case labels is not larger than supported by the target architectur
33887 \begin_layout Itemize
33888 If the case labels are not in numerical sequence ('gaps' between cases)
33889 SDCC checks whether a jump table with additionally inserted dummy cases
33890 is still attractive.
33894 \begin_layout Itemize
33895 If the starting number is not zero and a check for the lower boundary of
33896 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
33901 \begin_layout Standard
33902 Switch statements which have large gaps in the numeric sequence or those
33903 that have too many case labels can be split into more than one switch statement
33904 for efficient code generation, e.g.:
33907 \begin_layout Verse
33985 \begin_layout Standard
33986 If the above switch statement is broken down into two switch statements
33989 \begin_layout Verse
34032 \begin_layout Standard
34036 \begin_layout Verse
34079 \begin_layout Standard
34080 then both the switch statements will be implemented using jump-tables whereas
34081 the unmodified switch statement will not be.
34084 \begin_layout Standard
34085 \begin_inset Note Note
34088 \begin_layout Standard
34089 There might be reasons which SDCC cannot know about to either favour or
34090 not favour jump tables.
34091 If the target system has to be as quick for the last switch case as for
34092 the first (pro jump table), or if the switch argument is known to be zero
34093 in the majority of the cases (contra jump table).
34101 \begin_layout Standard
34102 The pragma nojtbound
34103 \begin_inset LatexCommand \index{\#pragma nojtbound}
34107 can be used to turn off checking the
34120 It has no effect if a default label is supplied.
34121 Use of this pragma is dangerous: if the switch
34122 \begin_inset LatexCommand \index{switch statement}
34126 argument is not matched by a case statement the processor will happily
34130 \begin_layout Subsection
34131 Bit-shifting Operations
34132 \begin_inset LatexCommand \index{Bit shifting}
34139 \begin_layout Standard
34140 Bit shifting is one of the most frequently used operation in embedded programmin
34142 SDCC tries to implement bit-shift operations in the most efficient way
34146 \begin_layout Verse
34159 \begin_layout Standard
34160 generates the following code:
34163 \begin_layout Verse
34178 \begin_layout Standard
34179 In general SDCC will never setup a loop if the shift count is known.
34183 \begin_layout Verse
34196 \begin_layout Standard
34200 \begin_layout Verse
34224 \begin_layout Subsection
34226 \begin_inset LatexCommand \index{Bit rotation}
34233 \begin_layout Standard
34234 A special case of the bit-shift operation is bit rotation
34235 \begin_inset LatexCommand \index{rotating bits}
34239 , SDCC recognizes the following expression to be a left bit-rotation:
34242 \begin_layout Verse
34250 char i;\InsetSpace ~
34261 /* unsigned is needed for rotation */
34266 i = ((i << 1) | (i >> 7));
34275 \begin_layout Standard
34276 will generate the following code:
34279 \begin_layout Verse
34296 \begin_layout Standard
34297 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
34298 ns of this case will also be recognized as bit-rotation, i.e.:
34301 \begin_layout Verse
34304 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
34307 \begin_layout Subsection
34308 Nibble and Byte Swapping
34311 \begin_layout Standard
34312 Other special cases of the bit-shift operations are nibble or byte swapping
34313 \begin_inset LatexCommand \index{swapping nibbles/bytes}
34317 , SDCC recognizes the following expressions:
34320 \begin_layout Verse
34341 i = ((i << 4) | (i >> 4));
34347 j = ((j << 8) | (j >> 8));
34350 \begin_layout Standard
34351 and generates a swap instruction for the nibble swapping
34352 \begin_inset LatexCommand \index{Nibble swapping}
34356 or move instructions for the byte swapping
34357 \begin_inset LatexCommand \index{Byte swapping}
34363 \begin_inset Quotes sld
34367 \begin_inset Quotes srd
34370 example can be used to convert from little to big-endian or vice versa.
34371 If you want to change the endianness of a
34375 integer you have to cast to
34382 \begin_layout Standard
34383 Note that SDCC stores numbers in little-endian
34387 \begin_layout Standard
34388 Usually 8-bit processors don't care much about endianness.
34389 This is not the case for the standard 8051 which only has an instruction
34395 \begin_inset LatexCommand \index{DPTR}
34403 so little-endian is the more efficient byte order.
34409 \begin_inset LatexCommand \index{little-endian}
34414 \begin_inset LatexCommand \index{Endianness}
34419 lowest order first).
34422 \begin_layout Subsection
34424 \begin_inset LatexCommand \index{Highest Order Bit}
34429 \begin_inset LatexCommand \index{Any Order Bit}
34436 \begin_layout Standard
34437 It is frequently required to obtain the highest order bit of an integral
34438 type (long, int, short or char types).
34439 Also obtaining any other order bit is not uncommon.
34440 SDCC recognizes the following expressions to yield the highest order bit
34441 and generates optimized code for it, e.g.:
34444 \begin_layout Verse
34455 unsigned char hob1, aob1;
34459 bit hob2, hob3, aob2,
34469 hob1 = (gint >> 15) & 1;
34473 hob2 = (gint >> 15) & 1;
34477 hob3 = gint & 0x8000;
34482 aob1 = (gint >> 9) & 1;
34486 aob2 = (gint >> 8) & 1;
34490 aob3 = gint & 0x0800;
34500 \begin_layout Standard
34501 will generate the following code:
34504 \begin_layout Verse
34535 000A E5*01\InsetSpace ~
34562 000C 23\InsetSpace ~
34593 000D 54 01\InsetSpace ~
34621 000F F5*02\InsetSpace ~
34676 0011 E5*01\InsetSpace ~
34704 0013 33\InsetSpace ~
34734 0014 92*00\InsetSpace ~
34790 0016 E5*01\InsetSpace ~
34817 0018 33\InsetSpace ~
34847 0019 92*01\InsetSpace ~
34903 001B E5*01\InsetSpace ~
34962 001E 54 01\InsetSpace ~
34989 0020 F5*03\InsetSpace ~
35045 0022 E5*01\InsetSpace ~
35072 0024 13\InsetSpace ~
35102 0025 92*02\InsetSpace ~
35158 0027 E5*01\InsetSpace ~
35213 002B 92*03\InsetSpace ~
35241 \begin_layout Standard
35242 Other variations of these cases however will
35247 They are standard C expressions, so I heartily recommend these be the only
35248 way to get the highest order bit, (it is portable).
35249 Of course it will be recognized even if it is embedded in other expressions,
35253 \begin_layout Verse
35256 xyz = gint + ((gint >> 15) & 1);
35259 \begin_layout Standard
35260 will still be recognized.
35263 \begin_layout Subsection
35265 \begin_inset LatexCommand \index{Higher Order Byte}
35269 / Higher Order Word
35270 \begin_inset LatexCommand \index{Higher Order Word}
35277 \begin_layout Standard
35278 It is also frequently required to obtain a higher order byte or word of
35279 a larger integral type (long, int or short types).
35280 SDCC recognizes the following expressions to yield the higher order byte
35281 or word and generates optimized code for it, e.g.:
35284 \begin_layout Verse
35289 unsigned long int glong;
35297 unsigned char hob1,
35302 unsigned int how1, how2;
35311 hob1 = (gint >> 8) & 0xFF;
35315 hob2 = glong >> 24;
35319 how1 = (glong >> 16) & 0xFFFF;
35334 \begin_layout Standard
35335 will generate the following code:
35338 \begin_layout Verse
35369 0037 85*01*06\InsetSpace ~
35391 _foo_hob1_1_1,(_gint + 1)
35422 003A 85*05*07\InsetSpace ~
35444 _foo_hob2_1_1,(_glong + 3)
35474 003D 85*04*08\InsetSpace ~
35497 _foo_how1_1_1,(_glong + 2)
35499 0040 85*05*09\InsetSpace ~
35524 0043 85*03*0A\InsetSpace ~
35546 _foo_how2_1_1,(_glong + 1)
35548 0046 85*04*0B\InsetSpace ~
35571 (_foo_how2_1_1 + 1),(_glong + 2)
35574 \begin_layout Standard
35575 Again, variations of these cases may
35580 They are standard C expressions, so I heartily recommend these be the only
35581 way to get the higher order byte/word, (it is portable).
35582 Of course it will be recognized even if it is embedded in other expressions,
35586 \begin_layout Verse
35589 xyz = gint + ((gint >> 8) & 0xFF);
35592 \begin_layout Standard
35593 will still be recognized.
35596 \begin_layout Subsection
35598 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
35603 \begin_inset LatexCommand \index{Peephole optimizer}
35610 \begin_layout Standard
35611 The compiler uses a rule based, pattern matching and re-writing mechanism
35612 for peep-hole optimization.
35617 a peep-hole optimizer by Christopher W.
35618 Fraser (cwfraser\InsetSpace ~
35621 A default set of rules are compiled into the compiler, additional rules
35622 may be added with the
35628 \begin_layout Standard
35638 \begin_inset LatexCommand \index{-\/-peep-file}
35645 The rule language is best illustrated with examples.
35648 \begin_layout Verse
35670 \begin_layout Standard
35671 The above rule will change the following assembly
35672 \begin_inset LatexCommand \index{Assembler routines}
35679 \begin_layout Verse
35687 \begin_layout Standard
35691 \begin_layout Verse
35697 \begin_layout Standard
35698 Note: All occurrences of a
35702 (pattern variable) must denote the same string.
35703 With the above rule, the assembly sequence:
35706 \begin_layout Verse
35714 \begin_layout Standard
35715 will remain unmodified.
35719 Other special case optimizations may be added by the
35726 \begin_layout Standard
35739 some variants of the 8051 MCU
35740 \begin_inset LatexCommand \index{MCS51 variants}
35753 The following two rules will change all
35770 \begin_layout Verse
35773 replace { lcall %1 } by { acall %1 }
35775 replace { ljmp %1 } by { ajmp %1 }
35778 \begin_layout Standard
35779 (NOTE: from version 2.7.3 on, you can use option -
35785 \begin_layout Standard
35797 \begin_inset LatexCommand \index{-\/-acall-ajmp}
35801 , which also takes care of aligning the interrupt vectors properly.)
35806 \begin_layout Standard
35809 inline-assembler code
35811 is also passed through the peep hole optimizer, thus the peephole optimizer
35812 can also be used as an assembly level macro expander.
35813 The rules themselves are MCU dependent whereas the rule language infra-structur
35814 e is MCU independent.
35815 Peephole optimization rules for other MCU can be easily programmed using
35820 The syntax for a rule is as follows:
35823 \begin_layout Verse
35826 rule := replace [ restart ] '{' <assembly sequence> '
35864 <assembly sequence> '
35882 '}' [if <functionName> ] '
35887 \begin_layout Standard
35888 <assembly sequence> := assembly instruction (each instruction including
35889 labels must be on a separate line).
35893 The optimizer will apply to the rules
35894 one by one from the top in the sequence of their appearance, it will terminate
35895 when all rules are exhausted.
35896 If the 'restart' option is specified, then the optimizer will start matching
35897 the rules again from the top, this option for a rule is expensive (performance)
35898 , it is intended to be used in situations where a transformation will trigger
35899 the same rule again.
35900 An example of this (not a good one, it has side effects) is the following
35904 \begin_layout Verse
35924 \begin_layout Standard
35925 Note that the replace pattern cannot be a blank, but can be a comment line.
35926 Without the 'restart' option only the innermost 'pop' 'push' pair would
35927 be eliminated, i.e.:
35930 \begin_layout Verse
35942 \begin_layout Standard
35946 \begin_layout Verse
35956 \begin_layout Standard
35961 the restart option the rule will be applied again to the resulting code
35962 and then all the pop-push pairs will be eliminated to yield:
35965 \begin_layout Verse
35973 \begin_layout Standard
35974 A conditional function can be attached to a rule.
35975 Attaching rules are somewhat more involved, let me illustrate this with
35979 \begin_layout Verse
36003 \begin_layout Standard
36004 The optimizer does a look-up of a function name table defined in function
36009 in the source file SDCCpeeph.c, with the name
36014 If it finds a corresponding entry the function is called.
36015 Note there can be no parameters specified for these functions, in this
36020 is crucial, since the function
36024 expects to find the label in that particular variable (the hash table containin
36025 g the variable bindings is passed as a parameter).
36026 If you want to code more such functions, take a close look at the function
36027 labelInRange and the calling mechanism in source file SDCCpeeph.c.
36028 Currently implemented are
36030 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
36031 24bitMode, portIsDS390, 24bitModeAndPortDS390
36040 \begin_layout Standard
36041 I know this whole thing is a little kludgey, but maybe some day we will
36042 have some better means.
36043 If you are looking at this file, you will see the default rules that are
36044 compiled into the compiler, you can add your own rules in the default set
36045 there if you get tired of specifying the -
36049 \begin_layout Standard
36061 \begin_layout Section
36063 \begin_inset LatexCommand \index{ANSI-compliance}
36068 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
36075 \begin_layout Standard
36076 The latest publically available version of the standard
36078 ISO/IEC 9899 - Programming languages - C
36080 should be available at:
36081 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
36090 \begin_layout Standard
36091 Deviations from the compliance:
36094 \begin_layout Itemize
36095 functions are not reentrant
36096 \begin_inset LatexCommand \index{reentrant}
36100 unless explicitly declared as such or the
36106 \begin_layout Standard
36116 \begin_inset LatexCommand \index{-\/-stack-auto}
36122 command line option is specified.
36125 \begin_layout Itemize
36127 \begin_inset LatexCommand \index{struct}
36132 \begin_inset LatexCommand \index{union}
36136 cannot be assigned values directly, cannot be passed as function parameters
36137 or assigned to each other and cannot be a return value
36138 \begin_inset LatexCommand \index{return value}
36142 from a function, e.g.:
36146 \begin_layout Verse
36169 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
36188 s parms) /* invalid in SDCC although allowed in ANSI */
36210 return rets; /* is invalid in SDCC although allowed in ANSI */
36216 \begin_layout Itemize
36217 initialization of structure arrays must be fully braced.
36221 \begin_layout Verse
36224 struct s { char x } a[] = {1, 2};\InsetSpace ~
36229 /* invalid in SDCC */
36232 } a[] = {{1}, {2}}; /* OK */
36236 \begin_layout Itemize
36238 \begin_inset LatexCommand \index{long long (not supported)}
36243 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
36250 \begin_layout Itemize
36252 \begin_inset LatexCommand \index{double (not supported)}
36256 ' precision floating point
36257 \begin_inset LatexCommand \index{Floating point support}
36264 \begin_layout Itemize
36266 \begin_inset LatexCommand \index{K\&R style}
36270 function declarations are NOT allowed.
36274 \begin_layout Verse
36277 foo(i,j) /* this old style of function declarations */
36279 int i,j; /* is valid
36280 in ANSI but not valid in SDCC */
36295 \begin_layout Itemize
36296 Most enhancements in C99 are not supported, e.g.:
36300 \begin_layout Verse
36307 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
36311 \begin_layout Itemize
36312 But some have been added recently in SDCC 2.7.0.
36313 They must be considered alpha quality however.
36317 \begin_layout Verse
36322 \begin_inset LatexCommand \index{inline (not supported)}
36328 int increment (int a) { return a+1; } /* inlines the increment without
36329 function call overhead */
36334 \begin_inset LatexCommand \index{inline (not supported)}
36340 p; /* accepted but ignored */
36344 \begin_layout Itemize
36345 Certain words that are valid identifiers in the standard may be reserved
36346 words in SDCC unless the
36352 \begin_layout Standard
36362 \begin_inset LatexCommand \index{-\/-std-c89}
36370 \begin_layout Standard
36380 \begin_inset LatexCommand \index{-\/-std-c99}
36386 command line options are used.
36387 These may include (depending on the selected processor): 'at', 'banked',
36388 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
36389 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
36390 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
36392 Compliant equivalents of these keywords are always available in a form
36393 that begin with two underscores
36394 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
36399 '__data' instead of 'data'.
36402 \begin_layout Section
36403 Cyclomatic Complexity
36404 \begin_inset LatexCommand \index{Cyclomatic complexity}
36411 \begin_layout Standard
36412 Cyclomatic complexity of a function is defined as the number of independent
36413 paths the program can take during execution of the function.
36414 This is an important number since it defines the number test cases you
36415 have to generate to validate the function.
36416 The accepted industry standard for complexity number is 10, if the cyclomatic
36417 complexity reported by SDCC exceeds 10 you should think about simplification
36418 of the function logic.
36419 Note that the complexity level is not related to the number of lines of
36420 code in a function.
36421 Large functions can have low complexity, and small functions can have large
36427 SDCC uses the following formula to compute the complexity:
36432 \begin_layout Standard
36433 complexity = (number of edges in control flow graph) - (number of nodes
36434 in control flow graph) + 2;
36438 Having said that the industry standard is 10,
36439 you should be aware that in some cases it be may unavoidable to have a
36440 complexity level of less than 10.
36441 For example if you have switch statement with more than 10 case labels,
36442 each case label adds one to the complexity level.
36443 The complexity level is by no means an absolute measure of the algorithmic
36444 complexity of the function, it does however provide a good starting point
36445 for which functions you might look at for further optimization.
36448 \begin_layout Section
36449 Retargetting for other Processors
36452 \begin_layout Standard
36453 The issues for retargetting the compiler are far too numerous to be covered
36455 What follows is a brief description of each of the seven phases of the
36456 compiler and its MCU dependency.
36459 \begin_layout Itemize
36460 Parsing the source and building the annotated parse tree.
36461 This phase is largely MCU independent (except for the language extensions).
36462 Syntax & semantic checks are also done in this phase, along with some initial
36463 optimizations like back patching labels and the pattern matching optimizations
36464 like bit-rotation etc.
36467 \begin_layout Itemize
36468 The second phase involves generating an intermediate code which can be easy
36469 manipulated during the later phases.
36470 This phase is entirely MCU independent.
36471 The intermediate code generation assumes the target machine has unlimited
36472 number of registers, and designates them with the name iTemp.
36473 The compiler can be made to dump a human readable form of the code generated
36478 \begin_layout Standard
36490 \begin_layout Itemize
36491 This phase does the bulk of the standard optimizations and is also MCU independe
36493 This phase can be broken down into several sub-phases:
36497 Break down intermediate
36498 code (iCode) into basic blocks.
36500 Do control flow & data flow analysis on the
36503 Do local common subexpression elimination, then global subexpressio
36506 Dead code elimination
36510 If loop optimizations
36511 caused any changes then do 'global subexpression elimination' and 'dead
36512 code elimination' again.
36515 \begin_layout Itemize
36516 This phase determines the live-ranges; by live range I mean those iTemp
36517 variables defined by the compiler that still survive after all the optimization
36519 Live range analysis
36520 \begin_inset LatexCommand \index{Live range analysis}
36524 is essential for register allocation, since these computation determines
36525 which of these iTemps will be assigned to registers, and for how long.
36528 \begin_layout Itemize
36529 Phase five is register allocation.
36530 There are two parts to this process.
36534 The first part I call 'register packing'
36535 (for lack of a better term).
36536 In this case several MCU specific expression folding is done to reduce
36541 The second part is more MCU independent and deals with
36542 allocating registers to the remaining live ranges.
36543 A lot of MCU specific code does creep into this phase because of the limited
36544 number of index registers available in the 8051.
36547 \begin_layout Itemize
36548 The Code generation phase is (unhappily), entirely MCU dependent and very
36549 little (if any at all) of this code can be reused for other MCU.
36550 However the scheme for allocating a homogenized assembler operand for each
36551 iCode operand may be reused.
36554 \begin_layout Itemize
36555 As mentioned in the optimization section the peep-hole optimizer is rule
36556 based system, which can reprogrammed for other MCUs.
36559 \begin_layout Standard
36560 More information is available on SDCC Wiki
36561 \begin_inset LatexCommand \index{wiki}
36566 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting}
36570 ) and in the thread
36571 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
36578 \begin_layout Chapter
36580 \begin_inset LatexCommand \index{Compiler internals}
36587 \begin_layout Section
36588 The anatomy of the compiler
36589 \begin_inset LatexCommand \label{sub:The-anatomy-of}
36596 \begin_layout Standard
36599 This is an excerpt from an article published in Circuit Cellar Magazine
36605 It's a little outdated (the compiler is much more efficient now and user/develo
36606 per friendly), but pretty well exposes the guts of it all.
36612 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
36613 It is fairly easy to retarget for other 8-bit MCU.
36614 Here we take a look at some of the internals of the compiler.
36618 \begin_layout Paragraph*
36620 \begin_inset LatexCommand \index{Parsing}
36627 \begin_layout Standard
36628 Parsing the input source file and creating an AST (Annotated Syntax Tree
36629 \begin_inset LatexCommand \index{Annotated syntax tree}
36634 This phase also involves propagating types (annotating each node of the
36635 parse tree with type information) and semantic analysis.
36636 There are some MCU specific parsing rules.
36637 For example the storage classes, the extended storage classes are MCU specific
36638 while there may be a xdata storage class for 8051 there is no such storage
36639 class for z80 or Atmel AVR.
36640 SDCC allows MCU specific storage class extensions, i.e.
36641 xdata will be treated as a storage class specifier when parsing 8051 C
36642 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
36646 \begin_layout Paragraph*
36648 \begin_inset LatexCommand \index{iCode}
36655 \begin_layout Standard
36656 Intermediate code generation.
36657 In this phase the AST is broken down into three-operand form (iCode).
36658 These three operand forms are represented as doubly linked lists.
36659 ICode is the term given to the intermediate form generated by the compiler.
36660 ICode example section shows some examples of iCode generated for some simple
36661 C source functions.
36664 \begin_layout Paragraph*
36666 \begin_inset LatexCommand \index{Optimizations}
36673 \begin_layout Standard
36674 Bulk of the target independent optimizations is performed in this phase.
36675 The optimizations include constant propagation, common sub-expression eliminati
36676 on, loop invariant code movement, strength reduction of loop induction variables
36677 and dead-code elimination.
36680 \begin_layout Paragraph*
36681 Live range analysis
36682 \begin_inset LatexCommand \index{Live range analysis}
36689 \begin_layout Standard
36690 During intermediate code generation phase, the compiler assumes the target
36691 machine has infinite number of registers and generates a lot of temporary
36693 The live range computation determines the lifetime of each of these compiler-ge
36694 nerated temporaries.
36695 A picture speaks a thousand words.
36696 ICode example sections show the live range annotations for each of the
36698 It is important to note here, each iCode is assigned a number in the order
36699 of its execution in the function.
36700 The live ranges are computed in terms of these numbers.
36701 The from number is the number of the iCode which first defines the operand
36702 and the to number signifies the iCode which uses this operand last.
36705 \begin_layout Paragraph*
36706 Register Allocation
36707 \begin_inset LatexCommand \index{Register allocation}
36714 \begin_layout Standard
36715 The register allocation determines the type and number of registers needed
36717 In most MCUs only a few registers can be used for indirect addressing.
36718 In case of 8051 for example the registers R0 & R1 can be used to indirectly
36719 address the internal ram and DPTR to indirectly address the external ram.
36720 The compiler will try to allocate the appropriate register to pointer variables
36722 ICode example section shows the operands annotated with the registers assigned
36724 The compiler will try to keep operands in registers as much as possible;
36725 there are several schemes the compiler uses to do achieve this.
36726 When the compiler runs out of registers the compiler will check to see
36727 if there are any live operands which is not used or defined in the current
36728 basic block being processed, if there are any found then it will push that
36729 operand and use the registers in this block, the operand will then be popped
36730 at the end of the basic block.
36734 \begin_layout Standard
36735 There are other MCU specific considerations in this phase.
36736 Some MCUs have an accumulator; very short-lived operands could be assigned
36737 to the accumulator instead of a general-purpose register.
36740 \begin_layout Paragraph*
36744 \begin_layout Standard
36745 Figure II gives a table of iCode
36746 \begin_inset LatexCommand \index{iCode}
36750 operations supported by the compiler.
36751 The code generation involves translating these operations into corresponding
36752 assembly code for the processor.
36753 This sounds overly simple but that is the essence of code generation.
36754 Some of the iCode operations are generated on a MCU specific manner for
36755 example, the z80 port does not use registers to pass parameters so the
36756 SEND and RECV iCode operations will not be generated, and it also does
36757 not support JUMPTABLES.
36763 \begin_layout Standard
36767 \begin_inset Tabular
36768 <lyxtabular version="3" rows="39" columns="4">
36769 <features islongtable="true" headBottomDL="true">
36770 <column alignment="block" valignment="top" leftline="true" width="13col%">
36771 <column alignment="left" valignment="top" leftline="true" width="13col%">
36772 <column alignment="block" valignment="top" leftline="true" width="22col%">
36773 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
36774 <row topline="true" bottomline="true" endhead="true">
36775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36778 \begin_layout Standard
36784 \begin_inset LatexCommand \index{iCode}
36793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36796 \begin_layout Standard
36804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36807 \begin_layout Standard
36815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36818 \begin_layout Standard
36827 <row topline="true">
36828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36831 \begin_layout Standard
36839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36842 \begin_layout Standard
36845 IC_LEFT() IC_RESULT()
36850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36853 \begin_layout Standard
36861 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36864 \begin_layout Standard
36867 IC_RESULT = ! IC_LEFT;
36873 <row topline="true">
36874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36877 \begin_layout Standard
36885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36888 \begin_layout Standard
36891 IC_LEFT() IC_RESULT()
36896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36899 \begin_layout Standard
36902 Bitwise complement of
36907 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36910 \begin_layout Standard
36913 IC_RESULT = ~IC_LEFT;
36919 <row topline="true">
36920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36923 \begin_layout Standard
36931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36934 \begin_layout Standard
36937 IC_LEFT() IC_RESULT()
36942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36945 \begin_layout Standard
36948 Rotate right with carry
36953 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36956 \begin_layout Standard
36959 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
36965 <row topline="true">
36966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36969 \begin_layout Standard
36977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36980 \begin_layout Standard
36983 IC_LEFT() IC_RESULT()
36988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36991 \begin_layout Standard
36994 Rotate left with carry
36999 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37002 \begin_layout Standard
37005 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
37011 <row topline="true">
37012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37015 \begin_layout Standard
37023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37026 \begin_layout Standard
37029 IC_LEFT() IC_RESULT()
37034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37037 \begin_layout Standard
37040 Get the highest order bit of IC_LEFT
37045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37048 \begin_layout Standard
37051 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
37057 <row topline="true">
37058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37061 \begin_layout Standard
37069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37072 \begin_layout Standard
37075 IC_LEFT() IC_RESULT()
37080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37083 \begin_layout Standard
37091 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37094 \begin_layout Standard
37097 IC_RESULT = - IC_LEFT;
37103 <row topline="true">
37104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37107 \begin_layout Standard
37115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37118 \begin_layout Standard
37126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37129 \begin_layout Standard
37132 Push the operand into stack
37137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37140 \begin_layout Standard
37149 <row topline="true">
37150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37153 \begin_layout Standard
37161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37164 \begin_layout Standard
37172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37175 \begin_layout Standard
37178 Pop the operand from the stack
37183 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37186 \begin_layout Standard
37195 <row topline="true">
37196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37199 \begin_layout Standard
37207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37210 \begin_layout Standard
37213 IC_LEFT() IC_RESULT()
37218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37221 \begin_layout Standard
37224 Call the function represented by IC_LEFT
37229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37232 \begin_layout Standard
37235 IC_RESULT = IC_LEFT();
37241 <row topline="true">
37242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37245 \begin_layout Standard
37253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37256 \begin_layout Standard
37259 IC_LEFT() IC_RESULT()
37264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37267 \begin_layout Standard
37270 Call via function pointer
37275 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37278 \begin_layout Standard
37281 IC_RESULT = (*IC_LEFT)();
37287 <row topline="true">
37288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37291 \begin_layout Standard
37299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37302 \begin_layout Standard
37310 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37313 \begin_layout Standard
37316 Return the value in operand IC_LEFT
37321 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37324 \begin_layout Standard
37333 <row topline="true">
37334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37337 \begin_layout Standard
37345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37348 \begin_layout Standard
37356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37359 \begin_layout Standard
37367 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37370 \begin_layout Standard
37379 <row topline="true">
37380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37383 \begin_layout Standard
37391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37394 \begin_layout Standard
37402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37405 \begin_layout Standard
37413 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37416 \begin_layout Standard
37425 <row topline="true">
37426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37429 \begin_layout Standard
37437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37440 \begin_layout Standard
37443 IC_LEFT() IC_RIGHT() IC_RESULT()
37448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37451 \begin_layout Standard
37459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37462 \begin_layout Standard
37465 IC_RESULT = IC_LEFT + IC_RIGHT
37471 <row topline="true">
37472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37475 \begin_layout Standard
37483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37486 \begin_layout Standard
37489 IC_LEFT() IC_RIGHT() IC_RESULT()
37494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37497 \begin_layout Standard
37505 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37508 \begin_layout Standard
37511 IC_RESULT = IC_LEFT - IC_RIGHT
37517 <row topline="true">
37518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37521 \begin_layout Standard
37529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37532 \begin_layout Standard
37535 IC_LEFT() IC_RIGHT() IC_RESULT()
37540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37543 \begin_layout Standard
37551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37554 \begin_layout Standard
37557 IC_RESULT = IC_LEFT * IC_RIGHT;
37563 <row topline="true">
37564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37567 \begin_layout Standard
37575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37578 \begin_layout Standard
37581 IC_LEFT() IC_RIGHT() IC_RESULT()
37586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37589 \begin_layout Standard
37597 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37600 \begin_layout Standard
37603 IC_RESULT = IC_LEFT / IC_RIGHT;
37609 <row topline="true">
37610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37613 \begin_layout Standard
37621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37624 \begin_layout Standard
37627 IC_LEFT() IC_RIGHT() IC_RESULT()
37632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37635 \begin_layout Standard
37643 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37646 \begin_layout Standard
37649 IC_RESULT = IC_LEFT % IC_RIGHT;
37655 <row topline="true">
37656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37659 \begin_layout Standard
37667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37670 \begin_layout Standard
37673 IC_LEFT() IC_RIGHT() IC_RESULT()
37678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37681 \begin_layout Standard
37689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37692 \begin_layout Standard
37695 IC_RESULT = IC_LEFT < IC_RIGHT;
37701 <row topline="true">
37702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37705 \begin_layout Standard
37713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37716 \begin_layout Standard
37719 IC_LEFT() IC_RIGHT() IC_RESULT()
37724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37727 \begin_layout Standard
37735 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37738 \begin_layout Standard
37741 IC_RESULT = IC_LEFT > IC_RIGHT;
37747 <row topline="true">
37748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37751 \begin_layout Standard
37759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37762 \begin_layout Standard
37765 IC_LEFT() IC_RIGHT() IC_RESULT()
37770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37773 \begin_layout Standard
37781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37784 \begin_layout Standard
37787 IC_RESULT = IC_LEFT == IC_RIGHT;
37793 <row topline="true">
37794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37797 \begin_layout Standard
37805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37808 \begin_layout Standard
37811 IC_LEFT() IC_RIGHT() IC_RESULT()
37816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37819 \begin_layout Standard
37822 Logical and operation
37827 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37830 \begin_layout Standard
37833 IC_RESULT = IC_LEFT && IC_RIGHT;
37839 <row topline="true">
37840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37843 \begin_layout Standard
37851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37854 \begin_layout Standard
37857 IC_LEFT() IC_RIGHT() IC_RESULT()
37862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37865 \begin_layout Standard
37868 Logical or operation
37873 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37876 \begin_layout Standard
37879 IC_RESULT = IC_LEFT || IC_RIGHT;
37885 <row topline="true">
37886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37889 \begin_layout Standard
37897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37900 \begin_layout Standard
37903 IC_LEFT() IC_RIGHT() IC_RESULT()
37908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37911 \begin_layout Standard
37919 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37922 \begin_layout Standard
37925 IC_RESULT = IC_LEFT ^ IC_RIGHT;
37931 <row topline="true">
37932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37935 \begin_layout Standard
37943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37946 \begin_layout Standard
37949 IC_LEFT() IC_RIGHT() IC_RESULT()
37954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37957 \begin_layout Standard
37965 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37968 \begin_layout Standard
37971 IC_RESULT = IC_LEFT | IC_RIGHT;
37977 <row topline="true">
37978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37981 \begin_layout Standard
37989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37992 \begin_layout Standard
37995 IC_LEFT() IC_RIGHT() IC_RESULT()
38000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38003 \begin_layout Standard
38011 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38014 \begin_layout Standard
38017 IC_RESULT = IC_LEFT & IC_RIGHT;
38023 <row topline="true">
38024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38027 \begin_layout Standard
38035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38038 \begin_layout Standard
38041 IC_LEFT() IC_RIGHT() IC_RESULT()
38046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38049 \begin_layout Standard
38057 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38060 \begin_layout Standard
38063 IC_RESULT = IC_LEFT << IC_RIGHT
38069 <row topline="true">
38070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38073 \begin_layout Standard
38081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38084 \begin_layout Standard
38087 IC_LEFT() IC_RIGHT() IC_RESULT()
38092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38095 \begin_layout Standard
38103 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38106 \begin_layout Standard
38109 IC_RESULT = IC_LEFT >> IC_RIGHT
38115 <row topline="true">
38116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38119 \begin_layout Standard
38129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38132 \begin_layout Standard
38135 IC_LEFT() IC_RESULT()
38140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38143 \begin_layout Standard
38151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38154 \begin_layout Standard
38157 IC_RESULT = (*IC_LEFT);
38163 <row topline="true">
38164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38167 \begin_layout Standard
38175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38178 \begin_layout Standard
38181 IC_RIGHT() IC_RESULT()
38186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38189 \begin_layout Standard
38197 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38200 \begin_layout Standard
38203 (*IC_RESULT) = IC_RIGHT;
38209 <row topline="true">
38210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38213 \begin_layout Standard
38221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38224 \begin_layout Standard
38227 IC_RIGHT() IC_RESULT()
38232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38235 \begin_layout Standard
38243 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38246 \begin_layout Standard
38249 IC_RESULT = IC_RIGHT;
38255 <row topline="true">
38256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38259 \begin_layout Standard
38267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38270 \begin_layout Standard
38273 IC_COND IC_TRUE IC_LABEL
38278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38281 \begin_layout Standard
38285 If true label is present then jump to true label if condition is true else
38286 jump to false label if condition is false
38291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38294 \begin_layout Standard
38297 if (IC_COND) goto IC_TRUE;
38303 If (!IC_COND) goto IC_FALSE;
38309 <row topline="true">
38310 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38313 \begin_layout Standard
38321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38324 \begin_layout Standard
38327 IC_LEFT() IC_RESULT()
38332 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38335 \begin_layout Standard
38343 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38346 \begin_layout Standard
38349 IC_RESULT = &IC_LEFT();
38355 <row topline="true">
38356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38359 \begin_layout Standard
38367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38370 \begin_layout Standard
38373 IC_JTCOND IC_JTLABELS
38378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38381 \begin_layout Standard
38384 Jump to list of labels depending on the value of JTCOND
38389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38392 \begin_layout Standard
38401 <row topline="true">
38402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38405 \begin_layout Standard
38413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38416 \begin_layout Standard
38419 IC_RIGHT() IC_LEFT() IC_RESULT()
38424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38427 \begin_layout Standard
38435 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38438 \begin_layout Standard
38441 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
38447 <row topline="true">
38448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38451 \begin_layout Standard
38459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38462 \begin_layout Standard
38470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38473 \begin_layout Standard
38476 This is used for passing parameters in registers;
38478 move IC_LEFT to the next
38479 available parameter register.
38484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38487 \begin_layout Standard
38496 <row topline="true">
38497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38500 \begin_layout Standard
38508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38511 \begin_layout Standard
38519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38522 \begin_layout Standard
38525 This is used for receiving parameters passed in registers;
38528 in the next parameter register to IC_RESULT
38533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38536 \begin_layout Standard
38545 <row topline="true" bottomline="true">
38546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38549 \begin_layout Standard
38553 (some more have been added)
38558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38561 \begin_layout Standard
38567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38570 \begin_layout Standard
38576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38579 \begin_layout Standard
38603 \begin_layout Standard
38604 \begin_inset Note Note
38607 \begin_layout Standard
38608 In the original article Figure II was announced to be downloadable on
38613 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
38621 \begin_layout Paragraph*
38623 \begin_inset LatexCommand \index{iCode}
38630 \begin_layout Standard
38631 This section shows some details of iCode.
38632 The example C code does not do anything useful; it is used as an example
38633 to illustrate the intermediate code generated by the compiler.
38636 \begin_layout Verse
38646 /* This function does nothing useful.
38653 for the purpose of explaining iCode */
38656 short function (data
38665 short i=10; \InsetSpace ~
38667 /* dead initialization eliminated */
38673 /* dead initialization eliminated */
38701 /* compiler detects i,j to be induction
38706 for (i = 0, j = 10 ; i < 10 ; i++, j
38712 \begin_layout Standard
38735 mul += i * 3; \InsetSpace ~
38737 /* this multiplication remains */
38744 j * 3;\InsetSpace ~
38746 /* this multiplication changed to addition */
38760 \begin_layout Standard
38761 In addition to the operands each iCode contains information about the filename
38762 and line it corresponds to in the source file.
38763 The first field in the listing should be interpreted as follows:
38768 Filename(linenumber: iCode Execution sequence number : ICode hash table
38769 key : loop depth of the iCode).
38774 Then follows the human readable form of the ICode operation.
38775 Each operand of this triplet form can be of three basic types a) compiler
38776 generated temporary b) user defined variable c) a constant value.
38777 Note that local variables and parameters are replaced by compiler generated
38780 \begin_inset LatexCommand \index{Live range analysis}
38784 are computed only for temporaries (i.e.
38785 live ranges are not computed for global variables).
38787 \begin_inset LatexCommand \index{Register allocation}
38791 are allocated for temporaries only.
38792 Operands are formatted in the following manner:
38797 Operand Name [lr live-from : live-to ] { type information } [ registers
38803 As mentioned earlier the live ranges are computed in terms of the execution
38804 sequence number of the iCodes, for example
38806 the iTemp0 is live from (i.e.
38807 first defined in iCode with execution sequence number 3, and is last used
38808 in the iCode with sequence number 5).
38809 For induction variables such as iTemp21 the live range computation extends
38810 the lifetime from the start to the end of the loop.
38812 The register allocator
38813 used the live range information to allocate registers, the same registers
38814 may be used for different temporaries if their live ranges do not overlap,
38815 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
38816 ranges do not overlap.
38817 In addition the allocator also takes into consideration the type and usage
38818 of a temporary, for example itemp6 is a pointer to near space and is used
38819 as to fetch data from (i.e.
38820 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
38821 Some short lived temporaries are allocated to special registers which have
38822 meaning to the code generator e.g.
38823 iTemp13 is allocated to a pseudo register CC which tells the back end that
38824 the temporary is used only for a conditional jump the code generation makes
38825 use of this information to optimize a compare and jump ICode.
38829 \begin_inset LatexCommand \index{Loop optimization}
38833 performed by the compiler.
38834 It can detect induction variables iTemp21(i) and iTemp23(j).
38835 Also note the compiler does selective strength reduction
38836 \begin_inset LatexCommand \index{Strength reduction}
38841 the multiplication of an induction variable in line 18 (gint = j * 3) is
38842 changed to addition, a new temporary iTemp17 is allocated and assigned
38843 a initial value, a constant 3 is then added for each iteration of the loop.
38844 The compiler does not change the multiplication
38845 \begin_inset LatexCommand \index{Multiplication}
38849 in line 17 however since the processor does support an 8 * 8 bit multiplication.
38852 Note the dead code elimination
38853 \begin_inset LatexCommand \index{Dead-code elimination}
38857 optimization eliminated the dead assignments in line 7 & 8 to I and sum
38863 \begin_layout Standard
38866 Sample.c (5:1:0:0) _entry($9) :
38869 \begin_layout Standard
38872 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
38875 \begin_layout Standard
38878 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
38881 \begin_layout Standard
38884 Sample.c(11:4:53:0) preHeaderLbl0($11) :
38887 \begin_layout Standard
38890 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
38894 \begin_layout Standard
38897 Sample.c(11:6:5:1) _whilecontinue_0($1) :
38900 \begin_layout Standard
38903 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
38907 \begin_layout Standard
38910 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38913 \begin_layout Standard
38916 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
38920 \begin_layout Standard
38923 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
38927 \begin_layout Standard
38930 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
38934 \begin_layout Standard
38937 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
38941 \begin_layout Standard
38944 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
38945 * int}[r0] + 0x2 {short}
38948 \begin_layout Standard
38951 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
38954 \begin_layout Standard
38957 Sample.c(11:17:21:0)_whilebreak_0($3) :
38960 \begin_layout Standard
38963 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38966 \begin_layout Standard
38969 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38972 \begin_layout Standard
38975 Sample.c(15:20:54:0)preHeaderLbl1($13) :
38978 \begin_layout Standard
38981 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38984 \begin_layout Standard
38987 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38990 \begin_layout Standard
38993 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38996 \begin_layout Standard
38999 Sample.c(15:24:26:1)_forcond_0($4) :
39002 \begin_layout Standard
39005 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
39009 \begin_layout Standard
39012 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39015 \begin_layout Standard
39018 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
39019 + ITemp21 [lr21:38]{short}[r4]
39022 \begin_layout Standard
39025 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
39029 \begin_layout Standard
39032 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
39033 + iTemp15 [lr29:30]{short}[r1]
39036 \begin_layout Standard
39039 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
39043 \begin_layout Standard
39046 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
39050 \begin_layout Standard
39053 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
39057 \begin_layout Standard
39060 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
39064 \begin_layout Standard
39067 Sample.c(19:38:47:1) goto _forcond_0($4)
39070 \begin_layout Standard
39073 Sample.c(19:39:48:0)_forbreak_0($7) :
39076 \begin_layout Standard
39079 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
39080 + ITemp11 [lr19:40]{short}[r3]
39083 \begin_layout Standard
39086 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
39089 \begin_layout Standard
39092 Sample.c(20:42:51:0)_return($8) :
39095 \begin_layout Standard
39098 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
39104 Finally the code generated for this function:
39109 \begin_layout Standard
39115 \begin_layout Standard
39121 \begin_layout Standard
39129 \begin_layout Standard
39135 \begin_layout Standard
39143 \begin_layout Standard
39149 \begin_layout Standard
39152 ; ----------------------------------------------
39155 \begin_layout Standard
39158 ; function function
39161 \begin_layout Standard
39164 ; ----------------------------------------------
39167 \begin_layout Standard
39173 \begin_layout Standard
39176 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
39179 \begin_layout Standard
39187 \begin_layout Standard
39190 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
39193 \begin_layout Standard
39201 \begin_layout Standard
39204 ;_whilecontinue_0($1) :
39207 \begin_layout Standard
39213 \begin_layout Standard
39216 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
39219 \begin_layout Standard
39222 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39225 \begin_layout Standard
39233 \begin_layout Standard
39241 \begin_layout Standard
39249 \begin_layout Standard
39257 \begin_layout Standard
39265 \begin_layout Standard
39273 \begin_layout Standard
39281 \begin_layout Standard
39287 \begin_layout Standard
39290 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
39293 \begin_layout Standard
39301 \begin_layout Standard
39309 \begin_layout Standard
39312 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
39315 \begin_layout Standard
39323 \begin_layout Standard
39331 \begin_layout Standard
39339 \begin_layout Standard
39347 \begin_layout Standard
39355 \begin_layout Standard
39363 \begin_layout Standard
39366 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
39369 \begin_layout Standard
39377 \begin_layout Standard
39385 \begin_layout Standard
39393 \begin_layout Standard
39401 \begin_layout Standard
39409 \begin_layout Standard
39412 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
39415 \begin_layout Standard
39423 \begin_layout Standard
39431 \begin_layout Standard
39439 \begin_layout Standard
39442 ; iTemp6 [lr5:16]{_near * int}[r0] =
39445 \begin_layout Standard
39448 ; iTemp6 [lr5:16]{_near * int}[r0] +
39451 \begin_layout Standard
39457 \begin_layout Standard
39465 \begin_layout Standard
39468 ; goto _whilecontinue_0($1)
39471 \begin_layout Standard
39479 \begin_layout Standard
39482 ; _whilebreak_0($3) :
39485 \begin_layout Standard
39491 \begin_layout Standard
39494 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39497 \begin_layout Standard
39505 \begin_layout Standard
39508 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39511 \begin_layout Standard
39519 \begin_layout Standard
39522 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39525 \begin_layout Standard
39533 \begin_layout Standard
39536 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39539 \begin_layout Standard
39547 \begin_layout Standard
39555 \begin_layout Standard
39558 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39561 \begin_layout Standard
39569 \begin_layout Standard
39577 \begin_layout Standard
39583 \begin_layout Standard
39589 \begin_layout Standard
39592 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
39595 \begin_layout Standard
39598 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39601 \begin_layout Standard
39609 \begin_layout Standard
39617 \begin_layout Standard
39625 \begin_layout Standard
39633 \begin_layout Standard
39641 \begin_layout Standard
39647 \begin_layout Standard
39650 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
39653 \begin_layout Standard
39656 ; iTemp21 [lr21:38]{short}[r4]
39659 \begin_layout Standard
39667 \begin_layout Standard
39675 \begin_layout Standard
39683 \begin_layout Standard
39686 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
39689 \begin_layout Standard
39697 \begin_layout Standard
39705 \begin_layout Standard
39713 \begin_layout Standard
39721 \begin_layout Standard
39724 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
39727 \begin_layout Standard
39730 ; iTemp15 [lr29:30]{short}[r1]
39733 \begin_layout Standard
39741 \begin_layout Standard
39749 \begin_layout Standard
39752 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
39755 \begin_layout Standard
39763 \begin_layout Standard
39771 \begin_layout Standard
39779 \begin_layout Standard
39787 \begin_layout Standard
39795 \begin_layout Standard
39803 \begin_layout Standard
39806 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
39809 \begin_layout Standard
39817 \begin_layout Standard
39825 \begin_layout Standard
39833 \begin_layout Standard
39841 \begin_layout Standard
39849 \begin_layout Standard
39857 \begin_layout Standard
39860 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
39863 \begin_layout Standard
39871 \begin_layout Standard
39874 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
39877 \begin_layout Standard
39885 \begin_layout Standard
39890 cjne r5,#0xff,00104$
39893 \begin_layout Standard
39901 \begin_layout Standard
39904 ; goto _forcond_0($4)
39907 \begin_layout Standard
39915 \begin_layout Standard
39918 ; _forbreak_0($7) :
39921 \begin_layout Standard
39927 \begin_layout Standard
39930 ; ret iTemp24 [lr40:41]{short}
39933 \begin_layout Standard
39941 \begin_layout Standard
39949 \begin_layout Standard
39957 \begin_layout Standard
39963 \begin_layout Standard
39969 \begin_layout Standard
39979 \begin_layout Section
39980 A few words about basic block successors, predecessors and dominators
39983 \begin_layout Standard
39984 Successors are basic blocks
39985 \begin_inset LatexCommand \index{Basic blocks}
39989 that might execute after this basic block.
39991 Predecessors are basic blocks
39992 that might execute before reaching this basic block.
39994 Dominators are basic
39995 blocks that WILL execute before reaching this basic block.
40000 \begin_layout Standard
40004 \begin_layout Standard
40008 \begin_layout Standard
40016 \begin_layout Standard
40020 \begin_layout Standard
40028 \begin_layout Standard
40034 \begin_layout Standard
40035 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
40038 \begin_layout Standard
40039 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
40042 \begin_layout Standard
40043 c) domVect of [BB4] = BB1 ...
40044 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
40048 \begin_layout Chapter
40052 \begin_layout Standard
40053 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
40063 Thanks to all the other volunteer developers who have helped with coding,
40064 testing, web-page creation, distribution sets, etc.
40065 You know who you are :-)
40073 Thanks to Sourceforge
40074 \begin_inset LatexCommand \url{http://www.sf.net}
40078 which has hosted the project since 1999 and donates significant download
40087 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
40088 cycles and bandwidth for snapshot builds.
40093 \begin_layout Standard
40094 This document was initially written by Sandeep Dutta
40097 \begin_layout Standard
40098 All product names mentioned herein may be trademarks
40099 \begin_inset LatexCommand \index{Trademarks}
40103 of their respective companies.
40107 \begin_layout Section*
40111 \begin_layout Standard
40112 To avoid confusion, the installation and building options for SDCC itself
40113 (chapter 2) are not part of the index.
40116 \begin_layout Standard
40117 \begin_inset LatexCommand \printindex{}