1 #LyX 1.5.0 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
55 \begin_layout Standard
56 \begin_inset Note Note
59 \begin_layout Standard
60 Please note: double dashed longoptions (e.g.
61 --version) are written this way: -
65 \begin_layout Standard
77 \begin_layout Standard
79 three consecutive dashes would otherwise result in a long resp.
83 \begin_layout Standard
84 Architecture specific stuff (like memory models, code examples) should maybe
88 \begin_layout Standard
89 into seperate sections/chapters/appendices (it is hard to document PIC or
93 \begin_layout Standard
94 a 8051 centered document) - for now simply add.
103 SDCC Compiler User Guide
118 \begin_layout Standard
119 \begin_inset Note Note
122 \begin_layout Standard
123 The above strings enclosed in $ are automatically updated by Subversion
131 \begin_layout Standard
132 \begin_inset LatexCommand \tableofcontents{}
139 \begin_layout Chapter
143 \begin_layout Section
147 \begin_layout Standard
168 ompiler) is free open source, retargettable, optimizing ANSI-C compiler
173 designed for 8 bit Microprocessors.
174 The current version targets Intel MCS51 based Microprocessors (8031, 8032,
176 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
180 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
181 Zilog Z80 based MCUs.
182 It can be retargeted for other microprocessors, support for Microchip PIC,
183 Atmel AVR is under development.
184 The entire source code for the compiler is distributed under GPL.
186 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
191 \begin_inset LatexCommand \index{aslink}
195 , an open source retargetable assembler & linker.
196 SDCC has extensive language extensions suitable for utilizing various microcont
197 rollers and underlying hardware effectively.
202 In addition to the MCU specific optimizations SDCC also does a host of
203 standard optimizations like:
206 \begin_layout Itemize
207 global sub expression elimination,
210 \begin_layout Itemize
211 loop optimizations (loop invariant, strength reduction of induction variables
215 \begin_layout Itemize
216 constant folding & propagation,
219 \begin_layout Itemize
223 \begin_layout Itemize
224 dead code elimination
227 \begin_layout Itemize
235 \begin_layout Standard
236 For the back-end SDCC uses a global register allocation scheme which should
237 be well suited for other 8 bit MCUs.
242 The peep hole optimizer uses a rule based substitution mechanism which
248 Supported data-types are:
251 \begin_layout Standard
253 <lyxtabular version="3" rows="8" columns="5">
255 <column alignment="center" valignment="top" leftline="true" width="0">
256 <column alignment="center" valignment="top" leftline="true" width="0">
257 <column alignment="center" valignment="top" leftline="true" width="0">
258 <column alignment="center" valignment="top" leftline="true" width="0">
259 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
260 <row topline="true" bottomline="true">
261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
264 \begin_layout Standard
270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
273 \begin_layout Standard
279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
282 \begin_layout Standard
288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
291 \begin_layout Standard
297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
300 \begin_layout Standard
308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
311 \begin_layout Standard
317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
320 \begin_layout Standard
326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
329 \begin_layout Standard
335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
338 \begin_layout Standard
344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
347 \begin_layout Standard
355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
358 \begin_layout Standard
364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
367 \begin_layout Standard
373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
376 \begin_layout Standard
382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
385 \begin_layout Standard
391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
394 \begin_layout Standard
402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
405 \begin_layout Standard
411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
414 \begin_layout Standard
420 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
423 \begin_layout Standard
429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
432 \begin_layout Standard
438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
441 \begin_layout Standard
449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
452 \begin_layout Standard
458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
461 \begin_layout Standard
467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
470 \begin_layout Standard
476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
479 \begin_layout Standard
485 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
488 \begin_layout Standard
495 <row topline="true" bottomline="true">
496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
499 \begin_layout Standard
505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
508 \begin_layout Standard
514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
517 \begin_layout Standard
523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
526 \begin_layout Standard
527 -2.147.483.648, +2.147.483.647
532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
535 \begin_layout Standard
542 <row topline="true" bottomline="true">
543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
546 \begin_layout Standard
552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
555 \begin_layout Standard
561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
564 \begin_layout Standard
570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
573 \begin_layout Standard
579 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
582 \begin_layout Standard
598 <row topline="true" bottomline="true">
599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
602 \begin_layout Standard
608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
611 \begin_layout Standard
617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
620 \begin_layout Standard
626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
629 \begin_layout Standard
635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
638 \begin_layout Standard
651 The compiler also allows
653 inline assembler code
655 to be embedded anywhere in a function.
656 In addition, routines developed in assembly can also be called.
661 provides an option (-
665 \begin_layout Standard
674 -cyclomatic) to report the relative complexity of a function.
675 These functions can then be further optimized, or hand coded in assembly
681 SDCC also comes with a companion source level debugger SDCDB.
682 The debugger currently uses ucSim, a free open source simulator for 8051
683 and other micro-controllers.
687 The latest SDCC version can be downloaded from
689 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
696 Please note: the compiler will probably always be some steps ahead of this
701 \begin_inset LatexCommand \index{Status of documentation}
709 \begin_layout Standard
710 Obviously this has pros and cons
718 \begin_layout Section
722 \begin_layout Standard
723 All packages used in this compiler system are
731 ; source code for all the sub-packages (pre-processor, assemblers, linkers
732 etc.) is distributed with the package.
733 This documentation is maintained using a free open source word processor
736 This program is free software; you can redistribute it and/or modify
737 it under the terms of the GNU General Public License
738 \begin_inset LatexCommand \index{GNU General Public License, GPL}
742 as published by the Free Software Foundation; either version 2, or (at
743 your option) any later version.
744 This program is distributed in the hope that it will be useful, but WITHOUT
745 ANY WARRANTY; without even the implied warranty
746 \begin_inset LatexCommand \index{warranty}
750 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
751 See the GNU General Public License for more details.
752 You should have received a copy of the GNU General Public License along
753 with this program; if not, write to the Free Software Foundation, 59 Temple
754 Place - Suite 330, Boston, MA 02111-1307, USA.
755 In other words, you are welcome to use, share and improve this program.
756 You are forbidden to forbid anyone else to use, share and improve what
758 Help stamp out software-hoarding!
761 \begin_layout Section
762 Typographic conventions
763 \begin_inset LatexCommand \index{Typographic conventions}
770 \begin_layout Standard
771 Throughout this manual, we will use the following convention.
772 Commands you have to type in are printed in
780 Code samples are printed in
785 Interesting items and new terms are printed in
790 \begin_layout Section
792 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
796 with previous versions
797 \begin_inset LatexCommand \index{Compatibility with previous versions}
804 \begin_layout Standard
805 Newer versions have usually numerous bug fixes compared with the previous
807 But we also sometimes introduce some incompatibilities with older versions.
808 Not just for the fun of it, but to make the compiler more stable, efficient
810 \begin_inset LatexCommand \index{ANSI-compliance}
815 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
819 for ANSI-Compliance).
821 \begin_inset Note Note
824 \begin_layout Standard
825 It would be fine to add to each item, in which version was it changed.
835 \begin_layout Itemize
836 short is now equivalent to int (16 bits), it used to be equivalent to char
837 (8 bits) which is not ANSI compliant.
838 To maintain compatibility, old programs may be compiled using the -
842 \begin_layout Standard
851 -short-is-8bits commandline option (see
852 \begin_inset LatexCommand \vref{lyx:--short-is-8bits}
859 \begin_layout Itemize
860 the default directory for gcc-builds where include, library and documentation
861 files are stored is now in /usr/local/share.
864 \begin_layout Itemize
865 char type parameters to vararg
866 \begin_inset LatexCommand \index{vararg, va\\_arg}
870 functions are casted to int unless explicitly casted
871 \begin_inset Marginal
874 \begin_layout Standard
899 will push a as an int and as a char resp.
902 \begin_layout Itemize
907 \begin_layout Standard
916 -regextend has been removed.
919 \begin_layout Itemize
924 \begin_layout Standard
933 -noregparms has been removed.
936 \begin_layout Itemize
941 \begin_layout Standard
950 -stack-after-data has been removed.
953 \begin_layout Itemize
955 \begin_inset LatexCommand \index{bit}
960 \begin_inset LatexCommand \index{sbit}
965 \begin_inset LatexCommand \index{\\_\\_sbit}
969 types now consistently behave like the C99 _Bool type with respect to type
971 \begin_inset LatexCommand \index{type conversion}
976 \begin_inset LatexCommand \index{type promotion}
981 The most common incompatibility resulting from this change is related to
983 \begin_inset LatexCommand \index{Bit toggling}
998 \begin_inset LatexCommand \index{\\~\\/ Operator}
1002 b; /* equivalent to b=1 instead of toggling b */
1003 \begin_inset Marginal
1006 \begin_layout Standard
1019 b = !b; /* toggles b */
1023 In previous versions, both forms would have toggled the bit.
1026 \begin_layout Standard
1029 <pending: more incompatibilities?>
1032 \begin_layout Section
1036 \begin_layout Standard
1037 What do you need before you start installation of SDCC? A computer, and
1038 a desire to compute.
1039 The preferred method of installation is to compile SDCC from source using
1041 For Windows some pre-compiled binary distributions are available for your
1043 You should have some experience with command line tools and compiler use.
1046 \begin_layout Section
1050 \begin_layout Standard
1051 The SDCC home page at
1052 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1056 is a great place to find distribution sets.
1057 You can also find links to the user mailing lists that offer help or discuss
1058 SDCC with other SDCC users.
1059 Web links to other SDCC related sites can also be found here.
1060 This document can be found in the DOC directory of the source package as
1061 a text or HTML file.
1062 A pdf version of this document is available at
1063 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1068 Some of the other tools (simulator and assembler) included with SDCC contain
1069 their own documentation and can be found in the source distribution.
1070 If you want the latest unreleased software, the complete source package
1071 is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1075 \begin_layout Section
1076 Wishes for the future
1079 \begin_layout Standard
1080 There are (and always will be) some things that could be done.
1081 Here are some I can think of:
1086 \begin_layout Standard
1089 char KernelFunction3(char p) at 0x340;
1094 \begin_layout Standard
1098 \begin_inset LatexCommand \index{code banking (limited support)}
1108 If you can think of some more, please see the section
1109 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1113 about filing feature requests
1114 \begin_inset LatexCommand \index{Requesting features}
1119 \begin_inset LatexCommand \index{Feature request}
1128 \begin_layout Chapter
1130 \begin_inset LatexCommand \index{Installation}
1137 \begin_layout Standard
1138 For most users it is sufficient to skip to either section
1139 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1144 \begin_inset LatexCommand \ref{sub:Windows-Install}
1149 More detailed instructions follow below.
1152 \begin_layout Section
1154 \begin_inset LatexCommand \index{Options SDCC configuration}
1161 \begin_layout Standard
1162 The install paths, search paths and other options are defined when running
1164 The defaults can be overridden by:
1168 \labelwidthstring 00.00.0000
1173 \begin_layout Standard
1182 -prefix see table below
1186 \labelwidthstring 00.00.0000
1191 \begin_layout Standard
1200 -exec_prefix see table below
1204 \labelwidthstring 00.00.0000
1209 \begin_layout Standard
1218 -bindir see table below
1222 \labelwidthstring 00.00.0000
1227 \begin_layout Standard
1236 -datadir see table below
1240 \labelwidthstring 00.00.0000
1245 \begin_layout Standard
1254 -datarootdir see table below
1260 \labelwidthstring 00.00.0000
1263 docdir environment variable, see table below
1267 \labelwidthstring 00.00.0000
1270 include_dir_suffix environment variable, see table below
1274 \labelwidthstring 00.00.0000
1277 lib_dir_suffix environment variable, see table below
1281 \labelwidthstring 00.00.0000
1284 sdccconf_h_dir_separator environment variable, either / or
1289 This character will only be used in sdccconf.h; don't forget it's a C-header,
1290 therefore a double-backslash is needed there.
1296 \labelwidthstring 00.00.0000
1301 \begin_layout Standard
1310 -disable-mcs51-port Excludes the Intel mcs51 port
1314 \labelwidthstring 00.00.0000
1319 \begin_layout Standard
1328 -disable-gbz80-port Excludes the Gameboy gbz80 port
1332 \labelwidthstring 00.00.0000
1337 \begin_layout Standard
1346 -disable-z80-port Excludes the z80 port
1350 \labelwidthstring 00.00.0000
1355 \begin_layout Standard
1364 -disable-avr-port Excludes the AVR port
1368 \labelwidthstring 00.00.0000
1373 \begin_layout Standard
1382 -disable-ds390-port Excludes the DS390 port
1386 \labelwidthstring 00.00.0000
1391 \begin_layout Standard
1400 -disable-hc08-port Excludes the HC08 port
1404 \labelwidthstring 00.00.0000
1409 \begin_layout Standard
1418 -disable-pic-port Excludes the PIC14 port
1422 \labelwidthstring 00.00.0000
1427 \begin_layout Standard
1436 -disable-pic16-port Excludes the PIC16 port
1440 \labelwidthstring 00.00.0000
1445 \begin_layout Standard
1454 -disable-xa51-port Excludes the XA51 port
1458 \labelwidthstring 00.00.0000
1463 \begin_layout Standard
1472 -disable-ucsim Disables configuring and building of ucsim
1476 \labelwidthstring 00.00.0000
1481 \begin_layout Standard
1490 -disable-device-lib Disables automatically building device libraries
1494 \labelwidthstring 00.00.0000
1499 \begin_layout Standard
1508 -disable-packihx Disables building packihx
1514 \labelwidthstring 00.00.0000
1519 \begin_layout Standard
1528 -enable-doc Build pdf, html and txt files from the lyx sources
1532 \labelwidthstring 00.00.0000
1537 \begin_layout Standard
1546 -enable-libgc Use the Bohem memory allocator.
1547 Lower runtime footprint.
1550 \begin_layout Standard
1551 Furthermore the environment variables CC, CFLAGS, ...
1552 the tools and their arguments can be influenced.
1553 Please see `configure -
1557 \begin_layout Standard
1566 -help' and the man/info pages of `configure' for details.
1571 standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1572 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1573 SDCC_LIB_NAME are defined by `configure' too.
1574 At the moment it's not possible to change the default settings (it was
1575 simply never required).
1579 These configure options are compiled into the binaries,
1580 and can only be changed by rerunning 'configure' and recompiling SDCC.
1581 The configure options are written in
1585 to distinguish them from run time environment variables (see section search
1591 \begin_inset Quotes sld
1595 \begin_inset Quotes srd
1598 are used by the SDCC team to build the official Win32 binaries.
1599 The SDCC team uses Mingw32 to build the official Windows binaries, because
1603 \begin_layout Enumerate
1607 \begin_layout Enumerate
1608 a gcc compiler and last but not least
1611 \begin_layout Enumerate
1612 the binaries can be built by cross compiling on SDCC Distributed Compile
1616 \begin_layout Standard
1617 See the examples, how to pass the Win32 settings to 'configure'.
1618 The other Win32 builds using Borland, VC or whatever don't use 'configure',
1619 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1629 \begin_layout Standard
1631 \begin_inset Tabular
1632 <lyxtabular version="3" rows="9" columns="3">
1634 <column alignment="block" valignment="top" leftline="true" width="0in">
1635 <column alignment="block" valignment="top" leftline="true" width="0in">
1636 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1637 <row topline="true" bottomline="true">
1638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1641 \begin_layout Standard
1647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1650 \begin_layout Standard
1656 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1659 \begin_layout Standard
1666 <row topline="true">
1667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1670 \begin_layout Standard
1678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1681 \begin_layout Standard
1687 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1690 \begin_layout Standard
1699 <row topline="true">
1700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1703 \begin_layout Standard
1711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1714 \begin_layout Standard
1722 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1725 \begin_layout Standard
1734 <row topline="true">
1735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1738 \begin_layout Standard
1746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1749 \begin_layout Standard
1759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1762 \begin_layout Standard
1775 <row topline="true">
1776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1779 \begin_layout Standard
1787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1790 \begin_layout Standard
1798 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1801 \begin_layout Standard
1810 <row topline="true">
1811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1814 \begin_layout Standard
1822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1825 \begin_layout Standard
1835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1838 \begin_layout Standard
1847 <row topline="true">
1848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1851 \begin_layout Standard
1859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1862 \begin_layout Standard
1872 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1875 \begin_layout Standard
1888 <row topline="true">
1889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1892 \begin_layout Standard
1900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1903 \begin_layout Standard
1909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1912 \begin_layout Standard
1919 <row topline="true" bottomline="true">
1920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1923 \begin_layout Standard
1931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1934 \begin_layout Standard
1940 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1943 \begin_layout Standard
1959 \begin_layout Standard
1961 'configure' also computes relative paths.
1962 This is needed for full relocatability of a binary package and to complete
1963 search paths (see section search paths below):
1968 \begin_layout Standard
1970 \begin_inset Tabular
1971 <lyxtabular version="3" rows="4" columns="3">
1973 <column alignment="block" valignment="top" leftline="true" width="0in">
1974 <column alignment="block" valignment="top" leftline="true" width="0in">
1975 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1976 <row topline="true" bottomline="true">
1977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1980 \begin_layout Standard
1986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1989 \begin_layout Standard
1995 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1998 \begin_layout Standard
2005 <row topline="true" bottomline="true">
2006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2009 \begin_layout Standard
2017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2020 \begin_layout Standard
2026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2029 \begin_layout Standard
2036 <row bottomline="true">
2037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2040 \begin_layout Standard
2048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2051 \begin_layout Standard
2057 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2060 \begin_layout Standard
2067 <row bottomline="true">
2068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2071 \begin_layout Standard
2079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2082 \begin_layout Standard
2088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2091 \begin_layout Standard
2107 \begin_layout Standard
2112 \begin_layout LyX-Code
2119 \begin_layout Standard
2129 \begin_inset Quotes srd
2133 \begin_inset Quotes srd
2140 \begin_layout Standard
2150 \begin_inset Quotes srd
2154 \begin_inset Quotes srd
2163 \begin_layout Standard
2176 \begin_layout Standard
2188 \begin_layout Standard
2189 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2193 \begin_layout LyX-Code
2199 \begin_inset Quotes srd
2202 i586-mingw32msvc-gcc
2203 \begin_inset Quotes srd
2207 \begin_inset Quotes srd
2210 i586-mingw32msvc-g++
2211 \begin_inset Quotes srd
2219 \begin_inset Quotes srd
2222 i586-mingw32msvc-ranlib
2223 \begin_inset Quotes srd
2231 \begin_inset Quotes srd
2234 i586-mingw32msvc-strip
2235 \begin_inset Quotes srd
2246 \begin_layout Standard
2256 \begin_inset Quotes srd
2260 \begin_inset Quotes srd
2271 \begin_layout Standard
2281 \begin_inset Quotes srd
2285 \begin_inset Quotes srd
2293 \begin_inset Quotes srd
2299 \begin_inset Quotes srd
2307 \begin_inset Quotes srd
2311 \begin_inset Quotes srd
2319 \begin_inset Quotes srd
2323 \begin_inset Quotes srd
2330 sdccconf_h_dir_separator=
2331 \begin_inset Quotes srd
2343 \begin_inset Quotes srd
2354 \begin_layout Standard
2371 \begin_layout Standard
2380 -host=i586-mingw32msvc
2388 \begin_layout Standard
2397 -build=unknown-unknown-linux-gnu
2400 \begin_layout Standard
2402 \begin_inset Quotes sld
2406 \begin_inset Quotes srd
2409 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2413 \begin_layout LyX-Code
2422 \begin_layout Standard
2432 \begin_inset Quotes srd
2436 \begin_inset Quotes srd
2447 \begin_layout Standard
2457 \begin_inset Quotes srd
2461 \begin_inset Quotes srd
2469 \begin_inset Quotes srd
2475 \begin_inset Quotes srd
2483 \begin_inset Quotes srd
2487 \begin_inset Quotes srd
2495 \begin_inset Quotes srd
2499 \begin_inset Quotes srd
2506 sdccconf_h_dir_separator=
2507 \begin_inset Quotes srd
2519 \begin_inset Quotes srd
2527 \begin_inset Quotes srd
2531 \begin_inset Quotes srd
2539 \begin_inset Quotes srd
2543 \begin_inset Quotes srd
2549 \begin_layout Standard
2550 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2555 \begin_layout Standard
2564 -C' turns on caching, which gives a little bit extra speed.
2565 However if options are changed, it can be necessary to delete the config.cache
2569 \begin_layout Section
2571 \begin_inset LatexCommand \label{sub:Install-paths}
2576 \begin_inset LatexCommand \index{Install paths}
2583 \begin_layout Standard
2584 \begin_inset VSpace medskip
2590 \begin_layout Standard
2592 \begin_inset Tabular
2593 <lyxtabular version="3" rows="5" columns="4">
2595 <column alignment="left" valignment="top" leftline="true" width="0">
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" rightline="true" width="0">
2599 <row topline="true" bottomline="true">
2600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2603 \begin_layout Standard
2611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2614 \begin_layout Standard
2622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2625 \begin_layout Standard
2633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2636 \begin_layout Standard
2645 <row topline="true">
2646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2649 \begin_layout Standard
2655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2658 \begin_layout Standard
2666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2669 \begin_layout Standard
2675 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2678 \begin_layout Standard
2689 <row topline="true">
2690 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2693 \begin_layout Standard
2699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2702 \begin_layout Standard
2705 $DATADIR/ $INCLUDE_DIR_SUFFIX
2710 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2713 \begin_layout Standard
2714 /usr/local/share/sdcc/include
2719 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2722 \begin_layout Standard
2733 <row topline="true">
2734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2737 \begin_layout Standard
2743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2746 \begin_layout Standard
2749 $DATADIR/$LIB_DIR_SUFFIX
2754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2757 \begin_layout Standard
2758 /usr/local/share/sdcc/lib
2763 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2766 \begin_layout Standard
2777 <row topline="true" bottomline="true">
2778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2781 \begin_layout Standard
2787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2790 \begin_layout Standard
2798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2801 \begin_layout Standard
2802 /usr/local/share/sdcc/doc
2807 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2810 \begin_layout Standard
2831 *compiler, preprocessor, assembler, and linker
2837 is auto-appended by the compiler, e.g.
2838 small, large, z80, ds390 etc
2841 \begin_layout Standard
2843 The install paths can still be changed during `make install' with e.g.:
2846 \begin_layout LyX-Code
2847 make install prefix=$(HOME)/local/sdcc
2850 \begin_layout Standard
2851 Of course this doesn't change the search paths compiled into the binaries.
2856 r the install path can be changed by defining DESTDIR
2857 \begin_inset LatexCommand \index{DESTDIR}
2864 \begin_layout LyX-Code
2865 make install DESTDIR=$(HOME)/sdcc.rpm/
2868 \begin_layout Standard
2869 Please note that DESTDIR must have a trailing slash!
2872 \begin_layout Section
2874 \begin_inset LatexCommand \label{sub:Search-Paths}
2879 \begin_inset LatexCommand \index{Search path}
2886 \begin_layout Standard
2887 Some search paths or parts of them are determined by configure variables
2892 , see section above).
2893 Further search paths are determined by environment variables during runtime.
2896 The paths searched when running the compiler are as follows (the first
2902 Binary files (preprocessor, assembler and linker)
2907 \begin_layout Standard
2909 \begin_inset Tabular
2910 <lyxtabular version="3" rows="4" columns="3">
2912 <column alignment="block" valignment="top" leftline="true" width="0in">
2913 <column alignment="block" valignment="top" leftline="true" width="0in">
2914 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2915 <row topline="true" bottomline="true">
2916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2919 \begin_layout Standard
2925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2928 \begin_layout Standard
2934 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2937 \begin_layout Standard
2944 <row topline="true">
2945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2948 \begin_layout Standard
2956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2959 \begin_layout Standard
2965 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2968 \begin_layout Standard
2977 <row topline="true">
2978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2981 \begin_layout Standard
2982 Path of argv[0] (if available)
2987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2990 \begin_layout Standard
2996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2999 \begin_layout Standard
3006 <row topline="true" bottomline="true">
3007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3010 \begin_layout Standard
3016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3019 \begin_layout Standard
3025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3028 \begin_layout Standard
3044 \begin_layout Standard
3052 \begin_layout Standard
3054 \begin_inset Tabular
3055 <lyxtabular version="3" rows="6" columns="3">
3057 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3058 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3059 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3060 <row topline="true" bottomline="true">
3061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3064 \begin_layout Standard
3070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3073 \begin_layout Standard
3079 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3082 \begin_layout Standard
3089 <row topline="true">
3090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3093 \begin_layout Standard
3098 \begin_layout Standard
3112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3115 \begin_layout Standard
3120 \begin_layout Standard
3134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3137 \begin_layout Standard
3142 \begin_layout Standard
3157 <row topline="true">
3158 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3161 \begin_layout Standard
3167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3170 \begin_layout Standard
3176 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3179 \begin_layout Standard
3186 <row topline="true">
3187 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3190 \begin_layout Standard
3202 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3205 \begin_layout Standard
3215 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3218 \begin_layout Standard
3227 <row topline="true">
3228 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3231 \begin_layout Standard
3247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3250 \begin_layout Standard
3298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3301 \begin_layout Standard
3312 <row topline="true" bottomline="true">
3313 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3316 \begin_layout Standard
3330 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3333 \begin_layout Standard
3334 /usr/local/share/sdcc/
3341 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3344 \begin_layout Standard
3360 \begin_layout Standard
3366 \begin_layout Standard
3375 -nostdinc disables the last two search paths.
3385 \begin_layout Standard
3386 With the exception of
3387 \begin_inset Quotes sld
3394 \begin_layout Standard
3404 \begin_inset Quotes srd
3411 is auto-appended by the compiler (e.g.
3412 small, large, z80, ds390 etc.).
3418 \begin_layout Standard
3420 \begin_inset Tabular
3421 <lyxtabular version="3" rows="6" columns="3">
3423 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3424 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3425 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3426 <row topline="true" bottomline="true">
3427 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3430 \begin_layout Standard
3436 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3439 \begin_layout Standard
3445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3448 \begin_layout Standard
3455 <row topline="true">
3456 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3459 \begin_layout Standard
3464 \begin_layout Standard
3478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3481 \begin_layout Standard
3486 \begin_layout Standard
3500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3503 \begin_layout Standard
3508 \begin_layout Standard
3523 <row topline="true">
3524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3527 \begin_layout Standard
3537 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3540 \begin_layout Standard
3550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3553 \begin_layout Standard
3566 <row topline="true">
3567 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3570 \begin_layout Standard
3577 $LIB_DIR_SUFFIX/<model>
3582 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3585 \begin_layout Standard
3597 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3600 \begin_layout Standard
3615 <row topline="true">
3616 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3619 \begin_layout Standard
3630 $LIB_DIR_SUFFIX/<model>
3635 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3638 \begin_layout Standard
3689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3692 \begin_layout Standard
3746 <row topline="true" bottomline="true">
3747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3750 \begin_layout Standard
3755 $LIB_DIR_SUFFIX/<model>
3760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3763 \begin_layout Standard
3764 /usr/local/share/sdcc/
3773 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3776 \begin_layout Standard
3792 \begin_layout Standard
3793 \begin_inset Note Note
3796 \begin_layout Standard
3797 Don't delete any of the stray spaces in the table above without checking
3798 the HTML output (last line)!
3806 \begin_layout Standard
3814 \begin_layout Standard
3823 -nostdlib disables the last two search paths.
3826 \begin_layout Section
3828 \begin_inset LatexCommand \index{Building SDCC}
3835 \begin_layout Subsection
3836 Building SDCC on Linux
3837 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3844 \begin_layout Enumerate
3847 Download the source package
3849 either from the SDCC Subversion repository or from snapshot builds
3851 , it will be named something like sdcc
3862 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3869 \begin_layout Enumerate
3872 Bring up a command line terminal, such as xterm.
3875 \begin_layout Enumerate
3878 Unpack the file using a command like:
3883 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
3884 \begin_inset Quotes srd
3890 , this will create a sub-directory called sdcc with all of the sources.
3893 \begin_layout Enumerate
3894 Change directory into the main SDCC directory, for example type:
3902 \begin_layout Enumerate
3914 This configures the package for compilation on your system.
3917 \begin_layout Enumerate
3933 All of the source packages will compile, this can take a while.
3936 \begin_layout Enumerate
3952 This copies the binary executables, the include files, the libraries and
3953 the documentation to the install directories.
3954 Proceed with section
3955 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3962 \begin_layout Subsection
3963 Building SDCC on Mac OS X
3966 \begin_layout Standard
3967 Follow the instruction for Linux.
3971 On Mac OS X 10.2.x it was reported, that the
3972 default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
3973 Fortunately there's also gcc 2.9.x installed, which works fine.
3974 This compiler can be selected by running 'configure' with:
3977 \begin_layout LyX-Code
3978 ./configure CC=gcc2 CXX=g++2
3981 \begin_layout Subsection
3982 Cross compiling SDCC on Linux for Windows
3985 \begin_layout Standard
3986 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3987 See section 'Configure Options'.
3990 \begin_layout Subsection
3991 Building SDCC using Cygwin and Mingw32
3994 \begin_layout Standard
3995 For building and installing a Cygwin executable follow the instructions
4001 \begin_inset Quotes sld
4005 \begin_inset Quotes srd
4008 Win32-binary can be built, which will not need the Cygwin-DLL.
4009 For the necessary 'configure' options see section 'configure options' or
4010 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4015 Cygwin on Windows download setup.exe from
4016 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
4022 \begin_inset Quotes sld
4025 default text file type
4026 \begin_inset Quotes srd
4030 \begin_inset Quotes sld
4034 \begin_inset Quotes srd
4037 and download/install at least the following packages.
4038 Some packages are selected by default, others will be automatically selected
4039 because of dependencies with the manually selected packages.
4040 Never deselect these packages!
4043 \begin_layout Itemize
4047 \begin_layout Itemize
4051 \begin_layout Itemize
4052 gcc ; version 3.x is fine, no need to use the old 2.9x
4055 \begin_layout Itemize
4056 binutils ; selected with gcc
4059 \begin_layout Itemize
4063 \begin_layout Itemize
4064 rxvt ; a nice console, which makes life much easier under windoze (see below)
4067 \begin_layout Itemize
4068 man ; not really needed for building SDCC, but you'll miss it sooner or
4072 \begin_layout Itemize
4073 less ; not really needed for building SDCC, but you'll miss it sooner or
4077 \begin_layout Itemize
4078 svn ; only if you use Subversion access
4081 \begin_layout Standard
4082 If you want to develop something you'll need:
4085 \begin_layout Itemize
4086 python ; for the regression tests
4089 \begin_layout Itemize
4090 gdb ; the gnu debugger, together with the nice GUI
4091 \begin_inset Quotes sld
4095 \begin_inset Quotes srd
4101 \begin_layout Itemize
4102 openssh ; to access the CF or commit changes
4105 \begin_layout Itemize
4106 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4107 use autoconf-stable!
4110 \begin_layout Standard
4111 rxvt is a nice console with history.
4112 Replace in your cygwin.bat the line
4115 \begin_layout LyX-Code
4120 \begin_layout Standard
4132 \begin_layout Standard
4136 \begin_layout LyX-Code
4137 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4140 \begin_layout LyX-Code
4141 -bg black -fg white -geometry 100x65 -e bash -
4145 \begin_layout Standard
4157 \begin_layout Standard
4158 Text selected with the mouse is automatically copied to the clipboard, pasting
4159 works with shift-insert.
4163 The other good tip is to make sure you have no //c/-styl
4164 e paths anywhere, use /cygdrive/c/ instead.
4165 Using // invokes a network lookup which is very slow.
4167 \begin_inset Quotes sld
4171 \begin_inset Quotes srd
4174 is too long, you can change it with e.g.
4177 \begin_layout LyX-Code
4181 \begin_layout Standard
4182 SDCC sources use the unix line ending LF.
4183 Life is much easier, if you store the source tree on a drive which is mounted
4185 And use an editor which can handle LF-only line endings.
4186 Make sure not to commit files with windows line endings.
4187 The tabulator spacing
4188 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4192 used in the project is 8.
4193 Although a tabulator spacing of 8 is a sensible choice for programmers
4194 (it's a power of 2 and allows to display 8/16 bit signed variables without
4195 loosing columns) the plan is to move towards using only spaces in the source.
4198 \begin_layout Subsection
4199 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4202 \begin_layout Standard
4205 Download the source package
4207 either from the SDCC Subversion repository or from the
4208 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4214 , it will be named something like sdcc
4218 -yyyymmdd-rrrr.tar.bz2.
4221 SDCC is distributed with all the projects, workspaces, and files you need
4222 to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4223 The workspace name is 'sdcc.dsw'.
4224 Please note that as it is now, all the executables are created in a folder
4228 Once built you need to copy the executables from sdcc
4232 bin before running SDCC.
4237 WARNING: Visual studio is very picky with line terminations; it expects
4238 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4239 When using the Subversion repository it's easiest to configure the svn
4240 client to convert automatically for you.
4241 If however you are getting a message such as "This makefile was not generated
4242 by Developer Studio etc.
4244 \begin_inset Quotes srd
4247 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4248 need to convert the Unix style line endings to DOS style line endings.
4249 To do so you can use the
4250 \begin_inset Quotes sld
4254 \begin_inset Quotes srd
4257 utility freely available on the internet.
4258 Doug Hawkins reported in the sdcc-user list that this works:
4266 SDCC> unix2dos sdcc.dsw
4272 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4276 In order to build SDCC with MSVC
4277 you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4278 One good place to get them is
4279 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4287 Download the file UnxUtils
4288 \begin_inset LatexCommand \index{UnxUtils}
4293 Now you have to install the utilities and setup MSVC so it can locate the
4295 Here there are two alternatives (choose one!):
4298 \begin_layout Enumerate
4303 a) Extract UnxUtils.zip to your C:
4305 hard disk PRESERVING the original paths, otherwise bison won't work.
4306 (If you are using WinZip make certain that 'Use folder names' is selected)
4311 In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4312 'Show directories for:' select 'Executable files', and in the directories
4313 window add a new path: 'C:
4323 (As a side effect, you get a bunch of Unix utilities that
4324 could be useful, such as diff and patch.)
4327 \begin_layout Enumerate
4332 This one avoids extracting a bunch of files you may not
4333 use, but requires some extra work:
4337 a) Create a directory were to put the
4338 tools needed, or use a directory already present.
4345 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4346 gawk.exe to such directory WITHOUT preserving the original paths.
4347 (If you are using WinZip make certain that 'Use folder names' is not selected)
4352 ) Rename bison.exe to '_bison.exe'.
4356 d) Create a batch file 'bison.bat' in 'C:
4360 ' and add these lines:
4380 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4384 Steps 'c' and 'd' are needed
4385 because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4386 reside in some weird Unix directory, '/usr/local/share/' I think.
4387 So it is necessary to tell bison where those files are located if they
4388 are not in such directory.
4389 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4394 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4395 in 'Show directories for:' select 'Executable files', and in the directories
4396 window add a new path: 'c:
4399 Note that you can use any other path instead of 'c:
4401 util', even the path where the Visual C++ tools are, probably: 'C:
4405 Microsoft Visual Studio
4410 So you don't have to execute step 'e' :)
4413 \begin_layout Standard
4415 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4416 the executables from sdcc
4420 bin, and you can compile using SDCC.
4423 \begin_layout Subsection
4424 Building SDCC Using Borland
4427 \begin_layout Enumerate
4428 From the sdcc directory, run the command "make -f Makefile.bcc".
4429 This should regenerate all the .exe files in the bin directory except for
4433 \begin_layout Enumerate
4434 If you modify any source files and need to rebuild, be aware that the dependenci
4435 es may not be correctly calculated.
4436 The safest option is to delete all .obj files and run the build again.
4437 From a Cygwin BASH prompt, this can easily be done with the command (be
4438 sure you are in the sdcc directory):
4448 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
4450 ) -print -exec rm {}
4459 or on Windows NT/2000/XP from the command prompt with the command:
4466 del /s *.obj *.lib *.rul
4469 from the sdcc directory.
4472 \begin_layout Subsection
4473 Windows Install Using a ZIP Package
4476 \begin_layout Enumerate
4477 Download the binary zip package from
4478 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4482 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4483 This should unpack to a group of sub-directories.
4484 An example directory structure after unpacking the mingw32 package is:
4489 bin for the executables, c:
4497 lib for the include and libraries.
4500 \begin_layout Enumerate
4501 Adjust your environment variable PATH to include the location of the bin
4502 directory or start sdcc using the full path.
4505 \begin_layout Subsection
4506 Windows Install Using the Setup Program
4507 \begin_inset LatexCommand \label{sub:Windows-Install}
4514 \begin_layout Standard
4515 Download the setup program
4517 sdcc-x.y.z-setup.exe
4519 for an official release from
4522 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4526 or a setup program for one of the snapshots
4528 sdcc-yyyymmdd-xxxx-setup.exe
4531 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4536 A windows typical installer will guide you through the installation process.
4539 \begin_layout Subsection
4541 \begin_inset LatexCommand \index{VPATH}
4548 \begin_layout Standard
4549 SDCC supports the VPATH feature provided by configure and make.
4550 It allows to separate the source and build trees.
4554 \begin_layout Standard
4581 \begin_layout Standard
4584 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4585 # extract source to directory sdcc
4588 \begin_layout Standard
4591 mkdir sdcc.build\InsetSpace ~
4600 # put output in sdcc.build
4603 \begin_layout Standard
4609 \begin_layout Standard
4612 ../sdcc/configure\InsetSpace ~
4620 # configure is doing all the magic!
4623 \begin_layout Standard
4629 \begin_layout Standard
4635 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4636 It automagically computes the variables srcdir, top_srcdir and top_buildir
4642 the generated files will be in ~/sdcc.build, while the source files stay
4645 This is not only usefull for building different binaries, e.g.
4646 when cross compiling.
4647 It also gives you a much better overview in the source tree when all the
4648 generated files are not scattered between the source files.
4649 And the best thing is: if you want to change a file you can leave the original
4650 file untouched in the source directory.
4651 Simply copy it to the build directory, edit it, enter `make clean', `rm
4652 Makefile.dep' and `make'.
4657 will do the rest for you!
4660 \begin_layout Section
4661 Building the Documentation
4664 \begin_layout Standard
4669 \begin_layout Standard
4678 -enable-doc to the configure arguments to build the documentation together
4679 with all the other stuff.
4680 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4681 dvips and makeindex) to get the job done.
4682 Another possibility is to change to the doc directory and to type
4686 \begin_inset Quotes srd
4690 \begin_inset Quotes srd
4697 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4700 \begin_inset LatexCommand \url{http://www.lyx.org}
4704 as editor is straightforward.
4705 Prebuilt documentation in html and pdf format is available from
4706 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4713 \begin_layout Section
4714 Reading the Documentation
4715 \begin_inset LatexCommand \index{Documentation}
4722 \begin_layout Standard
4723 Currently reading the document in pdf format is recommended, as for unknown
4724 reason the hyperlinks are working there whereas in the html version they
4729 \begin_layout Standard
4730 If you should know why please drop us a note
4738 You'll find the pdf version
4739 \begin_inset LatexCommand \index{PDF version of this document}
4744 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4752 \begin_inset LatexCommand \index{HTML version of this document}
4757 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4763 This documentation is in some aspects different from a commercial documentation:
4767 \begin_layout Itemize
4768 It tries to document SDCC for several processor architectures in one document
4769 (commercially these probably would be separate documents/products).
4771 \begin_inset LatexCommand \index{Status of documentation}
4775 currently matches SDCC for mcs51 and DS390 best and does give too few informati
4777 Z80, PIC14, PIC16 and HC08.
4780 \begin_layout Itemize
4781 There are many references pointing away from this documentation.
4782 Don't let this distract you.
4784 was a reference like
4785 \begin_inset LatexCommand \url{http://www.opencores.org}
4789 together with a statement
4790 \begin_inset Quotes sld
4793 some processors which are targetted by SDCC can be implemented in a
4810 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4815 \begin_inset Quotes srd
4819 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4824 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4829 \begin_inset Quotes sld
4832 have you ever heard of an open source compiler that compiles a subset of
4834 \begin_inset Quotes srd
4837 we expect you to have a quick look there and come back.
4838 If you read this you are on the right track.
4841 \begin_layout Itemize
4842 Some sections attribute more space to problems, restrictions and warnings
4843 than to the solution.
4846 \begin_layout Itemize
4847 The installation section and the section about the debugger is intimidating.
4850 \begin_layout Itemize
4851 There are still lots of typos and there are more different writing styles
4855 \begin_layout Section
4856 Testing the SDCC Compiler
4857 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4864 \begin_layout Standard
4865 The first thing you should do after installing your SDCC compiler is to
4874 \begin_layout Standard
4884 \begin_inset LatexCommand \index{version}
4891 at the prompt, and the program should run and output its version like:
4896 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4900 \begin_layout Standard
4901 If it doesn't run, or gives a message about not finding sdcc program, then
4902 you need to check over your installation.
4903 Make sure that the sdcc bin directory is in your executable search path
4904 defined by the PATH environment setting (
4909 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4916 Install trouble-shooting for suggestions
4919 Make sure that the sdcc program is in the bin folder, if not perhaps something
4920 did not install correctly.
4928 is commonly installed as described in section
4929 \begin_inset Quotes sld
4932 Install and search paths
4933 \begin_inset Quotes srd
4942 Make sure the compiler works on a very simple example.
4943 Type in the following test.c program using your favorite
4968 \begin_layout Standard
4971 Compile this using the following command:
4982 If all goes well, the compiler will generate a test.asm and test.rel file.
4983 Congratulations, you've just compiled your first program with SDCC.
4984 We used the -c option to tell SDCC not to link the generated code, just
4985 to keep things simple for this step.
4993 The next step is to try it with the linker.
5005 If all goes well the compiler will link with the libraries and produce
5006 a test.ihx output file.
5011 (no test.ihx, and the linker generates warnings), then the problem is most
5020 usr/local/share/sdcc/lib directory
5027 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5034 Install trouble-shooting for suggestions).
5042 The final test is to ensure
5050 header files and libraries.
5051 Edit test.c and change it to the following:
5069 strcpy(str1, "testing");
5074 \begin_layout Standard
5077 Compile this by typing
5086 This should generate a test.ihx output file, and it should give no warnings
5087 such as not finding the string.h file.
5088 If it cannot find the string.h file, then the problem is that
5092 cannot find the /usr/local/share/sdcc/include directory
5099 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5106 Install trouble-shooting section for suggestions).
5115 \begin_layout Standard
5127 \begin_inset LatexCommand \index{-\\/-print-search-dirs}
5131 to find exactly where SDCC is looking for the include and lib files.
5134 \begin_layout Section
5135 Install Trouble-shooting
5136 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5141 \begin_inset LatexCommand \index{Install trouble-shooting}
5148 \begin_layout Subsection
5149 If SDCC does not build correctly
5152 \begin_layout Standard
5153 A thing to try is starting from scratch by unpacking the .tgz source package
5154 again in an empty directory.
5162 ./configure 2>&1 | tee configure.log
5176 make 2>&1 | tee make.log
5183 If anything goes wrong, you can review the log files to locate the problem.
5184 Or a relevant part of this can be attached to an email that could be helpful
5185 when requesting help from the mailing list.
5188 \begin_layout Subsection
5190 \begin_inset Quotes sld
5194 \begin_inset Quotes srd
5200 \begin_layout Standard
5202 \begin_inset Quotes sld
5206 \begin_inset Quotes srd
5209 command is a script that analyzes your system and performs some configuration
5210 to ensure the source package compiles on your system.
5211 It will take a few minutes to run, and will compile a few tests to determine
5212 what compiler features are installed.
5215 \begin_layout Subsection
5217 \begin_inset Quotes sld
5221 \begin_inset Quotes srd
5227 \begin_layout Standard
5228 This runs the GNU make tool, which automatically compiles all the source
5229 packages into the final installed binary executables.
5232 \begin_layout Subsection
5234 \begin_inset Quotes sld
5238 \begin_inset Quotes erd
5244 \begin_layout Standard
5245 This will install the compiler, other executables libraries and include
5246 files into the appropriate directories.
5248 \begin_inset LatexCommand \ref{sub:Install-paths}
5254 \begin_inset LatexCommand \ref{sub:Search-Paths}
5259 about install and search paths.
5261 On most systems you will need super-user privilege
5265 \begin_layout Section
5269 \begin_layout Standard
5270 SDCC is not just a compiler, but a collection of tools by various developers.
5271 These include linkers, assemblers, simulators and other components.
5272 Here is a summary of some of the components.
5273 Note that the included simulator and assembler have separate documentation
5274 which you can find in the source package in their respective directories.
5275 As SDCC grows to include support for other processors, other packages from
5276 various developers are included and may have their own sets of documentation.
5281 might want to look at the files which are installed in <installdir>.
5282 At the time of this writing, we find the following programs for gcc-builds:
5287 In <installdir>/bin:
5290 \begin_layout Itemize
5291 sdcc - The compiler.
5294 \begin_layout Itemize
5295 sdcpp - The C preprocessor.
5298 \begin_layout Itemize
5299 asx8051 - The assembler for 8051 type processors.
5302 \begin_layout Itemize
5307 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5310 \begin_layout Itemize
5311 aslink -The linker for 8051 type processors.
5314 \begin_layout Itemize
5319 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5322 \begin_layout Itemize
5323 s51 - The ucSim 8051 simulator.
5326 \begin_layout Itemize
5327 sdcdb - The source debugger.
5330 \begin_layout Itemize
5331 packihx - A tool to pack (compress) Intel hex files.
5334 \begin_layout Standard
5335 In <installdir>/share/sdcc/include
5338 \begin_layout Itemize
5342 \begin_layout Standard
5343 In <installdir>/share/sdcc/lib
5346 \begin_layout Itemize
5347 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5351 \begin_layout Standard
5352 In <installdir>/share/sdcc/doc
5355 \begin_layout Itemize
5359 \begin_layout Standard
5360 As development for other processors proceeds, this list will expand to include
5361 executables to support processors like AVR, PIC, etc.
5364 \begin_layout Subsection
5368 \begin_layout Standard
5369 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5370 the assembler and linkage editor.
5373 \begin_layout Subsection
5374 sdcpp - The C-Preprocessor
5377 \begin_layout Standard
5379 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5383 is a modified version of the GNU cpp
5384 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5389 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5394 The C preprocessor is used to pull in #include sources, process #ifdef
5395 statements, #defines and so on.
5398 \begin_layout Subsection
5407 - The Assemblers and Linkage Editors
5410 \begin_layout Standard
5411 This is retargettable assembler & linkage editor, it was developed by Alan
5413 John Hartman created the version for 8051, and I (Sandeep) have made some
5414 enhancements and bug fixes for it to work properly with SDCC.
5417 \begin_layout Subsection
5421 \begin_layout Standard
5423 \begin_inset LatexCommand \index{s51}
5427 is a free open source simulator developed by Daniel Drotos.
5428 The simulator is built as part of the build process.
5429 For more information visit Daniel's web site at:
5430 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5435 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5439 \begin_layout Subsection
5440 sdcdb - Source Level Debugger
5443 \begin_layout Standard
5445 \begin_inset LatexCommand \index{SDCDB (debugger)}
5449 is the companion source level debugger.
5450 More about SDCDB in section
5451 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5456 The current version of the debugger uses Daniel's Simulator S51
5457 \begin_inset LatexCommand \index{s51}
5461 , but can be easily changed to use other simulators.
5464 \begin_layout Chapter
5468 \begin_layout Section
5472 \begin_layout Subsection
5473 Single Source File Projects
5476 \begin_layout Standard
5477 For single source file 8051 projects the process is very simple.
5478 Compile your programs with the following command
5481 "sdcc sourcefile.c".
5485 This will compile, assemble and link your source file.
5486 Output files are as follows:
5489 \begin_layout Itemize
5491 \begin_inset LatexCommand \index{<file>.asm}
5496 \begin_inset LatexCommand \index{Assembler source}
5500 file created by the compiler
5503 \begin_layout Itemize
5505 \begin_inset LatexCommand \index{<file>.lst}
5510 \begin_inset LatexCommand \index{Assembler listing}
5514 file created by the Assembler
5517 \begin_layout Itemize
5519 \begin_inset LatexCommand \index{<file>.rst}
5524 \begin_inset LatexCommand \index{Assembler listing}
5528 file updated with linkedit information, created by linkage editor
5531 \begin_layout Itemize
5533 \begin_inset LatexCommand \index{<file>.sym}
5538 \begin_inset LatexCommand \index{Symbol listing}
5542 for the sourcefile, created by the assembler
5545 \begin_layout Itemize
5547 \begin_inset LatexCommand \index{<file>.rel}
5552 \begin_inset LatexCommand \index{<file>.o}
5557 \begin_inset LatexCommand \index{Object file}
5561 created by the assembler, input to Linkage editor
5564 \begin_layout Itemize
5566 \begin_inset LatexCommand \index{<file>.map}
5571 \begin_inset LatexCommand \index{Memory map}
5575 for the load module, created by the Linker
5578 \begin_layout Itemize
5580 \begin_inset LatexCommand \index{<file>.mem}
5584 - A file with a summary of the memory usage
5587 \begin_layout Itemize
5589 \begin_inset LatexCommand \index{<file>.ihx}
5593 - The load module in Intel hex format
5594 \begin_inset LatexCommand \index{Intel hex format}
5598 (you can select the Motorola S19 format
5599 \begin_inset LatexCommand \index{Motorola S19 format}
5607 \begin_layout Standard
5617 \begin_inset LatexCommand \index{-\\/-out-fmt-s19}
5622 If you need another format you might want to use
5629 \begin_inset LatexCommand \index{objdump (tool)}
5640 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5645 \begin_inset Note Note
5648 \begin_layout Standard
5655 \begin_inset LatexCommand \vref{sub:Postprocessing-the-Intel}
5660 Both formats are documented in the documentation of srecord
5661 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5668 \begin_layout Itemize
5670 \begin_inset LatexCommand \index{<file>.adb}
5674 - An intermediate file containing debug information needed to create the
5679 \begin_layout Standard
5689 \begin_inset LatexCommand \index{-\\/-debug}
5696 \begin_layout Itemize
5698 \begin_inset LatexCommand \index{<file>.cdb}
5702 - An optional file (with -
5706 \begin_layout Standard
5715 -debug) containing debug information.
5716 The format is documented in cdbfileformat.pdf
5719 \begin_layout Itemize
5722 \begin_inset LatexCommand \index{<file> (no extension)}
5726 An optional AOMF or AOMF51
5727 \begin_inset LatexCommand \index{AOMF, AOMF51}
5732 \begin_inset LatexCommand \label{OMF file}
5736 file containing debug information (generated with option -
5740 \begin_layout Standard
5766 ormat is a subformat of the OMF51 format and is commonly used by third party
5768 \begin_inset LatexCommand \index{Debugger}
5772 , simulators, emulators).
5775 \begin_layout Itemize
5777 \begin_inset LatexCommand \index{<file>.dump*}
5781 - Dump file to debug the compiler it self (generated with option -
5785 \begin_layout Standard
5794 -dumpall) (see section
5795 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5801 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5807 \begin_inset Quotes sld
5810 Anatomy of the compiler
5811 \begin_inset Quotes srd
5817 \begin_layout Subsection
5818 Postprocessing the Intel Hex
5819 \begin_inset LatexCommand \index{Intel hex format}
5824 \begin_inset LatexCommand \label{sub:Postprocessing-the-Intel}
5831 \begin_layout Standard
5832 In most cases this won't be needed but the Intel Hex file
5833 \begin_inset LatexCommand \index{<file>.ihx}
5837 which is generated by SDCC might include lines of varying length and the
5838 addresses within the file are not guaranteed to be strictly ascending.
5839 If your toolchain or a bootloader does not like this you can use the tool
5845 \begin_inset LatexCommand \index{packihx (tool)}
5849 which is part of the SDCC distribution:
5856 packihx sourcefile.ihx >sourcefile.hex
5863 The separately available
5868 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5872 package additionally allows to set undefined locations to a predefined
5873 value, to insert checksums
5874 \begin_inset LatexCommand \index{checksum}
5878 of various flavours (crc, add, xor) and to perform other manipulations
5879 (convert, split, crop, offset, ...).
5887 srec_cat\InsetSpace ~
5889 sourcefile.ihx -intel\InsetSpace ~
5891 -o sourcefile.hex -intel
5898 An example for a more complex command line
5902 \begin_layout Standard
5903 the command backfills
5904 \begin_inset LatexCommand \index{backfill unused memory}
5908 unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5910 If the program counter on an mcs51 runs wild the backfill pattern 0x12
5911 will be interpreted as an
5919 (where an emergency routine could sit).
5932 srec_cat\InsetSpace ~
5933 sourcefile.ihx -intel\InsetSpace ~
5935 -fill 0x12 0x0000 0xfffe\InsetSpace ~
5936 -little-endian-checksum-nega
5937 tive 0xfffe 0x02 0x02\InsetSpace ~
5939 -o sourcefile.hex -intel
5948 The srecord package is available at
5949 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5956 \begin_layout Subsection
5957 Projects with Multiple Source Files
5960 \begin_layout Standard
5961 SDCC can compile only ONE file at a time.
5962 Let us for example assume that you have a project containing the following
5967 foo1.c (contains some functions)
5969 foo2.c (contains some more functions)
5972 n.c (contains more functions and the function main)
5980 The first two files will need to be compiled separately with the commands:
6012 Then compile the source file containing the
6017 \begin_inset LatexCommand \index{Linker}
6021 the files together with the following command:
6029 foomain.c\InsetSpace ~
6030 foo1.rel\InsetSpace ~
6035 \begin_inset LatexCommand \index{<file>.rel}
6047 can be separately compiled as well:
6058 sdcc foomain.rel foo1.rel foo2.rel
6065 The file containing the
6077 file specified in the command line, since the linkage editor processes
6078 file in the order they are presented to it.
6079 The linker is invoked from SDCC using a script file with extension .lnk
6080 \begin_inset LatexCommand \index{<file>.lnk}
6085 You can view this file to troubleshoot linking problems such as those arising
6086 from missing libraries.
6089 \begin_layout Subsection
6090 Projects with Additional Libraries
6091 \begin_inset LatexCommand \index{Libraries}
6098 \begin_layout Standard
6099 Some reusable routines may be compiled into a library, see the documentation
6100 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6104 \begin_inset LatexCommand \index{<file>.lib}
6111 Libraries created in this manner can be included in the command line.
6112 Make sure you include the -L <library-path> option to tell the linker where
6113 to look for these files if they are not in the current directory.
6114 Here is an example, assuming you have the source file
6126 (if that is not the same as your current project):
6133 sdcc foomain.c foolib.lib -L mylib
6144 must be an absolute path name.
6148 The most efficient way to use libraries is
6149 to keep separate modules in separate source files.
6150 The lib file now should name all the modules.rel
6151 \begin_inset LatexCommand \index{<file>.rel}
6156 For an example see the standard library file
6160 in the directory <installdir>/share/lib/small.
6163 \begin_layout Subsection
6164 Using sdcclib to Create and Manage Libraries
6165 \begin_inset LatexCommand \index{sdcclib}
6172 \begin_layout Standard
6173 Alternatively, instead of having a .rel file for each entry on the library
6174 file as described in the preceding section, sdcclib can be used to embed
6175 all the modules belonging to such library in the library file itself.
6176 This results in a larger library file, but it greatly reduces the number
6177 of disk files accessed by the linker.
6178 Additionally, the packed library file contains an index of all include
6179 modules and symbols that significantly speeds up the linking process.
6180 To display a list of options supported by sdcclib type:
6185 \begin_layout Standard
6190 \begin_inset LatexCommand \index{sdcclib}
6201 To create a new library file, start by compiling all the required modules.
6207 \begin_layout Standard
6214 \begin_layout Standard
6221 \begin_layout Standard
6228 \begin_layout Standard
6235 \begin_layout Standard
6244 \begin_layout Standard
6245 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6247 The next step is to add the .rel files to the library file:
6252 \begin_layout Standard
6256 sdcclib libint.lib _divsint.rel
6259 \begin_inset LatexCommand \index{sdcclib}
6266 \begin_layout Standard
6270 sdcclib libint.lib _divuint.rel
6273 \begin_layout Standard
6277 sdcclib libint.lib _modsint.rel
6280 \begin_layout Standard
6284 sdcclib libint.lib _moduint.rel
6287 \begin_layout Standard
6291 sdcclib libint.lib _mulint.rel
6298 \begin_layout Standard
6304 \begin_layout Standard
6308 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6313 \begin_layout Standard
6314 If the file already exists in the library, it will be replaced.
6315 If a list of .rel files is available, you can tell sdcclib to add those
6317 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
6361 \begin_layout Standard
6367 \begin_layout Standard
6371 sdcclib -l libint.lib myliblist.txt
6376 \begin_layout Standard
6377 Additionally, you can instruct sdcclib to compile the files before adding
6378 them to the library by setting environment variables SDCCLIB_CC
6379 \begin_inset LatexCommand \index{SDCCLIB_CC}
6384 \begin_inset LatexCommand \index{SDCCLIB_AS}
6394 \begin_layout Standard
6399 \begin_inset LatexCommand \index{SDCCLIB_CC}
6409 \begin_layout Standard
6426 \begin_layout Standard
6440 \begin_layout Standard
6444 sdcclib -l libint.lib myliblist.txt
6449 \begin_layout Standard
6450 To see what modules and symbols are included in the library, options -s
6451 and -m are available.
6459 sdcclib -s libint.lib
6462 \begin_inset LatexCommand \index{sdcclib}
6474 \begin_layout Standard
6480 \begin_layout Standard
6486 \begin_layout Standard
6494 \begin_layout Standard
6500 \begin_layout Standard
6506 \begin_layout Standard
6512 \begin_layout Standard
6518 \begin_layout Standard
6526 \begin_layout Standard
6532 \begin_layout Standard
6538 \begin_layout Standard
6546 \begin_layout Standard
6552 \begin_layout Standard
6558 \begin_layout Standard
6564 \begin_layout Standard
6572 \begin_layout Standard
6578 \begin_layout Standard
6589 \begin_layout Standard
6590 If the source files are compiled using -
6594 \begin_layout Standard
6604 \begin_inset LatexCommand \index{-\\/-debug}
6608 , the corresponding debug information file .adb will be include in the library
6610 The library files created with sdcclib are plain text files, so they can
6611 be viewed with a text editor.
6612 It is not recomended to modify a library file created with sdcclib using
6613 a text editor, as there are file indexes numbers located accross the file
6614 used by the linker to quickly locate the required module to link.
6615 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6616 it can be safely deleted, since all the information required for linking
6617 is embedded in the library file itself.
6618 Library files created using sdcclib are used as described in the preceding
6620 \begin_inset VSpace bigskip
6626 \begin_layout Section
6627 Command Line Options
6628 \begin_inset LatexCommand \index{Command Line Options}
6633 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6640 \begin_layout Subsection
6641 Processor Selection Options
6642 \begin_inset LatexCommand \index{Options processor selection}
6647 \begin_inset LatexCommand \index{Processor selection options}
6655 \labelwidthstring 00.00.0000
6659 \begin_inset LatexCommand \index{-mmcs51}
6665 Generate code for the Intel MCS51
6666 \begin_inset LatexCommand \index{MCS51}
6670 family of processors.
6671 This is the default processor target.
6675 \labelwidthstring 00.00.0000
6679 \begin_inset LatexCommand \index{-mds390}
6685 Generate code for the Dallas DS80C390
6686 \begin_inset LatexCommand \index{DS80C390}
6694 \labelwidthstring 00.00.0000
6698 \begin_inset LatexCommand \index{-mds400}
6704 Generate code for the Dallas DS80C400
6705 \begin_inset LatexCommand \index{DS80C400}
6713 \labelwidthstring 00.00.0000
6717 \begin_inset LatexCommand \index{-mhc08}
6723 Generate code for the Freescale/Motorola HC08
6724 \begin_inset LatexCommand \index{HC08}
6728 family of processors.
6732 \labelwidthstring 00.00.0000
6736 \begin_inset LatexCommand \index{-mz80}
6742 Generate code for the Zilog Z80
6743 \begin_inset LatexCommand \index{Z80}
6747 family of processors.
6751 \labelwidthstring 00.00.0000
6755 \begin_inset LatexCommand \index{-mgbz80}
6761 Generate code for the GameBoy Z80
6762 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6766 processor (Not actively maintained).
6770 \labelwidthstring 00.00.0000
6774 \begin_inset LatexCommand \index{-mavr}
6780 Generate code for the Atmel AVR
6781 \begin_inset LatexCommand \index{AVR}
6785 processor (Not maintained, not complete).
6786 AVR users should probably have a look at winavr
6787 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6792 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6796 , which is based on AVR-port of the gcc compiler.
6799 \begin_layout Standard
6800 \begin_inset Note Note
6803 \begin_layout Standard
6804 I think it is fair to direct users there for now.
6805 Open source is also about avoiding unnecessary work .
6806 But I didn't find the 'official' link.
6815 \labelwidthstring 00.00.0000
6819 \begin_inset LatexCommand \index{-mpic14}
6825 Generate code for the Microchip PIC 14
6826 \begin_inset LatexCommand \index{PIC14}
6830 -bit processors (p16f84 and variants.
6831 In development, not complete).
6834 \begin_layout Standard
6835 \begin_inset Note Note
6838 \begin_layout Standard
6839 p16f627 p16f628 p16f84 p16f873 p16f877?
6848 \labelwidthstring 00.00.0000
6852 \begin_inset LatexCommand \index{-mpic16}
6858 Generate code for the Microchip PIC 16
6859 \begin_inset LatexCommand \index{PIC16}
6863 -bit processors (p18f452 and variants.
6864 In development, not complete).
6868 \labelwidthstring 00.00.0000
6873 Generate code for the Toshiba TLCS-900H
6874 \begin_inset LatexCommand \index{TLCS-900H}
6878 processor (Not maintained, not complete).
6882 \labelwidthstring 00.00.0000
6886 \begin_inset LatexCommand \index{-mxa51}
6892 Generate code for the Phillips XA51
6893 \begin_inset LatexCommand \index{XA51}
6897 processor (Not maintained, not complete).
6900 \begin_layout Standard
6901 \begin_inset VSpace bigskip
6907 \begin_layout Subsection
6908 Preprocessor Options
6909 \begin_inset LatexCommand \index{Options preprocessor}
6914 \begin_inset LatexCommand \index{Preprocessor options}
6919 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6927 \labelwidthstring 00.00.0000
6931 \begin_inset LatexCommand \index{-I<path>}
6937 The additional location where the preprocessor will look for <..h> or
6938 \begin_inset Quotes eld
6942 \begin_inset Quotes erd
6949 \labelwidthstring 00.00.0000
6953 \begin_inset LatexCommand \index{-D<macro[=value]>}
6959 Command line definition of macros.
6960 Passed to the preprocessor.
6964 \labelwidthstring 00.00.0000
6968 \begin_inset LatexCommand \index{-M}
6974 Tell the preprocessor to output a rule suitable for make describing the
6975 dependencies of each object file.
6976 For each source file, the preprocessor outputs one make-rule whose target
6977 is the object file name for that source file and whose dependencies are
6978 all the files `#include'd in it.
6979 This rule may be a single line or may be continued with `
6981 '-newline if it is long.
6982 The list of rules is printed on standard output instead of the preprocessed
6985 \begin_inset LatexCommand \index{-E}
6993 \labelwidthstring 00.00.0000
6997 \begin_inset LatexCommand \index{-C}
7003 Tell the preprocessor not to discard comments.
7004 Used with the `-E' option.
7008 \labelwidthstring 00.00.0000
7012 \begin_inset LatexCommand \index{-MM}
7021 Like `-M' but the output mentions only the user header files included with
7023 \begin_inset Quotes eld
7027 System header files included with `#include <file>' are omitted.
7031 \labelwidthstring 00.00.0000
7035 \begin_inset LatexCommand \index{-Aquestion(answer)}
7041 Assert the answer answer for question, in case it is tested with a preprocessor
7042 conditional such as `#if #question(answer)'.
7043 `-A-' disables the standard assertions that normally describe the target
7048 \labelwidthstring 00.00.0000
7052 \begin_inset LatexCommand \index{-Umacro}
7058 Undefine macro macro.
7059 `-U' options are evaluated after all `-D' options, but before any `-include'
7060 and `-imacros' options.
7064 \labelwidthstring 00.00.0000
7068 \begin_inset LatexCommand \index{-dM}
7074 Tell the preprocessor to output only a list of the macro definitions that
7075 are in effect at the end of preprocessing.
7076 Used with the `-E' option.
7080 \labelwidthstring 00.00.0000
7084 \begin_inset LatexCommand \index{-dD}
7090 Tell the preprocessor to pass all macro definitions into the output, in
7091 their proper sequence in the rest of the output.
7095 \labelwidthstring 00.00.0000
7099 \begin_inset LatexCommand \index{-dN}
7108 Like `-dD' except that the macro arguments and contents are omitted.
7109 Only `#define name' is included in the output.
7113 \labelwidthstring 00.00.0000
7116 -pedantic-parse-number
7117 \begin_inset LatexCommand \index{pedantic}
7122 \begin_inset LatexCommand \index{-pedantic-parse-number}
7130 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
7139 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7140 and the macro LO_B(3) gets expanded.
7141 See also #pragma pedantic_parse_number
7142 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
7147 \begin_inset LatexCommand \ref{sec:Pragmas}
7153 Note: this functionality is not in conformance with C99 standard!
7157 \labelwidthstring 00.00.0000
7161 preprocessorOption[,preprocessorOption]
7164 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
7169 Pass the preprocessorOption to the preprocessor
7174 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7179 SDCC uses an adapted version of the preprocessor
7183 of the GNU Compiler Collection
7184 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
7193 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7197 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7202 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7209 \begin_layout Standard
7210 \begin_inset VSpace bigskip
7216 \begin_layout Subsection
7218 \begin_inset LatexCommand \index{Options linker}
7223 \begin_inset LatexCommand \index{Linker options}
7231 \labelwidthstring 00.00.0000
7241 \begin_layout Standard
7253 \begin_inset LatexCommand \index{-\\/-lib-path <path>}
7258 \begin_inset LatexCommand \index{-L -\\/-lib-path}
7265 <absolute path to additional libraries> This option is passed to the linkage
7266 editor's additional libraries
7267 \begin_inset LatexCommand \index{Libraries}
7272 The path name must be absolute.
7273 Additional library files may be specified in the command line.
7274 See section Compiling programs for more details.
7278 \labelwidthstring 00.00.0000
7285 \begin_layout Standard
7297 \begin_inset LatexCommand \index{-\\/-xram-loc <Value>}
7302 <Value> The start location of the external ram
7303 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7307 , default value is 0.
7308 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7312 \begin_layout Standard
7321 -xram-loc 0x8000 or -
7325 \begin_layout Standard
7338 \labelwidthstring 00.00.0000
7345 \begin_layout Standard
7357 \begin_inset LatexCommand \index{-\\/-code-loc <Value>}
7362 <Value> The start location of the code
7363 \begin_inset LatexCommand \index{code}
7367 segment, default value 0.
7368 Note when this option is used the interrupt vector table
7369 \begin_inset LatexCommand \index{interrupt vector table}
7373 is also relocated to the given address.
7374 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7378 \begin_layout Standard
7387 -code-loc 0x8000 or -
7391 \begin_layout Standard
7404 \labelwidthstring 00.00.0000
7411 \begin_layout Standard
7423 \begin_inset LatexCommand \index{-\\/-stack-loc <Value>}
7428 <Value> By default the stack
7429 \begin_inset LatexCommand \index{stack}
7433 is placed after the data segment.
7434 Using this option the stack can be placed anywhere in the internal memory
7436 The value entered can be in Hexadecimal or Decimal format, e.g.
7441 \begin_layout Standard
7450 -stack-loc 0x20 or -
7454 \begin_layout Standard
7464 Since the sp register is incremented before a push or call, the initial
7465 sp will be set to one byte prior the provided value.
7466 The provided value should not overlap any other memory areas such as used
7467 register banks or the data segment and with enough space for the current
7475 \begin_layout Standard
7488 \begin_inset LatexCommand \index{-\\/-pack-iram}
7492 option (which is now a default setting) will override this setting, so
7493 you should also specify the
7499 \begin_layout Standard
7512 \begin_inset LatexCommand \index{-\\/-no-pack-iram}
7516 option if you need to manually place the stack.
7520 \labelwidthstring 00.00.0000
7527 \begin_layout Standard
7539 \begin_inset LatexCommand \index{-\\/-xstack-loc <Value>}
7544 <Value> By default the external stack
7545 \begin_inset LatexCommand \index{xstack}
7549 is placed after the pdata
7550 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7555 Using this option the xstack can be placed anywhere in the external memory
7557 The value entered can be in Hexadecimal or Decimal format, e.g.
7562 \begin_layout Standard
7571 -xstack-loc 0x8000 or -
7575 \begin_layout Standard
7585 The provided value should not overlap any other memory areas such as the
7586 pdata or xdata segment and with enough space for the current application.
7590 \labelwidthstring 00.00.0000
7597 \begin_layout Standard
7609 \begin_inset LatexCommand \index{-\\/-data-loc <Value>}
7614 <Value> The start location of the internal ram data
7615 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7620 The value entered can be in Hexadecimal or Decimal format, eg.
7625 \begin_layout Standard
7638 \begin_layout Standard
7648 (By default, the start location of the internal ram data segment is set
7649 as low as possible in memory, taking into account the used register banks
7650 and the bit segment at address 0x20.
7651 For example if register banks 0 and 1 are used without bit variables, the
7652 data segment will be set, if -
7656 \begin_layout Standard
7665 -data-loc is not used, to location 0x10.)
7669 \labelwidthstring 00.00.0000
7676 \begin_layout Standard
7688 \begin_inset LatexCommand \index{-\\/-idata-loc <Value>}
7693 <Value> The start location of the indirectly addressable internal ram
7694 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7698 of the 8051, default value is 0x80.
7699 The value entered can be in Hexadecimal or Decimal format, eg.
7704 \begin_layout Standard
7713 -idata-loc 0x88 or -
7717 \begin_layout Standard
7730 \labelwidthstring 00.00.0000
7737 \begin_layout Standard
7749 <Value> The start location of the bit
7750 \begin_inset LatexCommand \index{bit}
7754 addressable internal ram of the 8051.
7760 Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7765 \labelwidthstring 00.00.0000
7772 \begin_layout Standard
7782 \begin_inset LatexCommand \index{-\\/-out-fmt-ihx}
7788 The linker output (final object code) is in Intel Hex format.
7789 \begin_inset LatexCommand \index{Intel hex format}
7793 This is the default option.
7794 The format itself is documented in the documentation of srecord
7795 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7803 \labelwidthstring 00.00.0000
7810 \begin_layout Standard
7820 \begin_inset LatexCommand \index{-\\/-out-fmt-s19}
7826 The linker output (final object code) is in Motorola S19 format
7827 \begin_inset LatexCommand \index{Motorola S19 format}
7832 The format itself is documented in the documentation of srecord.
7836 \labelwidthstring 00.00.0000
7843 \begin_layout Standard
7853 \begin_inset LatexCommand \index{-\\/-out-fmt-s19}
7858 \begin_inset LatexCommand \index{HC08!Options!-\\/-out-fmt-elf}
7864 The linker output (final object code) is in ELF format
7865 \begin_inset LatexCommand \index{ELF format}
7870 (Currently only supported for the HC08
7871 \begin_inset LatexCommand \index{HC08}
7879 \labelwidthstring 00.00.0000
7883 linkOption[,linkOption]
7886 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7891 Pass the linkOption to the linker.
7892 If a bootloader is used an option like
7893 \begin_inset Quotes sld
7898 \begin_inset Quotes srd
7901 would be typical to set the start of the code segment.
7902 See also #pragma constseg and #pragma codeseg in section
7903 \begin_inset LatexCommand \ref{sec:Pragmas}
7908 File sdcc/as/doc/asxhtm.html has more on linker options.
7911 \begin_layout Standard
7912 \begin_inset VSpace bigskip
7918 \begin_layout Subsection
7920 \begin_inset LatexCommand \index{Options MCS51}
7925 \begin_inset LatexCommand \index{MCS51 options}
7933 \labelwidthstring 00.00.0000
7940 \begin_layout Standard
7950 \begin_inset LatexCommand \index{-\\/-model-small}
7959 Generate code for Small Model programs, see section Memory Models for more
7961 This is the default model.
7965 \labelwidthstring 00.00.0000
7972 \begin_layout Standard
7982 \begin_inset LatexCommand \index{-\\/-model-medium}
7988 Generate code for Medium model programs, see section Memory Models for
7990 If this option is used all source files in the project have to be compiled
7992 It must also be used when invoking the linker.
7996 \labelwidthstring 00.00.0000
8003 \begin_layout Standard
8013 \begin_inset LatexCommand \index{-\\/-model-large}
8019 Generate code for Large model programs, see section Memory Models for more
8021 If this option is used all source files in the project have to be compiled
8023 It must also be used when invoking the linker.
8027 \labelwidthstring 00.00.0000
8034 \begin_layout Standard
8044 \begin_inset LatexCommand \index{-\\/-xstack}
8050 Uses a pseudo stack in the pdata
8051 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8055 area (usually the first 256 bytes in the external ram) for allocating variables
8056 and passing parameters.
8058 \begin_inset LatexCommand \ref{sub:External-Stack}
8063 External Stack for more details.
8067 \labelwidthstring 00.00.0000
8074 \begin_layout Standard
8087 \begin_inset LatexCommand \index{-\\/-iram-size <Value>}
8091 Causes the linker to check if the internal ram usage is within limits of
8096 \labelwidthstring 00.00.0000
8103 \begin_layout Standard
8116 \begin_inset LatexCommand \index{-\\/-xram-size <Value>}
8120 Causes the linker to check if the external ram usage is within limits of
8125 \labelwidthstring 00.00.0000
8132 \begin_layout Standard
8145 \begin_inset LatexCommand \index{-\\/-code-size <Value>}
8149 Causes the linker to check if the code memory usage is within limits of
8154 \labelwidthstring 00.00.0000
8161 \begin_layout Standard
8174 \begin_inset LatexCommand \index{-\\/-stack-size <Value>}
8178 Causes the linker to check if there is at minimum <Value> bytes for stack.
8182 \labelwidthstring 00.00.0000
8189 \begin_layout Standard
8202 \begin_inset LatexCommand \index{-\\/-pack-iram}
8206 Causes the linker to use unused register banks for data variables and pack
8207 data, idata and stack together.
8208 This is the default now.
8212 \labelwidthstring 00.00.0000
8219 \begin_layout Standard
8232 \begin_inset LatexCommand \index{-\\/-no-pack-iram}
8236 Causes the linker to use old style for allocating memory areas.
8240 \labelwidthstring 00.00.0000
8247 \begin_layout Standard
8260 \begin_inset LatexCommand \index{-\\/-acall-ajmp}
8264 Replaces the three byte instructions lcall/ljmp with the two byte instructions
8266 Only use this option if your code is in the same 2k block of memory.
8267 You may need to use this option for some 8051 derivatives which lack the
8268 lcall/ljmp instructions.
8271 \begin_layout Standard
8272 \begin_inset VSpace bigskip
8278 \begin_layout Subsection
8279 DS390 / DS400 Options
8280 \begin_inset LatexCommand \index{Options DS390}
8285 \begin_inset LatexCommand \index{DS390}
8293 \labelwidthstring 00.00.0000
8300 \begin_layout Standard
8312 \begin_inset LatexCommand \index{DS390!Options!-\\/-model-flat24}
8320 Generate 24-bit flat mode code.
8321 This is the one and only that the ds390 code generator supports right now
8322 and is default when using
8327 See section Memory Models for more details.
8331 \labelwidthstring 00.00.0000
8338 \begin_layout Standard
8348 \begin_inset LatexCommand \index{DS390!Options!-\\/-protect-sp-update}
8354 disable interrupts during ESP:SP updates.
8358 \labelwidthstring 00.00.0000
8365 \begin_layout Standard
8377 \begin_inset LatexCommand \index{DS390!Options!-\\/-stack-10bit}
8381 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8382 This is the one and only that the ds390 code generator supports right now
8383 and is default when using
8388 In this mode, the stack is located in the lower 1K of the internal RAM,
8389 which is mapped to 0x400000.
8390 Note that the support is incomplete, since it still uses a single byte
8391 as the stack pointer.
8392 This means that only the lower 256 bytes of the potential 1K stack space
8393 will actually be used.
8394 However, this does allow you to reclaim the precious 256 bytes of low RAM
8395 for use for the DATA and IDATA segments.
8396 The compiler will not generate any code to put the processor into 10 bit
8398 It is important to ensure that the processor is in this mode before calling
8399 any re-entrant functions compiled with this option.
8400 In principle, this should work with the
8406 \begin_layout Standard
8416 \begin_inset LatexCommand \index{-\\/-stack-auto}
8422 option, but that has not been tested.
8423 It is incompatible with the
8429 \begin_layout Standard
8439 \begin_inset LatexCommand \index{-\\/-xstack}
8446 It also only makes sense if the processor is in 24 bit contiguous addressing
8453 \begin_layout Standard
8462 -model-flat24 option
8467 \begin_inset Note Note
8471 \labelwidthstring 00.00.0000
8478 \begin_layout Standard
8487 -stack-8-bit - switches off the 10-bit mode
8496 \labelwidthstring 00.00.0000
8503 \begin_layout Standard
8513 \begin_inset LatexCommand \index{DS390!Options!-\\/-stack-probe}
8519 insert call to function __stack_probe at each function prologue.
8523 \labelwidthstring 00.00.0000
8530 \begin_layout Standard
8540 \begin_inset LatexCommand \index{DS390!Options!-\\/-tini-libid}
8546 <nnnn> LibraryID used in -mTININative.
8551 \labelwidthstring 00.00.0000
8558 \begin_layout Standard
8568 \begin_inset LatexCommand \index{DS390!Options!-\\/-use-accelerator}
8574 generate code for DS390 Arithmetic Accelerator.
8578 \begin_layout Standard
8579 \begin_inset VSpace bigskip
8585 \begin_layout Subsection
8587 \begin_inset LatexCommand \index{Options Z80}
8592 \begin_inset LatexCommand \index{Z80}
8600 \labelwidthstring 00.00.0000
8607 \begin_layout Standard
8619 \begin_inset LatexCommand \index{Z80!Options!-\\/-callee-saves-bc}
8627 Force a called function to always save BC.
8631 \labelwidthstring 00.00.0000
8638 \begin_layout Standard
8650 \begin_inset LatexCommand \index{Z80!Options!-\\/-no-std-crt0}
8654 When linking, skip the standard crt0.o object file.
8655 You must provide your own crt0.o for your system when linking.
8659 \labelwidthstring 00.00.0000
8666 \begin_layout Standard
8678 \begin_inset LatexCommand \index{Z80!Options!-\\/-portmode=<Value>}
8682 Determinate PORT I/O mode (<Value> is z80 or z180).
8686 \labelwidthstring 00.00.0000
8693 \begin_layout Standard
8705 \begin_inset LatexCommand \index{Z80!Options!-\\/-asm=<Value>}
8709 Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
8713 \labelwidthstring 00.00.0000
8720 \begin_layout Standard
8733 \begin_inset LatexCommand \index{Z80!Options!-\\/-codeseg <Value>}
8737 Use <Value> for the code segment name.
8741 \labelwidthstring 00.00.0000
8748 \begin_layout Standard
8761 \begin_inset LatexCommand \index{Z80!Options!-\\/-constseg <Value>}
8765 Use <Value> for the const segment name.
8769 \labelwidthstring 00.00.0000
8770 \begin_inset VSpace bigskip
8776 \begin_layout Subsection
8778 \begin_inset LatexCommand \index{Options GBZ80}
8783 \begin_inset LatexCommand \index{GBZ80}
8791 \labelwidthstring 00.00.0000
8798 \begin_layout Standard
8810 \begin_inset LatexCommand \index{GBZ80!Options!-\\/-callee-saves-bc}
8818 Force a called function to always save BC.
8822 \labelwidthstring 00.00.0000
8829 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
8833 Use code bank <Num>.
8837 \labelwidthstring 00.00.0000
8844 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
8848 Use data bank <Num>.
8852 \labelwidthstring 00.00.0000
8859 \begin_layout Standard
8872 \begin_inset LatexCommand \index{GBZ80!Options!-\\/-codeseg <Value>}
8876 Use <Value> for the code segment name.
8880 \labelwidthstring 00.00.0000
8887 \begin_layout Standard
8900 \begin_inset LatexCommand \index{GBZ80!Options!-\\/-constseg <Value>}
8904 Use <Value> for the const segment name.
8907 \begin_layout Standard
8908 \begin_inset VSpace bigskip
8914 \begin_layout Subsection
8915 Optimization Options
8916 \begin_inset LatexCommand \index{Options optimization}
8921 \begin_inset LatexCommand \index{Optimization options}
8929 \labelwidthstring 00.00.0000
8936 \begin_layout Standard
8946 \begin_inset LatexCommand \index{-\\/-nogcse}
8952 Will not do global subexpression elimination, this option may be used when
8953 the compiler creates undesirably large stack/data spaces to store compiler
8963 \begin_inset LatexCommand \index{sloc (spill location)}
8968 A warning message will be generated when this happens and the compiler
8969 will indicate the number of extra bytes it allocated.
8970 It is recommended that this option NOT be used, #pragma\InsetSpace ~
8972 \begin_inset LatexCommand \index{\\#pragma nogcse}
8976 can be used to turn off global subexpression elimination
8977 \begin_inset LatexCommand \index{Subexpression elimination}
8981 for a given function only.
8985 \labelwidthstring 00.00.0000
8992 \begin_layout Standard
9002 \begin_inset LatexCommand \index{-\\/-noinvariant}
9008 Will not do loop invariant optimizations, this may be turned off for reasons
9009 explained for the previous option.
9010 For more details of loop optimizations performed see Loop Invariants in
9012 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
9017 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9019 \begin_inset LatexCommand \index{\\#pragma noinvariant}
9023 can be used to turn off invariant optimizations for a given function only.
9027 \labelwidthstring 00.00.0000
9034 \begin_layout Standard
9044 \begin_inset LatexCommand \index{-\\/-noinduction}
9050 Will not do loop induction optimizations, see section strength reduction
9052 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9054 \begin_inset LatexCommand \index{\\#pragma noinduction}
9058 can be used to turn off induction optimizations for a given function only.
9062 \labelwidthstring 00.00.0000
9069 \begin_layout Standard
9079 \begin_inset LatexCommand \index{-\\/-nojtbound}
9088 Will not generate boundary condition check when switch statements
9089 \begin_inset LatexCommand \index{switch statement}
9093 are implemented using jump-tables.
9095 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
9100 Switch Statements for more details.
9101 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9103 \begin_inset LatexCommand \index{\\#pragma nojtbound}
9107 can be used to turn off boundary checking for jump tables for a given function
9112 \labelwidthstring 00.00.0000
9119 \begin_layout Standard
9129 \begin_inset LatexCommand \index{-\\/-noloopreverse}
9138 Will not do loop reversal
9139 \begin_inset LatexCommand \index{Loop reversing}
9147 \labelwidthstring 00.00.0000
9152 \begin_layout Standard
9166 \begin_inset LatexCommand \index{-\\/-nolabelopt }
9170 Will not optimize labels (makes the dumpfiles more readable).
9174 \labelwidthstring 00.00.0000
9181 \begin_layout Standard
9191 \begin_inset LatexCommand \index{-\\/-no-xinit-opt}
9197 Will not memcpy initialized data from code space into xdata space.
9198 This saves a few bytes in code space if you don't have initialized data
9199 \begin_inset LatexCommand \index{Variable initialization}
9207 \labelwidthstring 00.00.0000
9214 \begin_layout Standard
9224 \begin_inset LatexCommand \index{-\\/-nooverlay}
9230 The compiler will not overlay parameters and local variables of any function,
9231 see section Parameters and local variables for more details.
9235 \labelwidthstring 00.00.0000
9242 \begin_layout Standard
9252 \begin_inset LatexCommand \index{-\\/-no-peep}
9258 Disable peep-hole optimization with built-in rules.
9262 \labelwidthstring 00.00.0000
9269 \begin_layout Standard
9281 \begin_inset LatexCommand \index{-\\/-peep-file}
9286 <filename> This option can be used to use additional rules to be used by
9287 the peep hole optimizer.
9289 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9294 Peep Hole optimizations for details on how to write these rules.
9298 \labelwidthstring 00.00.0000
9305 \begin_layout Standard
9315 \begin_inset LatexCommand \index{-\\/-peep-asm}
9321 Pass the inline assembler code through the peep hole optimizer.
9322 This can cause unexpected changes to inline assembler code, please go through
9323 the peephole optimizer
9324 \begin_inset LatexCommand \index{Peephole optimizer}
9328 rules defined in the source file tree '<target>/peeph.def' before using
9333 \labelwidthstring 00.00.0000
9340 \begin_layout Standard
9350 \begin_inset LatexCommand \index{-\\/-opt-code-speed}
9356 The compiler will optimize code generation towards fast code, possibly
9357 at the expense of code size.
9361 \labelwidthstring 00.00.0000
9368 \begin_layout Standard
9378 \begin_inset LatexCommand \index{-\\/-opt-code-size}
9384 The compiler will optimize code generation towards compact code, possibly
9385 at the expense of code speed.
9388 \begin_layout Standard
9389 \begin_inset VSpace bigskip
9395 \begin_layout Subsection
9397 \begin_inset LatexCommand \index{Options other}
9405 \labelwidthstring 00.00.0000
9413 \begin_layout Standard
9423 \begin_inset LatexCommand \index{-\\/-compile-only}
9428 \begin_inset LatexCommand \index{-c -\\/-compile-only}
9434 will compile and assemble the source, but will not call the linkage editor.
9438 \labelwidthstring 00.00.0000
9447 \begin_layout Standard
9459 \begin_inset LatexCommand \index{-\\/-c1mode}
9465 reads the preprocessed source from standard input and compiles it.
9466 The file name for the assembler output must be specified using the -o option.
9470 \labelwidthstring 00.00.0000
9474 \begin_inset LatexCommand \index{-E}
9480 Run only the C preprocessor.
9481 Preprocess all the C source files specified and output the results to standard
9486 \labelwidthstring 00.00.0000
9491 \begin_inset LatexCommand \index{-o <path/file>}
9497 The output path where everything will be placed or the file name used for
9498 all generated output files.
9499 If the parameter is a path, it must have a trailing slash (or backslash
9500 for the Windows binaries) to be recognized as a path.
9501 Note for Windows users: if the path contains spaces, it should be surrounded
9503 The trailing backslash should be doubled in order to prevent escaping the
9504 final quote, for example:
9507 \begin_inset Quotes sld
9521 \begin_inset Quotes srd
9526 or put after the final quote, for example:
9529 \begin_inset Quotes sld
9539 \begin_inset Quotes srd
9547 The path using slashes for directory delimiters can be used too, for example:
9551 \begin_inset Quotes sld
9554 F:/Projects/test3/output 1/
9555 \begin_inset Quotes srd
9564 \labelwidthstring 00.00.0000
9571 \begin_layout Standard
9581 \begin_inset LatexCommand \index{-\\/-stack-auto}
9590 All functions in the source file will be compiled as
9595 \begin_inset LatexCommand \index{reentrant}
9600 the parameters and local variables will be allocated on the stack
9601 \begin_inset LatexCommand \index{stack}
9607 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9611 Parameters and Local Variables for more details.
9612 If this option is used all source files in the project should be compiled
9614 It automatically implies -
9620 \begin_layout Standard
9631 -int-long-reent and -
9637 \begin_layout Standard
9653 \labelwidthstring 00.00.0000
9660 \begin_layout Standard
9670 \begin_inset LatexCommand \index{-\\/-callee-saves}
9675 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9679 function1[,function2][,function3]....
9682 The compiler by default uses a caller saves convention for register saving
9683 across function calls, however this can cause unnecessary register pushing
9684 and popping when calling small functions from larger functions.
9685 This option can be used to switch the register saving convention for the
9686 function names specified.
9687 The compiler will not save registers when calling these functions, no extra
9688 code will be generated at the entry and exit (function prologue
9691 \begin_inset LatexCommand \index{function prologue}
9700 \begin_inset LatexCommand \index{function epilogue}
9706 ) for these functions to save and restore the registers used by these functions,
9707 this can SUBSTANTIALLY reduce code and improve run time performance of
9709 In the future the compiler (with inter procedural analysis) will be able
9710 to determine the appropriate scheme to use for each function call.
9711 DO NOT use this option for built-in functions such as _mulint..., if this
9712 option is used for a library function the appropriate library function
9713 needs to be recompiled with the same option.
9714 If the project consists of multiple source files then all the source file
9715 should be compiled with the same -
9719 \begin_layout Standard
9728 -callee-saves option string.
9729 Also see #pragma\InsetSpace ~
9731 \begin_inset LatexCommand \index{\\#pragma callee\\_saves}
9736 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9744 \labelwidthstring 00.00.0000
9751 \begin_layout Standard
9761 \begin_inset LatexCommand \index{-\\/-all-callee-saves}
9771 \begin_layout Standard
9780 -callee-saves will be applied to all functions by default.
9784 \labelwidthstring 00.00.0000
9791 \begin_layout Standard
9801 \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}
9833 Stop after the stage of compilation proper; do not assemble.
9834 The output is an assembler code file for the input file specified.
9838 \labelwidthstring 00.00.0000
9845 \begin_layout Standard
9855 \begin_inset LatexCommand \index{-\\/-int-long-reent}
9861 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
9862 Note by default these libraries are compiled as non-reentrant.
9863 See section Installation for more details.
9867 \labelwidthstring 00.00.0000
9874 \begin_layout Standard
9884 \begin_inset LatexCommand \index{-\\/-cyclomatic}
9890 This option will cause the compiler to generate an information message for
9891 each function in the source file.
9892 The message contains some
9896 information about the function.
9897 The number of edges and nodes the compiler detected in the control flow
9898 graph of the function, and most importantly the
9900 cyclomatic complexity
9901 \begin_inset LatexCommand \index{Cyclomatic complexity}
9907 see section on Cyclomatic Complexity for more details.
9911 \labelwidthstring 00.00.0000
9918 \begin_layout Standard
9928 \begin_inset LatexCommand \index{-\\/-float-reent}
9934 Floating point library is compiled as reentrant
9935 \begin_inset LatexCommand \index{reentrant}
9940 See section Installation for more details.
9944 \labelwidthstring 00.00.0000
9951 \begin_layout Standard
9961 \begin_inset LatexCommand \index{-\\/-funsigned-char}
9967 The default signedness for every type is
9972 In some embedded environments the default signedness of
9981 To set the signess for characters to unsigned, use the option -
9987 \begin_layout Standard
9999 If this option is set and no signedness keyword (unsigned/signed) is given,
10000 a char will be signed.
10001 All other types are unaffected.
10005 \labelwidthstring 00.00.0000
10012 \begin_layout Standard
10022 \begin_inset LatexCommand \index{-\\/-main-return}
10028 This option can be used if the code generated is called by a monitor program
10029 or if the main routine includes an endless loop.
10030 This option results in slightly smaller code and saves two bytes of stack
10032 The return from the 'main'
10033 \begin_inset LatexCommand \index{main return}
10037 function will return to the function calling main.
10038 The default setting is to lock up i.e.
10047 \labelwidthstring 00.00.0000
10054 \begin_layout Standard
10064 \begin_inset LatexCommand \index{-\\/-nostdinc}
10070 This will prevent the compiler from passing on the default include path
10071 to the preprocessor.
10075 \labelwidthstring 00.00.0000
10082 \begin_layout Standard
10092 \begin_inset LatexCommand \index{-\\/-nostdlib}
10098 This will prevent the compiler from passing on the default library
10099 \begin_inset LatexCommand \index{Libraries}
10103 path to the linker.
10107 \labelwidthstring 00.00.0000
10114 \begin_layout Standard
10124 \begin_inset LatexCommand \index{-\\/-verbose}
10130 Shows the various actions the compiler is performing.
10134 \labelwidthstring 00.00.0000
10138 \begin_inset LatexCommand \index{-V}
10144 Shows the actual commands the compiler is executing.
10148 \labelwidthstring 00.00.0000
10155 \begin_layout Standard
10165 \begin_inset LatexCommand \index{-\\/-no-c-code-in-asm}
10171 Hides your ugly and inefficient c-code from the asm file, so you can always
10172 blame the compiler :)
10176 \labelwidthstring 00.00.0000
10183 \begin_layout Standard
10193 \begin_inset LatexCommand \index{-\\/-no-gen-comments}
10199 Include code generator and peep-hole comments in the generated asm files.
10203 \labelwidthstring 00.00.0000
10210 \begin_layout Standard
10220 \begin_inset LatexCommand \index{-\\/-no-peep-comments}
10226 Don't include peep-hole comments in the generated asm files even if -
10232 \begin_layout Standard
10243 -fverbose-asm option is specified.
10247 \labelwidthstring 00.00.0000
10254 \begin_layout Standard
10264 \begin_inset LatexCommand \index{-\\/-i-code-in-asm}
10270 Include i-codes in the asm file.
10271 Sounds like noise but is most helpful for debugging the compiler itself.
10275 \labelwidthstring 00.00.0000
10282 \begin_layout Standard
10292 \begin_inset LatexCommand \index{pedantic}
10297 \begin_inset LatexCommand \index{-\\/-less-pedantic}
10304 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10308 Disable some of the more pedantic warnings
10309 \begin_inset LatexCommand \index{Warnings}
10314 For more details, see the less_pedantic pragma
10315 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10323 \labelwidthstring 00.00.0000
10330 \begin_layout Standard
10339 -disable-warning\InsetSpace ~
10341 \begin_inset LatexCommand \index{-\\/-disable-warning}
10347 Disable specific warning with number <nnnn>.
10351 \labelwidthstring 00.00.0000
10358 \begin_layout Standard
10368 \begin_inset LatexCommand \index{-\\/-print-search-dirs}
10374 Display the directories in the compiler's search path
10378 \labelwidthstring 00.00.0000
10385 \begin_layout Standard
10395 \begin_inset LatexCommand \index{-\\/-vc}
10401 Display errors and warnings using MSVC style, so you can use SDCC with
10402 the visual studio IDE
10403 \begin_inset LatexCommand \index{IDE}
10408 With SDCC both offering a GCC-like (the default) and a MSVC-like
10409 \begin_inset LatexCommand \index{MSVC output style}
10413 output style, integration into most programming editors should be straightforwa
10418 \labelwidthstring 00.00.0000
10425 \begin_layout Standard
10435 \begin_inset LatexCommand \index{-\\/-use-stdout}
10441 Send errors and warnings to stdout instead of stderr.
10445 \labelwidthstring 00.00.0000
10449 asmOption[,asmOption]
10452 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10457 Pass the asmOption to the assembler
10458 \begin_inset LatexCommand \index{Options assembler}
10463 \begin_inset LatexCommand \index{Assembler options}
10468 See file sdcc/as/doc/asxhtm.html for assembler options.cd
10472 \labelwidthstring 00.00.0000
10479 \begin_layout Standard
10489 \begin_inset LatexCommand \index{-\\/-std-sdcc89}
10495 Generally follow the C89 standard, but allow SDCC features that conflict
10496 with the standard (default).
10500 \labelwidthstring 00.00.0000
10507 \begin_layout Standard
10517 \begin_inset LatexCommand \index{-\\/-std-c89}
10523 Follow the C89 standard and disable SDCC features that conflict with the
10528 \labelwidthstring 00.00.0000
10535 \begin_layout Standard
10545 \begin_inset LatexCommand \index{-\\/-std-sdcc99}
10551 Generally follow the C99 standard, but allow SDCC features that conflict
10552 with the standard (incomplete support).
10556 \labelwidthstring 00.00.0000
10563 \begin_layout Standard
10573 \begin_inset LatexCommand \index{-\\/-std-sdcc99}
10579 Follow the C99 standard and disable SDCC features that conflict with the
10580 standard (incomplete support).
10584 \labelwidthstring 00.00.0000
10591 \begin_layout Standard
10603 \begin_inset LatexCommand \index{-\\/-codeseg <Value>}
10608 <Name> The name to be used for the code
10609 \begin_inset LatexCommand \index{code}
10613 segment, default CSEG.
10614 This is useful if you need to tell the compiler to put the code in a special
10615 segment so you can later on tell the linker to put this segment in a special
10617 Can be used for instance when using bank switching to put the code in a
10622 \labelwidthstring 00.00.0000
10629 \begin_layout Standard
10641 \begin_inset LatexCommand \index{-\\/-constseg <Value>}
10646 <Name> The name to be used for the const
10647 \begin_inset LatexCommand \index{const}
10651 segment, default CONST.
10652 This is useful if you need to tell the compiler to put the const data in
10653 a special segment so you can later on tell the linker to put this segment
10654 in a special place in memory.
10655 Can be used for instance when using bank switching to put the const data
10660 \labelwidthstring 00.00.0000
10667 \begin_layout Standard
10676 -fdollars-in-identifiers
10677 \begin_inset LatexCommand \index{-\\/-fdollars-in-identifiers}
10683 Permit '$' as an identifier character.
10687 \labelwidthstring 00.00.0000
10694 \begin_layout Standard
10706 \begin_inset LatexCommand \index{-\\/-more-pedantic}
10711 \begin_inset LatexCommand \index{pedantic}
10721 a SDCC compiler option but if you want
10725 warnings you can use a separate tool dedicated to syntax checking like
10727 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10732 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10737 \begin_inset LatexCommand \url{http://www.splint.org}
10742 To make your source files parseable by splint you will have to include
10748 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10752 in your source file and add brackets around extended keywords (like
10755 \begin_inset Quotes sld
10768 \begin_inset Quotes srd
10776 \begin_inset Quotes sld
10779 __interrupt\InsetSpace ~
10781 \begin_inset Quotes srd
10789 Splint has an excellent on line manual at
10790 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10794 and it's capabilities go beyond pure syntax checking.
10795 You'll need to tell splint the location of SDCC's include files so a typical
10796 command line could look like this:
10800 splint\InsetSpace ~
10802 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10808 \labelwidthstring 00.00.0000
10815 \begin_layout Standard
10827 \begin_inset LatexCommand \index{-\\/-short-is-8bits}
10832 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
10836 Treat short as 8-bit (for backward compatibility with older versions of
10837 compiler - see section
10838 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
10845 \begin_layout Standard
10846 \begin_inset VSpace bigskip
10852 \begin_layout Subsection
10853 Intermediate Dump Options
10854 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
10859 \begin_inset LatexCommand \index{Options intermediate dump}
10864 \begin_inset LatexCommand \index{Intermediate dump options}
10871 \begin_layout Standard
10872 The following options are provided for the purpose of retargetting and debugging
10874 They provide a means to dump the intermediate code (iCode
10875 \begin_inset LatexCommand \index{iCode}
10879 ) generated by the compiler in human readable form at various stages of
10880 the compilation process.
10881 More on iCodes see chapter
10882 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10887 \begin_inset Quotes srd
10890 The anatomy of the compiler
10891 \begin_inset Quotes srd
10898 \labelwidthstring 00.00.0000
10905 \begin_layout Standard
10915 \begin_inset LatexCommand \index{-\\/-dumpraw}
10921 This option will cause the compiler to dump the intermediate code into
10924 <source filename>.dumpraw
10926 just after the intermediate code has been generated for a function, i.e.
10927 before any optimizations are done.
10929 \begin_inset LatexCommand \index{Basic blocks}
10933 at this stage ordered in the depth first number, so they may not be in
10934 sequence of execution.
10938 \labelwidthstring 00.00.0000
10945 \begin_layout Standard
10955 \begin_inset LatexCommand \index{-\\/-dumpgcse}
10961 Will create a dump of iCodes, after global subexpression elimination
10962 \begin_inset LatexCommand \index{Global subexpression elimination}
10966 , into a file named
10968 <source filename>.dumpgcse.
10972 \labelwidthstring 00.00.0000
10979 \begin_layout Standard
10989 \begin_inset LatexCommand \index{-\\/-dumpdeadcode}
10995 Will create a dump of iCodes, after deadcode elimination
10996 \begin_inset LatexCommand \index{Dead-code elimination}
11000 , into a file named
11002 <source filename>.dumpdeadcode.
11006 \labelwidthstring 00.00.0000
11013 \begin_layout Standard
11023 \begin_inset LatexCommand \index{-\\/-dumploop}
11032 Will create a dump of iCodes, after loop optimizations
11033 \begin_inset LatexCommand \index{Loop optimization}
11037 , into a file named
11039 <source filename>.dumploop.
11043 \labelwidthstring 00.00.0000
11050 \begin_layout Standard
11060 \begin_inset LatexCommand \index{-\\/-dumprange}
11069 Will create a dump of iCodes, after live range analysis
11070 \begin_inset LatexCommand \index{Live range analysis}
11074 , into a file named
11076 <source filename>.dumprange.
11080 \labelwidthstring 00.00.0000
11087 \begin_layout Standard
11097 \begin_inset LatexCommand \index{-\\/-dumlrange}
11103 Will dump the life ranges
11104 \begin_inset LatexCommand \index{Live range analysis}
11112 \labelwidthstring 00.00.0000
11119 \begin_layout Standard
11129 \begin_inset LatexCommand \index{-\\/-dumpregassign}
11135 Will create a dump of iCodes, after register assignment
11136 \begin_inset LatexCommand \index{Register assignment}
11140 , into a file named
11142 <source filename>.dumprassgn.
11146 \labelwidthstring 00.00.0000
11153 \begin_layout Standard
11163 \begin_inset LatexCommand \index{-\\/-dumplrange}
11169 Will create a dump of the live ranges of iTemp's
11173 \labelwidthstring 00.00.0000
11180 \begin_layout Standard
11190 \begin_inset LatexCommand \index{-\\/-dumpall}
11199 Will cause all the above mentioned dumps to be created.
11202 \begin_layout Standard
11203 \begin_inset VSpace bigskip
11209 \begin_layout Subsection
11210 Redirecting output on Windows Shells
11213 \begin_layout Standard
11214 By default SDCC writes its error messages to
11215 \begin_inset Quotes sld
11219 \begin_inset Quotes srd
11223 To force all messages to
11224 \begin_inset Quotes sld
11228 \begin_inset Quotes srd
11240 \begin_layout Standard
11255 \begin_inset LatexCommand \index{-\\/-use-stdout}
11260 Additionally, if you happen to have visual studio installed in your windows
11261 machine, you can use it to compile your sources using a custom build and
11268 \begin_layout Standard
11280 \begin_inset LatexCommand \index{-\\/-vc}
11285 Something like this should work:
11304 \begin_layout Standard
11323 \begin_layout Standard
11335 -model-large -c $(InputPath)
11338 \begin_inset VSpace bigskip
11344 \begin_layout Section
11345 Environment variables
11346 \begin_inset LatexCommand \index{Environment variables}
11353 \begin_layout Standard
11354 SDCC recognizes the following environment variables:
11358 \labelwidthstring 00.00.0000
11362 \begin_inset LatexCommand \index{SDCC\\_LEAVE\\_SIGNALS}
11368 SDCC installs a signal handler
11369 \begin_inset LatexCommand \index{signal handler}
11373 to be able to delete temporary files after an user break (^C) or an exception.
11374 If this environment variable is set, SDCC won't install the signal handler
11375 in order to be able to debug SDCC.
11379 \labelwidthstring 00.00.0000
11385 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11391 Path, where temporary files will be created.
11392 The order of the variables is the search order.
11393 In a standard *nix environment these variables are not set, and there's
11394 no need to set them.
11395 On Windows it's recommended to set one of them.
11399 \labelwidthstring 00.00.0000
11403 \begin_inset LatexCommand \index{SDCC\\_HOME}
11410 \begin_inset LatexCommand \ref{sub:Install-paths}
11416 \begin_inset Quotes sld
11420 \begin_inset Quotes srd
11427 \labelwidthstring 00.00.0000
11431 \begin_inset LatexCommand \index{SDCC\\_INCLUDE}
11438 \begin_inset LatexCommand \ref{sub:Search-Paths}
11444 \begin_inset Quotes sld
11448 \begin_inset Quotes srd
11455 \labelwidthstring 00.00.0000
11459 \begin_inset LatexCommand \index{SDCC\\_LIB}
11466 \begin_inset LatexCommand \ref{sub:Search-Paths}
11472 \begin_inset Quotes sld
11476 \begin_inset Quotes srd
11482 \begin_layout Standard
11483 There are some more environment variables recognized by SDCC, but these
11484 are solely used for debugging purposes.
11485 They can change or disappear very quickly, and will never be documented.
11486 \begin_inset VSpace bigskip
11492 \begin_layout Section
11493 Storage Class Language Extensions
11496 \begin_layout Subsection
11497 MCS51/DS390 Storage Class
11498 \begin_inset LatexCommand \index{Storage class}
11502 Language Extensions
11505 \begin_layout Standard
11506 In addition to the ANSI storage classes SDCC allows the following MCS51
11507 specific storage classes:
11510 \begin_layout Subsubsection
11512 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11517 \begin_inset LatexCommand \index{\\_\\_data (mcs51, ds390 storage class)}
11522 \begin_inset LatexCommand \index{near (storage class)}
11527 \begin_inset LatexCommand \index{\\_\\_near (storage class)}
11534 \begin_layout Standard
11539 storage class for the Small Memory model (
11547 or the more ANSI-C compliant forms
11555 can be used synonymously).
11556 Variables declared with this storage class will be allocated in the directly
11557 addressable portion of the internal RAM of a 8051, e.g.:
11560 \begin_layout Verse
11563 __data unsigned char test_data;
11566 \begin_layout Standard
11567 Writing 0x01 to this variable generates the assembly code:
11570 \begin_layout Verse
11573 75*00 01\InsetSpace ~
11581 \begin_layout Subsubsection
11583 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11588 \begin_inset LatexCommand \index{\\_\\_xdata (mcs51, ds390 storage class)}
11593 \begin_inset LatexCommand \index{far (storage class)}
11598 \begin_inset LatexCommand \index{\\_\\_far (storage class)}
11605 \begin_layout Standard
11606 Variables declared with this storage class will be placed in the external
11612 storage class for the Large Memory model, e.g.:
11615 \begin_layout Verse
11618 __xdata unsigned char test_xdata;
11621 \begin_layout Standard
11622 Writing 0x01 to this variable generates the assembly code:
11625 \begin_layout Verse
11628 90s00r00\InsetSpace ~
11659 \begin_layout Subsubsection
11661 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11666 \begin_inset LatexCommand \index{\\_\\_idata (mcs51, ds390 storage class)}
11673 \begin_layout Standard
11674 Variables declared with this storage class will be allocated into the indirectly
11675 addressable portion of the internal ram of a 8051, e.g.:
11678 \begin_layout Verse
11681 __idata unsigned char test_idata;
11684 \begin_layout Standard
11685 Writing 0x01 to this variable generates the assembly code:
11688 \begin_layout Verse
11715 \begin_layout Standard
11716 Please note, the first 128 byte of idata physically access the same RAM
11717 as the data memory.
11718 The original 8051 had 128 byte idata memory, nowadays most devices have
11719 256 byte idata memory.
11721 \begin_inset LatexCommand \index{stack}
11725 is located in idata memory.
11728 \begin_layout Subsubsection
11730 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11735 \begin_inset LatexCommand \index{\\_\\_pdata (mcs51, ds390 storage class)}
11742 \begin_layout Standard
11743 Paged xdata access is just as straightforward as using the other addressing
11745 It is typically located at the start of xdata and has a maximum size of
11747 The following example writes 0x01 to the pdata variable.
11748 Please note, pdata access physically accesses xdata memory.
11749 The high byte of the address is determined by port P2
11750 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11754 (or in case of some 8051 variants by a separate Special Function Register,
11756 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11765 storage class for the Medium Memory model, e.g.:
11768 \begin_layout Verse
11771 __pdata unsigned char test_pdata;
11774 \begin_layout Standard
11775 Writing 0x01 to this variable generates the assembly code:
11778 \begin_layout Verse
11787 mov r0,#_test_pdata
11809 \begin_layout Standard
11814 \begin_layout Standard
11824 \begin_inset LatexCommand \index{-\\/-xstack}
11828 option is used the pdata memory area is followed by the xstack memory area
11829 and the sum of their sizes is limited to 256 bytes.
11832 \begin_layout Subsubsection
11834 \begin_inset LatexCommand \index{code}
11839 \begin_inset LatexCommand \index{\\_\\_code}
11846 \begin_layout Standard
11847 'Variables' declared with this storage class will be placed in the code
11851 \begin_layout Verse
11854 __code unsigned char test_code;
11857 \begin_layout Standard
11858 Read access to this variable generates the assembly code:
11861 \begin_layout Verse
11864 90s00r6F\InsetSpace ~
11867 mov dptr,#_test_code
11892 \begin_layout Standard
11897 indexed arrays of characters in code memory can be accessed efficiently:
11900 \begin_layout Verse
11903 __code char test_array[] = {'c','h','e','a','p'};
11906 \begin_layout Standard
11907 Read access to this array using an 8-bit unsigned index generates the assembly
11911 \begin_layout Verse
11923 \begin_layout Verse
11926 90s00r41\InsetSpace ~
11929 mov dptr,#_test_array
11932 \begin_layout Verse
11947 \begin_layout Subsubsection
11949 \begin_inset LatexCommand \index{bit}
11954 \begin_inset LatexCommand \index{\\_\\_bit}
11961 \begin_layout Standard
11962 This is a data-type and a storage class specifier.
11963 When a variable is declared as a bit, it is allocated into the bit addressable
11964 memory of 8051, e.g.:
11967 \begin_layout Verse
11973 \begin_layout Standard
11974 Writing 1 to this variable generates the assembly code:
11977 \begin_layout Verse
11991 \begin_layout Standard
11992 The bit addressable memory consists of 128 bits which are located from 0x20
11993 to 0x2f in data memory.
11996 Apart from this 8051 specific storage class most architectures support
11998 \begin_inset LatexCommand \index{bitfields}
12006 \begin_layout Standard
12007 Not really meant as examples, but nevertheless showing what bitfields are
12008 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12014 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12015 signed modifier are implemented as unsigned.
12018 \begin_layout Subsubsection
12020 \begin_inset LatexCommand \index{sfr}
12025 \begin_inset LatexCommand \index{\\_\\_sfr}
12030 \begin_inset LatexCommand \index{sfr16}
12035 \begin_inset LatexCommand \index{\\_\\_sfr16}
12040 \begin_inset LatexCommand \index{sfr32}
12045 \begin_inset LatexCommand \index{\\_\\_sfr32}
12050 \begin_inset LatexCommand \index{\\_\\_sbit}
12055 \begin_inset LatexCommand \index{sbit}
12062 \begin_layout Standard
12063 Like the bit keyword,
12065 sfr / sfr16 / sfr32 / sbit
12067 signify both a data-type and storage class, they are used to describe the
12088 variables of a 8051, eg:
12091 \begin_layout Verse
12095 \begin_inset LatexCommand \index{at}
12100 \begin_inset LatexCommand \index{\\_\\_at}
12104 (0x80) P0;\InsetSpace ~
12105 /* special function register P0 at location 0x80 */
12110 special function register combination for timer 0
12114 with the high byte at
12115 location 0x8C and the low byte at location 0x8A */
12117 __sfr16 __at (0x8C8A)
12123 \begin_inset LatexCommand \index{at}
12128 \begin_inset LatexCommand \index{\\_\\_at}
12132 (0xd7) CY;\InsetSpace ~
12134 \begin_inset LatexCommand \index{Flags}
12139 \begin_inset LatexCommand \index{Carry flag}
12146 \begin_layout Standard
12147 Special function registers which are located on an address dividable by
12148 8 are bit-addressable, an
12152 addresses a specific bit within these sfr.
12154 16 Bit and 32 bit special function
12155 register combinations which require a certain access order are better not
12165 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12166 this is not guaranteed.
12171 \begin_layout Standard
12172 Please note, if you use a header file which was written for another compiler
12173 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
12179 Specifically the syntax
12182 sfr P0 = 0x80;\InsetSpace ~
12189 by SDCC to an assignment of 0x80 to a variable called P0
12192 \begin_inset Marginal
12195 \begin_layout Standard
12209 Nevertheless it is possible to write header files
12210 \begin_inset LatexCommand \index{Header files}
12215 \begin_inset LatexCommand \index{Include files}
12219 which can be shared among different compilers (see section
12220 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
12228 \begin_layout Subsubsection
12230 \begin_inset LatexCommand \index{Pointer}
12234 to MCS51/DS390 specific memory spaces
12237 \begin_layout Standard
12238 SDCC allows (via language extensions) pointers to explicitly point to any
12239 of the memory spaces
12240 \begin_inset LatexCommand \index{Memory model}
12245 In addition to the explicit pointers, the compiler uses (by default) generic
12246 pointers which can be used to point to any of the memory spaces.
12251 declaration examples:
12254 \begin_layout Verse
12257 /* pointer physically in internal ram pointing to object in external ram
12260 __xdata unsigned char * __data p;
12264 /* pointer physically in external ram
12265 pointing to object in internal ram */
12267 __data unsigned char * __xdata p;
12272 pointer physically in code rom pointing to data in xdata space */
12275 unsigned char * __code p;
12279 /* pointer physically in code space pointing to
12280 data in code space */
12282 __code unsigned char * __code p;
12287 physically located in xdata space */
12289 unsigned char * __xdata p;
12294 pointer physically located in default memory space */
12301 the following is a function pointer
12302 \begin_inset LatexCommand \index{function pointer}
12306 physically located in data space */
12308 char (* __data fp)(void);
12311 \begin_layout Standard
12312 Well you get the idea.
12317 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
12330 The highest order byte of the
12334 pointers contains the data space information.
12335 Assembler support routines are called whenever data is stored or retrieved
12341 These are useful for developing reusable library
12342 \begin_inset LatexCommand \index{Libraries}
12347 Explicitly specifying the pointer
12348 \begin_inset LatexCommand \index{pointer}
12352 type will generate the most efficient code.
12355 \begin_layout Subsubsection
12356 Notes on MCS51 memory
12357 \begin_inset LatexCommand \index{MCS51 memory}
12364 \begin_layout Standard
12365 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12366 RAM memory which is structured as follows:
12370 - Bytes 00-1F - 32 bytes to hold
12371 up to 4 banks of the registers R0 to R7,
12373 - Bytes 20-2F - 16 bytes to hold
12375 \begin_inset LatexCommand \index{bit}
12381 - Bytes 30-7F - 80 bytes for general purpose use.
12386 \begin_layout Standard
12387 Additionally some members of the MCS51 family may have up to 128 bytes of
12388 additional, indirectly addressable, internal RAM memory (
12393 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12398 \begin_inset LatexCommand \index{\\_\\_idata (mcs51, ds390 storage class)}
12403 Furthermore, some chips may have some built in external memory (
12408 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12413 \begin_inset LatexCommand \index{\\_\\_xdata (mcs51, ds390 storage class)}
12417 ) which should not be confused with the internal, directly addressable RAM
12423 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12428 \begin_inset LatexCommand \index{\\_\\_data (mcs51, ds390 storage class)}
12433 Sometimes this built in
12437 memory has to be activated before using it (you can probably find this
12438 information on the datasheet of the microcontroller your are using, see
12440 \begin_inset LatexCommand \ref{sub:Startup-Code}
12448 \begin_layout Standard
12449 Normally SDCC will only use the first bank
12450 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12454 of registers (register bank 0), but it is possible to specify that other
12455 banks of registers (keyword
12462 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12467 \begin_inset LatexCommand \index{\\_\\_using (mcs51, ds390 register bank)}
12473 ) should be used for example in interrupt
12474 \begin_inset LatexCommand \index{interrupt}
12479 \begin_inset LatexCommand \index{\\_\\_interrupt}
12484 By default, the compiler will place the stack after the last byte of allocated
12485 memory for variables.
12486 For example, if the first 2 banks of registers are used, and only four
12491 variables, it will position the base of the internal stack at address 20
12493 This implies that as the stack
12494 \begin_inset LatexCommand \index{stack}
12498 grows, it will use up the remaining register banks, and the 16 bytes used
12499 by the 128 bit variables, and 80 bytes for general purpose use.
12500 If any bit variables are used, the data variables will be placed in unused
12501 register banks and after the byte holding the last bit variable.
12502 For example, if register banks 0 and 1 are used, and there are 9 bit variables
12507 variables will be placed starting from address 0x10 to 0x20 and continue
12513 \begin_layout Standard
12523 \begin_inset LatexCommand \index{-\\/-data-loc <Value>}
12527 to specify the start address of the
12535 \begin_layout Standard
12545 \begin_inset LatexCommand \index{-\\/-iram-size <Value>}
12549 to specify the size of the total internal RAM (
12563 \begin_layout Standard
12564 By default the 8051 linker will place the stack after the last byte of (i)data
12570 \begin_layout Standard
12580 \begin_inset LatexCommand \index{-\\/-stack-loc <Value>}
12584 allows you to specify the start of the stack, i.e.
12585 you could start it after any data in the general purpose area.
12586 If your microcontroller has additional indirectly addressable internal
12591 ) you can place the stack on it.
12592 You may also need to use -
12596 \begin_layout Standard
12606 \begin_inset LatexCommand \index{-\\/-xdata-loc<Value>}
12610 to set the start address of the external RAM (
12618 \begin_layout Standard
12628 \begin_inset LatexCommand \index{-\\/-xram-size <Value>}
12632 to specify its size.
12633 Same goes for the code memory, using -
12637 \begin_layout Standard
12647 \begin_inset LatexCommand \index{-\\/-code-loc <Value>}
12655 \begin_layout Standard
12665 \begin_inset LatexCommand \index{-\\/-code-size <Value>}
12670 If in doubt, don't specify any options and see if the resulting memory
12671 layout is appropriate, then you can adjust it.
12674 \begin_layout Standard
12675 The linker generates two files with memory allocation information.
12676 The first, with extension .map
12677 \begin_inset LatexCommand \index{<file>.map}
12681 shows all the variables and segments.
12682 The second with extension .mem
12683 \begin_inset LatexCommand \index{<file>.mem}
12687 shows the final memory layout.
12688 The linker will complain either if memory segments overlap, there is not
12689 enough memory, or there is not enough space for stack.
12690 If you get any linking warnings and/or errors related to stack or segments
12691 allocation, take a look at either the .map or .mem files to find out what
12693 The .mem file may even suggest a solution to the problem.
12694 \begin_inset VSpace bigskip
12700 \begin_layout Subsection
12701 Z80/Z180 Storage Class
12702 \begin_inset LatexCommand \index{Z80!Storage class}
12706 Language Extensions
12709 \begin_layout Subsubsection
12711 \begin_inset LatexCommand \index{sfr}
12716 \begin_inset LatexCommand \index{\\_\\_sfr}
12720 (in/out to 8-bit addresses)
12723 \begin_layout Standard
12725 \begin_inset LatexCommand \index{Z80}
12729 family has separate address spaces for memory and
12739 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12744 \begin_inset LatexCommand \index{Z80!I/O memory}
12749 \begin_inset LatexCommand \index{Z180!I/O memory}
12753 is accessed with special instructions, e.g.:
12756 \begin_layout Verse
12759 sfr at 0x78 IoPort;\InsetSpace ~
12761 /* define a var in I/O space at 78h called IoPort */
12765 \begin_layout Standard
12766 Writing 0x01 to this variable generates the assembly code:
12769 \begin_layout Verse
12789 \begin_layout Subsubsection
12791 \begin_inset LatexCommand \index{sfr}
12796 \begin_inset LatexCommand \index{\\_\\_sfr}
12800 (in/out to 16-bit addresses)
12803 \begin_layout Standard
12808 is used to support 16 bit addresses in I/O memory e.g.:
12811 \begin_layout Verse
12815 \begin_inset LatexCommand \index{at}
12820 \begin_inset LatexCommand \index{\\_\\_at}
12827 \begin_layout Standard
12828 Writing 0x01 to this variable generates the assembly code:
12831 \begin_layout Verse
12834 01 23 01\InsetSpace ~
12856 \begin_layout Subsubsection
12858 \begin_inset LatexCommand \index{sfr}
12863 \begin_inset LatexCommand \index{\\_\\_sfr}
12867 (in0/out0 to 8 bit addresses on Z180
12868 \begin_inset LatexCommand \index{Z180}
12873 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12880 \begin_layout Standard
12881 The compiler option -
12885 \begin_layout Standard
12895 \begin_inset LatexCommand \index{Z180!Options!-\\/-portmode}
12899 =180 (80) and a compiler #pragma\InsetSpace ~
12901 \begin_inset LatexCommand \index{Z180!Pragmas!\\#pragma portmode}
12905 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12915 If you include the file z180.h this will be set automatically.
12916 \begin_inset VSpace bigskip
12922 \begin_layout Subsection
12924 \begin_inset LatexCommand \index{HC08!Storage class}
12928 Language Extensions
12931 \begin_layout Subsubsection
12933 \begin_inset LatexCommand \index{data (hc08 storage class)}
12938 \begin_inset LatexCommand \index{\\_\\_data (hc08 storage class)}
12945 \begin_layout Standard
12946 The data storage class declares a variable that resides in the first 256
12947 bytes of memory (the direct page).
12949 \begin_inset LatexCommand \index{HC08}
12953 is most efficient at accessing variables (especially pointers) stored here.
12956 \begin_layout Subsubsection
12958 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
12963 \begin_inset LatexCommand \index{\\_\\_xdata (hc08 storage class)}
12970 \begin_layout Standard
12971 The xdata storage class declares a variable that can reside anywhere in
12973 This is the default if no storage class is specified.
12975 \begin_inset VSpace bigskip
12981 \begin_layout Section
12982 Absolute Addressing
12983 \begin_inset LatexCommand \index{Absolute addressing}
12990 \begin_layout Standard
12991 Data items can be assigned an absolute address with the
12994 \begin_inset LatexCommand \index{at}
12999 \begin_inset LatexCommand \index{\\_\\_at}
13005 keyword, in addition to a storage class, e.g.:
13008 \begin_layout Verse
13012 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13017 \begin_inset LatexCommand \index{\\_\\_xdata (mcs51, ds390 storage class)}
13022 \begin_inset LatexCommand \index{at}
13027 \begin_inset LatexCommand \index{\\_\\_at}
13031 0x7ffe unsigned int chksum;
13034 \begin_layout Standard
13035 or, better conforming to ISO/IEC 9899 C:
13038 \begin_layout Verse
13041 __xdata __at (0x7ffe) unsigned int chksum;
13044 \begin_layout Standard
13045 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
13046 of the external ram.
13051 reserve any space for variables declared in this way
13052 \begin_inset Marginal
13055 \begin_layout Standard
13064 (they are implemented with an equate in the assembler).
13065 Thus it is left to the programmer to make sure there are no overlaps with
13066 other variables that are declared without the absolute address.
13067 The assembler listing file (.lst
13068 \begin_inset LatexCommand \index{<file>.lst}
13072 ) and the linker output files (.rst
13073 \begin_inset LatexCommand \index{<file>.rst}
13078 \begin_inset LatexCommand \index{<file>.map}
13082 ) are good places to look for such overlaps.
13085 \begin_layout Standard
13086 If however you provide an initializer
13087 \begin_inset LatexCommand \index{Variable initialization}
13091 actual memory allocation will take place and overlaps will be detected
13096 \begin_layout Verse
13099 __code __at (0x7ff0) char Id[5] =
13100 \begin_inset Quotes sld
13104 \begin_inset Quotes srd
13110 \begin_layout Standard
13111 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
13115 \begin_layout Standard
13116 In case of memory mapped I/O devices the keyword
13120 has to be used to tell the compiler that accesses might not be removed:
13123 \begin_layout Verse
13127 \begin_inset LatexCommand \index{volatile}
13132 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13137 \begin_inset LatexCommand \index{at}
13141 (0x8000) unsigned char PORTA_8255;
13144 \begin_layout Standard
13145 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
13150 \begin_inset LatexCommand \index{Aligned array}
13157 starts at a block (256 byte) boundary
13158 \begin_inset LatexCommand \index{block boundary}
13163 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13169 Absolute addresses can be specified for variables in all
13170 storage classes, e.g.:
13173 \begin_layout Verse
13177 \begin_inset LatexCommand \index{bit}
13182 \begin_inset LatexCommand \index{at}
13189 \begin_layout Standard
13190 The above example will allocate the variable at offset 0x02 in the bit-addressab
13192 There is no real advantage to assigning absolute addresses to variables
13193 in this manner, unless you want strict control over all the variables allocated.
13194 One possible use would be to write hardware portable code.
13195 For example, if you have a routine that uses one or more of the microcontroller
13196 I/O pins, and such pins are different for two different hardwares, you
13197 can declare the I/O pins in your routine using:
13200 \begin_layout Verse
13204 \begin_inset LatexCommand \index{volatile}
13208 __bit MOSI;\InsetSpace ~
13212 /* master out, slave in */
13214 extern volatile __bit MISO;\InsetSpace ~
13221 extern volatile __bit MCLK;\InsetSpace ~
13230 Output of a byte on a 3-wire serial bus.
13235 If needed adapt polarity of clock,
13236 polarity of data and bit order
13241 unsigned char spi_io(unsigned char out_byte)
13266 MOSI = out_byte & 0x80;
13297 /* _asm nop _endasm; */\InsetSpace ~
13305 /* for slow peripherals */
13357 \begin_layout Standard
13358 Then, someplace in the code for the first hardware you would use
13361 \begin_layout Verse
13365 \begin_inset LatexCommand \index{at}
13370 \begin_inset LatexCommand \index{\\_\\_at}
13374 (0x80) MOSI;\InsetSpace ~
13378 /* I/O port 0, bit 0 */
13380 __bit __at (0x81) MISO;\InsetSpace ~
13387 __bit __at (0x82) MCLK;\InsetSpace ~
13391 /* I/O port 0, bit 2 */
13394 \begin_layout Standard
13395 Similarly, for the second hardware you would use
13398 \begin_layout Verse
13401 __bit __at (0x83) MOSI;\InsetSpace ~
13405 /* I/O port 0, bit 3 */
13407 __bit __at (0x91) MISO;\InsetSpace ~
13412 I/O port 1, bit 1 */
13415 \begin_inset LatexCommand \index{bit}
13419 __at (0x92) MCLK;\InsetSpace ~
13423 /* I/O port 1, bit 2 */
13426 \begin_layout Standard
13427 and you can use the same hardware dependent routine without changes, as
13428 for example in a library.
13429 This is somehow similar to sbit, but only one absolute address has to be
13430 specified in the whole project.
13431 \begin_inset VSpace bigskip
13437 \begin_layout Section
13439 \begin_inset LatexCommand \index{Parameters}
13444 \begin_inset LatexCommand \index{function parameter}
13449 \begin_inset LatexCommand \index{local variables}
13454 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13461 \begin_layout Standard
13462 Automatic (local) variables and parameters to functions can either be placed
13463 on the stack or in data-space.
13464 The default action of the compiler is to place these variables in the internal
13465 RAM (for small model) or external RAM (for medium or large model).
13466 This in fact makes them similar to
13469 \begin_inset LatexCommand \index{static}
13475 so by default functions are non-reentrant
13476 \begin_inset LatexCommand \index{reentrant}
13485 They can be placed on the stack
13486 \begin_inset LatexCommand \index{stack}
13496 \begin_layout Standard
13506 \begin_inset LatexCommand \index{-\\/-stack-auto}
13514 #pragma\InsetSpace ~
13518 \begin_inset LatexCommand \index{\\#pragma stackauto}
13525 \begin_inset LatexCommand \index{reentrant}
13531 keyword in the function declaration, e.g.:
13534 \begin_layout Verse
13537 unsigned char foo(char i) __reentrant
13551 \begin_layout Standard
13552 Since stack space on 8051 is limited, the
13562 \begin_layout Standard
13573 option should be used sparingly.
13574 Note that the reentrant keyword just means that the parameters & local
13575 variables will be allocated to the stack, it
13579 mean that the function is register bank
13580 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13589 \begin_inset LatexCommand \index{local variables}
13593 can be assigned storage classes and absolute
13594 \begin_inset LatexCommand \index{Absolute addressing}
13601 \begin_layout Verse
13604 unsigned char foo()
13612 __xdata unsigned char i;
13625 \begin_inset LatexCommand \index{at}
13629 (0x31) unsigned char j;
13641 \begin_layout Standard
13642 In the above example the variable
13646 will be allocated in the external ram,
13650 in bit addressable space and
13661 \begin_layout Standard
13672 or when a function is declared as
13676 this should only be done for static variables.
13679 \begin_layout Standard
13681 \begin_inset LatexCommand \index{function parameter}
13685 however are not allowed any storage class
13686 \begin_inset LatexCommand \index{Storage class}
13690 , (storage classes for parameters will be ignored), their allocation is
13691 governed by the memory model in use, and the reentrancy options.
13694 \begin_layout Standard
13695 It is however allowed to use bit parameters in reentrant functions and also
13696 non-static local bit variables are supported.
13697 Efficient use is limited to 8 semi-bitregisters in bit space.
13698 They are pushed and popped to stack
13699 \begin_inset LatexCommand \index{stack}
13703 as a single byte just like the normal registers.
13706 \begin_layout Section
13708 \begin_inset LatexCommand \label{sub:Overlaying}
13713 \begin_inset LatexCommand \index{Overlaying}
13720 \begin_layout Standard
13722 \begin_inset LatexCommand \index{reentrant}
13726 functions SDCC will try to reduce internal ram space usage by overlaying
13727 parameters and local variables of a function (if possible).
13728 Parameters and local variables
13729 \begin_inset LatexCommand \index{local variables}
13733 of a function will be allocated to an overlayable segment if the function
13736 no other function calls and the function is non-reentrant and the memory
13738 \begin_inset LatexCommand \index{Memory model}
13745 If an explicit storage class
13746 \begin_inset LatexCommand \index{Storage class}
13750 is specified for a local variable, it will NOT be overlayed.
13753 \begin_layout Standard
13754 Note that the compiler (not the linkage editor) makes the decision for overlayin
13756 Functions that are called from an interrupt service routine
13757 \begin_inset Marginal
13760 \begin_layout Standard
13768 should be preceded by a #pragma\InsetSpace ~
13770 \begin_inset LatexCommand \index{\\#pragma nooverlay}
13774 if they are not reentrant.
13777 \begin_layout Standard
13778 Also note that the compiler does not do any processing of inline assembler
13779 code, so the compiler might incorrectly assign local variables and parameters
13780 of a function into the overlay segment if the inline assembler code calls
13781 other c-functions that might use the overlay.
13782 In that case the #pragma\InsetSpace ~
13783 nooverlay should be used.
13786 \begin_layout Standard
13787 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13789 \begin_inset LatexCommand \index{Multiplication}
13794 \begin_inset LatexCommand \index{Division}
13798 will NOT be overlayed since these are implemented using external functions,
13802 \begin_layout Verse
13808 \begin_inset LatexCommand \index{\\#pragma nooverlay}
13814 void set_error(unsigned char errcd)
13831 some_isr () __interrupt
13832 \begin_inset LatexCommand \index{interrupt}
13862 \begin_layout Standard
13863 In the above example the parameter
13871 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13873 not present, this could cause unpredictable runtime behavior when called
13874 from an interrupt service routine.
13875 The #pragma\InsetSpace ~
13876 nooverlay ensures that the parameters and local variables for
13877 the function are NOT overlayed.
13878 \begin_inset VSpace bigskip
13884 \begin_layout Section
13885 Interrupt Service Routines
13886 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13893 \begin_layout Subsection
13894 General Information
13897 \begin_layout Standard
13910 outines to be coded in C, with some extended keywords.
13913 \begin_layout Verse
13916 void timer_isr (void) __interrupt (1) __using (1)
13930 \begin_layout Standard
13931 The optional number following the
13934 \begin_inset LatexCommand \index{interrupt}
13939 \begin_inset LatexCommand \index{\\_\\_interrupt}
13945 keyword is the interrupt number this routine will service.
13946 When present, the compiler will insert a call to this routine in the interrupt
13948 \begin_inset LatexCommand \index{interrupt vector table}
13952 for the interrupt number specified.
13953 If you have multiple source files in your project, interrupt service routines
13954 can be present in any of them, but a prototype of the isr MUST be present
13955 or included in the file that contains the function
13960 The optional (8051 specific) keyword
13963 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13968 \begin_inset LatexCommand \index{\\_\\_using (mcs51, ds390 register bank)}
13974 can be used to tell the compiler to use the specified register bank when
13975 generating code for this function.
13978 Interrupt service routines open the door for some very interesting bugs:
13981 \begin_layout Subsubsection
13982 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
13986 Common interrupt pitfall: variable not declared
13991 \begin_layout Standard
13992 If an interrupt service routine changes variables which are accessed by
13993 other functions these variables have to be declared
13998 \begin_inset LatexCommand \index{volatile}
14004 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
14011 \begin_layout Subsubsection
14012 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
14016 Common interrupt pitfall:
14021 \begin_layout Standard
14022 If the access to these variables is not
14025 \begin_inset LatexCommand \index{atomic}
14032 the processor needs more than one instruction for the access and could
14033 be interrupted while accessing the variable) the interrupt must be disabled
14034 during the access to avoid inconsistent data.
14037 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
14038 and should be protected by disabling interrupts.
14039 You're not automatically on the safe side if you use 8 bit variables though.
14040 We need an example here: f.e.
14041 on the 8051 the harmless looking
14042 \begin_inset Quotes srd
14052 \begin_inset Quotes sld
14061 \begin_inset Quotes srd
14071 \begin_inset Quotes sld
14074 from within an interrupt routine might get lost if the interrupt occurs
14077 \begin_inset Quotes sld
14082 counter\InsetSpace ~
14087 \begin_inset Quotes srd
14090 is not atomic on the 8051 even if
14094 is located in data memory.
14096 Bugs like these are hard to reproduce and can
14097 cause a lot of trouble.
14101 \begin_layout Subsubsection
14102 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
14106 Common interrupt pitfall:
14111 \begin_layout Standard
14112 The return address and the registers used in the interrupt service routine
14113 are saved on the stack
14114 \begin_inset LatexCommand \index{stack}
14118 so there must be sufficient stack space.
14119 If there isn't variables or registers (or even the return address itself)
14126 \begin_inset LatexCommand \index{stack overflow}
14130 is most likely to happen if the interrupt occurs during the
14131 \begin_inset Quotes sld
14135 \begin_inset Quotes srd
14138 subroutine when the stack is already in use for f.e.
14139 many return addresses.
14142 \begin_layout Subsubsection
14143 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
14147 Common interrupt pitfall:
14149 use of non-reentrant functions
14152 \begin_layout Standard
14153 A special note here, int (16 bit) and long (32 bit) integer division
14154 \begin_inset LatexCommand \index{Division}
14159 \begin_inset LatexCommand \index{Multiplication}
14164 \begin_inset LatexCommand \index{Modulus}
14169 \begin_inset LatexCommand \index{Floating point support}
14173 operations are implemented using external support routines.
14174 If an interrupt service routine needs to do any of these operations then
14175 the support routines (as mentioned in a following section) will have to
14176 be recompiled using the
14182 \begin_layout Standard
14192 \begin_inset LatexCommand \index{-\\/-stack-auto}
14198 option and the source file will need to be compiled using the
14204 \begin_layout Standard
14216 \begin_inset LatexCommand \index{-\\/-int-long-reent}
14223 Note, the type promotion
14224 \begin_inset LatexCommand \index{type promotion}
14228 required by ANSI C can cause 16 bit routines to be used
14229 \begin_inset Marginal
14232 \begin_layout Standard
14241 without the programmer being aware of it.
14246 (unsigned char)(tail-1)
14251 within the if clause in section
14252 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
14259 \begin_layout Standard
14260 Calling other functions from an interrupt service routine is not recommended,
14261 avoid it if possible.
14262 Note that when some function is called from an interrupt service routine
14263 it should be preceded by a #pragma\InsetSpace ~
14265 \begin_inset LatexCommand \index{\\#pragma nooverlay}
14269 if it is not reentrant.
14270 Furthermore nonreentrant functions should not be called from the main program
14271 while the interrupt service routine might be active.
14272 They also must not be called from low priority interrupt service routines
14273 while a high priority interrupt service routine might be active.
14274 You could use semaphores or make the function
14278 if all parameters are passed in registers.
14281 \begin_inset LatexCommand \ref{sub:Overlaying}
14286 about Overlaying and section
14287 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14292 about Functions using private register banks.
14293 \begin_inset VSpace bigskip
14299 \begin_layout Subsection
14300 MCS51/DS390 Interrupt Service Routines
14303 \begin_layout Standard
14305 \begin_inset LatexCommand \index{interrupt}
14309 numbers and the corresponding address & descriptions for the Standard 8051/8052
14311 SDCC will automatically adjust the
14312 \begin_inset LatexCommand \index{interrupt vector table}
14316 to the maximum interrupt number specified.
14321 \begin_layout Standard
14323 \begin_inset Tabular
14324 <lyxtabular version="3" rows="9" columns="3">
14326 <column alignment="center" valignment="top" leftline="true" width="0in">
14327 <column alignment="left" valignment="top" leftline="true" width="0in">
14328 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14329 <row topline="true" bottomline="true">
14330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14333 \begin_layout Standard
14339 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14342 \begin_layout Standard
14348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14351 \begin_layout Standard
14358 <row topline="true">
14359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14362 \begin_layout Standard
14368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14371 \begin_layout Standard
14377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14380 \begin_layout Standard
14387 <row topline="true">
14388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14391 \begin_layout Standard
14397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14400 \begin_layout Standard
14406 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14409 \begin_layout Standard
14416 <row topline="true">
14417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14420 \begin_layout Standard
14426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14429 \begin_layout Standard
14435 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14438 \begin_layout Standard
14445 <row topline="true">
14446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14449 \begin_layout Standard
14455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14458 \begin_layout Standard
14464 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14467 \begin_layout Standard
14474 <row topline="true">
14475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14478 \begin_layout Standard
14484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14487 \begin_layout Standard
14493 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14496 \begin_layout Standard
14503 <row topline="true">
14504 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14507 \begin_layout Standard
14513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14516 \begin_layout Standard
14522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14525 \begin_layout Standard
14532 <row topline="true">
14533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14536 \begin_layout Standard
14542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14545 \begin_layout Standard
14551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14554 \begin_layout Standard
14561 <row topline="true" bottomline="true">
14562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14565 \begin_layout Standard
14571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14574 \begin_layout Standard
14580 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14583 \begin_layout Standard
14599 \begin_layout Standard
14600 If the interrupt service routine is defined without
14603 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14608 \begin_inset LatexCommand \index{\\_\\_using (mcs51, ds390 register bank)}
14614 a register bank or with register bank 0 (
14618 0), the compiler will save the registers used by itself on the stack upon
14619 entry and restore them at exit, however if such an interrupt service routine
14620 calls another function then the entire register bank will be saved on the
14622 This scheme may be advantageous for small interrupt service routines which
14623 have low register usage.
14626 \begin_layout Standard
14627 If the interrupt service routine is defined to be using a specific register
14632 & psw are saved and restored, if such an interrupt service routine calls
14633 another function (using another register bank) then the entire register
14634 bank of the called function will be saved on the stack
14635 \begin_inset LatexCommand \index{stack}
14640 This scheme is recommended for larger interrupt service routines.
14641 \begin_inset VSpace bigskip
14647 \begin_layout Subsection
14649 \begin_inset LatexCommand \index{HC08}
14653 Interrupt Service Routines
14656 \begin_layout Standard
14657 Since the number of interrupts
14658 \begin_inset LatexCommand \index{HC08!interrupt}
14662 available is chip specific and the interrupt vector table always ends at
14663 the last byte of memory, the interrupt numbers corresponds to the interrupt
14664 vectors in reverse order of address.
14665 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14666 2 will use the interrupt vector at 0xfffa, and so on.
14667 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14668 this way; instead see section
14669 \begin_inset LatexCommand \ref{sub:Startup-Code}
14673 for details on customizing startup.
14674 \begin_inset VSpace bigskip
14680 \begin_layout Subsection
14681 Z80 Interrupt Service Routines
14684 \begin_layout Standard
14686 \begin_inset LatexCommand \index{Z80}
14690 uses several different methods for determining the correct interrupt
14691 \begin_inset LatexCommand \index{Z80!interrupt}
14695 vector depending on the hardware implementation.
14696 Therefore, SDCC ignores the optional interrupt number and does not attempt
14697 to generate an interrupt vector table.
14700 \begin_layout Standard
14701 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14702 instruction to return from the interrupt.
14703 To write an interrupt handler for the non-maskable interrupt, which needs
14704 a RETN instruction instead, add the
14711 \begin_layout Verse
14714 void nmi_isr (void) critical interrupt
14728 \begin_layout Standard
14729 However if you need to create a non-interruptable interrupt service routine
14730 you would also require the
14735 To distinguish between this and an nmi_isr you must provide an interrupt
14737 \begin_inset VSpace bigskip
14743 \begin_layout Section
14744 Enabling and Disabling Interrupts
14747 \begin_layout Subsection
14748 Critical Functions and Critical Statements
14751 \begin_layout Standard
14752 A special keyword may be associated with a block or a function declaring
14758 SDCC will generate code to disable all interrupts
14759 \begin_inset LatexCommand \index{interrupt}
14763 upon entry to a critical function and restore the interrupt enable to the
14764 previous state before returning.
14765 Nesting critical functions will need one additional byte on the stack
14766 \begin_inset LatexCommand \index{stack}
14773 \begin_layout Verse
14776 int foo () __critical
14777 \begin_inset LatexCommand \index{critical}
14782 \begin_inset LatexCommand \index{\\_\\_critical}
14807 \begin_layout Standard
14808 The critical attribute maybe used with other attributes like
14818 may also be used to disable interrupts more locally:
14821 \begin_layout Verse
14827 \begin_layout Standard
14828 More than one statement could have been included in the block.
14831 \begin_layout Subsection
14832 Enabling and Disabling Interrupts directly
14835 \begin_layout Standard
14837 \begin_inset LatexCommand \index{interrupt}
14841 can also be disabled and enabled directly (8051):
14844 \begin_layout Verse
14847 EA = 0;\InsetSpace ~
14873 \begin_layout Verse
14909 \begin_layout Verse
14912 EA = 1;\InsetSpace ~
14941 \begin_layout Verse
14980 \begin_layout Standard
14981 On other architectures which have seperate opcodes for enabling and disabling
14982 interrupts you might want to make use of defines with inline assembly
14983 \begin_inset LatexCommand \index{Assembler routines}
14988 \begin_inset LatexCommand \index{HC08!interrupt}
14995 \begin_layout Verse
14999 \begin_inset LatexCommand \index{\\_asm}
15008 \begin_inset LatexCommand \index{\\_endasm}
15015 \begin_layout Verse
15018 #define SEI _asm\InsetSpace ~
15025 \begin_layout Verse
15031 \begin_layout Standard
15032 Note: it is sometimes sufficient to disable only a specific interrupt source
15034 a timer or serial interrupt by manipulating an
15037 \begin_inset LatexCommand \index{interrupt mask}
15047 \begin_layout Standard
15048 Usually the time during which interrupts are disabled should be kept as
15050 This minimizes both
15055 \begin_inset LatexCommand \index{interrupt latency}
15059 (the time between the occurrence of the interrupt and the execution of
15060 the first code in the interrupt routine) and
15065 \begin_inset LatexCommand \index{interrupt jitter}
15069 (the difference between the shortest and the longest interrupt latency).
15070 These really are something different, f.e.
15071 a serial interrupt has to be served before its buffer overruns so it cares
15072 for the maximum interrupt latency, whereas it does not care about jitter.
15073 On a loudspeaker driven via a digital to analog converter which is fed
15074 by an interrupt a latency of a few milliseconds might be tolerable, whereas
15075 a much smaller jitter will be very audible.
15078 \begin_layout Standard
15079 You can reenable interrupts within an interrupt routine and on some architecture
15080 s you can make use of two (or more) levels of
15082 interrupt priorities
15085 \begin_inset LatexCommand \index{interrupt priority}
15090 On some architectures which don't support interrupt priorities these can
15091 be implemented by manipulating the interrupt mask and reenabling interrupts
15092 within the interrupt routine.
15093 Check there is sufficient space on the stack
15094 \begin_inset LatexCommand \index{stack}
15098 and don't add complexity unless you have to.
15102 \begin_layout Subsection
15104 \begin_inset LatexCommand \index{semaphore}
15108 locking (mcs51/ds390)
15111 \begin_layout Standard
15112 Some architectures (mcs51/ds390) have an atomic
15113 \begin_inset LatexCommand \index{atomic}
15117 bit test and clear instruction.
15118 These type of instructions are typically used in preemptive multitasking
15119 systems, where a routine f.e.
15120 claims the use of a data structure ('acquires a lock
15121 \begin_inset LatexCommand \index{lock}
15125 on it'), makes some modifications and then releases the lock when the data
15126 structure is consistent again.
15127 The instruction may also be used if interrupt and non-interrupt code have
15128 to compete for a resource.
15129 With the atomic bit test and clear instruction interrupts
15130 \begin_inset LatexCommand \index{interrupt}
15134 don't have to be disabled for the locking operation.
15138 \begin_layout Standard
15139 SDCC generates this instruction if the source follows this pattern:
15142 \begin_layout Verse
15146 \begin_inset LatexCommand \index{volatile}
15150 bit resource_is_free;
15154 if (resource_is_free)
15164 resource_is_free=0;
15177 resource_is_free=1;
15184 \begin_layout Standard
15185 Note, mcs51 and ds390 support only an atomic
15186 \begin_inset LatexCommand \index{atomic}
15194 instruction (as opposed to atomic bit test and
15199 \begin_layout Section
15200 Functions using private register banks
15201 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
15208 \begin_layout Standard
15209 Some architectures have support for quickly changing register sets.
15210 SDCC supports this feature with the
15213 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
15218 \begin_inset LatexCommand \index{\\_\\_using (mcs51, ds390 register bank)}
15224 attribute (which tells the compiler to use a register bank
15225 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
15229 other than the default bank zero).
15230 It should only be applied to
15233 \begin_inset LatexCommand \index{interrupt}
15239 functions (see footnote below).
15240 This will in most circumstances make the generated ISR code more efficient
15241 since it will not have to save registers on the stack.
15244 \begin_layout Standard
15249 attribute will have no effect on the generated code for a
15253 function (but may occasionally be useful anyway
15257 \begin_layout Standard
15258 possible exception: if a function is called ONLY from 'interrupt' functions
15259 using a particular bank, it can be declared with the same 'using' attribute
15260 as the calling 'interrupt' functions.
15261 For instance, if you have several ISRs using bank one, and all of them
15262 call memcpy(), it might make sense to create a specialized version of memcpy()
15263 'using 1', since this would prevent the ISR from having to save bank zero
15264 to the stack on entry and switch to bank zero before calling the function
15273 (pending: Note, nowadays the
15277 attribute has an effect on
15281 the generated code for a
15292 \begin_layout Standard
15297 function using a non-zero bank will assume that it can trash that register
15298 bank, and will not save it.
15299 Since high-priority interrupts
15300 \begin_inset LatexCommand \index{interrupts}
15305 \begin_inset LatexCommand \index{interrupt priority}
15309 can interrupt low-priority ones on the 8051 and friends, this means that
15310 if a high-priority ISR
15314 a particular bank occurs while processing a low-priority ISR
15318 the same bank, terrible and bad things can happen.
15319 To prevent this, no single register bank should be
15323 by both a high priority and a low priority ISR.
15324 This is probably most easily done by having all high priority ISRs use
15325 one bank and all low priority ISRs use another.
15326 If you have an ISR which can change priority at runtime, you're on your
15327 own: I suggest using the default bank zero and taking the small performance
15331 \begin_layout Standard
15332 It is most efficient if your ISR calls no other functions.
15333 If your ISR must call other functions, it is most efficient if those functions
15334 use the same bank as the ISR (see note 1 below); the next best is if the
15335 called functions use bank zero.
15336 It is very inefficient to call a function using a different, non-zero bank
15339 \begin_inset VSpace bigskip
15345 \begin_layout Section
15347 \begin_inset LatexCommand \label{sub:Startup-Code}
15352 \begin_inset LatexCommand \index{Startup code}
15359 \begin_layout Subsection
15360 MCS51/DS390 Startup Code
15363 \begin_layout Standard
15364 The compiler triggers the linker to link certain initialization modules
15365 from the runtime library
15366 \begin_inset LatexCommand \index{Runtime library}
15370 called crt<something>.
15371 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15372 GSINIT5) is not linked unless the -
15378 \begin_layout Standard
15389 -xstack option is used.
15390 These modules are highly entangled by the use of special segments/areas,
15391 but a common layout is shown below:
15394 \begin_layout Verse
15402 \begin_layout Verse
15426 ljmp __sdcc_gsinit_startup
15429 \begin_layout Verse
15437 \begin_layout Verse
15449 .area GSINIT0 (CODE)
15451 __sdcc_gsinit_startup::
15461 mov sp,#__start__stack - 1
15464 \begin_layout Verse
15472 \begin_layout Verse
15484 .area GSINIT1 (CODE)
15486 __sdcc_init_xstack::
15488 ; Need to initialize in GSINIT1 in
15489 case the user's __sdcc_external_startup uses the xstack.
15499 mov __XPAGE,#(__start__x
15510 mov _spx,#__start__xstack
15513 \begin_layout Verse
15521 \begin_layout Verse
15533 .area GSINIT2 (CODE)
15543 lcall __sdcc_external_startup
15563 jz __sdcc_init_data
15574 __sdcc_program_startup
15579 \begin_layout Verse
15587 \begin_layout Verse
15599 .area GSINIT3 (CODE)
15652 mov r2,#((l_XINIT+255) >> 8)
15683 __XPAGE,#(s_XISEG >> 8)
15685 00001$:\InsetSpace ~
15749 00002$:\InsetSpace ~
15776 \begin_layout Verse
15784 \begin_layout Verse
15796 .area GSINIT4 (CODE)
15798 __mcs51_genRAMCLEAR::
15820 00004$:\InsetSpace ~
15834 ; _mcs51_genRAMCLEAR() end
15837 \begin_layout Verse
15845 \begin_layout Verse
15857 .area GSINIT4 (CODE)
15859 __mcs51_genXRAMCLEAR::
15910 mov __XPAGE,#(s_PSEG >> 8)
15922 00005$:\InsetSpace ~
15976 orl a,#(l_XSEG >> 8)
16019 00007$:\InsetSpace ~
16056 \begin_layout Verse
16064 \begin_layout Verse
16076 .area GSINIT5 (CODE)
16078 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
16081 ; and __mcs51_genRAMCLEAR modifies _spx.
16091 mov __XPAGE,#(__start__x
16102 mov _spx,#__start__xstack
16105 \begin_layout Verse
16110 (application modules)
16113 \begin_layout Verse
16125 .area GSINIT (CODE)
16128 \begin_layout Verse
16136 \begin_layout Verse
16148 .area GSFINAL (CODE)
16158 ljmp __sdcc_program_startup
16160 ;---------------------------------
16161 -----------------------
16165 ;--------------------------------------------------
16188 __sdcc_program_startup:
16201 return from main will lock up
16214 \begin_layout Standard
16215 One of these modules (crtstart.asm) contains a call to the C routine
16217 _sdcc_external_startup()
16218 \begin_inset LatexCommand \index{\\_sdcc\\_external\\_startup()}
16224 at the start of the CODE area.
16225 This routine is also in the runtime library
16226 \begin_inset LatexCommand \index{Runtime library}
16230 and returns 0 by default.
16231 If this routine returns a non-zero value, the static & global variable
16232 initialization will be skipped and the function main will be invoked.
16233 Otherwise static & global variables will be initialized before the function
16237 _sdcc_external_startup()
16239 routine to your program to override the default if you need to setup hardware
16240 or perform some other critical operation prior to static & global variable
16242 \begin_inset LatexCommand \index{Variable initialization}
16247 On some mcs51 variants xdata
16248 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
16252 memory has to be explicitly enabled before it can be accessed or if the
16254 \begin_inset LatexCommand \index{watchdog}
16258 needs to be disabled, this is the place to do it.
16259 The startup code clears all internal data memory, 256 bytes by default,
16260 but from 0 to n-1 if
16266 \begin_layout Standard
16276 \begin_inset LatexCommand \index{-\\/-iram-size <Value>}
16283 (recommended for Chipcon CC1010).
16286 \begin_layout Standard
16287 See also the compiler options
16293 \begin_layout Standard
16309 \begin_inset LatexCommand \index{-\\/-no-xinit-opt}
16319 \begin_layout Standard
16331 \begin_inset LatexCommand \index{-\\/-main-return}
16336 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16340 about MCS51-variants.
16341 \begin_inset VSpace bigskip
16347 \begin_layout Subsection
16351 \begin_layout Standard
16353 \begin_inset LatexCommand \index{HC08}
16357 startup code follows the same scheme as the MCS51 startup code.
16358 \begin_inset VSpace bigskip
16364 \begin_layout Subsection
16368 \begin_layout Standard
16370 \begin_inset LatexCommand \index{Z80}
16374 the startup code is inserted by linking with crt0.o which is generated from
16375 sdcc/device/lib/z80/crt0.s.
16376 If you need a different startup code you can use the compiler option
16385 \begin_layout Standard
16400 \begin_inset LatexCommand \index{-\\/-no-std-crt0}
16404 and provide your own crt0.o.
16406 \begin_inset VSpace bigskip
16412 \begin_layout Section
16413 Inline Assembler Code
16414 \begin_inset LatexCommand \index{Assembler routines}
16421 \begin_layout Subsection
16422 A Step by Step Introduction
16423 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16430 \begin_layout Standard
16431 Starting from a small snippet of c-code this example shows for the MCS51
16432 how to use inline assembly, access variables, a function parameter and
16433 an array in xdata memory.
16434 The example uses an MCS51 here but is easily adapted for other architectures.
16435 This is a buffer routine which should be optimized:
16438 \begin_layout Verse
16442 unsigned char __far
16443 \begin_inset LatexCommand \index{far (storage class)}
16448 \begin_inset LatexCommand \index{\\_\\_far (storage class)}
16453 \begin_inset LatexCommand \index{at}
16458 \begin_inset LatexCommand \index{\\_\\_at}
16462 (0x7f00) buf[0x100];
16463 \begin_inset LatexCommand \index{Aligned array}
16469 unsigned char head, tail;\InsetSpace ~
16487 \begin_inset LatexCommand \index{interrupt}
16539 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16557 void to_buffer( unsigned char c )
16565 if( head != (unsigned char)(tail-1)
16578 \begin_inset LatexCommand \index{promotion to signed int}
16583 \begin_inset LatexCommand \index{type promotion}
16588 \begin_inset Marginal
16591 \begin_layout Standard
16610 buf[ head++ ] = c;\InsetSpace ~
16626 /* access to a 256 byte aligned array */
16631 \begin_layout Standard
16632 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16633 then a corresponding buffer.asm file is generated.
16634 We define a new function
16638 in file buffer.c in which we cut and paste the generated code, removing
16639 unwanted comments and some ':'.
16641 \begin_inset Quotes sld
16649 \begin_inset Quotes srd
16653 \begin_inset Quotes sld
16661 \begin_inset Quotes srd
16668 \begin_layout Standard
16669 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16670 and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16672 The latter is also used in the library functions.
16677 to the beginning and the end of the function body:
16680 \begin_layout Verse
16684 /* With a cut and paste from the .asm file, we have something to start with.
16690 function is not yet OK! (registers aren't saved) */
16692 void to_buffer_asm(
16702 \begin_inset LatexCommand \index{\\_asm}
16707 \begin_inset LatexCommand \index{\\_\\_asm}
16721 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16733 \begin_inset LatexCommand \index{promotion to signed int}
16738 \begin_inset LatexCommand \index{type promotion}
16791 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
16792 \begin_inset LatexCommand \index{Aligned array}
16858 \begin_inset LatexCommand \index{\\_endasm}
16863 \begin_inset LatexCommand \index{\\_\\_endasm}
16872 \begin_layout Standard
16873 The new file buffer.c should compile with only one warning about the unreferenced
16874 function argument 'c'.
16875 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
16876 (1) and finally have:
16879 \begin_layout Verse
16883 unsigned char __far __at(0x7f00) buf[0x100];
16885 unsigned char head, tail;
16896 void to_buffer( unsigned char c )
16905 head != (unsigned char)(tail-1) )
16934 c; // to avoid warning: unreferenced function argument
16941 \begin_inset LatexCommand \index{\\_asm}
16946 \begin_inset LatexCommand \index{\\_\\_asm}
16960 ; save used registers here.
16971 ; If we were still using r2,r3 we would have to push them here.
16974 ; if( head != (unsigned char)(tail-1) )
17018 could do an ANL a,#0x0f here to use a smaller buffer (see below)
17054 a,dpl \InsetSpace ~
17061 ; dpl holds lower byte of function argument
17073 dpl,_head \InsetSpace ~
17076 ; buf is 0x100 byte aligned so head can be used directly
17119 ; we could do an ANL _head,#0x0f here to use a
17120 smaller buffer (see above)
17132 ; restore used registers here
17139 \begin_inset LatexCommand \index{\\_endasm}
17144 \begin_inset LatexCommand \index{\\_\\_endasm}
17155 \begin_layout Standard
17156 The inline assembler code can contain any valid code understood by the assembler
17157 , this includes any assembler directives and comment lines.
17158 The assembler does not like some characters like ':' or ''' in comments.
17159 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
17160 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
17165 \begin_inset LatexCommand \index{Assembler documentation}
17170 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
17178 \begin_layout Standard
17179 The compiler does not do any validation of the code within the
17182 \begin_inset LatexCommand \index{\\_asm}
17187 \begin_inset LatexCommand \index{\\_\\_asm}
17195 \begin_inset LatexCommand \index{\\_endasm}
17200 \begin_inset LatexCommand \index{\\_\\_endasm}
17209 Specifically it will not know which registers are used and thus register
17211 \begin_inset LatexCommand \index{push/pop}
17215 has to be done manually.
17219 \begin_layout Standard
17220 It is recommended that each assembly instruction (including labels) be placed
17221 in a separate line (as the example shows).
17226 \begin_layout Standard
17238 \begin_inset LatexCommand \index{-\\/-peep-asm}
17244 command line option is used, the inline assembler code will be passed through
17245 the peephole optimizer
17246 \begin_inset LatexCommand \index{Peephole optimizer}
17251 There are only a few (if any) cases where this option makes sense, it might
17252 cause some unexpected changes in the inline assembler code.
17253 Please go through the peephole optimizer rules defined in file
17257 before using this option.
17260 \begin_layout Subsection
17262 \begin_inset LatexCommand \label{sub:Naked-Functions}
17267 \begin_inset LatexCommand \index{Naked functions}
17274 \begin_layout Standard
17275 A special keyword may be associated with a function declaring it as
17278 \begin_inset LatexCommand \index{\\_naked}
17283 \begin_inset LatexCommand \index{\\_\\_naked}
17294 function modifier attribute prevents the compiler from generating prologue
17295 \begin_inset LatexCommand \index{function prologue}
17300 \begin_inset LatexCommand \index{function epilogue}
17304 code for that function.
17305 This means that the user is entirely responsible for such things as saving
17306 any registers that may need to be preserved, selecting the proper register
17307 bank, generating the
17311 instruction at the end, etc.
17312 Practically, this means that the contents of the function must be written
17313 in inline assembler.
17314 This is particularly useful for interrupt functions, which can have a large
17315 (and often unnecessary) prologue/epilogue.
17316 For example, compare the code generated by these two functions:
17319 \begin_layout Verse
17323 \begin_inset LatexCommand \index{volatile}
17327 data unsigned char counter;
17331 void simpleInterrupt(void) __interrupt
17332 \begin_inset LatexCommand \index{interrupt}
17337 \begin_inset LatexCommand \index{\\_\\_interrupt}
17355 void nakedInterrupt(void) __interrupt (2) __naked
17364 \begin_inset LatexCommand \index{\\_asm}
17369 \begin_inset LatexCommand \index{\\_\\_asm}
17386 _counter ; does not change flags, no need to save psw
17399 include ret or reti in _naked function.
17406 \begin_inset LatexCommand \index{\\_endasm}
17411 \begin_inset LatexCommand \index{\\_\\_endasm}
17420 \begin_layout Standard
17421 For an 8051 target, the generated simpleInterrupt looks like:
17424 \begin_layout Verse
17437 example, recent versions of SDCC generate
17449 code for simpleInterrupt() and nakedInterrupt()!
17590 \begin_layout Standard
17591 whereas nakedInterrupt looks like:
17594 \begin_layout Verse
17607 _counter ; does not change flags, no need to save psw
17626 MUST explicitly include ret or reti in _naked function
17629 \begin_layout Standard
17630 The related directive #pragma exclude
17631 \begin_inset LatexCommand \index{\\#pragma exclude}
17635 allows a more fine grained control over pushing & popping
17636 \begin_inset LatexCommand \index{push/pop}
17643 \begin_layout Standard
17644 While there is nothing preventing you from writing C code inside a
17648 function, there are many ways to shoot yourself in the foot doing this,
17649 and it is recommended that you stick to inline assembler.
17652 \begin_layout Subsection
17653 Use of Labels within Inline Assembler
17656 \begin_layout Standard
17657 SDCC allows the use of in-line assembler with a few restrictions regarding
17659 All labels defined within inline assembler code have to be of the form
17664 where nnnnn is a number less than 100 (which implies a limit of utmost
17665 100 inline assembler labels
17676 \begin_layout Standard
17677 This is a slightly more stringent rule than absolutely necessary, but stays
17678 always on the safe side.
17679 Labels in the form of nnnnn$ are local labels in the assembler, locality
17680 of which is confined within two labels of the standard form.
17681 The compiler uses the same form for labels within a function (but starting
17682 from nnnnn=00100); and places always a standard label at the beginning
17683 of a function, thus limiting the locality of labels within the scope of
17685 So, if the inline assembler part would be embedded into C-code, an improperly
17686 placed non-local label in the assembler would break up the reference space
17687 for labels created by the compiler for the C-code, leading to an assembling
17691 \begin_layout Standard
17692 The numeric part of local labels does not need to have 5 digits (although
17693 this is the form of labels output by the compiler), any valid integer will
17695 Please refer to the assemblers documentation for further details.
17703 \begin_layout Verse
17707 \begin_inset LatexCommand \index{\\_asm}
17712 \begin_inset LatexCommand \index{\\_\\_asm}
17742 \begin_inset LatexCommand \index{\\_endasm}
17747 \begin_inset LatexCommand \index{\\_\\_endasm}
17754 \begin_layout Standard
17755 Inline assembler code cannot reference any C-labels, however it can reference
17757 \begin_inset LatexCommand \index{Labels}
17761 defined by the inline assembler, e.g.:
17764 \begin_layout Verse
17787 ; some assembler code
17808 /* some more c code */
17810 clabel:\InsetSpace ~
17812 /* inline assembler cannot reference this
17817 \begin_layout Standard
17822 is translated by the compiler into a local label, so the locality of labels
17823 within the function is not broken.
17840 0003$: ;label (can be referenced by inline assembler only)
17847 \begin_inset LatexCommand \index{\\_endasm}
17852 \begin_inset LatexCommand \index{\\_\\_endasm}
17862 /* some more c code */
17867 \begin_layout Standard
17868 In other words inline assembly code can access labels defined in inline
17869 assembly within the scope of the function.
17870 The same goes the other way, i.e.
17871 labels defines in inline assembly can not be accessed by C statements.
17874 \begin_layout Section
17875 Interfacing with Assembler Code
17876 \begin_inset LatexCommand \index{Assembler routines}
17883 \begin_layout Subsection
17884 Global Registers used for Parameter Passing
17885 \begin_inset LatexCommand \index{Parameter passing}
17892 \begin_layout Standard
17893 The compiler always uses the global registers
17896 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17901 \begin_inset LatexCommand \index{DPTR}
17906 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
17915 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
17921 to pass the first (non-bit) parameter to a function, and also to pass the
17923 \begin_inset LatexCommand \index{return value}
17927 of function; according to the following scheme: one byte return value in
17932 , two byte value in
17941 three byte values (generic pointers) in
17953 , and four byte values in
17971 \begin_inset LatexCommand \index{generic pointer}
17975 contain type of accessed memory in
17996 \begin_inset Note Note
17999 \begin_layout Standard
18000 This might not be the case of certain memory models (medium???)
18008 \begin_layout Standard
18009 The second parameter onwards is either allocated on the stack (for reentrant
18014 \begin_layout Standard
18023 -stack-auto is used) or in data/xdata memory (depending on the memory model).
18026 \begin_layout Standard
18027 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
18028 space for reentrant functions or allocated directly in bit memory otherwise.
18031 \begin_layout Standard
18032 Functions (with two or more parameters or bit parameters) that are called
18033 through function pointers
18034 \begin_inset LatexCommand \index{function pointers}
18038 must therefor be reentrant so the compiler knows how to pass the parameters.
18041 \begin_layout Subsection
18045 \begin_layout Standard
18046 Unless the called function is declared as
18051 \begin_inset LatexCommand \index{naked}
18059 \begin_layout Standard
18069 \begin_inset LatexCommand \index{-\\/-callee-saves}
18077 \begin_layout Standard
18086 -all-callee-saves command line option or the corresponding callee_saves
18087 pragma are used, the caller will save the registers (
18091 ) around the call, so the called function can destroy they content freely.
18094 \begin_layout Standard
18095 If the called function is not declared as
18099 , the caller will swap register banks around the call, if caller and callee
18100 use different register banks (having them defined by the
18108 \begin_layout Standard
18109 The called function can also use
18125 observing that they are used for parameter/return value passing.
18128 \begin_layout Subsection
18129 Assembler Routine (non-reentrant)
18132 \begin_layout Standard
18133 In the following example
18134 \begin_inset LatexCommand \index{reentrant}
18139 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
18143 the function c_func calls an assembler routine asm_func, which takes two
18145 \begin_inset LatexCommand \index{function parameter}
18152 \begin_layout Verse
18155 extern int asm_func(unsigned char, unsigned char);
18159 int c_func (unsigned char
18160 i, unsigned char j)
18168 return asm_func(i,j);
18182 return c_func(10,9);
18187 \begin_layout Standard
18188 The corresponding assembler function is:
18191 \begin_layout Verse
18194 .globl _asm_func_PARM_2
18296 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18313 \begin_layout Standard
18314 The parameter naming convention is _<function_name>_PARM_<n>, where n is
18315 the parameter number starting from 1, and counting from the left.
18316 The first parameter is passed in
18332 according to the description above.
18333 The variable name for the second parameter will be _<function_name>_PARM_2.
18338 ble the assembler routine with the following command:
18345 asx8051 -losg asmfunc.asm
18352 Then compile and link the assembler routine to the C source file with the
18360 sdcc cfunc.c asmfunc.rel
18363 \begin_layout Subsection
18364 Assembler Routine (reentrant)
18367 \begin_layout Standard
18369 \begin_inset LatexCommand \index{reentrant}
18374 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18378 the second parameter
18379 \begin_inset LatexCommand \index{function parameter}
18383 onwards will be passed on the stack, the parameters are pushed from right
18385 before the call the second leftmost parameter will be on the top of the
18386 stack (the leftmost parameter is passed in registers).
18387 Here is an example:
18390 \begin_layout Verse
18393 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18398 c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
18407 return asm_func(i,j,k);
18421 return c_func(10,9,8);
18426 \begin_layout Standard
18427 The corresponding (unoptimized) assembler routine is:
18430 \begin_layout Verse
18450 _bp,sp\InsetSpace ~
18456 ;stack contains: _bp, return
18457 address, second parameter, third parameter
18481 a,#0xfd\InsetSpace ~
18487 pointer to the second parameter
18511 a,#0xfc\InsetSpace ~
18517 to the rightmost parameter
18558 result (= sum of all three parameters)
18573 ;return value goes into dptr
18607 \begin_layout Standard
18608 The compiling and linking procedure remains the same, however note the extra
18609 entry & exit linkage required for the assembler code, _bp is the stack
18610 frame pointer and is used to compute the offset into the stack for parameters
18611 and local variables.
18612 \begin_inset VSpace bigskip
18618 \begin_layout Section
18620 \begin_inset LatexCommand \index{int (16 bit)}
18625 \begin_inset LatexCommand \index{long (32 bit)}
18632 \begin_layout Standard
18633 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18634 multiplication and modulus operations are implemented by support routines.
18635 These support routines are all developed in ANSI-C to facilitate porting
18636 to other MCUs, although some model specific assembler optimizations are
18638 The following files contain the described routines, all of them can be
18639 found in <installdir>/share/sdcc/lib.
18644 \begin_layout Standard
18646 \begin_inset Tabular
18647 <lyxtabular version="3" rows="11" columns="2">
18649 <column alignment="left" valignment="top" leftline="true" width="0">
18650 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18651 <row topline="true" bottomline="true">
18652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18655 \begin_layout Standard
18663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18666 \begin_layout Standard
18675 <row topline="true">
18676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18679 \begin_layout Standard
18685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18688 \begin_layout Standard
18689 16 bit multiplication
18695 <row topline="true">
18696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18699 \begin_layout Standard
18705 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18708 \begin_layout Standard
18709 signed 16 bit division (calls _divuint)
18715 <row topline="true">
18716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18719 \begin_layout Standard
18725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18728 \begin_layout Standard
18729 unsigned 16 bit division
18735 <row topline="true">
18736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18739 \begin_layout Standard
18745 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18748 \begin_layout Standard
18749 signed 16 bit modulus (calls _moduint)
18755 <row topline="true">
18756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18759 \begin_layout Standard
18765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18768 \begin_layout Standard
18769 unsigned 16 bit modulus
18775 <row topline="true">
18776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18779 \begin_layout Standard
18785 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18788 \begin_layout Standard
18789 32 bit multiplication
18795 <row topline="true">
18796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18799 \begin_layout Standard
18805 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18808 \begin_layout Standard
18809 signed 32 division (calls _divulong)
18815 <row topline="true">
18816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18819 \begin_layout Standard
18825 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18828 \begin_layout Standard
18829 unsigned 32 division
18835 <row topline="true">
18836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18839 \begin_layout Standard
18845 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18848 \begin_layout Standard
18849 signed 32 bit modulus (calls _modulong)
18855 <row topline="true" bottomline="true">
18856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18859 \begin_layout Standard
18865 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18868 \begin_layout Standard
18869 unsigned 32 bit modulus
18884 \begin_layout Standard
18885 Since they are compiled as
18890 \begin_inset LatexCommand \index{reentrant}
18895 \begin_inset LatexCommand \index{interrupt}
18899 service routines should not do any of the above operations.
18900 If this is unavoidable then the above routines will need to be compiled
18907 \begin_layout Standard
18917 \begin_inset LatexCommand \index{-\\/-stack-auto}
18923 option, after which the source program will have to be compiled with
18929 \begin_layout Standard
18939 \begin_inset LatexCommand \index{-\\/-int-long-reent}
18946 Notice that you don't have to call these routines directly.
18947 The compiler will use them automatically every time an integer operation
18951 \begin_layout Section
18952 Floating Point Support
18953 \begin_inset LatexCommand \index{Floating point support}
18960 \begin_layout Standard
18961 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
18962 The floating point support routines are derived from gcc's floatlib.c and
18963 consist of the following routines:
18968 \begin_layout Standard
18972 \begin_inset Tabular
18973 <lyxtabular version="3" rows="17" columns="2">
18975 <column alignment="left" valignment="top" leftline="true" width="0">
18976 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18977 <row topline="true" bottomline="true">
18978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18981 \begin_layout Standard
18996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18999 \begin_layout Standard
19006 <row topline="true">
19007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19010 \begin_layout Standard
19025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19028 \begin_layout Standard
19038 add floating point numbers
19044 <row topline="true">
19045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19048 \begin_layout Standard
19063 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19066 \begin_layout Standard
19076 subtract floating point numbers
19082 <row topline="true">
19083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19086 \begin_layout Standard
19101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19104 \begin_layout Standard
19114 divide floating point numbers
19120 <row topline="true">
19121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19124 \begin_layout Standard
19139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19142 \begin_layout Standard
19152 multiply floating point numbers
19158 <row topline="true">
19159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19162 \begin_layout Standard
19177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19180 \begin_layout Standard
19190 convert floating point to unsigned char
19196 <row topline="true">
19197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19200 \begin_layout Standard
19215 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19218 \begin_layout Standard
19228 convert floating point to signed char
19234 <row topline="true">
19235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19238 \begin_layout Standard
19253 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19256 \begin_layout Standard
19266 convert floating point to unsigned int
19272 <row topline="true">
19273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19276 \begin_layout Standard
19291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19294 \begin_layout Standard
19304 convert floating point to signed int
19310 <row topline="true">
19311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19314 \begin_layout Standard
19337 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19340 \begin_layout Standard
19350 convert floating point to unsigned long
19356 <row topline="true">
19357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19360 \begin_layout Standard
19375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19378 \begin_layout Standard
19388 convert floating point to signed long
19394 <row topline="true">
19395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19398 \begin_layout Standard
19413 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19416 \begin_layout Standard
19426 convert unsigned char to floating point
19432 <row topline="true">
19433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19436 \begin_layout Standard
19451 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19454 \begin_layout Standard
19464 convert char to floating point number
19470 <row topline="true">
19471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19474 \begin_layout Standard
19489 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19492 \begin_layout Standard
19502 convert unsigned int to floating point
19508 <row topline="true">
19509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19512 \begin_layout Standard
19527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19530 \begin_layout Standard
19540 convert int to floating point numbers
19546 <row topline="true">
19547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19550 \begin_layout Standard
19565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19568 \begin_layout Standard
19578 convert unsigned long to floating point number
19584 <row topline="true" bottomline="true">
19585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19588 \begin_layout Standard
19603 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19606 \begin_layout Standard
19616 convert long to floating point number
19631 \begin_layout Standard
19632 These support routines are developed in ANSI-C so there is room for space
19633 and speed improvement
19637 \begin_layout Standard
19638 These floating point routines (
19642 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19649 Note if all these routines are used simultaneously the data space might
19651 For serious floating point usage the large model might be needed.
19652 Also notice that you don't have to call this routines directly.
19653 The compiler will use them automatically every time a floating point operation
19655 \begin_inset VSpace bigskip
19661 \begin_layout Section
19663 \begin_inset LatexCommand \index{Libraries}
19670 \begin_layout Standard
19673 <pending: this is messy and incomplete - a little more information is in
19674 sdcc/doc/libdoc.txt
19679 \begin_layout Subsection
19680 Compiler support routines (_gptrget, _mulint etc.)
19683 \begin_layout Subsection
19684 Stdclib functions (puts, printf, strcat etc.)
19687 \begin_layout Subsubsection
19691 \begin_layout Paragraph
19692 getchar(), putchar()
19695 \begin_layout Standard
19696 \begin_inset LatexCommand \index{<stdio.h>}
19700 As usual on embedded systems you have to provide your own
19703 \begin_inset LatexCommand \index{getchar()}
19712 \begin_inset LatexCommand \index{putchar()}
19719 SDCC does not know whether the system connects to a serial line with or
19720 without handshake, LCD, keyboard or other device.
19734 You'll find examples for serial routines f.e.
19735 in sdcc/device/lib.
19736 For the mcs51 this minimalistic polling
19740 routine might be a start:
19743 \begin_layout Verse
19746 void putchar (char c) {
19752 while (!TI)\InsetSpace ~
19755 /* assumes UART is initialized */
19783 \begin_layout Paragraph
19787 \begin_layout Standard
19791 \begin_inset LatexCommand \index{printf()}
19801 does not support float (except on ds390).
19802 To enable this recompile it with the option
19808 \begin_layout Standard
19818 \begin_inset LatexCommand \index{USE\\_FLOATS}
19824 on the command line.
19831 \begin_layout Standard
19841 \begin_inset LatexCommand \index{-\\/-model-large}
19847 for the mcs51 port, since this uses a lot of memory.
19850 \begin_layout Standard
19851 If you're short on code memory you might want to use
19854 \begin_inset LatexCommand \index{printf\\_small()}
19869 For the mcs51 there additionally are assembly versions
19872 \begin_inset LatexCommand \index{printf\\_tiny() (mcs51)}
19878 (subset of printf using less than 270 bytes) and
19881 \begin_inset LatexCommand \index{printf\\_fast() (mcs51)}
19890 \begin_inset LatexCommand \index{printf\\_fast\\_f() (mcs51)}
19896 (floating-point aware version of printf_fast) which should fit the requirements
19897 of many embedded systems (printf_fast() can be customized by unsetting
19902 support long variables and field widths).
19903 Be sure to use only one of these printf options within a project.
19908 \begin_layout Standard
19909 Feature matrix of different
19916 \begin_layout Standard
19917 \begin_inset Tabular
19918 <lyxtabular version="3" rows="14" columns="7">
19919 <features islongtable="true">
19920 <column alignment="left" valignment="middle" leftline="true" width="14col%">
19921 <column alignment="center" valignment="top" leftline="true" width="0">
19922 <column alignment="center" valignment="top" leftline="true" width="12col%">
19923 <column alignment="center" valignment="top" leftline="true" width="10col%">
19924 <column alignment="center" valignment="top" leftline="true" width="0">
19925 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
19926 <column alignment="center" valignment="top" rightline="true" width="0">
19927 <row topline="true" bottomline="true" endhead="true">
19928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19931 \begin_layout Standard
19940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19943 \begin_layout Standard
19945 \begin_inset LatexCommand \index{printf}
19954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19957 \begin_layout Standard
19965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19968 \begin_layout Standard
19974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19977 \begin_layout Standard
19983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19986 \begin_layout Standard
19992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19995 \begin_layout Standard
20002 <row topline="true" endhead="true">
20003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20006 \begin_layout Standard
20012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20015 \begin_layout Standard
20023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20026 \begin_layout Standard
20034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20037 \begin_layout Standard
20045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20048 \begin_layout Standard
20056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20059 \begin_layout Standard
20067 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20070 \begin_layout Standard
20079 <row topline="true" endhead="true">
20080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20083 \begin_layout Standard
20084 \begin_inset Quotes sld
20088 \begin_inset Quotes srd
20094 \begin_layout Standard
20100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20103 \begin_layout Standard
20109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20112 \begin_layout Standard
20118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20121 \begin_layout Standard
20127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20130 \begin_layout Standard
20136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20139 \begin_layout Standard
20145 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20148 \begin_layout Standard
20155 <row topline="true" endhead="true">
20156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20159 \begin_layout Standard
20163 \begin_layout Standard
20169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20172 \begin_layout Standard
20178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20181 \begin_layout Standard
20187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20190 \begin_layout Standard
20191 0.45k / 0.47k (+ _ltoa)
20196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20199 \begin_layout Standard
20205 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20208 \begin_layout Standard
20214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20217 \begin_layout Standard
20224 <row topline="true">
20225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20228 \begin_layout Standard
20234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20237 \begin_layout Standard
20247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20250 \begin_layout Standard
20297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20300 \begin_layout Standard
20339 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20342 \begin_layout Standard
20348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20351 \begin_layout Standard
20357 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20360 \begin_layout Standard
20367 <row topline="true">
20368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20371 \begin_layout Standard
20372 long (32 bit) support
20377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20380 \begin_layout Standard
20386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20389 \begin_layout Standard
20395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20398 \begin_layout Standard
20404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20407 \begin_layout Standard
20413 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20416 \begin_layout Standard
20431 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20434 \begin_layout Standard
20441 <row topline="true">
20442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20445 \begin_layout Standard
20446 byte arguments on stack
20451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20454 \begin_layout Standard
20460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20463 \begin_layout Standard
20469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20472 \begin_layout Standard
20478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20481 \begin_layout Standard
20487 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20490 \begin_layout Standard
20496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20499 \begin_layout Standard
20506 <row topline="true">
20507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20510 \begin_layout Standard
20512 \begin_inset LatexCommand \index{Floating point support}
20521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20524 \begin_layout Standard
20530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20533 \begin_layout Standard
20539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20542 \begin_layout Standard
20548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20551 \begin_layout Standard
20557 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20560 \begin_layout Standard
20565 \begin_layout Standard
20566 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20579 \begin_layout Standard
20586 <row topline="true">
20587 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20590 \begin_layout Standard
20591 float formats %e %g
20596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20599 \begin_layout Standard
20605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20608 \begin_layout Standard
20614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20617 \begin_layout Standard
20623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20626 \begin_layout Standard
20632 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20635 \begin_layout Standard
20641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20644 \begin_layout Standard
20651 <row topline="true" bottomline="true">
20652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20655 \begin_layout Standard
20661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20664 \begin_layout Standard
20670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20673 \begin_layout Standard
20679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20682 \begin_layout Standard
20688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20691 \begin_layout Standard
20697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20700 \begin_layout Standard
20706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20709 \begin_layout Standard
20716 <row bottomline="true">
20717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20720 \begin_layout Standard
20725 \begin_layout Standard
20726 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20730 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20738 \begin_layout Standard
20744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20747 \begin_layout Standard
20753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20756 \begin_layout Standard
20762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20765 \begin_layout Standard
20771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20774 \begin_layout Standard
20780 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20783 \begin_layout Standard
20789 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20792 \begin_layout Standard
20799 <row bottomline="true">
20800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20803 \begin_layout Standard
20808 \begin_layout Standard
20809 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
20818 \begin_layout Standard
20824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20827 \begin_layout Standard
20833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20836 \begin_layout Standard
20842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20845 \begin_layout Standard
20851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20854 \begin_layout Standard
20860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20863 \begin_layout Standard
20869 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20872 \begin_layout Standard
20877 \begin_layout Standard
20878 printf_tiny integer speed is data dependent, worst case is 0.33 ms
20889 <row bottomline="true">
20890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20893 \begin_layout Standard
20898 \begin_layout Standard
20899 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
20908 \begin_layout Standard
20914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20917 \begin_layout Standard
20923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20926 \begin_layout Standard
20932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20935 \begin_layout Standard
20941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20944 \begin_layout Standard
20950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20953 \begin_layout Standard
20959 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20962 \begin_layout Standard
20969 <row bottomline="true">
20970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20973 \begin_layout Standard
20978 \begin_layout Standard
20979 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
20988 \begin_layout Standard
20994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20997 \begin_layout Standard
21003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21006 \begin_layout Standard
21012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21015 \begin_layout Standard
21021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21024 \begin_layout Standard
21030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21033 \begin_layout Standard
21039 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21042 \begin_layout Standard
21056 \begin_layout Subsubsection
21058 \begin_inset LatexCommand \index{malloc.h}
21065 \begin_layout Standard
21066 As of SDCC 2.6.2 you no longer need to call an initialization routine before
21067 using dynamic memory allocation
21068 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
21073 \begin_inset LatexCommand \index{heap (malloc)}
21077 space of 1024 bytes is provided for malloc to allocate memory from.
21078 If you need a different heap size you need to recompile _heap.c with the
21079 required size defined in HEAP_SIZE.
21080 It is recommended to make a copy of this file into your project directory
21081 and compile it there with:
21084 \begin_layout Verse
21087 sdcc -c _heap.c -D HEAD_SIZE=2048
21090 \begin_layout Standard
21091 And then link it with:
21094 \begin_layout Verse
21097 sdcc main.rel _heap.rel
21100 \begin_layout Subsection
21101 Math functions (sinf, powf, sqrtf etc.)
21104 \begin_layout Subsubsection
21108 \begin_layout Standard
21109 See definitions in file <math.h>.
21112 \begin_layout Subsection
21116 \begin_layout Standard
21118 \begin_inset LatexCommand \index{Libraries}
21122 included in SDCC should have a license at least as liberal as the GNU Lesser
21123 General Public License
21124 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
21135 \begin_layout Standard
21136 \begin_inset Note Note
21139 \begin_layout Standard
21140 license statements for the libraries are missing.
21141 sdcc/device/lib/ser_ir.c
21144 \begin_layout Standard
21146 come with a GPL (as opposed to LGPL) License - this will not be liberal
21147 enough for many embedded programmers.
21155 \begin_layout Standard
21156 If you have ported some library or want to share experience about some code
21158 falls into any of these categories Busses (I
21159 \begin_inset Formula $^{\textrm{2}}$
21162 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
21163 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
21164 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
21165 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
21170 would certainly like to hear about it.
21173 \begin_layout Standard
21174 Programmers coding for embedded systems are not especially famous for being
21175 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
21176 e these references are very valuable.
21177 Let's help to create a climate where information is shared.
21178 \begin_inset VSpace bigskip
21184 \begin_layout Section
21188 \begin_layout Subsection
21189 MCS51 Memory Models
21190 \begin_inset LatexCommand \index{Memory model}
21195 \begin_inset LatexCommand \index{MCS51 memory model}
21202 \begin_layout Subsubsection
21203 Small, Medium and Large
21206 \begin_layout Standard
21207 SDCC allows three memory models for MCS51 code,
21216 Modules compiled with different memory models should
21220 be combined together or the results would be unpredictable.
21221 The library routines supplied with the compiler are compiled as small,
21223 The compiled library modules are contained in separate directories as small,
21224 medium and large so that you can link to the appropriate set.
21227 \begin_layout Standard
21228 When the medium or large model is used all variables declared without a
21229 storage class will be allocated into the external ram, this includes all
21230 parameters and local variables (for non-reentrant
21231 \begin_inset LatexCommand \index{reentrant}
21236 When the small model is used variables without storage class are allocated
21237 in the internal ram.
21240 \begin_layout Standard
21241 Judicious usage of the processor specific storage classes
21242 \begin_inset LatexCommand \index{Storage class}
21246 and the 'reentrant' function type will yield much more efficient code,
21247 than using the large model.
21248 Several optimizations are disabled when the program is compiled using the
21249 large model, it is therefore recommended that the small model be used unless
21250 absolutely required.
21253 \begin_layout Subsubsection
21255 \begin_inset LatexCommand \label{sub:External-Stack}
21260 \begin_inset LatexCommand \index{stack}
21265 \begin_inset LatexCommand \index{External stack (mcs51)}
21272 \begin_layout Standard
21273 The external stack (-
21277 \begin_layout Standard
21287 \begin_inset LatexCommand \index{-\\/-xstack}
21291 ) is located in pdata
21292 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
21296 memory (usually at the start of the external ram segment) and uses all
21297 unused space in pdata (max.
21303 \begin_layout Standard
21312 -xstack option is used to compile the program, the parameters and local
21314 \begin_inset LatexCommand \index{local variables}
21318 of all reentrant functions are allocated in this area.
21319 This option is provided for programs with large stack space requirements.
21320 When used with the -
21324 \begin_layout Standard
21334 \begin_inset LatexCommand \index{-\\/-stack-auto}
21338 option, all parameters and local variables are allocated on the external
21339 stack (note: support libraries will need to be recompiled with the same
21341 There is a predefined target in the library makefile).
21344 \begin_layout Standard
21345 The compiler outputs the higher order address byte of the external ram segment
21347 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21352 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21356 ), therefore when using the External Stack option, this port
21360 be used by the application program.
21363 \begin_layout Subsection
21365 \begin_inset LatexCommand \index{Memory model}
21370 \begin_inset LatexCommand \index{DS390 memory model}
21377 \begin_layout Standard
21378 The only model supported is Flat 24
21379 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21384 This generates code for the 24 bit contiguous addressing mode of the Dallas
21386 In this mode, up to four meg of external RAM or code space can be directly
21388 See the data sheets at www.dalsemi.com for further information on this part.
21393 that the compiler does not generate any code to place the processor into
21394 24 bitmode (although
21398 in the ds390 libraries will do that for you).
21404 \begin_inset LatexCommand \index{Tinibios (DS390)}
21408 , the boot loader or similar code must ensure that the processor is in 24
21409 bit contiguous addressing mode before calling the SDCC startup code.
21420 \begin_layout Standard
21431 option, variables will by default be placed into the XDATA segment.
21436 Segments may be placed anywhere in the 4 meg address space using the usual
21441 \begin_layout Standard
21451 Note that if any segments are located above 64K, the -r flag must be passed
21452 to the linker to generate the proper segment relocations, and the Intel
21453 HEX output format must be used.
21454 The -r flag can be passed to the linker by using the option
21458 on the SDCC command line.
21459 However, currently the linker can not handle code segments > 64k.
21462 \begin_layout Section
21464 \begin_inset LatexCommand \label{sec:Pragmas}
21469 \begin_inset LatexCommand \index{Pragmas}
21476 \begin_layout Standard
21477 Pragmas are used to turn on and/or off certain compiler options.
21478 Some of them are closely related to corresponding command-line options
21480 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21486 Pragmas should be placed before and/or after a function, placing pragmas
21487 inside a function body could have unpredictable results.
21492 following #pragma directives:
21495 \begin_layout Itemize
21501 \begin_inset LatexCommand \index{\\#pragma save}
21505 - this will save most current options to the save/restore stack.
21506 See #pragma\InsetSpace ~
21510 \begin_layout Itemize
21516 \begin_inset LatexCommand \index{\\#pragma restore}
21520 - will restore saved options from the last save.
21521 saves & restores can be nested.
21522 SDCC uses a save/restore stack: save pushes current options to the stack,
21523 restore pulls current options from the stack.
21524 See #pragma\InsetSpace ~
21530 \begin_layout Itemize
21536 \begin_inset LatexCommand \index{\\#pragma callee\\_saves}
21541 \begin_inset LatexCommand \index{function prologue}
21545 function1[,function2[,function3...]]
21546 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21550 - The compiler by default uses a caller saves convention for register saving
21551 across function calls, however this can cause unnecessary register pushing
21553 \begin_inset LatexCommand \index{push/pop}
21557 when calling small functions from larger functions.
21558 This option can be used to switch off the register saving convention for
21559 the function names specified.
21560 The compiler will not save registers when calling these functions, extra
21561 code need to be manually inserted at the entry and exit for these functions
21562 to save and restore the registers used by these functions, this can SUBSTANTIAL
21563 LY reduce code and improve run time performance of the generated code.
21564 In the future the compiler (with inter procedural analysis) may be able
21565 to determine the appropriate scheme to use for each function call.
21570 \begin_layout Standard
21579 -callee-saves command line option is used (see page
21580 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21584 ), the function names specified in #pragma\InsetSpace ~
21586 \begin_inset LatexCommand \index{\\#pragma callee\\_saves}
21590 is appended to the list of functions specified in the command line.
21593 \begin_layout Itemize
21599 \begin_inset LatexCommand \index{\\#pragma exclude}
21603 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21604 of pairs of push/pop
21605 \begin_inset LatexCommand \index{push/pop}
21614 \begin_inset LatexCommand \index{interrupt}
21627 The directive should be placed immediately before the ISR function definition
21628 and it affects ALL ISR functions following it.
21629 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21630 exclude\InsetSpace ~
21632 \begin_inset LatexCommand \index{\\#pragma exclude}
21637 See also the related keyword _naked
21638 \begin_inset LatexCommand \index{\\_naked}
21643 \begin_inset LatexCommand \index{\\_\\_naked}
21650 \begin_layout Itemize
21656 \begin_inset LatexCommand \index{pedantic}
21661 \begin_inset LatexCommand \index{\\#pragma less\\_pedantic}
21666 \begin_inset LatexCommand \label{ite:less_pedantic}
21670 - the compiler will not warn you anymore for obvious mistakes, you're on
21672 See also the command line option -
21676 \begin_layout Standard
21686 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21693 More specifically, the following warnings will be disabled:
21695 comparison is always [true/false] due to limited range of data type
21699 overflow in implicit constant conversion
21701 (158); [the (in)famous]
21703 conditional flow changed by optimizer: so said EVELYN the modified DOG
21707 function '[function name]' must return value
21712 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21713 level) are disabled, too, namely:
21716 \begin_inset Note Note
21719 \begin_layout Standard
21720 dunno what comes here - this warning appears to be unused altogether
21729 [left/right] shifting more than size of object changed to zero
21737 integer overflow in expression
21741 unmatched #pragma save and #pragma restore
21745 comparison of 'signed char' with 'unsigned char' requires promotion to int
21749 ISO C90 does not support flexible array members
21753 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21757 \begin_inset Note Note
21760 \begin_layout Standard
21761 appears to be always blank - what was supposed to be here?
21770 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21771 complexity [number]
21776 \begin_layout Itemize
21782 \begin_inset LatexCommand \index{\\#pragma disable\\_warning}
21786 - the compiler will not warn you anymore about warning number <nnnn>.
21789 \begin_layout Itemize
21795 \begin_inset LatexCommand \index{\\#pragma nogcse}
21799 - will stop global common subexpression elimination.
21802 \begin_layout Itemize
21808 \begin_inset LatexCommand \index{\\#pragma noinduction}
21812 - will stop loop induction optimizations.
21815 \begin_layout Itemize
21821 \begin_inset LatexCommand \index{\\#pragma noinvariant}
21825 - will not do loop invariant optimizations.
21826 For more details see Loop Invariants in section
21827 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
21834 \begin_layout Itemize
21840 \begin_inset LatexCommand \index{\\#pragma noiv}
21844 - Do not generate interrupt
21845 \begin_inset LatexCommand \index{interrupt}
21850 \begin_inset LatexCommand \index{interrupt vector table}
21854 entries for all ISR functions defined after the pragma.
21855 This is useful in cases where the interrupt vector table must be defined
21856 manually, or when there is a secondary, manually defined interrupt vector
21858 for the autovector feature of the Cypress EZ-USB FX2).
21859 More elegantly this can be achieved by obmitting the optional interrupt
21860 number after the interrupt keyword, see section
21861 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
21869 \begin_layout Itemize
21875 \begin_inset LatexCommand \index{\\#pragma nojtbound}
21879 - will not generate code for boundary value checking, when switch statements
21880 are turned into jump-tables (dangerous).
21881 For more details see section
21882 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
21889 \begin_layout Itemize
21895 \begin_inset LatexCommand \index{\\#pragma noloopreverse}
21899 - Will not do loop reversal optimization
21902 \begin_layout Itemize
21908 \begin_inset LatexCommand \index{\\#pragma nooverlay}
21912 - the compiler will not overlay the parameters and local variables of a
21916 \begin_layout Itemize
21922 \begin_inset LatexCommand \index{\\#pragma stackauto}
21930 \begin_layout Standard
21940 \begin_inset LatexCommand \index{-\\/-stack-auto}
21945 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
21949 Parameters and Local Variables.
21952 \begin_layout Itemize
21958 \begin_inset LatexCommand \index{\\#pragma opt\\_code\\_speed}
21962 - The compiler will optimize code generation towards fast code, possibly
21963 at the expense of code size.
21964 Currently this has little effect.
21967 \begin_layout Itemize
21973 \begin_inset LatexCommand \index{\\#pragma opt\\_code\\_size}
21977 - The compiler will optimize code generation towards compact code, possibly
21978 at the expense of code speed.
21979 Currently this has little effect.
21982 \begin_layout Itemize
21988 \begin_inset LatexCommand \index{\\#pragma opt\\_code\\_balanced}
21992 - The compiler will attempt to generate code that is both compact and fast,
21993 as long as meeting one goal is not a detriment to the other (this is the
21998 \begin_layout Itemize
22004 \begin_inset LatexCommand \index{\\#pragma std\\_sdcc89}
22008 - Generally follow the C89 standard, but allow SDCC features that conflict
22009 with the standard (default).
22012 \begin_layout Itemize
22018 \begin_inset LatexCommand \index{\\#pragma std\\_c89}
22022 - Follow the C89 standard and disable SDCC features that conflict with the
22026 \begin_layout Itemize
22032 \begin_inset LatexCommand \index{\\#pragma std\\_sdcc99}
22036 - Generally follow the C99 standard, but allow SDCC features that conflict
22037 with the standard (incomplete support).
22040 \begin_layout Itemize
22046 \begin_inset LatexCommand \index{\\#pragma std\\_c99}
22050 - Follow the C99 standard and disable SDCC features that conflict with the
22051 standard (incomplete support).
22054 \begin_layout Itemize
22060 \begin_inset LatexCommand \index{\\#pragma codeseg}
22064 - Use this name (max.
22065 8 characters) for the code segment.
22070 \begin_layout Standard
22082 \begin_layout Itemize
22088 \begin_inset LatexCommand \index{\\#pragma constseg}
22092 - Use this name (max.
22093 8 characters) for the const segment.
22098 \begin_layout Standard
22110 \begin_layout Standard
22111 The preprocessor SDCPP
22112 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
22116 supports the following #pragma directives:
22119 \begin_layout Itemize
22122 pedantic_parse_number
22125 \begin_inset LatexCommand \index{pedantic}
22130 \begin_inset LatexCommand \index{\\#pragma pedantic\\_parse\\_number}
22135 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
22139 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
22140 properly and the macro LO_B(3) gets expanded.
22146 \begin_layout Standard
22155 -pedantic-parse-number command line option
22156 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
22163 Below is an example on how to use this pragma.
22166 Note: this functionality is not in conformance with standard!
22169 \begin_layout Verse
22172 #pragma pedantic_parse_number +
22173 \begin_inset LatexCommand \index{\\#pragma pedantic\\_parse\\_number}
22181 #define LO_B(x) ((x) & 0xff)
22185 unsigned char foo(void)
22192 unsigned char c=0xfe-LO_B(3)
22207 \begin_layout Itemize
22213 \begin_inset LatexCommand \index{\\#pragma preproc\\_asm}
22217 (+ | -) - switch _asm _endasm block preprocessing on / off.
22219 You use this prama to define multilines of assembly code.
22220 This will prevent the preprocessor from changing the formating required
22222 Below is an example on how to use this pragma.
22225 \begin_layout Verse
22228 #pragma preproc_asm -
22229 \begin_inset LatexCommand \index{\\#pragma preproc\\_asm}
22235 #define MYDELAY _asm
22240 nop ;my assembly comment...
22254 #pragma preproc_asm
22285 \begin_layout Itemize
22291 \begin_inset LatexCommand \index{\\#pragma sdcc\\_hash}
22295 (+ | -) - Allow "naked" hash in macro definition, for example:
22299 #define DIR_LO(x) #(x & 0xff)
22304 Below is an example on how to use this pragma.
22307 \begin_layout Verse
22310 #pragma preproc_asm +
22312 #pragma sdcc_hash +
22313 \begin_inset LatexCommand \index{\\#pragma sdcc\\_hash}
22328 mov R6_B3, #(x & 0xff)
22335 mov R7_B3, #((x >> 8) & 0xff)
22359 \begin_layout Standard
22360 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22361 ons which might cause the compiler to generate extra stack and/or data space
22362 to store compiler generated temporary variables.
22363 This usually happens in large functions.
22364 Pragma directives should be used as shown in the following example, they
22365 are used to control options and optimizations for a given function.
22369 \begin_layout Verse
22373 \begin_inset LatexCommand \index{\\#pragma save}
22384 /* save the current settings */
22387 \begin_inset LatexCommand \index{\\#pragma nogcse}
22396 /* turnoff global subexpression elimination */
22398 #pragma noinduction
22399 \begin_inset LatexCommand \index{\\#pragma noinduction}
22403 /* turn off induction optimizations */
22426 \begin_inset LatexCommand \index{\\#pragma restore}
22430 /* turn the optimizations back on */
22433 \begin_layout Standard
22434 The compiler will generate a warning message when extra space is allocated.
22435 It is strongly recommended that the save and restore pragmas be used when
22436 changing options for a function.
22445 \begin_layout Section
22446 Defines Created by the Compiler
22449 \begin_layout Standard
22450 The compiler creates the following #defines
22451 \begin_inset LatexCommand \index{\\#defines}
22456 \begin_inset LatexCommand \index{Defines created by the compiler}
22465 \begin_layout Standard
22466 \begin_inset Tabular
22467 <lyxtabular version="3" rows="11" columns="2">
22469 <column alignment="left" valignment="top" leftline="true" width="3in">
22470 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22471 <row topline="true" bottomline="true">
22472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22475 \begin_layout Standard
22483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22486 \begin_layout Standard
22495 <row topline="true">
22496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22499 \begin_layout Standard
22501 \begin_inset LatexCommand \index{SDCC}
22510 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22513 \begin_layout Standard
22515 Since version 2.5.6 the version number as an int (ex.
22522 <row topline="true">
22523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22526 \begin_layout Standard
22528 \begin_inset LatexCommand \index{SDCC\\_mcs51}
22533 \begin_inset LatexCommand \index{SDCC\\_ds390}
22538 \begin_inset LatexCommand \index{SDCC\\_z80}
22547 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22550 \begin_layout Standard
22551 depending on the model used (e.g.: -mds390)
22557 <row topline="true">
22558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22561 \begin_layout Standard
22563 \begin_inset LatexCommand \index{\\_\\_mcs51}
22568 \begin_inset LatexCommand \index{\\_\\_ds390}
22573 \begin_inset LatexCommand \index{\\_\\_hc08}
22578 \begin_inset LatexCommand \index{\\_\\_z80}
22587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22590 \begin_layout Standard
22591 depending on the model used (e.g.
22598 <row topline="true">
22599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22602 \begin_layout Standard
22604 \begin_inset LatexCommand \index{SDCC\\_STACK\\_AUTO}
22613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22616 \begin_layout Standard
22623 \begin_layout Standard
22640 <row topline="true">
22641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22644 \begin_layout Standard
22646 \begin_inset LatexCommand \index{SDCC\\_MODEL\\_SMALL}
22655 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22658 \begin_layout Standard
22665 \begin_layout Standard
22682 <row topline="true">
22683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22686 \begin_layout Standard
22688 \begin_inset LatexCommand \index{SDCC\\_MODEL\\_MEDIUM}
22697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22700 \begin_layout Standard
22707 \begin_layout Standard
22724 <row topline="true">
22725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22728 \begin_layout Standard
22730 \begin_inset LatexCommand \index{SDCC\\_MODEL\\_LARGE}
22739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22742 \begin_layout Standard
22749 \begin_layout Standard
22766 <row topline="true">
22767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22770 \begin_layout Standard
22772 \begin_inset LatexCommand \index{SDCC\\_USE\\_XSTACK}
22781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22784 \begin_layout Standard
22791 \begin_layout Standard
22808 <row topline="true">
22809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22812 \begin_layout Standard
22814 \begin_inset LatexCommand \index{SDCC\\_STACK\\_TENBIT}
22823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22826 \begin_layout Standard
22837 <row topline="true" bottomline="true">
22838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22841 \begin_layout Standard
22843 \begin_inset LatexCommand \index{SDCC\\_MODEL\\_FLAT24}
22852 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22855 \begin_layout Standard
22873 \begin_layout Chapter
22874 Notes on supported Processors
22877 \begin_layout Section
22879 \begin_inset LatexCommand \label{sub:MCS51-variants}
22884 \begin_inset LatexCommand \index{MCS51 variants}
22891 \begin_layout Standard
22892 MCS51 processors are available from many vendors and come in many different
22894 While they might differ considerably in respect to Special Function Registers
22895 the core MCS51 is usually not modified or is kept compatible.
22899 \begin_layout Subsection
22900 pdata access by SFR
22903 \begin_layout Standard
22904 With the upcome of devices with internal xdata and flash memory devices
22906 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
22910 as dedicated I/O port is becoming more popular.
22911 Switching the high byte for pdata
22912 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
22916 access which was formerly done by port P2 is then achieved by a Special
22918 \begin_inset LatexCommand \index{sfr}
22923 In well-established MCS51 tradition the address of this
22927 is where the chip designers decided to put it.
22928 Needless to say that they didn't agree on a common name either.
22929 So that the startup code can correctly initialize xdata variables, you
22930 should define an sfr with the name _XPAGE
22933 \begin_inset LatexCommand \index{\\_XPAGE (mcs51)}
22939 at the appropriate location if the default, port P2, is not used for this.
22943 \begin_layout Verse
22946 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
22950 \begin_layout Verse
22953 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
22958 \begin_layout Verse
22961 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
22965 \begin_layout Verse
22968 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22972 \begin_layout Verse
22975 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22979 \begin_layout Standard
22980 For more exotic implementations further customizations may be needed.
22982 \begin_inset LatexCommand \ref{sub:Startup-Code}
22986 for other possibilities.
22989 \begin_layout Subsection
22990 Other Features available by SFR
22993 \begin_layout Standard
22994 Some MCS51 variants offer features like Double DPTR
22995 \begin_inset LatexCommand \index{DPTR}
22999 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
23000 These are currently not used for the MCS51 port.
23001 If you absolutely need them you can fall back to inline assembly or submit
23003 \begin_inset VSpace bigskip
23009 \begin_layout Section
23013 \begin_layout Standard
23015 \begin_inset LatexCommand \index{DS80C400}
23020 \begin_inset LatexCommand \index{DS400}
23024 microcontroller has a rich set of peripherals.
23025 In its built-in ROM library it includes functions to access some of the
23026 features, among them is a TCP stack with IP4 and IP6 support.
23027 Library headers (currently in beta status) and other files are provided
23031 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
23037 \begin_inset VSpace bigskip
23043 \begin_layout Section
23044 The Z80 and gbz80 port
23047 \begin_layout Standard
23048 SDCC can target both the Zilog Z80
23049 \begin_inset LatexCommand \index{Z80}
23053 and the Nintendo Gameboy's Z80-like gbz80
23054 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
23059 The Z80 port is passed through the same
23062 \begin_inset LatexCommand \index{Regression test}
23069 \begin_inset LatexCommand \ref{sec:Quality-control}
23073 ) as the MCS51 and DS390 ports, so floating point support, support for long
23074 variables and bitfield support is fine.
23075 See mailing lists and forums about interrupt routines.
23078 \begin_layout Standard
23079 As always, the code is the authoritative reference - see z80/ralloc.c and
23082 \begin_inset LatexCommand \index{Z80!stack}
23086 frame is similar to that generated by the IAR Z80 compiler.
23087 IX is used as the base pointer, HL and IY are used as a temporary registers,
23088 and BC and DE are available for holding variables.
23090 \begin_inset LatexCommand \index{Z80!return value}
23094 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
23096 The gbz80 port use the same set of registers for the return values, but
23097 in a different order of significance: E (one byte), DE (two bytes), or
23099 \begin_inset VSpace bigskip
23105 \begin_layout Section
23109 \begin_layout Standard
23110 The port to the Freescale/Motorola HC08
23111 \begin_inset LatexCommand \index{HC08}
23115 family has been added in October 2003, and is still undergoing some basic
23117 The code generator is complete, but the register allocation is still quite
23119 Some of the SDCC's standard C library functions have embedded non-HC08
23120 inline assembly and so are not yet usable.
23123 \begin_layout Standard
23124 The HC08 port passes the regression test suite (see section
23125 \begin_inset LatexCommand \ref{sec:Quality-control}
23130 \begin_inset VSpace bigskip
23138 \begin_layout Section
23140 \begin_inset LatexCommand \index{PIC14}
23147 \begin_layout Standard
23148 The PIC14 port adds support for Microchip
23149 \begin_inset LatexCommand \index{Microchip}
23154 \begin_inset Formula $^{\text{TM}}$
23158 \begin_inset LatexCommand \index{PIC14}
23163 \begin_inset Formula $^{\text{TM}}$
23166 MCUs with 14 bit wide instructions.
23167 This port is not yet mature and still lacks many features.
23168 However, it can work for simple code.
23171 \begin_layout Standard
23172 Currently supported devices include:
23175 \begin_layout Standard
23176 12F: 629, 635, 675, 683
23179 \begin_layout Standard
23183 \begin_layout Standard
23187 \begin_layout Standard
23188 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
23191 \begin_layout Standard
23192 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
23196 \begin_layout Standard
23200 \begin_layout Standard
23201 16F: 627, 627a, 628, 628a, 630, 636, 639, 648a, 676, 684, 685, 687, 688,
23205 \begin_layout Standard
23206 16F: 716, 72, 73, 737, 74, 76, 767, 77, 777, 785
23209 \begin_layout Standard
23210 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
23214 \begin_layout Standard
23215 16F: 913, 914, 916, 917
23218 \begin_layout Standard
23219 An up-to-date list of currently supported devices can be obtained via
23221 sdcc -mpic14 -phelp foo.c
23223 (foo.c must exist...).
23226 \begin_layout Subsection
23228 \begin_inset LatexCommand \index{code page (pic14)}
23233 \begin_inset LatexCommand \index{Memory bank (pic14)}
23240 \begin_layout Standard
23241 The linker organizes allocation for the code page and RAM banks.
23242 It does not have intimate knowledge of the code flow.
23243 It will put all the code section of a single .asm file into a single code
23245 In order to make use of multiple code pages, separate asm files must be
23247 The compiler assigns all
23251 functions of a single .c file into the same code page.
23255 To get the best results,
23256 follow these guidelines:
23259 \begin_layout Enumerate
23260 Make local functions static, as non static functions require code page selection
23263 Due to the way sdcc handles functions, place called functions prior
23264 to calling functions in the file wherever possible: Otherwise sdcc will
23265 insert unneccessary pagesel directives around the call, believing that
23266 the called function is externally defined.
23269 \begin_layout Enumerate
23270 For devices that have multiple code pages it is more efficient to use the
23271 same number of files as pages: Use up to 4 separate .c files for the 16F877,
23272 but only 2 files for the 16F874.
23273 This way the linker can put the code for each file into different code
23274 pages and there will be less page selection overhead.
23277 \begin_layout Enumerate
23278 And as for any 8 bit micro (especially for PIC14 as they have a very simple
23279 instruction set), use `unsigned char' wherever possible instead of `int'.
23282 \begin_layout Subsection
23283 Adding New Devices to the Port
23286 \begin_layout Standard
23287 Adding support for a new 14
23291 \begin_layout Standard
23300 bit PIC MCU requires the following steps:
23303 \begin_layout Enumerate
23304 Create a new device description.
23306 Each device is described in two files: pic16f*.h
23308 These files primarily define SFRs, structs to access their bits, and symbolic
23309 configuration options.
23310 Both files can be generated from gputils' .inc files using the perl script
23313 support/scripts/inc2h.pl
23316 This file also contains further instructions on how to proceed.
23319 \begin_layout Enumerate
23320 Copy the .h file into SDCC's include path and either add the .c file to your
23321 project or copy it to
23323 device/lib/pic/libdev
23326 Afterwards, rebuild and install the libraries.
23329 \begin_layout Enumerate
23330 Edit pic14devices.txt in SDCC's include path (
23332 device/include/pic/
23334 in the source tree or
23336 /usr/local/share/sdcc/include/pic
23338 after installation).
23340 You need to add a device specification here to make
23341 the memory layout (code banks, RAM, aliased memory regions, ...) known to
23343 Probably you can copy and modify an existing entry.
23344 The file format is documented at the top of the file.
23347 \begin_layout Subsection
23351 \begin_layout Standard
23352 For the interrupt function, use the keyword `__interrupt'
23353 \begin_inset LatexCommand \index{PIC14!interrupt}
23357 with level number of 0 (PIC14 only has 1 interrupt so this number is only
23358 there to avoid a syntax error - it ought to be fixed).
23362 \begin_layout Verse
23365 void Intr(void) __interrupt 0
23371 T0IF = 0; /* Clear timer interrupt */
23376 \begin_layout Subsection
23377 Linking and Assembling
23380 \begin_layout Standard
23381 For assembling you can use either GPUTILS'
23382 \begin_inset LatexCommand \index{gputils (pic tools)}
23386 gpasm.exe or MPLAB's mpasmwin.exe.
23387 GPUTILS are available from
23388 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23393 For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
23394 If you use MPLAB and an interrupt function then the linker script file
23395 vectors section will need to be enlarged to link with mplink.
23406 \begin_layout Verse
23419 sdcc -V -mpic14 -p16f877 -c $<
23423 $(PRJ).hex: $(OBJS)
23433 gplink -m -s $(PRJ).lkr
23434 -o $(PRJ).hex $(OBJS) libsdcc.lib
23437 \begin_layout Standard
23445 \begin_layout Verse
23458 sdcc -S -V -mpic14 -p16f877 $<
23468 mpasmwin /q /o $*.asm
23472 $(PRJ).hex: $(OBJS)
23483 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
23486 \begin_layout Standard
23487 Please note that indentations within a
23491 have to be done with a tabulator character.
23494 \begin_layout Subsection
23495 Command-Line Options
23498 \begin_layout Standard
23499 Besides the switches common to all SDCC backends, the PIC14 port accepts
23500 the following options (for an updated list see sdcc -
23504 \begin_layout Standard
23516 \begin_layout Description
23521 \begin_layout Standard
23531 \begin_inset LatexCommand \index{PIC14!Options!-\\/-debug-extra}
23535 emit debug info in assembly output
23538 \begin_layout Description
23543 \begin_layout Standard
23553 \begin_inset LatexCommand \index{PIC14!Options!-\\/-no-pcode-opt}
23557 disable (slightly faulty) optimization on pCode
23560 \begin_layout Description
23565 \begin_layout Standard
23575 \begin_inset LatexCommand \index{PIC14!Options!-\\/-stack-loc}
23579 sets the lowest address of the argument passing stack (defaults to a suitably
23580 large shared databank to reduce BANKSEL overhead)
23583 \begin_layout Description
23588 \begin_layout Standard
23598 \begin_inset LatexCommand \index{PIC14!Options!-\\/-stack-size}
23602 sets the size if the argument passing stack (default: 16, minimum: 4)
23605 \begin_layout Subsection
23606 Environment Variables
23609 \begin_layout Standard
23610 The PIC14 port recognizes the following environment variables:
23613 \begin_layout Description
23614 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
23615 register (the ones called r0xNNNN) in a section of its own.
23616 By default (if this variable is unset), sdcc tries to cluster registers
23617 in sections in order to reduce the BANKSEL overhead when accessing them.
23620 \begin_layout Subsection
23624 \begin_layout Standard
23625 The PIC14 library currently only contains support routines required by the
23626 compiler to implement multiplication, division, and floating point support.
23627 No libc-like replacement is available at the moment, though many of the
23628 common sdcc library sources (in
23632 ) should also compile with the PIC14 port.
23635 \begin_layout Subsubsection
23636 error: missing definition for symbol ``__gptrget1''
23639 \begin_layout Standard
23640 The PIC14 port uses library routines to provide more complex operations
23641 like multiplication, division/modulus and (generic) pointer dereferencing.
23642 In order to add these routines to your project, you must link with PIC14's
23648 For single source file projects this is done automatically, more complex
23653 to the linker's arguments.
23654 Make sure you also add an include path for the library (using the -I switch
23658 \begin_layout Subsubsection
23659 Processor mismatch in file ``XXX''.
23662 \begin_layout Standard
23663 This warning can usually be ignored due to the very good compatibility amongst
23668 \begin_layout Standard
23678 \begin_inset LatexCommand \index{PIC14}
23685 \begin_layout Standard
23686 You might also consider recompiling the library for your specific device
23687 by changing the ARCH=p16f877 (default target) entry in
23689 device/lib/pic/Makefile.in
23693 device/lib/pic/Makefile
23695 to reflect your device.
23696 This might even improve performance for smaller devices as unneccesary
23697 BANKSELs might be removed.
23700 \begin_layout Subsection
23704 \begin_layout Subsubsection
23708 \begin_layout Standard
23709 Functions with variable argument lists (like printf) are not yet supported.
23710 Similarly, taking the argument of the first argument passed into a function
23711 does not work: It is currently passed in WREG and has no address...
23714 \begin_layout Subsubsection
23715 Regression tests fail
23718 \begin_layout Standard
23719 Though the small subset of regression tests in src/regression passes, SDCC
23720 regression test suite does not, indicating that there are still major bugs
23722 However, many smaller projects have successfully used SDCC in the past...
23725 \begin_layout Standard
23733 \begin_layout Section
23735 \begin_inset LatexCommand \index{PIC16}
23742 \begin_layout Standard
23743 The PIC16 port adds support for Microchip
23744 \begin_inset LatexCommand \index{Microchip}
23749 \begin_inset Formula $^{\text{TM}}$
23753 \begin_inset LatexCommand \index{PIC}
23758 \begin_inset Formula $^{\text{TM}}$
23761 MCUs with 16 bit wide instructions.
23762 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
23763 ; devices supported by the port include:
23766 \begin_layout Standard
23767 18F: 242, 248, 252, 258, 442, 448, 452, 458
23770 \begin_layout Standard
23774 \begin_layout Standard
23775 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 24j10, 2525, 2550, 25j10,
23779 \begin_layout Standard
23780 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 44j10, 4520, 4525, 4550,
23784 \begin_layout Standard
23785 18F: 6520, 6620, 6680, 6720
23788 \begin_layout Standard
23789 18F: 8520, 8620, 8680, 8720
23792 \begin_layout Subsection
23796 \begin_layout Standard
23797 PIC16 port supports the standard command line arguments as supposed, with
23798 the exception of certain cases that will be mentioned in the following
23802 \begin_layout Description
23807 \begin_layout Standard
23817 \begin_inset LatexCommand \index{PIC16!Options!-\\/-callee-saves}
23825 \begin_layout Standard
23837 \begin_layout Description
23842 \begin_layout Standard
23851 -fommit-frame-pointer
23852 \begin_inset LatexCommand \index{PIC16!Options!-\\/-fommit-frame-pointer}
23856 Frame pointer will be omitted when the function uses no local variables.
23859 \begin_layout Subsection
23860 Port Specific Options
23861 \begin_inset LatexCommand \index{Options PIC16}
23868 \begin_layout Standard
23869 The port specific options appear after the global options in the sdcc -
23873 \begin_layout Standard
23885 \begin_layout Subsubsection
23886 Code Generation Options
23889 \begin_layout Standard
23890 These options influence the generated assembler code.
23893 \begin_layout Description
23898 \begin_layout Standard
23907 -pstack-model=[model] Used in conjuction with the command above.
23908 Defines the stack model to be used, valid stack models are:
23913 \labelwidthstring 00.00.0000
23918 Selects small stack model.
23919 8 bit stack and frame pointers.
23920 Supports 256 bytes stack size.
23924 \labelwidthstring 00.00.0000
23929 Selects large stack model.
23930 16 bit stack and frame pointers.
23931 Supports 65536 bytes stack size.
23935 \begin_layout Description
23940 \begin_layout Standard
23949 -pno-banksel Do not generate BANKSEL assembler directives.
23952 \begin_layout Description
23957 \begin_layout Standard
23966 -extended Enable extended instruction set/literal offset addressing mode.
23970 \begin_layout Subsubsection
23971 Optimization Options
23974 \begin_layout Description
23979 \begin_layout Standard
23988 -obanksel=n Set optimization level for inserting BANKSELs.
23995 \labelwidthstring 00.00.0000
24000 \labelwidthstring 00.00.0000
24001 1 checks previous used register and if it is the same then does not emit
24002 BANKSEL, accounts only for labels.
24006 \labelwidthstring 00.00.0000
24007 2 tries to check the location of (even different) symbols and removes BANKSELs
24008 if they are in the same bank.
24013 Important: There might be problems if the linker script has data sections
24014 across bank borders!
24018 \begin_layout Description
24023 \begin_layout Standard
24032 -denable-peeps Force the usage of peepholes.
24036 \begin_layout Description
24041 \begin_layout Standard
24050 -optimize-goto Try to use (conditional) BRA instead of GOTO.
24053 \begin_layout Description
24058 \begin_layout Standard
24067 -optimize-cmp Try to optimize some compares.
24070 \begin_layout Description
24075 \begin_layout Standard
24084 -optimize-df Analyze the dataflow of the generated code and improve it.
24087 \begin_layout Subsubsection
24091 \begin_layout Description
24096 \begin_layout Standard
24105 -asm= Sets the full path and name of an external assembler to call.
24108 \begin_layout Description
24113 \begin_layout Standard
24123 \begin_inset LatexCommand \index{PIC16!MPLAB}
24127 compatibility option.
24128 Currently only suppresses special gpasm directives.
24131 \begin_layout Subsubsection
24135 \begin_layout Description
24140 \begin_layout Standard
24149 -link= Sets the full path and name of an external linker to call.
24152 \begin_layout Description
24157 \begin_layout Standard
24166 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
24167 unitialized data variables with [kword].
24168 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
24171 \begin_layout Description
24176 \begin_layout Standard
24185 -ivt-loc=n Place the interrupt vector table at address
24190 Useful for bootloaders.
24193 \begin_layout Description
24198 \begin_layout Standard
24207 -nodefaultlibs Do not link default libraries when linking.
24210 \begin_layout Description
24215 \begin_layout Standard
24224 -use-crt= Use a custom run-time module instead of the defaults.
24227 \begin_layout Description
24232 \begin_layout Standard
24241 -no-crt Don't link the default run-time modules
24244 \begin_layout Subsubsection
24248 \begin_layout Standard
24249 Debugging options enable extra debugging information in the output files.
24252 \begin_layout Description
24257 \begin_layout Standard
24266 -debug-xtra Similar to -
24270 \begin_layout Standard
24280 \begin_inset LatexCommand \index{-\\/-debug}
24284 , but dumps more information.
24287 \begin_layout Description
24292 \begin_layout Standard
24301 -debug-ralloc Force register allocator to dump <source>.d file with debugging
24303 <source> is the name of the file being compiled.
24306 \begin_layout Description
24311 \begin_layout Standard
24320 -pcode-verbose Enable pcode debugging information in translation.
24323 \begin_layout Description
24328 \begin_layout Standard
24337 -calltree Dump call tree in .calltree file.
24340 \begin_layout Description
24345 \begin_layout Standard
24354 -gstack Trace push/pops for stack pointer overflow.
24357 \begin_layout Subsection
24358 Enviroment Variables
24361 \begin_layout Standard
24362 There is a number of enviromental variables that can be used when running
24363 SDCC to enable certain optimizations or force a specific program behaviour.
24364 these variables are primarily for debugging purposes so they can be enabled/dis
24368 \begin_layout Standard
24369 Currently there is only two such variables available:
24372 \begin_layout Description
24373 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
24374 bitfields is optimized by directly loading FSR0 with the address of the
24375 bitfield structure.
24376 Normally SDCC will cast the bitfield structure to a bitfield pointer and
24378 This step saves data ram and code space for functions that make heavy use
24380 (i.e., 80 bytes of code space are saved when compiling malloc.c with this
24385 \begin_layout Description
24386 NO_REG_OPT Do not perform pCode registers optimization.
24387 This should be used for debugging purposes.
24388 If bugs in the pcode optimizer are found, users can benefit from temporarily
24389 disabling the optimizer until the bug is fixed.
24392 \begin_layout Subsection
24393 Preprocessor Macros
24396 \begin_layout Standard
24398 \begin_inset LatexCommand \index{PIC16}
24402 port defines the following preprocessor macros while translating a source.
24405 \begin_layout Standard
24407 \begin_inset Tabular
24408 <lyxtabular version="3" rows="6" columns="2">
24410 <column alignment="center" valignment="top" leftline="true" width="0">
24411 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24412 <row topline="true" bottomline="true">
24413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24416 \begin_layout Standard
24422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24425 \begin_layout Standard
24432 <row topline="true">
24433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24436 \begin_layout Standard
24442 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24445 \begin_layout Standard
24446 Port identification
24452 <row topline="true">
24453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24456 \begin_layout Standard
24461 \begin_layout Standard
24475 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24478 \begin_layout Standard
24479 Port identification (same as above)
24485 <row topline="true">
24486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24489 \begin_layout Standard
24495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24498 \begin_layout Standard
24499 MCU Identification.
24504 is the microcontrol identification number, i.e.
24511 <row topline="true">
24512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24515 \begin_layout Standard
24520 \begin_layout Standard
24534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24537 \begin_layout Standard
24538 MCU Identification (same as above)
24544 <row topline="true" bottomline="true">
24545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24548 \begin_layout Standard
24554 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24557 \begin_layout Standard
24558 nnn = SMALL or LARGE respectively according to the stack model used
24571 \begin_layout Standard
24572 In addition the following macros are defined when calling assembler:
24575 \begin_layout Standard
24577 \begin_inset Tabular
24578 <lyxtabular version="3" rows="4" columns="2">
24580 <column alignment="center" valignment="top" leftline="true" width="0">
24581 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24582 <row topline="true" bottomline="true">
24583 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24586 \begin_layout Standard
24592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24595 \begin_layout Standard
24602 <row topline="true">
24603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24606 \begin_layout Standard
24612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24615 \begin_layout Standard
24616 MCU Identification.
24621 is the microcontrol identification number, i.e.
24628 <row topline="true">
24629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24632 \begin_layout Standard
24638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24641 \begin_layout Standard
24642 nnn = SMALL or LARGE respectively according to the memory model used for
24649 <row topline="true" bottomline="true">
24650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24653 \begin_layout Standard
24659 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24662 \begin_layout Standard
24663 nnn = SMALL or LARGE respectively according to the stack model used
24676 \begin_layout Subsection
24680 \begin_layout Standard
24682 \begin_inset LatexCommand \index{PIC16}
24686 port uses the following directories for searching header files and libraries.
24689 \begin_layout Standard
24691 \begin_inset Tabular
24692 <lyxtabular version="3" rows="3" columns="4">
24694 <column alignment="center" valignment="top" leftline="true" width="0">
24695 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24696 <column alignment="center" valignment="top" width="0">
24697 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24698 <row topline="true" bottomline="true">
24699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24702 \begin_layout Standard
24708 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24711 \begin_layout Standard
24717 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24720 \begin_layout Standard
24726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24729 \begin_layout Standard
24736 <row topline="true">
24737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24740 \begin_layout Standard
24741 PREFIX/sdcc/include/pic16
24746 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24749 \begin_layout Standard
24750 PIC16 specific headers
24755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24758 \begin_layout Standard
24764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24767 \begin_layout Standard
24774 <row topline="true" bottomline="true">
24775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24778 \begin_layout Standard
24779 PREFIX/sdcc/lib/pic16
24784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24787 \begin_layout Standard
24788 PIC16 specific libraries
24793 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24796 \begin_layout Standard
24802 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24805 \begin_layout Standard
24819 \begin_layout Subsection
24821 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
24828 \begin_layout Standard
24830 \begin_inset LatexCommand \index{PIC16}
24834 port currently supports the following pragmas:
24837 \begin_layout Description
24839 \begin_inset LatexCommand \index{PIC16!Pragmas!\\#pragma stack}
24843 This forces the code generator to initialize the stack & frame pointers
24844 at a specific address.
24845 This is an ad hoc solution for cases where no STACK directive is available
24846 in the linker script or gplink is not instructed to create a stack section.
24849 stack pragma should be used only once in a project.
24850 Multiple pragmas may result in indeterminate behaviour of the program.
24854 \begin_layout Standard
24855 The old format (ie.
24856 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
24857 cross page boundaries (or even exceed the available data RAM) and crash
24859 Make sure that stack does not cross page boundaries when using the SMALL
24867 The format is as follows:
24872 \begin_layout LyX-Code
24873 #pragma stack bottom_address [stack_size]
24878 \begin_layout Standard
24883 is the lower bound of the stack section.
24884 The stack pointer initially will point at address (bottom_address+stack_size-1).
24887 \begin_layout LyX-Code
24891 \begin_layout LyX-Code
24895 \begin_layout LyX-Code
24896 /* initializes stack of 100 bytes at RAM address 0x200 */
24899 \begin_layout LyX-Code
24900 #pragma stack 0x200 100
24903 \begin_layout Standard
24904 If the stack_size field is omitted then a stack is created with the default
24906 This size might be enough for most programs, but its not enough for operations
24907 with deep function nesting or excessive stack usage.
24910 \begin_layout Description
24912 \begin_inset LatexCommand \index{PIC16!Pragmas!\\#pragma code}
24916 Force a function to a static FLASH address.
24919 \begin_layout LyX-Code
24923 \begin_layout LyX-Code
24927 \begin_layout LyX-Code
24928 /* place function test_func at 0x4000 */
24931 \begin_layout LyX-Code
24932 #pragma code test_func 0x4000
24935 \begin_layout LyX-Code
24939 \begin_layout Description
24940 library instructs the linker to use a library module.
24945 \begin_layout LyX-Code
24946 #pragma library module_name
24949 \begin_layout Standard
24954 can be any library or object file (including its path).
24955 Note that there are four reserved keywords which have special meaning.
24959 \begin_layout Standard
24961 \begin_inset Tabular
24962 <lyxtabular version="3" rows="6" columns="3">
24964 <column alignment="center" valignment="top" leftline="true" width="0">
24965 <column alignment="block" valignment="top" leftline="true" width="20page%">
24966 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
24967 <row topline="true" bottomline="true">
24968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24971 \begin_layout Standard
24977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24980 \begin_layout Standard
24986 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24989 \begin_layout Standard
24996 <row topline="true">
24997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25000 \begin_layout Standard
25008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25011 \begin_layout Standard
25012 ignore all library pragmas
25017 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25020 \begin_layout Standard
25029 <row topline="true">
25030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25033 \begin_layout Standard
25041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25044 \begin_layout Standard
25050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25053 \begin_layout Standard
25064 <row topline="true">
25065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25068 \begin_layout Standard
25076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25079 \begin_layout Standard
25080 link the Math libarary
25085 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25088 \begin_layout Standard
25099 <row topline="true">
25100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25103 \begin_layout Standard
25111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25114 \begin_layout Standard
25115 link the I/O library
25120 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25123 \begin_layout Standard
25134 <row topline="true" bottomline="true">
25135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25138 \begin_layout Standard
25146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25149 \begin_layout Standard
25150 link the debug library
25155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25158 \begin_layout Standard
25175 * is the device number, i.e.
25176 452 for PIC18F452 MCU.
25179 \begin_layout Standard
25180 This feature allows for linking with specific libraries withoug having to
25181 explicit name them in the command line.
25186 keyword will reject all modules specified by the library pragma.
25189 \begin_layout Description
25190 udata The pragma udata instructs the compiler to emit code so that linker
25191 will place a variable at a specific memory bank.
25194 \begin_layout LyX-Code
25198 \begin_layout LyX-Code
25202 \begin_layout LyX-Code
25203 /* places variable foo at bank2 */
25206 \begin_layout LyX-Code
25207 #pragma udata bank2 foo
25210 \begin_layout LyX-Code
25214 \begin_layout Standard
25215 In order for this pragma to work extra SECTION directives should be added
25216 in the .lkr script.
25217 In the following example a sample .lkr file is shown:
25220 \begin_layout LyX-Code
25224 \begin_layout LyX-Code
25225 // Sample linker script for the PIC18F452 processor
25228 \begin_layout LyX-Code
25232 \begin_layout LyX-Code
25233 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
25236 \begin_layout LyX-Code
25237 CODEPAGE NAME=page START=0x2A END=0x7FFF
25240 \begin_layout LyX-Code
25241 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
25244 \begin_layout LyX-Code
25245 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
25248 \begin_layout LyX-Code
25249 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
25252 \begin_layout LyX-Code
25253 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
25256 \begin_layout LyX-Code
25257 ACCESSBANK NAME=accessram START=0x0 END=0x7F
25260 \begin_layout LyX-Code
25264 \begin_layout LyX-Code
25265 DATABANK NAME=gpr0 START=0x80 END=0xFF
25268 \begin_layout LyX-Code
25269 DATABANK NAME=gpr1 START=0x100 END=0x1FF
25272 \begin_layout LyX-Code
25273 DATABANK NAME=gpr2 START=0x200 END=0x2FF
25276 \begin_layout LyX-Code
25277 DATABANK NAME=gpr3 START=0x300 END=0x3FF
25280 \begin_layout LyX-Code
25281 DATABANK NAME=gpr4 START=0x400 END=0x4FF
25284 \begin_layout LyX-Code
25285 DATABANK NAME=gpr5 START=0x500 END=0x5FF
25288 \begin_layout LyX-Code
25289 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
25292 \begin_layout LyX-Code
25296 \begin_layout LyX-Code
25297 SECTION NAME=CONFIG ROM=config
25300 \begin_layout LyX-Code
25304 \begin_layout LyX-Code
25305 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
25308 \begin_layout LyX-Code
25309 SECTION NAME=bank1 RAM=gpr1 # should be added to link
25312 \begin_layout LyX-Code
25313 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
25316 \begin_layout LyX-Code
25317 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
25320 \begin_layout LyX-Code
25321 SECTION NAME=bank4 RAM=gpr4
25324 \begin_layout LyX-Code
25325 SECTION NAME=bank5 RAM=gpr5
25328 \begin_layout Standard
25329 The linker will recognise the section name set in the pragma statement and
25330 will position the variable at the memory bank set with the RAM field at
25331 the SECTION line in the linker script file.
25334 \begin_layout Subsection
25336 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
25343 \begin_layout Standard
25344 There is one main header file
25345 \begin_inset LatexCommand \index{PIC16!Header files}
25349 that can be included to the source files using the pic16
25350 \begin_inset LatexCommand \index{PIC16}
25360 This header file contains the definitions for the processor special registers,
25361 so it is necessary if the source accesses them.
25362 It can be included by adding the following line in the beginning of the
25366 \begin_layout LyX-Code
25367 #include <pic18fregs.h>
25370 \begin_layout Standard
25371 The specific microcontroller is selected within the pic18fregs.h automatically,
25372 so the same source can be used with a variety of devices.
25375 \begin_layout Subsection
25379 \begin_layout Standard
25381 \begin_inset LatexCommand \index{PIC16!Libraries}
25386 \begin_inset LatexCommand \index{PIC16}
25390 port depends on are the microcontroller device libraries which contain
25391 the symbol definitions for the microcontroller special function registers.
25392 These libraries have the format pic18fxxxx.lib, where
25396 is the microcontroller identification number.
25397 The specific library is selected automatically by the compiler at link
25398 stage according to the selected device.
25401 \begin_layout Standard
25402 Libraries are created with gplib which is part of the gputils package
25403 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
25410 \begin_layout Subsubsection*
25411 Building the libraries
25414 \begin_layout Standard
25415 Before using SDCC/pic16 there are some libraries that need to be compiled.
25416 This process is not done automatically by SDCC since not all users use
25417 SDCC for pic16 projects.
25418 So each user should compile the libraries separately.
25421 \begin_layout Standard
25422 The steps to compile the pic16 libraries under Linux and Mac OS X are:
25425 \begin_layout LyX-Code
25426 cd device/lib/pic16
25429 \begin_layout LyX-Code
25433 \begin_layout LyX-Code
25437 \begin_layout LyX-Code
25441 \begin_layout LyX-Code
25445 \begin_layout LyX-Code
25446 su -c 'make install' # install the libraries, you need the root password
25449 \begin_layout Standard
25450 If you need to install the headers too, do:
25453 \begin_layout LyX-Code
25457 \begin_layout LyX-Code
25458 su -c 'make install' # install the headers, you need the root password
25461 \begin_layout Standard
25462 There exist a special target to build the I/O libraries.
25463 This target is not automatically build because it will build the I/O library
25469 This way building will take quite a lot of time.
25470 Users are advised to edit the
25472 device/lib/pic16/pics.build
25474 file and then execute:
25477 \begin_layout LyX-Code
25481 \begin_layout Subsection
25482 Adding New Devices to the Port
25485 \begin_layout Standard
25486 Adding support for a new 16
25490 \begin_layout Standard
25499 bit PIC MCU requires the following steps:
25502 \begin_layout Enumerate
25503 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
25507 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
25511 \begin_layout Enumerate
25514 mv picDEVICE.h /path/to/sdcc/device/include/pic16
25517 \begin_layout Enumerate
25520 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
25523 \begin_layout Enumerate
25526 /path/to/sdcc/device/lib/pics.all
25534 Note: No 18f prefix here!
25537 \begin_layout Enumerate
25540 /path/to/sdcc/device/lib/pic16/libio/*.ignore
25544 Add your DEVICE if it does not compile in
25559 \begin_layout Enumerate
25562 /path/to/sdcc/device/include/pic16/pic18fregs.h
25565 The file format is self-explanatory, just add
25569 #elif defined(picDEVICE)
25571 # include <picDEVICE.h>
25575 at the right place (keep it sorted).
25578 \begin_layout Enumerate
25581 /path/to/sdcc/src/pic16/devices.inc
25584 Copy and modify an existing entry and insert it at the correct place (keep
25586 The file is hardly documented, look at the entries for the 18f2221...
25589 \begin_layout Enumerate
25590 Recompile SDCC, including the pic16 libraries.
25593 \begin_layout Subsection
25597 \begin_layout Standard
25598 The following memory models are supported by the PIC16 port:
25601 \begin_layout Itemize
25605 \begin_layout Itemize
25609 \begin_layout Standard
25610 Memory model affects the default size of pointers within the source.
25611 The sizes are shown in the next table:
25614 \begin_layout Standard
25616 \begin_inset Tabular
25617 <lyxtabular version="3" rows="3" columns="3">
25619 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25620 <column alignment="center" valignment="top" leftline="true" width="0">
25621 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25622 <row topline="true" bottomline="true">
25623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25626 \begin_layout Standard
25627 Pointer sizes according to memory model
25632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25635 \begin_layout Standard
25641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25644 \begin_layout Standard
25651 <row topline="true" bottomline="true">
25652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25655 \begin_layout Standard
25661 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25664 \begin_layout Standard
25670 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25673 \begin_layout Standard
25680 <row topline="true" bottomline="true">
25681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25684 \begin_layout Standard
25690 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
25693 \begin_layout Standard
25699 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25702 \begin_layout Standard
25716 \begin_layout Standard
25717 It is advisable that all sources within a project are compiled with the
25719 If one wants to override the default memory model, this can be done by
25720 declaring a pointer as
25729 Far selects large memory model's pointers, while near selects small memory
25733 \begin_layout Standard
25734 The standard device libraries (see
25735 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
25739 ) contain no reference to pointers, so they can be used with both memory
25743 \begin_layout Subsection
25747 \begin_layout Standard
25749 \begin_inset LatexCommand \index{PIC16!stack}
25753 implementation for the PIC16 port uses two indirect registers, FSR1 and
25757 \begin_layout Description
25758 FSR1 is assigned as stack pointer
25761 \begin_layout Description
25762 FSR2 is assigned as frame pointer
25765 \begin_layout Standard
25766 The following stack models are supported by the PIC16 port
25769 \begin_layout Itemize
25777 \begin_layout Itemize
25785 \begin_layout Standard
25790 model means that only the FSRxL byte is used to access stack and frame,
25797 uses both FSRxL and FSRxH registers.
25798 The following table shows the stack/frame pointers sizes according to stack
25799 model and the maximum space they can address:
25802 \begin_layout Standard
25804 \begin_inset Tabular
25805 <lyxtabular version="3" rows="3" columns="3">
25807 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25808 <column alignment="center" valignment="top" leftline="true" width="0">
25809 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25810 <row topline="true" bottomline="true">
25811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25814 \begin_layout Standard
25815 Stack & Frame pointer sizes according to stack model
25820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25823 \begin_layout Standard
25829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25832 \begin_layout Standard
25839 <row topline="true">
25840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25843 \begin_layout Standard
25849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25852 \begin_layout Standard
25858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25861 \begin_layout Standard
25868 <row topline="true" bottomline="true">
25869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25872 \begin_layout Standard
25878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25881 \begin_layout Standard
25887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25890 \begin_layout Standard
25904 \begin_layout Standard
25909 stack model is currently not working properly throughout the code generator.
25910 So its use is not advised.
25911 Also there are some other points that need special care:
25916 \begin_layout Enumerate
25917 Do not create stack sections with size more than one physical bank (that
25921 \begin_layout Enumerate
25922 Stack sections should no cross physical bank limits (i.e.
25923 #pragma stack 0x50 0x100)
25926 \begin_layout Standard
25927 These limitations are caused by the fact that only FSRxL is modified when
25928 using SMALL stack model, so no more than 256 bytes of stack can be used.
25929 This problem will disappear after LARGE model is fully implemented.
25932 \begin_layout Subsection
25936 \begin_layout Standard
25937 In addition to the standard SDCC function keywords, PIC16
25938 \begin_inset LatexCommand \index{PIC16}
25942 port makes available two more:
25945 \begin_layout Description
25947 \begin_inset LatexCommand \index{PIC16!wparam}
25951 Use the WREG to pass one byte of the first function argument.
25952 This improves speed but you may not use this for functions with arguments
25953 that are called via function pointers, otherwise the first byte of the
25954 first parameter will get lost.
25958 \begin_layout LyX-Code
25959 void func_wparam(int a) wparam
25962 \begin_layout LyX-Code
25966 \begin_layout LyX-Code
25967 /* WREG hold the lower part of a */
25970 \begin_layout LyX-Code
25971 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
25975 \begin_layout LyX-Code
25979 \begin_layout LyX-Code
25983 \begin_layout Description
25985 \begin_inset LatexCommand \index{PIC16!shadowregs}
25989 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
25990 hardware shadow registers which hold the values of WREG, STATUS and BSR
25992 This can be done by adding the keyword
26000 keyword in the function's header.
26003 \begin_layout LyX-Code
26004 void isr_shadow(void) shadowregs interrupt 1
26007 \begin_layout LyX-Code
26011 \begin_layout LyX-Code
26015 \begin_layout LyX-Code
26019 \begin_layout Standard
26024 instructs the code generator not to store/restore WREG, STATUS, BSR when
26025 entering/exiting the ISR.
26028 \begin_layout Subsection
26029 Function return values
26032 \begin_layout Standard
26033 Return values from functions are placed to the appropriate registers following
26034 a modified Microchip policy optimized for SDCC.
26035 The following table shows these registers:
26038 \begin_layout Standard
26040 \begin_inset Tabular
26041 <lyxtabular version="3" rows="6" columns="2">
26043 <column alignment="center" valignment="top" leftline="true" width="0">
26044 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26045 <row topline="true" bottomline="true">
26046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26049 \begin_layout Standard
26055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26058 \begin_layout Standard
26059 destination register
26065 <row topline="true">
26066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26069 \begin_layout Standard
26075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26078 \begin_layout Standard
26085 <row topline="true">
26086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26089 \begin_layout Standard
26095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26098 \begin_layout Standard
26105 <row topline="true">
26106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26109 \begin_layout Standard
26115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26118 \begin_layout Standard
26125 <row topline="true">
26126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26129 \begin_layout Standard
26135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26138 \begin_layout Standard
26139 FSR0L:PRODH:PRODL:WREG
26145 <row topline="true" bottomline="true">
26146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26149 \begin_layout Standard
26155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26158 \begin_layout Standard
26159 on stack, FSR0 points to the beginning
26172 \begin_layout Subsection
26176 \begin_layout Standard
26178 \begin_inset LatexCommand \index{PIC16!interrupt}
26182 service routine (ISR) is declared using the
26189 \begin_layout LyX-Code
26190 void isr(void) interrupt
26195 \begin_layout LyX-Code
26199 \begin_layout LyX-Code
26203 \begin_layout LyX-Code
26207 \begin_layout Standard
26212 is the interrupt number, which for PIC18F devices can be:
26215 \begin_layout Standard
26217 \begin_inset Tabular
26218 <lyxtabular version="3" rows="4" columns="3">
26220 <column alignment="center" valignment="top" leftline="true" width="0">
26221 <column alignment="center" valignment="top" leftline="true" width="0">
26222 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26223 <row topline="true" bottomline="true">
26224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26227 \begin_layout Standard
26235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26238 \begin_layout Standard
26244 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26247 \begin_layout Standard
26248 Interrupt Vector Address
26254 <row topline="true">
26255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26258 \begin_layout Standard
26264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26267 \begin_layout Standard
26273 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26276 \begin_layout Standard
26283 <row topline="true">
26284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26287 \begin_layout Standard
26302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26305 \begin_layout Standard
26315 HIGH priority interrupts
26320 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26323 \begin_layout Standard
26330 <row topline="true" bottomline="true">
26331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26334 \begin_layout Standard
26340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26343 \begin_layout Standard
26344 LOW priority interrupts
26349 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26352 \begin_layout Standard
26366 \begin_layout Standard
26367 When generating assembly code for ISR the code generator places a
26373 Interrupt Vector Address
26375 which points at the genetated ISR.
26376 This single GOTO instruction is part of an automatically generated
26378 interrupt entry point
26381 The actuall ISR code is placed as normally would in the code space.
26382 Upon interrupt request, the GOTO instruction is executed which jumps to
26384 When declaring interrupt functions as _naked this GOTO instruction is
26389 The whole interrupt functions is therefore placed at the Interrupt Vector
26390 Address of the specific interrupt.
26391 This is not a problem for the LOW priority interrupts, but it is a problem
26392 for the RESET and the HIGH priority interrupts because code may be written
26393 at the next interrupt's vector address and cause undeterminate program
26394 behaviour if that interrupt is raised.
26398 \begin_layout Standard
26399 This is not a problem when
26402 \begin_layout Enumerate
26403 this is a HIGH interrupt ISR and LOW interrupts are
26410 \begin_layout Enumerate
26411 when the ISR is small enough not to reach the next interrupt's vector address.
26419 \begin_layout Standard
26425 This way a function is generated similar to an ISR, but it is not assigned
26429 \begin_layout Standard
26430 When entering an interrupt, currently the PIC16
26431 \begin_inset LatexCommand \index{PIC16}
26435 port automatically saves the following registers:
26438 \begin_layout Itemize
26442 \begin_layout Itemize
26446 \begin_layout Itemize
26450 \begin_layout Itemize
26451 PROD (PRODL and PRODH)
26454 \begin_layout Itemize
26455 FSR0 (FSR0L and FSR0H)
26458 \begin_layout Standard
26459 These registers are restored upon return from the interrupt routine.
26463 \begin_layout Standard
26464 NOTE that when the _naked attribute is specified for an interrupt routine,
26465 then NO registers are stored or restored.
26473 \begin_layout Subsection
26477 \begin_layout Standard
26478 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
26479 There are 3 types of generic pointers currently implemented data, code
26480 and eeprom pointers.
26481 They are differentiated by the value of the 7th and 6th bits of the upper
26485 \begin_layout Standard
26487 \begin_inset Tabular
26488 <lyxtabular version="3" rows="5" columns="5">
26490 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26491 <column alignment="center" valignment="top" width="0">
26492 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26493 <column alignment="center" valignment="top" width="0">
26494 <column alignment="left" valignment="top" rightline="true" width="0">
26495 <row topline="true" bottomline="true">
26496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26499 \begin_layout Standard
26505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26508 \begin_layout Standard
26514 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26517 \begin_layout Standard
26523 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26526 \begin_layout Standard
26527 rest of the pointer
26532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26535 \begin_layout Standard
26542 <row topline="true" bottomline="true">
26543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26546 \begin_layout Standard
26552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26555 \begin_layout Standard
26561 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26564 \begin_layout Standard
26570 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26573 \begin_layout Standard
26578 uuuuuu uuuuxxxx xxxxxxxx
26583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26586 \begin_layout Standard
26587 a 12-bit data pointer in data RAM memory
26593 <row bottomline="true">
26594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26597 \begin_layout Standard
26603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26606 \begin_layout Standard
26612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26615 \begin_layout Standard
26621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26624 \begin_layout Standard
26629 uxxxxx xxxxxxxx xxxxxxxx
26634 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26637 \begin_layout Standard
26638 a 21-bit code pointer in FLASH memory
26644 <row bottomline="true">
26645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26648 \begin_layout Standard
26654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26657 \begin_layout Standard
26663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26666 \begin_layout Standard
26672 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26675 \begin_layout Standard
26680 uuuuuu uuuuuuxx xxxxxxxx
26685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26688 \begin_layout Standard
26689 a 10-bit eeprom pointer in EEPROM memory
26695 <row bottomline="true">
26696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26699 \begin_layout Standard
26705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26708 \begin_layout Standard
26714 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26717 \begin_layout Standard
26723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26726 \begin_layout Standard
26731 xxxxxx xxxxxxxx xxxxxxxx
26736 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26739 \begin_layout Standard
26740 unimplemented pointer type
26753 \begin_layout Standard
26754 Generic pointer are read and written with a set of library functions which
26755 read/write 1, 2, 3, 4 bytes.
26758 \begin_layout Subsection
26762 \begin_layout Subsubsection
26763 Standard I/O Streams
26766 \begin_layout Standard
26771 the type FILE is defined as:
26774 \begin_layout LyX-Code
26775 typedef char * FILE;
26778 \begin_layout Standard
26779 This type is the stream type implemented I/O in the PIC18F devices.
26780 Also the standard input and output streams are declared in stdio.h:
26783 \begin_layout LyX-Code
26784 extern FILE * stdin;
26787 \begin_layout LyX-Code
26788 extern FILE * stdout;
26791 \begin_layout Standard
26792 The FILE type is actually a generic pointer which defines one more type
26793 of generic pointers, the
26798 This new type has the format:
26801 \begin_layout Standard
26803 \begin_inset Tabular
26804 <lyxtabular version="3" rows="2" columns="7">
26806 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26807 <column alignment="center" valignment="top" width="0">
26808 <column alignment="center" valignment="top" leftline="true" width="0">
26809 <column alignment="center" valignment="top" leftline="true" width="0">
26810 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26811 <column alignment="center" valignment="top" width="0">
26812 <column alignment="left" valignment="top" rightline="true" width="0">
26813 <row topline="true" bottomline="true">
26814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26817 \begin_layout Standard
26823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26826 \begin_layout Standard
26832 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26835 \begin_layout Standard
26841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26844 \begin_layout Standard
26850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26853 \begin_layout Standard
26859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26862 \begin_layout Standard
26863 rest of the pointer
26868 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26871 \begin_layout Standard
26878 <row topline="true" bottomline="true">
26879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26882 \begin_layout Standard
26888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26891 \begin_layout Standard
26897 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26900 \begin_layout Standard
26906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26909 \begin_layout Standard
26915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26918 \begin_layout Standard
26924 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26927 \begin_layout Standard
26937 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26940 \begin_layout Standard
26941 upper byte high nubble is 0x2n, the rest are zeroes
26954 \begin_layout Standard
26955 Currently implemented there are 3 types of streams defined:
26958 \begin_layout Standard
26960 \begin_inset Tabular
26961 <lyxtabular version="3" rows="4" columns="4">
26963 <column alignment="center" valignment="top" leftline="true" width="0">
26964 <column alignment="center" valignment="top" leftline="true" width="0">
26965 <column alignment="center" valignment="top" leftline="true" width="0">
26966 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26967 <row topline="true" bottomline="true">
26968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26971 \begin_layout Standard
26977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26980 \begin_layout Standard
26986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26989 \begin_layout Standard
26995 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26998 \begin_layout Standard
27005 <row topline="true">
27006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27009 \begin_layout Standard
27015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27018 \begin_layout Standard
27026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27029 \begin_layout Standard
27035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27038 \begin_layout Standard
27039 Writes/Reads characters via the USART peripheral
27045 <row topline="true">
27046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27049 \begin_layout Standard
27055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27058 \begin_layout Standard
27066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27069 \begin_layout Standard
27075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27078 \begin_layout Standard
27079 Writes/Reads characters via the MSSP peripheral
27085 <row topline="true" bottomline="true">
27086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27089 \begin_layout Standard
27095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27098 \begin_layout Standard
27106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27109 \begin_layout Standard
27115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27118 \begin_layout Standard
27119 Writes/Reads characters via used defined functions
27132 \begin_layout Standard
27133 The stream identifiers are declared as macros in the stdio.h header.
27136 \begin_layout Standard
27137 In the libc library there exist the functions that are used to write to
27138 each of the above streams.
27142 \begin_layout Description
27147 \begin_layout Standard
27156 _stream_usart_putchar writes a character at the USART stream
27159 \begin_layout Description
27164 \begin_layout Standard
27173 _stream_mssp_putchar writes a character at the MSSP stream
27176 \begin_layout Description
27177 putchar dummy function.
27178 This writes a character to a user specified manner.
27181 \begin_layout Standard
27182 In order to increase performance
27186 is declared in stdio.h as having its parameter in WREG (it has the wparam
27188 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
27189 in a user-friendly way.
27194 is the name of the variable that holds the character to print.
27195 An example follows:
27198 \begin_layout LyX-Code
27199 #include <pic18fregs.h>
27208 \begin_layout LyX-Code
27212 \begin_layout LyX-Code
27213 PORTA = c; /* dump character c to PORTA */
27216 \begin_layout LyX-Code
27224 \begin_layout LyX-Code
27228 \begin_layout LyX-Code
27229 stdout = STREAM_USER; /* this is not necessary, since stdout points
27232 \begin_layout LyX-Code
27233 * by default to STREAM_USER */
27236 \begin_layout LyX-Code
27238 \begin_inset Quotes sld
27241 This is a printf test
27244 \begin_inset Quotes srd
27250 \begin_layout LyX-Code
27254 \begin_layout LyX-Code
27258 \begin_layout Subsubsection
27262 \begin_layout Standard
27263 PIC16 contains an implementation of the printf-family of functions.
27264 There exist the following functions:
27267 \begin_layout LyX-Code
27268 extern unsigned int sprintf(char *buf, char *fmt, ...);
27271 \begin_layout LyX-Code
27272 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
27275 \begin_layout LyX-Code
27279 \begin_layout LyX-Code
27280 extern unsigned int printf(char *fmt, ...);
27283 \begin_layout LyX-Code
27284 extern unsigned int vprintf(char *fmt, va_lista ap);
27287 \begin_layout LyX-Code
27291 \begin_layout LyX-Code
27292 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
27295 \begin_layout LyX-Code
27296 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
27299 \begin_layout Standard
27300 For sprintf and vsprintf
27304 should normally be a data pointer where the resulting string will be placed.
27305 No range checking is done so the user should allocate the necessery buffer.
27306 For fprintf and vfprintf
27310 should be a stream pointer (i.e.
27311 stdout, STREAM_MSSP, etc...).
27314 \begin_layout Subsubsection
27318 \begin_layout Standard
27319 The PIC18F family of microcontrollers supports a number of interrupt sources.
27320 A list of these interrupts is shown in the following table:
27323 \begin_layout Standard
27325 \begin_inset Tabular
27326 <lyxtabular version="3" rows="11" columns="4">
27328 <column alignment="left" valignment="top" leftline="true" width="0">
27329 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27330 <column alignment="left" valignment="top" leftline="true" width="0">
27331 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27332 <row topline="true" bottomline="true">
27333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27336 \begin_layout Standard
27342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27345 \begin_layout Standard
27351 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27354 \begin_layout Standard
27360 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27363 \begin_layout Standard
27370 <row topline="true">
27371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27374 \begin_layout Standard
27380 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27383 \begin_layout Standard
27384 PORTB change interrupt
27389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27392 \begin_layout Standard
27398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27401 \begin_layout Standard
27402 EEPROM/FLASH write complete interrupt
27408 <row topline="true">
27409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27412 \begin_layout Standard
27418 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27421 \begin_layout Standard
27422 INT0 external interrupt
27427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27430 \begin_layout Standard
27436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27439 \begin_layout Standard
27440 Bus collision interrupt
27446 <row topline="true">
27447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27450 \begin_layout Standard
27456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27459 \begin_layout Standard
27460 INT1 external interrupt
27465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27468 \begin_layout Standard
27474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27477 \begin_layout Standard
27478 Low voltage detect interrupt
27484 <row topline="true">
27485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27488 \begin_layout Standard
27494 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27497 \begin_layout Standard
27498 INT2 external interrupt
27503 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27506 \begin_layout Standard
27512 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27515 \begin_layout Standard
27516 Parallel slave port interrupt
27522 <row topline="true">
27523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27526 \begin_layout Standard
27532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27535 \begin_layout Standard
27536 CCP1 module interrupt
27541 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27544 \begin_layout Standard
27550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27553 \begin_layout Standard
27554 AD convertion complete interrupt
27560 <row topline="true">
27561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27564 \begin_layout Standard
27570 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27573 \begin_layout Standard
27574 CCP2 module interrupt
27579 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27582 \begin_layout Standard
27588 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27591 \begin_layout Standard
27592 USART receive interrupt
27598 <row topline="true">
27599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27602 \begin_layout Standard
27608 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27611 \begin_layout Standard
27612 TMR0 overflow interrupt
27617 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27620 \begin_layout Standard
27626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27629 \begin_layout Standard
27630 USART transmit interrupt
27636 <row topline="true">
27637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27640 \begin_layout Standard
27646 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27649 \begin_layout Standard
27650 TMR1 overflow interrupt
27655 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27658 \begin_layout Standard
27664 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27667 \begin_layout Standard
27668 SSP receive/transmit interrupt
27674 <row topline="true">
27675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27678 \begin_layout Standard
27684 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27687 \begin_layout Standard
27688 TMR2 matches PR2 interrupt
27693 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27696 \begin_layout Standard
27702 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27705 \begin_layout Standard
27712 <row topline="true" bottomline="true">
27713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27716 \begin_layout Standard
27722 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27725 \begin_layout Standard
27726 TMR3 overflow interrupt
27731 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27734 \begin_layout Standard
27740 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27743 \begin_layout Standard
27757 \begin_layout Standard
27758 The prototypes for these names are defined in the header file
27765 \begin_layout Standard
27766 In order to simplify signal handling, a number of macros is provided:
27770 \labelwidthstring 00.00.0000
27771 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
27772 high priority interrupts.
27777 is the function name to use.
27781 \labelwidthstring 00.00.0000
27782 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
27783 low priority interrupt.
27788 is the function name to use.
27792 \labelwidthstring 00.00.0000
27793 DEF_HANDLER(sig,handler) define a handler for signal
27799 \labelwidthstring 00.00.0000
27800 END_DEF end the declaration of the dispatch table.
27803 \begin_layout Standard
27804 Additionally there are two more macros to simplify the declaration of the
27809 \labelwidthstring 00.00.0000
27812 SIGHANDLER(handler)
27814 this declares the function prototype for the
27822 \labelwidthstring 00.00.0000
27823 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
27826 \begin_layout Standard
27827 An example of using the macros above is shown below:
27830 \begin_layout LyX-Code
27831 #include <pic18fregs.h>
27834 \begin_layout LyX-Code
27835 #include <signal.h>
27839 DEF_INTHIGH(high_int)
27842 \begin_layout LyX-Code
27843 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
27846 \begin_layout LyX-Code
27847 DEF_HANDLER(SIG_BCOL, _bcol_handler)
27850 \begin_layout LyX-Code
27855 SIGHANDLER(_tmr0_handler)
27858 \begin_layout LyX-Code
27862 \begin_layout LyX-Code
27863 /* action to be taken when timer 0 overflows */
27866 \begin_layout LyX-Code
27871 SIGHANDLERNAKED(_bcol_handler)
27874 \begin_layout LyX-Code
27878 \begin_layout LyX-Code
27882 \begin_layout LyX-Code
27883 /* action to be taken when bus collision occurs */
27886 \begin_layout LyX-Code
27890 \begin_layout LyX-Code
27894 \begin_layout LyX-Code
27898 \begin_layout Standard
27903 Special care should be taken when using the above scheme:
27906 \begin_layout Itemize
27907 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
27910 \begin_layout Itemize
27911 when declaring SIGHANDLERNAKED handler never forget to use
27915 for proper returning.
27918 \begin_layout Subsection
27922 \begin_layout Standard
27923 Here you can find some general tips for compiling programs with SDCC/pic16.
27926 \begin_layout Subsubsection
27930 \begin_layout Standard
27932 \begin_inset LatexCommand \index{PIC16!stack}
27936 size (that is 64 bytes) probably is enough for many programs.
27937 One must take care that when there are many levels of function nesting,
27938 or there is excessive usage of stack, its size should be extended.
27939 An example of such a case is the printf/sprintf family of functions.
27940 If you encounter problems like not being able to print integers, then you
27941 need to set the stack size around the maximum (256 for small stack model).
27942 The following diagram shows what happens when calling printf to print an
27946 \begin_layout LyX-Code
27947 printf () --> ltoa () --> ultoa () --> divschar ()
27950 \begin_layout Standard
27951 It is should be understood that stack is easily consumed when calling complicate
27953 Using command line arguments like -
27957 \begin_layout Standard
27966 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
27968 Other ways to reduce stack usage may exist.
27971 \begin_layout Subsection
27975 \begin_layout Standard
27976 The PIC16 Port currently does not pass SDCC's regression test
27977 \begin_inset LatexCommand \index{Regression test (PIC16)}
27982 \begin_inset LatexCommand \ref{sec:Quality-control}
27986 ) and thus the snapshot build regression tests for the PIC16 target are
27987 currently disabled for all hosts
27992 \begin_layout Chapter
27996 \begin_layout Standard
27997 There are several approaches to debugging your code.
27998 This chapter is meant to show your options and to give detail on some of
28003 When writing your code:
28006 \begin_layout Itemize
28007 write your code with debugging in mind (avoid duplicating code, put conceptually
28008 similar variables into structs, use structured code, have strategic points
28009 within your code where all variables are consistent, ...)
28012 \begin_layout Itemize
28013 run a syntax-checking tool like splint
28014 \begin_inset LatexCommand \index{splint (syntax checking tool)}
28019 \begin_inset LatexCommand \index{lint (syntax checking tool)}
28027 \begin_layout Standard
28037 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28044 \begin_layout Itemize
28045 for the high level code use a C-compiler (like f.e.
28046 GCC) to compile run and debug the code on your host.
28051 \begin_layout Standard
28061 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28065 ) on how to handle syntax extensions like __xdata, __at(), ...
28069 \begin_layout Itemize
28070 use another C-compiler to compile code for your target.
28071 Always an option but not recommended:) And not very likely to help you.
28072 If you seriously consider walking this path you should at least occasionally
28073 check portability of your code.
28074 Most commercial compiler vendors will offer an evaluation version so you
28075 can test compile your code or snippets of your code.
28078 \begin_layout Standard
28079 Debugging on a simulator:
28082 \begin_layout Itemize
28083 there is a separate section about SDCDB (section
28084 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
28091 \begin_layout Itemize
28092 or (8051 specific) use a freeware/commercial simulator which interfaces
28094 \begin_inset LatexCommand \index{AOMF, AOMF51}
28099 \begin_inset LatexCommand \ref{OMF file}
28103 ) optionally generated by SDCC.
28106 \begin_layout Standard
28107 Debugging On-target:
28110 \begin_layout Itemize
28111 use a MCU port pin to serially output debug data to the RS232 port of your
28113 You'll probably want some level shifting device typically involving a MAX232
28115 If the hardware serial port of the MCU is not available search for 'Software
28116 UART' in your favourite search machine.
28119 \begin_layout Itemize
28120 use an on-target monitor.
28121 In this context a monitor is a small program which usually accepts commands
28122 via a serial line and allows to set program counter, to single step through
28123 a program and read/write memory locations.
28124 For the 8051 good examples of monitors are paulmon and cmon51 (see section
28126 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
28133 \begin_layout Itemize
28134 toggle MCU port pins at strategic points within your code and use an oscilloscop
28138 digital oscilloscope
28141 \begin_inset LatexCommand \index{Oscilloscope}
28145 with deep trace memory is really helpful especially if you have to debug
28146 a realtime application.
28147 If you need to monitor more pins than your oscilloscope provides you can
28148 sometimes get away with a small R-2R network.
28149 On a single channel oscilloscope you could f.e.
28150 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
28152 \begin_inset Formula $\Omega$
28155 resistor and the other one by a 5\InsetSpace ~
28157 \begin_inset Formula $\Omega$
28160 resistor to the oscilloscope probe (check output drive capability of the
28161 pins you want to monitor).
28162 If you need to monitor many more pins a
28169 \begin_layout Itemize
28183 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
28188 Usually very expensive.
28189 And very nice to have too.
28190 And usually locks you (for years...) to the devices the ICE can emulate.
28194 \begin_layout Itemize
28195 use a remote debugger.
28196 In most 8-bit systems the symbol information is not available on the target,
28197 and a complete debugger is too bulky for the target system.
28198 Therefore usually a debugger on the host system connects to an on-target
28199 debugging stub which accepts only primitive commands.
28202 Terms to enter into your favourite search engine could be 'remote debugging',
28203 'gdb stub' or 'inferior debugger'.
28207 \begin_layout Itemize
28208 use an on target hardware debugger.
28209 Some of the more modern MCUs include hardware support for setting break
28210 points and monitoring/changing variables by using dedicated hardware pins.
28211 This facility doesn't require additional code to run on the target and
28216 doesn't affect runtime behaviour until a breakpoint is hit.
28217 For the mcs51 most hardware debuggers use the AOMF
28218 \begin_inset LatexCommand \index{AOMF, AOMF51}
28223 \begin_inset LatexCommand \ref{OMF file}
28231 \begin_layout Standard
28235 \begin_layout Itemize
28236 if you are not familiar with any of the following terms you're likely to
28237 run into problems rather sooner than later:
28254 As an embedded programmer you
28258 to know them so why not look them up
28262 you have problems?)
28265 \begin_layout Itemize
28266 tell someone else about your problem (actually this is a surprisingly effective
28267 means to hunt down the bug even if the listener is not familiar with your
28269 As 'failure to communicate' is probably one of the job-induced deformations
28270 of an embedded programmer this is highly encouraged.
28273 \begin_layout Section
28274 Debugging with SDCDB
28275 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
28280 \begin_inset LatexCommand \index{SDCDB (debugger)}
28287 \begin_layout Standard
28288 SDCC is distributed with a source level debugger
28289 \begin_inset LatexCommand \index{Debugger}
28294 The debugger uses a command line interface, the command repertoire of the
28295 debugger has been kept as close to gdb
28296 \begin_inset LatexCommand \index{gdb}
28300 (the GNU debugger) as possible.
28301 The configuration and build process is part of the standard compiler installati
28302 on, which also builds and installs the debugger in the target directory
28303 specified during configuration.
28304 The debugger allows you debug BOTH at the C source and at the ASM source
28308 \begin_layout Subsection
28309 Compiling for Debugging
28312 \begin_layout Standard
28317 \begin_layout Standard
28327 \begin_inset LatexCommand \index{-\\/-debug}
28331 option must be specified for all files for which debug information is to
28333 The compiler generates a .adb file for each of these files.
28334 The linker creates the .cdb
28335 \begin_inset LatexCommand \index{<file>.cdb}
28340 \begin_inset LatexCommand \index{<file>.adb}
28344 files and the address information.
28345 This .cdb is used by the debugger.
28348 \begin_layout Subsection
28349 How the Debugger Works
28352 \begin_layout Standard
28357 \begin_layout Standard
28366 -debug option is specified the compiler generates extra symbol information
28367 some of which are put into the assembler source and some are put into the
28369 Then the linker creates the .cdb file from the individual .adb files with
28370 the address information for the symbols.
28371 The debugger reads the symbolic information generated by the compiler &
28372 the address information generated by the linker.
28373 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
28374 execution is controlled by the debugger.
28375 When a command is issued for the debugger, it translates it into appropriate
28376 commands for the simulator.
28377 (Currently SDCDM only connects to the simulator but
28382 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
28386 is an effort to connect directly to the hardware.)
28389 \begin_layout Subsection
28390 Starting the Debugger SDCDB
28393 \begin_layout Standard
28394 The debugger can be started using the following command line.
28395 (Assume the file you are debugging has the file name foo).
28409 The debugger will look for the following files.
28412 \begin_layout Itemize
28413 foo.c - the source file.
28416 \begin_layout Itemize
28417 foo.cdb - the debugger symbol information file.
28420 \begin_layout Itemize
28421 foo.ihx - the Intel hex format
28422 \begin_inset LatexCommand \index{Intel hex format}
28429 \begin_layout Subsection
28430 SDCDB Command Line Options
28433 \begin_layout Itemize
28438 \begin_layout Standard
28447 -directory=<source file directory> this option can used to specify the directory
28449 The debugger will look into the directory list specified for source, cdb
28451 The items in the directory list must be separated by ':', e.g.
28452 if the source files can be in the directories /home/src1 and /home/src2,
28457 \begin_layout Standard
28466 -directory option should be -
28470 \begin_layout Standard
28479 -directory=/home/src1:/home/src2.
28480 Note there can be no spaces in the option.
28484 \begin_layout Itemize
28485 -cd <directory> - change to the <directory>.
28488 \begin_layout Itemize
28489 -fullname - used by GUI front ends.
28492 \begin_layout Itemize
28493 -cpu <cpu-type> - this argument is passed to the simulator please see the
28494 simulator docs for details.
28497 \begin_layout Itemize
28498 -X <Clock frequency > this options is passed to the simulator please see
28499 the simulator docs for details.
28502 \begin_layout Itemize
28503 -s <serial port file> passed to simulator see the simulator docs for details.
28506 \begin_layout Itemize
28507 -S <serial in,out> passed to simulator see the simulator docs for details.
28510 \begin_layout Itemize
28511 -k <port number> passed to simulator see the simulator docs for details.
28514 \begin_layout Subsection
28515 SDCDB Debugger Commands
28518 \begin_layout Standard
28519 As mentioned earlier the command interface for the debugger has been deliberatel
28520 y kept as close the GNU debugger gdb, as possible.
28521 This will help the integration with existing graphical user interfaces
28522 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
28523 If you use a graphical user interface for the debugger you can skip this
28527 \begin_layout Subsubsection*
28528 break [line | file:line | function | file:function]
28531 \begin_layout Standard
28532 Set breakpoint at specified line or function:
28541 sdcdb>break foo.c:100
28543 sdcdb>break funcfoo
28545 sdcdb>break foo.c:funcfoo
28548 \begin_layout Subsubsection*
28549 clear [line | file:line | function | file:function ]
28552 \begin_layout Standard
28553 Clear breakpoint at specified line or function:
28562 sdcdb>clear foo.c:100
28564 sdcdb>clear funcfoo
28566 sdcdb>clear foo.c:funcfoo
28569 \begin_layout Subsubsection*
28573 \begin_layout Standard
28574 Continue program being debugged, after breakpoint.
28577 \begin_layout Subsubsection*
28581 \begin_layout Standard
28582 Execute till the end of the current function.
28585 \begin_layout Subsubsection*
28589 \begin_layout Standard
28590 Delete breakpoint number 'n'.
28591 If used without any option clear ALL user defined break points.
28594 \begin_layout Subsubsection*
28595 info [break | stack | frame | registers ]
28598 \begin_layout Itemize
28599 info break - list all breakpoints
28602 \begin_layout Itemize
28603 info stack - show the function call stack.
28606 \begin_layout Itemize
28607 info frame - show information about the current execution frame.
28610 \begin_layout Itemize
28611 info registers - show content of all registers.
28614 \begin_layout Subsubsection*
28618 \begin_layout Standard
28619 Step program until it reaches a different source line.
28620 Note: pressing <return> repeats the last command.
28623 \begin_layout Subsubsection*
28627 \begin_layout Standard
28628 Step program, proceeding through subroutine calls.
28631 \begin_layout Subsubsection*
28635 \begin_layout Standard
28636 Start debugged program.
28639 \begin_layout Subsubsection*
28643 \begin_layout Standard
28644 Print type information of the variable.
28647 \begin_layout Subsubsection*
28651 \begin_layout Standard
28652 print value of variable.
28655 \begin_layout Subsubsection*
28659 \begin_layout Standard
28660 load the given file name.
28661 Note this is an alternate method of loading file for debugging.
28664 \begin_layout Subsubsection*
28668 \begin_layout Standard
28669 print information about current frame.
28672 \begin_layout Subsubsection*
28676 \begin_layout Standard
28677 Toggle between C source & assembly source.
28680 \begin_layout Subsubsection*
28681 ! simulator command
28684 \begin_layout Standard
28685 Send the string following '!' to the simulator, the simulator response is
28687 Note the debugger does not interpret the command being sent to the simulator,
28688 so if a command like 'go' is sent the debugger can loose its execution
28689 context and may display incorrect values.
28692 \begin_layout Subsubsection*
28696 \begin_layout Standard
28699 My name is Bobby Brown"
28702 \begin_layout Subsection
28703 Interfacing SDCDB with DDD
28706 \begin_layout Standard
28707 \begin_inset Note Note
28710 \begin_layout Standard
28711 The screenshot was converted from png to eps with:
28712 \begin_inset Quotes sld
28715 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
28716 \begin_inset Quotes srd
28719 which produces a pretty compact eps file which is free from compression
28723 \begin_layout Standard
28724 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
28725 as this broke the build system on Sourceforge (pdf-file was broken.
28726 pdflatex does not accept eps files).
28734 \begin_layout Standard
28750 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
28756 shows a screenshot of a debugging session with DDD
28757 \begin_inset LatexCommand \index{DDD (debugger)}
28761 (Unix only) on a simulated 8032.
28762 The debugging session might not run as smoothly as the screenshot suggests.
28763 The debugger allows setting of breakpoints, displaying and changing variables,
28764 single stepping through C and assembler code.
28767 The source was compiled with
28781 \begin_layout Standard
28793 -debug ddd_example.c
28806 and DDD was invoked with
28813 ddd -debugger "sdcdb -cpu 8032 ddd_example"
28816 \begin_layout Standard
28817 \begin_inset Note Note
28820 \begin_layout Standard
28821 Check that the double quotes or an apostroph within the command line survive
28822 the LyX tool chain.
28823 Previously the apostrophs got slanted in the PDF output so a cut and paste
28832 \begin_layout Subsection
28833 Interfacing SDCDB with XEmacs
28834 \begin_inset LatexCommand \index{XEmacs}
28839 \begin_inset LatexCommand \index{Emacs}
28846 \begin_layout Standard
28847 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
28848 sdcdb.el and sdcdbsrc.el.
28849 These two files can be found in the $(prefix)/bin directory after the installat
28851 These files need to be loaded into XEmacs for the interface to work.
28852 This can be done at XEmacs startup time by inserting the following into
28853 your '.xemacs' file (which can be found in your HOME directory):
28859 (load-file sdcdbsrc.el)
28865 .xemacs is a lisp file so the () around the command is REQUIRED.
28866 The files can also be loaded dynamically while XEmacs is running, set the
28867 environment variable 'EMACSLOADPATH' to the installation bin directory
28868 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
28869 To start the interface enter the following command:
28883 You will prompted to enter the file name to be debugged.
28888 The command line options that are passed to the simulator directly are
28889 bound to default values in the file sdcdbsrc.el.
28890 The variables are listed below, these values maybe changed as required.
28893 \begin_layout Itemize
28894 sdcdbsrc-cpu-type '51
28897 \begin_layout Itemize
28898 sdcdbsrc-frequency '11059200
28901 \begin_layout Itemize
28902 sdcdbsrc-serial nil
28905 \begin_layout Standard
28906 The following is a list of key mapping for the debugger interface.
28909 \begin_layout Standard
28932 binding\InsetSpace ~
28970 -------\InsetSpace ~
29041 sdcdb-back-from-src\InsetSpace ~
29070 rom-src\InsetSpace ~
29080 SDCDB continue command
29098 sdcdb-step-from-src\InsetSpace ~
29127 hatis-c-sexp\InsetSpace ~
29137 SDCDB ptypecommand for data at
29204 sdcdbsrc-delete\InsetSpace ~
29219 B Delete all breakpoints if no arg
29268 given or delete arg (C-u arg x)
29287 -frame\InsetSpace ~
29302 SDCDB Display current frame if no arg,
29351 given or display frame arg
29419 sdcdbsrc-goto-sdcdb\InsetSpace ~
29429 Goto the SDCDB output buffer
29448 t-c-sexp\InsetSpace ~
29459 SDCDB print command for data at
29526 sdcdbsrc-goto-sdcdb\InsetSpace ~
29537 o the SDCDB output buffer
29555 sdcdbsrc-mode\InsetSpace ~
29571 Toggles Sdcdbsrc mode (turns it
29587 sdcdb-finish-from-src\InsetSpace ~
29595 SDCDB finish command
29629 Set break for line with point
29644 sdcdbsrc-mode\InsetSpace ~
29660 Toggle Sdcdbsrc mode
29676 dbsrc-srcmode\InsetSpace ~
29700 \begin_layout Chapter
29704 \begin_layout Standard
29705 Here are a few guidelines that will help the compiler generate more efficient
29706 code, some of the tips are specific to this compiler others are generally
29707 good programming practice.
29710 \begin_layout Itemize
29711 Use the smallest data type to represent your data-value.
29712 If it is known in advance that the value is going to be less than 256 then
29713 use an 'unsigned char' instead of a 'short' or 'int'.
29714 Please note, that ANSI C requires both signed and unsigned chars to be
29715 promoted to 'signed int'
29716 \begin_inset LatexCommand \index{promotion to signed int}
29721 \begin_inset Marginal
29724 \begin_layout Standard
29733 before doing any operation.
29735 \begin_inset LatexCommand \index{type promotion}
29740 \begin_inset LatexCommand \label{type promotion}
29744 can be omitted, if the result is the same.
29745 The effect of the promotion rules together with the sign-extension is often
29750 \begin_layout Verse
29753 unsigned char uc = 0xfe;
29755 if (uc * uc < 0) /* this is true! */
29768 \begin_layout Standard
29775 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
29783 \begin_layout Verse
29786 (unsigned char) -12 / (signed char) -3 = ...
29789 \begin_layout Standard
29790 No, the result is not 4:
29793 \begin_layout Verse
29796 (int) (unsigned char) -12 / (int) (signed char) -3 =
29798 (int) (unsigned char)
29799 0xf4 / (int) (signed char) 0xfd =
29801 (int) 0x00f4 / (int) 0xfffd =
29806 (int) 244 / (int) -3 =
29808 (int) -81 = (int) 0xffaf;
29811 \begin_layout Standard
29812 Don't complain, that gcc gives you a different result.
29813 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
29814 Therefore the results are different.
29817 \begin_inset Quotes sld
29821 \begin_inset Quotes srd
29827 \begin_layout Quote
29830 If well-defined overflow characteristics are important and negative values
29831 are not, or if you want to steer clear of sign-extension problems when
29832 manipulating bits or bytes, use one of the corresponding unsigned types.
29833 (Beware when mixing signed and unsigned values in expressions, though.)
29836 character types (especially unsigned char) can be used as "tiny" integers,
29837 doing so is sometimes more trouble than it's worth, due to unpredictable
29838 sign extension and increased code size.
29842 \begin_layout Itemize
29843 Use unsigned when it is known in advance that the value is not going to
29845 This helps especially if you are doing division or multiplication, bit-shifting
29846 or are using an array index.
29849 \begin_layout Itemize
29850 NEVER jump into a LOOP.
29853 \begin_layout Itemize
29854 Declare the variables to be local
29855 \begin_inset LatexCommand \index{local variables}
29859 whenever possible, especially loop control variables (induction).
29862 \begin_layout Itemize
29863 Have a look at the assembly listing to get a
29864 \begin_inset Quotes sld
29868 \begin_inset Quotes srd
29871 for the code generation.
29874 \begin_layout Section
29875 Porting code from or to other compilers
29876 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
29883 \begin_layout Itemize
29884 check whether endianness of the compilers differs and adapt where needed.
29887 \begin_layout Itemize
29888 check the device specific header files
29889 \begin_inset LatexCommand \index{Header files}
29894 \begin_inset LatexCommand \index{Include files}
29898 for compiler specific syntax.
29899 Eventually include the file <compiler.h
29900 \begin_inset LatexCommand \index{compiler.h (include file)}
29905 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
29909 to allow using common header files.
29912 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
29919 \begin_layout Itemize
29920 check whether the startup code contains the correct initialization (watchdog,
29924 \begin_layout Itemize
29925 check whether the sizes of short, int, long match.
29928 \begin_layout Itemize
29929 check if some 16 or 32 bit hardware registers require a specific addressing
29930 order (least significant or most significant byte first) and adapt if needed
29939 relate to time and not to lower/upper memory location here, so this is
29944 the same as endianness).
29947 \begin_layout Itemize
29948 check whether the keyword
29952 is used where needed.
29953 The compilers might differ in their optimization characteristics (as different
29954 versions of the same compiler might also use more clever optimizations
29955 this is good idea anyway).
29957 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
29964 \begin_layout Itemize
29965 check that the compilers are not told to supress warnings.
29968 \begin_layout Itemize
29969 check and convert compiler specific extensions (interrupts, memory areas,
29973 \begin_layout Itemize
29974 check for differences in type promotion.
29975 Especially check for math operations on
29984 For the sake of C99 compatibility SDCC will probably promote these to
29988 more often than other compilers.
29989 Eventually insert explicit casts to
29998 Also check that the ~\InsetSpace ~
30000 \begin_inset LatexCommand \index{\\~\\/ Operator}
30007 \begin_inset LatexCommand \index{bit}
30013 variables, use the !\InsetSpace ~
30016 \begin_inset LatexCommand \ref{type promotion}
30021 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30028 \begin_layout Itemize
30029 check the assembly code generated for interrupt routines (f.e.
30030 for calls to possibly non-reentrant library functions).
30033 \begin_layout Itemize
30034 check whether timing loops result in proper timing (or preferably consider
30035 a rewrite of the code with timer based delays instead).
30038 \begin_layout Itemize
30039 check for differences in printf parameters (some compilers push (va_arg
30040 \begin_inset LatexCommand \index{vararg, va\\_arg}
30044 ) char variables as
30048 others push them as
30054 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30061 \begin_layout Itemize
30062 check the resulting memory map
30063 \begin_inset LatexCommand \index{Memory map}
30068 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
30069 ly idata, pdata, xdata).
30070 Eventually check if unexpected library functions are included.
30073 \begin_layout Section
30075 \begin_inset LatexCommand \index{Tools}
30079 included in the distribution
30082 \begin_layout Standard
30084 \begin_inset Tabular
30085 <lyxtabular version="3" rows="12" columns="3">
30087 <column alignment="left" valignment="top" leftline="true" width="0pt">
30088 <column alignment="left" valignment="top" leftline="true" width="0pt">
30089 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30090 <row topline="true" bottomline="true">
30091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30094 \begin_layout Standard
30102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30105 \begin_layout Standard
30113 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30116 \begin_layout Standard
30125 <row topline="true">
30126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30129 \begin_layout Standard
30131 \begin_inset LatexCommand \index{uCsim}
30140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30143 \begin_layout Standard
30144 Simulator for various architectures
30149 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30152 \begin_layout Standard
30159 <row topline="true">
30160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30163 \begin_layout Standard
30169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30172 \begin_layout Standard
30174 \begin_inset LatexCommand \index{Header files}
30179 \begin_inset LatexCommand \index{Include files}
30188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30191 \begin_layout Standard
30192 sdcc/support/scripts
30198 <row topline="true">
30199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30202 \begin_layout Standard
30208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30211 \begin_layout Standard
30212 header file conversion
30217 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30220 \begin_layout Standard
30221 sdcc/support/scripts
30227 <row topline="true">
30228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30231 \begin_layout Standard
30237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30240 \begin_layout Standard
30246 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30249 \begin_layout Standard
30265 <row topline="true">
30266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30269 \begin_layout Standard
30275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30278 \begin_layout Standard
30284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30287 \begin_layout Standard
30303 <row topline="true">
30304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30307 \begin_layout Standard
30313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30316 \begin_layout Standard
30322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30325 \begin_layout Standard
30341 <row topline="true">
30342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30345 \begin_layout Standard
30351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30354 \begin_layout Standard
30360 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30363 \begin_layout Standard
30379 <row topline="true">
30380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30383 \begin_layout Standard
30389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30392 \begin_layout Standard
30398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30401 \begin_layout Standard
30417 <row topline="true">
30418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30421 \begin_layout Standard
30427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30430 \begin_layout Standard
30436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30439 \begin_layout Standard
30455 <row topline="true">
30456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30459 \begin_layout Standard
30465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30468 \begin_layout Standard
30474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30477 \begin_layout Standard
30493 <row topline="true" bottomline="true">
30494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30497 \begin_layout Standard
30503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30506 \begin_layout Standard
30508 \begin_inset LatexCommand \index{packihx (tool)}
30517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30520 \begin_layout Standard
30545 \begin_layout Section
30547 \begin_inset LatexCommand \index{Documentation}
30551 included in the distribution
30554 \begin_layout Standard
30556 \begin_inset Tabular
30557 <lyxtabular version="3" rows="10" columns="2">
30559 <column alignment="block" valignment="top" leftline="true" width="40col%">
30560 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
30561 <row topline="true" bottomline="true" endhead="true">
30562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30565 \begin_layout Standard
30573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30576 \begin_layout Standard
30579 Filename / Where to get
30585 <row topline="true">
30586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30589 \begin_layout Standard
30590 SDCC Compiler User Guide
30595 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30598 \begin_layout Standard
30599 You're reading it right now
30611 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
30621 <row topline="true">
30622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30625 \begin_layout Standard
30631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30634 \begin_layout Standard
30647 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
30657 <row topline="true">
30658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30661 \begin_layout Standard
30663 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
30668 \begin_inset LatexCommand \index{Assembler documentation}
30675 \begin_inset LatexCommand \index{aslink}
30680 \begin_inset LatexCommand \index{Linker documentation}
30689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30692 \begin_layout Standard
30693 sdcc/as/doc/asxhtm.html
30705 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
30715 <row topline="true">
30716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30719 \begin_layout Standard
30720 SDCC regression test
30721 \begin_inset LatexCommand \index{Regression test}
30730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30733 \begin_layout Standard
30734 sdcc/doc/test_suite_spec.pdf
30746 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30756 <row topline="true">
30757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30760 \begin_layout Standard
30766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30769 \begin_layout Standard
30782 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
30792 <row topline="true">
30793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30796 \begin_layout Standard
30797 Notes on debugging with SDCDB
30798 \begin_inset LatexCommand \index{SDCDB (debugger)}
30807 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30810 \begin_layout Standard
30811 sdcc/debugger/README
30823 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
30833 <row topline="true">
30834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30837 \begin_layout Standard
30839 \begin_inset LatexCommand \index{uCsim}
30843 Software simulator for microcontrollers
30848 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30851 \begin_layout Standard
30881 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
30891 <row topline="true">
30892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30895 \begin_layout Standard
30896 Temporary notes on the pic16
30897 \begin_inset LatexCommand \index{PIC16}
30906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30909 \begin_layout Standard
30910 sdcc/src/pic16/NOTES
30922 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
30932 <row topline="true" bottomline="true">
30933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30936 \begin_layout Standard
30937 SDCC internal documentation (debugging file format)
30942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30945 \begin_layout Standard
30975 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
30994 \begin_layout Section
30995 Related open source tools
30996 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
31001 \begin_inset LatexCommand \index{Related tools}
31008 \begin_layout Standard
31010 \begin_inset Tabular
31011 <lyxtabular version="3" rows="14" columns="3">
31013 <column alignment="left" valignment="top" leftline="true" width="0pt">
31014 <column alignment="block" valignment="top" leftline="true" width="30line%">
31015 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
31016 <row topline="true" bottomline="true">
31017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31020 \begin_layout Standard
31028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31031 \begin_layout Standard
31039 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31042 \begin_layout Standard
31051 <row topline="true">
31052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31055 \begin_layout Standard
31057 \begin_inset LatexCommand \index{gpsim (pic simulator)}
31066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31069 \begin_layout Standard
31075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31078 \begin_layout Standard
31079 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
31089 <row topline="true">
31090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31093 \begin_layout Standard
31095 \begin_inset LatexCommand \index{gputils (pic tools)}
31104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31107 \begin_layout Standard
31113 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31116 \begin_layout Standard
31117 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
31127 <row topline="true">
31128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31131 \begin_layout Standard
31137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31140 \begin_layout Standard
31146 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31149 \begin_layout Standard
31150 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
31160 <row topline="true">
31161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31164 \begin_layout Standard
31170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31173 \begin_layout Standard
31174 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
31180 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31183 \begin_layout Standard
31184 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
31194 <row topline="true">
31195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31198 \begin_layout Standard
31200 \begin_inset LatexCommand \index{indent (source formatting tool)}
31209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31212 \begin_layout Standard
31213 Formats C source - Master of the white spaces
31218 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31221 \begin_layout Standard
31222 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
31232 <row topline="true">
31233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31236 \begin_layout Standard
31238 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
31247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31250 \begin_layout Standard
31251 Object file conversion, checksumming, ...
31256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31259 \begin_layout Standard
31260 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
31270 <row topline="true">
31271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31274 \begin_layout Standard
31276 \begin_inset LatexCommand \index{objdump (tool)}
31285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31288 \begin_layout Standard
31289 Object file conversion, ...
31294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31297 \begin_layout Standard
31298 Part of binutils (should be there anyway)
31304 <row topline="true">
31305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31308 \begin_layout Standard
31314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31317 \begin_layout Standard
31318 8051 monitor (hex up-/download, single step, disassemble)
31323 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31326 \begin_layout Standard
31327 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
31337 <row topline="true">
31338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31341 \begin_layout Standard
31343 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
31352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31355 \begin_layout Standard
31356 Source code documentation system
31361 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31364 \begin_layout Standard
31365 \begin_inset LatexCommand \url{http://www.doxygen.org}
31375 <row topline="true">
31376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31379 \begin_layout Standard
31385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31388 \begin_layout Standard
31389 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
31394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31397 \begin_layout Standard
31398 \begin_inset LatexCommand \url{http://www.kdevelop.org}
31408 <row topline="true">
31409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31412 \begin_layout Standard
31418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31421 \begin_layout Standard
31422 8051 monitor (hex up-/download, single step, disassemble)
31427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31430 \begin_layout Standard
31431 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
31441 <row topline="true">
31442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31445 \begin_layout Standard
31447 \begin_inset LatexCommand \index{splint (syntax checking tool)}
31456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31459 \begin_layout Standard
31460 Statically checks c sources (see
31461 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
31470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31473 \begin_layout Standard
31474 \begin_inset LatexCommand \url{http://www.splint.org}
31484 <row topline="true" bottomline="true">
31485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31488 \begin_layout Standard
31490 \begin_inset LatexCommand \index{DDD (debugger)}
31499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31502 \begin_layout Standard
31503 Debugger, serves nicely as GUI to SDCDB
31504 \begin_inset LatexCommand \index{SDCDB (debugger)}
31513 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31516 \begin_layout Standard
31517 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
31536 \begin_layout Section
31537 Related documentation / recommended reading
31540 \begin_layout Standard
31542 \begin_inset Tabular
31543 <lyxtabular version="3" rows="7" columns="3">
31545 <column alignment="left" valignment="top" leftline="true" width="0pt">
31546 <column alignment="left" valignment="top" leftline="true" width="0">
31547 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
31548 <row topline="true" bottomline="true">
31549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31552 \begin_layout Standard
31560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31563 \begin_layout Standard
31571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31574 \begin_layout Standard
31583 <row topline="true">
31584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31587 \begin_layout Standard
31602 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31605 \begin_layout Standard
31607 \begin_inset LatexCommand \index{C Reference card}
31616 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31619 \begin_layout Standard
31620 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
31630 <row topline="true">
31631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31634 \begin_layout Standard
31640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31643 \begin_layout Standard
31645 \begin_inset LatexCommand \index{C FAQ}
31654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31657 \begin_layout Standard
31658 \begin_inset LatexCommand \url{http://www.c-faq.com}
31668 <row topline="true">
31669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31672 \begin_layout Standard
31678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31681 \begin_layout Standard
31682 \begin_inset Quotes sld
31686 \begin_inset Quotes srd
31694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31697 \begin_layout Standard
31700 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
31710 <row topline="true">
31711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31714 \begin_layout Standard
31720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31723 \begin_layout Standard
31724 \begin_inset Quotes sld
31727 Extensions for Embedded C
31728 \begin_inset Quotes srd
31736 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31739 \begin_layout Standard
31742 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
31752 <row topline="true">
31753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31756 \begin_layout Standard
31762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31765 \begin_layout Standard
31766 Latest datasheet of target CPU
31771 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31774 \begin_layout Standard
31781 <row topline="true" bottomline="true">
31782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31785 \begin_layout Standard
31791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31794 \begin_layout Standard
31795 Revision history of datasheet
31800 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31803 \begin_layout Standard
31819 \begin_layout Section
31820 Application notes specifically for SDCC
31823 \begin_layout Standard
31824 SDCC makes no claims about the completeness of this list and about up-to-datenes
31825 s or correctness of the application notes
31826 \begin_inset LatexCommand \index{Application notes}
31833 \begin_layout Standard
31837 \begin_inset Tabular
31838 <lyxtabular version="3" rows="7" columns="3">
31840 <column alignment="block" valignment="top" leftline="true" width="17col%">
31841 <column alignment="block" valignment="top" leftline="true" width="27col%">
31842 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
31843 <row topline="true" bottomline="true">
31844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31847 \begin_layout Standard
31856 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
31859 \begin_layout Standard
31868 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31871 \begin_layout Standard
31881 <row topline="true">
31882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31885 \begin_layout Standard
31893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31896 \begin_layout Standard
31899 Using the SDCC Compiler for the DS80C400
31900 \begin_inset LatexCommand \index{DS80C400}
31909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31912 \begin_layout Standard
31915 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
31925 <row topline="true">
31926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31929 \begin_layout Standard
31937 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
31940 \begin_layout Standard
31943 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
31944 \begin_inset LatexCommand \index{DS89C4x0}
31948 Family of Microcontrollers
31953 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31956 \begin_layout Standard
31959 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
31969 <row topline="true">
31970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31973 \begin_layout Standard
31976 Silicon Laboratories / Cygnal
31981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31984 \begin_layout Standard
31987 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
31988 \begin_inset LatexCommand \index{IDE}
31997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32000 \begin_layout Standard
32003 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
32013 <row topline="true">
32014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32017 \begin_layout Standard
32020 Ramtron / Goal Semiconductor
32025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32028 \begin_layout Standard
32031 Interfacing SDCC to Syn and Textpad
32036 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32039 \begin_layout Standard
32042 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32052 <row topline="true">
32053 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32056 \begin_layout Standard
32059 Ramtron / Goal Semiconductor
32064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32067 \begin_layout Standard
32070 Installing and Configuring SDCC and Crimson Editor
32075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32078 \begin_layout Standard
32081 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32091 <row topline="true" bottomline="true">
32092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32095 \begin_layout Standard
32103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32106 \begin_layout Standard
32109 MSC12xx Programming with SDCC
32114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32117 \begin_layout Standard
32120 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
32137 \begin_layout Section
32141 \begin_layout Standard
32142 Some questions answered, some pointers given - it might be time to in turn
32150 \begin_layout Itemize
32151 can you solve your project with the selected microcontroller? Would you
32152 find out early or rather late that your target is too small/slow/whatever?
32153 Can you switch to a slightly better device if it doesn't fit?
32156 \begin_layout Itemize
32157 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
32158 and/or another programming language be more adequate? Would an operating
32159 system on the target device help?
32162 \begin_layout Itemize
32163 if you solved the problem, will the marketing department be happy?
32166 \begin_layout Itemize
32167 if the marketing department is happy, will customers be happy?
32170 \begin_layout Itemize
32171 if you're the project manager, marketing department and maybe even the customer
32172 in one person, have you tried to see the project from the outside?
32175 \begin_layout Itemize
32176 is the project done if you think it is done? Or is just that other interface/pro
32177 tocol/feature/configuration/option missing? How about website, manual(s),
32178 internationali(z|s)ation, packaging, labels, 2nd source for components,
32179 electromagnetic compatability/interference, documentation for production,
32180 production test software, update mechanism, patent issues?
32183 \begin_layout Itemize
32184 is your project adequately positioned in that magic triangle: fame, fortune,
32188 \begin_layout Standard
32189 Maybe not all answers to these questions are known and some answers may
32194 , nevertheless knowing these questions may help you to avoid burnout
32198 \begin_layout Standard
32199 burnout is bad for electronic devices, programmers and motorcycle tyres
32205 Chances are you didn't want to hear some of them...
32208 \begin_layout Chapter
32210 \begin_inset LatexCommand \index{Support}
32217 \begin_layout Standard
32218 SDCC has grown to be a large project.
32219 The compiler alone (without the preprocessor, assembler and linker) is
32220 well over 150,000 lines of code (blank stripped).
32221 The open source nature of this project is a key to its continued growth
32223 You gain the benefit and support of many active software developers and
32225 Is SDCC perfect? No, that's why we need your help.
32226 The developers take pride in fixing reported bugs.
32227 You can help by reporting the bugs and helping other SDCC users.
32228 There are lots of ways to contribute, and we encourage you to take part
32229 in making SDCC a great software package.
32233 \begin_layout Standard
32234 The SDCC project is hosted on the SDCC sourceforge site at
32235 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
32240 You'll find the complete set of mailing lists
32241 \begin_inset LatexCommand \index{Mailing list(s)}
32245 , forums, bug reporting system, patch submission
32246 \begin_inset LatexCommand \index{Patch submission}
32251 \begin_inset LatexCommand \index{download}
32255 area and Subversion code repository
32256 \begin_inset LatexCommand \index{Subversion code repository}
32263 \begin_layout Section
32265 \begin_inset LatexCommand \index{Bug reporting}
32270 \begin_inset LatexCommand \index{Reporting bugs}
32277 \begin_layout Standard
32278 The recommended way of reporting bugs is using the infrastructure of the
32280 You can follow the status of bug reports there and have an overview about
32284 \begin_layout Standard
32285 Bug reports are automatically forwarded to the developer mailing list and
32286 will be fixed ASAP.
32287 When reporting a bug, it is very useful to include a small test program
32288 (the smaller the better) which reproduces the problem.
32289 If you can isolate the problem by looking at the generated assembly code,
32290 this can be very helpful.
32291 Compiling your program with the -
32295 \begin_layout Standard
32305 \begin_inset LatexCommand \index{-\\/-dumpall}
32309 option can sometimes be useful in locating optimization problems.
32310 When reporting a bug please make sure you:
32313 \begin_layout Enumerate
32314 Attach the code you are compiling with SDCC.
32318 \begin_layout Enumerate
32319 Specify the exact command you use to run SDCC, or attach your Makefile.
32323 \begin_layout Enumerate
32324 Specify the SDCC version (type "
32330 "), your platform, and operating system.
32334 \begin_layout Enumerate
32335 Provide an exact copy of any error message or incorrect output.
32339 \begin_layout Enumerate
32340 Put something meaningful in the subject of your message.
32343 \begin_layout Standard
32344 Please attempt to include these 5 important parts, as applicable, in all
32345 requests for support or when reporting any problems or bugs with SDCC.
32346 Though this will make your message lengthy, it will greatly improve your
32347 chance that SDCC users and developers will be able to help you.
32348 Some SDCC developers are frustrated by bug reports without code provided
32349 that they can use to reproduce and ultimately fix the problem, so please
32350 be sure to provide sample code if you are reporting a bug!
32353 \begin_layout Standard
32354 Please have a short check that you are using a recent version of SDCC and
32355 the bug is not yet known.
32356 This is the link for reporting bugs:
32357 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
32362 With SDCC on average having more than 200 downloads
32363 \begin_inset LatexCommand \index{download}
32367 on sourceforge per day
32371 \begin_layout Standard
32372 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
32373 between 2002 and 2005.
32374 This does not include other methods of distribution.
32379 there must be some users.
32380 So it's not exactly easy to find a new bug.
32381 If you find one we need it:
32383 reporting bugs is good
32388 \begin_layout Section
32389 Requesting Features
32390 \begin_inset LatexCommand \label{sub:Requesting-Features}
32395 \begin_inset LatexCommand \index{Feature request}
32400 \begin_inset LatexCommand \index{Requesting features}
32407 \begin_layout Standard
32408 Like bug reports feature requests are forwarded to the developer mailing
32410 This is the link for requesting features:
32411 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32418 \begin_layout Section
32422 \begin_layout Standard
32423 Like bug reports contributed patches are forwarded to the developer mailing
32425 This is the link for submitting patches
32426 \begin_inset LatexCommand \index{Patch submission}
32431 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
32438 \begin_layout Standard
32439 You need to specify some parameters to the
32443 command for the patches to be useful.
32444 If you modified more than one file a patch created f.e.
32449 \begin_inset Quotes sld
32452 diff -Naur unmodified_directory modified_directory >my_changes.patch
32453 \begin_inset Quotes srd
32459 will be fine, otherwise
32463 \begin_inset Quotes sld
32466 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
32467 \begin_inset Quotes srd
32476 \begin_layout Section
32480 \begin_layout Standard
32481 These links should take you directly to the
32482 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
32490 \begin_layout Standard
32491 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
32492 automated messages (mid 2003)
32498 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
32503 \begin_inset LatexCommand \index{Mailing list(s)}
32507 and forums are archived and searchable so if you are lucky someone already
32508 had a similar problem.
32509 While mails to the lists themselves are delivered promptly their web front
32510 end on sourceforge sometimes shows a severe time lag (up to several weeks),
32511 if you're seriously using SDCC please consider subscribing to the lists.
32514 \begin_layout Section
32518 \begin_layout Standard
32519 You can follow the status of the Subversion version
32520 \begin_inset LatexCommand \index{version}
32524 of SDCC by watching the Changelog
32525 \begin_inset LatexCommand \index{Changelog}
32529 in the Subversion repository
32532 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
32539 \begin_layout Section
32540 Subversion Source Code Repository
32543 \begin_layout Standard
32553 \begin_layout Standard
32567 or the filenames of the snapshot versions of SDCC include date and its
32569 \begin_inset LatexCommand \index{Subversion code repository}
32574 Subversion allows to download the source of recent or previous versions
32576 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
32580 (by number or by date).
32581 An on-line source code browser and detailled instructions are also available
32583 SDCC versions starting from 1999 up to now are available (currently the
32584 versions prior to the conversion from cvs
32585 \begin_inset LatexCommand \index{cvs|see{Subversion}}
32589 to Subversion (April 2006) are either by accessible by Subversion or by
32593 \begin_layout Section
32595 \begin_inset LatexCommand \index{Release policy}
32602 \begin_layout Standard
32603 Historically there often were long delays between official releases and
32604 the sourceforge download area tends to get not updated at all.
32605 Excuses in the past might have referred to problems with live range analysis,
32606 but as this was fixed a while ago, the current problem is that another
32607 excuse has to be found.
32608 Kidding aside, we have to get better there! On the other hand there are
32609 daily snapshots available at
32610 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
32614 , and you can always build the very last version (hopefully with many bugs
32615 fixed, and features added) from the source code available at
32616 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
32622 \begin_inset LatexCommand \index{wiki}
32627 \begin_inset LatexCommand \index{SDCC Wiki}
32632 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/}
32636 also holds some information about past and future releases.
32639 \begin_layout Section
32641 \begin_inset LatexCommand \index{Examples}
32648 \begin_layout Standard
32649 You'll find some small examples in the directory
32651 sdcc/device/examples/.
32654 More examples and libraries are available at
32656 The SDCC Open Knowledge Resource
32657 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
32664 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
32671 \begin_layout Standard
32672 \begin_inset Note Note
32675 \begin_layout Standard
32676 I did insert a reference to Paul's web site here although it seems rather
32677 dedicated to a specific 8032 board (I think it's okay because it f.e.
32678 shows LCD/Harddisc interface and has a free 8051 monitor.
32679 Independent 8032 board vendors face hard competition of heavily subsidized
32680 development boards anyway).
32683 \begin_layout Standard
32684 Maybe we should include some links to real world applications.
32685 Preferably pointer to pointers (one for each architecture) so this stays
32694 \begin_layout Section
32696 \begin_inset LatexCommand \label{sec:Quality-control}
32701 \begin_inset LatexCommand \index{Quality control}
32708 \begin_layout Standard
32709 The compiler is passed through snaphot build compile and build checks.
32715 \begin_inset LatexCommand \index{Regression test}
32719 check that SDCC itself compiles flawlessly on several host platforms (i386,
32720 Opteron, 64 bit Alpha, ppc64, Mac OS X on PPC, Solaris on Sparc) and checks
32721 the quality of the code generated by SDCC by running the code for several
32722 target platforms through simulators.
32723 The regression test suite comprises more than 100 files which expand to
32724 more than 500 test cases which include more than 4500 tests.
32725 The results of these tests are published daily on SDCC's snapshot page
32726 (click on the red or green symbols on the right side of
32727 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
32734 \begin_layout Standard
32735 There is a separate document
32738 \begin_inset LatexCommand \index{Test suite}
32745 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
32749 about the regression test suite.
32752 \begin_layout Standard
32753 You'll find the test code in the directory
32755 sdcc/support/regression
32758 You can run these tests manually by running
32762 in this directory (or f.e.
32767 \begin_inset Quotes sld
32771 \begin_inset Quotes srd
32777 if you don't want to run the complete tests).
32778 The test code might also be interesting if you want to look for examples
32779 \begin_inset LatexCommand \index{Examples}
32783 checking corner cases of SDCC or if you plan to submit patches
32784 \begin_inset LatexCommand \index{Patch submission}
32791 \begin_layout Standard
32792 The PIC14 port uses a different set of regression tests
32793 \begin_inset LatexCommand \index{Regression test (PIC14)}
32797 , you'll find them in the directory
32799 sdcc/src/regression
32804 \begin_layout Section
32805 Use of SDCC in Education
32808 \begin_layout Standard
32817 \begin_layout Standard
32818 the phrase "use in education" might evoke the association "
32822 fit for use in education".
32823 This connotation is not intended but nevertheless risked as the licensing
32824 of SDCC makes it difficult to offer educational discounts
32830 If your rationales are to:
32833 \begin_layout Enumerate
32834 give students a chance to understand the
32838 steps of code generation
32841 \begin_layout Enumerate
32842 have a curriculum that can be extended for years.
32843 Then you could use an fpga board as target and your curriculum will seamlessly
32844 extend from logic synthesis (
32845 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
32850 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
32854 ), over assembly programming, to C to FPGA compilers (
32855 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
32862 \begin_layout Enumerate
32863 be able to insert excursions about skills like using a revision control
32864 system, submitting/applying patches, using a type-setting (as opposed to
32865 word-processing) engine LyX/LaTeX, using
32866 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
32871 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
32875 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
32876 Source Software, CPU simulation, compiler regression tests
32877 \begin_inset LatexCommand \index{Regression test}
32884 And if there should be a shortage of ideas then you can always point students
32885 to the ever-growing feature request list
32886 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32893 \begin_layout Enumerate
32894 not tie students to a specific host platform and instead allow them to use
32899 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
32901 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
32908 \begin_layout Enumerate
32909 not encourage students to use illegal copies of educational software
32912 \begin_layout Enumerate
32913 be immune to licensing/availability/price changes of the chosen tool chain
32916 \begin_layout Enumerate
32917 be able to change to a new target platform without having to adopt a new
32921 \begin_layout Enumerate
32922 have complete control over and insight into the tool chain
32925 \begin_layout Enumerate
32926 make your students aware about the pros and cons of open source software
32930 \begin_layout Enumerate
32931 give back to the public as you are probably at least partially publically
32935 \begin_layout Enumerate
32936 give students a chance to publically prove their skills and to possibly
32937 see a world wide impact
32940 \begin_layout Standard
32941 then SDCC is probably among the first choices.
32942 Well, probably SDCC might be the only choice.
32947 \begin_layout Chapter
32948 SDCC Technical Data
32951 \begin_layout Section
32953 \begin_inset LatexCommand \index{Optimizations}
32960 \begin_layout Standard
32961 SDCC performs a host of standard optimizations in addition to some MCU specific
32966 \begin_layout Subsection
32967 Sub-expression Elimination
32968 \begin_inset LatexCommand \index{Subexpression elimination}
32975 \begin_layout Standard
32976 The compiler does local and
32995 \begin_layout Verse
33003 \begin_layout Standard
33004 will be translated to
33007 \begin_layout Verse
33017 \begin_layout Standard
33018 Some subexpressions are not as obvious as the above example, e.g.:
33021 \begin_layout Verse
33029 \begin_layout Standard
33030 In this case the address arithmetic a->b[i] will be computed only once;
33031 the equivalent code in C would be.
33034 \begin_layout Verse
33044 \begin_layout Standard
33045 The compiler will try to keep these temporary variables in registers.
33048 \begin_layout Subsection
33049 Dead-Code Elimination
33050 \begin_inset LatexCommand \index{Dead-code elimination}
33057 \begin_layout Verse
33072 i = 1; \InsetSpace ~
33081 global = 1;\InsetSpace ~
33095 global = 3;\InsetSpace ~
33101 \begin_layout Standard
33105 \begin_layout Verse
33121 \begin_layout Subsection
33123 \begin_inset LatexCommand \index{Copy propagation}
33130 \begin_layout Verse
33154 \begin_layout Standard
33158 \begin_layout Verse
33182 \begin_layout Standard
33183 Note: the dead stores created by this copy propagation will be eliminated
33184 by dead-code elimination.
33187 \begin_layout Subsection
33189 \begin_inset LatexCommand \index{Loop optimization}
33194 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
33201 \begin_layout Standard
33202 Two types of loop optimizations are done by SDCC
33210 of loop induction variables.
33211 In addition to the strength reduction the optimizer marks the induction
33212 variables and the register allocator tries to keep the induction variables
33213 in registers for the duration of the loop.
33214 Because of this preference of the register allocator
33215 \begin_inset LatexCommand \index{Register allocation}
33219 , loop induction optimization causes an increase in register pressure, which
33220 may cause unwanted spilling of other temporary variables into the stack
33221 \begin_inset LatexCommand \index{stack}
33226 The compiler will generate a warning message when it is forced to allocate
33227 extra space either on the stack or data space.
33228 If this extra space allocation is undesirable then induction optimization
33229 can be eliminated either for the entire source file (with -
33233 \begin_layout Standard
33242 -noinduction option) or for a given function only using #pragma\InsetSpace ~
33244 \begin_inset LatexCommand \index{\\#pragma noinduction}
33255 \begin_layout Verse
33258 for (i = 0 ; i < 100 ; i ++)
33267 \begin_layout Standard
33271 \begin_layout Verse
33276 for (i = 0; i < 100; i++)
33285 \begin_layout Standard
33286 As mentioned previously some loop invariants are not as apparent, all static
33287 address computations are also moved out of the loop.
33292 \begin_inset LatexCommand \index{Strength reduction}
33296 , this optimization substitutes an expression by a cheaper expression:
33299 \begin_layout Verse
33302 for (i=0;i < 100; i++)
33311 \begin_layout Standard
33315 \begin_layout Verse
33322 for (i=0;i< 100;i++) {
33328 ar[itemp1] = itemp2;
33346 \begin_layout Standard
33347 The more expensive multiplication
33348 \begin_inset LatexCommand \index{Multiplication}
33352 is changed to a less expensive addition.
33355 \begin_layout Subsection
33357 \begin_inset LatexCommand \index{Loop reversing}
33364 \begin_layout Standard
33365 This optimization is done to reduce the overhead of checking loop boundaries
33366 for every iteration.
33367 Some simple loops can be reversed and implemented using a
33368 \begin_inset Quotes eld
33371 decrement and jump if not zero
33372 \begin_inset Quotes erd
33376 SDCC checks for the following criterion to determine if a loop is reversible
33377 (note: more sophisticated compilers use data-dependency analysis to make
33378 this determination, SDCC uses a more simple minded analysis).
33381 \begin_layout Itemize
33382 The 'for' loop is of the form
33388 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
33398 \begin_layout Itemize
33399 The <for body> does not contain
33400 \begin_inset Quotes eld
33404 \begin_inset Quotes erd
33408 \begin_inset Quotes erd
33414 \begin_layout Itemize
33415 All goto's are contained within the loop.
33418 \begin_layout Itemize
33419 No function calls within the loop.
33422 \begin_layout Itemize
33423 The loop control variable <sym> is not assigned any value within the loop
33426 \begin_layout Itemize
33427 The loop control variable does NOT participate in any arithmetic operation
33431 \begin_layout Itemize
33432 There are NO switch statements in the loop.
33435 \begin_layout Subsection
33436 Algebraic Simplifications
33439 \begin_layout Standard
33440 SDCC does numerous algebraic simplifications, the following is a small sub-set
33441 of these optimizations.
33444 \begin_layout Verse
33447 i = j + 0;\InsetSpace ~
33451 /* changed to: */\InsetSpace ~
33457 i /= 2;\InsetSpace ~
33464 /* changed to: */\InsetSpace ~
33471 = j - j;\InsetSpace ~
33475 /* changed to: */\InsetSpace ~
33481 i = j / 1;\InsetSpace ~
33485 /* changed to: */\InsetSpace ~
33492 \begin_layout Standard
33493 Note the subexpressions
33494 \begin_inset LatexCommand \index{Subexpression}
33498 given above are generally introduced by macro expansions or as a result
33499 of copy/constant propagation.
33502 \begin_layout Subsection
33503 'switch' Statements
33504 \begin_inset LatexCommand \label{sub:'switch'-Statements}
33509 \begin_inset LatexCommand \index{switch statement}
33516 \begin_layout Standard
33517 SDCC can optimize switch statements to jump tables
33518 \begin_inset LatexCommand \index{jump tables}
33523 It makes the decision based on an estimate of the generated code size.
33524 SDCC is quite liberal in the requirements for jump table generation:
33527 \begin_layout Itemize
33528 The labels need not be in order, and the starting number need not be one
33529 or zero, the case labels are in numerical sequence or not too many case
33530 labels are missing.
33534 \begin_layout Verse
33537 switch(i) {\InsetSpace ~
33568 case 4: ...\InsetSpace ~
33600 case 5: ...\InsetSpace ~
33632 case 3: ...\InsetSpace ~
33663 case 6: ...\InsetSpace ~
33695 case 7: ...\InsetSpace ~
33727 case 8: ...\InsetSpace ~
33759 case 9: ...\InsetSpace ~
33791 case 10: ...\InsetSpace ~
33822 case 11: ...\InsetSpace ~
33889 \begin_layout Standard
33890 Both the above switch statements will be implemented using a jump-table.
33891 The example to the right side is slightly more efficient as the check for
33892 the lower boundary of the jump-table is not needed.
33896 \begin_layout Itemize
33897 The number of case labels is not larger than supported by the target architectur
33901 \begin_layout Itemize
33902 If the case labels are not in numerical sequence ('gaps' between cases)
33903 SDCC checks whether a jump table with additionally inserted dummy cases
33904 is still attractive.
33908 \begin_layout Itemize
33909 If the starting number is not zero and a check for the lower boundary of
33910 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
33915 \begin_layout Standard
33916 Switch statements which have large gaps in the numeric sequence or those
33917 that have too many case labels can be split into more than one switch statement
33918 for efficient code generation, e.g.:
33921 \begin_layout Verse
33999 \begin_layout Standard
34000 If the above switch statement is broken down into two switch statements
34003 \begin_layout Verse
34046 \begin_layout Standard
34050 \begin_layout Verse
34093 \begin_layout Standard
34094 then both the switch statements will be implemented using jump-tables whereas
34095 the unmodified switch statement will not be.
34098 \begin_layout Standard
34099 \begin_inset Note Note
34102 \begin_layout Standard
34103 There might be reasons which SDCC cannot know about to either favour or
34104 not favour jump tables.
34105 If the target system has to be as quick for the last switch case as for
34106 the first (pro jump table), or if the switch argument is known to be zero
34107 in the majority of the cases (contra jump table).
34115 \begin_layout Standard
34116 The pragma nojtbound
34117 \begin_inset LatexCommand \index{\\#pragma nojtbound}
34121 can be used to turn off checking the
34134 It has no effect if a default label is supplied.
34135 Use of this pragma is dangerous: if the switch
34136 \begin_inset LatexCommand \index{switch statement}
34140 argument is not matched by a case statement the processor will happily
34144 \begin_layout Subsection
34145 Bit-shifting Operations
34146 \begin_inset LatexCommand \index{Bit shifting}
34153 \begin_layout Standard
34154 Bit shifting is one of the most frequently used operation in embedded programmin
34156 SDCC tries to implement bit-shift operations in the most efficient way
34160 \begin_layout Verse
34173 \begin_layout Standard
34174 generates the following code:
34177 \begin_layout Verse
34192 \begin_layout Standard
34193 In general SDCC will never setup a loop if the shift count is known.
34197 \begin_layout Verse
34210 \begin_layout Standard
34214 \begin_layout Verse
34238 \begin_layout Subsection
34240 \begin_inset LatexCommand \index{Bit rotation}
34247 \begin_layout Standard
34248 A special case of the bit-shift operation is bit rotation
34249 \begin_inset LatexCommand \index{rotating bits}
34253 , SDCC recognizes the following expression to be a left bit-rotation:
34256 \begin_layout Verse
34264 char i;\InsetSpace ~
34275 /* unsigned is needed for rotation */
34280 i = ((i << 1) | (i >> 7));
34289 \begin_layout Standard
34290 will generate the following code:
34293 \begin_layout Verse
34310 \begin_layout Standard
34311 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
34312 ns of this case will also be recognized as bit-rotation, i.e.:
34315 \begin_layout Verse
34318 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
34321 \begin_layout Subsection
34322 Nibble and Byte Swapping
34325 \begin_layout Standard
34326 Other special cases of the bit-shift operations are nibble or byte swapping
34327 \begin_inset LatexCommand \index{swapping nibbles/bytes}
34331 , SDCC recognizes the following expressions:
34334 \begin_layout Verse
34355 i = ((i << 4) | (i >> 4));
34361 j = ((j << 8) | (j >> 8));
34364 \begin_layout Standard
34365 and generates a swap instruction for the nibble swapping
34366 \begin_inset LatexCommand \index{Nibble swapping}
34370 or move instructions for the byte swapping
34371 \begin_inset LatexCommand \index{Byte swapping}
34377 \begin_inset Quotes sld
34381 \begin_inset Quotes srd
34384 example can be used to convert from little to big-endian or vice versa.
34385 If you want to change the endianness of a
34389 integer you have to cast to
34396 \begin_layout Standard
34397 Note that SDCC stores numbers in little-endian
34401 \begin_layout Standard
34402 Usually 8-bit processors don't care much about endianness.
34403 This is not the case for the standard 8051 which only has an instruction
34409 \begin_inset LatexCommand \index{DPTR}
34413 -datapointer so little-endian is the more efficient byte order.
34419 \begin_inset LatexCommand \index{little-endian}
34424 \begin_inset LatexCommand \index{Endianness}
34429 lowest order first).
34432 \begin_layout Subsection
34434 \begin_inset LatexCommand \index{Highest Order Bit}
34439 \begin_inset LatexCommand \index{Any Order Bit}
34446 \begin_layout Standard
34447 It is frequently required to obtain the highest order bit of an integral
34448 type (long, int, short or char types).
34449 Also obtaining any other order bit is not uncommon.
34450 SDCC recognizes the following expressions to yield the highest order bit
34451 and generates optimized code for it, e.g.:
34454 \begin_layout Verse
34465 unsigned char hob1, aob1;
34469 bit hob2, hob3, aob2,
34479 hob1 = (gint >> 15) & 1;
34483 hob2 = (gint >> 15) & 1;
34487 hob3 = gint & 0x8000;
34492 aob1 = (gint >> 9) & 1;
34496 aob2 = (gint >> 8) & 1;
34500 aob3 = gint & 0x0800;
34510 \begin_layout Standard
34511 will generate the following code:
34514 \begin_layout Verse
34545 000A E5*01\InsetSpace ~
34572 000C 23\InsetSpace ~
34603 000D 54 01\InsetSpace ~
34631 000F F5*02\InsetSpace ~
34686 0011 E5*01\InsetSpace ~
34714 0013 33\InsetSpace ~
34744 0014 92*00\InsetSpace ~
34800 0016 E5*01\InsetSpace ~
34827 0018 33\InsetSpace ~
34857 0019 92*01\InsetSpace ~
34913 001B E5*01\InsetSpace ~
34972 001E 54 01\InsetSpace ~
34999 0020 F5*03\InsetSpace ~
35055 0022 E5*01\InsetSpace ~
35082 0024 13\InsetSpace ~
35112 0025 92*02\InsetSpace ~
35168 0027 E5*01\InsetSpace ~
35223 002B 92*03\InsetSpace ~
35251 \begin_layout Standard
35252 Other variations of these cases however will
35257 They are standard C expressions, so I heartily recommend these be the only
35258 way to get the highest order bit, (it is portable).
35259 Of course it will be recognized even if it is embedded in other expressions,
35263 \begin_layout Verse
35266 xyz = gint + ((gint >> 15) & 1);
35269 \begin_layout Standard
35270 will still be recognized.
35273 \begin_layout Subsection
35275 \begin_inset LatexCommand \index{Higher Order Byte}
35279 / Higher Order Word
35280 \begin_inset LatexCommand \index{Higher Order Word}
35287 \begin_layout Standard
35288 It is also frequently required to obtain a higher order byte or word of
35289 a larger integral type (long, int or short types).
35290 SDCC recognizes the following expressions to yield the higher order byte
35291 or word and generates optimized code for it, e.g.:
35294 \begin_layout Verse
35299 unsigned long int glong;
35307 unsigned char hob1,
35312 unsigned int how1, how2;
35321 hob1 = (gint >> 8) & 0xFF;
35325 hob2 = glong >> 24;
35329 how1 = (glong >> 16) & 0xFFFF;
35344 \begin_layout Standard
35345 will generate the following code:
35348 \begin_layout Verse
35379 0037 85*01*06\InsetSpace ~
35401 _foo_hob1_1_1,(_gint + 1)
35432 003A 85*05*07\InsetSpace ~
35454 _foo_hob2_1_1,(_glong + 3)
35484 003D 85*04*08\InsetSpace ~
35507 _foo_how1_1_1,(_glong + 2)
35509 0040 85*05*09\InsetSpace ~
35534 0043 85*03*0A\InsetSpace ~
35556 _foo_how2_1_1,(_glong + 1)
35558 0046 85*04*0B\InsetSpace ~
35581 (_foo_how2_1_1 + 1),(_glong + 2)
35584 \begin_layout Standard
35585 Again, variations of these cases may
35590 They are standard C expressions, so I heartily recommend these be the only
35591 way to get the higher order byte/word, (it is portable).
35592 Of course it will be recognized even if it is embedded in other expressions,
35596 \begin_layout Verse
35599 xyz = gint + ((gint >> 8) & 0xFF);
35602 \begin_layout Standard
35603 will still be recognized.
35606 \begin_layout Subsection
35608 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
35613 \begin_inset LatexCommand \index{Peephole optimizer}
35620 \begin_layout Standard
35621 The compiler uses a rule based, pattern matching and re-writing mechanism
35622 for peep-hole optimization.
35627 a peep-hole optimizer by Christopher W.
35628 Fraser (cwfraser\InsetSpace ~
35631 A default set of rules are compiled into the compiler, additional rules
35632 may be added with the
35638 \begin_layout Standard
35648 \begin_inset LatexCommand \index{-\\/-peep-file}
35655 The rule language is best illustrated with examples.
35658 \begin_layout Verse
35680 \begin_layout Standard
35681 The above rule will change the following assembly
35682 \begin_inset LatexCommand \index{Assembler routines}
35689 \begin_layout Verse
35697 \begin_layout Standard
35701 \begin_layout Verse
35707 \begin_layout Standard
35708 Note: All occurrences of a
35712 (pattern variable) must denote the same string.
35713 With the above rule, the assembly sequence:
35716 \begin_layout Verse
35724 \begin_layout Standard
35725 will remain unmodified.
35729 Other special case optimizations may be added by the
35736 \begin_layout Standard
35749 some variants of the 8051 MCU
35750 \begin_inset LatexCommand \index{MCS51 variants}
35763 The following two rules will change all
35780 \begin_layout Verse
35783 replace { lcall %1 } by { acall %1 }
35785 replace { ljmp %1 } by { ajmp %1 }
35788 \begin_layout Standard
35789 (NOTE: from version 2.7.3 on, you can use option -
35795 \begin_layout Standard
35807 \begin_inset LatexCommand \index{ajmp}
35811 , which also takes care of aligning the interrupt vectors properly.)
35816 \begin_layout Standard
35819 inline-assembler code
35821 is also passed through the peep hole optimizer, thus the peephole optimizer
35822 can also be used as an assembly level macro expander.
35823 The rules themselves are MCU dependent whereas the rule language infra-structur
35824 e is MCU independent.
35825 Peephole optimization rules for other MCU can be easily programmed using
35830 The syntax for a rule is as follows:
35833 \begin_layout Verse
35836 rule := replace [ restart ] '{' <assembly sequence> '
35874 <assembly sequence> '
35892 '}' [if <functionName> ] '
35897 \begin_layout Standard
35898 <assembly sequence> := assembly instruction (each instruction including
35899 labels must be on a separate line).
35903 The optimizer will apply to the rules
35904 one by one from the top in the sequence of their appearance, it will terminate
35905 when all rules are exhausted.
35906 If the 'restart' option is specified, then the optimizer will start matching
35907 the rules again from the top, this option for a rule is expensive (performance)
35908 , it is intended to be used in situations where a transformation will trigger
35909 the same rule again.
35910 An example of this (not a good one, it has side effects) is the following
35914 \begin_layout Verse
35934 \begin_layout Standard
35935 Note that the replace pattern cannot be a blank, but can be a comment line.
35936 Without the 'restart' option only the innermost 'pop' 'push' pair would
35937 be eliminated, i.e.:
35940 \begin_layout Verse
35952 \begin_layout Standard
35956 \begin_layout Verse
35966 \begin_layout Standard
35971 the restart option the rule will be applied again to the resulting code
35972 and then all the pop-push pairs will be eliminated to yield:
35975 \begin_layout Verse
35983 \begin_layout Standard
35984 A conditional function can be attached to a rule.
35985 Attaching rules are somewhat more involved, let me illustrate this with
35989 \begin_layout Verse
36013 \begin_layout Standard
36014 The optimizer does a look-up of a function name table defined in function
36019 in the source file SDCCpeeph.c, with the name
36024 If it finds a corresponding entry the function is called.
36025 Note there can be no parameters specified for these functions, in this
36030 is crucial, since the function
36034 expects to find the label in that particular variable (the hash table containin
36035 g the variable bindings is passed as a parameter).
36036 If you want to code more such functions, take a close look at the function
36037 labelInRange and the calling mechanism in source file SDCCpeeph.c.
36038 Currently implemented are
36040 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
36041 24bitMode, portIsDS390, 24bitModeAndPortDS390
36050 \begin_layout Standard
36051 I know this whole thing is a little kludgey, but maybe some day we will
36052 have some better means.
36053 If you are looking at this file, you will see the default rules that are
36054 compiled into the compiler, you can add your own rules in the default set
36055 there if you get tired of specifying the -
36059 \begin_layout Standard
36071 \begin_layout Section
36073 \begin_inset LatexCommand \index{ANSI-compliance}
36078 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
36085 \begin_layout Standard
36086 The latest publically available version of the standard
36088 ISO/IEC 9899 - Programming languages - C
36090 should be available at:
36091 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
36100 \begin_layout Standard
36101 Deviations from the compliance:
36104 \begin_layout Itemize
36105 functions are not reentrant
36106 \begin_inset LatexCommand \index{reentrant}
36110 unless explicitly declared as such or the
36116 \begin_layout Standard
36126 \begin_inset LatexCommand \index{-\\/-stack-auto}
36132 command line option is specified.
36135 \begin_layout Itemize
36137 \begin_inset LatexCommand \index{struct}
36142 \begin_inset LatexCommand \index{union}
36146 cannot be assigned values directly, cannot be passed as function parameters
36147 or assigned to each other and cannot be a return value
36148 \begin_inset LatexCommand \index{return value}
36152 from a function, e.g.:
36156 \begin_layout Verse
36179 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
36204 s parms) /* invalid in SDCC although allowed in ANSI */
36226 return rets; /* is invalid in SDCC although allowed in ANSI */
36232 \begin_layout Itemize
36233 initialization of structure arrays must be fully braced.
36237 \begin_layout Verse
36240 struct s { char x } a[] = {1, 2};\InsetSpace ~
36245 /* invalid in SDCC */
36248 } a[] = {{1}, {2}}; /* OK */
36252 \begin_layout Itemize
36254 \begin_inset LatexCommand \index{long long (not supported)}
36259 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
36266 \begin_layout Itemize
36268 \begin_inset LatexCommand \index{double (not supported)}
36272 ' precision floating point
36273 \begin_inset LatexCommand \index{Floating point support}
36280 \begin_layout Itemize
36282 \begin_inset LatexCommand \index{K\\&R style}
36286 function declarations are NOT allowed.
36290 \begin_layout Verse
36293 foo(i,j) /* this old style of function declarations */
36295 int i,j; /* is valid
36296 in ANSI but not valid in SDCC */
36311 \begin_layout Itemize
36312 Most enhancements in C99 are not supported, e.g.:
36316 \begin_layout Verse
36326 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
36330 \begin_layout Itemize
36331 But some have been added recently in SDCC 2.7.0.
36332 They must be considered alpha quality however.
36336 \begin_layout Verse
36341 \begin_inset LatexCommand \index{inline (not supported)}
36350 int increment (int a) { return a+1; } /* inlines the increment without function
36359 \begin_inset LatexCommand \index{inline (not supported)}
36368 p; /* accepted but ignored */
36372 \begin_layout Itemize
36373 Certain words that are valid identifiers in the standard may be reserved
36374 words in SDCC unless the
36380 \begin_layout Standard
36390 \begin_inset LatexCommand \index{-\\/-std-c89}
36398 \begin_layout Standard
36408 \begin_inset LatexCommand \index{-\\/-std-c99}
36414 command line options are used.
36415 These may include (depending on the selected processor): 'at', 'banked',
36416 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
36417 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
36418 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
36420 Compliant equivalents of these keywords are always available in a form
36421 that begin with two underscores
36422 \begin_inset LatexCommand \index{\\_\\_ (prefix for extended keywords)}
36427 '__data' instead of 'data'.
36430 \begin_layout Section
36431 Cyclomatic Complexity
36432 \begin_inset LatexCommand \index{Cyclomatic complexity}
36439 \begin_layout Standard
36440 Cyclomatic complexity of a function is defined as the number of independent
36441 paths the program can take during execution of the function.
36442 This is an important number since it defines the number test cases you
36443 have to generate to validate the function.
36444 The accepted industry standard for complexity number is 10, if the cyclomatic
36445 complexity reported by SDCC exceeds 10 you should think about simplification
36446 of the function logic.
36447 Note that the complexity level is not related to the number of lines of
36448 code in a function.
36449 Large functions can have low complexity, and small functions can have large
36455 SDCC uses the following formula to compute the complexity:
36460 \begin_layout Standard
36461 complexity = (number of edges in control flow graph) - (number of nodes
36462 in control flow graph) + 2;
36466 Having said that the industry standard is 10,
36467 you should be aware that in some cases it be may unavoidable to have a
36468 complexity level of less than 10.
36469 For example if you have switch statement with more than 10 case labels,
36470 each case label adds one to the complexity level.
36471 The complexity level is by no means an absolute measure of the algorithmic
36472 complexity of the function, it does however provide a good starting point
36473 for which functions you might look at for further optimization.
36476 \begin_layout Section
36477 Retargetting for other Processors
36480 \begin_layout Standard
36481 The issues for retargetting the compiler are far too numerous to be covered
36483 What follows is a brief description of each of the seven phases of the
36484 compiler and its MCU dependency.
36487 \begin_layout Itemize
36488 Parsing the source and building the annotated parse tree.
36489 This phase is largely MCU independent (except for the language extensions).
36490 Syntax & semantic checks are also done in this phase, along with some initial
36491 optimizations like back patching labels and the pattern matching optimizations
36492 like bit-rotation etc.
36495 \begin_layout Itemize
36496 The second phase involves generating an intermediate code which can be easy
36497 manipulated during the later phases.
36498 This phase is entirely MCU independent.
36499 The intermediate code generation assumes the target machine has unlimited
36500 number of registers, and designates them with the name iTemp.
36501 The compiler can be made to dump a human readable form of the code generated
36506 \begin_layout Standard
36518 \begin_layout Itemize
36519 This phase does the bulk of the standard optimizations and is also MCU independe
36521 This phase can be broken down into several sub-phases:
36525 Break down intermediate
36526 code (iCode) into basic blocks.
36528 Do control flow & data flow analysis on the
36531 Do local common subexpression elimination, then global subexpressio
36534 Dead code elimination
36538 If loop optimizations
36539 caused any changes then do 'global subexpression elimination' and 'dead
36540 code elimination' again.
36543 \begin_layout Itemize
36544 This phase determines the live-ranges; by live range I mean those iTemp
36545 variables defined by the compiler that still survive after all the optimization
36547 Live range analysis
36548 \begin_inset LatexCommand \index{Live range analysis}
36552 is essential for register allocation, since these computation determines
36553 which of these iTemps will be assigned to registers, and for how long.
36556 \begin_layout Itemize
36557 Phase five is register allocation.
36558 There are two parts to this process.
36562 The first part I call 'register packing'
36563 (for lack of a better term).
36564 In this case several MCU specific expression folding is done to reduce
36569 The second part is more MCU independent and deals with
36570 allocating registers to the remaining live ranges.
36571 A lot of MCU specific code does creep into this phase because of the limited
36572 number of index registers available in the 8051.
36575 \begin_layout Itemize
36576 The Code generation phase is (unhappily), entirely MCU dependent and very
36577 little (if any at all) of this code can be reused for other MCU.
36578 However the scheme for allocating a homogenized assembler operand for each
36579 iCode operand may be reused.
36582 \begin_layout Itemize
36583 As mentioned in the optimization section the peep-hole optimizer is rule
36584 based system, which can reprogrammed for other MCUs.
36587 \begin_layout Standard
36588 More information is available on SDCC Wiki
36589 \begin_inset LatexCommand \index{wiki}
36594 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting}
36598 ) and in the thread
36599 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
36606 \begin_layout Chapter
36608 \begin_inset LatexCommand \index{Compiler internals}
36615 \begin_layout Section
36616 The anatomy of the compiler
36617 \begin_inset LatexCommand \label{sub:The-anatomy-of}
36624 \begin_layout Standard
36627 This is an excerpt from an article published in Circuit Cellar Magazine
36636 It's a little outdated (the compiler is much more efficient now and user/develo
36637 per friendly), but pretty well exposes the guts of it all.
36643 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
36644 It is fairly easy to retarget for other 8-bit MCU.
36645 Here we take a look at some of the internals of the compiler.
36649 \begin_layout Paragraph*
36651 \begin_inset LatexCommand \index{Parsing}
36658 \begin_layout Standard
36659 Parsing the input source file and creating an AST (Annotated Syntax Tree
36660 \begin_inset LatexCommand \index{Annotated syntax tree}
36665 This phase also involves propagating types (annotating each node of the
36666 parse tree with type information) and semantic analysis.
36667 There are some MCU specific parsing rules.
36668 For example the storage classes, the extended storage classes are MCU specific
36669 while there may be a xdata storage class for 8051 there is no such storage
36670 class for z80 or Atmel AVR.
36671 SDCC allows MCU specific storage class extensions, i.e.
36672 xdata will be treated as a storage class specifier when parsing 8051 C
36673 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
36677 \begin_layout Paragraph*
36679 \begin_inset LatexCommand \index{iCode}
36686 \begin_layout Standard
36687 Intermediate code generation.
36688 In this phase the AST is broken down into three-operand form (iCode).
36689 These three operand forms are represented as doubly linked lists.
36690 ICode is the term given to the intermediate form generated by the compiler.
36691 ICode example section shows some examples of iCode generated for some simple
36692 C source functions.
36695 \begin_layout Paragraph*
36697 \begin_inset LatexCommand \index{Optimizations}
36704 \begin_layout Standard
36705 Bulk of the target independent optimizations is performed in this phase.
36706 The optimizations include constant propagation, common sub-expression eliminati
36707 on, loop invariant code movement, strength reduction of loop induction variables
36708 and dead-code elimination.
36711 \begin_layout Paragraph*
36712 Live range analysis
36713 \begin_inset LatexCommand \index{Live range analysis}
36720 \begin_layout Standard
36721 During intermediate code generation phase, the compiler assumes the target
36722 machine has infinite number of registers and generates a lot of temporary
36724 The live range computation determines the lifetime of each of these compiler-ge
36725 nerated temporaries.
36726 A picture speaks a thousand words.
36727 ICode example sections show the live range annotations for each of the
36729 It is important to note here, each iCode is assigned a number in the order
36730 of its execution in the function.
36731 The live ranges are computed in terms of these numbers.
36732 The from number is the number of the iCode which first defines the operand
36733 and the to number signifies the iCode which uses this operand last.
36736 \begin_layout Paragraph*
36737 Register Allocation
36738 \begin_inset LatexCommand \index{Register allocation}
36745 \begin_layout Standard
36746 The register allocation determines the type and number of registers needed
36748 In most MCUs only a few registers can be used for indirect addressing.
36749 In case of 8051 for example the registers R0 & R1 can be used to indirectly
36750 address the internal ram and DPTR to indirectly address the external ram.
36751 The compiler will try to allocate the appropriate register to pointer variables
36753 ICode example section shows the operands annotated with the registers assigned
36755 The compiler will try to keep operands in registers as much as possible;
36756 there are several schemes the compiler uses to do achieve this.
36757 When the compiler runs out of registers the compiler will check to see
36758 if there are any live operands which is not used or defined in the current
36759 basic block being processed, if there are any found then it will push that
36760 operand and use the registers in this block, the operand will then be popped
36761 at the end of the basic block.
36765 \begin_layout Standard
36766 There are other MCU specific considerations in this phase.
36767 Some MCUs have an accumulator; very short-lived operands could be assigned
36768 to the accumulator instead of a general-purpose register.
36771 \begin_layout Paragraph*
36775 \begin_layout Standard
36776 Figure II gives a table of iCode
36777 \begin_inset LatexCommand \index{iCode}
36781 operations supported by the compiler.
36782 The code generation involves translating these operations into corresponding
36783 assembly code for the processor.
36784 This sounds overly simple but that is the essence of code generation.
36785 Some of the iCode operations are generated on a MCU specific manner for
36786 example, the z80 port does not use registers to pass parameters so the
36787 SEND and RECV iCode operations will not be generated, and it also does
36788 not support JUMPTABLES.
36794 \begin_layout Standard
36798 \begin_inset Tabular
36799 <lyxtabular version="3" rows="39" columns="4">
36800 <features islongtable="true" headBottomDL="true">
36801 <column alignment="block" valignment="top" leftline="true" width="13col%">
36802 <column alignment="left" valignment="top" leftline="true" width="13col%">
36803 <column alignment="block" valignment="top" leftline="true" width="22col%">
36804 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
36805 <row topline="true" bottomline="true" endhead="true">
36806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36809 \begin_layout Standard
36815 \begin_inset LatexCommand \index{iCode}
36824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36827 \begin_layout Standard
36835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36838 \begin_layout Standard
36846 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36849 \begin_layout Standard
36858 <row topline="true">
36859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36862 \begin_layout Standard
36870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36873 \begin_layout Standard
36876 IC_LEFT() IC_RESULT()
36881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36884 \begin_layout Standard
36892 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36895 \begin_layout Standard
36898 IC_RESULT = ! IC_LEFT;
36904 <row topline="true">
36905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36908 \begin_layout Standard
36916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36919 \begin_layout Standard
36922 IC_LEFT() IC_RESULT()
36927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36930 \begin_layout Standard
36933 Bitwise complement of
36938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36941 \begin_layout Standard
36944 IC_RESULT = ~IC_LEFT;
36950 <row topline="true">
36951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36954 \begin_layout Standard
36962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36965 \begin_layout Standard
36968 IC_LEFT() IC_RESULT()
36973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36976 \begin_layout Standard
36979 Rotate right with carry
36984 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36987 \begin_layout Standard
36990 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
36996 <row topline="true">
36997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37000 \begin_layout Standard
37008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37011 \begin_layout Standard
37014 IC_LEFT() IC_RESULT()
37019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37022 \begin_layout Standard
37025 Rotate left with carry
37030 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37033 \begin_layout Standard
37036 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
37042 <row topline="true">
37043 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37046 \begin_layout Standard
37054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37057 \begin_layout Standard
37060 IC_LEFT() IC_RESULT()
37065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37068 \begin_layout Standard
37071 Get the highest order bit of IC_LEFT
37076 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37079 \begin_layout Standard
37082 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
37088 <row topline="true">
37089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37092 \begin_layout Standard
37100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37103 \begin_layout Standard
37106 IC_LEFT() IC_RESULT()
37111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37114 \begin_layout Standard
37122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37125 \begin_layout Standard
37128 IC_RESULT = - IC_LEFT;
37134 <row topline="true">
37135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37138 \begin_layout Standard
37146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37149 \begin_layout Standard
37157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37160 \begin_layout Standard
37163 Push the operand into stack
37168 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37171 \begin_layout Standard
37180 <row topline="true">
37181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37184 \begin_layout Standard
37192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37195 \begin_layout Standard
37203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37206 \begin_layout Standard
37209 Pop the operand from the stack
37214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37217 \begin_layout Standard
37226 <row topline="true">
37227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37230 \begin_layout Standard
37238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37241 \begin_layout Standard
37244 IC_LEFT() IC_RESULT()
37249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37252 \begin_layout Standard
37255 Call the function represented by IC_LEFT
37260 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37263 \begin_layout Standard
37266 IC_RESULT = IC_LEFT();
37272 <row topline="true">
37273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37276 \begin_layout Standard
37284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37287 \begin_layout Standard
37290 IC_LEFT() IC_RESULT()
37295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37298 \begin_layout Standard
37301 Call via function pointer
37306 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37309 \begin_layout Standard
37312 IC_RESULT = (*IC_LEFT)();
37318 <row topline="true">
37319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37322 \begin_layout Standard
37330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37333 \begin_layout Standard
37341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37344 \begin_layout Standard
37347 Return the value in operand IC_LEFT
37352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37355 \begin_layout Standard
37364 <row topline="true">
37365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37368 \begin_layout Standard
37376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37379 \begin_layout Standard
37387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37390 \begin_layout Standard
37398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37401 \begin_layout Standard
37410 <row topline="true">
37411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37414 \begin_layout Standard
37422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37425 \begin_layout Standard
37433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37436 \begin_layout Standard
37444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37447 \begin_layout Standard
37456 <row topline="true">
37457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37460 \begin_layout Standard
37468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37471 \begin_layout Standard
37474 IC_LEFT() IC_RIGHT() IC_RESULT()
37479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37482 \begin_layout Standard
37490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37493 \begin_layout Standard
37496 IC_RESULT = IC_LEFT + IC_RIGHT
37502 <row topline="true">
37503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37506 \begin_layout Standard
37514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37517 \begin_layout Standard
37520 IC_LEFT() IC_RIGHT() IC_RESULT()
37525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37528 \begin_layout Standard
37536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37539 \begin_layout Standard
37542 IC_RESULT = IC_LEFT - IC_RIGHT
37548 <row topline="true">
37549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37552 \begin_layout Standard
37560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37563 \begin_layout Standard
37566 IC_LEFT() IC_RIGHT() IC_RESULT()
37571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37574 \begin_layout Standard
37582 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37585 \begin_layout Standard
37588 IC_RESULT = IC_LEFT * IC_RIGHT;
37594 <row topline="true">
37595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37598 \begin_layout Standard
37606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37609 \begin_layout Standard
37612 IC_LEFT() IC_RIGHT() IC_RESULT()
37617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37620 \begin_layout Standard
37628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37631 \begin_layout Standard
37634 IC_RESULT = IC_LEFT / IC_RIGHT;
37640 <row topline="true">
37641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37644 \begin_layout Standard
37652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37655 \begin_layout Standard
37658 IC_LEFT() IC_RIGHT() IC_RESULT()
37663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37666 \begin_layout Standard
37674 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37677 \begin_layout Standard
37680 IC_RESULT = IC_LEFT % IC_RIGHT;
37686 <row topline="true">
37687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37690 \begin_layout Standard
37698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37701 \begin_layout Standard
37704 IC_LEFT() IC_RIGHT() IC_RESULT()
37709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37712 \begin_layout Standard
37720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37723 \begin_layout Standard
37726 IC_RESULT = IC_LEFT < IC_RIGHT;
37732 <row topline="true">
37733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37736 \begin_layout Standard
37744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37747 \begin_layout Standard
37750 IC_LEFT() IC_RIGHT() IC_RESULT()
37755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37758 \begin_layout Standard
37766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37769 \begin_layout Standard
37772 IC_RESULT = IC_LEFT > IC_RIGHT;
37778 <row topline="true">
37779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37782 \begin_layout Standard
37790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37793 \begin_layout Standard
37796 IC_LEFT() IC_RIGHT() IC_RESULT()
37801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37804 \begin_layout Standard
37812 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37815 \begin_layout Standard
37818 IC_RESULT = IC_LEFT == IC_RIGHT;
37824 <row topline="true">
37825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37828 \begin_layout Standard
37836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37839 \begin_layout Standard
37842 IC_LEFT() IC_RIGHT() IC_RESULT()
37847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37850 \begin_layout Standard
37853 Logical and operation
37858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37861 \begin_layout Standard
37864 IC_RESULT = IC_LEFT && IC_RIGHT;
37870 <row topline="true">
37871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37874 \begin_layout Standard
37882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37885 \begin_layout Standard
37888 IC_LEFT() IC_RIGHT() IC_RESULT()
37893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37896 \begin_layout Standard
37899 Logical or operation
37904 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37907 \begin_layout Standard
37910 IC_RESULT = IC_LEFT || IC_RIGHT;
37916 <row topline="true">
37917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37920 \begin_layout Standard
37928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37931 \begin_layout Standard
37934 IC_LEFT() IC_RIGHT() IC_RESULT()
37939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37942 \begin_layout Standard
37950 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37953 \begin_layout Standard
37956 IC_RESULT = IC_LEFT ^ IC_RIGHT;
37962 <row topline="true">
37963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37966 \begin_layout Standard
37974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37977 \begin_layout Standard
37980 IC_LEFT() IC_RIGHT() IC_RESULT()
37985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37988 \begin_layout Standard
37996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37999 \begin_layout Standard
38002 IC_RESULT = IC_LEFT | IC_RIGHT;
38008 <row topline="true">
38009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38012 \begin_layout Standard
38020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38023 \begin_layout Standard
38026 IC_LEFT() IC_RIGHT() IC_RESULT()
38031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38034 \begin_layout Standard
38042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38045 \begin_layout Standard
38048 IC_RESULT = IC_LEFT & IC_RIGHT;
38054 <row topline="true">
38055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38058 \begin_layout Standard
38066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38069 \begin_layout Standard
38072 IC_LEFT() IC_RIGHT() IC_RESULT()
38077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38080 \begin_layout Standard
38088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38091 \begin_layout Standard
38094 IC_RESULT = IC_LEFT << IC_RIGHT
38100 <row topline="true">
38101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38104 \begin_layout Standard
38112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38115 \begin_layout Standard
38118 IC_LEFT() IC_RIGHT() IC_RESULT()
38123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38126 \begin_layout Standard
38134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38137 \begin_layout Standard
38140 IC_RESULT = IC_LEFT >> IC_RIGHT
38146 <row topline="true">
38147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38150 \begin_layout Standard
38160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38163 \begin_layout Standard
38166 IC_LEFT() IC_RESULT()
38171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38174 \begin_layout Standard
38182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38185 \begin_layout Standard
38188 IC_RESULT = (*IC_LEFT);
38194 <row topline="true">
38195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38198 \begin_layout Standard
38206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38209 \begin_layout Standard
38212 IC_RIGHT() IC_RESULT()
38217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38220 \begin_layout Standard
38228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38231 \begin_layout Standard
38234 (*IC_RESULT) = IC_RIGHT;
38240 <row topline="true">
38241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38244 \begin_layout Standard
38252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38255 \begin_layout Standard
38258 IC_RIGHT() IC_RESULT()
38263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38266 \begin_layout Standard
38274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38277 \begin_layout Standard
38280 IC_RESULT = IC_RIGHT;
38286 <row topline="true">
38287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38290 \begin_layout Standard
38298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38301 \begin_layout Standard
38304 IC_COND IC_TRUE IC_LABEL
38309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38312 \begin_layout Standard
38316 If true label is present then jump to true label if condition is true else
38317 jump to false label if condition is false
38322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38325 \begin_layout Standard
38328 if (IC_COND) goto IC_TRUE;
38334 If (!IC_COND) goto IC_FALSE;
38340 <row topline="true">
38341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38344 \begin_layout Standard
38352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38355 \begin_layout Standard
38358 IC_LEFT() IC_RESULT()
38363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38366 \begin_layout Standard
38374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38377 \begin_layout Standard
38380 IC_RESULT = &IC_LEFT();
38386 <row topline="true">
38387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38390 \begin_layout Standard
38398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38401 \begin_layout Standard
38404 IC_JTCOND IC_JTLABELS
38409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38412 \begin_layout Standard
38415 Jump to list of labels depending on the value of JTCOND
38420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38423 \begin_layout Standard
38432 <row topline="true">
38433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38436 \begin_layout Standard
38444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38447 \begin_layout Standard
38450 IC_RIGHT() IC_LEFT() IC_RESULT()
38455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38458 \begin_layout Standard
38466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38469 \begin_layout Standard
38472 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
38478 <row topline="true">
38479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38482 \begin_layout Standard
38490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38493 \begin_layout Standard
38501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38504 \begin_layout Standard
38507 This is used for passing parameters in registers;
38509 move IC_LEFT to the next
38510 available parameter register.
38515 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38518 \begin_layout Standard
38527 <row topline="true">
38528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38531 \begin_layout Standard
38539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38542 \begin_layout Standard
38550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38553 \begin_layout Standard
38556 This is used for receiving parameters passed in registers;
38559 in the next parameter register to IC_RESULT
38564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38567 \begin_layout Standard
38576 <row topline="true" bottomline="true">
38577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38580 \begin_layout Standard
38584 (some more have been added)
38589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38592 \begin_layout Standard
38598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38601 \begin_layout Standard
38607 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38610 \begin_layout Standard
38643 \begin_layout Standard
38644 \begin_inset Note Note
38647 \begin_layout Standard
38648 In the original article Figure II was announced to be downloadable on
38653 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
38661 \begin_layout Paragraph*
38663 \begin_inset LatexCommand \index{iCode}
38670 \begin_layout Standard
38671 This section shows some details of iCode.
38672 The example C code does not do anything useful; it is used as an example
38673 to illustrate the intermediate code generated by the compiler.
38676 \begin_layout Verse
38686 /* This function does nothing useful.
38693 for the purpose of explaining iCode */
38696 short function (data
38705 short i=10; \InsetSpace ~
38707 /* dead initialization eliminated */
38713 /* dead initialization eliminated */
38741 /* compiler detects i,j to be induction
38746 for (i = 0, j = 10 ; i < 10 ; i++, j
38752 \begin_layout Standard
38775 mul += i * 3; \InsetSpace ~
38777 /* this multiplication remains */
38784 j * 3;\InsetSpace ~
38786 /* this multiplication changed to addition */
38800 \begin_layout Standard
38801 In addition to the operands each iCode contains information about the filename
38802 and line it corresponds to in the source file.
38803 The first field in the listing should be interpreted as follows:
38808 Filename(linenumber: iCode Execution sequence number : ICode hash table
38809 key : loop depth of the iCode).
38814 Then follows the human readable form of the ICode operation.
38815 Each operand of this triplet form can be of three basic types a) compiler
38816 generated temporary b) user defined variable c) a constant value.
38817 Note that local variables and parameters are replaced by compiler generated
38820 \begin_inset LatexCommand \index{Live range analysis}
38824 are computed only for temporaries (i.e.
38825 live ranges are not computed for global variables).
38827 \begin_inset LatexCommand \index{Register allocation}
38831 are allocated for temporaries only.
38832 Operands are formatted in the following manner:
38837 Operand Name [lr live-from : live-to ] { type information } [ registers
38843 As mentioned earlier the live ranges are computed in terms of the execution
38844 sequence number of the iCodes, for example
38846 the iTemp0 is live from (i.e.
38847 first defined in iCode with execution sequence number 3, and is last used
38848 in the iCode with sequence number 5).
38849 For induction variables such as iTemp21 the live range computation extends
38850 the lifetime from the start to the end of the loop.
38852 The register allocator
38853 used the live range information to allocate registers, the same registers
38854 may be used for different temporaries if their live ranges do not overlap,
38855 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
38856 ranges do not overlap.
38857 In addition the allocator also takes into consideration the type and usage
38858 of a temporary, for example itemp6 is a pointer to near space and is used
38859 as to fetch data from (i.e.
38860 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
38861 Some short lived temporaries are allocated to special registers which have
38862 meaning to the code generator e.g.
38863 iTemp13 is allocated to a pseudo register CC which tells the back end that
38864 the temporary is used only for a conditional jump the code generation makes
38865 use of this information to optimize a compare and jump ICode.
38869 \begin_inset LatexCommand \index{Loop optimization}
38873 performed by the compiler.
38874 It can detect induction variables iTemp21(i) and iTemp23(j).
38875 Also note the compiler does selective strength reduction
38876 \begin_inset LatexCommand \index{Strength reduction}
38881 the multiplication of an induction variable in line 18 (gint = j * 3) is
38882 changed to addition, a new temporary iTemp17 is allocated and assigned
38883 a initial value, a constant 3 is then added for each iteration of the loop.
38884 The compiler does not change the multiplication
38885 \begin_inset LatexCommand \index{Multiplication}
38889 in line 17 however since the processor does support an 8 * 8 bit multiplication.
38892 Note the dead code elimination
38893 \begin_inset LatexCommand \index{Dead-code elimination}
38897 optimization eliminated the dead assignments in line 7 & 8 to I and sum
38903 \begin_layout Standard
38906 Sample.c (5:1:0:0) _entry($9) :
38909 \begin_layout Standard
38912 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
38915 \begin_layout Standard
38918 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
38921 \begin_layout Standard
38924 Sample.c(11:4:53:0) preHeaderLbl0($11) :
38927 \begin_layout Standard
38930 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
38934 \begin_layout Standard
38937 Sample.c(11:6:5:1) _whilecontinue_0($1) :
38940 \begin_layout Standard
38943 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
38947 \begin_layout Standard
38950 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38953 \begin_layout Standard
38956 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
38960 \begin_layout Standard
38963 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
38967 \begin_layout Standard
38970 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
38974 \begin_layout Standard
38977 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
38981 \begin_layout Standard
38984 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
38985 * int}[r0] + 0x2 {short}
38988 \begin_layout Standard
38991 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
38994 \begin_layout Standard
38997 Sample.c(11:17:21:0)_whilebreak_0($3) :
39000 \begin_layout Standard
39003 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39006 \begin_layout Standard
39009 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39012 \begin_layout Standard
39015 Sample.c(15:20:54:0)preHeaderLbl1($13) :
39018 \begin_layout Standard
39021 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39024 \begin_layout Standard
39027 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39030 \begin_layout Standard
39033 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39036 \begin_layout Standard
39039 Sample.c(15:24:26:1)_forcond_0($4) :
39042 \begin_layout Standard
39045 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
39049 \begin_layout Standard
39052 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39055 \begin_layout Standard
39058 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
39059 + ITemp21 [lr21:38]{short}[r4]
39062 \begin_layout Standard
39065 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
39069 \begin_layout Standard
39072 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
39073 + iTemp15 [lr29:30]{short}[r1]
39076 \begin_layout Standard
39079 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
39083 \begin_layout Standard
39086 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
39090 \begin_layout Standard
39093 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
39097 \begin_layout Standard
39100 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
39104 \begin_layout Standard
39107 Sample.c(19:38:47:1) goto _forcond_0($4)
39110 \begin_layout Standard
39113 Sample.c(19:39:48:0)_forbreak_0($7) :
39116 \begin_layout Standard
39119 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
39120 + ITemp11 [lr19:40]{short}[r3]
39123 \begin_layout Standard
39126 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
39129 \begin_layout Standard
39132 Sample.c(20:42:51:0)_return($8) :
39135 \begin_layout Standard
39138 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
39144 Finally the code generated for this function:
39149 \begin_layout Standard
39155 \begin_layout Standard
39161 \begin_layout Standard
39169 \begin_layout Standard
39175 \begin_layout Standard
39183 \begin_layout Standard
39189 \begin_layout Standard
39192 ; ----------------------------------------------
39195 \begin_layout Standard
39198 ; function function
39201 \begin_layout Standard
39204 ; ----------------------------------------------
39207 \begin_layout Standard
39213 \begin_layout Standard
39216 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
39219 \begin_layout Standard
39227 \begin_layout Standard
39230 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
39233 \begin_layout Standard
39241 \begin_layout Standard
39244 ;_whilecontinue_0($1) :
39247 \begin_layout Standard
39253 \begin_layout Standard
39256 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
39259 \begin_layout Standard
39262 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39265 \begin_layout Standard
39273 \begin_layout Standard
39281 \begin_layout Standard
39289 \begin_layout Standard
39297 \begin_layout Standard
39305 \begin_layout Standard
39313 \begin_layout Standard
39321 \begin_layout Standard
39327 \begin_layout Standard
39330 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
39333 \begin_layout Standard
39341 \begin_layout Standard
39349 \begin_layout Standard
39352 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
39355 \begin_layout Standard
39363 \begin_layout Standard
39371 \begin_layout Standard
39379 \begin_layout Standard
39387 \begin_layout Standard
39395 \begin_layout Standard
39403 \begin_layout Standard
39406 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
39409 \begin_layout Standard
39417 \begin_layout Standard
39425 \begin_layout Standard
39433 \begin_layout Standard
39441 \begin_layout Standard
39449 \begin_layout Standard
39452 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
39455 \begin_layout Standard
39463 \begin_layout Standard
39471 \begin_layout Standard
39479 \begin_layout Standard
39482 ; iTemp6 [lr5:16]{_near * int}[r0] =
39485 \begin_layout Standard
39488 ; iTemp6 [lr5:16]{_near * int}[r0] +
39491 \begin_layout Standard
39497 \begin_layout Standard
39505 \begin_layout Standard
39508 ; goto _whilecontinue_0($1)
39511 \begin_layout Standard
39519 \begin_layout Standard
39522 ; _whilebreak_0($3) :
39525 \begin_layout Standard
39531 \begin_layout Standard
39534 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39537 \begin_layout Standard
39545 \begin_layout Standard
39548 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39551 \begin_layout Standard
39559 \begin_layout Standard
39562 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39565 \begin_layout Standard
39573 \begin_layout Standard
39576 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39579 \begin_layout Standard
39587 \begin_layout Standard
39595 \begin_layout Standard
39598 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39601 \begin_layout Standard
39609 \begin_layout Standard
39617 \begin_layout Standard
39623 \begin_layout Standard
39629 \begin_layout Standard
39632 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
39635 \begin_layout Standard
39638 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39641 \begin_layout Standard
39649 \begin_layout Standard
39657 \begin_layout Standard
39665 \begin_layout Standard
39673 \begin_layout Standard
39681 \begin_layout Standard
39687 \begin_layout Standard
39690 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
39693 \begin_layout Standard
39696 ; iTemp21 [lr21:38]{short}[r4]
39699 \begin_layout Standard
39707 \begin_layout Standard
39715 \begin_layout Standard
39723 \begin_layout Standard
39726 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
39729 \begin_layout Standard
39737 \begin_layout Standard
39745 \begin_layout Standard
39753 \begin_layout Standard
39761 \begin_layout Standard
39764 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
39767 \begin_layout Standard
39770 ; iTemp15 [lr29:30]{short}[r1]
39773 \begin_layout Standard
39781 \begin_layout Standard
39789 \begin_layout Standard
39792 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
39795 \begin_layout Standard
39803 \begin_layout Standard
39811 \begin_layout Standard
39819 \begin_layout Standard
39827 \begin_layout Standard
39835 \begin_layout Standard
39843 \begin_layout Standard
39846 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
39849 \begin_layout Standard
39857 \begin_layout Standard
39865 \begin_layout Standard
39873 \begin_layout Standard
39881 \begin_layout Standard
39889 \begin_layout Standard
39897 \begin_layout Standard
39900 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
39903 \begin_layout Standard
39911 \begin_layout Standard
39914 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
39917 \begin_layout Standard
39925 \begin_layout Standard
39930 cjne r5,#0xff,00104$
39933 \begin_layout Standard
39941 \begin_layout Standard
39944 ; goto _forcond_0($4)
39947 \begin_layout Standard
39955 \begin_layout Standard
39958 ; _forbreak_0($7) :
39961 \begin_layout Standard
39967 \begin_layout Standard
39970 ; ret iTemp24 [lr40:41]{short}
39973 \begin_layout Standard
39981 \begin_layout Standard
39989 \begin_layout Standard
39997 \begin_layout Standard
40003 \begin_layout Standard
40009 \begin_layout Standard
40019 \begin_layout Section
40020 A few words about basic block successors, predecessors and dominators
40023 \begin_layout Standard
40024 Successors are basic blocks
40025 \begin_inset LatexCommand \index{Basic blocks}
40029 that might execute after this basic block.
40031 Predecessors are basic blocks
40032 that might execute before reaching this basic block.
40034 Dominators are basic
40035 blocks that WILL execute before reaching this basic block.
40040 \begin_layout Standard
40044 \begin_layout Standard
40048 \begin_layout Standard
40056 \begin_layout Standard
40060 \begin_layout Standard
40068 \begin_layout Standard
40074 \begin_layout Standard
40075 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
40078 \begin_layout Standard
40079 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
40082 \begin_layout Standard
40083 c) domVect of [BB4] = BB1 ...
40084 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
40088 \begin_layout Chapter
40092 \begin_layout Standard
40093 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
40103 Thanks to all the other volunteer developers who have helped with coding,
40104 testing, web-page creation, distribution sets, etc.
40105 You know who you are :-)
40113 Thanks to Sourceforge
40114 \begin_inset LatexCommand \url{http://www.sf.net}
40118 which has hosted the project since 1999 and donates significant download
40127 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
40128 cycles and bandwidth for snapshot builds.
40133 \begin_layout Standard
40134 This document was initially written by Sandeep Dutta
40137 \begin_layout Standard
40138 All product names mentioned herein may be trademarks
40139 \begin_inset LatexCommand \index{Trademarks}
40143 of their respective companies.
40147 \begin_layout Section*
40151 \begin_layout Standard
40152 To avoid confusion, the installation and building options for SDCC itself
40153 (chapter 2) are not part of the index.
40156 \begin_layout Standard
40157 \begin_inset LatexCommand \printindex{}