1 #LyX 1.4.4 created this file. For more info see http://www.lyx.org/
7 \pdfoptionpdfminorversion=3
9 pdftitle={SDCC Compiler User Guide},
10 pdfauthor={SDCC development team},
11 pdfsubject={installation, user manual},
12 pdfkeywords={68hc08 8032 8051 ansi c compiler assembler CPU DS390 embedded development free Floating Point Arithmetic Freescale GPL HC08 inline Intel ISO/IEC 9899:1990 Linux MAC OS X manual Maxim mcs51 Microchip microcontroller open source PIC Unix Windows Z80 Zilog},
13 pdfpagemode=UseOutlines,
15 linkcolor=blue] {hyperref}
19 \emergencystretch=30pt
24 \inputencoding default
27 \paperfontsize default
29 \papersize letterpaper
34 \paperorientation portrait
41 \paragraph_separation indent
43 \quotes_language swedish
47 \tracking_changes false
53 \begin_layout Standard
54 \begin_inset Note Note
57 \begin_layout Standard
58 Please note: double dashed longoptions (e.g.
59 --version) are written this way: -
63 \begin_layout Standard
75 \begin_layout Standard
77 three consecutive dashes would otherwise result in a long resp.
81 \begin_layout Standard
82 Architecture specific stuff (like memory models, code examples) should maybe
86 \begin_layout Standard
87 into seperate sections/chapters/appendices (it is hard to document PIC or
91 \begin_layout Standard
92 a 8051 centered document) - for now simply add.
101 SDCC Compiler User Guide
116 \begin_layout Standard
117 \begin_inset Note Note
120 \begin_layout Standard
121 The above strings enclosed in $ are automatically updated by Subversion
129 \begin_layout Standard
130 \begin_inset LatexCommand \tableofcontents{}
137 \begin_layout Chapter
141 \begin_layout Section
145 \begin_layout Standard
166 ompiler) is free open source, retargettable, optimizing ANSI-C compiler
171 designed for 8 bit Microprocessors.
172 The current version targets Intel MCS51 based Microprocessors (8031, 8032,
174 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
178 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
179 Zilog Z80 based MCUs.
180 It can be retargeted for other microprocessors, support for Microchip PIC,
181 Atmel AVR is under development.
182 The entire source code for the compiler is distributed under GPL.
184 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
189 \begin_inset LatexCommand \index{aslink}
193 , an open source retargetable assembler & linker.
194 SDCC has extensive language extensions suitable for utilizing various microcont
195 rollers and underlying hardware effectively.
200 In addition to the MCU specific optimizations SDCC also does a host of
201 standard optimizations like:
204 \begin_layout Itemize
205 global sub expression elimination,
208 \begin_layout Itemize
209 loop optimizations (loop invariant, strength reduction of induction variables
213 \begin_layout Itemize
214 constant folding & propagation,
217 \begin_layout Itemize
221 \begin_layout Itemize
222 dead code elimination
225 \begin_layout Itemize
233 \begin_layout Standard
234 For the back-end SDCC uses a global register allocation scheme which should
235 be well suited for other 8 bit MCUs.
240 The peep hole optimizer uses a rule based substitution mechanism which
246 Supported data-types are:
249 \begin_layout Standard
251 <lyxtabular version="3" rows="8" columns="5">
253 <column alignment="center" valignment="top" leftline="true" width="0">
254 <column alignment="center" valignment="top" leftline="true" width="0">
255 <column alignment="center" valignment="top" leftline="true" width="0">
256 <column alignment="center" valignment="top" leftline="true" width="0">
257 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
258 <row topline="true" bottomline="true">
259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
262 \begin_layout Standard
268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
271 \begin_layout Standard
277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
280 \begin_layout Standard
286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
289 \begin_layout Standard
295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
298 \begin_layout Standard
306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
309 \begin_layout Standard
315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
318 \begin_layout Standard
324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
327 \begin_layout Standard
333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
336 \begin_layout Standard
342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
345 \begin_layout Standard
353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
356 \begin_layout Standard
362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
365 \begin_layout Standard
371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
374 \begin_layout Standard
380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
383 \begin_layout Standard
389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
392 \begin_layout Standard
400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
403 \begin_layout Standard
409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
412 \begin_layout Standard
418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
421 \begin_layout Standard
427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
430 \begin_layout Standard
436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
439 \begin_layout Standard
447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
450 \begin_layout Standard
456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
459 \begin_layout Standard
465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
468 \begin_layout Standard
474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
477 \begin_layout Standard
483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
486 \begin_layout Standard
493 <row topline="true" bottomline="true">
494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
497 \begin_layout Standard
503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
506 \begin_layout Standard
512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
515 \begin_layout Standard
521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
524 \begin_layout Standard
525 -2.147.483.648, +2.147.483.647
530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
533 \begin_layout Standard
540 <row topline="true" bottomline="true">
541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
544 \begin_layout Standard
550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
553 \begin_layout Standard
559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
562 \begin_layout Standard
568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
571 \begin_layout Standard
577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
580 \begin_layout Standard
596 <row topline="true" bottomline="true">
597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
600 \begin_layout Standard
606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
609 \begin_layout Standard
615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
618 \begin_layout Standard
624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
627 \begin_layout Standard
633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
636 \begin_layout Standard
649 The compiler also allows
651 inline assembler code
653 to be embedded anywhere in a function.
654 In addition, routines developed in assembly can also be called.
659 provides an option (-
663 \begin_layout Standard
672 -cyclomatic) to report the relative complexity of a function.
673 These functions can then be further optimized, or hand coded in assembly
679 SDCC also comes with a companion source level debugger SDCDB.
680 The debugger currently uses ucSim, a free open source simulator for 8051
681 and other micro-controllers.
685 The latest SDCC version can be downloaded from
687 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
697 Please note: the compiler will probably always be some steps ahead of this
702 \begin_inset LatexCommand \index{Status of documentation}
710 \begin_layout Standard
711 Obviously this has pros and cons
719 \begin_layout Section
723 \begin_layout Standard
724 All packages used in this compiler system are
732 ; source code for all the sub-packages (pre-processor, assemblers, linkers
733 etc.) is distributed with the package.
734 This documentation is maintained using a free open source word processor
737 This program is free software; you can redistribute it and/or modify
738 it under the terms of the GNU General Public License
739 \begin_inset LatexCommand \index{GNU General Public License, GPL}
743 as published by the Free Software Foundation; either version 2, or (at
744 your option) any later version.
745 This program is distributed in the hope that it will be useful, but WITHOUT
746 ANY WARRANTY; without even the implied warranty
747 \begin_inset LatexCommand \index{warranty}
751 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
752 See the GNU General Public License for more details.
753 You should have received a copy of the GNU General Public License along
754 with this program; if not, write to the Free Software Foundation, 59 Temple
755 Place - Suite 330, Boston, MA 02111-1307, USA.
756 In other words, you are welcome to use, share and improve this program.
757 You are forbidden to forbid anyone else to use, share and improve what
759 Help stamp out software-hoarding!
762 \begin_layout Section
763 Typographic conventions
764 \begin_inset LatexCommand \index{Typographic conventions}
771 \begin_layout Standard
772 Throughout this manual, we will use the following convention.
773 Commands you have to type in are printed in
781 Code samples are printed in
786 Interesting items and new terms are printed in
791 \begin_layout Section
793 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
797 with previous versions
798 \begin_inset LatexCommand \index{Compatibility with previous versions}
805 \begin_layout Standard
806 Newer versions have usually numerous bug fixes compared with the previous
808 But we also sometimes introduce some incompatibilities with older versions.
809 Not just for the fun of it, but to make the compiler more stable, efficient
811 \begin_inset LatexCommand \index{ANSI-compliance}
816 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
820 for ANSI-Compliance).
822 \begin_inset Note Note
825 \begin_layout Standard
826 It would be fine to add to each item, in which version was it changed.
836 \begin_layout Itemize
837 short is now equivalent to int (16 bits), it used to be equivalent to char
838 (8 bits) which is not ANSI compliant.
839 To maintain compatibility, old programs may be compiled using the -
843 \begin_layout Standard
852 -short-is-8bits commandline option (see
853 \begin_inset LatexCommand \vref{lyx:--short-is-8bits}
860 \begin_layout Itemize
861 the default directory for gcc-builds where include, library and documentation
862 files are stored is now in /usr/local/share.
865 \begin_layout Itemize
866 char type parameters to vararg
867 \begin_inset LatexCommand \index{vararg, va\_arg}
871 functions are casted to int unless explicitly casted
872 \begin_inset Marginal
875 \begin_layout Standard
900 will push a as an int and as a char resp.
903 \begin_layout Itemize
908 \begin_layout Standard
917 -regextend has been removed.
920 \begin_layout Itemize
925 \begin_layout Standard
934 -noregparms has been removed.
937 \begin_layout Itemize
942 \begin_layout Standard
951 -stack-after-data has been removed.
954 \begin_layout Itemize
956 \begin_inset LatexCommand \index{bit}
961 \begin_inset LatexCommand \index{sbit}
966 \begin_inset LatexCommand \index{\_\_sbit}
970 types now consistently behave like the C99 _Bool type with respect to type
972 \begin_inset LatexCommand \index{type conversion}
977 \begin_inset LatexCommand \index{type promotion}
982 The most common incompatibility resulting from this change is related to
984 \begin_inset LatexCommand \index{Bit toggling}
999 \begin_inset LatexCommand \index{\~\/ Operator}
1003 b; /* equivalent to b=1 instead of toggling b */
1004 \begin_inset Marginal
1007 \begin_layout Standard
1020 b = !b; /* toggles b */
1024 In previous versions, both forms would have toggled the bit.
1027 \begin_layout Standard
1030 <pending: more incompatibilities?>
1033 \begin_layout Section
1037 \begin_layout Standard
1038 What do you need before you start installation of SDCC? A computer, and
1039 a desire to compute.
1040 The preferred method of installation is to compile SDCC from source using
1042 For Windows some pre-compiled binary distributions are available for your
1044 You should have some experience with command line tools and compiler use.
1047 \begin_layout Section
1051 \begin_layout Standard
1052 The SDCC home page at
1053 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1057 is a great place to find distribution sets.
1058 You can also find links to the user mailing lists that offer help or discuss
1059 SDCC with other SDCC users.
1060 Web links to other SDCC related sites can also be found here.
1061 This document can be found in the DOC directory of the source package as
1062 a text or HTML file.
1063 A pdf version of this document is available at
1064 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1069 Some of the other tools (simulator and assembler) included with SDCC contain
1070 their own documentation and can be found in the source distribution.
1071 If you want the latest unreleased software, the complete source package
1072 is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1076 \begin_layout Section
1077 Wishes for the future
1080 \begin_layout Standard
1081 There are (and always will be) some things that could be done.
1082 Here are some I can think of:
1087 \begin_layout Standard
1090 char KernelFunction3(char p) at 0x340;
1095 \begin_layout Standard
1099 \begin_inset LatexCommand \index{code banking (limited support)}
1109 If you can think of some more, please see the section
1110 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1114 about filing feature requests
1115 \begin_inset LatexCommand \index{Requesting features}
1120 \begin_inset LatexCommand \index{Feature request}
1129 \begin_layout Chapter
1131 \begin_inset LatexCommand \index{Installation}
1138 \begin_layout Standard
1139 For most users it is sufficient to skip to either section
1140 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1145 \begin_inset LatexCommand \ref{sub:Windows-Install}
1150 More detailed instructions follow below.
1153 \begin_layout Section
1155 \begin_inset LatexCommand \index{Options SDCC configuration}
1162 \begin_layout Standard
1163 The install paths, search paths and other options are defined when running
1165 The defaults can be overridden by:
1169 \labelwidthstring 00.00.0000
1174 \begin_layout Standard
1183 -prefix see table below
1187 \labelwidthstring 00.00.0000
1192 \begin_layout Standard
1201 -exec_prefix see table below
1205 \labelwidthstring 00.00.0000
1210 \begin_layout Standard
1219 -bindir see table below
1223 \labelwidthstring 00.00.0000
1228 \begin_layout Standard
1237 -datadir see table below
1241 \labelwidthstring 00.00.0000
1246 \begin_layout Standard
1255 -datarootdir see table below
1261 \labelwidthstring 00.00.0000
1264 docdir environment variable, see table below
1268 \labelwidthstring 00.00.0000
1271 include_dir_suffix environment variable, see table below
1275 \labelwidthstring 00.00.0000
1278 lib_dir_suffix environment variable, see table below
1282 \labelwidthstring 00.00.0000
1285 sdccconf_h_dir_separator environment variable, either / or
1290 This character will only be used in sdccconf.h; don't forget it's a C-header,
1291 therefore a double-backslash is needed there.
1297 \labelwidthstring 00.00.0000
1302 \begin_layout Standard
1311 -disable-mcs51-port Excludes the Intel mcs51 port
1315 \labelwidthstring 00.00.0000
1320 \begin_layout Standard
1329 -disable-gbz80-port Excludes the Gameboy gbz80 port
1333 \labelwidthstring 00.00.0000
1338 \begin_layout Standard
1347 -disable-z80-port Excludes the z80 port
1351 \labelwidthstring 00.00.0000
1356 \begin_layout Standard
1365 -disable-avr-port Excludes the AVR port
1369 \labelwidthstring 00.00.0000
1374 \begin_layout Standard
1383 -disable-ds390-port Excludes the DS390 port
1387 \labelwidthstring 00.00.0000
1392 \begin_layout Standard
1401 -disable-hc08-port Excludes the HC08 port
1405 \labelwidthstring 00.00.0000
1410 \begin_layout Standard
1419 -disable-pic-port Excludes the PIC14 port
1423 \labelwidthstring 00.00.0000
1428 \begin_layout Standard
1437 -disable-pic16-port Excludes the PIC16 port
1441 \labelwidthstring 00.00.0000
1446 \begin_layout Standard
1455 -disable-xa51-port Excludes the XA51 port
1459 \labelwidthstring 00.00.0000
1464 \begin_layout Standard
1473 -disable-ucsim Disables configuring and building of ucsim
1477 \labelwidthstring 00.00.0000
1482 \begin_layout Standard
1491 -disable-device-lib Disables automatically building device libraries
1495 \labelwidthstring 00.00.0000
1500 \begin_layout Standard
1509 -disable-packihx Disables building packihx
1515 \labelwidthstring 00.00.0000
1520 \begin_layout Standard
1529 -enable-doc Build pdf, html and txt files from the lyx sources
1533 \labelwidthstring 00.00.0000
1538 \begin_layout Standard
1547 -enable-libgc Use the Bohem memory allocator.
1548 Lower runtime footprint.
1551 \begin_layout Standard
1552 Furthermore the environment variables CC, CFLAGS, ...
1553 the tools and their arguments can be influenced.
1554 Please see `configure -
1558 \begin_layout Standard
1567 -help' and the man/info pages of `configure' for details.
1572 standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1573 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1574 SDCC_LIB_NAME are defined by `configure' too.
1575 At the moment it's not possible to change the default settings (it was
1576 simply never required).
1580 These configure options are compiled into the binaries,
1581 and can only be changed by rerunning 'configure' and recompiling SDCC.
1582 The configure options are written in
1586 to distinguish them from run time environment variables (see section search
1592 \begin_inset Quotes sld
1596 \begin_inset Quotes srd
1599 are used by the SDCC team to build the official Win32 binaries.
1600 The SDCC team uses Mingw32 to build the official Windows binaries, because
1604 \begin_layout Enumerate
1608 \begin_layout Enumerate
1609 a gcc compiler and last but not least
1612 \begin_layout Enumerate
1613 the binaries can be built by cross compiling on SDCC Distributed Compile
1617 \begin_layout Standard
1618 See the examples, how to pass the Win32 settings to 'configure'.
1619 The other Win32 builds using Borland, VC or whatever don't use 'configure',
1620 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1630 \begin_layout Standard
1632 \begin_inset Tabular
1633 <lyxtabular version="3" rows="9" columns="3">
1635 <column alignment="block" valignment="top" leftline="true" width="0in">
1636 <column alignment="block" valignment="top" leftline="true" width="0in">
1637 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1638 <row topline="true" bottomline="true">
1639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1642 \begin_layout Standard
1648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1651 \begin_layout Standard
1657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1660 \begin_layout Standard
1667 <row topline="true">
1668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1671 \begin_layout Standard
1679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1682 \begin_layout Standard
1688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1691 \begin_layout Standard
1700 <row topline="true">
1701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1704 \begin_layout Standard
1712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1715 \begin_layout Standard
1723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1726 \begin_layout Standard
1735 <row topline="true">
1736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1739 \begin_layout Standard
1747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1750 \begin_layout Standard
1760 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1763 \begin_layout Standard
1776 <row topline="true">
1777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1780 \begin_layout Standard
1788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1791 \begin_layout Standard
1799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1802 \begin_layout Standard
1811 <row topline="true">
1812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1815 \begin_layout Standard
1823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1826 \begin_layout Standard
1836 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1839 \begin_layout Standard
1848 <row topline="true">
1849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1852 \begin_layout Standard
1860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1863 \begin_layout Standard
1873 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1876 \begin_layout Standard
1889 <row topline="true">
1890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1893 \begin_layout Standard
1901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1904 \begin_layout Standard
1910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1913 \begin_layout Standard
1920 <row topline="true" bottomline="true">
1921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1924 \begin_layout Standard
1932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1935 \begin_layout Standard
1941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1944 \begin_layout Standard
1960 \begin_layout Standard
1962 'configure' also computes relative paths.
1963 This is needed for full relocatability of a binary package and to complete
1964 search paths (see section search paths below):
1969 \begin_layout Standard
1971 \begin_inset Tabular
1972 <lyxtabular version="3" rows="4" columns="3">
1974 <column alignment="block" valignment="top" leftline="true" width="0in">
1975 <column alignment="block" valignment="top" leftline="true" width="0in">
1976 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1977 <row topline="true" bottomline="true">
1978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1981 \begin_layout Standard
1987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1990 \begin_layout Standard
1996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1999 \begin_layout Standard
2006 <row topline="true" bottomline="true">
2007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2010 \begin_layout Standard
2018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2021 \begin_layout Standard
2027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2030 \begin_layout Standard
2037 <row bottomline="true">
2038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2041 \begin_layout Standard
2049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2052 \begin_layout Standard
2058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2061 \begin_layout Standard
2068 <row bottomline="true">
2069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2072 \begin_layout Standard
2080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2083 \begin_layout Standard
2089 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2092 \begin_layout Standard
2108 \begin_layout Standard
2113 \begin_layout LyX-Code
2120 \begin_layout Standard
2130 \begin_inset Quotes srd
2134 \begin_inset Quotes srd
2141 \begin_layout Standard
2151 \begin_inset Quotes srd
2155 \begin_inset Quotes srd
2164 \begin_layout Standard
2177 \begin_layout Standard
2189 \begin_layout Standard
2190 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2194 \begin_layout LyX-Code
2200 \begin_inset Quotes srd
2203 i586-mingw32msvc-gcc
2204 \begin_inset Quotes srd
2208 \begin_inset Quotes srd
2211 i586-mingw32msvc-g++
2212 \begin_inset Quotes srd
2220 \begin_inset Quotes srd
2223 i586-mingw32msvc-ranlib
2224 \begin_inset Quotes srd
2232 \begin_inset Quotes srd
2235 i586-mingw32msvc-strip
2236 \begin_inset Quotes srd
2247 \begin_layout Standard
2257 \begin_inset Quotes srd
2261 \begin_inset Quotes srd
2272 \begin_layout Standard
2282 \begin_inset Quotes srd
2286 \begin_inset Quotes srd
2294 \begin_inset Quotes srd
2300 \begin_inset Quotes srd
2308 \begin_inset Quotes srd
2312 \begin_inset Quotes srd
2320 \begin_inset Quotes srd
2324 \begin_inset Quotes srd
2331 sdccconf_h_dir_separator=
2332 \begin_inset Quotes srd
2344 \begin_inset Quotes srd
2355 \begin_layout Standard
2372 \begin_layout Standard
2381 -host=i586-mingw32msvc
2389 \begin_layout Standard
2398 -build=unknown-unknown-linux-gnu
2401 \begin_layout Standard
2403 \begin_inset Quotes sld
2407 \begin_inset Quotes srd
2410 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2414 \begin_layout LyX-Code
2423 \begin_layout Standard
2433 \begin_inset Quotes srd
2437 \begin_inset Quotes srd
2448 \begin_layout Standard
2458 \begin_inset Quotes srd
2462 \begin_inset Quotes srd
2470 \begin_inset Quotes srd
2476 \begin_inset Quotes srd
2484 \begin_inset Quotes srd
2488 \begin_inset Quotes srd
2496 \begin_inset Quotes srd
2500 \begin_inset Quotes srd
2507 sdccconf_h_dir_separator=
2508 \begin_inset Quotes srd
2520 \begin_inset Quotes srd
2528 \begin_inset Quotes srd
2532 \begin_inset Quotes srd
2540 \begin_inset Quotes srd
2544 \begin_inset Quotes srd
2550 \begin_layout Standard
2551 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2556 \begin_layout Standard
2565 -C' turns on caching, which gives a little bit extra speed.
2566 However if options are changed, it can be necessary to delete the config.cache
2570 \begin_layout Section
2572 \begin_inset LatexCommand \label{sub:Install-paths}
2577 \begin_inset LatexCommand \index{Install paths}
2584 \begin_layout Standard
2585 \begin_inset VSpace medskip
2591 \begin_layout Standard
2593 \begin_inset Tabular
2594 <lyxtabular version="3" rows="5" columns="4">
2596 <column alignment="left" valignment="top" leftline="true" width="0">
2597 <column alignment="left" valignment="top" leftline="true" width="0">
2598 <column alignment="left" valignment="top" leftline="true" width="0">
2599 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2600 <row topline="true" bottomline="true">
2601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2604 \begin_layout Standard
2612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2615 \begin_layout Standard
2623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2626 \begin_layout Standard
2634 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2637 \begin_layout Standard
2646 <row topline="true">
2647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2650 \begin_layout Standard
2656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2659 \begin_layout Standard
2667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2670 \begin_layout Standard
2676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2679 \begin_layout Standard
2690 <row topline="true">
2691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2694 \begin_layout Standard
2700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2703 \begin_layout Standard
2706 $DATADIR/ $INCLUDE_DIR_SUFFIX
2711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2714 \begin_layout Standard
2715 /usr/local/share/sdcc/include
2720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2723 \begin_layout Standard
2734 <row topline="true">
2735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2738 \begin_layout Standard
2744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2747 \begin_layout Standard
2750 $DATADIR/$LIB_DIR_SUFFIX
2755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2758 \begin_layout Standard
2759 /usr/local/share/sdcc/lib
2764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2767 \begin_layout Standard
2778 <row topline="true" bottomline="true">
2779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2782 \begin_layout Standard
2788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2791 \begin_layout Standard
2799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2802 \begin_layout Standard
2803 /usr/local/share/sdcc/doc
2808 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2811 \begin_layout Standard
2832 *compiler, preprocessor, assembler, and linker
2838 is auto-appended by the compiler, e.g.
2839 small, large, z80, ds390 etc
2842 \begin_layout Standard
2844 The install paths can still be changed during `make install' with e.g.:
2847 \begin_layout LyX-Code
2848 make install prefix=$(HOME)/local/sdcc
2851 \begin_layout Standard
2852 Of course this doesn't change the search paths compiled into the binaries.
2857 r the install path can be changed by defining DESTDIR
2858 \begin_inset LatexCommand \index{DESTDIR}
2865 \begin_layout LyX-Code
2866 make install DESTDIR=$(HOME)/sdcc.rpm/
2869 \begin_layout Standard
2870 Please note that DESTDIR must have a trailing slash!
2873 \begin_layout Section
2875 \begin_inset LatexCommand \label{sub:Search-Paths}
2880 \begin_inset LatexCommand \index{Search path}
2887 \begin_layout Standard
2888 Some search paths or parts of them are determined by configure variables
2893 , see section above).
2894 Further search paths are determined by environment variables during runtime.
2897 The paths searched when running the compiler are as follows (the first
2903 Binary files (preprocessor, assembler and linker)
2908 \begin_layout Standard
2910 \begin_inset Tabular
2911 <lyxtabular version="3" rows="4" columns="3">
2913 <column alignment="block" valignment="top" leftline="true" width="0in">
2914 <column alignment="block" valignment="top" leftline="true" width="0in">
2915 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2916 <row topline="true" bottomline="true">
2917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2920 \begin_layout Standard
2926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2929 \begin_layout Standard
2935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2938 \begin_layout Standard
2945 <row topline="true">
2946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2949 \begin_layout Standard
2957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2960 \begin_layout Standard
2966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2969 \begin_layout Standard
2978 <row topline="true">
2979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2982 \begin_layout Standard
2983 Path of argv[0] (if available)
2988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2991 \begin_layout Standard
2997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3000 \begin_layout Standard
3007 <row topline="true" bottomline="true">
3008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3011 \begin_layout Standard
3017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3020 \begin_layout Standard
3026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3029 \begin_layout Standard
3045 \begin_layout Standard
3053 \begin_layout Standard
3055 \begin_inset Tabular
3056 <lyxtabular version="3" rows="6" columns="3">
3058 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3059 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3060 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3061 <row topline="true" bottomline="true">
3062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3065 \begin_layout Standard
3071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3074 \begin_layout Standard
3080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3083 \begin_layout Standard
3090 <row topline="true">
3091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3094 \begin_layout Standard
3099 \begin_layout Standard
3113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3116 \begin_layout Standard
3121 \begin_layout Standard
3135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3138 \begin_layout Standard
3143 \begin_layout Standard
3158 <row topline="true">
3159 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3162 \begin_layout Standard
3168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3171 \begin_layout Standard
3177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3180 \begin_layout Standard
3187 <row topline="true">
3188 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3191 \begin_layout Standard
3203 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3206 \begin_layout Standard
3216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3219 \begin_layout Standard
3228 <row topline="true">
3229 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3232 \begin_layout Standard
3248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3251 \begin_layout Standard
3299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3302 \begin_layout Standard
3313 <row topline="true" bottomline="true">
3314 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3317 \begin_layout Standard
3331 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3334 \begin_layout Standard
3335 /usr/local/share/sdcc/
3342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3345 \begin_layout Standard
3361 \begin_layout Standard
3367 \begin_layout Standard
3376 -nostdinc disables the last two search paths.
3386 \begin_layout Standard
3387 With the exception of
3388 \begin_inset Quotes sld
3395 \begin_layout Standard
3405 \begin_inset Quotes srd
3412 is auto-appended by the compiler (e.g.
3413 small, large, z80, ds390 etc.).
3419 \begin_layout Standard
3421 \begin_inset Tabular
3422 <lyxtabular version="3" rows="6" columns="3">
3424 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3425 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3426 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3427 <row topline="true" bottomline="true">
3428 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3431 \begin_layout Standard
3437 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3440 \begin_layout Standard
3446 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3449 \begin_layout Standard
3456 <row topline="true">
3457 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3460 \begin_layout Standard
3465 \begin_layout Standard
3479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3482 \begin_layout Standard
3487 \begin_layout Standard
3501 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3504 \begin_layout Standard
3509 \begin_layout Standard
3524 <row topline="true">
3525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3528 \begin_layout Standard
3538 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3541 \begin_layout Standard
3551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3554 \begin_layout Standard
3567 <row topline="true">
3568 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3571 \begin_layout Standard
3578 $LIB_DIR_SUFFIX/<model>
3583 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3586 \begin_layout Standard
3598 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3601 \begin_layout Standard
3616 <row topline="true">
3617 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3620 \begin_layout Standard
3631 $LIB_DIR_SUFFIX/<model>
3636 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3639 \begin_layout Standard
3690 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3693 \begin_layout Standard
3747 <row topline="true" bottomline="true">
3748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3751 \begin_layout Standard
3756 $LIB_DIR_SUFFIX/<model>
3761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3764 \begin_layout Standard
3765 /usr/local/share/sdcc/
3774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3777 \begin_layout Standard
3793 \begin_layout Standard
3794 \begin_inset Note Note
3797 \begin_layout Standard
3798 Don't delete any of the stray spaces in the table above without checking
3799 the HTML output (last line)!
3807 \begin_layout Standard
3815 \begin_layout Standard
3824 -nostdlib disables the last two search paths.
3827 \begin_layout Section
3829 \begin_inset LatexCommand \index{Building SDCC}
3836 \begin_layout Subsection
3837 Building SDCC on Linux
3838 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3845 \begin_layout Enumerate
3848 Download the source package
3850 either from the SDCC Subversion repository or from snapshot builds
3852 , it will be named something like sdcc
3863 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3870 \begin_layout Enumerate
3873 Bring up a command line terminal, such as xterm.
3876 \begin_layout Enumerate
3879 Unpack the file using a command like:
3882 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
3883 \begin_inset Quotes srd
3889 , this will create a sub-directory called sdcc with all of the sources.
3892 \begin_layout Enumerate
3893 Change directory into the main SDCC directory, for example type:
3901 \begin_layout Enumerate
3911 This configures the package for compilation on your system.
3914 \begin_layout Enumerate
3928 All of the source packages will compile, this can take a while.
3931 \begin_layout Enumerate
3945 This copies the binary executables, the include files, the libraries and
3946 the documentation to the install directories.
3947 Proceed with section
3948 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3955 \begin_layout Subsection
3956 Building SDCC on Mac OS X
3959 \begin_layout Standard
3960 Follow the instruction for Linux.
3964 On Mac OS X 10.2.x it was reported, that the
3965 default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
3966 Fortunately there's also gcc 2.9.x installed, which works fine.
3967 This compiler can be selected by running 'configure' with:
3970 \begin_layout LyX-Code
3971 ./configure CC=gcc2 CXX=g++2
3974 \begin_layout Subsection
3975 Cross compiling SDCC on Linux for Windows
3978 \begin_layout Standard
3979 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3980 See section 'Configure Options'.
3983 \begin_layout Subsection
3984 Building SDCC using Cygwin and Mingw32
3987 \begin_layout Standard
3988 For building and installing a Cygwin executable follow the instructions
3994 \begin_inset Quotes sld
3998 \begin_inset Quotes srd
4001 Win32-binary can be built, which will not need the Cygwin-DLL.
4002 For the necessary 'configure' options see section 'configure options' or
4003 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4008 Cygwin on Windows download setup.exe from
4009 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
4015 \begin_inset Quotes sld
4018 default text file type
4019 \begin_inset Quotes srd
4023 \begin_inset Quotes sld
4027 \begin_inset Quotes srd
4030 and download/install at least the following packages.
4031 Some packages are selected by default, others will be automatically selected
4032 because of dependencies with the manually selected packages.
4033 Never deselect these packages!
4036 \begin_layout Itemize
4040 \begin_layout Itemize
4044 \begin_layout Itemize
4045 gcc ; version 3.x is fine, no need to use the old 2.9x
4048 \begin_layout Itemize
4049 binutils ; selected with gcc
4052 \begin_layout Itemize
4056 \begin_layout Itemize
4057 rxvt ; a nice console, which makes life much easier under windoze (see below)
4060 \begin_layout Itemize
4061 man ; not really needed for building SDCC, but you'll miss it sooner or
4065 \begin_layout Itemize
4066 less ; not really needed for building SDCC, but you'll miss it sooner or
4070 \begin_layout Itemize
4071 svn ; only if you use Subversion access
4074 \begin_layout Standard
4075 If you want to develop something you'll need:
4078 \begin_layout Itemize
4079 python ; for the regression tests
4082 \begin_layout Itemize
4083 gdb ; the gnu debugger, together with the nice GUI
4084 \begin_inset Quotes sld
4088 \begin_inset Quotes srd
4094 \begin_layout Itemize
4095 openssh ; to access the CF or commit changes
4098 \begin_layout Itemize
4099 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4100 use autoconf-stable!
4103 \begin_layout Standard
4104 rxvt is a nice console with history.
4105 Replace in your cygwin.bat the line
4108 \begin_layout LyX-Code
4113 \begin_layout Standard
4125 \begin_layout Standard
4129 \begin_layout LyX-Code
4130 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4133 \begin_layout LyX-Code
4134 -bg black -fg white -geometry 100x65 -e bash -
4138 \begin_layout Standard
4150 \begin_layout Standard
4151 Text selected with the mouse is automatically copied to the clipboard, pasting
4152 works with shift-insert.
4156 The other good tip is to make sure you have no //c/-styl
4157 e paths anywhere, use /cygdrive/c/ instead.
4158 Using // invokes a network lookup which is very slow.
4160 \begin_inset Quotes sld
4164 \begin_inset Quotes srd
4167 is too long, you can change it with e.g.
4170 \begin_layout LyX-Code
4174 \begin_layout Standard
4175 SDCC sources use the unix line ending LF.
4176 Life is much easier, if you store the source tree on a drive which is mounted
4178 And use an editor which can handle LF-only line endings.
4179 Make sure not to commit files with windows line endings.
4180 The tabulator spacing
4181 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4185 used in the project is 8.
4186 Although a tabulator spacing of 8 is a sensible choice for programmers
4187 (it's a power of 2 and allows to display 8/16 bit signed variables without
4188 loosing columns) the plan is to move towards using only spaces in the source.
4191 \begin_layout Subsection
4192 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4195 \begin_layout Standard
4198 Download the source package
4200 either from the SDCC Subversion repository or from the
4201 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4207 , it will be named something like sdcc
4211 -yyyymmdd-rrrr.tar.bz2.
4214 SDCC is distributed with all the projects, workspaces, and files you need
4215 to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4216 The workspace name is 'sdcc.dsw'.
4217 Please note that as it is now, all the executables are created in a folder
4221 Once built you need to copy the executables from sdcc
4225 bin before running SDCC.
4230 WARNING: Visual studio is very picky with line terminations; it expects
4231 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4232 When using the Subversion repository it's easiest to configure the svn
4233 client to convert automatically for you.
4234 If however you are getting a message such as "This makefile was not generated
4235 by Developer Studio etc.
4237 \begin_inset Quotes srd
4240 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4241 need to convert the Unix style line endings to DOS style line endings.
4242 To do so you can use the
4243 \begin_inset Quotes sld
4247 \begin_inset Quotes srd
4250 utility freely available on the internet.
4251 Doug Hawkins reported in the sdcc-user list that this works:
4259 SDCC> unix2dos sdcc.dsw
4265 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4269 In order to build SDCC with MSVC
4270 you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4271 One good place to get them is
4272 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4280 Download the file UnxUtils
4281 \begin_inset LatexCommand \index{UnxUtils}
4286 Now you have to install the utilities and setup MSVC so it can locate the
4288 Here there are two alternatives (choose one!):
4291 \begin_layout Enumerate
4296 a) Extract UnxUtils.zip to your C:
4298 hard disk PRESERVING the original paths, otherwise bison won't work.
4299 (If you are using WinZip make certain that 'Use folder names' is selected)
4304 In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4305 'Show directories for:' select 'Executable files', and in the directories
4306 window add a new path: 'C:
4316 (As a side effect, you get a bunch of Unix utilities that
4317 could be useful, such as diff and patch.)
4320 \begin_layout Enumerate
4325 This one avoids extracting a bunch of files you may not
4326 use, but requires some extra work:
4330 a) Create a directory were to put the
4331 tools needed, or use a directory already present.
4338 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4339 gawk.exe to such directory WITHOUT preserving the original paths.
4340 (If you are using WinZip make certain that 'Use folder names' is not selected)
4345 ) Rename bison.exe to '_bison.exe'.
4349 d) Create a batch file 'bison.bat' in 'C:
4353 ' and add these lines:
4373 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4377 Steps 'c' and 'd' are needed
4378 because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4379 reside in some weird Unix directory, '/usr/local/share/' I think.
4380 So it is necessary to tell bison where those files are located if they
4381 are not in such directory.
4382 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4387 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4388 in 'Show directories for:' select 'Executable files', and in the directories
4389 window add a new path: 'c:
4392 Note that you can use any other path instead of 'c:
4394 util', even the path where the Visual C++ tools are, probably: 'C:
4398 Microsoft Visual Studio
4403 So you don't have to execute step 'e' :)
4406 \begin_layout Standard
4408 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4409 the executables from sdcc
4413 bin, and you can compile using SDCC.
4416 \begin_layout Subsection
4417 Building SDCC Using Borland
4420 \begin_layout Enumerate
4421 From the sdcc directory, run the command "make -f Makefile.bcc".
4422 This should regenerate all the .exe files in the bin directory except for
4426 \begin_layout Enumerate
4427 If you modify any source files and need to rebuild, be aware that the dependenci
4428 es may not be correctly calculated.
4429 The safest option is to delete all .obj files and run the build again.
4430 From a Cygwin BASH prompt, this can easily be done with the command (be
4431 sure you are in the sdcc directory):
4441 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
4443 ) -print -exec rm {}
4452 or on Windows NT/2000/XP from the command prompt with the command:
4459 del /s *.obj *.lib *.rul
4462 from the sdcc directory.
4465 \begin_layout Subsection
4466 Windows Install Using a ZIP Package
4469 \begin_layout Enumerate
4470 Download the binary zip package from
4471 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4475 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4476 This should unpack to a group of sub-directories.
4477 An example directory structure after unpacking the mingw32 package is:
4482 bin for the executables, c:
4490 lib for the include and libraries.
4493 \begin_layout Enumerate
4494 Adjust your environment variable PATH to include the location of the bin
4495 directory or start sdcc using the full path.
4498 \begin_layout Subsection
4499 Windows Install Using the Setup Program
4500 \begin_inset LatexCommand \label{sub:Windows-Install}
4507 \begin_layout Standard
4508 Download the setup program
4510 sdcc-x.y.z-setup.exe
4512 for an official release from
4515 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4519 or a setup program for one of the snapshots
4521 sdcc-yyyymmdd-xxxx-setup.exe
4524 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4529 A windows typical installer will guide you through the installation process.
4532 \begin_layout Subsection
4534 \begin_inset LatexCommand \index{VPATH}
4541 \begin_layout Standard
4542 SDCC supports the VPATH feature provided by configure and make.
4543 It allows to separate the source and build trees.
4547 \begin_layout Standard
4574 \begin_layout Standard
4577 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4578 # extract source to directory sdcc
4581 \begin_layout Standard
4584 mkdir sdcc.build\InsetSpace ~
4593 # put output in sdcc.build
4596 \begin_layout Standard
4602 \begin_layout Standard
4605 ../sdcc/configure\InsetSpace ~
4613 # configure is doing all the magic!
4616 \begin_layout Standard
4622 \begin_layout Standard
4628 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4629 It automagically computes the variables srcdir, top_srcdir and top_buildir
4635 the generated files will be in ~/sdcc.build, while the source files stay
4638 This is not only usefull for building different binaries, e.g.
4639 when cross compiling.
4640 It also gives you a much better overview in the source tree when all the
4641 generated files are not scattered between the source files.
4642 And the best thing is: if you want to change a file you can leave the original
4643 file untouched in the source directory.
4644 Simply copy it to the build directory, edit it, enter `make clean', `rm
4645 Makefile.dep' and `make'.
4650 will do the rest for you!
4653 \begin_layout Section
4654 Building the Documentation
4657 \begin_layout Standard
4662 \begin_layout Standard
4671 -enable-doc to the configure arguments to build the documentation together
4672 with all the other stuff.
4673 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4674 dvips and makeindex) to get the job done.
4675 Another possibility is to change to the doc directory and to type
4679 \begin_inset Quotes srd
4683 \begin_inset Quotes srd
4690 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4693 \begin_inset LatexCommand \url{http://www.lyx.org}
4697 as editor is straightforward.
4698 Prebuilt documentation in html and pdf format is available from
4699 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4706 \begin_layout Section
4707 Reading the Documentation
4708 \begin_inset LatexCommand \index{Documentation}
4715 \begin_layout Standard
4716 Currently reading the document in pdf format is recommended, as for unknown
4717 reason the hyperlinks are working there whereas in the html version they
4722 \begin_layout Standard
4723 If you should know why please drop us a note
4731 You'll find the pdf version
4732 \begin_inset LatexCommand \index{PDF version of this document}
4737 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4745 \begin_inset LatexCommand \index{HTML version of this document}
4750 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4756 This documentation is in some aspects different from a commercial documentation:
4760 \begin_layout Itemize
4761 It tries to document SDCC for several processor architectures in one document
4762 (commercially these probably would be separate documents/products).
4764 \begin_inset LatexCommand \index{Status of documentation}
4768 currently matches SDCC for mcs51 and DS390 best and does give too few informati
4770 Z80, PIC14, PIC16 and HC08.
4773 \begin_layout Itemize
4774 There are many references pointing away from this documentation.
4775 Don't let this distract you.
4777 was a reference like
4778 \begin_inset LatexCommand \url{http://www.opencores.org}
4782 together with a statement
4783 \begin_inset Quotes sld
4786 some processors which are targetted by SDCC can be implemented in a
4803 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4808 \begin_inset Quotes srd
4812 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4817 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4822 \begin_inset Quotes sld
4825 have you ever heard of an open source compiler that compiles a subset of
4827 \begin_inset Quotes srd
4830 we expect you to have a quick look there and come back.
4831 If you read this you are on the right track.
4834 \begin_layout Itemize
4835 Some sections attribute more space to problems, restrictions and warnings
4836 than to the solution.
4839 \begin_layout Itemize
4840 The installation section and the section about the debugger is intimidating.
4843 \begin_layout Itemize
4844 There are still lots of typos and there are more different writing styles
4848 \begin_layout Section
4849 Testing the SDCC Compiler
4850 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4857 \begin_layout Standard
4858 The first thing you should do after installing your SDCC compiler is to
4867 \begin_layout Standard
4877 \begin_inset LatexCommand \index{version}
4884 at the prompt, and the program should run and output its version like:
4889 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4893 \begin_layout Standard
4894 If it doesn't run, or gives a message about not finding sdcc program, then
4895 you need to check over your installation.
4896 Make sure that the sdcc bin directory is in your executable search path
4897 defined by the PATH environment setting (
4902 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4909 Install trouble-shooting for suggestions
4912 Make sure that the sdcc program is in the bin folder, if not perhaps something
4913 did not install correctly.
4921 is commonly installed as described in section
4922 \begin_inset Quotes sld
4925 Install and search paths
4926 \begin_inset Quotes srd
4935 Make sure the compiler works on a very simple example.
4936 Type in the following test.c program using your favorite
4961 \begin_layout Standard
4964 Compile this using the following command:
4973 If all goes well, the compiler will generate a test.asm and test.rel file.
4974 Congratulations, you've just compiled your first program with SDCC.
4975 We used the -c option to tell SDCC not to link the generated code, just
4976 to keep things simple for this step.
4984 The next step is to try it with the linker.
4994 If all goes well the compiler will link with the libraries and produce
4995 a test.ihx output file.
5000 (no test.ihx, and the linker generates warnings), then the problem is most
5009 usr/local/share/sdcc/lib directory
5016 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5023 Install trouble-shooting for suggestions).
5031 The final test is to ensure
5039 header files and libraries.
5040 Edit test.c and change it to the following:
5058 strcpy(str1, "testing");
5063 \begin_layout Standard
5066 Compile this by typing
5073 This should generate a test.ihx output file, and it should give no warnings
5074 such as not finding the string.h file.
5075 If it cannot find the string.h file, then the problem is that
5079 cannot find the /usr/local/share/sdcc/include directory
5086 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5093 Install trouble-shooting section for suggestions).
5102 \begin_layout Standard
5114 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5118 to find exactly where SDCC is looking for the include and lib files.
5121 \begin_layout Section
5122 Install Trouble-shooting
5123 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5128 \begin_inset LatexCommand \index{Install trouble-shooting}
5135 \begin_layout Subsection
5136 If SDCC does not build correctly
5139 \begin_layout Standard
5140 A thing to try is starting from scratch by unpacking the .tgz source package
5141 again in an empty directory.
5149 ./configure 2>&1 | tee configure.log
5163 make 2>&1 | tee make.log
5170 If anything goes wrong, you can review the log files to locate the problem.
5171 Or a relevant part of this can be attached to an email that could be helpful
5172 when requesting help from the mailing list.
5175 \begin_layout Subsection
5177 \begin_inset Quotes sld
5181 \begin_inset Quotes srd
5187 \begin_layout Standard
5189 \begin_inset Quotes sld
5193 \begin_inset Quotes srd
5196 command is a script that analyzes your system and performs some configuration
5197 to ensure the source package compiles on your system.
5198 It will take a few minutes to run, and will compile a few tests to determine
5199 what compiler features are installed.
5202 \begin_layout Subsection
5204 \begin_inset Quotes sld
5208 \begin_inset Quotes srd
5214 \begin_layout Standard
5215 This runs the GNU make tool, which automatically compiles all the source
5216 packages into the final installed binary executables.
5219 \begin_layout Subsection
5221 \begin_inset Quotes sld
5225 \begin_inset Quotes erd
5231 \begin_layout Standard
5232 This will install the compiler, other executables libraries and include
5233 files into the appropriate directories.
5235 \begin_inset LatexCommand \ref{sub:Install-paths}
5241 \begin_inset LatexCommand \ref{sub:Search-Paths}
5246 about install and search paths.
5248 On most systems you will need super-user privilege
5252 \begin_layout Section
5256 \begin_layout Standard
5257 SDCC is not just a compiler, but a collection of tools by various developers.
5258 These include linkers, assemblers, simulators and other components.
5259 Here is a summary of some of the components.
5260 Note that the included simulator and assembler have separate documentation
5261 which you can find in the source package in their respective directories.
5262 As SDCC grows to include support for other processors, other packages from
5263 various developers are included and may have their own sets of documentation.
5268 might want to look at the files which are installed in <installdir>.
5269 At the time of this writing, we find the following programs for gcc-builds:
5274 In <installdir>/bin:
5277 \begin_layout Itemize
5278 sdcc - The compiler.
5281 \begin_layout Itemize
5282 sdcpp - The C preprocessor.
5285 \begin_layout Itemize
5286 asx8051 - The assembler for 8051 type processors.
5289 \begin_layout Itemize
5294 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5297 \begin_layout Itemize
5298 aslink -The linker for 8051 type processors.
5301 \begin_layout Itemize
5306 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5309 \begin_layout Itemize
5310 s51 - The ucSim 8051 simulator.
5313 \begin_layout Itemize
5314 sdcdb - The source debugger.
5317 \begin_layout Itemize
5318 packihx - A tool to pack (compress) Intel hex files.
5321 \begin_layout Standard
5322 In <installdir>/share/sdcc/include
5325 \begin_layout Itemize
5329 \begin_layout Standard
5330 In <installdir>/share/sdcc/lib
5333 \begin_layout Itemize
5334 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5338 \begin_layout Standard
5339 In <installdir>/share/sdcc/doc
5342 \begin_layout Itemize
5346 \begin_layout Standard
5347 As development for other processors proceeds, this list will expand to include
5348 executables to support processors like AVR, PIC, etc.
5351 \begin_layout Subsection
5355 \begin_layout Standard
5356 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5357 the assembler and linkage editor.
5360 \begin_layout Subsection
5361 sdcpp - The C-Preprocessor
5364 \begin_layout Standard
5366 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5370 is a modified version of the GNU cpp
5371 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5376 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5381 The C preprocessor is used to pull in #include sources, process #ifdef
5382 statements, #defines and so on.
5385 \begin_layout Subsection
5394 - The Assemblers and Linkage Editors
5397 \begin_layout Standard
5398 This is retargettable assembler & linkage editor, it was developed by Alan
5400 John Hartman created the version for 8051, and I (Sandeep) have made some
5401 enhancements and bug fixes for it to work properly with SDCC.
5404 \begin_layout Subsection
5408 \begin_layout Standard
5410 \begin_inset LatexCommand \index{s51}
5414 is a free open source simulator developed by Daniel Drotos.
5415 The simulator is built as part of the build process.
5416 For more information visit Daniel's web site at:
5417 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5422 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5426 \begin_layout Subsection
5427 sdcdb - Source Level Debugger
5430 \begin_layout Standard
5432 \begin_inset LatexCommand \index{SDCDB (debugger)}
5436 is the companion source level debugger.
5437 More about SDCDB in section
5438 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5443 The current version of the debugger uses Daniel's Simulator S51
5444 \begin_inset LatexCommand \index{s51}
5448 , but can be easily changed to use other simulators.
5451 \begin_layout Chapter
5455 \begin_layout Section
5459 \begin_layout Subsection
5460 Single Source File Projects
5463 \begin_layout Standard
5464 For single source file 8051 projects the process is very simple.
5465 Compile your programs with the following command
5468 "sdcc sourcefile.c".
5472 This will compile, assemble and link your source file.
5473 Output files are as follows:
5476 \begin_layout Itemize
5478 \begin_inset LatexCommand \index{<file>.asm}
5483 \begin_inset LatexCommand \index{Assembler source}
5487 file created by the compiler
5490 \begin_layout Itemize
5492 \begin_inset LatexCommand \index{<file>.lst}
5497 \begin_inset LatexCommand \index{Assembler listing}
5501 file created by the Assembler
5504 \begin_layout Itemize
5506 \begin_inset LatexCommand \index{<file>.rst}
5511 \begin_inset LatexCommand \index{Assembler listing}
5515 file updated with linkedit information, created by linkage editor
5518 \begin_layout Itemize
5520 \begin_inset LatexCommand \index{<file>.sym}
5525 \begin_inset LatexCommand \index{Symbol listing}
5529 for the sourcefile, created by the assembler
5532 \begin_layout Itemize
5534 \begin_inset LatexCommand \index{<file>.rel}
5539 \begin_inset LatexCommand \index{<file>.o}
5544 \begin_inset LatexCommand \index{Object file}
5548 created by the assembler, input to Linkage editor
5551 \begin_layout Itemize
5553 \begin_inset LatexCommand \index{<file>.map}
5558 \begin_inset LatexCommand \index{Memory map}
5562 for the load module, created by the Linker
5565 \begin_layout Itemize
5567 \begin_inset LatexCommand \index{<file>.mem}
5571 - A file with a summary of the memory usage
5574 \begin_layout Itemize
5576 \begin_inset LatexCommand \index{<file>.ihx}
5580 - The load module in Intel hex format
5581 \begin_inset LatexCommand \index{Intel hex format}
5585 (you can select the Motorola S19 format
5586 \begin_inset LatexCommand \index{Motorola S19 format}
5594 \begin_layout Standard
5604 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5609 If you need another format you might want to use
5616 \begin_inset LatexCommand \index{objdump (tool)}
5627 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5632 \begin_inset Note Note
5635 \begin_layout Standard
5642 \begin_inset LatexCommand \vref{sub:Postprocessing-the-Intel}
5647 Both formats are documented in the documentation of srecord
5648 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5655 \begin_layout Itemize
5657 \begin_inset LatexCommand \index{<file>.adb}
5661 - An intermediate file containing debug information needed to create the
5666 \begin_layout Standard
5676 \begin_inset LatexCommand \index{-\/-debug}
5683 \begin_layout Itemize
5685 \begin_inset LatexCommand \index{<file>.cdb}
5689 - An optional file (with -
5693 \begin_layout Standard
5702 -debug) containing debug information.
5703 The format is documented in cdbfileformat.pdf
5706 \begin_layout Itemize
5709 \begin_inset LatexCommand \index{<file> (no extension)}
5713 An optional AOMF or AOMF51
5714 \begin_inset LatexCommand \index{AOMF, AOMF51}
5719 \begin_inset LatexCommand \label{OMF file}
5723 file containing debug information (generated with option -
5727 \begin_layout Standard
5753 ormat is a subformat of the OMF51 format and is commonly used by third party
5755 \begin_inset LatexCommand \index{Debugger}
5759 , simulators, emulators).
5762 \begin_layout Itemize
5764 \begin_inset LatexCommand \index{<file>.dump*}
5768 - Dump file to debug the compiler it self (generated with option -
5772 \begin_layout Standard
5781 -dumpall) (see section
5782 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5788 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5794 \begin_inset Quotes sld
5797 Anatomy of the compiler
5798 \begin_inset Quotes srd
5804 \begin_layout Subsection
5805 Postprocessing the Intel Hex
5806 \begin_inset LatexCommand \index{Intel hex format}
5811 \begin_inset LatexCommand \label{sub:Postprocessing-the-Intel}
5818 \begin_layout Standard
5819 In most cases this won't be needed but the Intel Hex file
5820 \begin_inset LatexCommand \index{<file>.ihx}
5824 which is generated by SDCC might include lines of varying length and the
5825 addresses within the file are not guaranteed to be strictly ascending.
5826 If your toolchain or a bootloader does not like this you can use the tool
5832 \begin_inset LatexCommand \index{packihx (tool)}
5836 which is part of the SDCC distribution:
5843 packihx sourcefile.ihx >sourcefile.hex
5850 The separately available
5855 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5859 package additionally allows to set undefined locations to a predefined
5860 value, to insert checksums
5861 \begin_inset LatexCommand \index{checksum}
5865 of various flavours (crc, add, xor) and to perform other manipulations
5866 (convert, split, crop, offset, ...).
5874 srec_cat\InsetSpace ~
5876 sourcefile.ihx -intel\InsetSpace ~
5878 -o sourcefile.hex -intel
5885 An example for a more complex command line
5889 \begin_layout Standard
5890 the command backfills
5891 \begin_inset LatexCommand \index{backfill unused memory}
5895 unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5897 If the program counter on an mcs51 runs wild the backfill pattern 0x12
5898 will be interpreted as an
5906 (where an emergency routine could sit).
5919 srec_cat\InsetSpace ~
5920 sourcefile.ihx -intel\InsetSpace ~
5922 -fill 0x12 0x0000 0xfffe\InsetSpace ~
5923 -little-endian-checksum-nega
5924 tive 0xfffe 0x02 0x02\InsetSpace ~
5926 -o sourcefile.hex -intel
5935 The srecord package is available at
5936 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5943 \begin_layout Subsection
5944 Projects with Multiple Source Files
5947 \begin_layout Standard
5948 SDCC can compile only ONE file at a time.
5949 Let us for example assume that you have a project containing the following
5954 foo1.c (contains some functions)
5956 foo2.c (contains some more functions)
5959 n.c (contains more functions and the function main)
5967 The first two files will need to be compiled separately with the commands:
5999 Then compile the source file containing the
6004 \begin_inset LatexCommand \index{Linker}
6008 the files together with the following command:
6016 foomain.c\InsetSpace ~
6017 foo1.rel\InsetSpace ~
6022 \begin_inset LatexCommand \index{<file>.rel}
6034 can be separately compiled as well:
6045 sdcc foomain.rel foo1.rel foo2.rel
6052 The file containing the
6067 file specified in the command line, since the linkage editor processes
6068 file in the order they are presented to it.
6069 The linker is invoked from SDCC using a script file with extension .lnk
6070 \begin_inset LatexCommand \index{<file>.lnk}
6075 You can view this file to troubleshoot linking problems such as those arising
6076 from missing libraries.
6079 \begin_layout Subsection
6080 Projects with Additional Libraries
6081 \begin_inset LatexCommand \index{Libraries}
6088 \begin_layout Standard
6089 Some reusable routines may be compiled into a library, see the documentation
6090 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6094 \begin_inset LatexCommand \index{<file>.lib}
6101 Libraries created in this manner can be included in the command line.
6102 Make sure you include the -L <library-path> option to tell the linker where
6103 to look for these files if they are not in the current directory.
6104 Here is an example, assuming you have the source file
6116 (if that is not the same as your current project):
6123 sdcc foomain.c foolib.lib -L mylib
6134 must be an absolute path name.
6138 The most efficient way to use libraries is
6139 to keep separate modules in separate source files.
6140 The lib file now should name all the modules.rel
6141 \begin_inset LatexCommand \index{<file>.rel}
6146 For an example see the standard library file
6150 in the directory <installdir>/share/lib/small.
6153 \begin_layout Subsection
6154 Using sdcclib to Create and Manage Libraries
6155 \begin_inset LatexCommand \index{sdcclib}
6162 \begin_layout Standard
6163 Alternatively, instead of having a .rel file for each entry on the library
6164 file as described in the preceding section, sdcclib can be used to embed
6165 all the modules belonging to such library in the library file itself.
6166 This results in a larger library file, but it greatly reduces the number
6167 of disk files accessed by the linker.
6168 Additionally, the packed library file contains an index of all include
6169 modules and symbols that significantly speeds up the linking process.
6170 To display a list of options supported by sdcclib type:
6175 \begin_layout Standard
6180 \begin_inset LatexCommand \index{sdcclib}
6191 To create a new library file, start by compiling all the required modules.
6197 \begin_layout Standard
6204 \begin_layout Standard
6211 \begin_layout Standard
6218 \begin_layout Standard
6225 \begin_layout Standard
6234 \begin_layout Standard
6235 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6237 The next step is to add the .rel files to the library file:
6242 \begin_layout Standard
6246 sdcclib libint.lib _divsint.rel
6249 \begin_inset LatexCommand \index{sdcclib}
6256 \begin_layout Standard
6260 sdcclib libint.lib _divuint.rel
6263 \begin_layout Standard
6267 sdcclib libint.lib _modsint.rel
6270 \begin_layout Standard
6274 sdcclib libint.lib _moduint.rel
6277 \begin_layout Standard
6281 sdcclib libint.lib _mulint.rel
6288 \begin_layout Standard
6289 If the file already exists in the library, it will be replaced.
6290 To see what modules and symbols are included in the library, options -s
6291 and -m are available.
6299 sdcclib -s libint.lib
6302 \begin_inset LatexCommand \index{sdcclib}
6314 \begin_layout Standard
6320 \begin_layout Standard
6326 \begin_layout Standard
6334 \begin_layout Standard
6340 \begin_layout Standard
6346 \begin_layout Standard
6352 \begin_layout Standard
6358 \begin_layout Standard
6366 \begin_layout Standard
6372 \begin_layout Standard
6378 \begin_layout Standard
6386 \begin_layout Standard
6392 \begin_layout Standard
6398 \begin_layout Standard
6404 \begin_layout Standard
6412 \begin_layout Standard
6418 \begin_layout Standard
6429 \begin_layout Standard
6430 If the source files are compiled using -
6434 \begin_layout Standard
6444 \begin_inset LatexCommand \index{-\/-debug}
6448 , the corresponding debug information file .adb will be include in the library
6450 The library files created with sdcclib are plain text files, so they can
6451 be viewed with a text editor.
6452 It is not recomended to modify a library file created with sdcclib using
6453 a text editor, as there are file indexes numbers located accross the file
6454 used by the linker to quickly locate the required module to link.
6455 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6456 it can be safely deleted, since all the information required for linking
6457 is embedded in the library file itself.
6458 Library files created using sdcclib are used as described in the preceding
6460 \begin_inset VSpace bigskip
6466 \begin_layout Section
6467 Command Line Options
6468 \begin_inset LatexCommand \index{Command Line Options}
6473 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6480 \begin_layout Subsection
6481 Processor Selection Options
6482 \begin_inset LatexCommand \index{Options processor selection}
6487 \begin_inset LatexCommand \index{Processor selection options}
6495 \labelwidthstring 00.00.0000
6499 \begin_inset LatexCommand \index{-mmcs51}
6505 Generate code for the Intel MCS51
6506 \begin_inset LatexCommand \index{MCS51}
6510 family of processors.
6511 This is the default processor target.
6515 \labelwidthstring 00.00.0000
6519 \begin_inset LatexCommand \index{-mds390}
6525 Generate code for the Dallas DS80C390
6526 \begin_inset LatexCommand \index{DS80C390}
6534 \labelwidthstring 00.00.0000
6538 \begin_inset LatexCommand \index{-mds400}
6544 Generate code for the Dallas DS80C400
6545 \begin_inset LatexCommand \index{DS80C400}
6553 \labelwidthstring 00.00.0000
6557 \begin_inset LatexCommand \index{-mhc08}
6563 Generate code for the Freescale/Motorola HC08
6564 \begin_inset LatexCommand \index{HC08}
6568 family of processors.
6572 \labelwidthstring 00.00.0000
6576 \begin_inset LatexCommand \index{-mz80}
6582 Generate code for the Zilog Z80
6583 \begin_inset LatexCommand \index{Z80}
6587 family of processors.
6591 \labelwidthstring 00.00.0000
6595 \begin_inset LatexCommand \index{-mgbz80}
6601 Generate code for the GameBoy Z80
6602 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6606 processor (Not actively maintained).
6610 \labelwidthstring 00.00.0000
6614 \begin_inset LatexCommand \index{-mavr}
6620 Generate code for the Atmel AVR
6621 \begin_inset LatexCommand \index{AVR}
6625 processor (Not maintained, not complete).
6626 AVR users should probably have a look at winavr
6627 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6632 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6636 , which is based on AVR-port of the gcc compiler.
6639 \begin_layout Standard
6640 \begin_inset Note Note
6643 \begin_layout Standard
6644 I think it is fair to direct users there for now.
6645 Open source is also about avoiding unnecessary work .
6646 But I didn't find the 'official' link.
6655 \labelwidthstring 00.00.0000
6659 \begin_inset LatexCommand \index{-mpic14}
6665 Generate code for the Microchip PIC 14
6666 \begin_inset LatexCommand \index{PIC14}
6670 -bit processors (p16f84 and variants.
6671 In development, not complete).
6674 \begin_layout Standard
6675 \begin_inset Note Note
6678 \begin_layout Standard
6679 p16f627 p16f628 p16f84 p16f873 p16f877?
6688 \labelwidthstring 00.00.0000
6692 \begin_inset LatexCommand \index{-mpic16}
6698 Generate code for the Microchip PIC 16
6699 \begin_inset LatexCommand \index{PIC16}
6703 -bit processors (p18f452 and variants.
6704 In development, not complete).
6708 \labelwidthstring 00.00.0000
6713 Generate code for the Toshiba TLCS-900H
6714 \begin_inset LatexCommand \index{TLCS-900H}
6718 processor (Not maintained, not complete).
6722 \labelwidthstring 00.00.0000
6726 \begin_inset LatexCommand \index{-mxa51}
6732 Generate code for the Phillips XA51
6733 \begin_inset LatexCommand \index{XA51}
6737 processor (Not maintained, not complete).
6740 \begin_layout Standard
6741 \begin_inset VSpace bigskip
6747 \begin_layout Subsection
6748 Preprocessor Options
6749 \begin_inset LatexCommand \index{Options preprocessor}
6754 \begin_inset LatexCommand \index{Preprocessor options}
6759 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6767 \labelwidthstring 00.00.0000
6771 \begin_inset LatexCommand \index{-I<path>}
6777 The additional location where the preprocessor will look for <..h> or
6778 \begin_inset Quotes eld
6782 \begin_inset Quotes erd
6789 \labelwidthstring 00.00.0000
6793 \begin_inset LatexCommand \index{-D<macro[=value]>}
6799 Command line definition of macros.
6800 Passed to the preprocessor.
6804 \labelwidthstring 00.00.0000
6808 \begin_inset LatexCommand \index{-M}
6814 Tell the preprocessor to output a rule suitable for make describing the
6815 dependencies of each object file.
6816 For each source file, the preprocessor outputs one make-rule whose target
6817 is the object file name for that source file and whose dependencies are
6818 all the files `#include'd in it.
6819 This rule may be a single line or may be continued with `
6821 '-newline if it is long.
6822 The list of rules is printed on standard output instead of the preprocessed
6825 \begin_inset LatexCommand \index{-E}
6833 \labelwidthstring 00.00.0000
6837 \begin_inset LatexCommand \index{-C}
6843 Tell the preprocessor not to discard comments.
6844 Used with the `-E' option.
6848 \labelwidthstring 00.00.0000
6852 \begin_inset LatexCommand \index{-MM}
6863 Like `-M' but the output mentions only the user header files included with
6865 \begin_inset Quotes eld
6869 System header files included with `#include <file>' are omitted.
6873 \labelwidthstring 00.00.0000
6877 \begin_inset LatexCommand \index{-Aquestion(answer)}
6883 Assert the answer answer for question, in case it is tested with a preprocessor
6884 conditional such as `#if #question(answer)'.
6885 `-A-' disables the standard assertions that normally describe the target
6890 \labelwidthstring 00.00.0000
6894 \begin_inset LatexCommand \index{-Umacro}
6900 Undefine macro macro.
6901 `-U' options are evaluated after all `-D' options, but before any `-include'
6902 and `-imacros' options.
6906 \labelwidthstring 00.00.0000
6910 \begin_inset LatexCommand \index{-dM}
6916 Tell the preprocessor to output only a list of the macro definitions that
6917 are in effect at the end of preprocessing.
6918 Used with the `-E' option.
6922 \labelwidthstring 00.00.0000
6926 \begin_inset LatexCommand \index{-dD}
6932 Tell the preprocessor to pass all macro definitions into the output, in
6933 their proper sequence in the rest of the output.
6937 \labelwidthstring 00.00.0000
6941 \begin_inset LatexCommand \index{-dN}
6952 Like `-dD' except that the macro arguments and contents are omitted.
6953 Only `#define name' is included in the output.
6957 \labelwidthstring 00.00.0000
6960 -pedantic-parse-number
6961 \begin_inset LatexCommand \index{pedantic}
6966 \begin_inset LatexCommand \index{-pedantic-parse-number}
6974 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
6982 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
6983 and the macro LO_B(3) gets expanded.
6984 See also #pragma pedantic_parse_number
6985 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
6990 \begin_inset LatexCommand \ref{sec:Pragmas}
6996 Note: this functionality is not in conformance with C99 standard!
7000 \labelwidthstring 00.00.0000
7004 preprocessorOption[,preprocessorOption]
7007 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
7012 Pass the preprocessorOption to the preprocessor
7017 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7022 SDCC uses an adapted version of the preprocessor
7026 of the GNU Compiler Collection
7027 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
7036 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7040 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7045 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7052 \begin_layout Standard
7053 \begin_inset VSpace bigskip
7059 \begin_layout Subsection
7061 \begin_inset LatexCommand \index{Options linker}
7066 \begin_inset LatexCommand \index{Linker options}
7074 \labelwidthstring 00.00.0000
7084 \begin_layout Standard
7096 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7101 \begin_inset LatexCommand \index{-L -\/-lib-path}
7108 <absolute path to additional libraries> This option is passed to the linkage
7109 editor's additional libraries
7110 \begin_inset LatexCommand \index{Libraries}
7115 The path name must be absolute.
7116 Additional library files may be specified in the command line.
7117 See section Compiling programs for more details.
7121 \labelwidthstring 00.00.0000
7128 \begin_layout Standard
7140 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7145 <Value> The start location of the external ram
7146 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7150 , default value is 0.
7151 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7155 \begin_layout Standard
7164 -xram-loc 0x8000 or -
7168 \begin_layout Standard
7181 \labelwidthstring 00.00.0000
7188 \begin_layout Standard
7200 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7205 <Value> The start location of the code
7206 \begin_inset LatexCommand \index{code}
7210 segment, default value 0.
7211 Note when this option is used the interrupt vector table
7212 \begin_inset LatexCommand \index{interrupt vector table}
7216 is also relocated to the given address.
7217 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7221 \begin_layout Standard
7230 -code-loc 0x8000 or -
7234 \begin_layout Standard
7247 \labelwidthstring 00.00.0000
7254 \begin_layout Standard
7266 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7271 <Value> By default the stack
7272 \begin_inset LatexCommand \index{stack}
7276 is placed after the data segment.
7277 Using this option the stack can be placed anywhere in the internal memory
7279 The value entered can be in Hexadecimal or Decimal format, e.g.
7284 \begin_layout Standard
7293 -stack-loc 0x20 or -
7297 \begin_layout Standard
7307 Since the sp register is incremented before a push or call, the initial
7308 sp will be set to one byte prior the provided value.
7309 The provided value should not overlap any other memory areas such as used
7310 register banks or the data segment and with enough space for the current
7318 \begin_layout Standard
7331 \begin_inset LatexCommand \index{-\/-pack-iram}
7335 option (which is now a default setting) will override this setting, so
7336 you should also specify the
7342 \begin_layout Standard
7355 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7359 option if you need to manually place the stack.
7363 \labelwidthstring 00.00.0000
7370 \begin_layout Standard
7382 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7387 <Value> By default the external stack
7388 \begin_inset LatexCommand \index{xstack}
7392 is placed after the pdata
7393 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7398 Using this option the xstack can be placed anywhere in the external memory
7400 The value entered can be in Hexadecimal or Decimal format, e.g.
7405 \begin_layout Standard
7414 -xstack-loc 0x8000 or -
7418 \begin_layout Standard
7428 The provided value should not overlap any other memory areas such as the
7429 pdata or xdata segment and with enough space for the current application.
7433 \labelwidthstring 00.00.0000
7440 \begin_layout Standard
7452 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7457 <Value> The start location of the internal ram data
7458 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7463 The value entered can be in Hexadecimal or Decimal format, eg.
7468 \begin_layout Standard
7481 \begin_layout Standard
7491 (By default, the start location of the internal ram data segment is set
7492 as low as possible in memory, taking into account the used register banks
7493 and the bit segment at address 0x20.
7494 For example if register banks 0 and 1 are used without bit variables, the
7495 data segment will be set, if -
7499 \begin_layout Standard
7508 -data-loc is not used, to location 0x10.)
7512 \labelwidthstring 00.00.0000
7519 \begin_layout Standard
7531 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7536 <Value> The start location of the indirectly addressable internal ram
7537 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7541 of the 8051, default value is 0x80.
7542 The value entered can be in Hexadecimal or Decimal format, eg.
7547 \begin_layout Standard
7556 -idata-loc 0x88 or -
7560 \begin_layout Standard
7573 \labelwidthstring 00.00.0000
7580 \begin_layout Standard
7592 <Value> The start location of the bit
7593 \begin_inset LatexCommand \index{bit}
7597 addressable internal ram of the 8051.
7603 Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7608 \labelwidthstring 00.00.0000
7615 \begin_layout Standard
7625 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7634 The linker output (final object code) is in Intel Hex format.
7635 \begin_inset LatexCommand \index{Intel hex format}
7639 This is the default option.
7640 The format itself is documented in the documentation of srecord
7641 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7649 \labelwidthstring 00.00.0000
7656 \begin_layout Standard
7666 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7675 The linker output (final object code) is in Motorola S19 format
7676 \begin_inset LatexCommand \index{Motorola S19 format}
7681 The format itself is documented in the documentation of srecord.
7685 \labelwidthstring 00.00.0000
7692 \begin_layout Standard
7702 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7707 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7716 The linker output (final object code) is in ELF format
7717 \begin_inset LatexCommand \index{ELF format}
7722 (Currently only supported for the HC08
7723 \begin_inset LatexCommand \index{HC08}
7731 \labelwidthstring 00.00.0000
7735 linkOption[,linkOption]
7738 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7743 Pass the linkOption to the linker.
7744 If a bootloader is used an option like
7745 \begin_inset Quotes sld
7750 \begin_inset Quotes srd
7753 would be typical to set the start of the code segment.
7754 See also #pragma constseg and #pragma codeseg in section
7755 \begin_inset LatexCommand \ref{sec:Pragmas}
7760 File sdcc/as/doc/asxhtm.html has more on linker options.
7763 \begin_layout Standard
7764 \begin_inset VSpace bigskip
7770 \begin_layout Subsection
7772 \begin_inset LatexCommand \index{Options MCS51}
7777 \begin_inset LatexCommand \index{MCS51 options}
7785 \labelwidthstring 00.00.0000
7792 \begin_layout Standard
7802 \begin_inset LatexCommand \index{-\/-model-small}
7813 Generate code for Small Model programs, see section Memory Models for more
7815 This is the default model.
7819 \labelwidthstring 00.00.0000
7826 \begin_layout Standard
7836 \begin_inset LatexCommand \index{-\/-model-medium}
7842 Generate code for Medium model programs, see section Memory Models for
7844 If this option is used all source files in the project have to be compiled
7846 It must also be used when invoking the linker.
7850 \labelwidthstring 00.00.0000
7857 \begin_layout Standard
7867 \begin_inset LatexCommand \index{-\/-model-large}
7873 Generate code for Large model programs, see section Memory Models for more
7875 If this option is used all source files in the project have to be compiled
7877 It must also be used when invoking the linker.
7881 \labelwidthstring 00.00.0000
7888 \begin_layout Standard
7898 \begin_inset LatexCommand \index{-\/-xstack}
7904 Uses a pseudo stack in the pdata
7905 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7909 area (usually the first 256 bytes in the external ram) for allocating variables
7910 and passing parameters.
7912 \begin_inset LatexCommand \ref{sub:External-Stack}
7917 External Stack for more details.
7921 \labelwidthstring 00.00.0000
7928 \begin_layout Standard
7941 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
7945 Causes the linker to check if the internal ram usage is within limits of
7950 \labelwidthstring 00.00.0000
7957 \begin_layout Standard
7970 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
7974 Causes the linker to check if the external ram usage is within limits of
7979 \labelwidthstring 00.00.0000
7986 \begin_layout Standard
7999 \begin_inset LatexCommand \index{-\/-code-size <Value>}
8003 Causes the linker to check if the code memory usage is within limits of
8008 \labelwidthstring 00.00.0000
8015 \begin_layout Standard
8028 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8032 Causes the linker to check if there is at minimum <Value> bytes for stack.
8036 \labelwidthstring 00.00.0000
8043 \begin_layout Standard
8056 \begin_inset LatexCommand \index{-\/-pack-iram}
8060 Causes the linker to use unused register banks for data variables and pack
8061 data, idata and stack together.
8062 This is the default now.
8066 \labelwidthstring 00.00.0000
8073 \begin_layout Standard
8086 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8090 Causes the linker to use old style for allocating memory areas.
8093 \begin_layout Standard
8094 \begin_inset VSpace bigskip
8100 \begin_layout Subsection
8101 DS390 / DS400 Options
8102 \begin_inset LatexCommand \index{Options DS390}
8107 \begin_inset LatexCommand \index{DS390}
8115 \labelwidthstring 00.00.0000
8122 \begin_layout Standard
8134 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8144 Generate 24-bit flat mode code.
8145 This is the one and only that the ds390 code generator supports right now
8146 and is default when using
8151 See section Memory Models for more details.
8155 \labelwidthstring 00.00.0000
8162 \begin_layout Standard
8172 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8178 disable interrupts during ESP:SP updates.
8182 \labelwidthstring 00.00.0000
8189 \begin_layout Standard
8201 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8205 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8206 This is the one and only that the ds390 code generator supports right now
8207 and is default when using
8212 In this mode, the stack is located in the lower 1K of the internal RAM,
8213 which is mapped to 0x400000.
8214 Note that the support is incomplete, since it still uses a single byte
8215 as the stack pointer.
8216 This means that only the lower 256 bytes of the potential 1K stack space
8217 will actually be used.
8218 However, this does allow you to reclaim the precious 256 bytes of low RAM
8219 for use for the DATA and IDATA segments.
8220 The compiler will not generate any code to put the processor into 10 bit
8222 It is important to ensure that the processor is in this mode before calling
8223 any re-entrant functions compiled with this option.
8224 In principle, this should work with the
8230 \begin_layout Standard
8240 \begin_inset LatexCommand \index{-\/-stack-auto}
8246 option, but that has not been tested.
8247 It is incompatible with the
8253 \begin_layout Standard
8263 \begin_inset LatexCommand \index{-\/-xstack}
8270 It also only makes sense if the processor is in 24 bit contiguous addressing
8277 \begin_layout Standard
8286 -model-flat24 option
8291 \begin_inset Note Note
8295 \labelwidthstring 00.00.0000
8302 \begin_layout Standard
8311 -stack-8-bit - switches off the 10-bit mode
8320 \labelwidthstring 00.00.0000
8327 \begin_layout Standard
8337 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8343 insert call to function __stack_probe at each function prologue.
8347 \labelwidthstring 00.00.0000
8354 \begin_layout Standard
8364 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8370 <nnnn> LibraryID used in -mTININative.
8375 \labelwidthstring 00.00.0000
8382 \begin_layout Standard
8392 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8398 generate code for DS390 Arithmetic Accelerator.
8402 \begin_layout Standard
8403 \begin_inset VSpace bigskip
8409 \begin_layout Subsection
8411 \begin_inset LatexCommand \index{Options Z80}
8416 \begin_inset LatexCommand \index{Z80}
8424 \labelwidthstring 00.00.0000
8431 \begin_layout Standard
8443 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8453 Force a called function to always save BC.
8457 \labelwidthstring 00.00.0000
8464 \begin_layout Standard
8476 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8480 When linking, skip the standard crt0.o object file.
8481 You must provide your own crt0.o for your system when linking.
8485 \labelwidthstring 00.00.0000
8492 \begin_layout Standard
8504 \begin_inset LatexCommand \index{Z80!Options!-\/-portmode=<Value>}
8508 Determinate PORT I/O mode (<Value> is z80 or z180).
8512 \labelwidthstring 00.00.0000
8519 \begin_layout Standard
8531 \begin_inset LatexCommand \index{Z80!Options!-\/-asm=<Value>}
8535 Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
8539 \labelwidthstring 00.00.0000
8546 \begin_layout Standard
8559 \begin_inset LatexCommand \index{Z80!Options!-\/-codeseg <Value>}
8563 Use <Value> for the code segment name.
8567 \labelwidthstring 00.00.0000
8574 \begin_layout Standard
8587 \begin_inset LatexCommand \index{Z80!Options!-\/-constseg <Value>}
8591 Use <Value> for the const segment name.
8595 \labelwidthstring 00.00.0000
8596 \begin_inset VSpace bigskip
8602 \begin_layout Subsection
8604 \begin_inset LatexCommand \index{Options GBZ80}
8609 \begin_inset LatexCommand \index{GBZ80}
8617 \labelwidthstring 00.00.0000
8624 \begin_layout Standard
8636 \begin_inset LatexCommand \index{GBZ80!Options!-\/-callee-saves-bc}
8646 Force a called function to always save BC.
8650 \labelwidthstring 00.00.0000
8657 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
8661 Use code bank <Num>.
8665 \labelwidthstring 00.00.0000
8672 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
8676 Use data bank <Num>.
8680 \labelwidthstring 00.00.0000
8687 \begin_layout Standard
8700 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
8704 Use <Value> for the code segment name.
8708 \labelwidthstring 00.00.0000
8715 \begin_layout Standard
8728 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
8732 Use <Value> for the const segment name.
8735 \begin_layout Standard
8736 \begin_inset VSpace bigskip
8742 \begin_layout Subsection
8743 Optimization Options
8744 \begin_inset LatexCommand \index{Options optimization}
8749 \begin_inset LatexCommand \index{Optimization options}
8757 \labelwidthstring 00.00.0000
8764 \begin_layout Standard
8774 \begin_inset LatexCommand \index{-\/-nogcse}
8780 Will not do global subexpression elimination, this option may be used when
8781 the compiler creates undesirably large stack/data spaces to store compiler
8791 \begin_inset LatexCommand \index{sloc (spill location)}
8796 A warning message will be generated when this happens and the compiler
8797 will indicate the number of extra bytes it allocated.
8798 It is recommended that this option NOT be used, #pragma\InsetSpace ~
8800 \begin_inset LatexCommand \index{\#pragma nogcse}
8804 can be used to turn off global subexpression elimination
8805 \begin_inset LatexCommand \index{Subexpression elimination}
8809 for a given function only.
8813 \labelwidthstring 00.00.0000
8820 \begin_layout Standard
8830 \begin_inset LatexCommand \index{-\/-noinvariant}
8836 Will not do loop invariant optimizations, this may be turned off for reasons
8837 explained for the previous option.
8838 For more details of loop optimizations performed see Loop Invariants in
8840 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
8845 It is recommended that this option NOT be used, #pragma\InsetSpace ~
8847 \begin_inset LatexCommand \index{\#pragma noinvariant}
8851 can be used to turn off invariant optimizations for a given function only.
8855 \labelwidthstring 00.00.0000
8862 \begin_layout Standard
8872 \begin_inset LatexCommand \index{-\/-noinduction}
8878 Will not do loop induction optimizations, see section strength reduction
8880 It is recommended that this option is NOT used, #pragma\InsetSpace ~
8882 \begin_inset LatexCommand \index{\#pragma noinduction}
8886 can be used to turn off induction optimizations for a given function only.
8890 \labelwidthstring 00.00.0000
8897 \begin_layout Standard
8907 \begin_inset LatexCommand \index{-\/-nojtbound}
8918 Will not generate boundary condition check when switch statements
8919 \begin_inset LatexCommand \index{switch statement}
8923 are implemented using jump-tables.
8925 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
8930 Switch Statements for more details.
8931 It is recommended that this option is NOT used, #pragma\InsetSpace ~
8933 \begin_inset LatexCommand \index{\#pragma nojtbound}
8937 can be used to turn off boundary checking for jump tables for a given function
8942 \labelwidthstring 00.00.0000
8949 \begin_layout Standard
8959 \begin_inset LatexCommand \index{-\/-noloopreverse}
8968 Will not do loop reversal
8969 \begin_inset LatexCommand \index{Loop reversing}
8977 \labelwidthstring 00.00.0000
8982 \begin_layout Standard
8996 \begin_inset LatexCommand \index{-\/-nolabelopt }
9000 Will not optimize labels (makes the dumpfiles more readable).
9004 \labelwidthstring 00.00.0000
9011 \begin_layout Standard
9021 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9027 Will not memcpy initialized data from code space into xdata space.
9028 This saves a few bytes in code space if you don't have initialized data
9029 \begin_inset LatexCommand \index{Variable initialization}
9037 \labelwidthstring 00.00.0000
9044 \begin_layout Standard
9054 \begin_inset LatexCommand \index{-\/-nooverlay}
9060 The compiler will not overlay parameters and local variables of any function,
9061 see section Parameters and local variables for more details.
9065 \labelwidthstring 00.00.0000
9072 \begin_layout Standard
9082 \begin_inset LatexCommand \index{-\/-no-peep}
9088 Disable peep-hole optimization with built-in rules.
9092 \labelwidthstring 00.00.0000
9099 \begin_layout Standard
9111 \begin_inset LatexCommand \index{-\/-peep-file}
9116 <filename> This option can be used to use additional rules to be used by
9117 the peep hole optimizer.
9119 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9124 Peep Hole optimizations for details on how to write these rules.
9128 \labelwidthstring 00.00.0000
9135 \begin_layout Standard
9145 \begin_inset LatexCommand \index{-\/-peep-asm}
9151 Pass the inline assembler code through the peep hole optimizer.
9152 This can cause unexpected changes to inline assembler code, please go through
9153 the peephole optimizer
9154 \begin_inset LatexCommand \index{Peephole optimizer}
9158 rules defined in the source file tree '<target>/peeph.def' before using
9163 \labelwidthstring 00.00.0000
9170 \begin_layout Standard
9180 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9186 The compiler will optimize code generation towards fast code, possibly
9187 at the expense of code size.
9191 \labelwidthstring 00.00.0000
9198 \begin_layout Standard
9208 \begin_inset LatexCommand \index{-\/-opt-code-size}
9214 The compiler will optimize code generation towards compact code, possibly
9215 at the expense of code speed.
9218 \begin_layout Standard
9219 \begin_inset VSpace bigskip
9225 \begin_layout Subsection
9227 \begin_inset LatexCommand \index{Options other}
9235 \labelwidthstring 00.00.0000
9243 \begin_layout Standard
9253 \begin_inset LatexCommand \index{-\/-compile-only}
9258 \begin_inset LatexCommand \index{-c -\/-compile-only}
9264 will compile and assemble the source, but will not call the linkage editor.
9268 \labelwidthstring 00.00.0000
9277 \begin_layout Standard
9289 \begin_inset LatexCommand \index{-\/-c1mode}
9295 reads the preprocessed source from standard input and compiles it.
9296 The file name for the assembler output must be specified using the -o option.
9300 \labelwidthstring 00.00.0000
9304 \begin_inset LatexCommand \index{-E}
9310 Run only the C preprocessor.
9311 Preprocess all the C source files specified and output the results to standard
9316 \labelwidthstring 00.00.0000
9321 \begin_inset LatexCommand \index{-o <path/file>}
9327 The output path where everything will be placed or the file name used for
9328 all generated output files.
9329 If the parameter is a path, it must have a trailing slash (or backslash
9330 for the Windows binaries) to be recognized as a path.
9335 Note for Windows users: if the path contains spaces, it should be surrounded
9337 The trailing backslash should be doubled in order to prevent escaping the
9338 final quote, for example:
9341 \begin_inset Quotes sld
9355 \begin_inset Quotes srd
9360 or put after the final quote, for example:
9363 \begin_inset Quotes sld
9373 \begin_inset Quotes srd
9381 The path using slashes for directory delimiters can be used too, for example:
9385 \begin_inset Quotes sld
9388 F:/Projects/test3/output 1/
9389 \begin_inset Quotes srd
9398 \labelwidthstring 00.00.0000
9405 \begin_layout Standard
9415 \begin_inset LatexCommand \index{-\/-stack-auto}
9426 All functions in the source file will be compiled as
9431 \begin_inset LatexCommand \index{reentrant}
9436 the parameters and local variables will be allocated on the stack
9437 \begin_inset LatexCommand \index{stack}
9443 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9447 Parameters and Local Variables for more details.
9448 If this option is used all source files in the project should be compiled
9450 It automatically implies -
9456 \begin_layout Standard
9467 -int-long-reent and -
9473 \begin_layout Standard
9489 \labelwidthstring 00.00.0000
9496 \begin_layout Standard
9506 \begin_inset LatexCommand \index{-\/-callee-saves}
9511 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9515 function1[,function2][,function3]....
9518 The compiler by default uses a caller saves convention for register saving
9519 across function calls, however this can cause unnecessary register pushing
9520 and popping when calling small functions from larger functions.
9521 This option can be used to switch the register saving convention for the
9522 function names specified.
9523 The compiler will not save registers when calling these functions, no extra
9524 code will be generated at the entry and exit (function prologue
9527 \begin_inset LatexCommand \index{function prologue}
9536 \begin_inset LatexCommand \index{function epilogue}
9542 ) for these functions to save and restore the registers used by these functions,
9543 this can SUBSTANTIALLY reduce code and improve run time performance of
9545 In the future the compiler (with inter procedural analysis) will be able
9546 to determine the appropriate scheme to use for each function call.
9547 DO NOT use this option for built-in functions such as _mulint..., if this
9548 option is used for a library function the appropriate library function
9549 needs to be recompiled with the same option.
9550 If the project consists of multiple source files then all the source file
9551 should be compiled with the same -
9555 \begin_layout Standard
9564 -callee-saves option string.
9565 Also see #pragma\InsetSpace ~
9567 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9572 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9580 \labelwidthstring 00.00.0000
9587 \begin_layout Standard
9597 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9611 \begin_layout Standard
9620 -callee-saves will be applied to all functions by default.
9624 \labelwidthstring 00.00.0000
9631 \begin_layout Standard
9641 \begin_inset LatexCommand \index{-\/-debug}
9650 When this option is used the compiler will generate debug information.
9651 The debug information collected in a file with .cdb extension can be used
9653 For more information see documentation for SDCDB.
9654 Another file with no extension contains debug information in AOMF or AOMF51
9655 \begin_inset LatexCommand \index{AOMF, AOMF51}
9659 format which is commonly used by third party tools.
9663 \labelwidthstring 00.00.0000
9667 \begin_inset LatexCommand \index{-S}
9678 Stop after the stage of compilation proper; do not assemble.
9679 The output is an assembler code file for the input file specified.
9683 \labelwidthstring 00.00.0000
9690 \begin_layout Standard
9700 \begin_inset LatexCommand \index{-\/-int-long-reent}
9706 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
9707 Note by default these libraries are compiled as non-reentrant.
9708 See section Installation for more details.
9712 \labelwidthstring 00.00.0000
9719 \begin_layout Standard
9729 \begin_inset LatexCommand \index{-\/-cyclomatic}
9738 This option will cause the compiler to generate an information message for
9739 each function in the source file.
9740 The message contains some
9744 information about the function.
9745 The number of edges and nodes the compiler detected in the control flow
9746 graph of the function, and most importantly the
9748 cyclomatic complexity
9749 \begin_inset LatexCommand \index{Cyclomatic complexity}
9755 see section on Cyclomatic Complexity for more details.
9759 \labelwidthstring 00.00.0000
9766 \begin_layout Standard
9776 \begin_inset LatexCommand \index{-\/-float-reent}
9782 Floating point library is compiled as reentrant
9783 \begin_inset LatexCommand \index{reentrant}
9788 See section Installation for more details.
9792 \labelwidthstring 00.00.0000
9799 \begin_layout Standard
9809 \begin_inset LatexCommand \index{-\/-funsigned-char}
9815 The default signedness for every type is
9820 In some embedded environments the default signedness of
9829 To set the signess for characters to unsigned, use the option -
9835 \begin_layout Standard
9847 If this option is set and no signedness keyword (unsigned/signed) is given,
9848 a char will be signed.
9849 All other types are unaffected.
9853 \labelwidthstring 00.00.0000
9860 \begin_layout Standard
9870 \begin_inset LatexCommand \index{-\/-main-return}
9876 This option can be used if the code generated is called by a monitor program
9877 or if the main routine includes an endless loop.
9878 This option results in slightly smaller code and saves two bytes of stack
9880 The return from the 'main'
9881 \begin_inset LatexCommand \index{main return}
9885 function will return to the function calling main.
9886 The default setting is to lock up i.e.
9895 \labelwidthstring 00.00.0000
9902 \begin_layout Standard
9912 \begin_inset LatexCommand \index{-\/-nostdinc}
9918 This will prevent the compiler from passing on the default include path
9919 to the preprocessor.
9923 \labelwidthstring 00.00.0000
9930 \begin_layout Standard
9940 \begin_inset LatexCommand \index{-\/-nostdlib}
9946 This will prevent the compiler from passing on the default library
9947 \begin_inset LatexCommand \index{Libraries}
9955 \labelwidthstring 00.00.0000
9962 \begin_layout Standard
9972 \begin_inset LatexCommand \index{-\/-verbose}
9978 Shows the various actions the compiler is performing.
9982 \labelwidthstring 00.00.0000
9986 \begin_inset LatexCommand \index{-V}
9992 Shows the actual commands the compiler is executing.
9996 \labelwidthstring 00.00.0000
10003 \begin_layout Standard
10013 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
10019 Hides your ugly and inefficient c-code from the asm file, so you can always
10020 blame the compiler :)
10024 \labelwidthstring 00.00.0000
10031 \begin_layout Standard
10041 \begin_inset LatexCommand \index{-\/-no-gen-comments}
10047 Include code generator and peep-hole comments in the generated asm files.
10051 \labelwidthstring 00.00.0000
10058 \begin_layout Standard
10068 \begin_inset LatexCommand \index{-\/-no-peep-comments}
10074 Don't include peep-hole comments in the generated asm files even if -
10080 \begin_layout Standard
10091 -fverbose-asm option is specified.
10095 \labelwidthstring 00.00.0000
10102 \begin_layout Standard
10112 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10118 Include i-codes in the asm file.
10119 Sounds like noise but is most helpful for debugging the compiler itself.
10123 \labelwidthstring 00.00.0000
10130 \begin_layout Standard
10140 \begin_inset LatexCommand \index{pedantic}
10145 \begin_inset LatexCommand \index{-\/-less-pedantic}
10152 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10156 Disable some of the more pedantic warnings
10157 \begin_inset LatexCommand \index{Warnings}
10162 For more details, see the less_pedantic pragma
10163 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10171 \labelwidthstring 00.00.0000
10178 \begin_layout Standard
10187 -disable-warning\InsetSpace ~
10189 \begin_inset LatexCommand \index{-\/-disable-warning}
10195 Disable specific warning with number <nnnn>.
10199 \labelwidthstring 00.00.0000
10206 \begin_layout Standard
10216 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10222 Display the directories in the compiler's search path
10226 \labelwidthstring 00.00.0000
10233 \begin_layout Standard
10243 \begin_inset LatexCommand \index{-\/-vc}
10249 Display errors and warnings using MSVC style, so you can use SDCC with
10250 the visual studio IDE
10251 \begin_inset LatexCommand \index{IDE}
10256 With SDCC both offering a GCC-like (the default) and a MSVC-like
10257 \begin_inset LatexCommand \index{MSVC output style}
10261 output style, integration into most programming editors should be straightforwa
10266 \labelwidthstring 00.00.0000
10273 \begin_layout Standard
10283 \begin_inset LatexCommand \index{-\/-use-stdout}
10289 Send errors and warnings to stdout instead of stderr.
10293 \labelwidthstring 00.00.0000
10297 asmOption[,asmOption]
10300 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10305 Pass the asmOption to the assembler
10306 \begin_inset LatexCommand \index{Options assembler}
10311 \begin_inset LatexCommand \index{Assembler options}
10316 See file sdcc/as/doc/asxhtm.html for assembler options.cd
10320 \labelwidthstring 00.00.0000
10327 \begin_layout Standard
10337 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10343 Generally follow the C89 standard, but allow SDCC features that conflict
10344 with the standard (default).
10348 \labelwidthstring 00.00.0000
10355 \begin_layout Standard
10365 \begin_inset LatexCommand \index{-\/-std-c89}
10371 Follow the C89 standard and disable SDCC features that conflict with the
10376 \labelwidthstring 00.00.0000
10383 \begin_layout Standard
10393 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10399 Generally follow the C99 standard, but allow SDCC features that conflict
10400 with the standard (incomplete support).
10404 \labelwidthstring 00.00.0000
10411 \begin_layout Standard
10421 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10427 Follow the C99 standard and disable SDCC features that conflict with the
10428 standard (incomplete support).
10432 \labelwidthstring 00.00.0000
10439 \begin_layout Standard
10451 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10456 <Name> The name to be used for the code
10457 \begin_inset LatexCommand \index{code}
10461 segment, default CSEG.
10462 This is useful if you need to tell the compiler to put the code in a special
10463 segment so you can later on tell the linker to put this segment in a special
10465 Can be used for instance when using bank switching to put the code in a
10470 \labelwidthstring 00.00.0000
10477 \begin_layout Standard
10489 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10494 <Name> The name to be used for the const
10495 \begin_inset LatexCommand \index{const}
10499 segment, default CONST.
10500 This is useful if you need to tell the compiler to put the const data in
10501 a special segment so you can later on tell the linker to put this segment
10502 in a special place in memory.
10503 Can be used for instance when using bank switching to put the const data
10508 \labelwidthstring 00.00.0000
10515 \begin_layout Standard
10524 -fdollars-in-identifiers
10525 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10531 Permit '$' as an identifier character.
10535 \labelwidthstring 00.00.0000
10542 \begin_layout Standard
10554 \begin_inset LatexCommand \index{-\/-more-pedantic}
10559 \begin_inset LatexCommand \index{pedantic}
10569 a SDCC compiler option but if you want
10573 warnings you can use a separate tool dedicated to syntax checking like
10575 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10580 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10585 \begin_inset LatexCommand \url{http://www.splint.org}
10590 To make your source files parseable by splint you will have to include
10596 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10600 in your source file and add brackets around extended keywords (like
10603 \begin_inset Quotes sld
10616 \begin_inset Quotes srd
10624 \begin_inset Quotes sld
10627 __interrupt\InsetSpace ~
10629 \begin_inset Quotes srd
10637 Splint has an excellent on line manual at
10638 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10642 and it's capabilities go beyond pure syntax checking.
10643 You'll need to tell splint the location of SDCC's include files so a typical
10644 command line could look like this:
10648 splint\InsetSpace ~
10650 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10656 \labelwidthstring 00.00.0000
10663 \begin_layout Standard
10675 \begin_inset LatexCommand \index{-\/-short-is-8bits}
10680 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
10684 Treat short as 8-bit (for backward compatibility with older versions of
10685 compiler - see section
10686 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
10693 \begin_layout Standard
10694 \begin_inset VSpace bigskip
10700 \begin_layout Subsection
10701 Intermediate Dump Options
10702 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
10707 \begin_inset LatexCommand \index{Options intermediate dump}
10712 \begin_inset LatexCommand \index{Intermediate dump options}
10719 \begin_layout Standard
10720 The following options are provided for the purpose of retargetting and debugging
10722 They provide a means to dump the intermediate code (iCode
10723 \begin_inset LatexCommand \index{iCode}
10727 ) generated by the compiler in human readable form at various stages of
10728 the compilation process.
10729 More on iCodes see chapter
10730 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10735 \begin_inset Quotes srd
10738 The anatomy of the compiler
10739 \begin_inset Quotes srd
10746 \labelwidthstring 00.00.0000
10753 \begin_layout Standard
10763 \begin_inset LatexCommand \index{-\/-dumpraw}
10769 This option will cause the compiler to dump the intermediate code into
10772 <source filename>.dumpraw
10774 just after the intermediate code has been generated for a function, i.e.
10775 before any optimizations are done.
10777 \begin_inset LatexCommand \index{Basic blocks}
10781 at this stage ordered in the depth first number, so they may not be in
10782 sequence of execution.
10786 \labelwidthstring 00.00.0000
10793 \begin_layout Standard
10803 \begin_inset LatexCommand \index{-\/-dumpgcse}
10809 Will create a dump of iCodes, after global subexpression elimination
10810 \begin_inset LatexCommand \index{Global subexpression elimination}
10814 , into a file named
10816 <source filename>.dumpgcse.
10820 \labelwidthstring 00.00.0000
10827 \begin_layout Standard
10837 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
10843 Will create a dump of iCodes, after deadcode elimination
10844 \begin_inset LatexCommand \index{Dead-code elimination}
10848 , into a file named
10850 <source filename>.dumpdeadcode.
10854 \labelwidthstring 00.00.0000
10861 \begin_layout Standard
10871 \begin_inset LatexCommand \index{-\/-dumploop}
10880 Will create a dump of iCodes, after loop optimizations
10881 \begin_inset LatexCommand \index{Loop optimization}
10885 , into a file named
10887 <source filename>.dumploop.
10891 \labelwidthstring 00.00.0000
10898 \begin_layout Standard
10908 \begin_inset LatexCommand \index{-\/-dumprange}
10917 Will create a dump of iCodes, after live range analysis
10918 \begin_inset LatexCommand \index{Live range analysis}
10922 , into a file named
10924 <source filename>.dumprange.
10928 \labelwidthstring 00.00.0000
10935 \begin_layout Standard
10945 \begin_inset LatexCommand \index{-\/-dumlrange}
10951 Will dump the life ranges
10952 \begin_inset LatexCommand \index{Live range analysis}
10960 \labelwidthstring 00.00.0000
10967 \begin_layout Standard
10977 \begin_inset LatexCommand \index{-\/-dumpregassign}
10986 Will create a dump of iCodes, after register assignment
10987 \begin_inset LatexCommand \index{Register assignment}
10991 , into a file named
10993 <source filename>.dumprassgn.
10997 \labelwidthstring 00.00.0000
11004 \begin_layout Standard
11014 \begin_inset LatexCommand \index{-\/-dumplrange}
11020 Will create a dump of the live ranges of iTemp's
11024 \labelwidthstring 00.00.0000
11031 \begin_layout Standard
11041 \begin_inset LatexCommand \index{-\/-dumpall}
11052 Will cause all the above mentioned dumps to be created.
11055 \begin_layout Standard
11056 \begin_inset VSpace bigskip
11062 \begin_layout Subsection
11063 Redirecting output on Windows Shells
11066 \begin_layout Standard
11067 By default SDCC writes its error messages to
11068 \begin_inset Quotes sld
11072 \begin_inset Quotes srd
11076 To force all messages to
11077 \begin_inset Quotes sld
11081 \begin_inset Quotes srd
11093 \begin_layout Standard
11108 \begin_inset LatexCommand \index{-\/-use-stdout}
11113 Additionally, if you happen to have visual studio installed in your windows
11114 machine, you can use it to compile your sources using a custom build and
11121 \begin_layout Standard
11133 \begin_inset LatexCommand \index{-\/-vc}
11138 Something like this should work:
11157 \begin_layout Standard
11176 \begin_layout Standard
11188 -model-large -c $(InputPath)
11191 \begin_inset VSpace bigskip
11197 \begin_layout Section
11198 Environment variables
11199 \begin_inset LatexCommand \index{Environment variables}
11206 \begin_layout Standard
11207 SDCC recognizes the following environment variables:
11211 \labelwidthstring 00.00.0000
11215 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11221 SDCC installs a signal handler
11222 \begin_inset LatexCommand \index{signal handler}
11226 to be able to delete temporary files after an user break (^C) or an exception.
11227 If this environment variable is set, SDCC won't install the signal handler
11228 in order to be able to debug SDCC.
11232 \labelwidthstring 00.00.0000
11238 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11244 Path, where temporary files will be created.
11245 The order of the variables is the search order.
11246 In a standard *nix environment these variables are not set, and there's
11247 no need to set them.
11248 On Windows it's recommended to set one of them.
11252 \labelwidthstring 00.00.0000
11256 \begin_inset LatexCommand \index{SDCC\_HOME}
11263 \begin_inset LatexCommand \ref{sub:Install-paths}
11269 \begin_inset Quotes sld
11273 \begin_inset Quotes srd
11280 \labelwidthstring 00.00.0000
11284 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11291 \begin_inset LatexCommand \ref{sub:Search-Paths}
11297 \begin_inset Quotes sld
11301 \begin_inset Quotes srd
11308 \labelwidthstring 00.00.0000
11312 \begin_inset LatexCommand \index{SDCC\_LIB}
11319 \begin_inset LatexCommand \ref{sub:Search-Paths}
11325 \begin_inset Quotes sld
11329 \begin_inset Quotes srd
11335 \begin_layout Standard
11336 There are some more environment variables recognized by SDCC, but these
11337 are solely used for debugging purposes.
11338 They can change or disappear very quickly, and will never be documented.
11339 \begin_inset VSpace bigskip
11345 \begin_layout Section
11346 Storage Class Language Extensions
11349 \begin_layout Subsection
11350 MCS51/DS390 Storage Class
11351 \begin_inset LatexCommand \index{Storage class}
11355 Language Extensions
11358 \begin_layout Standard
11359 In addition to the ANSI storage classes SDCC allows the following MCS51
11360 specific storage classes:
11363 \begin_layout Subsubsection
11365 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11370 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11375 \begin_inset LatexCommand \index{near (storage class)}
11380 \begin_inset LatexCommand \index{\_\_near (storage class)}
11387 \begin_layout Standard
11392 storage class for the Small Memory model (
11400 or the more ANSI-C compliant forms
11408 can be used synonymously).
11409 Variables declared with this storage class will be allocated in the directly
11410 addressable portion of the internal RAM of a 8051, e.g.:
11413 \begin_layout Verse
11416 __data unsigned char test_data;
11419 \begin_layout Standard
11420 Writing 0x01 to this variable generates the assembly code:
11423 \begin_layout Verse
11426 75*00 01\InsetSpace ~
11434 \begin_layout Subsubsection
11436 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11441 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11446 \begin_inset LatexCommand \index{far (storage class)}
11451 \begin_inset LatexCommand \index{\_\_far (storage class)}
11458 \begin_layout Standard
11459 Variables declared with this storage class will be placed in the external
11465 storage class for the Large Memory model, e.g.:
11468 \begin_layout Verse
11471 __xdata unsigned char test_xdata;
11474 \begin_layout Standard
11475 Writing 0x01 to this variable generates the assembly code:
11478 \begin_layout Verse
11481 90s00r00\InsetSpace ~
11512 \begin_layout Subsubsection
11514 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11519 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11526 \begin_layout Standard
11527 Variables declared with this storage class will be allocated into the indirectly
11528 addressable portion of the internal ram of a 8051, e.g.:
11531 \begin_layout Verse
11534 __idata unsigned char test_idata;
11537 \begin_layout Standard
11538 Writing 0x01 to this variable generates the assembly code:
11541 \begin_layout Verse
11568 \begin_layout Standard
11569 Please note, the first 128 byte of idata physically access the same RAM
11570 as the data memory.
11571 The original 8051 had 128 byte idata memory, nowadays most devices have
11572 256 byte idata memory.
11574 \begin_inset LatexCommand \index{stack}
11578 is located in idata memory.
11581 \begin_layout Subsubsection
11583 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11588 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11595 \begin_layout Standard
11596 Paged xdata access is just as straightforward as using the other addressing
11598 It is typically located at the start of xdata and has a maximum size of
11600 The following example writes 0x01 to the pdata variable.
11601 Please note, pdata access physically accesses xdata memory.
11602 The high byte of the address is determined by port P2
11603 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11607 (or in case of some 8051 variants by a separate Special Function Register,
11609 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11618 storage class for the Medium Memory model, e.g.:
11621 \begin_layout Verse
11624 __pdata unsigned char test_pdata;
11627 \begin_layout Standard
11628 Writing 0x01 to this variable generates the assembly code:
11631 \begin_layout Verse
11640 mov r0,#_test_pdata
11662 \begin_layout Standard
11667 \begin_layout Standard
11677 \begin_inset LatexCommand \index{-\/-xstack}
11681 option is used the pdata memory area is followed by the xstack memory area
11682 and the sum of their sizes is limited to 256 bytes.
11685 \begin_layout Subsubsection
11687 \begin_inset LatexCommand \index{code}
11692 \begin_inset LatexCommand \index{\_\_code}
11699 \begin_layout Standard
11700 'Variables' declared with this storage class will be placed in the code
11704 \begin_layout Verse
11707 __code unsigned char test_code;
11710 \begin_layout Standard
11711 Read access to this variable generates the assembly code:
11714 \begin_layout Verse
11717 90s00r6F\InsetSpace ~
11720 mov dptr,#_test_code
11745 \begin_layout Standard
11750 indexed arrays of characters in code memory can be accessed efficiently:
11753 \begin_layout Verse
11756 __code char test_array[] = {'c','h','e','a','p'};
11759 \begin_layout Standard
11760 Read access to this array using an 8-bit unsigned index generates the assembly
11764 \begin_layout Verse
11776 \begin_layout Verse
11779 90s00r41\InsetSpace ~
11782 mov dptr,#_test_array
11785 \begin_layout Verse
11800 \begin_layout Subsubsection
11802 \begin_inset LatexCommand \index{bit}
11807 \begin_inset LatexCommand \index{\_\_bit}
11814 \begin_layout Standard
11815 This is a data-type and a storage class specifier.
11816 When a variable is declared as a bit, it is allocated into the bit addressable
11817 memory of 8051, e.g.:
11820 \begin_layout Verse
11826 \begin_layout Standard
11827 Writing 1 to this variable generates the assembly code:
11830 \begin_layout Verse
11844 \begin_layout Standard
11845 The bit addressable memory consists of 128 bits which are located from 0x20
11846 to 0x2f in data memory.
11849 Apart from this 8051 specific storage class most architectures support
11851 \begin_inset LatexCommand \index{bitfields}
11859 \begin_layout Standard
11860 Not really meant as examples, but nevertheless showing what bitfields are
11861 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
11867 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
11868 signed modifier are implemented as unsigned.
11871 \begin_layout Subsubsection
11873 \begin_inset LatexCommand \index{sfr}
11878 \begin_inset LatexCommand \index{\_\_sfr}
11883 \begin_inset LatexCommand \index{sfr16}
11888 \begin_inset LatexCommand \index{\_\_sfr16}
11893 \begin_inset LatexCommand \index{sfr32}
11898 \begin_inset LatexCommand \index{\_\_sfr32}
11903 \begin_inset LatexCommand \index{\_\_sbit}
11908 \begin_inset LatexCommand \index{sbit}
11915 \begin_layout Standard
11916 Like the bit keyword,
11918 sfr / sfr16 / sfr32 / sbit
11920 signify both a data-type and storage class, they are used to describe the
11941 variables of a 8051, eg:
11944 \begin_layout Verse
11948 \begin_inset LatexCommand \index{at}
11953 \begin_inset LatexCommand \index{\_\_at}
11957 (0x80) P0;\InsetSpace ~
11958 /* special function register P0 at location 0x80 */
11963 special function register combination for timer 0
11967 with the high byte at
11968 location 0x8C and the low byte at location 0x8A */
11970 __sfr16 __at (0x8C8A)
11976 \begin_inset LatexCommand \index{at}
11981 \begin_inset LatexCommand \index{\_\_at}
11985 (0xd7) CY;\InsetSpace ~
11987 \begin_inset LatexCommand \index{Flags}
11992 \begin_inset LatexCommand \index{Carry flag}
11999 \begin_layout Standard
12000 Special function registers which are located on an address dividable by
12001 8 are bit-addressable, an
12005 addresses a specific bit within these sfr.
12007 16 Bit and 32 bit special function
12008 register combinations which require a certain access order are better not
12018 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12019 this is not guaranteed.
12024 \begin_layout Standard
12025 Please note, if you use a header file which was written for another compiler
12026 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
12032 Specifically the syntax
12035 sfr P0 = 0x80;\InsetSpace ~
12042 by SDCC to an assignment of 0x80 to a variable called P0
12045 \begin_inset Marginal
12048 \begin_layout Standard
12060 Nevertheless it is possible to write header files
12061 \begin_inset LatexCommand \index{Header files}
12066 \begin_inset LatexCommand \index{Include files}
12070 which can be shared among different compilers (see section
12071 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
12079 \begin_layout Subsubsection
12081 \begin_inset LatexCommand \index{Pointer}
12085 to MCS51/DS390 specific memory spaces
12088 \begin_layout Standard
12089 SDCC allows (via language extensions) pointers to explicitly point to any
12090 of the memory spaces
12091 \begin_inset LatexCommand \index{Memory model}
12096 In addition to the explicit pointers, the compiler uses (by default) generic
12097 pointers which can be used to point to any of the memory spaces.
12102 declaration examples:
12105 \begin_layout Verse
12108 /* pointer physically in internal ram pointing to object in external ram
12111 __xdata unsigned char * __data p;
12115 /* pointer physically in external ram
12116 pointing to object in internal ram */
12118 __data unsigned char * __xdata p;
12123 pointer physically in code rom pointing to data in xdata space */
12126 unsigned char * __code p;
12130 /* pointer physically in code space pointing to
12131 data in code space */
12133 __code unsigned char * __code p;
12138 physically located in xdata space */
12140 unsigned char * __xdata p;
12145 pointer physically located in default memory space */
12152 the following is a function pointer
12153 \begin_inset LatexCommand \index{function pointer}
12157 physically located in data space */
12159 char (* __data fp)(void);
12162 \begin_layout Standard
12163 Well you get the idea.
12168 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
12181 The highest order byte of the
12185 pointers contains the data space information.
12186 Assembler support routines are called whenever data is stored or retrieved
12192 These are useful for developing reusable library
12193 \begin_inset LatexCommand \index{Libraries}
12198 Explicitly specifying the pointer
12199 \begin_inset LatexCommand \index{pointer}
12203 type will generate the most efficient code.
12206 \begin_layout Subsubsection
12207 Notes on MCS51 memory
12208 \begin_inset LatexCommand \index{MCS51 memory}
12215 \begin_layout Standard
12216 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12217 RAM memory which is structured as follows:
12221 - Bytes 00-1F - 32 bytes to hold
12222 up to 4 banks of the registers R0 to R7,
12224 - Bytes 20-2F - 16 bytes to hold
12226 \begin_inset LatexCommand \index{bit}
12232 - Bytes 30-7F - 80 bytes for general purpose use.
12237 \begin_layout Standard
12238 Additionally some members of the MCS51 family may have up to 128 bytes of
12239 additional, indirectly addressable, internal RAM memory (
12244 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12249 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12254 Furthermore, some chips may have some built in external memory (
12259 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12264 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12268 ) which should not be confused with the internal, directly addressable RAM
12274 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12279 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12284 Sometimes this built in
12288 memory has to be activated before using it (you can probably find this
12289 information on the datasheet of the microcontroller your are using, see
12291 \begin_inset LatexCommand \ref{sub:Startup-Code}
12299 \begin_layout Standard
12300 Normally SDCC will only use the first bank
12301 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12305 of registers (register bank 0), but it is possible to specify that other
12306 banks of registers (keyword
12313 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12318 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12324 ) should be used for example in interrupt
12325 \begin_inset LatexCommand \index{interrupt}
12330 \begin_inset LatexCommand \index{\_\_interrupt}
12335 By default, the compiler will place the stack after the last byte of allocated
12336 memory for variables.
12337 For example, if the first 2 banks of registers are used, and only four
12342 variables, it will position the base of the internal stack at address 20
12344 This implies that as the stack
12345 \begin_inset LatexCommand \index{stack}
12349 grows, it will use up the remaining register banks, and the 16 bytes used
12350 by the 128 bit variables, and 80 bytes for general purpose use.
12351 If any bit variables are used, the data variables will be placed in unused
12352 register banks and after the byte holding the last bit variable.
12353 For example, if register banks 0 and 1 are used, and there are 9 bit variables
12358 variables will be placed starting from address 0x10 to 0x20 and continue
12364 \begin_layout Standard
12374 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12378 to specify the start address of the
12386 \begin_layout Standard
12396 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12400 to specify the size of the total internal RAM (
12414 \begin_layout Standard
12415 By default the 8051 linker will place the stack after the last byte of (i)data
12421 \begin_layout Standard
12431 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12435 allows you to specify the start of the stack, i.e.
12436 you could start it after any data in the general purpose area.
12437 If your microcontroller has additional indirectly addressable internal
12442 ) you can place the stack on it.
12443 You may also need to use -
12447 \begin_layout Standard
12457 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12461 to set the start address of the external RAM (
12469 \begin_layout Standard
12479 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12483 to specify its size.
12484 Same goes for the code memory, using -
12488 \begin_layout Standard
12498 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12506 \begin_layout Standard
12516 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12521 If in doubt, don't specify any options and see if the resulting memory
12522 layout is appropriate, then you can adjust it.
12525 \begin_layout Standard
12526 The linker generates two files with memory allocation information.
12527 The first, with extension .map
12528 \begin_inset LatexCommand \index{<file>.map}
12532 shows all the variables and segments.
12533 The second with extension .mem
12534 \begin_inset LatexCommand \index{<file>.mem}
12538 shows the final memory layout.
12539 The linker will complain either if memory segments overlap, there is not
12540 enough memory, or there is not enough space for stack.
12541 If you get any linking warnings and/or errors related to stack or segments
12542 allocation, take a look at either the .map or .mem files to find out what
12544 The .mem file may even suggest a solution to the problem.
12545 \begin_inset VSpace bigskip
12551 \begin_layout Subsection
12552 Z80/Z180 Storage Class
12553 \begin_inset LatexCommand \index{Z80!Storage class}
12557 Language Extensions
12560 \begin_layout Subsubsection
12562 \begin_inset LatexCommand \index{sfr}
12567 \begin_inset LatexCommand \index{\_\_sfr}
12571 (in/out to 8-bit addresses)
12574 \begin_layout Standard
12576 \begin_inset LatexCommand \index{Z80}
12580 family has separate address spaces for memory and
12590 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12595 \begin_inset LatexCommand \index{Z80!I/O memory}
12600 \begin_inset LatexCommand \index{Z180!I/O memory}
12604 is accessed with special instructions, e.g.:
12607 \begin_layout Verse
12610 sfr at 0x78 IoPort;\InsetSpace ~
12612 /* define a var in I/O space at 78h called IoPort */
12616 \begin_layout Standard
12617 Writing 0x01 to this variable generates the assembly code:
12620 \begin_layout Verse
12640 \begin_layout Subsubsection
12642 \begin_inset LatexCommand \index{sfr}
12647 \begin_inset LatexCommand \index{\_\_sfr}
12651 (in/out to 16-bit addresses)
12654 \begin_layout Standard
12659 is used to support 16 bit addresses in I/O memory e.g.:
12662 \begin_layout Verse
12666 \begin_inset LatexCommand \index{at}
12671 \begin_inset LatexCommand \index{\_\_at}
12678 \begin_layout Standard
12679 Writing 0x01 to this variable generates the assembly code:
12682 \begin_layout Verse
12685 01 23 01\InsetSpace ~
12707 \begin_layout Subsubsection
12709 \begin_inset LatexCommand \index{sfr}
12714 \begin_inset LatexCommand \index{\_\_sfr}
12718 (in0/out0 to 8 bit addresses on Z180
12719 \begin_inset LatexCommand \index{Z180}
12724 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12731 \begin_layout Standard
12732 The compiler option -
12736 \begin_layout Standard
12746 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
12750 =180 (80) and a compiler #pragma\InsetSpace ~
12752 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
12756 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12766 If you include the file z180.h this will be set automatically.
12767 \begin_inset VSpace bigskip
12773 \begin_layout Subsection
12775 \begin_inset LatexCommand \index{HC08!Storage class}
12779 Language Extensions
12782 \begin_layout Subsubsection
12784 \begin_inset LatexCommand \index{data (hc08 storage class)}
12789 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
12796 \begin_layout Standard
12797 The data storage class declares a variable that resides in the first 256
12798 bytes of memory (the direct page).
12800 \begin_inset LatexCommand \index{HC08}
12804 is most efficient at accessing variables (especially pointers) stored here.
12807 \begin_layout Subsubsection
12809 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
12814 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
12821 \begin_layout Standard
12822 The xdata storage class declares a variable that can reside anywhere in
12824 This is the default if no storage class is specified.
12826 \begin_inset VSpace bigskip
12832 \begin_layout Section
12833 Absolute Addressing
12834 \begin_inset LatexCommand \index{Absolute addressing}
12841 \begin_layout Standard
12842 Data items can be assigned an absolute address with the
12845 \begin_inset LatexCommand \index{at}
12850 \begin_inset LatexCommand \index{\_\_at}
12856 keyword, in addition to a storage class, e.g.:
12859 \begin_layout Verse
12863 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12868 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12873 \begin_inset LatexCommand \index{at}
12878 \begin_inset LatexCommand \index{\_\_at}
12882 0x7ffe unsigned int chksum;
12885 \begin_layout Standard
12886 or, better conforming to ISO/IEC 9899 C:
12889 \begin_layout Verse
12892 __xdata __at (0x7ffe) unsigned int chksum;
12895 \begin_layout Standard
12896 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
12897 of the external ram.
12902 reserve any space for variables declared in this way
12903 \begin_inset Marginal
12906 \begin_layout Standard
12915 (they are implemented with an equate in the assembler).
12916 Thus it is left to the programmer to make sure there are no overlaps with
12917 other variables that are declared without the absolute address.
12918 The assembler listing file (.lst
12919 \begin_inset LatexCommand \index{<file>.lst}
12923 ) and the linker output files (.rst
12924 \begin_inset LatexCommand \index{<file>.rst}
12929 \begin_inset LatexCommand \index{<file>.map}
12933 ) are good places to look for such overlaps.
12936 \begin_layout Standard
12937 If however you provide an initializer
12938 \begin_inset LatexCommand \index{Variable initialization}
12942 actual memory allocation will take place and overlaps will be detected
12947 \begin_layout Verse
12950 __code __at (0x7ff0) char Id[5] =
12951 \begin_inset Quotes sld
12955 \begin_inset Quotes srd
12961 \begin_layout Standard
12962 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
12966 \begin_layout Standard
12967 In case of memory mapped I/O devices the keyword
12971 has to be used to tell the compiler that accesses might not be removed:
12974 \begin_layout Verse
12978 \begin_inset LatexCommand \index{volatile}
12983 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12988 \begin_inset LatexCommand \index{at}
12992 (0x8000) unsigned char PORTA_8255;
12995 \begin_layout Standard
12996 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
13001 \begin_inset LatexCommand \index{Aligned array}
13008 starts at a block (256 byte) boundary
13009 \begin_inset LatexCommand \index{block boundary}
13014 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13020 Absolute addresses can be specified for variables in all
13021 storage classes, e.g.:
13024 \begin_layout Verse
13028 \begin_inset LatexCommand \index{bit}
13033 \begin_inset LatexCommand \index{at}
13040 \begin_layout Standard
13041 The above example will allocate the variable at offset 0x02 in the bit-addressab
13043 There is no real advantage to assigning absolute addresses to variables
13044 in this manner, unless you want strict control over all the variables allocated.
13045 One possible use would be to write hardware portable code.
13046 For example, if you have a routine that uses one or more of the microcontroller
13047 I/O pins, and such pins are different for two different hardwares, you
13048 can declare the I/O pins in your routine using:
13051 \begin_layout Verse
13055 \begin_inset LatexCommand \index{volatile}
13059 __bit MOSI;\InsetSpace ~
13063 /* master out, slave in */
13065 extern volatile __bit MISO;\InsetSpace ~
13072 extern volatile __bit MCLK;\InsetSpace ~
13081 Output of a byte on a 3-wire serial bus.
13086 If needed adapt polarity of clock,
13087 polarity of data and bit order
13092 unsigned char spi_io(unsigned char out_byte)
13117 MOSI = out_byte & 0x80;
13148 /* _asm nop _endasm; */\InsetSpace ~
13156 /* for slow peripherals */
13208 \begin_layout Standard
13209 Then, someplace in the code for the first hardware you would use
13212 \begin_layout Verse
13216 \begin_inset LatexCommand \index{at}
13221 \begin_inset LatexCommand \index{\_\_at}
13225 (0x80) MOSI;\InsetSpace ~
13229 /* I/O port 0, bit 0 */
13231 __bit __at (0x81) MISO;\InsetSpace ~
13238 __bit __at (0x82) MCLK;\InsetSpace ~
13242 /* I/O port 0, bit 2 */
13245 \begin_layout Standard
13246 Similarly, for the second hardware you would use
13249 \begin_layout Verse
13252 __bit __at (0x83) MOSI;\InsetSpace ~
13256 /* I/O port 0, bit 3 */
13258 __bit __at (0x91) MISO;\InsetSpace ~
13263 I/O port 1, bit 1 */
13266 \begin_inset LatexCommand \index{bit}
13270 __at (0x92) MCLK;\InsetSpace ~
13274 /* I/O port 1, bit 2 */
13277 \begin_layout Standard
13278 and you can use the same hardware dependent routine without changes, as
13279 for example in a library.
13280 This is somehow similar to sbit, but only one absolute address has to be
13281 specified in the whole project.
13282 \begin_inset VSpace bigskip
13288 \begin_layout Section
13290 \begin_inset LatexCommand \index{Parameters}
13295 \begin_inset LatexCommand \index{function parameter}
13300 \begin_inset LatexCommand \index{local variables}
13305 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13312 \begin_layout Standard
13313 Automatic (local) variables and parameters to functions can either be placed
13314 on the stack or in data-space.
13315 The default action of the compiler is to place these variables in the internal
13316 RAM (for small model) or external RAM (for medium or large model).
13317 This in fact makes them similar to
13320 \begin_inset LatexCommand \index{static}
13326 so by default functions are non-reentrant
13327 \begin_inset LatexCommand \index{reentrant}
13336 They can be placed on the stack
13337 \begin_inset LatexCommand \index{stack}
13347 \begin_layout Standard
13357 \begin_inset LatexCommand \index{-\/-stack-auto}
13365 #pragma\InsetSpace ~
13369 \begin_inset LatexCommand \index{\#pragma stackauto}
13376 \begin_inset LatexCommand \index{reentrant}
13382 keyword in the function declaration, e.g.:
13385 \begin_layout Verse
13388 unsigned char foo(char i) __reentrant
13402 \begin_layout Standard
13403 Since stack space on 8051 is limited, the
13413 \begin_layout Standard
13424 option should be used sparingly.
13425 Note that the reentrant keyword just means that the parameters & local
13426 variables will be allocated to the stack, it
13430 mean that the function is register bank
13431 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13440 \begin_inset LatexCommand \index{local variables}
13444 can be assigned storage classes and absolute
13445 \begin_inset LatexCommand \index{Absolute addressing}
13452 \begin_layout Verse
13455 unsigned char foo()
13463 __xdata unsigned char i;
13476 \begin_inset LatexCommand \index{at}
13480 (0x31) unsigned char j;
13492 \begin_layout Standard
13493 In the above example the variable
13497 will be allocated in the external ram,
13501 in bit addressable space and
13512 \begin_layout Standard
13523 or when a function is declared as
13527 this should only be done for static variables.
13530 \begin_layout Standard
13532 \begin_inset LatexCommand \index{function parameter}
13536 however are not allowed any storage class
13537 \begin_inset LatexCommand \index{Storage class}
13541 , (storage classes for parameters will be ignored), their allocation is
13542 governed by the memory model in use, and the reentrancy options.
13545 \begin_layout Standard
13546 It is however allowed to use bit parameters in reentrant functions and also
13547 non-static local bit variables are supported.
13548 Efficient use is limited to 8 semi-bitregisters in bit space.
13549 They are pushed and popped to stack
13550 \begin_inset LatexCommand \index{stack}
13554 as a single byte just like the normal registers.
13557 \begin_layout Section
13559 \begin_inset LatexCommand \label{sub:Overlaying}
13564 \begin_inset LatexCommand \index{Overlaying}
13571 \begin_layout Standard
13573 \begin_inset LatexCommand \index{reentrant}
13577 functions SDCC will try to reduce internal ram space usage by overlaying
13578 parameters and local variables of a function (if possible).
13579 Parameters and local variables
13580 \begin_inset LatexCommand \index{local variables}
13584 of a function will be allocated to an overlayable segment if the function
13587 no other function calls and the function is non-reentrant and the memory
13589 \begin_inset LatexCommand \index{Memory model}
13596 If an explicit storage class
13597 \begin_inset LatexCommand \index{Storage class}
13601 is specified for a local variable, it will NOT be overlayed.
13604 \begin_layout Standard
13605 Note that the compiler (not the linkage editor) makes the decision for overlayin
13607 Functions that are called from an interrupt service routine
13608 \begin_inset Marginal
13611 \begin_layout Standard
13619 should be preceded by a #pragma\InsetSpace ~
13621 \begin_inset LatexCommand \index{\#pragma nooverlay}
13625 if they are not reentrant.
13628 \begin_layout Standard
13629 Also note that the compiler does not do any processing of inline assembler
13630 code, so the compiler might incorrectly assign local variables and parameters
13631 of a function into the overlay segment if the inline assembler code calls
13632 other c-functions that might use the overlay.
13633 In that case the #pragma\InsetSpace ~
13634 nooverlay should be used.
13637 \begin_layout Standard
13638 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13640 \begin_inset LatexCommand \index{Multiplication}
13645 \begin_inset LatexCommand \index{Division}
13649 will NOT be overlayed since these are implemented using external functions,
13653 \begin_layout Verse
13659 \begin_inset LatexCommand \index{\#pragma nooverlay}
13665 void set_error(unsigned char errcd)
13682 some_isr () __interrupt
13683 \begin_inset LatexCommand \index{interrupt}
13713 \begin_layout Standard
13714 In the above example the parameter
13722 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13724 not present, this could cause unpredictable runtime behavior when called
13725 from an interrupt service routine.
13726 The #pragma\InsetSpace ~
13727 nooverlay ensures that the parameters and local variables for
13728 the function are NOT overlayed.
13729 \begin_inset VSpace bigskip
13735 \begin_layout Section
13736 Interrupt Service Routines
13737 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13744 \begin_layout Subsection
13745 General Information
13748 \begin_layout Standard
13761 outines to be coded in C, with some extended keywords.
13764 \begin_layout Verse
13767 void timer_isr (void) __interrupt (1) __using (1)
13781 \begin_layout Standard
13782 The optional number following the
13785 \begin_inset LatexCommand \index{interrupt}
13790 \begin_inset LatexCommand \index{\_\_interrupt}
13796 keyword is the interrupt number this routine will service.
13797 When present, the compiler will insert a call to this routine in the interrupt
13799 \begin_inset LatexCommand \index{interrupt vector table}
13803 for the interrupt number specified.
13804 If you have multiple source files in your project, interrupt service routines
13805 can be present in any of them, but a prototype of the isr MUST be present
13806 or included in the file that contains the function
13811 The optional (8051 specific) keyword
13814 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13819 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13825 can be used to tell the compiler to use the specified register bank when
13826 generating code for this function.
13829 Interrupt service routines open the door for some very interesting bugs:
13832 \begin_layout Subsubsection
13833 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
13837 Common interrupt pitfall: variable not declared
13842 \begin_layout Standard
13843 If an interrupt service routine changes variables which are accessed by
13844 other functions these variables have to be declared
13849 \begin_inset LatexCommand \index{volatile}
13855 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
13862 \begin_layout Subsubsection
13863 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
13867 Common interrupt pitfall:
13872 \begin_layout Standard
13873 If the access to these variables is not
13876 \begin_inset LatexCommand \index{atomic}
13883 the processor needs more than one instruction for the access and could
13884 be interrupted while accessing the variable) the interrupt must be disabled
13885 during the access to avoid inconsistent data.
13888 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
13889 and should be protected by disabling interrupts.
13890 You're not automatically on the safe side if you use 8 bit variables though.
13891 We need an example here: f.e.
13892 on the 8051 the harmless looking
13893 \begin_inset Quotes srd
13903 \begin_inset Quotes sld
13912 \begin_inset Quotes srd
13922 \begin_inset Quotes sld
13925 from within an interrupt routine might get lost if the interrupt occurs
13928 \begin_inset Quotes sld
13933 counter\InsetSpace ~
13938 \begin_inset Quotes srd
13941 is not atomic on the 8051 even if
13945 is located in data memory.
13947 Bugs like these are hard to reproduce and can
13948 cause a lot of trouble.
13952 \begin_layout Subsubsection
13953 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
13957 Common interrupt pitfall:
13962 \begin_layout Standard
13963 The return address and the registers used in the interrupt service routine
13964 are saved on the stack
13965 \begin_inset LatexCommand \index{stack}
13969 so there must be sufficient stack space.
13970 If there isn't variables or registers (or even the return address itself)
13977 \begin_inset LatexCommand \index{stack overflow}
13981 is most likely to happen if the interrupt occurs during the
13982 \begin_inset Quotes sld
13986 \begin_inset Quotes srd
13989 subroutine when the stack is already in use for f.e.
13990 many return addresses.
13993 \begin_layout Subsubsection
13994 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
13998 Common interrupt pitfall:
14000 use of non-reentrant functions
14003 \begin_layout Standard
14004 A special note here, int (16 bit) and long (32 bit) integer division
14005 \begin_inset LatexCommand \index{Division}
14010 \begin_inset LatexCommand \index{Multiplication}
14015 \begin_inset LatexCommand \index{Modulus}
14020 \begin_inset LatexCommand \index{Floating point support}
14024 operations are implemented using external support routines.
14025 If an interrupt service routine needs to do any of these operations then
14026 the support routines (as mentioned in a following section) will have to
14027 be recompiled using the
14033 \begin_layout Standard
14043 \begin_inset LatexCommand \index{-\/-stack-auto}
14049 option and the source file will need to be compiled using the
14055 \begin_layout Standard
14067 \begin_inset LatexCommand \index{-\/-int-long-reent}
14074 Note, the type promotion
14075 \begin_inset LatexCommand \index{type promotion}
14079 required by ANSI C can cause 16 bit routines to be used
14080 \begin_inset Marginal
14083 \begin_layout Standard
14092 without the programmer being aware of it.
14096 (unsigned char)(tail-1)
14098 within the if clause in section
14099 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
14106 \begin_layout Standard
14107 Calling other functions from an interrupt service routine is not recommended,
14108 avoid it if possible.
14109 Note that when some function is called from an interrupt service routine
14110 it should be preceded by a #pragma\InsetSpace ~
14112 \begin_inset LatexCommand \index{\#pragma nooverlay}
14116 if it is not reentrant.
14117 Furthermore nonreentrant functions should not be called from the main program
14118 while the interrupt service routine might be active.
14119 They also must not be called from low priority interrupt service routines
14120 while a high priority interrupt service routine might be active.
14121 You could use semaphores or make the function
14125 if all parameters are passed in registers.
14128 \begin_inset LatexCommand \ref{sub:Overlaying}
14133 about Overlaying and section
14134 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14139 about Functions using private register banks.
14140 \begin_inset VSpace bigskip
14146 \begin_layout Subsection
14147 MCS51/DS390 Interrupt Service Routines
14150 \begin_layout Standard
14152 \begin_inset LatexCommand \index{interrupt}
14156 numbers and the corresponding address & descriptions for the Standard 8051/8052
14158 SDCC will automatically adjust the
14159 \begin_inset LatexCommand \index{interrupt vector table}
14163 to the maximum interrupt number specified.
14168 \begin_layout Standard
14170 \begin_inset Tabular
14171 <lyxtabular version="3" rows="9" columns="3">
14173 <column alignment="center" valignment="top" leftline="true" width="0in">
14174 <column alignment="left" valignment="top" leftline="true" width="0in">
14175 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14176 <row topline="true" bottomline="true">
14177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14180 \begin_layout Standard
14186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14189 \begin_layout Standard
14195 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14198 \begin_layout Standard
14205 <row topline="true">
14206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14209 \begin_layout Standard
14215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14218 \begin_layout Standard
14224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14227 \begin_layout Standard
14234 <row topline="true">
14235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14238 \begin_layout Standard
14244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14247 \begin_layout Standard
14253 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14256 \begin_layout Standard
14263 <row topline="true">
14264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14267 \begin_layout Standard
14273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14276 \begin_layout Standard
14282 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14285 \begin_layout Standard
14292 <row topline="true">
14293 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14296 \begin_layout Standard
14302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14305 \begin_layout Standard
14311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14314 \begin_layout Standard
14321 <row topline="true">
14322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14325 \begin_layout Standard
14331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14334 \begin_layout Standard
14340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14343 \begin_layout Standard
14350 <row topline="true">
14351 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14354 \begin_layout Standard
14360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14363 \begin_layout Standard
14369 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14372 \begin_layout Standard
14379 <row topline="true">
14380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14383 \begin_layout Standard
14389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14392 \begin_layout Standard
14398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14401 \begin_layout Standard
14408 <row topline="true" bottomline="true">
14409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14412 \begin_layout Standard
14418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14421 \begin_layout Standard
14427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14430 \begin_layout Standard
14446 \begin_layout Standard
14447 If the interrupt service routine is defined without
14450 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14455 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14461 a register bank or with register bank 0 (
14465 0), the compiler will save the registers used by itself on the stack upon
14466 entry and restore them at exit, however if such an interrupt service routine
14467 calls another function then the entire register bank will be saved on the
14469 This scheme may be advantageous for small interrupt service routines which
14470 have low register usage.
14473 \begin_layout Standard
14474 If the interrupt service routine is defined to be using a specific register
14479 & psw are saved and restored, if such an interrupt service routine calls
14480 another function (using another register bank) then the entire register
14481 bank of the called function will be saved on the stack
14482 \begin_inset LatexCommand \index{stack}
14487 This scheme is recommended for larger interrupt service routines.
14488 \begin_inset VSpace bigskip
14494 \begin_layout Subsection
14496 \begin_inset LatexCommand \index{HC08}
14500 Interrupt Service Routines
14503 \begin_layout Standard
14504 Since the number of interrupts
14505 \begin_inset LatexCommand \index{HC08!interrupt}
14509 available is chip specific and the interrupt vector table always ends at
14510 the last byte of memory, the interrupt numbers corresponds to the interrupt
14511 vectors in reverse order of address.
14512 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14513 2 will use the interrupt vector at 0xfffa, and so on.
14514 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14515 this way; instead see section
14516 \begin_inset LatexCommand \ref{sub:Startup-Code}
14520 for details on customizing startup.
14521 \begin_inset VSpace bigskip
14527 \begin_layout Subsection
14528 Z80 Interrupt Service Routines
14531 \begin_layout Standard
14533 \begin_inset LatexCommand \index{Z80}
14537 uses several different methods for determining the correct interrupt
14538 \begin_inset LatexCommand \index{Z80!interrupt}
14542 vector depending on the hardware implementation.
14543 Therefore, SDCC ignores the optional interrupt number and does not attempt
14544 to generate an interrupt vector table.
14547 \begin_layout Standard
14548 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14549 instruction to return from the interrupt.
14550 To write an interrupt handler for the non-maskable interrupt, which needs
14551 a RETN instruction instead, add the
14558 \begin_layout Verse
14561 void nmi_isr (void) critical interrupt
14575 \begin_layout Standard
14576 However if you need to create a non-interruptable interrupt service routine
14577 you would also require the
14582 To distinguish between this and an nmi_isr you must provide an interrupt
14584 \begin_inset VSpace bigskip
14590 \begin_layout Section
14591 Enabling and Disabling Interrupts
14594 \begin_layout Subsection
14595 Critical Functions and Critical Statements
14598 \begin_layout Standard
14599 A special keyword may be associated with a block or a function declaring
14605 SDCC will generate code to disable all interrupts
14606 \begin_inset LatexCommand \index{interrupt}
14610 upon entry to a critical function and restore the interrupt enable to the
14611 previous state before returning.
14612 Nesting critical functions will need one additional byte on the stack
14613 \begin_inset LatexCommand \index{stack}
14620 \begin_layout Verse
14623 int foo () __critical
14624 \begin_inset LatexCommand \index{critical}
14629 \begin_inset LatexCommand \index{\_\_critical}
14654 \begin_layout Standard
14655 The critical attribute maybe used with other attributes like
14665 may also be used to disable interrupts more locally:
14668 \begin_layout Verse
14674 \begin_layout Standard
14675 More than one statement could have been included in the block.
14678 \begin_layout Subsection
14679 Enabling and Disabling Interrupts directly
14682 \begin_layout Standard
14684 \begin_inset LatexCommand \index{interrupt}
14688 can also be disabled and enabled directly (8051):
14691 \begin_layout Verse
14694 EA = 0;\InsetSpace ~
14720 \begin_layout Verse
14756 \begin_layout Verse
14759 EA = 1;\InsetSpace ~
14788 \begin_layout Verse
14827 \begin_layout Standard
14828 On other architectures which have seperate opcodes for enabling and disabling
14829 interrupts you might want to make use of defines with inline assembly
14830 \begin_inset LatexCommand \index{Assembler routines}
14835 \begin_inset LatexCommand \index{HC08!interrupt}
14842 \begin_layout Verse
14846 \begin_inset LatexCommand \index{\_asm}
14855 \begin_inset LatexCommand \index{\_endasm}
14862 \begin_layout Verse
14865 #define SEI _asm\InsetSpace ~
14872 \begin_layout Verse
14878 \begin_layout Standard
14879 Note: it is sometimes sufficient to disable only a specific interrupt source
14881 a timer or serial interrupt by manipulating an
14884 \begin_inset LatexCommand \index{interrupt mask}
14894 \begin_layout Standard
14895 Usually the time during which interrupts are disabled should be kept as
14897 This minimizes both
14902 \begin_inset LatexCommand \index{interrupt latency}
14906 (the time between the occurrence of the interrupt and the execution of
14907 the first code in the interrupt routine) and
14912 \begin_inset LatexCommand \index{interrupt jitter}
14916 (the difference between the shortest and the longest interrupt latency).
14917 These really are something different, f.e.
14918 a serial interrupt has to be served before its buffer overruns so it cares
14919 for the maximum interrupt latency, whereas it does not care about jitter.
14920 On a loudspeaker driven via a digital to analog converter which is fed
14921 by an interrupt a latency of a few milliseconds might be tolerable, whereas
14922 a much smaller jitter will be very audible.
14925 \begin_layout Standard
14926 You can reenable interrupts within an interrupt routine and on some architecture
14927 s you can make use of two (or more) levels of
14929 interrupt priorities
14932 \begin_inset LatexCommand \index{interrupt priority}
14937 On some architectures which don't support interrupt priorities these can
14938 be implemented by manipulating the interrupt mask and reenabling interrupts
14939 within the interrupt routine.
14940 Check there is sufficient space on the stack
14941 \begin_inset LatexCommand \index{stack}
14945 and don't add complexity unless you have to.
14949 \begin_layout Subsection
14951 \begin_inset LatexCommand \index{semaphore}
14955 locking (mcs51/ds390)
14958 \begin_layout Standard
14959 Some architectures (mcs51/ds390) have an atomic
14960 \begin_inset LatexCommand \index{atomic}
14973 These type of instructions are typically used in preemptive multitasking
14974 systems, where a routine f.e.
14975 claims the use of a data structure ('acquires a lock
14976 \begin_inset LatexCommand \index{lock}
14980 on it'), makes some modifications and then releases the lock when the data
14981 structure is consistent again.
14982 The instruction may also be used if interrupt and non-interrupt code have
14983 to compete for a resource.
14984 With the atomic bit test and clear instruction interrupts
14985 \begin_inset LatexCommand \index{interrupt}
14989 don't have to be disabled for the locking operation.
14993 \begin_layout Standard
14994 SDCC generates this instruction if the source follows this pattern:
14997 \begin_layout Verse
15001 \begin_inset LatexCommand \index{volatile}
15005 bit resource_is_free;
15009 if (resource_is_free)
15019 resource_is_free=0;
15032 resource_is_free=1;
15039 \begin_layout Standard
15040 Note, mcs51 and ds390 support only an atomic
15041 \begin_inset LatexCommand \index{atomic}
15049 instruction (as opposed to atomic bit test and
15054 \begin_layout Section
15055 Functions using private register banks
15056 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
15063 \begin_layout Standard
15064 Some architectures have support for quickly changing register sets.
15065 SDCC supports this feature with the
15068 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
15073 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
15079 attribute (which tells the compiler to use a register bank
15080 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
15084 other than the default bank zero).
15085 It should only be applied to
15088 \begin_inset LatexCommand \index{interrupt}
15094 functions (see footnote below).
15095 This will in most circumstances make the generated ISR code more efficient
15096 since it will not have to save registers on the stack.
15099 \begin_layout Standard
15104 attribute will have no effect on the generated code for a
15108 function (but may occasionally be useful anyway
15112 \begin_layout Standard
15113 possible exception: if a function is called ONLY from 'interrupt' functions
15114 using a particular bank, it can be declared with the same 'using' attribute
15115 as the calling 'interrupt' functions.
15116 For instance, if you have several ISRs using bank one, and all of them
15117 call memcpy(), it might make sense to create a specialized version of memcpy()
15118 'using 1', since this would prevent the ISR from having to save bank zero
15119 to the stack on entry and switch to bank zero before calling the function
15128 (pending: Note, nowadays the
15132 attribute has an effect on
15136 the generated code for a
15147 \begin_layout Standard
15152 function using a non-zero bank will assume that it can trash that register
15153 bank, and will not save it.
15154 Since high-priority interrupts
15155 \begin_inset LatexCommand \index{interrupts}
15160 \begin_inset LatexCommand \index{interrupt priority}
15164 can interrupt low-priority ones on the 8051 and friends, this means that
15165 if a high-priority ISR
15169 a particular bank occurs while processing a low-priority ISR
15173 the same bank, terrible and bad things can happen.
15174 To prevent this, no single register bank should be
15178 by both a high priority and a low priority ISR.
15179 This is probably most easily done by having all high priority ISRs use
15180 one bank and all low priority ISRs use another.
15181 If you have an ISR which can change priority at runtime, you're on your
15182 own: I suggest using the default bank zero and taking the small performance
15186 \begin_layout Standard
15187 It is most efficient if your ISR calls no other functions.
15188 If your ISR must call other functions, it is most efficient if those functions
15189 use the same bank as the ISR (see note 1 below); the next best is if the
15190 called functions use bank zero.
15191 It is very inefficient to call a function using a different, non-zero bank
15194 \begin_inset VSpace bigskip
15200 \begin_layout Section
15202 \begin_inset LatexCommand \label{sub:Startup-Code}
15207 \begin_inset LatexCommand \index{Startup code}
15214 \begin_layout Subsection
15215 MCS51/DS390 Startup Code
15218 \begin_layout Standard
15219 The compiler triggers the linker to link certain initialization modules
15220 from the runtime library
15221 \begin_inset LatexCommand \index{Runtime library}
15225 called crt<something>.
15226 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15227 GSINIT5) is not linked unless the -
15233 \begin_layout Standard
15244 -xstack option is used.
15245 These modules are highly entangled by the use of special segments/areas,
15246 but a common layout is shown below:
15249 \begin_layout Verse
15257 \begin_layout Verse
15281 ljmp __sdcc_gsinit_startup
15284 \begin_layout Verse
15292 \begin_layout Verse
15304 .area GSINIT0 (CODE)
15306 __sdcc_gsinit_startup::
15316 mov sp,#__start__stack - 1
15319 \begin_layout Verse
15327 \begin_layout Verse
15339 .area GSINIT1 (CODE)
15341 __sdcc_init_xstack::
15343 ; Need to initialize in GSINIT1 in
15344 case the user's __sdcc_external_startup uses the xstack.
15354 mov __XPAGE,#(__start__x
15365 mov _spx,#__start__xstack
15368 \begin_layout Verse
15376 \begin_layout Verse
15388 .area GSINIT2 (CODE)
15398 lcall __sdcc_external_startup
15418 jz __sdcc_init_data
15429 __sdcc_program_startup
15434 \begin_layout Verse
15442 \begin_layout Verse
15454 .area GSINIT3 (CODE)
15507 mov r2,#((l_XINIT+255) >> 8)
15538 __XPAGE,#(s_XISEG >> 8)
15540 00001$:\InsetSpace ~
15604 00002$:\InsetSpace ~
15631 \begin_layout Verse
15639 \begin_layout Verse
15651 .area GSINIT4 (CODE)
15653 __mcs51_genRAMCLEAR::
15675 00004$:\InsetSpace ~
15689 ; _mcs51_genRAMCLEAR() end
15692 \begin_layout Verse
15700 \begin_layout Verse
15712 .area GSINIT4 (CODE)
15714 __mcs51_genXRAMCLEAR::
15765 mov __XPAGE,#(s_PSEG >> 8)
15777 00005$:\InsetSpace ~
15831 orl a,#(l_XSEG >> 8)
15874 00007$:\InsetSpace ~
15911 \begin_layout Verse
15919 \begin_layout Verse
15931 .area GSINIT5 (CODE)
15933 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
15936 ; and __mcs51_genRAMCLEAR modifies _spx.
15946 mov __XPAGE,#(__start__x
15957 mov _spx,#__start__xstack
15960 \begin_layout Verse
15965 (application modules)
15968 \begin_layout Verse
15980 .area GSINIT (CODE)
15983 \begin_layout Verse
15991 \begin_layout Verse
16003 .area GSFINAL (CODE)
16013 ljmp __sdcc_program_startup
16015 ;---------------------------------
16016 -----------------------
16020 ;--------------------------------------------------
16043 __sdcc_program_startup:
16056 return from main will lock up
16069 \begin_layout Standard
16070 One of these modules (crtstart.asm) contains a call to the C routine
16072 _sdcc_external_startup()
16073 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
16082 at the start of the CODE area.
16083 This routine is also in the runtime library
16084 \begin_inset LatexCommand \index{Runtime library}
16088 and returns 0 by default.
16089 If this routine returns a non-zero value, the static & global variable
16090 initialization will be skipped and the function main will be invoked.
16091 Otherwise static & global variables will be initialized before the function
16095 _sdcc_external_startup()
16097 routine to your program to override the default if you need to setup hardware
16098 or perform some other critical operation prior to static & global variable
16100 \begin_inset LatexCommand \index{Variable initialization}
16105 On some mcs51 variants xdata
16106 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
16110 memory has to be explicitly enabled before it can be accessed or if the
16112 \begin_inset LatexCommand \index{watchdog}
16116 needs to be disabled, this is the place to do it.
16117 The startup code clears all internal data memory, 256 bytes by default,
16118 but from 0 to n-1 if
16124 \begin_layout Standard
16134 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16141 (recommended for Chipcon CC1010).
16144 \begin_layout Standard
16145 See also the compiler options
16151 \begin_layout Standard
16167 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16177 \begin_layout Standard
16189 \begin_inset LatexCommand \index{-\/-main-return}
16194 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16198 about MCS51-variants.
16199 \begin_inset VSpace bigskip
16205 \begin_layout Subsection
16209 \begin_layout Standard
16211 \begin_inset LatexCommand \index{HC08}
16215 startup code follows the same scheme as the MCS51 startup code.
16216 \begin_inset VSpace bigskip
16222 \begin_layout Subsection
16226 \begin_layout Standard
16228 \begin_inset LatexCommand \index{Z80}
16232 the startup code is inserted by linking with crt0.o which is generated from
16233 sdcc/device/lib/z80/crt0.s.
16234 If you need a different startup code you can use the compiler option
16243 \begin_layout Standard
16258 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16262 and provide your own crt0.o.
16264 \begin_inset VSpace bigskip
16270 \begin_layout Section
16271 Inline Assembler Code
16272 \begin_inset LatexCommand \index{Assembler routines}
16279 \begin_layout Subsection
16280 A Step by Step Introduction
16281 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16288 \begin_layout Standard
16289 Starting from a small snippet of c-code this example shows for the MCS51
16290 how to use inline assembly, access variables, a function parameter and
16291 an array in xdata memory.
16292 The example uses an MCS51 here but is easily adapted for other architectures.
16293 This is a buffer routine which should be optimized:
16296 \begin_layout Verse
16300 unsigned char __far
16301 \begin_inset LatexCommand \index{far (storage class)}
16306 \begin_inset LatexCommand \index{\_\_far (storage class)}
16311 \begin_inset LatexCommand \index{at}
16316 \begin_inset LatexCommand \index{\_\_at}
16320 (0x7f00) buf[0x100];
16321 \begin_inset LatexCommand \index{Aligned array}
16327 unsigned char head, tail;\InsetSpace ~
16345 \begin_inset LatexCommand \index{interrupt}
16397 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16409 void to_buffer( unsigned char c )
16417 if( head != (unsigned char)(tail-1)
16424 \begin_inset LatexCommand \index{promotion to signed int}
16429 \begin_inset LatexCommand \index{type promotion}
16434 \begin_inset Marginal
16437 \begin_layout Standard
16456 buf[ head++ ] = c;\InsetSpace ~
16472 /* access to a 256 byte aligned array */
16477 \begin_layout Standard
16478 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16479 then a corresponding buffer.asm file is generated.
16480 We define a new function
16484 in file buffer.c in which we cut and paste the generated code, removing
16485 unwanted comments and some ':'.
16487 \begin_inset Quotes sld
16495 \begin_inset Quotes srd
16499 \begin_inset Quotes sld
16507 \begin_inset Quotes srd
16514 \begin_layout Standard
16515 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16516 and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16518 The latter is also used in the library functions.
16523 to the beginning and the end of the function body:
16526 \begin_layout Verse
16530 /* With a cut and paste from the .asm file, we have something to start with.
16536 function is not yet OK! (registers aren't saved) */
16538 void to_buffer_asm(
16548 \begin_inset LatexCommand \index{\_asm}
16553 \begin_inset LatexCommand \index{\_\_asm}
16567 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16573 \begin_inset LatexCommand \index{promotion to signed int}
16578 \begin_inset LatexCommand \index{type promotion}
16631 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
16632 \begin_inset LatexCommand \index{Aligned array}
16698 \begin_inset LatexCommand \index{\_endasm}
16703 \begin_inset LatexCommand \index{\_\_endasm}
16712 \begin_layout Standard
16713 The new file buffer.c should compile with only one warning about the unreferenced
16714 function argument 'c'.
16715 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
16716 (1) and finally have:
16719 \begin_layout Verse
16723 unsigned char __far __at(0x7f00) buf[0x100];
16725 unsigned char head, tail;
16736 void to_buffer( unsigned char c )
16745 head != (unsigned char)(tail-1) )
16774 c; // to avoid warning: unreferenced function argument
16781 \begin_inset LatexCommand \index{\_asm}
16786 \begin_inset LatexCommand \index{\_\_asm}
16800 ; save used registers here.
16811 ; If we were still using r2,r3 we would have to push them here.
16814 ; if( head != (unsigned char)(tail-1) )
16858 could do an ANL a,#0x0f here to use a smaller buffer (see below)
16894 a,dpl \InsetSpace ~
16901 ; dpl holds lower byte of function argument
16913 dpl,_head \InsetSpace ~
16916 ; buf is 0x100 byte aligned so head can be used directly
16959 ; we could do an ANL _head,#0x0f here to use a
16960 smaller buffer (see above)
16972 ; restore used registers here
16979 \begin_inset LatexCommand \index{\_endasm}
16984 \begin_inset LatexCommand \index{\_\_endasm}
16995 \begin_layout Standard
16996 The inline assembler code can contain any valid code understood by the assembler
16997 , this includes any assembler directives and comment lines.
16998 The assembler does not like some characters like ':' or ''' in comments.
16999 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
17000 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
17005 \begin_inset LatexCommand \index{Assembler documentation}
17010 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
17018 \begin_layout Standard
17019 The compiler does not do any validation of the code within the
17022 \begin_inset LatexCommand \index{\_asm}
17027 \begin_inset LatexCommand \index{\_\_asm}
17035 \begin_inset LatexCommand \index{\_endasm}
17040 \begin_inset LatexCommand \index{\_\_endasm}
17049 Specifically it will not know which registers are used and thus register
17051 \begin_inset LatexCommand \index{push/pop}
17055 has to be done manually.
17059 \begin_layout Standard
17060 It is recommended that each assembly instruction (including labels) be placed
17061 in a separate line (as the example shows).
17066 \begin_layout Standard
17078 \begin_inset LatexCommand \index{-\/-peep-asm}
17084 command line option is used, the inline assembler code will be passed through
17085 the peephole optimizer
17086 \begin_inset LatexCommand \index{Peephole optimizer}
17091 There are only a few (if any) cases where this option makes sense, it might
17092 cause some unexpected changes in the inline assembler code.
17093 Please go through the peephole optimizer rules defined in file
17097 before using this option.
17100 \begin_layout Subsection
17102 \begin_inset LatexCommand \label{sub:Naked-Functions}
17107 \begin_inset LatexCommand \index{Naked functions}
17114 \begin_layout Standard
17115 A special keyword may be associated with a function declaring it as
17118 \begin_inset LatexCommand \index{\_naked}
17123 \begin_inset LatexCommand \index{\_\_naked}
17134 function modifier attribute prevents the compiler from generating prologue
17135 \begin_inset LatexCommand \index{function prologue}
17140 \begin_inset LatexCommand \index{function epilogue}
17144 code for that function.
17145 This means that the user is entirely responsible for such things as saving
17146 any registers that may need to be preserved, selecting the proper register
17147 bank, generating the
17151 instruction at the end, etc.
17152 Practically, this means that the contents of the function must be written
17153 in inline assembler.
17154 This is particularly useful for interrupt functions, which can have a large
17155 (and often unnecessary) prologue/epilogue.
17156 For example, compare the code generated by these two functions:
17159 \begin_layout Verse
17163 \begin_inset LatexCommand \index{volatile}
17167 data unsigned char counter;
17171 void simpleInterrupt(void) __interrupt
17172 \begin_inset LatexCommand \index{interrupt}
17177 \begin_inset LatexCommand \index{\_\_interrupt}
17195 void nakedInterrupt(void) __interrupt (2) __naked
17204 \begin_inset LatexCommand \index{\_asm}
17209 \begin_inset LatexCommand \index{\_\_asm}
17226 _counter ; does not change flags, no need to save psw
17239 include ret or reti in _naked function.
17246 \begin_inset LatexCommand \index{\_endasm}
17251 \begin_inset LatexCommand \index{\_\_endasm}
17260 \begin_layout Standard
17261 For an 8051 target, the generated simpleInterrupt looks like:
17264 \begin_layout Verse
17271 example, recent versions of SDCC generate
17277 code for simpleInterrupt() and nakedInterrupt()!
17418 \begin_layout Standard
17419 whereas nakedInterrupt looks like:
17422 \begin_layout Verse
17435 _counter ; does not change flags, no need to save psw
17454 MUST explicitly include ret or reti in _naked function
17457 \begin_layout Standard
17458 The related directive #pragma exclude
17459 \begin_inset LatexCommand \index{\#pragma exclude}
17463 allows a more fine grained control over pushing & popping
17464 \begin_inset LatexCommand \index{push/pop}
17471 \begin_layout Standard
17472 While there is nothing preventing you from writing C code inside a
17476 function, there are many ways to shoot yourself in the foot doing this,
17477 and it is recommended that you stick to inline assembler.
17480 \begin_layout Subsection
17481 Use of Labels within Inline Assembler
17484 \begin_layout Standard
17485 SDCC allows the use of in-line assembler with a few restrictions regarding
17487 All labels defined within inline assembler code have to be of the form
17492 where nnnnn is a number less than 100 (which implies a limit of utmost
17493 100 inline assembler labels
17504 \begin_layout Standard
17505 This is a slightly more stringent rule than absolutely necessary, but stays
17506 always on the safe side.
17507 Labels in the form of nnnnn$ are local labels in the assembler, locality
17508 of which is confined within two labels of the standard form.
17509 The compiler uses the same form for labels within a function (but starting
17510 from nnnnn=00100); and places always a standard label at the beginning
17511 of a function, thus limiting the locality of labels within the scope of
17513 So, if the inline assembler part would be embedded into C-code, an improperly
17514 placed non-local label in the assembler would break up the reference space
17515 for labels created by the compiler for the C-code, leading to an assembling
17519 \begin_layout Standard
17520 The numeric part of local labels does not need to have 5 digits (although
17521 this is the form of labels output by the compiler), any valid integer will
17523 Please refer to the assemblers documentation for further details.
17531 \begin_layout Verse
17535 \begin_inset LatexCommand \index{\_asm}
17540 \begin_inset LatexCommand \index{\_\_asm}
17570 \begin_inset LatexCommand \index{\_endasm}
17575 \begin_inset LatexCommand \index{\_\_endasm}
17582 \begin_layout Standard
17583 Inline assembler code cannot reference any C-labels, however it can reference
17585 \begin_inset LatexCommand \index{Labels}
17589 defined by the inline assembler, e.g.:
17592 \begin_layout Verse
17615 ; some assembler code
17636 /* some more c code */
17638 clabel:\InsetSpace ~
17640 /* inline assembler cannot reference this
17645 \begin_layout Standard
17650 is translated by the compiler into a local label, so the locality of labels
17651 within the function is not broken.
17668 0003$: ;label (can be referenced by inline assembler only)
17675 \begin_inset LatexCommand \index{\_endasm}
17680 \begin_inset LatexCommand \index{\_\_endasm}
17690 /* some more c code */
17695 \begin_layout Standard
17696 In other words inline assembly code can access labels defined in inline
17697 assembly within the scope of the function.
17698 The same goes the other way, i.e.
17699 labels defines in inline assembly can not be accessed by C statements.
17702 \begin_layout Section
17703 Interfacing with Assembler Code
17704 \begin_inset LatexCommand \index{Assembler routines}
17711 \begin_layout Subsection
17712 Global Registers used for Parameter Passing
17713 \begin_inset LatexCommand \index{Parameter passing}
17720 \begin_layout Standard
17721 The compiler always uses the global registers
17724 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17729 \begin_inset LatexCommand \index{DPTR}
17734 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
17743 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
17749 to pass the first (non-bit) parameter to a function, and also to pass the
17751 \begin_inset LatexCommand \index{return value}
17755 of function; according to the following scheme: one byte return value in
17760 , two byte value in
17769 three byte values (generic pointers) in
17781 , and four byte values in
17799 \begin_inset LatexCommand \index{generic pointer}
17803 contain type of accessed memory in
17824 \begin_inset Note Note
17827 \begin_layout Standard
17828 This might not be the case of certain memory models (medium???)
17836 \begin_layout Standard
17837 The second parameter onwards is either allocated on the stack (for reentrant
17842 \begin_layout Standard
17851 -stack-auto is used) or in data/xdata memory (depending on the memory model).
17854 \begin_layout Standard
17855 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
17856 space for reentrant functions or allocated directly in bit memory otherwise.
17859 \begin_layout Standard
17860 Functions (with two or more parameters or bit parameters) that are called
17861 through function pointers
17862 \begin_inset LatexCommand \index{function pointers}
17866 must therefor be reentrant so the compiler knows how to pass the parameters.
17869 \begin_layout Subsection
17873 \begin_layout Standard
17874 Unless the called function is declared as
17879 \begin_inset LatexCommand \index{naked}
17887 \begin_layout Standard
17897 \begin_inset LatexCommand \index{-\/-callee-saves}
17905 \begin_layout Standard
17914 -all-callee-saves command line option or the corresponding callee_saves
17915 pragma are used, the caller will save the registers (
17919 ) around the call, so the called function can destroy they content freely.
17922 \begin_layout Standard
17923 If the called function is not declared as
17927 , the caller will swap register banks around the call, if caller and callee
17928 use different register banks (having them defined by the
17936 \begin_layout Standard
17937 The called function can also use
17953 observing that they are used for parameter/return value passing.
17956 \begin_layout Subsection
17957 Assembler Routine (non-reentrant)
17960 \begin_layout Standard
17961 In the following example
17962 \begin_inset LatexCommand \index{reentrant}
17967 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
17971 the function c_func calls an assembler routine asm_func, which takes two
17973 \begin_inset LatexCommand \index{function parameter}
17980 \begin_layout Verse
17983 extern int asm_func(unsigned char, unsigned char);
17987 int c_func (unsigned char
17988 i, unsigned char j)
17996 return asm_func(i,j);
18010 return c_func(10,9);
18015 \begin_layout Standard
18016 The corresponding assembler function is:
18019 \begin_layout Verse
18022 .globl _asm_func_PARM_2
18124 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18141 \begin_layout Standard
18142 The parameter naming convention is _<function_name>_PARM_<n>, where n is
18143 the parameter number starting from 1, and counting from the left.
18144 The first parameter is passed in
18160 according to the description above.
18161 The variable name for the second parameter will be _<function_name>_PARM_2.
18166 ble the assembler routine with the following command:
18173 asx8051 -losg asmfunc.asm
18180 Then compile and link the assembler routine to the C source file with the
18188 sdcc cfunc.c asmfunc.rel
18191 \begin_layout Subsection
18192 Assembler Routine (reentrant)
18195 \begin_layout Standard
18197 \begin_inset LatexCommand \index{reentrant}
18202 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18206 the second parameter
18207 \begin_inset LatexCommand \index{function parameter}
18211 onwards will be passed on the stack, the parameters are pushed from right
18213 before the call the second leftmost parameter will be on the top of the
18214 stack (the leftmost parameter is passed in registers).
18215 Here is an example:
18218 \begin_layout Verse
18221 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18226 c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
18235 return asm_func(i,j,k);
18249 return c_func(10,9,8);
18254 \begin_layout Standard
18255 The corresponding (unoptimized) assembler routine is:
18258 \begin_layout Verse
18278 _bp,sp\InsetSpace ~
18284 ;stack contains: _bp, return
18285 address, second parameter, third parameter
18309 a,#0xfd\InsetSpace ~
18315 pointer to the second parameter
18339 a,#0xfc\InsetSpace ~
18345 to the rightmost parameter
18386 result (= sum of all three parameters)
18401 ;return value goes into dptr
18435 \begin_layout Standard
18436 The compiling and linking procedure remains the same, however note the extra
18437 entry & exit linkage required for the assembler code, _bp is the stack
18438 frame pointer and is used to compute the offset into the stack for parameters
18439 and local variables.
18440 \begin_inset VSpace bigskip
18446 \begin_layout Section
18448 \begin_inset LatexCommand \index{int (16 bit)}
18453 \begin_inset LatexCommand \index{long (32 bit)}
18460 \begin_layout Standard
18461 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18462 multiplication and modulus operations are implemented by support routines.
18463 These support routines are all developed in ANSI-C to facilitate porting
18464 to other MCUs, although some model specific assembler optimizations are
18466 The following files contain the described routines, all of them can be
18467 found in <installdir>/share/sdcc/lib.
18472 \begin_layout Standard
18474 \begin_inset Tabular
18475 <lyxtabular version="3" rows="11" columns="2">
18477 <column alignment="left" valignment="top" leftline="true" width="0">
18478 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18479 <row topline="true" bottomline="true">
18480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18483 \begin_layout Standard
18491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18494 \begin_layout Standard
18503 <row topline="true">
18504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18507 \begin_layout Standard
18513 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18516 \begin_layout Standard
18517 16 bit multiplication
18523 <row topline="true">
18524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18527 \begin_layout Standard
18533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18536 \begin_layout Standard
18537 signed 16 bit division (calls _divuint)
18543 <row topline="true">
18544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18547 \begin_layout Standard
18553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18556 \begin_layout Standard
18557 unsigned 16 bit division
18563 <row topline="true">
18564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18567 \begin_layout Standard
18573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18576 \begin_layout Standard
18577 signed 16 bit modulus (calls _moduint)
18583 <row topline="true">
18584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18587 \begin_layout Standard
18593 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18596 \begin_layout Standard
18597 unsigned 16 bit modulus
18603 <row topline="true">
18604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18607 \begin_layout Standard
18613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18616 \begin_layout Standard
18617 32 bit multiplication
18623 <row topline="true">
18624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18627 \begin_layout Standard
18633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18636 \begin_layout Standard
18637 signed 32 division (calls _divulong)
18643 <row topline="true">
18644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18647 \begin_layout Standard
18653 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18656 \begin_layout Standard
18657 unsigned 32 division
18663 <row topline="true">
18664 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18667 \begin_layout Standard
18673 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18676 \begin_layout Standard
18677 signed 32 bit modulus (calls _modulong)
18683 <row topline="true" bottomline="true">
18684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18687 \begin_layout Standard
18693 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18696 \begin_layout Standard
18697 unsigned 32 bit modulus
18712 \begin_layout Standard
18713 Since they are compiled as
18718 \begin_inset LatexCommand \index{reentrant}
18723 \begin_inset LatexCommand \index{interrupt}
18727 service routines should not do any of the above operations.
18728 If this is unavoidable then the above routines will need to be compiled
18735 \begin_layout Standard
18745 \begin_inset LatexCommand \index{-\/-stack-auto}
18751 option, after which the source program will have to be compiled with
18757 \begin_layout Standard
18767 \begin_inset LatexCommand \index{-\/-int-long-reent}
18774 Notice that you don't have to call these routines directly.
18775 The compiler will use them automatically every time an integer operation
18779 \begin_layout Section
18780 Floating Point Support
18781 \begin_inset LatexCommand \index{Floating point support}
18788 \begin_layout Standard
18789 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
18790 The floating point support routines are derived from gcc's floatlib.c and
18791 consist of the following routines:
18796 \begin_layout Standard
18800 \begin_inset Tabular
18801 <lyxtabular version="3" rows="17" columns="2">
18803 <column alignment="left" valignment="top" leftline="true" width="0">
18804 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18805 <row topline="true" bottomline="true">
18806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18809 \begin_layout Standard
18824 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18827 \begin_layout Standard
18834 <row topline="true">
18835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18838 \begin_layout Standard
18853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18856 \begin_layout Standard
18866 add floating point numbers
18872 <row topline="true">
18873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18876 \begin_layout Standard
18891 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18894 \begin_layout Standard
18904 subtract floating point numbers
18910 <row topline="true">
18911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18914 \begin_layout Standard
18929 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18932 \begin_layout Standard
18942 divide floating point numbers
18948 <row topline="true">
18949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18952 \begin_layout Standard
18967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18970 \begin_layout Standard
18980 multiply floating point numbers
18986 <row topline="true">
18987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18990 \begin_layout Standard
19005 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19008 \begin_layout Standard
19018 convert floating point to unsigned char
19024 <row topline="true">
19025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19028 \begin_layout Standard
19043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19046 \begin_layout Standard
19056 convert floating point to signed char
19062 <row topline="true">
19063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19066 \begin_layout Standard
19081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19084 \begin_layout Standard
19094 convert floating point to unsigned int
19100 <row topline="true">
19101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19104 \begin_layout Standard
19119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19122 \begin_layout Standard
19132 convert floating point to signed int
19138 <row topline="true">
19139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19142 \begin_layout Standard
19165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19168 \begin_layout Standard
19178 convert floating point to unsigned long
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 convert floating point to signed long
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 unsigned char to floating point
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 char to floating point number
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 unsigned int to floating point
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 int to floating point numbers
19374 <row topline="true">
19375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19378 \begin_layout Standard
19393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19396 \begin_layout Standard
19406 convert unsigned long to floating point number
19412 <row topline="true" bottomline="true">
19413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19416 \begin_layout Standard
19431 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19434 \begin_layout Standard
19444 convert long to floating point number
19459 \begin_layout Standard
19460 These support routines are developed in ANSI-C so there is room for space
19461 and speed improvement
19465 \begin_layout Standard
19466 These floating point routines (
19470 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19477 Note if all these routines are used simultaneously the data space might
19479 For serious floating point usage the large model might be needed.
19480 Also notice that you don't have to call this routines directly.
19481 The compiler will use them automatically every time a floating point operation
19483 \begin_inset VSpace bigskip
19489 \begin_layout Section
19491 \begin_inset LatexCommand \index{Libraries}
19498 \begin_layout Standard
19501 <pending: this is messy and incomplete - a little more information is in
19502 sdcc/doc/libdoc.txt
19507 \begin_layout Subsection
19508 Compiler support routines (_gptrget, _mulint etc.)
19511 \begin_layout Subsection
19512 Stdclib functions (puts, printf, strcat etc.)
19515 \begin_layout Subsubsection
19519 \begin_layout Paragraph
19520 getchar(), putchar()
19523 \begin_layout Standard
19524 \begin_inset LatexCommand \index{<stdio.h>}
19528 As usual on embedded systems you have to provide your own
19531 \begin_inset LatexCommand \index{getchar()}
19540 \begin_inset LatexCommand \index{putchar()}
19547 SDCC does not know whether the system connects to a serial line with or
19548 without handshake, LCD, keyboard or other device.
19562 You'll find examples for serial routines f.e.
19563 in sdcc/device/lib.
19564 For the mcs51 this minimalistic polling
19568 routine might be a start:
19571 \begin_layout Verse
19574 void putchar (char c) {
19580 while (!TI)\InsetSpace ~
19583 /* assumes UART is initialized */
19611 \begin_layout Paragraph
19615 \begin_layout Standard
19619 \begin_inset LatexCommand \index{printf()}
19629 does not support float (except on ds390).
19630 To enable this recompile it with the option
19636 \begin_layout Standard
19646 \begin_inset LatexCommand \index{USE\_FLOATS}
19652 on the command line.
19659 \begin_layout Standard
19669 \begin_inset LatexCommand \index{-\/-model-large}
19675 for the mcs51 port, since this uses a lot of memory.
19678 \begin_layout Standard
19679 If you're short on code memory you might want to use
19682 \begin_inset LatexCommand \index{printf\_small()}
19697 For the mcs51 there additionally are assembly versions
19700 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
19706 (subset of printf using less than 270 bytes) and
19709 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
19718 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
19724 (floating-point aware version of printf_fast) which should fit the requirements
19725 of many embedded systems (printf_fast() can be customized by unsetting
19730 support long variables and field widths).
19731 Be sure to use only one of these printf options within a project.
19736 \begin_layout Standard
19737 Feature matrix of different
19744 \begin_layout Standard
19745 \begin_inset Tabular
19746 <lyxtabular version="3" rows="14" columns="7">
19747 <features islongtable="true">
19748 <column alignment="left" valignment="middle" leftline="true" width="14col%">
19749 <column alignment="center" valignment="top" leftline="true" width="0">
19750 <column alignment="center" valignment="top" leftline="true" width="12col%">
19751 <column alignment="center" valignment="top" leftline="true" width="10col%">
19752 <column alignment="center" valignment="top" leftline="true" width="0">
19753 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
19754 <column alignment="center" valignment="top" rightline="true" width="0">
19755 <row topline="true" bottomline="true" endhead="true">
19756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19759 \begin_layout Standard
19768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19771 \begin_layout Standard
19773 \begin_inset LatexCommand \index{printf}
19782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19785 \begin_layout Standard
19793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19796 \begin_layout Standard
19802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19805 \begin_layout Standard
19811 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19814 \begin_layout Standard
19820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19823 \begin_layout Standard
19830 <row topline="true" endhead="true">
19831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19834 \begin_layout Standard
19840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19843 \begin_layout Standard
19851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19854 \begin_layout Standard
19862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19865 \begin_layout Standard
19873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19876 \begin_layout Standard
19884 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19887 \begin_layout Standard
19895 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19898 \begin_layout Standard
19907 <row topline="true" endhead="true">
19908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19911 \begin_layout Standard
19912 \begin_inset Quotes sld
19916 \begin_inset Quotes srd
19922 \begin_layout Standard
19928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19931 \begin_layout Standard
19937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19940 \begin_layout Standard
19946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19949 \begin_layout Standard
19955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19958 \begin_layout Standard
19964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19967 \begin_layout Standard
19973 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19976 \begin_layout Standard
19983 <row topline="true" endhead="true">
19984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19987 \begin_layout Standard
19991 \begin_layout Standard
19997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20000 \begin_layout Standard
20006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20009 \begin_layout Standard
20015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20018 \begin_layout Standard
20019 0.45k / 0.47k (+ _ltoa)
20024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20027 \begin_layout Standard
20033 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20036 \begin_layout Standard
20042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20045 \begin_layout Standard
20052 <row topline="true">
20053 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20056 \begin_layout Standard
20062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20065 \begin_layout Standard
20075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20078 \begin_layout Standard
20125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20128 \begin_layout Standard
20167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20170 \begin_layout Standard
20176 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20179 \begin_layout Standard
20185 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20188 \begin_layout Standard
20195 <row topline="true">
20196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20199 \begin_layout Standard
20200 long (32 bit) support
20205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20208 \begin_layout Standard
20214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20217 \begin_layout Standard
20223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20226 \begin_layout Standard
20232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20235 \begin_layout Standard
20241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20244 \begin_layout Standard
20259 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20262 \begin_layout Standard
20269 <row topline="true">
20270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20273 \begin_layout Standard
20274 byte arguments on stack
20279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20282 \begin_layout Standard
20288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20291 \begin_layout Standard
20297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20300 \begin_layout Standard
20306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20309 \begin_layout Standard
20315 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20318 \begin_layout Standard
20324 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20327 \begin_layout Standard
20334 <row topline="true">
20335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20338 \begin_layout Standard
20340 \begin_inset LatexCommand \index{Floating point support}
20349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20352 \begin_layout Standard
20358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20361 \begin_layout Standard
20367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20370 \begin_layout Standard
20376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20379 \begin_layout Standard
20385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20388 \begin_layout Standard
20393 \begin_layout Standard
20394 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20407 \begin_layout Standard
20414 <row topline="true">
20415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20418 \begin_layout Standard
20419 float formats %e %g
20424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20427 \begin_layout Standard
20433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20436 \begin_layout Standard
20442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20445 \begin_layout Standard
20451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20454 \begin_layout Standard
20460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20463 \begin_layout Standard
20469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20472 \begin_layout Standard
20479 <row topline="true" bottomline="true">
20480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20483 \begin_layout Standard
20489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20492 \begin_layout Standard
20498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20501 \begin_layout Standard
20507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20510 \begin_layout Standard
20516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20519 \begin_layout Standard
20525 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20528 \begin_layout Standard
20534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20537 \begin_layout Standard
20544 <row bottomline="true">
20545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20548 \begin_layout Standard
20553 \begin_layout Standard
20554 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20558 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20566 \begin_layout Standard
20572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20575 \begin_layout Standard
20581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20584 \begin_layout Standard
20590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20593 \begin_layout Standard
20599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20602 \begin_layout Standard
20608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20611 \begin_layout Standard
20617 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20620 \begin_layout Standard
20627 <row bottomline="true">
20628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20631 \begin_layout Standard
20636 \begin_layout Standard
20637 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
20646 \begin_layout Standard
20652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20655 \begin_layout Standard
20661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20664 \begin_layout Standard
20670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20673 \begin_layout Standard
20679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20682 \begin_layout Standard
20688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20691 \begin_layout Standard
20697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20700 \begin_layout Standard
20705 \begin_layout Standard
20706 printf_tiny integer speed is data dependent, worst case is 0.33 ms
20717 <row bottomline="true">
20718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20721 \begin_layout Standard
20726 \begin_layout Standard
20727 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
20736 \begin_layout Standard
20742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20745 \begin_layout Standard
20751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20754 \begin_layout Standard
20760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20763 \begin_layout Standard
20769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20772 \begin_layout Standard
20778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20781 \begin_layout Standard
20787 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20790 \begin_layout Standard
20797 <row bottomline="true">
20798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20801 \begin_layout Standard
20806 \begin_layout Standard
20807 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
20816 \begin_layout Standard
20822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20825 \begin_layout Standard
20831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20834 \begin_layout Standard
20840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20843 \begin_layout Standard
20849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20852 \begin_layout Standard
20858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20861 \begin_layout Standard
20867 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20870 \begin_layout Standard
20884 \begin_layout Subsubsection
20886 \begin_inset LatexCommand \index{malloc.h}
20893 \begin_layout Standard
20894 As of SDCC 2.6.2 you no longer need to call an initialization routine before
20895 using dynamic memory allocation
20896 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
20901 \begin_inset LatexCommand \index{heap (malloc)}
20905 space of 1024 bytes is provided for malloc to allocate memory from.
20906 If you need a different heap size you need to recompile _heap.c with the
20907 required size defined in HEAP_SIZE.
20908 It is recommended to make a copy of this file into your project directory
20909 and compile it there with:
20912 \begin_layout Verse
20915 sdcc -c _heap.c -D HEAD_SIZE=2048
20918 \begin_layout Standard
20919 And then link it with:
20922 \begin_layout Verse
20925 sdcc main.rel _heap.rel
20928 \begin_layout Subsection
20929 Math functions (sinf, powf, sqrtf etc.)
20932 \begin_layout Subsubsection
20936 \begin_layout Standard
20937 See definitions in file <math.h>.
20940 \begin_layout Subsection
20944 \begin_layout Standard
20946 \begin_inset LatexCommand \index{Libraries}
20950 included in SDCC should have a license at least as liberal as the GNU Lesser
20951 General Public License
20952 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
20963 \begin_layout Standard
20964 \begin_inset Note Note
20967 \begin_layout Standard
20968 license statements for the libraries are missing.
20969 sdcc/device/lib/ser_ir.c
20972 \begin_layout Standard
20974 come with a GPL (as opposed to LGPL) License - this will not be liberal
20975 enough for many embedded programmers.
20983 \begin_layout Standard
20984 If you have ported some library or want to share experience about some code
20986 falls into any of these categories Busses (I
20987 \begin_inset Formula $^{\textrm{2}}$
20990 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
20991 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
20992 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
20993 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
20998 would certainly like to hear about it.
21001 \begin_layout Standard
21002 Programmers coding for embedded systems are not especially famous for being
21003 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
21004 e these references are very valuable.
21005 Let's help to create a climate where information is shared.
21006 \begin_inset VSpace bigskip
21012 \begin_layout Section
21016 \begin_layout Subsection
21017 MCS51 Memory Models
21018 \begin_inset LatexCommand \index{Memory model}
21023 \begin_inset LatexCommand \index{MCS51 memory model}
21030 \begin_layout Subsubsection
21031 Small, Medium and Large
21034 \begin_layout Standard
21035 SDCC allows three memory models for MCS51 code,
21044 Modules compiled with different memory models should
21048 be combined together or the results would be unpredictable.
21049 The library routines supplied with the compiler are compiled as small,
21051 The compiled library modules are contained in separate directories as small,
21052 medium and large so that you can link to the appropriate set.
21055 \begin_layout Standard
21056 When the medium or large model is used all variables declared without a
21057 storage class will be allocated into the external ram, this includes all
21058 parameters and local variables (for non-reentrant
21059 \begin_inset LatexCommand \index{reentrant}
21064 When the small model is used variables without storage class are allocated
21065 in the internal ram.
21068 \begin_layout Standard
21069 Judicious usage of the processor specific storage classes
21070 \begin_inset LatexCommand \index{Storage class}
21074 and the 'reentrant' function type will yield much more efficient code,
21075 than using the large model.
21076 Several optimizations are disabled when the program is compiled using the
21077 large model, it is therefore recommended that the small model be used unless
21078 absolutely required.
21081 \begin_layout Subsubsection
21083 \begin_inset LatexCommand \label{sub:External-Stack}
21088 \begin_inset LatexCommand \index{stack}
21093 \begin_inset LatexCommand \index{External stack (mcs51)}
21100 \begin_layout Standard
21101 The external stack (-
21105 \begin_layout Standard
21115 \begin_inset LatexCommand \index{-\/-xstack}
21119 ) is located in pdata
21120 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
21124 memory (usually at the start of the external ram segment) and uses all
21125 unused space in pdata (max.
21131 \begin_layout Standard
21140 -xstack option is used to compile the program, the parameters and local
21142 \begin_inset LatexCommand \index{local variables}
21146 of all reentrant functions are allocated in this area.
21147 This option is provided for programs with large stack space requirements.
21148 When used with the -
21152 \begin_layout Standard
21162 \begin_inset LatexCommand \index{-\/-stack-auto}
21166 option, all parameters and local variables are allocated on the external
21167 stack (note: support libraries will need to be recompiled with the same
21169 There is a predefined target in the library makefile).
21172 \begin_layout Standard
21173 The compiler outputs the higher order address byte of the external ram segment
21175 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21180 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21184 ), therefore when using the External Stack option, this port
21188 be used by the application program.
21191 \begin_layout Subsection
21193 \begin_inset LatexCommand \index{Memory model}
21198 \begin_inset LatexCommand \index{DS390 memory model}
21205 \begin_layout Standard
21206 The only model supported is Flat 24
21207 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21212 This generates code for the 24 bit contiguous addressing mode of the Dallas
21214 In this mode, up to four meg of external RAM or code space can be directly
21216 See the data sheets at www.dalsemi.com for further information on this part.
21221 that the compiler does not generate any code to place the processor into
21222 24 bitmode (although
21226 in the ds390 libraries will do that for you).
21232 \begin_inset LatexCommand \index{Tinibios (DS390)}
21236 , the boot loader or similar code must ensure that the processor is in 24
21237 bit contiguous addressing mode before calling the SDCC startup code.
21248 \begin_layout Standard
21259 option, variables will by default be placed into the XDATA segment.
21264 Segments may be placed anywhere in the 4 meg address space using the usual
21269 \begin_layout Standard
21279 Note that if any segments are located above 64K, the -r flag must be passed
21280 to the linker to generate the proper segment relocations, and the Intel
21281 HEX output format must be used.
21282 The -r flag can be passed to the linker by using the option
21286 on the SDCC command line.
21287 However, currently the linker can not handle code segments > 64k.
21290 \begin_layout Section
21292 \begin_inset LatexCommand \label{sec:Pragmas}
21297 \begin_inset LatexCommand \index{Pragmas}
21304 \begin_layout Standard
21305 Pragmas are used to turn on and/or off certain compiler options.
21306 Some of them are closely related to corresponding command-line options
21308 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21314 Pragmas should be placed before and/or after a function, placing pragmas
21315 inside a function body could have unpredictable results.
21320 following #pragma directives:
21323 \begin_layout Itemize
21329 \begin_inset LatexCommand \index{\#pragma save}
21333 - this will save most current options to the save/restore stack.
21334 See #pragma\InsetSpace ~
21338 \begin_layout Itemize
21344 \begin_inset LatexCommand \index{\#pragma restore}
21348 - will restore saved options from the last save.
21349 saves & restores can be nested.
21350 SDCC uses a save/restore stack: save pushes current options to the stack,
21351 restore pulls current options from the stack.
21352 See #pragma\InsetSpace ~
21358 \begin_layout Itemize
21364 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21369 \begin_inset LatexCommand \index{function prologue}
21373 function1[,function2[,function3...]]
21374 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21378 - The compiler by default uses a caller saves convention for register saving
21379 across function calls, however this can cause unnecessary register pushing
21381 \begin_inset LatexCommand \index{push/pop}
21385 when calling small functions from larger functions.
21386 This option can be used to switch off the register saving convention for
21387 the function names specified.
21388 The compiler will not save registers when calling these functions, extra
21389 code need to be manually inserted at the entry and exit for these functions
21390 to save and restore the registers used by these functions, this can SUBSTANTIAL
21391 LY reduce code and improve run time performance of the generated code.
21392 In the future the compiler (with inter procedural analysis) may be able
21393 to determine the appropriate scheme to use for each function call.
21398 \begin_layout Standard
21407 -callee-saves command line option is used (see page
21408 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21412 ), the function names specified in #pragma\InsetSpace ~
21414 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21418 is appended to the list of functions specified in the command line.
21421 \begin_layout Itemize
21427 \begin_inset LatexCommand \index{\#pragma exclude}
21431 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21432 of pairs of push/pop
21433 \begin_inset LatexCommand \index{push/pop}
21442 \begin_inset LatexCommand \index{interrupt}
21455 The directive should be placed immediately before the ISR function definition
21456 and it affects ALL ISR functions following it.
21457 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21458 exclude\InsetSpace ~
21460 \begin_inset LatexCommand \index{\#pragma exclude}
21465 See also the related keyword _naked
21466 \begin_inset LatexCommand \index{\_naked}
21471 \begin_inset LatexCommand \index{\_\_naked}
21478 \begin_layout Itemize
21484 \begin_inset LatexCommand \index{pedantic}
21489 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21494 \begin_inset LatexCommand \label{ite:less_pedantic}
21498 - the compiler will not warn you anymore for obvious mistakes, you're on
21500 See also the command line option -
21504 \begin_layout Standard
21514 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21521 More specifically, the following warnings will be disabled:
21523 comparison is always [true/false] due to limited range of data type
21527 overflow in implicit constant conversion
21529 (158); [the (in)famous]
21531 conditional flow changed by optimizer: so said EVELYN the modified DOG
21535 function '[function name]' must return value
21540 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21541 level) are disabled, too, namely:
21544 \begin_inset Note Note
21547 \begin_layout Standard
21548 dunno what comes here - this warning appears to be unused altogether
21557 [left/right] shifting more than size of object changed to zero
21565 integer overflow in expression
21569 unmatched #pragma save and #pragma restore
21573 comparison of 'signed char' with 'unsigned char' requires promotion to int
21577 ISO C90 does not support flexible array members
21581 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21585 \begin_inset Note Note
21588 \begin_layout Standard
21589 appears to be always blank - what was supposed to be here?
21598 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21599 complexity [number]
21604 \begin_layout Itemize
21610 \begin_inset LatexCommand \index{\#pragma disable\_warning}
21614 - the compiler will not warn you anymore about warning number <nnnn>.
21617 \begin_layout Itemize
21623 \begin_inset LatexCommand \index{\#pragma nogcse}
21627 - will stop global common subexpression elimination.
21630 \begin_layout Itemize
21636 \begin_inset LatexCommand \index{\#pragma noinduction}
21640 - will stop loop induction optimizations.
21643 \begin_layout Itemize
21649 \begin_inset LatexCommand \index{\#pragma noinvariant}
21653 - will not do loop invariant optimizations.
21654 For more details see Loop Invariants in section
21655 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
21662 \begin_layout Itemize
21668 \begin_inset LatexCommand \index{\#pragma noiv}
21672 - Do not generate interrupt
21673 \begin_inset LatexCommand \index{interrupt}
21678 \begin_inset LatexCommand \index{interrupt vector table}
21682 entries for all ISR functions defined after the pragma.
21683 This is useful in cases where the interrupt vector table must be defined
21684 manually, or when there is a secondary, manually defined interrupt vector
21686 for the autovector feature of the Cypress EZ-USB FX2).
21687 More elegantly this can be achieved by obmitting the optional interrupt
21688 number after the interrupt keyword, see section
21689 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
21697 \begin_layout Itemize
21703 \begin_inset LatexCommand \index{\#pragma nojtbound}
21707 - will not generate code for boundary value checking, when switch statements
21708 are turned into jump-tables (dangerous).
21709 For more details see section
21710 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
21717 \begin_layout Itemize
21723 \begin_inset LatexCommand \index{\#pragma noloopreverse}
21727 - Will not do loop reversal optimization
21730 \begin_layout Itemize
21736 \begin_inset LatexCommand \index{\#pragma nooverlay}
21740 - the compiler will not overlay the parameters and local variables of a
21744 \begin_layout Itemize
21750 \begin_inset LatexCommand \index{\#pragma stackauto}
21758 \begin_layout Standard
21768 \begin_inset LatexCommand \index{-\/-stack-auto}
21773 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
21777 Parameters and Local Variables.
21780 \begin_layout Itemize
21786 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
21790 - The compiler will optimize code generation towards fast code, possibly
21791 at the expense of code size.
21792 Currently this has little effect.
21795 \begin_layout Itemize
21801 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
21805 - The compiler will optimize code generation towards compact code, possibly
21806 at the expense of code speed.
21807 Currently this has little effect.
21810 \begin_layout Itemize
21816 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
21820 - The compiler will attempt to generate code that is both compact and fast,
21821 as long as meeting one goal is not a detriment to the other (this is the
21826 \begin_layout Itemize
21832 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
21836 - Generally follow the C89 standard, but allow SDCC features that conflict
21837 with the standard (default).
21840 \begin_layout Itemize
21846 \begin_inset LatexCommand \index{\#pragma std\_c89}
21850 - Follow the C89 standard and disable SDCC features that conflict with the
21854 \begin_layout Itemize
21860 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
21864 - Generally follow the C99 standard, but allow SDCC features that conflict
21865 with the standard (incomplete support).
21868 \begin_layout Itemize
21874 \begin_inset LatexCommand \index{\#pragma std\_c99}
21878 - Follow the C99 standard and disable SDCC features that conflict with the
21879 standard (incomplete support).
21882 \begin_layout Itemize
21888 \begin_inset LatexCommand \index{\#pragma codeseg}
21892 - Use this name (max.
21893 8 characters) for the code segment.
21898 \begin_layout Standard
21910 \begin_layout Itemize
21916 \begin_inset LatexCommand \index{\#pragma constseg}
21920 - Use this name (max.
21921 8 characters) for the const segment.
21926 \begin_layout Standard
21938 \begin_layout Standard
21939 The preprocessor SDCPP
21940 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
21944 supports the following #pragma directives:
21947 \begin_layout Itemize
21950 pedantic_parse_number
21953 \begin_inset LatexCommand \index{pedantic}
21958 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21963 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
21967 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
21968 properly and the macro LO_B(3) gets expanded.
21974 \begin_layout Standard
21983 -pedantic-parse-number command line option
21984 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
21991 Below is an example on how to use this pragma.
21994 Note: this functionality is not in conformance with standard!
21997 \begin_layout Verse
22000 #pragma pedantic_parse_number +
22001 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22009 #define LO_B(x) ((x) & 0xff)
22013 unsigned char foo(void)
22020 unsigned char c=0xfe-LO_B(3)
22035 \begin_layout Itemize
22041 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22045 (+ | -) - switch _asm _endasm block preprocessing on / off.
22047 You use this prama to define multilines of assembly code.
22048 This will prevent the preprocessor from changing the formating required
22050 Below is an example on how to use this pragma.
22053 \begin_layout Verse
22056 #pragma preproc_asm -
22057 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22063 #define MYDELAY _asm
22068 nop ;my assembly comment...
22082 #pragma preproc_asm
22113 \begin_layout Itemize
22119 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22123 (+ | -) - Allow "naked" hash in macro definition, for example:
22127 #define DIR_LO(x) #(x & 0xff)
22132 Below is an example on how to use this pragma.
22135 \begin_layout Verse
22138 #pragma preproc_asm +
22140 #pragma sdcc_hash +
22141 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22156 mov R6_B3, #(x & 0xff)
22163 mov R7_B3, #((x >> 8) & 0xff)
22187 \begin_layout Standard
22188 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22189 ons which might cause the compiler to generate extra stack and/or data space
22190 to store compiler generated temporary variables.
22191 This usually happens in large functions.
22192 Pragma directives should be used as shown in the following example, they
22193 are used to control options and optimizations for a given function.
22197 \begin_layout Verse
22201 \begin_inset LatexCommand \index{\#pragma save}
22212 /* save the current settings */
22215 \begin_inset LatexCommand \index{\#pragma nogcse}
22224 /* turnoff global subexpression elimination */
22226 #pragma noinduction
22227 \begin_inset LatexCommand \index{\#pragma noinduction}
22231 /* turn off induction optimizations */
22254 \begin_inset LatexCommand \index{\#pragma restore}
22258 /* turn the optimizations back on */
22261 \begin_layout Standard
22262 The compiler will generate a warning message when extra space is allocated.
22263 It is strongly recommended that the save and restore pragmas be used when
22264 changing options for a function.
22273 \begin_layout Section
22274 Defines Created by the Compiler
22277 \begin_layout Standard
22278 The compiler creates the following #defines
22279 \begin_inset LatexCommand \index{\#defines}
22284 \begin_inset LatexCommand \index{Defines created by the compiler}
22293 \begin_layout Standard
22294 \begin_inset Tabular
22295 <lyxtabular version="3" rows="11" columns="2">
22297 <column alignment="left" valignment="top" leftline="true" width="3in">
22298 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22299 <row topline="true" bottomline="true">
22300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22303 \begin_layout Standard
22311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22314 \begin_layout Standard
22323 <row topline="true">
22324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22327 \begin_layout Standard
22329 \begin_inset LatexCommand \index{SDCC}
22338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22341 \begin_layout Standard
22343 Since version 2.5.6 the version number as an int (ex.
22350 <row topline="true">
22351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22354 \begin_layout Standard
22356 \begin_inset LatexCommand \index{SDCC\_mcs51}
22361 \begin_inset LatexCommand \index{SDCC\_ds390}
22366 \begin_inset LatexCommand \index{SDCC\_z80}
22375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22378 \begin_layout Standard
22379 depending on the model used (e.g.: -mds390)
22385 <row topline="true">
22386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22389 \begin_layout Standard
22391 \begin_inset LatexCommand \index{\_\_mcs51}
22396 \begin_inset LatexCommand \index{\_\_ds390}
22401 \begin_inset LatexCommand \index{\_\_hc08}
22406 \begin_inset LatexCommand \index{\_\_z80}
22415 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22418 \begin_layout Standard
22419 depending on the model used (e.g.
22426 <row topline="true">
22427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22430 \begin_layout Standard
22432 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22444 \begin_layout Standard
22451 \begin_layout Standard
22468 <row topline="true">
22469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22472 \begin_layout Standard
22474 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22486 \begin_layout Standard
22493 \begin_layout Standard
22510 <row topline="true">
22511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22514 \begin_layout Standard
22516 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22525 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22528 \begin_layout Standard
22535 \begin_layout Standard
22552 <row topline="true">
22553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22556 \begin_layout Standard
22558 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22567 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22570 \begin_layout Standard
22577 \begin_layout Standard
22594 <row topline="true">
22595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22598 \begin_layout Standard
22600 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
22609 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22612 \begin_layout Standard
22619 \begin_layout Standard
22636 <row topline="true">
22637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22640 \begin_layout Standard
22642 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
22651 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22654 \begin_layout Standard
22665 <row topline="true" bottomline="true">
22666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22669 \begin_layout Standard
22671 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
22680 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22683 \begin_layout Standard
22701 \begin_layout Chapter
22702 Notes on supported Processors
22705 \begin_layout Section
22707 \begin_inset LatexCommand \label{sub:MCS51-variants}
22712 \begin_inset LatexCommand \index{MCS51 variants}
22719 \begin_layout Standard
22720 MCS51 processors are available from many vendors and come in many different
22722 While they might differ considerably in respect to Special Function Registers
22723 the core MCS51 is usually not modified or is kept compatible.
22727 \begin_layout Subsection
22728 pdata access by SFR
22731 \begin_layout Standard
22732 With the upcome of devices with internal xdata and flash memory devices
22734 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
22738 as dedicated I/O port is becoming more popular.
22739 Switching the high byte for pdata
22740 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
22744 access which was formerly done by port P2 is then achieved by a Special
22746 \begin_inset LatexCommand \index{sfr}
22751 In well-established MCS51 tradition the address of this
22755 is where the chip designers decided to put it.
22756 Needless to say that they didn't agree on a common name either.
22757 So that the startup code can correctly initialize xdata variables, you
22758 should define an sfr with the name _XPAGE
22761 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
22767 at the appropriate location if the default, port P2, is not used for this.
22771 \begin_layout Verse
22774 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
22778 \begin_layout Verse
22781 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
22786 \begin_layout Verse
22789 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
22793 \begin_layout Verse
22796 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22800 \begin_layout Verse
22803 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22807 \begin_layout Standard
22808 For more exotic implementations further customizations may be needed.
22810 \begin_inset LatexCommand \ref{sub:Startup-Code}
22814 for other possibilities.
22817 \begin_layout Subsection
22818 Other Features available by SFR
22821 \begin_layout Standard
22822 Some MCS51 variants offer features like Double DPTR
22823 \begin_inset LatexCommand \index{DPTR}
22827 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
22828 These are currently not used for the MCS51 port.
22829 If you absolutely need them you can fall back to inline assembly or submit
22831 \begin_inset VSpace bigskip
22837 \begin_layout Section
22841 \begin_layout Standard
22843 \begin_inset LatexCommand \index{DS80C400}
22848 \begin_inset LatexCommand \index{DS400}
22852 microcontroller has a rich set of peripherals.
22853 In its built-in ROM library it includes functions to access some of the
22854 features, among them is a TCP stack with IP4 and IP6 support.
22855 Library headers (currently in beta status) and other files are provided
22859 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
22865 \begin_inset VSpace bigskip
22871 \begin_layout Section
22872 The Z80 and gbz80 port
22875 \begin_layout Standard
22876 SDCC can target both the Zilog Z80
22877 \begin_inset LatexCommand \index{Z80}
22881 and the Nintendo Gameboy's Z80-like gbz80
22882 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
22887 The Z80 port is passed through the same
22890 \begin_inset LatexCommand \index{Regression test}
22897 \begin_inset LatexCommand \ref{sec:Quality-control}
22901 ) as the MCS51 and DS390 ports, so floating point support, support for long
22902 variables and bitfield support is fine.
22903 See mailing lists and forums about interrupt routines.
22906 \begin_layout Standard
22907 As always, the code is the authoritative reference - see z80/ralloc.c and
22910 \begin_inset LatexCommand \index{Z80!stack}
22914 frame is similar to that generated by the IAR Z80 compiler.
22915 IX is used as the base pointer, HL and IY are used as a temporary registers,
22916 and BC and DE are available for holding variables.
22918 \begin_inset LatexCommand \index{Z80!return value}
22922 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
22924 The gbz80 port use the same set of registers for the return values, but
22925 in a different order of significance: E (one byte), DE (two bytes), or
22927 \begin_inset VSpace bigskip
22933 \begin_layout Section
22937 \begin_layout Standard
22938 The port to the Freescale/Motorola HC08
22939 \begin_inset LatexCommand \index{HC08}
22943 family has been added in October 2003, and is still undergoing some basic
22945 The code generator is complete, but the register allocation is still quite
22947 Some of the SDCC's standard C library functions have embedded non-HC08
22948 inline assembly and so are not yet usable.
22951 \begin_layout Standard
22952 The HC08 port passes the regression test suite (see section
22953 \begin_inset LatexCommand \ref{sec:Quality-control}
22958 \begin_inset VSpace bigskip
22966 \begin_layout Section
22968 \begin_inset LatexCommand \index{PIC14}
22975 \begin_layout Standard
22976 The PIC14 port adds support for Microchip
22977 \begin_inset LatexCommand \index{Microchip}
22982 \begin_inset Formula $^{\text{TM}}$
22986 \begin_inset LatexCommand \index{PIC14}
22991 \begin_inset Formula $^{\text{TM}}$
22994 MCUs with 14 bit wide instructions.
22995 This port is not yet mature and still lacks many features.
22996 However, it can work for simple code.
22999 \begin_layout Standard
23000 Currently supported devices include:
23003 \begin_layout Standard
23004 12F: 629, 635, 675, 683
23007 \begin_layout Standard
23011 \begin_layout Standard
23015 \begin_layout Standard
23016 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
23019 \begin_layout Standard
23020 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
23024 \begin_layout Standard
23028 \begin_layout Standard
23029 16F: 627, 627a, 628, 628a, 630, 636, 639, 648a, 676, 684, 685, 687, 688,
23033 \begin_layout Standard
23034 16F: 716, 72, 73, 737, 74, 76, 767, 77, 777, 785
23037 \begin_layout Standard
23038 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
23042 \begin_layout Standard
23043 16F: 913, 914, 916, 917
23046 \begin_layout Standard
23047 An up-to-date list of currently supported devices can be obtained via
23049 sdcc -mpic14 -phelp foo.c
23051 (foo.c must exist...).
23054 \begin_layout Subsection
23056 \begin_inset LatexCommand \index{code page (pic14)}
23061 \begin_inset LatexCommand \index{Memory bank (pic14)}
23068 \begin_layout Standard
23069 The linker organizes allocation for the code page and RAM banks.
23070 It does not have intimate knowledge of the code flow.
23071 It will put all the code section of a single .asm file into a single code
23073 In order to make use of multiple code pages, separate asm files must be
23075 The compiler assigns all
23079 functions of a single .c file into the same code page.
23083 To get the best results,
23084 follow these guidelines:
23087 \begin_layout Enumerate
23088 Make local functions static, as non static functions require code page selection
23091 Due to the way sdcc handles functions, place called functions prior
23092 to calling functions in the file wherever possible: Otherwise sdcc will
23093 insert unneccessary pagesel directives around the call, believing that
23094 the called function is externally defined.
23097 \begin_layout Enumerate
23098 For devices that have multiple code pages it is more efficient to use the
23099 same number of files as pages: Use up to 4 separate .c files for the 16F877,
23100 but only 2 files for the 16F874.
23101 This way the linker can put the code for each file into different code
23102 pages and there will be less page selection overhead.
23105 \begin_layout Enumerate
23106 And as for any 8 bit micro (especially for PIC14 as they have a very simple
23107 instruction set), use `unsigned char' wherever possible instead of `int'.
23110 \begin_layout Subsection
23111 Adding New Devices to the Port
23114 \begin_layout Standard
23115 Adding support for a new 14
23119 \begin_layout Standard
23128 bit PIC MCU requires the following steps:
23131 \begin_layout Enumerate
23132 Create a new device description.
23134 Each device is described in two files: pic16f*.h
23136 These files primarily define SFRs, structs to access their bits, and symbolic
23137 configuration options.
23138 Both files can be generated from gputils' .inc files using the perl script
23141 support/scripts/inc2h.pl
23144 This file also contains further instructions on how to proceed.
23147 \begin_layout Enumerate
23148 Copy the .h file into SDCC's include path and either add the .c file to your
23149 project or copy it to
23151 device/lib/pic/libdev
23154 Afterwards, rebuild and install the libraries.
23157 \begin_layout Enumerate
23158 Edit pic14devices.txt in SDCC's include path (
23160 device/include/pic/
23162 in the source tree or
23164 /usr/local/share/sdcc/include/pic
23166 after installation).
23168 You need to add a device specification here to make
23169 the memory layout (code banks, RAM, aliased memory regions, ...) known to
23171 Probably you can copy and modify an existing entry.
23172 The file format is documented at the top of the file.
23175 \begin_layout Subsection
23179 \begin_layout Standard
23180 For the interrupt function, use the keyword `__interrupt'
23181 \begin_inset LatexCommand \index{PIC14!interrupt}
23185 with level number of 0 (PIC14 only has 1 interrupt so this number is only
23186 there to avoid a syntax error - it ought to be fixed).
23190 \begin_layout Verse
23193 void Intr(void) __interrupt 0
23199 T0IF = 0; /* Clear timer interrupt */
23204 \begin_layout Subsection
23205 Linking and Assembling
23208 \begin_layout Standard
23209 For assembling you can use either GPUTILS'
23210 \begin_inset LatexCommand \index{gputils (pic tools)}
23214 gpasm.exe or MPLAB's mpasmwin.exe.
23215 GPUTILS are available from
23216 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23221 For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
23222 If you use MPLAB and an interrupt function then the linker script file
23223 vectors section will need to be enlarged to link with mplink.
23234 \begin_layout Verse
23247 sdcc -V -mpic14 -p16f877 -c $<
23251 $(PRJ).hex: $(OBJS)
23261 gplink -m -s $(PRJ).lkr
23262 -o $(PRJ).hex $(OBJS) libsdcc.lib
23265 \begin_layout Standard
23273 \begin_layout Verse
23286 sdcc -S -V -mpic14 -p16f877 $<
23296 mpasmwin /q /o $*.asm
23300 $(PRJ).hex: $(OBJS)
23311 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
23314 \begin_layout Standard
23315 Please note that indentations within a
23319 have to be done with a tabulator character.
23322 \begin_layout Subsection
23323 Command-Line Options
23326 \begin_layout Standard
23327 Besides the switches common to all SDCC backends, the PIC14 port accepts
23328 the following options (for an updated list see sdcc -
23332 \begin_layout Standard
23344 \begin_layout Description
23349 \begin_layout Standard
23359 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
23363 emit debug info in assembly output
23366 \begin_layout Description
23371 \begin_layout Standard
23381 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
23385 disable (slightly faulty) optimization on pCode
23388 \begin_layout Description
23393 \begin_layout Standard
23403 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
23407 sets the lowest address of the argument passing stack (defaults to a suitably
23408 large shared databank to reduce BANKSEL overhead)
23411 \begin_layout Description
23416 \begin_layout Standard
23426 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
23430 sets the size if the argument passing stack (default: 16, minimum: 4)
23433 \begin_layout Subsection
23434 Environment Variables
23437 \begin_layout Standard
23438 The PIC14 port recognizes the following environment variables:
23441 \begin_layout Description
23442 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
23443 register (the ones called r0xNNNN) in a section of its own.
23444 By default (if this variable is unset), sdcc tries to cluster registers
23445 in sections in order to reduce the BANKSEL overhead when accessing them.
23448 \begin_layout Subsection
23452 \begin_layout Standard
23453 The PIC14 library currently only contains support routines required by the
23454 compiler to implement multiplication, division, and floating point support.
23455 No libc-like replacement is available at the moment, though many of the
23456 common sdcc library sources (in
23460 ) should also compile with the PIC14 port.
23463 \begin_layout Subsubsection
23464 error: missing definition for symbol ``__gptrget1''
23467 \begin_layout Standard
23468 The PIC14 port uses library routines to provide more complex operations
23469 like multiplication, division/modulus and (generic) pointer dereferencing.
23470 In order to add these routines to your project, you must link with PIC14's
23476 For single source file projects this is done automatically, more complex
23481 to the linker's arguments.
23482 Make sure you also add an include path for the library (using the -I switch
23486 \begin_layout Subsubsection
23487 Processor mismatch in file ``XXX''.
23490 \begin_layout Standard
23491 This warning can usually be ignored due to the very good compatibility amongst
23496 \begin_layout Standard
23506 \begin_inset LatexCommand \index{PIC14}
23513 \begin_layout Standard
23514 You might also consider recompiling the library for your specific device
23515 by changing the ARCH=p16f877 (default target) entry in
23517 device/lib/pic/Makefile.in
23521 device/lib/pic/Makefile
23523 to reflect your device.
23524 This might even improve performance for smaller devices as unneccesary
23525 BANKSELs might be removed.
23528 \begin_layout Subsection
23532 \begin_layout Subsubsection
23536 \begin_layout Standard
23537 Functions with variable argument lists (like printf) are not yet supported.
23538 Similarly, taking the argument of the first argument passed into a function
23539 does not work: It is currently passed in WREG and has no address...
23542 \begin_layout Subsubsection
23543 Regression tests fail
23546 \begin_layout Standard
23547 Though the small subset of regression tests in src/regression passes, SDCC
23548 regression test suite does not, indicating that there are still major bugs
23550 However, many smaller projects have successfully used SDCC in the past...
23553 \begin_layout Standard
23561 \begin_layout Section
23563 \begin_inset LatexCommand \index{PIC16}
23570 \begin_layout Standard
23571 The PIC16 port adds support for Microchip
23572 \begin_inset LatexCommand \index{Microchip}
23577 \begin_inset Formula $^{\text{TM}}$
23581 \begin_inset LatexCommand \index{PIC}
23586 \begin_inset Formula $^{\text{TM}}$
23589 MCUs with 16 bit wide instructions.
23590 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
23591 ; devices supported by the port include:
23594 \begin_layout Standard
23595 18F: 242, 248, 252, 258, 442, 448, 452, 458
23598 \begin_layout Standard
23602 \begin_layout Standard
23603 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 24j10, 2525, 2550, 25j10,
23607 \begin_layout Standard
23608 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 44j10, 4520, 4525, 4550,
23612 \begin_layout Standard
23613 18F: 6520, 6620, 6680, 6720
23616 \begin_layout Standard
23617 18F: 8520, 8620, 8680, 8720
23620 \begin_layout Subsection
23624 \begin_layout Standard
23625 PIC16 port supports the standard command line arguments as supposed, with
23626 the exception of certain cases that will be mentioned in the following
23630 \begin_layout Description
23635 \begin_layout Standard
23645 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
23653 \begin_layout Standard
23665 \begin_layout Description
23670 \begin_layout Standard
23679 -fommit-frame-pointer
23680 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
23684 Frame pointer will be omitted when the function uses no local variables.
23687 \begin_layout Subsection
23688 Port Specific Options
23689 \begin_inset LatexCommand \index{Options PIC16}
23696 \begin_layout Standard
23697 The port specific options appear after the global options in the sdcc -
23701 \begin_layout Standard
23713 \begin_layout Subsubsection
23714 Code Generation Options
23717 \begin_layout Standard
23718 These options influence the generated assembler code.
23721 \begin_layout Description
23726 \begin_layout Standard
23735 -pstack-model=[model] Used in conjuction with the command above.
23736 Defines the stack model to be used, valid stack models are:
23741 \labelwidthstring 00.00.0000
23746 Selects small stack model.
23747 8 bit stack and frame pointers.
23748 Supports 256 bytes stack size.
23752 \labelwidthstring 00.00.0000
23757 Selects large stack model.
23758 16 bit stack and frame pointers.
23759 Supports 65536 bytes stack size.
23763 \begin_layout Description
23768 \begin_layout Standard
23777 -pno-banksel Do not generate BANKSEL assembler directives.
23780 \begin_layout Description
23785 \begin_layout Standard
23794 -extended Enable extended instruction set/literal offset addressing mode.
23798 \begin_layout Subsubsection
23799 Optimization Options
23802 \begin_layout Description
23807 \begin_layout Standard
23816 -obanksel=n Set optimization level for inserting BANKSELs.
23823 \labelwidthstring 00.00.0000
23828 \labelwidthstring 00.00.0000
23829 1 checks previous used register and if it is the same then does not emit
23830 BANKSEL, accounts only for labels.
23834 \labelwidthstring 00.00.0000
23835 2 tries to check the location of (even different) symbols and removes BANKSELs
23836 if they are in the same bank.
23841 Important: There might be problems if the linker script has data sections
23842 across bank borders!
23846 \begin_layout Description
23851 \begin_layout Standard
23860 -denable-peeps Force the usage of peepholes.
23864 \begin_layout Description
23869 \begin_layout Standard
23878 -optimize-goto Try to use (conditional) BRA instead of GOTO.
23881 \begin_layout Description
23886 \begin_layout Standard
23895 -optimize-cmp Try to optimize some compares.
23898 \begin_layout Description
23903 \begin_layout Standard
23912 -optimize-df Analyze the dataflow of the generated code and improve it.
23915 \begin_layout Subsubsection
23919 \begin_layout Description
23924 \begin_layout Standard
23933 -asm= Sets the full path and name of an external assembler to call.
23936 \begin_layout Description
23941 \begin_layout Standard
23951 \begin_inset LatexCommand \index{PIC16!MPLAB}
23955 compatibility option.
23956 Currently only suppresses special gpasm directives.
23959 \begin_layout Subsubsection
23963 \begin_layout Description
23968 \begin_layout Standard
23977 -link= Sets the full path and name of an external linker to call.
23980 \begin_layout Description
23985 \begin_layout Standard
23994 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
23995 unitialized data variables with [kword].
23996 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
23999 \begin_layout Description
24004 \begin_layout Standard
24013 -ivt-loc=n Place the interrupt vector table at address
24018 Useful for bootloaders.
24021 \begin_layout Description
24026 \begin_layout Standard
24035 -nodefaultlibs Do not link default libraries when linking.
24038 \begin_layout Description
24043 \begin_layout Standard
24052 -use-crt= Use a custom run-time module instead of the defaults.
24055 \begin_layout Description
24060 \begin_layout Standard
24069 -no-crt Don't link the default run-time modules
24072 \begin_layout Subsubsection
24076 \begin_layout Standard
24077 Debugging options enable extra debugging information in the output files.
24080 \begin_layout Description
24085 \begin_layout Standard
24094 -debug-xtra Similar to -
24098 \begin_layout Standard
24108 \begin_inset LatexCommand \index{-\/-debug}
24112 , but dumps more information.
24115 \begin_layout Description
24120 \begin_layout Standard
24129 -debug-ralloc Force register allocator to dump <source>.d file with debugging
24131 <source> is the name of the file being compiled.
24134 \begin_layout Description
24139 \begin_layout Standard
24148 -pcode-verbose Enable pcode debugging information in translation.
24151 \begin_layout Description
24156 \begin_layout Standard
24165 -calltree Dump call tree in .calltree file.
24168 \begin_layout Description
24173 \begin_layout Standard
24182 -gstack Trace push/pops for stack pointer overflow.
24185 \begin_layout Subsection
24186 Enviroment Variables
24189 \begin_layout Standard
24190 There is a number of enviromental variables that can be used when running
24191 SDCC to enable certain optimizations or force a specific program behaviour.
24192 these variables are primarily for debugging purposes so they can be enabled/dis
24196 \begin_layout Standard
24197 Currently there is only two such variables available:
24200 \begin_layout Description
24201 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
24202 bitfields is optimized by directly loading FSR0 with the address of the
24203 bitfield structure.
24204 Normally SDCC will cast the bitfield structure to a bitfield pointer and
24206 This step saves data ram and code space for functions that make heavy use
24208 (i.e., 80 bytes of code space are saved when compiling malloc.c with this
24213 \begin_layout Description
24214 NO_REG_OPT Do not perform pCode registers optimization.
24215 This should be used for debugging purposes.
24216 If bugs in the pcode optimizer are found, users can benefit from temporarily
24217 disabling the optimizer until the bug is fixed.
24220 \begin_layout Subsection
24221 Preprocessor Macros
24224 \begin_layout Standard
24226 \begin_inset LatexCommand \index{PIC16}
24230 port defines the following preprocessor macros while translating a source.
24233 \begin_layout Standard
24235 \begin_inset Tabular
24236 <lyxtabular version="3" rows="6" columns="2">
24238 <column alignment="center" valignment="top" leftline="true" width="0">
24239 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24240 <row topline="true" bottomline="true">
24241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24244 \begin_layout Standard
24250 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24253 \begin_layout Standard
24260 <row topline="true">
24261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24264 \begin_layout Standard
24270 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24273 \begin_layout Standard
24274 Port identification
24280 <row topline="true">
24281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24284 \begin_layout Standard
24289 \begin_layout Standard
24303 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24306 \begin_layout Standard
24307 Port identification (same as above)
24313 <row topline="true">
24314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24317 \begin_layout Standard
24323 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24326 \begin_layout Standard
24327 MCU Identification.
24332 is the microcontrol identification number, i.e.
24339 <row topline="true">
24340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24343 \begin_layout Standard
24348 \begin_layout Standard
24362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24365 \begin_layout Standard
24366 MCU Identification (same as above)
24372 <row topline="true" bottomline="true">
24373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24376 \begin_layout Standard
24382 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24385 \begin_layout Standard
24386 nnn = SMALL or LARGE respectively according to the stack model used
24399 \begin_layout Standard
24400 In addition the following macros are defined when calling assembler:
24403 \begin_layout Standard
24405 \begin_inset Tabular
24406 <lyxtabular version="3" rows="4" columns="2">
24408 <column alignment="center" valignment="top" leftline="true" width="0">
24409 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24410 <row topline="true" bottomline="true">
24411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24414 \begin_layout Standard
24420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24423 \begin_layout Standard
24430 <row topline="true">
24431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24434 \begin_layout Standard
24440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24443 \begin_layout Standard
24444 MCU Identification.
24449 is the microcontrol identification number, i.e.
24456 <row topline="true">
24457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24460 \begin_layout Standard
24466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24469 \begin_layout Standard
24470 nnn = SMALL or LARGE respectively according to the memory model used for
24477 <row topline="true" bottomline="true">
24478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24481 \begin_layout Standard
24487 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24490 \begin_layout Standard
24491 nnn = SMALL or LARGE respectively according to the stack model used
24504 \begin_layout Subsection
24508 \begin_layout Standard
24510 \begin_inset LatexCommand \index{PIC16}
24514 port uses the following directories for searching header files and libraries.
24517 \begin_layout Standard
24519 \begin_inset Tabular
24520 <lyxtabular version="3" rows="3" columns="4">
24522 <column alignment="center" valignment="top" leftline="true" width="0">
24523 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24524 <column alignment="center" valignment="top" width="0">
24525 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24526 <row topline="true" bottomline="true">
24527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24530 \begin_layout Standard
24536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24539 \begin_layout Standard
24545 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24548 \begin_layout Standard
24554 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24557 \begin_layout Standard
24564 <row topline="true">
24565 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24568 \begin_layout Standard
24569 PREFIX/sdcc/include/pic16
24574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24577 \begin_layout Standard
24578 PIC16 specific headers
24583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24586 \begin_layout Standard
24592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24595 \begin_layout Standard
24602 <row topline="true" bottomline="true">
24603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24606 \begin_layout Standard
24607 PREFIX/sdcc/lib/pic16
24612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24615 \begin_layout Standard
24616 PIC16 specific libraries
24621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24624 \begin_layout Standard
24630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24633 \begin_layout Standard
24647 \begin_layout Subsection
24649 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
24656 \begin_layout Standard
24658 \begin_inset LatexCommand \index{PIC16}
24662 port currently supports the following pragmas:
24665 \begin_layout Description
24667 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
24671 This forces the code generator to initialize the stack & frame pointers
24672 at a specific address.
24673 This is an ad hoc solution for cases where no STACK directive is available
24674 in the linker script or gplink is not instructed to create a stack section.
24677 stack pragma should be used only once in a project.
24678 Multiple pragmas may result in indeterminate behaviour of the program.
24682 \begin_layout Standard
24683 The old format (ie.
24684 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
24685 cross page boundaries (or even exceed the available data RAM) and crash
24687 Make sure that stack does not cross page boundaries when using the SMALL
24695 The format is as follows:
24700 \begin_layout LyX-Code
24701 #pragma stack bottom_address [stack_size]
24706 \begin_layout Standard
24711 is the lower bound of the stack section.
24712 The stack pointer initially will point at address (bottom_address+stack_size-1).
24715 \begin_layout LyX-Code
24719 \begin_layout LyX-Code
24723 \begin_layout LyX-Code
24724 /* initializes stack of 100 bytes at RAM address 0x200 */
24727 \begin_layout LyX-Code
24728 #pragma stack 0x200 100
24731 \begin_layout Standard
24732 If the stack_size field is omitted then a stack is created with the default
24734 This size might be enough for most programs, but its not enough for operations
24735 with deep function nesting or excessive stack usage.
24738 \begin_layout Description
24740 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
24744 Force a function to a static FLASH address.
24747 \begin_layout LyX-Code
24751 \begin_layout LyX-Code
24755 \begin_layout LyX-Code
24756 /* place function test_func at 0x4000 */
24759 \begin_layout LyX-Code
24760 #pragma code test_func 0x4000
24763 \begin_layout LyX-Code
24767 \begin_layout Description
24768 library instructs the linker to use a library module.
24773 \begin_layout LyX-Code
24774 #pragma library module_name
24777 \begin_layout Standard
24782 can be any library or object file (including its path).
24783 Note that there are four reserved keywords which have special meaning.
24787 \begin_layout Standard
24789 \begin_inset Tabular
24790 <lyxtabular version="3" rows="6" columns="3">
24792 <column alignment="center" valignment="top" leftline="true" width="0">
24793 <column alignment="block" valignment="top" leftline="true" width="20page%">
24794 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
24795 <row topline="true" bottomline="true">
24796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24799 \begin_layout Standard
24805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24808 \begin_layout Standard
24814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24817 \begin_layout Standard
24824 <row topline="true">
24825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24828 \begin_layout Standard
24836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24839 \begin_layout Standard
24840 ignore all library pragmas
24845 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24848 \begin_layout Standard
24857 <row topline="true">
24858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24861 \begin_layout Standard
24869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24872 \begin_layout Standard
24878 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24881 \begin_layout Standard
24892 <row topline="true">
24893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24896 \begin_layout Standard
24904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24907 \begin_layout Standard
24908 link the Math libarary
24913 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24916 \begin_layout Standard
24927 <row topline="true">
24928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24931 \begin_layout Standard
24939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24942 \begin_layout Standard
24943 link the I/O library
24948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24951 \begin_layout Standard
24962 <row topline="true" bottomline="true">
24963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24966 \begin_layout Standard
24974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24977 \begin_layout Standard
24978 link the debug library
24983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24986 \begin_layout Standard
25003 * is the device number, i.e.
25004 452 for PIC18F452 MCU.
25007 \begin_layout Standard
25008 This feature allows for linking with specific libraries withoug having to
25009 explicit name them in the command line.
25014 keyword will reject all modules specified by the library pragma.
25017 \begin_layout Description
25018 udata The pragma udata instructs the compiler to emit code so that linker
25019 will place a variable at a specific memory bank.
25022 \begin_layout LyX-Code
25026 \begin_layout LyX-Code
25030 \begin_layout LyX-Code
25031 /* places variable foo at bank2 */
25034 \begin_layout LyX-Code
25035 #pragma udata bank2 foo
25038 \begin_layout LyX-Code
25042 \begin_layout Standard
25043 In order for this pragma to work extra SECTION directives should be added
25044 in the .lkr script.
25045 In the following example a sample .lkr file is shown:
25048 \begin_layout LyX-Code
25052 \begin_layout LyX-Code
25053 // Sample linker script for the PIC18F452 processor
25056 \begin_layout LyX-Code
25060 \begin_layout LyX-Code
25061 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
25064 \begin_layout LyX-Code
25065 CODEPAGE NAME=page START=0x2A END=0x7FFF
25068 \begin_layout LyX-Code
25069 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
25072 \begin_layout LyX-Code
25073 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
25076 \begin_layout LyX-Code
25077 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
25080 \begin_layout LyX-Code
25081 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
25084 \begin_layout LyX-Code
25085 ACCESSBANK NAME=accessram START=0x0 END=0x7F
25088 \begin_layout LyX-Code
25092 \begin_layout LyX-Code
25093 DATABANK NAME=gpr0 START=0x80 END=0xFF
25096 \begin_layout LyX-Code
25097 DATABANK NAME=gpr1 START=0x100 END=0x1FF
25100 \begin_layout LyX-Code
25101 DATABANK NAME=gpr2 START=0x200 END=0x2FF
25104 \begin_layout LyX-Code
25105 DATABANK NAME=gpr3 START=0x300 END=0x3FF
25108 \begin_layout LyX-Code
25109 DATABANK NAME=gpr4 START=0x400 END=0x4FF
25112 \begin_layout LyX-Code
25113 DATABANK NAME=gpr5 START=0x500 END=0x5FF
25116 \begin_layout LyX-Code
25117 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
25120 \begin_layout LyX-Code
25124 \begin_layout LyX-Code
25125 SECTION NAME=CONFIG ROM=config
25128 \begin_layout LyX-Code
25132 \begin_layout LyX-Code
25133 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
25136 \begin_layout LyX-Code
25137 SECTION NAME=bank1 RAM=gpr1 # should be added to link
25140 \begin_layout LyX-Code
25141 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
25144 \begin_layout LyX-Code
25145 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
25148 \begin_layout LyX-Code
25149 SECTION NAME=bank4 RAM=gpr4
25152 \begin_layout LyX-Code
25153 SECTION NAME=bank5 RAM=gpr5
25156 \begin_layout Standard
25157 The linker will recognise the section name set in the pragma statement and
25158 will position the variable at the memory bank set with the RAM field at
25159 the SECTION line in the linker script file.
25162 \begin_layout Subsection
25164 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
25171 \begin_layout Standard
25172 There is one main header file
25173 \begin_inset LatexCommand \index{PIC16!Header files}
25177 that can be included to the source files using the pic16
25178 \begin_inset LatexCommand \index{PIC16}
25188 This header file contains the definitions for the processor special registers,
25189 so it is necessary if the source accesses them.
25190 It can be included by adding the following line in the beginning of the
25194 \begin_layout LyX-Code
25195 #include <pic18fregs.h>
25198 \begin_layout Standard
25199 The specific microcontroller is selected within the pic18fregs.h automatically,
25200 so the same source can be used with a variety of devices.
25203 \begin_layout Subsection
25207 \begin_layout Standard
25209 \begin_inset LatexCommand \index{PIC16!Libraries}
25214 \begin_inset LatexCommand \index{PIC16}
25218 port depends on are the microcontroller device libraries which contain
25219 the symbol definitions for the microcontroller special function registers.
25220 These libraries have the format pic18fxxxx.lib, where
25224 is the microcontroller identification number.
25225 The specific library is selected automatically by the compiler at link
25226 stage according to the selected device.
25229 \begin_layout Standard
25230 Libraries are created with gplib which is part of the gputils package
25231 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
25238 \begin_layout Subsubsection*
25239 Building the libraries
25242 \begin_layout Standard
25243 Before using SDCC/pic16 there are some libraries that need to be compiled.
25244 This process is not done automatically by SDCC since not all users use
25245 SDCC for pic16 projects.
25246 So each user should compile the libraries separately.
25249 \begin_layout Standard
25250 The steps to compile the pic16 libraries under Linux and Mac OS X are:
25253 \begin_layout LyX-Code
25254 cd device/lib/pic16
25257 \begin_layout LyX-Code
25261 \begin_layout LyX-Code
25265 \begin_layout LyX-Code
25269 \begin_layout LyX-Code
25273 \begin_layout LyX-Code
25274 su -c 'make install' # install the libraries, you need the root password
25277 \begin_layout Standard
25278 If you need to install the headers too, do:
25281 \begin_layout LyX-Code
25285 \begin_layout LyX-Code
25286 su -c 'make install' # install the headers, you need the root password
25289 \begin_layout Standard
25290 There exist a special target to build the I/O libraries.
25291 This target is not automatically build because it will build the I/O library
25297 This way building will take quite a lot of time.
25298 Users are advised to edit the
25300 device/lib/pic16/pics.build
25302 file and then execute:
25305 \begin_layout LyX-Code
25309 \begin_layout Subsection
25310 Adding New Devices to the Port
25313 \begin_layout Standard
25314 Adding support for a new 16
25318 \begin_layout Standard
25327 bit PIC MCU requires the following steps:
25330 \begin_layout Enumerate
25331 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
25335 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
25339 \begin_layout Enumerate
25342 mv picDEVICE.h /path/to/sdcc/device/include/pic16
25345 \begin_layout Enumerate
25348 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
25351 \begin_layout Enumerate
25354 /path/to/sdcc/device/lib/pics.all
25362 Note: No 18f prefix here!
25365 \begin_layout Enumerate
25368 /path/to/sdcc/device/lib/pic16/libio/*.ignore
25372 Add your DEVICE if it does not compile in
25387 \begin_layout Enumerate
25390 /path/to/sdcc/device/include/pic16/pic18fregs.h
25393 The file format is self-explanatory, just add
25397 #elif defined(picDEVICE)
25399 # include <picDEVICE.h>
25403 at the right place (keep it sorted).
25406 \begin_layout Enumerate
25409 /path/to/sdcc/src/pic16/devices.inc
25412 Copy and modify an existing entry and insert it at the correct place (keep
25414 The file is hardly documented, look at the entries for the 18f2221...
25417 \begin_layout Enumerate
25418 Recompile SDCC, including the pic16 libraries.
25421 \begin_layout Subsection
25425 \begin_layout Standard
25426 The following memory models are supported by the PIC16 port:
25429 \begin_layout Itemize
25433 \begin_layout Itemize
25437 \begin_layout Standard
25438 Memory model affects the default size of pointers within the source.
25439 The sizes are shown in the next table:
25442 \begin_layout Standard
25444 \begin_inset Tabular
25445 <lyxtabular version="3" rows="3" columns="3">
25447 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25448 <column alignment="center" valignment="top" leftline="true" width="0">
25449 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25450 <row topline="true" bottomline="true">
25451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25454 \begin_layout Standard
25455 Pointer sizes according to memory model
25460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25463 \begin_layout Standard
25469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25472 \begin_layout Standard
25479 <row topline="true" bottomline="true">
25480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25483 \begin_layout Standard
25489 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25492 \begin_layout Standard
25498 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25501 \begin_layout Standard
25508 <row topline="true" bottomline="true">
25509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25512 \begin_layout Standard
25518 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
25521 \begin_layout Standard
25527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25530 \begin_layout Standard
25544 \begin_layout Standard
25545 It is advisable that all sources within a project are compiled with the
25547 If one wants to override the default memory model, this can be done by
25548 declaring a pointer as
25557 Far selects large memory model's pointers, while near selects small memory
25561 \begin_layout Standard
25562 The standard device libraries (see
25563 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
25567 ) contain no reference to pointers, so they can be used with both memory
25571 \begin_layout Subsection
25575 \begin_layout Standard
25577 \begin_inset LatexCommand \index{PIC16!stack}
25581 implementation for the PIC16 port uses two indirect registers, FSR1 and
25585 \begin_layout Description
25586 FSR1 is assigned as stack pointer
25589 \begin_layout Description
25590 FSR2 is assigned as frame pointer
25593 \begin_layout Standard
25594 The following stack models are supported by the PIC16 port
25597 \begin_layout Itemize
25605 \begin_layout Itemize
25613 \begin_layout Standard
25618 model means that only the FSRxL byte is used to access stack and frame,
25625 uses both FSRxL and FSRxH registers.
25626 The following table shows the stack/frame pointers sizes according to stack
25627 model and the maximum space they can address:
25630 \begin_layout Standard
25632 \begin_inset Tabular
25633 <lyxtabular version="3" rows="3" columns="3">
25635 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25636 <column alignment="center" valignment="top" leftline="true" width="0">
25637 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25638 <row topline="true" bottomline="true">
25639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25642 \begin_layout Standard
25643 Stack & Frame pointer sizes according to stack model
25648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25651 \begin_layout Standard
25657 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25660 \begin_layout Standard
25667 <row topline="true">
25668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25671 \begin_layout Standard
25677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25680 \begin_layout Standard
25686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25689 \begin_layout Standard
25696 <row topline="true" bottomline="true">
25697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25700 \begin_layout Standard
25706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25709 \begin_layout Standard
25715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25718 \begin_layout Standard
25732 \begin_layout Standard
25737 stack model is currently not working properly throughout the code generator.
25738 So its use is not advised.
25739 Also there are some other points that need special care:
25744 \begin_layout Enumerate
25745 Do not create stack sections with size more than one physical bank (that
25749 \begin_layout Enumerate
25750 Stack sections should no cross physical bank limits (i.e.
25751 #pragma stack 0x50 0x100)
25754 \begin_layout Standard
25755 These limitations are caused by the fact that only FSRxL is modified when
25756 using SMALL stack model, so no more than 256 bytes of stack can be used.
25757 This problem will disappear after LARGE model is fully implemented.
25760 \begin_layout Subsection
25764 \begin_layout Standard
25765 In addition to the standard SDCC function keywords, PIC16
25766 \begin_inset LatexCommand \index{PIC16}
25770 port makes available two more:
25773 \begin_layout Description
25775 \begin_inset LatexCommand \index{PIC16!wparam}
25779 Use the WREG to pass one byte of the first function argument.
25780 This improves speed but you may not use this for functions with arguments
25781 that are called via function pointers, otherwise the first byte of the
25782 first parameter will get lost.
25786 \begin_layout LyX-Code
25787 void func_wparam(int a) wparam
25790 \begin_layout LyX-Code
25794 \begin_layout LyX-Code
25795 /* WREG hold the lower part of a */
25798 \begin_layout LyX-Code
25799 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
25803 \begin_layout LyX-Code
25807 \begin_layout LyX-Code
25811 \begin_layout Description
25813 \begin_inset LatexCommand \index{PIC16!shadowregs}
25817 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
25818 hardware shadow registers which hold the values of WREG, STATUS and BSR
25820 This can be done by adding the keyword
25828 keyword in the function's header.
25831 \begin_layout LyX-Code
25832 void isr_shadow(void) shadowregs interrupt 1
25835 \begin_layout LyX-Code
25839 \begin_layout LyX-Code
25843 \begin_layout LyX-Code
25847 \begin_layout Standard
25852 instructs the code generator not to store/restore WREG, STATUS, BSR when
25853 entering/exiting the ISR.
25856 \begin_layout Subsection
25857 Function return values
25860 \begin_layout Standard
25861 Return values from functions are placed to the appropriate registers following
25862 a modified Microchip policy optimized for SDCC.
25863 The following table shows these registers:
25866 \begin_layout Standard
25868 \begin_inset Tabular
25869 <lyxtabular version="3" rows="6" columns="2">
25871 <column alignment="center" valignment="top" leftline="true" width="0">
25872 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25873 <row topline="true" bottomline="true">
25874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25877 \begin_layout Standard
25883 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25886 \begin_layout Standard
25887 destination register
25893 <row topline="true">
25894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25897 \begin_layout Standard
25903 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25906 \begin_layout Standard
25913 <row topline="true">
25914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25917 \begin_layout Standard
25923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25926 \begin_layout Standard
25933 <row topline="true">
25934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25937 \begin_layout Standard
25943 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25946 \begin_layout Standard
25953 <row topline="true">
25954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25957 \begin_layout Standard
25963 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25966 \begin_layout Standard
25967 FSR0L:PRODH:PRODL:WREG
25973 <row topline="true" bottomline="true">
25974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25977 \begin_layout Standard
25983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25986 \begin_layout Standard
25987 on stack, FSR0 points to the beginning
26000 \begin_layout Subsection
26004 \begin_layout Standard
26006 \begin_inset LatexCommand \index{PIC16!interrupt}
26010 service routine (ISR) is declared using the
26017 \begin_layout LyX-Code
26018 void isr(void) interrupt
26023 \begin_layout LyX-Code
26027 \begin_layout LyX-Code
26031 \begin_layout LyX-Code
26035 \begin_layout Standard
26040 is the interrupt number, which for PIC18F devices can be:
26043 \begin_layout Standard
26045 \begin_inset Tabular
26046 <lyxtabular version="3" rows="4" columns="3">
26048 <column alignment="center" valignment="top" leftline="true" width="0">
26049 <column alignment="center" valignment="top" leftline="true" width="0">
26050 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26051 <row topline="true" bottomline="true">
26052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26055 \begin_layout Standard
26063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26066 \begin_layout Standard
26072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26075 \begin_layout Standard
26076 Interrupt Vector Address
26082 <row topline="true">
26083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26086 \begin_layout Standard
26092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26095 \begin_layout Standard
26101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26104 \begin_layout Standard
26111 <row topline="true">
26112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26115 \begin_layout Standard
26130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26133 \begin_layout Standard
26143 HIGH priority interrupts
26148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26151 \begin_layout Standard
26158 <row topline="true" bottomline="true">
26159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26162 \begin_layout Standard
26168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26171 \begin_layout Standard
26172 LOW priority interrupts
26177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26180 \begin_layout Standard
26194 \begin_layout Standard
26195 When generating assembly code for ISR the code generator places a
26201 Interrupt Vector Address
26203 which points at the genetated ISR.
26204 This single GOTO instruction is part of an automatically generated
26206 interrupt entry point
26209 The actuall ISR code is placed as normally would in the code space.
26210 Upon interrupt request, the GOTO instruction is executed which jumps to
26212 When declaring interrupt functions as _naked this GOTO instruction is
26217 The whole interrupt functions is therefore placed at the Interrupt Vector
26218 Address of the specific interrupt.
26219 This is not a problem for the LOW priority interrupts, but it is a problem
26220 for the RESET and the HIGH priority interrupts because code may be written
26221 at the next interrupt's vector address and cause undeterminate program
26222 behaviour if that interrupt is raised.
26226 \begin_layout Standard
26227 This is not a problem when
26230 \begin_layout Enumerate
26231 this is a HIGH interrupt ISR and LOW interrupts are
26238 \begin_layout Enumerate
26239 when the ISR is small enough not to reach the next interrupt's vector address.
26247 \begin_layout Standard
26253 This way a function is generated similar to an ISR, but it is not assigned
26257 \begin_layout Standard
26258 When entering an interrupt, currently the PIC16
26259 \begin_inset LatexCommand \index{PIC16}
26263 port automatically saves the following registers:
26266 \begin_layout Itemize
26270 \begin_layout Itemize
26274 \begin_layout Itemize
26278 \begin_layout Itemize
26279 PROD (PRODL and PRODH)
26282 \begin_layout Itemize
26283 FSR0 (FSR0L and FSR0H)
26286 \begin_layout Standard
26287 These registers are restored upon return from the interrupt routine.
26291 \begin_layout Standard
26292 NOTE that when the _naked attribute is specified for an interrupt routine,
26293 then NO registers are stored or restored.
26301 \begin_layout Subsection
26305 \begin_layout Standard
26306 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
26307 There are 3 types of generic pointers currently implemented data, code
26308 and eeprom pointers.
26309 They are differentiated by the value of the 7th and 6th bits of the upper
26313 \begin_layout Standard
26315 \begin_inset Tabular
26316 <lyxtabular version="3" rows="5" columns="5">
26318 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26319 <column alignment="center" valignment="top" width="0">
26320 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26321 <column alignment="center" valignment="top" width="0">
26322 <column alignment="left" valignment="top" rightline="true" width="0">
26323 <row topline="true" bottomline="true">
26324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26327 \begin_layout Standard
26333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26336 \begin_layout Standard
26342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26345 \begin_layout Standard
26351 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26354 \begin_layout Standard
26355 rest of the pointer
26360 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26363 \begin_layout Standard
26370 <row topline="true" bottomline="true">
26371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26374 \begin_layout Standard
26380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26383 \begin_layout Standard
26389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26392 \begin_layout Standard
26398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26401 \begin_layout Standard
26406 uuuuuu uuuuxxxx xxxxxxxx
26411 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26414 \begin_layout Standard
26415 a 12-bit data pointer in data RAM memory
26421 <row bottomline="true">
26422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26425 \begin_layout Standard
26431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26434 \begin_layout Standard
26440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26443 \begin_layout Standard
26449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26452 \begin_layout Standard
26457 uxxxxx xxxxxxxx xxxxxxxx
26462 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26465 \begin_layout Standard
26466 a 21-bit code pointer in FLASH memory
26472 <row bottomline="true">
26473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26476 \begin_layout Standard
26482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26485 \begin_layout Standard
26491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26494 \begin_layout Standard
26500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26503 \begin_layout Standard
26508 uuuuuu uuuuuuxx xxxxxxxx
26513 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26516 \begin_layout Standard
26517 a 10-bit eeprom pointer in EEPROM memory
26523 <row bottomline="true">
26524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26527 \begin_layout Standard
26533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26536 \begin_layout Standard
26542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26545 \begin_layout Standard
26551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26554 \begin_layout Standard
26559 xxxxxx xxxxxxxx xxxxxxxx
26564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26567 \begin_layout Standard
26568 unimplemented pointer type
26581 \begin_layout Standard
26582 Generic pointer are read and written with a set of library functions which
26583 read/write 1, 2, 3, 4 bytes.
26586 \begin_layout Subsection
26590 \begin_layout Subsubsection
26591 Standard I/O Streams
26594 \begin_layout Standard
26599 the type FILE is defined as:
26602 \begin_layout LyX-Code
26603 typedef char * FILE;
26606 \begin_layout Standard
26607 This type is the stream type implemented I/O in the PIC18F devices.
26608 Also the standard input and output streams are declared in stdio.h:
26611 \begin_layout LyX-Code
26612 extern FILE * stdin;
26615 \begin_layout LyX-Code
26616 extern FILE * stdout;
26619 \begin_layout Standard
26620 The FILE type is actually a generic pointer which defines one more type
26621 of generic pointers, the
26626 This new type has the format:
26629 \begin_layout Standard
26631 \begin_inset Tabular
26632 <lyxtabular version="3" rows="2" columns="7">
26634 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26635 <column alignment="center" valignment="top" width="0">
26636 <column alignment="center" valignment="top" leftline="true" width="0">
26637 <column alignment="center" valignment="top" leftline="true" width="0">
26638 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26639 <column alignment="center" valignment="top" width="0">
26640 <column alignment="left" valignment="top" rightline="true" width="0">
26641 <row topline="true" bottomline="true">
26642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26645 \begin_layout Standard
26651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26654 \begin_layout Standard
26660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26663 \begin_layout Standard
26669 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26672 \begin_layout Standard
26678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26681 \begin_layout Standard
26687 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26690 \begin_layout Standard
26691 rest of the pointer
26696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26699 \begin_layout Standard
26706 <row topline="true" bottomline="true">
26707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26710 \begin_layout Standard
26716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26719 \begin_layout Standard
26725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26728 \begin_layout Standard
26734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26737 \begin_layout Standard
26743 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26746 \begin_layout Standard
26752 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26755 \begin_layout Standard
26765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26768 \begin_layout Standard
26769 upper byte high nubble is 0x2n, the rest are zeroes
26782 \begin_layout Standard
26783 Currently implemented there are 3 types of streams defined:
26786 \begin_layout Standard
26788 \begin_inset Tabular
26789 <lyxtabular version="3" rows="4" columns="4">
26791 <column alignment="center" valignment="top" leftline="true" width="0">
26792 <column alignment="center" valignment="top" leftline="true" width="0">
26793 <column alignment="center" valignment="top" leftline="true" width="0">
26794 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26795 <row topline="true" bottomline="true">
26796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26799 \begin_layout Standard
26805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26808 \begin_layout Standard
26814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26817 \begin_layout Standard
26823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26826 \begin_layout Standard
26833 <row topline="true">
26834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26837 \begin_layout Standard
26843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26846 \begin_layout Standard
26854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26857 \begin_layout Standard
26863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26866 \begin_layout Standard
26867 Writes/Reads characters via the USART peripheral
26873 <row topline="true">
26874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26877 \begin_layout Standard
26883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26886 \begin_layout Standard
26894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26897 \begin_layout Standard
26903 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26906 \begin_layout Standard
26907 Writes/Reads characters via the MSSP peripheral
26913 <row topline="true" bottomline="true">
26914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26917 \begin_layout Standard
26923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26926 \begin_layout Standard
26934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26937 \begin_layout Standard
26943 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26946 \begin_layout Standard
26947 Writes/Reads characters via used defined functions
26960 \begin_layout Standard
26961 The stream identifiers are declared as macros in the stdio.h header.
26964 \begin_layout Standard
26965 In the libc library there exist the functions that are used to write to
26966 each of the above streams.
26970 \begin_layout Description
26975 \begin_layout Standard
26984 _stream_usart_putchar writes a character at the USART stream
26987 \begin_layout Description
26992 \begin_layout Standard
27001 _stream_mssp_putchar writes a character at the MSSP stream
27004 \begin_layout Description
27005 putchar dummy function.
27006 This writes a character to a user specified manner.
27009 \begin_layout Standard
27010 In order to increase performance
27014 is declared in stdio.h as having its parameter in WREG (it has the wparam
27016 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
27017 in a user-friendly way.
27022 is the name of the variable that holds the character to print.
27023 An example follows:
27026 \begin_layout LyX-Code
27027 #include <pic18fregs.h>
27036 \begin_layout LyX-Code
27040 \begin_layout LyX-Code
27041 PORTA = c; /* dump character c to PORTA */
27044 \begin_layout LyX-Code
27052 \begin_layout LyX-Code
27056 \begin_layout LyX-Code
27057 stdout = STREAM_USER; /* this is not necessary, since stdout points
27060 \begin_layout LyX-Code
27061 * by default to STREAM_USER */
27064 \begin_layout LyX-Code
27066 \begin_inset Quotes sld
27069 This is a printf test
27072 \begin_inset Quotes srd
27078 \begin_layout LyX-Code
27082 \begin_layout LyX-Code
27086 \begin_layout Subsubsection
27090 \begin_layout Standard
27091 PIC16 contains an implementation of the printf-family of functions.
27092 There exist the following functions:
27095 \begin_layout LyX-Code
27096 extern unsigned int sprintf(char *buf, char *fmt, ...);
27099 \begin_layout LyX-Code
27100 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
27103 \begin_layout LyX-Code
27107 \begin_layout LyX-Code
27108 extern unsigned int printf(char *fmt, ...);
27111 \begin_layout LyX-Code
27112 extern unsigned int vprintf(char *fmt, va_lista ap);
27115 \begin_layout LyX-Code
27119 \begin_layout LyX-Code
27120 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
27123 \begin_layout LyX-Code
27124 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
27127 \begin_layout Standard
27128 For sprintf and vsprintf
27132 should normally be a data pointer where the resulting string will be placed.
27133 No range checking is done so the user should allocate the necessery buffer.
27134 For fprintf and vfprintf
27138 should be a stream pointer (i.e.
27139 stdout, STREAM_MSSP, etc...).
27142 \begin_layout Subsubsection
27146 \begin_layout Standard
27147 The PIC18F family of microcontrollers supports a number of interrupt sources.
27148 A list of these interrupts is shown in the following table:
27151 \begin_layout Standard
27153 \begin_inset Tabular
27154 <lyxtabular version="3" rows="11" columns="4">
27156 <column alignment="left" valignment="top" leftline="true" width="0">
27157 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27158 <column alignment="left" valignment="top" leftline="true" width="0">
27159 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27160 <row topline="true" bottomline="true">
27161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27164 \begin_layout Standard
27170 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="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
27188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27191 \begin_layout Standard
27198 <row topline="true">
27199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27202 \begin_layout Standard
27208 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27211 \begin_layout Standard
27212 PORTB change interrupt
27217 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27220 \begin_layout Standard
27226 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27229 \begin_layout Standard
27230 EEPROM/FLASH write complete interrupt
27236 <row topline="true">
27237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27240 \begin_layout Standard
27246 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27249 \begin_layout Standard
27250 INT0 external interrupt
27255 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27258 \begin_layout Standard
27264 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27267 \begin_layout Standard
27268 Bus collision interrupt
27274 <row topline="true">
27275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27278 \begin_layout Standard
27284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27287 \begin_layout Standard
27288 INT1 external interrupt
27293 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27296 \begin_layout Standard
27302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27305 \begin_layout Standard
27306 Low voltage detect interrupt
27312 <row topline="true">
27313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27316 \begin_layout Standard
27322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27325 \begin_layout Standard
27326 INT2 external interrupt
27331 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27334 \begin_layout Standard
27340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27343 \begin_layout Standard
27344 Parallel slave port interrupt
27350 <row topline="true">
27351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27354 \begin_layout Standard
27360 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27363 \begin_layout Standard
27364 CCP1 module interrupt
27369 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27372 \begin_layout Standard
27378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27381 \begin_layout Standard
27382 AD convertion complete interrupt
27388 <row topline="true">
27389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27392 \begin_layout Standard
27398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27401 \begin_layout Standard
27402 CCP2 module interrupt
27407 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27410 \begin_layout Standard
27416 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27419 \begin_layout Standard
27420 USART receive interrupt
27426 <row topline="true">
27427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27430 \begin_layout Standard
27436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27439 \begin_layout Standard
27440 TMR0 overflow interrupt
27445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27448 \begin_layout Standard
27454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27457 \begin_layout Standard
27458 USART transmit interrupt
27464 <row topline="true">
27465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27468 \begin_layout Standard
27474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27477 \begin_layout Standard
27478 TMR1 overflow interrupt
27483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27486 \begin_layout Standard
27492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27495 \begin_layout Standard
27496 SSP receive/transmit interrupt
27502 <row topline="true">
27503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27506 \begin_layout Standard
27512 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27515 \begin_layout Standard
27516 TMR2 matches PR2 interrupt
27521 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27524 \begin_layout Standard
27530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27533 \begin_layout Standard
27540 <row topline="true" bottomline="true">
27541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27544 \begin_layout Standard
27550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27553 \begin_layout Standard
27554 TMR3 overflow interrupt
27559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27562 \begin_layout Standard
27568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27571 \begin_layout Standard
27585 \begin_layout Standard
27586 The prototypes for these names are defined in the header file
27593 \begin_layout Standard
27594 In order to simplify signal handling, a number of macros is provided:
27598 \labelwidthstring 00.00.0000
27599 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
27600 high priority interrupts.
27605 is the function name to use.
27609 \labelwidthstring 00.00.0000
27610 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
27611 low priority interrupt.
27616 is the function name to use.
27620 \labelwidthstring 00.00.0000
27621 DEF_HANDLER(sig,handler) define a handler for signal
27627 \labelwidthstring 00.00.0000
27628 END_DEF end the declaration of the dispatch table.
27631 \begin_layout Standard
27632 Additionally there are two more macros to simplify the declaration of the
27637 \labelwidthstring 00.00.0000
27640 SIGHANDLER(handler)
27642 this declares the function prototype for the
27650 \labelwidthstring 00.00.0000
27651 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
27654 \begin_layout Standard
27655 An example of using the macros above is shown below:
27658 \begin_layout LyX-Code
27659 #include <pic18fregs.h>
27662 \begin_layout LyX-Code
27663 #include <signal.h>
27667 DEF_INTHIGH(high_int)
27670 \begin_layout LyX-Code
27671 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
27674 \begin_layout LyX-Code
27675 DEF_HANDLER(SIG_BCOL, _bcol_handler)
27678 \begin_layout LyX-Code
27683 SIGHANDLER(_tmr0_handler)
27686 \begin_layout LyX-Code
27690 \begin_layout LyX-Code
27691 /* action to be taken when timer 0 overflows */
27694 \begin_layout LyX-Code
27699 SIGHANDLERNAKED(_bcol_handler)
27702 \begin_layout LyX-Code
27706 \begin_layout LyX-Code
27710 \begin_layout LyX-Code
27711 /* action to be taken when bus collision occurs */
27714 \begin_layout LyX-Code
27718 \begin_layout LyX-Code
27722 \begin_layout LyX-Code
27726 \begin_layout Standard
27731 Special care should be taken when using the above scheme:
27734 \begin_layout Itemize
27735 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
27738 \begin_layout Itemize
27739 when declaring SIGHANDLERNAKED handler never forget to use
27743 for proper returning.
27746 \begin_layout Subsection
27750 \begin_layout Standard
27751 Here you can find some general tips for compiling programs with SDCC/pic16.
27754 \begin_layout Subsubsection
27758 \begin_layout Standard
27760 \begin_inset LatexCommand \index{PIC16!stack}
27764 size (that is 64 bytes) probably is enough for many programs.
27765 One must take care that when there are many levels of function nesting,
27766 or there is excessive usage of stack, its size should be extended.
27767 An example of such a case is the printf/sprintf family of functions.
27768 If you encounter problems like not being able to print integers, then you
27769 need to set the stack size around the maximum (256 for small stack model).
27770 The following diagram shows what happens when calling printf to print an
27774 \begin_layout LyX-Code
27775 printf () --> ltoa () --> ultoa () --> divschar ()
27778 \begin_layout Standard
27779 It is should be understood that stack is easily consumed when calling complicate
27781 Using command line arguments like -
27785 \begin_layout Standard
27794 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
27796 Other ways to reduce stack usage may exist.
27799 \begin_layout Subsection
27803 \begin_layout Standard
27804 The PIC16 Port currently does not pass SDCC's regression test
27805 \begin_inset LatexCommand \index{Regression test (PIC16)}
27810 \begin_inset LatexCommand \ref{sec:Quality-control}
27814 ) and thus the snapshot build regression tests for the PIC16 target are
27815 currently disabled for all hosts
27820 \begin_layout Chapter
27824 \begin_layout Standard
27825 There are several approaches to debugging your code.
27826 This chapter is meant to show your options and to give detail on some of
27831 When writing your code:
27834 \begin_layout Itemize
27835 write your code with debugging in mind (avoid duplicating code, put conceptually
27836 similar variables into structs, use structured code, have strategic points
27837 within your code where all variables are consistent, ...)
27840 \begin_layout Itemize
27841 run a syntax-checking tool like splint
27842 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27847 \begin_inset LatexCommand \index{lint (syntax checking tool)}
27855 \begin_layout Standard
27865 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27872 \begin_layout Itemize
27873 for the high level code use a C-compiler (like f.e.
27874 GCC) to compile run and debug the code on your host.
27879 \begin_layout Standard
27889 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27893 ) on how to handle syntax extensions like __xdata, __at(), ...
27897 \begin_layout Itemize
27898 use another C-compiler to compile code for your target.
27899 Always an option but not recommended:) And not very likely to help you.
27900 If you seriously consider walking this path you should at least occasionally
27901 check portability of your code.
27902 Most commercial compiler vendors will offer an evaluation version so you
27903 can test compile your code or snippets of your code.
27906 \begin_layout Standard
27907 Debugging on a simulator:
27910 \begin_layout Itemize
27911 there is a separate section about SDCDB (section
27912 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
27919 \begin_layout Itemize
27920 or (8051 specific) use a freeware/commercial simulator which interfaces
27922 \begin_inset LatexCommand \index{AOMF, AOMF51}
27927 \begin_inset LatexCommand \ref{OMF file}
27931 ) optionally generated by SDCC.
27934 \begin_layout Standard
27935 Debugging On-target:
27938 \begin_layout Itemize
27939 use a MCU port pin to serially output debug data to the RS232 port of your
27941 You'll probably want some level shifting device typically involving a MAX232
27943 If the hardware serial port of the MCU is not available search for 'Software
27944 UART' in your favourite search machine.
27947 \begin_layout Itemize
27948 use an on-target monitor.
27949 In this context a monitor is a small program which usually accepts commands
27950 via a serial line and allows to set program counter, to single step through
27951 a program and read/write memory locations.
27952 For the 8051 good examples of monitors are paulmon and cmon51 (see section
27954 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
27961 \begin_layout Itemize
27962 toggle MCU port pins at strategic points within your code and use an oscilloscop
27966 digital oscilloscope
27969 \begin_inset LatexCommand \index{Oscilloscope}
27973 with deep trace memory is really helpful especially if you have to debug
27974 a realtime application.
27975 If you need to monitor more pins than your oscilloscope provides you can
27976 sometimes get away with a small R-2R network.
27977 On a single channel oscilloscope you could f.e.
27978 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
27980 \begin_inset Formula $\Omega$
27983 resistor and the other one by a 5\InsetSpace ~
27985 \begin_inset Formula $\Omega$
27988 resistor to the oscilloscope probe (check output drive capability of the
27989 pins you want to monitor).
27990 If you need to monitor many more pins a
27997 \begin_layout Itemize
28011 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
28016 Usually very expensive.
28017 And very nice to have too.
28018 And usually locks you (for years...) to the devices the ICE can emulate.
28022 \begin_layout Itemize
28023 use a remote debugger.
28024 In most 8-bit systems the symbol information is not available on the target,
28025 and a complete debugger is too bulky for the target system.
28026 Therefore usually a debugger on the host system connects to an on-target
28027 debugging stub which accepts only primitive commands.
28030 Terms to enter into your favourite search engine could be 'remote debugging',
28031 'gdb stub' or 'inferior debugger'.
28035 \begin_layout Itemize
28036 use an on target hardware debugger.
28037 Some of the more modern MCUs include hardware support for setting break
28038 points and monitoring/changing variables by using dedicated hardware pins.
28039 This facility doesn't require additional code to run on the target and
28044 doesn't affect runtime behaviour until a breakpoint is hit.
28045 For the mcs51 most hardware debuggers use the AOMF
28046 \begin_inset LatexCommand \index{AOMF, AOMF51}
28051 \begin_inset LatexCommand \ref{OMF file}
28059 \begin_layout Standard
28063 \begin_layout Itemize
28064 if you are not familiar with any of the following terms you're likely to
28065 run into problems rather sooner than later:
28082 As an embedded programmer you
28086 to know them so why not look them up
28090 you have problems?)
28093 \begin_layout Itemize
28094 tell someone else about your problem (actually this is a surprisingly effective
28095 means to hunt down the bug even if the listener is not familiar with your
28097 As 'failure to communicate' is probably one of the job-induced deformations
28098 of an embedded programmer this is highly encouraged.
28101 \begin_layout Section
28102 Debugging with SDCDB
28103 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
28108 \begin_inset LatexCommand \index{SDCDB (debugger)}
28115 \begin_layout Standard
28116 SDCC is distributed with a source level debugger
28117 \begin_inset LatexCommand \index{Debugger}
28122 The debugger uses a command line interface, the command repertoire of the
28123 debugger has been kept as close to gdb
28124 \begin_inset LatexCommand \index{gdb}
28128 (the GNU debugger) as possible.
28129 The configuration and build process is part of the standard compiler installati
28130 on, which also builds and installs the debugger in the target directory
28131 specified during configuration.
28132 The debugger allows you debug BOTH at the C source and at the ASM source
28136 \begin_layout Subsection
28137 Compiling for Debugging
28140 \begin_layout Standard
28145 \begin_layout Standard
28155 \begin_inset LatexCommand \index{-\/-debug}
28159 option must be specified for all files for which debug information is to
28161 The compiler generates a .adb file for each of these files.
28162 The linker creates the .cdb
28163 \begin_inset LatexCommand \index{<file>.cdb}
28168 \begin_inset LatexCommand \index{<file>.adb}
28172 files and the address information.
28173 This .cdb is used by the debugger.
28176 \begin_layout Subsection
28177 How the Debugger Works
28180 \begin_layout Standard
28185 \begin_layout Standard
28194 -debug option is specified the compiler generates extra symbol information
28195 some of which are put into the assembler source and some are put into the
28197 Then the linker creates the .cdb file from the individual .adb files with
28198 the address information for the symbols.
28199 The debugger reads the symbolic information generated by the compiler &
28200 the address information generated by the linker.
28201 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
28202 execution is controlled by the debugger.
28203 When a command is issued for the debugger, it translates it into appropriate
28204 commands for the simulator.
28205 (Currently SDCDM only connects to the simulator but
28210 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
28214 is an effort to connect directly to the hardware.)
28217 \begin_layout Subsection
28218 Starting the Debugger SDCDB
28221 \begin_layout Standard
28222 The debugger can be started using the following command line.
28223 (Assume the file you are debugging has the file name foo).
28237 The debugger will look for the following files.
28240 \begin_layout Itemize
28241 foo.c - the source file.
28244 \begin_layout Itemize
28245 foo.cdb - the debugger symbol information file.
28248 \begin_layout Itemize
28249 foo.ihx - the Intel hex format
28250 \begin_inset LatexCommand \index{Intel hex format}
28257 \begin_layout Subsection
28258 SDCDB Command Line Options
28261 \begin_layout Itemize
28266 \begin_layout Standard
28275 -directory=<source file directory> this option can used to specify the directory
28277 The debugger will look into the directory list specified for source, cdb
28279 The items in the directory list must be separated by ':', e.g.
28280 if the source files can be in the directories /home/src1 and /home/src2,
28285 \begin_layout Standard
28294 -directory option should be -
28298 \begin_layout Standard
28307 -directory=/home/src1:/home/src2.
28308 Note there can be no spaces in the option.
28312 \begin_layout Itemize
28313 -cd <directory> - change to the <directory>.
28316 \begin_layout Itemize
28317 -fullname - used by GUI front ends.
28320 \begin_layout Itemize
28321 -cpu <cpu-type> - this argument is passed to the simulator please see the
28322 simulator docs for details.
28325 \begin_layout Itemize
28326 -X <Clock frequency > this options is passed to the simulator please see
28327 the simulator docs for details.
28330 \begin_layout Itemize
28331 -s <serial port file> passed to simulator see the simulator docs for details.
28334 \begin_layout Itemize
28335 -S <serial in,out> passed to simulator see the simulator docs for details.
28338 \begin_layout Itemize
28339 -k <port number> passed to simulator see the simulator docs for details.
28342 \begin_layout Subsection
28343 SDCDB Debugger Commands
28346 \begin_layout Standard
28347 As mentioned earlier the command interface for the debugger has been deliberatel
28348 y kept as close the GNU debugger gdb, as possible.
28349 This will help the integration with existing graphical user interfaces
28350 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
28351 If you use a graphical user interface for the debugger you can skip this
28355 \begin_layout Subsubsection*
28356 break [line | file:line | function | file:function]
28359 \begin_layout Standard
28360 Set breakpoint at specified line or function:
28369 sdcdb>break foo.c:100
28371 sdcdb>break funcfoo
28373 sdcdb>break foo.c:funcfoo
28376 \begin_layout Subsubsection*
28377 clear [line | file:line | function | file:function ]
28380 \begin_layout Standard
28381 Clear breakpoint at specified line or function:
28390 sdcdb>clear foo.c:100
28392 sdcdb>clear funcfoo
28394 sdcdb>clear foo.c:funcfoo
28397 \begin_layout Subsubsection*
28401 \begin_layout Standard
28402 Continue program being debugged, after breakpoint.
28405 \begin_layout Subsubsection*
28409 \begin_layout Standard
28410 Execute till the end of the current function.
28413 \begin_layout Subsubsection*
28417 \begin_layout Standard
28418 Delete breakpoint number 'n'.
28419 If used without any option clear ALL user defined break points.
28422 \begin_layout Subsubsection*
28423 info [break | stack | frame | registers ]
28426 \begin_layout Itemize
28427 info break - list all breakpoints
28430 \begin_layout Itemize
28431 info stack - show the function call stack.
28434 \begin_layout Itemize
28435 info frame - show information about the current execution frame.
28438 \begin_layout Itemize
28439 info registers - show content of all registers.
28442 \begin_layout Subsubsection*
28446 \begin_layout Standard
28447 Step program until it reaches a different source line.
28448 Note: pressing <return> repeats the last command.
28451 \begin_layout Subsubsection*
28455 \begin_layout Standard
28456 Step program, proceeding through subroutine calls.
28459 \begin_layout Subsubsection*
28463 \begin_layout Standard
28464 Start debugged program.
28467 \begin_layout Subsubsection*
28471 \begin_layout Standard
28472 Print type information of the variable.
28475 \begin_layout Subsubsection*
28479 \begin_layout Standard
28480 print value of variable.
28483 \begin_layout Subsubsection*
28487 \begin_layout Standard
28488 load the given file name.
28489 Note this is an alternate method of loading file for debugging.
28492 \begin_layout Subsubsection*
28496 \begin_layout Standard
28497 print information about current frame.
28500 \begin_layout Subsubsection*
28504 \begin_layout Standard
28505 Toggle between C source & assembly source.
28508 \begin_layout Subsubsection*
28509 ! simulator command
28512 \begin_layout Standard
28513 Send the string following '!' to the simulator, the simulator response is
28515 Note the debugger does not interpret the command being sent to the simulator,
28516 so if a command like 'go' is sent the debugger can loose its execution
28517 context and may display incorrect values.
28520 \begin_layout Subsubsection*
28524 \begin_layout Standard
28527 My name is Bobby Brown"
28530 \begin_layout Subsection
28531 Interfacing SDCDB with DDD
28534 \begin_layout Standard
28535 \begin_inset Note Note
28538 \begin_layout Standard
28539 The screenshot was converted from png to eps with:
28540 \begin_inset Quotes sld
28543 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
28544 \begin_inset Quotes srd
28547 which produces a pretty compact eps file which is free from compression
28551 \begin_layout Standard
28552 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
28553 as this broke the build system on Sourceforge (pdf-file was broken.
28554 pdflatex does not accept eps files).
28562 \begin_layout Standard
28578 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
28584 shows a screenshot of a debugging session with DDD
28585 \begin_inset LatexCommand \index{DDD (debugger)}
28589 (Unix only) on a simulated 8032.
28590 The debugging session might not run as smoothly as the screenshot suggests.
28591 The debugger allows setting of breakpoints, displaying and changing variables,
28592 single stepping through C and assembler code.
28595 The source was compiled with
28609 \begin_layout Standard
28621 -debug ddd_example.c
28634 and DDD was invoked with
28641 ddd -debugger "sdcdb -cpu 8032 ddd_example"
28644 \begin_layout Standard
28645 \begin_inset Note Note
28648 \begin_layout Standard
28649 Check that the double quotes or an apostroph within the command line survive
28650 the LyX tool chain.
28651 Previously the apostrophs got slanted in the PDF output so a cut and paste
28660 \begin_layout Subsection
28661 Interfacing SDCDB with XEmacs
28662 \begin_inset LatexCommand \index{XEmacs}
28667 \begin_inset LatexCommand \index{Emacs}
28674 \begin_layout Standard
28675 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
28676 sdcdb.el and sdcdbsrc.el.
28677 These two files can be found in the $(prefix)/bin directory after the installat
28679 These files need to be loaded into XEmacs for the interface to work.
28680 This can be done at XEmacs startup time by inserting the following into
28681 your '.xemacs' file (which can be found in your HOME directory):
28687 (load-file sdcdbsrc.el)
28693 .xemacs is a lisp file so the () around the command is REQUIRED.
28694 The files can also be loaded dynamically while XEmacs is running, set the
28695 environment variable 'EMACSLOADPATH' to the installation bin directory
28696 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
28697 To start the interface enter the following command:
28711 You will prompted to enter the file name to be debugged.
28716 The command line options that are passed to the simulator directly are
28717 bound to default values in the file sdcdbsrc.el.
28718 The variables are listed below, these values maybe changed as required.
28721 \begin_layout Itemize
28722 sdcdbsrc-cpu-type '51
28725 \begin_layout Itemize
28726 sdcdbsrc-frequency '11059200
28729 \begin_layout Itemize
28730 sdcdbsrc-serial nil
28733 \begin_layout Standard
28734 The following is a list of key mapping for the debugger interface.
28737 \begin_layout Standard
28760 binding\InsetSpace ~
28798 -------\InsetSpace ~
28869 sdcdb-back-from-src\InsetSpace ~
28898 rom-src\InsetSpace ~
28908 SDCDB continue command
28926 sdcdb-step-from-src\InsetSpace ~
28955 hatis-c-sexp\InsetSpace ~
28965 SDCDB ptypecommand for data at
29032 sdcdbsrc-delete\InsetSpace ~
29047 B Delete all breakpoints if no arg
29096 given or delete arg (C-u arg x)
29115 -frame\InsetSpace ~
29130 SDCDB Display current frame if no arg,
29179 given or display frame arg
29247 sdcdbsrc-goto-sdcdb\InsetSpace ~
29257 Goto the SDCDB output buffer
29276 t-c-sexp\InsetSpace ~
29287 SDCDB print command for data at
29354 sdcdbsrc-goto-sdcdb\InsetSpace ~
29365 o the SDCDB output buffer
29383 sdcdbsrc-mode\InsetSpace ~
29399 Toggles Sdcdbsrc mode (turns it
29415 sdcdb-finish-from-src\InsetSpace ~
29423 SDCDB finish command
29457 Set break for line with point
29472 sdcdbsrc-mode\InsetSpace ~
29488 Toggle Sdcdbsrc mode
29504 dbsrc-srcmode\InsetSpace ~
29528 \begin_layout Chapter
29532 \begin_layout Standard
29533 Here are a few guidelines that will help the compiler generate more efficient
29534 code, some of the tips are specific to this compiler others are generally
29535 good programming practice.
29538 \begin_layout Itemize
29539 Use the smallest data type to represent your data-value.
29540 If it is known in advance that the value is going to be less than 256 then
29541 use an 'unsigned char' instead of a 'short' or 'int'.
29542 Please note, that ANSI C requires both signed and unsigned chars to be
29543 promoted to 'signed int'
29544 \begin_inset LatexCommand \index{promotion to signed int}
29549 \begin_inset Marginal
29552 \begin_layout Standard
29561 before doing any operation.
29563 \begin_inset LatexCommand \index{type promotion}
29568 \begin_inset LatexCommand \label{type promotion}
29572 can be omitted, if the result is the same.
29573 The effect of the promotion rules together with the sign-extension is often
29578 \begin_layout Verse
29581 unsigned char uc = 0xfe;
29583 if (uc * uc < 0) /* this is true! */
29596 \begin_layout Standard
29603 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
29611 \begin_layout Verse
29614 (unsigned char) -12 / (signed char) -3 = ...
29617 \begin_layout Standard
29618 No, the result is not 4:
29621 \begin_layout Verse
29624 (int) (unsigned char) -12 / (int) (signed char) -3 =
29626 (int) (unsigned char)
29627 0xf4 / (int) (signed char) 0xfd =
29629 (int) 0x00f4 / (int) 0xfffd =
29634 (int) 244 / (int) -3 =
29636 (int) -81 = (int) 0xffaf;
29639 \begin_layout Standard
29640 Don't complain, that gcc gives you a different result.
29641 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
29642 Therefore the results are different.
29645 \begin_inset Quotes sld
29649 \begin_inset Quotes srd
29655 \begin_layout Quote
29658 If well-defined overflow characteristics are important and negative values
29659 are not, or if you want to steer clear of sign-extension problems when
29660 manipulating bits or bytes, use one of the corresponding unsigned types.
29661 (Beware when mixing signed and unsigned values in expressions, though.)
29664 character types (especially unsigned char) can be used as "tiny" integers,
29665 doing so is sometimes more trouble than it's worth, due to unpredictable
29666 sign extension and increased code size.
29670 \begin_layout Itemize
29671 Use unsigned when it is known in advance that the value is not going to
29673 This helps especially if you are doing division or multiplication, bit-shifting
29674 or are using an array index.
29677 \begin_layout Itemize
29678 NEVER jump into a LOOP.
29681 \begin_layout Itemize
29682 Declare the variables to be local
29683 \begin_inset LatexCommand \index{local variables}
29687 whenever possible, especially loop control variables (induction).
29690 \begin_layout Itemize
29691 Have a look at the assembly listing to get a
29692 \begin_inset Quotes sld
29696 \begin_inset Quotes srd
29699 for the code generation.
29702 \begin_layout Section
29703 Porting code from or to other compilers
29704 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
29711 \begin_layout Itemize
29712 check whether endianness of the compilers differs and adapt where needed.
29715 \begin_layout Itemize
29716 check the device specific header files
29717 \begin_inset LatexCommand \index{Header files}
29722 \begin_inset LatexCommand \index{Include files}
29726 for compiler specific syntax.
29727 Eventually include the file <compiler.h
29728 \begin_inset LatexCommand \index{compiler.h (include file)}
29733 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
29737 to allow using common header files.
29740 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
29747 \begin_layout Itemize
29748 check whether the startup code contains the correct initialization (watchdog,
29752 \begin_layout Itemize
29753 check whether the sizes of short, int, long match.
29756 \begin_layout Itemize
29757 check if some 16 or 32 bit hardware registers require a specific addressing
29758 order (least significant or most significant byte first) and adapt if needed
29767 relate to time and not to lower/upper memory location here, so this is
29772 the same as endianness).
29775 \begin_layout Itemize
29776 check whether the keyword
29780 is used where needed.
29781 The compilers might differ in their optimization characteristics (as different
29782 versions of the same compiler might also use more clever optimizations
29783 this is good idea anyway).
29785 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
29792 \begin_layout Itemize
29793 check that the compilers are not told to supress warnings.
29796 \begin_layout Itemize
29797 check and convert compiler specific extensions (interrupts, memory areas,
29801 \begin_layout Itemize
29802 check for differences in type promotion.
29803 Especially check for math operations on
29812 For the sake of C99 compatibility SDCC will probably promote these to
29816 more often than other compilers.
29817 Eventually insert explicit casts to
29826 Also check that the ~\InsetSpace ~
29828 \begin_inset LatexCommand \index{\~\/ Operator}
29835 \begin_inset LatexCommand \index{bit}
29841 variables, use the !\InsetSpace ~
29844 \begin_inset LatexCommand \ref{type promotion}
29849 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29856 \begin_layout Itemize
29857 check the assembly code generated for interrupt routines (f.e.
29858 for calls to possibly non-reentrant library functions).
29861 \begin_layout Itemize
29862 check whether timing loops result in proper timing (or preferably consider
29863 a rewrite of the code with timer based delays instead).
29866 \begin_layout Itemize
29867 check for differences in printf parameters (some compilers push (va_arg
29868 \begin_inset LatexCommand \index{vararg, va\_arg}
29872 ) char variables as
29876 others push them as
29882 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29889 \begin_layout Itemize
29890 check the resulting memory map
29891 \begin_inset LatexCommand \index{Memory map}
29896 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
29897 ly idata, pdata, xdata).
29898 Eventually check if unexpected library functions are included.
29901 \begin_layout Section
29903 \begin_inset LatexCommand \index{Tools}
29907 included in the distribution
29910 \begin_layout Standard
29912 \begin_inset Tabular
29913 <lyxtabular version="3" rows="12" columns="3">
29915 <column alignment="left" valignment="top" leftline="true" width="0pt">
29916 <column alignment="left" valignment="top" leftline="true" width="0pt">
29917 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
29918 <row topline="true" bottomline="true">
29919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29922 \begin_layout Standard
29930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29933 \begin_layout Standard
29941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29944 \begin_layout Standard
29953 <row topline="true">
29954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29957 \begin_layout Standard
29959 \begin_inset LatexCommand \index{uCsim}
29968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29971 \begin_layout Standard
29972 Simulator for various architectures
29977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29980 \begin_layout Standard
29987 <row topline="true">
29988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29991 \begin_layout Standard
29997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30000 \begin_layout Standard
30002 \begin_inset LatexCommand \index{Header files}
30007 \begin_inset LatexCommand \index{Include files}
30016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30019 \begin_layout Standard
30020 sdcc/support/scripts
30026 <row topline="true">
30027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30030 \begin_layout Standard
30036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30039 \begin_layout Standard
30040 header file conversion
30045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30048 \begin_layout Standard
30049 sdcc/support/scripts
30055 <row topline="true">
30056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30059 \begin_layout Standard
30065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30068 \begin_layout Standard
30074 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30077 \begin_layout Standard
30093 <row topline="true">
30094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30097 \begin_layout Standard
30103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30106 \begin_layout Standard
30112 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30115 \begin_layout Standard
30131 <row topline="true">
30132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30135 \begin_layout Standard
30141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30144 \begin_layout Standard
30150 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30153 \begin_layout Standard
30169 <row topline="true">
30170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30173 \begin_layout Standard
30179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30182 \begin_layout Standard
30188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30191 \begin_layout Standard
30207 <row topline="true">
30208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30211 \begin_layout Standard
30217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30220 \begin_layout Standard
30226 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30229 \begin_layout Standard
30245 <row topline="true">
30246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30249 \begin_layout Standard
30255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30258 \begin_layout Standard
30264 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30267 \begin_layout Standard
30283 <row topline="true">
30284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30287 \begin_layout Standard
30293 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30296 \begin_layout Standard
30302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30305 \begin_layout Standard
30321 <row topline="true" bottomline="true">
30322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30325 \begin_layout Standard
30331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30334 \begin_layout Standard
30336 \begin_inset LatexCommand \index{packihx (tool)}
30345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30348 \begin_layout Standard
30373 \begin_layout Section
30375 \begin_inset LatexCommand \index{Documentation}
30379 included in the distribution
30382 \begin_layout Standard
30384 \begin_inset Tabular
30385 <lyxtabular version="3" rows="10" columns="2">
30387 <column alignment="block" valignment="top" leftline="true" width="40col%">
30388 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
30389 <row topline="true" bottomline="true" endhead="true">
30390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30393 \begin_layout Standard
30401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30404 \begin_layout Standard
30407 Filename / Where to get
30413 <row topline="true">
30414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30417 \begin_layout Standard
30418 SDCC Compiler User Guide
30423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30426 \begin_layout Standard
30427 You're reading it right now
30439 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
30449 <row topline="true">
30450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30453 \begin_layout Standard
30459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30462 \begin_layout Standard
30475 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
30485 <row topline="true">
30486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30489 \begin_layout Standard
30491 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
30496 \begin_inset LatexCommand \index{Assembler documentation}
30503 \begin_inset LatexCommand \index{aslink}
30508 \begin_inset LatexCommand \index{Linker documentation}
30517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30520 \begin_layout Standard
30521 sdcc/as/doc/asxhtm.html
30533 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
30543 <row topline="true">
30544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30547 \begin_layout Standard
30548 SDCC regression test
30549 \begin_inset LatexCommand \index{Regression test}
30558 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30561 \begin_layout Standard
30562 sdcc/doc/test_suite_spec.pdf
30574 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30584 <row topline="true">
30585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30588 \begin_layout Standard
30594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30597 \begin_layout Standard
30610 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
30620 <row topline="true">
30621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30624 \begin_layout Standard
30625 Notes on debugging with SDCDB
30626 \begin_inset LatexCommand \index{SDCDB (debugger)}
30635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30638 \begin_layout Standard
30639 sdcc/debugger/README
30651 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
30661 <row topline="true">
30662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30665 \begin_layout Standard
30667 \begin_inset LatexCommand \index{uCsim}
30671 Software simulator for microcontrollers
30676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30679 \begin_layout Standard
30709 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
30719 <row topline="true">
30720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30723 \begin_layout Standard
30724 Temporary notes on the pic16
30725 \begin_inset LatexCommand \index{PIC16}
30734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30737 \begin_layout Standard
30738 sdcc/src/pic16/NOTES
30750 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
30760 <row topline="true" bottomline="true">
30761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30764 \begin_layout Standard
30765 SDCC internal documentation (debugging file format)
30770 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30773 \begin_layout Standard
30803 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
30822 \begin_layout Section
30823 Related open source tools
30824 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
30829 \begin_inset LatexCommand \index{Related tools}
30836 \begin_layout Standard
30838 \begin_inset Tabular
30839 <lyxtabular version="3" rows="14" columns="3">
30841 <column alignment="left" valignment="top" leftline="true" width="0pt">
30842 <column alignment="block" valignment="top" leftline="true" width="30line%">
30843 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30844 <row topline="true" bottomline="true">
30845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30848 \begin_layout Standard
30856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30859 \begin_layout Standard
30867 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30870 \begin_layout Standard
30879 <row topline="true">
30880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30883 \begin_layout Standard
30885 \begin_inset LatexCommand \index{gpsim (pic simulator)}
30894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30897 \begin_layout Standard
30903 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30906 \begin_layout Standard
30907 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
30917 <row topline="true">
30918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30921 \begin_layout Standard
30923 \begin_inset LatexCommand \index{gputils (pic tools)}
30932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30935 \begin_layout Standard
30941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30944 \begin_layout Standard
30945 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
30955 <row topline="true">
30956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30959 \begin_layout Standard
30965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30968 \begin_layout Standard
30974 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30977 \begin_layout Standard
30978 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
30988 <row topline="true">
30989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30992 \begin_layout Standard
30998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31001 \begin_layout Standard
31002 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
31008 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31011 \begin_layout Standard
31012 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
31022 <row topline="true">
31023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31026 \begin_layout Standard
31028 \begin_inset LatexCommand \index{indent (source formatting tool)}
31037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31040 \begin_layout Standard
31041 Formats C source - Master of the white spaces
31046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31049 \begin_layout Standard
31050 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
31060 <row topline="true">
31061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31064 \begin_layout Standard
31066 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
31075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31078 \begin_layout Standard
31079 Object file conversion, checksumming, ...
31084 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31087 \begin_layout Standard
31088 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
31098 <row topline="true">
31099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31102 \begin_layout Standard
31104 \begin_inset LatexCommand \index{objdump (tool)}
31113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31116 \begin_layout Standard
31117 Object file conversion, ...
31122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31125 \begin_layout Standard
31126 Part of binutils (should be there anyway)
31132 <row topline="true">
31133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31136 \begin_layout Standard
31142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31145 \begin_layout Standard
31146 8051 monitor (hex up-/download, single step, disassemble)
31151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31154 \begin_layout Standard
31155 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
31165 <row topline="true">
31166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31169 \begin_layout Standard
31171 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
31180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31183 \begin_layout Standard
31184 Source code documentation system
31189 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31192 \begin_layout Standard
31193 \begin_inset LatexCommand \url{http://www.doxygen.org}
31203 <row topline="true">
31204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31207 \begin_layout Standard
31213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31216 \begin_layout Standard
31217 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
31222 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31225 \begin_layout Standard
31226 \begin_inset LatexCommand \url{http://www.kdevelop.org}
31236 <row topline="true">
31237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31240 \begin_layout Standard
31246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31249 \begin_layout Standard
31250 8051 monitor (hex up-/download, single step, disassemble)
31255 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31258 \begin_layout Standard
31259 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
31269 <row topline="true">
31270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31273 \begin_layout Standard
31275 \begin_inset LatexCommand \index{splint (syntax checking tool)}
31284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31287 \begin_layout Standard
31288 Statically checks c sources (see
31289 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
31298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31301 \begin_layout Standard
31302 \begin_inset LatexCommand \url{http://www.splint.org}
31312 <row topline="true" bottomline="true">
31313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31316 \begin_layout Standard
31318 \begin_inset LatexCommand \index{DDD (debugger)}
31327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31330 \begin_layout Standard
31331 Debugger, serves nicely as GUI to SDCDB
31332 \begin_inset LatexCommand \index{SDCDB (debugger)}
31341 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31344 \begin_layout Standard
31345 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
31364 \begin_layout Section
31365 Related documentation / recommended reading
31368 \begin_layout Standard
31370 \begin_inset Tabular
31371 <lyxtabular version="3" rows="7" columns="3">
31373 <column alignment="left" valignment="top" leftline="true" width="0pt">
31374 <column alignment="left" valignment="top" leftline="true" width="0">
31375 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
31376 <row topline="true" bottomline="true">
31377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31380 \begin_layout Standard
31388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31391 \begin_layout Standard
31399 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31402 \begin_layout Standard
31411 <row topline="true">
31412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31415 \begin_layout Standard
31430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31433 \begin_layout Standard
31435 \begin_inset LatexCommand \index{C Reference card}
31444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31447 \begin_layout Standard
31448 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
31458 <row topline="true">
31459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31462 \begin_layout Standard
31468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31471 \begin_layout Standard
31473 \begin_inset LatexCommand \index{C FAQ}
31482 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31485 \begin_layout Standard
31486 \begin_inset LatexCommand \url{http://www.c-faq.com}
31496 <row topline="true">
31497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31500 \begin_layout Standard
31506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31509 \begin_layout Standard
31510 \begin_inset Quotes sld
31514 \begin_inset Quotes srd
31522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31525 \begin_layout Standard
31528 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
31538 <row topline="true">
31539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31542 \begin_layout Standard
31548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31551 \begin_layout Standard
31552 \begin_inset Quotes sld
31555 Extensions for Embedded C
31556 \begin_inset Quotes srd
31564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31567 \begin_layout Standard
31570 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
31580 <row topline="true">
31581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31584 \begin_layout Standard
31590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31593 \begin_layout Standard
31594 Latest datasheet of target CPU
31599 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31602 \begin_layout Standard
31609 <row topline="true" bottomline="true">
31610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31613 \begin_layout Standard
31619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31622 \begin_layout Standard
31623 Revision history of datasheet
31628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31631 \begin_layout Standard
31647 \begin_layout Section
31648 Application notes specifically for SDCC
31651 \begin_layout Standard
31652 SDCC makes no claims about the completeness of this list and about up-to-datenes
31653 s or correctness of the application notes
31654 \begin_inset LatexCommand \index{Application notes}
31661 \begin_layout Standard
31665 \begin_inset Tabular
31666 <lyxtabular version="3" rows="7" columns="3">
31668 <column alignment="block" valignment="top" leftline="true" width="17col%">
31669 <column alignment="block" valignment="top" leftline="true" width="27col%">
31670 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
31671 <row topline="true" bottomline="true">
31672 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31675 \begin_layout Standard
31684 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
31687 \begin_layout Standard
31696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31699 \begin_layout Standard
31709 <row topline="true">
31710 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31713 \begin_layout Standard
31721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31724 \begin_layout Standard
31727 Using the SDCC Compiler for the DS80C400
31728 \begin_inset LatexCommand \index{DS80C400}
31737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31740 \begin_layout Standard
31743 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
31753 <row topline="true">
31754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31757 \begin_layout Standard
31765 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
31768 \begin_layout Standard
31771 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
31772 \begin_inset LatexCommand \index{DS89C4x0}
31776 Family of Microcontrollers
31781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31784 \begin_layout Standard
31787 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
31797 <row topline="true">
31798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31801 \begin_layout Standard
31804 Silicon Laboratories / Cygnal
31809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31812 \begin_layout Standard
31815 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
31816 \begin_inset LatexCommand \index{IDE}
31825 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31828 \begin_layout Standard
31831 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
31841 <row topline="true">
31842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31845 \begin_layout Standard
31848 Ramtron / Goal Semiconductor
31853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31856 \begin_layout Standard
31859 Interfacing SDCC to Syn and Textpad
31864 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31867 \begin_layout Standard
31870 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31880 <row topline="true">
31881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31884 \begin_layout Standard
31887 Ramtron / Goal Semiconductor
31892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31895 \begin_layout Standard
31898 Installing and Configuring SDCC and Crimson Editor
31903 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31906 \begin_layout Standard
31909 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31919 <row topline="true" bottomline="true">
31920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31923 \begin_layout Standard
31931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31934 \begin_layout Standard
31937 MSC12xx Programming with SDCC
31942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31945 \begin_layout Standard
31948 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
31965 \begin_layout Section
31969 \begin_layout Standard
31970 Some questions answered, some pointers given - it might be time to in turn
31978 \begin_layout Itemize
31979 can you solve your project with the selected microcontroller? Would you
31980 find out early or rather late that your target is too small/slow/whatever?
31981 Can you switch to a slightly better device if it doesn't fit?
31984 \begin_layout Itemize
31985 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
31986 and/or another programming language be more adequate? Would an operating
31987 system on the target device help?
31990 \begin_layout Itemize
31991 if you solved the problem, will the marketing department be happy?
31994 \begin_layout Itemize
31995 if the marketing department is happy, will customers be happy?
31998 \begin_layout Itemize
31999 if you're the project manager, marketing department and maybe even the customer
32000 in one person, have you tried to see the project from the outside?
32003 \begin_layout Itemize
32004 is the project done if you think it is done? Or is just that other interface/pro
32005 tocol/feature/configuration/option missing? How about website, manual(s),
32006 internationali(z|s)ation, packaging, labels, 2nd source for components,
32007 electromagnetic compatability/interference, documentation for production,
32008 production test software, update mechanism, patent issues?
32011 \begin_layout Itemize
32012 is your project adequately positioned in that magic triangle: fame, fortune,
32016 \begin_layout Standard
32017 Maybe not all answers to these questions are known and some answers may
32022 , nevertheless knowing these questions may help you to avoid burnout
32026 \begin_layout Standard
32027 burnout is bad for electronic devices, programmers and motorcycle tyres
32033 Chances are you didn't want to hear some of them...
32036 \begin_layout Chapter
32038 \begin_inset LatexCommand \index{Support}
32045 \begin_layout Standard
32046 SDCC has grown to be a large project.
32047 The compiler alone (without the preprocessor, assembler and linker) is
32048 well over 150,000 lines of code (blank stripped).
32049 The open source nature of this project is a key to its continued growth
32051 You gain the benefit and support of many active software developers and
32053 Is SDCC perfect? No, that's why we need your help.
32054 The developers take pride in fixing reported bugs.
32055 You can help by reporting the bugs and helping other SDCC users.
32056 There are lots of ways to contribute, and we encourage you to take part
32057 in making SDCC a great software package.
32061 \begin_layout Standard
32062 The SDCC project is hosted on the SDCC sourceforge site at
32063 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
32068 You'll find the complete set of mailing lists
32069 \begin_inset LatexCommand \index{Mailing list(s)}
32073 , forums, bug reporting system, patch submission
32074 \begin_inset LatexCommand \index{Patch submission}
32079 \begin_inset LatexCommand \index{download}
32083 area and Subversion code repository
32084 \begin_inset LatexCommand \index{Subversion code repository}
32091 \begin_layout Section
32093 \begin_inset LatexCommand \index{Bug reporting}
32098 \begin_inset LatexCommand \index{Reporting bugs}
32105 \begin_layout Standard
32106 The recommended way of reporting bugs is using the infrastructure of the
32108 You can follow the status of bug reports there and have an overview about
32112 \begin_layout Standard
32113 Bug reports are automatically forwarded to the developer mailing list and
32114 will be fixed ASAP.
32115 When reporting a bug, it is very useful to include a small test program
32116 (the smaller the better) which reproduces the problem.
32117 If you can isolate the problem by looking at the generated assembly code,
32118 this can be very helpful.
32119 Compiling your program with the -
32123 \begin_layout Standard
32133 \begin_inset LatexCommand \index{-\/-dumpall}
32137 option can sometimes be useful in locating optimization problems.
32138 When reporting a bug please make sure you:
32141 \begin_layout Enumerate
32142 Attach the code you are compiling with SDCC.
32146 \begin_layout Enumerate
32147 Specify the exact command you use to run SDCC, or attach your Makefile.
32151 \begin_layout Enumerate
32152 Specify the SDCC version (type "
32158 "), your platform, and operating system.
32162 \begin_layout Enumerate
32163 Provide an exact copy of any error message or incorrect output.
32167 \begin_layout Enumerate
32168 Put something meaningful in the subject of your message.
32171 \begin_layout Standard
32172 Please attempt to include these 5 important parts, as applicable, in all
32173 requests for support or when reporting any problems or bugs with SDCC.
32174 Though this will make your message lengthy, it will greatly improve your
32175 chance that SDCC users and developers will be able to help you.
32176 Some SDCC developers are frustrated by bug reports without code provided
32177 that they can use to reproduce and ultimately fix the problem, so please
32178 be sure to provide sample code if you are reporting a bug!
32181 \begin_layout Standard
32182 Please have a short check that you are using a recent version of SDCC and
32183 the bug is not yet known.
32184 This is the link for reporting bugs:
32185 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
32190 With SDCC on average having more than 200 downloads
32191 \begin_inset LatexCommand \index{download}
32195 on sourceforge per day
32199 \begin_layout Standard
32200 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
32201 between 2002 and 2005.
32202 This does not include other methods of distribution.
32207 there must be some users.
32208 So it's not exactly easy to find a new bug.
32209 If you find one we need it:
32211 reporting bugs is good
32216 \begin_layout Section
32217 Requesting Features
32218 \begin_inset LatexCommand \label{sub:Requesting-Features}
32223 \begin_inset LatexCommand \index{Feature request}
32228 \begin_inset LatexCommand \index{Requesting features}
32235 \begin_layout Standard
32236 Like bug reports feature requests are forwarded to the developer mailing
32238 This is the link for requesting features:
32239 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32246 \begin_layout Section
32250 \begin_layout Standard
32251 Like bug reports contributed patches are forwarded to the developer mailing
32253 This is the link for submitting patches
32254 \begin_inset LatexCommand \index{Patch submission}
32259 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
32266 \begin_layout Standard
32267 You need to specify some parameters to the
32271 command for the patches to be useful.
32272 If you modified more than one file a patch created f.e.
32277 \begin_inset Quotes sld
32280 diff -Naur unmodified_directory modified_directory >my_changes.patch
32281 \begin_inset Quotes srd
32287 will be fine, otherwise
32291 \begin_inset Quotes sld
32294 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
32295 \begin_inset Quotes srd
32305 \begin_layout Section
32309 \begin_layout Standard
32310 These links should take you directly to the
32311 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
32319 \begin_layout Standard
32320 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
32321 automated messages (mid 2003)
32327 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
32332 \begin_inset LatexCommand \index{Mailing list(s)}
32336 and forums are archived and searchable so if you are lucky someone already
32337 had a similar problem.
32338 While mails to the lists themselves are delivered promptly their web front
32339 end on sourceforge sometimes shows a severe time lag (up to several weeks),
32340 if you're seriously using SDCC please consider subscribing to the lists.
32343 \begin_layout Section
32347 \begin_layout Standard
32348 You can follow the status of the Subversion version
32349 \begin_inset LatexCommand \index{version}
32353 of SDCC by watching the Changelog
32354 \begin_inset LatexCommand \index{Changelog}
32358 in the Subversion repository
32361 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
32368 \begin_layout Section
32369 Subversion Source Code Repository
32372 \begin_layout Standard
32382 \begin_layout Standard
32396 or the filenames of the snapshot versions of SDCC include date and its
32398 \begin_inset LatexCommand \index{Subversion code repository}
32403 Subversion allows to download the source of recent or previous versions
32405 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
32409 (by number or by date).
32410 An on-line source code browser and detailled instructions are also available
32412 SDCC versions starting from 1999 up to now are available (currently the
32413 versions prior to the conversion from cvs
32414 \begin_inset LatexCommand \index{cvs|see{Subversion}}
32418 to Subversion (April 2006) are either by accessible by Subversion or by
32422 \begin_layout Section
32424 \begin_inset LatexCommand \index{Release policy}
32431 \begin_layout Standard
32432 Historically there often were long delays between official releases and
32433 the sourceforge download area tends to get not updated at all.
32434 Excuses in the past might have referred to problems with live range analysis,
32435 but as this was fixed a while ago, the current problem is that another
32436 excuse has to be found.
32437 Kidding aside, we have to get better there! On the other hand there are
32438 daily snapshots available at
32439 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
32443 , and you can always build the very last version (hopefully with many bugs
32444 fixed, and features added) from the source code available at
32445 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
32451 \begin_inset LatexCommand \index{wiki}
32456 \begin_inset LatexCommand \index{Release wiki}
32461 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
32465 also holds some information about past and future releases.
32468 \begin_layout Section
32470 \begin_inset LatexCommand \index{Examples}
32477 \begin_layout Standard
32478 You'll find some small examples in the directory
32480 sdcc/device/examples/.
32483 More examples and libraries are available at
32485 The SDCC Open Knowledge Resource
32486 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
32493 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
32500 \begin_layout Standard
32501 \begin_inset Note Note
32504 \begin_layout Standard
32505 I did insert a reference to Paul's web site here although it seems rather
32506 dedicated to a specific 8032 board (I think it's okay because it f.e.
32507 shows LCD/Harddisc interface and has a free 8051 monitor.
32508 Independent 8032 board vendors face hard competition of heavily subsidized
32509 development boards anyway).
32512 \begin_layout Standard
32513 Maybe we should include some links to real world applications.
32514 Preferably pointer to pointers (one for each architecture) so this stays
32523 \begin_layout Section
32525 \begin_inset LatexCommand \label{sec:Quality-control}
32530 \begin_inset LatexCommand \index{Quality control}
32537 \begin_layout Standard
32538 The compiler is passed through snaphot build compile and build checks.
32544 \begin_inset LatexCommand \index{Regression test}
32548 check that SDCC itself compiles flawlessly on several host platforms (i386,
32549 Opteron, 64 bit Alpha, ppc64, Mac OS X on PPC, Solaris on Sparc) and checks
32550 the quality of the code generated by SDCC by running the code for several
32551 target platforms through simulators.
32552 The regression test suite comprises more than 100 files which expand to
32553 more than 500 test cases which include more than 4500 tests.
32554 The results of these tests are published daily on SDCC's snapshot page
32555 (click on the red or green symbols on the right side of
32556 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
32563 \begin_layout Standard
32564 There is a separate document
32567 \begin_inset LatexCommand \index{Test suite}
32574 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
32578 about the regression test suite.
32581 \begin_layout Standard
32582 You'll find the test code in the directory
32584 sdcc/support/regression
32587 You can run these tests manually by running
32591 in this directory (or f.e.
32596 \begin_inset Quotes sld
32600 \begin_inset Quotes srd
32606 if you don't want to run the complete tests).
32607 The test code might also be interesting if you want to look for examples
32608 \begin_inset LatexCommand \index{Examples}
32612 checking corner cases of SDCC or if you plan to submit patches
32613 \begin_inset LatexCommand \index{Patch submission}
32620 \begin_layout Standard
32621 The PIC14 port uses a different set of regression tests
32622 \begin_inset LatexCommand \index{Regression test (PIC14)}
32626 , you'll find them in the directory
32628 sdcc/src/regression
32633 \begin_layout Section
32634 Use of SDCC in Education
32637 \begin_layout Standard
32646 \begin_layout Standard
32647 the phrase "use in education" might evoke the association "
32651 fit for use in education".
32652 This connotation is not intended but nevertheless risked as the licensing
32653 of SDCC makes it difficult to offer educational discounts
32659 If your rationales are to:
32662 \begin_layout Enumerate
32663 give students a chance to understand the
32667 steps of code generation
32670 \begin_layout Enumerate
32671 have a curriculum that can be extended for years.
32672 Then you could use an fpga board as target and your curriculum will seamlessly
32673 extend from logic synthesis (
32674 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
32679 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
32683 ), over assembly programming, to C to FPGA compilers (
32684 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
32691 \begin_layout Enumerate
32692 be able to insert excursions about skills like using a revision control
32693 system, submitting/applying patches, using a type-setting (as opposed to
32694 word-processing) engine LyX/LaTeX, using
32695 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
32700 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
32704 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
32705 Source Software, CPU simulation, compiler regression tests
32706 \begin_inset LatexCommand \index{Regression test}
32713 And if there should be a shortage of ideas then you can always point students
32714 to the ever-growing feature request list
32715 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32722 \begin_layout Enumerate
32723 not tie students to a specific host platform and instead allow them to use
32728 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
32730 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
32737 \begin_layout Enumerate
32738 not encourage students to use illegal copies of educational software
32741 \begin_layout Enumerate
32742 be immune to licensing/availability/price changes of the chosen tool chain
32745 \begin_layout Enumerate
32746 be able to change to a new target platform without having to adopt a new
32750 \begin_layout Enumerate
32751 have complete control over and insight into the tool chain
32754 \begin_layout Enumerate
32755 make your students aware about the pros and cons of open source software
32759 \begin_layout Enumerate
32760 give back to the public as you are probably at least partially publically
32764 \begin_layout Enumerate
32765 give students a chance to publically prove their skills and to possibly
32766 see a world wide impact
32769 \begin_layout Standard
32770 then SDCC is probably among the first choices.
32771 Well, probably SDCC might be the only choice.
32776 \begin_layout Chapter
32777 SDCC Technical Data
32780 \begin_layout Section
32782 \begin_inset LatexCommand \index{Optimizations}
32789 \begin_layout Standard
32790 SDCC performs a host of standard optimizations in addition to some MCU specific
32795 \begin_layout Subsection
32796 Sub-expression Elimination
32797 \begin_inset LatexCommand \index{Subexpression elimination}
32804 \begin_layout Standard
32805 The compiler does local and
32824 \begin_layout Verse
32832 \begin_layout Standard
32833 will be translated to
32836 \begin_layout Verse
32846 \begin_layout Standard
32847 Some subexpressions are not as obvious as the above example, e.g.:
32850 \begin_layout Verse
32858 \begin_layout Standard
32859 In this case the address arithmetic a->b[i] will be computed only once;
32860 the equivalent code in C would be.
32863 \begin_layout Verse
32873 \begin_layout Standard
32874 The compiler will try to keep these temporary variables in registers.
32877 \begin_layout Subsection
32878 Dead-Code Elimination
32879 \begin_inset LatexCommand \index{Dead-code elimination}
32886 \begin_layout Verse
32901 i = 1; \InsetSpace ~
32910 global = 1;\InsetSpace ~
32924 global = 3;\InsetSpace ~
32930 \begin_layout Standard
32934 \begin_layout Verse
32950 \begin_layout Subsection
32952 \begin_inset LatexCommand \index{Copy propagation}
32959 \begin_layout Verse
32983 \begin_layout Standard
32987 \begin_layout Verse
33011 \begin_layout Standard
33012 Note: the dead stores created by this copy propagation will be eliminated
33013 by dead-code elimination.
33016 \begin_layout Subsection
33018 \begin_inset LatexCommand \index{Loop optimization}
33023 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
33030 \begin_layout Standard
33031 Two types of loop optimizations are done by SDCC
33039 of loop induction variables.
33040 In addition to the strength reduction the optimizer marks the induction
33041 variables and the register allocator tries to keep the induction variables
33042 in registers for the duration of the loop.
33043 Because of this preference of the register allocator
33044 \begin_inset LatexCommand \index{Register allocation}
33048 , loop induction optimization causes an increase in register pressure, which
33049 may cause unwanted spilling of other temporary variables into the stack
33050 \begin_inset LatexCommand \index{stack}
33055 The compiler will generate a warning message when it is forced to allocate
33056 extra space either on the stack or data space.
33057 If this extra space allocation is undesirable then induction optimization
33058 can be eliminated either for the entire source file (with -
33062 \begin_layout Standard
33071 -noinduction option) or for a given function only using #pragma\InsetSpace ~
33073 \begin_inset LatexCommand \index{\#pragma noinduction}
33084 \begin_layout Verse
33087 for (i = 0 ; i < 100 ; i ++)
33096 \begin_layout Standard
33100 \begin_layout Verse
33105 for (i = 0; i < 100; i++)
33114 \begin_layout Standard
33115 As mentioned previously some loop invariants are not as apparent, all static
33116 address computations are also moved out of the loop.
33121 \begin_inset LatexCommand \index{Strength reduction}
33125 , this optimization substitutes an expression by a cheaper expression:
33128 \begin_layout Verse
33131 for (i=0;i < 100; i++)
33140 \begin_layout Standard
33144 \begin_layout Verse
33151 for (i=0;i< 100;i++) {
33157 ar[itemp1] = itemp2;
33175 \begin_layout Standard
33176 The more expensive multiplication
33177 \begin_inset LatexCommand \index{Multiplication}
33181 is changed to a less expensive addition.
33184 \begin_layout Subsection
33186 \begin_inset LatexCommand \index{Loop reversing}
33193 \begin_layout Standard
33194 This optimization is done to reduce the overhead of checking loop boundaries
33195 for every iteration.
33196 Some simple loops can be reversed and implemented using a
33197 \begin_inset Quotes eld
33200 decrement and jump if not zero
33201 \begin_inset Quotes erd
33205 SDCC checks for the following criterion to determine if a loop is reversible
33206 (note: more sophisticated compilers use data-dependency analysis to make
33207 this determination, SDCC uses a more simple minded analysis).
33210 \begin_layout Itemize
33211 The 'for' loop is of the form
33217 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
33227 \begin_layout Itemize
33228 The <for body> does not contain
33229 \begin_inset Quotes eld
33233 \begin_inset Quotes erd
33237 \begin_inset Quotes erd
33243 \begin_layout Itemize
33244 All goto's are contained within the loop.
33247 \begin_layout Itemize
33248 No function calls within the loop.
33251 \begin_layout Itemize
33252 The loop control variable <sym> is not assigned any value within the loop
33255 \begin_layout Itemize
33256 The loop control variable does NOT participate in any arithmetic operation
33260 \begin_layout Itemize
33261 There are NO switch statements in the loop.
33264 \begin_layout Subsection
33265 Algebraic Simplifications
33268 \begin_layout Standard
33269 SDCC does numerous algebraic simplifications, the following is a small sub-set
33270 of these optimizations.
33273 \begin_layout Verse
33276 i = j + 0;\InsetSpace ~
33280 /* changed to: */\InsetSpace ~
33286 i /= 2;\InsetSpace ~
33293 /* changed to: */\InsetSpace ~
33300 = j - j;\InsetSpace ~
33304 /* changed to: */\InsetSpace ~
33310 i = j / 1;\InsetSpace ~
33314 /* changed to: */\InsetSpace ~
33321 \begin_layout Standard
33322 Note the subexpressions
33323 \begin_inset LatexCommand \index{Subexpression}
33327 given above are generally introduced by macro expansions or as a result
33328 of copy/constant propagation.
33331 \begin_layout Subsection
33332 'switch' Statements
33333 \begin_inset LatexCommand \label{sub:'switch'-Statements}
33338 \begin_inset LatexCommand \index{switch statement}
33345 \begin_layout Standard
33346 SDCC can optimize switch statements to jump tables
33347 \begin_inset LatexCommand \index{jump tables}
33352 It makes the decision based on an estimate of the generated code size.
33353 SDCC is quite liberal in the requirements for jump table generation:
33356 \begin_layout Itemize
33357 The labels need not be in order, and the starting number need not be one
33358 or zero, the case labels are in numerical sequence or not too many case
33359 labels are missing.
33363 \begin_layout Verse
33366 switch(i) {\InsetSpace ~
33397 case 4: ...\InsetSpace ~
33429 case 5: ...\InsetSpace ~
33461 case 3: ...\InsetSpace ~
33492 case 6: ...\InsetSpace ~
33524 case 7: ...\InsetSpace ~
33556 case 8: ...\InsetSpace ~
33588 case 9: ...\InsetSpace ~
33620 case 10: ...\InsetSpace ~
33651 case 11: ...\InsetSpace ~
33718 \begin_layout Standard
33719 Both the above switch statements will be implemented using a jump-table.
33720 The example to the right side is slightly more efficient as the check for
33721 the lower boundary of the jump-table is not needed.
33725 \begin_layout Itemize
33726 The number of case labels is not larger than supported by the target architectur
33730 \begin_layout Itemize
33731 If the case labels are not in numerical sequence ('gaps' between cases)
33732 SDCC checks whether a jump table with additionally inserted dummy cases
33733 is still attractive.
33737 \begin_layout Itemize
33738 If the starting number is not zero and a check for the lower boundary of
33739 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
33744 \begin_layout Standard
33745 Switch statements which have large gaps in the numeric sequence or those
33746 that have too many case labels can be split into more than one switch statement
33747 for efficient code generation, e.g.:
33750 \begin_layout Verse
33828 \begin_layout Standard
33829 If the above switch statement is broken down into two switch statements
33832 \begin_layout Verse
33875 \begin_layout Standard
33879 \begin_layout Verse
33922 \begin_layout Standard
33923 then both the switch statements will be implemented using jump-tables whereas
33924 the unmodified switch statement will not be.
33927 \begin_layout Standard
33928 \begin_inset Note Note
33931 \begin_layout Standard
33932 There might be reasons which SDCC cannot know about to either favour or
33933 not favour jump tables.
33934 If the target system has to be as quick for the last switch case as for
33935 the first (pro jump table), or if the switch argument is known to be zero
33936 in the majority of the cases (contra jump table).
33944 \begin_layout Standard
33945 The pragma nojtbound
33946 \begin_inset LatexCommand \index{\#pragma nojtbound}
33950 can be used to turn off checking the
33963 It has no effect if a default label is supplied.
33964 Use of this pragma is dangerous: if the switch
33965 \begin_inset LatexCommand \index{switch statement}
33969 argument is not matched by a case statement the processor will happily
33973 \begin_layout Subsection
33974 Bit-shifting Operations
33975 \begin_inset LatexCommand \index{Bit shifting}
33982 \begin_layout Standard
33983 Bit shifting is one of the most frequently used operation in embedded programmin
33985 SDCC tries to implement bit-shift operations in the most efficient way
33989 \begin_layout Verse
34002 \begin_layout Standard
34003 generates the following code:
34006 \begin_layout Verse
34021 \begin_layout Standard
34022 In general SDCC will never setup a loop if the shift count is known.
34026 \begin_layout Verse
34039 \begin_layout Standard
34043 \begin_layout Verse
34067 \begin_layout Subsection
34069 \begin_inset LatexCommand \index{Bit rotation}
34076 \begin_layout Standard
34077 A special case of the bit-shift operation is bit rotation
34078 \begin_inset LatexCommand \index{rotating bits}
34082 , SDCC recognizes the following expression to be a left bit-rotation:
34085 \begin_layout Verse
34093 char i;\InsetSpace ~
34104 /* unsigned is needed for rotation */
34109 i = ((i << 1) | (i >> 7));
34118 \begin_layout Standard
34119 will generate the following code:
34122 \begin_layout Verse
34139 \begin_layout Standard
34140 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
34141 ns of this case will also be recognized as bit-rotation, i.e.:
34144 \begin_layout Verse
34147 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
34150 \begin_layout Subsection
34151 Nibble and Byte Swapping
34154 \begin_layout Standard
34155 Other special cases of the bit-shift operations are nibble or byte swapping
34156 \begin_inset LatexCommand \index{swapping nibbles/bytes}
34160 , SDCC recognizes the following expressions:
34163 \begin_layout Verse
34184 i = ((i << 4) | (i >> 4));
34190 j = ((j << 8) | (j >> 8));
34193 \begin_layout Standard
34194 and generates a swap instruction for the nibble swapping
34195 \begin_inset LatexCommand \index{Nibble swapping}
34199 or move instructions for the byte swapping
34200 \begin_inset LatexCommand \index{Byte swapping}
34206 \begin_inset Quotes sld
34210 \begin_inset Quotes srd
34213 example can be used to convert from little to big-endian or vice versa.
34214 If you want to change the endianness of a
34218 integer you have to cast to
34225 \begin_layout Standard
34226 Note that SDCC stores numbers in little-endian
34230 \begin_layout Standard
34231 Usually 8-bit processors don't care much about endianness.
34232 This is not the case for the standard 8051 which only has an instruction
34238 \begin_inset LatexCommand \index{DPTR}
34246 so little-endian is the more efficient byte order.
34252 \begin_inset LatexCommand \index{little-endian}
34257 \begin_inset LatexCommand \index{Endianness}
34262 lowest order first).
34265 \begin_layout Subsection
34267 \begin_inset LatexCommand \index{Highest Order Bit}
34272 \begin_inset LatexCommand \index{Any Order Bit}
34279 \begin_layout Standard
34280 It is frequently required to obtain the highest order bit of an integral
34281 type (long, int, short or char types).
34282 Also obtaining any other order bit is not uncommon.
34283 SDCC recognizes the following expressions to yield the highest order bit
34284 and generates optimized code for it, e.g.:
34287 \begin_layout Verse
34298 unsigned char hob1, aob1;
34302 bit hob2, hob3, aob2,
34312 hob1 = (gint >> 15) & 1;
34316 hob2 = (gint >> 15) & 1;
34320 hob3 = gint & 0x8000;
34325 aob1 = (gint >> 9) & 1;
34329 aob2 = (gint >> 8) & 1;
34333 aob3 = gint & 0x0800;
34343 \begin_layout Standard
34344 will generate the following code:
34347 \begin_layout Verse
34378 000A E5*01\InsetSpace ~
34405 000C 23\InsetSpace ~
34436 000D 54 01\InsetSpace ~
34464 000F F5*02\InsetSpace ~
34519 0011 E5*01\InsetSpace ~
34547 0013 33\InsetSpace ~
34577 0014 92*00\InsetSpace ~
34633 0016 E5*01\InsetSpace ~
34660 0018 33\InsetSpace ~
34690 0019 92*01\InsetSpace ~
34746 001B E5*01\InsetSpace ~
34805 001E 54 01\InsetSpace ~
34832 0020 F5*03\InsetSpace ~
34888 0022 E5*01\InsetSpace ~
34915 0024 13\InsetSpace ~
34945 0025 92*02\InsetSpace ~
35001 0027 E5*01\InsetSpace ~
35056 002B 92*03\InsetSpace ~
35084 \begin_layout Standard
35085 Other variations of these cases however will
35090 They are standard C expressions, so I heartily recommend these be the only
35091 way to get the highest order bit, (it is portable).
35092 Of course it will be recognized even if it is embedded in other expressions,
35096 \begin_layout Verse
35099 xyz = gint + ((gint >> 15) & 1);
35102 \begin_layout Standard
35103 will still be recognized.
35106 \begin_layout Subsection
35108 \begin_inset LatexCommand \index{Higher Order Byte}
35112 / Higher Order Word
35113 \begin_inset LatexCommand \index{Higher Order Word}
35120 \begin_layout Standard
35121 It is also frequently required to obtain a higher order byte or word of
35122 a larger integral type (long, int or short types).
35123 SDCC recognizes the following expressions to yield the higher order byte
35124 or word and generates optimized code for it, e.g.:
35127 \begin_layout Verse
35132 unsigned long int glong;
35140 unsigned char hob1,
35145 unsigned int how1, how2;
35154 hob1 = (gint >> 8) & 0xFF;
35158 hob2 = glong >> 24;
35162 how1 = (glong >> 16) & 0xFFFF;
35177 \begin_layout Standard
35178 will generate the following code:
35181 \begin_layout Verse
35212 0037 85*01*06\InsetSpace ~
35234 _foo_hob1_1_1,(_gint + 1)
35265 003A 85*05*07\InsetSpace ~
35287 _foo_hob2_1_1,(_glong + 3)
35317 003D 85*04*08\InsetSpace ~
35340 _foo_how1_1_1,(_glong + 2)
35342 0040 85*05*09\InsetSpace ~
35367 0043 85*03*0A\InsetSpace ~
35389 _foo_how2_1_1,(_glong + 1)
35391 0046 85*04*0B\InsetSpace ~
35414 (_foo_how2_1_1 + 1),(_glong + 2)
35417 \begin_layout Standard
35418 Again, variations of these cases may
35423 They are standard C expressions, so I heartily recommend these be the only
35424 way to get the higher order byte/word, (it is portable).
35425 Of course it will be recognized even if it is embedded in other expressions,
35429 \begin_layout Verse
35432 xyz = gint + ((gint >> 8) & 0xFF);
35435 \begin_layout Standard
35436 will still be recognized.
35439 \begin_layout Subsection
35441 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
35446 \begin_inset LatexCommand \index{Peephole optimizer}
35453 \begin_layout Standard
35454 The compiler uses a rule based, pattern matching and re-writing mechanism
35455 for peep-hole optimization.
35460 a peep-hole optimizer by Christopher W.
35461 Fraser (cwfraser\InsetSpace ~
35464 A default set of rules are compiled into the compiler, additional rules
35465 may be added with the
35471 \begin_layout Standard
35481 \begin_inset LatexCommand \index{-\/-peep-file}
35488 The rule language is best illustrated with examples.
35491 \begin_layout Verse
35513 \begin_layout Standard
35514 The above rule will change the following assembly
35515 \begin_inset LatexCommand \index{Assembler routines}
35522 \begin_layout Verse
35530 \begin_layout Standard
35534 \begin_layout Verse
35540 \begin_layout Standard
35541 Note: All occurrences of a
35545 (pattern variable) must denote the same string.
35546 With the above rule, the assembly sequence:
35549 \begin_layout Verse
35557 \begin_layout Standard
35558 will remain unmodified.
35562 Other special case optimizations may be added by the
35569 \begin_layout Standard
35582 some variants of the 8051 MCU
35583 \begin_inset LatexCommand \index{MCS51 variants}
35596 The following two rules will change all
35613 \begin_layout Verse
35616 replace { lcall %1 } by { acall %1 }
35618 replace { ljmp %1 } by { ajmp %1 }
35621 \begin_layout Standard
35624 inline-assembler code
35626 is also passed through the peep hole optimizer, thus the peephole optimizer
35627 can also be used as an assembly level macro expander.
35628 The rules themselves are MCU dependent whereas the rule language infra-structur
35629 e is MCU independent.
35630 Peephole optimization rules for other MCU can be easily programmed using
35635 The syntax for a rule is as follows:
35638 \begin_layout Verse
35641 rule := replace [ restart ] '{' <assembly sequence> '
35679 <assembly sequence> '
35697 '}' [if <functionName> ] '
35702 \begin_layout Standard
35703 <assembly sequence> := assembly instruction (each instruction including
35704 labels must be on a separate line).
35708 The optimizer will apply to the rules
35709 one by one from the top in the sequence of their appearance, it will terminate
35710 when all rules are exhausted.
35711 If the 'restart' option is specified, then the optimizer will start matching
35712 the rules again from the top, this option for a rule is expensive (performance)
35713 , it is intended to be used in situations where a transformation will trigger
35714 the same rule again.
35715 An example of this (not a good one, it has side effects) is the following
35719 \begin_layout Verse
35739 \begin_layout Standard
35740 Note that the replace pattern cannot be a blank, but can be a comment line.
35741 Without the 'restart' option only the innermost 'pop' 'push' pair would
35742 be eliminated, i.e.:
35745 \begin_layout Verse
35757 \begin_layout Standard
35761 \begin_layout Verse
35771 \begin_layout Standard
35776 the restart option the rule will be applied again to the resulting code
35777 and then all the pop-push pairs will be eliminated to yield:
35780 \begin_layout Verse
35788 \begin_layout Standard
35789 A conditional function can be attached to a rule.
35790 Attaching rules are somewhat more involved, let me illustrate this with
35794 \begin_layout Verse
35818 \begin_layout Standard
35819 The optimizer does a look-up of a function name table defined in function
35824 in the source file SDCCpeeph.c, with the name
35829 If it finds a corresponding entry the function is called.
35830 Note there can be no parameters specified for these functions, in this
35835 is crucial, since the function
35839 expects to find the label in that particular variable (the hash table containin
35840 g the variable bindings is passed as a parameter).
35841 If you want to code more such functions, take a close look at the function
35842 labelInRange and the calling mechanism in source file SDCCpeeph.c.
35843 Currently implemented are
35845 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
35846 24bitMode, portIsDS390, 24bitModeAndPortDS390
35855 \begin_layout Standard
35856 I know this whole thing is a little kludgey, but maybe some day we will
35857 have some better means.
35858 If you are looking at this file, you will see the default rules that are
35859 compiled into the compiler, you can add your own rules in the default set
35860 there if you get tired of specifying the -
35864 \begin_layout Standard
35876 \begin_layout Section
35878 \begin_inset LatexCommand \index{ANSI-compliance}
35883 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
35890 \begin_layout Standard
35891 The latest publically available version of the standard
35893 ISO/IEC 9899 - Programming languages - C
35895 should be available at:
35896 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
35905 \begin_layout Standard
35906 Deviations from the compliance:
35909 \begin_layout Itemize
35910 functions are not reentrant
35911 \begin_inset LatexCommand \index{reentrant}
35915 unless explicitly declared as such or the
35921 \begin_layout Standard
35931 \begin_inset LatexCommand \index{-\/-stack-auto}
35937 command line option is specified.
35940 \begin_layout Itemize
35942 \begin_inset LatexCommand \index{struct}
35947 \begin_inset LatexCommand \index{union}
35951 cannot be assigned values directly, cannot be passed as function parameters
35952 or assigned to each other and cannot be a return value
35953 \begin_inset LatexCommand \index{return value}
35957 from a function, e.g.:
35961 \begin_layout Verse
35984 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
36003 s parms) /* invalid in SDCC although allowed in ANSI */
36025 return rets; /* is invalid in SDCC although allowed in ANSI */
36031 \begin_layout Itemize
36032 initialization of structure arrays must be fully braced.
36036 \begin_layout Verse
36039 struct s { char x } a[] = {1, 2};\InsetSpace ~
36044 /* invalid in SDCC */
36047 } a[] = {{1}, {2}}; /* OK */
36051 \begin_layout Itemize
36053 \begin_inset LatexCommand \index{long long (not supported)}
36058 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
36065 \begin_layout Itemize
36067 \begin_inset LatexCommand \index{double (not supported)}
36071 ' precision floating point
36072 \begin_inset LatexCommand \index{Floating point support}
36079 \begin_layout Itemize
36081 \begin_inset LatexCommand \index{K\&R style}
36085 function declarations are NOT allowed.
36089 \begin_layout Verse
36092 foo(i,j) /* this old style of function declarations */
36094 int i,j; /* is valid
36095 in ANSI but not valid in SDCC */
36110 \begin_layout Itemize
36111 Most enhancements in C99 are not supported, e.g.:
36115 \begin_layout Verse
36122 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
36126 \begin_layout Itemize
36127 But some have been added recently in SDCC 2.7.0.
36128 They must be considered alpha quality however.
36132 \begin_layout Verse
36137 \begin_inset LatexCommand \index{inline (not supported)}
36143 int increment (int a) { return a+1; } /* inlines the increment without
36144 function call overhead */
36149 \begin_inset LatexCommand \index{inline (not supported)}
36155 p; /* accepted but ignored */
36159 \begin_layout Itemize
36160 Certain words that are valid identifiers in the standard may be reserved
36161 words in SDCC unless the
36167 \begin_layout Standard
36177 \begin_inset LatexCommand \index{-\/-std-c89}
36185 \begin_layout Standard
36195 \begin_inset LatexCommand \index{-\/-std-c99}
36201 command line options are used.
36202 These may include (depending on the selected processor): 'at', 'banked',
36203 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
36204 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
36205 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
36207 Compliant equivalents of these keywords are always available in a form
36208 that begin with two underscores
36209 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
36214 '__data' instead of 'data'.
36217 \begin_layout Section
36218 Cyclomatic Complexity
36219 \begin_inset LatexCommand \index{Cyclomatic complexity}
36226 \begin_layout Standard
36227 Cyclomatic complexity of a function is defined as the number of independent
36228 paths the program can take during execution of the function.
36229 This is an important number since it defines the number test cases you
36230 have to generate to validate the function.
36231 The accepted industry standard for complexity number is 10, if the cyclomatic
36232 complexity reported by SDCC exceeds 10 you should think about simplification
36233 of the function logic.
36234 Note that the complexity level is not related to the number of lines of
36235 code in a function.
36236 Large functions can have low complexity, and small functions can have large
36242 SDCC uses the following formula to compute the complexity:
36247 \begin_layout Standard
36248 complexity = (number of edges in control flow graph) - (number of nodes
36249 in control flow graph) + 2;
36253 Having said that the industry standard is 10,
36254 you should be aware that in some cases it be may unavoidable to have a
36255 complexity level of less than 10.
36256 For example if you have switch statement with more than 10 case labels,
36257 each case label adds one to the complexity level.
36258 The complexity level is by no means an absolute measure of the algorithmic
36259 complexity of the function, it does however provide a good starting point
36260 for which functions you might look at for further optimization.
36263 \begin_layout Section
36264 Retargetting for other Processors
36267 \begin_layout Standard
36268 The issues for retargetting the compiler are far too numerous to be covered
36270 What follows is a brief description of each of the seven phases of the
36271 compiler and its MCU dependency.
36274 \begin_layout Itemize
36275 Parsing the source and building the annotated parse tree.
36276 This phase is largely MCU independent (except for the language extensions).
36277 Syntax & semantic checks are also done in this phase, along with some initial
36278 optimizations like back patching labels and the pattern matching optimizations
36279 like bit-rotation etc.
36282 \begin_layout Itemize
36283 The second phase involves generating an intermediate code which can be easy
36284 manipulated during the later phases.
36285 This phase is entirely MCU independent.
36286 The intermediate code generation assumes the target machine has unlimited
36287 number of registers, and designates them with the name iTemp.
36288 The compiler can be made to dump a human readable form of the code generated
36293 \begin_layout Standard
36305 \begin_layout Itemize
36306 This phase does the bulk of the standard optimizations and is also MCU independe
36308 This phase can be broken down into several sub-phases:
36312 Break down intermediate
36313 code (iCode) into basic blocks.
36315 Do control flow & data flow analysis on the
36318 Do local common subexpression elimination, then global subexpressio
36321 Dead code elimination
36325 If loop optimizations
36326 caused any changes then do 'global subexpression elimination' and 'dead
36327 code elimination' again.
36330 \begin_layout Itemize
36331 This phase determines the live-ranges; by live range I mean those iTemp
36332 variables defined by the compiler that still survive after all the optimization
36334 Live range analysis
36335 \begin_inset LatexCommand \index{Live range analysis}
36339 is essential for register allocation, since these computation determines
36340 which of these iTemps will be assigned to registers, and for how long.
36343 \begin_layout Itemize
36344 Phase five is register allocation.
36345 There are two parts to this process.
36349 The first part I call 'register packing'
36350 (for lack of a better term).
36351 In this case several MCU specific expression folding is done to reduce
36356 The second part is more MCU independent and deals with
36357 allocating registers to the remaining live ranges.
36358 A lot of MCU specific code does creep into this phase because of the limited
36359 number of index registers available in the 8051.
36362 \begin_layout Itemize
36363 The Code generation phase is (unhappily), entirely MCU dependent and very
36364 little (if any at all) of this code can be reused for other MCU.
36365 However the scheme for allocating a homogenized assembler operand for each
36366 iCode operand may be reused.
36369 \begin_layout Itemize
36370 As mentioned in the optimization section the peep-hole optimizer is rule
36371 based system, which can reprogrammed for other MCUs.
36374 \begin_layout Standard
36375 More information is available in a wiki
36376 \begin_inset LatexCommand \index{wiki}
36381 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
36385 ) and in the thread
36386 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
36393 \begin_layout Chapter
36395 \begin_inset LatexCommand \index{Compiler internals}
36402 \begin_layout Section
36403 The anatomy of the compiler
36404 \begin_inset LatexCommand \label{sub:The-anatomy-of}
36411 \begin_layout Standard
36414 This is an excerpt from an article published in Circuit Cellar Magazine
36420 It's a little outdated (the compiler is much more efficient now and user/develo
36421 per friendly), but pretty well exposes the guts of it all.
36427 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
36428 It is fairly easy to retarget for other 8-bit MCU.
36429 Here we take a look at some of the internals of the compiler.
36433 \begin_layout Paragraph*
36435 \begin_inset LatexCommand \index{Parsing}
36442 \begin_layout Standard
36443 Parsing the input source file and creating an AST (Annotated Syntax Tree
36444 \begin_inset LatexCommand \index{Annotated syntax tree}
36449 This phase also involves propagating types (annotating each node of the
36450 parse tree with type information) and semantic analysis.
36451 There are some MCU specific parsing rules.
36452 For example the storage classes, the extended storage classes are MCU specific
36453 while there may be a xdata storage class for 8051 there is no such storage
36454 class for z80 or Atmel AVR.
36455 SDCC allows MCU specific storage class extensions, i.e.
36456 xdata will be treated as a storage class specifier when parsing 8051 C
36457 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
36461 \begin_layout Paragraph*
36463 \begin_inset LatexCommand \index{iCode}
36470 \begin_layout Standard
36471 Intermediate code generation.
36472 In this phase the AST is broken down into three-operand form (iCode).
36473 These three operand forms are represented as doubly linked lists.
36474 ICode is the term given to the intermediate form generated by the compiler.
36475 ICode example section shows some examples of iCode generated for some simple
36476 C source functions.
36479 \begin_layout Paragraph*
36481 \begin_inset LatexCommand \index{Optimizations}
36488 \begin_layout Standard
36489 Bulk of the target independent optimizations is performed in this phase.
36490 The optimizations include constant propagation, common sub-expression eliminati
36491 on, loop invariant code movement, strength reduction of loop induction variables
36492 and dead-code elimination.
36495 \begin_layout Paragraph*
36496 Live range analysis
36497 \begin_inset LatexCommand \index{Live range analysis}
36504 \begin_layout Standard
36505 During intermediate code generation phase, the compiler assumes the target
36506 machine has infinite number of registers and generates a lot of temporary
36508 The live range computation determines the lifetime of each of these compiler-ge
36509 nerated temporaries.
36510 A picture speaks a thousand words.
36511 ICode example sections show the live range annotations for each of the
36513 It is important to note here, each iCode is assigned a number in the order
36514 of its execution in the function.
36515 The live ranges are computed in terms of these numbers.
36516 The from number is the number of the iCode which first defines the operand
36517 and the to number signifies the iCode which uses this operand last.
36520 \begin_layout Paragraph*
36521 Register Allocation
36522 \begin_inset LatexCommand \index{Register allocation}
36529 \begin_layout Standard
36530 The register allocation determines the type and number of registers needed
36532 In most MCUs only a few registers can be used for indirect addressing.
36533 In case of 8051 for example the registers R0 & R1 can be used to indirectly
36534 address the internal ram and DPTR to indirectly address the external ram.
36535 The compiler will try to allocate the appropriate register to pointer variables
36537 ICode example section shows the operands annotated with the registers assigned
36539 The compiler will try to keep operands in registers as much as possible;
36540 there are several schemes the compiler uses to do achieve this.
36541 When the compiler runs out of registers the compiler will check to see
36542 if there are any live operands which is not used or defined in the current
36543 basic block being processed, if there are any found then it will push that
36544 operand and use the registers in this block, the operand will then be popped
36545 at the end of the basic block.
36549 \begin_layout Standard
36550 There are other MCU specific considerations in this phase.
36551 Some MCUs have an accumulator; very short-lived operands could be assigned
36552 to the accumulator instead of a general-purpose register.
36555 \begin_layout Paragraph*
36559 \begin_layout Standard
36560 Figure II gives a table of iCode
36561 \begin_inset LatexCommand \index{iCode}
36565 operations supported by the compiler.
36566 The code generation involves translating these operations into corresponding
36567 assembly code for the processor.
36568 This sounds overly simple but that is the essence of code generation.
36569 Some of the iCode operations are generated on a MCU specific manner for
36570 example, the z80 port does not use registers to pass parameters so the
36571 SEND and RECV iCode operations will not be generated, and it also does
36572 not support JUMPTABLES.
36578 \begin_layout Standard
36582 \begin_inset Tabular
36583 <lyxtabular version="3" rows="39" columns="4">
36584 <features islongtable="true" headBottomDL="true">
36585 <column alignment="block" valignment="top" leftline="true" width="13col%">
36586 <column alignment="left" valignment="top" leftline="true" width="13col%">
36587 <column alignment="block" valignment="top" leftline="true" width="22col%">
36588 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
36589 <row topline="true" bottomline="true" endhead="true">
36590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36593 \begin_layout Standard
36599 \begin_inset LatexCommand \index{iCode}
36608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36611 \begin_layout Standard
36619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36622 \begin_layout Standard
36630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36633 \begin_layout Standard
36642 <row topline="true">
36643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36646 \begin_layout Standard
36654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36657 \begin_layout Standard
36660 IC_LEFT() IC_RESULT()
36665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36668 \begin_layout Standard
36676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36679 \begin_layout Standard
36682 IC_RESULT = ! IC_LEFT;
36688 <row topline="true">
36689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36692 \begin_layout Standard
36700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36703 \begin_layout Standard
36706 IC_LEFT() IC_RESULT()
36711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36714 \begin_layout Standard
36717 Bitwise complement of
36722 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36725 \begin_layout Standard
36728 IC_RESULT = ~IC_LEFT;
36734 <row topline="true">
36735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36738 \begin_layout Standard
36746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36749 \begin_layout Standard
36752 IC_LEFT() IC_RESULT()
36757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36760 \begin_layout Standard
36763 Rotate right with carry
36768 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36771 \begin_layout Standard
36774 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
36780 <row topline="true">
36781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36784 \begin_layout Standard
36792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36795 \begin_layout Standard
36798 IC_LEFT() IC_RESULT()
36803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36806 \begin_layout Standard
36809 Rotate left with carry
36814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36817 \begin_layout Standard
36820 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
36826 <row topline="true">
36827 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36830 \begin_layout Standard
36838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36841 \begin_layout Standard
36844 IC_LEFT() IC_RESULT()
36849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36852 \begin_layout Standard
36855 Get the highest order bit of IC_LEFT
36860 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36863 \begin_layout Standard
36866 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
36872 <row topline="true">
36873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36876 \begin_layout Standard
36884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36887 \begin_layout Standard
36890 IC_LEFT() IC_RESULT()
36895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36898 \begin_layout Standard
36906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36909 \begin_layout Standard
36912 IC_RESULT = - IC_LEFT;
36918 <row topline="true">
36919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36922 \begin_layout Standard
36930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36933 \begin_layout Standard
36941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36944 \begin_layout Standard
36947 Push the operand into stack
36952 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36955 \begin_layout Standard
36964 <row topline="true">
36965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36968 \begin_layout Standard
36976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36979 \begin_layout Standard
36987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36990 \begin_layout Standard
36993 Pop the operand from the stack
36998 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37001 \begin_layout Standard
37010 <row topline="true">
37011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37014 \begin_layout Standard
37022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37025 \begin_layout Standard
37028 IC_LEFT() IC_RESULT()
37033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37036 \begin_layout Standard
37039 Call the function represented by IC_LEFT
37044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37047 \begin_layout Standard
37050 IC_RESULT = IC_LEFT();
37056 <row topline="true">
37057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37060 \begin_layout Standard
37068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37071 \begin_layout Standard
37074 IC_LEFT() IC_RESULT()
37079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37082 \begin_layout Standard
37085 Call via function pointer
37090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37093 \begin_layout Standard
37096 IC_RESULT = (*IC_LEFT)();
37102 <row topline="true">
37103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37106 \begin_layout Standard
37114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37117 \begin_layout Standard
37125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37128 \begin_layout Standard
37131 Return the value in operand IC_LEFT
37136 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37139 \begin_layout Standard
37148 <row topline="true">
37149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37152 \begin_layout Standard
37160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37163 \begin_layout Standard
37171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37174 \begin_layout Standard
37182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37185 \begin_layout Standard
37194 <row topline="true">
37195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37198 \begin_layout Standard
37206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37209 \begin_layout Standard
37217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37220 \begin_layout Standard
37228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37231 \begin_layout Standard
37240 <row topline="true">
37241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37244 \begin_layout Standard
37252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37255 \begin_layout Standard
37258 IC_LEFT() IC_RIGHT() IC_RESULT()
37263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37266 \begin_layout Standard
37274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37277 \begin_layout Standard
37280 IC_RESULT = IC_LEFT + IC_RIGHT
37286 <row topline="true">
37287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37290 \begin_layout Standard
37298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37301 \begin_layout Standard
37304 IC_LEFT() IC_RIGHT() IC_RESULT()
37309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37312 \begin_layout Standard
37320 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37323 \begin_layout Standard
37326 IC_RESULT = IC_LEFT - IC_RIGHT
37332 <row topline="true">
37333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37336 \begin_layout Standard
37344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37347 \begin_layout Standard
37350 IC_LEFT() IC_RIGHT() IC_RESULT()
37355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37358 \begin_layout Standard
37366 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37369 \begin_layout Standard
37372 IC_RESULT = IC_LEFT * IC_RIGHT;
37378 <row topline="true">
37379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37382 \begin_layout Standard
37390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37393 \begin_layout Standard
37396 IC_LEFT() IC_RIGHT() IC_RESULT()
37401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37404 \begin_layout Standard
37412 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37415 \begin_layout Standard
37418 IC_RESULT = IC_LEFT / IC_RIGHT;
37424 <row topline="true">
37425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37428 \begin_layout Standard
37436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37439 \begin_layout Standard
37442 IC_LEFT() IC_RIGHT() IC_RESULT()
37447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37450 \begin_layout Standard
37458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37461 \begin_layout Standard
37464 IC_RESULT = IC_LEFT % IC_RIGHT;
37470 <row topline="true">
37471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37474 \begin_layout Standard
37482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37485 \begin_layout Standard
37488 IC_LEFT() IC_RIGHT() IC_RESULT()
37493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37496 \begin_layout Standard
37504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37507 \begin_layout Standard
37510 IC_RESULT = IC_LEFT < IC_RIGHT;
37516 <row topline="true">
37517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37520 \begin_layout Standard
37528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37531 \begin_layout Standard
37534 IC_LEFT() IC_RIGHT() IC_RESULT()
37539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37542 \begin_layout Standard
37550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37553 \begin_layout Standard
37556 IC_RESULT = IC_LEFT > IC_RIGHT;
37562 <row topline="true">
37563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37566 \begin_layout Standard
37574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37577 \begin_layout Standard
37580 IC_LEFT() IC_RIGHT() IC_RESULT()
37585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37588 \begin_layout Standard
37596 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37599 \begin_layout Standard
37602 IC_RESULT = IC_LEFT == IC_RIGHT;
37608 <row topline="true">
37609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37612 \begin_layout Standard
37620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37623 \begin_layout Standard
37626 IC_LEFT() IC_RIGHT() IC_RESULT()
37631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37634 \begin_layout Standard
37637 Logical and operation
37642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37645 \begin_layout Standard
37648 IC_RESULT = IC_LEFT && IC_RIGHT;
37654 <row topline="true">
37655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37658 \begin_layout Standard
37666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37669 \begin_layout Standard
37672 IC_LEFT() IC_RIGHT() IC_RESULT()
37677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37680 \begin_layout Standard
37683 Logical or operation
37688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37691 \begin_layout Standard
37694 IC_RESULT = IC_LEFT || IC_RIGHT;
37700 <row topline="true">
37701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37704 \begin_layout Standard
37712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37715 \begin_layout Standard
37718 IC_LEFT() IC_RIGHT() IC_RESULT()
37723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37726 \begin_layout Standard
37734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37737 \begin_layout Standard
37740 IC_RESULT = IC_LEFT ^ IC_RIGHT;
37746 <row topline="true">
37747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37750 \begin_layout Standard
37758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37761 \begin_layout Standard
37764 IC_LEFT() IC_RIGHT() IC_RESULT()
37769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37772 \begin_layout Standard
37780 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37783 \begin_layout Standard
37786 IC_RESULT = IC_LEFT | IC_RIGHT;
37792 <row topline="true">
37793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37796 \begin_layout Standard
37804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37807 \begin_layout Standard
37810 IC_LEFT() IC_RIGHT() IC_RESULT()
37815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37818 \begin_layout Standard
37826 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37829 \begin_layout Standard
37832 IC_RESULT = IC_LEFT & IC_RIGHT;
37838 <row topline="true">
37839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37842 \begin_layout Standard
37850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37853 \begin_layout Standard
37856 IC_LEFT() IC_RIGHT() IC_RESULT()
37861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37864 \begin_layout Standard
37872 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37875 \begin_layout Standard
37878 IC_RESULT = IC_LEFT << IC_RIGHT
37884 <row topline="true">
37885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37888 \begin_layout Standard
37896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37899 \begin_layout Standard
37902 IC_LEFT() IC_RIGHT() IC_RESULT()
37907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37910 \begin_layout Standard
37918 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37921 \begin_layout Standard
37924 IC_RESULT = IC_LEFT >> IC_RIGHT
37930 <row topline="true">
37931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37934 \begin_layout Standard
37944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37947 \begin_layout Standard
37950 IC_LEFT() IC_RESULT()
37955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37958 \begin_layout Standard
37966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37969 \begin_layout Standard
37972 IC_RESULT = (*IC_LEFT);
37978 <row topline="true">
37979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37982 \begin_layout Standard
37990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37993 \begin_layout Standard
37996 IC_RIGHT() IC_RESULT()
38001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38004 \begin_layout Standard
38012 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38015 \begin_layout Standard
38018 (*IC_RESULT) = IC_RIGHT;
38024 <row topline="true">
38025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38028 \begin_layout Standard
38036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38039 \begin_layout Standard
38042 IC_RIGHT() IC_RESULT()
38047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38050 \begin_layout Standard
38058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38061 \begin_layout Standard
38064 IC_RESULT = IC_RIGHT;
38070 <row topline="true">
38071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38074 \begin_layout Standard
38082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38085 \begin_layout Standard
38088 IC_COND IC_TRUE IC_LABEL
38093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38096 \begin_layout Standard
38100 If true label is present then jump to true label if condition is true else
38101 jump to false label if condition is false
38106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38109 \begin_layout Standard
38112 if (IC_COND) goto IC_TRUE;
38118 If (!IC_COND) goto IC_FALSE;
38124 <row topline="true">
38125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38128 \begin_layout Standard
38136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38139 \begin_layout Standard
38142 IC_LEFT() IC_RESULT()
38147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38150 \begin_layout Standard
38158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38161 \begin_layout Standard
38164 IC_RESULT = &IC_LEFT();
38170 <row topline="true">
38171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38174 \begin_layout Standard
38182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38185 \begin_layout Standard
38188 IC_JTCOND IC_JTLABELS
38193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38196 \begin_layout Standard
38199 Jump to list of labels depending on the value of JTCOND
38204 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38207 \begin_layout Standard
38216 <row topline="true">
38217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38220 \begin_layout Standard
38228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38231 \begin_layout Standard
38234 IC_RIGHT() IC_LEFT() IC_RESULT()
38239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38242 \begin_layout Standard
38250 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38253 \begin_layout Standard
38256 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
38262 <row topline="true">
38263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38266 \begin_layout Standard
38274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38277 \begin_layout Standard
38285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38288 \begin_layout Standard
38291 This is used for passing parameters in registers;
38293 move IC_LEFT to the next
38294 available parameter register.
38299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38302 \begin_layout Standard
38311 <row topline="true">
38312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38315 \begin_layout Standard
38323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38326 \begin_layout Standard
38334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38337 \begin_layout Standard
38340 This is used for receiving parameters passed in registers;
38343 in the next parameter register to IC_RESULT
38348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38351 \begin_layout Standard
38360 <row topline="true" bottomline="true">
38361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38364 \begin_layout Standard
38368 (some more have been added)
38373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38376 \begin_layout Standard
38382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38385 \begin_layout Standard
38391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38394 \begin_layout Standard
38418 \begin_layout Standard
38419 \begin_inset Note Note
38422 \begin_layout Standard
38423 In the original article Figure II was announced to be downloadable on
38428 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
38436 \begin_layout Paragraph*
38438 \begin_inset LatexCommand \index{iCode}
38445 \begin_layout Standard
38446 This section shows some details of iCode.
38447 The example C code does not do anything useful; it is used as an example
38448 to illustrate the intermediate code generated by the compiler.
38451 \begin_layout Verse
38461 /* This function does nothing useful.
38468 for the purpose of explaining iCode */
38471 short function (data
38480 short i=10; \InsetSpace ~
38482 /* dead initialization eliminated */
38488 /* dead initialization eliminated */
38516 /* compiler detects i,j to be induction
38521 for (i = 0, j = 10 ; i < 10 ; i++, j
38527 \begin_layout Standard
38550 mul += i * 3; \InsetSpace ~
38552 /* this multiplication remains */
38559 j * 3;\InsetSpace ~
38561 /* this multiplication changed to addition */
38575 \begin_layout Standard
38576 In addition to the operands each iCode contains information about the filename
38577 and line it corresponds to in the source file.
38578 The first field in the listing should be interpreted as follows:
38583 Filename(linenumber: iCode Execution sequence number : ICode hash table
38584 key : loop depth of the iCode).
38589 Then follows the human readable form of the ICode operation.
38590 Each operand of this triplet form can be of three basic types a) compiler
38591 generated temporary b) user defined variable c) a constant value.
38592 Note that local variables and parameters are replaced by compiler generated
38595 \begin_inset LatexCommand \index{Live range analysis}
38599 are computed only for temporaries (i.e.
38600 live ranges are not computed for global variables).
38602 \begin_inset LatexCommand \index{Register allocation}
38606 are allocated for temporaries only.
38607 Operands are formatted in the following manner:
38612 Operand Name [lr live-from : live-to ] { type information } [ registers
38618 As mentioned earlier the live ranges are computed in terms of the execution
38619 sequence number of the iCodes, for example
38621 the iTemp0 is live from (i.e.
38622 first defined in iCode with execution sequence number 3, and is last used
38623 in the iCode with sequence number 5).
38624 For induction variables such as iTemp21 the live range computation extends
38625 the lifetime from the start to the end of the loop.
38627 The register allocator
38628 used the live range information to allocate registers, the same registers
38629 may be used for different temporaries if their live ranges do not overlap,
38630 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
38631 ranges do not overlap.
38632 In addition the allocator also takes into consideration the type and usage
38633 of a temporary, for example itemp6 is a pointer to near space and is used
38634 as to fetch data from (i.e.
38635 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
38636 Some short lived temporaries are allocated to special registers which have
38637 meaning to the code generator e.g.
38638 iTemp13 is allocated to a pseudo register CC which tells the back end that
38639 the temporary is used only for a conditional jump the code generation makes
38640 use of this information to optimize a compare and jump ICode.
38644 \begin_inset LatexCommand \index{Loop optimization}
38648 performed by the compiler.
38649 It can detect induction variables iTemp21(i) and iTemp23(j).
38650 Also note the compiler does selective strength reduction
38651 \begin_inset LatexCommand \index{Strength reduction}
38656 the multiplication of an induction variable in line 18 (gint = j * 3) is
38657 changed to addition, a new temporary iTemp17 is allocated and assigned
38658 a initial value, a constant 3 is then added for each iteration of the loop.
38659 The compiler does not change the multiplication
38660 \begin_inset LatexCommand \index{Multiplication}
38664 in line 17 however since the processor does support an 8 * 8 bit multiplication.
38667 Note the dead code elimination
38668 \begin_inset LatexCommand \index{Dead-code elimination}
38672 optimization eliminated the dead assignments in line 7 & 8 to I and sum
38678 \begin_layout Standard
38681 Sample.c (5:1:0:0) _entry($9) :
38684 \begin_layout Standard
38687 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
38690 \begin_layout Standard
38693 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
38696 \begin_layout Standard
38699 Sample.c(11:4:53:0) preHeaderLbl0($11) :
38702 \begin_layout Standard
38705 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
38709 \begin_layout Standard
38712 Sample.c(11:6:5:1) _whilecontinue_0($1) :
38715 \begin_layout Standard
38718 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
38722 \begin_layout Standard
38725 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38728 \begin_layout Standard
38731 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
38735 \begin_layout Standard
38738 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
38742 \begin_layout Standard
38745 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
38749 \begin_layout Standard
38752 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
38756 \begin_layout Standard
38759 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
38760 * int}[r0] + 0x2 {short}
38763 \begin_layout Standard
38766 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
38769 \begin_layout Standard
38772 Sample.c(11:17:21:0)_whilebreak_0($3) :
38775 \begin_layout Standard
38778 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38781 \begin_layout Standard
38784 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38787 \begin_layout Standard
38790 Sample.c(15:20:54:0)preHeaderLbl1($13) :
38793 \begin_layout Standard
38796 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38799 \begin_layout Standard
38802 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38805 \begin_layout Standard
38808 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38811 \begin_layout Standard
38814 Sample.c(15:24:26:1)_forcond_0($4) :
38817 \begin_layout Standard
38820 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
38824 \begin_layout Standard
38827 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38830 \begin_layout Standard
38833 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
38834 + ITemp21 [lr21:38]{short}[r4]
38837 \begin_layout Standard
38840 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
38844 \begin_layout Standard
38847 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
38848 + iTemp15 [lr29:30]{short}[r1]
38851 \begin_layout Standard
38854 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
38858 \begin_layout Standard
38861 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
38865 \begin_layout Standard
38868 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
38872 \begin_layout Standard
38875 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
38879 \begin_layout Standard
38882 Sample.c(19:38:47:1) goto _forcond_0($4)
38885 \begin_layout Standard
38888 Sample.c(19:39:48:0)_forbreak_0($7) :
38891 \begin_layout Standard
38894 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
38895 + ITemp11 [lr19:40]{short}[r3]
38898 \begin_layout Standard
38901 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
38904 \begin_layout Standard
38907 Sample.c(20:42:51:0)_return($8) :
38910 \begin_layout Standard
38913 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
38919 Finally the code generated for this function:
38924 \begin_layout Standard
38930 \begin_layout Standard
38936 \begin_layout Standard
38944 \begin_layout Standard
38950 \begin_layout Standard
38958 \begin_layout Standard
38964 \begin_layout Standard
38967 ; ----------------------------------------------
38970 \begin_layout Standard
38973 ; function function
38976 \begin_layout Standard
38979 ; ----------------------------------------------
38982 \begin_layout Standard
38988 \begin_layout Standard
38991 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
38994 \begin_layout Standard
39002 \begin_layout Standard
39005 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
39008 \begin_layout Standard
39016 \begin_layout Standard
39019 ;_whilecontinue_0($1) :
39022 \begin_layout Standard
39028 \begin_layout Standard
39031 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
39034 \begin_layout Standard
39037 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39040 \begin_layout Standard
39048 \begin_layout Standard
39056 \begin_layout Standard
39064 \begin_layout Standard
39072 \begin_layout Standard
39080 \begin_layout Standard
39088 \begin_layout Standard
39096 \begin_layout Standard
39102 \begin_layout Standard
39105 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
39108 \begin_layout Standard
39116 \begin_layout Standard
39124 \begin_layout Standard
39127 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
39130 \begin_layout Standard
39138 \begin_layout Standard
39146 \begin_layout Standard
39154 \begin_layout Standard
39162 \begin_layout Standard
39170 \begin_layout Standard
39178 \begin_layout Standard
39181 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
39184 \begin_layout Standard
39192 \begin_layout Standard
39200 \begin_layout Standard
39208 \begin_layout Standard
39216 \begin_layout Standard
39224 \begin_layout Standard
39227 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
39230 \begin_layout Standard
39238 \begin_layout Standard
39246 \begin_layout Standard
39254 \begin_layout Standard
39257 ; iTemp6 [lr5:16]{_near * int}[r0] =
39260 \begin_layout Standard
39263 ; iTemp6 [lr5:16]{_near * int}[r0] +
39266 \begin_layout Standard
39272 \begin_layout Standard
39280 \begin_layout Standard
39283 ; goto _whilecontinue_0($1)
39286 \begin_layout Standard
39294 \begin_layout Standard
39297 ; _whilebreak_0($3) :
39300 \begin_layout Standard
39306 \begin_layout Standard
39309 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39312 \begin_layout Standard
39320 \begin_layout Standard
39323 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39326 \begin_layout Standard
39334 \begin_layout Standard
39337 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39340 \begin_layout Standard
39348 \begin_layout Standard
39351 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39354 \begin_layout Standard
39362 \begin_layout Standard
39370 \begin_layout Standard
39373 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39376 \begin_layout Standard
39384 \begin_layout Standard
39392 \begin_layout Standard
39398 \begin_layout Standard
39404 \begin_layout Standard
39407 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
39410 \begin_layout Standard
39413 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
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 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
39468 \begin_layout Standard
39471 ; iTemp21 [lr21:38]{short}[r4]
39474 \begin_layout Standard
39482 \begin_layout Standard
39490 \begin_layout Standard
39498 \begin_layout Standard
39501 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
39504 \begin_layout Standard
39512 \begin_layout Standard
39520 \begin_layout Standard
39528 \begin_layout Standard
39536 \begin_layout Standard
39539 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
39542 \begin_layout Standard
39545 ; iTemp15 [lr29:30]{short}[r1]
39548 \begin_layout Standard
39556 \begin_layout Standard
39564 \begin_layout Standard
39567 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
39570 \begin_layout Standard
39578 \begin_layout Standard
39586 \begin_layout Standard
39594 \begin_layout Standard
39602 \begin_layout Standard
39610 \begin_layout Standard
39618 \begin_layout Standard
39621 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
39624 \begin_layout Standard
39632 \begin_layout Standard
39640 \begin_layout Standard
39648 \begin_layout Standard
39656 \begin_layout Standard
39664 \begin_layout Standard
39672 \begin_layout Standard
39675 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
39678 \begin_layout Standard
39686 \begin_layout Standard
39689 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
39692 \begin_layout Standard
39700 \begin_layout Standard
39705 cjne r5,#0xff,00104$
39708 \begin_layout Standard
39716 \begin_layout Standard
39719 ; goto _forcond_0($4)
39722 \begin_layout Standard
39730 \begin_layout Standard
39733 ; _forbreak_0($7) :
39736 \begin_layout Standard
39742 \begin_layout Standard
39745 ; ret iTemp24 [lr40:41]{short}
39748 \begin_layout Standard
39756 \begin_layout Standard
39764 \begin_layout Standard
39772 \begin_layout Standard
39778 \begin_layout Standard
39784 \begin_layout Standard
39794 \begin_layout Section
39795 A few words about basic block successors, predecessors and dominators
39798 \begin_layout Standard
39799 Successors are basic blocks
39800 \begin_inset LatexCommand \index{Basic blocks}
39804 that might execute after this basic block.
39806 Predecessors are basic blocks
39807 that might execute before reaching this basic block.
39809 Dominators are basic
39810 blocks that WILL execute before reaching this basic block.
39815 \begin_layout Standard
39819 \begin_layout Standard
39823 \begin_layout Standard
39831 \begin_layout Standard
39835 \begin_layout Standard
39843 \begin_layout Standard
39849 \begin_layout Standard
39850 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
39853 \begin_layout Standard
39854 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
39857 \begin_layout Standard
39858 c) domVect of [BB4] = BB1 ...
39859 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
39863 \begin_layout Chapter
39867 \begin_layout Standard
39868 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
39878 Thanks to all the other volunteer developers who have helped with coding,
39879 testing, web-page creation, distribution sets, etc.
39880 You know who you are :-)
39888 Thanks to Sourceforge
39889 \begin_inset LatexCommand \url{http://www.sf.net}
39893 which has hosted the project since 1999 and donates significant download
39902 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
39903 cycles and bandwidth for snapshot builds.
39908 \begin_layout Standard
39909 This document was initially written by Sandeep Dutta
39912 \begin_layout Standard
39913 All product names mentioned herein may be trademarks
39914 \begin_inset LatexCommand \index{Trademarks}
39918 of their respective companies.
39922 \begin_layout Section*
39926 \begin_layout Standard
39927 To avoid confusion, the installation and building options for SDCC itself
39928 (chapter 2) are not part of the index.
39931 \begin_layout Standard
39932 \begin_inset LatexCommand \printindex{}