1 #LyX 1.4.2 created this file. For more info see http://www.lyx.org/
7 \pdfoptionpdfminorversion=3
9 pdftitle={SDCC Compiler User Guide},
10 pdfauthor={SDCC development team},
11 pdfsubject={installation, user manual},
12 pdfkeywords={68hc08 8032 8051 ansi c compiler assembler CPU DS390 embedded development free Floating Point Arithmetic Freescale GPL HC08 inline Intel ISO/IEC 9899:1990 Linux MAC OS X manual Maxim mcs51 Microchip microcontroller open source PIC Unix Windows Z80 Zilog},
13 pdfpagemode=UseOutlines,
15 linkcolor=blue] {hyperref}
19 \emergencystretch=30pt
24 \inputencoding default
27 \paperfontsize default
29 \papersize letterpaper
34 \paperorientation portrait
41 \paragraph_separation indent
43 \quotes_language swedish
47 \tracking_changes false
53 \begin_layout Standard
54 \begin_inset Note Note
57 \begin_layout Standard
58 Please note: double dashed longoptions (e.g.
59 --version) are written this way: -
63 \begin_layout Standard
75 \begin_layout Standard
77 three consecutive dashes would otherwise result in a long resp.
81 \begin_layout Standard
82 Architecture specific stuff (like memory models, code examples) should maybe
86 \begin_layout Standard
87 into seperate sections/chapters/appendices (it is hard to document PIC or
91 \begin_layout Standard
92 a 8051 centered document) - for now simply add.
101 SDCC Compiler User Guide
116 \begin_layout Standard
117 \begin_inset Note Note
120 \begin_layout Standard
121 The above strings enclosed in $ are automatically updated by Subversion
129 \begin_layout Standard
130 \begin_inset LatexCommand \tableofcontents{}
137 \begin_layout Chapter
141 \begin_layout Section
145 \begin_layout Standard
166 ompiler) is free open source, retargettable, optimizing ANSI-C compiler
171 designed for 8 bit Microprocessors.
172 The current version targets Intel MCS51 based Microprocessors (8031, 8032,
174 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
178 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
179 Zilog Z80 based MCUs.
180 It can be retargeted for other microprocessors, support for Microchip PIC,
181 Atmel AVR is under development.
182 The entire source code for the compiler is distributed under GPL.
184 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
189 \begin_inset LatexCommand \index{aslink}
193 , an open source retargetable assembler & linker.
194 SDCC has extensive language extensions suitable for utilizing various microcont
195 rollers and underlying hardware effectively.
200 In addition to the MCU specific optimizations SDCC also does a host of
201 standard optimizations like:
204 \begin_layout Itemize
205 global sub expression elimination,
208 \begin_layout Itemize
209 loop optimizations (loop invariant, strength reduction of induction variables
213 \begin_layout Itemize
214 constant folding & propagation,
217 \begin_layout Itemize
221 \begin_layout Itemize
222 dead code elimination
225 \begin_layout Itemize
233 \begin_layout Standard
234 For the back-end SDCC uses a global register allocation scheme which should
235 be well suited for other 8 bit MCUs.
240 The peep hole optimizer uses a rule based substitution mechanism which
246 Supported data-types are:
249 \begin_layout Standard
251 <lyxtabular version="3" rows="8" columns="5">
253 <column alignment="center" valignment="top" leftline="true" width="0">
254 <column alignment="center" valignment="top" leftline="true" width="0">
255 <column alignment="center" valignment="top" leftline="true" width="0">
256 <column alignment="center" valignment="top" leftline="true" width="0">
257 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
258 <row topline="true" bottomline="true">
259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
262 \begin_layout Standard
268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
271 \begin_layout Standard
277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
280 \begin_layout Standard
286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
289 \begin_layout Standard
295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
298 \begin_layout Standard
306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
309 \begin_layout Standard
315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
318 \begin_layout Standard
324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
327 \begin_layout Standard
333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
336 \begin_layout Standard
342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
345 \begin_layout Standard
353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
356 \begin_layout Standard
362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
365 \begin_layout Standard
371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
374 \begin_layout Standard
380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
383 \begin_layout Standard
389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
392 \begin_layout Standard
400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
403 \begin_layout Standard
409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
412 \begin_layout Standard
418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
421 \begin_layout Standard
427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
430 \begin_layout Standard
436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
439 \begin_layout Standard
447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
450 \begin_layout Standard
456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
459 \begin_layout Standard
465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
468 \begin_layout Standard
474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
477 \begin_layout Standard
483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
486 \begin_layout Standard
493 <row topline="true" bottomline="true">
494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
497 \begin_layout Standard
503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
506 \begin_layout Standard
512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
515 \begin_layout Standard
521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
524 \begin_layout Standard
525 -2.147.483.648, +2.147.483.647
530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
533 \begin_layout Standard
540 <row topline="true" bottomline="true">
541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
544 \begin_layout Standard
550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
553 \begin_layout Standard
559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
562 \begin_layout Standard
568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
571 \begin_layout Standard
577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
580 \begin_layout Standard
596 <row topline="true" bottomline="true">
597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
600 \begin_layout Standard
606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
609 \begin_layout Standard
615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
618 \begin_layout Standard
624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
627 \begin_layout Standard
633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
636 \begin_layout Standard
649 The compiler also allows
651 inline assembler code
653 to be embedded anywhere in a function.
654 In addition, routines developed in assembly can also be called.
659 provides an option (-
663 \begin_layout Standard
672 -cyclomatic) to report the relative complexity of a function.
673 These functions can then be further optimized, or hand coded in assembly
679 SDCC also comes with a companion source level debugger SDCDB.
680 The debugger currently uses ucSim, a free open source simulator for 8051
681 and other micro-controllers.
685 The latest SDCC version can be downloaded from
687 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
697 Please note: the compiler will probably always be some steps ahead of this
702 \begin_inset LatexCommand \index{Status of documentation}
710 \begin_layout Standard
711 Obviously this has pros and cons
719 \begin_layout Section
723 \begin_layout Standard
724 All packages used in this compiler system are
732 ; source code for all the sub-packages (pre-processor, assemblers, linkers
733 etc.) is distributed with the package.
734 This documentation is maintained using a free open source word processor
737 This program is free software; you can redistribute it and/or modify
738 it under the terms of the GNU General Public License
739 \begin_inset LatexCommand \index{GNU General Public License, GPL}
743 as published by the Free Software Foundation; either version 2, or (at
744 your option) any later version.
745 This program is distributed in the hope that it will be useful, but WITHOUT
746 ANY WARRANTY; without even the implied warranty
747 \begin_inset LatexCommand \index{warranty}
751 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
752 See the GNU General Public License for more details.
753 You should have received a copy of the GNU General Public License along
754 with this program; if not, write to the Free Software Foundation, 59 Temple
755 Place - Suite 330, Boston, MA 02111-1307, USA.
756 In other words, you are welcome to use, share and improve this program.
757 You are forbidden to forbid anyone else to use, share and improve what
759 Help stamp out software-hoarding!
762 \begin_layout Section
763 Typographic conventions
764 \begin_inset LatexCommand \index{Typographic conventions}
771 \begin_layout Standard
772 Throughout this manual, we will use the following convention.
773 Commands you have to type in are printed in
781 Code samples are printed in
786 Interesting items and new terms are printed in
791 \begin_layout Section
793 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
797 with previous versions
798 \begin_inset LatexCommand \index{Compatibility with previous versions}
805 \begin_layout Standard
806 Newer versions have usually numerous bug fixes compared with the previous
808 But we also sometimes introduce some incompatibilities with older versions.
809 Not just for the fun of it, but to make the compiler more stable, efficient
811 \begin_inset LatexCommand \index{ANSI-compliance}
816 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
820 for ANSI-Compliance).
822 \begin_inset Note Note
825 \begin_layout Standard
826 It would be fine to add to each item, in which version was it changed.
836 \begin_layout Itemize
837 short is now equivalent to int (16 bits), it used to be equivalent to char
838 (8 bits) which is not ANSI compliant.
839 To maintain compatibility, old programs may be compiled using the -
843 \begin_layout Standard
852 -short-is-8bits commandline option (see
853 \begin_inset LatexCommand \vref{lyx:--short-is-8bits}
860 \begin_layout Itemize
861 the default directory for gcc-builds where include, library and documentation
862 files are stored is now in /usr/local/share.
865 \begin_layout Itemize
866 char type parameters to vararg
867 \begin_inset LatexCommand \index{vararg, va\_arg}
871 functions are casted to int unless explicitly casted
872 \begin_inset Marginal
875 \begin_layout Standard
900 will push a as an int and as a char resp.
903 \begin_layout Itemize
908 \begin_layout Standard
917 -regextend has been removed.
920 \begin_layout Itemize
925 \begin_layout Standard
934 -noregparms has been removed.
937 \begin_layout Itemize
942 \begin_layout Standard
951 -stack-after-data has been removed.
954 \begin_layout Itemize
956 \begin_inset LatexCommand \index{bit}
961 \begin_inset LatexCommand \index{sbit}
966 \begin_inset LatexCommand \index{\_\_sbit}
970 types now consistently behave like the C99 _Bool type with respect to type
972 \begin_inset LatexCommand \index{type conversion}
977 \begin_inset LatexCommand \index{type promotion}
982 The most common incompatibility resulting from this change is related to
984 \begin_inset LatexCommand \index{Bit toggling}
999 \begin_inset LatexCommand \index{\~\/ Operator}
1003 b; /* equivalent to b=1 instead of toggling b */
1004 \begin_inset Marginal
1007 \begin_layout Standard
1020 b = !b; /* toggles b */
1024 In previous versions, both forms would have toggled the bit.
1027 \begin_layout Standard
1030 <pending: more incompatibilities?>
1033 \begin_layout Section
1037 \begin_layout Standard
1038 What do you need before you start installation of SDCC? A computer, and
1039 a desire to compute.
1040 The preferred method of installation is to compile SDCC from source using
1042 For Windows some pre-compiled binary distributions are available for your
1044 You should have some experience with command line tools and compiler use.
1047 \begin_layout Section
1051 \begin_layout Standard
1052 The SDCC home page at
1053 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1057 is a great place to find distribution sets.
1058 You can also find links to the user mailing lists that offer help or discuss
1059 SDCC with other SDCC users.
1060 Web links to other SDCC related sites can also be found here.
1061 This document can be found in the DOC directory of the source package as
1062 a text or HTML file.
1063 A pdf version of this document is available at
1064 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1069 Some of the other tools (simulator and assembler) included with SDCC contain
1070 their own documentation and can be found in the source distribution.
1071 If you want the latest unreleased software, the complete source package
1072 is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1076 \begin_layout Section
1077 Wishes for the future
1080 \begin_layout Standard
1081 There are (and always will be) some things that could be done.
1082 Here are some I can think of:
1087 \begin_layout Standard
1090 char KernelFunction3(char p) at 0x340;
1095 \begin_layout Standard
1099 \begin_inset LatexCommand \index{code banking (limited support)}
1109 If you can think of some more, please see the section
1110 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1114 about filing feature requests
1115 \begin_inset LatexCommand \index{Requesting features}
1120 \begin_inset LatexCommand \index{Feature request}
1129 \begin_layout Chapter
1131 \begin_inset LatexCommand \index{Installation}
1138 \begin_layout Standard
1139 For most users it is sufficient to skip to either section
1140 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1145 \begin_inset LatexCommand \ref{sub:Windows-Install}
1150 More detailed instructions follow below.
1153 \begin_layout Section
1155 \begin_inset LatexCommand \index{Options SDCC configuration}
1162 \begin_layout Standard
1163 The install paths, search paths and other options are defined when running
1165 The defaults can be overridden by:
1169 \labelwidthstring 00.00.0000
1174 \begin_layout Standard
1183 -prefix see table below
1187 \labelwidthstring 00.00.0000
1192 \begin_layout Standard
1201 -exec_prefix see table below
1205 \labelwidthstring 00.00.0000
1210 \begin_layout Standard
1219 -bindir see table below
1223 \labelwidthstring 00.00.0000
1228 \begin_layout Standard
1237 -datadir see table below
1241 \labelwidthstring 00.00.0000
1246 \begin_layout Standard
1255 -datarootdir see table below
1261 \labelwidthstring 00.00.0000
1264 docdir environment variable, see table below
1268 \labelwidthstring 00.00.0000
1271 include_dir_suffix environment variable, see table below
1275 \labelwidthstring 00.00.0000
1278 lib_dir_suffix environment variable, see table below
1282 \labelwidthstring 00.00.0000
1285 sdccconf_h_dir_separator environment variable, either / or
1290 This character will only be used in sdccconf.h; don't forget it's a C-header,
1291 therefore a double-backslash is needed there.
1297 \labelwidthstring 00.00.0000
1302 \begin_layout Standard
1311 -disable-mcs51-port Excludes the Intel mcs51 port
1315 \labelwidthstring 00.00.0000
1320 \begin_layout Standard
1329 -disable-gbz80-port Excludes the Gameboy gbz80 port
1333 \labelwidthstring 00.00.0000
1338 \begin_layout Standard
1347 -disable-z80-port Excludes the z80 port
1351 \labelwidthstring 00.00.0000
1356 \begin_layout Standard
1365 -disable-avr-port Excludes the AVR port
1369 \labelwidthstring 00.00.0000
1374 \begin_layout Standard
1383 -disable-ds390-port Excludes the DS390 port
1387 \labelwidthstring 00.00.0000
1392 \begin_layout Standard
1401 -disable-hc08-port Excludes the HC08 port
1405 \labelwidthstring 00.00.0000
1410 \begin_layout Standard
1419 -disable-pic-port Excludes the PIC14 port
1423 \labelwidthstring 00.00.0000
1428 \begin_layout Standard
1437 -disable-pic16-port Excludes the PIC16 port
1441 \labelwidthstring 00.00.0000
1446 \begin_layout Standard
1455 -disable-xa51-port Excludes the XA51 port
1459 \labelwidthstring 00.00.0000
1464 \begin_layout Standard
1473 -disable-ucsim Disables configuring and building of ucsim
1477 \labelwidthstring 00.00.0000
1482 \begin_layout Standard
1491 -disable-device-lib Disables automatically building device libraries
1495 \labelwidthstring 00.00.0000
1500 \begin_layout Standard
1509 -disable-packihx Disables building packihx
1515 \labelwidthstring 00.00.0000
1520 \begin_layout Standard
1529 -enable-doc Build pdf, html and txt files from the lyx sources
1533 \labelwidthstring 00.00.0000
1538 \begin_layout Standard
1547 -enable-libgc Use the Bohem memory allocator.
1548 Lower runtime footprint.
1551 \begin_layout Standard
1552 Furthermore the environment variables CC, CFLAGS, ...
1553 the tools and their arguments can be influenced.
1554 Please see `configure -
1558 \begin_layout Standard
1567 -help' and the man/info pages of `configure' for details.
1572 standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1573 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1574 SDCC_LIB_NAME are defined by `configure' too.
1575 At the moment it's not possible to change the default settings (it was
1576 simply never required).
1580 These configure options are compiled into the binaries,
1581 and can only be changed by rerunning 'configure' and recompiling SDCC.
1582 The configure options are written in
1586 to distinguish them from run time environment variables (see section search
1592 \begin_inset Quotes sld
1596 \begin_inset Quotes srd
1599 are used by the SDCC team to build the official Win32 binaries.
1600 The SDCC team uses Mingw32 to build the official Windows binaries, because
1604 \begin_layout Enumerate
1608 \begin_layout Enumerate
1609 a gcc compiler and last but not least
1612 \begin_layout Enumerate
1613 the binaries can be built by cross compiling on SDCC Distributed Compile
1617 \begin_layout Standard
1618 See the examples, how to pass the Win32 settings to 'configure'.
1619 The other Win32 builds using Borland, VC or whatever don't use 'configure',
1620 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1630 \begin_layout Standard
1632 \begin_inset Tabular
1633 <lyxtabular version="3" rows="9" columns="3">
1635 <column alignment="block" valignment="top" leftline="true" width="0in">
1636 <column alignment="block" valignment="top" leftline="true" width="0in">
1637 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1638 <row topline="true" bottomline="true">
1639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1642 \begin_layout Standard
1648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1651 \begin_layout Standard
1657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1660 \begin_layout Standard
1667 <row topline="true">
1668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1671 \begin_layout Standard
1679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1682 \begin_layout Standard
1688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1691 \begin_layout Standard
1700 <row topline="true">
1701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1704 \begin_layout Standard
1712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1715 \begin_layout Standard
1723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1726 \begin_layout Standard
1735 <row topline="true">
1736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1739 \begin_layout Standard
1747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1750 \begin_layout Standard
1760 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1763 \begin_layout Standard
1776 <row topline="true">
1777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1780 \begin_layout Standard
1788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1791 \begin_layout Standard
1799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1802 \begin_layout Standard
1811 <row topline="true">
1812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1815 \begin_layout Standard
1823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1826 \begin_layout Standard
1836 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1839 \begin_layout Standard
1848 <row topline="true">
1849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1852 \begin_layout Standard
1860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1863 \begin_layout Standard
1873 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1876 \begin_layout Standard
1889 <row topline="true">
1890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1893 \begin_layout Standard
1901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1904 \begin_layout Standard
1910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1913 \begin_layout Standard
1920 <row topline="true" bottomline="true">
1921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1924 \begin_layout Standard
1932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1935 \begin_layout Standard
1941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1944 \begin_layout Standard
1960 \begin_layout Standard
1962 'configure' also computes relative paths.
1963 This is needed for full relocatability of a binary package and to complete
1964 search paths (see section search paths below):
1969 \begin_layout Standard
1971 \begin_inset Tabular
1972 <lyxtabular version="3" rows="4" columns="3">
1974 <column alignment="block" valignment="top" leftline="true" width="0in">
1975 <column alignment="block" valignment="top" leftline="true" width="0in">
1976 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1977 <row topline="true" bottomline="true">
1978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1981 \begin_layout Standard
1987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1990 \begin_layout Standard
1996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1999 \begin_layout Standard
2006 <row topline="true" bottomline="true">
2007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2010 \begin_layout Standard
2018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2021 \begin_layout Standard
2027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2030 \begin_layout Standard
2037 <row bottomline="true">
2038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2041 \begin_layout Standard
2049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2052 \begin_layout Standard
2058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2061 \begin_layout Standard
2068 <row bottomline="true">
2069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2072 \begin_layout Standard
2080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2083 \begin_layout Standard
2089 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2092 \begin_layout Standard
2108 \begin_layout Standard
2113 \begin_layout LyX-Code
2120 \begin_layout Standard
2130 \begin_inset Quotes srd
2134 \begin_inset Quotes srd
2141 \begin_layout Standard
2151 \begin_inset Quotes srd
2155 \begin_inset Quotes srd
2164 \begin_layout Standard
2177 \begin_layout Standard
2189 \begin_layout Standard
2190 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2194 \begin_layout LyX-Code
2200 \begin_inset Quotes srd
2203 i586-mingw32msvc-gcc
2204 \begin_inset Quotes srd
2208 \begin_inset Quotes srd
2211 i586-mingw32msvc-g++
2212 \begin_inset Quotes srd
2220 \begin_inset Quotes srd
2223 i586-mingw32msvc-ranlib
2224 \begin_inset Quotes srd
2232 \begin_inset Quotes srd
2235 i586-mingw32msvc-strip
2236 \begin_inset Quotes srd
2247 \begin_layout Standard
2257 \begin_inset Quotes srd
2261 \begin_inset Quotes srd
2272 \begin_layout Standard
2282 \begin_inset Quotes srd
2286 \begin_inset Quotes srd
2294 \begin_inset Quotes srd
2300 \begin_inset Quotes srd
2308 \begin_inset Quotes srd
2312 \begin_inset Quotes srd
2320 \begin_inset Quotes srd
2324 \begin_inset Quotes srd
2331 sdccconf_h_dir_separator=
2332 \begin_inset Quotes srd
2344 \begin_inset Quotes srd
2355 \begin_layout Standard
2372 \begin_layout Standard
2381 -host=i586-mingw32msvc
2389 \begin_layout Standard
2398 -build=unknown-unknown-linux-gnu
2401 \begin_layout Standard
2403 \begin_inset Quotes sld
2407 \begin_inset Quotes srd
2410 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2414 \begin_layout LyX-Code
2423 \begin_layout Standard
2433 \begin_inset Quotes srd
2437 \begin_inset Quotes srd
2448 \begin_layout Standard
2458 \begin_inset Quotes srd
2462 \begin_inset Quotes srd
2470 \begin_inset Quotes srd
2476 \begin_inset Quotes srd
2484 \begin_inset Quotes srd
2488 \begin_inset Quotes srd
2496 \begin_inset Quotes srd
2500 \begin_inset Quotes srd
2507 sdccconf_h_dir_separator=
2508 \begin_inset Quotes srd
2520 \begin_inset Quotes srd
2528 \begin_inset Quotes srd
2532 \begin_inset Quotes srd
2540 \begin_inset Quotes srd
2544 \begin_inset Quotes srd
2550 \begin_layout Standard
2551 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2556 \begin_layout Standard
2565 -C' turns on caching, which gives a little bit extra speed.
2566 However if options are changed, it can be necessary to delete the config.cache
2570 \begin_layout Section
2572 \begin_inset LatexCommand \label{sub:Install-paths}
2577 \begin_inset LatexCommand \index{Install paths}
2584 \begin_layout Standard
2585 \begin_inset VSpace medskip
2591 \begin_layout Standard
2593 \begin_inset Tabular
2594 <lyxtabular version="3" rows="5" columns="4">
2596 <column alignment="left" valignment="top" leftline="true" width="0">
2597 <column alignment="left" valignment="top" leftline="true" width="0">
2598 <column alignment="left" valignment="top" leftline="true" width="0">
2599 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2600 <row topline="true" bottomline="true">
2601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2604 \begin_layout Standard
2612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2615 \begin_layout Standard
2623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2626 \begin_layout Standard
2634 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2637 \begin_layout Standard
2646 <row topline="true">
2647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2650 \begin_layout Standard
2656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2659 \begin_layout Standard
2667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2670 \begin_layout Standard
2676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2679 \begin_layout Standard
2690 <row topline="true">
2691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2694 \begin_layout Standard
2700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2703 \begin_layout Standard
2706 $DATADIR/ $INCLUDE_DIR_SUFFIX
2711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2714 \begin_layout Standard
2715 /usr/local/share/sdcc/include
2720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2723 \begin_layout Standard
2734 <row topline="true">
2735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2738 \begin_layout Standard
2744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2747 \begin_layout Standard
2750 $DATADIR/$LIB_DIR_SUFFIX
2755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2758 \begin_layout Standard
2759 /usr/local/share/sdcc/lib
2764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2767 \begin_layout Standard
2778 <row topline="true" bottomline="true">
2779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2782 \begin_layout Standard
2788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2791 \begin_layout Standard
2799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2802 \begin_layout Standard
2803 /usr/local/share/sdcc/doc
2808 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2811 \begin_layout Standard
2832 *compiler, preprocessor, assembler, and linker
2838 is auto-appended by the compiler, e.g.
2839 small, large, z80, ds390 etc
2842 \begin_layout Standard
2844 The install paths can still be changed during `make install' with e.g.:
2847 \begin_layout LyX-Code
2848 make install prefix=$(HOME)/local/sdcc
2851 \begin_layout Standard
2852 Of course this doesn't change the search paths compiled into the binaries.
2857 r the install path can be changed by defining DESTDIR
2858 \begin_inset LatexCommand \index{DESTDIR}
2865 \begin_layout LyX-Code
2866 make install DESTDIR=$(HOME)/sdcc.rpm/
2869 \begin_layout Standard
2870 Please note that DESTDIR must have a trailing slash!
2873 \begin_layout Section
2875 \begin_inset LatexCommand \label{sub:Search-Paths}
2880 \begin_inset LatexCommand \index{Search path}
2887 \begin_layout Standard
2888 Some search paths or parts of them are determined by configure variables
2893 , see section above).
2894 Further search paths are determined by environment variables during runtime.
2897 The paths searched when running the compiler are as follows (the first
2903 Binary files (preprocessor, assembler and linker)
2908 \begin_layout Standard
2910 \begin_inset Tabular
2911 <lyxtabular version="3" rows="4" columns="3">
2913 <column alignment="block" valignment="top" leftline="true" width="0in">
2914 <column alignment="block" valignment="top" leftline="true" width="0in">
2915 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2916 <row topline="true" bottomline="true">
2917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2920 \begin_layout Standard
2926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2929 \begin_layout Standard
2935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2938 \begin_layout Standard
2945 <row topline="true">
2946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2949 \begin_layout Standard
2957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2960 \begin_layout Standard
2966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2969 \begin_layout Standard
2978 <row topline="true">
2979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2982 \begin_layout Standard
2983 Path of argv[0] (if available)
2988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2991 \begin_layout Standard
2997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3000 \begin_layout Standard
3007 <row topline="true" bottomline="true">
3008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3011 \begin_layout Standard
3017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3020 \begin_layout Standard
3026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3029 \begin_layout Standard
3045 \begin_layout Standard
3053 \begin_layout Standard
3055 \begin_inset Tabular
3056 <lyxtabular version="3" rows="6" columns="3">
3058 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3059 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3060 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3061 <row topline="true" bottomline="true">
3062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3065 \begin_layout Standard
3071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3074 \begin_layout Standard
3080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3083 \begin_layout Standard
3090 <row topline="true">
3091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3094 \begin_layout Standard
3099 \begin_layout Standard
3113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3116 \begin_layout Standard
3121 \begin_layout Standard
3135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3138 \begin_layout Standard
3143 \begin_layout Standard
3158 <row topline="true">
3159 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3162 \begin_layout Standard
3168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3171 \begin_layout Standard
3177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3180 \begin_layout Standard
3187 <row topline="true">
3188 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3191 \begin_layout Standard
3203 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3206 \begin_layout Standard
3216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3219 \begin_layout Standard
3228 <row topline="true">
3229 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3232 \begin_layout Standard
3248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3251 \begin_layout Standard
3299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3302 \begin_layout Standard
3313 <row topline="true" bottomline="true">
3314 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3317 \begin_layout Standard
3331 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3334 \begin_layout Standard
3335 /usr/local/share/sdcc/
3342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3345 \begin_layout Standard
3361 \begin_layout Standard
3367 \begin_layout Standard
3376 -nostdinc disables the last two search paths.
3386 \begin_layout Standard
3387 With the exception of
3388 \begin_inset Quotes sld
3395 \begin_layout Standard
3405 \begin_inset Quotes srd
3412 is auto-appended by the compiler (e.g.
3413 small, large, z80, ds390 etc.).
3419 \begin_layout Standard
3421 \begin_inset Tabular
3422 <lyxtabular version="3" rows="6" columns="3">
3424 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3425 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3426 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3427 <row topline="true" bottomline="true">
3428 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3431 \begin_layout Standard
3437 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3440 \begin_layout Standard
3446 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3449 \begin_layout Standard
3456 <row topline="true">
3457 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3460 \begin_layout Standard
3465 \begin_layout Standard
3479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3482 \begin_layout Standard
3487 \begin_layout Standard
3501 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3504 \begin_layout Standard
3509 \begin_layout Standard
3524 <row topline="true">
3525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3528 \begin_layout Standard
3538 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3541 \begin_layout Standard
3551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3554 \begin_layout Standard
3567 <row topline="true">
3568 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3571 \begin_layout Standard
3578 $LIB_DIR_SUFFIX/<model>
3583 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3586 \begin_layout Standard
3598 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3601 \begin_layout Standard
3616 <row topline="true">
3617 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3620 \begin_layout Standard
3631 $LIB_DIR_SUFFIX/<model>
3636 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3639 \begin_layout Standard
3690 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3693 \begin_layout Standard
3747 <row topline="true" bottomline="true">
3748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3751 \begin_layout Standard
3756 $LIB_DIR_SUFFIX/<model>
3761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3764 \begin_layout Standard
3765 /usr/local/share/sdcc/
3774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3777 \begin_layout Standard
3793 \begin_layout Standard
3794 \begin_inset Note Note
3797 \begin_layout Standard
3798 Don't delete any of the stray spaces in the table above without checking
3799 the HTML output (last line)!
3807 \begin_layout Standard
3815 \begin_layout Standard
3824 -nostdlib disables the last two search paths.
3827 \begin_layout Section
3829 \begin_inset LatexCommand \index{Building SDCC}
3836 \begin_layout Subsection
3837 Building SDCC on Linux
3838 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3845 \begin_layout Enumerate
3848 Download the source package
3850 either from the SDCC Subversion repository or from snapshot builds
3852 , it will be named something like sdcc
3863 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3870 \begin_layout Enumerate
3873 Bring up a command line terminal, such as xterm.
3876 \begin_layout Enumerate
3879 Unpack the file using a command like:
3882 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
3883 \begin_inset Quotes srd
3889 , this will create a sub-directory called sdcc with all of the sources.
3892 \begin_layout Enumerate
3893 Change directory into the main SDCC directory, for example type:
3901 \begin_layout Enumerate
3911 This configures the package for compilation on your system.
3914 \begin_layout Enumerate
3928 All of the source packages will compile, this can take a while.
3931 \begin_layout Enumerate
3945 This copies the binary executables, the include files, the libraries and
3946 the documentation to the install directories.
3947 Proceed with section
3948 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3955 \begin_layout Subsection
3956 Building SDCC on Mac OS X
3959 \begin_layout Standard
3960 Follow the instruction for Linux.
3964 On Mac OS X 10.2.x it was reported, that the
3965 default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
3966 Fortunately there's also gcc 2.9.x installed, which works fine.
3967 This compiler can be selected by running 'configure' with:
3970 \begin_layout LyX-Code
3971 ./configure CC=gcc2 CXX=g++2
3974 \begin_layout Subsection
3975 Cross compiling SDCC on Linux for Windows
3978 \begin_layout Standard
3979 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3980 See section 'Configure Options'.
3983 \begin_layout Subsection
3984 Building SDCC using Cygwin and Mingw32
3987 \begin_layout Standard
3988 For building and installing a Cygwin executable follow the instructions
3994 \begin_inset Quotes sld
3998 \begin_inset Quotes srd
4001 Win32-binary can be built, which will not need the Cygwin-DLL.
4002 For the necessary 'configure' options see section 'configure options' or
4003 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4008 Cygwin on Windows download setup.exe from
4009 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
4015 \begin_inset Quotes sld
4018 default text file type
4019 \begin_inset Quotes srd
4023 \begin_inset Quotes sld
4027 \begin_inset Quotes srd
4030 and download/install at least the following packages.
4031 Some packages are selected by default, others will be automatically selected
4032 because of dependencies with the manually selected packages.
4033 Never deselect these packages!
4036 \begin_layout Itemize
4040 \begin_layout Itemize
4044 \begin_layout Itemize
4045 gcc ; version 3.x is fine, no need to use the old 2.9x
4048 \begin_layout Itemize
4049 binutils ; selected with gcc
4052 \begin_layout Itemize
4056 \begin_layout Itemize
4057 rxvt ; a nice console, which makes life much easier under windoze (see below)
4060 \begin_layout Itemize
4061 man ; not really needed for building SDCC, but you'll miss it sooner or
4065 \begin_layout Itemize
4066 less ; not really needed for building SDCC, but you'll miss it sooner or
4070 \begin_layout Itemize
4071 svn ; only if you use Subversion access
4074 \begin_layout Standard
4075 If you want to develop something you'll need:
4078 \begin_layout Itemize
4079 python ; for the regression tests
4082 \begin_layout Itemize
4083 gdb ; the gnu debugger, together with the nice GUI
4084 \begin_inset Quotes sld
4088 \begin_inset Quotes srd
4094 \begin_layout Itemize
4095 openssh ; to access the CF or commit changes
4098 \begin_layout Itemize
4099 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4100 use autoconf-stable!
4103 \begin_layout Standard
4104 rxvt is a nice console with history.
4105 Replace in your cygwin.bat the line
4108 \begin_layout LyX-Code
4113 \begin_layout Standard
4125 \begin_layout Standard
4129 \begin_layout LyX-Code
4130 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4133 \begin_layout LyX-Code
4134 -bg black -fg white -geometry 100x65 -e bash -
4138 \begin_layout Standard
4150 \begin_layout Standard
4151 Text selected with the mouse is automatically copied to the clipboard, pasting
4152 works with shift-insert.
4156 The other good tip is to make sure you have no //c/-styl
4157 e paths anywhere, use /cygdrive/c/ instead.
4158 Using // invokes a network lookup which is very slow.
4160 \begin_inset Quotes sld
4164 \begin_inset Quotes srd
4167 is too long, you can change it with e.g.
4170 \begin_layout LyX-Code
4174 \begin_layout Standard
4175 SDCC sources use the unix line ending LF.
4176 Life is much easier, if you store the source tree on a drive which is mounted
4178 And use an editor which can handle LF-only line endings.
4179 Make sure not to commit files with windows line endings.
4180 The tabulator spacing
4181 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4185 used in the project is 8.
4186 Although a tabulator spacing of 8 is a sensible choice for programmers
4187 (it's a power of 2 and allows to display 8/16 bit signed variables without
4188 loosing columns) the plan is to move towards using only spaces in the source.
4191 \begin_layout Subsection
4192 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4195 \begin_layout Standard
4198 Download the source package
4200 either from the SDCC Subversion repository or from the
4201 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4207 , it will be named something like sdcc
4211 -yyyymmdd-rrrr.tar.bz2.
4214 SDCC is distributed with all the projects, workspaces, and files you need
4215 to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4216 The workspace name is 'sdcc.dsw'.
4217 Please note that as it is now, all the executables are created in a folder
4221 Once built you need to copy the executables from sdcc
4225 bin before running SDCC.
4230 WARNING: Visual studio is very picky with line terminations; it expects
4231 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4232 When using the Subversion repository it's easiest to configure the svn
4233 client to convert automatically for you.
4234 If however you are getting a message such as "This makefile was not generated
4235 by Developer Studio etc.
4237 \begin_inset Quotes srd
4240 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4241 need to convert the Unix style line endings to DOS style line endings.
4242 To do so you can use the
4243 \begin_inset Quotes sld
4247 \begin_inset Quotes srd
4250 utility freely available on the internet.
4251 Doug Hawkins reported in the sdcc-user list that this works:
4259 SDCC> unix2dos sdcc.dsw
4265 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4269 In order to build SDCC with MSVC
4270 you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4271 One good place to get them is
4272 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4280 Download the file UnxUtils
4281 \begin_inset LatexCommand \index{UnxUtils}
4286 Now you have to install the utilities and setup MSVC so it can locate the
4288 Here there are two alternatives (choose one!):
4291 \begin_layout Enumerate
4296 a) Extract UnxUtils.zip to your C:
4298 hard disk PRESERVING the original paths, otherwise bison won't work.
4299 (If you are using WinZip make certain that 'Use folder names' is selected)
4304 In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4305 'Show directories for:' select 'Executable files', and in the directories
4306 window add a new path: 'C:
4316 (As a side effect, you get a bunch of Unix utilities that
4317 could be useful, such as diff and patch.)
4320 \begin_layout Enumerate
4325 This one avoids extracting a bunch of files you may not
4326 use, but requires some extra work:
4330 a) Create a directory were to put the
4331 tools needed, or use a directory already present.
4338 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4339 gawk.exe to such directory WITHOUT preserving the original paths.
4340 (If you are using WinZip make certain that 'Use folder names' is not selected)
4345 ) Rename bison.exe to '_bison.exe'.
4349 d) Create a batch file 'bison.bat' in 'C:
4353 ' and add these lines:
4373 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4377 Steps 'c' and 'd' are needed
4378 because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4379 reside in some weird Unix directory, '/usr/local/share/' I think.
4380 So it is necessary to tell bison where those files are located if they
4381 are not in such directory.
4382 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4387 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4388 in 'Show directories for:' select 'Executable files', and in the directories
4389 window add a new path: 'c:
4392 Note that you can use any other path instead of 'c:
4394 util', even the path where the Visual C++ tools are, probably: 'C:
4398 Microsoft Visual Studio
4403 So you don't have to execute step 'e' :)
4406 \begin_layout Standard
4408 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4409 the executables from sdcc
4413 bin, and you can compile using SDCC.
4416 \begin_layout Subsection
4417 Building SDCC Using Borland
4420 \begin_layout Enumerate
4421 From the sdcc directory, run the command "make -f Makefile.bcc".
4422 This should regenerate all the .exe files in the bin directory except for
4426 \begin_layout Enumerate
4427 If you modify any source files and need to rebuild, be aware that the dependenci
4428 es may not be correctly calculated.
4429 The safest option is to delete all .obj files and run the build again.
4430 From a Cygwin BASH prompt, this can easily be done with the command (be
4431 sure you are in the sdcc directory):
4441 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
4443 ) -print -exec rm {}
4452 or on Windows NT/2000/XP from the command prompt with the command:
4459 del /s *.obj *.lib *.rul
4462 from the sdcc directory.
4465 \begin_layout Subsection
4466 Windows Install Using a ZIP Package
4469 \begin_layout Enumerate
4470 Download the binary zip package from
4471 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4475 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4476 This should unpack to a group of sub-directories.
4477 An example directory structure after unpacking the mingw32 package is:
4482 bin for the executables, c:
4490 lib for the include and libraries.
4493 \begin_layout Enumerate
4494 Adjust your environment variable PATH to include the location of the bin
4495 directory or start sdcc using the full path.
4498 \begin_layout Subsection
4499 Windows Install Using the Setup Program
4500 \begin_inset LatexCommand \label{sub:Windows-Install}
4507 \begin_layout Standard
4508 Download the setup program
4510 sdcc-x.y.z-setup.exe
4512 for an official release from
4515 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4519 or a setup program for one of the snapshots
4521 sdcc-yyyymmdd-xxxx-setup.exe
4524 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4529 A windows typical installer will guide you through the installation process.
4532 \begin_layout Subsection
4534 \begin_inset LatexCommand \index{VPATH}
4541 \begin_layout Standard
4542 SDCC supports the VPATH feature provided by configure and make.
4543 It allows to separate the source and build trees.
4547 \begin_layout Standard
4574 \begin_layout Standard
4577 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4578 # extract source to directory sdcc
4581 \begin_layout Standard
4584 mkdir sdcc.build\InsetSpace ~
4593 # put output in sdcc.build
4596 \begin_layout Standard
4602 \begin_layout Standard
4605 ../sdcc/configure\InsetSpace ~
4613 # configure is doing all the magic!
4616 \begin_layout Standard
4622 \begin_layout Standard
4628 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4629 It automagically computes the variables srcdir, top_srcdir and top_buildir
4635 the generated files will be in ~/sdcc.build, while the source files stay
4638 This is not only usefull for building different binaries, e.g.
4639 when cross compiling.
4640 It also gives you a much better overview in the source tree when all the
4641 generated files are not scattered between the source files.
4642 And the best thing is: if you want to change a file you can leave the original
4643 file untouched in the source directory.
4644 Simply copy it to the build directory, edit it, enter `make clean', `rm
4645 Makefile.dep' and `make'.
4650 will do the rest for you!
4653 \begin_layout Section
4654 Building the Documentation
4657 \begin_layout Standard
4662 \begin_layout Standard
4671 -enable-doc to the configure arguments to build the documentation together
4672 with all the other stuff.
4673 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4674 dvips and makeindex) to get the job done.
4675 Another possibility is to change to the doc directory and to type
4679 \begin_inset Quotes srd
4683 \begin_inset Quotes srd
4690 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4693 \begin_inset LatexCommand \url{http://www.lyx.org}
4697 as editor is straightforward.
4698 Prebuilt documentation in html and pdf format is available from
4699 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4706 \begin_layout Section
4707 Reading the Documentation
4708 \begin_inset LatexCommand \index{Documentation}
4715 \begin_layout Standard
4716 Currently reading the document in pdf format is recommended, as for unknown
4717 reason the hyperlinks are working there whereas in the html version they
4722 \begin_layout Standard
4723 If you should know why please drop us a note
4731 You'll find the pdf version
4732 \begin_inset LatexCommand \index{PDF version of this document}
4737 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4745 \begin_inset LatexCommand \index{HTML version of this document}
4750 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4756 This documentation is in some aspects different from a commercial documentation:
4760 \begin_layout Itemize
4761 It tries to document SDCC for several processor architectures in one document
4762 (commercially these probably would be separate documents/products).
4764 \begin_inset LatexCommand \index{Status of documentation}
4768 currently matches SDCC for mcs51 and DS390 best and does give too few informati
4770 Z80, PIC14, PIC16 and HC08.
4773 \begin_layout Itemize
4774 There are many references pointing away from this documentation.
4775 Don't let this distract you.
4777 was a reference like
4778 \begin_inset LatexCommand \url{http://www.opencores.org}
4782 together with a statement
4783 \begin_inset Quotes sld
4786 some processors which are targetted by SDCC can be implemented in a
4803 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4808 \begin_inset Quotes srd
4812 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4817 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4822 \begin_inset Quotes sld
4825 have you ever heard of an open source compiler that compiles a subset of
4827 \begin_inset Quotes srd
4830 we expect you to have a quick look there and come back.
4831 If you read this you are on the right track.
4834 \begin_layout Itemize
4835 Some sections attribute more space to problems, restrictions and warnings
4836 than to the solution.
4839 \begin_layout Itemize
4840 The installation section and the section about the debugger is intimidating.
4843 \begin_layout Itemize
4844 There are still lots of typos and there are more different writing styles
4848 \begin_layout Section
4849 Testing the SDCC Compiler
4850 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4857 \begin_layout Standard
4858 The first thing you should do after installing your SDCC compiler is to
4867 \begin_layout Standard
4877 \begin_inset LatexCommand \index{version}
4884 at the prompt, and the program should run and output its version like:
4889 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4893 \begin_layout Standard
4894 If it doesn't run, or gives a message about not finding sdcc program, then
4895 you need to check over your installation.
4896 Make sure that the sdcc bin directory is in your executable search path
4897 defined by the PATH environment setting (
4902 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4909 Install trouble-shooting for suggestions
4912 Make sure that the sdcc program is in the bin folder, if not perhaps something
4913 did not install correctly.
4921 is commonly installed as described in section
4922 \begin_inset Quotes sld
4925 Install and search paths
4926 \begin_inset Quotes srd
4935 Make sure the compiler works on a very simple example.
4936 Type in the following test.c program using your favorite
4961 \begin_layout Standard
4964 Compile this using the following command:
4973 If all goes well, the compiler will generate a test.asm and test.rel file.
4974 Congratulations, you've just compiled your first program with SDCC.
4975 We used the -c option to tell SDCC not to link the generated code, just
4976 to keep things simple for this step.
4984 The next step is to try it with the linker.
4994 If all goes well the compiler will link with the libraries and produce
4995 a test.ihx output file.
5000 (no test.ihx, and the linker generates warnings), then the problem is most
5009 usr/local/share/sdcc/lib directory
5016 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5023 Install trouble-shooting for suggestions).
5031 The final test is to ensure
5039 header files and libraries.
5040 Edit test.c and change it to the following:
5058 strcpy(str1, "testing");
5063 \begin_layout Standard
5066 Compile this by typing
5073 This should generate a test.ihx output file, and it should give no warnings
5074 such as not finding the string.h file.
5075 If it cannot find the string.h file, then the problem is that
5079 cannot find the /usr/local/share/sdcc/include directory
5086 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5093 Install trouble-shooting section for suggestions).
5102 \begin_layout Standard
5114 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5118 to find exactly where SDCC is looking for the include and lib files.
5121 \begin_layout Section
5122 Install Trouble-shooting
5123 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5128 \begin_inset LatexCommand \index{Install trouble-shooting}
5135 \begin_layout Subsection
5136 If SDCC does not build correctly
5139 \begin_layout Standard
5140 A thing to try is starting from scratch by unpacking the .tgz source package
5141 again in an empty directory.
5149 ./configure 2>&1 | tee configure.log
5163 make 2>&1 | tee make.log
5170 If anything goes wrong, you can review the log files to locate the problem.
5171 Or a relevant part of this can be attached to an email that could be helpful
5172 when requesting help from the mailing list.
5175 \begin_layout Subsection
5177 \begin_inset Quotes sld
5181 \begin_inset Quotes srd
5187 \begin_layout Standard
5189 \begin_inset Quotes sld
5193 \begin_inset Quotes srd
5196 command is a script that analyzes your system and performs some configuration
5197 to ensure the source package compiles on your system.
5198 It will take a few minutes to run, and will compile a few tests to determine
5199 what compiler features are installed.
5202 \begin_layout Subsection
5204 \begin_inset Quotes sld
5208 \begin_inset Quotes srd
5214 \begin_layout Standard
5215 This runs the GNU make tool, which automatically compiles all the source
5216 packages into the final installed binary executables.
5219 \begin_layout Subsection
5221 \begin_inset Quotes sld
5225 \begin_inset Quotes erd
5231 \begin_layout Standard
5232 This will install the compiler, other executables libraries and include
5233 files into the appropriate directories.
5235 \begin_inset LatexCommand \ref{sub:Install-paths}
5241 \begin_inset LatexCommand \ref{sub:Search-Paths}
5246 about install and search paths.
5248 On most systems you will need super-user privilege
5252 \begin_layout Section
5256 \begin_layout Standard
5257 SDCC is not just a compiler, but a collection of tools by various developers.
5258 These include linkers, assemblers, simulators and other components.
5259 Here is a summary of some of the components.
5260 Note that the included simulator and assembler have separate documentation
5261 which you can find in the source package in their respective directories.
5262 As SDCC grows to include support for other processors, other packages from
5263 various developers are included and may have their own sets of documentation.
5268 might want to look at the files which are installed in <installdir>.
5269 At the time of this writing, we find the following programs for gcc-builds:
5274 In <installdir>/bin:
5277 \begin_layout Itemize
5278 sdcc - The compiler.
5281 \begin_layout Itemize
5282 sdcpp - The C preprocessor.
5285 \begin_layout Itemize
5286 asx8051 - The assembler for 8051 type processors.
5289 \begin_layout Itemize
5294 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5297 \begin_layout Itemize
5298 aslink -The linker for 8051 type processors.
5301 \begin_layout Itemize
5306 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5309 \begin_layout Itemize
5310 s51 - The ucSim 8051 simulator.
5313 \begin_layout Itemize
5314 sdcdb - The source debugger.
5317 \begin_layout Itemize
5318 packihx - A tool to pack (compress) Intel hex files.
5321 \begin_layout Standard
5322 In <installdir>/share/sdcc/include
5325 \begin_layout Itemize
5329 \begin_layout Standard
5330 In <installdir>/share/sdcc/lib
5333 \begin_layout Itemize
5334 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5338 \begin_layout Standard
5339 In <installdir>/share/sdcc/doc
5342 \begin_layout Itemize
5346 \begin_layout Standard
5347 As development for other processors proceeds, this list will expand to include
5348 executables to support processors like AVR, PIC, etc.
5351 \begin_layout Subsection
5355 \begin_layout Standard
5356 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5357 the assembler and linkage editor.
5360 \begin_layout Subsection
5361 sdcpp - The C-Preprocessor
5364 \begin_layout Standard
5366 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5370 is a modified version of the GNU cpp
5371 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5376 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5381 The C preprocessor is used to pull in #include sources, process #ifdef
5382 statements, #defines and so on.
5385 \begin_layout Subsection
5394 - The Assemblers and Linkage Editors
5397 \begin_layout Standard
5398 This is retargettable assembler & linkage editor, it was developed by Alan
5400 John Hartman created the version for 8051, and I (Sandeep) have made some
5401 enhancements and bug fixes for it to work properly with SDCC.
5404 \begin_layout Subsection
5408 \begin_layout Standard
5410 \begin_inset LatexCommand \index{s51}
5414 is a free open source simulator developed by Daniel Drotos.
5415 The simulator is built as part of the build process.
5416 For more information visit Daniel's web site at:
5417 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5422 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5426 \begin_layout Subsection
5427 sdcdb - Source Level Debugger
5430 \begin_layout Standard
5432 \begin_inset LatexCommand \index{SDCDB (debugger)}
5436 is the companion source level debugger.
5437 More about SDCDB in section
5438 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5443 The current version of the debugger uses Daniel's Simulator S51
5444 \begin_inset LatexCommand \index{s51}
5448 , but can be easily changed to use other simulators.
5451 \begin_layout Chapter
5455 \begin_layout Section
5459 \begin_layout Subsection
5460 Single Source File Projects
5463 \begin_layout Standard
5464 For single source file 8051 projects the process is very simple.
5465 Compile your programs with the following command
5468 "sdcc sourcefile.c".
5472 This will compile, assemble and link your source file.
5473 Output files are as follows:
5476 \begin_layout Itemize
5478 \begin_inset LatexCommand \index{<file>.asm}
5483 \begin_inset LatexCommand \index{Assembler source}
5487 file created by the compiler
5490 \begin_layout Itemize
5492 \begin_inset LatexCommand \index{<file>.lst}
5497 \begin_inset LatexCommand \index{Assembler listing}
5501 file created by the Assembler
5504 \begin_layout Itemize
5506 \begin_inset LatexCommand \index{<file>.rst}
5511 \begin_inset LatexCommand \index{Assembler listing}
5515 file updated with linkedit information, created by linkage editor
5518 \begin_layout Itemize
5520 \begin_inset LatexCommand \index{<file>.sym}
5525 \begin_inset LatexCommand \index{Symbol listing}
5529 for the sourcefile, created by the assembler
5532 \begin_layout Itemize
5534 \begin_inset LatexCommand \index{<file>.rel}
5539 \begin_inset LatexCommand \index{<file>.o}
5544 \begin_inset LatexCommand \index{Object file}
5548 created by the assembler, input to Linkage editor
5551 \begin_layout Itemize
5553 \begin_inset LatexCommand \index{<file>.map}
5558 \begin_inset LatexCommand \index{Memory map}
5562 for the load module, created by the Linker
5565 \begin_layout Itemize
5567 \begin_inset LatexCommand \index{<file>.mem}
5571 - A file with a summary of the memory usage
5574 \begin_layout Itemize
5576 \begin_inset LatexCommand \index{<file>.ihx}
5580 - The load module in Intel hex format
5581 \begin_inset LatexCommand \index{Intel hex format}
5585 (you can select the Motorola S19 format
5586 \begin_inset LatexCommand \index{Motorola S19 format}
5594 \begin_layout Standard
5604 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5609 If you need another format you might want to use
5616 \begin_inset LatexCommand \index{objdump (tool)}
5627 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5632 \begin_inset Note Note
5635 \begin_layout Standard
5642 \begin_inset LatexCommand \vref{sub:Postprocessing-the-Intel}
5647 Both formats are documented in the documentation of srecord
5648 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5655 \begin_layout Itemize
5657 \begin_inset LatexCommand \index{<file>.adb}
5661 - An intermediate file containing debug information needed to create the
5666 \begin_layout Standard
5676 \begin_inset LatexCommand \index{-\/-debug}
5683 \begin_layout Itemize
5685 \begin_inset LatexCommand \index{<file>.cdb}
5689 - An optional file (with -
5693 \begin_layout Standard
5702 -debug) containing debug information.
5703 The format is documented in cdbfileformat.pdf
5706 \begin_layout Itemize
5709 \begin_inset LatexCommand \index{<file> (no extension)}
5713 An optional AOMF or AOMF51
5714 \begin_inset LatexCommand \index{AOMF, AOMF51}
5719 \begin_inset LatexCommand \label{OMF file}
5723 file containing debug information (generated with option -
5727 \begin_layout Standard
5753 ormat is a subformat of the OMF51 format and is commonly used by third party
5755 \begin_inset LatexCommand \index{Debugger}
5759 , simulators, emulators).
5762 \begin_layout Itemize
5764 \begin_inset LatexCommand \index{<file>.dump*}
5768 - Dump file to debug the compiler it self (generated with option -
5772 \begin_layout Standard
5781 -dumpall) (see section
5782 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5788 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5794 \begin_inset Quotes sld
5797 Anatomy of the compiler
5798 \begin_inset Quotes srd
5804 \begin_layout Subsection
5805 Postprocessing the Intel Hex
5806 \begin_inset LatexCommand \index{Intel hex format}
5811 \begin_inset LatexCommand \label{sub:Postprocessing-the-Intel}
5818 \begin_layout Standard
5819 In most cases this won't be needed but the Intel Hex file
5820 \begin_inset LatexCommand \index{<file>.ihx}
5824 which is generated by SDCC might include lines of varying length and the
5825 addresses within the file are not guaranteed to be strictly ascending.
5826 If your toolchain or a bootloader does not like this you can use the tool
5832 \begin_inset LatexCommand \index{packihx (tool)}
5836 which is part of the SDCC distribution:
5843 packihx sourcefile.ihx >sourcefile.hex
5850 The separately available
5855 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5859 package additionally allows to set undefined locations to a predefined
5860 value, to insert checksums
5861 \begin_inset LatexCommand \index{checksum}
5865 of various flavours (crc, add, xor) and to perform other manipulations
5866 (convert, split, crop, offset, ...).
5874 srec_cat\InsetSpace ~
5876 sourcefile.ihx -intel\InsetSpace ~
5878 -o sourcefile.hex -intel
5885 An example for a more complex command line
5889 \begin_layout Standard
5890 the command backfills
5891 \begin_inset LatexCommand \index{backfill unused memory}
5895 unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5897 If the program counter on an mcs51 runs wild the backfill pattern 0x12
5898 will be interpreted as an
5906 (where an emergency routine could sit).
5919 srec_cat\InsetSpace ~
5920 sourcefile.ihx -intel\InsetSpace ~
5922 -fill 0x12 0x0000 0xfffe\InsetSpace ~
5923 -little-endian-checksum-nega
5924 tive 0xfffe 0x02 0x02\InsetSpace ~
5926 -o sourcefile.hex -intel
5935 The srecord package is available at
5936 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5943 \begin_layout Subsection
5944 Projects with Multiple Source Files
5947 \begin_layout Standard
5948 SDCC can compile only ONE file at a time.
5949 Let us for example assume that you have a project containing the following
5954 foo1.c (contains some functions)
5956 foo2.c (contains some more functions)
5959 n.c (contains more functions and the function main)
5967 The first two files will need to be compiled separately with the commands:
5999 Then compile the source file containing the
6004 \begin_inset LatexCommand \index{Linker}
6008 the files together with the following command:
6016 foomain.c\InsetSpace ~
6017 foo1.rel\InsetSpace ~
6022 \begin_inset LatexCommand \index{<file>.rel}
6034 can be separately compiled as well:
6045 sdcc foomain.rel foo1.rel foo2.rel
6052 The file containing the
6067 file specified in the command line, since the linkage editor processes
6068 file in the order they are presented to it.
6069 The linker is invoked from SDCC using a script file with extension .lnk
6070 \begin_inset LatexCommand \index{<file>.lnk}
6075 You can view this file to troubleshoot linking problems such as those arising
6076 from missing libraries.
6079 \begin_layout Subsection
6080 Projects with Additional Libraries
6081 \begin_inset LatexCommand \index{Libraries}
6088 \begin_layout Standard
6089 Some reusable routines may be compiled into a library, see the documentation
6090 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6094 \begin_inset LatexCommand \index{<file>.lib}
6101 Libraries created in this manner can be included in the command line.
6102 Make sure you include the -L <library-path> option to tell the linker where
6103 to look for these files if they are not in the current directory.
6104 Here is an example, assuming you have the source file
6116 (if that is not the same as your current project):
6123 sdcc foomain.c foolib.lib -L mylib
6134 must be an absolute path name.
6138 The most efficient way to use libraries is
6139 to keep separate modules in separate source files.
6140 The lib file now should name all the modules.rel
6141 \begin_inset LatexCommand \index{<file>.rel}
6146 For an example see the standard library file
6150 in the directory <installdir>/share/lib/small.
6153 \begin_layout Subsection
6154 Using sdcclib to Create and Manage Libraries
6155 \begin_inset LatexCommand \index{sdcclib}
6162 \begin_layout Standard
6163 Alternatively, instead of having a .rel file for each entry on the library
6164 file as described in the preceding section, sdcclib can be used to embed
6165 all the modules belonging to such library in the library file itself.
6166 This results in a larger library file, but it greatly reduces the number
6167 of disk files accessed by the linker.
6168 Additionally, the packed library file contains an index of all include
6169 modules and symbols that significantly speeds up the linking process.
6170 To display a list of options supported by sdcclib type:
6175 \begin_layout Standard
6180 \begin_inset LatexCommand \index{sdcclib}
6191 To create a new library file, start by compiling all the required modules.
6197 \begin_layout Standard
6204 \begin_layout Standard
6211 \begin_layout Standard
6218 \begin_layout Standard
6225 \begin_layout Standard
6234 \begin_layout Standard
6235 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6237 The next step is to add the .rel files to the library file:
6242 \begin_layout Standard
6246 sdcclib libint.lib _divsint.rel
6249 \begin_inset LatexCommand \index{sdcclib}
6256 \begin_layout Standard
6260 sdcclib libint.lib _divuint.rel
6263 \begin_layout Standard
6267 sdcclib libint.lib _modsint.rel
6270 \begin_layout Standard
6274 sdcclib libint.lib _moduint.rel
6277 \begin_layout Standard
6281 sdcclib libint.lib _mulint.rel
6289 \begin_layout Standard
6298 \begin_layout Standard
6302 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6310 \begin_layout Standard
6311 If the file already exists in the library, it will be replaced.
6312 If a list of .rel files is available, you can tell sdcclib to add those
6314 For example, if the file 'myliblist.txt' contains
6322 \begin_layout Standard
6329 \begin_layout Standard
6336 \begin_layout Standard
6343 \begin_layout Standard
6350 \begin_layout Standard
6362 \begin_layout Standard
6371 \begin_layout Standard
6375 sdcclib -l libint.lib myliblist.txt
6383 \begin_layout Standard
6384 Additionally, you can instruct sdcclib to compiles the files before adding
6385 them to the library.
6386 This is achieved using the environment variables SDCCLIB_CC and/or SDCCLIB_AS.
6395 \begin_layout Standard
6399 set SDCCLIB_CC=sdcc -c
6402 \begin_layout Standard
6406 sdcclib -l libint.lib myliblist.txt
6414 \begin_layout Standard
6415 To see what modules and symbols are included in the library, options -s
6416 and -m are available.
6424 sdcclib -s libint.lib
6427 \begin_inset LatexCommand \index{sdcclib}
6439 \begin_layout Standard
6445 \begin_layout Standard
6451 \begin_layout Standard
6459 \begin_layout Standard
6465 \begin_layout Standard
6471 \begin_layout Standard
6477 \begin_layout Standard
6483 \begin_layout Standard
6491 \begin_layout Standard
6497 \begin_layout Standard
6503 \begin_layout Standard
6511 \begin_layout Standard
6517 \begin_layout Standard
6523 \begin_layout Standard
6529 \begin_layout Standard
6537 \begin_layout Standard
6543 \begin_layout Standard
6554 \begin_layout Standard
6555 If the source files are compiled using -
6559 \begin_layout Standard
6569 \begin_inset LatexCommand \index{-\/-debug}
6573 , the corresponding debug information file .adb will be include in the library
6575 The library files created with sdcclib are plain text files, so they can
6576 be viewed with a text editor.
6577 It is not recomended to modify a library file created with sdcclib using
6578 a text editor, as there are file indexes numbers located accross the file
6579 used by the linker to quickly locate the required module to link.
6580 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6581 it can be safely deleted, since all the information required for linking
6582 is embedded in the library file itself.
6583 Library files created using sdcclib are used as described in the preceding
6585 \begin_inset VSpace bigskip
6591 \begin_layout Section
6592 Command Line Options
6593 \begin_inset LatexCommand \index{Command Line Options}
6598 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6605 \begin_layout Subsection
6606 Processor Selection Options
6607 \begin_inset LatexCommand \index{Options processor selection}
6612 \begin_inset LatexCommand \index{Processor selection options}
6620 \labelwidthstring 00.00.0000
6624 \begin_inset LatexCommand \index{-mmcs51}
6630 Generate code for the Intel MCS51
6631 \begin_inset LatexCommand \index{MCS51}
6635 family of processors.
6636 This is the default processor target.
6640 \labelwidthstring 00.00.0000
6644 \begin_inset LatexCommand \index{-mds390}
6650 Generate code for the Dallas DS80C390
6651 \begin_inset LatexCommand \index{DS80C390}
6659 \labelwidthstring 00.00.0000
6663 \begin_inset LatexCommand \index{-mds400}
6669 Generate code for the Dallas DS80C400
6670 \begin_inset LatexCommand \index{DS80C400}
6678 \labelwidthstring 00.00.0000
6682 \begin_inset LatexCommand \index{-mhc08}
6688 Generate code for the Freescale/Motorola HC08
6689 \begin_inset LatexCommand \index{HC08}
6693 family of processors.
6697 \labelwidthstring 00.00.0000
6701 \begin_inset LatexCommand \index{-mz80}
6707 Generate code for the Zilog Z80
6708 \begin_inset LatexCommand \index{Z80}
6712 family of processors.
6716 \labelwidthstring 00.00.0000
6720 \begin_inset LatexCommand \index{-mgbz80}
6726 Generate code for the GameBoy Z80
6727 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6731 processor (Not actively maintained).
6735 \labelwidthstring 00.00.0000
6739 \begin_inset LatexCommand \index{-mavr}
6745 Generate code for the Atmel AVR
6746 \begin_inset LatexCommand \index{AVR}
6750 processor (Not maintained, not complete).
6751 AVR users should probably have a look at winavr
6752 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6757 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6761 , which is based on AVR-port of the gcc compiler.
6764 \begin_layout Standard
6765 \begin_inset Note Note
6768 \begin_layout Standard
6769 I think it is fair to direct users there for now.
6770 Open source is also about avoiding unnecessary work .
6771 But I didn't find the 'official' link.
6780 \labelwidthstring 00.00.0000
6784 \begin_inset LatexCommand \index{-mpic14}
6790 Generate code for the Microchip PIC 14
6791 \begin_inset LatexCommand \index{PIC14}
6795 -bit processors (p16f84 and variants.
6796 In development, not complete).
6799 \begin_layout Standard
6800 \begin_inset Note Note
6803 \begin_layout Standard
6804 p16f627 p16f628 p16f84 p16f873 p16f877?
6813 \labelwidthstring 00.00.0000
6817 \begin_inset LatexCommand \index{-mpic16}
6823 Generate code for the Microchip PIC 16
6824 \begin_inset LatexCommand \index{PIC16}
6828 -bit processors (p18f452 and variants.
6829 In development, not complete).
6833 \labelwidthstring 00.00.0000
6838 Generate code for the Toshiba TLCS-900H
6839 \begin_inset LatexCommand \index{TLCS-900H}
6843 processor (Not maintained, not complete).
6847 \labelwidthstring 00.00.0000
6851 \begin_inset LatexCommand \index{-mxa51}
6857 Generate code for the Phillips XA51
6858 \begin_inset LatexCommand \index{XA51}
6862 processor (Not maintained, not complete).
6865 \begin_layout Standard
6866 \begin_inset VSpace bigskip
6872 \begin_layout Subsection
6873 Preprocessor Options
6874 \begin_inset LatexCommand \index{Options preprocessor}
6879 \begin_inset LatexCommand \index{Preprocessor options}
6884 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6892 \labelwidthstring 00.00.0000
6896 \begin_inset LatexCommand \index{-I<path>}
6902 The additional location where the preprocessor will look for <..h> or
6903 \begin_inset Quotes eld
6907 \begin_inset Quotes erd
6914 \labelwidthstring 00.00.0000
6918 \begin_inset LatexCommand \index{-D<macro[=value]>}
6924 Command line definition of macros.
6925 Passed to the preprocessor.
6929 \labelwidthstring 00.00.0000
6933 \begin_inset LatexCommand \index{-M}
6939 Tell the preprocessor to output a rule suitable for make describing the
6940 dependencies of each object file.
6941 For each source file, the preprocessor outputs one make-rule whose target
6942 is the object file name for that source file and whose dependencies are
6943 all the files `#include'd in it.
6944 This rule may be a single line or may be continued with `
6946 '-newline if it is long.
6947 The list of rules is printed on standard output instead of the preprocessed
6950 \begin_inset LatexCommand \index{-E}
6958 \labelwidthstring 00.00.0000
6962 \begin_inset LatexCommand \index{-C}
6968 Tell the preprocessor not to discard comments.
6969 Used with the `-E' option.
6973 \labelwidthstring 00.00.0000
6977 \begin_inset LatexCommand \index{-MM}
6988 Like `-M' but the output mentions only the user header files included with
6990 \begin_inset Quotes eld
6994 System header files included with `#include <file>' are omitted.
6998 \labelwidthstring 00.00.0000
7002 \begin_inset LatexCommand \index{-Aquestion(answer)}
7008 Assert the answer answer for question, in case it is tested with a preprocessor
7009 conditional such as `#if #question(answer)'.
7010 `-A-' disables the standard assertions that normally describe the target
7015 \labelwidthstring 00.00.0000
7019 \begin_inset LatexCommand \index{-Umacro}
7025 Undefine macro macro.
7026 `-U' options are evaluated after all `-D' options, but before any `-include'
7027 and `-imacros' options.
7031 \labelwidthstring 00.00.0000
7035 \begin_inset LatexCommand \index{-dM}
7041 Tell the preprocessor to output only a list of the macro definitions that
7042 are in effect at the end of preprocessing.
7043 Used with the `-E' option.
7047 \labelwidthstring 00.00.0000
7051 \begin_inset LatexCommand \index{-dD}
7057 Tell the preprocessor to pass all macro definitions into the output, in
7058 their proper sequence in the rest of the output.
7062 \labelwidthstring 00.00.0000
7066 \begin_inset LatexCommand \index{-dN}
7077 Like `-dD' except that the macro arguments and contents are omitted.
7078 Only `#define name' is included in the output.
7082 \labelwidthstring 00.00.0000
7085 -pedantic-parse-number
7086 \begin_inset LatexCommand \index{pedantic}
7091 \begin_inset LatexCommand \index{-pedantic-parse-number}
7099 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
7107 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7108 and the macro LO_B(3) gets expanded.
7109 See also #pragma pedantic_parse_number
7110 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
7115 \begin_inset LatexCommand \ref{sec:Pragmas}
7121 Note: this functionality is not in conformance with C99 standard!
7125 \labelwidthstring 00.00.0000
7129 preprocessorOption[,preprocessorOption]
7132 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
7137 Pass the preprocessorOption to the preprocessor
7142 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7147 SDCC uses an adapted version of the preprocessor
7151 of the GNU Compiler Collection
7152 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
7161 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7165 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7170 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7177 \begin_layout Standard
7178 \begin_inset VSpace bigskip
7184 \begin_layout Subsection
7186 \begin_inset LatexCommand \index{Options linker}
7191 \begin_inset LatexCommand \index{Linker options}
7199 \labelwidthstring 00.00.0000
7209 \begin_layout Standard
7221 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7226 \begin_inset LatexCommand \index{-L -\/-lib-path}
7233 <absolute path to additional libraries> This option is passed to the linkage
7234 editor's additional libraries
7235 \begin_inset LatexCommand \index{Libraries}
7240 The path name must be absolute.
7241 Additional library files may be specified in the command line.
7242 See section Compiling programs for more details.
7246 \labelwidthstring 00.00.0000
7253 \begin_layout Standard
7265 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7270 <Value> The start location of the external ram
7271 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7275 , default value is 0.
7276 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7280 \begin_layout Standard
7289 -xram-loc 0x8000 or -
7293 \begin_layout Standard
7306 \labelwidthstring 00.00.0000
7313 \begin_layout Standard
7325 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7330 <Value> The start location of the code
7331 \begin_inset LatexCommand \index{code}
7335 segment, default value 0.
7336 Note when this option is used the interrupt vector table
7337 \begin_inset LatexCommand \index{interrupt vector table}
7341 is also relocated to the given address.
7342 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7346 \begin_layout Standard
7355 -code-loc 0x8000 or -
7359 \begin_layout Standard
7372 \labelwidthstring 00.00.0000
7379 \begin_layout Standard
7391 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7396 <Value> By default the stack
7397 \begin_inset LatexCommand \index{stack}
7401 is placed after the data segment.
7402 Using this option the stack can be placed anywhere in the internal memory
7404 The value entered can be in Hexadecimal or Decimal format, e.g.
7409 \begin_layout Standard
7418 -stack-loc 0x20 or -
7422 \begin_layout Standard
7432 Since the sp register is incremented before a push or call, the initial
7433 sp will be set to one byte prior the provided value.
7434 The provided value should not overlap any other memory areas such as used
7435 register banks or the data segment and with enough space for the current
7443 \begin_layout Standard
7456 \begin_inset LatexCommand \index{-\/-pack-iram}
7460 option (which is now a default setting) will override this setting, so
7461 you should also specify the
7467 \begin_layout Standard
7480 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7484 option if you need to manually place the stack.
7488 \labelwidthstring 00.00.0000
7495 \begin_layout Standard
7507 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7512 <Value> By default the external stack
7513 \begin_inset LatexCommand \index{xstack}
7517 is placed after the pdata
7518 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7523 Using this option the xstack can be placed anywhere in the external memory
7525 The value entered can be in Hexadecimal or Decimal format, e.g.
7530 \begin_layout Standard
7539 -xstack-loc 0x8000 or -
7543 \begin_layout Standard
7553 The provided value should not overlap any other memory areas such as the
7554 pdata or xdata segment and with enough space for the current application.
7558 \labelwidthstring 00.00.0000
7565 \begin_layout Standard
7577 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7582 <Value> The start location of the internal ram data
7583 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7588 The value entered can be in Hexadecimal or Decimal format, eg.
7593 \begin_layout Standard
7606 \begin_layout Standard
7616 (By default, the start location of the internal ram data segment is set
7617 as low as possible in memory, taking into account the used register banks
7618 and the bit segment at address 0x20.
7619 For example if register banks 0 and 1 are used without bit variables, the
7620 data segment will be set, if -
7624 \begin_layout Standard
7633 -data-loc is not used, to location 0x10.)
7637 \labelwidthstring 00.00.0000
7644 \begin_layout Standard
7656 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7661 <Value> The start location of the indirectly addressable internal ram
7662 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7666 of the 8051, default value is 0x80.
7667 The value entered can be in Hexadecimal or Decimal format, eg.
7672 \begin_layout Standard
7681 -idata-loc 0x88 or -
7685 \begin_layout Standard
7698 \labelwidthstring 00.00.0000
7705 \begin_layout Standard
7717 <Value> The start location of the bit
7718 \begin_inset LatexCommand \index{bit}
7722 addressable internal ram of the 8051.
7728 Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7733 \labelwidthstring 00.00.0000
7740 \begin_layout Standard
7750 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7759 The linker output (final object code) is in Intel Hex format.
7760 \begin_inset LatexCommand \index{Intel hex format}
7764 This is the default option.
7765 The format itself is documented in the documentation of srecord
7766 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7774 \labelwidthstring 00.00.0000
7781 \begin_layout Standard
7791 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7800 The linker output (final object code) is in Motorola S19 format
7801 \begin_inset LatexCommand \index{Motorola S19 format}
7806 The format itself is documented in the documentation of srecord.
7810 \labelwidthstring 00.00.0000
7817 \begin_layout Standard
7827 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7832 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7841 The linker output (final object code) is in ELF format
7842 \begin_inset LatexCommand \index{ELF format}
7847 (Currently only supported for the HC08
7848 \begin_inset LatexCommand \index{HC08}
7856 \labelwidthstring 00.00.0000
7860 linkOption[,linkOption]
7863 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7868 Pass the linkOption to the linker.
7869 If a bootloader is used an option like
7870 \begin_inset Quotes sld
7875 \begin_inset Quotes srd
7878 would be typical to set the start of the code segment.
7879 See also #pragma constseg and #pragma codeseg in section
7880 \begin_inset LatexCommand \ref{sec:Pragmas}
7885 File sdcc/as/doc/asxhtm.html has more on linker options.
7888 \begin_layout Standard
7889 \begin_inset VSpace bigskip
7895 \begin_layout Subsection
7897 \begin_inset LatexCommand \index{Options MCS51}
7902 \begin_inset LatexCommand \index{MCS51 options}
7910 \labelwidthstring 00.00.0000
7917 \begin_layout Standard
7927 \begin_inset LatexCommand \index{-\/-model-small}
7938 Generate code for Small Model programs, see section Memory Models for more
7940 This is the default model.
7944 \labelwidthstring 00.00.0000
7951 \begin_layout Standard
7961 \begin_inset LatexCommand \index{-\/-model-medium}
7967 Generate code for Medium model programs, see section Memory Models for
7969 If this option is used all source files in the project have to be compiled
7971 It must also be used when invoking the linker.
7975 \labelwidthstring 00.00.0000
7982 \begin_layout Standard
7992 \begin_inset LatexCommand \index{-\/-model-large}
7998 Generate code for Large model programs, see section Memory Models for more
8000 If this option is used all source files in the project have to be compiled
8002 It must also be used when invoking the linker.
8006 \labelwidthstring 00.00.0000
8013 \begin_layout Standard
8023 \begin_inset LatexCommand \index{-\/-xstack}
8029 Uses a pseudo stack in the pdata
8030 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8034 area (usually the first 256 bytes in the external ram) for allocating variables
8035 and passing parameters.
8037 \begin_inset LatexCommand \ref{sub:External-Stack}
8042 External Stack for more details.
8046 \labelwidthstring 00.00.0000
8053 \begin_layout Standard
8066 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
8070 Causes the linker to check if the internal ram usage is within limits of
8075 \labelwidthstring 00.00.0000
8082 \begin_layout Standard
8095 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
8099 Causes the linker to check if the external ram usage is within limits of
8104 \labelwidthstring 00.00.0000
8111 \begin_layout Standard
8124 \begin_inset LatexCommand \index{-\/-code-size <Value>}
8128 Causes the linker to check if the code memory usage is within limits of
8133 \labelwidthstring 00.00.0000
8140 \begin_layout Standard
8153 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8157 Causes the linker to check if there is at minimum <Value> bytes for stack.
8161 \labelwidthstring 00.00.0000
8168 \begin_layout Standard
8181 \begin_inset LatexCommand \index{-\/-pack-iram}
8185 Causes the linker to use unused register banks for data variables and pack
8186 data, idata and stack together.
8187 This is the default now.
8191 \labelwidthstring 00.00.0000
8198 \begin_layout Standard
8211 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8215 Causes the linker to use old style for allocating memory areas.
8219 \labelwidthstring 00.00.0000
8226 \begin_layout Standard
8239 \begin_inset LatexCommand \index{-\/-acall-ajmp}
8243 Replaces the three byte instructions lcall/ljmp with the two byte instructions
8245 Only use this option if your code is in the same 2k block of memory.
8246 You may need to use this option for some 8051 derivatives which lack the
8247 lcall/ljmp instructions..
8250 \begin_layout Standard
8251 \begin_inset VSpace bigskip
8257 \begin_layout Subsection
8258 DS390 / DS400 Options
8259 \begin_inset LatexCommand \index{Options DS390}
8264 \begin_inset LatexCommand \index{DS390}
8272 \labelwidthstring 00.00.0000
8279 \begin_layout Standard
8291 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8301 Generate 24-bit flat mode code.
8302 This is the one and only that the ds390 code generator supports right now
8303 and is default when using
8308 See section Memory Models for more details.
8312 \labelwidthstring 00.00.0000
8319 \begin_layout Standard
8329 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8335 disable interrupts during ESP:SP updates.
8339 \labelwidthstring 00.00.0000
8346 \begin_layout Standard
8358 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8362 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8363 This is the one and only that the ds390 code generator supports right now
8364 and is default when using
8369 In this mode, the stack is located in the lower 1K of the internal RAM,
8370 which is mapped to 0x400000.
8371 Note that the support is incomplete, since it still uses a single byte
8372 as the stack pointer.
8373 This means that only the lower 256 bytes of the potential 1K stack space
8374 will actually be used.
8375 However, this does allow you to reclaim the precious 256 bytes of low RAM
8376 for use for the DATA and IDATA segments.
8377 The compiler will not generate any code to put the processor into 10 bit
8379 It is important to ensure that the processor is in this mode before calling
8380 any re-entrant functions compiled with this option.
8381 In principle, this should work with the
8387 \begin_layout Standard
8397 \begin_inset LatexCommand \index{-\/-stack-auto}
8403 option, but that has not been tested.
8404 It is incompatible with the
8410 \begin_layout Standard
8420 \begin_inset LatexCommand \index{-\/-xstack}
8427 It also only makes sense if the processor is in 24 bit contiguous addressing
8434 \begin_layout Standard
8443 -model-flat24 option
8448 \begin_inset Note Note
8452 \labelwidthstring 00.00.0000
8459 \begin_layout Standard
8468 -stack-8-bit - switches off the 10-bit mode
8477 \labelwidthstring 00.00.0000
8484 \begin_layout Standard
8494 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8500 insert call to function __stack_probe at each function prologue.
8504 \labelwidthstring 00.00.0000
8511 \begin_layout Standard
8521 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8527 <nnnn> LibraryID used in -mTININative.
8532 \labelwidthstring 00.00.0000
8539 \begin_layout Standard
8549 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8555 generate code for DS390 Arithmetic Accelerator.
8559 \begin_layout Standard
8560 \begin_inset VSpace bigskip
8566 \begin_layout Subsection
8568 \begin_inset LatexCommand \index{Options Z80}
8573 \begin_inset LatexCommand \index{Z80}
8581 \labelwidthstring 00.00.0000
8588 \begin_layout Standard
8600 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8610 Force a called function to always save BC.
8614 \labelwidthstring 00.00.0000
8621 \begin_layout Standard
8633 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8637 When linking, skip the standard crt0.o object file.
8638 You must provide your own crt0.o for your system when linking.
8642 \labelwidthstring 00.00.0000
8649 \begin_layout Standard
8661 \begin_inset LatexCommand \index{Z80!Options!-\/-portmode=<Value>}
8665 Determinate PORT I/O mode (<Value> is z80 or z180).
8669 \labelwidthstring 00.00.0000
8676 \begin_layout Standard
8688 \begin_inset LatexCommand \index{Z80!Options!-\/-asm=<Value>}
8692 Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
8696 \labelwidthstring 00.00.0000
8703 \begin_layout Standard
8716 \begin_inset LatexCommand \index{Z80!Options!-\/-codeseg <Value>}
8720 Use <Value> for the code segment name.
8724 \labelwidthstring 00.00.0000
8731 \begin_layout Standard
8744 \begin_inset LatexCommand \index{Z80!Options!-\/-constseg <Value>}
8748 Use <Value> for the const segment name.
8752 \labelwidthstring 00.00.0000
8753 \begin_inset VSpace bigskip
8759 \begin_layout Subsection
8761 \begin_inset LatexCommand \index{Options GBZ80}
8766 \begin_inset LatexCommand \index{GBZ80}
8774 \labelwidthstring 00.00.0000
8781 \begin_layout Standard
8793 \begin_inset LatexCommand \index{GBZ80!Options!-\/-callee-saves-bc}
8803 Force a called function to always save BC.
8807 \labelwidthstring 00.00.0000
8814 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
8818 Use code bank <Num>.
8822 \labelwidthstring 00.00.0000
8829 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
8833 Use data bank <Num>.
8837 \labelwidthstring 00.00.0000
8844 \begin_layout Standard
8857 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
8861 Use <Value> for the code segment name.
8865 \labelwidthstring 00.00.0000
8872 \begin_layout Standard
8885 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
8889 Use <Value> for the const segment name.
8892 \begin_layout Standard
8893 \begin_inset VSpace bigskip
8899 \begin_layout Subsection
8900 Optimization Options
8901 \begin_inset LatexCommand \index{Options optimization}
8906 \begin_inset LatexCommand \index{Optimization options}
8914 \labelwidthstring 00.00.0000
8921 \begin_layout Standard
8931 \begin_inset LatexCommand \index{-\/-nogcse}
8937 Will not do global subexpression elimination, this option may be used when
8938 the compiler creates undesirably large stack/data spaces to store compiler
8948 \begin_inset LatexCommand \index{sloc (spill location)}
8953 A warning message will be generated when this happens and the compiler
8954 will indicate the number of extra bytes it allocated.
8955 It is recommended that this option NOT be used, #pragma\InsetSpace ~
8957 \begin_inset LatexCommand \index{\#pragma nogcse}
8961 can be used to turn off global subexpression elimination
8962 \begin_inset LatexCommand \index{Subexpression elimination}
8966 for a given function only.
8970 \labelwidthstring 00.00.0000
8977 \begin_layout Standard
8987 \begin_inset LatexCommand \index{-\/-noinvariant}
8993 Will not do loop invariant optimizations, this may be turned off for reasons
8994 explained for the previous option.
8995 For more details of loop optimizations performed see Loop Invariants in
8997 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
9002 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9004 \begin_inset LatexCommand \index{\#pragma noinvariant}
9008 can be used to turn off invariant optimizations for a given function only.
9012 \labelwidthstring 00.00.0000
9019 \begin_layout Standard
9029 \begin_inset LatexCommand \index{-\/-noinduction}
9035 Will not do loop induction optimizations, see section strength reduction
9037 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9039 \begin_inset LatexCommand \index{\#pragma noinduction}
9043 can be used to turn off induction optimizations for a given function only.
9047 \labelwidthstring 00.00.0000
9054 \begin_layout Standard
9064 \begin_inset LatexCommand \index{-\/-nojtbound}
9075 Will not generate boundary condition check when switch statements
9076 \begin_inset LatexCommand \index{switch statement}
9080 are implemented using jump-tables.
9082 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
9087 Switch Statements for more details.
9088 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9090 \begin_inset LatexCommand \index{\#pragma nojtbound}
9094 can be used to turn off boundary checking for jump tables for a given function
9099 \labelwidthstring 00.00.0000
9106 \begin_layout Standard
9116 \begin_inset LatexCommand \index{-\/-noloopreverse}
9125 Will not do loop reversal
9126 \begin_inset LatexCommand \index{Loop reversing}
9134 \labelwidthstring 00.00.0000
9139 \begin_layout Standard
9153 \begin_inset LatexCommand \index{-\/-nolabelopt }
9157 Will not optimize labels (makes the dumpfiles more readable).
9161 \labelwidthstring 00.00.0000
9168 \begin_layout Standard
9178 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9184 Will not memcpy initialized data from code space into xdata space.
9185 This saves a few bytes in code space if you don't have initialized data
9186 \begin_inset LatexCommand \index{Variable initialization}
9194 \labelwidthstring 00.00.0000
9201 \begin_layout Standard
9211 \begin_inset LatexCommand \index{-\/-nooverlay}
9217 The compiler will not overlay parameters and local variables of any function,
9218 see section Parameters and local variables for more details.
9222 \labelwidthstring 00.00.0000
9229 \begin_layout Standard
9239 \begin_inset LatexCommand \index{-\/-no-peep}
9245 Disable peep-hole optimization with built-in rules.
9249 \labelwidthstring 00.00.0000
9256 \begin_layout Standard
9268 \begin_inset LatexCommand \index{-\/-peep-file}
9273 <filename> This option can be used to use additional rules to be used by
9274 the peep hole optimizer.
9276 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9281 Peep Hole optimizations for details on how to write these rules.
9285 \labelwidthstring 00.00.0000
9292 \begin_layout Standard
9302 \begin_inset LatexCommand \index{-\/-peep-asm}
9308 Pass the inline assembler code through the peep hole optimizer.
9309 This can cause unexpected changes to inline assembler code, please go through
9310 the peephole optimizer
9311 \begin_inset LatexCommand \index{Peephole optimizer}
9315 rules defined in the source file tree '<target>/peeph.def' before using
9320 \labelwidthstring 00.00.0000
9327 \begin_layout Standard
9337 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9343 The compiler will optimize code generation towards fast code, possibly
9344 at the expense of code size.
9348 \labelwidthstring 00.00.0000
9355 \begin_layout Standard
9365 \begin_inset LatexCommand \index{-\/-opt-code-size}
9371 The compiler will optimize code generation towards compact code, possibly
9372 at the expense of code speed.
9375 \begin_layout Standard
9376 \begin_inset VSpace bigskip
9382 \begin_layout Subsection
9384 \begin_inset LatexCommand \index{Options other}
9392 \labelwidthstring 00.00.0000
9400 \begin_layout Standard
9410 \begin_inset LatexCommand \index{-\/-compile-only}
9415 \begin_inset LatexCommand \index{-c -\/-compile-only}
9421 will compile and assemble the source, but will not call the linkage editor.
9425 \labelwidthstring 00.00.0000
9434 \begin_layout Standard
9446 \begin_inset LatexCommand \index{-\/-c1mode}
9452 reads the preprocessed source from standard input and compiles it.
9453 The file name for the assembler output must be specified using the -o option.
9457 \labelwidthstring 00.00.0000
9461 \begin_inset LatexCommand \index{-E}
9467 Run only the C preprocessor.
9468 Preprocess all the C source files specified and output the results to standard
9473 \labelwidthstring 00.00.0000
9478 \begin_inset LatexCommand \index{-o <path/file>}
9484 The output path where everything will be placed or the file name used for
9485 all generated output files.
9486 If the parameter is a path, it must have a trailing slash (or backslash
9487 for the Windows binaries) to be recognized as a path.
9492 Note for Windows users: if the path contains spaces, it should be surrounded
9494 The trailing backslash should be doubled in order to prevent escaping the
9495 final quote, for example:
9498 \begin_inset Quotes sld
9512 \begin_inset Quotes srd
9517 or put after the final quote, for example:
9520 \begin_inset Quotes sld
9530 \begin_inset Quotes srd
9538 The path using slashes for directory delimiters can be used too, for example:
9542 \begin_inset Quotes sld
9545 F:/Projects/test3/output 1/
9546 \begin_inset Quotes srd
9555 \labelwidthstring 00.00.0000
9562 \begin_layout Standard
9572 \begin_inset LatexCommand \index{-\/-stack-auto}
9583 All functions in the source file will be compiled as
9588 \begin_inset LatexCommand \index{reentrant}
9593 the parameters and local variables will be allocated on the stack
9594 \begin_inset LatexCommand \index{stack}
9600 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9604 Parameters and Local Variables for more details.
9605 If this option is used all source files in the project should be compiled
9607 It automatically implies -
9613 \begin_layout Standard
9624 -int-long-reent and -
9630 \begin_layout Standard
9646 \labelwidthstring 00.00.0000
9653 \begin_layout Standard
9663 \begin_inset LatexCommand \index{-\/-callee-saves}
9668 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9672 function1[,function2][,function3]....
9675 The compiler by default uses a caller saves convention for register saving
9676 across function calls, however this can cause unnecessary register pushing
9677 and popping when calling small functions from larger functions.
9678 This option can be used to switch the register saving convention for the
9679 function names specified.
9680 The compiler will not save registers when calling these functions, no extra
9681 code will be generated at the entry and exit (function prologue
9684 \begin_inset LatexCommand \index{function prologue}
9693 \begin_inset LatexCommand \index{function epilogue}
9699 ) for these functions to save and restore the registers used by these functions,
9700 this can SUBSTANTIALLY reduce code and improve run time performance of
9702 In the future the compiler (with inter procedural analysis) will be able
9703 to determine the appropriate scheme to use for each function call.
9704 DO NOT use this option for built-in functions such as _mulint..., if this
9705 option is used for a library function the appropriate library function
9706 needs to be recompiled with the same option.
9707 If the project consists of multiple source files then all the source file
9708 should be compiled with the same -
9712 \begin_layout Standard
9721 -callee-saves option string.
9722 Also see #pragma\InsetSpace ~
9724 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9729 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9737 \labelwidthstring 00.00.0000
9744 \begin_layout Standard
9754 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9768 \begin_layout Standard
9777 -callee-saves will be applied to all functions by default.
9781 \labelwidthstring 00.00.0000
9788 \begin_layout Standard
9798 \begin_inset LatexCommand \index{-\/-debug}
9807 When this option is used the compiler will generate debug information.
9808 The debug information collected in a file with .cdb extension can be used
9810 For more information see documentation for SDCDB.
9811 Another file with no extension contains debug information in AOMF or AOMF51
9812 \begin_inset LatexCommand \index{AOMF, AOMF51}
9816 format which is commonly used by third party tools.
9820 \labelwidthstring 00.00.0000
9824 \begin_inset LatexCommand \index{-S}
9835 Stop after the stage of compilation proper; do not assemble.
9836 The output is an assembler code file for the input file specified.
9840 \labelwidthstring 00.00.0000
9847 \begin_layout Standard
9857 \begin_inset LatexCommand \index{-\/-int-long-reent}
9863 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
9864 Note by default these libraries are compiled as non-reentrant.
9865 See section Installation for more details.
9869 \labelwidthstring 00.00.0000
9876 \begin_layout Standard
9886 \begin_inset LatexCommand \index{-\/-cyclomatic}
9895 This option will cause the compiler to generate an information message for
9896 each function in the source file.
9897 The message contains some
9901 information about the function.
9902 The number of edges and nodes the compiler detected in the control flow
9903 graph of the function, and most importantly the
9905 cyclomatic complexity
9906 \begin_inset LatexCommand \index{Cyclomatic complexity}
9912 see section on Cyclomatic Complexity for more details.
9916 \labelwidthstring 00.00.0000
9923 \begin_layout Standard
9933 \begin_inset LatexCommand \index{-\/-float-reent}
9939 Floating point library is compiled as reentrant
9940 \begin_inset LatexCommand \index{reentrant}
9945 See section Installation for more details.
9949 \labelwidthstring 00.00.0000
9956 \begin_layout Standard
9966 \begin_inset LatexCommand \index{-\/-funsigned-char}
9972 The default signedness for every type is
9977 In some embedded environments the default signedness of
9986 To set the signess for characters to unsigned, use the option -
9992 \begin_layout Standard
10004 If this option is set and no signedness keyword (unsigned/signed) is given,
10005 a char will be signed.
10006 All other types are unaffected.
10010 \labelwidthstring 00.00.0000
10017 \begin_layout Standard
10027 \begin_inset LatexCommand \index{-\/-main-return}
10033 This option can be used if the code generated is called by a monitor program
10034 or if the main routine includes an endless loop.
10035 This option results in slightly smaller code and saves two bytes of stack
10037 The return from the 'main'
10038 \begin_inset LatexCommand \index{main return}
10042 function will return to the function calling main.
10043 The default setting is to lock up i.e.
10052 \labelwidthstring 00.00.0000
10059 \begin_layout Standard
10069 \begin_inset LatexCommand \index{-\/-nostdinc}
10075 This will prevent the compiler from passing on the default include path
10076 to the preprocessor.
10080 \labelwidthstring 00.00.0000
10087 \begin_layout Standard
10097 \begin_inset LatexCommand \index{-\/-nostdlib}
10103 This will prevent the compiler from passing on the default library
10104 \begin_inset LatexCommand \index{Libraries}
10108 path to the linker.
10112 \labelwidthstring 00.00.0000
10119 \begin_layout Standard
10129 \begin_inset LatexCommand \index{-\/-verbose}
10135 Shows the various actions the compiler is performing.
10139 \labelwidthstring 00.00.0000
10143 \begin_inset LatexCommand \index{-V}
10149 Shows the actual commands the compiler is executing.
10153 \labelwidthstring 00.00.0000
10160 \begin_layout Standard
10170 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
10176 Hides your ugly and inefficient c-code from the asm file, so you can always
10177 blame the compiler :)
10181 \labelwidthstring 00.00.0000
10188 \begin_layout Standard
10198 \begin_inset LatexCommand \index{-\/-no-gen-comments}
10204 Include code generator and peep-hole comments in the generated asm files.
10208 \labelwidthstring 00.00.0000
10215 \begin_layout Standard
10225 \begin_inset LatexCommand \index{-\/-no-peep-comments}
10231 Don't include peep-hole comments in the generated asm files even if -
10237 \begin_layout Standard
10248 -fverbose-asm option is specified.
10252 \labelwidthstring 00.00.0000
10259 \begin_layout Standard
10269 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10275 Include i-codes in the asm file.
10276 Sounds like noise but is most helpful for debugging the compiler itself.
10280 \labelwidthstring 00.00.0000
10287 \begin_layout Standard
10297 \begin_inset LatexCommand \index{pedantic}
10302 \begin_inset LatexCommand \index{-\/-less-pedantic}
10309 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10313 Disable some of the more pedantic warnings
10314 \begin_inset LatexCommand \index{Warnings}
10319 For more details, see the less_pedantic pragma
10320 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10328 \labelwidthstring 00.00.0000
10335 \begin_layout Standard
10344 -disable-warning\InsetSpace ~
10346 \begin_inset LatexCommand \index{-\/-disable-warning}
10352 Disable specific warning with number <nnnn>.
10356 \labelwidthstring 00.00.0000
10363 \begin_layout Standard
10373 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10379 Display the directories in the compiler's search path
10383 \labelwidthstring 00.00.0000
10390 \begin_layout Standard
10400 \begin_inset LatexCommand \index{-\/-vc}
10406 Display errors and warnings using MSVC style, so you can use SDCC with
10407 the visual studio IDE
10408 \begin_inset LatexCommand \index{IDE}
10413 With SDCC both offering a GCC-like (the default) and a MSVC-like
10414 \begin_inset LatexCommand \index{MSVC output style}
10418 output style, integration into most programming editors should be straightforwa
10423 \labelwidthstring 00.00.0000
10430 \begin_layout Standard
10440 \begin_inset LatexCommand \index{-\/-use-stdout}
10446 Send errors and warnings to stdout instead of stderr.
10450 \labelwidthstring 00.00.0000
10454 asmOption[,asmOption]
10457 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10462 Pass the asmOption to the assembler
10463 \begin_inset LatexCommand \index{Options assembler}
10468 \begin_inset LatexCommand \index{Assembler options}
10473 See file sdcc/as/doc/asxhtm.html for assembler options.cd
10477 \labelwidthstring 00.00.0000
10484 \begin_layout Standard
10494 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10500 Generally follow the C89 standard, but allow SDCC features that conflict
10501 with the standard (default).
10505 \labelwidthstring 00.00.0000
10512 \begin_layout Standard
10522 \begin_inset LatexCommand \index{-\/-std-c89}
10528 Follow the C89 standard and disable SDCC features that conflict with the
10533 \labelwidthstring 00.00.0000
10540 \begin_layout Standard
10550 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10556 Generally follow the C99 standard, but allow SDCC features that conflict
10557 with the standard (incomplete support).
10561 \labelwidthstring 00.00.0000
10568 \begin_layout Standard
10578 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10584 Follow the C99 standard and disable SDCC features that conflict with the
10585 standard (incomplete support).
10589 \labelwidthstring 00.00.0000
10596 \begin_layout Standard
10608 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10613 <Name> The name to be used for the code
10614 \begin_inset LatexCommand \index{code}
10618 segment, default CSEG.
10619 This is useful if you need to tell the compiler to put the code in a special
10620 segment so you can later on tell the linker to put this segment in a special
10622 Can be used for instance when using bank switching to put the code in a
10627 \labelwidthstring 00.00.0000
10634 \begin_layout Standard
10646 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10651 <Name> The name to be used for the const
10652 \begin_inset LatexCommand \index{const}
10656 segment, default CONST.
10657 This is useful if you need to tell the compiler to put the const data in
10658 a special segment so you can later on tell the linker to put this segment
10659 in a special place in memory.
10660 Can be used for instance when using bank switching to put the const data
10665 \labelwidthstring 00.00.0000
10672 \begin_layout Standard
10681 -fdollars-in-identifiers
10682 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10688 Permit '$' as an identifier character.
10692 \labelwidthstring 00.00.0000
10699 \begin_layout Standard
10711 \begin_inset LatexCommand \index{-\/-more-pedantic}
10716 \begin_inset LatexCommand \index{pedantic}
10726 a SDCC compiler option but if you want
10730 warnings you can use a separate tool dedicated to syntax checking like
10732 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10737 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10742 \begin_inset LatexCommand \url{http://www.splint.org}
10747 To make your source files parseable by splint you will have to include
10753 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10757 in your source file and add brackets around extended keywords (like
10760 \begin_inset Quotes sld
10773 \begin_inset Quotes srd
10781 \begin_inset Quotes sld
10784 __interrupt\InsetSpace ~
10786 \begin_inset Quotes srd
10794 Splint has an excellent on line manual at
10795 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10799 and it's capabilities go beyond pure syntax checking.
10800 You'll need to tell splint the location of SDCC's include files so a typical
10801 command line could look like this:
10805 splint\InsetSpace ~
10807 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10813 \labelwidthstring 00.00.0000
10820 \begin_layout Standard
10832 \begin_inset LatexCommand \index{-\/-short-is-8bits}
10837 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
10841 Treat short as 8-bit (for backward compatibility with older versions of
10842 compiler - see section
10843 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
10850 \begin_layout Standard
10851 \begin_inset VSpace bigskip
10857 \begin_layout Subsection
10858 Intermediate Dump Options
10859 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
10864 \begin_inset LatexCommand \index{Options intermediate dump}
10869 \begin_inset LatexCommand \index{Intermediate dump options}
10876 \begin_layout Standard
10877 The following options are provided for the purpose of retargetting and debugging
10879 They provide a means to dump the intermediate code (iCode
10880 \begin_inset LatexCommand \index{iCode}
10884 ) generated by the compiler in human readable form at various stages of
10885 the compilation process.
10886 More on iCodes see chapter
10887 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10892 \begin_inset Quotes srd
10895 The anatomy of the compiler
10896 \begin_inset Quotes srd
10903 \labelwidthstring 00.00.0000
10910 \begin_layout Standard
10920 \begin_inset LatexCommand \index{-\/-dumpraw}
10926 This option will cause the compiler to dump the intermediate code into
10929 <source filename>.dumpraw
10931 just after the intermediate code has been generated for a function, i.e.
10932 before any optimizations are done.
10934 \begin_inset LatexCommand \index{Basic blocks}
10938 at this stage ordered in the depth first number, so they may not be in
10939 sequence of execution.
10943 \labelwidthstring 00.00.0000
10950 \begin_layout Standard
10960 \begin_inset LatexCommand \index{-\/-dumpgcse}
10966 Will create a dump of iCodes, after global subexpression elimination
10967 \begin_inset LatexCommand \index{Global subexpression elimination}
10971 , into a file named
10973 <source filename>.dumpgcse.
10977 \labelwidthstring 00.00.0000
10984 \begin_layout Standard
10994 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
11000 Will create a dump of iCodes, after deadcode elimination
11001 \begin_inset LatexCommand \index{Dead-code elimination}
11005 , into a file named
11007 <source filename>.dumpdeadcode.
11011 \labelwidthstring 00.00.0000
11018 \begin_layout Standard
11028 \begin_inset LatexCommand \index{-\/-dumploop}
11037 Will create a dump of iCodes, after loop optimizations
11038 \begin_inset LatexCommand \index{Loop optimization}
11042 , into a file named
11044 <source filename>.dumploop.
11048 \labelwidthstring 00.00.0000
11055 \begin_layout Standard
11065 \begin_inset LatexCommand \index{-\/-dumprange}
11074 Will create a dump of iCodes, after live range analysis
11075 \begin_inset LatexCommand \index{Live range analysis}
11079 , into a file named
11081 <source filename>.dumprange.
11085 \labelwidthstring 00.00.0000
11092 \begin_layout Standard
11102 \begin_inset LatexCommand \index{-\/-dumlrange}
11108 Will dump the life ranges
11109 \begin_inset LatexCommand \index{Live range analysis}
11117 \labelwidthstring 00.00.0000
11124 \begin_layout Standard
11134 \begin_inset LatexCommand \index{-\/-dumpregassign}
11143 Will create a dump of iCodes, after register assignment
11144 \begin_inset LatexCommand \index{Register assignment}
11148 , into a file named
11150 <source filename>.dumprassgn.
11154 \labelwidthstring 00.00.0000
11161 \begin_layout Standard
11171 \begin_inset LatexCommand \index{-\/-dumplrange}
11177 Will create a dump of the live ranges of iTemp's
11181 \labelwidthstring 00.00.0000
11188 \begin_layout Standard
11198 \begin_inset LatexCommand \index{-\/-dumpall}
11209 Will cause all the above mentioned dumps to be created.
11212 \begin_layout Standard
11213 \begin_inset VSpace bigskip
11219 \begin_layout Subsection
11220 Redirecting output on Windows Shells
11223 \begin_layout Standard
11224 By default SDCC writes its error messages to
11225 \begin_inset Quotes sld
11229 \begin_inset Quotes srd
11233 To force all messages to
11234 \begin_inset Quotes sld
11238 \begin_inset Quotes srd
11250 \begin_layout Standard
11265 \begin_inset LatexCommand \index{-\/-use-stdout}
11270 Additionally, if you happen to have visual studio installed in your windows
11271 machine, you can use it to compile your sources using a custom build and
11278 \begin_layout Standard
11290 \begin_inset LatexCommand \index{-\/-vc}
11295 Something like this should work:
11314 \begin_layout Standard
11333 \begin_layout Standard
11345 -model-large -c $(InputPath)
11348 \begin_inset VSpace bigskip
11354 \begin_layout Section
11355 Environment variables
11356 \begin_inset LatexCommand \index{Environment variables}
11363 \begin_layout Standard
11364 SDCC recognizes the following environment variables:
11368 \labelwidthstring 00.00.0000
11372 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11378 SDCC installs a signal handler
11379 \begin_inset LatexCommand \index{signal handler}
11383 to be able to delete temporary files after an user break (^C) or an exception.
11384 If this environment variable is set, SDCC won't install the signal handler
11385 in order to be able to debug SDCC.
11389 \labelwidthstring 00.00.0000
11395 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11401 Path, where temporary files will be created.
11402 The order of the variables is the search order.
11403 In a standard *nix environment these variables are not set, and there's
11404 no need to set them.
11405 On Windows it's recommended to set one of them.
11409 \labelwidthstring 00.00.0000
11413 \begin_inset LatexCommand \index{SDCC\_HOME}
11420 \begin_inset LatexCommand \ref{sub:Install-paths}
11426 \begin_inset Quotes sld
11430 \begin_inset Quotes srd
11437 \labelwidthstring 00.00.0000
11441 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11448 \begin_inset LatexCommand \ref{sub:Search-Paths}
11454 \begin_inset Quotes sld
11458 \begin_inset Quotes srd
11465 \labelwidthstring 00.00.0000
11469 \begin_inset LatexCommand \index{SDCC\_LIB}
11476 \begin_inset LatexCommand \ref{sub:Search-Paths}
11482 \begin_inset Quotes sld
11486 \begin_inset Quotes srd
11492 \begin_layout Standard
11493 There are some more environment variables recognized by SDCC, but these
11494 are solely used for debugging purposes.
11495 They can change or disappear very quickly, and will never be documented.
11496 \begin_inset VSpace bigskip
11502 \begin_layout Section
11503 Storage Class Language Extensions
11506 \begin_layout Subsection
11507 MCS51/DS390 Storage Class
11508 \begin_inset LatexCommand \index{Storage class}
11512 Language Extensions
11515 \begin_layout Standard
11516 In addition to the ANSI storage classes SDCC allows the following MCS51
11517 specific storage classes:
11520 \begin_layout Subsubsection
11522 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11527 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11532 \begin_inset LatexCommand \index{near (storage class)}
11537 \begin_inset LatexCommand \index{\_\_near (storage class)}
11544 \begin_layout Standard
11549 storage class for the Small Memory model (
11557 or the more ANSI-C compliant forms
11565 can be used synonymously).
11566 Variables declared with this storage class will be allocated in the directly
11567 addressable portion of the internal RAM of a 8051, e.g.:
11570 \begin_layout Verse
11573 __data unsigned char test_data;
11576 \begin_layout Standard
11577 Writing 0x01 to this variable generates the assembly code:
11580 \begin_layout Verse
11583 75*00 01\InsetSpace ~
11591 \begin_layout Subsubsection
11593 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11598 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11603 \begin_inset LatexCommand \index{far (storage class)}
11608 \begin_inset LatexCommand \index{\_\_far (storage class)}
11615 \begin_layout Standard
11616 Variables declared with this storage class will be placed in the external
11622 storage class for the Large Memory model, e.g.:
11625 \begin_layout Verse
11628 __xdata unsigned char test_xdata;
11631 \begin_layout Standard
11632 Writing 0x01 to this variable generates the assembly code:
11635 \begin_layout Verse
11638 90s00r00\InsetSpace ~
11669 \begin_layout Subsubsection
11671 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11676 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11683 \begin_layout Standard
11684 Variables declared with this storage class will be allocated into the indirectly
11685 addressable portion of the internal ram of a 8051, e.g.:
11688 \begin_layout Verse
11691 __idata unsigned char test_idata;
11694 \begin_layout Standard
11695 Writing 0x01 to this variable generates the assembly code:
11698 \begin_layout Verse
11725 \begin_layout Standard
11726 Please note, the first 128 byte of idata physically access the same RAM
11727 as the data memory.
11728 The original 8051 had 128 byte idata memory, nowadays most devices have
11729 256 byte idata memory.
11731 \begin_inset LatexCommand \index{stack}
11735 is located in idata memory.
11738 \begin_layout Subsubsection
11740 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11745 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11752 \begin_layout Standard
11753 Paged xdata access is just as straightforward as using the other addressing
11755 It is typically located at the start of xdata and has a maximum size of
11757 The following example writes 0x01 to the pdata variable.
11758 Please note, pdata access physically accesses xdata memory.
11759 The high byte of the address is determined by port P2
11760 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11764 (or in case of some 8051 variants by a separate Special Function Register,
11766 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11775 storage class for the Medium Memory model, e.g.:
11778 \begin_layout Verse
11781 __pdata unsigned char test_pdata;
11784 \begin_layout Standard
11785 Writing 0x01 to this variable generates the assembly code:
11788 \begin_layout Verse
11797 mov r0,#_test_pdata
11819 \begin_layout Standard
11824 \begin_layout Standard
11834 \begin_inset LatexCommand \index{-\/-xstack}
11838 option is used the pdata memory area is followed by the xstack memory area
11839 and the sum of their sizes is limited to 256 bytes.
11842 \begin_layout Subsubsection
11844 \begin_inset LatexCommand \index{code}
11849 \begin_inset LatexCommand \index{\_\_code}
11856 \begin_layout Standard
11857 'Variables' declared with this storage class will be placed in the code
11861 \begin_layout Verse
11864 __code unsigned char test_code;
11867 \begin_layout Standard
11868 Read access to this variable generates the assembly code:
11871 \begin_layout Verse
11874 90s00r6F\InsetSpace ~
11877 mov dptr,#_test_code
11902 \begin_layout Standard
11907 indexed arrays of characters in code memory can be accessed efficiently:
11910 \begin_layout Verse
11913 __code char test_array[] = {'c','h','e','a','p'};
11916 \begin_layout Standard
11917 Read access to this array using an 8-bit unsigned index generates the assembly
11921 \begin_layout Verse
11933 \begin_layout Verse
11936 90s00r41\InsetSpace ~
11939 mov dptr,#_test_array
11942 \begin_layout Verse
11957 \begin_layout Subsubsection
11959 \begin_inset LatexCommand \index{bit}
11964 \begin_inset LatexCommand \index{\_\_bit}
11971 \begin_layout Standard
11972 This is a data-type and a storage class specifier.
11973 When a variable is declared as a bit, it is allocated into the bit addressable
11974 memory of 8051, e.g.:
11977 \begin_layout Verse
11983 \begin_layout Standard
11984 Writing 1 to this variable generates the assembly code:
11987 \begin_layout Verse
12001 \begin_layout Standard
12002 The bit addressable memory consists of 128 bits which are located from 0x20
12003 to 0x2f in data memory.
12006 Apart from this 8051 specific storage class most architectures support
12008 \begin_inset LatexCommand \index{bitfields}
12016 \begin_layout Standard
12017 Not really meant as examples, but nevertheless showing what bitfields are
12018 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12024 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12025 signed modifier are implemented as unsigned.
12028 \begin_layout Subsubsection
12030 \begin_inset LatexCommand \index{sfr}
12035 \begin_inset LatexCommand \index{\_\_sfr}
12040 \begin_inset LatexCommand \index{sfr16}
12045 \begin_inset LatexCommand \index{\_\_sfr16}
12050 \begin_inset LatexCommand \index{sfr32}
12055 \begin_inset LatexCommand \index{\_\_sfr32}
12060 \begin_inset LatexCommand \index{\_\_sbit}
12065 \begin_inset LatexCommand \index{sbit}
12072 \begin_layout Standard
12073 Like the bit keyword,
12075 sfr / sfr16 / sfr32 / sbit
12077 signify both a data-type and storage class, they are used to describe the
12098 variables of a 8051, eg:
12101 \begin_layout Verse
12105 \begin_inset LatexCommand \index{at}
12110 \begin_inset LatexCommand \index{\_\_at}
12114 (0x80) P0;\InsetSpace ~
12115 /* special function register P0 at location 0x80 */
12120 special function register combination for timer 0
12124 with the high byte at
12125 location 0x8C and the low byte at location 0x8A */
12127 __sfr16 __at (0x8C8A)
12133 \begin_inset LatexCommand \index{at}
12138 \begin_inset LatexCommand \index{\_\_at}
12142 (0xd7) CY;\InsetSpace ~
12144 \begin_inset LatexCommand \index{Flags}
12149 \begin_inset LatexCommand \index{Carry flag}
12156 \begin_layout Standard
12157 Special function registers which are located on an address dividable by
12158 8 are bit-addressable, an
12162 addresses a specific bit within these sfr.
12164 16 Bit and 32 bit special function
12165 register combinations which require a certain access order are better not
12175 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12176 this is not guaranteed.
12181 \begin_layout Standard
12182 Please note, if you use a header file which was written for another compiler
12183 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
12189 Specifically the syntax
12192 sfr P0 = 0x80;\InsetSpace ~
12199 by SDCC to an assignment of 0x80 to a variable called P0
12202 \begin_inset Marginal
12205 \begin_layout Standard
12217 Nevertheless it is possible to write header files
12218 \begin_inset LatexCommand \index{Header files}
12223 \begin_inset LatexCommand \index{Include files}
12227 which can be shared among different compilers (see section
12228 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
12236 \begin_layout Subsubsection
12238 \begin_inset LatexCommand \index{Pointer}
12242 to MCS51/DS390 specific memory spaces
12245 \begin_layout Standard
12246 SDCC allows (via language extensions) pointers to explicitly point to any
12247 of the memory spaces
12248 \begin_inset LatexCommand \index{Memory model}
12253 In addition to the explicit pointers, the compiler uses (by default) generic
12254 pointers which can be used to point to any of the memory spaces.
12259 declaration examples:
12262 \begin_layout Verse
12265 /* pointer physically in internal ram pointing to object in external ram
12268 __xdata unsigned char * __data p;
12272 /* pointer physically in external ram
12273 pointing to object in internal ram */
12275 __data unsigned char * __xdata p;
12280 pointer physically in code rom pointing to data in xdata space */
12283 unsigned char * __code p;
12287 /* pointer physically in code space pointing to
12288 data in code space */
12290 __code unsigned char * __code p;
12295 physically located in xdata space */
12297 unsigned char * __xdata p;
12302 pointer physically located in default memory space */
12309 the following is a function pointer
12310 \begin_inset LatexCommand \index{function pointer}
12314 physically located in data space */
12316 char (* __data fp)(void);
12319 \begin_layout Standard
12320 Well you get the idea.
12325 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
12338 The highest order byte of the
12342 pointers contains the data space information.
12343 Assembler support routines are called whenever data is stored or retrieved
12349 These are useful for developing reusable library
12350 \begin_inset LatexCommand \index{Libraries}
12355 Explicitly specifying the pointer
12356 \begin_inset LatexCommand \index{pointer}
12360 type will generate the most efficient code.
12363 \begin_layout Subsubsection
12364 Notes on MCS51 memory
12365 \begin_inset LatexCommand \index{MCS51 memory}
12372 \begin_layout Standard
12373 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12374 RAM memory which is structured as follows:
12378 - Bytes 00-1F - 32 bytes to hold
12379 up to 4 banks of the registers R0 to R7,
12381 - Bytes 20-2F - 16 bytes to hold
12383 \begin_inset LatexCommand \index{bit}
12389 - Bytes 30-7F - 80 bytes for general purpose use.
12394 \begin_layout Standard
12395 Additionally some members of the MCS51 family may have up to 128 bytes of
12396 additional, indirectly addressable, internal RAM memory (
12401 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12406 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12411 Furthermore, some chips may have some built in external memory (
12416 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12421 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12425 ) which should not be confused with the internal, directly addressable RAM
12431 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12436 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12441 Sometimes this built in
12445 memory has to be activated before using it (you can probably find this
12446 information on the datasheet of the microcontroller your are using, see
12448 \begin_inset LatexCommand \ref{sub:Startup-Code}
12456 \begin_layout Standard
12457 Normally SDCC will only use the first bank
12458 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12462 of registers (register bank 0), but it is possible to specify that other
12463 banks of registers (keyword
12470 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12475 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12481 ) should be used for example in interrupt
12482 \begin_inset LatexCommand \index{interrupt}
12487 \begin_inset LatexCommand \index{\_\_interrupt}
12492 By default, the compiler will place the stack after the last byte of allocated
12493 memory for variables.
12494 For example, if the first 2 banks of registers are used, and only four
12499 variables, it will position the base of the internal stack at address 20
12501 This implies that as the stack
12502 \begin_inset LatexCommand \index{stack}
12506 grows, it will use up the remaining register banks, and the 16 bytes used
12507 by the 128 bit variables, and 80 bytes for general purpose use.
12508 If any bit variables are used, the data variables will be placed in unused
12509 register banks and after the byte holding the last bit variable.
12510 For example, if register banks 0 and 1 are used, and there are 9 bit variables
12515 variables will be placed starting from address 0x10 to 0x20 and continue
12521 \begin_layout Standard
12531 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12535 to specify the start address of the
12543 \begin_layout Standard
12553 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12557 to specify the size of the total internal RAM (
12571 \begin_layout Standard
12572 By default the 8051 linker will place the stack after the last byte of (i)data
12578 \begin_layout Standard
12588 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12592 allows you to specify the start of the stack, i.e.
12593 you could start it after any data in the general purpose area.
12594 If your microcontroller has additional indirectly addressable internal
12599 ) you can place the stack on it.
12600 You may also need to use -
12604 \begin_layout Standard
12614 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12618 to set the start address of the external RAM (
12626 \begin_layout Standard
12636 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12640 to specify its size.
12641 Same goes for the code memory, using -
12645 \begin_layout Standard
12655 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12663 \begin_layout Standard
12673 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12678 If in doubt, don't specify any options and see if the resulting memory
12679 layout is appropriate, then you can adjust it.
12682 \begin_layout Standard
12683 The linker generates two files with memory allocation information.
12684 The first, with extension .map
12685 \begin_inset LatexCommand \index{<file>.map}
12689 shows all the variables and segments.
12690 The second with extension .mem
12691 \begin_inset LatexCommand \index{<file>.mem}
12695 shows the final memory layout.
12696 The linker will complain either if memory segments overlap, there is not
12697 enough memory, or there is not enough space for stack.
12698 If you get any linking warnings and/or errors related to stack or segments
12699 allocation, take a look at either the .map or .mem files to find out what
12701 The .mem file may even suggest a solution to the problem.
12702 \begin_inset VSpace bigskip
12708 \begin_layout Subsection
12709 Z80/Z180 Storage Class
12710 \begin_inset LatexCommand \index{Z80!Storage class}
12714 Language Extensions
12717 \begin_layout Subsubsection
12719 \begin_inset LatexCommand \index{sfr}
12724 \begin_inset LatexCommand \index{\_\_sfr}
12728 (in/out to 8-bit addresses)
12731 \begin_layout Standard
12733 \begin_inset LatexCommand \index{Z80}
12737 family has separate address spaces for memory and
12747 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12752 \begin_inset LatexCommand \index{Z80!I/O memory}
12757 \begin_inset LatexCommand \index{Z180!I/O memory}
12761 is accessed with special instructions, e.g.:
12764 \begin_layout Verse
12767 sfr at 0x78 IoPort;\InsetSpace ~
12769 /* define a var in I/O space at 78h called IoPort */
12773 \begin_layout Standard
12774 Writing 0x01 to this variable generates the assembly code:
12777 \begin_layout Verse
12797 \begin_layout Subsubsection
12799 \begin_inset LatexCommand \index{sfr}
12804 \begin_inset LatexCommand \index{\_\_sfr}
12808 (in/out to 16-bit addresses)
12811 \begin_layout Standard
12816 is used to support 16 bit addresses in I/O memory e.g.:
12819 \begin_layout Verse
12823 \begin_inset LatexCommand \index{at}
12828 \begin_inset LatexCommand \index{\_\_at}
12835 \begin_layout Standard
12836 Writing 0x01 to this variable generates the assembly code:
12839 \begin_layout Verse
12842 01 23 01\InsetSpace ~
12864 \begin_layout Subsubsection
12866 \begin_inset LatexCommand \index{sfr}
12871 \begin_inset LatexCommand \index{\_\_sfr}
12875 (in0/out0 to 8 bit addresses on Z180
12876 \begin_inset LatexCommand \index{Z180}
12881 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12888 \begin_layout Standard
12889 The compiler option -
12893 \begin_layout Standard
12903 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
12907 =180 (80) and a compiler #pragma\InsetSpace ~
12909 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
12913 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12923 If you include the file z180.h this will be set automatically.
12924 \begin_inset VSpace bigskip
12930 \begin_layout Subsection
12932 \begin_inset LatexCommand \index{HC08!Storage class}
12936 Language Extensions
12939 \begin_layout Subsubsection
12941 \begin_inset LatexCommand \index{data (hc08 storage class)}
12946 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
12953 \begin_layout Standard
12954 The data storage class declares a variable that resides in the first 256
12955 bytes of memory (the direct page).
12957 \begin_inset LatexCommand \index{HC08}
12961 is most efficient at accessing variables (especially pointers) stored here.
12964 \begin_layout Subsubsection
12966 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
12971 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
12978 \begin_layout Standard
12979 The xdata storage class declares a variable that can reside anywhere in
12981 This is the default if no storage class is specified.
12983 \begin_inset VSpace bigskip
12989 \begin_layout Section
12990 Absolute Addressing
12991 \begin_inset LatexCommand \index{Absolute addressing}
12998 \begin_layout Standard
12999 Data items can be assigned an absolute address with the
13002 \begin_inset LatexCommand \index{at}
13007 \begin_inset LatexCommand \index{\_\_at}
13013 keyword, in addition to a storage class, e.g.:
13016 \begin_layout Verse
13020 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13025 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
13030 \begin_inset LatexCommand \index{at}
13035 \begin_inset LatexCommand \index{\_\_at}
13039 0x7ffe unsigned int chksum;
13042 \begin_layout Standard
13043 or, better conforming to ISO/IEC 9899 C:
13046 \begin_layout Verse
13049 __xdata __at (0x7ffe) unsigned int chksum;
13052 \begin_layout Standard
13053 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
13054 of the external ram.
13059 reserve any space for variables declared in this way
13060 \begin_inset Marginal
13063 \begin_layout Standard
13072 (they are implemented with an equate in the assembler).
13073 Thus it is left to the programmer to make sure there are no overlaps with
13074 other variables that are declared without the absolute address.
13075 The assembler listing file (.lst
13076 \begin_inset LatexCommand \index{<file>.lst}
13080 ) and the linker output files (.rst
13081 \begin_inset LatexCommand \index{<file>.rst}
13086 \begin_inset LatexCommand \index{<file>.map}
13090 ) are good places to look for such overlaps.
13093 \begin_layout Standard
13094 If however you provide an initializer
13095 \begin_inset LatexCommand \index{Variable initialization}
13099 actual memory allocation will take place and overlaps will be detected
13104 \begin_layout Verse
13107 __code __at (0x7ff0) char Id[5] =
13108 \begin_inset Quotes sld
13112 \begin_inset Quotes srd
13118 \begin_layout Standard
13119 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
13123 \begin_layout Standard
13124 In case of memory mapped I/O devices the keyword
13128 has to be used to tell the compiler that accesses might not be removed:
13131 \begin_layout Verse
13135 \begin_inset LatexCommand \index{volatile}
13140 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13145 \begin_inset LatexCommand \index{at}
13149 (0x8000) unsigned char PORTA_8255;
13152 \begin_layout Standard
13153 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
13158 \begin_inset LatexCommand \index{Aligned array}
13165 starts at a block (256 byte) boundary
13166 \begin_inset LatexCommand \index{block boundary}
13171 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13177 Absolute addresses can be specified for variables in all
13178 storage classes, e.g.:
13181 \begin_layout Verse
13185 \begin_inset LatexCommand \index{bit}
13190 \begin_inset LatexCommand \index{at}
13197 \begin_layout Standard
13198 The above example will allocate the variable at offset 0x02 in the bit-addressab
13200 There is no real advantage to assigning absolute addresses to variables
13201 in this manner, unless you want strict control over all the variables allocated.
13202 One possible use would be to write hardware portable code.
13203 For example, if you have a routine that uses one or more of the microcontroller
13204 I/O pins, and such pins are different for two different hardwares, you
13205 can declare the I/O pins in your routine using:
13208 \begin_layout Verse
13212 \begin_inset LatexCommand \index{volatile}
13216 __bit MOSI;\InsetSpace ~
13220 /* master out, slave in */
13222 extern volatile __bit MISO;\InsetSpace ~
13229 extern volatile __bit MCLK;\InsetSpace ~
13238 Output of a byte on a 3-wire serial bus.
13243 If needed adapt polarity of clock,
13244 polarity of data and bit order
13249 unsigned char spi_io(unsigned char out_byte)
13274 MOSI = out_byte & 0x80;
13305 /* _asm nop _endasm; */\InsetSpace ~
13313 /* for slow peripherals */
13365 \begin_layout Standard
13366 Then, someplace in the code for the first hardware you would use
13369 \begin_layout Verse
13373 \begin_inset LatexCommand \index{at}
13378 \begin_inset LatexCommand \index{\_\_at}
13382 (0x80) MOSI;\InsetSpace ~
13386 /* I/O port 0, bit 0 */
13388 __bit __at (0x81) MISO;\InsetSpace ~
13395 __bit __at (0x82) MCLK;\InsetSpace ~
13399 /* I/O port 0, bit 2 */
13402 \begin_layout Standard
13403 Similarly, for the second hardware you would use
13406 \begin_layout Verse
13409 __bit __at (0x83) MOSI;\InsetSpace ~
13413 /* I/O port 0, bit 3 */
13415 __bit __at (0x91) MISO;\InsetSpace ~
13420 I/O port 1, bit 1 */
13423 \begin_inset LatexCommand \index{bit}
13427 __at (0x92) MCLK;\InsetSpace ~
13431 /* I/O port 1, bit 2 */
13434 \begin_layout Standard
13435 and you can use the same hardware dependent routine without changes, as
13436 for example in a library.
13437 This is somehow similar to sbit, but only one absolute address has to be
13438 specified in the whole project.
13439 \begin_inset VSpace bigskip
13445 \begin_layout Section
13447 \begin_inset LatexCommand \index{Parameters}
13452 \begin_inset LatexCommand \index{function parameter}
13457 \begin_inset LatexCommand \index{local variables}
13462 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13469 \begin_layout Standard
13470 Automatic (local) variables and parameters to functions can either be placed
13471 on the stack or in data-space.
13472 The default action of the compiler is to place these variables in the internal
13473 RAM (for small model) or external RAM (for medium or large model).
13474 This in fact makes them similar to
13477 \begin_inset LatexCommand \index{static}
13483 so by default functions are non-reentrant
13484 \begin_inset LatexCommand \index{reentrant}
13493 They can be placed on the stack
13494 \begin_inset LatexCommand \index{stack}
13504 \begin_layout Standard
13514 \begin_inset LatexCommand \index{-\/-stack-auto}
13522 #pragma\InsetSpace ~
13526 \begin_inset LatexCommand \index{\#pragma stackauto}
13533 \begin_inset LatexCommand \index{reentrant}
13539 keyword in the function declaration, e.g.:
13542 \begin_layout Verse
13545 unsigned char foo(char i) __reentrant
13559 \begin_layout Standard
13560 Since stack space on 8051 is limited, the
13570 \begin_layout Standard
13581 option should be used sparingly.
13582 Note that the reentrant keyword just means that the parameters & local
13583 variables will be allocated to the stack, it
13587 mean that the function is register bank
13588 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13597 \begin_inset LatexCommand \index{local variables}
13601 can be assigned storage classes and absolute
13602 \begin_inset LatexCommand \index{Absolute addressing}
13609 \begin_layout Verse
13612 unsigned char foo()
13620 __xdata unsigned char i;
13633 \begin_inset LatexCommand \index{at}
13637 (0x31) unsigned char j;
13649 \begin_layout Standard
13650 In the above example the variable
13654 will be allocated in the external ram,
13658 in bit addressable space and
13669 \begin_layout Standard
13680 or when a function is declared as
13684 this should only be done for static variables.
13687 \begin_layout Standard
13689 \begin_inset LatexCommand \index{function parameter}
13693 however are not allowed any storage class
13694 \begin_inset LatexCommand \index{Storage class}
13698 , (storage classes for parameters will be ignored), their allocation is
13699 governed by the memory model in use, and the reentrancy options.
13702 \begin_layout Standard
13703 It is however allowed to use bit parameters in reentrant functions and also
13704 non-static local bit variables are supported.
13705 Efficient use is limited to 8 semi-bitregisters in bit space.
13706 They are pushed and popped to stack
13707 \begin_inset LatexCommand \index{stack}
13711 as a single byte just like the normal registers.
13714 \begin_layout Section
13716 \begin_inset LatexCommand \label{sub:Overlaying}
13721 \begin_inset LatexCommand \index{Overlaying}
13728 \begin_layout Standard
13730 \begin_inset LatexCommand \index{reentrant}
13734 functions SDCC will try to reduce internal ram space usage by overlaying
13735 parameters and local variables of a function (if possible).
13736 Parameters and local variables
13737 \begin_inset LatexCommand \index{local variables}
13741 of a function will be allocated to an overlayable segment if the function
13744 no other function calls and the function is non-reentrant and the memory
13746 \begin_inset LatexCommand \index{Memory model}
13753 If an explicit storage class
13754 \begin_inset LatexCommand \index{Storage class}
13758 is specified for a local variable, it will NOT be overlayed.
13761 \begin_layout Standard
13762 Note that the compiler (not the linkage editor) makes the decision for overlayin
13764 Functions that are called from an interrupt service routine
13765 \begin_inset Marginal
13768 \begin_layout Standard
13776 should be preceded by a #pragma\InsetSpace ~
13778 \begin_inset LatexCommand \index{\#pragma nooverlay}
13782 if they are not reentrant.
13785 \begin_layout Standard
13786 Also note that the compiler does not do any processing of inline assembler
13787 code, so the compiler might incorrectly assign local variables and parameters
13788 of a function into the overlay segment if the inline assembler code calls
13789 other c-functions that might use the overlay.
13790 In that case the #pragma\InsetSpace ~
13791 nooverlay should be used.
13794 \begin_layout Standard
13795 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13797 \begin_inset LatexCommand \index{Multiplication}
13802 \begin_inset LatexCommand \index{Division}
13806 will NOT be overlayed since these are implemented using external functions,
13810 \begin_layout Verse
13816 \begin_inset LatexCommand \index{\#pragma nooverlay}
13822 void set_error(unsigned char errcd)
13839 some_isr () __interrupt
13840 \begin_inset LatexCommand \index{interrupt}
13870 \begin_layout Standard
13871 In the above example the parameter
13879 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13881 not present, this could cause unpredictable runtime behavior when called
13882 from an interrupt service routine.
13883 The #pragma\InsetSpace ~
13884 nooverlay ensures that the parameters and local variables for
13885 the function are NOT overlayed.
13886 \begin_inset VSpace bigskip
13892 \begin_layout Section
13893 Interrupt Service Routines
13894 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13901 \begin_layout Subsection
13902 General Information
13905 \begin_layout Standard
13918 outines to be coded in C, with some extended keywords.
13921 \begin_layout Verse
13924 void timer_isr (void) __interrupt (1) __using (1)
13938 \begin_layout Standard
13939 The optional number following the
13942 \begin_inset LatexCommand \index{interrupt}
13947 \begin_inset LatexCommand \index{\_\_interrupt}
13953 keyword is the interrupt number this routine will service.
13954 When present, the compiler will insert a call to this routine in the interrupt
13956 \begin_inset LatexCommand \index{interrupt vector table}
13960 for the interrupt number specified.
13961 If you have multiple source files in your project, interrupt service routines
13962 can be present in any of them, but a prototype of the isr MUST be present
13963 or included in the file that contains the function
13968 The optional (8051 specific) keyword
13971 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13976 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13982 can be used to tell the compiler to use the specified register bank when
13983 generating code for this function.
13986 Interrupt service routines open the door for some very interesting bugs:
13989 \begin_layout Subsubsection
13990 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
13994 Common interrupt pitfall: variable not declared
13999 \begin_layout Standard
14000 If an interrupt service routine changes variables which are accessed by
14001 other functions these variables have to be declared
14006 \begin_inset LatexCommand \index{volatile}
14012 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
14019 \begin_layout Subsubsection
14020 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
14024 Common interrupt pitfall:
14029 \begin_layout Standard
14030 If the access to these variables is not
14033 \begin_inset LatexCommand \index{atomic}
14040 the processor needs more than one instruction for the access and could
14041 be interrupted while accessing the variable) the interrupt must be disabled
14042 during the access to avoid inconsistent data.
14045 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
14046 and should be protected by disabling interrupts.
14047 You're not automatically on the safe side if you use 8 bit variables though.
14048 We need an example here: f.e.
14049 on the 8051 the harmless looking
14050 \begin_inset Quotes srd
14060 \begin_inset Quotes sld
14069 \begin_inset Quotes srd
14079 \begin_inset Quotes sld
14082 from within an interrupt routine might get lost if the interrupt occurs
14085 \begin_inset Quotes sld
14090 counter\InsetSpace ~
14095 \begin_inset Quotes srd
14098 is not atomic on the 8051 even if
14102 is located in data memory.
14104 Bugs like these are hard to reproduce and can
14105 cause a lot of trouble.
14109 \begin_layout Subsubsection
14110 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
14114 Common interrupt pitfall:
14119 \begin_layout Standard
14120 The return address and the registers used in the interrupt service routine
14121 are saved on the stack
14122 \begin_inset LatexCommand \index{stack}
14126 so there must be sufficient stack space.
14127 If there isn't variables or registers (or even the return address itself)
14134 \begin_inset LatexCommand \index{stack overflow}
14138 is most likely to happen if the interrupt occurs during the
14139 \begin_inset Quotes sld
14143 \begin_inset Quotes srd
14146 subroutine when the stack is already in use for f.e.
14147 many return addresses.
14150 \begin_layout Subsubsection
14151 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
14155 Common interrupt pitfall:
14157 use of non-reentrant functions
14160 \begin_layout Standard
14161 A special note here, int (16 bit) and long (32 bit) integer division
14162 \begin_inset LatexCommand \index{Division}
14167 \begin_inset LatexCommand \index{Multiplication}
14172 \begin_inset LatexCommand \index{Modulus}
14177 \begin_inset LatexCommand \index{Floating point support}
14181 operations are implemented using external support routines.
14182 If an interrupt service routine needs to do any of these operations then
14183 the support routines (as mentioned in a following section) will have to
14184 be recompiled using the
14190 \begin_layout Standard
14200 \begin_inset LatexCommand \index{-\/-stack-auto}
14206 option and the source file will need to be compiled using the
14212 \begin_layout Standard
14224 \begin_inset LatexCommand \index{-\/-int-long-reent}
14231 Note, the type promotion
14232 \begin_inset LatexCommand \index{type promotion}
14236 required by ANSI C can cause 16 bit routines to be used
14237 \begin_inset Marginal
14240 \begin_layout Standard
14249 without the programmer being aware of it.
14253 (unsigned char)(tail-1)
14255 within the if clause in section
14256 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
14263 \begin_layout Standard
14264 Calling other functions from an interrupt service routine is not recommended,
14265 avoid it if possible.
14266 Note that when some function is called from an interrupt service routine
14267 it should be preceded by a #pragma\InsetSpace ~
14269 \begin_inset LatexCommand \index{\#pragma nooverlay}
14273 if it is not reentrant.
14274 Furthermore nonreentrant functions should not be called from the main program
14275 while the interrupt service routine might be active.
14276 They also must not be called from low priority interrupt service routines
14277 while a high priority interrupt service routine might be active.
14278 You could use semaphores or make the function
14282 if all parameters are passed in registers.
14285 \begin_inset LatexCommand \ref{sub:Overlaying}
14290 about Overlaying and section
14291 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14296 about Functions using private register banks.
14297 \begin_inset VSpace bigskip
14303 \begin_layout Subsection
14304 MCS51/DS390 Interrupt Service Routines
14307 \begin_layout Standard
14309 \begin_inset LatexCommand \index{interrupt}
14313 numbers and the corresponding address & descriptions for the Standard 8051/8052
14315 SDCC will automatically adjust the
14316 \begin_inset LatexCommand \index{interrupt vector table}
14320 to the maximum interrupt number specified.
14325 \begin_layout Standard
14327 \begin_inset Tabular
14328 <lyxtabular version="3" rows="9" columns="3">
14330 <column alignment="center" valignment="top" leftline="true" width="0in">
14331 <column alignment="left" valignment="top" leftline="true" width="0in">
14332 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14333 <row topline="true" bottomline="true">
14334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14337 \begin_layout Standard
14343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14346 \begin_layout Standard
14352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14355 \begin_layout Standard
14362 <row topline="true">
14363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14366 \begin_layout Standard
14372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14375 \begin_layout Standard
14381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14384 \begin_layout Standard
14391 <row topline="true">
14392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14395 \begin_layout Standard
14401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14404 \begin_layout Standard
14410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14413 \begin_layout Standard
14420 <row topline="true">
14421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14424 \begin_layout Standard
14430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14433 \begin_layout Standard
14439 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14442 \begin_layout Standard
14449 <row topline="true">
14450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14453 \begin_layout Standard
14459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14462 \begin_layout Standard
14468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14471 \begin_layout Standard
14478 <row topline="true">
14479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14482 \begin_layout Standard
14488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14491 \begin_layout Standard
14497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14500 \begin_layout Standard
14507 <row topline="true">
14508 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14511 \begin_layout Standard
14517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14520 \begin_layout Standard
14526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14529 \begin_layout Standard
14536 <row topline="true">
14537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14540 \begin_layout Standard
14546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14549 \begin_layout Standard
14555 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14558 \begin_layout Standard
14565 <row topline="true" bottomline="true">
14566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14569 \begin_layout Standard
14575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14578 \begin_layout Standard
14584 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14587 \begin_layout Standard
14603 \begin_layout Standard
14604 If the interrupt service routine is defined without
14607 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14612 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14618 a register bank or with register bank 0 (
14622 0), the compiler will save the registers used by itself on the stack upon
14623 entry and restore them at exit, however if such an interrupt service routine
14624 calls another function then the entire register bank will be saved on the
14626 This scheme may be advantageous for small interrupt service routines which
14627 have low register usage.
14630 \begin_layout Standard
14631 If the interrupt service routine is defined to be using a specific register
14636 & psw are saved and restored, if such an interrupt service routine calls
14637 another function (using another register bank) then the entire register
14638 bank of the called function will be saved on the stack
14639 \begin_inset LatexCommand \index{stack}
14644 This scheme is recommended for larger interrupt service routines.
14645 \begin_inset VSpace bigskip
14651 \begin_layout Subsection
14653 \begin_inset LatexCommand \index{HC08}
14657 Interrupt Service Routines
14660 \begin_layout Standard
14661 Since the number of interrupts
14662 \begin_inset LatexCommand \index{HC08!interrupt}
14666 available is chip specific and the interrupt vector table always ends at
14667 the last byte of memory, the interrupt numbers corresponds to the interrupt
14668 vectors in reverse order of address.
14669 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14670 2 will use the interrupt vector at 0xfffa, and so on.
14671 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14672 this way; instead see section
14673 \begin_inset LatexCommand \ref{sub:Startup-Code}
14677 for details on customizing startup.
14678 \begin_inset VSpace bigskip
14684 \begin_layout Subsection
14685 Z80 Interrupt Service Routines
14688 \begin_layout Standard
14690 \begin_inset LatexCommand \index{Z80}
14694 uses several different methods for determining the correct interrupt
14695 \begin_inset LatexCommand \index{Z80!interrupt}
14699 vector depending on the hardware implementation.
14700 Therefore, SDCC ignores the optional interrupt number and does not attempt
14701 to generate an interrupt vector table.
14704 \begin_layout Standard
14705 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14706 instruction to return from the interrupt.
14707 To write an interrupt handler for the non-maskable interrupt, which needs
14708 a RETN instruction instead, add the
14715 \begin_layout Verse
14718 void nmi_isr (void) critical interrupt
14732 \begin_layout Standard
14733 However if you need to create a non-interruptable interrupt service routine
14734 you would also require the
14739 To distinguish between this and an nmi_isr you must provide an interrupt
14741 \begin_inset VSpace bigskip
14747 \begin_layout Section
14748 Enabling and Disabling Interrupts
14751 \begin_layout Subsection
14752 Critical Functions and Critical Statements
14755 \begin_layout Standard
14756 A special keyword may be associated with a block or a function declaring
14762 SDCC will generate code to disable all interrupts
14763 \begin_inset LatexCommand \index{interrupt}
14767 upon entry to a critical function and restore the interrupt enable to the
14768 previous state before returning.
14769 Nesting critical functions will need one additional byte on the stack
14770 \begin_inset LatexCommand \index{stack}
14777 \begin_layout Verse
14780 int foo () __critical
14781 \begin_inset LatexCommand \index{critical}
14786 \begin_inset LatexCommand \index{\_\_critical}
14811 \begin_layout Standard
14812 The critical attribute maybe used with other attributes like
14822 may also be used to disable interrupts more locally:
14825 \begin_layout Verse
14831 \begin_layout Standard
14832 More than one statement could have been included in the block.
14835 \begin_layout Subsection
14836 Enabling and Disabling Interrupts directly
14839 \begin_layout Standard
14841 \begin_inset LatexCommand \index{interrupt}
14845 can also be disabled and enabled directly (8051):
14848 \begin_layout Verse
14851 EA = 0;\InsetSpace ~
14877 \begin_layout Verse
14913 \begin_layout Verse
14916 EA = 1;\InsetSpace ~
14945 \begin_layout Verse
14984 \begin_layout Standard
14985 On other architectures which have seperate opcodes for enabling and disabling
14986 interrupts you might want to make use of defines with inline assembly
14987 \begin_inset LatexCommand \index{Assembler routines}
14992 \begin_inset LatexCommand \index{HC08!interrupt}
14999 \begin_layout Verse
15003 \begin_inset LatexCommand \index{\_asm}
15012 \begin_inset LatexCommand \index{\_endasm}
15019 \begin_layout Verse
15022 #define SEI _asm\InsetSpace ~
15029 \begin_layout Verse
15035 \begin_layout Standard
15036 Note: it is sometimes sufficient to disable only a specific interrupt source
15038 a timer or serial interrupt by manipulating an
15041 \begin_inset LatexCommand \index{interrupt mask}
15051 \begin_layout Standard
15052 Usually the time during which interrupts are disabled should be kept as
15054 This minimizes both
15059 \begin_inset LatexCommand \index{interrupt latency}
15063 (the time between the occurrence of the interrupt and the execution of
15064 the first code in the interrupt routine) and
15069 \begin_inset LatexCommand \index{interrupt jitter}
15073 (the difference between the shortest and the longest interrupt latency).
15074 These really are something different, f.e.
15075 a serial interrupt has to be served before its buffer overruns so it cares
15076 for the maximum interrupt latency, whereas it does not care about jitter.
15077 On a loudspeaker driven via a digital to analog converter which is fed
15078 by an interrupt a latency of a few milliseconds might be tolerable, whereas
15079 a much smaller jitter will be very audible.
15082 \begin_layout Standard
15083 You can reenable interrupts within an interrupt routine and on some architecture
15084 s you can make use of two (or more) levels of
15086 interrupt priorities
15089 \begin_inset LatexCommand \index{interrupt priority}
15094 On some architectures which don't support interrupt priorities these can
15095 be implemented by manipulating the interrupt mask and reenabling interrupts
15096 within the interrupt routine.
15097 Check there is sufficient space on the stack
15098 \begin_inset LatexCommand \index{stack}
15102 and don't add complexity unless you have to.
15106 \begin_layout Subsection
15108 \begin_inset LatexCommand \index{semaphore}
15112 locking (mcs51/ds390)
15115 \begin_layout Standard
15116 Some architectures (mcs51/ds390) have an atomic
15117 \begin_inset LatexCommand \index{atomic}
15130 These type of instructions are typically used in preemptive multitasking
15131 systems, where a routine f.e.
15132 claims the use of a data structure ('acquires a lock
15133 \begin_inset LatexCommand \index{lock}
15137 on it'), makes some modifications and then releases the lock when the data
15138 structure is consistent again.
15139 The instruction may also be used if interrupt and non-interrupt code have
15140 to compete for a resource.
15141 With the atomic bit test and clear instruction interrupts
15142 \begin_inset LatexCommand \index{interrupt}
15146 don't have to be disabled for the locking operation.
15150 \begin_layout Standard
15151 SDCC generates this instruction if the source follows this pattern:
15154 \begin_layout Verse
15158 \begin_inset LatexCommand \index{volatile}
15162 bit resource_is_free;
15166 if (resource_is_free)
15176 resource_is_free=0;
15189 resource_is_free=1;
15196 \begin_layout Standard
15197 Note, mcs51 and ds390 support only an atomic
15198 \begin_inset LatexCommand \index{atomic}
15206 instruction (as opposed to atomic bit test and
15211 \begin_layout Section
15212 Functions using private register banks
15213 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
15220 \begin_layout Standard
15221 Some architectures have support for quickly changing register sets.
15222 SDCC supports this feature with the
15225 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
15230 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
15236 attribute (which tells the compiler to use a register bank
15237 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
15241 other than the default bank zero).
15242 It should only be applied to
15245 \begin_inset LatexCommand \index{interrupt}
15251 functions (see footnote below).
15252 This will in most circumstances make the generated ISR code more efficient
15253 since it will not have to save registers on the stack.
15256 \begin_layout Standard
15261 attribute will have no effect on the generated code for a
15265 function (but may occasionally be useful anyway
15269 \begin_layout Standard
15270 possible exception: if a function is called ONLY from 'interrupt' functions
15271 using a particular bank, it can be declared with the same 'using' attribute
15272 as the calling 'interrupt' functions.
15273 For instance, if you have several ISRs using bank one, and all of them
15274 call memcpy(), it might make sense to create a specialized version of memcpy()
15275 'using 1', since this would prevent the ISR from having to save bank zero
15276 to the stack on entry and switch to bank zero before calling the function
15285 (pending: Note, nowadays the
15289 attribute has an effect on
15293 the generated code for a
15304 \begin_layout Standard
15309 function using a non-zero bank will assume that it can trash that register
15310 bank, and will not save it.
15311 Since high-priority interrupts
15312 \begin_inset LatexCommand \index{interrupts}
15317 \begin_inset LatexCommand \index{interrupt priority}
15321 can interrupt low-priority ones on the 8051 and friends, this means that
15322 if a high-priority ISR
15326 a particular bank occurs while processing a low-priority ISR
15330 the same bank, terrible and bad things can happen.
15331 To prevent this, no single register bank should be
15335 by both a high priority and a low priority ISR.
15336 This is probably most easily done by having all high priority ISRs use
15337 one bank and all low priority ISRs use another.
15338 If you have an ISR which can change priority at runtime, you're on your
15339 own: I suggest using the default bank zero and taking the small performance
15343 \begin_layout Standard
15344 It is most efficient if your ISR calls no other functions.
15345 If your ISR must call other functions, it is most efficient if those functions
15346 use the same bank as the ISR (see note 1 below); the next best is if the
15347 called functions use bank zero.
15348 It is very inefficient to call a function using a different, non-zero bank
15351 \begin_inset VSpace bigskip
15357 \begin_layout Section
15359 \begin_inset LatexCommand \label{sub:Startup-Code}
15364 \begin_inset LatexCommand \index{Startup code}
15371 \begin_layout Subsection
15372 MCS51/DS390 Startup Code
15375 \begin_layout Standard
15376 The compiler triggers the linker to link certain initialization modules
15377 from the runtime library
15378 \begin_inset LatexCommand \index{Runtime library}
15382 called crt<something>.
15383 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15384 GSINIT5) is not linked unless the -
15390 \begin_layout Standard
15401 -xstack option is used.
15402 These modules are highly entangled by the use of special segments/areas,
15403 but a common layout is shown below:
15406 \begin_layout Verse
15414 \begin_layout Verse
15438 ljmp __sdcc_gsinit_startup
15441 \begin_layout Verse
15449 \begin_layout Verse
15461 .area GSINIT0 (CODE)
15463 __sdcc_gsinit_startup::
15473 mov sp,#__start__stack - 1
15476 \begin_layout Verse
15484 \begin_layout Verse
15496 .area GSINIT1 (CODE)
15498 __sdcc_init_xstack::
15500 ; Need to initialize in GSINIT1 in
15501 case the user's __sdcc_external_startup uses the xstack.
15511 mov __XPAGE,#(__start__x
15522 mov _spx,#__start__xstack
15525 \begin_layout Verse
15533 \begin_layout Verse
15545 .area GSINIT2 (CODE)
15555 lcall __sdcc_external_startup
15575 jz __sdcc_init_data
15586 __sdcc_program_startup
15591 \begin_layout Verse
15599 \begin_layout Verse
15611 .area GSINIT3 (CODE)
15664 mov r2,#((l_XINIT+255) >> 8)
15695 __XPAGE,#(s_XISEG >> 8)
15697 00001$:\InsetSpace ~
15761 00002$:\InsetSpace ~
15788 \begin_layout Verse
15796 \begin_layout Verse
15808 .area GSINIT4 (CODE)
15810 __mcs51_genRAMCLEAR::
15832 00004$:\InsetSpace ~
15846 ; _mcs51_genRAMCLEAR() end
15849 \begin_layout Verse
15857 \begin_layout Verse
15869 .area GSINIT4 (CODE)
15871 __mcs51_genXRAMCLEAR::
15932 mov __XPAGE,#(s_PSEG >> 8)
15944 00005$:\InsetSpace ~
16019 mov r1,#((l_XSEG + 255) >> 8)
16041 00007$:\InsetSpace ~
16078 \begin_layout Verse
16086 \begin_layout Verse
16098 .area GSINIT5 (CODE)
16100 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
16103 ; and __mcs51_genRAMCLEAR modifies _spx.
16113 mov __XPAGE,#(__start__x
16124 mov _spx,#__start__xstack
16127 \begin_layout Verse
16132 (application modules)
16135 \begin_layout Verse
16147 .area GSINIT (CODE)
16150 \begin_layout Verse
16158 \begin_layout Verse
16170 .area GSFINAL (CODE)
16180 ljmp __sdcc_program_startup
16182 ;---------------------------------
16183 -----------------------
16187 ;--------------------------------------------------
16210 __sdcc_program_startup:
16223 return from main will lock up
16236 \begin_layout Standard
16237 One of these modules (crtstart.asm) contains a call to the C routine
16239 _sdcc_external_startup()
16240 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
16249 at the start of the CODE area.
16250 This routine is also in the runtime library
16251 \begin_inset LatexCommand \index{Runtime library}
16255 and returns 0 by default.
16256 If this routine returns a non-zero value, the static & global variable
16257 initialization will be skipped and the function main will be invoked.
16258 Otherwise static & global variables will be initialized before the function
16262 _sdcc_external_startup()
16264 routine to your program to override the default if you need to setup hardware
16265 or perform some other critical operation prior to static & global variable
16267 \begin_inset LatexCommand \index{Variable initialization}
16272 On some mcs51 variants xdata
16273 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
16277 memory has to be explicitly enabled before it can be accessed or if the
16279 \begin_inset LatexCommand \index{watchdog}
16283 needs to be disabled, this is the place to do it.
16284 The startup code clears all internal data memory, 256 bytes by default,
16285 but from 0 to n-1 if
16291 \begin_layout Standard
16301 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16308 (recommended for Chipcon CC1010).
16311 \begin_layout Standard
16312 See also the compiler options
16318 \begin_layout Standard
16334 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16344 \begin_layout Standard
16356 \begin_inset LatexCommand \index{-\/-main-return}
16361 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16365 about MCS51-variants.
16370 \begin_layout Standard
16371 While these initialization modules are meant as generic startup code there
16372 might be the need for customization.
16373 Let's assume the return value of
16375 _sdcc_external_startup()
16381 should not be checked (or
16383 _sdcc_external_startup()
16385 should not be called at all).
16386 The recommended way would be to copy
16392 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm}
16396 ) into the source directory, adapt it there, then assemble it with
16402 \begin_layout Standard
16403 \begin_inset Quotes sld
16407 \begin_inset Quotes srd
16410 are the assembler options used in
16411 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup }
16422 and when linking your project explicitely specify
16427 As a bonus a listing of the relocated object file
16434 \begin_layout Standard
16435 \begin_inset VSpace bigskip
16441 \begin_layout Subsection
16445 \begin_layout Standard
16447 \begin_inset LatexCommand \index{HC08}
16451 startup code follows the same scheme as the MCS51 startup code.
16452 \begin_inset VSpace bigskip
16458 \begin_layout Subsection
16462 \begin_layout Standard
16464 \begin_inset LatexCommand \index{Z80}
16468 the startup code is inserted by linking with crt0.o which is generated from
16469 sdcc/device/lib/z80/crt0.s.
16470 If you need a different startup code you can use the compiler option
16479 \begin_layout Standard
16494 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16498 and provide your own crt0.o.
16500 \begin_inset VSpace bigskip
16506 \begin_layout Section
16507 Inline Assembler Code
16508 \begin_inset LatexCommand \index{Assembler routines}
16515 \begin_layout Subsection
16516 A Step by Step Introduction
16517 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16524 \begin_layout Standard
16525 Starting from a small snippet of c-code this example shows for the MCS51
16526 how to use inline assembly, access variables, a function parameter and
16527 an array in xdata memory.
16528 The example uses an MCS51 here but is easily adapted for other architectures.
16529 This is a buffer routine which should be optimized:
16532 \begin_layout Verse
16536 unsigned char __far
16537 \begin_inset LatexCommand \index{far (storage class)}
16542 \begin_inset LatexCommand \index{\_\_far (storage class)}
16547 \begin_inset LatexCommand \index{at}
16552 \begin_inset LatexCommand \index{\_\_at}
16556 (0x7f00) buf[0x100];
16557 \begin_inset LatexCommand \index{Aligned array}
16563 unsigned char head, tail;\InsetSpace ~
16581 \begin_inset LatexCommand \index{interrupt}
16633 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16645 void to_buffer( unsigned char c )
16653 if( head != (unsigned char)(tail-1)
16660 \begin_inset LatexCommand \index{promotion to signed int}
16665 \begin_inset LatexCommand \index{type promotion}
16670 \begin_inset Marginal
16673 \begin_layout Standard
16692 buf[ head++ ] = c;\InsetSpace ~
16708 /* access to a 256 byte aligned array */
16713 \begin_layout Standard
16714 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16715 then a corresponding buffer.asm file is generated.
16716 We define a new function
16720 in file buffer.c in which we cut and paste the generated code, removing
16721 unwanted comments and some ':'.
16723 \begin_inset Quotes sld
16731 \begin_inset Quotes srd
16735 \begin_inset Quotes sld
16743 \begin_inset Quotes srd
16750 \begin_layout Standard
16751 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16752 and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16754 The latter is also used in the library functions.
16759 to the beginning and the end of the function body:
16762 \begin_layout Verse
16766 /* With a cut and paste from the .asm file, we have something to start with.
16772 function is not yet OK! (registers aren't saved) */
16774 void to_buffer_asm(
16784 \begin_inset LatexCommand \index{\_asm}
16789 \begin_inset LatexCommand \index{\_\_asm}
16803 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16809 \begin_inset LatexCommand \index{promotion to signed int}
16814 \begin_inset LatexCommand \index{type promotion}
16867 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
16868 \begin_inset LatexCommand \index{Aligned array}
16934 \begin_inset LatexCommand \index{\_endasm}
16939 \begin_inset LatexCommand \index{\_\_endasm}
16948 \begin_layout Standard
16949 The new file buffer.c should compile with only one warning about the unreferenced
16950 function argument 'c'.
16951 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
16952 (1) and finally have:
16955 \begin_layout Verse
16959 unsigned char __far __at(0x7f00) buf[0x100];
16961 unsigned char head, tail;
16972 void to_buffer( unsigned char c )
16981 head != (unsigned char)(tail-1) )
17010 c; // to avoid warning: unreferenced function argument
17017 \begin_inset LatexCommand \index{\_asm}
17022 \begin_inset LatexCommand \index{\_\_asm}
17036 ; save used registers here.
17047 ; If we were still using r2,r3 we would have to push them here.
17050 ; if( head != (unsigned char)(tail-1) )
17094 could do an ANL a,#0x0f here to use a smaller buffer (see below)
17130 a,dpl \InsetSpace ~
17137 ; dpl holds lower byte of function argument
17149 dpl,_head \InsetSpace ~
17152 ; buf is 0x100 byte aligned so head can be used directly
17195 ; we could do an ANL _head,#0x0f here to use a
17196 smaller buffer (see above)
17208 ; restore used registers here
17215 \begin_inset LatexCommand \index{\_endasm}
17220 \begin_inset LatexCommand \index{\_\_endasm}
17231 \begin_layout Standard
17232 The inline assembler code can contain any valid code understood by the assembler
17233 , this includes any assembler directives and comment lines.
17234 The assembler does not like some characters like ':' or ''' in comments.
17235 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
17236 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
17241 \begin_inset LatexCommand \index{Assembler documentation}
17246 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
17254 \begin_layout Standard
17255 The compiler does not do any validation of the code within the
17258 \begin_inset LatexCommand \index{\_asm}
17263 \begin_inset LatexCommand \index{\_\_asm}
17271 \begin_inset LatexCommand \index{\_endasm}
17276 \begin_inset LatexCommand \index{\_\_endasm}
17285 Specifically it will not know which registers are used and thus register
17287 \begin_inset LatexCommand \index{push/pop}
17291 has to be done manually.
17295 \begin_layout Standard
17296 It is recommended that each assembly instruction (including labels) be placed
17297 in a separate line (as the example shows).
17302 \begin_layout Standard
17314 \begin_inset LatexCommand \index{-\/-peep-asm}
17320 command line option is used, the inline assembler code will be passed through
17321 the peephole optimizer
17322 \begin_inset LatexCommand \index{Peephole optimizer}
17327 There are only a few (if any) cases where this option makes sense, it might
17328 cause some unexpected changes in the inline assembler code.
17329 Please go through the peephole optimizer rules defined in file
17333 before using this option.
17336 \begin_layout Subsection
17338 \begin_inset LatexCommand \label{sub:Naked-Functions}
17343 \begin_inset LatexCommand \index{Naked functions}
17350 \begin_layout Standard
17351 A special keyword may be associated with a function declaring it as
17354 \begin_inset LatexCommand \index{\_naked}
17359 \begin_inset LatexCommand \index{\_\_naked}
17370 function modifier attribute prevents the compiler from generating prologue
17371 \begin_inset LatexCommand \index{function prologue}
17376 \begin_inset LatexCommand \index{function epilogue}
17380 code for that function.
17381 This means that the user is entirely responsible for such things as saving
17382 any registers that may need to be preserved, selecting the proper register
17383 bank, generating the
17387 instruction at the end, etc.
17388 Practically, this means that the contents of the function must be written
17389 in inline assembler.
17390 This is particularly useful for interrupt functions, which can have a large
17391 (and often unnecessary) prologue/epilogue.
17392 For example, compare the code generated by these two functions:
17395 \begin_layout Verse
17399 \begin_inset LatexCommand \index{volatile}
17403 data unsigned char counter;
17407 void simpleInterrupt(void) __interrupt
17408 \begin_inset LatexCommand \index{interrupt}
17413 \begin_inset LatexCommand \index{\_\_interrupt}
17431 void nakedInterrupt(void) __interrupt (2) __naked
17440 \begin_inset LatexCommand \index{\_asm}
17445 \begin_inset LatexCommand \index{\_\_asm}
17462 _counter ; does not change flags, no need to save psw
17475 include ret or reti in _naked function.
17482 \begin_inset LatexCommand \index{\_endasm}
17487 \begin_inset LatexCommand \index{\_\_endasm}
17496 \begin_layout Standard
17497 For an 8051 target, the generated simpleInterrupt looks like:
17500 \begin_layout Verse
17507 example, recent versions of SDCC generate
17513 code for simpleInterrupt() and nakedInterrupt()!
17654 \begin_layout Standard
17655 whereas nakedInterrupt looks like:
17658 \begin_layout Verse
17671 _counter ; does not change flags, no need to save psw
17690 MUST explicitly include ret or reti in _naked function
17693 \begin_layout Standard
17694 The related directive #pragma exclude
17695 \begin_inset LatexCommand \index{\#pragma exclude}
17699 allows a more fine grained control over pushing & popping
17700 \begin_inset LatexCommand \index{push/pop}
17707 \begin_layout Standard
17708 While there is nothing preventing you from writing C code inside a
17712 function, there are many ways to shoot yourself in the foot doing this,
17713 and it is recommended that you stick to inline assembler.
17716 \begin_layout Subsection
17717 Use of Labels within Inline Assembler
17720 \begin_layout Standard
17721 SDCC allows the use of in-line assembler with a few restrictions regarding
17723 All labels defined within inline assembler code have to be of the form
17728 where nnnnn is a number less than 100 (which implies a limit of utmost
17729 100 inline assembler labels
17740 \begin_layout Standard
17741 This is a slightly more stringent rule than absolutely necessary, but stays
17742 always on the safe side.
17743 Labels in the form of nnnnn$ are local labels in the assembler, locality
17744 of which is confined within two labels of the standard form.
17745 The compiler uses the same form for labels within a function (but starting
17746 from nnnnn=00100); and places always a standard label at the beginning
17747 of a function, thus limiting the locality of labels within the scope of
17749 So, if the inline assembler part would be embedded into C-code, an improperly
17750 placed non-local label in the assembler would break up the reference space
17751 for labels created by the compiler for the C-code, leading to an assembling
17755 \begin_layout Standard
17756 The numeric part of local labels does not need to have 5 digits (although
17757 this is the form of labels output by the compiler), any valid integer will
17759 Please refer to the assemblers documentation for further details.
17767 \begin_layout Verse
17771 \begin_inset LatexCommand \index{\_asm}
17776 \begin_inset LatexCommand \index{\_\_asm}
17806 \begin_inset LatexCommand \index{\_endasm}
17811 \begin_inset LatexCommand \index{\_\_endasm}
17818 \begin_layout Standard
17819 Inline assembler code cannot reference any C-labels, however it can reference
17821 \begin_inset LatexCommand \index{Labels}
17825 defined by the inline assembler, e.g.:
17828 \begin_layout Verse
17851 ; some assembler code
17872 /* some more c code */
17874 clabel:\InsetSpace ~
17876 /* inline assembler cannot reference this
17881 \begin_layout Standard
17886 is translated by the compiler into a local label, so the locality of labels
17887 within the function is not broken.
17904 0003$: ;label (can be referenced by inline assembler only)
17911 \begin_inset LatexCommand \index{\_endasm}
17916 \begin_inset LatexCommand \index{\_\_endasm}
17926 /* some more c code */
17931 \begin_layout Standard
17932 In other words inline assembly code can access labels defined in inline
17933 assembly within the scope of the function.
17934 The same goes the other way, i.e.
17935 labels defines in inline assembly can not be accessed by C statements.
17938 \begin_layout Section
17939 Interfacing with Assembler Code
17940 \begin_inset LatexCommand \index{Assembler routines}
17947 \begin_layout Subsection
17948 Global Registers used for Parameter Passing
17949 \begin_inset LatexCommand \index{Parameter passing}
17956 \begin_layout Standard
17957 The compiler always uses the global registers
17960 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17965 \begin_inset LatexCommand \index{DPTR}
17970 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
17979 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
17985 to pass the first (non-bit) parameter to a function, and also to pass the
17987 \begin_inset LatexCommand \index{return value}
17991 of function; according to the following scheme: one byte return value in
17996 , two byte value in
18005 three byte values (generic pointers) in
18017 , and four byte values in
18035 \begin_inset LatexCommand \index{generic pointer}
18039 contain type of accessed memory in
18060 \begin_inset Note Note
18063 \begin_layout Standard
18064 This might not be the case of certain memory models (medium???)
18072 \begin_layout Standard
18073 The second parameter onwards is either allocated on the stack (for reentrant
18078 \begin_layout Standard
18087 -stack-auto is used) or in data/xdata memory (depending on the memory model).
18090 \begin_layout Standard
18091 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
18092 space for reentrant functions or allocated directly in bit memory otherwise.
18095 \begin_layout Standard
18096 Functions (with two or more parameters or bit parameters) that are called
18097 through function pointers
18098 \begin_inset LatexCommand \index{function pointers}
18102 must therefor be reentrant so the compiler knows how to pass the parameters.
18105 \begin_layout Subsection
18109 \begin_layout Standard
18110 Unless the called function is declared as
18115 \begin_inset LatexCommand \index{naked}
18123 \begin_layout Standard
18133 \begin_inset LatexCommand \index{-\/-callee-saves}
18141 \begin_layout Standard
18150 -all-callee-saves command line option or the corresponding callee_saves
18151 pragma are used, the caller will save the registers (
18155 ) around the call, so the called function can destroy they content freely.
18158 \begin_layout Standard
18159 If the called function is not declared as
18163 , the caller will swap register banks around the call, if caller and callee
18164 use different register banks (having them defined by the
18172 \begin_layout Standard
18173 The called function can also use
18189 observing that they are used for parameter/return value passing.
18192 \begin_layout Subsection
18193 Assembler Routine (non-reentrant)
18196 \begin_layout Standard
18197 In the following example
18198 \begin_inset LatexCommand \index{reentrant}
18203 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
18207 the function c_func calls an assembler routine asm_func, which takes two
18209 \begin_inset LatexCommand \index{function parameter}
18216 \begin_layout Verse
18219 extern int asm_func(unsigned char, unsigned char);
18223 int c_func (unsigned char
18224 i, unsigned char j)
18232 return asm_func(i,j);
18246 return c_func(10,9);
18251 \begin_layout Standard
18252 The corresponding assembler function is:
18255 \begin_layout Verse
18258 .globl _asm_func_PARM_2
18360 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18377 \begin_layout Standard
18378 The parameter naming convention is _<function_name>_PARM_<n>, where n is
18379 the parameter number starting from 1, and counting from the left.
18380 The first parameter is passed in
18396 according to the description above.
18397 The variable name for the second parameter will be _<function_name>_PARM_2.
18402 ble the assembler routine with the following command:
18409 asx8051 -losg asmfunc.asm
18416 Then compile and link the assembler routine to the C source file with the
18424 sdcc cfunc.c asmfunc.rel
18427 \begin_layout Subsection
18428 Assembler Routine (reentrant)
18431 \begin_layout Standard
18433 \begin_inset LatexCommand \index{reentrant}
18438 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18442 the second parameter
18443 \begin_inset LatexCommand \index{function parameter}
18447 onwards will be passed on the stack, the parameters are pushed from right
18449 before the call the second leftmost parameter will be on the top of the
18450 stack (the leftmost parameter is passed in registers).
18451 Here is an example:
18454 \begin_layout Verse
18457 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18462 c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
18471 return asm_func(i,j,k);
18485 return c_func(10,9,8);
18490 \begin_layout Standard
18491 The corresponding (unoptimized) assembler routine is:
18494 \begin_layout Verse
18514 _bp,sp\InsetSpace ~
18520 ;stack contains: _bp, return
18521 address, second parameter, third parameter
18545 a,#0xfd\InsetSpace ~
18551 pointer to the second parameter
18575 a,#0xfc\InsetSpace ~
18581 to the rightmost parameter
18622 result (= sum of all three parameters)
18637 ;return value goes into dptr
18671 \begin_layout Standard
18672 The compiling and linking procedure remains the same, however note the extra
18673 entry & exit linkage required for the assembler code, _bp is the stack
18674 frame pointer and is used to compute the offset into the stack for parameters
18675 and local variables.
18676 \begin_inset VSpace bigskip
18682 \begin_layout Section
18684 \begin_inset LatexCommand \index{int (16 bit)}
18689 \begin_inset LatexCommand \index{long (32 bit)}
18696 \begin_layout Standard
18697 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18698 multiplication and modulus operations are implemented by support routines.
18699 These support routines are all developed in ANSI-C to facilitate porting
18700 to other MCUs, although some model specific assembler optimizations are
18702 The following files contain the described routines, all of them can be
18703 found in <installdir>/share/sdcc/lib.
18708 \begin_layout Standard
18710 \begin_inset Tabular
18711 <lyxtabular version="3" rows="11" columns="2">
18713 <column alignment="left" valignment="top" leftline="true" width="0">
18714 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18715 <row topline="true" bottomline="true">
18716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18719 \begin_layout Standard
18727 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18730 \begin_layout Standard
18739 <row topline="true">
18740 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18743 \begin_layout Standard
18749 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18752 \begin_layout Standard
18753 16 bit multiplication
18759 <row topline="true">
18760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18763 \begin_layout Standard
18769 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18772 \begin_layout Standard
18773 signed 16 bit division (calls _divuint)
18779 <row topline="true">
18780 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18783 \begin_layout Standard
18789 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18792 \begin_layout Standard
18793 unsigned 16 bit division
18799 <row topline="true">
18800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18803 \begin_layout Standard
18809 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18812 \begin_layout Standard
18813 signed 16 bit modulus (calls _moduint)
18819 <row topline="true">
18820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18823 \begin_layout Standard
18829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18832 \begin_layout Standard
18833 unsigned 16 bit modulus
18839 <row topline="true">
18840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18843 \begin_layout Standard
18849 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18852 \begin_layout Standard
18853 32 bit multiplication
18859 <row topline="true">
18860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18863 \begin_layout Standard
18869 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18872 \begin_layout Standard
18873 signed 32 division (calls _divulong)
18879 <row topline="true">
18880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18883 \begin_layout Standard
18889 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18892 \begin_layout Standard
18893 unsigned 32 division
18899 <row topline="true">
18900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18903 \begin_layout Standard
18909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18912 \begin_layout Standard
18913 signed 32 bit modulus (calls _modulong)
18919 <row topline="true" bottomline="true">
18920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18923 \begin_layout Standard
18929 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18932 \begin_layout Standard
18933 unsigned 32 bit modulus
18948 \begin_layout Standard
18949 Since they are compiled as
18954 \begin_inset LatexCommand \index{reentrant}
18959 \begin_inset LatexCommand \index{interrupt}
18963 service routines should not do any of the above operations.
18964 If this is unavoidable then the above routines will need to be compiled
18971 \begin_layout Standard
18981 \begin_inset LatexCommand \index{-\/-stack-auto}
18987 option, after which the source program will have to be compiled with
18993 \begin_layout Standard
19003 \begin_inset LatexCommand \index{-\/-int-long-reent}
19010 Notice that you don't have to call these routines directly.
19011 The compiler will use them automatically every time an integer operation
19015 \begin_layout Section
19016 Floating Point Support
19017 \begin_inset LatexCommand \index{Floating point support}
19024 \begin_layout Standard
19025 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
19026 The floating point support routines are derived from gcc's floatlib.c and
19027 consist of the following routines:
19032 \begin_layout Standard
19036 \begin_inset Tabular
19037 <lyxtabular version="3" rows="17" columns="2">
19039 <column alignment="left" valignment="top" leftline="true" width="0">
19040 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19041 <row topline="true" bottomline="true">
19042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19045 \begin_layout Standard
19060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19063 \begin_layout Standard
19070 <row topline="true">
19071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19074 \begin_layout Standard
19089 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19092 \begin_layout Standard
19102 add floating point numbers
19108 <row topline="true">
19109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19112 \begin_layout Standard
19127 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19130 \begin_layout Standard
19140 subtract floating point numbers
19146 <row topline="true">
19147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19150 \begin_layout Standard
19165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19168 \begin_layout Standard
19178 divide floating point numbers
19184 <row topline="true">
19185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19188 \begin_layout Standard
19203 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19206 \begin_layout Standard
19216 multiply floating point numbers
19222 <row topline="true">
19223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19226 \begin_layout Standard
19241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19244 \begin_layout Standard
19254 convert floating point to unsigned char
19260 <row topline="true">
19261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19264 \begin_layout Standard
19279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19282 \begin_layout Standard
19292 convert floating point to signed char
19298 <row topline="true">
19299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19302 \begin_layout Standard
19317 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19320 \begin_layout Standard
19330 convert floating point to unsigned int
19336 <row topline="true">
19337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19340 \begin_layout Standard
19355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19358 \begin_layout Standard
19368 convert floating point to signed int
19374 <row topline="true">
19375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19378 \begin_layout Standard
19401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19404 \begin_layout Standard
19414 convert floating point to unsigned long
19420 <row topline="true">
19421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19424 \begin_layout Standard
19439 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19442 \begin_layout Standard
19452 convert floating point to signed long
19458 <row topline="true">
19459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19462 \begin_layout Standard
19477 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19480 \begin_layout Standard
19490 convert unsigned char to floating point
19496 <row topline="true">
19497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19500 \begin_layout Standard
19515 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19518 \begin_layout Standard
19528 convert char to floating point number
19534 <row topline="true">
19535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19538 \begin_layout Standard
19553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19556 \begin_layout Standard
19566 convert unsigned int to floating point
19572 <row topline="true">
19573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19576 \begin_layout Standard
19591 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19594 \begin_layout Standard
19604 convert int to floating point numbers
19610 <row topline="true">
19611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19614 \begin_layout Standard
19629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19632 \begin_layout Standard
19642 convert unsigned long to floating point number
19648 <row topline="true" bottomline="true">
19649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19652 \begin_layout Standard
19667 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19670 \begin_layout Standard
19680 convert long to floating point number
19695 \begin_layout Standard
19696 These support routines are developed in ANSI-C so there is room for space
19697 and speed improvement
19701 \begin_layout Standard
19702 These floating point routines (
19706 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19713 Note if all these routines are used simultaneously the data space might
19715 For serious floating point usage the large model might be needed.
19716 Also notice that you don't have to call this routines directly.
19717 The compiler will use them automatically every time a floating point operation
19719 \begin_inset VSpace bigskip
19725 \begin_layout Section
19727 \begin_inset LatexCommand \index{Libraries}
19734 \begin_layout Standard
19737 <pending: this is messy and incomplete - a little more information is in
19738 sdcc/doc/libdoc.txt
19743 \begin_layout Subsection
19744 Compiler support routines (_gptrget, _mulint etc.)
19747 \begin_layout Subsection
19748 Stdclib functions (puts, printf, strcat etc.)
19751 \begin_layout Subsubsection
19755 \begin_layout Paragraph
19756 getchar(), putchar()
19759 \begin_layout Standard
19760 \begin_inset LatexCommand \index{<stdio.h>}
19764 As usual on embedded systems you have to provide your own
19767 \begin_inset LatexCommand \index{getchar()}
19776 \begin_inset LatexCommand \index{putchar()}
19783 SDCC does not know whether the system connects to a serial line with or
19784 without handshake, LCD, keyboard or other device.
19798 You'll find examples for serial routines f.e.
19799 in sdcc/device/lib.
19800 For the mcs51 this minimalistic polling
19804 routine might be a start:
19807 \begin_layout Verse
19810 void putchar (char c) {
19816 while (!TI)\InsetSpace ~
19819 /* assumes UART is initialized */
19847 \begin_layout Paragraph
19851 \begin_layout Standard
19855 \begin_inset LatexCommand \index{printf()}
19865 does not support float (except on ds390).
19866 To enable this recompile it with the option
19872 \begin_layout Standard
19882 \begin_inset LatexCommand \index{USE\_FLOATS}
19888 on the command line.
19895 \begin_layout Standard
19905 \begin_inset LatexCommand \index{-\/-model-large}
19911 for the mcs51 port, since this uses a lot of memory.
19914 \begin_layout Standard
19915 If you're short on code memory you might want to use
19918 \begin_inset LatexCommand \index{printf\_small()}
19933 For the mcs51 there additionally are assembly versions
19936 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
19942 (subset of printf using less than 270 bytes) and
19945 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
19954 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
19960 (floating-point aware version of printf_fast) which should fit the requirements
19961 of many embedded systems (printf_fast() can be customized by unsetting
19966 support long variables and field widths).
19967 Be sure to use only one of these printf options within a project.
19972 \begin_layout Standard
19973 Feature matrix of different
19980 \begin_layout Standard
19981 \begin_inset Tabular
19982 <lyxtabular version="3" rows="14" columns="7">
19983 <features islongtable="true">
19984 <column alignment="left" valignment="middle" leftline="true" width="14col%">
19985 <column alignment="center" valignment="top" leftline="true" width="0">
19986 <column alignment="center" valignment="top" leftline="true" width="12col%">
19987 <column alignment="center" valignment="top" leftline="true" width="10col%">
19988 <column alignment="center" valignment="top" leftline="true" width="0">
19989 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
19990 <column alignment="center" valignment="top" rightline="true" width="0">
19991 <row topline="true" bottomline="true" endhead="true">
19992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19995 \begin_layout Standard
20004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20007 \begin_layout Standard
20009 \begin_inset LatexCommand \index{printf}
20018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20021 \begin_layout Standard
20029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20032 \begin_layout Standard
20038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20041 \begin_layout Standard
20047 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20050 \begin_layout Standard
20056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20059 \begin_layout Standard
20066 <row topline="true" endhead="true">
20067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20070 \begin_layout Standard
20076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20079 \begin_layout Standard
20087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20090 \begin_layout Standard
20098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20101 \begin_layout Standard
20109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20112 \begin_layout Standard
20120 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20123 \begin_layout Standard
20131 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20134 \begin_layout Standard
20143 <row topline="true" endhead="true">
20144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20147 \begin_layout Standard
20148 \begin_inset Quotes sld
20152 \begin_inset Quotes srd
20158 \begin_layout Standard
20164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20167 \begin_layout Standard
20173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20176 \begin_layout Standard
20182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20185 \begin_layout Standard
20191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20194 \begin_layout Standard
20200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20203 \begin_layout Standard
20209 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20212 \begin_layout Standard
20219 <row topline="true" endhead="true">
20220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20223 \begin_layout Standard
20227 \begin_layout Standard
20233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20236 \begin_layout Standard
20242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20245 \begin_layout Standard
20251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20254 \begin_layout Standard
20255 0.45k / 0.47k (+ _ltoa)
20260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20263 \begin_layout Standard
20269 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20272 \begin_layout Standard
20278 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20281 \begin_layout Standard
20288 <row topline="true">
20289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20292 \begin_layout Standard
20298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20301 \begin_layout Standard
20311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20314 \begin_layout Standard
20361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20364 \begin_layout Standard
20403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20406 \begin_layout Standard
20412 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20415 \begin_layout Standard
20421 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20424 \begin_layout Standard
20431 <row topline="true">
20432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20435 \begin_layout Standard
20436 long (32 bit) support
20441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20444 \begin_layout Standard
20450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20453 \begin_layout Standard
20459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20462 \begin_layout Standard
20468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20471 \begin_layout Standard
20477 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20480 \begin_layout Standard
20495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20498 \begin_layout Standard
20505 <row topline="true">
20506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20509 \begin_layout Standard
20510 byte arguments on stack
20515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20518 \begin_layout Standard
20524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20527 \begin_layout Standard
20533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20536 \begin_layout Standard
20542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20545 \begin_layout Standard
20551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20554 \begin_layout Standard
20560 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20563 \begin_layout Standard
20570 <row topline="true">
20571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20574 \begin_layout Standard
20576 \begin_inset LatexCommand \index{Floating point support}
20585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20588 \begin_layout Standard
20594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20597 \begin_layout Standard
20603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20606 \begin_layout Standard
20612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20615 \begin_layout Standard
20621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20624 \begin_layout Standard
20629 \begin_layout Standard
20630 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20643 \begin_layout Standard
20650 <row topline="true">
20651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20654 \begin_layout Standard
20655 float formats %e %g
20660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20663 \begin_layout Standard
20669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20672 \begin_layout Standard
20678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20681 \begin_layout Standard
20687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20690 \begin_layout Standard
20696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20699 \begin_layout Standard
20705 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20708 \begin_layout Standard
20715 <row topline="true" bottomline="true">
20716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20719 \begin_layout Standard
20725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20728 \begin_layout Standard
20734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20737 \begin_layout Standard
20743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20746 \begin_layout Standard
20752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20755 \begin_layout Standard
20761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20764 \begin_layout Standard
20770 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20773 \begin_layout Standard
20780 <row bottomline="true">
20781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20784 \begin_layout Standard
20789 \begin_layout Standard
20790 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20794 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20802 \begin_layout Standard
20808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20811 \begin_layout Standard
20817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20820 \begin_layout Standard
20826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20829 \begin_layout Standard
20835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20838 \begin_layout Standard
20844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20847 \begin_layout Standard
20853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20856 \begin_layout Standard
20863 <row bottomline="true">
20864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20867 \begin_layout Standard
20872 \begin_layout Standard
20873 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
20882 \begin_layout Standard
20888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20891 \begin_layout Standard
20897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20900 \begin_layout Standard
20906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20909 \begin_layout Standard
20915 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20918 \begin_layout Standard
20924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20927 \begin_layout Standard
20933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20936 \begin_layout Standard
20941 \begin_layout Standard
20942 printf_tiny integer speed is data dependent, worst case is 0.33 ms
20953 <row bottomline="true">
20954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20957 \begin_layout Standard
20962 \begin_layout Standard
20963 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
20972 \begin_layout Standard
20978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20981 \begin_layout Standard
20987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20990 \begin_layout Standard
20996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20999 \begin_layout Standard
21005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21008 \begin_layout Standard
21014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21017 \begin_layout Standard
21023 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21026 \begin_layout Standard
21033 <row bottomline="true">
21034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21037 \begin_layout Standard
21042 \begin_layout Standard
21043 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
21052 \begin_layout Standard
21058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21061 \begin_layout Standard
21067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21070 \begin_layout Standard
21076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21079 \begin_layout Standard
21085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21088 \begin_layout Standard
21094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21097 \begin_layout Standard
21103 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21106 \begin_layout Standard
21120 \begin_layout Subsubsection
21122 \begin_inset LatexCommand \index{malloc.h}
21129 \begin_layout Standard
21130 As of SDCC 2.6.2 you no longer need to call an initialization routine before
21131 using dynamic memory allocation
21132 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
21137 \begin_inset LatexCommand \index{heap (malloc)}
21141 space of 1024 bytes is provided for malloc to allocate memory from.
21142 If you need a different heap size you need to recompile _heap.c with the
21143 required size defined in HEAP_SIZE.
21144 It is recommended to make a copy of this file into your project directory
21145 and compile it there with:
21148 \begin_layout Verse
21151 sdcc -c _heap.c -D HEAD_SIZE=2048
21154 \begin_layout Standard
21155 And then link it with:
21158 \begin_layout Verse
21161 sdcc main.rel _heap.rel
21164 \begin_layout Subsection
21165 Math functions (sinf, powf, sqrtf etc.)
21168 \begin_layout Subsubsection
21172 \begin_layout Standard
21173 See definitions in file <math.h>.
21176 \begin_layout Subsection
21180 \begin_layout Standard
21182 \begin_inset LatexCommand \index{Libraries}
21186 included in SDCC should have a license at least as liberal as the GNU Lesser
21187 General Public License
21188 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
21199 \begin_layout Standard
21200 \begin_inset Note Note
21203 \begin_layout Standard
21204 license statements for the libraries are missing.
21205 sdcc/device/lib/ser_ir.c
21208 \begin_layout Standard
21210 come with a GPL (as opposed to LGPL) License - this will not be liberal
21211 enough for many embedded programmers.
21219 \begin_layout Standard
21220 If you have ported some library or want to share experience about some code
21222 falls into any of these categories Busses (I
21223 \begin_inset Formula $^{\textrm{2}}$
21226 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
21227 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
21228 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
21229 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
21234 would certainly like to hear about it.
21237 \begin_layout Standard
21238 Programmers coding for embedded systems are not especially famous for being
21239 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
21240 e these references are very valuable.
21241 Let's help to create a climate where information is shared.
21242 \begin_inset VSpace bigskip
21248 \begin_layout Section
21252 \begin_layout Subsection
21253 MCS51 Memory Models
21254 \begin_inset LatexCommand \index{Memory model}
21259 \begin_inset LatexCommand \index{MCS51 memory model}
21266 \begin_layout Subsubsection
21267 Small, Medium and Large
21270 \begin_layout Standard
21271 SDCC allows three memory models for MCS51 code,
21280 Modules compiled with different memory models should
21284 be combined together or the results would be unpredictable.
21285 The library routines supplied with the compiler are compiled as small,
21287 The compiled library modules are contained in separate directories as small,
21288 medium and large so that you can link to the appropriate set.
21291 \begin_layout Standard
21292 When the medium or large model is used all variables declared without a
21293 storage class will be allocated into the external ram, this includes all
21294 parameters and local variables (for non-reentrant
21295 \begin_inset LatexCommand \index{reentrant}
21300 When the small model is used variables without storage class are allocated
21301 in the internal ram.
21304 \begin_layout Standard
21305 Judicious usage of the processor specific storage classes
21306 \begin_inset LatexCommand \index{Storage class}
21310 and the 'reentrant' function type will yield much more efficient code,
21311 than using the large model.
21312 Several optimizations are disabled when the program is compiled using the
21313 large model, it is therefore recommended that the small model be used unless
21314 absolutely required.
21317 \begin_layout Subsubsection
21319 \begin_inset LatexCommand \label{sub:External-Stack}
21324 \begin_inset LatexCommand \index{stack}
21329 \begin_inset LatexCommand \index{External stack (mcs51)}
21336 \begin_layout Standard
21337 The external stack (-
21341 \begin_layout Standard
21351 \begin_inset LatexCommand \index{-\/-xstack}
21355 ) is located in pdata
21356 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
21360 memory (usually at the start of the external ram segment) and uses all
21361 unused space in pdata (max.
21367 \begin_layout Standard
21376 -xstack option is used to compile the program, the parameters and local
21378 \begin_inset LatexCommand \index{local variables}
21382 of all reentrant functions are allocated in this area.
21383 This option is provided for programs with large stack space requirements.
21384 When used with the -
21388 \begin_layout Standard
21398 \begin_inset LatexCommand \index{-\/-stack-auto}
21402 option, all parameters and local variables are allocated on the external
21403 stack (note: support libraries will need to be recompiled with the same
21405 There is a predefined target in the library makefile).
21408 \begin_layout Standard
21409 The compiler outputs the higher order address byte of the external ram segment
21411 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21416 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21420 ), therefore when using the External Stack option, this port
21424 be used by the application program.
21427 \begin_layout Subsection
21429 \begin_inset LatexCommand \index{Memory model}
21434 \begin_inset LatexCommand \index{DS390 memory model}
21441 \begin_layout Standard
21442 The only model supported is Flat 24
21443 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21448 This generates code for the 24 bit contiguous addressing mode of the Dallas
21450 In this mode, up to four meg of external RAM or code space can be directly
21452 See the data sheets at www.dalsemi.com for further information on this part.
21457 that the compiler does not generate any code to place the processor into
21458 24 bitmode (although
21462 in the ds390 libraries will do that for you).
21468 \begin_inset LatexCommand \index{Tinibios (DS390)}
21472 , the boot loader or similar code must ensure that the processor is in 24
21473 bit contiguous addressing mode before calling the SDCC startup code.
21484 \begin_layout Standard
21495 option, variables will by default be placed into the XDATA segment.
21500 Segments may be placed anywhere in the 4 meg address space using the usual
21505 \begin_layout Standard
21515 Note that if any segments are located above 64K, the -r flag must be passed
21516 to the linker to generate the proper segment relocations, and the Intel
21517 HEX output format must be used.
21518 The -r flag can be passed to the linker by using the option
21522 on the SDCC command line.
21523 However, currently the linker can not handle code segments > 64k.
21526 \begin_layout Section
21528 \begin_inset LatexCommand \label{sec:Pragmas}
21533 \begin_inset LatexCommand \index{Pragmas}
21540 \begin_layout Standard
21541 Pragmas are used to turn on and/or off certain compiler options.
21542 Some of them are closely related to corresponding command-line options
21544 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21550 Pragmas should be placed before and/or after a function, placing pragmas
21551 inside a function body could have unpredictable results.
21556 following #pragma directives:
21559 \begin_layout Itemize
21565 \begin_inset LatexCommand \index{\#pragma save}
21569 - this will save most current options to the save/restore stack.
21570 See #pragma\InsetSpace ~
21574 \begin_layout Itemize
21580 \begin_inset LatexCommand \index{\#pragma restore}
21584 - will restore saved options from the last save.
21585 saves & restores can be nested.
21586 SDCC uses a save/restore stack: save pushes current options to the stack,
21587 restore pulls current options from the stack.
21588 See #pragma\InsetSpace ~
21594 \begin_layout Itemize
21600 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21605 \begin_inset LatexCommand \index{function prologue}
21609 function1[,function2[,function3...]]
21610 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21614 - The compiler by default uses a caller saves convention for register saving
21615 across function calls, however this can cause unnecessary register pushing
21617 \begin_inset LatexCommand \index{push/pop}
21621 when calling small functions from larger functions.
21622 This option can be used to switch off the register saving convention for
21623 the function names specified.
21624 The compiler will not save registers when calling these functions, extra
21625 code need to be manually inserted at the entry and exit for these functions
21626 to save and restore the registers used by these functions, this can SUBSTANTIAL
21627 LY reduce code and improve run time performance of the generated code.
21628 In the future the compiler (with inter procedural analysis) may be able
21629 to determine the appropriate scheme to use for each function call.
21634 \begin_layout Standard
21643 -callee-saves command line option is used (see page
21644 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21648 ), the function names specified in #pragma\InsetSpace ~
21650 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21654 is appended to the list of functions specified in the command line.
21657 \begin_layout Itemize
21663 \begin_inset LatexCommand \index{\#pragma exclude}
21667 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21668 of pairs of push/pop
21669 \begin_inset LatexCommand \index{push/pop}
21678 \begin_inset LatexCommand \index{interrupt}
21691 The directive should be placed immediately before the ISR function definition
21692 and it affects ALL ISR functions following it.
21693 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21694 exclude\InsetSpace ~
21696 \begin_inset LatexCommand \index{\#pragma exclude}
21701 See also the related keyword _naked
21702 \begin_inset LatexCommand \index{\_naked}
21707 \begin_inset LatexCommand \index{\_\_naked}
21714 \begin_layout Itemize
21720 \begin_inset LatexCommand \index{pedantic}
21725 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21730 \begin_inset LatexCommand \label{ite:less_pedantic}
21734 - the compiler will not warn you anymore for obvious mistakes, you're on
21736 See also the command line option -
21740 \begin_layout Standard
21750 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21757 More specifically, the following warnings will be disabled:
21759 comparison is always [true/false] due to limited range of data type
21763 overflow in implicit constant conversion
21765 (158); [the (in)famous]
21767 conditional flow changed by optimizer: so said EVELYN the modified DOG
21771 function '[function name]' must return value
21776 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21777 level) are disabled, too, namely:
21780 \begin_inset Note Note
21783 \begin_layout Standard
21784 dunno what comes here - this warning appears to be unused altogether
21793 [left/right] shifting more than size of object changed to zero
21801 integer overflow in expression
21805 unmatched #pragma save and #pragma restore
21809 comparison of 'signed char' with 'unsigned char' requires promotion to int
21813 ISO C90 does not support flexible array members
21817 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21821 \begin_inset Note Note
21824 \begin_layout Standard
21825 appears to be always blank - what was supposed to be here?
21834 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21835 complexity [number]
21840 \begin_layout Itemize
21846 \begin_inset LatexCommand \index{\#pragma disable\_warning}
21850 - the compiler will not warn you anymore about warning number <nnnn>.
21853 \begin_layout Itemize
21859 \begin_inset LatexCommand \index{\#pragma nogcse}
21863 - will stop global common subexpression elimination.
21866 \begin_layout Itemize
21872 \begin_inset LatexCommand \index{\#pragma noinduction}
21876 - will stop loop induction optimizations.
21879 \begin_layout Itemize
21885 \begin_inset LatexCommand \index{\#pragma noinvariant}
21889 - will not do loop invariant optimizations.
21890 For more details see Loop Invariants in section
21891 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
21898 \begin_layout Itemize
21904 \begin_inset LatexCommand \index{\#pragma noiv}
21908 - Do not generate interrupt
21909 \begin_inset LatexCommand \index{interrupt}
21914 \begin_inset LatexCommand \index{interrupt vector table}
21918 entries for all ISR functions defined after the pragma.
21919 This is useful in cases where the interrupt vector table must be defined
21920 manually, or when there is a secondary, manually defined interrupt vector
21922 for the autovector feature of the Cypress EZ-USB FX2).
21923 More elegantly this can be achieved by obmitting the optional interrupt
21924 number after the interrupt keyword, see section
21925 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
21933 \begin_layout Itemize
21939 \begin_inset LatexCommand \index{\#pragma nojtbound}
21943 - will not generate code for boundary value checking, when switch statements
21944 are turned into jump-tables (dangerous).
21945 For more details see section
21946 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
21953 \begin_layout Itemize
21959 \begin_inset LatexCommand \index{\#pragma noloopreverse}
21963 - Will not do loop reversal optimization
21966 \begin_layout Itemize
21972 \begin_inset LatexCommand \index{\#pragma nooverlay}
21976 - the compiler will not overlay the parameters and local variables of a
21980 \begin_layout Itemize
21986 \begin_inset LatexCommand \index{\#pragma stackauto}
21994 \begin_layout Standard
22004 \begin_inset LatexCommand \index{-\/-stack-auto}
22009 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
22013 Parameters and Local Variables.
22016 \begin_layout Itemize
22022 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
22026 - The compiler will optimize code generation towards fast code, possibly
22027 at the expense of code size.
22028 Currently this has little effect.
22031 \begin_layout Itemize
22037 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
22041 - The compiler will optimize code generation towards compact code, possibly
22042 at the expense of code speed.
22043 Currently this has little effect.
22046 \begin_layout Itemize
22052 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
22056 - The compiler will attempt to generate code that is both compact and fast,
22057 as long as meeting one goal is not a detriment to the other (this is the
22062 \begin_layout Itemize
22068 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
22072 - Generally follow the C89 standard, but allow SDCC features that conflict
22073 with the standard (default).
22076 \begin_layout Itemize
22082 \begin_inset LatexCommand \index{\#pragma std\_c89}
22086 - Follow the C89 standard and disable SDCC features that conflict with the
22090 \begin_layout Itemize
22096 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
22100 - Generally follow the C99 standard, but allow SDCC features that conflict
22101 with the standard (incomplete support).
22104 \begin_layout Itemize
22110 \begin_inset LatexCommand \index{\#pragma std\_c99}
22114 - Follow the C99 standard and disable SDCC features that conflict with the
22115 standard (incomplete support).
22118 \begin_layout Itemize
22124 \begin_inset LatexCommand \index{\#pragma codeseg}
22128 - Use this name (max.
22129 8 characters) for the code segment.
22134 \begin_layout Standard
22146 \begin_layout Itemize
22152 \begin_inset LatexCommand \index{\#pragma constseg}
22156 - Use this name (max.
22157 8 characters) for the const segment.
22162 \begin_layout Standard
22174 \begin_layout Standard
22175 The preprocessor SDCPP
22176 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
22180 supports the following #pragma directives:
22183 \begin_layout Itemize
22186 pedantic_parse_number
22189 \begin_inset LatexCommand \index{pedantic}
22194 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22199 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
22203 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
22204 properly and the macro LO_B(3) gets expanded.
22210 \begin_layout Standard
22219 -pedantic-parse-number command line option
22220 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
22227 Below is an example on how to use this pragma.
22230 Note: this functionality is not in conformance with standard!
22233 \begin_layout Verse
22236 #pragma pedantic_parse_number +
22237 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22245 #define LO_B(x) ((x) & 0xff)
22249 unsigned char foo(void)
22256 unsigned char c=0xfe-LO_B(3)
22271 \begin_layout Itemize
22277 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22281 (+ | -) - switch _asm _endasm block preprocessing on / off.
22283 You use this prama to define multilines of assembly code.
22284 This will prevent the preprocessor from changing the formating required
22286 Below is an example on how to use this pragma.
22289 \begin_layout Verse
22292 #pragma preproc_asm -
22293 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22299 #define MYDELAY _asm
22304 nop ;my assembly comment...
22318 #pragma preproc_asm
22349 \begin_layout Itemize
22355 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22359 (+ | -) - Allow "naked" hash in macro definition, for example:
22363 #define DIR_LO(x) #(x & 0xff)
22368 Below is an example on how to use this pragma.
22371 \begin_layout Verse
22374 #pragma preproc_asm +
22376 #pragma sdcc_hash +
22377 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22392 mov R6_B3, #(x & 0xff)
22399 mov R7_B3, #((x >> 8) & 0xff)
22423 \begin_layout Standard
22424 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22425 ons which might cause the compiler to generate extra stack and/or data space
22426 to store compiler generated temporary variables.
22427 This usually happens in large functions.
22428 Pragma directives should be used as shown in the following example, they
22429 are used to control options and optimizations for a given function.
22433 \begin_layout Verse
22437 \begin_inset LatexCommand \index{\#pragma save}
22448 /* save the current settings */
22451 \begin_inset LatexCommand \index{\#pragma nogcse}
22460 /* turnoff global subexpression elimination */
22462 #pragma noinduction
22463 \begin_inset LatexCommand \index{\#pragma noinduction}
22467 /* turn off induction optimizations */
22490 \begin_inset LatexCommand \index{\#pragma restore}
22494 /* turn the optimizations back on */
22497 \begin_layout Standard
22498 The compiler will generate a warning message when extra space is allocated.
22499 It is strongly recommended that the save and restore pragmas be used when
22500 changing options for a function.
22509 \begin_layout Section
22510 Defines Created by the Compiler
22513 \begin_layout Standard
22514 The compiler creates the following #defines
22515 \begin_inset LatexCommand \index{\#defines}
22520 \begin_inset LatexCommand \index{Defines created by the compiler}
22529 \begin_layout Standard
22530 \begin_inset Tabular
22531 <lyxtabular version="3" rows="11" columns="2">
22533 <column alignment="left" valignment="top" leftline="true" width="3in">
22534 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22535 <row topline="true" bottomline="true">
22536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22539 \begin_layout Standard
22547 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22550 \begin_layout Standard
22559 <row topline="true">
22560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22563 \begin_layout Standard
22565 \begin_inset LatexCommand \index{SDCC}
22574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22577 \begin_layout Standard
22579 Since version 2.5.6 the version number as an int (ex.
22586 <row topline="true">
22587 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22590 \begin_layout Standard
22592 \begin_inset LatexCommand \index{SDCC\_mcs51}
22597 \begin_inset LatexCommand \index{SDCC\_ds390}
22602 \begin_inset LatexCommand \index{SDCC\_z80}
22611 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22614 \begin_layout Standard
22615 depending on the model used (e.g.: -mds390)
22621 <row topline="true">
22622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22625 \begin_layout Standard
22627 \begin_inset LatexCommand \index{\_\_mcs51}
22632 \begin_inset LatexCommand \index{\_\_ds390}
22637 \begin_inset LatexCommand \index{\_\_hc08}
22642 \begin_inset LatexCommand \index{\_\_z80}
22651 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22654 \begin_layout Standard
22655 depending on the model used (e.g.
22662 <row topline="true">
22663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22666 \begin_layout Standard
22668 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22677 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22680 \begin_layout Standard
22687 \begin_layout Standard
22704 <row topline="true">
22705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22708 \begin_layout Standard
22710 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22719 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22722 \begin_layout Standard
22729 \begin_layout Standard
22746 <row topline="true">
22747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22750 \begin_layout Standard
22752 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22764 \begin_layout Standard
22771 \begin_layout Standard
22788 <row topline="true">
22789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22792 \begin_layout Standard
22794 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22806 \begin_layout Standard
22813 \begin_layout Standard
22830 <row topline="true">
22831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22834 \begin_layout Standard
22836 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
22845 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22848 \begin_layout Standard
22855 \begin_layout Standard
22872 <row topline="true">
22873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22876 \begin_layout Standard
22878 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
22887 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22890 \begin_layout Standard
22901 <row topline="true" bottomline="true">
22902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22905 \begin_layout Standard
22907 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
22916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22919 \begin_layout Standard
22937 \begin_layout Chapter
22938 Notes on supported Processors
22941 \begin_layout Section
22943 \begin_inset LatexCommand \label{sub:MCS51-variants}
22948 \begin_inset LatexCommand \index{MCS51 variants}
22955 \begin_layout Standard
22956 MCS51 processors are available from many vendors and come in many different
22958 While they might differ considerably in respect to Special Function Registers
22959 the core MCS51 is usually not modified or is kept compatible.
22963 \begin_layout Subsection
22964 pdata access by SFR
22967 \begin_layout Standard
22968 With the upcome of devices with internal xdata and flash memory devices
22970 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
22974 as dedicated I/O port is becoming more popular.
22975 Switching the high byte for pdata
22976 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
22980 access which was formerly done by port P2 is then achieved by a Special
22982 \begin_inset LatexCommand \index{sfr}
22987 In well-established MCS51 tradition the address of this
22991 is where the chip designers decided to put it.
22992 Needless to say that they didn't agree on a common name either.
22993 So that the startup code can correctly initialize xdata variables, you
22994 should define an sfr with the name _XPAGE
22997 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
23003 at the appropriate location if the default, port P2, is not used for this.
23007 \begin_layout Verse
23010 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
23014 \begin_layout Verse
23017 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
23022 \begin_layout Verse
23025 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
23029 \begin_layout Verse
23032 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23036 \begin_layout Verse
23039 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23043 \begin_layout Standard
23044 For more exotic implementations further customizations may be needed.
23046 \begin_inset LatexCommand \ref{sub:Startup-Code}
23050 for other possibilities.
23053 \begin_layout Subsection
23054 Other Features available by SFR
23057 \begin_layout Standard
23058 Some MCS51 variants offer features like Double DPTR
23059 \begin_inset LatexCommand \index{DPTR}
23063 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
23064 These are currently not used for the MCS51 port.
23065 If you absolutely need them you can fall back to inline assembly or submit
23067 \begin_inset VSpace bigskip
23073 \begin_layout Section
23077 \begin_layout Standard
23079 \begin_inset LatexCommand \index{DS80C400}
23084 \begin_inset LatexCommand \index{DS400}
23088 microcontroller has a rich set of peripherals.
23089 In its built-in ROM library it includes functions to access some of the
23090 features, among them is a TCP stack with IP4 and IP6 support.
23091 Library headers (currently in beta status) and other files are provided
23095 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
23101 \begin_inset VSpace bigskip
23107 \begin_layout Section
23108 The Z80 and gbz80 port
23111 \begin_layout Standard
23112 SDCC can target both the Zilog Z80
23113 \begin_inset LatexCommand \index{Z80}
23117 and the Nintendo Gameboy's Z80-like gbz80
23118 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
23123 The Z80 port is passed through the same
23126 \begin_inset LatexCommand \index{Regression test}
23133 \begin_inset LatexCommand \ref{sec:Quality-control}
23137 ) as the MCS51 and DS390 ports, so floating point support, support for long
23138 variables and bitfield support is fine.
23139 See mailing lists and forums about interrupt routines.
23142 \begin_layout Standard
23143 As always, the code is the authoritative reference - see z80/ralloc.c and
23146 \begin_inset LatexCommand \index{Z80!stack}
23150 frame is similar to that generated by the IAR Z80 compiler.
23151 IX is used as the base pointer, HL and IY are used as a temporary registers,
23152 and BC and DE are available for holding variables.
23154 \begin_inset LatexCommand \index{Z80!return value}
23158 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
23160 The gbz80 port use the same set of registers for the return values, but
23161 in a different order of significance: E (one byte), DE (two bytes), or
23163 \begin_inset VSpace bigskip
23169 \begin_layout Section
23173 \begin_layout Standard
23174 The port to the Freescale/Motorola HC08
23175 \begin_inset LatexCommand \index{HC08}
23179 family has been added in October 2003, and is still undergoing some basic
23181 The code generator is complete, but the register allocation is still quite
23183 Some of the SDCC's standard C library functions have embedded non-HC08
23184 inline assembly and so are not yet usable.
23187 \begin_layout Standard
23188 The HC08 port passes the regression test suite (see section
23189 \begin_inset LatexCommand \ref{sec:Quality-control}
23194 \begin_inset VSpace bigskip
23202 \begin_layout Section
23204 \begin_inset LatexCommand \index{PIC14}
23211 \begin_layout Standard
23212 The PIC14 port adds support for Microchip
23213 \begin_inset LatexCommand \index{Microchip}
23218 \begin_inset Formula $^{\text{TM}}$
23222 \begin_inset LatexCommand \index{PIC14}
23227 \begin_inset Formula $^{\text{TM}}$
23230 MCUs with 14 bit wide instructions.
23231 This port is not yet mature and still lacks many features.
23232 However, it can work for simple code.
23235 \begin_layout Standard
23236 Currently supported devices include:
23239 \begin_layout Standard
23240 12F: 629, 635, 675, 683
23243 \begin_layout Standard
23247 \begin_layout Standard
23251 \begin_layout Standard
23252 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
23255 \begin_layout Standard
23256 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
23260 \begin_layout Standard
23264 \begin_layout Standard
23265 16F: 627, 627a, 628, 628a, 630, 636, 639, 648a, 676, 684, 685, 687, 688,
23269 \begin_layout Standard
23270 16F: 716, 72, 73, 737, 74, 76, 767, 77, 777, 785
23273 \begin_layout Standard
23274 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
23278 \begin_layout Standard
23279 16F: 913, 914, 916, 917
23282 \begin_layout Standard
23283 An up-to-date list of currently supported devices can be obtained via
23285 sdcc -mpic14 -phelp foo.c
23287 (foo.c must exist...).
23290 \begin_layout Subsection
23292 \begin_inset LatexCommand \index{code page (pic14)}
23297 \begin_inset LatexCommand \index{Memory bank (pic14)}
23304 \begin_layout Standard
23305 The linker organizes allocation for the code page and RAM banks.
23306 It does not have intimate knowledge of the code flow.
23307 It will put all the code section of a single .asm file into a single code
23309 In order to make use of multiple code pages, separate asm files must be
23311 The compiler assigns all
23315 functions of a single .c file into the same code page.
23319 To get the best results,
23320 follow these guidelines:
23323 \begin_layout Enumerate
23324 Make local functions static, as non static functions require code page selection
23327 Due to the way sdcc handles functions, place called functions prior
23328 to calling functions in the file wherever possible: Otherwise sdcc will
23329 insert unneccessary pagesel directives around the call, believing that
23330 the called function is externally defined.
23333 \begin_layout Enumerate
23334 For devices that have multiple code pages it is more efficient to use the
23335 same number of files as pages: Use up to 4 separate .c files for the 16F877,
23336 but only 2 files for the 16F874.
23337 This way the linker can put the code for each file into different code
23338 pages and there will be less page selection overhead.
23341 \begin_layout Enumerate
23342 And as for any 8 bit micro (especially for PIC14 as they have a very simple
23343 instruction set), use `unsigned char' wherever possible instead of `int'.
23346 \begin_layout Subsection
23347 Adding New Devices to the Port
23350 \begin_layout Standard
23351 Adding support for a new 14
23355 \begin_layout Standard
23364 bit PIC MCU requires the following steps:
23367 \begin_layout Enumerate
23368 Create a new device description.
23370 Each device is described in two files: pic16f*.h
23372 These files primarily define SFRs, structs to access their bits, and symbolic
23373 configuration options.
23374 Both files can be generated from gputils' .inc files using the perl script
23377 support/scripts/inc2h.pl
23380 This file also contains further instructions on how to proceed.
23383 \begin_layout Enumerate
23384 Copy the .h file into SDCC's include path and either add the .c file to your
23385 project or copy it to
23387 device/lib/pic/libdev
23390 Afterwards, rebuild and install the libraries.
23393 \begin_layout Enumerate
23394 Edit pic14devices.txt in SDCC's include path (
23396 device/include/pic/
23398 in the source tree or
23400 /usr/local/share/sdcc/include/pic
23402 after installation).
23404 You need to add a device specification here to make
23405 the memory layout (code banks, RAM, aliased memory regions, ...) known to
23407 Probably you can copy and modify an existing entry.
23408 The file format is documented at the top of the file.
23411 \begin_layout Subsection
23415 \begin_layout Standard
23416 For the interrupt function, use the keyword `__interrupt'
23417 \begin_inset LatexCommand \index{PIC14!interrupt}
23421 with level number of 0 (PIC14 only has 1 interrupt so this number is only
23422 there to avoid a syntax error - it ought to be fixed).
23426 \begin_layout Verse
23429 void Intr(void) __interrupt 0
23435 T0IF = 0; /* Clear timer interrupt */
23440 \begin_layout Subsection
23441 Linking and Assembling
23444 \begin_layout Standard
23445 For assembling you can use either GPUTILS'
23446 \begin_inset LatexCommand \index{gputils (pic tools)}
23450 gpasm.exe or MPLAB's mpasmwin.exe.
23451 GPUTILS are available from
23452 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23457 For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
23458 If you use MPLAB and an interrupt function then the linker script file
23459 vectors section will need to be enlarged to link with mplink.
23470 \begin_layout Verse
23483 sdcc -V -mpic14 -p16f877 -c $<
23487 $(PRJ).hex: $(OBJS)
23497 gplink -m -s $(PRJ).lkr
23498 -o $(PRJ).hex $(OBJS) libsdcc.lib
23501 \begin_layout Standard
23509 \begin_layout Verse
23522 sdcc -S -V -mpic14 -p16f877 $<
23532 mpasmwin /q /o $*.asm
23536 $(PRJ).hex: $(OBJS)
23547 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
23550 \begin_layout Standard
23551 Please note that indentations within a
23555 have to be done with a tabulator character.
23558 \begin_layout Subsection
23559 Command-Line Options
23562 \begin_layout Standard
23563 Besides the switches common to all SDCC backends, the PIC14 port accepts
23564 the following options (for an updated list see sdcc -
23568 \begin_layout Standard
23580 \begin_layout Description
23585 \begin_layout Standard
23595 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
23599 emit debug info in assembly output
23602 \begin_layout Description
23607 \begin_layout Standard
23617 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
23621 disable (slightly faulty) optimization on pCode
23624 \begin_layout Description
23629 \begin_layout Standard
23639 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
23643 sets the lowest address of the argument passing stack (defaults to a suitably
23644 large shared databank to reduce BANKSEL overhead)
23647 \begin_layout Description
23652 \begin_layout Standard
23662 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
23666 sets the size if the argument passing stack (default: 16, minimum: 4)
23669 \begin_layout Subsection
23670 Environment Variables
23673 \begin_layout Standard
23674 The PIC14 port recognizes the following environment variables:
23677 \begin_layout Description
23678 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
23679 register (the ones called r0xNNNN) in a section of its own.
23680 By default (if this variable is unset), sdcc tries to cluster registers
23681 in sections in order to reduce the BANKSEL overhead when accessing them.
23684 \begin_layout Subsection
23688 \begin_layout Standard
23689 The PIC14 library currently only contains support routines required by the
23690 compiler to implement multiplication, division, and floating point support.
23691 No libc-like replacement is available at the moment, though many of the
23692 common sdcc library sources (in
23696 ) should also compile with the PIC14 port.
23699 \begin_layout Subsubsection
23700 error: missing definition for symbol ``__gptrget1''
23703 \begin_layout Standard
23704 The PIC14 port uses library routines to provide more complex operations
23705 like multiplication, division/modulus and (generic) pointer dereferencing.
23706 In order to add these routines to your project, you must link with PIC14's
23712 For single source file projects this is done automatically, more complex
23717 to the linker's arguments.
23718 Make sure you also add an include path for the library (using the -I switch
23722 \begin_layout Subsubsection
23723 Processor mismatch in file ``XXX''.
23726 \begin_layout Standard
23727 This warning can usually be ignored due to the very good compatibility amongst
23732 \begin_layout Standard
23742 \begin_inset LatexCommand \index{PIC14}
23749 \begin_layout Standard
23750 You might also consider recompiling the library for your specific device
23751 by changing the ARCH=p16f877 (default target) entry in
23753 device/lib/pic/Makefile.in
23757 device/lib/pic/Makefile
23759 to reflect your device.
23760 This might even improve performance for smaller devices as unneccesary
23761 BANKSELs might be removed.
23764 \begin_layout Subsection
23768 \begin_layout Subsubsection
23772 \begin_layout Standard
23773 Functions with variable argument lists (like printf) are not yet supported.
23774 Similarly, taking the argument of the first argument passed into a function
23775 does not work: It is currently passed in WREG and has no address...
23778 \begin_layout Subsubsection
23779 Regression tests fail
23782 \begin_layout Standard
23783 Though the small subset of regression tests in src/regression passes, SDCC
23784 regression test suite does not, indicating that there are still major bugs
23786 However, many smaller projects have successfully used SDCC in the past...
23789 \begin_layout Standard
23797 \begin_layout Section
23799 \begin_inset LatexCommand \index{PIC16}
23806 \begin_layout Standard
23807 The PIC16 port adds support for Microchip
23808 \begin_inset LatexCommand \index{Microchip}
23813 \begin_inset Formula $^{\text{TM}}$
23817 \begin_inset LatexCommand \index{PIC}
23822 \begin_inset Formula $^{\text{TM}}$
23825 MCUs with 16 bit wide instructions.
23826 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
23827 ; devices supported by the port include:
23830 \begin_layout Standard
23831 18F: 242, 248, 252, 258, 442, 448, 452, 458
23834 \begin_layout Standard
23838 \begin_layout Standard
23839 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 24j10, 2525, 2550, 25j10,
23843 \begin_layout Standard
23844 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 44j10, 4520, 4525, 4550,
23848 \begin_layout Standard
23849 18F: 6520, 6620, 6680, 6720
23852 \begin_layout Standard
23853 18F: 8520, 8620, 8680, 8720
23856 \begin_layout Subsection
23860 \begin_layout Standard
23861 PIC16 port supports the standard command line arguments as supposed, with
23862 the exception of certain cases that will be mentioned in the following
23866 \begin_layout Description
23871 \begin_layout Standard
23881 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
23889 \begin_layout Standard
23901 \begin_layout Description
23906 \begin_layout Standard
23915 -fommit-frame-pointer
23916 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
23920 Frame pointer will be omitted when the function uses no local variables.
23923 \begin_layout Subsection
23924 Port Specific Options
23925 \begin_inset LatexCommand \index{Options PIC16}
23932 \begin_layout Standard
23933 The port specific options appear after the global options in the sdcc -
23937 \begin_layout Standard
23949 \begin_layout Subsubsection
23950 Code Generation Options
23953 \begin_layout Standard
23954 These options influence the generated assembler code.
23957 \begin_layout Description
23962 \begin_layout Standard
23971 -pstack-model=[model] Used in conjuction with the command above.
23972 Defines the stack model to be used, valid stack models are:
23977 \labelwidthstring 00.00.0000
23982 Selects small stack model.
23983 8 bit stack and frame pointers.
23984 Supports 256 bytes stack size.
23988 \labelwidthstring 00.00.0000
23993 Selects large stack model.
23994 16 bit stack and frame pointers.
23995 Supports 65536 bytes stack size.
23999 \begin_layout Description
24004 \begin_layout Standard
24013 -pno-banksel Do not generate BANKSEL assembler directives.
24016 \begin_layout Description
24021 \begin_layout Standard
24030 -extended Enable extended instruction set/literal offset addressing mode.
24034 \begin_layout Subsubsection
24035 Optimization Options
24038 \begin_layout Description
24043 \begin_layout Standard
24052 -obanksel=n Set optimization level for inserting BANKSELs.
24059 \labelwidthstring 00.00.0000
24064 \labelwidthstring 00.00.0000
24065 1 checks previous used register and if it is the same then does not emit
24066 BANKSEL, accounts only for labels.
24070 \labelwidthstring 00.00.0000
24071 2 tries to check the location of (even different) symbols and removes BANKSELs
24072 if they are in the same bank.
24077 Important: There might be problems if the linker script has data sections
24078 across bank borders!
24082 \begin_layout Description
24087 \begin_layout Standard
24096 -denable-peeps Force the usage of peepholes.
24100 \begin_layout Description
24105 \begin_layout Standard
24114 -optimize-goto Try to use (conditional) BRA instead of GOTO.
24117 \begin_layout Description
24122 \begin_layout Standard
24131 -optimize-cmp Try to optimize some compares.
24134 \begin_layout Description
24139 \begin_layout Standard
24148 -optimize-df Analyze the dataflow of the generated code and improve it.
24151 \begin_layout Subsubsection
24155 \begin_layout Description
24160 \begin_layout Standard
24169 -asm= Sets the full path and name of an external assembler to call.
24172 \begin_layout Description
24177 \begin_layout Standard
24187 \begin_inset LatexCommand \index{PIC16!MPLAB}
24191 compatibility option.
24192 Currently only suppresses special gpasm directives.
24195 \begin_layout Subsubsection
24199 \begin_layout Description
24204 \begin_layout Standard
24213 -link= Sets the full path and name of an external linker to call.
24216 \begin_layout Description
24221 \begin_layout Standard
24230 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
24231 unitialized data variables with [kword].
24232 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
24235 \begin_layout Description
24240 \begin_layout Standard
24249 -ivt-loc=n Place the interrupt vector table at address
24254 Useful for bootloaders.
24257 \begin_layout Description
24262 \begin_layout Standard
24271 -nodefaultlibs Do not link default libraries when linking.
24274 \begin_layout Description
24279 \begin_layout Standard
24288 -use-crt= Use a custom run-time module instead of the defaults.
24291 \begin_layout Description
24296 \begin_layout Standard
24305 -no-crt Don't link the default run-time modules
24308 \begin_layout Subsubsection
24312 \begin_layout Standard
24313 Debugging options enable extra debugging information in the output files.
24316 \begin_layout Description
24321 \begin_layout Standard
24330 -debug-xtra Similar to -
24334 \begin_layout Standard
24344 \begin_inset LatexCommand \index{-\/-debug}
24348 , but dumps more information.
24351 \begin_layout Description
24356 \begin_layout Standard
24365 -debug-ralloc Force register allocator to dump <source>.d file with debugging
24367 <source> is the name of the file being compiled.
24370 \begin_layout Description
24375 \begin_layout Standard
24384 -pcode-verbose Enable pcode debugging information in translation.
24387 \begin_layout Description
24392 \begin_layout Standard
24401 -calltree Dump call tree in .calltree file.
24404 \begin_layout Description
24409 \begin_layout Standard
24418 -gstack Trace push/pops for stack pointer overflow.
24421 \begin_layout Subsection
24422 Enviroment Variables
24425 \begin_layout Standard
24426 There is a number of enviromental variables that can be used when running
24427 SDCC to enable certain optimizations or force a specific program behaviour.
24428 these variables are primarily for debugging purposes so they can be enabled/dis
24432 \begin_layout Standard
24433 Currently there is only two such variables available:
24436 \begin_layout Description
24437 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
24438 bitfields is optimized by directly loading FSR0 with the address of the
24439 bitfield structure.
24440 Normally SDCC will cast the bitfield structure to a bitfield pointer and
24442 This step saves data ram and code space for functions that make heavy use
24444 (i.e., 80 bytes of code space are saved when compiling malloc.c with this
24449 \begin_layout Description
24450 NO_REG_OPT Do not perform pCode registers optimization.
24451 This should be used for debugging purposes.
24452 If bugs in the pcode optimizer are found, users can benefit from temporarily
24453 disabling the optimizer until the bug is fixed.
24456 \begin_layout Subsection
24457 Preprocessor Macros
24460 \begin_layout Standard
24462 \begin_inset LatexCommand \index{PIC16}
24466 port defines the following preprocessor macros while translating a source.
24469 \begin_layout Standard
24471 \begin_inset Tabular
24472 <lyxtabular version="3" rows="6" columns="2">
24474 <column alignment="center" valignment="top" leftline="true" width="0">
24475 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24476 <row topline="true" bottomline="true">
24477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24480 \begin_layout Standard
24486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24489 \begin_layout Standard
24496 <row topline="true">
24497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24500 \begin_layout Standard
24506 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24509 \begin_layout Standard
24510 Port identification
24516 <row topline="true">
24517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24520 \begin_layout Standard
24525 \begin_layout Standard
24539 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24542 \begin_layout Standard
24543 Port identification (same as above)
24549 <row topline="true">
24550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24553 \begin_layout Standard
24559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24562 \begin_layout Standard
24563 MCU Identification.
24568 is the microcontrol identification number, i.e.
24575 <row topline="true">
24576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24579 \begin_layout Standard
24584 \begin_layout Standard
24598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24601 \begin_layout Standard
24602 MCU Identification (same as above)
24608 <row topline="true" bottomline="true">
24609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24612 \begin_layout Standard
24618 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24621 \begin_layout Standard
24622 nnn = SMALL or LARGE respectively according to the stack model used
24635 \begin_layout Standard
24636 In addition the following macros are defined when calling assembler:
24639 \begin_layout Standard
24641 \begin_inset Tabular
24642 <lyxtabular version="3" rows="4" columns="2">
24644 <column alignment="center" valignment="top" leftline="true" width="0">
24645 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24646 <row topline="true" bottomline="true">
24647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24650 \begin_layout Standard
24656 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24659 \begin_layout Standard
24666 <row topline="true">
24667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24670 \begin_layout Standard
24676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24679 \begin_layout Standard
24680 MCU Identification.
24685 is the microcontrol identification number, i.e.
24692 <row topline="true">
24693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24696 \begin_layout Standard
24702 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24705 \begin_layout Standard
24706 nnn = SMALL or LARGE respectively according to the memory model used for
24713 <row topline="true" bottomline="true">
24714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24717 \begin_layout Standard
24723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24726 \begin_layout Standard
24727 nnn = SMALL or LARGE respectively according to the stack model used
24740 \begin_layout Subsection
24744 \begin_layout Standard
24746 \begin_inset LatexCommand \index{PIC16}
24750 port uses the following directories for searching header files and libraries.
24753 \begin_layout Standard
24755 \begin_inset Tabular
24756 <lyxtabular version="3" rows="3" columns="4">
24758 <column alignment="center" valignment="top" leftline="true" width="0">
24759 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24760 <column alignment="center" valignment="top" width="0">
24761 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24762 <row topline="true" bottomline="true">
24763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24766 \begin_layout Standard
24772 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24775 \begin_layout Standard
24781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24784 \begin_layout Standard
24790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24793 \begin_layout Standard
24800 <row topline="true">
24801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24804 \begin_layout Standard
24805 PREFIX/sdcc/include/pic16
24810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24813 \begin_layout Standard
24814 PIC16 specific headers
24819 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24822 \begin_layout Standard
24828 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24831 \begin_layout Standard
24838 <row topline="true" bottomline="true">
24839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24842 \begin_layout Standard
24843 PREFIX/sdcc/lib/pic16
24848 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24851 \begin_layout Standard
24852 PIC16 specific libraries
24857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24860 \begin_layout Standard
24866 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24869 \begin_layout Standard
24883 \begin_layout Subsection
24885 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
24892 \begin_layout Standard
24894 \begin_inset LatexCommand \index{PIC16}
24898 port currently supports the following pragmas:
24901 \begin_layout Description
24903 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
24907 This forces the code generator to initialize the stack & frame pointers
24908 at a specific address.
24909 This is an ad hoc solution for cases where no STACK directive is available
24910 in the linker script or gplink is not instructed to create a stack section.
24913 stack pragma should be used only once in a project.
24914 Multiple pragmas may result in indeterminate behaviour of the program.
24918 \begin_layout Standard
24919 The old format (ie.
24920 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
24921 cross page boundaries (or even exceed the available data RAM) and crash
24923 Make sure that stack does not cross page boundaries when using the SMALL
24931 The format is as follows:
24936 \begin_layout LyX-Code
24937 #pragma stack bottom_address [stack_size]
24942 \begin_layout Standard
24947 is the lower bound of the stack section.
24948 The stack pointer initially will point at address (bottom_address+stack_size-1).
24951 \begin_layout LyX-Code
24955 \begin_layout LyX-Code
24959 \begin_layout LyX-Code
24960 /* initializes stack of 100 bytes at RAM address 0x200 */
24963 \begin_layout LyX-Code
24964 #pragma stack 0x200 100
24967 \begin_layout Standard
24968 If the stack_size field is omitted then a stack is created with the default
24970 This size might be enough for most programs, but its not enough for operations
24971 with deep function nesting or excessive stack usage.
24974 \begin_layout Description
24976 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
24980 Force a function to a static FLASH address.
24983 \begin_layout LyX-Code
24987 \begin_layout LyX-Code
24991 \begin_layout LyX-Code
24992 /* place function test_func at 0x4000 */
24995 \begin_layout LyX-Code
24996 #pragma code test_func 0x4000
24999 \begin_layout LyX-Code
25003 \begin_layout Description
25004 library instructs the linker to use a library module.
25009 \begin_layout LyX-Code
25010 #pragma library module_name
25013 \begin_layout Standard
25018 can be any library or object file (including its path).
25019 Note that there are four reserved keywords which have special meaning.
25023 \begin_layout Standard
25025 \begin_inset Tabular
25026 <lyxtabular version="3" rows="6" columns="3">
25028 <column alignment="center" valignment="top" leftline="true" width="0">
25029 <column alignment="block" valignment="top" leftline="true" width="20page%">
25030 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
25031 <row topline="true" bottomline="true">
25032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25035 \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
25060 <row topline="true">
25061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25064 \begin_layout Standard
25072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25075 \begin_layout Standard
25076 ignore all library pragmas
25081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25084 \begin_layout Standard
25093 <row topline="true">
25094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25097 \begin_layout Standard
25105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25108 \begin_layout Standard
25114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25117 \begin_layout Standard
25128 <row topline="true">
25129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25132 \begin_layout Standard
25140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25143 \begin_layout Standard
25144 link the Math libarary
25149 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25152 \begin_layout Standard
25163 <row topline="true">
25164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25167 \begin_layout Standard
25175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25178 \begin_layout Standard
25179 link the I/O library
25184 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25187 \begin_layout Standard
25198 <row topline="true" bottomline="true">
25199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25202 \begin_layout Standard
25210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25213 \begin_layout Standard
25214 link the debug library
25219 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25222 \begin_layout Standard
25239 * is the device number, i.e.
25240 452 for PIC18F452 MCU.
25243 \begin_layout Standard
25244 This feature allows for linking with specific libraries withoug having to
25245 explicit name them in the command line.
25250 keyword will reject all modules specified by the library pragma.
25253 \begin_layout Description
25254 udata The pragma udata instructs the compiler to emit code so that linker
25255 will place a variable at a specific memory bank.
25258 \begin_layout LyX-Code
25262 \begin_layout LyX-Code
25266 \begin_layout LyX-Code
25267 /* places variable foo at bank2 */
25270 \begin_layout LyX-Code
25271 #pragma udata bank2 foo
25274 \begin_layout LyX-Code
25278 \begin_layout Standard
25279 In order for this pragma to work extra SECTION directives should be added
25280 in the .lkr script.
25281 In the following example a sample .lkr file is shown:
25284 \begin_layout LyX-Code
25288 \begin_layout LyX-Code
25289 // Sample linker script for the PIC18F452 processor
25292 \begin_layout LyX-Code
25296 \begin_layout LyX-Code
25297 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
25300 \begin_layout LyX-Code
25301 CODEPAGE NAME=page START=0x2A END=0x7FFF
25304 \begin_layout LyX-Code
25305 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
25308 \begin_layout LyX-Code
25309 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
25312 \begin_layout LyX-Code
25313 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
25316 \begin_layout LyX-Code
25317 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
25320 \begin_layout LyX-Code
25321 ACCESSBANK NAME=accessram START=0x0 END=0x7F
25324 \begin_layout LyX-Code
25328 \begin_layout LyX-Code
25329 DATABANK NAME=gpr0 START=0x80 END=0xFF
25332 \begin_layout LyX-Code
25333 DATABANK NAME=gpr1 START=0x100 END=0x1FF
25336 \begin_layout LyX-Code
25337 DATABANK NAME=gpr2 START=0x200 END=0x2FF
25340 \begin_layout LyX-Code
25341 DATABANK NAME=gpr3 START=0x300 END=0x3FF
25344 \begin_layout LyX-Code
25345 DATABANK NAME=gpr4 START=0x400 END=0x4FF
25348 \begin_layout LyX-Code
25349 DATABANK NAME=gpr5 START=0x500 END=0x5FF
25352 \begin_layout LyX-Code
25353 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
25356 \begin_layout LyX-Code
25360 \begin_layout LyX-Code
25361 SECTION NAME=CONFIG ROM=config
25364 \begin_layout LyX-Code
25368 \begin_layout LyX-Code
25369 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
25372 \begin_layout LyX-Code
25373 SECTION NAME=bank1 RAM=gpr1 # should be added to link
25376 \begin_layout LyX-Code
25377 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
25380 \begin_layout LyX-Code
25381 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
25384 \begin_layout LyX-Code
25385 SECTION NAME=bank4 RAM=gpr4
25388 \begin_layout LyX-Code
25389 SECTION NAME=bank5 RAM=gpr5
25392 \begin_layout Standard
25393 The linker will recognise the section name set in the pragma statement and
25394 will position the variable at the memory bank set with the RAM field at
25395 the SECTION line in the linker script file.
25398 \begin_layout Subsection
25400 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
25407 \begin_layout Standard
25408 There is one main header file
25409 \begin_inset LatexCommand \index{PIC16!Header files}
25413 that can be included to the source files using the pic16
25414 \begin_inset LatexCommand \index{PIC16}
25424 This header file contains the definitions for the processor special registers,
25425 so it is necessary if the source accesses them.
25426 It can be included by adding the following line in the beginning of the
25430 \begin_layout LyX-Code
25431 #include <pic18fregs.h>
25434 \begin_layout Standard
25435 The specific microcontroller is selected within the pic18fregs.h automatically,
25436 so the same source can be used with a variety of devices.
25439 \begin_layout Subsection
25443 \begin_layout Standard
25445 \begin_inset LatexCommand \index{PIC16!Libraries}
25450 \begin_inset LatexCommand \index{PIC16}
25454 port depends on are the microcontroller device libraries which contain
25455 the symbol definitions for the microcontroller special function registers.
25456 These libraries have the format pic18fxxxx.lib, where
25460 is the microcontroller identification number.
25461 The specific library is selected automatically by the compiler at link
25462 stage according to the selected device.
25465 \begin_layout Standard
25466 Libraries are created with gplib which is part of the gputils package
25467 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
25474 \begin_layout Subsubsection*
25475 Building the libraries
25478 \begin_layout Standard
25479 Before using SDCC/pic16 there are some libraries that need to be compiled.
25480 This process is not done automatically by SDCC since not all users use
25481 SDCC for pic16 projects.
25482 So each user should compile the libraries separately.
25485 \begin_layout Standard
25486 The steps to compile the pic16 libraries under Linux and Mac OS X are:
25489 \begin_layout LyX-Code
25490 cd device/lib/pic16
25493 \begin_layout LyX-Code
25497 \begin_layout LyX-Code
25501 \begin_layout LyX-Code
25505 \begin_layout LyX-Code
25509 \begin_layout LyX-Code
25510 su -c 'make install' # install the libraries, you need the root password
25513 \begin_layout Standard
25514 If you need to install the headers too, do:
25517 \begin_layout LyX-Code
25521 \begin_layout LyX-Code
25522 su -c 'make install' # install the headers, you need the root password
25525 \begin_layout Standard
25526 There exist a special target to build the I/O libraries.
25527 This target is not automatically build because it will build the I/O library
25533 This way building will take quite a lot of time.
25534 Users are advised to edit the
25536 device/lib/pic16/pics.build
25538 file and then execute:
25541 \begin_layout LyX-Code
25545 \begin_layout Subsection
25546 Adding New Devices to the Port
25549 \begin_layout Standard
25550 Adding support for a new 16
25554 \begin_layout Standard
25563 bit PIC MCU requires the following steps:
25566 \begin_layout Enumerate
25567 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
25571 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
25575 \begin_layout Enumerate
25578 mv picDEVICE.h /path/to/sdcc/device/include/pic16
25581 \begin_layout Enumerate
25584 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
25587 \begin_layout Enumerate
25590 /path/to/sdcc/device/lib/pics.all
25598 Note: No 18f prefix here!
25601 \begin_layout Enumerate
25604 /path/to/sdcc/device/lib/pic16/libio/*.ignore
25608 Add your DEVICE if it does not compile in
25623 \begin_layout Enumerate
25626 /path/to/sdcc/device/include/pic16/pic18fregs.h
25629 The file format is self-explanatory, just add
25633 #elif defined(picDEVICE)
25635 # include <picDEVICE.h>
25639 at the right place (keep it sorted).
25642 \begin_layout Enumerate
25645 /path/to/sdcc/src/pic16/devices.inc
25648 Copy and modify an existing entry and insert it at the correct place (keep
25650 The file is hardly documented, look at the entries for the 18f2221...
25653 \begin_layout Enumerate
25654 Recompile SDCC, including the pic16 libraries.
25657 \begin_layout Subsection
25661 \begin_layout Standard
25662 The following memory models are supported by the PIC16 port:
25665 \begin_layout Itemize
25669 \begin_layout Itemize
25673 \begin_layout Standard
25674 Memory model affects the default size of pointers within the source.
25675 The sizes are shown in the next table:
25678 \begin_layout Standard
25680 \begin_inset Tabular
25681 <lyxtabular version="3" rows="3" columns="3">
25683 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25684 <column alignment="center" valignment="top" leftline="true" width="0">
25685 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25686 <row topline="true" bottomline="true">
25687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25690 \begin_layout Standard
25691 Pointer sizes according to memory model
25696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25699 \begin_layout Standard
25705 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25708 \begin_layout Standard
25715 <row topline="true" bottomline="true">
25716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25719 \begin_layout Standard
25725 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25728 \begin_layout Standard
25734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25737 \begin_layout Standard
25744 <row topline="true" bottomline="true">
25745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25748 \begin_layout Standard
25754 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
25757 \begin_layout Standard
25763 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25766 \begin_layout Standard
25780 \begin_layout Standard
25781 It is advisable that all sources within a project are compiled with the
25783 If one wants to override the default memory model, this can be done by
25784 declaring a pointer as
25793 Far selects large memory model's pointers, while near selects small memory
25797 \begin_layout Standard
25798 The standard device libraries (see
25799 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
25803 ) contain no reference to pointers, so they can be used with both memory
25807 \begin_layout Subsection
25811 \begin_layout Standard
25813 \begin_inset LatexCommand \index{PIC16!stack}
25817 implementation for the PIC16 port uses two indirect registers, FSR1 and
25821 \begin_layout Description
25822 FSR1 is assigned as stack pointer
25825 \begin_layout Description
25826 FSR2 is assigned as frame pointer
25829 \begin_layout Standard
25830 The following stack models are supported by the PIC16 port
25833 \begin_layout Itemize
25841 \begin_layout Itemize
25849 \begin_layout Standard
25854 model means that only the FSRxL byte is used to access stack and frame,
25861 uses both FSRxL and FSRxH registers.
25862 The following table shows the stack/frame pointers sizes according to stack
25863 model and the maximum space they can address:
25866 \begin_layout Standard
25868 \begin_inset Tabular
25869 <lyxtabular version="3" rows="3" columns="3">
25871 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25872 <column alignment="center" valignment="top" leftline="true" width="0">
25873 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25874 <row topline="true" bottomline="true">
25875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25878 \begin_layout Standard
25879 Stack & Frame pointer sizes according to stack model
25884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25887 \begin_layout Standard
25893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25896 \begin_layout Standard
25903 <row topline="true">
25904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25907 \begin_layout Standard
25913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25916 \begin_layout Standard
25922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25925 \begin_layout Standard
25932 <row topline="true" bottomline="true">
25933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25936 \begin_layout Standard
25942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25945 \begin_layout Standard
25951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25954 \begin_layout Standard
25968 \begin_layout Standard
25973 stack model is currently not working properly throughout the code generator.
25974 So its use is not advised.
25975 Also there are some other points that need special care:
25980 \begin_layout Enumerate
25981 Do not create stack sections with size more than one physical bank (that
25985 \begin_layout Enumerate
25986 Stack sections should no cross physical bank limits (i.e.
25987 #pragma stack 0x50 0x100)
25990 \begin_layout Standard
25991 These limitations are caused by the fact that only FSRxL is modified when
25992 using SMALL stack model, so no more than 256 bytes of stack can be used.
25993 This problem will disappear after LARGE model is fully implemented.
25996 \begin_layout Subsection
26000 \begin_layout Standard
26001 In addition to the standard SDCC function keywords, PIC16
26002 \begin_inset LatexCommand \index{PIC16}
26006 port makes available two more:
26009 \begin_layout Description
26011 \begin_inset LatexCommand \index{PIC16!wparam}
26015 Use the WREG to pass one byte of the first function argument.
26016 This improves speed but you may not use this for functions with arguments
26017 that are called via function pointers, otherwise the first byte of the
26018 first parameter will get lost.
26022 \begin_layout LyX-Code
26023 void func_wparam(int a) wparam
26026 \begin_layout LyX-Code
26030 \begin_layout LyX-Code
26031 /* WREG hold the lower part of a */
26034 \begin_layout LyX-Code
26035 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
26039 \begin_layout LyX-Code
26043 \begin_layout LyX-Code
26047 \begin_layout Description
26049 \begin_inset LatexCommand \index{PIC16!shadowregs}
26053 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
26054 hardware shadow registers which hold the values of WREG, STATUS and BSR
26056 This can be done by adding the keyword
26064 keyword in the function's header.
26067 \begin_layout LyX-Code
26068 void isr_shadow(void) shadowregs interrupt 1
26071 \begin_layout LyX-Code
26075 \begin_layout LyX-Code
26079 \begin_layout LyX-Code
26083 \begin_layout Standard
26088 instructs the code generator not to store/restore WREG, STATUS, BSR when
26089 entering/exiting the ISR.
26092 \begin_layout Subsection
26093 Function return values
26096 \begin_layout Standard
26097 Return values from functions are placed to the appropriate registers following
26098 a modified Microchip policy optimized for SDCC.
26099 The following table shows these registers:
26102 \begin_layout Standard
26104 \begin_inset Tabular
26105 <lyxtabular version="3" rows="6" columns="2">
26107 <column alignment="center" valignment="top" leftline="true" width="0">
26108 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26109 <row topline="true" bottomline="true">
26110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26113 \begin_layout Standard
26119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26122 \begin_layout Standard
26123 destination register
26129 <row topline="true">
26130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26133 \begin_layout Standard
26139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26142 \begin_layout Standard
26149 <row topline="true">
26150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26153 \begin_layout Standard
26159 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26162 \begin_layout Standard
26169 <row topline="true">
26170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26173 \begin_layout Standard
26179 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26182 \begin_layout Standard
26189 <row topline="true">
26190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26193 \begin_layout Standard
26199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26202 \begin_layout Standard
26203 FSR0L:PRODH:PRODL:WREG
26209 <row topline="true" bottomline="true">
26210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26213 \begin_layout Standard
26219 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26222 \begin_layout Standard
26223 on stack, FSR0 points to the beginning
26236 \begin_layout Subsection
26240 \begin_layout Standard
26242 \begin_inset LatexCommand \index{PIC16!interrupt}
26246 service routine (ISR) is declared using the
26253 \begin_layout LyX-Code
26254 void isr(void) interrupt
26259 \begin_layout LyX-Code
26263 \begin_layout LyX-Code
26267 \begin_layout LyX-Code
26271 \begin_layout Standard
26276 is the interrupt number, which for PIC18F devices can be:
26279 \begin_layout Standard
26281 \begin_inset Tabular
26282 <lyxtabular version="3" rows="4" columns="3">
26284 <column alignment="center" valignment="top" leftline="true" width="0">
26285 <column alignment="center" valignment="top" leftline="true" width="0">
26286 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26287 <row topline="true" bottomline="true">
26288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26291 \begin_layout Standard
26299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26302 \begin_layout Standard
26308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26311 \begin_layout Standard
26312 Interrupt Vector Address
26318 <row topline="true">
26319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26322 \begin_layout Standard
26328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26331 \begin_layout Standard
26337 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26340 \begin_layout Standard
26347 <row topline="true">
26348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26351 \begin_layout Standard
26366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26369 \begin_layout Standard
26379 HIGH priority interrupts
26384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26387 \begin_layout Standard
26394 <row topline="true" bottomline="true">
26395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26398 \begin_layout Standard
26404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26407 \begin_layout Standard
26408 LOW priority interrupts
26413 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26416 \begin_layout Standard
26430 \begin_layout Standard
26431 When generating assembly code for ISR the code generator places a
26437 Interrupt Vector Address
26439 which points at the genetated ISR.
26440 This single GOTO instruction is part of an automatically generated
26442 interrupt entry point
26445 The actuall ISR code is placed as normally would in the code space.
26446 Upon interrupt request, the GOTO instruction is executed which jumps to
26448 When declaring interrupt functions as _naked this GOTO instruction is
26453 The whole interrupt functions is therefore placed at the Interrupt Vector
26454 Address of the specific interrupt.
26455 This is not a problem for the LOW priority interrupts, but it is a problem
26456 for the RESET and the HIGH priority interrupts because code may be written
26457 at the next interrupt's vector address and cause undeterminate program
26458 behaviour if that interrupt is raised.
26462 \begin_layout Standard
26463 This is not a problem when
26466 \begin_layout Enumerate
26467 this is a HIGH interrupt ISR and LOW interrupts are
26474 \begin_layout Enumerate
26475 when the ISR is small enough not to reach the next interrupt's vector address.
26483 \begin_layout Standard
26489 This way a function is generated similar to an ISR, but it is not assigned
26493 \begin_layout Standard
26494 When entering an interrupt, currently the PIC16
26495 \begin_inset LatexCommand \index{PIC16}
26499 port automatically saves the following registers:
26502 \begin_layout Itemize
26506 \begin_layout Itemize
26510 \begin_layout Itemize
26514 \begin_layout Itemize
26515 PROD (PRODL and PRODH)
26518 \begin_layout Itemize
26519 FSR0 (FSR0L and FSR0H)
26522 \begin_layout Standard
26523 These registers are restored upon return from the interrupt routine.
26527 \begin_layout Standard
26528 NOTE that when the _naked attribute is specified for an interrupt routine,
26529 then NO registers are stored or restored.
26537 \begin_layout Subsection
26541 \begin_layout Standard
26542 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
26543 There are 3 types of generic pointers currently implemented data, code
26544 and eeprom pointers.
26545 They are differentiated by the value of the 7th and 6th bits of the upper
26549 \begin_layout Standard
26551 \begin_inset Tabular
26552 <lyxtabular version="3" rows="5" columns="5">
26554 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26555 <column alignment="center" valignment="top" width="0">
26556 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26557 <column alignment="center" valignment="top" width="0">
26558 <column alignment="left" valignment="top" rightline="true" width="0">
26559 <row topline="true" bottomline="true">
26560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26563 \begin_layout Standard
26569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26572 \begin_layout Standard
26578 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26581 \begin_layout Standard
26587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26590 \begin_layout Standard
26591 rest of the pointer
26596 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26599 \begin_layout Standard
26606 <row topline="true" bottomline="true">
26607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26610 \begin_layout Standard
26616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26619 \begin_layout Standard
26625 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26628 \begin_layout Standard
26634 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26637 \begin_layout Standard
26642 uuuuuu uuuuxxxx xxxxxxxx
26647 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26650 \begin_layout Standard
26651 a 12-bit data pointer in data RAM memory
26657 <row bottomline="true">
26658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26661 \begin_layout Standard
26667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26670 \begin_layout Standard
26676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26679 \begin_layout Standard
26685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26688 \begin_layout Standard
26693 uxxxxx xxxxxxxx xxxxxxxx
26698 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26701 \begin_layout Standard
26702 a 21-bit code pointer in FLASH memory
26708 <row bottomline="true">
26709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26712 \begin_layout Standard
26718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26721 \begin_layout Standard
26727 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26730 \begin_layout Standard
26736 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26739 \begin_layout Standard
26744 uuuuuu uuuuuuxx xxxxxxxx
26749 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26752 \begin_layout Standard
26753 a 10-bit eeprom pointer in EEPROM memory
26759 <row bottomline="true">
26760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26763 \begin_layout Standard
26769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26772 \begin_layout Standard
26778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26781 \begin_layout Standard
26787 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26790 \begin_layout Standard
26795 xxxxxx xxxxxxxx xxxxxxxx
26800 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26803 \begin_layout Standard
26804 unimplemented pointer type
26817 \begin_layout Standard
26818 Generic pointer are read and written with a set of library functions which
26819 read/write 1, 2, 3, 4 bytes.
26822 \begin_layout Subsection
26826 \begin_layout Subsubsection
26827 Standard I/O Streams
26830 \begin_layout Standard
26835 the type FILE is defined as:
26838 \begin_layout LyX-Code
26839 typedef char * FILE;
26842 \begin_layout Standard
26843 This type is the stream type implemented I/O in the PIC18F devices.
26844 Also the standard input and output streams are declared in stdio.h:
26847 \begin_layout LyX-Code
26848 extern FILE * stdin;
26851 \begin_layout LyX-Code
26852 extern FILE * stdout;
26855 \begin_layout Standard
26856 The FILE type is actually a generic pointer which defines one more type
26857 of generic pointers, the
26862 This new type has the format:
26865 \begin_layout Standard
26867 \begin_inset Tabular
26868 <lyxtabular version="3" rows="2" columns="7">
26870 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26871 <column alignment="center" valignment="top" width="0">
26872 <column alignment="center" valignment="top" leftline="true" width="0">
26873 <column alignment="center" valignment="top" leftline="true" width="0">
26874 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26875 <column alignment="center" valignment="top" width="0">
26876 <column alignment="left" valignment="top" rightline="true" width="0">
26877 <row topline="true" bottomline="true">
26878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26881 \begin_layout Standard
26887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26890 \begin_layout Standard
26896 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26899 \begin_layout Standard
26905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26908 \begin_layout Standard
26914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26917 \begin_layout Standard
26923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26926 \begin_layout Standard
26927 rest of the pointer
26932 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26935 \begin_layout Standard
26942 <row topline="true" bottomline="true">
26943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26946 \begin_layout Standard
26952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26955 \begin_layout Standard
26961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26964 \begin_layout Standard
26970 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26973 \begin_layout Standard
26979 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26982 \begin_layout Standard
26988 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26991 \begin_layout Standard
27001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27004 \begin_layout Standard
27005 upper byte high nubble is 0x2n, the rest are zeroes
27018 \begin_layout Standard
27019 Currently implemented there are 3 types of streams defined:
27022 \begin_layout Standard
27024 \begin_inset Tabular
27025 <lyxtabular version="3" rows="4" columns="4">
27027 <column alignment="center" valignment="top" leftline="true" width="0">
27028 <column alignment="center" valignment="top" leftline="true" width="0">
27029 <column alignment="center" valignment="top" leftline="true" width="0">
27030 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27031 <row topline="true" bottomline="true">
27032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27035 \begin_layout Standard
27041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27044 \begin_layout Standard
27050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27053 \begin_layout Standard
27059 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27062 \begin_layout Standard
27069 <row topline="true">
27070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27073 \begin_layout Standard
27079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27082 \begin_layout Standard
27090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27093 \begin_layout Standard
27099 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27102 \begin_layout Standard
27103 Writes/Reads characters via the USART peripheral
27109 <row topline="true">
27110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27113 \begin_layout Standard
27119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27122 \begin_layout Standard
27130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27133 \begin_layout Standard
27139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27142 \begin_layout Standard
27143 Writes/Reads characters via the MSSP peripheral
27149 <row topline="true" bottomline="true">
27150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27153 \begin_layout Standard
27159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27162 \begin_layout Standard
27170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27173 \begin_layout Standard
27179 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27182 \begin_layout Standard
27183 Writes/Reads characters via used defined functions
27196 \begin_layout Standard
27197 The stream identifiers are declared as macros in the stdio.h header.
27200 \begin_layout Standard
27201 In the libc library there exist the functions that are used to write to
27202 each of the above streams.
27206 \begin_layout Description
27211 \begin_layout Standard
27220 _stream_usart_putchar writes a character at the USART stream
27223 \begin_layout Description
27228 \begin_layout Standard
27237 _stream_mssp_putchar writes a character at the MSSP stream
27240 \begin_layout Description
27241 putchar dummy function.
27242 This writes a character to a user specified manner.
27245 \begin_layout Standard
27246 In order to increase performance
27250 is declared in stdio.h as having its parameter in WREG (it has the wparam
27252 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
27253 in a user-friendly way.
27258 is the name of the variable that holds the character to print.
27259 An example follows:
27262 \begin_layout LyX-Code
27263 #include <pic18fregs.h>
27272 \begin_layout LyX-Code
27276 \begin_layout LyX-Code
27277 PORTA = c; /* dump character c to PORTA */
27280 \begin_layout LyX-Code
27288 \begin_layout LyX-Code
27292 \begin_layout LyX-Code
27293 stdout = STREAM_USER; /* this is not necessary, since stdout points
27296 \begin_layout LyX-Code
27297 * by default to STREAM_USER */
27300 \begin_layout LyX-Code
27302 \begin_inset Quotes sld
27305 This is a printf test
27308 \begin_inset Quotes srd
27314 \begin_layout LyX-Code
27318 \begin_layout LyX-Code
27322 \begin_layout Subsubsection
27326 \begin_layout Standard
27327 PIC16 contains an implementation of the printf-family of functions.
27328 There exist the following functions:
27331 \begin_layout LyX-Code
27332 extern unsigned int sprintf(char *buf, char *fmt, ...);
27335 \begin_layout LyX-Code
27336 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
27339 \begin_layout LyX-Code
27343 \begin_layout LyX-Code
27344 extern unsigned int printf(char *fmt, ...);
27347 \begin_layout LyX-Code
27348 extern unsigned int vprintf(char *fmt, va_lista ap);
27351 \begin_layout LyX-Code
27355 \begin_layout LyX-Code
27356 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
27359 \begin_layout LyX-Code
27360 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
27363 \begin_layout Standard
27364 For sprintf and vsprintf
27368 should normally be a data pointer where the resulting string will be placed.
27369 No range checking is done so the user should allocate the necessery buffer.
27370 For fprintf and vfprintf
27374 should be a stream pointer (i.e.
27375 stdout, STREAM_MSSP, etc...).
27378 \begin_layout Subsubsection
27382 \begin_layout Standard
27383 The PIC18F family of microcontrollers supports a number of interrupt sources.
27384 A list of these interrupts is shown in the following table:
27387 \begin_layout Standard
27389 \begin_inset Tabular
27390 <lyxtabular version="3" rows="11" columns="4">
27392 <column alignment="left" valignment="top" leftline="true" width="0">
27393 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27394 <column alignment="left" valignment="top" leftline="true" width="0">
27395 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27396 <row topline="true" bottomline="true">
27397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27400 \begin_layout Standard
27406 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27409 \begin_layout Standard
27415 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27418 \begin_layout Standard
27424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27427 \begin_layout Standard
27434 <row topline="true">
27435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27438 \begin_layout Standard
27444 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27447 \begin_layout Standard
27448 PORTB change interrupt
27453 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27456 \begin_layout Standard
27462 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27465 \begin_layout Standard
27466 EEPROM/FLASH write complete interrupt
27472 <row topline="true">
27473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27476 \begin_layout Standard
27482 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27485 \begin_layout Standard
27486 INT0 external interrupt
27491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27494 \begin_layout Standard
27500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27503 \begin_layout Standard
27504 Bus collision interrupt
27510 <row topline="true">
27511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27514 \begin_layout Standard
27520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27523 \begin_layout Standard
27524 INT1 external interrupt
27529 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27532 \begin_layout Standard
27538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27541 \begin_layout Standard
27542 Low voltage detect interrupt
27548 <row topline="true">
27549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27552 \begin_layout Standard
27558 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27561 \begin_layout Standard
27562 INT2 external interrupt
27567 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27570 \begin_layout Standard
27576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27579 \begin_layout Standard
27580 Parallel slave port interrupt
27586 <row topline="true">
27587 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27590 \begin_layout Standard
27596 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27599 \begin_layout Standard
27600 CCP1 module interrupt
27605 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27608 \begin_layout Standard
27614 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27617 \begin_layout Standard
27618 AD convertion complete interrupt
27624 <row topline="true">
27625 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27628 \begin_layout Standard
27634 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27637 \begin_layout Standard
27638 CCP2 module interrupt
27643 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27646 \begin_layout Standard
27652 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27655 \begin_layout Standard
27656 USART receive interrupt
27662 <row topline="true">
27663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27666 \begin_layout Standard
27672 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27675 \begin_layout Standard
27676 TMR0 overflow interrupt
27681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27684 \begin_layout Standard
27690 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27693 \begin_layout Standard
27694 USART transmit interrupt
27700 <row topline="true">
27701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27704 \begin_layout Standard
27710 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27713 \begin_layout Standard
27714 TMR1 overflow interrupt
27719 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27722 \begin_layout Standard
27728 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27731 \begin_layout Standard
27732 SSP receive/transmit interrupt
27738 <row topline="true">
27739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27742 \begin_layout Standard
27748 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27751 \begin_layout Standard
27752 TMR2 matches PR2 interrupt
27757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27760 \begin_layout Standard
27766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27769 \begin_layout Standard
27776 <row topline="true" bottomline="true">
27777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27780 \begin_layout Standard
27786 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27789 \begin_layout Standard
27790 TMR3 overflow interrupt
27795 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27798 \begin_layout Standard
27804 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27807 \begin_layout Standard
27821 \begin_layout Standard
27822 The prototypes for these names are defined in the header file
27829 \begin_layout Standard
27830 In order to simplify signal handling, a number of macros is provided:
27834 \labelwidthstring 00.00.0000
27835 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
27836 high priority interrupts.
27841 is the function name to use.
27845 \labelwidthstring 00.00.0000
27846 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
27847 low priority interrupt.
27852 is the function name to use.
27856 \labelwidthstring 00.00.0000
27857 DEF_HANDLER(sig,handler) define a handler for signal
27863 \labelwidthstring 00.00.0000
27864 END_DEF end the declaration of the dispatch table.
27867 \begin_layout Standard
27868 Additionally there are two more macros to simplify the declaration of the
27873 \labelwidthstring 00.00.0000
27876 SIGHANDLER(handler)
27878 this declares the function prototype for the
27886 \labelwidthstring 00.00.0000
27887 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
27890 \begin_layout Standard
27891 An example of using the macros above is shown below:
27894 \begin_layout LyX-Code
27895 #include <pic18fregs.h>
27898 \begin_layout LyX-Code
27899 #include <signal.h>
27903 DEF_INTHIGH(high_int)
27906 \begin_layout LyX-Code
27907 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
27910 \begin_layout LyX-Code
27911 DEF_HANDLER(SIG_BCOL, _bcol_handler)
27914 \begin_layout LyX-Code
27919 SIGHANDLER(_tmr0_handler)
27922 \begin_layout LyX-Code
27926 \begin_layout LyX-Code
27927 /* action to be taken when timer 0 overflows */
27930 \begin_layout LyX-Code
27935 SIGHANDLERNAKED(_bcol_handler)
27938 \begin_layout LyX-Code
27942 \begin_layout LyX-Code
27946 \begin_layout LyX-Code
27947 /* action to be taken when bus collision occurs */
27950 \begin_layout LyX-Code
27954 \begin_layout LyX-Code
27958 \begin_layout LyX-Code
27962 \begin_layout Standard
27967 Special care should be taken when using the above scheme:
27970 \begin_layout Itemize
27971 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
27974 \begin_layout Itemize
27975 when declaring SIGHANDLERNAKED handler never forget to use
27979 for proper returning.
27982 \begin_layout Subsection
27986 \begin_layout Standard
27987 Here you can find some general tips for compiling programs with SDCC/pic16.
27990 \begin_layout Subsubsection
27994 \begin_layout Standard
27996 \begin_inset LatexCommand \index{PIC16!stack}
28000 size (that is 64 bytes) probably is enough for many programs.
28001 One must take care that when there are many levels of function nesting,
28002 or there is excessive usage of stack, its size should be extended.
28003 An example of such a case is the printf/sprintf family of functions.
28004 If you encounter problems like not being able to print integers, then you
28005 need to set the stack size around the maximum (256 for small stack model).
28006 The following diagram shows what happens when calling printf to print an
28010 \begin_layout LyX-Code
28011 printf () --> ltoa () --> ultoa () --> divschar ()
28014 \begin_layout Standard
28015 It is should be understood that stack is easily consumed when calling complicate
28017 Using command line arguments like -
28021 \begin_layout Standard
28030 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
28032 Other ways to reduce stack usage may exist.
28035 \begin_layout Subsection
28039 \begin_layout Standard
28040 The PIC16 Port currently does not pass SDCC's regression test
28041 \begin_inset LatexCommand \index{Regression test (PIC16)}
28046 \begin_inset LatexCommand \ref{sec:Quality-control}
28050 ) and thus the snapshot build regression tests for the PIC16 target are
28051 currently disabled for all hosts
28056 \begin_layout Chapter
28060 \begin_layout Standard
28061 There are several approaches to debugging your code.
28062 This chapter is meant to show your options and to give detail on some of
28067 When writing your code:
28070 \begin_layout Itemize
28071 write your code with debugging in mind (avoid duplicating code, put conceptually
28072 similar variables into structs, use structured code, have strategic points
28073 within your code where all variables are consistent, ...)
28076 \begin_layout Itemize
28077 run a syntax-checking tool like splint
28078 \begin_inset LatexCommand \index{splint (syntax checking tool)}
28083 \begin_inset LatexCommand \index{lint (syntax checking tool)}
28091 \begin_layout Standard
28101 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28108 \begin_layout Itemize
28109 for the high level code use a C-compiler (like f.e.
28110 GCC) to compile run and debug the code on your host.
28115 \begin_layout Standard
28125 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28129 ) on how to handle syntax extensions like __xdata, __at(), ...
28133 \begin_layout Itemize
28134 use another C-compiler to compile code for your target.
28135 Always an option but not recommended:) And not very likely to help you.
28136 If you seriously consider walking this path you should at least occasionally
28137 check portability of your code.
28138 Most commercial compiler vendors will offer an evaluation version so you
28139 can test compile your code or snippets of your code.
28142 \begin_layout Standard
28143 Debugging on a simulator:
28146 \begin_layout Itemize
28147 there is a separate section about SDCDB (section
28148 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
28155 \begin_layout Itemize
28156 or (8051 specific) use a freeware/commercial simulator which interfaces
28158 \begin_inset LatexCommand \index{AOMF, AOMF51}
28163 \begin_inset LatexCommand \ref{OMF file}
28167 ) optionally generated by SDCC.
28170 \begin_layout Standard
28171 Debugging On-target:
28174 \begin_layout Itemize
28175 use a MCU port pin to serially output debug data to the RS232 port of your
28177 You'll probably want some level shifting device typically involving a MAX232
28179 If the hardware serial port of the MCU is not available search for 'Software
28180 UART' in your favourite search machine.
28183 \begin_layout Itemize
28184 use an on-target monitor.
28185 In this context a monitor is a small program which usually accepts commands
28186 via a serial line and allows to set program counter, to single step through
28187 a program and read/write memory locations.
28188 For the 8051 good examples of monitors are paulmon and cmon51 (see section
28190 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
28197 \begin_layout Itemize
28198 toggle MCU port pins at strategic points within your code and use an oscilloscop
28202 digital oscilloscope
28205 \begin_inset LatexCommand \index{Oscilloscope}
28209 with deep trace memory is really helpful especially if you have to debug
28210 a realtime application.
28211 If you need to monitor more pins than your oscilloscope provides you can
28212 sometimes get away with a small R-2R network.
28213 On a single channel oscilloscope you could f.e.
28214 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
28216 \begin_inset Formula $\Omega$
28219 resistor and the other one by a 5\InsetSpace ~
28221 \begin_inset Formula $\Omega$
28224 resistor to the oscilloscope probe (check output drive capability of the
28225 pins you want to monitor).
28226 If you need to monitor many more pins a
28233 \begin_layout Itemize
28247 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
28252 Usually very expensive.
28253 And very nice to have too.
28254 And usually locks you (for years...) to the devices the ICE can emulate.
28258 \begin_layout Itemize
28259 use a remote debugger.
28260 In most 8-bit systems the symbol information is not available on the target,
28261 and a complete debugger is too bulky for the target system.
28262 Therefore usually a debugger on the host system connects to an on-target
28263 debugging stub which accepts only primitive commands.
28266 Terms to enter into your favourite search engine could be 'remote debugging',
28267 'gdb stub' or 'inferior debugger'.
28271 \begin_layout Itemize
28272 use an on target hardware debugger.
28273 Some of the more modern MCUs include hardware support for setting break
28274 points and monitoring/changing variables by using dedicated hardware pins.
28275 This facility doesn't require additional code to run on the target and
28280 doesn't affect runtime behaviour until a breakpoint is hit.
28281 For the mcs51 most hardware debuggers use the AOMF
28282 \begin_inset LatexCommand \index{AOMF, AOMF51}
28287 \begin_inset LatexCommand \ref{OMF file}
28295 \begin_layout Standard
28299 \begin_layout Itemize
28300 if you are not familiar with any of the following terms you're likely to
28301 run into problems rather sooner than later:
28318 As an embedded programmer you
28322 to know them so why not look them up
28326 you have problems?)
28329 \begin_layout Itemize
28330 tell someone else about your problem (actually this is a surprisingly effective
28331 means to hunt down the bug even if the listener is not familiar with your
28333 As 'failure to communicate' is probably one of the job-induced deformations
28334 of an embedded programmer this is highly encouraged.
28337 \begin_layout Section
28338 Debugging with SDCDB
28339 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
28344 \begin_inset LatexCommand \index{SDCDB (debugger)}
28351 \begin_layout Standard
28352 SDCC is distributed with a source level debugger
28353 \begin_inset LatexCommand \index{Debugger}
28358 The debugger uses a command line interface, the command repertoire of the
28359 debugger has been kept as close to gdb
28360 \begin_inset LatexCommand \index{gdb}
28364 (the GNU debugger) as possible.
28365 The configuration and build process is part of the standard compiler installati
28366 on, which also builds and installs the debugger in the target directory
28367 specified during configuration.
28368 The debugger allows you debug BOTH at the C source and at the ASM source
28372 \begin_layout Subsection
28373 Compiling for Debugging
28376 \begin_layout Standard
28381 \begin_layout Standard
28391 \begin_inset LatexCommand \index{-\/-debug}
28395 option must be specified for all files for which debug information is to
28397 The compiler generates a .adb file for each of these files.
28398 The linker creates the .cdb
28399 \begin_inset LatexCommand \index{<file>.cdb}
28404 \begin_inset LatexCommand \index{<file>.adb}
28408 files and the address information.
28409 This .cdb is used by the debugger.
28412 \begin_layout Subsection
28413 How the Debugger Works
28416 \begin_layout Standard
28421 \begin_layout Standard
28430 -debug option is specified the compiler generates extra symbol information
28431 some of which are put into the assembler source and some are put into the
28433 Then the linker creates the .cdb file from the individual .adb files with
28434 the address information for the symbols.
28435 The debugger reads the symbolic information generated by the compiler &
28436 the address information generated by the linker.
28437 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
28438 execution is controlled by the debugger.
28439 When a command is issued for the debugger, it translates it into appropriate
28440 commands for the simulator.
28441 (Currently SDCDM only connects to the simulator but
28446 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
28450 is an effort to connect directly to the hardware.)
28453 \begin_layout Subsection
28454 Starting the Debugger SDCDB
28457 \begin_layout Standard
28458 The debugger can be started using the following command line.
28459 (Assume the file you are debugging has the file name foo).
28473 The debugger will look for the following files.
28476 \begin_layout Itemize
28477 foo.c - the source file.
28480 \begin_layout Itemize
28481 foo.cdb - the debugger symbol information file.
28484 \begin_layout Itemize
28485 foo.ihx - the Intel hex format
28486 \begin_inset LatexCommand \index{Intel hex format}
28493 \begin_layout Subsection
28494 SDCDB Command Line Options
28497 \begin_layout Itemize
28502 \begin_layout Standard
28511 -directory=<source file directory> this option can used to specify the directory
28513 The debugger will look into the directory list specified for source, cdb
28515 The items in the directory list must be separated by ':', e.g.
28516 if the source files can be in the directories /home/src1 and /home/src2,
28521 \begin_layout Standard
28530 -directory option should be -
28534 \begin_layout Standard
28543 -directory=/home/src1:/home/src2.
28544 Note there can be no spaces in the option.
28548 \begin_layout Itemize
28549 -cd <directory> - change to the <directory>.
28552 \begin_layout Itemize
28553 -fullname - used by GUI front ends.
28556 \begin_layout Itemize
28557 -cpu <cpu-type> - this argument is passed to the simulator please see the
28558 simulator docs for details.
28561 \begin_layout Itemize
28562 -X <Clock frequency > this options is passed to the simulator please see
28563 the simulator docs for details.
28566 \begin_layout Itemize
28567 -s <serial port file> passed to simulator see the simulator docs for details.
28570 \begin_layout Itemize
28571 -S <serial in,out> passed to simulator see the simulator docs for details.
28574 \begin_layout Itemize
28575 -k <port number> passed to simulator see the simulator docs for details.
28578 \begin_layout Subsection
28579 SDCDB Debugger Commands
28582 \begin_layout Standard
28583 As mentioned earlier the command interface for the debugger has been deliberatel
28584 y kept as close the GNU debugger gdb, as possible.
28585 This will help the integration with existing graphical user interfaces
28586 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
28587 If you use a graphical user interface for the debugger you can skip this
28591 \begin_layout Subsubsection*
28592 break [line | file:line | function | file:function]
28595 \begin_layout Standard
28596 Set breakpoint at specified line or function:
28605 sdcdb>break foo.c:100
28607 sdcdb>break funcfoo
28609 sdcdb>break foo.c:funcfoo
28612 \begin_layout Subsubsection*
28613 clear [line | file:line | function | file:function ]
28616 \begin_layout Standard
28617 Clear breakpoint at specified line or function:
28626 sdcdb>clear foo.c:100
28628 sdcdb>clear funcfoo
28630 sdcdb>clear foo.c:funcfoo
28633 \begin_layout Subsubsection*
28637 \begin_layout Standard
28638 Continue program being debugged, after breakpoint.
28641 \begin_layout Subsubsection*
28645 \begin_layout Standard
28646 Execute till the end of the current function.
28649 \begin_layout Subsubsection*
28653 \begin_layout Standard
28654 Delete breakpoint number 'n'.
28655 If used without any option clear ALL user defined break points.
28658 \begin_layout Subsubsection*
28659 info [break | stack | frame | registers ]
28662 \begin_layout Itemize
28663 info break - list all breakpoints
28666 \begin_layout Itemize
28667 info stack - show the function call stack.
28670 \begin_layout Itemize
28671 info frame - show information about the current execution frame.
28674 \begin_layout Itemize
28675 info registers - show content of all registers.
28678 \begin_layout Subsubsection*
28682 \begin_layout Standard
28683 Step program until it reaches a different source line.
28684 Note: pressing <return> repeats the last command.
28687 \begin_layout Subsubsection*
28691 \begin_layout Standard
28692 Step program, proceeding through subroutine calls.
28695 \begin_layout Subsubsection*
28699 \begin_layout Standard
28700 Start debugged program.
28703 \begin_layout Subsubsection*
28707 \begin_layout Standard
28708 Print type information of the variable.
28711 \begin_layout Subsubsection*
28715 \begin_layout Standard
28716 print value of variable.
28719 \begin_layout Subsubsection*
28723 \begin_layout Standard
28724 load the given file name.
28725 Note this is an alternate method of loading file for debugging.
28728 \begin_layout Subsubsection*
28732 \begin_layout Standard
28733 print information about current frame.
28736 \begin_layout Subsubsection*
28740 \begin_layout Standard
28741 Toggle between C source & assembly source.
28744 \begin_layout Subsubsection*
28745 ! simulator command
28748 \begin_layout Standard
28749 Send the string following '!' to the simulator, the simulator response is
28751 Note the debugger does not interpret the command being sent to the simulator,
28752 so if a command like 'go' is sent the debugger can loose its execution
28753 context and may display incorrect values.
28756 \begin_layout Subsubsection*
28760 \begin_layout Standard
28763 My name is Bobby Brown"
28766 \begin_layout Subsection
28767 Interfacing SDCDB with DDD
28770 \begin_layout Standard
28771 \begin_inset Note Note
28774 \begin_layout Standard
28775 The screenshot was converted from png to eps with:
28776 \begin_inset Quotes sld
28779 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
28780 \begin_inset Quotes srd
28783 which produces a pretty compact eps file which is free from compression
28787 \begin_layout Standard
28788 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
28789 as this broke the build system on Sourceforge (pdf-file was broken.
28790 pdflatex does not accept eps files).
28798 \begin_layout Standard
28814 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
28820 shows a screenshot of a debugging session with DDD
28821 \begin_inset LatexCommand \index{DDD (debugger)}
28825 (Unix only) on a simulated 8032.
28826 The debugging session might not run as smoothly as the screenshot suggests.
28827 The debugger allows setting of breakpoints, displaying and changing variables,
28828 single stepping through C and assembler code.
28831 The source was compiled with
28845 \begin_layout Standard
28857 -debug ddd_example.c
28870 and DDD was invoked with
28877 ddd -debugger "sdcdb -cpu 8032 ddd_example"
28880 \begin_layout Standard
28881 \begin_inset Note Note
28884 \begin_layout Standard
28885 Check that the double quotes or an apostroph within the command line survive
28886 the LyX tool chain.
28887 Previously the apostrophs got slanted in the PDF output so a cut and paste
28896 \begin_layout Subsection
28897 Interfacing SDCDB with XEmacs
28898 \begin_inset LatexCommand \index{XEmacs}
28903 \begin_inset LatexCommand \index{Emacs}
28910 \begin_layout Standard
28911 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
28912 sdcdb.el and sdcdbsrc.el.
28913 These two files can be found in the $(prefix)/bin directory after the installat
28915 These files need to be loaded into XEmacs for the interface to work.
28916 This can be done at XEmacs startup time by inserting the following into
28917 your '.xemacs' file (which can be found in your HOME directory):
28923 (load-file sdcdbsrc.el)
28929 .xemacs is a lisp file so the () around the command is REQUIRED.
28930 The files can also be loaded dynamically while XEmacs is running, set the
28931 environment variable 'EMACSLOADPATH' to the installation bin directory
28932 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
28933 To start the interface enter the following command:
28947 You will prompted to enter the file name to be debugged.
28952 The command line options that are passed to the simulator directly are
28953 bound to default values in the file sdcdbsrc.el.
28954 The variables are listed below, these values maybe changed as required.
28957 \begin_layout Itemize
28958 sdcdbsrc-cpu-type '51
28961 \begin_layout Itemize
28962 sdcdbsrc-frequency '11059200
28965 \begin_layout Itemize
28966 sdcdbsrc-serial nil
28969 \begin_layout Standard
28970 The following is a list of key mapping for the debugger interface.
28973 \begin_layout Standard
28996 binding\InsetSpace ~
29034 -------\InsetSpace ~
29105 sdcdb-back-from-src\InsetSpace ~
29134 rom-src\InsetSpace ~
29144 SDCDB continue command
29162 sdcdb-step-from-src\InsetSpace ~
29191 hatis-c-sexp\InsetSpace ~
29201 SDCDB ptypecommand for data at
29268 sdcdbsrc-delete\InsetSpace ~
29283 B Delete all breakpoints if no arg
29332 given or delete arg (C-u arg x)
29351 -frame\InsetSpace ~
29366 SDCDB Display current frame if no arg,
29415 given or display frame arg
29483 sdcdbsrc-goto-sdcdb\InsetSpace ~
29493 Goto the SDCDB output buffer
29512 t-c-sexp\InsetSpace ~
29523 SDCDB print command for data at
29590 sdcdbsrc-goto-sdcdb\InsetSpace ~
29601 o the SDCDB output buffer
29619 sdcdbsrc-mode\InsetSpace ~
29635 Toggles Sdcdbsrc mode (turns it
29651 sdcdb-finish-from-src\InsetSpace ~
29659 SDCDB finish command
29693 Set break for line with point
29708 sdcdbsrc-mode\InsetSpace ~
29724 Toggle Sdcdbsrc mode
29740 dbsrc-srcmode\InsetSpace ~
29764 \begin_layout Chapter
29768 \begin_layout Standard
29769 Here are a few guidelines that will help the compiler generate more efficient
29770 code, some of the tips are specific to this compiler others are generally
29771 good programming practice.
29774 \begin_layout Itemize
29775 Use the smallest data type to represent your data-value.
29776 If it is known in advance that the value is going to be less than 256 then
29777 use an 'unsigned char' instead of a 'short' or 'int'.
29778 Please note, that ANSI C requires both signed and unsigned chars to be
29779 promoted to 'signed int'
29780 \begin_inset LatexCommand \index{promotion to signed int}
29785 \begin_inset Marginal
29788 \begin_layout Standard
29797 before doing any operation.
29799 \begin_inset LatexCommand \index{type promotion}
29804 \begin_inset LatexCommand \label{type promotion}
29808 can be omitted, if the result is the same.
29809 The effect of the promotion rules together with the sign-extension is often
29814 \begin_layout Verse
29817 unsigned char uc = 0xfe;
29819 if (uc * uc < 0) /* this is true! */
29832 \begin_layout Standard
29839 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
29847 \begin_layout Verse
29850 (unsigned char) -12 / (signed char) -3 = ...
29853 \begin_layout Standard
29854 No, the result is not 4:
29857 \begin_layout Verse
29860 (int) (unsigned char) -12 / (int) (signed char) -3 =
29862 (int) (unsigned char)
29863 0xf4 / (int) (signed char) 0xfd =
29865 (int) 0x00f4 / (int) 0xfffd =
29870 (int) 244 / (int) -3 =
29872 (int) -81 = (int) 0xffaf;
29875 \begin_layout Standard
29876 Don't complain, that gcc gives you a different result.
29877 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
29878 Therefore the results are different.
29881 \begin_inset Quotes sld
29885 \begin_inset Quotes srd
29891 \begin_layout Quote
29894 If well-defined overflow characteristics are important and negative values
29895 are not, or if you want to steer clear of sign-extension problems when
29896 manipulating bits or bytes, use one of the corresponding unsigned types.
29897 (Beware when mixing signed and unsigned values in expressions, though.)
29900 character types (especially unsigned char) can be used as "tiny" integers,
29901 doing so is sometimes more trouble than it's worth, due to unpredictable
29902 sign extension and increased code size.
29906 \begin_layout Itemize
29907 Use unsigned when it is known in advance that the value is not going to
29909 This helps especially if you are doing division or multiplication, bit-shifting
29910 or are using an array index.
29913 \begin_layout Itemize
29914 NEVER jump into a LOOP.
29917 \begin_layout Itemize
29918 Declare the variables to be local
29919 \begin_inset LatexCommand \index{local variables}
29923 whenever possible, especially loop control variables (induction).
29926 \begin_layout Itemize
29927 Have a look at the assembly listing to get a
29928 \begin_inset Quotes sld
29932 \begin_inset Quotes srd
29935 for the code generation.
29938 \begin_layout Section
29939 Porting code from or to other compilers
29940 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
29947 \begin_layout Itemize
29948 check whether endianness of the compilers differs and adapt where needed.
29951 \begin_layout Itemize
29952 check the device specific header files
29953 \begin_inset LatexCommand \index{Header files}
29958 \begin_inset LatexCommand \index{Include files}
29962 for compiler specific syntax.
29963 Eventually include the file <compiler.h
29964 \begin_inset LatexCommand \index{compiler.h (include file)}
29969 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
29973 to allow using common header files.
29976 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
29983 \begin_layout Itemize
29984 check whether the startup code contains the correct initialization (watchdog,
29988 \begin_layout Itemize
29989 check whether the sizes of short, int, long match.
29992 \begin_layout Itemize
29993 check if some 16 or 32 bit hardware registers require a specific addressing
29994 order (least significant or most significant byte first) and adapt if needed
30003 relate to time and not to lower/upper memory location here, so this is
30008 the same as endianness).
30011 \begin_layout Itemize
30012 check whether the keyword
30016 is used where needed.
30017 The compilers might differ in their optimization characteristics (as different
30018 versions of the same compiler might also use more clever optimizations
30019 this is good idea anyway).
30021 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
30028 \begin_layout Itemize
30029 check that the compilers are not told to supress warnings.
30032 \begin_layout Itemize
30033 check and convert compiler specific extensions (interrupts, memory areas,
30037 \begin_layout Itemize
30038 check for differences in type promotion.
30039 Especially check for math operations on
30048 For the sake of C99 compatibility SDCC will probably promote these to
30052 more often than other compilers.
30053 Eventually insert explicit casts to
30062 Also check that the ~\InsetSpace ~
30064 \begin_inset LatexCommand \index{\~\/ Operator}
30071 \begin_inset LatexCommand \index{bit}
30077 variables, use the !\InsetSpace ~
30080 \begin_inset LatexCommand \ref{type promotion}
30085 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30092 \begin_layout Itemize
30093 check the assembly code generated for interrupt routines (f.e.
30094 for calls to possibly non-reentrant library functions).
30097 \begin_layout Itemize
30098 check whether timing loops result in proper timing (or preferably consider
30099 a rewrite of the code with timer based delays instead).
30102 \begin_layout Itemize
30103 check for differences in printf parameters (some compilers push (va_arg
30104 \begin_inset LatexCommand \index{vararg, va\_arg}
30108 ) char variables as
30112 others push them as
30118 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30125 \begin_layout Itemize
30126 check the resulting memory map
30127 \begin_inset LatexCommand \index{Memory map}
30132 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
30133 ly idata, pdata, xdata).
30134 Eventually check if unexpected library functions are included.
30137 \begin_layout Section
30139 \begin_inset LatexCommand \index{Tools}
30143 included in the distribution
30146 \begin_layout Standard
30148 \begin_inset Tabular
30149 <lyxtabular version="3" rows="12" columns="3">
30151 <column alignment="left" valignment="top" leftline="true" width="0pt">
30152 <column alignment="left" valignment="top" leftline="true" width="0pt">
30153 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30154 <row topline="true" bottomline="true">
30155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30158 \begin_layout Standard
30166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30169 \begin_layout Standard
30177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30180 \begin_layout Standard
30189 <row topline="true">
30190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30193 \begin_layout Standard
30195 \begin_inset LatexCommand \index{uCsim}
30204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30207 \begin_layout Standard
30208 Simulator for various architectures
30213 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30216 \begin_layout Standard
30223 <row topline="true">
30224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30227 \begin_layout Standard
30233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30236 \begin_layout Standard
30238 \begin_inset LatexCommand \index{Header files}
30243 \begin_inset LatexCommand \index{Include files}
30252 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30255 \begin_layout Standard
30256 sdcc/support/scripts
30262 <row topline="true">
30263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30266 \begin_layout Standard
30272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30275 \begin_layout Standard
30276 header file conversion
30281 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30284 \begin_layout Standard
30285 sdcc/support/scripts
30291 <row topline="true">
30292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30295 \begin_layout Standard
30301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30304 \begin_layout Standard
30310 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30313 \begin_layout Standard
30329 <row topline="true">
30330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30333 \begin_layout Standard
30339 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30342 \begin_layout Standard
30348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30351 \begin_layout Standard
30367 <row topline="true">
30368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30371 \begin_layout Standard
30377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30380 \begin_layout Standard
30386 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30389 \begin_layout Standard
30405 <row topline="true">
30406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30409 \begin_layout Standard
30415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30418 \begin_layout Standard
30424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30427 \begin_layout Standard
30443 <row topline="true">
30444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30447 \begin_layout Standard
30453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30456 \begin_layout Standard
30462 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30465 \begin_layout Standard
30481 <row topline="true">
30482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30485 \begin_layout Standard
30491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30494 \begin_layout Standard
30500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30503 \begin_layout Standard
30519 <row topline="true">
30520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30523 \begin_layout Standard
30529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30532 \begin_layout Standard
30538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30541 \begin_layout Standard
30557 <row topline="true" bottomline="true">
30558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30561 \begin_layout Standard
30567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30570 \begin_layout Standard
30572 \begin_inset LatexCommand \index{packihx (tool)}
30581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30584 \begin_layout Standard
30609 \begin_layout Section
30611 \begin_inset LatexCommand \index{Documentation}
30615 included in the distribution
30618 \begin_layout Standard
30620 \begin_inset Tabular
30621 <lyxtabular version="3" rows="10" columns="2">
30623 <column alignment="block" valignment="top" leftline="true" width="40col%">
30624 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
30625 <row topline="true" bottomline="true" endhead="true">
30626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30629 \begin_layout Standard
30637 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30640 \begin_layout Standard
30643 Filename / Where to get
30649 <row topline="true">
30650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30653 \begin_layout Standard
30654 SDCC Compiler User Guide
30659 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30662 \begin_layout Standard
30663 You're reading it right now
30675 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
30685 <row topline="true">
30686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30689 \begin_layout Standard
30695 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30698 \begin_layout Standard
30711 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
30721 <row topline="true">
30722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30725 \begin_layout Standard
30727 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
30732 \begin_inset LatexCommand \index{Assembler documentation}
30739 \begin_inset LatexCommand \index{aslink}
30744 \begin_inset LatexCommand \index{Linker documentation}
30753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30756 \begin_layout Standard
30757 sdcc/as/doc/asxhtm.html
30769 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
30779 <row topline="true">
30780 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30783 \begin_layout Standard
30784 SDCC regression test
30785 \begin_inset LatexCommand \index{Regression test}
30794 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30797 \begin_layout Standard
30798 sdcc/doc/test_suite_spec.pdf
30810 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30820 <row topline="true">
30821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30824 \begin_layout Standard
30830 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30833 \begin_layout Standard
30846 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
30856 <row topline="true">
30857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30860 \begin_layout Standard
30861 Notes on debugging with SDCDB
30862 \begin_inset LatexCommand \index{SDCDB (debugger)}
30871 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30874 \begin_layout Standard
30875 sdcc/debugger/README
30887 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
30897 <row topline="true">
30898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30901 \begin_layout Standard
30903 \begin_inset LatexCommand \index{uCsim}
30907 Software simulator for microcontrollers
30912 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30915 \begin_layout Standard
30945 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
30955 <row topline="true">
30956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30959 \begin_layout Standard
30960 Temporary notes on the pic16
30961 \begin_inset LatexCommand \index{PIC16}
30970 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30973 \begin_layout Standard
30974 sdcc/src/pic16/NOTES
30986 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
30996 <row topline="true" bottomline="true">
30997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31000 \begin_layout Standard
31001 SDCC internal documentation (debugging file format)
31006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31009 \begin_layout Standard
31039 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
31058 \begin_layout Section
31059 Related open source tools
31060 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
31065 \begin_inset LatexCommand \index{Related tools}
31072 \begin_layout Standard
31074 \begin_inset Tabular
31075 <lyxtabular version="3" rows="16" columns="3">
31077 <column alignment="left" valignment="top" leftline="true" width="0pt">
31078 <column alignment="block" valignment="top" leftline="true" width="30line%">
31079 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
31080 <row topline="true" bottomline="true">
31081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31084 \begin_layout Standard
31092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31095 \begin_layout Standard
31103 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31106 \begin_layout Standard
31115 <row topline="true">
31116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31119 \begin_layout Standard
31121 \begin_inset LatexCommand \index{gpsim (pic simulator)}
31130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31133 \begin_layout Standard
31139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31142 \begin_layout Standard
31143 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
31153 <row topline="true">
31154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31157 \begin_layout Standard
31159 \begin_inset LatexCommand \index{gputils (pic tools)}
31168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31171 \begin_layout Standard
31177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31180 \begin_layout Standard
31181 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
31191 <row topline="true">
31192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31195 \begin_layout Standard
31201 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31204 \begin_layout Standard
31210 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31213 \begin_layout Standard
31214 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
31224 <row topline="true">
31225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31228 \begin_layout Standard
31234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31237 \begin_layout Standard
31238 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
31244 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31247 \begin_layout Standard
31248 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
31258 <row topline="true">
31259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31262 \begin_layout Standard
31264 \begin_inset LatexCommand \index{indent (source formatting tool)}
31273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31276 \begin_layout Standard
31277 Formats C source - Master of the white spaces
31282 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31285 \begin_layout Standard
31286 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
31296 <row topline="true">
31297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31300 \begin_layout Standard
31302 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
31311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31314 \begin_layout Standard
31315 Object file conversion, checksumming, ...
31320 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31323 \begin_layout Standard
31324 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
31334 <row topline="true">
31335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31338 \begin_layout Standard
31340 \begin_inset LatexCommand \index{objdump (tool)}
31349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31352 \begin_layout Standard
31353 Object file conversion, ...
31358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31361 \begin_layout Standard
31362 Part of binutils (should be there anyway)
31368 <row topline="true">
31369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31372 \begin_layout Standard
31378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31381 \begin_layout Standard
31382 8051 monitor (hex up-/download, single step, disassemble)
31387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31390 \begin_layout Standard
31391 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
31401 <row topline="true">
31402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31405 \begin_layout Standard
31407 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
31416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31419 \begin_layout Standard
31420 Source code documentation system
31425 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31428 \begin_layout Standard
31429 \begin_inset LatexCommand \url{http://www.doxygen.org}
31439 <row topline="true">
31440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31443 \begin_layout Standard
31449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31452 \begin_layout Standard
31453 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
31458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31461 \begin_layout Standard
31462 \begin_inset LatexCommand \url{http://www.kdevelop.org}
31472 <row topline="true">
31473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31476 \begin_layout Standard
31482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31485 \begin_layout Standard
31486 8051 monitor (hex up-/download, single step, disassemble)
31491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31494 \begin_layout Standard
31495 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
31505 <row topline="true">
31506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31509 \begin_layout Standard
31511 \begin_inset LatexCommand \index{splint (syntax checking tool)}
31520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31523 \begin_layout Standard
31524 Statically checks c sources (see
31525 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
31534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31537 \begin_layout Standard
31538 \begin_inset LatexCommand \url{http://www.splint.org}
31548 <row topline="true" bottomline="true">
31549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31552 \begin_layout Standard
31554 \begin_inset LatexCommand \index{DDD (debugger)}
31563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31566 \begin_layout Standard
31567 Debugger, serves nicely as GUI to SDCDB
31568 \begin_inset LatexCommand \index{SDCDB (debugger)}
31577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31580 \begin_layout Standard
31581 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
31591 <row bottomline="true">
31592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31595 \begin_layout Standard
31597 \begin_inset LatexCommand \index{d52}
31602 \begin_inset LatexCommand \index{d52 (disassembler)}
31611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31614 \begin_layout Standard
31615 Disassembler, can count instruction cycles
31616 \begin_inset LatexCommand \index{instruction cycles (count)}
31620 , use with options -pnd
31625 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31628 \begin_layout Standard
31629 \begin_inset LatexCommand \url{http://www.8052.com/users/disasm/}
31639 <row bottomline="true">
31640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31643 \begin_layout Standard
31645 \begin_inset LatexCommand \index{cmake}
31654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31657 \begin_layout Standard
31658 Cross platform build system, generates Makefiles
31659 \begin_inset LatexCommand \index{Makefile}
31663 and project workspaces
31664 \begin_inset LatexCommand \index{project workspace}
31673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31676 \begin_layout Standard
31677 \begin_inset LatexCommand \url{http://www.cmake.org}
31696 \begin_layout Section
31697 Related documentation / recommended reading
31700 \begin_layout Standard
31702 \begin_inset Tabular
31703 <lyxtabular version="3" rows="7" columns="3">
31705 <column alignment="left" valignment="top" leftline="true" width="0pt">
31706 <column alignment="left" valignment="top" leftline="true" width="0">
31707 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
31708 <row topline="true" bottomline="true">
31709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31712 \begin_layout Standard
31720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31723 \begin_layout Standard
31731 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31734 \begin_layout Standard
31743 <row topline="true">
31744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31747 \begin_layout Standard
31762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31765 \begin_layout Standard
31767 \begin_inset LatexCommand \index{C Reference card}
31776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31779 \begin_layout Standard
31780 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
31790 <row topline="true">
31791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31794 \begin_layout Standard
31800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31803 \begin_layout Standard
31805 \begin_inset LatexCommand \index{C FAQ}
31814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31817 \begin_layout Standard
31818 \begin_inset LatexCommand \url{http://www.c-faq.com}
31828 <row topline="true">
31829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31832 \begin_layout Standard
31838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31841 \begin_layout Standard
31842 \begin_inset Quotes sld
31846 \begin_inset Quotes srd
31854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31857 \begin_layout Standard
31860 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
31870 <row topline="true">
31871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31874 \begin_layout Standard
31880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31883 \begin_layout Standard
31884 \begin_inset Quotes sld
31887 Extensions for Embedded C
31888 \begin_inset Quotes srd
31896 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31899 \begin_layout Standard
31902 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
31912 <row topline="true">
31913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31916 \begin_layout Standard
31922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31925 \begin_layout Standard
31926 Latest datasheet of target CPU
31931 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31934 \begin_layout Standard
31941 <row topline="true" bottomline="true">
31942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31945 \begin_layout Standard
31951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31954 \begin_layout Standard
31955 Revision history of datasheet
31960 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31963 \begin_layout Standard
31979 \begin_layout Section
31980 Application notes specifically for SDCC
31983 \begin_layout Standard
31984 SDCC makes no claims about the completeness of this list and about up-to-datenes
31985 s or correctness of the application notes
31986 \begin_inset LatexCommand \index{Application notes}
31993 \begin_layout Standard
31997 \begin_inset Tabular
31998 <lyxtabular version="3" rows="7" columns="3">
32000 <column alignment="block" valignment="top" leftline="true" width="17col%">
32001 <column alignment="block" valignment="top" leftline="true" width="27col%">
32002 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
32003 <row topline="true" bottomline="true">
32004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32007 \begin_layout Standard
32016 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
32019 \begin_layout Standard
32028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32031 \begin_layout Standard
32041 <row topline="true">
32042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32045 \begin_layout Standard
32053 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32056 \begin_layout Standard
32059 Using the SDCC Compiler for the DS80C400
32060 \begin_inset LatexCommand \index{DS80C400}
32069 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32072 \begin_layout Standard
32075 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
32085 <row topline="true">
32086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32089 \begin_layout Standard
32097 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
32100 \begin_layout Standard
32103 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
32104 \begin_inset LatexCommand \index{DS89C4x0}
32108 Family of Microcontrollers
32113 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32116 \begin_layout Standard
32119 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
32129 <row topline="true">
32130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32133 \begin_layout Standard
32136 Silicon Laboratories / Cygnal
32141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32144 \begin_layout Standard
32147 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
32148 \begin_inset LatexCommand \index{IDE}
32157 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32160 \begin_layout Standard
32163 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
32173 <row topline="true">
32174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32177 \begin_layout Standard
32180 Ramtron / Goal Semiconductor
32185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32188 \begin_layout Standard
32191 Interfacing SDCC to Syn and Textpad
32196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32199 \begin_layout Standard
32202 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32212 <row topline="true">
32213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32216 \begin_layout Standard
32219 Ramtron / Goal Semiconductor
32224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32227 \begin_layout Standard
32230 Installing and Configuring SDCC and Crimson Editor
32235 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32238 \begin_layout Standard
32241 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32251 <row topline="true" bottomline="true">
32252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32255 \begin_layout Standard
32263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32266 \begin_layout Standard
32269 MSC12xx Programming with SDCC
32274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32277 \begin_layout Standard
32280 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
32297 \begin_layout Section
32301 \begin_layout Standard
32302 Some questions answered, some pointers given - it might be time to in turn
32310 \begin_layout Itemize
32311 can you solve your project with the selected microcontroller? Would you
32312 find out early or rather late that your target is too small/slow/whatever?
32313 Can you switch to a slightly better device if it doesn't fit?
32316 \begin_layout Itemize
32317 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
32318 and/or another programming language be more adequate? Would an operating
32319 system on the target device help?
32322 \begin_layout Itemize
32323 if you solved the problem, will the marketing department be happy?
32326 \begin_layout Itemize
32327 if the marketing department is happy, will customers be happy?
32330 \begin_layout Itemize
32331 if you're the project manager, marketing department and maybe even the customer
32332 in one person, have you tried to see the project from the outside?
32335 \begin_layout Itemize
32336 is the project done if you think it is done? Or is just that other interface/pro
32337 tocol/feature/configuration/option missing? How about website, manual(s),
32338 internationali(z|s)ation, packaging, labels, 2nd source for components,
32339 electromagnetic compatability/interference, documentation for production,
32340 production test software, update mechanism, patent issues?
32343 \begin_layout Itemize
32344 is your project adequately positioned in that magic triangle: fame, fortune,
32348 \begin_layout Standard
32349 Maybe not all answers to these questions are known and some answers may
32354 , nevertheless knowing these questions may help you to avoid burnout
32358 \begin_layout Standard
32359 burnout is bad for electronic devices, programmers and motorcycle tyres
32365 Chances are you didn't want to hear some of them...
32368 \begin_layout Chapter
32370 \begin_inset LatexCommand \index{Support}
32377 \begin_layout Standard
32378 SDCC has grown to be a large project.
32379 The compiler alone (without the preprocessor, assembler and linker) is
32380 well over 150,000 lines of code (blank stripped).
32381 The open source nature of this project is a key to its continued growth
32383 You gain the benefit and support of many active software developers and
32385 Is SDCC perfect? No, that's why we need your help.
32386 The developers take pride in fixing reported bugs.
32387 You can help by reporting the bugs and helping other SDCC users.
32388 There are lots of ways to contribute, and we encourage you to take part
32389 in making SDCC a great software package.
32393 \begin_layout Standard
32394 The SDCC project is hosted on the SDCC sourceforge site at
32395 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
32400 You'll find the complete set of mailing lists
32401 \begin_inset LatexCommand \index{Mailing list(s)}
32405 , forums, bug reporting system, patch submission
32406 \begin_inset LatexCommand \index{Patch submission}
32411 \begin_inset LatexCommand \index{download}
32415 area and Subversion code repository
32416 \begin_inset LatexCommand \index{Subversion code repository}
32423 \begin_layout Section
32425 \begin_inset LatexCommand \index{Bug reporting}
32430 \begin_inset LatexCommand \index{Reporting bugs}
32437 \begin_layout Standard
32438 The recommended way of reporting bugs is using the infrastructure of the
32440 You can follow the status of bug reports there and have an overview about
32444 \begin_layout Standard
32445 Bug reports are automatically forwarded to the developer mailing list and
32446 will be fixed ASAP.
32447 When reporting a bug, it is very useful to include a small test program
32448 (the smaller the better) which reproduces the problem.
32449 If you can isolate the problem by looking at the generated assembly code,
32450 this can be very helpful.
32451 Compiling your program with the -
32455 \begin_layout Standard
32465 \begin_inset LatexCommand \index{-\/-dumpall}
32469 option can sometimes be useful in locating optimization problems.
32470 When reporting a bug please make sure you:
32473 \begin_layout Enumerate
32474 Attach the code you are compiling with SDCC.
32478 \begin_layout Enumerate
32479 Specify the exact command you use to run SDCC, or attach your Makefile.
32483 \begin_layout Enumerate
32484 Specify the SDCC version (type "
32490 "), your platform, and operating system.
32494 \begin_layout Enumerate
32495 Provide an exact copy of any error message or incorrect output.
32499 \begin_layout Enumerate
32500 Put something meaningful in the subject of your message.
32503 \begin_layout Standard
32504 Please attempt to include these 5 important parts, as applicable, in all
32505 requests for support or when reporting any problems or bugs with SDCC.
32506 Though this will make your message lengthy, it will greatly improve your
32507 chance that SDCC users and developers will be able to help you.
32508 Some SDCC developers are frustrated by bug reports without code provided
32509 that they can use to reproduce and ultimately fix the problem, so please
32510 be sure to provide sample code if you are reporting a bug!
32513 \begin_layout Standard
32514 Please have a short check that you are using a recent version of SDCC and
32515 the bug is not yet known.
32516 This is the link for reporting bugs:
32517 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
32522 With SDCC on average having more than 200 downloads
32523 \begin_inset LatexCommand \index{download}
32527 on sourceforge per day
32531 \begin_layout Standard
32532 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
32533 between 2002 and 2005.
32534 This does not include other methods of distribution.
32539 there must be some users.
32540 So it's not exactly easy to find a new bug.
32541 If you find one we need it:
32543 reporting bugs is good
32548 \begin_layout Section
32549 Requesting Features
32550 \begin_inset LatexCommand \label{sub:Requesting-Features}
32555 \begin_inset LatexCommand \index{Feature request}
32560 \begin_inset LatexCommand \index{Requesting features}
32567 \begin_layout Standard
32568 Like bug reports feature requests are forwarded to the developer mailing
32570 This is the link for requesting features:
32571 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32578 \begin_layout Section
32582 \begin_layout Standard
32583 Like bug reports contributed patches are forwarded to the developer mailing
32585 This is the link for submitting patches
32586 \begin_inset LatexCommand \index{Patch submission}
32591 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
32598 \begin_layout Standard
32599 You need to specify some parameters to the
32603 command for the patches to be useful.
32604 If you modified more than one file a patch created f.e.
32609 \begin_inset Quotes sld
32612 diff -Naur unmodified_directory modified_directory >my_changes.patch
32613 \begin_inset Quotes srd
32619 will be fine, otherwise
32623 \begin_inset Quotes sld
32626 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
32627 \begin_inset Quotes srd
32637 \begin_layout Section
32641 \begin_layout Standard
32642 These links should take you directly to the
32643 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
32651 \begin_layout Standard
32652 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
32653 automated messages (mid 2003)
32659 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
32664 \begin_inset LatexCommand \index{Mailing list(s)}
32668 and forums are archived and searchable so if you are lucky someone already
32669 had a similar problem.
32670 While mails to the lists themselves are delivered promptly their web front
32671 end on sourceforge sometimes shows a severe time lag (up to several weeks),
32672 if you're seriously using SDCC please consider subscribing to the lists.
32675 \begin_layout Section
32679 \begin_layout Standard
32680 You can follow the status of the Subversion version
32681 \begin_inset LatexCommand \index{version}
32685 of SDCC by watching the Changelog
32686 \begin_inset LatexCommand \index{Changelog}
32690 in the Subversion repository
32693 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
32700 \begin_layout Section
32701 Subversion Source Code Repository
32704 \begin_layout Standard
32714 \begin_layout Standard
32728 or the filenames of the snapshot versions of SDCC include date and its
32730 \begin_inset LatexCommand \index{Subversion code repository}
32735 Subversion allows to download the source of recent or previous versions
32737 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
32741 (by number or by date).
32742 An on-line source code browser and detailled instructions are also available
32744 SDCC versions starting from 1999 up to now are available (currently the
32745 versions prior to the conversion from cvs
32746 \begin_inset LatexCommand \index{cvs|see{Subversion}}
32750 to Subversion (April 2006) are either by accessible by Subversion or by
32754 \begin_layout Section
32756 \begin_inset LatexCommand \index{Release policy}
32763 \begin_layout Standard
32764 Historically there often were long delays between official releases and
32765 the sourceforge download area tends to get not updated at all.
32766 Excuses in the past might have referred to problems with live range analysis,
32767 but as this was fixed a while ago, the current problem is that another
32768 excuse has to be found.
32769 Kidding aside, we have to get better there! On the other hand there are
32770 daily snapshots available at
32771 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
32775 , and you can always build the very last version (hopefully with many bugs
32776 fixed, and features added) from the source code available at
32777 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
32783 \begin_inset LatexCommand \index{wiki}
32788 \begin_inset LatexCommand \index{SDCC Wiki}
32793 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/}
32797 also holds some information about past and future releases.
32800 \begin_layout Section
32802 \begin_inset LatexCommand \index{Examples}
32809 \begin_layout Standard
32810 You'll find some small examples in the directory
32812 sdcc/device/examples/.
32815 More examples and libraries are available at
32817 The SDCC Open Knowledge Resource
32818 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
32825 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
32832 \begin_layout Standard
32833 \begin_inset Note Note
32836 \begin_layout Standard
32837 I did insert a reference to Paul's web site here although it seems rather
32838 dedicated to a specific 8032 board (I think it's okay because it f.e.
32839 shows LCD/Harddisc interface and has a free 8051 monitor.
32840 Independent 8032 board vendors face hard competition of heavily subsidized
32841 development boards anyway).
32844 \begin_layout Standard
32845 Maybe we should include some links to real world applications.
32846 Preferably pointer to pointers (one for each architecture) so this stays
32855 \begin_layout Section
32857 \begin_inset LatexCommand \label{sec:Quality-control}
32862 \begin_inset LatexCommand \index{Quality control}
32869 \begin_layout Standard
32870 The compiler is passed through snaphot build compile and build checks.
32876 \begin_inset LatexCommand \index{Regression test}
32880 check that SDCC itself compiles flawlessly on several host platforms (i386,
32881 Opteron, 64 bit Alpha, ppc64, Mac OS X on PPC, Solaris on Sparc) and checks
32882 the quality of the code generated by SDCC by running the code for several
32883 target platforms through simulators.
32884 The regression test suite comprises more than 100 files which expand to
32885 more than 500 test cases which include more than 4500 tests.
32886 The results of these tests are published daily on SDCC's snapshot page
32887 (click on the red or green symbols on the right side of
32888 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
32895 \begin_layout Standard
32896 There is a separate document
32899 \begin_inset LatexCommand \index{Test suite}
32906 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
32910 about the regression test suite.
32913 \begin_layout Standard
32914 You'll find the test code in the directory
32916 sdcc/support/regression
32919 You can run these tests manually by running
32923 in this directory (or f.e.
32928 \begin_inset Quotes sld
32932 \begin_inset Quotes srd
32938 if you don't want to run the complete tests).
32939 The test code might also be interesting if you want to look for examples
32940 \begin_inset LatexCommand \index{Examples}
32944 checking corner cases of SDCC or if you plan to submit patches
32945 \begin_inset LatexCommand \index{Patch submission}
32952 \begin_layout Standard
32953 The PIC14 port uses a different set of regression tests
32954 \begin_inset LatexCommand \index{Regression test (PIC14)}
32958 , you'll find them in the directory
32960 sdcc/src/regression
32965 \begin_layout Section
32966 Use of SDCC in Education
32969 \begin_layout Standard
32978 \begin_layout Standard
32979 the phrase "use in education" might evoke the association "
32983 fit for use in education".
32984 This connotation is not intended but nevertheless risked as the licensing
32985 of SDCC makes it difficult to offer educational discounts
32991 If your rationales are to:
32994 \begin_layout Enumerate
32995 give students a chance to understand the
32999 steps of code generation
33002 \begin_layout Enumerate
33003 have a curriculum that can be extended for years.
33004 Then you could use an fpga board as target and your curriculum will seamlessly
33005 extend from logic synthesis (
33006 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
33011 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
33015 ), over assembly programming, to C to FPGA compilers (
33016 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
33023 \begin_layout Enumerate
33024 be able to insert excursions about skills like using a revision control
33025 system, submitting/applying patches, using a type-setting (as opposed to
33026 word-processing) engine LyX/LaTeX, using
33027 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
33032 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
33036 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
33037 Source Software, CPU simulation, compiler regression tests
33038 \begin_inset LatexCommand \index{Regression test}
33045 And if there should be a shortage of ideas then you can always point students
33046 to the ever-growing feature request list
33047 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33054 \begin_layout Enumerate
33055 not tie students to a specific host platform and instead allow them to use
33060 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
33062 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
33069 \begin_layout Enumerate
33070 not encourage students to use illegal copies of educational software
33073 \begin_layout Enumerate
33074 be immune to licensing/availability/price changes of the chosen tool chain
33077 \begin_layout Enumerate
33078 be able to change to a new target platform without having to adopt a new
33082 \begin_layout Enumerate
33083 have complete control over and insight into the tool chain
33086 \begin_layout Enumerate
33087 make your students aware about the pros and cons of open source software
33091 \begin_layout Enumerate
33092 give back to the public as you are probably at least partially publically
33096 \begin_layout Enumerate
33097 give students a chance to publically prove their skills and to possibly
33098 see a world wide impact
33101 \begin_layout Standard
33102 then SDCC is probably among the first choices.
33103 Well, probably SDCC might be the only choice.
33108 \begin_layout Chapter
33109 SDCC Technical Data
33112 \begin_layout Section
33114 \begin_inset LatexCommand \index{Optimizations}
33121 \begin_layout Standard
33122 SDCC performs a host of standard optimizations in addition to some MCU specific
33127 \begin_layout Subsection
33128 Sub-expression Elimination
33129 \begin_inset LatexCommand \index{Subexpression elimination}
33136 \begin_layout Standard
33137 The compiler does local and
33156 \begin_layout Verse
33164 \begin_layout Standard
33165 will be translated to
33168 \begin_layout Verse
33178 \begin_layout Standard
33179 Some subexpressions are not as obvious as the above example, e.g.:
33182 \begin_layout Verse
33190 \begin_layout Standard
33191 In this case the address arithmetic a->b[i] will be computed only once;
33192 the equivalent code in C would be.
33195 \begin_layout Verse
33205 \begin_layout Standard
33206 The compiler will try to keep these temporary variables in registers.
33209 \begin_layout Subsection
33210 Dead-Code Elimination
33211 \begin_inset LatexCommand \index{Dead-code elimination}
33218 \begin_layout Verse
33233 i = 1; \InsetSpace ~
33242 global = 1;\InsetSpace ~
33256 global = 3;\InsetSpace ~
33262 \begin_layout Standard
33266 \begin_layout Verse
33282 \begin_layout Subsection
33284 \begin_inset LatexCommand \index{Copy propagation}
33291 \begin_layout Verse
33315 \begin_layout Standard
33319 \begin_layout Verse
33343 \begin_layout Standard
33344 Note: the dead stores created by this copy propagation will be eliminated
33345 by dead-code elimination.
33348 \begin_layout Subsection
33350 \begin_inset LatexCommand \index{Loop optimization}
33355 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
33362 \begin_layout Standard
33363 Two types of loop optimizations are done by SDCC
33371 of loop induction variables.
33372 In addition to the strength reduction the optimizer marks the induction
33373 variables and the register allocator tries to keep the induction variables
33374 in registers for the duration of the loop.
33375 Because of this preference of the register allocator
33376 \begin_inset LatexCommand \index{Register allocation}
33380 , loop induction optimization causes an increase in register pressure, which
33381 may cause unwanted spilling of other temporary variables into the stack
33382 \begin_inset LatexCommand \index{stack}
33387 The compiler will generate a warning message when it is forced to allocate
33388 extra space either on the stack or data space.
33389 If this extra space allocation is undesirable then induction optimization
33390 can be eliminated either for the entire source file (with -
33394 \begin_layout Standard
33403 -noinduction option) or for a given function only using #pragma\InsetSpace ~
33405 \begin_inset LatexCommand \index{\#pragma noinduction}
33416 \begin_layout Verse
33419 for (i = 0 ; i < 100 ; i ++)
33428 \begin_layout Standard
33432 \begin_layout Verse
33437 for (i = 0; i < 100; i++)
33446 \begin_layout Standard
33447 As mentioned previously some loop invariants are not as apparent, all static
33448 address computations are also moved out of the loop.
33453 \begin_inset LatexCommand \index{Strength reduction}
33457 , this optimization substitutes an expression by a cheaper expression:
33460 \begin_layout Verse
33463 for (i=0;i < 100; i++)
33472 \begin_layout Standard
33476 \begin_layout Verse
33483 for (i=0;i< 100;i++) {
33489 ar[itemp1] = itemp2;
33507 \begin_layout Standard
33508 The more expensive multiplication
33509 \begin_inset LatexCommand \index{Multiplication}
33513 is changed to a less expensive addition.
33516 \begin_layout Subsection
33518 \begin_inset LatexCommand \index{Loop reversing}
33525 \begin_layout Standard
33526 This optimization is done to reduce the overhead of checking loop boundaries
33527 for every iteration.
33528 Some simple loops can be reversed and implemented using a
33529 \begin_inset Quotes eld
33532 decrement and jump if not zero
33533 \begin_inset Quotes erd
33537 SDCC checks for the following criterion to determine if a loop is reversible
33538 (note: more sophisticated compilers use data-dependency analysis to make
33539 this determination, SDCC uses a more simple minded analysis).
33542 \begin_layout Itemize
33543 The 'for' loop is of the form
33549 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
33559 \begin_layout Itemize
33560 The <for body> does not contain
33561 \begin_inset Quotes eld
33565 \begin_inset Quotes erd
33569 \begin_inset Quotes erd
33575 \begin_layout Itemize
33576 All goto's are contained within the loop.
33579 \begin_layout Itemize
33580 No function calls within the loop.
33583 \begin_layout Itemize
33584 The loop control variable <sym> is not assigned any value within the loop
33587 \begin_layout Itemize
33588 The loop control variable does NOT participate in any arithmetic operation
33592 \begin_layout Itemize
33593 There are NO switch statements in the loop.
33596 \begin_layout Subsection
33597 Algebraic Simplifications
33600 \begin_layout Standard
33601 SDCC does numerous algebraic simplifications, the following is a small sub-set
33602 of these optimizations.
33605 \begin_layout Verse
33608 i = j + 0;\InsetSpace ~
33612 /* changed to: */\InsetSpace ~
33618 i /= 2;\InsetSpace ~
33625 /* changed to: */\InsetSpace ~
33632 = j - j;\InsetSpace ~
33636 /* changed to: */\InsetSpace ~
33642 i = j / 1;\InsetSpace ~
33646 /* changed to: */\InsetSpace ~
33653 \begin_layout Standard
33654 Note the subexpressions
33655 \begin_inset LatexCommand \index{Subexpression}
33659 given above are generally introduced by macro expansions or as a result
33660 of copy/constant propagation.
33663 \begin_layout Subsection
33664 'switch' Statements
33665 \begin_inset LatexCommand \label{sub:'switch'-Statements}
33670 \begin_inset LatexCommand \index{switch statement}
33677 \begin_layout Standard
33678 SDCC can optimize switch statements to jump tables
33679 \begin_inset LatexCommand \index{jump tables}
33684 It makes the decision based on an estimate of the generated code size.
33685 SDCC is quite liberal in the requirements for jump table generation:
33688 \begin_layout Itemize
33689 The labels need not be in order, and the starting number need not be one
33690 or zero, the case labels are in numerical sequence or not too many case
33691 labels are missing.
33695 \begin_layout Verse
33698 switch(i) {\InsetSpace ~
33729 case 4: ...\InsetSpace ~
33761 case 5: ...\InsetSpace ~
33793 case 3: ...\InsetSpace ~
33824 case 6: ...\InsetSpace ~
33856 case 7: ...\InsetSpace ~
33888 case 8: ...\InsetSpace ~
33920 case 9: ...\InsetSpace ~
33952 case 10: ...\InsetSpace ~
33983 case 11: ...\InsetSpace ~
34050 \begin_layout Standard
34051 Both the above switch statements will be implemented using a jump-table.
34052 The example to the right side is slightly more efficient as the check for
34053 the lower boundary of the jump-table is not needed.
34057 \begin_layout Itemize
34058 The number of case labels is not larger than supported by the target architectur
34062 \begin_layout Itemize
34063 If the case labels are not in numerical sequence ('gaps' between cases)
34064 SDCC checks whether a jump table with additionally inserted dummy cases
34065 is still attractive.
34069 \begin_layout Itemize
34070 If the starting number is not zero and a check for the lower boundary of
34071 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
34076 \begin_layout Standard
34077 Switch statements which have large gaps in the numeric sequence or those
34078 that have too many case labels can be split into more than one switch statement
34079 for efficient code generation, e.g.:
34082 \begin_layout Verse
34160 \begin_layout Standard
34161 If the above switch statement is broken down into two switch statements
34164 \begin_layout Verse
34207 \begin_layout Standard
34211 \begin_layout Verse
34254 \begin_layout Standard
34255 then both the switch statements will be implemented using jump-tables whereas
34256 the unmodified switch statement will not be.
34259 \begin_layout Standard
34260 \begin_inset Note Note
34263 \begin_layout Standard
34264 There might be reasons which SDCC cannot know about to either favour or
34265 not favour jump tables.
34266 If the target system has to be as quick for the last switch case as for
34267 the first (pro jump table), or if the switch argument is known to be zero
34268 in the majority of the cases (contra jump table).
34276 \begin_layout Standard
34277 The pragma nojtbound
34278 \begin_inset LatexCommand \index{\#pragma nojtbound}
34282 can be used to turn off checking the
34295 It has no effect if a default label is supplied.
34296 Use of this pragma is dangerous: if the switch
34297 \begin_inset LatexCommand \index{switch statement}
34301 argument is not matched by a case statement the processor will happily
34305 \begin_layout Subsection
34306 Bit-shifting Operations
34307 \begin_inset LatexCommand \index{Bit shifting}
34314 \begin_layout Standard
34315 Bit shifting is one of the most frequently used operation in embedded programmin
34317 SDCC tries to implement bit-shift operations in the most efficient way
34321 \begin_layout Verse
34334 \begin_layout Standard
34335 generates the following code:
34338 \begin_layout Verse
34353 \begin_layout Standard
34354 In general SDCC will never setup a loop if the shift count is known.
34358 \begin_layout Verse
34371 \begin_layout Standard
34375 \begin_layout Verse
34399 \begin_layout Subsection
34401 \begin_inset LatexCommand \index{Bit rotation}
34408 \begin_layout Standard
34409 A special case of the bit-shift operation is bit rotation
34410 \begin_inset LatexCommand \index{rotating bits}
34414 , SDCC recognizes the following expression to be a left bit-rotation:
34417 \begin_layout Verse
34425 char i;\InsetSpace ~
34436 /* unsigned is needed for rotation */
34441 i = ((i << 1) | (i >> 7));
34450 \begin_layout Standard
34451 will generate the following code:
34454 \begin_layout Verse
34471 \begin_layout Standard
34472 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
34473 ns of this case will also be recognized as bit-rotation, i.e.:
34476 \begin_layout Verse
34479 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
34482 \begin_layout Subsection
34483 Nibble and Byte Swapping
34486 \begin_layout Standard
34487 Other special cases of the bit-shift operations are nibble or byte swapping
34488 \begin_inset LatexCommand \index{swapping nibbles/bytes}
34492 , SDCC recognizes the following expressions:
34495 \begin_layout Verse
34516 i = ((i << 4) | (i >> 4));
34522 j = ((j << 8) | (j >> 8));
34525 \begin_layout Standard
34526 and generates a swap instruction for the nibble swapping
34527 \begin_inset LatexCommand \index{Nibble swapping}
34531 or move instructions for the byte swapping
34532 \begin_inset LatexCommand \index{Byte swapping}
34538 \begin_inset Quotes sld
34542 \begin_inset Quotes srd
34545 example can be used to convert from little to big-endian or vice versa.
34546 If you want to change the endianness of a
34550 integer you have to cast to
34557 \begin_layout Standard
34558 Note that SDCC stores numbers in little-endian
34562 \begin_layout Standard
34563 Usually 8-bit processors don't care much about endianness.
34564 This is not the case for the standard 8051 which only has an instruction
34570 \begin_inset LatexCommand \index{DPTR}
34578 so little-endian is the more efficient byte order.
34584 \begin_inset LatexCommand \index{little-endian}
34589 \begin_inset LatexCommand \index{Endianness}
34594 lowest order first).
34597 \begin_layout Subsection
34599 \begin_inset LatexCommand \index{Highest Order Bit}
34604 \begin_inset LatexCommand \index{Any Order Bit}
34611 \begin_layout Standard
34612 It is frequently required to obtain the highest order bit of an integral
34613 type (long, int, short or char types).
34614 Also obtaining any other order bit is not uncommon.
34615 SDCC recognizes the following expressions to yield the highest order bit
34616 and generates optimized code for it, e.g.:
34619 \begin_layout Verse
34630 unsigned char hob1, aob1;
34634 bit hob2, hob3, aob2,
34644 hob1 = (gint >> 15) & 1;
34648 hob2 = (gint >> 15) & 1;
34652 hob3 = gint & 0x8000;
34657 aob1 = (gint >> 9) & 1;
34661 aob2 = (gint >> 8) & 1;
34665 aob3 = gint & 0x0800;
34675 \begin_layout Standard
34676 will generate the following code:
34679 \begin_layout Verse
34710 000A E5*01\InsetSpace ~
34737 000C 23\InsetSpace ~
34768 000D 54 01\InsetSpace ~
34796 000F F5*02\InsetSpace ~
34851 0011 E5*01\InsetSpace ~
34879 0013 33\InsetSpace ~
34909 0014 92*00\InsetSpace ~
34965 0016 E5*01\InsetSpace ~
34992 0018 33\InsetSpace ~
35022 0019 92*01\InsetSpace ~
35078 001B E5*01\InsetSpace ~
35137 001E 54 01\InsetSpace ~
35164 0020 F5*03\InsetSpace ~
35220 0022 E5*01\InsetSpace ~
35247 0024 13\InsetSpace ~
35277 0025 92*02\InsetSpace ~
35333 0027 E5*01\InsetSpace ~
35388 002B 92*03\InsetSpace ~
35416 \begin_layout Standard
35417 Other variations of these cases however will
35422 They are standard C expressions, so I heartily recommend these be the only
35423 way to get the highest order bit, (it is portable).
35424 Of course it will be recognized even if it is embedded in other expressions,
35428 \begin_layout Verse
35431 xyz = gint + ((gint >> 15) & 1);
35434 \begin_layout Standard
35435 will still be recognized.
35438 \begin_layout Subsection
35440 \begin_inset LatexCommand \index{Higher Order Byte}
35444 / Higher Order Word
35445 \begin_inset LatexCommand \index{Higher Order Word}
35452 \begin_layout Standard
35453 It is also frequently required to obtain a higher order byte or word of
35454 a larger integral type (long, int or short types).
35455 SDCC recognizes the following expressions to yield the higher order byte
35456 or word and generates optimized code for it, e.g.:
35459 \begin_layout Verse
35464 unsigned long int glong;
35472 unsigned char hob1,
35477 unsigned int how1, how2;
35486 hob1 = (gint >> 8) & 0xFF;
35490 hob2 = glong >> 24;
35494 how1 = (glong >> 16) & 0xFFFF;
35509 \begin_layout Standard
35510 will generate the following code:
35513 \begin_layout Verse
35544 0037 85*01*06\InsetSpace ~
35566 _foo_hob1_1_1,(_gint + 1)
35597 003A 85*05*07\InsetSpace ~
35619 _foo_hob2_1_1,(_glong + 3)
35649 003D 85*04*08\InsetSpace ~
35672 _foo_how1_1_1,(_glong + 2)
35674 0040 85*05*09\InsetSpace ~
35699 0043 85*03*0A\InsetSpace ~
35721 _foo_how2_1_1,(_glong + 1)
35723 0046 85*04*0B\InsetSpace ~
35746 (_foo_how2_1_1 + 1),(_glong + 2)
35749 \begin_layout Standard
35750 Again, variations of these cases may
35755 They are standard C expressions, so I heartily recommend these be the only
35756 way to get the higher order byte/word, (it is portable).
35757 Of course it will be recognized even if it is embedded in other expressions,
35761 \begin_layout Verse
35764 xyz = gint + ((gint >> 8) & 0xFF);
35767 \begin_layout Standard
35768 will still be recognized.
35771 \begin_layout Subsection
35773 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
35778 \begin_inset LatexCommand \index{Peephole optimizer}
35785 \begin_layout Standard
35786 The compiler uses a rule based, pattern matching and re-writing mechanism
35787 for peep-hole optimization.
35792 a peep-hole optimizer by Christopher W.
35793 Fraser (cwfraser\InsetSpace ~
35796 A default set of rules are compiled into the compiler, additional rules
35797 may be added with the
35803 \begin_layout Standard
35813 \begin_inset LatexCommand \index{-\/-peep-file}
35820 The rule language is best illustrated with examples.
35823 \begin_layout Verse
35845 \begin_layout Standard
35846 The above rule will change the following assembly
35847 \begin_inset LatexCommand \index{Assembler routines}
35854 \begin_layout Verse
35862 \begin_layout Standard
35866 \begin_layout Verse
35872 \begin_layout Standard
35873 Note: All occurrences of a
35877 (pattern variable) must denote the same string.
35878 With the above rule, the assembly sequence:
35881 \begin_layout Verse
35889 \begin_layout Standard
35890 will remain unmodified.
35894 Other special case optimizations may be added by the
35901 \begin_layout Standard
35914 some variants of the 8051 MCU
35915 \begin_inset LatexCommand \index{MCS51 variants}
35928 The following two rules will change all
35945 \begin_layout Verse
35948 replace { lcall %1 } by { acall %1 }
35950 replace { ljmp %1 } by { ajmp %1 }
35953 \begin_layout Standard
35954 (NOTE: from version 2.7.3 on, you can use option -
35960 \begin_layout Standard
35972 \begin_inset LatexCommand \index{-\/-acall-ajmp}
35976 , which also takes care of aligning the interrupt vectors properly.)
35981 \begin_layout Standard
35984 inline-assembler code
35986 is also passed through the peep hole optimizer, thus the peephole optimizer
35987 can also be used as an assembly level macro expander.
35988 The rules themselves are MCU dependent whereas the rule language infra-structur
35989 e is MCU independent.
35990 Peephole optimization rules for other MCU can be easily programmed using
35995 The syntax for a rule is as follows:
35998 \begin_layout Verse
36001 rule := replace [ restart ] '{' <assembly sequence> '
36039 <assembly sequence> '
36057 '}' [if <functionName> ] '
36062 \begin_layout Standard
36063 <assembly sequence> := assembly instruction (each instruction including
36064 labels must be on a separate line).
36068 The optimizer will apply to the rules
36069 one by one from the top in the sequence of their appearance, it will terminate
36070 when all rules are exhausted.
36071 If the 'restart' option is specified, then the optimizer will start matching
36072 the rules again from the top, this option for a rule is expensive (performance)
36073 , it is intended to be used in situations where a transformation will trigger
36074 the same rule again.
36075 An example of this (not a good one, it has side effects) is the following
36079 \begin_layout Verse
36099 \begin_layout Standard
36100 Note that the replace pattern cannot be a blank, but can be a comment line.
36101 Without the 'restart' option only the innermost 'pop' 'push' pair would
36102 be eliminated, i.e.:
36105 \begin_layout Verse
36117 \begin_layout Standard
36121 \begin_layout Verse
36131 \begin_layout Standard
36136 the restart option the rule will be applied again to the resulting code
36137 and then all the pop-push pairs will be eliminated to yield:
36140 \begin_layout Verse
36148 \begin_layout Standard
36149 A conditional function can be attached to a rule.
36150 Attaching rules are somewhat more involved, let me illustrate this with
36154 \begin_layout Verse
36178 \begin_layout Standard
36179 The optimizer does a look-up of a function name table defined in function
36184 in the source file SDCCpeeph.c, with the name
36189 If it finds a corresponding entry the function is called.
36190 Note there can be no parameters specified for these functions, in this
36195 is crucial, since the function
36199 expects to find the label in that particular variable (the hash table containin
36200 g the variable bindings is passed as a parameter).
36201 If you want to code more such functions, take a close look at the function
36202 labelInRange and the calling mechanism in source file SDCCpeeph.c.
36203 Currently implemented are
36205 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
36206 24bitMode, portIsDS390, 24bitModeAndPortDS390
36215 \begin_layout Standard
36216 I know this whole thing is a little kludgey, but maybe some day we will
36217 have some better means.
36218 If you are looking at this file, you will see the default rules that are
36219 compiled into the compiler, you can add your own rules in the default set
36220 there if you get tired of specifying the -
36224 \begin_layout Standard
36236 \begin_layout Section
36238 \begin_inset LatexCommand \index{ANSI-compliance}
36243 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
36250 \begin_layout Standard
36251 The latest publically available version of the standard
36253 ISO/IEC 9899 - Programming languages - C
36255 should be available at:
36256 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
36265 \begin_layout Standard
36266 Deviations from the compliance:
36269 \begin_layout Itemize
36270 functions are not reentrant
36271 \begin_inset LatexCommand \index{reentrant}
36275 unless explicitly declared as such or the
36281 \begin_layout Standard
36291 \begin_inset LatexCommand \index{-\/-stack-auto}
36297 command line option is specified.
36300 \begin_layout Itemize
36302 \begin_inset LatexCommand \index{struct}
36307 \begin_inset LatexCommand \index{union}
36311 cannot be assigned values directly, cannot be passed as function parameters
36312 or assigned to each other and cannot be a return value
36313 \begin_inset LatexCommand \index{return value}
36317 from a function, e.g.:
36321 \begin_layout Verse
36344 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
36363 s parms) /* invalid in SDCC although allowed in ANSI */
36385 return rets; /* is invalid in SDCC although allowed in ANSI */
36391 \begin_layout Itemize
36392 initialization of structure arrays must be fully braced.
36396 \begin_layout Verse
36399 struct s { char x } a[] = {1, 2};\InsetSpace ~
36404 /* invalid in SDCC */
36407 } a[] = {{1}, {2}}; /* OK */
36411 \begin_layout Itemize
36413 \begin_inset LatexCommand \index{long long (not supported)}
36418 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
36425 \begin_layout Itemize
36427 \begin_inset LatexCommand \index{double (not supported)}
36431 ' precision floating point
36432 \begin_inset LatexCommand \index{Floating point support}
36439 \begin_layout Itemize
36441 \begin_inset LatexCommand \index{K\&R style}
36445 function declarations are NOT allowed.
36449 \begin_layout Verse
36452 foo(i,j) /* this old style of function declarations */
36454 int i,j; /* is valid
36455 in ANSI but not valid in SDCC */
36470 \begin_layout Itemize
36471 Most enhancements in C99 are not supported, e.g.:
36475 \begin_layout Verse
36482 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
36486 \begin_layout Itemize
36487 But some have been added recently in SDCC 2.7.0.
36488 They must be considered alpha quality however.
36492 \begin_layout Verse
36497 \begin_inset LatexCommand \index{inline (not supported)}
36503 int increment (int a) { return a+1; } /* inlines the increment without
36504 function call overhead */
36509 \begin_inset LatexCommand \index{inline (not supported)}
36515 p; /* accepted but ignored */
36519 \begin_layout Itemize
36520 Certain words that are valid identifiers in the standard may be reserved
36521 words in SDCC unless the
36527 \begin_layout Standard
36537 \begin_inset LatexCommand \index{-\/-std-c89}
36545 \begin_layout Standard
36555 \begin_inset LatexCommand \index{-\/-std-c99}
36561 command line options are used.
36562 These may include (depending on the selected processor): 'at', 'banked',
36563 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
36564 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
36565 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
36567 Compliant equivalents of these keywords are always available in a form
36568 that begin with two underscores
36569 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
36574 '__data' instead of 'data'.
36577 \begin_layout Section
36578 Cyclomatic Complexity
36579 \begin_inset LatexCommand \index{Cyclomatic complexity}
36586 \begin_layout Standard
36587 Cyclomatic complexity of a function is defined as the number of independent
36588 paths the program can take during execution of the function.
36589 This is an important number since it defines the number test cases you
36590 have to generate to validate the function.
36591 The accepted industry standard for complexity number is 10, if the cyclomatic
36592 complexity reported by SDCC exceeds 10 you should think about simplification
36593 of the function logic.
36594 Note that the complexity level is not related to the number of lines of
36595 code in a function.
36596 Large functions can have low complexity, and small functions can have large
36602 SDCC uses the following formula to compute the complexity:
36607 \begin_layout Standard
36608 complexity = (number of edges in control flow graph) - (number of nodes
36609 in control flow graph) + 2;
36613 Having said that the industry standard is 10,
36614 you should be aware that in some cases it be may unavoidable to have a
36615 complexity level of less than 10.
36616 For example if you have switch statement with more than 10 case labels,
36617 each case label adds one to the complexity level.
36618 The complexity level is by no means an absolute measure of the algorithmic
36619 complexity of the function, it does however provide a good starting point
36620 for which functions you might look at for further optimization.
36623 \begin_layout Section
36624 Retargetting for other Processors
36627 \begin_layout Standard
36628 The issues for retargetting the compiler are far too numerous to be covered
36630 What follows is a brief description of each of the seven phases of the
36631 compiler and its MCU dependency.
36634 \begin_layout Itemize
36635 Parsing the source and building the annotated parse tree.
36636 This phase is largely MCU independent (except for the language extensions).
36637 Syntax & semantic checks are also done in this phase, along with some initial
36638 optimizations like back patching labels and the pattern matching optimizations
36639 like bit-rotation etc.
36642 \begin_layout Itemize
36643 The second phase involves generating an intermediate code which can be easy
36644 manipulated during the later phases.
36645 This phase is entirely MCU independent.
36646 The intermediate code generation assumes the target machine has unlimited
36647 number of registers, and designates them with the name iTemp.
36648 The compiler can be made to dump a human readable form of the code generated
36653 \begin_layout Standard
36665 \begin_layout Itemize
36666 This phase does the bulk of the standard optimizations and is also MCU independe
36668 This phase can be broken down into several sub-phases:
36672 Break down intermediate
36673 code (iCode) into basic blocks.
36675 Do control flow & data flow analysis on the
36678 Do local common subexpression elimination, then global subexpressio
36681 Dead code elimination
36685 If loop optimizations
36686 caused any changes then do 'global subexpression elimination' and 'dead
36687 code elimination' again.
36690 \begin_layout Itemize
36691 This phase determines the live-ranges; by live range I mean those iTemp
36692 variables defined by the compiler that still survive after all the optimization
36694 Live range analysis
36695 \begin_inset LatexCommand \index{Live range analysis}
36699 is essential for register allocation, since these computation determines
36700 which of these iTemps will be assigned to registers, and for how long.
36703 \begin_layout Itemize
36704 Phase five is register allocation.
36705 There are two parts to this process.
36709 The first part I call 'register packing'
36710 (for lack of a better term).
36711 In this case several MCU specific expression folding is done to reduce
36716 The second part is more MCU independent and deals with
36717 allocating registers to the remaining live ranges.
36718 A lot of MCU specific code does creep into this phase because of the limited
36719 number of index registers available in the 8051.
36722 \begin_layout Itemize
36723 The Code generation phase is (unhappily), entirely MCU dependent and very
36724 little (if any at all) of this code can be reused for other MCU.
36725 However the scheme for allocating a homogenized assembler operand for each
36726 iCode operand may be reused.
36729 \begin_layout Itemize
36730 As mentioned in the optimization section the peep-hole optimizer is rule
36731 based system, which can reprogrammed for other MCUs.
36734 \begin_layout Standard
36735 More information is available on SDCC Wiki
36736 \begin_inset LatexCommand \index{wiki}
36741 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting}
36745 ) and in the thread
36746 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
36753 \begin_layout Chapter
36755 \begin_inset LatexCommand \index{Compiler internals}
36762 \begin_layout Section
36763 The anatomy of the compiler
36764 \begin_inset LatexCommand \label{sub:The-anatomy-of}
36771 \begin_layout Standard
36774 This is an excerpt from an article published in Circuit Cellar Magazine
36780 It's a little outdated (the compiler is much more efficient now and user/develo
36781 per friendly), but pretty well exposes the guts of it all.
36787 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
36788 It is fairly easy to retarget for other 8-bit MCU.
36789 Here we take a look at some of the internals of the compiler.
36793 \begin_layout Paragraph*
36795 \begin_inset LatexCommand \index{Parsing}
36802 \begin_layout Standard
36803 Parsing the input source file and creating an AST (Annotated Syntax Tree
36804 \begin_inset LatexCommand \index{Annotated syntax tree}
36809 This phase also involves propagating types (annotating each node of the
36810 parse tree with type information) and semantic analysis.
36811 There are some MCU specific parsing rules.
36812 For example the storage classes, the extended storage classes are MCU specific
36813 while there may be a xdata storage class for 8051 there is no such storage
36814 class for z80 or Atmel AVR.
36815 SDCC allows MCU specific storage class extensions, i.e.
36816 xdata will be treated as a storage class specifier when parsing 8051 C
36817 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
36821 \begin_layout Paragraph*
36823 \begin_inset LatexCommand \index{iCode}
36830 \begin_layout Standard
36831 Intermediate code generation.
36832 In this phase the AST is broken down into three-operand form (iCode).
36833 These three operand forms are represented as doubly linked lists.
36834 ICode is the term given to the intermediate form generated by the compiler.
36835 ICode example section shows some examples of iCode generated for some simple
36836 C source functions.
36839 \begin_layout Paragraph*
36841 \begin_inset LatexCommand \index{Optimizations}
36848 \begin_layout Standard
36849 Bulk of the target independent optimizations is performed in this phase.
36850 The optimizations include constant propagation, common sub-expression eliminati
36851 on, loop invariant code movement, strength reduction of loop induction variables
36852 and dead-code elimination.
36855 \begin_layout Paragraph*
36856 Live range analysis
36857 \begin_inset LatexCommand \index{Live range analysis}
36864 \begin_layout Standard
36865 During intermediate code generation phase, the compiler assumes the target
36866 machine has infinite number of registers and generates a lot of temporary
36868 The live range computation determines the lifetime of each of these compiler-ge
36869 nerated temporaries.
36870 A picture speaks a thousand words.
36871 ICode example sections show the live range annotations for each of the
36873 It is important to note here, each iCode is assigned a number in the order
36874 of its execution in the function.
36875 The live ranges are computed in terms of these numbers.
36876 The from number is the number of the iCode which first defines the operand
36877 and the to number signifies the iCode which uses this operand last.
36880 \begin_layout Paragraph*
36881 Register Allocation
36882 \begin_inset LatexCommand \index{Register allocation}
36889 \begin_layout Standard
36890 The register allocation determines the type and number of registers needed
36892 In most MCUs only a few registers can be used for indirect addressing.
36893 In case of 8051 for example the registers R0 & R1 can be used to indirectly
36894 address the internal ram and DPTR to indirectly address the external ram.
36895 The compiler will try to allocate the appropriate register to pointer variables
36897 ICode example section shows the operands annotated with the registers assigned
36899 The compiler will try to keep operands in registers as much as possible;
36900 there are several schemes the compiler uses to do achieve this.
36901 When the compiler runs out of registers the compiler will check to see
36902 if there are any live operands which is not used or defined in the current
36903 basic block being processed, if there are any found then it will push that
36904 operand and use the registers in this block, the operand will then be popped
36905 at the end of the basic block.
36909 \begin_layout Standard
36910 There are other MCU specific considerations in this phase.
36911 Some MCUs have an accumulator; very short-lived operands could be assigned
36912 to the accumulator instead of a general-purpose register.
36915 \begin_layout Paragraph*
36919 \begin_layout Standard
36920 Figure II gives a table of iCode
36921 \begin_inset LatexCommand \index{iCode}
36925 operations supported by the compiler.
36926 The code generation involves translating these operations into corresponding
36927 assembly code for the processor.
36928 This sounds overly simple but that is the essence of code generation.
36929 Some of the iCode operations are generated on a MCU specific manner for
36930 example, the z80 port does not use registers to pass parameters so the
36931 SEND and RECV iCode operations will not be generated, and it also does
36932 not support JUMPTABLES.
36938 \begin_layout Standard
36942 \begin_inset Tabular
36943 <lyxtabular version="3" rows="39" columns="4">
36944 <features islongtable="true" headBottomDL="true">
36945 <column alignment="block" valignment="top" leftline="true" width="13col%">
36946 <column alignment="left" valignment="top" leftline="true" width="13col%">
36947 <column alignment="block" valignment="top" leftline="true" width="22col%">
36948 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
36949 <row topline="true" bottomline="true" endhead="true">
36950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36953 \begin_layout Standard
36959 \begin_inset LatexCommand \index{iCode}
36968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36971 \begin_layout Standard
36979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36982 \begin_layout Standard
36990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36993 \begin_layout Standard
37002 <row topline="true">
37003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37006 \begin_layout Standard
37014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37017 \begin_layout Standard
37020 IC_LEFT() IC_RESULT()
37025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37028 \begin_layout Standard
37036 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37039 \begin_layout Standard
37042 IC_RESULT = ! IC_LEFT;
37048 <row topline="true">
37049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37052 \begin_layout Standard
37060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37063 \begin_layout Standard
37066 IC_LEFT() IC_RESULT()
37071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37074 \begin_layout Standard
37077 Bitwise complement of
37082 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37085 \begin_layout Standard
37088 IC_RESULT = ~IC_LEFT;
37094 <row topline="true">
37095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37098 \begin_layout Standard
37106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37109 \begin_layout Standard
37112 IC_LEFT() IC_RESULT()
37117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37120 \begin_layout Standard
37123 Rotate right with carry
37128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37131 \begin_layout Standard
37134 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
37140 <row topline="true">
37141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37144 \begin_layout Standard
37152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37155 \begin_layout Standard
37158 IC_LEFT() IC_RESULT()
37163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37166 \begin_layout Standard
37169 Rotate left with carry
37174 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37177 \begin_layout Standard
37180 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
37186 <row topline="true">
37187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37190 \begin_layout Standard
37198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37201 \begin_layout Standard
37204 IC_LEFT() IC_RESULT()
37209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37212 \begin_layout Standard
37215 Get the highest order bit of IC_LEFT
37220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37223 \begin_layout Standard
37226 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
37232 <row topline="true">
37233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37236 \begin_layout Standard
37244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37247 \begin_layout Standard
37250 IC_LEFT() IC_RESULT()
37255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37258 \begin_layout Standard
37266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37269 \begin_layout Standard
37272 IC_RESULT = - IC_LEFT;
37278 <row topline="true">
37279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37282 \begin_layout Standard
37290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37293 \begin_layout Standard
37301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37304 \begin_layout Standard
37307 Push the operand into stack
37312 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37315 \begin_layout Standard
37324 <row topline="true">
37325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37328 \begin_layout Standard
37336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37339 \begin_layout Standard
37347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37350 \begin_layout Standard
37353 Pop the operand from the stack
37358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37361 \begin_layout Standard
37370 <row topline="true">
37371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37374 \begin_layout Standard
37382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37385 \begin_layout Standard
37388 IC_LEFT() IC_RESULT()
37393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37396 \begin_layout Standard
37399 Call the function represented by IC_LEFT
37404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37407 \begin_layout Standard
37410 IC_RESULT = IC_LEFT();
37416 <row topline="true">
37417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37420 \begin_layout Standard
37428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37431 \begin_layout Standard
37434 IC_LEFT() IC_RESULT()
37439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37442 \begin_layout Standard
37445 Call via function pointer
37450 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37453 \begin_layout Standard
37456 IC_RESULT = (*IC_LEFT)();
37462 <row topline="true">
37463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37466 \begin_layout Standard
37474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37477 \begin_layout Standard
37485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37488 \begin_layout Standard
37491 Return the value in operand IC_LEFT
37496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37499 \begin_layout Standard
37508 <row topline="true">
37509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37512 \begin_layout Standard
37520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37523 \begin_layout Standard
37531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37534 \begin_layout Standard
37542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37545 \begin_layout Standard
37554 <row topline="true">
37555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37558 \begin_layout Standard
37566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37569 \begin_layout Standard
37577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37580 \begin_layout Standard
37588 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37591 \begin_layout Standard
37600 <row topline="true">
37601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37604 \begin_layout Standard
37612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37615 \begin_layout Standard
37618 IC_LEFT() IC_RIGHT() IC_RESULT()
37623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37626 \begin_layout Standard
37634 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37637 \begin_layout Standard
37640 IC_RESULT = IC_LEFT + IC_RIGHT
37646 <row topline="true">
37647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37650 \begin_layout Standard
37658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37661 \begin_layout Standard
37664 IC_LEFT() IC_RIGHT() IC_RESULT()
37669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37672 \begin_layout Standard
37680 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37683 \begin_layout Standard
37686 IC_RESULT = IC_LEFT - IC_RIGHT
37692 <row topline="true">
37693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37696 \begin_layout Standard
37704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37707 \begin_layout Standard
37710 IC_LEFT() IC_RIGHT() IC_RESULT()
37715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37718 \begin_layout Standard
37726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37729 \begin_layout Standard
37732 IC_RESULT = IC_LEFT * IC_RIGHT;
37738 <row topline="true">
37739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37742 \begin_layout Standard
37750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37753 \begin_layout Standard
37756 IC_LEFT() IC_RIGHT() IC_RESULT()
37761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37764 \begin_layout Standard
37772 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37775 \begin_layout Standard
37778 IC_RESULT = IC_LEFT / IC_RIGHT;
37784 <row topline="true">
37785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37788 \begin_layout Standard
37796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37799 \begin_layout Standard
37802 IC_LEFT() IC_RIGHT() IC_RESULT()
37807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37810 \begin_layout Standard
37818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37821 \begin_layout Standard
37824 IC_RESULT = IC_LEFT % IC_RIGHT;
37830 <row topline="true">
37831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37834 \begin_layout Standard
37842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37845 \begin_layout Standard
37848 IC_LEFT() IC_RIGHT() IC_RESULT()
37853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37856 \begin_layout Standard
37864 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37867 \begin_layout Standard
37870 IC_RESULT = IC_LEFT < IC_RIGHT;
37876 <row topline="true">
37877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37880 \begin_layout Standard
37888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37891 \begin_layout Standard
37894 IC_LEFT() IC_RIGHT() IC_RESULT()
37899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37902 \begin_layout Standard
37910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37913 \begin_layout Standard
37916 IC_RESULT = IC_LEFT > IC_RIGHT;
37922 <row topline="true">
37923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37926 \begin_layout Standard
37934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37937 \begin_layout Standard
37940 IC_LEFT() IC_RIGHT() IC_RESULT()
37945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37948 \begin_layout Standard
37956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37959 \begin_layout Standard
37962 IC_RESULT = IC_LEFT == IC_RIGHT;
37968 <row topline="true">
37969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37972 \begin_layout Standard
37980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37983 \begin_layout Standard
37986 IC_LEFT() IC_RIGHT() IC_RESULT()
37991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37994 \begin_layout Standard
37997 Logical and operation
38002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38005 \begin_layout Standard
38008 IC_RESULT = IC_LEFT && IC_RIGHT;
38014 <row topline="true">
38015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38018 \begin_layout Standard
38026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38029 \begin_layout Standard
38032 IC_LEFT() IC_RIGHT() IC_RESULT()
38037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38040 \begin_layout Standard
38043 Logical or operation
38048 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38051 \begin_layout Standard
38054 IC_RESULT = IC_LEFT || IC_RIGHT;
38060 <row topline="true">
38061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38064 \begin_layout Standard
38072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38075 \begin_layout Standard
38078 IC_LEFT() IC_RIGHT() IC_RESULT()
38083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38086 \begin_layout Standard
38094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38097 \begin_layout Standard
38100 IC_RESULT = IC_LEFT ^ IC_RIGHT;
38106 <row topline="true">
38107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38110 \begin_layout Standard
38118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38121 \begin_layout Standard
38124 IC_LEFT() IC_RIGHT() IC_RESULT()
38129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38132 \begin_layout Standard
38140 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38143 \begin_layout Standard
38146 IC_RESULT = IC_LEFT | IC_RIGHT;
38152 <row topline="true">
38153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38156 \begin_layout Standard
38164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38167 \begin_layout Standard
38170 IC_LEFT() IC_RIGHT() IC_RESULT()
38175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38178 \begin_layout Standard
38186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38189 \begin_layout Standard
38192 IC_RESULT = IC_LEFT & IC_RIGHT;
38198 <row topline="true">
38199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38202 \begin_layout Standard
38210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38213 \begin_layout Standard
38216 IC_LEFT() IC_RIGHT() IC_RESULT()
38221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38224 \begin_layout Standard
38232 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38235 \begin_layout Standard
38238 IC_RESULT = IC_LEFT << IC_RIGHT
38244 <row topline="true">
38245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38248 \begin_layout Standard
38256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38259 \begin_layout Standard
38262 IC_LEFT() IC_RIGHT() IC_RESULT()
38267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38270 \begin_layout Standard
38278 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38281 \begin_layout Standard
38284 IC_RESULT = IC_LEFT >> IC_RIGHT
38290 <row topline="true">
38291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38294 \begin_layout Standard
38304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38307 \begin_layout Standard
38310 IC_LEFT() IC_RESULT()
38315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38318 \begin_layout Standard
38326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38329 \begin_layout Standard
38332 IC_RESULT = (*IC_LEFT);
38338 <row topline="true">
38339 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38342 \begin_layout Standard
38350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38353 \begin_layout Standard
38356 IC_RIGHT() IC_RESULT()
38361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38364 \begin_layout Standard
38372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38375 \begin_layout Standard
38378 (*IC_RESULT) = IC_RIGHT;
38384 <row topline="true">
38385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38388 \begin_layout Standard
38396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38399 \begin_layout Standard
38402 IC_RIGHT() IC_RESULT()
38407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38410 \begin_layout Standard
38418 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38421 \begin_layout Standard
38424 IC_RESULT = IC_RIGHT;
38430 <row topline="true">
38431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38434 \begin_layout Standard
38442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38445 \begin_layout Standard
38448 IC_COND IC_TRUE IC_LABEL
38453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38456 \begin_layout Standard
38460 If true label is present then jump to true label if condition is true else
38461 jump to false label if condition is false
38466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38469 \begin_layout Standard
38472 if (IC_COND) goto IC_TRUE;
38478 If (!IC_COND) goto IC_FALSE;
38484 <row topline="true">
38485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38488 \begin_layout Standard
38496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38499 \begin_layout Standard
38502 IC_LEFT() IC_RESULT()
38507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38510 \begin_layout Standard
38518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38521 \begin_layout Standard
38524 IC_RESULT = &IC_LEFT();
38530 <row topline="true">
38531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38534 \begin_layout Standard
38542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38545 \begin_layout Standard
38548 IC_JTCOND IC_JTLABELS
38553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38556 \begin_layout Standard
38559 Jump to list of labels depending on the value of JTCOND
38564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38567 \begin_layout Standard
38576 <row topline="true">
38577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38580 \begin_layout Standard
38588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38591 \begin_layout Standard
38594 IC_RIGHT() IC_LEFT() IC_RESULT()
38599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38602 \begin_layout Standard
38610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38613 \begin_layout Standard
38616 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
38622 <row topline="true">
38623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38626 \begin_layout Standard
38634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38637 \begin_layout Standard
38645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38648 \begin_layout Standard
38651 This is used for passing parameters in registers;
38653 move IC_LEFT to the next
38654 available parameter register.
38659 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38662 \begin_layout Standard
38671 <row topline="true">
38672 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38675 \begin_layout Standard
38683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38686 \begin_layout Standard
38694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38697 \begin_layout Standard
38700 This is used for receiving parameters passed in registers;
38703 in the next parameter register to IC_RESULT
38708 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38711 \begin_layout Standard
38720 <row topline="true" bottomline="true">
38721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38724 \begin_layout Standard
38728 (some more have been added)
38733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38736 \begin_layout Standard
38742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38745 \begin_layout Standard
38751 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38754 \begin_layout Standard
38778 \begin_layout Standard
38779 \begin_inset Note Note
38782 \begin_layout Standard
38783 In the original article Figure II was announced to be downloadable on
38788 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
38796 \begin_layout Paragraph*
38798 \begin_inset LatexCommand \index{iCode}
38805 \begin_layout Standard
38806 This section shows some details of iCode.
38807 The example C code does not do anything useful; it is used as an example
38808 to illustrate the intermediate code generated by the compiler.
38811 \begin_layout Verse
38821 /* This function does nothing useful.
38828 for the purpose of explaining iCode */
38831 short function (data
38840 short i=10; \InsetSpace ~
38842 /* dead initialization eliminated */
38848 /* dead initialization eliminated */
38876 /* compiler detects i,j to be induction
38881 for (i = 0, j = 10 ; i < 10 ; i++, j
38887 \begin_layout Standard
38910 mul += i * 3; \InsetSpace ~
38912 /* this multiplication remains */
38919 j * 3;\InsetSpace ~
38921 /* this multiplication changed to addition */
38935 \begin_layout Standard
38936 In addition to the operands each iCode contains information about the filename
38937 and line it corresponds to in the source file.
38938 The first field in the listing should be interpreted as follows:
38943 Filename(linenumber: iCode Execution sequence number : ICode hash table
38944 key : loop depth of the iCode).
38949 Then follows the human readable form of the ICode operation.
38950 Each operand of this triplet form can be of three basic types a) compiler
38951 generated temporary b) user defined variable c) a constant value.
38952 Note that local variables and parameters are replaced by compiler generated
38955 \begin_inset LatexCommand \index{Live range analysis}
38959 are computed only for temporaries (i.e.
38960 live ranges are not computed for global variables).
38962 \begin_inset LatexCommand \index{Register allocation}
38966 are allocated for temporaries only.
38967 Operands are formatted in the following manner:
38972 Operand Name [lr live-from : live-to ] { type information } [ registers
38978 As mentioned earlier the live ranges are computed in terms of the execution
38979 sequence number of the iCodes, for example
38981 the iTemp0 is live from (i.e.
38982 first defined in iCode with execution sequence number 3, and is last used
38983 in the iCode with sequence number 5).
38984 For induction variables such as iTemp21 the live range computation extends
38985 the lifetime from the start to the end of the loop.
38987 The register allocator
38988 used the live range information to allocate registers, the same registers
38989 may be used for different temporaries if their live ranges do not overlap,
38990 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
38991 ranges do not overlap.
38992 In addition the allocator also takes into consideration the type and usage
38993 of a temporary, for example itemp6 is a pointer to near space and is used
38994 as to fetch data from (i.e.
38995 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
38996 Some short lived temporaries are allocated to special registers which have
38997 meaning to the code generator e.g.
38998 iTemp13 is allocated to a pseudo register CC which tells the back end that
38999 the temporary is used only for a conditional jump the code generation makes
39000 use of this information to optimize a compare and jump ICode.
39004 \begin_inset LatexCommand \index{Loop optimization}
39008 performed by the compiler.
39009 It can detect induction variables iTemp21(i) and iTemp23(j).
39010 Also note the compiler does selective strength reduction
39011 \begin_inset LatexCommand \index{Strength reduction}
39016 the multiplication of an induction variable in line 18 (gint = j * 3) is
39017 changed to addition, a new temporary iTemp17 is allocated and assigned
39018 a initial value, a constant 3 is then added for each iteration of the loop.
39019 The compiler does not change the multiplication
39020 \begin_inset LatexCommand \index{Multiplication}
39024 in line 17 however since the processor does support an 8 * 8 bit multiplication.
39027 Note the dead code elimination
39028 \begin_inset LatexCommand \index{Dead-code elimination}
39032 optimization eliminated the dead assignments in line 7 & 8 to I and sum
39038 \begin_layout Standard
39041 Sample.c (5:1:0:0) _entry($9) :
39044 \begin_layout Standard
39047 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
39050 \begin_layout Standard
39053 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
39056 \begin_layout Standard
39059 Sample.c(11:4:53:0) preHeaderLbl0($11) :
39062 \begin_layout Standard
39065 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
39069 \begin_layout Standard
39072 Sample.c(11:6:5:1) _whilecontinue_0($1) :
39075 \begin_layout Standard
39078 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
39082 \begin_layout Standard
39085 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39088 \begin_layout Standard
39091 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
39095 \begin_layout Standard
39098 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
39102 \begin_layout Standard
39105 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
39109 \begin_layout Standard
39112 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
39116 \begin_layout Standard
39119 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
39120 * int}[r0] + 0x2 {short}
39123 \begin_layout Standard
39126 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
39129 \begin_layout Standard
39132 Sample.c(11:17:21:0)_whilebreak_0($3) :
39135 \begin_layout Standard
39138 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39141 \begin_layout Standard
39144 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39147 \begin_layout Standard
39150 Sample.c(15:20:54:0)preHeaderLbl1($13) :
39153 \begin_layout Standard
39156 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39159 \begin_layout Standard
39162 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39165 \begin_layout Standard
39168 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39171 \begin_layout Standard
39174 Sample.c(15:24:26:1)_forcond_0($4) :
39177 \begin_layout Standard
39180 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
39184 \begin_layout Standard
39187 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39190 \begin_layout Standard
39193 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
39194 + ITemp21 [lr21:38]{short}[r4]
39197 \begin_layout Standard
39200 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
39204 \begin_layout Standard
39207 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
39208 + iTemp15 [lr29:30]{short}[r1]
39211 \begin_layout Standard
39214 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
39218 \begin_layout Standard
39221 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
39225 \begin_layout Standard
39228 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
39232 \begin_layout Standard
39235 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
39239 \begin_layout Standard
39242 Sample.c(19:38:47:1) goto _forcond_0($4)
39245 \begin_layout Standard
39248 Sample.c(19:39:48:0)_forbreak_0($7) :
39251 \begin_layout Standard
39254 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
39255 + ITemp11 [lr19:40]{short}[r3]
39258 \begin_layout Standard
39261 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
39264 \begin_layout Standard
39267 Sample.c(20:42:51:0)_return($8) :
39270 \begin_layout Standard
39273 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
39279 Finally the code generated for this function:
39284 \begin_layout Standard
39290 \begin_layout Standard
39296 \begin_layout Standard
39304 \begin_layout Standard
39310 \begin_layout Standard
39318 \begin_layout Standard
39324 \begin_layout Standard
39327 ; ----------------------------------------------
39330 \begin_layout Standard
39333 ; function function
39336 \begin_layout Standard
39339 ; ----------------------------------------------
39342 \begin_layout Standard
39348 \begin_layout Standard
39351 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
39354 \begin_layout Standard
39362 \begin_layout Standard
39365 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
39368 \begin_layout Standard
39376 \begin_layout Standard
39379 ;_whilecontinue_0($1) :
39382 \begin_layout Standard
39388 \begin_layout Standard
39391 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
39394 \begin_layout Standard
39397 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39400 \begin_layout Standard
39408 \begin_layout Standard
39416 \begin_layout Standard
39424 \begin_layout Standard
39432 \begin_layout Standard
39440 \begin_layout Standard
39448 \begin_layout Standard
39456 \begin_layout Standard
39462 \begin_layout Standard
39465 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
39468 \begin_layout Standard
39476 \begin_layout Standard
39484 \begin_layout Standard
39487 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
39490 \begin_layout Standard
39498 \begin_layout Standard
39506 \begin_layout Standard
39514 \begin_layout Standard
39522 \begin_layout Standard
39530 \begin_layout Standard
39538 \begin_layout Standard
39541 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
39544 \begin_layout Standard
39552 \begin_layout Standard
39560 \begin_layout Standard
39568 \begin_layout Standard
39576 \begin_layout Standard
39584 \begin_layout Standard
39587 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
39590 \begin_layout Standard
39598 \begin_layout Standard
39606 \begin_layout Standard
39614 \begin_layout Standard
39617 ; iTemp6 [lr5:16]{_near * int}[r0] =
39620 \begin_layout Standard
39623 ; iTemp6 [lr5:16]{_near * int}[r0] +
39626 \begin_layout Standard
39632 \begin_layout Standard
39640 \begin_layout Standard
39643 ; goto _whilecontinue_0($1)
39646 \begin_layout Standard
39654 \begin_layout Standard
39657 ; _whilebreak_0($3) :
39660 \begin_layout Standard
39666 \begin_layout Standard
39669 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39672 \begin_layout Standard
39680 \begin_layout Standard
39683 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39686 \begin_layout Standard
39694 \begin_layout Standard
39697 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39700 \begin_layout Standard
39708 \begin_layout Standard
39711 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39714 \begin_layout Standard
39722 \begin_layout Standard
39730 \begin_layout Standard
39733 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39736 \begin_layout Standard
39744 \begin_layout Standard
39752 \begin_layout Standard
39758 \begin_layout Standard
39764 \begin_layout Standard
39767 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
39770 \begin_layout Standard
39773 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39776 \begin_layout Standard
39784 \begin_layout Standard
39792 \begin_layout Standard
39800 \begin_layout Standard
39808 \begin_layout Standard
39816 \begin_layout Standard
39822 \begin_layout Standard
39825 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
39828 \begin_layout Standard
39831 ; iTemp21 [lr21:38]{short}[r4]
39834 \begin_layout Standard
39842 \begin_layout Standard
39850 \begin_layout Standard
39858 \begin_layout Standard
39861 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
39864 \begin_layout Standard
39872 \begin_layout Standard
39880 \begin_layout Standard
39888 \begin_layout Standard
39896 \begin_layout Standard
39899 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
39902 \begin_layout Standard
39905 ; iTemp15 [lr29:30]{short}[r1]
39908 \begin_layout Standard
39916 \begin_layout Standard
39924 \begin_layout Standard
39927 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
39930 \begin_layout Standard
39938 \begin_layout Standard
39946 \begin_layout Standard
39954 \begin_layout Standard
39962 \begin_layout Standard
39970 \begin_layout Standard
39978 \begin_layout Standard
39981 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
39984 \begin_layout Standard
39992 \begin_layout Standard
40000 \begin_layout Standard
40008 \begin_layout Standard
40016 \begin_layout Standard
40024 \begin_layout Standard
40032 \begin_layout Standard
40035 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
40038 \begin_layout Standard
40046 \begin_layout Standard
40049 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
40052 \begin_layout Standard
40060 \begin_layout Standard
40065 cjne r5,#0xff,00104$
40068 \begin_layout Standard
40076 \begin_layout Standard
40079 ; goto _forcond_0($4)
40082 \begin_layout Standard
40090 \begin_layout Standard
40093 ; _forbreak_0($7) :
40096 \begin_layout Standard
40102 \begin_layout Standard
40105 ; ret iTemp24 [lr40:41]{short}
40108 \begin_layout Standard
40116 \begin_layout Standard
40124 \begin_layout Standard
40132 \begin_layout Standard
40138 \begin_layout Standard
40144 \begin_layout Standard
40154 \begin_layout Section
40155 A few words about basic block successors, predecessors and dominators
40158 \begin_layout Standard
40159 Successors are basic blocks
40160 \begin_inset LatexCommand \index{Basic blocks}
40164 that might execute after this basic block.
40166 Predecessors are basic blocks
40167 that might execute before reaching this basic block.
40169 Dominators are basic
40170 blocks that WILL execute before reaching this basic block.
40175 \begin_layout Standard
40179 \begin_layout Standard
40183 \begin_layout Standard
40191 \begin_layout Standard
40195 \begin_layout Standard
40203 \begin_layout Standard
40209 \begin_layout Standard
40210 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
40213 \begin_layout Standard
40214 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
40217 \begin_layout Standard
40218 c) domVect of [BB4] = BB1 ...
40219 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
40223 \begin_layout Chapter
40227 \begin_layout Standard
40228 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
40238 Thanks to all the other volunteer developers who have helped with coding,
40239 testing, web-page creation, distribution sets, etc.
40240 You know who you are :-)
40248 Thanks to Sourceforge
40249 \begin_inset LatexCommand \url{http://www.sf.net}
40253 which has hosted the project since 1999 and donates significant download
40262 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
40263 cycles and bandwidth for snapshot builds.
40268 \begin_layout Standard
40269 This document was initially written by Sandeep Dutta
40272 \begin_layout Standard
40273 All product names mentioned herein may be trademarks
40274 \begin_inset LatexCommand \index{Trademarks}
40278 of their respective companies.
40282 \begin_layout Section*
40286 \begin_layout Standard
40287 To avoid confusion, the installation and building options for SDCC itself
40288 (chapter 2) are not part of the index.
40291 \begin_layout Standard
40292 \begin_inset LatexCommand \printindex{}